blob: 587380131305346cfde0d65dad0d763551c726bb [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 const unsigned long init_flags,
43 TwopassStatsStore *stats) const = 0;
44
Yaowu Xuf883b422016-08-30 14:01:10 -070045 virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
John Koleszar706cafe2013-01-18 11:51:12 -080046 int usage) const = 0;
47};
48
49/* Provide CodecTestWith<n>Params classes for a variable number of parameters
50 * to avoid having to include a pointer to the CodecFactory in every test
51 * definition.
52 */
clang-format3a826f12016-08-11 17:46:05 -070053template <class T1>
54class CodecTestWithParam
55 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070056 std::tr1::tuple<const libaom_test::CodecFactory *, T1> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080057
clang-format3a826f12016-08-11 17:46:05 -070058template <class T1, class T2>
59class CodecTestWith2Params
60 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070061 std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080062
clang-format3a826f12016-08-11 17:46:05 -070063template <class T1, class T2, class T3>
64class CodecTestWith3Params
65 : public ::testing::TestWithParam<
Yaowu Xuc27fc142016-08-22 16:08:15 -070066 std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2, T3> > {};
John Koleszar706cafe2013-01-18 11:51:12 -080067
68/*
Yaowu Xuf883b422016-08-30 14:01:10 -070069 * AV1 Codec Definitions
Jingning Han3ee6db62015-08-05 19:00:31 -070070 */
Yaowu Xuf883b422016-08-30 14:01:10 -070071#if CONFIG_AV1
72class AV1Decoder : public Decoder {
Jingning Han3ee6db62015-08-05 19:00:31 -070073 public:
James Zern3b96b762017-03-24 17:12:19 -070074 explicit AV1Decoder(aom_codec_dec_cfg_t cfg) : Decoder(cfg) {}
Jingning Han3ee6db62015-08-05 19:00:31 -070075
James Zern3b96b762017-03-24 17:12:19 -070076 AV1Decoder(aom_codec_dec_cfg_t cfg, const aom_codec_flags_t flag)
77 : Decoder(cfg, flag) {}
Jingning Han3ee6db62015-08-05 19:00:31 -070078
79 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070080 virtual aom_codec_iface_t *CodecInterface() const {
81#if CONFIG_AV1_DECODER
82 return &aom_codec_av1_dx_algo;
Jingning Han3ee6db62015-08-05 19:00:31 -070083#else
84 return NULL;
85#endif
86 }
87};
88
Yaowu Xuf883b422016-08-30 14:01:10 -070089class AV1Encoder : public Encoder {
Jingning Han3ee6db62015-08-05 19:00:31 -070090 public:
Sean DuBois47cc2552018-01-23 07:44:16 +000091 AV1Encoder(aom_codec_enc_cfg_t cfg, const uint32_t init_flags,
92 TwopassStatsStore *stats)
93 : Encoder(cfg, init_flags, stats) {}
Jingning Han3ee6db62015-08-05 19:00:31 -070094
95 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -070096 virtual aom_codec_iface_t *CodecInterface() const {
97#if CONFIG_AV1_ENCODER
98 return &aom_codec_av1_cx_algo;
Jingning Han3ee6db62015-08-05 19:00:31 -070099#else
100 return NULL;
101#endif
102 }
103};
104
Yaowu Xuf883b422016-08-30 14:01:10 -0700105class AV1CodecFactory : public CodecFactory {
Jingning Han3ee6db62015-08-05 19:00:31 -0700106 public:
Yaowu Xuf883b422016-08-30 14:01:10 -0700107 AV1CodecFactory() : CodecFactory() {}
Jingning Han3ee6db62015-08-05 19:00:31 -0700108
James Zern3b96b762017-03-24 17:12:19 -0700109 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const {
110 return CreateDecoder(cfg, 0);
Jingning Han3ee6db62015-08-05 19:00:31 -0700111 }
112
Yaowu Xuf883b422016-08-30 14:01:10 -0700113 virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
James Zern3b96b762017-03-24 17:12:19 -0700114 const aom_codec_flags_t flags) const {
Yaowu Xuf883b422016-08-30 14:01:10 -0700115#if CONFIG_AV1_DECODER
James Zern3b96b762017-03-24 17:12:19 -0700116 return new AV1Decoder(cfg, flags);
Jingning Han3ee6db62015-08-05 19:00:31 -0700117#else
Urvang Joshid71a2312016-07-14 12:33:48 -0700118 (void)cfg;
119 (void)flags;
Jingning Han3ee6db62015-08-05 19:00:31 -0700120 return NULL;
121#endif
122 }
123
Yaowu Xuf883b422016-08-30 14:01:10 -0700124 virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
Jingning Han3ee6db62015-08-05 19:00:31 -0700125 const unsigned long init_flags,
126 TwopassStatsStore *stats) const {
Yaowu Xuf883b422016-08-30 14:01:10 -0700127#if CONFIG_AV1_ENCODER
Sean DuBois47cc2552018-01-23 07:44:16 +0000128 return new AV1Encoder(cfg, init_flags, stats);
Jingning Han3ee6db62015-08-05 19:00:31 -0700129#else
Urvang Joshid71a2312016-07-14 12:33:48 -0700130 (void)cfg;
Urvang Joshid71a2312016-07-14 12:33:48 -0700131 (void)init_flags;
132 (void)stats;
Jingning Han3ee6db62015-08-05 19:00:31 -0700133 return NULL;
134#endif
135 }
136
Yaowu Xuf883b422016-08-30 14:01:10 -0700137 virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
Jingning Han3ee6db62015-08-05 19:00:31 -0700138 int usage) const {
Yaowu Xuf883b422016-08-30 14:01:10 -0700139#if CONFIG_AV1_ENCODER
140 return aom_codec_enc_config_default(&aom_codec_av1_cx_algo, cfg, usage);
Jingning Han3ee6db62015-08-05 19:00:31 -0700141#else
Urvang Joshid71a2312016-07-14 12:33:48 -0700142 (void)cfg;
143 (void)usage;
Yaowu Xuf883b422016-08-30 14:01:10 -0700144 return AOM_CODEC_INCAPABLE;
Jingning Han3ee6db62015-08-05 19:00:31 -0700145#endif
146 }
147};
148
Yaowu Xuf883b422016-08-30 14:01:10 -0700149const libaom_test::AV1CodecFactory kAV1;
Jingning Han3ee6db62015-08-05 19:00:31 -0700150
Yaowu Xuf883b422016-08-30 14:01:10 -0700151#define AV1_INSTANTIATE_TEST_CASE(test, ...) \
clang-format3a826f12016-08-11 17:46:05 -0700152 INSTANTIATE_TEST_CASE_P( \
Yaowu Xuf883b422016-08-30 14:01:10 -0700153 AV1, test, \
clang-format3a826f12016-08-11 17:46:05 -0700154 ::testing::Combine( \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700155 ::testing::Values(static_cast<const libaom_test::CodecFactory *>( \
Yaowu Xuf883b422016-08-30 14:01:10 -0700156 &libaom_test::kAV1)), \
Jingning Han3ee6db62015-08-05 19:00:31 -0700157 __VA_ARGS__))
158#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700159#define AV1_INSTANTIATE_TEST_CASE(test, ...)
160#endif // CONFIG_AV1
John Koleszar706cafe2013-01-18 11:51:12 -0800161
Yaowu Xuc27fc142016-08-22 16:08:15 -0700162} // namespace libaom_test
John Koleszar706cafe2013-01-18 11:51:12 -0800163#endif // TEST_CODEC_FACTORY_H_