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