mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-14 14:20:45 +01:00
Introduce new api to initialize VideoDecoder
Bug: webrtc:13045 Change-Id: If14fa3998176ee07b6f2835745568f70347ccac6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227766 Reviewed-by: Christoffer Rodbro <crodbro@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34694}
This commit is contained in:
parent
029d5d208c
commit
ecc46eff5b
8 changed files with 151 additions and 23 deletions
|
@ -37,6 +37,7 @@ class MockDecodedImageCallback : public DecodedImageCallback {
|
||||||
|
|
||||||
class MockVideoDecoder : public VideoDecoder {
|
class MockVideoDecoder : public VideoDecoder {
|
||||||
public:
|
public:
|
||||||
|
MOCK_METHOD(bool, Configure, (const Settings& settings), (override));
|
||||||
MOCK_METHOD(int32_t,
|
MOCK_METHOD(int32_t,
|
||||||
InitDecode,
|
InitDecode,
|
||||||
(const VideoCodec* codec_settings, int32_t number_of_cores),
|
(const VideoCodec* codec_settings, int32_t number_of_cores),
|
||||||
|
|
|
@ -24,7 +24,10 @@ rtc_source_set("dependency_descriptor") {
|
||||||
"dependency_descriptor.cc",
|
"dependency_descriptor.cc",
|
||||||
"dependency_descriptor.h",
|
"dependency_descriptor.h",
|
||||||
]
|
]
|
||||||
deps = [ "../../../rtc_base:checks" ]
|
deps = [
|
||||||
|
"../../../rtc_base:checks",
|
||||||
|
"../../video:render_resolution",
|
||||||
|
]
|
||||||
absl_deps = [
|
absl_deps = [
|
||||||
"//third_party/abseil-cpp/absl/container:inlined_vector",
|
"//third_party/abseil-cpp/absl/container:inlined_vector",
|
||||||
"//third_party/abseil-cpp/absl/strings",
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
|
|
|
@ -20,30 +20,11 @@
|
||||||
#include "absl/container/inlined_vector.h"
|
#include "absl/container/inlined_vector.h"
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
|
#include "api/video/render_resolution.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
// Structures to build and parse dependency descriptor as described in
|
// Structures to build and parse dependency descriptor as described in
|
||||||
// https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension
|
// https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension
|
||||||
class RenderResolution {
|
|
||||||
public:
|
|
||||||
constexpr RenderResolution() = default;
|
|
||||||
constexpr RenderResolution(int width, int height)
|
|
||||||
: width_(width), height_(height) {}
|
|
||||||
RenderResolution(const RenderResolution&) = default;
|
|
||||||
RenderResolution& operator=(const RenderResolution&) = default;
|
|
||||||
|
|
||||||
friend bool operator==(const RenderResolution& lhs,
|
|
||||||
const RenderResolution& rhs) {
|
|
||||||
return lhs.width_ == rhs.width_ && lhs.height_ == rhs.height_;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr int Width() const { return width_; }
|
|
||||||
constexpr int Height() const { return height_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
int width_ = 0;
|
|
||||||
int height_ = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Relationship of a frame to a Decode target.
|
// Relationship of a frame to a Decode target.
|
||||||
enum class DecodeTargetIndication {
|
enum class DecodeTargetIndication {
|
||||||
|
|
|
@ -112,6 +112,11 @@ rtc_source_set("video_frame_type") {
|
||||||
sources = [ "video_frame_type.h" ]
|
sources = [ "video_frame_type.h" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rtc_source_set("render_resolution") {
|
||||||
|
visibility = [ "*" ]
|
||||||
|
public = [ "render_resolution.h" ]
|
||||||
|
}
|
||||||
|
|
||||||
rtc_library("encoded_image") {
|
rtc_library("encoded_image") {
|
||||||
visibility = [ "*" ]
|
visibility = [ "*" ]
|
||||||
sources = [
|
sources = [
|
||||||
|
|
45
api/video/render_resolution.h
Normal file
45
api/video/render_resolution.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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 API_VIDEO_RENDER_RESOLUTION_H_
|
||||||
|
#define API_VIDEO_RENDER_RESOLUTION_H_
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
class RenderResolution {
|
||||||
|
public:
|
||||||
|
constexpr RenderResolution() = default;
|
||||||
|
constexpr RenderResolution(int width, int height)
|
||||||
|
: width_(width), height_(height) {}
|
||||||
|
RenderResolution(const RenderResolution&) = default;
|
||||||
|
RenderResolution& operator=(const RenderResolution&) = default;
|
||||||
|
|
||||||
|
friend bool operator==(const RenderResolution& lhs,
|
||||||
|
const RenderResolution& rhs) {
|
||||||
|
return lhs.width_ == rhs.width_ && lhs.height_ == rhs.height_;
|
||||||
|
}
|
||||||
|
friend bool operator!=(const RenderResolution& lhs,
|
||||||
|
const RenderResolution& rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool Valid() const { return width_ > 0 && height_ > 0; }
|
||||||
|
|
||||||
|
constexpr int Width() const { return width_; }
|
||||||
|
constexpr int Height() const { return height_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int width_ = 0;
|
||||||
|
int height_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // API_VIDEO_RENDER_RESOLUTION_H_
|
|
@ -50,6 +50,7 @@ rtc_library("video_codecs_api") {
|
||||||
"../../rtc_base/system:rtc_export",
|
"../../rtc_base/system:rtc_export",
|
||||||
"../units:data_rate",
|
"../units:data_rate",
|
||||||
"../video:encoded_image",
|
"../video:encoded_image",
|
||||||
|
"../video:render_resolution",
|
||||||
"../video:video_bitrate_allocation",
|
"../video:video_bitrate_allocation",
|
||||||
"../video:video_codec_constants",
|
"../video:video_codec_constants",
|
||||||
"../video:video_frame",
|
"../video:video_frame",
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
#include "api/video_codecs/video_decoder.h"
|
#include "api/video_codecs/video_decoder.h"
|
||||||
|
|
||||||
|
#include "absl/types/optional.h"
|
||||||
|
#include "api/video/render_resolution.h"
|
||||||
|
#include "api/video/video_codec_type.h"
|
||||||
#include "rtc_base/strings/string_builder.h"
|
#include "rtc_base/strings/string_builder.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
@ -53,4 +56,29 @@ bool VideoDecoder::DecoderInfo::operator==(const DecoderInfo& rhs) const {
|
||||||
implementation_name == rhs.implementation_name;
|
implementation_name == rhs.implementation_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VideoDecoder::Configure(const Settings& settings) {
|
||||||
|
VideoCodec codec_settings = {};
|
||||||
|
codec_settings.buffer_pool_size = settings.buffer_pool_size();
|
||||||
|
RenderResolution max_resolution = settings.max_render_resolution();
|
||||||
|
if (max_resolution.Valid()) {
|
||||||
|
codec_settings.width = max_resolution.Width();
|
||||||
|
codec_settings.height = max_resolution.Height();
|
||||||
|
}
|
||||||
|
codec_settings.codecType = settings.codec_type();
|
||||||
|
return InitDecode(&codec_settings, settings.number_of_cores()) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoDecoder::InitDecode(const VideoCodec* codec_settings,
|
||||||
|
int32_t number_of_cores) {
|
||||||
|
Settings settings;
|
||||||
|
if (codec_settings != nullptr) {
|
||||||
|
settings.set_buffer_pool_size(codec_settings->buffer_pool_size);
|
||||||
|
settings.set_max_render_resolution(
|
||||||
|
{codec_settings->width, codec_settings->height});
|
||||||
|
settings.set_codec_type(codec_settings->codecType);
|
||||||
|
}
|
||||||
|
settings.set_number_of_cores(number_of_cores);
|
||||||
|
return Configure(settings) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
|
@ -15,7 +15,10 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/types/optional.h"
|
||||||
#include "api/video/encoded_image.h"
|
#include "api/video/encoded_image.h"
|
||||||
|
#include "api/video/render_resolution.h"
|
||||||
|
#include "api/video/video_codec_type.h"
|
||||||
#include "api/video/video_frame.h"
|
#include "api/video/video_frame.h"
|
||||||
#include "api/video_codecs/video_codec.h"
|
#include "api/video_codecs/video_codec.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
@ -54,10 +57,53 @@ class RTC_EXPORT VideoDecoder {
|
||||||
bool operator!=(const DecoderInfo& rhs) const { return !(*this == rhs); }
|
bool operator!=(const DecoderInfo& rhs) const { return !(*this == rhs); }
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~VideoDecoder() {}
|
class Settings {
|
||||||
|
public:
|
||||||
|
Settings() = default;
|
||||||
|
Settings(const Settings&) = default;
|
||||||
|
Settings& operator=(const Settings&) = default;
|
||||||
|
~Settings() = default;
|
||||||
|
|
||||||
|
// The size of pool which is used to store video frame buffers inside
|
||||||
|
// decoder. If value isn't present some codec-default value will be used. If
|
||||||
|
// value is present and decoder doesn't have buffer pool the value will be
|
||||||
|
// ignored.
|
||||||
|
absl::optional<int> buffer_pool_size() const;
|
||||||
|
void set_buffer_pool_size(absl::optional<int> value);
|
||||||
|
|
||||||
|
// When valid, user of the VideoDecoder interface shouldn't `Decode`
|
||||||
|
// encoded images with render resolution larger than width and height
|
||||||
|
// specified here.
|
||||||
|
RenderResolution max_render_resolution() const;
|
||||||
|
void set_max_render_resolution(RenderResolution value);
|
||||||
|
|
||||||
|
// Maximum number of cpu cores the decoder is allowed to use in parallel.
|
||||||
|
int number_of_cores() const { return number_of_cores_; }
|
||||||
|
void set_number_of_cores(int value) { number_of_cores_ = value; }
|
||||||
|
|
||||||
|
// Codec of encoded images user of the VideoDecoder interface will `Decode`.
|
||||||
|
VideoCodecType codec_type() const { return codec_type_; }
|
||||||
|
void set_codec_type(VideoCodecType value) { codec_type_ = value; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
absl::optional<int> buffer_pool_size_;
|
||||||
|
RenderResolution max_resolution_;
|
||||||
|
int number_of_cores_ = 1;
|
||||||
|
VideoCodecType codec_type_ = kVideoCodecGeneric;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual ~VideoDecoder() = default;
|
||||||
|
|
||||||
|
// Prepares decoder to handle incoming encoded frames. Can be called multiple
|
||||||
|
// times, in such case only latest `settings` are in effect.
|
||||||
|
// TODO(bugs.webrtc.org/13045): Make pure virtual when implemented by all
|
||||||
|
// derived classes.
|
||||||
|
virtual bool Configure(const Settings& settings);
|
||||||
|
|
||||||
|
// TODO(bugs.webrtc.org/13045): Delete in favor of the Configure function
|
||||||
|
// above.
|
||||||
virtual int32_t InitDecode(const VideoCodec* codec_settings,
|
virtual int32_t InitDecode(const VideoCodec* codec_settings,
|
||||||
int32_t number_of_cores) = 0;
|
int32_t number_of_cores);
|
||||||
|
|
||||||
virtual int32_t Decode(const EncodedImage& input_image,
|
virtual int32_t Decode(const EncodedImage& input_image,
|
||||||
bool missing_frames,
|
bool missing_frames,
|
||||||
|
@ -74,6 +120,24 @@ class RTC_EXPORT VideoDecoder {
|
||||||
virtual const char* ImplementationName() const;
|
virtual const char* ImplementationName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline absl::optional<int> VideoDecoder::Settings::buffer_pool_size() const {
|
||||||
|
return buffer_pool_size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void VideoDecoder::Settings::set_buffer_pool_size(
|
||||||
|
absl::optional<int> value) {
|
||||||
|
buffer_pool_size_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline RenderResolution VideoDecoder::Settings::max_render_resolution() const {
|
||||||
|
return max_resolution_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void VideoDecoder::Settings::set_max_render_resolution(
|
||||||
|
RenderResolution value) {
|
||||||
|
max_resolution_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // API_VIDEO_CODECS_VIDEO_DECODER_H_
|
#endif // API_VIDEO_CODECS_VIDEO_DECODER_H_
|
||||||
|
|
Loading…
Reference in a new issue