• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2013 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 #ifndef TEST_CODEC_FACTORY_H_
11 #define TEST_CODEC_FACTORY_H_
12 
13 #include "./vpx_config.h"
14 #include "vpx/vpx_decoder.h"
15 #include "vpx/vpx_encoder.h"
16 #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
17 #include "vpx/vp8cx.h"
18 #endif
19 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_DECODER
20 #include "vpx/vp8dx.h"
21 #endif
22 
23 #include "test/decode_test_driver.h"
24 #include "test/encode_test_driver.h"
25 namespace libvpx_test {
26 
27 const int kCodecFactoryParam = 0;
28 
29 class CodecFactory {
30  public:
CodecFactory()31   CodecFactory() {}
32 
~CodecFactory()33   virtual ~CodecFactory() {}
34 
35   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
36                                  unsigned long deadline) const = 0;
37 
38   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
39                                  const vpx_codec_flags_t flags,
40                                  unsigned long deadline)  // NOLINT(runtime/int)
41                                  const = 0;
42 
43   virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
44                                  unsigned long deadline,
45                                  const unsigned long init_flags,
46                                  TwopassStatsStore *stats) const = 0;
47 
48   virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
49                                                int usage) const = 0;
50 };
51 
52 /* Provide CodecTestWith<n>Params classes for a variable number of parameters
53  * to avoid having to include a pointer to the CodecFactory in every test
54  * definition.
55  */
56 template<class T1>
57 class CodecTestWithParam : public ::testing::TestWithParam<
58     std::tr1::tuple< const libvpx_test::CodecFactory*, T1 > > {
59 };
60 
61 template<class T1, class T2>
62 class CodecTestWith2Params : public ::testing::TestWithParam<
63     std::tr1::tuple< const libvpx_test::CodecFactory*, T1, T2 > > {
64 };
65 
66 template<class T1, class T2, class T3>
67 class CodecTestWith3Params : public ::testing::TestWithParam<
68     std::tr1::tuple< const libvpx_test::CodecFactory*, T1, T2, T3 > > {
69 };
70 
71 /*
72  * VP8 Codec Definitions
73  */
74 #if CONFIG_VP8
75 class VP8Decoder : public Decoder {
76  public:
VP8Decoder(vpx_codec_dec_cfg_t cfg,unsigned long deadline)77   VP8Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
78       : Decoder(cfg, deadline) {}
79 
VP8Decoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flag,unsigned long deadline)80   VP8Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag,
81              unsigned long deadline)  // NOLINT
82       : Decoder(cfg, flag, deadline) {}
83 
84  protected:
CodecInterface()85   virtual vpx_codec_iface_t* CodecInterface() const {
86 #if CONFIG_VP8_DECODER
87     return &vpx_codec_vp8_dx_algo;
88 #else
89     return NULL;
90 #endif
91   }
92 };
93 
94 class VP8Encoder : public Encoder {
95  public:
VP8Encoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)96   VP8Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
97              const unsigned long init_flags, TwopassStatsStore *stats)
98       : Encoder(cfg, deadline, init_flags, stats) {}
99 
100  protected:
CodecInterface()101   virtual vpx_codec_iface_t* CodecInterface() const {
102 #if CONFIG_VP8_ENCODER
103     return &vpx_codec_vp8_cx_algo;
104 #else
105     return NULL;
106 #endif
107   }
108 };
109 
110 class VP8CodecFactory : public CodecFactory {
111  public:
VP8CodecFactory()112   VP8CodecFactory() : CodecFactory() {}
113 
CreateDecoder(vpx_codec_dec_cfg_t cfg,unsigned long deadline)114   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
115                                  unsigned long deadline) const {
116     return CreateDecoder(cfg, 0, deadline);
117   }
118 
CreateDecoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flags,unsigned long deadline)119   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
120                                  const vpx_codec_flags_t flags,
121                                  unsigned long deadline) const {  // NOLINT
122 #if CONFIG_VP8_DECODER
123     return new VP8Decoder(cfg, flags, deadline);
124 #else
125     return NULL;
126 #endif
127   }
128 
CreateEncoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)129   virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
130                                  unsigned long deadline,
131                                  const unsigned long init_flags,
132                                  TwopassStatsStore *stats) const {
133 #if CONFIG_VP8_ENCODER
134     return new VP8Encoder(cfg, deadline, init_flags, stats);
135 #else
136     return NULL;
137 #endif
138   }
139 
DefaultEncoderConfig(vpx_codec_enc_cfg_t * cfg,int usage)140   virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
141                                                int usage) const {
142 #if CONFIG_VP8_ENCODER
143     return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage);
144 #else
145     return VPX_CODEC_INCAPABLE;
146 #endif
147   }
148 };
149 
150 const libvpx_test::VP8CodecFactory kVP8;
151 
152 #define VP8_INSTANTIATE_TEST_CASE(test, ...)\
153   INSTANTIATE_TEST_CASE_P(VP8, test, \
154       ::testing::Combine( \
155           ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
156               &libvpx_test::kVP8)), \
157           __VA_ARGS__))
158 #else
159 #define VP8_INSTANTIATE_TEST_CASE(test, ...)
160 #endif  // CONFIG_VP8
161 
162 
163 /*
164  * VP9 Codec Definitions
165  */
166 #if CONFIG_VP9
167 class VP9Decoder : public Decoder {
168  public:
VP9Decoder(vpx_codec_dec_cfg_t cfg,unsigned long deadline)169   VP9Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
170       : Decoder(cfg, deadline) {}
171 
VP9Decoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flag,unsigned long deadline)172   VP9Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag,
173              unsigned long deadline)  // NOLINT
174       : Decoder(cfg, flag, deadline) {}
175 
176  protected:
CodecInterface()177   virtual vpx_codec_iface_t* CodecInterface() const {
178 #if CONFIG_VP9_DECODER
179     return &vpx_codec_vp9_dx_algo;
180 #else
181     return NULL;
182 #endif
183   }
184 };
185 
186 class VP9Encoder : public Encoder {
187  public:
VP9Encoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)188   VP9Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
189              const unsigned long init_flags, TwopassStatsStore *stats)
190       : Encoder(cfg, deadline, init_flags, stats) {}
191 
192  protected:
CodecInterface()193   virtual vpx_codec_iface_t* CodecInterface() const {
194 #if CONFIG_VP9_ENCODER
195     return &vpx_codec_vp9_cx_algo;
196 #else
197     return NULL;
198 #endif
199   }
200 };
201 
202 class VP9CodecFactory : public CodecFactory {
203  public:
VP9CodecFactory()204   VP9CodecFactory() : CodecFactory() {}
205 
CreateDecoder(vpx_codec_dec_cfg_t cfg,unsigned long deadline)206   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
207                                  unsigned long deadline) const {
208     return CreateDecoder(cfg, 0, deadline);
209   }
210 
CreateDecoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flags,unsigned long deadline)211   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
212                                  const vpx_codec_flags_t flags,
213                                  unsigned long deadline) const {  // NOLINT
214 #if CONFIG_VP9_DECODER
215     return new VP9Decoder(cfg, flags, deadline);
216 #else
217     return NULL;
218 #endif
219   }
220 
CreateEncoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)221   virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
222                                  unsigned long deadline,
223                                  const unsigned long init_flags,
224                                  TwopassStatsStore *stats) const {
225 #if CONFIG_VP9_ENCODER
226     return new VP9Encoder(cfg, deadline, init_flags, stats);
227 #else
228     return NULL;
229 #endif
230   }
231 
DefaultEncoderConfig(vpx_codec_enc_cfg_t * cfg,int usage)232   virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
233                                                int usage) const {
234 #if CONFIG_VP9_ENCODER
235     return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage);
236 #elif CONFIG_VP10_ENCODER
237     return vpx_codec_enc_config_default(&vpx_codec_vp10_cx_algo, cfg, usage);
238 #else
239     return VPX_CODEC_INCAPABLE;
240 #endif
241   }
242 };
243 
244 const libvpx_test::VP9CodecFactory kVP9;
245 
246 #define VP9_INSTANTIATE_TEST_CASE(test, ...)\
247   INSTANTIATE_TEST_CASE_P(VP9, test, \
248       ::testing::Combine( \
249           ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
250                &libvpx_test::kVP9)), \
251           __VA_ARGS__))
252 #else
253 #define VP9_INSTANTIATE_TEST_CASE(test, ...)
254 #endif  // CONFIG_VP9
255 
256 /*
257  * VP10 Codec Definitions
258  */
259 #if CONFIG_VP10
260 class VP10Decoder : public Decoder {
261  public:
VP10Decoder(vpx_codec_dec_cfg_t cfg,unsigned long deadline)262   VP10Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
263       : Decoder(cfg, deadline) {}
264 
VP10Decoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flag,unsigned long deadline)265   VP10Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag,
266               unsigned long deadline)  // NOLINT
267       : Decoder(cfg, flag, deadline) {}
268 
269  protected:
CodecInterface()270   virtual vpx_codec_iface_t* CodecInterface() const {
271 #if CONFIG_VP10_DECODER
272     return &vpx_codec_vp10_dx_algo;
273 #else
274     return NULL;
275 #endif
276   }
277 };
278 
279 class VP10Encoder : public Encoder {
280  public:
VP10Encoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)281   VP10Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
282               const unsigned long init_flags, TwopassStatsStore *stats)
283       : Encoder(cfg, deadline, init_flags, stats) {}
284 
285  protected:
CodecInterface()286   virtual vpx_codec_iface_t* CodecInterface() const {
287 #if CONFIG_VP10_ENCODER
288     return &vpx_codec_vp10_cx_algo;
289 #else
290     return NULL;
291 #endif
292   }
293 };
294 
295 class VP10CodecFactory : public CodecFactory {
296  public:
VP10CodecFactory()297   VP10CodecFactory() : CodecFactory() {}
298 
CreateDecoder(vpx_codec_dec_cfg_t cfg,unsigned long deadline)299   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
300                                  unsigned long deadline) const {
301     return CreateDecoder(cfg, 0, deadline);
302   }
303 
CreateDecoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flags,unsigned long deadline)304   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
305                                  const vpx_codec_flags_t flags,
306                                  unsigned long deadline) const {  // NOLINT
307 #if CONFIG_VP10_DECODER
308     return new VP10Decoder(cfg, flags, deadline);
309 #else
310     return NULL;
311 #endif
312   }
313 
CreateEncoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)314   virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
315                                  unsigned long deadline,
316                                  const unsigned long init_flags,
317                                  TwopassStatsStore *stats) const {
318 #if CONFIG_VP10_ENCODER
319     return new VP10Encoder(cfg, deadline, init_flags, stats);
320 #else
321     return NULL;
322 #endif
323   }
324 
DefaultEncoderConfig(vpx_codec_enc_cfg_t * cfg,int usage)325   virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
326                                                int usage) const {
327 #if CONFIG_VP10_ENCODER
328     return vpx_codec_enc_config_default(&vpx_codec_vp10_cx_algo, cfg, usage);
329 #else
330     return VPX_CODEC_INCAPABLE;
331 #endif
332   }
333 };
334 
335 const libvpx_test::VP10CodecFactory kVP10;
336 
337 #define VP10_INSTANTIATE_TEST_CASE(test, ...)\
338   INSTANTIATE_TEST_CASE_P(VP10, test, \
339       ::testing::Combine( \
340           ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
341                &libvpx_test::kVP10)), \
342           __VA_ARGS__))
343 #else
344 #define VP10_INSTANTIATE_TEST_CASE(test, ...)
345 #endif  // CONFIG_VP10
346 
347 }  // namespace libvpx_test
348 #endif  // TEST_CODEC_FACTORY_H_
349