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