codec_factory.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. #include <tuple>
  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. #include "test/decode_test_driver.h"
  23. #include "test/encode_test_driver.h"
  24. namespace libvpx_test {
  25. const int kCodecFactoryParam = 0;
  26. class CodecFactory {
  27. public:
  28. CodecFactory() {}
  29. virtual ~CodecFactory() {}
  30. virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const = 0;
  31. virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
  32. const vpx_codec_flags_t flags) const = 0;
  33. virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg,
  34. unsigned long deadline,
  35. const unsigned long init_flags,
  36. TwopassStatsStore *stats) const = 0;
  37. virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
  38. int usage) const = 0;
  39. };
  40. /* Provide CodecTestWith<n>Params classes for a variable number of parameters
  41. * to avoid having to include a pointer to the CodecFactory in every test
  42. * definition.
  43. */
  44. template <class T1>
  45. class CodecTestWithParam
  46. : public ::testing::TestWithParam<
  47. std::tuple<const libvpx_test::CodecFactory *, T1> > {};
  48. template <class T1, class T2>
  49. class CodecTestWith2Params
  50. : public ::testing::TestWithParam<
  51. std::tuple<const libvpx_test::CodecFactory *, T1, T2> > {};
  52. template <class T1, class T2, class T3>
  53. class CodecTestWith3Params
  54. : public ::testing::TestWithParam<
  55. std::tuple<const libvpx_test::CodecFactory *, T1, T2, T3> > {};
  56. template <class T1, class T2, class T3, class T4>
  57. class CodecTestWith4Params
  58. : public ::testing::TestWithParam<
  59. std::tuple<const libvpx_test::CodecFactory *, T1, T2, T3, T4> > {};
  60. /*
  61. * VP8 Codec Definitions
  62. */
  63. #if CONFIG_VP8
  64. class VP8Decoder : public Decoder {
  65. public:
  66. explicit VP8Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {}
  67. VP8Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag)
  68. : Decoder(cfg, flag) {}
  69. protected:
  70. virtual vpx_codec_iface_t *CodecInterface() const {
  71. #if CONFIG_VP8_DECODER
  72. return &vpx_codec_vp8_dx_algo;
  73. #else
  74. return NULL;
  75. #endif
  76. }
  77. };
  78. class VP8Encoder : public Encoder {
  79. public:
  80. VP8Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
  81. const unsigned long init_flags, TwopassStatsStore *stats)
  82. : Encoder(cfg, deadline, init_flags, stats) {}
  83. protected:
  84. virtual vpx_codec_iface_t *CodecInterface() const {
  85. #if CONFIG_VP8_ENCODER
  86. return &vpx_codec_vp8_cx_algo;
  87. #else
  88. return NULL;
  89. #endif
  90. }
  91. };
  92. class VP8CodecFactory : public CodecFactory {
  93. public:
  94. VP8CodecFactory() : CodecFactory() {}
  95. virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const {
  96. return CreateDecoder(cfg, 0);
  97. }
  98. virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
  99. const vpx_codec_flags_t flags) const {
  100. #if CONFIG_VP8_DECODER
  101. return new VP8Decoder(cfg, flags);
  102. #else
  103. (void)cfg;
  104. (void)flags;
  105. return NULL;
  106. #endif
  107. }
  108. virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg,
  109. unsigned long deadline,
  110. const unsigned long init_flags,
  111. TwopassStatsStore *stats) const {
  112. #if CONFIG_VP8_ENCODER
  113. return new VP8Encoder(cfg, deadline, init_flags, stats);
  114. #else
  115. (void)cfg;
  116. (void)deadline;
  117. (void)init_flags;
  118. (void)stats;
  119. return NULL;
  120. #endif
  121. }
  122. virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
  123. int usage) const {
  124. #if CONFIG_VP8_ENCODER
  125. return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage);
  126. #else
  127. (void)cfg;
  128. (void)usage;
  129. return VPX_CODEC_INCAPABLE;
  130. #endif
  131. }
  132. };
  133. const libvpx_test::VP8CodecFactory kVP8;
  134. #define VP8_INSTANTIATE_TEST_CASE(test, ...) \
  135. INSTANTIATE_TEST_CASE_P( \
  136. VP8, test, \
  137. ::testing::Combine( \
  138. ::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \
  139. &libvpx_test::kVP8)), \
  140. __VA_ARGS__))
  141. #else
  142. #define VP8_INSTANTIATE_TEST_CASE(test, ...)
  143. #endif // CONFIG_VP8
  144. /*
  145. * VP9 Codec Definitions
  146. */
  147. #if CONFIG_VP9
  148. class VP9Decoder : public Decoder {
  149. public:
  150. explicit VP9Decoder(vpx_codec_dec_cfg_t cfg) : Decoder(cfg) {}
  151. VP9Decoder(vpx_codec_dec_cfg_t cfg, const vpx_codec_flags_t flag)
  152. : Decoder(cfg, flag) {}
  153. protected:
  154. virtual vpx_codec_iface_t *CodecInterface() const {
  155. #if CONFIG_VP9_DECODER
  156. return &vpx_codec_vp9_dx_algo;
  157. #else
  158. return NULL;
  159. #endif
  160. }
  161. };
  162. class VP9Encoder : public Encoder {
  163. public:
  164. VP9Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline,
  165. const unsigned long init_flags, TwopassStatsStore *stats)
  166. : Encoder(cfg, deadline, init_flags, stats) {}
  167. protected:
  168. virtual vpx_codec_iface_t *CodecInterface() const {
  169. #if CONFIG_VP9_ENCODER
  170. return &vpx_codec_vp9_cx_algo;
  171. #else
  172. return NULL;
  173. #endif
  174. }
  175. };
  176. class VP9CodecFactory : public CodecFactory {
  177. public:
  178. VP9CodecFactory() : CodecFactory() {}
  179. virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const {
  180. return CreateDecoder(cfg, 0);
  181. }
  182. virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg,
  183. const vpx_codec_flags_t flags) const {
  184. #if CONFIG_VP9_DECODER
  185. return new VP9Decoder(cfg, flags);
  186. #else
  187. (void)cfg;
  188. (void)flags;
  189. return NULL;
  190. #endif
  191. }
  192. virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg,
  193. unsigned long deadline,
  194. const unsigned long init_flags,
  195. TwopassStatsStore *stats) const {
  196. #if CONFIG_VP9_ENCODER
  197. return new VP9Encoder(cfg, deadline, init_flags, stats);
  198. #else
  199. (void)cfg;
  200. (void)deadline;
  201. (void)init_flags;
  202. (void)stats;
  203. return NULL;
  204. #endif
  205. }
  206. virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg,
  207. int usage) const {
  208. #if CONFIG_VP9_ENCODER
  209. return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage);
  210. #else
  211. (void)cfg;
  212. (void)usage;
  213. return VPX_CODEC_INCAPABLE;
  214. #endif
  215. }
  216. };
  217. const libvpx_test::VP9CodecFactory kVP9;
  218. #define VP9_INSTANTIATE_TEST_CASE(test, ...) \
  219. INSTANTIATE_TEST_CASE_P( \
  220. VP9, test, \
  221. ::testing::Combine( \
  222. ::testing::Values(static_cast<const libvpx_test::CodecFactory *>( \
  223. &libvpx_test::kVP9)), \
  224. __VA_ARGS__))
  225. #else
  226. #define VP9_INSTANTIATE_TEST_CASE(test, ...)
  227. #endif // CONFIG_VP9
  228. } // namespace libvpx_test
  229. #endif // VPX_TEST_CODEC_FACTORY_H_