John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * 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 Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 10 | */ |
| 11 | #ifndef TEST_CODEC_FACTORY_H_ |
| 12 | #define TEST_CODEC_FACTORY_H_ |
| 13 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | #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 Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 19 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | #if CONFIG_AV1_DECODER |
| 21 | #include "aom/aomdx.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 22 | #endif |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 23 | |
| 24 | #include "test/decode_test_driver.h" |
| 25 | #include "test/encode_test_driver.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | namespace libaom_test { |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 27 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 28 | const int kCodecFactoryParam = 0; |
| 29 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 30 | class CodecFactory { |
| 31 | public: |
| 32 | CodecFactory() {} |
| 33 | |
| 34 | virtual ~CodecFactory() {} |
| 35 | |
James Zern | 3b96b76 | 2017-03-24 17:12:19 -0700 | [diff] [blame] | 36 | virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const = 0; |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 37 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 38 | virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg, |
James Zern | 3b96b76 | 2017-03-24 17:12:19 -0700 | [diff] [blame] | 39 | const aom_codec_flags_t flags) const = 0; |
hkuang | 9353607 | 2014-11-20 15:39:56 -0800 | [diff] [blame] | 40 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 41 | virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg, |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 42 | const unsigned long init_flags, |
| 43 | TwopassStatsStore *stats) const = 0; |
| 44 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg, |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 46 | 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 53 | template <class T1> |
| 54 | class CodecTestWithParam |
| 55 | : public ::testing::TestWithParam< |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 56 | std::tr1::tuple<const libaom_test::CodecFactory *, T1> > {}; |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 57 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 58 | template <class T1, class T2> |
| 59 | class CodecTestWith2Params |
| 60 | : public ::testing::TestWithParam< |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2> > {}; |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 62 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 63 | template <class T1, class T2, class T3> |
| 64 | class CodecTestWith3Params |
| 65 | : public ::testing::TestWithParam< |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2, T3> > {}; |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 67 | |
| 68 | /* |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | * AV1 Codec Definitions |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 70 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | #if CONFIG_AV1 |
| 72 | class AV1Decoder : public Decoder { |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 73 | public: |
James Zern | 3b96b76 | 2017-03-24 17:12:19 -0700 | [diff] [blame] | 74 | explicit AV1Decoder(aom_codec_dec_cfg_t cfg) : Decoder(cfg) {} |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 75 | |
James Zern | 3b96b76 | 2017-03-24 17:12:19 -0700 | [diff] [blame] | 76 | AV1Decoder(aom_codec_dec_cfg_t cfg, const aom_codec_flags_t flag) |
| 77 | : Decoder(cfg, flag) {} |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 78 | |
| 79 | protected: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 80 | virtual aom_codec_iface_t *CodecInterface() const { |
| 81 | #if CONFIG_AV1_DECODER |
| 82 | return &aom_codec_av1_dx_algo; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 83 | #else |
| 84 | return NULL; |
| 85 | #endif |
| 86 | } |
| 87 | }; |
| 88 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 89 | class AV1Encoder : public Encoder { |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 90 | public: |
Sean DuBois | 47cc255 | 2018-01-23 07:44:16 +0000 | [diff] [blame] | 91 | AV1Encoder(aom_codec_enc_cfg_t cfg, const uint32_t init_flags, |
| 92 | TwopassStatsStore *stats) |
| 93 | : Encoder(cfg, init_flags, stats) {} |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 94 | |
| 95 | protected: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | virtual aom_codec_iface_t *CodecInterface() const { |
| 97 | #if CONFIG_AV1_ENCODER |
| 98 | return &aom_codec_av1_cx_algo; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 99 | #else |
| 100 | return NULL; |
| 101 | #endif |
| 102 | } |
| 103 | }; |
| 104 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 105 | class AV1CodecFactory : public CodecFactory { |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 106 | public: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 107 | AV1CodecFactory() : CodecFactory() {} |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 108 | |
James Zern | 3b96b76 | 2017-03-24 17:12:19 -0700 | [diff] [blame] | 109 | virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const { |
| 110 | return CreateDecoder(cfg, 0); |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg, |
James Zern | 3b96b76 | 2017-03-24 17:12:19 -0700 | [diff] [blame] | 114 | const aom_codec_flags_t flags) const { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 115 | #if CONFIG_AV1_DECODER |
James Zern | 3b96b76 | 2017-03-24 17:12:19 -0700 | [diff] [blame] | 116 | return new AV1Decoder(cfg, flags); |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 117 | #else |
Urvang Joshi | d71a231 | 2016-07-14 12:33:48 -0700 | [diff] [blame] | 118 | (void)cfg; |
| 119 | (void)flags; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 120 | return NULL; |
| 121 | #endif |
| 122 | } |
| 123 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 124 | virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg, |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 125 | const unsigned long init_flags, |
| 126 | TwopassStatsStore *stats) const { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 127 | #if CONFIG_AV1_ENCODER |
Sean DuBois | 47cc255 | 2018-01-23 07:44:16 +0000 | [diff] [blame] | 128 | return new AV1Encoder(cfg, init_flags, stats); |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 129 | #else |
Urvang Joshi | d71a231 | 2016-07-14 12:33:48 -0700 | [diff] [blame] | 130 | (void)cfg; |
Urvang Joshi | d71a231 | 2016-07-14 12:33:48 -0700 | [diff] [blame] | 131 | (void)init_flags; |
| 132 | (void)stats; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 133 | return NULL; |
| 134 | #endif |
| 135 | } |
| 136 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 137 | virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg, |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 138 | int usage) const { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 139 | #if CONFIG_AV1_ENCODER |
| 140 | return aom_codec_enc_config_default(&aom_codec_av1_cx_algo, cfg, usage); |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 141 | #else |
Urvang Joshi | d71a231 | 2016-07-14 12:33:48 -0700 | [diff] [blame] | 142 | (void)cfg; |
| 143 | (void)usage; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 144 | return AOM_CODEC_INCAPABLE; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 145 | #endif |
| 146 | } |
| 147 | }; |
| 148 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 149 | const libaom_test::AV1CodecFactory kAV1; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 150 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 151 | #define AV1_INSTANTIATE_TEST_CASE(test, ...) \ |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 152 | INSTANTIATE_TEST_CASE_P( \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 153 | AV1, test, \ |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 154 | ::testing::Combine( \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 155 | ::testing::Values(static_cast<const libaom_test::CodecFactory *>( \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 156 | &libaom_test::kAV1)), \ |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 157 | __VA_ARGS__)) |
| 158 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 159 | #define AV1_INSTANTIATE_TEST_CASE(test, ...) |
| 160 | #endif // CONFIG_AV1 |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 161 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 162 | } // namespace libaom_test |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 163 | #endif // TEST_CODEC_FACTORY_H_ |