codec_factory.h 9.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
#ifndef TEST_CODEC_FACTORY_H_
#define TEST_CODEC_FACTORY_H_

#include "./vpx_config.h"
#include "vpx/vpx_decoder.h"
#include "vpx/vpx_encoder.h"
16
#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
17 18
#include "vpx/vp8cx.h"
#endif
19
#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_DECODER
20 21 22 23 24 25 26
#include "vpx/vp8dx.h"
#endif

#include "test/decode_test_driver.h"
#include "test/encode_test_driver.h"
namespace libvpx_test {

27 28
const int kCodecFactoryParam = 0;

29 30 31 32 33 34 35 36 37
class CodecFactory {
 public:
  CodecFactory() {}

  virtual ~CodecFactory() {}

  virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
                                 unsigned long deadline) const = 0;

38 39 40 41 42
  virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
                                 const vpx_codec_flags_t flags,
                                 unsigned long deadline)  // NOLINT(runtime/int)
                                 const = 0;

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
                                 unsigned long deadline,
                                 const unsigned long init_flags,
                                 TwopassStatsStore *stats) const = 0;

  virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
                                               int usage) const = 0;
};

/* Provide CodecTestWith<n>Params classes for a variable number of parameters
 * to avoid having to include a pointer to the CodecFactory in every test
 * definition.
 */
template<class T1>
class CodecTestWithParam : public ::testing::TestWithParam<
    std::tr1::tuple< const libvpx_test::CodecFactory*, T1 > > {
};

template<class T1, class T2>
class CodecTestWith2Params : public ::testing::TestWithParam<
    std::tr1::tuple< const libvpx_test::CodecFactory*, T1, T2 > > {
};

template<class T1, class T2, class T3>
class CodecTestWith3Params : public ::testing::TestWithParam<
    std::tr1::tuple< const libvpx_test::CodecFactory*, T1, T2, T3 > > {
};

/*
 * VP8 Codec Definitions
 */
#if CONFIG_VP8
class VP8Decoder : public Decoder {
 public:
  VP8Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
      : Decoder(cfg, deadline) {}

80 81 82 83
  VP8Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag,
             unsigned long deadline)  // NOLINT
      : Decoder(cfg, flag, deadline) {}

84
 protected:
85
  virtual vpx_codec_iface_t* CodecInterface() const {
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#if CONFIG_VP8_DECODER
    return &vpx_codec_vp8_dx_algo;
#else
    return NULL;
#endif
  }
};

class VP8Encoder : public Encoder {
 public:
  VP8Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
             const unsigned long init_flags, TwopassStatsStore *stats)
      : Encoder(cfg, deadline, init_flags, stats) {}

 protected:
101
  virtual vpx_codec_iface_t* CodecInterface() const {
102 103 104 105 106 107 108 109 110 111 112 113 114 115
#if CONFIG_VP8_ENCODER
    return &vpx_codec_vp8_cx_algo;
#else
    return NULL;
#endif
  }
};

class VP8CodecFactory : public CodecFactory {
 public:
  VP8CodecFactory() : CodecFactory() {}

  virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
                                 unsigned long deadline) const {
116 117 118 119 120 121
    return CreateDecoder(cfg, 0, deadline);
  }

  virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
                                 const vpx_codec_flags_t flags,
                                 unsigned long deadline) const {  // NOLINT
122
#if CONFIG_VP8_DECODER
123
    return new VP8Decoder(cfg, flags, deadline);
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
#else
    return NULL;
#endif
  }

  virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
                                 unsigned long deadline,
                                 const unsigned long init_flags,
                                 TwopassStatsStore *stats) const {
#if CONFIG_VP8_ENCODER
    return new VP8Encoder(cfg, deadline, init_flags, stats);
#else
    return NULL;
#endif
  }

  virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
                                               int usage) const {
#if CONFIG_VP8_ENCODER
    return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage);
#else
    return VPX_CODEC_INCAPABLE;
#endif
  }
};

const libvpx_test::VP8CodecFactory kVP8;

152
#define VP8_INSTANTIATE_TEST_CASE(test, ...)\
153 154 155 156
  INSTANTIATE_TEST_CASE_P(VP8, test, \
      ::testing::Combine( \
          ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
              &libvpx_test::kVP8)), \
157
          __VA_ARGS__))
158
#else
159
#define VP8_INSTANTIATE_TEST_CASE(test, ...)
160 161 162 163 164 165 166 167 168 169 170 171
#endif  // CONFIG_VP8


/*
 * VP9 Codec Definitions
 */
#if CONFIG_VP9
class VP9Decoder : public Decoder {
 public:
  VP9Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
      : Decoder(cfg, deadline) {}

172 173 174 175
  VP9Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag,
             unsigned long deadline)  // NOLINT
      : Decoder(cfg, flag, deadline) {}

176
 protected:
177
  virtual vpx_codec_iface_t* CodecInterface() const {
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
#if CONFIG_VP9_DECODER
    return &vpx_codec_vp9_dx_algo;
#else
    return NULL;
#endif
  }
};

