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