Splits vp9_impl into libvpx_vp9_encoder and libvpx_vp9_decoder.
Also moves the LibvpxVp8Interface from codec/vp8 to codec/interface and drops vp8 from the name. Follow-up CLs will wire up actual usage in the new classes through the interface so that we can unit test them more easily. Bug: webrtc:12274 Change-Id: I95f66e90245d9320e5fc23cdc845fbeb2648b38b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/196522 Commit-Queue: Erik Språng <sprang@webrtc.org> Reviewed-by: Sergey Silkin <ssilkin@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32816}
This commit is contained in:
210
modules/video_coding/codecs/interface/libvpx_interface.cc
Normal file
210
modules/video_coding/codecs/interface/libvpx_interface.cc
Normal file
@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/video_coding/codecs/interface/libvpx_interface.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
class LibvpxFacade : public LibvpxInterface {
|
||||
public:
|
||||
LibvpxFacade() = default;
|
||||
~LibvpxFacade() override = default;
|
||||
|
||||
vpx_image_t* img_alloc(vpx_image_t* img,
|
||||
vpx_img_fmt_t fmt,
|
||||
unsigned int d_w,
|
||||
unsigned int d_h,
|
||||
unsigned int align) const override {
|
||||
return ::vpx_img_alloc(img, fmt, d_w, d_h, align);
|
||||
}
|
||||
|
||||
vpx_image_t* img_wrap(vpx_image_t* img,
|
||||
vpx_img_fmt_t fmt,
|
||||
unsigned int d_w,
|
||||
unsigned int d_h,
|
||||
unsigned int stride_align,
|
||||
unsigned char* img_data) const override {
|
||||
return ::vpx_img_wrap(img, fmt, d_w, d_h, stride_align, img_data);
|
||||
}
|
||||
|
||||
void img_free(vpx_image_t* img) const override { ::vpx_img_free(img); }
|
||||
|
||||
vpx_codec_err_t codec_enc_config_set(
|
||||
vpx_codec_ctx_t* ctx,
|
||||
const vpx_codec_enc_cfg_t* cfg) const override {
|
||||
return ::vpx_codec_enc_config_set(ctx, cfg);
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_enc_config_default(vpx_codec_iface_t* iface,
|
||||
vpx_codec_enc_cfg_t* cfg,
|
||||
unsigned int usage) const override {
|
||||
return ::vpx_codec_enc_config_default(iface, cfg, usage);
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_enc_init(vpx_codec_ctx_t* ctx,
|
||||
vpx_codec_iface_t* iface,
|
||||
const vpx_codec_enc_cfg_t* cfg,
|
||||
vpx_codec_flags_t flags) const override {
|
||||
return ::vpx_codec_enc_init(ctx, iface, cfg, flags);
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_enc_init_multi(vpx_codec_ctx_t* ctx,
|
||||
vpx_codec_iface_t* iface,
|
||||
vpx_codec_enc_cfg_t* cfg,
|
||||
int num_enc,
|
||||
vpx_codec_flags_t flags,
|
||||
vpx_rational_t* dsf) const override {
|
||||
return ::vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf);
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_destroy(vpx_codec_ctx_t* ctx) const override {
|
||||
return ::vpx_codec_destroy(ctx);
|
||||
}
|
||||
|
||||
// For types related to these parameters, see section
|
||||
// "VP8 encoder control function parameter type" in vpx/vp8cx.h.
|
||||
|
||||
vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
uint32_t param) const override {
|
||||
// We need an explicit call for each type since vpx_codec_control is a
|
||||
// macro that gets expanded into another call based on the parameter name.
|
||||
switch (ctrl_id) {
|
||||
case VP8E_SET_ENABLEAUTOALTREF:
|
||||
return vpx_codec_control(ctx, VP8E_SET_ENABLEAUTOALTREF, param);
|
||||
case VP8E_SET_NOISE_SENSITIVITY:
|
||||
return vpx_codec_control(ctx, VP8E_SET_NOISE_SENSITIVITY, param);
|
||||
case VP8E_SET_SHARPNESS:
|
||||
return vpx_codec_control(ctx, VP8E_SET_SHARPNESS, param);
|
||||
case VP8E_SET_STATIC_THRESHOLD:
|
||||
return vpx_codec_control(ctx, VP8E_SET_STATIC_THRESHOLD, param);
|
||||
case VP8E_SET_ARNR_MAXFRAMES:
|
||||
return vpx_codec_control(ctx, VP8E_SET_ARNR_MAXFRAMES, param);
|
||||
case VP8E_SET_ARNR_STRENGTH:
|
||||
return vpx_codec_control(ctx, VP8E_SET_ARNR_STRENGTH, param);
|
||||
case VP8E_SET_ARNR_TYPE:
|
||||
RTC_NOTREACHED() << "VP8E_SET_ARNR_TYPE is deprecated.";
|
||||
return VPX_CODEC_UNSUP_FEATURE;
|
||||
case VP8E_SET_CQ_LEVEL:
|
||||
return vpx_codec_control(ctx, VP8E_SET_CQ_LEVEL, param);
|
||||
case VP8E_SET_MAX_INTRA_BITRATE_PCT:
|
||||
return vpx_codec_control(ctx, VP8E_SET_MAX_INTRA_BITRATE_PCT, param);
|
||||
case VP8E_SET_GF_CBR_BOOST_PCT:
|
||||
return vpx_codec_control(ctx, VP8E_SET_GF_CBR_BOOST_PCT, param);
|
||||
case VP8E_SET_SCREEN_CONTENT_MODE:
|
||||
return vpx_codec_control(ctx, VP8E_SET_SCREEN_CONTENT_MODE, param);
|
||||
default:
|
||||
RTC_NOTREACHED() << "Unsupported libvpx ctrl_id: " << ctrl_id;
|
||||
}
|
||||
return VPX_CODEC_ERROR;
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
int param) const override {
|
||||
switch (ctrl_id) {
|
||||
case VP8E_SET_FRAME_FLAGS:
|
||||
return vpx_codec_control(ctx, VP8E_SET_FRAME_FLAGS, param);
|
||||
case VP8E_SET_TEMPORAL_LAYER_ID:
|
||||
return vpx_codec_control(ctx, VP8E_SET_TEMPORAL_LAYER_ID, param);
|
||||
case VP8E_SET_CPUUSED:
|
||||
return vpx_codec_control(ctx, VP8E_SET_CPUUSED, param);
|
||||
case VP8E_SET_TOKEN_PARTITIONS:
|
||||
return vpx_codec_control(ctx, VP8E_SET_TOKEN_PARTITIONS, param);
|
||||
case VP8E_SET_TUNING:
|
||||
return vpx_codec_control(ctx, VP8E_SET_TUNING, param);
|
||||
|
||||
default:
|
||||
RTC_NOTREACHED() << "Unsupported libvpx ctrl_id: " << ctrl_id;
|
||||
}
|
||||
return VPX_CODEC_ERROR;
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
int* param) const override {
|
||||
switch (ctrl_id) {
|
||||
case VP8E_GET_LAST_QUANTIZER:
|
||||
return vpx_codec_control(ctx, VP8E_GET_LAST_QUANTIZER, param);
|
||||
case VP8E_GET_LAST_QUANTIZER_64:
|
||||
return vpx_codec_control(ctx, VP8E_GET_LAST_QUANTIZER_64, param);
|
||||
default:
|
||||
RTC_NOTREACHED() << "Unsupported libvpx ctrl_id: " << ctrl_id;
|
||||
}
|
||||
return VPX_CODEC_ERROR;
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
vpx_roi_map* param) const override {
|
||||
switch (ctrl_id) {
|
||||
case VP8E_SET_ROI_MAP:
|
||||
return vpx_codec_control(ctx, VP8E_SET_ROI_MAP, param);
|
||||
default:
|
||||
RTC_NOTREACHED() << "Unsupported libvpx ctrl_id: " << ctrl_id;
|
||||
}
|
||||
return VPX_CODEC_ERROR;
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
vpx_active_map* param) const override {
|
||||
switch (ctrl_id) {
|
||||
case VP8E_SET_ACTIVEMAP:
|
||||
return vpx_codec_control(ctx, VP8E_SET_ACTIVEMAP, param);
|
||||
default:
|
||||
RTC_NOTREACHED() << "Unsupported libvpx ctrl_id: " << ctrl_id;
|
||||
}
|
||||
return VPX_CODEC_ERROR;
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
vpx_scaling_mode* param) const override {
|
||||
switch (ctrl_id) {
|
||||
case VP8E_SET_SCALEMODE:
|
||||
return vpx_codec_control(ctx, VP8E_SET_SCALEMODE, param);
|
||||
default:
|
||||
RTC_NOTREACHED() << "Unsupported libvpx ctrl_id: " << ctrl_id;
|
||||
}
|
||||
return VPX_CODEC_ERROR;
|
||||
}
|
||||
|
||||
vpx_codec_err_t codec_encode(vpx_codec_ctx_t* ctx,
|
||||
const vpx_image_t* img,
|
||||
vpx_codec_pts_t pts,
|
||||
uint64_t duration,
|
||||
vpx_enc_frame_flags_t flags,
|
||||
uint64_t deadline) const override {
|
||||
return ::vpx_codec_encode(ctx, img, pts, duration, flags, deadline);
|
||||
}
|
||||
|
||||
const vpx_codec_cx_pkt_t* codec_get_cx_data(
|
||||
vpx_codec_ctx_t* ctx,
|
||||
vpx_codec_iter_t* iter) const override {
|
||||
return ::vpx_codec_get_cx_data(ctx, iter);
|
||||
}
|
||||
|
||||
const char* codec_error_detail(vpx_codec_ctx_t* ctx) const override {
|
||||
return ::vpx_codec_error_detail(ctx);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<LibvpxInterface> LibvpxInterface::Create() {
|
||||
return std::make_unique<LibvpxFacade>();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
104
modules/video_coding/codecs/interface/libvpx_interface.h
Normal file
104
modules/video_coding/codecs/interface/libvpx_interface.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "vpx/vp8cx.h"
|
||||
#include "vpx/vpx_codec.h"
|
||||
#include "vpx/vpx_encoder.h"
|
||||
#include "vpx/vpx_image.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// This interface is a proxy to the static libvpx functions, so that they
|
||||
// can be mocked for testing. Currently supports VP8 encoder functions.
|
||||
// TODO(sprang): Extend this to VP8 decoder and VP9 encoder/decoder too.
|
||||
class LibvpxInterface {
|
||||
public:
|
||||
LibvpxInterface() = default;
|
||||
virtual ~LibvpxInterface() = default;
|
||||
|
||||
virtual vpx_image_t* img_alloc(vpx_image_t* img,
|
||||
vpx_img_fmt_t fmt,
|
||||
unsigned int d_w,
|
||||
unsigned int d_h,
|
||||
unsigned int align) const = 0;
|
||||
virtual vpx_image_t* img_wrap(vpx_image_t* img,
|
||||
vpx_img_fmt_t fmt,
|
||||
unsigned int d_w,
|
||||
unsigned int d_h,
|
||||
unsigned int stride_align,
|
||||
unsigned char* img_data) const = 0;
|
||||
virtual void img_free(vpx_image_t* img) const = 0;
|
||||
|
||||
virtual vpx_codec_err_t codec_enc_config_set(
|
||||
vpx_codec_ctx_t* ctx,
|
||||
const vpx_codec_enc_cfg_t* cfg) const = 0;
|
||||
virtual vpx_codec_err_t codec_enc_config_default(
|
||||
vpx_codec_iface_t* iface,
|
||||
vpx_codec_enc_cfg_t* cfg,
|
||||
unsigned int usage) const = 0;
|
||||
|
||||
virtual vpx_codec_err_t codec_enc_init(vpx_codec_ctx_t* ctx,
|
||||
vpx_codec_iface_t* iface,
|
||||
const vpx_codec_enc_cfg_t* cfg,
|
||||
vpx_codec_flags_t flags) const = 0;
|
||||
virtual vpx_codec_err_t codec_enc_init_multi(vpx_codec_ctx_t* ctx,
|
||||
vpx_codec_iface_t* iface,
|
||||
vpx_codec_enc_cfg_t* cfg,
|
||||
int num_enc,
|
||||
vpx_codec_flags_t flags,
|
||||
vpx_rational_t* dsf) const = 0;
|
||||
virtual vpx_codec_err_t codec_destroy(vpx_codec_ctx_t* ctx) const = 0;
|
||||
|
||||
virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
uint32_t param) const = 0;
|
||||
virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
int param) const = 0;
|
||||
virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
int* param) const = 0;
|
||||
virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
vpx_roi_map* param) const = 0;
|
||||
virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
vpx_active_map* param) const = 0;
|
||||
virtual vpx_codec_err_t codec_control(vpx_codec_ctx_t* ctx,
|
||||
vp8e_enc_control_id ctrl_id,
|
||||
vpx_scaling_mode* param) const = 0;
|
||||
|
||||
virtual vpx_codec_err_t codec_encode(vpx_codec_ctx_t* ctx,
|
||||
const vpx_image_t* img,
|
||||
vpx_codec_pts_t pts,
|
||||
uint64_t duration,
|
||||
vpx_enc_frame_flags_t flags,
|
||||
uint64_t deadline) const = 0;
|
||||
|
||||
virtual const vpx_codec_cx_pkt_t* codec_get_cx_data(
|
||||
vpx_codec_ctx_t* ctx,
|
||||
vpx_codec_iter_t* iter) const = 0;
|
||||
|
||||
virtual const char* codec_error_detail(vpx_codec_ctx_t* ctx) const = 0;
|
||||
|
||||
// Returns interface wrapping the actual libvpx functions.
|
||||
static std::unique_ptr<LibvpxInterface> Create();
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_INTERFACE_LIBVPX_INTERFACE_H_
|
||||
110
modules/video_coding/codecs/interface/mock_libvpx_interface.h
Normal file
110
modules/video_coding/codecs/interface/mock_libvpx_interface.h
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_INTERFACE_MOCK_LIBVPX_INTERFACE_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_INTERFACE_MOCK_LIBVPX_INTERFACE_H_
|
||||
|
||||
#include "modules/video_coding/codecs/interface/libvpx_interface.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class MockLibvpxInterface : public LibvpxInterface {
|
||||
public:
|
||||
MOCK_METHOD(
|
||||
vpx_image_t*,
|
||||
img_alloc,
|
||||
(vpx_image_t*, vpx_img_fmt_t, unsigned int, unsigned int, unsigned int),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_image_t*,
|
||||
img_wrap,
|
||||
(vpx_image_t*,
|
||||
vpx_img_fmt_t,
|
||||
unsigned int,
|
||||
unsigned int,
|
||||
unsigned int,
|
||||
unsigned char*),
|
||||
(const, override));
|
||||
MOCK_METHOD(void, img_free, (vpx_image_t * img), (const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_enc_config_set,
|
||||
(vpx_codec_ctx_t*, const vpx_codec_enc_cfg_t*),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_enc_config_default,
|
||||
(vpx_codec_iface_t*, vpx_codec_enc_cfg_t*, unsigned int),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_enc_init,
|
||||
(vpx_codec_ctx_t*,
|
||||
vpx_codec_iface_t*,
|
||||
const vpx_codec_enc_cfg_t*,
|
||||
vpx_codec_flags_t),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_enc_init_multi,
|
||||
(vpx_codec_ctx_t*,
|
||||
vpx_codec_iface_t*,
|
||||
vpx_codec_enc_cfg_t*,
|
||||
int,
|
||||
vpx_codec_flags_t,
|
||||
vpx_rational_t*),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_destroy,
|
||||
(vpx_codec_ctx_t*),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_control,
|
||||
(vpx_codec_ctx_t*, vp8e_enc_control_id, uint32_t),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_control,
|
||||
(vpx_codec_ctx_t*, vp8e_enc_control_id, int),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_control,
|
||||
(vpx_codec_ctx_t*, vp8e_enc_control_id, int*),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_control,
|
||||
(vpx_codec_ctx_t*, vp8e_enc_control_id, vpx_roi_map*),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_control,
|
||||
(vpx_codec_ctx_t*, vp8e_enc_control_id, vpx_active_map*),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_control,
|
||||
(vpx_codec_ctx_t*, vp8e_enc_control_id, vpx_scaling_mode*),
|
||||
(const, override));
|
||||
MOCK_METHOD(vpx_codec_err_t,
|
||||
codec_encode,
|
||||
(vpx_codec_ctx_t*,
|
||||
const vpx_image_t*,
|
||||
vpx_codec_pts_t,
|
||||
uint64_t,
|
||||
vpx_enc_frame_flags_t,
|
||||
uint64_t),
|
||||
(const, override));
|
||||
MOCK_METHOD(const vpx_codec_cx_pkt_t*,
|
||||
codec_get_cx_data,
|
||||
(vpx_codec_ctx_t*, vpx_codec_iter_t*),
|
||||
(const, override));
|
||||
MOCK_METHOD(const char*,
|
||||
codec_error_detail,
|
||||
(vpx_codec_ctx_t*),
|
||||
(const, override));
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_INTERFACE_MOCK_LIBVPX_INTERFACE_H_
|
||||
Reference in New Issue
Block a user