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