codec_factory.h 4.69 KB
Newer Older
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 11 12 13
 */
#ifndef TEST_CODEC_FACTORY_H_
#define TEST_CODEC_FACTORY_H_

14 15 16 17 18
#include "./aom_config.h"
#include "aom/aom_decoder.h"
#include "aom/aom_encoder.h"
#if CONFIG_AV1_ENCODER
#include "aom/aomcx.h"
19
#endif
20 21
#if CONFIG_AV1_DECODER
#include "aom/aomdx.h"
22 23 24 25
#endif

#include "test/decode_test_driver.h"
#include "test/encode_test_driver.h"
26
namespace libaom_test {
27

28 29
const int kCodecFactoryParam = 0;

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

  virtual ~CodecFactory() {}

36
  virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const = 0;
37

38
  virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
39
                                 const aom_codec_flags_t flags) const = 0;
40

41
  virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
42 43 44
                                 const unsigned long init_flags,
                                 TwopassStatsStore *stats) const = 0;

45
  virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
46 47 48 49 50 51 52
                                               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.
 */
clang-format's avatar
clang-format committed
53 54 55
template <class T1>
class CodecTestWithParam
    : public ::testing::TestWithParam<
56
          std::tr1::tuple<const libaom_test::CodecFactory *, T1> > {};
57

clang-format's avatar
clang-format committed
58 59 60
template <class T1, class T2>
class CodecTestWith2Params
    : public ::testing::TestWithParam<
61
          std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2> > {};
62

clang-format's avatar
clang-format committed
63 64 65
template <class T1, class T2, class T3>
class CodecTestWith3Params
    : public ::testing::TestWithParam<
66
          std::tr1::tuple<const libaom_test::CodecFactory *, T1, T2, T3> > {};
67

Jingning Han's avatar
Jingning Han committed
68
/*
69
 * AV1 Codec Definitions
Jingning Han's avatar
Jingning Han committed
70
 */
71 72
#if CONFIG_AV1
class AV1Decoder : public Decoder {
Jingning Han's avatar
Jingning Han committed
73
 public:
74
  explicit AV1Decoder(aom_codec_dec_cfg_t cfg) : Decoder(cfg) {}
75

76 77
  AV1Decoder(aom_codec_dec_cfg_t cfg, const aom_codec_flags_t flag)
      : Decoder(cfg, flag) {}
Jingning Han's avatar
Jingning Han committed
78 79

 protected:
80 81 82
  virtual aom_codec_iface_t *CodecInterface() const {
#if CONFIG_AV1_DECODER
    return &aom_codec_av1_dx_algo;
Jingning Han's avatar
Jingning Han committed
83 84 85 86 87 88
#else
    return NULL;
#endif
  }
};

89
class AV1Encoder : public Encoder {
Jingning Han's avatar
Jingning Han committed
90
 public:
Sean DuBois's avatar
Sean DuBois committed
91 92 93
  AV1Encoder(aom_codec_enc_cfg_t cfg, const uint32_t init_flags,
             TwopassStatsStore *stats)
      : Encoder(cfg, init_flags, stats) {}
Jingning Han's avatar
Jingning Han committed
94 95

 protected:
96 97 98
  virtual aom_codec_iface_t *CodecInterface() const {
#if CONFIG_AV1_ENCODER
    return &aom_codec_av1_cx_algo;
Jingning Han's avatar
Jingning Han committed
99 100 101 102 103 104
#else
    return NULL;
#endif
  }
};

105
class AV1CodecFactory : public CodecFactory {
Jingning Han's avatar
Jingning Han committed
106
 public:
107
  AV1CodecFactory() : CodecFactory() {}
Jingning Han's avatar
Jingning Han committed
108

109 110
  virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg) const {
    return CreateDecoder(cfg, 0);
Jingning Han's avatar
Jingning Han committed
111
  }
112

113
  virtual Decoder *CreateDecoder(aom_codec_dec_cfg_t cfg,
114
                                 const aom_codec_flags_t flags) const {
115
#if CONFIG_AV1_DECODER
116
    return new AV1Decoder(cfg, flags);
Jingning Han's avatar
Jingning Han committed
117
#else
118 119
    (void)cfg;
    (void)flags;
Jingning Han's avatar
Jingning Han committed
120 121 122 123
    return NULL;
#endif
  }

124
  virtual Encoder *CreateEncoder(aom_codec_enc_cfg_t cfg,
Jingning Han's avatar
Jingning Han committed
125 126
                                 const unsigned long init_flags,
                                 TwopassStatsStore *stats) const {
127
#if CONFIG_AV1_ENCODER
Sean DuBois's avatar
Sean DuBois committed
128
    return new AV1Encoder(cfg, init_flags, stats);
Jingning Han's avatar
Jingning Han committed
129
#else
130 131 132
    (void)cfg;
    (void)init_flags;
    (void)stats;
Jingning Han's avatar
Jingning Han committed
133 134 135 136
    return NULL;
#endif
  }

137
  virtual aom_codec_err_t DefaultEncoderConfig(aom_codec_enc_cfg_t *cfg,
Jingning Han's avatar
Jingning Han committed
138
                                               int usage) const {
139 140
#if CONFIG_AV1_ENCODER
    return aom_codec_enc_config_default(&aom_codec_av1_cx_algo, cfg, usage);
Jingning Han's avatar
Jingning Han committed
141
#else
142 143
    (void)cfg;
    (void)usage;
144
    return AOM_CODEC_INCAPABLE;
Jingning Han's avatar
Jingning Han committed
145 146 147 148
#endif
  }
};

149
const libaom_test::AV1CodecFactory kAV1;
Jingning Han's avatar
Jingning Han committed
150

151
#define AV1_INSTANTIATE_TEST_CASE(test, ...)                                \
clang-format's avatar
clang-format committed
152
  INSTANTIATE_TEST_CASE_P(                                                  \
153
      AV1, test,                                                            \
clang-format's avatar
clang-format committed
154
      ::testing::Combine(                                                   \
155
          ::testing::Values(static_cast<const libaom_test::CodecFactory *>( \
156
              &libaom_test::kAV1)),                                         \
Jingning Han's avatar
Jingning Han committed
157 158
          __VA_ARGS__))
#else
159 160
#define AV1_INSTANTIATE_TEST_CASE(test, ...)
#endif  // CONFIG_AV1
Jingning Han's avatar
Jingning Han committed
161

162
}  // namespace libaom_test
163
#endif  // TEST_CODEC_FACTORY_H_