2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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.
11 #include "third_party/googletest/src/include/gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/util.h"
16 #include "test/y4m_video_source.h"
17 #include "vp9/decoder/vp9_decoder.h"
19 #include "vp9/vp9_dx_iface.c"
23 const int kCpuUsed = 2;
25 struct EncodePerfTestVideo {
33 const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
34 {"niklas_1280_720_30.y4m", 1280, 720, 600, 10},
37 struct EncodeParameters {
41 int32_t error_resilient;
42 int32_t frame_parallel;
43 vpx_color_range_t color_range;
46 // TODO(JBB): quantizers / bitrate
49 const EncodeParameters kVP9EncodeParameterSet[] = {
50 {0, 0, 0, 1, 0, VPX_CR_STUDIO_RANGE, VPX_CS_BT_601},
51 {0, 0, 0, 0, 0, VPX_CR_FULL_RANGE, VPX_CS_BT_709},
52 {0, 0, 1, 0, 0, VPX_CR_FULL_RANGE, VPX_CS_BT_2020},
53 {0, 2, 0, 0, 1, VPX_CR_STUDIO_RANGE, VPX_CS_UNKNOWN, { 640, 480 }},
54 // TODO(JBB): Test profiles (requires more work).
57 class VpxEncoderParmsGetToDecoder
58 : public ::libvpx_test::EncoderTest,
59 public ::libvpx_test::CodecTestWith2Params<EncodeParameters,
60 EncodePerfTestVideo> {
62 VpxEncoderParmsGetToDecoder()
63 : EncoderTest(GET_PARAM(0)), encode_parms(GET_PARAM(1)) {}
65 virtual ~VpxEncoderParmsGetToDecoder() {}
67 virtual void SetUp() {
69 SetMode(::libvpx_test::kTwoPassGood);
70 cfg_.g_lag_in_frames = 25;
71 cfg_.g_error_resilient = encode_parms.error_resilient;
73 test_video_ = GET_PARAM(2);
74 cfg_.rc_target_bitrate = test_video_.bitrate;
77 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
78 ::libvpx_test::Encoder *encoder) {
79 if (video->frame() == 1) {
80 encoder->Control(VP9E_SET_COLOR_SPACE, encode_parms.cs);
81 encoder->Control(VP9E_SET_COLOR_RANGE, encode_parms.color_range);
82 encoder->Control(VP9E_SET_LOSSLESS, encode_parms.lossless);
83 encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING,
84 encode_parms.frame_parallel);
85 encoder->Control(VP9E_SET_TILE_ROWS, encode_parms.tile_rows);
86 encoder->Control(VP9E_SET_TILE_COLUMNS, encode_parms.tile_cols);
87 encoder->Control(VP8E_SET_CPUUSED, kCpuUsed);
88 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
89 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
90 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
91 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
92 if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0)
93 encoder->Control(VP9E_SET_RENDER_SIZE, encode_parms.render_size);
97 virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
98 const libvpx_test::VideoSource &video,
99 libvpx_test::Decoder *decoder) {
100 vpx_codec_ctx_t *const vp9_decoder = decoder->GetDecoder();
101 vpx_codec_alg_priv_t *const priv =
102 reinterpret_cast<vpx_codec_alg_priv_t *>(vp9_decoder->priv);
103 FrameWorkerData *const worker_data =
104 reinterpret_cast<FrameWorkerData *>(priv->frame_workers[0].data1);
105 VP9_COMMON *const common = &worker_data->pbi->common;
107 if (encode_parms.lossless) {
108 EXPECT_EQ(0, common->base_qindex);
109 EXPECT_EQ(0, common->y_dc_delta_q);
110 EXPECT_EQ(0, common->uv_dc_delta_q);
111 EXPECT_EQ(0, common->uv_ac_delta_q);
112 EXPECT_EQ(ONLY_4X4, common->tx_mode);
114 EXPECT_EQ(encode_parms.error_resilient, common->error_resilient_mode);
115 if (encode_parms.error_resilient) {
116 EXPECT_EQ(1, common->frame_parallel_decoding_mode);
117 EXPECT_EQ(0, common->use_prev_frame_mvs);
119 EXPECT_EQ(encode_parms.frame_parallel,
120 common->frame_parallel_decoding_mode);
122 EXPECT_EQ(encode_parms.color_range, common->color_range);
123 EXPECT_EQ(encode_parms.cs, common->color_space);
124 if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0) {
125 EXPECT_EQ(encode_parms.render_size[0], common->render_width);
126 EXPECT_EQ(encode_parms.render_size[1], common->render_height);
128 EXPECT_EQ(encode_parms.tile_cols, common->log2_tile_cols);
129 EXPECT_EQ(encode_parms.tile_rows, common->log2_tile_rows);
131 EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
132 return VPX_CODEC_OK == res_dec;
135 EncodePerfTestVideo test_video_;
138 EncodeParameters encode_parms;
141 TEST_P(VpxEncoderParmsGetToDecoder, BitstreamParms) {
142 init_flags_ = VPX_CODEC_USE_PSNR;
144 libvpx_test::VideoSource *const video =
145 new libvpx_test::Y4mVideoSource(test_video_.name, 0, test_video_.frames);
146 ASSERT_TRUE(video != NULL);
148 ASSERT_NO_FATAL_FAILURE(RunLoop(video));
152 VP9_INSTANTIATE_TEST_CASE(VpxEncoderParmsGetToDecoder,
153 ::testing::ValuesIn(kVP9EncodeParameterSet),
154 ::testing::ValuesIn(kVP9EncodePerfTestVectors));