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