blob: c92d5c1cf4ec0c80f820362b7f4a5d7c928ca037 [file] [log] [blame]
John Koleszar706cafe2013-01-18 11:51:12 -08001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar706cafe2013-01-18 11:51:12 -08003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
John Koleszar706cafe2013-01-18 11:51:12 -080010 */
11#ifndef TEST_CODEC_FACTORY_H_
12#define TEST_CODEC_FACTORY_H_
13
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "./aom_config.h"
15#include "aom/aom_decoder.h"
16#include "aom/aom_encoder.h"
17#if CONFIG_AV1_ENCODER
18#include "aom/aomcx.h"
John Koleszar706cafe2013-01-18 11:51:12 -080019#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070020#if CONFIG_AV1_DECODER
21#include "aom/aomdx.h"
John Koleszar706cafe2013-01-18 11:51:12 -080022#endif
John Koleszar706cafe2013-01-18 11:51:12 -080023
24#include "test/decode_test_driver.h"
25#include "test/encode_test_driver.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070026namespace libaom_test {
John Koleszar706cafe2013-01-18 11:51:12 -080027
Frank Galligana4f30a52014-02-06 17:13:08 -080028const int kCodecFactoryParam = 0;
29
John Koleszar706cafe2013-01-18 11:51:12 -080030class CodecFactory {
31 public:
32 CodecFactory() {}
33
34 virtual ~CodecFactory() {}
35
Yaowu Xuf883b422016-08-30 14:01:10 -070036 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
John Koleszar706cafe2013-01-18 11:51:12 -080037 unsigned long deadline) const = 0;
38
Yaowu Xuf883b422016-08-30 14:01:10 -070039 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
40 const aom_codec_flags_t flags,
hkuang93536072014-11-20 15:39:56 -080041 unsigned long deadline) // NOLINT(runtime/int)
clang-format3a826f12016-08-11 17:46:05 -070042 const = 0;
hkuang93536072014-11-20 15:39:56 -080043
Yaowu Xuf883b422016-08-30 14:01:10 -070044 virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
John Koleszar706cafe2013-01-18 11:51:12 -080045 unsigned long deadline,
46 const unsigned long init_flags,
47 TwopassStatsStore *stats) const = 0;
48
Yaowu Xuf883b422016-08-30 14:01:10 -070049 virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
John Koleszar706cafe2013-01-18 11:51:12 -080050 int usage) const = 0;
51};
52
53/* Provide CodecTestWith<n>Params classes for a variable number of parameters
54 * to avoid having to include a pointer to the CodecFactory in every test
55 * definition.
56 */
clang-format3a826f12016-08-11 17:46:05 -070057template <class T1>
58class CodecTestWithParam
59 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070060 std::tr1::tuple<const libaom_test::CodecFactory *, T1> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080061
clang-format3a826f12016-08-11 17:46:05 -070062template <class T1, class T2>
63class CodecTestWith2Params
64 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070065 std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080066
clang-format3a826f12016-08-11 17:46:05 -070067template <class T1, class T2, class T3>
68class CodecTestWith3Params
69 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070070 std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2, T3> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080071
72/*
Yaowu Xuf883b422016-08-30 14:01:10 -070073 * AV1 Codec Definitions
Jingning Han3ee6db62015-08-05 19:00:31 -070074 */
Yaowu Xuf883b422016-08-30 14:01:10 -070075#if CONFIG_AV1
76class AV1Decoder : public Decoder {
Jingning Han3ee6db62015-08-05 19:00:31 -070077 public:
Yaowu Xuf883b422016-08-30 14:01:10 -070078 AV1Decoder(aom_codec_dec_cfg_t cfg, unsigned long deadline)
Jingning Han3ee6db62015-08-05 19:00:31 -070079 : Decoder(cfg, deadline) {}
80
Yaowu Xuf883b422016-08-30 14:01:10 -070081 AV1Decoder(aom_codec_dec_cfg_t cfg, const aom_codec_flags_t flag,
82 unsigned long deadline) // NOLINT
Jingning Han3ee6db62015-08-05 19:00:31 -070083 : Decoder(cfg, flag, deadline) {}
84
85 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070086 virtual aom_codec_iface_t *CodecInterface() const {
87#if CONFIG_AV1_DECODER
88 return &aom_codec_av1_dx_algo;
Jingning Han3ee6db62015-08-05 19:00:31 -070089#else
90 return NULL;
91#endif
92 }
93};
94
Yaowu Xuf883b422016-08-30 14:01:10 -070095class AV1Encoder : public Encoder {
Jingning Han3ee6db62015-08-05 19:00:31 -070096 public:
Yaowu Xuf883b422016-08-30 14:01:10 -070097 AV1Encoder(aom_codec_enc_cfg_t cfg, unsigned long deadline,
98 const unsigned long init_flags, TwopassStatsStore *stats)
Jingning Han3ee6db62015-08-05 19:00:31 -070099 : Encoder(cfg, deadline, init_flags, stats) {}
100
101 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -0700102 virtual aom_codec_iface_t *CodecInterface() const {
103#if CONFIG_AV1_ENCODER
104 return &aom_codec_av1_cx_algo;
Jingning Han3ee6db62015-08-05 19:00:31 -0700105#else
106 return NULL;
107#endif
108 }
109};
110
Yaowu Xuf883b422016-08-30 14:01:10 -0700111class AV1CodecFactory : public CodecFactory {
Jingning Han3ee6db62015-08-05 19:00:31 -0700112 public:
Yaowu Xuf883b422016-08-30 14:01:10 -0700113 AV1CodecFactory() : CodecFactory() {}
Jingning Han3ee6db62015-08-05 19:00:31 -0700114
Yaowu Xuf883b422016-08-30 14:01:10 -0700115 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
Jingning Han3ee6db62015-08-05 19:00:31 -0700116 unsigned long deadline) const {
117 return CreateDecoder(cfg, 0, deadline);
118 }
119
Yaowu Xuf883b422016-08-30 14:01:10 -0700120 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
121 const aom_codec_flags_t flags,
Jingning Han3ee6db62015-08-05 19:00:31 -0700122 unsigned long deadline) const { // NOLINT
Yaowu Xuf883b422016-08-30 14:01:10 -0700123#if CONFIG_AV1_DECODER
124 return new AV1Decoder(cfg, flags, deadline);
Jingning Han3ee6db62015-08-05 19:00:31 -0700125#else
126 return NULL;
127#endif
128 }
129
Yaowu Xuf883b422016-08-30 14:01:10 -0700130 virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
Jingning Han3ee6db62015-08-05 19:00:31 -0700131 unsigned long deadline,
132 const unsigned long init_flags,
133 TwopassStatsStore *stats) const {
Yaowu Xuf883b422016-08-30 14:01:10 -0700134#if CONFIG_AV1_ENCODER
135 return new AV1Encoder(cfg, deadline, init_flags, stats);
Jingning Han3ee6db62015-08-05 19:00:31 -0700136#else
137 return NULL;
138#endif
139 }
140
Yaowu Xuf883b422016-08-30 14:01:10 -0700141 virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
Jingning Han3ee6db62015-08-05 19:00:31 -0700142 int usage) const {
Yaowu Xuf883b422016-08-30 14:01:10 -0700143#if CONFIG_AV1_ENCODER
144 return aom_codec_enc_config_default(&aom_codec_av1_cx_algo, cfg, usage);
Jingning Han3ee6db62015-08-05 19:00:31 -0700145#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700146 return AOM_CODEC_INCAPABLE;
Jingning Han3ee6db62015-08-05 19:00:31 -0700147#endif
148 }
149};
150
Yaowu Xuf883b422016-08-30 14:01:10 -0700151const libaom_test::AV1CodecFactory kAV1;
Jingning Han3ee6db62015-08-05 19:00:31 -0700152
Yaowu Xuf883b422016-08-30 14:01:10 -0700153#define AV1_INSTANTIATE_TEST_CASE(test, ...) \
clang-format3a826f12016-08-11 17:46:05 -0700154 INSTANTIATE_TEST_CASE_P( \
Yaowu Xuf883b422016-08-30 14:01:10 -0700155 AV1, test, \
clang-format3a826f12016-08-11 17:46:05 -0700156 ::testing::Combine( \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700157 ::testing::Values(static_cast<const libaom_test::CodecFactory *>( \
Yaowu Xuf883b422016-08-30 14:01:10 -0700158 &libaom_test::kAV1)), \
Jingning Han3ee6db62015-08-05 19:00:31 -0700159 __VA_ARGS__))
160#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700161#define AV1_INSTANTIATE_TEST_CASE(test, ...)
162#endif // CONFIG_AV1
John Koleszar706cafe2013-01-18 11:51:12 -0800163
Yaowu Xuc27fc142016-08-22 16:08:15 -0700164} // namespace libaom_test
John Koleszar706cafe2013-01-18 11:51:12 -0800165#endif // TEST_CODEC_FACTORY_H_