1 /* 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef VPX_TEST_CODEC_FACTORY_H_ 11 #define VPX_TEST_CODEC_FACTORY_H_ 12 13 #include <tuple> 14 15 #include "./vpx_config.h" 16 #include "vpx/vpx_decoder.h" 17 #include "vpx/vpx_encoder.h" 18 #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER 19 #include "vpx/vp8cx.h" 20 #endif 21 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER 22 #include "vpx/vp8dx.h" 23 #endif 24 25 #include "test/decode_test_driver.h" 26 #include "test/encode_test_driver.h" 27 namespace libvpx_test { 28 29 const int kCodecFactoryParam = 0; 30 31 class CodecFactory { 32 public: CodecFactory()33 CodecFactory() {} 34 ~CodecFactory()35 virtual ~CodecFactory() {} 36 37 virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const = 0; 38 39 virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg, 40 const vpx_codec_flags_t flags) const = 0; 41 42 virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, 43 unsigned long deadline, 44 const unsigned long init_flags, 45 TwopassStatsStore *stats) const = 0; 46 47 virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg, 48 int usage) const = 0; 49 }; 50 51 /* Provide CodecTestWith<n>Params classes for a variable number of parameters 52 * to avoid having to include a pointer to the CodecFactory in every test 53 * definition. 54 */ 55 template <class T1> 56 class CodecTestWithParam 57 : public ::testing::TestWithParam< 58 std::tuple<const libvpx_test::CodecFactory *, T1> > {}; 59 60 template <class T1, class T2> 61 class CodecTestWith2Params 62 : public ::testing::TestWithParam< 63 std::tuple<const libvpx_test::CodecFactory *, T1, T2> > {}; 64 65 template <class T1, class T2, class T3> 66 class CodecTestWith3Params 67 : public ::testing::TestWithParam< 68 std::tuple<const libvpx_test::CodecFactory *, T1, T2, T3> > {}; 69 70 template <class T1, class T2, class T3, class T4> 71 class CodecTestWith4Params 72 : public ::testing::TestWithParam< 73 std::tuple<const libvpx_test::CodecFactory *, T1, T2, T3, T4> > {}; 74 75 /* 76 * VP8 Codec Definitions 77 */ 78 #if CONFIG_VP8 79 class VP8Decoder : public Decoder { 80 public: VP8Decoder(vpx_codec_dec_cfg_t cfg)81 explicit VP8Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {} 82 VP8Decoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flag)83 VP8Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag) 84 : Decoder(cfg, flag) {} 85 86 protected: CodecInterface()87 virtual vpx_codec_iface_t *CodecInterface() const { 88 #if CONFIG_VP8_DECODER 89 return &vpx_codec_vp8_dx_algo; 90 #else 91 return NULL; 92 #endif 93 } 94 }; 95 96 class VP8Encoder : public Encoder { 97 public: VP8Encoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)98 VP8Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline, 99 const unsigned long init_flags, TwopassStatsStore *stats) 100 : Encoder(cfg, deadline, init_flags, stats) {} 101 102 protected: CodecInterface()103 virtual vpx_codec_iface_t *CodecInterface() const { 104 #if CONFIG_VP8_ENCODER 105 return &vpx_codec_vp8_cx_algo; 106 #else 107 return NULL; 108 #endif 109 } 110 }; 111 112 class VP8CodecFactory : public CodecFactory { 113 public: VP8CodecFactory()114 VP8CodecFactory() : CodecFactory() {} 115 CreateDecoder(vpx_codec_dec_cfg_t cfg)116 virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const { 117 return CreateDecoder(cfg, 0); 118 } 119 CreateDecoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flags)120 virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg, 121 const vpx_codec_flags_t flags) const { 122 #if CONFIG_VP8_DECODER 123 return new VP8Decoder(cfg, flags); 124 #else 125 (void)cfg; 126 (void)flags; 127 return NULL; 128 #endif 129 } 130 CreateEncoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)131 virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, 132 unsigned long deadline, 133 const unsigned long init_flags, 134 TwopassStatsStore *stats) const { 135 #if CONFIG_VP8_ENCODER 136 return new VP8Encoder(cfg, deadline, init_flags, stats); 137 #else 138 (void)cfg; 139 (void)deadline; 140 (void)init_flags; 141 (void)stats; 142 return NULL; 143 #endif 144 } 145 DefaultEncoderConfig(vpx_codec_enc_cfg_t * cfg,int usage)146 virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg, 147 int usage) const { 148 #if CONFIG_VP8_ENCODER 149 return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage); 150 #else 151 (void)cfg; 152 (void)usage; 153 return VPX_CODEC_INCAPABLE; 154 #endif 155 } 156 }; 157 158 const libvpx_test::VP8CodecFactory kVP8; 159 160 #define VP8_INSTANTIATE_TEST_CASE(test, ...) \ 161 INSTANTIATE_TEST_CASE_P( \ 162 VP8, test, \ 163 ::testing::Combine( \ 164 ::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \ 165 &libvpx_test::kVP8)), \ 166 __VA_ARGS__)) 167 #else 168 #define VP8_INSTANTIATE_TEST_CASE(test, ...) 169 #endif // CONFIG_VP8 170 171 /* 172 * VP9 Codec Definitions 173 */ 174 #if CONFIG_VP9 175 class VP9Decoder : public Decoder { 176 public: VP9Decoder(vpx_codec_dec_cfg_t cfg)177 explicit VP9Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {} 178 VP9Decoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flag)179 VP9Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag) 180 : Decoder(cfg, flag) {} 181 182 protected: CodecInterface()183 virtual vpx_codec_iface_t *CodecInterface() const { 184 #if CONFIG_VP9_DECODER 185 return &vpx_codec_vp9_dx_algo; 186 #else 187 return NULL; 188 #endif 189 } 190 }; 191 192 class VP9Encoder : public Encoder { 193 public: VP9Encoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)194 VP9Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline, 195 const unsigned long init_flags, TwopassStatsStore *stats) 196 : Encoder(cfg, deadline, init_flags, stats) {} 197 198 protected: CodecInterface()199 virtual vpx_codec_iface_t *CodecInterface() const { 200 #if CONFIG_VP9_ENCODER 201 return &vpx_codec_vp9_cx_algo; 202 #else 203 return NULL; 204 #endif 205 } 206 }; 207 208 class VP9CodecFactory : public CodecFactory { 209 public: VP9CodecFactory()210 VP9CodecFactory() : CodecFactory() {} 211 CreateDecoder(vpx_codec_dec_cfg_t cfg)212 virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const { 213 return CreateDecoder(cfg, 0); 214 } 215 CreateDecoder(vpx_codec_dec_cfg_t cfg,const vpx_codec_flags_t flags)216 virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg, 217 const vpx_codec_flags_t flags) const { 218 #if CONFIG_VP9_DECODER 219 return new VP9Decoder(cfg, flags); 220 #else 221 (void)cfg; 222 (void)flags; 223 return NULL; 224 #endif 225 } 226 CreateEncoder(vpx_codec_enc_cfg_t cfg,unsigned long deadline,const unsigned long init_flags,TwopassStatsStore * stats)227 virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, 228 unsigned long deadline, 229 const unsigned long init_flags, 230 TwopassStatsStore *stats) const { 231 #if CONFIG_VP9_ENCODER 232 return new VP9Encoder(cfg, deadline, init_flags, stats); 233 #else 234 (void)cfg; 235 (void)deadline; 236 (void)init_flags; 237 (void)stats; 238 return NULL; 239 #endif 240 } 241 DefaultEncoderConfig(vpx_codec_enc_cfg_t * cfg,int usage)242 virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg, 243 int usage) const { 244 #if CONFIG_VP9_ENCODER 245 return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage); 246 #else 247 (void)cfg; 248 (void)usage; 249 return VPX_CODEC_INCAPABLE; 250 #endif 251 } 252 }; 253 254 const libvpx_test::VP9CodecFactory kVP9; 255 256 #define VP9_INSTANTIATE_TEST_CASE(test, ...) \ 257 INSTANTIATE_TEST_CASE_P( \ 258 VP9, test, \ 259 ::testing::Combine( \ 260 ::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \ 261 &libvpx_test::kVP9)), \ 262 __VA_ARGS__)) 263 #else 264 #define VP9_INSTANTIATE_TEST_CASE(test, ...) 265 #endif // CONFIG_VP9 266 267 } // namespace libvpx_test 268 #endif // VPX_TEST_CODEC_FACTORY_H_ 269