Tom Finegan | 5a9f21d | 2016-06-15 13:42:59 -0700 | [diff] [blame^] | 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 | |
| 16 | namespace { |
| 17 | |
| 18 | const int kVideoSourceWidth = 320; |
| 19 | const int kVideoSourceHeight = 240; |
| 20 | const int kFramesToEncode = 2; |
| 21 | |
| 22 | class RealtimeTest |
| 23 | : public ::libvpx_test::EncoderTest, |
| 24 | public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { |
| 25 | protected: |
| 26 | RealtimeTest() |
| 27 | : EncoderTest(GET_PARAM(0)), num_decoded_(0), frame_packets_(0) {} |
| 28 | virtual ~RealtimeTest() {} |
| 29 | |
| 30 | virtual void SetUp() { |
| 31 | InitializeConfig(); |
| 32 | cfg_.g_lag_in_frames = 0; |
| 33 | SetMode(::libvpx_test::kRealTime); |
| 34 | } |
| 35 | |
| 36 | virtual void BeginPassHook(unsigned int /*pass*/) { |
| 37 | // TODO(tomfinegan): We're changing the pass value here to make sure |
| 38 | // we get frames when real time mode is combined with |g_pass| set to |
| 39 | // VPX_RC_FIRST_PASS. This is necessary because EncoderTest::RunLoop() sets |
| 40 | // the pass value based on the mode passed into EncoderTest::SetMode(), |
| 41 | // which overrides the one specified in SetUp() above. |
| 42 | cfg_.g_pass = VPX_RC_FIRST_PASS; |
| 43 | } |
| 44 | virtual void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) { |
| 45 | frame_packets_++; |
| 46 | } |
| 47 | virtual void DecompressedFrameHook(const vpx_image_t & /*img*/, |
| 48 | vpx_codec_pts_t /*pts*/) { |
| 49 | num_decoded_++; |
| 50 | } |
| 51 | virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec, |
| 52 | const libvpx_test::VideoSource & /*video*/, |
| 53 | libvpx_test::Decoder *decoder) { |
| 54 | EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError(); |
| 55 | return !::testing::Test::HasFailure(); |
| 56 | } |
| 57 | |
| 58 | int num_decoded_; |
| 59 | int frame_packets_; |
| 60 | }; |
| 61 | |
| 62 | TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) { |
| 63 | ::libvpx_test::RandomVideoSource video; |
| 64 | video.SetSize(kVideoSourceWidth, kVideoSourceHeight); |
| 65 | video.set_limit(kFramesToEncode); |
| 66 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 67 | EXPECT_EQ(kFramesToEncode, num_decoded_); |
| 68 | EXPECT_EQ(kFramesToEncode, frame_packets_); |
| 69 | } |
| 70 | |
| 71 | VP8_INSTANTIATE_TEST_CASE(RealtimeTest, |
| 72 | ::testing::Values(::libvpx_test::kRealTime)); |
| 73 | VP9_INSTANTIATE_TEST_CASE(RealtimeTest, |
| 74 | ::testing::Values(::libvpx_test::kRealTime)); |
| 75 | |
| 76 | } // namespace |