diff --git a/api/video_codecs/BUILD.gn b/api/video_codecs/BUILD.gn index ceb8eaf218..4a8a380ecf 100644 --- a/api/video_codecs/BUILD.gn +++ b/api/video_codecs/BUILD.gn @@ -42,6 +42,7 @@ rtc_source_set("video_codecs_api") { "../../rtc_base:checks", "../../rtc_base:rtc_base_approved", "../../rtc_base/system:rtc_export", + "../units:data_rate", "../video:encoded_image", "../video:video_bitrate_allocation", "../video:video_codec_constants", diff --git a/api/video_codecs/video_encoder.cc b/api/video_codecs/video_encoder.cc index 233ca24e49..abdbf8c060 100644 --- a/api/video_codecs/video_encoder.cc +++ b/api/video_codecs/video_encoder.cc @@ -125,6 +125,11 @@ int32_t VideoEncoder::SetRateAllocation( return SetRates(allocation.get_sum_kbps(), framerate); } +void VideoEncoder::SetRates(const RateControlParameters& parameters) { + SetRateAllocation(parameters.bitrate, + static_cast(parameters.framerate_fps + 0.5)); +} + void VideoEncoder::OnPacketLossRateUpdate(float packet_loss_rate) {} void VideoEncoder::OnRttUpdate(int64_t rtt_ms) {} diff --git a/api/video_codecs/video_encoder.h b/api/video_codecs/video_encoder.h index 9ff8faacda..90cd8226b0 100644 --- a/api/video_codecs/video_encoder.h +++ b/api/video_codecs/video_encoder.h @@ -18,6 +18,7 @@ #include "absl/container/inlined_vector.h" #include "absl/types/optional.h" +#include "api/units/data_rate.h" #include "api/video/encoded_image.h" #include "api/video/video_bitrate_allocation.h" #include "api/video/video_codec_constants.h" @@ -192,6 +193,21 @@ class RTC_EXPORT VideoEncoder { fps_allocation[kMaxSpatialLayers]; }; + struct RateControlParameters { + // Target bitrate, per spatial/temporal layer. + // A target bitrate of 0bps indicates a layer should not be encoded at all. + VideoBitrateAllocation bitrate; + // Target framerate, in fps. A value <= 0.0 is invalid and should be + // interpreted as framerate target not available. In this case the encoder + // should fall back to the max framerate specified in |codec_settings| of + // the last InitEncode() call. + double framerate_fps; + // The network bandwidth available for video. This is at least + // |bitrate.get_sum_bps()|, but may be higher if the application is not + // network constrained. + DataRate bandwidth_allocation; + }; + static VideoCodecVP8 GetDefaultVp8Settings(); static VideoCodecVP9 GetDefaultVp9Settings(); static VideoCodecH264 GetDefaultH264Settings(); @@ -249,20 +265,27 @@ class RTC_EXPORT VideoEncoder { const CodecSpecificInfo* codec_specific_info, const std::vector* frame_types); - // Inform the encoder about the new target bit rate. - // - // Input: - // - bitrate : New target bit rate - // - framerate : The target frame rate - // - // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. + // DEPRECATED! Instead use the one below: + // void SetRateAllocation(const VideoBitrateAllocation&, DataRate, uint32) + // For now has a default implementation that call RTC_NOTREACHED(). + // TODO(bugs.webrtc.org/10481): Remove this once all usage is gone. virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate); - // Default fallback: Just use the sum of bitrates as the single target rate. - // TODO(sprang): Remove this default implementation when we remove SetRates(). + // DEPRECATED! Instead, use void SetRates(const RateControlParameters&); + // For now has a default implementation that calls + // int32_t SetRates(uin32_t, uint32_t) with |allocation.get_sum_kbps()| and + // |framerate| as arguments. This will be removed. + // TODO(bugs.webrtc.org/10481): Remove this once all usage is gone. virtual int32_t SetRateAllocation(const VideoBitrateAllocation& allocation, uint32_t framerate); + // Sets rate control parameters: bitrate, framerate, etc. These settings are + // instantaneous (i.e. not moving averages) and should apply from now until + // the next call to SetRates(). + // Default implementation will call SetRateAllocation() with appropriate + // members of |parameters| as parameters. + virtual void SetRates(const RateControlParameters& parameters); + // Inform the encoder when the packet loss rate changes. // // Input: - packet_loss_rate : The packet loss rate (0.0 to 1.0).