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:
committed by
WebRTC LUCI CQ
parent
029d5d208c
commit
ecc46eff5b
@ -50,6 +50,7 @@ rtc_library("video_codecs_api") {
|
||||
"../../rtc_base/system:rtc_export",
|
||||
"../units:data_rate",
|
||||
"../video:encoded_image",
|
||||
"../video:render_resolution",
|
||||
"../video:video_bitrate_allocation",
|
||||
"../video:video_codec_constants",
|
||||
"../video:video_frame",
|
||||
|
||||
@ -10,6 +10,9 @@
|
||||
|
||||
#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"
|
||||
|
||||
namespace webrtc {
|
||||
@ -53,4 +56,29 @@ bool VideoDecoder::DecoderInfo::operator==(const DecoderInfo& rhs) const {
|
||||
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
|
||||
|
||||
@ -15,7 +15,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.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_codecs/video_codec.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); }
|
||||
};
|
||||
|
||||
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,
|
||||
int32_t number_of_cores) = 0;
|
||||
int32_t number_of_cores);
|
||||
|
||||
virtual int32_t Decode(const EncodedImage& input_image,
|
||||
bool missing_frames,
|
||||
@ -74,6 +120,24 @@ class RTC_EXPORT VideoDecoder {
|
||||
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
|
||||
|
||||
#endif // API_VIDEO_CODECS_VIDEO_DECODER_H_
|
||||
|
||||
Reference in New Issue
Block a user