class VP9Encoder : public Encoder {
 public:
  VP9Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
             const unsigned long init_flags, TwopassStatsStore *stats)
      : Encoder(cfg, deadline, init_flags, stats) {}

 protected:
193
  virtual vpx_codec_iface_t* CodecInterface() const {
194 195 196 197 198 199 200 201 202 203 204 205 206 207
#if CONFIG_VP9_ENCODER
    return &vpx_codec_vp9_cx_algo;
#else
    return NULL;
#endif
  }
};

class VP9CodecFactory : public CodecFactory {
 public:
  VP9CodecFactory() : CodecFactory() {}

  virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
                                 unsigned long deadline) const {
208 209 210 211 212 213
    return CreateDecoder(cfg, 0, deadline);
  }

  virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
                                 const vpx_codec_flags_t flags,
                                 unsigned long deadline) const {  // NOLINT
214
#if CONFIG_VP9_DECODER
215
    return new VP9Decoder(cfg, flags, deadline);
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
#else
    return NULL;
#endif
  }

  virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
                                 unsigned long deadline,
                                 const unsigned long init_flags,
                                 TwopassStatsStore *stats) const {
#if CONFIG_VP9_ENCODER
    return new VP9Encoder(cfg, deadline, init_flags, stats);
#else
    return NULL;
#endif
  }

  virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
                                               int usage) const {
#if CONFIG_VP9_ENCODER
    return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage);
236 237
#elif CONFIG_VP10_ENCODER
    return vpx_codec_enc_config_default(&vpx_codec_vp10_cx_algo, cfg, usage);
238 239 240 241 242 243 244 245
#else
    return VPX_CODEC_INCAPABLE;
#endif
  }
};

const libvpx_test::VP9CodecFactory kVP9;

246
#define VP9_INSTANTIATE_TEST_CASE(test, ...)\
247 248 249 250
  INSTANTIATE_TEST_CASE_P(VP9, test, \
      ::testing::Combine( \
          ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
               &libvpx_test::kVP9)), \
251
          __VA_ARGS__))
252
#else
253
#define VP9_INSTANTIATE_TEST_CASE(test, ...)
254 255
#endif  // CONFIG_VP9

256 257 258 259 260 261 262 263
/*
 * VP10 Codec Definitions
 */
#if CONFIG_VP10
class VP10Decoder : public Decoder {
 public:
  VP10Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
      : Decoder(cfg, deadline) {}
264

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
  VP10Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag,
              unsigned long deadline)  // NOLINT
      : Decoder(cfg, flag, deadline) {}

 protected:
  virtual vpx_codec_iface_t* CodecInterface() const {
#if CONFIG_VP10_DECODER
    return &vpx_codec_vp10_dx_algo;
#else
    return NULL;
#endif
  }
};

class VP10Encoder : public Encoder {
 public:
  VP10Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
              const unsigned long init_flags, TwopassStatsStore *stats)
      : Encoder(cfg, deadline, init_flags, stats) {}

 protected:
  virtual vpx_codec_iface_t* CodecInterface() const {
#if CONFIG_VP10_ENCODER
    return &vpx_codec_vp10_cx_algo;
#else
    return NULL;
#endif
  }
};

class VP10CodecFactory : public CodecFactory {
 public:
  VP10CodecFactory() : CodecFactory() {}

  virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
                                 unsigned long deadline) const {
    return CreateDecoder(cfg, 0, deadline);
  }
303

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
  virtual Decoder* CreateDecoder(vpx_codec_dec_cfg_t cfg,
                                 const vpx_codec_flags_t flags,
                                 unsigned long deadline) const {  // NOLINT
#if CONFIG_VP10_DECODER
    return new VP10Decoder(cfg, flags, deadline);
#else
    return NULL;
#endif
  }

  virtual Encoder* CreateEncoder(vpx_codec_enc_cfg_t cfg,
                                 unsigned long deadline,
                                 const unsigned long init_flags,
                                 TwopassStatsStore *stats) const {
#if CONFIG_VP10_ENCODER
    return new VP10Encoder(cfg, deadline, init_flags, stats);
#else
    return NULL;
#endif
  }

  virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
                                               int usage) const {
#if CONFIG_VP10_ENCODER
    return vpx_codec_enc_config_default(&vpx_codec_vp10_cx_algo, cfg, usage);
#else
    return VPX_CODEC_INCAPABLE;
#endif
  }
};

const libvpx_test::VP10CodecFactory kVP10;

#define VP10_INSTANTIATE_TEST_CASE(test, ...)\
  INSTANTIATE_TEST_CASE_P(VP10, test, \
      ::testing::Combine( \
          ::testing::Values(static_cast<const libvpx_test::CodecFactory*>( \
               &libvpx_test::kVP10)), \
          __VA_ARGS__))
#else
#define VP10_INSTANTIATE_TEST_CASE(test, ...)
#endif  // CONFIG_VP10

}  // namespace libvpx_test
348
#endif  // TEST_CODEC_FACTORY_H_