blob: fe40dedeca3f4fd93347a337429f82a2c9a93ada [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
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
25// This interface is a proxy to to the static libvpx functions, so that they
26// 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;
84
85 virtual vpx_codec_err_t codec_encode(vpx_codec_ctx_t* ctx,
86 const vpx_image_t* img,
87 vpx_codec_pts_t pts,
88 uint64_t duration,
89 vpx_enc_frame_flags_t flags,
90 uint64_t deadline) const = 0;
91
92 virtual const vpx_codec_cx_pkt_t* codec_get_cx_data(
93 vpx_codec_ctx_t* ctx,
94 vpx_codec_iter_t* iter) const = 0;
95
96 // Returns interface wrapping the actual libvpx functions.
97 static std::unique_ptr<LibvpxInterface> CreateEncoder();
98};
99
100} // namespace webrtc
101
102#endif // MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_INTERFACE_H_