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 "test/codec_factory.h"
12 #include "test/encode_test_driver.h"
13 #include "test/y4m_video_source.h"
14 #include "test/yuv_video_source.h"
15 #include "test/util.h"
16 #include "third_party/googletest/src/include/gtest/gtest.h"
17 #include "vp9/decoder/vp9_decoder.h"
19 typedef vpx_codec_stream_info_t vp9_stream_info_t;
20 struct vpx_codec_alg_priv {
21 vpx_codec_priv_t base;
22 vpx_codec_dec_cfg_t cfg;
24 struct VP9Decoder *pbi;
26 vp8_postproc_cfg_t postproc_cfg;
27 vpx_decrypt_cb decrypt_cb;
32 int invert_tile_order;
33 int frame_parallel_decode;
35 // External frame buffer info to save for VP9 common.
36 void *ext_priv; // Private data associated with the external frame buffers.
37 vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb;
38 vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb;
41 static vpx_codec_alg_priv_t *get_alg_priv(vpx_codec_ctx_t *ctx) {
42 return (vpx_codec_alg_priv_t *)ctx->priv;
47 const unsigned int kFramerate = 50;
48 const int kCpuUsed = 2;
50 struct EncodePerfTestVideo {
58 const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
59 {"niklas_1280_720_30.yuv", 1280, 720, 600, 10},
62 struct EncodeParameters {
66 int32_t error_resilient;
67 int32_t frame_parallel;
69 // TODO(JBB): quantizers / bitrate
72 const EncodeParameters kVP9EncodeParameterSet[] = {
73 {0, 0, 0, 1, 0, VPX_CS_BT_601},
74 {0, 0, 0, 0, 0, VPX_CS_BT_709},
75 {0, 0, 1, 0, 0, VPX_CS_BT_2020},
76 {0, 2, 0, 0, 1, VPX_CS_UNKNOWN},
77 // TODO(JBB): Test profiles (requires more work).
80 int is_extension_y4m(const char *filename) {
81 const char *dot = strrchr(filename, '.');
82 if (!dot || dot == filename)
85 return !strcmp(dot, ".y4m");
88 class Vp9EncoderParmsGetToDecoder
89 : public ::libvpx_test::EncoderTest,
90 public ::libvpx_test::CodecTestWith2Params<EncodeParameters, \
91 EncodePerfTestVideo> {
93 Vp9EncoderParmsGetToDecoder()
94 : EncoderTest(GET_PARAM(0)),
95 encode_parms(GET_PARAM(1)) {
98 virtual ~Vp9EncoderParmsGetToDecoder() {}
100 virtual void SetUp() {
102 SetMode(::libvpx_test::kTwoPassGood);
103 cfg_.g_lag_in_frames = 25;
104 cfg_.g_error_resilient = encode_parms.error_resilient;
105 dec_cfg_.threads = 4;
106 test_video_ = GET_PARAM(2);
107 cfg_.rc_target_bitrate = test_video_.bitrate;
110 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
111 ::libvpx_test::Encoder *encoder) {
112 if (video->frame() == 1) {
113 encoder->Control(VP9E_SET_COLOR_SPACE, encode_parms.cs);
114 encoder->Control(VP9E_SET_LOSSLESS, encode_parms.lossless);
115 encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING,
116 encode_parms.frame_parallel);
117 encoder->Control(VP9E_SET_TILE_ROWS, encode_parms.tile_rows);
118 encoder->Control(VP9E_SET_TILE_COLUMNS, encode_parms.tile_cols);
119 encoder->Control(VP8E_SET_CPUUSED, kCpuUsed);
120 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
121 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
122 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
123 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
127 virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
128 const libvpx_test::VideoSource& video,
129 libvpx_test::Decoder *decoder) {
130 vpx_codec_ctx_t* vp9_decoder = decoder->GetDecoder();
131 vpx_codec_alg_priv_t* priv =
132 (vpx_codec_alg_priv_t*) get_alg_priv(vp9_decoder);
134 VP9Decoder* pbi = priv->pbi;
135 VP9_COMMON* common = &pbi->common;
137 if (encode_parms.lossless) {
138 EXPECT_EQ(common->base_qindex, 0);
139 EXPECT_EQ(common->y_dc_delta_q, 0);
140 EXPECT_EQ(common->uv_dc_delta_q, 0);
141 EXPECT_EQ(common->uv_ac_delta_q, 0);
142 EXPECT_EQ(common->tx_mode, ONLY_4X4);
144 EXPECT_EQ(common->error_resilient_mode, encode_parms.error_resilient);
145 if (encode_parms.error_resilient) {
146 EXPECT_EQ(common->frame_parallel_decoding_mode, 1);
147 EXPECT_EQ(common->use_prev_frame_mvs, 0);
149 EXPECT_EQ(common->frame_parallel_decoding_mode,
150 encode_parms.frame_parallel);
152 EXPECT_EQ(common->color_space, encode_parms.cs);
153 EXPECT_EQ(common->log2_tile_cols, encode_parms.tile_cols);
154 EXPECT_EQ(common->log2_tile_rows, encode_parms.tile_rows);
156 EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
157 return VPX_CODEC_OK == res_dec;
160 EncodePerfTestVideo test_video_;
163 EncodeParameters encode_parms;
166 // TODO(hkuang): This test conflicts with frame parallel decode. So disable it
167 // for now until fix.
168 TEST_P(Vp9EncoderParmsGetToDecoder, DISABLED_BitstreamParms) {
169 init_flags_ = VPX_CODEC_USE_PSNR;
171 libvpx_test::VideoSource *video;
172 if (is_extension_y4m(test_video_.name)) {
173 video = new libvpx_test::Y4mVideoSource(test_video_.name,
174 0, test_video_.frames);
176 video = new libvpx_test::YUVVideoSource(test_video_.name,
184 ASSERT_NO_FATAL_FAILURE(RunLoop(video));
188 VP9_INSTANTIATE_TEST_CASE(
189 Vp9EncoderParmsGetToDecoder,
190 ::testing::ValuesIn(kVP9EncodeParameterSet),
191 ::testing::ValuesIn(kVP9EncodePerfTestVectors));