Yaowu Xu | 5ce638f | 2018-08-21 10:39:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, 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 | |
sarahparker | 270a7ff | 2018-11-02 13:22:27 -0700 | [diff] [blame] | 12 | #include <memory> |
| 13 | |
Yaowu Xu | 5ce638f | 2018-08-21 10:39:05 -0700 | [diff] [blame] | 14 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
| 15 | |
| 16 | #include "test/codec_factory.h" |
| 17 | #include "test/encode_test_driver.h" |
| 18 | #include "test/util.h" |
| 19 | #include "test/y4m_video_source.h" |
| 20 | |
| 21 | #include "aom/aom_decoder.h" |
| 22 | #include "av1/decoder/decoder.h" |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | const int kMaxPsnr = 100; |
| 27 | |
| 28 | struct ParamPassingTestVideo { |
| 29 | const char *name; |
| 30 | uint32_t width; |
| 31 | uint32_t height; |
| 32 | uint32_t bitrate; |
| 33 | int frames; |
| 34 | }; |
| 35 | |
| 36 | const ParamPassingTestVideo kAV1ParamPassingTestVector = { |
| 37 | "niklas_1280_720_30.y4m", 1280, 720, 600, 3 |
| 38 | }; |
| 39 | |
| 40 | struct EncodeParameters { |
| 41 | int32_t lossless; |
Yaowu Xu | 8443732 | 2018-08-21 11:42:27 -0700 | [diff] [blame] | 42 | aom_color_primaries_t color_primaries; |
| 43 | aom_transfer_characteristics_t transfer_characteristics; |
| 44 | aom_matrix_coefficients_t matrix_coefficients; |
| 45 | aom_color_range_t color_range; |
| 46 | aom_chroma_sample_position_t chroma_sample_position; |
Yaowu Xu | 5ce638f | 2018-08-21 10:39:05 -0700 | [diff] [blame] | 47 | int32_t render_size[2]; |
| 48 | }; |
| 49 | |
| 50 | const EncodeParameters kAV1EncodeParameterSet[] = { |
Yaowu Xu | 8443732 | 2018-08-21 11:42:27 -0700 | [diff] [blame] | 51 | { 1, |
| 52 | AOM_CICP_CP_BT_709, |
| 53 | AOM_CICP_TC_BT_709, |
| 54 | AOM_CICP_MC_BT_709, |
| 55 | AOM_CR_STUDIO_RANGE, |
| 56 | AOM_CSP_UNKNOWN, |
| 57 | { 0, 0 } }, |
| 58 | { 0, |
| 59 | AOM_CICP_CP_BT_470_M, |
| 60 | AOM_CICP_TC_BT_470_M, |
| 61 | AOM_CICP_MC_BT_470_B_G, |
| 62 | AOM_CR_FULL_RANGE, |
| 63 | AOM_CSP_VERTICAL, |
| 64 | { 0, 0 } }, |
| 65 | { 1, |
| 66 | AOM_CICP_CP_BT_601, |
| 67 | AOM_CICP_TC_BT_601, |
| 68 | AOM_CICP_MC_BT_601, |
| 69 | AOM_CR_STUDIO_RANGE, |
| 70 | AOM_CSP_COLOCATED, |
| 71 | { 0, 0 } }, |
| 72 | { 0, |
| 73 | AOM_CICP_CP_BT_2020, |
| 74 | AOM_CICP_TC_BT_2020_10_BIT, |
| 75 | AOM_CICP_MC_BT_2020_NCL, |
| 76 | AOM_CR_FULL_RANGE, |
| 77 | AOM_CSP_RESERVED, |
| 78 | { 640, 480 } }, |
Yaowu Xu | 5ce638f | 2018-08-21 10:39:05 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | class AVxEncoderParmsGetToDecoder |
| 82 | : public ::libaom_test::EncoderTest, |
| 83 | public ::libaom_test::CodecTestWithParam<EncodeParameters> { |
| 84 | protected: |
| 85 | AVxEncoderParmsGetToDecoder() |
| 86 | : EncoderTest(GET_PARAM(0)), encode_parms(GET_PARAM(1)) {} |
| 87 | |
| 88 | virtual ~AVxEncoderParmsGetToDecoder() {} |
| 89 | |
| 90 | virtual void SetUp() { |
| 91 | InitializeConfig(); |
| 92 | SetMode(::libaom_test::kTwoPassGood); |
| 93 | cfg_.g_lag_in_frames = 25; |
| 94 | test_video_ = kAV1ParamPassingTestVector; |
| 95 | cfg_.rc_target_bitrate = test_video_.bitrate; |
| 96 | } |
| 97 | |
| 98 | virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video, |
| 99 | ::libaom_test::Encoder *encoder) { |
Yunqing Wang | 51b282d | 2018-10-01 16:25:34 -0700 | [diff] [blame] | 100 | if (video->frame() == 0) { |
Yaowu Xu | 8443732 | 2018-08-21 11:42:27 -0700 | [diff] [blame] | 101 | encoder->Control(AV1E_SET_COLOR_PRIMARIES, encode_parms.color_primaries); |
| 102 | encoder->Control(AV1E_SET_TRANSFER_CHARACTERISTICS, |
| 103 | encode_parms.transfer_characteristics); |
| 104 | encoder->Control(AV1E_SET_MATRIX_COEFFICIENTS, |
| 105 | encode_parms.matrix_coefficients); |
| 106 | encoder->Control(AV1E_SET_COLOR_RANGE, encode_parms.color_range); |
| 107 | encoder->Control(AV1E_SET_CHROMA_SAMPLE_POSITION, |
| 108 | encode_parms.chroma_sample_position); |
Yaowu Xu | 5ce638f | 2018-08-21 10:39:05 -0700 | [diff] [blame] | 109 | encoder->Control(AV1E_SET_LOSSLESS, encode_parms.lossless); |
| 110 | if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0) { |
| 111 | encoder->Control(AV1E_SET_RENDER_SIZE, encode_parms.render_size); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | virtual void DecompressedFrameHook(const aom_image_t &img, |
| 117 | aom_codec_pts_t pts) { |
| 118 | (void)pts; |
| 119 | if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0) { |
| 120 | EXPECT_EQ(encode_parms.render_size[0], (int)img.r_w); |
| 121 | EXPECT_EQ(encode_parms.render_size[1], (int)img.r_h); |
| 122 | } |
Yaowu Xu | 8443732 | 2018-08-21 11:42:27 -0700 | [diff] [blame] | 123 | EXPECT_EQ(encode_parms.color_primaries, img.cp); |
| 124 | EXPECT_EQ(encode_parms.transfer_characteristics, img.tc); |
| 125 | EXPECT_EQ(encode_parms.matrix_coefficients, img.mc); |
| 126 | EXPECT_EQ(encode_parms.color_range, img.range); |
| 127 | EXPECT_EQ(encode_parms.chroma_sample_position, img.csp); |
Yaowu Xu | 5ce638f | 2018-08-21 10:39:05 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) { |
| 131 | if (encode_parms.lossless) { |
| 132 | EXPECT_EQ(kMaxPsnr, pkt->data.psnr.psnr[0]); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | virtual bool HandleDecodeResult(const aom_codec_err_t res_dec, |
| 137 | libaom_test::Decoder *decoder) { |
| 138 | EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError(); |
| 139 | return AOM_CODEC_OK == res_dec; |
| 140 | } |
| 141 | |
| 142 | ParamPassingTestVideo test_video_; |
| 143 | |
| 144 | private: |
| 145 | EncodeParameters encode_parms; |
| 146 | }; |
| 147 | |
| 148 | TEST_P(AVxEncoderParmsGetToDecoder, BitstreamParms) { |
| 149 | init_flags_ = AOM_CODEC_USE_PSNR; |
| 150 | |
sarahparker | 270a7ff | 2018-11-02 13:22:27 -0700 | [diff] [blame] | 151 | std::unique_ptr<libaom_test::VideoSource> video( |
Yaowu Xu | 5ce638f | 2018-08-21 10:39:05 -0700 | [diff] [blame] | 152 | new libaom_test::Y4mVideoSource(test_video_.name, 0, test_video_.frames)); |
| 153 | ASSERT_TRUE(video.get() != NULL); |
| 154 | |
| 155 | ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); |
| 156 | } |
| 157 | |
| 158 | AV1_INSTANTIATE_TEST_CASE(AVxEncoderParmsGetToDecoder, |
| 159 | ::testing::ValuesIn(kAV1EncodeParameterSet)); |
| 160 | } // namespace |