realtime_test.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2016 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "test/codec_factory.h"
  11. #include "test/encode_test_driver.h"
  12. #include "test/util.h"
  13. #include "test/video_source.h"
  14. #include "third_party/googletest/src/include/gtest/gtest.h"
  15. namespace {
  16. const int kVideoSourceWidth = 320;
  17. const int kVideoSourceHeight = 240;
  18. const int kFramesToEncode = 2;
  19. class RealtimeTest
  20. : public ::libvpx_test::EncoderTest,
  21. public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
  22. protected:
  23. RealtimeTest() : EncoderTest(GET_PARAM(0)), frame_packets_(0) {}
  24. virtual ~RealtimeTest() {}
  25. virtual void SetUp() {
  26. InitializeConfig();
  27. cfg_.g_lag_in_frames = 0;
  28. SetMode(::libvpx_test::kRealTime);
  29. }
  30. virtual void BeginPassHook(unsigned int /*pass*/) {
  31. // TODO(tomfinegan): We're changing the pass value here to make sure
  32. // we get frames when real time mode is combined with |g_pass| set to
  33. // VPX_RC_FIRST_PASS. This is necessary because EncoderTest::RunLoop() sets
  34. // the pass value based on the mode passed into EncoderTest::SetMode(),
  35. // which overrides the one specified in SetUp() above.
  36. cfg_.g_pass = VPX_RC_FIRST_PASS;
  37. }
  38. virtual void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) {
  39. frame_packets_++;
  40. }
  41. int frame_packets_;
  42. };
  43. TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) {
  44. ::libvpx_test::RandomVideoSource video;
  45. video.SetSize(kVideoSourceWidth, kVideoSourceHeight);
  46. video.set_limit(kFramesToEncode);
  47. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  48. EXPECT_EQ(kFramesToEncode, frame_packets_);
  49. }
  50. VP8_INSTANTIATE_TEST_CASE(RealtimeTest,
  51. ::testing::Values(::libvpx_test::kRealTime));
  52. VP9_INSTANTIATE_TEST_CASE(RealtimeTest,
  53. ::testing::Values(::libvpx_test::kRealTime));
  54. } // namespace