xref: /aosp_15_r20/external/libaom/test/codec_factory.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_TEST_CODEC_FACTORY_H_
12*77c1e3ccSAndroid Build Coastguard Worker #define AOM_TEST_CODEC_FACTORY_H_
13*77c1e3ccSAndroid Build Coastguard Worker 
14*77c1e3ccSAndroid Build Coastguard Worker #include <tuple>
15*77c1e3ccSAndroid Build Coastguard Worker 
16*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
17*77c1e3ccSAndroid Build Coastguard Worker 
18*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_decoder.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_encoder.h"
20*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_ENCODER
21*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aomcx.h"
22*77c1e3ccSAndroid Build Coastguard Worker #endif
23*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
24*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aomdx.h"
25*77c1e3ccSAndroid Build Coastguard Worker #endif
26*77c1e3ccSAndroid Build Coastguard Worker 
27*77c1e3ccSAndroid Build Coastguard Worker #include "test/decode_test_driver.h"
28*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
29*77c1e3ccSAndroid Build Coastguard Worker namespace libaom_test {
30*77c1e3ccSAndroid Build Coastguard Worker 
31*77c1e3ccSAndroid Build Coastguard Worker const int kCodecFactoryParam = 0;
32*77c1e3ccSAndroid Build Coastguard Worker 
33*77c1e3ccSAndroid Build Coastguard Worker class CodecFactory {
34*77c1e3ccSAndroid Build Coastguard Worker  public:
35*77c1e3ccSAndroid Build Coastguard Worker   CodecFactory() = default;
36*77c1e3ccSAndroid Build Coastguard Worker 
37*77c1e3ccSAndroid Build Coastguard Worker   virtual ~CodecFactory() = default;
38*77c1e3ccSAndroid Build Coastguard Worker 
39*77c1e3ccSAndroid Build Coastguard Worker   virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const = 0;
40*77c1e3ccSAndroid Build Coastguard Worker 
41*77c1e3ccSAndroid Build Coastguard Worker   virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
42*77c1e3ccSAndroid Build Coastguard Worker                                  const aom_codec_flags_t flags) const = 0;
43*77c1e3ccSAndroid Build Coastguard Worker 
44*77c1e3ccSAndroid Build Coastguard Worker   virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
45*77c1e3ccSAndroid Build Coastguard Worker                                  const aom_codec_flags_t init_flags,
46*77c1e3ccSAndroid Build Coastguard Worker                                  TwopassStatsStore *stats) const = 0;
47*77c1e3ccSAndroid Build Coastguard Worker 
48*77c1e3ccSAndroid Build Coastguard Worker   virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
49*77c1e3ccSAndroid Build Coastguard Worker                                                unsigned int usage) const = 0;
50*77c1e3ccSAndroid Build Coastguard Worker };
51*77c1e3ccSAndroid Build Coastguard Worker 
52*77c1e3ccSAndroid Build Coastguard Worker /* Provide CodecTestWith<n>Params classes for a variable number of parameters
53*77c1e3ccSAndroid Build Coastguard Worker  * to avoid having to include a pointer to the CodecFactory in every test
54*77c1e3ccSAndroid Build Coastguard Worker  * definition.
55*77c1e3ccSAndroid Build Coastguard Worker  */
56*77c1e3ccSAndroid Build Coastguard Worker template <class T1>
57*77c1e3ccSAndroid Build Coastguard Worker class CodecTestWithParam
58*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<
59*77c1e3ccSAndroid Build Coastguard Worker           std::tuple<const libaom_test::CodecFactory *, T1> > {};
60*77c1e3ccSAndroid Build Coastguard Worker 
61*77c1e3ccSAndroid Build Coastguard Worker template <class T1, class T2>
62*77c1e3ccSAndroid Build Coastguard Worker class CodecTestWith2Params
63*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<
64*77c1e3ccSAndroid Build Coastguard Worker           std::tuple<const libaom_test::CodecFactory *, T1, T2> > {};
65*77c1e3ccSAndroid Build Coastguard Worker 
66*77c1e3ccSAndroid Build Coastguard Worker template <class T1, class T2, class T3>
67*77c1e3ccSAndroid Build Coastguard Worker class CodecTestWith3Params
68*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<
69*77c1e3ccSAndroid Build Coastguard Worker           std::tuple<const libaom_test::CodecFactory *, T1, T2, T3> > {};
70*77c1e3ccSAndroid Build Coastguard Worker 
71*77c1e3ccSAndroid Build Coastguard Worker template <class T1, class T2, class T3, class T4>
72*77c1e3ccSAndroid Build Coastguard Worker class CodecTestWith4Params
73*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<
74*77c1e3ccSAndroid Build Coastguard Worker           std::tuple<const libaom_test::CodecFactory *, T1, T2, T3, T4> > {};
75*77c1e3ccSAndroid Build Coastguard Worker 
76*77c1e3ccSAndroid Build Coastguard Worker template <class T1, class T2, class T3, class T4, class T5>
77*77c1e3ccSAndroid Build Coastguard Worker class CodecTestWith5Params
78*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<
79*77c1e3ccSAndroid Build Coastguard Worker           std::tuple<const libaom_test::CodecFactory *, T1, T2, T3, T4, T5> > {
80*77c1e3ccSAndroid Build Coastguard Worker };
81*77c1e3ccSAndroid Build Coastguard Worker 
82*77c1e3ccSAndroid Build Coastguard Worker template <class T1, class T2, class T3, class T4, class T5, class T6>
83*77c1e3ccSAndroid Build Coastguard Worker class CodecTestWith6Params
84*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<std::tuple<
85*77c1e3ccSAndroid Build Coastguard Worker           const libaom_test::CodecFactory *, T1, T2, T3, T4, T5, T6> > {};
86*77c1e3ccSAndroid Build Coastguard Worker 
87*77c1e3ccSAndroid Build Coastguard Worker /*
88*77c1e3ccSAndroid Build Coastguard Worker  * AV1 Codec Definitions
89*77c1e3ccSAndroid Build Coastguard Worker  */
90*77c1e3ccSAndroid Build Coastguard Worker class AV1Decoder : public Decoder {
91*77c1e3ccSAndroid Build Coastguard Worker  public:
AV1Decoder(aom_codec_dec_cfg_t cfg)92*77c1e3ccSAndroid Build Coastguard Worker   explicit AV1Decoder(aom_codec_dec_cfg_t cfg) : Decoder(cfg) {}
93*77c1e3ccSAndroid Build Coastguard Worker 
AV1Decoder(aom_codec_dec_cfg_t cfg,const aom_codec_flags_t flag)94*77c1e3ccSAndroid Build Coastguard Worker   AV1Decoder(aom_codec_dec_cfg_t cfg, const aom_codec_flags_t flag)
95*77c1e3ccSAndroid Build Coastguard Worker       : Decoder(cfg, flag) {}
96*77c1e3ccSAndroid Build Coastguard Worker 
97*77c1e3ccSAndroid Build Coastguard Worker  protected:
CodecInterface()98*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *CodecInterface() const override {
99*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
100*77c1e3ccSAndroid Build Coastguard Worker     return aom_codec_av1_dx();
101*77c1e3ccSAndroid Build Coastguard Worker #else
102*77c1e3ccSAndroid Build Coastguard Worker     return nullptr;
103*77c1e3ccSAndroid Build Coastguard Worker #endif
104*77c1e3ccSAndroid Build Coastguard Worker   }
105*77c1e3ccSAndroid Build Coastguard Worker };
106*77c1e3ccSAndroid Build Coastguard Worker 
107*77c1e3ccSAndroid Build Coastguard Worker class AV1Encoder : public Encoder {
108*77c1e3ccSAndroid Build Coastguard Worker  public:
AV1Encoder(aom_codec_enc_cfg_t cfg,const aom_codec_flags_t init_flags,TwopassStatsStore * stats)109*77c1e3ccSAndroid Build Coastguard Worker   AV1Encoder(aom_codec_enc_cfg_t cfg, const aom_codec_flags_t init_flags,
110*77c1e3ccSAndroid Build Coastguard Worker              TwopassStatsStore *stats)
111*77c1e3ccSAndroid Build Coastguard Worker       : Encoder(cfg, init_flags, stats) {}
112*77c1e3ccSAndroid Build Coastguard Worker 
113*77c1e3ccSAndroid Build Coastguard Worker  protected:
CodecInterface()114*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iface_t *CodecInterface() const override {
115*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_ENCODER
116*77c1e3ccSAndroid Build Coastguard Worker     return aom_codec_av1_cx();
117*77c1e3ccSAndroid Build Coastguard Worker #else
118*77c1e3ccSAndroid Build Coastguard Worker     return nullptr;
119*77c1e3ccSAndroid Build Coastguard Worker #endif
120*77c1e3ccSAndroid Build Coastguard Worker   }
121*77c1e3ccSAndroid Build Coastguard Worker };
122*77c1e3ccSAndroid Build Coastguard Worker 
123*77c1e3ccSAndroid Build Coastguard Worker class AV1CodecFactory : public CodecFactory {
124*77c1e3ccSAndroid Build Coastguard Worker  public:
AV1CodecFactory()125*77c1e3ccSAndroid Build Coastguard Worker   AV1CodecFactory() : CodecFactory() {}
126*77c1e3ccSAndroid Build Coastguard Worker 
CreateDecoder(aom_codec_dec_cfg_t cfg)127*77c1e3ccSAndroid Build Coastguard Worker   Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const override {
128*77c1e3ccSAndroid Build Coastguard Worker     return CreateDecoder(cfg, 0);
129*77c1e3ccSAndroid Build Coastguard Worker   }
130*77c1e3ccSAndroid Build Coastguard Worker 
CreateDecoder(aom_codec_dec_cfg_t cfg,const aom_codec_flags_t flags)131*77c1e3ccSAndroid Build Coastguard Worker   Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
132*77c1e3ccSAndroid Build Coastguard Worker                          const aom_codec_flags_t flags) const override {
133*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
134*77c1e3ccSAndroid Build Coastguard Worker     return new AV1Decoder(cfg, flags);
135*77c1e3ccSAndroid Build Coastguard Worker #else
136*77c1e3ccSAndroid Build Coastguard Worker     (void)cfg;
137*77c1e3ccSAndroid Build Coastguard Worker     (void)flags;
138*77c1e3ccSAndroid Build Coastguard Worker     return nullptr;
139*77c1e3ccSAndroid Build Coastguard Worker #endif
140*77c1e3ccSAndroid Build Coastguard Worker   }
141*77c1e3ccSAndroid Build Coastguard Worker 
CreateEncoder(aom_codec_enc_cfg_t cfg,const aom_codec_flags_t init_flags,TwopassStatsStore * stats)142*77c1e3ccSAndroid Build Coastguard Worker   Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
143*77c1e3ccSAndroid Build Coastguard Worker                          const aom_codec_flags_t init_flags,
144*77c1e3ccSAndroid Build Coastguard Worker                          TwopassStatsStore *stats) const override {
145*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_ENCODER
146*77c1e3ccSAndroid Build Coastguard Worker     return new AV1Encoder(cfg, init_flags, stats);
147*77c1e3ccSAndroid Build Coastguard Worker #else
148*77c1e3ccSAndroid Build Coastguard Worker     (void)cfg;
149*77c1e3ccSAndroid Build Coastguard Worker     (void)init_flags;
150*77c1e3ccSAndroid Build Coastguard Worker     (void)stats;
151*77c1e3ccSAndroid Build Coastguard Worker     return nullptr;
152*77c1e3ccSAndroid Build Coastguard Worker #endif
153*77c1e3ccSAndroid Build Coastguard Worker   }
154*77c1e3ccSAndroid Build Coastguard Worker 
DefaultEncoderConfig(aom_codec_enc_cfg_t * cfg,unsigned int usage)155*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
156*77c1e3ccSAndroid Build Coastguard Worker                                        unsigned int usage) const override {
157*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_ENCODER
158*77c1e3ccSAndroid Build Coastguard Worker     return aom_codec_enc_config_default(aom_codec_av1_cx(), cfg, usage);
159*77c1e3ccSAndroid Build Coastguard Worker #else
160*77c1e3ccSAndroid Build Coastguard Worker     (void)cfg;
161*77c1e3ccSAndroid Build Coastguard Worker     (void)usage;
162*77c1e3ccSAndroid Build Coastguard Worker     return AOM_CODEC_INCAPABLE;
163*77c1e3ccSAndroid Build Coastguard Worker #endif
164*77c1e3ccSAndroid Build Coastguard Worker   }
165*77c1e3ccSAndroid Build Coastguard Worker };
166*77c1e3ccSAndroid Build Coastguard Worker 
167*77c1e3ccSAndroid Build Coastguard Worker const libaom_test::AV1CodecFactory kAV1;
168*77c1e3ccSAndroid Build Coastguard Worker 
169*77c1e3ccSAndroid Build Coastguard Worker #define AV1_INSTANTIATE_TEST_SUITE(test, ...)                               \
170*77c1e3ccSAndroid Build Coastguard Worker   INSTANTIATE_TEST_SUITE_P(                                                 \
171*77c1e3ccSAndroid Build Coastguard Worker       AV1, test,                                                            \
172*77c1e3ccSAndroid Build Coastguard Worker       ::testing::Combine(                                                   \
173*77c1e3ccSAndroid Build Coastguard Worker           ::testing::Values(static_cast<const libaom_test::CodecFactory *>( \
174*77c1e3ccSAndroid Build Coastguard Worker               &libaom_test::kAV1)),                                         \
175*77c1e3ccSAndroid Build Coastguard Worker           __VA_ARGS__))
176*77c1e3ccSAndroid Build Coastguard Worker 
177*77c1e3ccSAndroid Build Coastguard Worker }  // namespace libaom_test
178*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_TEST_CODEC_FACTORY_H_
179