blob: d2f20b832dac1281085c6e9f7fd17086b9cd33f4 [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
James Zern3b96b762017-03-24 17:12:19 -070036 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const = 0;
John Koleszar706cafe2013-01-18 11:51:12 -080037
Yaowu Xuf883b422016-08-30 14:01:10 -070038 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
James Zern3b96b762017-03-24 17:12:19 -070039 const aom_codec_flags_t flags) const = 0;
hkuang93536072014-11-20 15:39:56 -080040
Yaowu Xuf883b422016-08-30 14:01:10 -070041 virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
John Koleszar706cafe2013-01-18 11:51:12 -080042 unsigned long deadline,
43 const unsigned long init_flags,
44 TwopassStatsStore *stats) const = 0;
45
Yaowu Xuf883b422016-08-30 14:01:10 -070046 virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
John Koleszar706cafe2013-01-18 11:51:12 -080047 int usage) const = 0;
48};
49
50/* Provide CodecTestWith<n>Params classes for a variable number of parameters
51 * to avoid having to include a pointer to the CodecFactory in every test
52 * definition.
53 */
clang-format3a826f12016-08-11 17:46:05 -070054template <class T1>
55class CodecTestWithParam
56 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070057 std::tr1::tuple<const libaom_test::CodecFactory *, T1> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080058
clang-format3a826f12016-08-11 17:46:05 -070059template <class T1, class T2>
60class CodecTestWith2Params
61 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070062 std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080063
clang-format3a826f12016-08-11 17:46:05 -070064template <class T1, class T2, class T3>
65class CodecTestWith3Params
66 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070067 std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2, T3> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080068
69/*
Yaowu Xuf883b422016-08-30 14:01:10 -070070 * AV1 Codec Definitions
Jingning Han3ee6db62015-08-05 19:00:31 -070071 */
Yaowu Xuf883b422016-08-30 14:01:10 -070072#if CONFIG_AV1
73class AV1Decoder : public Decoder {
Jingning Han3ee6db62015-08-05 19:00:31 -070074 public:
James Zern3b96b762017-03-24 17:12:19 -070075 explicit AV1Decoder(aom_codec_dec_cfg_t cfg) : Decoder(cfg) {}
Jingning Han3ee6db62015-08-05 19:00:31 -070076
James Zern3b96b762017-03-24 17:12:19 -070077 AV1Decoder(aom_codec_dec_cfg_t cfg, const aom_codec_flags_t flag)
78 : Decoder(cfg, flag) {}
Jingning Han3ee6db62015-08-05 19:00:31 -070079
80 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070081 virtual aom_codec_iface_t *CodecInterface() const {
82#if CONFIG_AV1_DECODER
83 return &aom_codec_av1_dx_algo;
Jingning Han3ee6db62015-08-05 19:00:31 -070084#else
85 return NULL;
86#endif
87 }
88};
89
Yaowu Xuf883b422016-08-30 14:01:10 -070090class AV1Encoder : public Encoder {
Jingning Han3ee6db62015-08-05 19:00:31 -070091 public:
Yaowu Xuf883b422016-08-30 14:01:10 -070092 AV1Encoder(aom_codec_enc_cfg_t cfg, unsigned long deadline,
93 const unsigned long init_flags, TwopassStatsStore *stats)
Jingning Han3ee6db62015-08-05 19:00:31 -070094 : Encoder(cfg, deadline, init_flags, stats) {}
95
96 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070097 virtual aom_codec_iface_t *CodecInterface() const {
98#if CONFIG_AV1_ENCODER
99 return &aom_codec_av1_cx_algo;
Jingning Han3ee6db62015-08-05 19:00:31 -0700100#else
101 return NULL;
102#endif
103 }
104};
105
Yaowu Xuf883b422016-08-30 14:01:10 -0700106class AV1CodecFactory : public CodecFactory {
Jingning Han3ee6db62015-08-05 19:00:31 -0700107 public:
Yaowu Xuf883b422016-08-30 14:01:10 -0700108 AV1CodecFactory() : CodecFactory() {}
Jingning Han3ee6db62015-08-05 19:00:31 -0700109
James Zern3b96b762017-03-24 17:12:19 -0700110 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const {
111 return CreateDecoder(cfg, 0);
Jingning Han3ee6db62015-08-05 19:00:31 -0700112 }
113
Yaowu Xuf883b422016-08-30 14:01:10 -0700114 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
James Zern3b96b762017-03-24 17:12:19 -0700115 const aom_codec_flags_t flags) const {
Yaowu Xuf883b422016-08-30 14:01:10 -0700116#if CONFIG_AV1_DECODER
James Zern3b96b762017-03-24 17:12:19 -0700117 return new AV1Decoder(cfg, flags);
Jingning Han3ee6db62015-08-05 19:00:31 -0700118#else
Urvang Joshid71a2312016-07-14 12:33:48 -0700119 (void)cfg;
120 (void)flags;
Jingning Han3ee6db62015-08-05 19:00:31 -0700121 return NULL;
122#endif
123 }
124
Yaowu Xuf883b422016-08-30 14:01:10 -0700125 virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
Jingning Han3ee6db62015-08-05 19:00:31 -0700126 unsigned long deadline,
127 const unsigned long init_flags,
128 TwopassStatsStore *stats) const {
Yaowu Xuf883b422016-08-30 14:01:10 -0700129#if CONFIG_AV1_ENCODER
130 return new AV1Encoder(cfg, deadline, init_flags, stats);
Jingning Han3ee6db62015-08-05 19:00:31 -0700131#else
Urvang Joshid71a2312016-07-14 12:33:48 -0700132 (void)cfg;
133 (void)deadline;
134 (void)init_flags;
135 (void)stats;
Jingning Han3ee6db62015-08-05 19:00:31 -0700136 return NULL;
137#endif
138 }
139
Yaowu Xuf883b422016-08-30 14:01:10 -0700140 virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
Jingning Han3ee6db62015-08-05 19:00:31 -0700141 int usage) const {
Yaowu Xuf883b422016-08-30 14:01:10 -0700142#if CONFIG_AV1_ENCODER
143 return aom_codec_enc_config_default(&aom_codec_av1_cx_algo, cfg, usage);
Jingning Han3ee6db62015-08-05 19:00:31 -0700144#else
Urvang Joshid71a2312016-07-14 12:33:48 -0700145 (void)cfg;
146 (void)usage;
Yaowu Xuf883b422016-08-30 14:01:10 -0700147 return AOM_CODEC_INCAPABLE;
Jingning Han3ee6db62015-08-05 19:00:31 -0700148#endif
149 }
150};
151
Yaowu Xuf883b422016-08-30 14:01:10 -0700152const libaom_test::AV1CodecFactory kAV1;
Jingning Han3ee6db62015-08-05 19:00:31 -0700153
Yaowu Xuf883b422016-08-30 14:01:10 -0700154#define AV1_INSTANTIATE_TEST_CASE(test, ...) \
clang-format3a826f12016-08-11 17:46:05 -0700155 INSTANTIATE_TEST_CASE_P( \
Yaowu Xuf883b422016-08-30 14:01:10 -0700156 AV1, test, \
clang-format3a826f12016-08-11 17:46:05 -0700157 ::testing::Combine( \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700158 ::testing::Values(static_cast<const libaom_test::CodecFactory *>( \
Yaowu Xuf883b422016-08-30 14:01:10 -0700159 &libaom_test::kAV1)), \
Jingning Han3ee6db62015-08-05 19:00:31 -0700160 __VA_ARGS__))
161#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700162#define AV1_INSTANTIATE_TEST_CASE(test, ...)
163#endif // CONFIG_AV1
John Koleszar706cafe2013-01-18 11:51:12 -0800164
Yaowu Xuc27fc142016-08-22 16:08:15 -0700165} // namespace libaom_test
John Koleszar706cafe2013-01-18 11:51:12 -0800166#endif // TEST_CODEC_FACTORY_H_