av1_encoder_parms_get_to_decoder.cc (5007B)
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 12 #include <memory> 13 14 #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; 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; 47 int32_t render_size[2]; 48 }; 49 50 const EncodeParameters kAV1EncodeParameterSet[] = { 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 } }, 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 ~AVxEncoderParmsGetToDecoder() override = default; 89 90 void SetUp() override { 91 InitializeConfig(::libaom_test::kTwoPassGood); 92 cfg_.g_lag_in_frames = 25; 93 test_video_ = kAV1ParamPassingTestVector; 94 cfg_.rc_target_bitrate = test_video_.bitrate; 95 } 96 97 void PreEncodeFrameHook(::libaom_test::VideoSource *video, 98 ::libaom_test::Encoder *encoder) override { 99 if (video->frame() == 0) { 100 encoder->Control(AOME_SET_CPUUSED, 3); 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); 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 void DecompressedFrameHook(const aom_image_t &img, 117 aom_codec_pts_t pts) override { 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 } 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); 128 } 129 130 void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override { 131 if (encode_parms.lossless) { 132 EXPECT_EQ(kMaxPsnr, pkt->data.psnr.psnr[0]); 133 } 134 } 135 136 bool HandleDecodeResult(const aom_codec_err_t res_dec, 137 libaom_test::Decoder *decoder) override { 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 151 std::unique_ptr<libaom_test::VideoSource> video( 152 new libaom_test::Y4mVideoSource(test_video_.name, 0, test_video_.frames)); 153 ASSERT_NE(video, nullptr); 154 155 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); 156 } 157 158 AV1_INSTANTIATE_TEST_SUITE(AVxEncoderParmsGetToDecoder, 159 ::testing::ValuesIn(kAV1EncodeParameterSet)); 160 } // namespace