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 "test/yuv_video_source.h"
18 #include "vp9/decoder/vp9_decoder.h"
20 typedef vpx_codec_stream_info_t vp9_stream_info_t;
21 struct vpx_codec_alg_priv {
22 vpx_codec_priv_t base;
23 vpx_codec_dec_cfg_t cfg;
25 struct VP9Decoder *pbi;
27 vp8_postproc_cfg_t postproc_cfg;
28 vpx_decrypt_cb decrypt_cb;
33 int invert_tile_order;
34 int frame_parallel_decode;
36 // External frame buffer info to save for VP9 common.
37 void *ext_priv; // Private data associated with the external frame buffers.
38 vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb;
39 vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb;
42 static vpx_codec_alg_priv_t *get_alg_priv(vpx_codec_ctx_t *ctx) {
43 return (vpx_codec_alg_priv_t *)ctx->priv;
48 const unsigned int kFramerate = 50;
49 const int kCpuUsed = 2;
51 struct EncodePerfTestVideo {
59 const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
60 {"niklas_1280_720_30.y4m", 1280, 720, 600, 10},
63 struct EncodeParameters {
67 int32_t error_resilient;
68 int32_t frame_parallel;
70 // TODO(JBB): quantizers / bitrate
73 const EncodeParameters kVP9EncodeParameterSet[] = {
74 {0, 0, 0, 1, 0, VPX_CS_BT_601},
75 {0, 0, 0, 0, 0, VPX_CS_BT_709},
76 {0, 0, 1, 0, 0, VPX_CS_BT_2020},
77 {0, 2, 0, 0, 1, VPX_CS_UNKNOWN},
78 // TODO(JBB): Test profiles (requires more work).
81 int is_extension_y4m(const char *filename) {
82 const char *dot = strrchr(filename, '.');
83 if (!dot || dot == filename)
86 return !strcmp(dot, ".y4m");
89 class Vp9EncoderParmsGetToDecoder
90 : public ::libvpx_test::EncoderTest,
91 public ::libvpx_test::CodecTestWith2Params<EncodeParameters, \
92 EncodePerfTestVideo> {
94 Vp9EncoderParmsGetToDecoder()
95 : EncoderTest(GET_PARAM(0)),
96 encode_parms(GET_PARAM(1)) {
99 virtual ~Vp9EncoderParmsGetToDecoder() {}
101 virtual void SetUp() {
103 SetMode(::libvpx_test::kTwoPassGood);
104 cfg_.g_lag_in_frames = 25;
105 cfg_.g_error_resilient = encode_parms.error_resilient;
106 dec_cfg_.threads = 4;
107 test_video_ = GET_PARAM(2);
108 cfg_.rc_target_bitrate = test_video_.bitrate;
111 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
112 ::libvpx_test::Encoder *encoder) {
113 if (video->frame() == 1) {
114 encoder->Control(VP9E_SET_COLOR_SPACE, encode_parms.cs);
115 encoder->Control(VP9E_SET_LOSSLESS, encode_parms.lossless);
116 encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING,
117 encode_parms.frame_parallel);
118 encoder->Control(VP9E_SET_TILE_ROWS, encode_parms.tile_rows);
119 encoder->Control(VP9E_SET_TILE_COLUMNS, encode_parms.tile_cols);
120 encoder->Control(VP8E_SET_CPUUSED, kCpuUsed);
121 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
122 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
123 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
124 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
128 virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
129 const libvpx_test::VideoSource& video,
130 libvpx_test::Decoder *decoder) {
131 vpx_codec_ctx_t* vp9_decoder = decoder->GetDecoder();
132 vpx_codec_alg_priv_t* priv =
133 (vpx_codec_alg_priv_t*) get_alg_priv(vp9_decoder);
135 VP9Decoder* pbi = priv->pbi;
136 VP9_COMMON* common = &pbi->common;
138 if (encode_parms.lossless) {
139 EXPECT_EQ(common->base_qindex, 0);
140 EXPECT_EQ(common->y_dc_delta_q, 0);
141 EXPECT_EQ(common->uv_dc_delta_q, 0);
142 EXPECT_EQ(common->uv_ac_delta_q, 0);
143 EXPECT_EQ(common->tx_mode, ONLY_4X4);
145 EXPECT_EQ(common->error_resilient_mode, encode_parms.error_resilient);
146 if (encode_parms.error_resilient) {
147 EXPECT_EQ(common->frame_parallel_decoding_mode, 1);
148 EXPECT_EQ(common->use_prev_frame_mvs, 0);
150 EXPECT_EQ(common->frame_parallel_decoding_mode,
151 encode_parms.frame_parallel);
153 EXPECT_EQ(common->color_space, encode_parms.cs);
154 EXPECT_EQ(common->log2_tile_cols, encode_parms.tile_cols);
155 EXPECT_EQ(common->log2_tile_rows, encode_parms.tile_rows);
157 EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
158 return VPX_CODEC_OK == res_dec;
161 EncodePerfTestVideo test_video_;
164 EncodeParameters encode_parms;
167 // TODO(hkuang): This test conflicts with frame parallel decode. So disable it
168 // for now until fix.
169 TEST_P(Vp9EncoderParmsGetToDecoder, DISABLED_BitstreamParms) {
170 init_flags_ = VPX_CODEC_USE_PSNR;
172 libvpx_test::VideoSource *video;
173 if (is_extension_y4m(test_video_.name)) {
174 video = new libvpx_test::Y4mVideoSource(test_video_.name,
175 0, test_video_.frames);
177 video = new libvpx_test::YUVVideoSource(test_video_.name,
185 ASSERT_NO_FATAL_FAILURE(RunLoop(video));
189 VP9_INSTANTIATE_TEST_CASE(
190 Vp9EncoderParmsGetToDecoder,
191 ::testing::ValuesIn(kVP9EncodeParameterSet),
192 ::testing::ValuesIn(kVP9EncodePerfTestVectors));