Alex Converse | 2f6bdd8 | 2016-12-15 09:54:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
| 3 | * |
| 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 10 | */ |
| 11 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Alex Converse | 2f6bdd8 | 2016-12-15 09:54:28 -0800 | [diff] [blame] | 13 | |
| 14 | #include "test/codec_factory.h" |
| 15 | #include "test/encode_test_driver.h" |
| 16 | #include "test/util.h" |
| 17 | #include "test/y4m_video_source.h" |
| 18 | #include "aom_dsp/ans.h" |
| 19 | #include "av1/av1_dx_iface.c" |
| 20 | |
| 21 | // A note on ANS_MAX_SYMBOLS == 0: |
| 22 | // Fused gtest doesn't work with EXPECT_FATAL_FAILURE [1]. Just run with a |
| 23 | // single iteration and don't try to check the window size if we are unwindowed. |
| 24 | // [1] https://github.com/google/googletest/issues/356 |
| 25 | |
| 26 | namespace { |
| 27 | |
| 28 | const char kTestVideoName[] = "niklas_1280_720_30.y4m"; |
| 29 | const int kTestVideoFrames = 10; |
| 30 | |
| 31 | class AnsCodecTest : public ::libaom_test::EncoderTest, |
| 32 | public ::libaom_test::CodecTestWithParam<int> { |
| 33 | protected: |
| 34 | AnsCodecTest() |
| 35 | : EncoderTest(GET_PARAM(0)), ans_window_size_log2_(GET_PARAM(1)) {} |
| 36 | |
| 37 | virtual ~AnsCodecTest() {} |
| 38 | |
| 39 | virtual void SetUp() { |
| 40 | InitializeConfig(); |
| 41 | SetMode(::libaom_test::kOnePassGood); |
| 42 | cfg_.g_lag_in_frames = 25; |
| 43 | cfg_.rc_end_usage = AOM_CQ; |
| 44 | } |
| 45 | |
| 46 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 47 | ::libaom_test::Encoder *encoder) { |
| 48 | if (video->frame() == 1) { |
| 49 | #if ANS_MAX_SYMBOLS |
| 50 | encoder->Control(AV1E_SET_ANS_WINDOW_SIZE_LOG2, ans_window_size_log2_); |
| 51 | #endif |
| 52 | // Try to push a high symbol count through the codec |
| 53 | encoder->Control(AOME_SET_CQ_LEVEL, 8); |
| 54 | encoder->Control(AOME_SET_CPUUSED, 2); |
| 55 | encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1); |
| 56 | encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7); |
| 57 | encoder->Control(AOME_SET_ARNR_STRENGTH, 5); |
| 58 | encoder->Control(AV1E_SET_TILE_COLUMNS, 0); |
| 59 | encoder->Control(AV1E_SET_TILE_ROWS, 0); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | virtual bool HandleDecodeResult(const aom_codec_err_t res_dec, |
| 64 | libaom_test::Decoder *decoder) { |
| 65 | aom_codec_ctx_t *const av1_decoder = decoder->GetDecoder(); |
| 66 | #if ANS_MAX_SYMBOLS |
| 67 | aom_codec_alg_priv_t *const priv = |
| 68 | reinterpret_cast<aom_codec_alg_priv_t *>(av1_decoder->priv); |
| 69 | FrameWorkerData *const worker_data = |
| 70 | reinterpret_cast<FrameWorkerData *>(priv->frame_workers[0].data1); |
| 71 | AV1_COMMON *const common = &worker_data->pbi->common; |
| 72 | |
| 73 | EXPECT_EQ(ans_window_size_log2_, common->ans_window_size_log2); |
| 74 | #endif |
| 75 | |
| 76 | EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError(); |
| 77 | return AOM_CODEC_OK == res_dec; |
| 78 | } |
| 79 | |
| 80 | private: |
| 81 | int ans_window_size_log2_; |
| 82 | }; |
| 83 | |
| 84 | TEST_P(AnsCodecTest, BitstreamParms) { |
| 85 | testing::internal::scoped_ptr<libaom_test::VideoSource> video( |
| 86 | new libaom_test::Y4mVideoSource(kTestVideoName, 0, kTestVideoFrames)); |
| 87 | ASSERT_TRUE(video.get() != NULL); |
| 88 | |
| 89 | ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); |
| 90 | } |
| 91 | |
| 92 | #if ANS_MAX_SYMBOLS |
| 93 | AV1_INSTANTIATE_TEST_CASE(AnsCodecTest, ::testing::Range(8, 24)); |
| 94 | #else |
| 95 | AV1_INSTANTIATE_TEST_CASE(AnsCodecTest, ::testing::Range(0, 1)); |
| 96 | #endif |
| 97 | } // namespace |