libvpx_interface.h (6421B)
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 11 #ifndef MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_ 12 #define MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_ 13 14 #include <stdint.h> 15 16 #include <memory> 17 18 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h" 19 #include "third_party/libvpx/source/libvpx/vpx/vpx_codec.h" 20 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h" 21 #include "third_party/libvpx/source/libvpx/vpx/vpx_ext_ratectrl.h" 22 #include "third_party/libvpx/source/libvpx/vpx/vpx_image.h" 23 24 namespace webrtc { 25 26 // This interface is a proxy to the static libvpx functions, so that they 27 // can be mocked for testing. Currently supports VP8 encoder functions. 28 // TODO(sprang): Extend this to VP8 decoder and VP9 encoder/decoder too. 29 class LibvpxInterface { 30 public: 31 LibvpxInterface() = default; 32 virtual ~LibvpxInterface() = default; 33 34 virtual vpx_image_t* img_alloc(vpx_image_t* img, 35 vpx_img_fmt_t fmt, 36 unsigned int d_w, 37 unsigned int d_h, 38 unsigned int align) const = 0; 39 virtual vpx_image_t* img_wrap(vpx_image_t* img, 40 vpx_img_fmt_t fmt, 41 unsigned int d_w, 42 unsigned int d_h, 43 unsigned int stride_align, 44 unsigned char* img_data) const = 0; 45 virtual void img_free(vpx_image_t* img) const = 0; 46 47 virtual vpx_codec_err_t codec_enc_config_set( 48 vpx_codec_ctx_t* ctx, 49 const vpx_codec_enc_cfg_t* cfg) const = 0; 50 virtual vpx_codec_err_t codec_enc_config_default( 51 vpx_codec_iface_t* iface, 52 vpx_codec_enc_cfg_t* cfg, 53 unsigned int usage) const = 0; 54 55 virtual vpx_codec_err_t codec_enc_init(vpx_codec_ctx_t* ctx, 56 vpx_codec_iface_t* iface, 57 const vpx_codec_enc_cfg_t* cfg, 58 vpx_codec_flags_t flags) const = 0; 59 virtual vpx_codec_err_t codec_enc_init_multi(vpx_codec_ctx_t* ctx, 60 vpx_codec_iface_t* iface, 61 vpx_codec_enc_cfg_t* cfg, 62 int num_enc, 63 vpx_codec_flags_t flags, 64 vpx_rational_t* dsf) const = 0; 65 virtual vpx_codec_err_t codec_destroy(vpx_codec_ctx_t* ctx) const = 0; 66 67 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 68 vp8e_enc_control_id ctrl_id, 69 uint32_t param) const = 0; 70 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 71 vp8e_enc_control_id ctrl_id, 72 int param) const = 0; 73 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 74 vp8e_enc_control_id ctrl_id, 75 int* param) const = 0; 76 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 77 vp8e_enc_control_id ctrl_id, 78 vpx_roi_map* param) const = 0; 79 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 80 vp8e_enc_control_id ctrl_id, 81 vpx_active_map* param) const = 0; 82 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 83 vp8e_enc_control_id ctrl_id, 84 vpx_scaling_mode* param) const = 0; 85 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 86 vp8e_enc_control_id ctrl_id, 87 vpx_svc_extra_cfg_t* param) const = 0; 88 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 89 vp8e_enc_control_id ctrl_id, 90 vpx_svc_frame_drop_t* param) const = 0; 91 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 92 vp8e_enc_control_id ctrl_id, 93 void* param) const = 0; 94 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 95 vp8e_enc_control_id ctrl_id, 96 vpx_svc_layer_id_t* param) const = 0; 97 virtual vpx_codec_err_t codec_control( 98 vpx_codec_ctx_t* ctx, 99 vp8e_enc_control_id ctrl_id, 100 vpx_svc_ref_frame_config_t* param) const = 0; 101 virtual vpx_codec_err_t codec_control( 102 vpx_codec_ctx_t* ctx, 103 vp8e_enc_control_id ctrl_id, 104 vpx_svc_spatial_layer_sync_t* param) const = 0; 105 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx, 106 vp8e_enc_control_id ctrl_id, 107 vpx_rc_funcs_t* param) const = 0; 108 virtual vpx_codec_err_t codec_encode(vpx_codec_ctx_t* ctx, 109 const vpx_image_t* img, 110 vpx_codec_pts_t pts, 111 uint64_t duration, 112 vpx_enc_frame_flags_t flags, 113 uint64_t deadline) const = 0; 114 115 virtual const vpx_codec_cx_pkt_t* codec_get_cx_data( 116 vpx_codec_ctx_t* ctx, 117 vpx_codec_iter_t* iter) const = 0; 118 119 virtual const char* codec_error_detail(vpx_codec_ctx_t* ctx) const = 0; 120 virtual const char* codec_error(vpx_codec_ctx_t* ctx) const = 0; 121 virtual const char* codec_err_to_string(vpx_codec_err_t err) const = 0; 122 123 // Returns interface wrapping the actual libvpx functions. 124 static std::unique_ptr<LibvpxInterface> Create(); 125 }; 126 127 } // namespace webrtc 128 129 #endif // MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_