]> granicus.if.org Git - libvpx/blob - test/codec_factory.h
Add VP9 frame-parallel unit test.
[libvpx] / test / codec_factory.h
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
17 #include "vpx/vp8cx.h"
18 #endif
19 #if CONFIG_VP8_DECODER || CONFIG_VP9_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:
31   CodecFactory() {}
32
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) const = 0;  // NOLINT
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 : public ::testing::TestWithParam<
57     std::tr1::tuple< const libvpx_test::CodecFactory*, T1 > > {
58 };
59
60 template<class T1, class T2>
61 class CodecTestWith2Params : public ::testing::TestWithParam<
62     std::tr1::tuple< const libvpx_test::CodecFactory*, T1, T2 > > {
63 };
64
65 template<class T1, class T2, class T3>
66 class CodecTestWith3Params : public ::testing::TestWithParam<
67     std::tr1::tuple< const libvpx_test::CodecFactory*, T1, T2, T3 > > {
68 };
69
70 /*
71  * VP8 Codec Definitions
72  */
73 #if CONFIG_VP8
74 class VP8Decoder : public Decoder {
75  public:
76   VP8Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
77       : Decoder(cfg, deadline) {}
78
79   VP8Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag,
80              unsigned long deadline)  // NOLINT
81       : Decoder(cfg, flag, deadline) {}
82
83  protected:
84   virtual vpx_codec_iface_t* CodecInterface() const {
85 #if CONFIG_VP8_DECODER
86     return &vpx_codec_vp8_dx_algo;
87 #else
88     return NULL;
89 #endif
90   }
91 };
92
93 class VP8Encoder : public Encoder {
94  public:
95   VP8Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
96              const unsigned long init_flags, TwopassStatsStore *stats)
97       : Encoder(cfg, deadline, init_flags, stats) {}
98
99  protected:
100   virtual vpx_codec_iface_t* CodecInterface() const {
101 #if CONFIG_VP8_ENCODER
102     return &vpx_codec_vp8_cx_algo;
103 #else
104     return NULL;
105 #endif
106   }
107 };
108
109 class VP8CodecFactory : public CodecFactory {
110  public:
111   VP8CodecFactory() : CodecFactory() {}
112
113   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
114                                  unsigned long deadline) const {
115     return CreateDecoder(cfg, 0, deadline);
116   }
117
118   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
119                                  const vpx_codec_flags_t flags,
120                                  unsigned long deadline) const {  // NOLINT
121 #if CONFIG_VP8_DECODER
122     return new VP8Decoder(cfg, flags, deadline);
123 #else
124     return NULL;
125 #endif
126   }
127
128   virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
129                                  unsigned long deadline,
130                                  const unsigned long init_flags,
131                                  TwopassStatsStore *stats) const {
132 #if CONFIG_VP8_ENCODER
133     return new VP8Encoder(cfg, deadline, init_flags, stats);
134 #else
135     return NULL;
136 #endif
137   }
138
139   virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
140                                                int usage) const {
141 #if CONFIG_VP8_ENCODER
142     return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage);
143 #else
144     return VPX_CODEC_INCAPABLE;
145 #endif
146   }
147 };
148
149 const libvpx_test::VP8CodecFactory kVP8;
150
151 #define VP8_INSTANTIATE_TEST_CASE(test, ...)\
152   INSTANTIATE_TEST_CASE_P(VP8, test, \
153       ::testing::Combine( \
154           ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
155               &libvpx_test::kVP8)), \
156           __VA_ARGS__))
157 #else
158 #define VP8_INSTANTIATE_TEST_CASE(test, ...)
159 #endif  // CONFIG_VP8
160
161
162 /*
163  * VP9 Codec Definitions
164  */
165 #if CONFIG_VP9
166 class VP9Decoder : public Decoder {
167  public:
168   VP9Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
169       : Decoder(cfg, deadline) {}
170
171   VP9Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag,
172              unsigned long deadline)  // NOLINT
173       : Decoder(cfg, flag, deadline) {}
174
175  protected:
176   virtual vpx_codec_iface_t* CodecInterface() const {
177 #if CONFIG_VP9_DECODER
178     return &vpx_codec_vp9_dx_algo;
179 #else
180     return NULL;
181 #endif
182   }
183 };
184
185 class VP9Encoder : public Encoder {
186  public:
187   VP9Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
188              const unsigned long init_flags, TwopassStatsStore *stats)
189       : Encoder(cfg, deadline, init_flags, stats) {}
190
191  protected:
192   virtual vpx_codec_iface_t* CodecInterface() const {
193 #if CONFIG_VP9_ENCODER
194     return &vpx_codec_vp9_cx_algo;
195 #else
196     return NULL;
197 #endif
198   }
199 };
200
201 class VP9CodecFactory : public CodecFactory {
202  public:
203   VP9CodecFactory() : CodecFactory() {}
204
205   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
206                                  unsigned long deadline) const {
207     return CreateDecoder(cfg, 0, deadline);
208   }
209
210   virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
211                                  const vpx_codec_flags_t flags,
212                                  unsigned long deadline) const {  // NOLINT
213 #if CONFIG_VP9_DECODER
214     return new VP9Decoder(cfg, flags, deadline);
215 #else
216     return NULL;
217 #endif
218   }
219
220   virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
221                                  unsigned long deadline,
222                                  const unsigned long init_flags,
223                                  TwopassStatsStore *stats) const {
224 #if CONFIG_VP9_ENCODER
225     return new VP9Encoder(cfg, deadline, init_flags, stats);
226 #else
227     return NULL;
228 #endif
229   }
230
231   virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
232                                                int usage) const {
233 #if CONFIG_VP9_ENCODER
234     return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage);
235 #else
236     return VPX_CODEC_INCAPABLE;
237 #endif
238   }
239 };
240
241 const libvpx_test::VP9CodecFactory kVP9;
242
243 #define VP9_INSTANTIATE_TEST_CASE(test, ...)\
244   INSTANTIATE_TEST_CASE_P(VP9, test, \
245       ::testing::Combine( \
246           ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
247                &libvpx_test::kVP9)), \
248           __VA_ARGS__))
249 #else
250 #define VP9_INSTANTIATE_TEST_CASE(test, ...)
251 #endif  // CONFIG_VP9
252
253
254 }  // namespace libvpx_test
255
256 #endif  // TEST_CODEC_FACTORY_H_