]> granicus.if.org Git - libvpx/blob - test/vp9_encoder_parms_get_to_decoder.cc
Merge "endian_inl.h: fix mips32 android build"
[libvpx] / test / vp9_encoder_parms_get_to_decoder.cc
1 /*
2  *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3  *
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.
9  */
10
11 #include "third_party/googletest/src/include/gtest/gtest.h"
12
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"
19
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;
24   vp9_stream_info_t       si;
25   struct VP9Decoder      *pbi;
26   int                     postproc_cfg_set;
27   vp8_postproc_cfg_t      postproc_cfg;
28   vpx_decrypt_cb          decrypt_cb;
29   void                   *decrypt_state;
30   vpx_image_t             img;
31   int                     img_avail;
32   int                     flushed;
33   int                     invert_tile_order;
34   int                     frame_parallel_decode;
35
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;
40 };
41
42 static vpx_codec_alg_priv_t *get_alg_priv(vpx_codec_ctx_t *ctx) {
43   return (vpx_codec_alg_priv_t *)ctx->priv;
44 }
45
46 namespace {
47
48 const unsigned int kFramerate = 50;
49 const int kCpuUsed = 2;
50
51 struct EncodePerfTestVideo {
52   const char *name;
53   uint32_t width;
54   uint32_t height;
55   uint32_t bitrate;
56   int frames;
57 };
58
59 const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
60   {"niklas_1280_720_30.y4m", 1280, 720, 600, 10},
61 };
62
63 struct EncodeParameters {
64   int32_t tile_rows;
65   int32_t tile_cols;
66   int32_t lossless;
67   int32_t error_resilient;
68   int32_t frame_parallel;
69   vpx_color_space_t cs;
70   // TODO(JBB): quantizers / bitrate
71 };
72
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).
79 };
80
81 int is_extension_y4m(const char *filename) {
82   const char *dot = strrchr(filename, '.');
83   if (!dot || dot == filename)
84     return 0;
85   else
86     return !strcmp(dot, ".y4m");
87 }
88
89 class Vp9EncoderParmsGetToDecoder
90     : public ::libvpx_test::EncoderTest,
91       public ::libvpx_test::CodecTestWith2Params<EncodeParameters, \
92                                                  EncodePerfTestVideo> {
93  protected:
94   Vp9EncoderParmsGetToDecoder()
95       : EncoderTest(GET_PARAM(0)),
96         encode_parms(GET_PARAM(1)) {
97   }
98
99   virtual ~Vp9EncoderParmsGetToDecoder() {}
100
101   virtual void SetUp() {
102     InitializeConfig();
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;
109   }
110
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);
125     }
126   }
127
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);
134
135     VP9Decoder* pbi = priv->pbi;
136     VP9_COMMON* common = &pbi->common;
137
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);
144     }
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);
149     } else {
150       EXPECT_EQ(common->frame_parallel_decoding_mode,
151                 encode_parms.frame_parallel);
152     }
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);
156
157     EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
158     return VPX_CODEC_OK == res_dec;
159   }
160
161   EncodePerfTestVideo test_video_;
162
163  private:
164   EncodeParameters encode_parms;
165 };
166
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;
171
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);
176   } else {
177     video = new libvpx_test::YUVVideoSource(test_video_.name,
178                                             VPX_IMG_FMT_I420,
179                                             test_video_.width,
180                                             test_video_.height,
181                                             kFramerate, 1, 0,
182                                             test_video_.frames);
183   }
184
185   ASSERT_NO_FATAL_FAILURE(RunLoop(video));
186   delete(video);
187 }
188
189 VP9_INSTANTIATE_TEST_CASE(
190     Vp9EncoderParmsGetToDecoder,
191     ::testing::ValuesIn(kVP9EncodeParameterSet),
192     ::testing::ValuesIn(kVP9EncodePerfTestVectors));
193
194 }  // namespace