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