libvpx_interface.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2018 The WebRTC 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 MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_INTERFACE_H_
  11. #define MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_INTERFACE_H_
  12. #include <stdint.h>
  13. #include <memory>
  14. #include "vpx/vp8cx.h"
  15. #include "vpx/vpx_codec.h"
  16. #include "vpx/vpx_encoder.h"
  17. #include "vpx/vpx_image.h"
  18. namespace webrtc {
  19. // This interface is a proxy to to the static libvpx functions, so that they
  20. // can be mocked for testing. Currently supports VP8 encoder functions.
  21. // TODO(sprang): Extend this to VP8 decoder and VP9 encoder/decoder too.
  22. class LibvpxInterface {
  23. public:
  24. LibvpxInterface() = default;
  25. virtual ~LibvpxInterface() = default;
  26. virtual vpx_image_t* img_alloc(vpx_image_t* img,
  27. vpx_img_fmt_t fmt,
  28. unsigned int d_w,
  29. unsigned int d_h,
  30. unsigned int align) const = 0;
  31. virtual vpx_image_t* img_wrap(vpx_image_t* img,
  32. vpx_img_fmt_t fmt,
  33. unsigned int d_w,
  34. unsigned int d_h,
  35. unsigned int stride_align,
  36. unsigned char* img_data) const = 0;
  37. virtual void img_free(vpx_image_t* img) const = 0;
  38. virtual vpx_codec_err_t codec_enc_config_set(
  39. vpx_codec_ctx_t* ctx,
  40. const vpx_codec_enc_cfg_t* cfg) const = 0;
  41. virtual vpx_codec_err_t codec_enc_config_default(
  42. vpx_codec_iface_t* iface,
  43. vpx_codec_enc_cfg_t* cfg,
  44. unsigned int usage) const = 0;
  45. virtual vpx_codec_err_t codec_enc_init(vpx_codec_ctx_t* ctx,
  46. vpx_codec_iface_t* iface,
  47. const vpx_codec_enc_cfg_t* cfg,
  48. vpx_codec_flags_t flags) const = 0;
  49. virtual vpx_codec_err_t codec_enc_init_multi(vpx_codec_ctx_t* ctx,
  50. vpx_codec_iface_t* iface,
  51. vpx_codec_enc_cfg_t* cfg,
  52. int num_enc,
  53. vpx_codec_flags_t flags,
  54. vpx_rational_t* dsf) const = 0;
  55. virtual vpx_codec_err_t codec_destroy(vpx_codec_ctx_t* ctx) const = 0;
  56. virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
  57. vp8e_enc_control_id ctrl_id,
  58. uint32_t param) const = 0;
  59. virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
  60. vp8e_enc_control_id ctrl_id,
  61. int param) const = 0;
  62. virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
  63. vp8e_enc_control_id ctrl_id,
  64. int* param) const = 0;
  65. virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
  66. vp8e_enc_control_id ctrl_id,
  67. vpx_roi_map* param) const = 0;
  68. virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
  69. vp8e_enc_control_id ctrl_id,
  70. vpx_active_map* param) const = 0;
  71. virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
  72. vp8e_enc_control_id ctrl_id,
  73. vpx_scaling_mode* param) const = 0;
  74. virtual vpx_codec_err_t codec_encode(vpx_codec_ctx_t* ctx,
  75. const vpx_image_t* img,
  76. vpx_codec_pts_t pts,
  77. uint64_t duration,
  78. vpx_enc_frame_flags_t flags,
  79. uint64_t deadline) const = 0;
  80. virtual const vpx_codec_cx_pkt_t* codec_get_cx_data(
  81. vpx_codec_ctx_t* ctx,
  82. vpx_codec_iter_t* iter) const = 0;
  83. virtual const char* codec_error_detail(vpx_codec_ctx_t* ctx) const = 0;
  84. // Returns interface wrapping the actual libvpx functions.
  85. static std::unique_ptr<LibvpxInterface> CreateEncoder();
  86. };
  87. } // namespace webrtc
  88. #endif // MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_INTERFACE_H_