• 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 VPX_TEST_CODEC_FACTORY_H_
11 #define VPX_TEST_CODEC_FACTORY_H_
12 
13 #include <tuple>
14 
15 #include "./vpx_config.h"
16 #include "vpx/vpx_decoder.h"
17 #include "vpx/vpx_encoder.h"
18 #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER
19 #include "vpx/vp8cx.h"
20 #endif
21 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
22 #include "vpx/vp8dx.h"
23 #endif
24 
25 #include "test/decode_test_driver.h"
26 #include "test/encode_test_driver.h"
27 namespace libvpx_test {
28 
29 const int kCodecFactoryParam = 0;
30 
31 class CodecFactory {
32  public:
CodecFactory()33   CodecFactory() {}
34 
~CodecFactory()35   virtual ~CodecFactory() {}
36 
37   virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const = 0;
38 
39   virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
40                                  const vpx_codec_flags_t flags) const = 0;
41 
42   virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg,
43                                  unsigned long deadline,
44                                  const unsigned long init_flags,
45                                  TwopassStatsStore *stats) const = 0;
46 
47   virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
48                                                int usage) const = 0;
49 };
50 
51 /* Provide CodecTestWith<n>Params classes for a variable number of parameters
52  * to avoid having to include a pointer to the CodecFactory in every test
53  * definition.
54  */
55 template <class T1>
56 class CodecTestWithParam
57     : public ::testing::TestWithParam<
58           std::tuple<const libvpx_test::CodecFactory *, T1> > {};
59 
60 template <class T1, class T2>
61 class CodecTestWith2Params
62     : public ::testing::TestWithParam<
63           std::tuple<const libvpx_test::CodecFactory *, T1, T2> > {};
64 
65 template <class T1, class T2, class T3>
66 class CodecTestWith3Params
67     : public ::testing::TestWithParam<
68           std::tuple<const libvpx_test::CodecFactory *, T1, T2, T3> > {};
69 
70 template <class T1, class T2, class T3, class T4>
71 class CodecTestWith4Params
72     : public ::testing::TestWithParam<
73           std::tuple<const libvpx_test::CodecFactory *, T1, T2, T3, T4> > {};
74 
75 /*
76  * VP8 Codec Definitions
77  */
78 #if CONFIG_VP8
79 class VP8Decoder : public Decoder {
80  public:
VP8Decoder(vpx_codec_dec_cfg_t cfg)81   explicit VP8Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {}
82 
VP8Decoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flag)83   VP8Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag)
84       : Decoder(cfg, flag) {}
85 
86  protected:
CodecInterface()87   vpx_codec_iface_t *CodecInterface() const override {
88 #if CONFIG_VP8_DECODER
89     return &vpx_codec_vp8_dx_algo;
90 #else
91     return nullptr;
92 #endif
93   }
94 };
95 
96 class VP8Encoder : public Encoder {
97  public:
VP8Encoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)98   VP8Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
99              const unsigned long init_flags, TwopassStatsStore *stats)
100       : Encoder(cfg, deadline, init_flags, stats) {}
101 
102  protected:
CodecInterface()103   vpx_codec_iface_t *CodecInterface() const override {
104 #if CONFIG_VP8_ENCODER
105     return &vpx_codec_vp8_cx_algo;
106 #else
107     return nullptr;
108 #endif
109   }
110 };
111 
112 class VP8CodecFactory : public CodecFactory {
113  public:
VP8CodecFactory()114   VP8CodecFactory() : CodecFactory() {}
115 
CreateDecoder(vpx_codec_dec_cfg_t cfg)116   Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const override {
117     return CreateDecoder(cfg, 0);
118   }
119 
CreateDecoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flags)120   Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
121                          const vpx_codec_flags_t flags) const override {
122 #if CONFIG_VP8_DECODER
123     return new VP8Decoder(cfg, flags);
124 #else
125     (void)cfg;
126     (void)flags;
127     return nullptr;
128 #endif
129   }
130 
CreateEncoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)131   Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
132                          const unsigned long init_flags,
133                          TwopassStatsStore *stats) const override {
134 #if CONFIG_VP8_ENCODER
135     return new VP8Encoder(cfg, deadline, init_flags, stats);
136 #else
137     (void)cfg;
138     (void)deadline;
139     (void)init_flags;
140     (void)stats;
141     return nullptr;
142 #endif
143   }
144 
DefaultEncoderConfig(vpx_codec_enc_cfg_t * cfg,int usage)145   vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
146                                        int usage) const override {
147 #if CONFIG_VP8_ENCODER
148     return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage);
149 #else
150     (void)cfg;
151     (void)usage;
152     return VPX_CODEC_INCAPABLE;
153 #endif
154   }
155 };
156 
157 const libvpx_test::VP8CodecFactory kVP8;
158 
159 #define VP8_INSTANTIATE_TEST_SUITE(test, ...)                               \
160   INSTANTIATE_TEST_SUITE_P(                                                 \
161       VP8, test,                                                            \
162       ::testing::Combine(                                                   \
163           ::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \
164               &libvpx_test::kVP8)),                                         \
165           __VA_ARGS__))
166 #else
167 #define VP8_INSTANTIATE_TEST_SUITE(test, ...)
168 #endif  // CONFIG_VP8
169 
170 /*
171  * VP9 Codec Definitions
172  */
173 #if CONFIG_VP9
174 class VP9Decoder : public Decoder {
175  public:
VP9Decoder(vpx_codec_dec_cfg_t cfg)176   explicit VP9Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {}
177 
VP9Decoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flag)178   VP9Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag)
179       : Decoder(cfg, flag) {}
180 
181  protected:
CodecInterface()182   vpx_codec_iface_t *CodecInterface() const override {
183 #if CONFIG_VP9_DECODER
184     return &vpx_codec_vp9_dx_algo;
185 #else
186     return nullptr;
187 #endif
188   }
189 };
190 
191 class VP9Encoder : public Encoder {
192  public:
VP9Encoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)193   VP9Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
194              const unsigned long init_flags, TwopassStatsStore *stats)
195       : Encoder(cfg, deadline, init_flags, stats) {}
196 
197  protected:
CodecInterface()198   vpx_codec_iface_t *CodecInterface() const override {
199 #if CONFIG_VP9_ENCODER
200     return &vpx_codec_vp9_cx_algo;
201 #else
202     return nullptr;
203 #endif
204   }
205 };
206 
207 class VP9CodecFactory : public CodecFactory {
208  public:
VP9CodecFactory()209   VP9CodecFactory() : CodecFactory() {}
210 
CreateDecoder(vpx_codec_dec_cfg_t cfg)211   Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const override {
212     return CreateDecoder(cfg, 0);
213   }
214 
CreateDecoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flags)215   Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
216                          const vpx_codec_flags_t flags) const override {
217 #if CONFIG_VP9_DECODER
218     return new VP9Decoder(cfg, flags);
219 #else
220     (void)cfg;
221     (void)flags;
222     return nullptr;
223 #endif
224   }
225 
CreateEncoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)226   Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
227                          const unsigned long init_flags,
228                          TwopassStatsStore *stats) const override {
229 #if CONFIG_VP9_ENCODER
230     return new VP9Encoder(cfg, deadline, init_flags, stats);
231 #else
232     (void)cfg;
233     (void)deadline;
234     (void)init_flags;
235     (void)stats;
236     return nullptr;
237 #endif
238   }
239 
DefaultEncoderConfig(vpx_codec_enc_cfg_t * cfg,int usage)240   vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
241                                        int usage) const override {
242 #if CONFIG_VP9_ENCODER
243     return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage);
244 #else
245     (void)cfg;
246     (void)usage;
247     return VPX_CODEC_INCAPABLE;
248 #endif
249   }
250 };
251 
252 const libvpx_test::VP9CodecFactory kVP9;
253 
254 #define VP9_INSTANTIATE_TEST_SUITE(test, ...)                               \
255   INSTANTIATE_TEST_SUITE_P(                                                 \
256       VP9, test,                                                            \
257       ::testing::Combine(                                                   \
258           ::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \
259               &libvpx_test::kVP9)),                                         \
260           __VA_ARGS__))
261 #else
262 #define VP9_INSTANTIATE_TEST_SUITE(test, ...)
263 #endif  // CONFIG_VP9
264 
265 }  // namespace libvpx_test
266 #endif  // VPX_TEST_CODEC_FACTORY_H_
267