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