xref: /aosp_15_r20/external/libvpx/test/codec_factory.h (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
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                                  vpx_enc_deadline_t 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,vpx_enc_deadline_t deadline,const unsigned long init_flags,TwopassStatsStore * stats)98   VP8Encoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t 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,vpx_enc_deadline_t deadline,const unsigned long init_flags,TwopassStatsStore * stats)131   Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t 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 // static_assert() is used to avoid warnings about an extra ';' outside of a
168 // function.
169 #define VP8_INSTANTIATE_TEST_SUITE(test, ...) static_assert(CONFIG_VP8 == 0, "")
170 #endif  // CONFIG_VP8
171 
172 /*
173  * VP9 Codec Definitions
174  */
175 #if CONFIG_VP9
176 class VP9Decoder : public Decoder {
177  public:
VP9Decoder(vpx_codec_dec_cfg_t cfg)178   explicit VP9Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {}
179 
VP9Decoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flag)180   VP9Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag)
181       : Decoder(cfg, flag) {}
182 
183  protected:
CodecInterface()184   vpx_codec_iface_t *CodecInterface() const override {
185 #if CONFIG_VP9_DECODER
186     return &vpx_codec_vp9_dx_algo;
187 #else
188     return nullptr;
189 #endif
190   }
191 };
192 
193 class VP9Encoder : public Encoder {
194  public:
VP9Encoder(vpx_codec_enc_cfg_t cfg,vpx_enc_deadline_t deadline,const unsigned long init_flags,TwopassStatsStore * stats)195   VP9Encoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline,
196              const unsigned long init_flags, TwopassStatsStore *stats)
197       : Encoder(cfg, deadline, init_flags, stats) {}
198 
199  protected:
CodecInterface()200   vpx_codec_iface_t *CodecInterface() const override {
201 #if CONFIG_VP9_ENCODER
202     return &vpx_codec_vp9_cx_algo;
203 #else
204     return nullptr;
205 #endif
206   }
207 };
208 
209 class VP9CodecFactory : public CodecFactory {
210  public:
VP9CodecFactory()211   VP9CodecFactory() : CodecFactory() {}
212 
CreateDecoder(vpx_codec_dec_cfg_t cfg)213   Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const override {
214     return CreateDecoder(cfg, 0);
215   }
216 
CreateDecoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flags)217   Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
218                          const vpx_codec_flags_t flags) const override {
219 #if CONFIG_VP9_DECODER
220     return new VP9Decoder(cfg, flags);
221 #else
222     (void)cfg;
223     (void)flags;
224     return nullptr;
225 #endif
226   }
227 
CreateEncoder(vpx_codec_enc_cfg_t cfg,vpx_enc_deadline_t deadline,const unsigned long init_flags,TwopassStatsStore * stats)228   Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline,
229                          const unsigned long init_flags,
230                          TwopassStatsStore *stats) const override {
231 #if CONFIG_VP9_ENCODER
232     return new VP9Encoder(cfg, deadline, init_flags, stats);
233 #else
234     (void)cfg;
235     (void)deadline;
236     (void)init_flags;
237     (void)stats;
238     return nullptr;
239 #endif
240   }
241 
DefaultEncoderConfig(vpx_codec_enc_cfg_t * cfg,int usage)242   vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
243                                        int usage) const override {
244 #if CONFIG_VP9_ENCODER
245     return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage);
246 #else
247     (void)cfg;
248     (void)usage;
249     return VPX_CODEC_INCAPABLE;
250 #endif
251   }
252 };
253 
254 const libvpx_test::VP9CodecFactory kVP9;
255 
256 #define VP9_INSTANTIATE_TEST_SUITE(test, ...)                               \
257   INSTANTIATE_TEST_SUITE_P(                                                 \
258       VP9, test,                                                            \
259       ::testing::Combine(                                                   \
260           ::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \
261               &libvpx_test::kVP9)),                                         \
262           __VA_ARGS__))
263 #else
264 // static_assert() is used to avoid warnings about an extra ';' outside of a
265 // function.
266 #define VP9_INSTANTIATE_TEST_SUITE(test, ...) static_assert(CONFIG_VP9 == 0, "")
267 #endif  // CONFIG_VP9
268 
269 }  // namespace libvpx_test
270 #endif  // VPX_TEST_CODEC_FACTORY_H_
271