blob: 3dea24dd6da73075c3479c89d5d03ed082d281da [file] [log] [blame]
Erik Språng5fbc0e02018-10-04 17:52:36 +02001/*
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
Erik Språng0186d2d2020-12-09 20:58:21 +010011#ifndef MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_
12#define MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_
Erik Språng5fbc0e02018-10-04 17:52:36 +020013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Erik Språng5fbc0e02018-10-04 17:52:36 +020016#include <memory>
17
18#include "vpx/vp8cx.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "vpx/vpx_codec.h"
Erik Språng5fbc0e02018-10-04 17:52:36 +020020#include "vpx/vpx_encoder.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "vpx/vpx_image.h"
Erik Språng5fbc0e02018-10-04 17:52:36 +020022
23namespace webrtc {
24
Erik Språng0186d2d2020-12-09 20:58:21 +010025// This interface is a proxy to the static libvpx functions, so that they
Erik Språng5fbc0e02018-10-04 17:52:36 +020026// can be mocked for testing. Currently supports VP8 encoder functions.
27// TODO(sprang): Extend this to VP8 decoder and VP9 encoder/decoder too.
28class LibvpxInterface {
29 public:
30 LibvpxInterface() = default;
31 virtual ~LibvpxInterface() = default;
32
33 virtual vpx_image_t* img_alloc(vpx_image_t* img,
34 vpx_img_fmt_t fmt,
35 unsigned int d_w,
36 unsigned int d_h,
37 unsigned int align) const = 0;
38 virtual vpx_image_t* img_wrap(vpx_image_t* img,
39 vpx_img_fmt_t fmt,
40 unsigned int d_w,
41 unsigned int d_h,
42 unsigned int stride_align,
43 unsigned char* img_data) const = 0;
44 virtual void img_free(vpx_image_t* img) const = 0;
45
46 virtual vpx_codec_err_t codec_enc_config_set(
47 vpx_codec_ctx_t* ctx,
48 const vpx_codec_enc_cfg_t* cfg) const = 0;
49 virtual vpx_codec_err_t codec_enc_config_default(
50 vpx_codec_iface_t* iface,
51 vpx_codec_enc_cfg_t* cfg,
52 unsigned int usage) const = 0;
53
54 virtual vpx_codec_err_t codec_enc_init(vpx_codec_ctx_t* ctx,
55 vpx_codec_iface_t* iface,
56 const vpx_codec_enc_cfg_t* cfg,
57 vpx_codec_flags_t flags) const = 0;
58 virtual vpx_codec_err_t codec_enc_init_multi(vpx_codec_ctx_t* ctx,
59 vpx_codec_iface_t* iface,
60 vpx_codec_enc_cfg_t* cfg,
61 int num_enc,
62 vpx_codec_flags_t flags,
63 vpx_rational_t* dsf) const = 0;
64 virtual vpx_codec_err_t codec_destroy(vpx_codec_ctx_t* ctx) const = 0;
65
66 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
67 vp8e_enc_control_id ctrl_id,
68 uint32_t param) const = 0;
69 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
70 vp8e_enc_control_id ctrl_id,
71 int param) const = 0;
72 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
73 vp8e_enc_control_id ctrl_id,
74 int* param) const = 0;
75 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
76 vp8e_enc_control_id ctrl_id,
77 vpx_roi_map* param) const = 0;
78 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
79 vp8e_enc_control_id ctrl_id,
80 vpx_active_map* param) const = 0;
81 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
82 vp8e_enc_control_id ctrl_id,
83 vpx_scaling_mode* param) const = 0;
Erik Språngcc027212020-12-13 14:50:59 +010084 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
85 vp8e_enc_control_id ctrl_id,
86 vpx_svc_extra_cfg_t* param) const = 0;
87 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
88 vp8e_enc_control_id ctrl_id,
89 vpx_svc_frame_drop_t* param) const = 0;
90 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
91 vp8e_enc_control_id ctrl_id,
92 void* param) const = 0;
93 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
94 vp8e_enc_control_id ctrl_id,
95 vpx_svc_layer_id_t* param) const = 0;
96 virtual vpx_codec_err_t codec_control(
97 vpx_codec_ctx_t* ctx,
98 vp8e_enc_control_id ctrl_id,
99 vpx_svc_ref_frame_config_t* param) const = 0;
100 virtual vpx_codec_err_t codec_control(
101 vpx_codec_ctx_t* ctx,
102 vp8e_enc_control_id ctrl_id,
103 vpx_svc_spatial_layer_sync_t* param) const = 0;
104 virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
105 vp8e_enc_control_id ctrl_id,
106 vpx_rc_funcs_t* param) const = 0;
Erik Språng5fbc0e02018-10-04 17:52:36 +0200107 virtual vpx_codec_err_t codec_encode(vpx_codec_ctx_t* ctx,
108 const vpx_image_t* img,
109 vpx_codec_pts_t pts,
110 uint64_t duration,
111 vpx_enc_frame_flags_t flags,
112 uint64_t deadline) const = 0;
113
114 virtual const vpx_codec_cx_pkt_t* codec_get_cx_data(
115 vpx_codec_ctx_t* ctx,
116 vpx_codec_iter_t* iter) const = 0;
117
Florent Castellieeedb6e2020-08-19 12:33:26 +0200118 virtual const char* codec_error_detail(vpx_codec_ctx_t* ctx) const = 0;
Erik Språngcc027212020-12-13 14:50:59 +0100119 virtual const char* codec_error(vpx_codec_ctx_t* ctx) const = 0;
120 virtual const char* codec_err_to_string(vpx_codec_err_t err) const = 0;
Florent Castellieeedb6e2020-08-19 12:33:26 +0200121
Erik Språng5fbc0e02018-10-04 17:52:36 +0200122 // Returns interface wrapping the actual libvpx functions.
Erik Språng0186d2d2020-12-09 20:58:21 +0100123 static std::unique_ptr<LibvpxInterface> Create();
Erik Språng5fbc0e02018-10-04 17:52:36 +0200124};
125
126} // namespace webrtc
127
Erik Språng0186d2d2020-12-09 20:58:21 +0100128#endif // MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_