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