From 566124a6df20995484868fdaef524c85e3faa7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Mon, 23 Apr 2018 12:32:22 +0200 Subject: [PATCH] Move BitrateAllocation to api/ and rename it VideoBitrateAllocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the webrtc_common build target does not have visibility set, we cannot easily use BitrateAllocation in other parts of Chromium. This is currently blocking parts of chromium:794608, and I know of other usage outside webrtc already, so moving it to api/ should be warranted. Also, since there's some naming confusion and this class is video specific rename it VideoBitrateAllocation. This also fits with the standard interface for producing these: VideoBitrateAllocator. Bug: chromium:794608 Change-Id: I4c0fae40f9365e860c605a76a4f67ecc9b9cf9fe Reviewed-on: https://webrtc-review.googlesource.com/70783 Reviewed-by: Karl Wiberg Reviewed-by: Niels Moller Commit-Queue: Erik SprÃ¥ng Cr-Commit-Position: refs/heads/master@{#22986} --- BUILD.gn | 1 + api/BUILD.gn | 15 ++ api/video/video_bitrate_allocation.cc | 168 ++++++++++++++++++ api/video/video_bitrate_allocation.h | 85 +++++++++ api/video_codecs/video_encoder.cc | 2 +- api/video_codecs/video_encoder.h | 2 +- call/call_perf_tests.cc | 2 +- common_types.cc | 133 -------------- common_types.h | 60 +------ .../include/video_bitrate_allocator.h | 6 +- media/engine/fakewebrtcvideoengine.h | 2 +- media/engine/scopedvideoencoder.cc | 4 +- media/engine/simulcast_encoder_adapter.cc | 9 +- media/engine/simulcast_encoder_adapter.h | 2 +- .../simulcast_encoder_adapter_unittest.cc | 14 +- .../videoencodersoftwarefallbackwrapper.cc | 2 +- .../videoencodersoftwarefallbackwrapper.h | 4 +- ...encodersoftwarefallbackwrapper_unittest.cc | 4 +- media/engine/vp8_encoder_simulcast_proxy.cc | 2 +- media/engine/vp8_encoder_simulcast_proxy.h | 2 +- modules/rtp_rtcp/include/rtp_rtcp.h | 3 +- modules/rtp_rtcp/mocks/mock_rtp_rtcp.h | 2 +- modules/rtp_rtcp/source/rtcp_receiver.cc | 4 +- .../rtp_rtcp/source/rtcp_receiver_unittest.cc | 6 +- modules/rtp_rtcp/source/rtcp_sender.cc | 3 +- modules/rtp_rtcp/source/rtcp_sender.h | 4 +- .../rtp_rtcp/source/rtcp_sender_unittest.cc | 2 +- .../rtp_rtcp/source/rtcp_transceiver_config.h | 2 +- .../rtp_rtcp/source/rtcp_transceiver_impl.cc | 4 +- .../source/rtcp_transceiver_impl_unittest.cc | 9 +- modules/rtp_rtcp/source/rtp_rtcp_impl.cc | 2 +- modules/rtp_rtcp/source/rtp_rtcp_impl.h | 3 +- .../codecs/h264/h264_encoder_impl.cc | 2 +- .../codecs/h264/h264_encoder_impl.h | 2 +- .../include/multiplex_encoder_adapter.h | 2 +- .../multiplex/multiplex_encoder_adapter.cc | 5 +- .../video_coding/codecs/test/videoprocessor.h | 2 +- .../codecs/test/videoprocessor_unittest.cc | 8 +- .../codecs/vp8/libvpx_vp8_encoder.cc | 4 +- .../codecs/vp8/libvpx_vp8_encoder.h | 2 +- .../codecs/vp8/simulcast_rate_allocator.cc | 8 +- .../codecs/vp8/simulcast_rate_allocator.h | 8 +- .../codecs/vp8/test/vp8_impl_unittest.cc | 2 +- .../codecs/vp9/svc_rate_allocator.cc | 7 +- .../codecs/vp9/svc_rate_allocator.h | 4 +- .../codecs/vp9/svc_rate_allocator_unittest.cc | 14 +- .../codecs/vp9/test/vp9_impl_unittest.cc | 4 +- modules/video_coding/codecs/vp9/vp9_impl.cc | 7 +- modules/video_coding/codecs/vp9/vp9_impl.h | 4 +- modules/video_coding/generic_encoder.cc | 5 +- modules/video_coding/generic_encoder.h | 2 +- .../include/mock/mock_video_codec_interface.h | 2 +- .../default_video_bitrate_allocator.cc | 4 +- .../utility/default_video_bitrate_allocator.h | 4 +- ...efault_video_bitrate_allocator_unittest.cc | 13 +- .../simulcast_rate_allocator_unittest.cc | 15 +- .../video_codec_initializer_unittest.cc | 27 +-- modules/video_coding/video_sender.cc | 6 +- modules/video_coding/video_sender_unittest.cc | 6 +- sdk/android/src/jni/androidmediaencoder.cc | 4 +- sdk/android/src/jni/videoencoderwrapper.cc | 4 +- sdk/android/src/jni/videoencoderwrapper.h | 4 +- test/configurable_frame_size_encoder.cc | 2 +- test/configurable_frame_size_encoder.h | 2 +- test/encoder_proxy_factory.h | 2 +- test/fake_encoder.cc | 5 +- test/fake_encoder.h | 4 +- video/end_to_end_tests/bandwidth_tests.cc | 2 +- video/payload_router.cc | 8 +- video/payload_router.h | 2 +- video/payload_router_unittest.cc | 14 +- video/video_send_stream_impl.cc | 2 +- video/video_send_stream_impl.h | 3 +- video/video_send_stream_tests.cc | 6 +- video/video_stream_encoder_unittest.cc | 4 +- 75 files changed, 452 insertions(+), 348 deletions(-) create mode 100644 api/video/video_bitrate_allocation.cc create mode 100644 api/video/video_bitrate_allocation.h diff --git a/BUILD.gn b/BUILD.gn index 797467c49e..1c3d55d62b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -384,6 +384,7 @@ rtc_static_library("webrtc_common") { ":typedefs", "api:array_view", "api:optional", + "api:video_bitrate_allocation", "rtc_base:checks", "rtc_base:deprecation", "rtc_base:stringutils", diff --git a/api/BUILD.gn b/api/BUILD.gn index 7690624200..94ed84e090 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -343,6 +343,21 @@ rtc_source_set("libjingle_peerconnection_test_api") { ] } +rtc_source_set("video_bitrate_allocation") { + visibility = [ "*" ] + sources = [ + "video/video_bitrate_allocation.cc", + "video/video_bitrate_allocation.h", + ] + deps = [ + ":optional", + "..:typedefs", + "../rtc_base:checks", + "../rtc_base:safe_conversions", + "../rtc_base:stringutils", + ] +} + if (rtc_include_tests) { if (rtc_enable_protobuf) { rtc_source_set("audioproc_f_api") { diff --git a/api/video/video_bitrate_allocation.cc b/api/video/video_bitrate_allocation.cc new file mode 100644 index 0000000000..059eb8f403 --- /dev/null +++ b/api/video/video_bitrate_allocation.cc @@ -0,0 +1,168 @@ +/* + * 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 "api/video/video_bitrate_allocation.h" + +#include + +#include "rtc_base/checks.h" +#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/strings/string_builder.h" +#include "rtc_base/stringutils.h" + +namespace webrtc { + +VideoBitrateAllocation::VideoBitrateAllocation() : sum_(0) {} + +bool VideoBitrateAllocation::SetBitrate(size_t spatial_index, + size_t temporal_index, + uint32_t bitrate_bps) { + RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); + RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); + int64_t new_bitrate_sum_bps = sum_; + rtc::Optional& layer_bitrate = + bitrates_[spatial_index][temporal_index]; + if (layer_bitrate) { + RTC_DCHECK_LE(*layer_bitrate, sum_); + new_bitrate_sum_bps -= *layer_bitrate; + } + new_bitrate_sum_bps += bitrate_bps; + if (new_bitrate_sum_bps > kMaxBitrateBps) + return false; + + layer_bitrate = bitrate_bps; + sum_ = rtc::dchecked_cast(new_bitrate_sum_bps); + return true; +} + +bool VideoBitrateAllocation::HasBitrate(size_t spatial_index, + size_t temporal_index) const { + RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); + RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); + return bitrates_[spatial_index][temporal_index].has_value(); +} + +uint32_t VideoBitrateAllocation::GetBitrate(size_t spatial_index, + size_t temporal_index) const { + RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); + RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); + return bitrates_[spatial_index][temporal_index].value_or(0); +} + +// Whether the specific spatial layers has the bitrate set in any of its +// temporal layers. +bool VideoBitrateAllocation::IsSpatialLayerUsed(size_t spatial_index) const { + RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); + for (size_t i = 0; i < kMaxTemporalStreams; ++i) { + if (bitrates_[spatial_index][i].has_value()) + return true; + } + return false; +} + +// Get the sum of all the temporal layer for a specific spatial layer. +uint32_t VideoBitrateAllocation::GetSpatialLayerSum( + size_t spatial_index) const { + RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); + return GetTemporalLayerSum(spatial_index, kMaxTemporalStreams - 1); +} + +uint32_t VideoBitrateAllocation::GetTemporalLayerSum( + size_t spatial_index, + size_t temporal_index) const { + RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); + RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); + uint32_t sum = 0; + for (size_t i = 0; i <= temporal_index; ++i) { + sum += bitrates_[spatial_index][i].value_or(0); + } + return sum; +} + +std::vector VideoBitrateAllocation::GetTemporalLayerAllocation( + size_t spatial_index) const { + RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); + std::vector temporal_rates; + + // Find the highest temporal layer with a defined bitrate in order to + // determine the size of the temporal layer allocation. + for (size_t i = kMaxTemporalStreams; i > 0; --i) { + if (bitrates_[spatial_index][i - 1].has_value()) { + temporal_rates.resize(i); + break; + } + } + + for (size_t i = 0; i < temporal_rates.size(); ++i) { + temporal_rates[i] = bitrates_[spatial_index][i].value_or(0); + } + + return temporal_rates; +} + +bool VideoBitrateAllocation::operator==( + const VideoBitrateAllocation& other) const { + for (size_t si = 0; si < kMaxSpatialLayers; ++si) { + for (size_t ti = 0; ti < kMaxTemporalStreams; ++ti) { + if (bitrates_[si][ti] != other.bitrates_[si][ti]) + return false; + } + } + return true; +} + +std::string VideoBitrateAllocation::ToString() const { + if (sum_ == 0) + return "VideoBitrateAllocation [ [] ]"; + + // Max string length in practice is 260, but let's have some overhead and + // round up to nearest power of two. + char string_buf[512]; + rtc::SimpleStringBuilder ssb(string_buf); + + ssb << "VideoBitrateAllocation ["; + uint32_t spatial_cumulator = 0; + for (size_t si = 0; si < kMaxSpatialLayers; ++si) { + RTC_DCHECK_LE(spatial_cumulator, sum_); + if (spatial_cumulator == sum_) + break; + + const uint32_t layer_sum = GetSpatialLayerSum(si); + if (layer_sum == sum_) { + ssb << " ["; + } else { + if (si > 0) + ssb << ","; + ssb << '\n' << " ["; + } + spatial_cumulator += layer_sum; + + uint32_t temporal_cumulator = 0; + for (size_t ti = 0; ti < kMaxTemporalStreams; ++ti) { + RTC_DCHECK_LE(temporal_cumulator, layer_sum); + if (temporal_cumulator == layer_sum) + break; + + if (ti > 0) + ssb << ", "; + + uint32_t bitrate = bitrates_[si][ti].value_or(0); + ssb << bitrate; + temporal_cumulator += bitrate; + } + ssb << "]"; + } + + RTC_DCHECK_EQ(spatial_cumulator, sum_); + ssb << " ]"; + return ssb.str(); +} + +} // namespace webrtc diff --git a/api/video/video_bitrate_allocation.h b/api/video/video_bitrate_allocation.h new file mode 100644 index 0000000000..b748b67fd0 --- /dev/null +++ b/api/video/video_bitrate_allocation.h @@ -0,0 +1,85 @@ +/* + * 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 API_VIDEO_VIDEO_BITRATE_ALLOCATION_H_ +#define API_VIDEO_VIDEO_BITRATE_ALLOCATION_H_ + +#include +#include +#include + +#include "api/optional.h" +#include "typedefs.h" // NOLINT(build/include) + +namespace webrtc { + +// TODO(sprang): Move back to common_types when include of this is removed. +enum : int { kMaxSimulcastStreams = 4 }; +enum : int { kMaxSpatialLayers = 5 }; +enum : int { kMaxTemporalStreams = 4 }; + +// Class that describes how video bitrate, in bps, is allocated across temporal +// and spatial layers. Not that bitrates are NOT cumulative. Depending on if +// layers are dependent or not, it is up to the user to aggregate. +// For each index, the bitrate can also both set and unset. This is used with a +// set bps = 0 to signal an explicit "turn off" signal. +class VideoBitrateAllocation { + public: + static constexpr uint32_t kMaxBitrateBps = + std::numeric_limits::max(); + VideoBitrateAllocation(); + + bool SetBitrate(size_t spatial_index, + size_t temporal_index, + uint32_t bitrate_bps); + + bool HasBitrate(size_t spatial_index, size_t temporal_index) const; + + uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const; + + // Whether the specific spatial layers has the bitrate set in any of its + // temporal layers. + bool IsSpatialLayerUsed(size_t spatial_index) const; + + // Get the sum of all the temporal layer for a specific spatial layer. + uint32_t GetSpatialLayerSum(size_t spatial_index) const; + + // Sum of bitrates of temporal layers, from layer 0 to |temporal_index| + // inclusive, of specified spatial layer |spatial_index|. Bitrates of lower + // spatial layers are not included. + uint32_t GetTemporalLayerSum(size_t spatial_index, + size_t temporal_index) const; + + // Returns a vector of the temporal layer bitrates for the specific spatial + // layer. Length of the returned vector is cropped to the highest temporal + // layer with a defined bitrate. + std::vector GetTemporalLayerAllocation(size_t spatial_index) const; + + uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates. + uint32_t get_sum_kbps() const { + // Round down to not exceed the allocated bitrate. + return sum_ / 1000; + } + + bool operator==(const VideoBitrateAllocation& other) const; + inline bool operator!=(const VideoBitrateAllocation& other) const { + return !(*this == other); + } + + std::string ToString() const; + + private: + uint32_t sum_; + rtc::Optional bitrates_[kMaxSpatialLayers][kMaxTemporalStreams]; +}; + +} // namespace webrtc + +#endif // API_VIDEO_VIDEO_BITRATE_ALLOCATION_H_ diff --git a/api/video_codecs/video_encoder.cc b/api/video_codecs/video_encoder.cc index 1abee76548..4de6829fa8 100644 --- a/api/video_codecs/video_encoder.cc +++ b/api/video_codecs/video_encoder.cc @@ -86,7 +86,7 @@ int32_t VideoEncoder::SetRates(uint32_t bitrate, uint32_t framerate) { } int32_t VideoEncoder::SetRateAllocation( - const BitrateAllocation& allocation, + const VideoBitrateAllocation& allocation, uint32_t framerate) { return SetRates(allocation.get_sum_kbps(), framerate); } diff --git a/api/video_codecs/video_encoder.h b/api/video_codecs/video_encoder.h index 583c8acc51..6218741e0c 100644 --- a/api/video_codecs/video_encoder.h +++ b/api/video_codecs/video_encoder.h @@ -197,7 +197,7 @@ class VideoEncoder { // Default fallback: Just use the sum of bitrates as the single target rate. // TODO(sprang): Remove this default implementation when we remove SetRates(). - virtual int32_t SetRateAllocation(const BitrateAllocation& allocation, + virtual int32_t SetRateAllocation(const VideoBitrateAllocation& allocation, uint32_t framerate); // Any encoder implementation wishing to use the WebRTC provided diff --git a/call/call_perf_tests.cc b/call/call_perf_tests.cc index 6520e6fcf9..ba48d9aace 100644 --- a/call/call_perf_tests.cc +++ b/call/call_perf_tests.cc @@ -716,7 +716,7 @@ TEST_F(CallPerfTest, MAYBE_KeepsHighBitrateWhenReconfiguringSender) { return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); } - int32_t SetRateAllocation(const BitrateAllocation& rate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation, uint32_t framerate) override { last_set_bitrate_kbps_ = rate_allocation.get_sum_kbps(); if (encoder_inits_ == 1 && diff --git a/common_types.cc b/common_types.cc index 5e0dc934f8..20766cd0f9 100644 --- a/common_types.cc +++ b/common_types.cc @@ -174,137 +174,4 @@ VideoCodecType PayloadStringToCodecType(const std::string& name) { return kVideoCodecGeneric; } -const uint32_t BitrateAllocation::kMaxBitrateBps = - std::numeric_limits::max(); - -BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{}, has_bitrate_{} {} - -bool BitrateAllocation::SetBitrate(size_t spatial_index, - size_t temporal_index, - uint32_t bitrate_bps) { - RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); - RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); - RTC_CHECK_LE(bitrates_[spatial_index][temporal_index], sum_); - uint64_t new_bitrate_sum_bps = sum_; - new_bitrate_sum_bps -= bitrates_[spatial_index][temporal_index]; - new_bitrate_sum_bps += bitrate_bps; - if (new_bitrate_sum_bps > kMaxBitrateBps) - return false; - - bitrates_[spatial_index][temporal_index] = bitrate_bps; - has_bitrate_[spatial_index][temporal_index] = true; - sum_ = static_cast(new_bitrate_sum_bps); - return true; -} - -bool BitrateAllocation::HasBitrate(size_t spatial_index, - size_t temporal_index) const { - RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); - RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); - return has_bitrate_[spatial_index][temporal_index]; -} - -uint32_t BitrateAllocation::GetBitrate(size_t spatial_index, - size_t temporal_index) const { - RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); - RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); - return bitrates_[spatial_index][temporal_index]; -} - -// Whether the specific spatial layers has the bitrate set in any of its -// temporal layers. -bool BitrateAllocation::IsSpatialLayerUsed(size_t spatial_index) const { - RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); - for (int i = 0; i < kMaxTemporalStreams; ++i) { - if (has_bitrate_[spatial_index][i]) - return true; - } - return false; -} - -// Get the sum of all the temporal layer for a specific spatial layer. -uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const { - RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); - return GetTemporalLayerSum(spatial_index, kMaxTemporalStreams - 1); -} - -uint32_t BitrateAllocation::GetTemporalLayerSum(size_t spatial_index, - size_t temporal_index) const { - RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); - RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); - uint32_t sum = 0; - for (size_t i = 0; i <= temporal_index; ++i) { - sum += bitrates_[spatial_index][i]; - } - return sum; -} - -std::vector BitrateAllocation::GetTemporalLayerAllocation( - size_t spatial_index) const { - RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); - std::vector temporal_rates; - - // Find the highest temporal layer with a defined bitrate in order to - // determine the size of the temporal layer allocation. - for (size_t i = kMaxTemporalStreams; i > 0; --i) { - if (has_bitrate_[spatial_index][i - 1]) { - temporal_rates.resize(i); - break; - } - } - - for (size_t i = 0; i < temporal_rates.size(); ++i) { - temporal_rates[i] = bitrates_[spatial_index][i]; - } - - return temporal_rates; -} - -std::string BitrateAllocation::ToString() const { - if (sum_ == 0) - return "BitrateAllocation [ [] ]"; - - // Max string length in practice is 260, but let's have some overhead and - // round up to nearest power of two. - char string_buf[512]; - rtc::SimpleStringBuilder ssb(string_buf); - - ssb << "BitrateAllocation ["; - uint32_t spatial_cumulator = 0; - for (int si = 0; si < kMaxSpatialLayers; ++si) { - RTC_DCHECK_LE(spatial_cumulator, sum_); - if (spatial_cumulator == sum_) - break; - - const uint32_t layer_sum = GetSpatialLayerSum(si); - if (layer_sum == sum_) { - ssb << " ["; - } else { - if (si > 0) - ssb << ","; - ssb << '\n' << " ["; - } - spatial_cumulator += layer_sum; - - uint32_t temporal_cumulator = 0; - for (int ti = 0; ti < kMaxTemporalStreams; ++ti) { - RTC_DCHECK_LE(temporal_cumulator, layer_sum); - if (temporal_cumulator == layer_sum) - break; - - if (ti > 0) - ssb << ", "; - - uint32_t bitrate = bitrates_[si][ti]; - ssb << bitrate; - temporal_cumulator += bitrate; - } - ssb << "]"; - } - - RTC_DCHECK_EQ(spatial_cumulator, sum_); - ssb << " ]"; - return ssb.str(); -} - } // namespace webrtc diff --git a/common_types.h b/common_types.h index 140854c247..a6ec5f24b1 100644 --- a/common_types.h +++ b/common_types.h @@ -18,6 +18,8 @@ #include "api/array_view.h" #include "api/optional.h" +// TODO(sprang): Remove this include when all usage includes it directly. +#include "api/video/video_bitrate_allocation.h" #include "rtc_base/checks.h" #include "rtc_base/deprecation.h" #include "typedefs.h" // NOLINT(build/include) @@ -338,10 +340,6 @@ enum class VideoType { }; // Video codec -enum { kMaxSimulcastStreams = 4 }; -enum { kMaxSpatialLayers = 5 }; -enum { kMaxTemporalStreams = 4 }; - enum VideoCodecComplexity { kComplexityNormal = 0, kComplexityHigh = 1, @@ -519,58 +517,8 @@ class VideoCodec { VideoCodecUnion codec_specific_; }; -class BitrateAllocation { - public: - static const uint32_t kMaxBitrateBps; - BitrateAllocation(); - - bool SetBitrate(size_t spatial_index, - size_t temporal_index, - uint32_t bitrate_bps); - - bool HasBitrate(size_t spatial_index, size_t temporal_index) const; - - uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const; - - // Whether the specific spatial layers has the bitrate set in any of its - // temporal layers. - bool IsSpatialLayerUsed(size_t spatial_index) const; - - // Get the sum of all the temporal layer for a specific spatial layer. - uint32_t GetSpatialLayerSum(size_t spatial_index) const; - - // Sum of bitrates of temporal layers, from layer 0 to |temporal_index| - // inclusive, of specified spatial layer |spatial_index|. Bitrates of lower - // spatial layers are not included. - uint32_t GetTemporalLayerSum(size_t spatial_index, - size_t temporal_index) const; - - // Returns a vector of the temporal layer bitrates for the specific spatial - // layer. Length of the returned vector is cropped to the highest temporal - // layer with a defined bitrate. - std::vector GetTemporalLayerAllocation(size_t spatial_index) const; - - uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates. - uint32_t get_sum_kbps() const { - // Round down to not exceed the allocated bitrate. - return sum_ / 1000; - } - - inline bool operator==(const BitrateAllocation& other) const { - return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0; - } - inline bool operator!=(const BitrateAllocation& other) const { - return !(*this == other); - } - - // Expensive, please use only in tests. - std::string ToString() const; - - private: - uint32_t sum_; - uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams]; - bool has_bitrate_[kMaxSpatialLayers][kMaxTemporalStreams]; -}; +// TODO(sprang): Remove this when downstream projects have been updated. +using BitrateAllocation = VideoBitrateAllocation; // Bandwidth over-use detector options. These are used to drive // experimentation with bandwidth estimation parameters. diff --git a/common_video/include/video_bitrate_allocator.h b/common_video/include/video_bitrate_allocator.h index 597b6259a4..be7cd649d0 100644 --- a/common_video/include/video_bitrate_allocator.h +++ b/common_video/include/video_bitrate_allocator.h @@ -20,8 +20,8 @@ class VideoBitrateAllocator { VideoBitrateAllocator() {} virtual ~VideoBitrateAllocator() {} - virtual BitrateAllocation GetAllocation(uint32_t total_bitrate, - uint32_t framerate) = 0; + virtual VideoBitrateAllocation GetAllocation(uint32_t total_bitrate, + uint32_t framerate) = 0; virtual uint32_t GetPreferredBitrateBps(uint32_t framerate) = 0; }; @@ -31,7 +31,7 @@ class VideoBitrateAllocationObserver { virtual ~VideoBitrateAllocationObserver() {} virtual void OnBitrateAllocationUpdated( - const BitrateAllocation& allocation) = 0; + const VideoBitrateAllocation& allocation) = 0; }; } // namespace webrtc diff --git a/media/engine/fakewebrtcvideoengine.h b/media/engine/fakewebrtcvideoengine.h index 2153f6be38..3705a83dfd 100644 --- a/media/engine/fakewebrtcvideoengine.h +++ b/media/engine/fakewebrtcvideoengine.h @@ -159,7 +159,7 @@ class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder { return WEBRTC_VIDEO_CODEC_OK; } - int32_t SetRateAllocation(const webrtc::BitrateAllocation& allocation, + int32_t SetRateAllocation(const webrtc::VideoBitrateAllocation& allocation, uint32_t framerate) override { return WEBRTC_VIDEO_CODEC_OK; } diff --git a/media/engine/scopedvideoencoder.cc b/media/engine/scopedvideoencoder.cc index 41d3bb05a5..2a1d93d3db 100644 --- a/media/engine/scopedvideoencoder.cc +++ b/media/engine/scopedvideoencoder.cc @@ -34,7 +34,7 @@ class ScopedVideoEncoder : public webrtc::VideoEncoder { const std::vector* frame_types) override; int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; - int32_t SetRateAllocation(const webrtc::BitrateAllocation& allocation, + int32_t SetRateAllocation(const webrtc::VideoBitrateAllocation& allocation, uint32_t framerate) override; ScalingSettings GetScalingSettings() const override; bool SupportsNativeHandle() const override; @@ -84,7 +84,7 @@ int32_t ScopedVideoEncoder::SetRates(uint32_t bitrate, uint32_t framerate) { } int32_t ScopedVideoEncoder::SetRateAllocation( - const webrtc::BitrateAllocation& allocation, + const webrtc::VideoBitrateAllocation& allocation, uint32_t framerate) { return encoder_->SetRateAllocation(allocation, framerate); } diff --git a/media/engine/simulcast_encoder_adapter.cc b/media/engine/simulcast_encoder_adapter.cc index e33666f152..88c0a38470 100644 --- a/media/engine/simulcast_encoder_adapter.cc +++ b/media/engine/simulcast_encoder_adapter.cc @@ -178,7 +178,7 @@ int SimulcastEncoderAdapter::InitEncode(const VideoCodec* inst, codec_ = *inst; SimulcastRateAllocator rate_allocator(codec_); - BitrateAllocation allocation = rate_allocator.GetAllocation( + VideoBitrateAllocation allocation = rate_allocator.GetAllocation( codec_.startBitrate * 1000, codec_.maxFramerate); std::vector start_bitrates; for (int i = 0; i < kMaxSimulcastStreams; ++i) { @@ -367,8 +367,9 @@ int SimulcastEncoderAdapter::SetChannelParameters(uint32_t packet_loss, return WEBRTC_VIDEO_CODEC_OK; } -int SimulcastEncoderAdapter::SetRateAllocation(const BitrateAllocation& bitrate, - uint32_t new_framerate) { +int SimulcastEncoderAdapter::SetRateAllocation( + const VideoBitrateAllocation& bitrate, + uint32_t new_framerate) { RTC_DCHECK_CALLED_SEQUENTIALLY(&encoder_queue_); if (!Initialized()) { @@ -410,7 +411,7 @@ int SimulcastEncoderAdapter::SetRateAllocation(const BitrateAllocation& bitrate, // Slice the temporal layers out of the full allocation and pass it on to // the encoder handling the current simulcast stream. - BitrateAllocation stream_allocation; + VideoBitrateAllocation stream_allocation; for (int i = 0; i < kMaxTemporalStreams; ++i) { if (bitrate.HasBitrate(stream_idx, i)) { stream_allocation.SetBitrate(0, i, bitrate.GetBitrate(stream_idx, i)); diff --git a/media/engine/simulcast_encoder_adapter.h b/media/engine/simulcast_encoder_adapter.h index 240a621134..f3361501c4 100644 --- a/media/engine/simulcast_encoder_adapter.h +++ b/media/engine/simulcast_encoder_adapter.h @@ -47,7 +47,7 @@ class SimulcastEncoderAdapter : public VP8Encoder { const std::vector* frame_types) override; int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int SetRateAllocation(const BitrateAllocation& bitrate, + int SetRateAllocation(const VideoBitrateAllocation& bitrate, uint32_t new_framerate) override; // Eventual handler for the contained encoders' EncodedImageCallbacks, but diff --git a/media/engine/simulcast_encoder_adapter_unittest.cc b/media/engine/simulcast_encoder_adapter_unittest.cc index b3a6bd49c7..2930e25d66 100644 --- a/media/engine/simulcast_encoder_adapter_unittest.cc +++ b/media/engine/simulcast_encoder_adapter_unittest.cc @@ -150,7 +150,7 @@ class MockVideoEncoder : public VideoEncoder { MOCK_METHOD0(Release, int32_t()); - int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation, uint32_t framerate) { last_set_bitrate_ = bitrate_allocation; return 0; @@ -184,7 +184,7 @@ class MockVideoEncoder : public VideoEncoder { init_encode_return_value_ = value; } - BitrateAllocation last_set_bitrate() const { return last_set_bitrate_; } + VideoBitrateAllocation last_set_bitrate() const { return last_set_bitrate_; } MOCK_CONST_METHOD0(ImplementationName, const char*()); @@ -192,7 +192,7 @@ class MockVideoEncoder : public VideoEncoder { MockVideoEncoderFactory* const factory_; bool supports_native_handle_ = false; int32_t init_encode_return_value_ = 0; - BitrateAllocation last_set_bitrate_; + VideoBitrateAllocation last_set_bitrate_; VideoCodec codec_; EncodedImageCallback* callback_; @@ -679,22 +679,22 @@ TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) { rate_allocator_.reset(new SimulcastRateAllocator(codec_)); // Above min should be respected. - BitrateAllocation target_bitrate = + VideoBitrateAllocation target_bitrate = rate_allocator_->GetAllocation(codec_.minBitrate * 1000, 30); adapter_->SetRateAllocation(target_bitrate, 30); EXPECT_EQ(target_bitrate, helper_->factory()->encoders()[0]->last_set_bitrate()); // Below min but non-zero should be replaced with the min bitrate. - BitrateAllocation too_low_bitrate = + VideoBitrateAllocation too_low_bitrate = rate_allocator_->GetAllocation((codec_.minBitrate - 1) * 1000, 30); adapter_->SetRateAllocation(too_low_bitrate, 30); EXPECT_EQ(target_bitrate, helper_->factory()->encoders()[0]->last_set_bitrate()); // Zero should be passed on as is, since it means "pause". - adapter_->SetRateAllocation(BitrateAllocation(), 30); - EXPECT_EQ(BitrateAllocation(), + adapter_->SetRateAllocation(VideoBitrateAllocation(), 30); + EXPECT_EQ(VideoBitrateAllocation(), helper_->factory()->encoders()[0]->last_set_bitrate()); } diff --git a/media/engine/videoencodersoftwarefallbackwrapper.cc b/media/engine/videoencodersoftwarefallbackwrapper.cc index 50bc3f2ab7..bc60fde030 100644 --- a/media/engine/videoencodersoftwarefallbackwrapper.cc +++ b/media/engine/videoencodersoftwarefallbackwrapper.cc @@ -203,7 +203,7 @@ int32_t VideoEncoderSoftwareFallbackWrapper::SetChannelParameters( } int32_t VideoEncoderSoftwareFallbackWrapper::SetRateAllocation( - const BitrateAllocation& bitrate_allocation, + const VideoBitrateAllocation& bitrate_allocation, uint32_t framerate) { rates_set_ = true; bitrate_allocation_ = bitrate_allocation; diff --git a/media/engine/videoencodersoftwarefallbackwrapper.h b/media/engine/videoencodersoftwarefallbackwrapper.h index c54728e521..1c472d1e55 100644 --- a/media/engine/videoencodersoftwarefallbackwrapper.h +++ b/media/engine/videoencodersoftwarefallbackwrapper.h @@ -42,7 +42,7 @@ class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder { const CodecSpecificInfo* codec_specific_info, const std::vector* frame_types) override; int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation, uint32_t framerate) override; bool SupportsNativeHandle() const override; ScalingSettings GetScalingSettings() const override; @@ -80,7 +80,7 @@ class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder { // The last bitrate/framerate set, and a flag for noting they are set. bool rates_set_; - BitrateAllocation bitrate_allocation_; + VideoBitrateAllocation bitrate_allocation_; uint32_t framerate_; // The last channel parameters set, and a flag for noting they are set. diff --git a/media/engine/videoencodersoftwarefallbackwrapper_unittest.cc b/media/engine/videoencodersoftwarefallbackwrapper_unittest.cc index df04d8082b..07b569c681 100644 --- a/media/engine/videoencodersoftwarefallbackwrapper_unittest.cc +++ b/media/engine/videoencodersoftwarefallbackwrapper_unittest.cc @@ -84,7 +84,7 @@ class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test { return WEBRTC_VIDEO_CODEC_OK; } - int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation, uint32_t framerate) override { ++set_rates_count_; return WEBRTC_VIDEO_CODEC_OK; @@ -283,7 +283,7 @@ TEST_F(VideoEncoderSoftwareFallbackWrapperTest, SetRatesForwardedDuringFallback) { UtilizeFallbackEncoder(); EXPECT_EQ(1, fake_encoder_->set_rates_count_); - fallback_wrapper_.SetRateAllocation(BitrateAllocation(), 1); + fallback_wrapper_.SetRateAllocation(VideoBitrateAllocation(), 1); EXPECT_EQ(2, fake_encoder_->set_rates_count_); EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); } diff --git a/media/engine/vp8_encoder_simulcast_proxy.cc b/media/engine/vp8_encoder_simulcast_proxy.cc index 283f17bb94..94020c332d 100644 --- a/media/engine/vp8_encoder_simulcast_proxy.cc +++ b/media/engine/vp8_encoder_simulcast_proxy.cc @@ -59,7 +59,7 @@ int VP8EncoderSimulcastProxy::SetChannelParameters(uint32_t packet_loss, } int VP8EncoderSimulcastProxy::SetRateAllocation( - const BitrateAllocation& bitrate, + const VideoBitrateAllocation& bitrate, uint32_t new_framerate) { return encoder_->SetRateAllocation(bitrate, new_framerate); } diff --git a/media/engine/vp8_encoder_simulcast_proxy.h b/media/engine/vp8_encoder_simulcast_proxy.h index d32f9b22ed..7e9fd4effd 100644 --- a/media/engine/vp8_encoder_simulcast_proxy.h +++ b/media/engine/vp8_encoder_simulcast_proxy.h @@ -37,7 +37,7 @@ class VP8EncoderSimulcastProxy : public VP8Encoder { const std::vector* frame_types) override; int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int SetRateAllocation(const BitrateAllocation& bitrate, + int SetRateAllocation(const VideoBitrateAllocation& bitrate, uint32_t new_framerate) override; VideoEncoder::ScalingSettings GetScalingSettings() const override; diff --git a/modules/rtp_rtcp/include/rtp_rtcp.h b/modules/rtp_rtcp/include/rtp_rtcp.h index de9016a5ed..24e658ece4 100644 --- a/modules/rtp_rtcp/include/rtp_rtcp.h +++ b/modules/rtp_rtcp/include/rtp_rtcp.h @@ -399,7 +399,8 @@ class RtpRtcp : public Module, public RtcpFeedbackSenderInterface { // BWE feedback packets. bool SendFeedbackPacket(const rtcp::TransportFeedback& packet) override = 0; - virtual void SetVideoBitrateAllocation(const BitrateAllocation& bitrate) = 0; + virtual void SetVideoBitrateAllocation( + const VideoBitrateAllocation& bitrate) = 0; // ************************************************************************** // Audio diff --git a/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h b/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h index c556959430..e535832a2b 100644 --- a/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h +++ b/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h @@ -179,7 +179,7 @@ class MockRtpRtcp : public RtpRtcp { void(StreamDataCountersCallback*)); MOCK_CONST_METHOD0(GetSendChannelRtpStatisticsCallback, StreamDataCountersCallback*(void)); - MOCK_METHOD1(SetVideoBitrateAllocation, void(const BitrateAllocation&)); + MOCK_METHOD1(SetVideoBitrateAllocation, void(const VideoBitrateAllocation&)); // Members. unsigned int remote_ssrc_; diff --git a/modules/rtp_rtcp/source/rtcp_receiver.cc b/modules/rtp_rtcp/source/rtcp_receiver.cc index abe135e2ed..f9c542e966 100644 --- a/modules/rtp_rtcp/source/rtcp_receiver.cc +++ b/modules/rtp_rtcp/source/rtcp_receiver.cc @@ -71,7 +71,7 @@ struct RTCPReceiver::PacketInformation { int64_t rtt_ms = 0; uint32_t receiver_estimated_max_bitrate_bps = 0; std::unique_ptr transport_feedback; - rtc::Optional target_bitrate_allocation; + rtc::Optional target_bitrate_allocation; }; // Structure for handing TMMBR and TMMBN rtcp messages (RFC5104, section 3.5.4). @@ -775,7 +775,7 @@ void RTCPReceiver::HandleXrTargetBitrate( return; // Not for us. } - BitrateAllocation bitrate_allocation; + VideoBitrateAllocation bitrate_allocation; for (const auto& item : target_bitrate.GetTargetBitrates()) { if (item.spatial_layer >= kMaxSpatialLayers || item.temporal_layer >= kMaxTemporalStreams) { diff --git a/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc b/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc index 3c3c4b37c7..a7cbba1d39 100644 --- a/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc +++ b/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc @@ -93,7 +93,7 @@ class MockVideoBitrateAllocationObserver : public VideoBitrateAllocationObserver { public: MOCK_METHOD1(OnBitrateAllocationUpdated, - void(const BitrateAllocation& allocation)); + void(const VideoBitrateAllocation& allocation)); }; // SSRC of remote peer, that sends rtcp packet to the rtcp receiver under test. @@ -1318,7 +1318,7 @@ TEST_F(RtcpReceiverTest, ForceSenderReport) { } TEST_F(RtcpReceiverTest, ReceivesTargetBitrate) { - BitrateAllocation expected_allocation; + VideoBitrateAllocation expected_allocation; expected_allocation.SetBitrate(0, 0, 10000); expected_allocation.SetBitrate(0, 1, 20000); expected_allocation.SetBitrate(1, 0, 40000); @@ -1348,7 +1348,7 @@ TEST_F(RtcpReceiverTest, ReceivesTargetBitrate) { } TEST_F(RtcpReceiverTest, HandlesIncorrectTargetBitrate) { - BitrateAllocation expected_allocation; + VideoBitrateAllocation expected_allocation; expected_allocation.SetBitrate(0, 0, 10000); rtcp::TargetBitrate bitrate; diff --git a/modules/rtp_rtcp/source/rtcp_sender.cc b/modules/rtp_rtcp/source/rtcp_sender.cc index 6b266cb66e..5c379f7716 100644 --- a/modules/rtp_rtcp/source/rtcp_sender.cc +++ b/modules/rtp_rtcp/source/rtcp_sender.cc @@ -947,7 +947,8 @@ bool RTCPSender::AllVolatileFlagsConsumed() const { return true; } -void RTCPSender::SetVideoBitrateAllocation(const BitrateAllocation& bitrate) { +void RTCPSender::SetVideoBitrateAllocation( + const VideoBitrateAllocation& bitrate) { rtc::CritScope lock(&critical_section_rtcp_sender_); video_bitrate_allocation_.emplace(bitrate); SetFlag(kRtcpAnyExtendedReports, true); diff --git a/modules/rtp_rtcp/source/rtcp_sender.h b/modules/rtp_rtcp/source/rtcp_sender.h index f6cb55e0a5..f77fe3c632 100644 --- a/modules/rtp_rtcp/source/rtcp_sender.h +++ b/modules/rtp_rtcp/source/rtcp_sender.h @@ -149,7 +149,7 @@ class RTCPSender { void SetCsrcs(const std::vector& csrcs); void SetTargetBitrate(unsigned int target_bitrate); - void SetVideoBitrateAllocation(const BitrateAllocation& bitrate); + void SetVideoBitrateAllocation(const VideoBitrateAllocation& bitrate); bool SendFeedbackPacket(const rtcp::TransportFeedback& packet); int64_t RtcpAudioReportInverval() const; @@ -261,7 +261,7 @@ class RTCPSender { RtcpNackStats nack_stats_ RTC_GUARDED_BY(critical_section_rtcp_sender_); - rtc::Optional video_bitrate_allocation_ + rtc::Optional video_bitrate_allocation_ RTC_GUARDED_BY(critical_section_rtcp_sender_); void SetFlag(uint32_t type, bool is_volatile) diff --git a/modules/rtp_rtcp/source/rtcp_sender_unittest.cc b/modules/rtp_rtcp/source/rtcp_sender_unittest.cc index 98513325e1..120a43e489 100644 --- a/modules/rtp_rtcp/source/rtcp_sender_unittest.cc +++ b/modules/rtp_rtcp/source/rtcp_sender_unittest.cc @@ -823,7 +823,7 @@ TEST_F(RtcpSenderTest, SendXrWithTargetBitrate) { rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); const size_t kNumSpatialLayers = 2; const size_t kNumTemporalLayers = 2; - BitrateAllocation allocation; + VideoBitrateAllocation allocation; for (size_t sl = 0; sl < kNumSpatialLayers; ++sl) { uint32_t start_bitrate_bps = (sl + 1) * 100000; for (size_t tl = 0; tl < kNumTemporalLayers; ++tl) diff --git a/modules/rtp_rtcp/source/rtcp_transceiver_config.h b/modules/rtp_rtcp/source/rtcp_transceiver_config.h index 75c007da18..8a4a4c4cea 100644 --- a/modules/rtp_rtcp/source/rtcp_transceiver_config.h +++ b/modules/rtp_rtcp/source/rtcp_transceiver_config.h @@ -33,7 +33,7 @@ class MediaReceiverRtcpObserver { uint32_t rtp_time) {} virtual void OnBye(uint32_t sender_ssrc) {} virtual void OnBitrateAllocation(uint32_t sender_ssrc, - const BitrateAllocation& allocation) {} + const VideoBitrateAllocation& allocation) {} }; struct RtcpTransceiverConfig { diff --git a/modules/rtp_rtcp/source/rtcp_transceiver_impl.cc b/modules/rtp_rtcp/source/rtcp_transceiver_impl.cc index 925cc03410..a58de8c126 100644 --- a/modules/rtp_rtcp/source/rtcp_transceiver_impl.cc +++ b/modules/rtp_rtcp/source/rtcp_transceiver_impl.cc @@ -294,8 +294,8 @@ void RtcpTransceiverImpl::HandleTargetBitrate( remote_sender_it->second.observers.empty()) return; - // Convert rtcp::TargetBitrate to BitrateAllocation from common types. - BitrateAllocation bitrate_allocation; + // Convert rtcp::TargetBitrate to VideoBitrateAllocation. + VideoBitrateAllocation bitrate_allocation; for (const rtcp::TargetBitrate::BitrateItem& item : target_bitrate.GetTargetBitrates()) { if (item.spatial_layer >= kMaxSpatialLayers || diff --git a/modules/rtp_rtcp/source/rtcp_transceiver_impl_unittest.cc b/modules/rtp_rtcp/source/rtcp_transceiver_impl_unittest.cc index 831e51f8a2..8cffd28f89 100644 --- a/modules/rtp_rtcp/source/rtcp_transceiver_impl_unittest.cc +++ b/modules/rtp_rtcp/source/rtcp_transceiver_impl_unittest.cc @@ -35,7 +35,7 @@ using ::testing::Invoke; using ::testing::Return; using ::testing::SizeIs; using ::testing::StrictMock; -using ::webrtc::BitrateAllocation; +using ::webrtc::VideoBitrateAllocation; using ::webrtc::CompactNtp; using ::webrtc::CompactNtpRttToMs; using ::webrtc::MockRtcpRttStats; @@ -60,7 +60,8 @@ class MockMediaReceiverRtcpObserver : public webrtc::MediaReceiverRtcpObserver { public: MOCK_METHOD3(OnSenderReport, void(uint32_t, NtpTime, uint32_t)); MOCK_METHOD1(OnBye, void(uint32_t)); - MOCK_METHOD2(OnBitrateAllocation, void(uint32_t, const BitrateAllocation&)); + MOCK_METHOD2(OnBitrateAllocation, + void(uint32_t, const VideoBitrateAllocation&)); }; // Since some tests will need to wait for this period, make it small to avoid @@ -552,7 +553,7 @@ TEST(RtcpTransceiverImplTest, CallsObserverOnTargetBitrateBySenderSsrc) { xr.SetTargetBitrate(target_bitrate); auto raw_packet = xr.Build(); - BitrateAllocation bitrate_allocation; + VideoBitrateAllocation bitrate_allocation; bitrate_allocation.SetBitrate(0, 0, /*bitrate_bps=*/10000); bitrate_allocation.SetBitrate(0, 1, /*bitrate_bps=*/20000); bitrate_allocation.SetBitrate(1, 0, /*bitrate_bps=*/40000); @@ -578,7 +579,7 @@ TEST(RtcpTransceiverImplTest, SkipsIncorrectTargetBitrateEntries) { xr.SetSenderSsrc(kRemoteSsrc); auto raw_packet = xr.Build(); - BitrateAllocation expected_allocation; + VideoBitrateAllocation expected_allocation; expected_allocation.SetBitrate(0, 0, /*bitrate_bps=*/10000); EXPECT_CALL(observer, OnBitrateAllocation(kRemoteSsrc, expected_allocation)); rtcp_transceiver.ReceivePacket(raw_packet, /*now_us=*/0); diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index 22e399dfd1..07a6afb9e9 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -927,7 +927,7 @@ StreamDataCountersCallback* } void ModuleRtpRtcpImpl::SetVideoBitrateAllocation( - const BitrateAllocation& bitrate) { + const VideoBitrateAllocation& bitrate) { rtcp_sender_.SetVideoBitrateAllocation(bitrate); } } // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/modules/rtp_rtcp/source/rtp_rtcp_impl.h index b364a29e9e..97afde5a2f 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl.h +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.h @@ -292,7 +292,8 @@ class ModuleRtpRtcpImpl : public RtpRtcp, public RTCPReceiver::ModuleRtpRtcp { const ReportBlockList& report_blocks) override; void OnRequestSendReport() override; - void SetVideoBitrateAllocation(const BitrateAllocation& bitrate) override; + void SetVideoBitrateAllocation( + const VideoBitrateAllocation& bitrate) override; protected: bool UpdateRTCPReceiveInformationTimers(); diff --git a/modules/video_coding/codecs/h264/h264_encoder_impl.cc b/modules/video_coding/codecs/h264/h264_encoder_impl.cc index dffc348e74..02f93e1480 100644 --- a/modules/video_coding/codecs/h264/h264_encoder_impl.cc +++ b/modules/video_coding/codecs/h264/h264_encoder_impl.cc @@ -288,7 +288,7 @@ int32_t H264EncoderImpl::RegisterEncodeCompleteCallback( } int32_t H264EncoderImpl::SetRateAllocation( - const BitrateAllocation& bitrate_allocation, + const VideoBitrateAllocation& bitrate_allocation, uint32_t framerate) { if (bitrate_allocation.get_sum_bps() <= 0 || framerate <= 0) return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; diff --git a/modules/video_coding/codecs/h264/h264_encoder_impl.h b/modules/video_coding/codecs/h264/h264_encoder_impl.h index 20d5ea6056..c48439b444 100644 --- a/modules/video_coding/codecs/h264/h264_encoder_impl.h +++ b/modules/video_coding/codecs/h264/h264_encoder_impl.h @@ -44,7 +44,7 @@ class H264EncoderImpl : public H264Encoder { int32_t RegisterEncodeCompleteCallback( EncodedImageCallback* callback) override; - int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation, uint32_t framerate) override; // The result of encoding - an EncodedImage and RTPFragmentationHeader - are diff --git a/modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h b/modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h index cbdd6c3508..7ce86156d4 100644 --- a/modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h +++ b/modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h @@ -46,7 +46,7 @@ class MultiplexEncoderAdapter : public VideoEncoder { const std::vector* frame_types) override; int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int SetRateAllocation(const BitrateAllocation& bitrate, + int SetRateAllocation(const VideoBitrateAllocation& bitrate, uint32_t new_framerate) override; int Release() override; const char* ImplementationName() const override; diff --git a/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc b/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc index 7eb0d50f36..dcf1b56e0f 100644 --- a/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc +++ b/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc @@ -174,8 +174,9 @@ int MultiplexEncoderAdapter::SetChannelParameters(uint32_t packet_loss, return WEBRTC_VIDEO_CODEC_OK; } -int MultiplexEncoderAdapter::SetRateAllocation(const BitrateAllocation& bitrate, - uint32_t framerate) { +int MultiplexEncoderAdapter::SetRateAllocation( + const VideoBitrateAllocation& bitrate, + uint32_t framerate) { for (auto& encoder : encoders_) { // TODO(emircan): |framerate| is used to calculate duration in encoder // instances. We report the total frame rate to keep real time for now. diff --git a/modules/video_coding/codecs/test/videoprocessor.h b/modules/video_coding/codecs/test/videoprocessor.h index a56b83d669..66e7525c25 100644 --- a/modules/video_coding/codecs/test/videoprocessor.h +++ b/modules/video_coding/codecs/test/videoprocessor.h @@ -188,7 +188,7 @@ class VideoProcessor { webrtc::VideoEncoder* const encoder_; VideoDecoderList* const decoders_; const std::unique_ptr bitrate_allocator_; - BitrateAllocation bitrate_allocation_ RTC_GUARDED_BY(sequence_checker_); + VideoBitrateAllocation bitrate_allocation_ RTC_GUARDED_BY(sequence_checker_); uint32_t framerate_fps_ RTC_GUARDED_BY(sequence_checker_); // Adapters for the codec callbacks. diff --git a/modules/video_coding/codecs/test/videoprocessor_unittest.cc b/modules/video_coding/codecs/test/videoprocessor_unittest.cc index cb01459fe9..baf97bf393 100644 --- a/modules/video_coding/codecs/test/videoprocessor_unittest.cc +++ b/modules/video_coding/codecs/test/videoprocessor_unittest.cc @@ -166,7 +166,7 @@ TEST_F(VideoProcessorTest, SetRates) { const int kFramerateFps = 17; EXPECT_CALL(encoder_mock_, SetRateAllocation( - Property(&BitrateAllocation::get_sum_kbps, kBitrateKbps), + Property(&VideoBitrateAllocation::get_sum_kbps, kBitrateKbps), kFramerateFps)) .Times(1); DO_SYNC(q_, { video_processor_->SetRates(kBitrateKbps, kFramerateFps); }); @@ -174,9 +174,9 @@ TEST_F(VideoProcessorTest, SetRates) { const int kNewBitrateKbps = 456; const int kNewFramerateFps = 34; EXPECT_CALL(encoder_mock_, - SetRateAllocation( - Property(&BitrateAllocation::get_sum_kbps, kNewBitrateKbps), - kNewFramerateFps)) + SetRateAllocation(Property(&VideoBitrateAllocation::get_sum_kbps, + kNewBitrateKbps), + kNewFramerateFps)) .Times(1); DO_SYNC(q_, { video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); }); diff --git a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc index b1cecf0691..d84d0011da 100644 --- a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc +++ b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc @@ -252,7 +252,7 @@ int LibvpxVp8Encoder::Release() { return ret_val; } -int LibvpxVp8Encoder::SetRateAllocation(const BitrateAllocation& bitrate, +int LibvpxVp8Encoder::SetRateAllocation(const VideoBitrateAllocation& bitrate, uint32_t new_framerate) { if (!inited_) return WEBRTC_VIDEO_CODEC_UNINITIALIZED; @@ -512,7 +512,7 @@ int LibvpxVp8Encoder::InitEncode(const VideoCodec* inst, // at position 0 and they have highest resolution at position 0. int stream_idx = encoders_.size() - 1; SimulcastRateAllocator init_allocator(codec_); - BitrateAllocation allocation = init_allocator.GetAllocation( + VideoBitrateAllocation allocation = init_allocator.GetAllocation( inst->startBitrate * 1000, inst->maxFramerate); std::vector stream_bitrates; for (int i = 0; i == 0 || i < inst->numberOfSimulcastStreams; ++i) { diff --git a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.h b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.h index f3e8c7a91a..4e9d374c4c 100644 --- a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.h +++ b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.h @@ -46,7 +46,7 @@ class LibvpxVp8Encoder : public VP8Encoder { int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int SetRateAllocation(const BitrateAllocation& bitrate, + int SetRateAllocation(const VideoBitrateAllocation& bitrate, uint32_t new_framerate) override; ScalingSettings GetScalingSettings() const override; diff --git a/modules/video_coding/codecs/vp8/simulcast_rate_allocator.cc b/modules/video_coding/codecs/vp8/simulcast_rate_allocator.cc index b819caa80e..5effa682bd 100644 --- a/modules/video_coding/codecs/vp8/simulcast_rate_allocator.cc +++ b/modules/video_coding/codecs/vp8/simulcast_rate_allocator.cc @@ -23,10 +23,10 @@ namespace webrtc { SimulcastRateAllocator::SimulcastRateAllocator(const VideoCodec& codec) : codec_(codec) {} -BitrateAllocation SimulcastRateAllocator::GetAllocation( +VideoBitrateAllocation SimulcastRateAllocator::GetAllocation( uint32_t total_bitrate_bps, uint32_t framerate) { - BitrateAllocation allocated_bitrates_bps; + VideoBitrateAllocation allocated_bitrates_bps; DistributeAllocationToSimulcastLayers(total_bitrate_bps, &allocated_bitrates_bps); DistributeAllocationToTemporalLayers(framerate, &allocated_bitrates_bps); @@ -35,7 +35,7 @@ BitrateAllocation SimulcastRateAllocator::GetAllocation( void SimulcastRateAllocator::DistributeAllocationToSimulcastLayers( uint32_t total_bitrate_bps, - BitrateAllocation* allocated_bitrates_bps) const { + VideoBitrateAllocation* allocated_bitrates_bps) const { uint32_t left_to_allocate = total_bitrate_bps; if (codec_.maxBitrate && codec_.maxBitrate * 1000 < left_to_allocate) left_to_allocate = codec_.maxBitrate * 1000; @@ -111,7 +111,7 @@ void SimulcastRateAllocator::DistributeAllocationToSimulcastLayers( void SimulcastRateAllocator::DistributeAllocationToTemporalLayers( uint32_t framerate, - BitrateAllocation* allocated_bitrates_bps) const { + VideoBitrateAllocation* allocated_bitrates_bps) const { const int num_spatial_streams = std::max(1, static_cast(codec_.numberOfSimulcastStreams)); diff --git a/modules/video_coding/codecs/vp8/simulcast_rate_allocator.h b/modules/video_coding/codecs/vp8/simulcast_rate_allocator.h index 23d158b91b..7cb1a8a1fd 100644 --- a/modules/video_coding/codecs/vp8/simulcast_rate_allocator.h +++ b/modules/video_coding/codecs/vp8/simulcast_rate_allocator.h @@ -28,18 +28,18 @@ class SimulcastRateAllocator : public VideoBitrateAllocator { public: explicit SimulcastRateAllocator(const VideoCodec& codec); - BitrateAllocation GetAllocation(uint32_t total_bitrate_bps, - uint32_t framerate) override; + VideoBitrateAllocation GetAllocation(uint32_t total_bitrate_bps, + uint32_t framerate) override; uint32_t GetPreferredBitrateBps(uint32_t framerate) override; const VideoCodec& GetCodec() const; private: void DistributeAllocationToSimulcastLayers( uint32_t total_bitrate_bps, - BitrateAllocation* allocated_bitrates_bps) const; + VideoBitrateAllocation* allocated_bitrates_bps) const; void DistributeAllocationToTemporalLayers( uint32_t framerate, - BitrateAllocation* allocated_bitrates_bps) const; + VideoBitrateAllocation* allocated_bitrates_bps) const; std::vector DefaultTemporalLayerAllocation(int bitrate_kbps, int max_bitrate_kbps, int framerate, diff --git a/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc b/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc index 6db6b5b02c..ce4bb8391b 100644 --- a/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc +++ b/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc @@ -85,7 +85,7 @@ TEST_F(TestVp8Impl, SetRateAllocation) { EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); const int kBitrateBps = 300000; - BitrateAllocation bitrate_allocation; + VideoBitrateAllocation bitrate_allocation; bitrate_allocation.SetBitrate(0, 0, kBitrateBps); EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, encoder_->SetRateAllocation(bitrate_allocation, diff --git a/modules/video_coding/codecs/vp9/svc_rate_allocator.cc b/modules/video_coding/codecs/vp9/svc_rate_allocator.cc index e335550cdc..46caef42d9 100644 --- a/modules/video_coding/codecs/vp9/svc_rate_allocator.cc +++ b/modules/video_coding/codecs/vp9/svc_rate_allocator.cc @@ -27,9 +27,10 @@ SvcRateAllocator::SvcRateAllocator(const VideoCodec& codec) : codec_(codec) { RTC_DCHECK_EQ(codec.codecType, kVideoCodecVP9); } -BitrateAllocation SvcRateAllocator::GetAllocation(uint32_t total_bitrate_bps, - uint32_t framerate_fps) { - BitrateAllocation bitrate_allocation; +VideoBitrateAllocation SvcRateAllocator::GetAllocation( + uint32_t total_bitrate_bps, + uint32_t framerate_fps) { + VideoBitrateAllocation bitrate_allocation; size_t num_spatial_layers = codec_.VP9().numberOfSpatialLayers; RTC_CHECK(num_spatial_layers > 0); diff --git a/modules/video_coding/codecs/vp9/svc_rate_allocator.h b/modules/video_coding/codecs/vp9/svc_rate_allocator.h index 24a3cab351..cbf2096d90 100644 --- a/modules/video_coding/codecs/vp9/svc_rate_allocator.h +++ b/modules/video_coding/codecs/vp9/svc_rate_allocator.h @@ -23,8 +23,8 @@ class SvcRateAllocator : public VideoBitrateAllocator { public: explicit SvcRateAllocator(const VideoCodec& codec); - BitrateAllocation GetAllocation(uint32_t total_bitrate_bps, - uint32_t framerate_fps) override; + VideoBitrateAllocation GetAllocation(uint32_t total_bitrate_bps, + uint32_t framerate_fps) override; uint32_t GetPreferredBitrateBps(uint32_t framerate_fps) override; private: diff --git a/modules/video_coding/codecs/vp9/svc_rate_allocator_unittest.cc b/modules/video_coding/codecs/vp9/svc_rate_allocator_unittest.cc index e89416694c..536950e18e 100644 --- a/modules/video_coding/codecs/vp9/svc_rate_allocator_unittest.cc +++ b/modules/video_coding/codecs/vp9/svc_rate_allocator_unittest.cc @@ -46,7 +46,7 @@ TEST(SvcRateAllocatorTest, SingleLayerFor320x180Input) { VideoCodec codec = Configure(320, 180, 3, 3); SvcRateAllocator allocator = SvcRateAllocator(codec); - BitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30); + VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30); EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u); EXPECT_EQ(allocation.GetSpatialLayerSum(1), 0u); @@ -56,7 +56,7 @@ TEST(SvcRateAllocatorTest, TwoLayersFor640x360Input) { VideoCodec codec = Configure(640, 360, 3, 3); SvcRateAllocator allocator = SvcRateAllocator(codec); - BitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30); + VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30); EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u); EXPECT_GT(allocation.GetSpatialLayerSum(1), 0u); @@ -67,7 +67,7 @@ TEST(SvcRateAllocatorTest, ThreeLayersFor1280x720Input) { VideoCodec codec = Configure(1280, 720, 3, 3); SvcRateAllocator allocator = SvcRateAllocator(codec); - BitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30); + VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30); EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u); EXPECT_GT(allocation.GetSpatialLayerSum(1), 0u); @@ -81,7 +81,7 @@ TEST(SvcRateAllocatorTest, const SpatialLayer* layers = codec.spatialLayers; - BitrateAllocation allocation = + VideoBitrateAllocation allocation = allocator.GetAllocation(layers[0].minBitrate * 1000 / 2, 30); EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u); @@ -98,7 +98,7 @@ TEST(SvcRateAllocatorTest, Disable640x360Layer) { size_t min_bitrate_for_640x360_layer_kbps = layers[0].minBitrate + layers[1].minBitrate; - BitrateAllocation allocation = allocator.GetAllocation( + VideoBitrateAllocation allocation = allocator.GetAllocation( min_bitrate_for_640x360_layer_kbps * 1000 - 1, 30); EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u); @@ -114,7 +114,7 @@ TEST(SvcRateAllocatorTest, Disable1280x720Layer) { size_t min_bitrate_for_1280x720_layer_kbps = layers[0].minBitrate + layers[1].minBitrate + layers[2].minBitrate; - BitrateAllocation allocation = allocator.GetAllocation( + VideoBitrateAllocation allocation = allocator.GetAllocation( min_bitrate_for_1280x720_layer_kbps * 1000 - 1, 30); EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u); @@ -129,7 +129,7 @@ TEST(SvcRateAllocatorTest, BitrateIsCapped) { const SpatialLayer* layers = codec.spatialLayers; const uint32_t link_mbps = 100; - BitrateAllocation allocation = + VideoBitrateAllocation allocation = allocator.GetAllocation(link_mbps * 1000000, 30); EXPECT_EQ(allocation.get_sum_kbps(), diff --git a/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc b/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc index b16419b6b6..d060f5f436 100644 --- a/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc +++ b/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc @@ -224,7 +224,7 @@ TEST_F(TestVp9Impl, EnableDisableSpatialLayers) { encoder_->InitEncode(&codec_settings_, 1 /* number of cores */, 0 /* max payload size (unused) */)); - BitrateAllocation bitrate_allocation; + VideoBitrateAllocation bitrate_allocation; for (size_t sl_idx = 0; sl_idx < num_spatial_layers; ++sl_idx) { bitrate_allocation.SetBitrate(sl_idx, 0, layers[sl_idx].targetBitrate * 1000); @@ -283,7 +283,7 @@ TEST_F(TestVp9Impl, EndOfSuperframe) { // Encode both base and upper layers. Check that end-of-superframe flag is // set on upper layer frame but not on base layer frame. - BitrateAllocation bitrate_allocation; + VideoBitrateAllocation bitrate_allocation; bitrate_allocation.SetBitrate(0, 0, layers[0].targetBitrate * 1000); bitrate_allocation.SetBitrate(1, 0, layers[1].targetBitrate * 1000); EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc index 5ae44ed0ae..5076af2e9d 100644 --- a/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -123,7 +123,8 @@ bool VP9EncoderImpl::ExplicitlyConfiguredSpatialLayers() const { return num_spatial_layers_ > 1 && codec_.spatialLayers[0].targetBitrate > 0; } -bool VP9EncoderImpl::SetSvcRates(const BitrateAllocation& bitrate_allocation) { +bool VP9EncoderImpl::SetSvcRates( + const VideoBitrateAllocation& bitrate_allocation) { uint8_t i = 0; config_->rc_target_bitrate = bitrate_allocation.get_sum_kbps(); @@ -192,7 +193,7 @@ bool VP9EncoderImpl::SetSvcRates(const BitrateAllocation& bitrate_allocation) { } int VP9EncoderImpl::SetRateAllocation( - const BitrateAllocation& bitrate_allocation, + const VideoBitrateAllocation& bitrate_allocation, uint32_t frame_rate) { if (!inited_) { return WEBRTC_VIDEO_CODEC_UNINITIALIZED; @@ -434,7 +435,7 @@ int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { } SvcRateAllocator init_allocator(codec_); - BitrateAllocation allocation = init_allocator.GetAllocation( + VideoBitrateAllocation allocation = init_allocator.GetAllocation( inst->startBitrate * 1000, inst->maxFramerate); if (!SetSvcRates(allocation)) { return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; diff --git a/modules/video_coding/codecs/vp9/vp9_impl.h b/modules/video_coding/codecs/vp9/vp9_impl.h index b158523dab..da868491ad 100644 --- a/modules/video_coding/codecs/vp9/vp9_impl.h +++ b/modules/video_coding/codecs/vp9/vp9_impl.h @@ -46,7 +46,7 @@ class VP9EncoderImpl : public VP9Encoder { int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int SetRateAllocation(const BitrateAllocation& bitrate_allocation, + int SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation, uint32_t frame_rate) override; const char* ImplementationName() const override; @@ -78,7 +78,7 @@ class VP9EncoderImpl : public VP9Encoder { bool first_frame_in_picture); bool ExplicitlyConfiguredSpatialLayers() const; - bool SetSvcRates(const BitrateAllocation& bitrate_allocation); + bool SetSvcRates(const VideoBitrateAllocation& bitrate_allocation); // Used for flexible mode to set the flags and buffer references used // by the encoder. Also calculates the references used by the RTP diff --git a/modules/video_coding/generic_encoder.cc b/modules/video_coding/generic_encoder.cc index 1490882b50..f9d82346e3 100644 --- a/modules/video_coding/generic_encoder.cc +++ b/modules/video_coding/generic_encoder.cc @@ -38,8 +38,9 @@ VCMGenericEncoder::VCMGenericEncoder( : encoder_(encoder), vcm_encoded_frame_callback_(encoded_frame_callback), internal_source_(internal_source), - encoder_params_({BitrateAllocation(), 0, 0, 0}), - streams_or_svc_num_(0) {} + encoder_params_({VideoBitrateAllocation(), 0, 0, 0}), + streams_or_svc_num_(0), + codec_type_(VideoCodecType::kVideoCodecUnknown) {} VCMGenericEncoder::~VCMGenericEncoder() {} diff --git a/modules/video_coding/generic_encoder.h b/modules/video_coding/generic_encoder.h index 4efd9619d1..03de62676c 100644 --- a/modules/video_coding/generic_encoder.h +++ b/modules/video_coding/generic_encoder.h @@ -28,7 +28,7 @@ class MediaOptimization; } // namespace media_optimization struct EncoderParameters { - BitrateAllocation target_bitrate; + VideoBitrateAllocation target_bitrate; uint8_t loss_rate; int64_t rtt; uint32_t input_frame_rate; diff --git a/modules/video_coding/include/mock/mock_video_codec_interface.h b/modules/video_coding/include/mock/mock_video_codec_interface.h index e558b7ce9e..82363f338d 100644 --- a/modules/video_coding/include/mock/mock_video_codec_interface.h +++ b/modules/video_coding/include/mock/mock_video_codec_interface.h @@ -46,7 +46,7 @@ class MockVideoEncoder : public VideoEncoder { MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); MOCK_METHOD2(SetRates, int32_t(uint32_t newBitRate, uint32_t frameRate)); MOCK_METHOD2(SetRateAllocation, - int32_t(const BitrateAllocation& newBitRate, + int32_t(const VideoBitrateAllocation& newBitRate, uint32_t frameRate)); }; diff --git a/modules/video_coding/utility/default_video_bitrate_allocator.cc b/modules/video_coding/utility/default_video_bitrate_allocator.cc index 0c4ae9bae5..0124ad1698 100644 --- a/modules/video_coding/utility/default_video_bitrate_allocator.cc +++ b/modules/video_coding/utility/default_video_bitrate_allocator.cc @@ -20,10 +20,10 @@ DefaultVideoBitrateAllocator::DefaultVideoBitrateAllocator( DefaultVideoBitrateAllocator::~DefaultVideoBitrateAllocator() {} -BitrateAllocation DefaultVideoBitrateAllocator::GetAllocation( +VideoBitrateAllocation DefaultVideoBitrateAllocator::GetAllocation( uint32_t total_bitrate_bps, uint32_t framerate) { - BitrateAllocation allocation; + VideoBitrateAllocation allocation; if (total_bitrate_bps == 0 || !codec_.active) return allocation; diff --git a/modules/video_coding/utility/default_video_bitrate_allocator.h b/modules/video_coding/utility/default_video_bitrate_allocator.h index 0ef709efa7..6ecd8781e2 100644 --- a/modules/video_coding/utility/default_video_bitrate_allocator.h +++ b/modules/video_coding/utility/default_video_bitrate_allocator.h @@ -20,8 +20,8 @@ class DefaultVideoBitrateAllocator : public VideoBitrateAllocator { explicit DefaultVideoBitrateAllocator(const VideoCodec& codec); ~DefaultVideoBitrateAllocator() override; - BitrateAllocation GetAllocation(uint32_t total_bitrate, - uint32_t framerate) override; + VideoBitrateAllocation GetAllocation(uint32_t total_bitrate, + uint32_t framerate) override; uint32_t GetPreferredBitrateBps(uint32_t framerate) override; private: diff --git a/modules/video_coding/utility/default_video_bitrate_allocator_unittest.cc b/modules/video_coding/utility/default_video_bitrate_allocator_unittest.cc index e27b3d30a0..05b5a0af5d 100644 --- a/modules/video_coding/utility/default_video_bitrate_allocator_unittest.cc +++ b/modules/video_coding/utility/default_video_bitrate_allocator_unittest.cc @@ -41,19 +41,22 @@ class DefaultVideoBitrateAllocatorTest : public ::testing::Test { }; TEST_F(DefaultVideoBitrateAllocatorTest, ZeroIsOff) { - BitrateAllocation allocation = allocator_->GetAllocation(0, kMaxFramerate); + VideoBitrateAllocation allocation = + allocator_->GetAllocation(0, kMaxFramerate); EXPECT_EQ(0u, allocation.get_sum_bps()); } TEST_F(DefaultVideoBitrateAllocatorTest, Inactive) { codec_.active = false; allocator_.reset(new DefaultVideoBitrateAllocator(codec_)); - BitrateAllocation allocation = allocator_->GetAllocation(1, kMaxFramerate); + VideoBitrateAllocation allocation = + allocator_->GetAllocation(1, kMaxFramerate); EXPECT_EQ(0u, allocation.get_sum_bps()); } TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMin) { - BitrateAllocation allocation = allocator_->GetAllocation(1, kMaxFramerate); + VideoBitrateAllocation allocation = + allocator_->GetAllocation(1, kMaxFramerate); EXPECT_EQ(kMinBitrateBps, allocation.get_sum_bps()); allocation = allocator_->GetAllocation(kMinBitrateBps - 1, kMaxFramerate); @@ -64,7 +67,7 @@ TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMin) { } TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMax) { - BitrateAllocation allocation = + VideoBitrateAllocation allocation = allocator_->GetAllocation(kMaxBitrateBps, kMaxFramerate); EXPECT_EQ(kMaxBitrateBps, allocation.get_sum_bps()); @@ -77,7 +80,7 @@ TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMax) { } TEST_F(DefaultVideoBitrateAllocatorTest, GoodInBetween) { - BitrateAllocation allocation = + VideoBitrateAllocation allocation = allocator_->GetAllocation(kMinBitrateBps + 1, kMaxFramerate); EXPECT_EQ(kMinBitrateBps + 1, allocation.get_sum_bps()); diff --git a/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc b/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc index f986d3b636..aa9b32006b 100644 --- a/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc +++ b/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc @@ -65,7 +65,8 @@ class SimulcastRateAllocatorTest : public ::testing::TestWithParam { } template - void ExpectEqual(uint32_t (&expected)[S], const BitrateAllocation& actual) { + void ExpectEqual(uint32_t (&expected)[S], + const VideoBitrateAllocation& actual) { // EXPECT_EQ(S, actual.size()); uint32_t sum = 0; for (size_t i = 0; i < S; ++i) { @@ -112,7 +113,7 @@ class SimulcastRateAllocatorTest : public ::testing::TestWithParam { } } - BitrateAllocation GetAllocation(uint32_t target_bitrate) { + VideoBitrateAllocation GetAllocation(uint32_t target_bitrate) { return allocator_->GetAllocation(target_bitrate * 1000U, kDefaultFrameRate); } @@ -138,7 +139,7 @@ TEST_F(SimulcastRateAllocatorTest, NoSimulcastAboveMax) { } TEST_F(SimulcastRateAllocatorTest, NoSimulcastNoMax) { - const uint32_t kMax = BitrateAllocation::kMaxBitrateBps / 1000; + const uint32_t kMax = VideoBitrateAllocation::kMaxBitrateBps / 1000; codec_.active = true; codec_.maxBitrate = 0; CreateAllocator(); @@ -528,7 +529,7 @@ TEST_P(ScreenshareRateAllocationTest, BitrateBelowTl0) { SetupConferenceScreenshare(GetParam()); CreateAllocator(); - BitrateAllocation allocation = + VideoBitrateAllocation allocation = allocator_->GetAllocation(kTargetBitrateKbps * 1000, kFramerateFps); // All allocation should go in TL0. @@ -541,7 +542,7 @@ TEST_P(ScreenshareRateAllocationTest, BitrateAboveTl0) { CreateAllocator(); uint32_t target_bitrate_kbps = (kTargetBitrateKbps + kMaxBitrateKbps) / 2; - BitrateAllocation allocation = + VideoBitrateAllocation allocation = allocator_->GetAllocation(target_bitrate_kbps * 1000, kFramerateFps); // Fill TL0, then put the rest in TL1. @@ -555,7 +556,7 @@ TEST_P(ScreenshareRateAllocationTest, BitrateAboveTl1) { SetupConferenceScreenshare(GetParam()); CreateAllocator(); - BitrateAllocation allocation = + VideoBitrateAllocation allocation = allocator_->GetAllocation(kMaxBitrateKbps * 2000, kFramerateFps); // Fill both TL0 and TL1, but no more. @@ -573,7 +574,7 @@ TEST_P(ScreenshareRateAllocationTest, InactiveScreenshare) { // Enough bitrate for TL0 and TL1. uint32_t target_bitrate_kbps = (kTargetBitrateKbps + kMaxBitrateKbps) / 2; - BitrateAllocation allocation = + VideoBitrateAllocation allocation = allocator_->GetAllocation(target_bitrate_kbps * 1000, kFramerateFps); EXPECT_EQ(0U, allocation.get_sum_kbps()); diff --git a/modules/video_coding/video_codec_initializer_unittest.cc b/modules/video_coding/video_codec_initializer_unittest.cc index 2bb67cb439..2ef1159ff2 100644 --- a/modules/video_coding/video_codec_initializer_unittest.cc +++ b/modules/video_coding/video_codec_initializer_unittest.cc @@ -135,8 +135,9 @@ TEST_F(VideoCodecInitializerTest, SingleStreamVp8Screenshare) { streams_.push_back(DefaultStream()); EXPECT_TRUE(InitializeCodec()); - BitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation( - kDefaultTargetBitrateBps, kDefaultFrameRate); + VideoBitrateAllocation bitrate_allocation = + bitrate_allocator_out_->GetAllocation(kDefaultTargetBitrateBps, + kDefaultFrameRate); EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams); EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers); EXPECT_EQ(kDefaultTargetBitrateBps, bitrate_allocation.get_sum_bps()); @@ -149,8 +150,9 @@ TEST_F(VideoCodecInitializerTest, SingleStreamVp8ScreenshareInactive) { streams_.push_back(inactive_stream); EXPECT_TRUE(InitializeCodec()); - BitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation( - kDefaultTargetBitrateBps, kDefaultFrameRate); + VideoBitrateAllocation bitrate_allocation = + bitrate_allocator_out_->GetAllocation(kDefaultTargetBitrateBps, + kDefaultFrameRate); EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams); EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers); EXPECT_EQ(0U, bitrate_allocation.get_sum_bps()); @@ -163,8 +165,9 @@ TEST_F(VideoCodecInitializerTest, TemporalLayeredVp8Screenshare) { EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams); EXPECT_EQ(2u, codec_out_.VP8()->numberOfTemporalLayers); - BitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation( - kScreenshareCodecTargetBitrateBps, kScreenshareDefaultFramerate); + VideoBitrateAllocation bitrate_allocation = + bitrate_allocator_out_->GetAllocation(kScreenshareCodecTargetBitrateBps, + kScreenshareDefaultFramerate); EXPECT_EQ(kScreenshareCodecTargetBitrateBps, bitrate_allocation.get_sum_bps()); EXPECT_EQ(kScreenshareTl0BitrateBps, bitrate_allocation.GetBitrate(0, 0)); @@ -182,8 +185,9 @@ TEST_F(VideoCodecInitializerTest, SimulcastVp8Screenshare) { EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers); const uint32_t max_bitrate_bps = streams_[0].target_bitrate_bps + streams_[1].max_bitrate_bps; - BitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation( - max_bitrate_bps, kScreenshareDefaultFramerate); + VideoBitrateAllocation bitrate_allocation = + bitrate_allocator_out_->GetAllocation(max_bitrate_bps, + kScreenshareDefaultFramerate); EXPECT_EQ(max_bitrate_bps, bitrate_allocation.get_sum_bps()); EXPECT_EQ(static_cast(streams_[0].target_bitrate_bps), bitrate_allocation.GetSpatialLayerSum(0)); @@ -206,8 +210,9 @@ TEST_F(VideoCodecInitializerTest, SimulcastVp8ScreenshareInactive) { EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers); const uint32_t target_bitrate = streams_[0].target_bitrate_bps + streams_[1].target_bitrate_bps; - BitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation( - target_bitrate, kScreenshareDefaultFramerate); + VideoBitrateAllocation bitrate_allocation = + bitrate_allocator_out_->GetAllocation(target_bitrate, + kScreenshareDefaultFramerate); EXPECT_EQ(static_cast(streams_[0].max_bitrate_bps), bitrate_allocation.get_sum_bps()); EXPECT_EQ(static_cast(streams_[0].max_bitrate_bps), @@ -229,7 +234,7 @@ TEST_F(VideoCodecInitializerTest, HighFpsSimulcastVp8Screenshare) { EXPECT_EQ(3u, codec_out_.VP8()->numberOfTemporalLayers); const uint32_t max_bitrate_bps = streams_[0].target_bitrate_bps + streams_[1].max_bitrate_bps; - BitrateAllocation bitrate_allocation = + VideoBitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation(max_bitrate_bps, kDefaultFrameRate); EXPECT_EQ(max_bitrate_bps, bitrate_allocation.get_sum_bps()); EXPECT_EQ(static_cast(streams_[0].target_bitrate_bps), diff --git a/modules/video_coding/video_sender.cc b/modules/video_coding/video_sender.cc index 680b76f8c0..c8150a8a74 100644 --- a/modules/video_coding/video_sender.cc +++ b/modules/video_coding/video_sender.cc @@ -35,7 +35,7 @@ VideoSender::VideoSender(Clock* clock, _codecDataBase(&_encodedFrameCallback), frame_dropper_enabled_(true), current_codec_(), - encoder_params_({BitrateAllocation(), 0, 0, 0}), + encoder_params_({VideoBitrateAllocation(), 0, 0, 0}), encoder_has_internal_source_(false), next_frame_types_(1, kVideoFrameDelta) { _mediaOpt.Reset(); @@ -150,7 +150,7 @@ EncoderParameters VideoSender::UpdateEncoderParameters( if (input_frame_rate == 0) input_frame_rate = current_codec_.maxFramerate; - BitrateAllocation bitrate_allocation; + VideoBitrateAllocation bitrate_allocation; // Only call allocators if bitrate > 0 (ie, not suspended), otherwise they // might cap the bitrate to the min bitrate configured. if (target_bitrate_bps > 0) { @@ -171,7 +171,7 @@ EncoderParameters VideoSender::UpdateEncoderParameters( void VideoSender::UpdateChannelParameters( VideoBitrateAllocator* bitrate_allocator, VideoBitrateAllocationObserver* bitrate_updated_callback) { - BitrateAllocation target_rate; + VideoBitrateAllocation target_rate; { rtc::CritScope cs(¶ms_crit_); encoder_params_ = diff --git a/modules/video_coding/video_sender_unittest.cc b/modules/video_coding/video_sender_unittest.cc index 8e1330af68..877eb99635 100644 --- a/modules/video_coding/video_sender_unittest.cc +++ b/modules/video_coding/video_sender_unittest.cc @@ -306,7 +306,7 @@ TEST_F(TestVideoSenderWithMockEncoder, TestSetRate) { const uint32_t new_bitrate_kbps = settings_.startBitrate + 300; // Initial frame rate is taken from config, as we have no data yet. - BitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation( + VideoBitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation( new_bitrate_kbps * 1000, settings_.maxFramerate); EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, settings_.maxFramerate)) @@ -351,7 +351,7 @@ TEST_F(TestVideoSenderWithMockEncoder, TestEncoderParametersForInternalSource) { // Update encoder bitrate parameters. We expect that to immediately call // SetRates on the encoder without waiting for AddFrame processing. const uint32_t new_bitrate_kbps = settings_.startBitrate + 300; - BitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation( + VideoBitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation( new_bitrate_kbps * 1000, settings_.maxFramerate); EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, _)) .Times(1) @@ -383,7 +383,7 @@ TEST_F(TestVideoSenderWithMockEncoder, // Call to SetChannelParameters with changed bitrate should call encoder // SetRates but not encoder SetChannelParameters (that are unchanged). uint32_t new_bitrate_bps = 2 * settings_.startBitrate * 1000; - BitrateAllocation new_rate_allocation = + VideoBitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation(new_bitrate_bps, kInputFps); EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, kInputFps)) .Times(1) diff --git a/sdk/android/src/jni/androidmediaencoder.cc b/sdk/android/src/jni/androidmediaencoder.cc index a75d037d95..5e59f06f07 100644 --- a/sdk/android/src/jni/androidmediaencoder.cc +++ b/sdk/android/src/jni/androidmediaencoder.cc @@ -110,7 +110,7 @@ class MediaCodecVideoEncoder : public VideoEncoder { int32_t Release() override; int32_t SetChannelParameters(uint32_t /* packet_loss */, int64_t /* rtt */) override; - int32_t SetRateAllocation(const BitrateAllocation& rate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation, uint32_t frame_rate) override; bool SupportsNativeHandle() const override { return egl_context_ != nullptr; } @@ -951,7 +951,7 @@ int32_t MediaCodecVideoEncoder::Release() { } int32_t MediaCodecVideoEncoder::SetRateAllocation( - const BitrateAllocation& rate_allocation, + const VideoBitrateAllocation& rate_allocation, uint32_t frame_rate) { RTC_DCHECK_CALLED_SEQUENTIALLY(&encoder_queue_checker_); const uint32_t new_bit_rate = rate_allocation.get_sum_kbps(); diff --git a/sdk/android/src/jni/videoencoderwrapper.cc b/sdk/android/src/jni/videoencoderwrapper.cc index 4f4086ba2f..621f824128 100644 --- a/sdk/android/src/jni/videoencoderwrapper.cc +++ b/sdk/android/src/jni/videoencoderwrapper.cc @@ -149,7 +149,7 @@ int32_t VideoEncoderWrapper::SetChannelParameters(uint32_t packet_loss, } int32_t VideoEncoderWrapper::SetRateAllocation( - const BitrateAllocation& allocation, + const VideoBitrateAllocation& allocation, uint32_t framerate) { JNIEnv* jni = AttachCurrentThreadIfNeeded(); @@ -437,7 +437,7 @@ CodecSpecificInfo VideoEncoderWrapper::ParseCodecSpecificInfo( ScopedJavaLocalRef VideoEncoderWrapper::ToJavaBitrateAllocation( JNIEnv* jni, - const BitrateAllocation& allocation) { + const VideoBitrateAllocation& allocation) { ScopedJavaLocalRef j_allocation_array( jni, jni->NewObjectArray(kMaxSpatialLayers, int_array_class_.obj(), nullptr /* initial */)); diff --git a/sdk/android/src/jni/videoencoderwrapper.h b/sdk/android/src/jni/videoencoderwrapper.h index f25e83db69..c58a0afbca 100644 --- a/sdk/android/src/jni/videoencoderwrapper.h +++ b/sdk/android/src/jni/videoencoderwrapper.h @@ -47,7 +47,7 @@ class VideoEncoderWrapper : public VideoEncoder { int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int32_t SetRateAllocation(const BitrateAllocation& allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& allocation, uint32_t framerate) override; ScalingSettings GetScalingSettings() const override; @@ -89,7 +89,7 @@ class VideoEncoderWrapper : public VideoEncoder { CodecSpecificInfo ParseCodecSpecificInfo(const EncodedImage& frame); ScopedJavaLocalRef ToJavaBitrateAllocation( JNIEnv* jni, - const BitrateAllocation& allocation); + const VideoBitrateAllocation& allocation); std::string GetImplementationName(JNIEnv* jni) const; const ScopedJavaGlobalRef encoder_; diff --git a/test/configurable_frame_size_encoder.cc b/test/configurable_frame_size_encoder.cc index f09be533af..107c4cb498 100644 --- a/test/configurable_frame_size_encoder.cc +++ b/test/configurable_frame_size_encoder.cc @@ -74,7 +74,7 @@ int32_t ConfigurableFrameSizeEncoder::SetChannelParameters(uint32_t packet_loss, } int32_t ConfigurableFrameSizeEncoder::SetRateAllocation( - const BitrateAllocation& allocation, + const VideoBitrateAllocation& allocation, uint32_t framerate) { return WEBRTC_VIDEO_CODEC_OK; } diff --git a/test/configurable_frame_size_encoder.h b/test/configurable_frame_size_encoder.h index f3733c8369..b8c3b830d4 100644 --- a/test/configurable_frame_size_encoder.h +++ b/test/configurable_frame_size_encoder.h @@ -39,7 +39,7 @@ class ConfigurableFrameSizeEncoder : public VideoEncoder { int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int32_t SetRateAllocation(const BitrateAllocation& allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& allocation, uint32_t framerate) override; int32_t SetFrameSize(size_t size); diff --git a/test/encoder_proxy_factory.h b/test/encoder_proxy_factory.h index 9c7ff0c652..2982010711 100644 --- a/test/encoder_proxy_factory.h +++ b/test/encoder_proxy_factory.h @@ -82,7 +82,7 @@ class EncoderProxyFactory final : public VideoEncoderFactory { int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override { return encoder_->SetChannelParameters(packet_loss, rtt); } - int32_t SetRateAllocation(const BitrateAllocation& rate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation, uint32_t framerate) override { return encoder_->SetRateAllocation(rate_allocation, framerate); } diff --git a/test/fake_encoder.cc b/test/fake_encoder.cc index a7dbbd9048..c8d13cb6bc 100644 --- a/test/fake_encoder.cc +++ b/test/fake_encoder.cc @@ -178,8 +178,9 @@ int32_t FakeEncoder::SetChannelParameters(uint32_t packet_loss, int64_t rtt) { return 0; } -int32_t FakeEncoder::SetRateAllocation(const BitrateAllocation& rate_allocation, - uint32_t framerate) { +int32_t FakeEncoder::SetRateAllocation( + const VideoBitrateAllocation& rate_allocation, + uint32_t framerate) { rtc::CritScope cs(&crit_sect_); target_bitrate_ = rate_allocation; configured_input_framerate_ = framerate; diff --git a/test/fake_encoder.h b/test/fake_encoder.h index f6ed2899e0..2700f3d6f1 100644 --- a/test/fake_encoder.h +++ b/test/fake_encoder.h @@ -42,7 +42,7 @@ class FakeEncoder : public VideoEncoder { EncodedImageCallback* callback) override; int32_t Release() override; int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; - int32_t SetRateAllocation(const BitrateAllocation& rate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation, uint32_t framerate) override; const char* ImplementationName() const override; int GetConfiguredInputFramerate() const; @@ -53,7 +53,7 @@ class FakeEncoder : public VideoEncoder { Clock* const clock_; VideoCodec config_ RTC_GUARDED_BY(crit_sect_); EncodedImageCallback* callback_ RTC_GUARDED_BY(crit_sect_); - BitrateAllocation target_bitrate_ RTC_GUARDED_BY(crit_sect_); + VideoBitrateAllocation target_bitrate_ RTC_GUARDED_BY(crit_sect_); int configured_input_framerate_ RTC_GUARDED_BY(crit_sect_); int max_target_bitrate_kbps_ RTC_GUARDED_BY(crit_sect_); bool pending_keyframe_ RTC_GUARDED_BY(crit_sect_); diff --git a/video/end_to_end_tests/bandwidth_tests.cc b/video/end_to_end_tests/bandwidth_tests.cc index 50e874b661..dc4e1c9756 100644 --- a/video/end_to_end_tests/bandwidth_tests.cc +++ b/video/end_to_end_tests/bandwidth_tests.cc @@ -299,7 +299,7 @@ TEST_P(BandwidthEndToEndTest, ReportsSetEncoderRates) { RTC_DCHECK_EQ(1, encoder_config->number_of_streams); } - int32_t SetRateAllocation(const BitrateAllocation& rate_allocation, + int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation, uint32_t framerate) override { // Make sure not to trigger on any default zero bitrates. if (rate_allocation.get_sum_bps() == 0) diff --git a/video/payload_router.cc b/video/payload_router.cc index b06908fe1f..b76257794b 100644 --- a/video/payload_router.cc +++ b/video/payload_router.cc @@ -266,15 +266,15 @@ EncodedImageCallback::Result PayloadRouter::OnEncodedImage( } void PayloadRouter::OnBitrateAllocationUpdated( - const BitrateAllocation& bitrate) { + const VideoBitrateAllocation& bitrate) { rtc::CritScope lock(&crit_); if (IsActive()) { if (rtp_modules_.size() == 1) { // If spatial scalability is enabled, it is covered by a single stream. rtp_modules_[0]->SetVideoBitrateAllocation(bitrate); } else { - // Simulcast is in use, split the BitrateAllocation into one struct per - // rtp stream, moving over the temporal layer allocation. + // Simulcast is in use, split the VideoBitrateAllocation into one struct + // per rtp stream, moving over the temporal layer allocation. for (size_t si = 0; si < rtp_modules_.size(); ++si) { // Don't send empty TargetBitrate messages on streams not being relayed. if (!bitrate.IsSpatialLayerUsed(si)) { @@ -283,7 +283,7 @@ void PayloadRouter::OnBitrateAllocationUpdated( continue; } - BitrateAllocation layer_bitrate; + VideoBitrateAllocation layer_bitrate; for (int tl = 0; tl < kMaxTemporalStreams; ++tl) { if (bitrate.HasBitrate(si, tl)) layer_bitrate.SetBitrate(0, tl, bitrate.GetBitrate(si, tl)); diff --git a/video/payload_router.h b/video/payload_router.h index e32d60729a..dc6284d03f 100644 --- a/video/payload_router.h +++ b/video/payload_router.h @@ -60,7 +60,7 @@ class PayloadRouter : public EncodedImageCallback { const CodecSpecificInfo* codec_specific_info, const RTPFragmentationHeader* fragmentation) override; - void OnBitrateAllocationUpdated(const BitrateAllocation& bitrate); + void OnBitrateAllocationUpdated(const VideoBitrateAllocation& bitrate); private: class RtpPayloadParams; diff --git a/video/payload_router_unittest.cc b/video/payload_router_unittest.cc index af574429a1..a559be04cb 100644 --- a/video/payload_router_unittest.cc +++ b/video/payload_router_unittest.cc @@ -232,17 +232,17 @@ TEST(PayloadRouterTest, SimulcastTargetBitrate) { PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); payload_router.SetActive(true); - BitrateAllocation bitrate; + VideoBitrateAllocation bitrate; bitrate.SetBitrate(0, 0, 10000); bitrate.SetBitrate(0, 1, 20000); bitrate.SetBitrate(1, 0, 40000); bitrate.SetBitrate(1, 1, 80000); - BitrateAllocation layer0_bitrate; + VideoBitrateAllocation layer0_bitrate; layer0_bitrate.SetBitrate(0, 0, 10000); layer0_bitrate.SetBitrate(0, 1, 20000); - BitrateAllocation layer1_bitrate; + VideoBitrateAllocation layer1_bitrate; layer1_bitrate.SetBitrate(0, 0, 40000); layer1_bitrate.SetBitrate(0, 1, 80000); @@ -265,17 +265,17 @@ TEST(PayloadRouterTest, SimulcastTargetBitrateWithInactiveStream) { payload_router.SetActive(true); // Create bitrate allocation with bitrate only for the first and third stream. - BitrateAllocation bitrate; + VideoBitrateAllocation bitrate; bitrate.SetBitrate(0, 0, 10000); bitrate.SetBitrate(0, 1, 20000); bitrate.SetBitrate(2, 0, 40000); bitrate.SetBitrate(2, 1, 80000); - BitrateAllocation layer0_bitrate; + VideoBitrateAllocation layer0_bitrate; layer0_bitrate.SetBitrate(0, 0, 10000); layer0_bitrate.SetBitrate(0, 1, 20000); - BitrateAllocation layer2_bitrate; + VideoBitrateAllocation layer2_bitrate; layer2_bitrate.SetBitrate(0, 0, 40000); layer2_bitrate.SetBitrate(0, 1, 80000); @@ -294,7 +294,7 @@ TEST(PayloadRouterTest, SvcTargetBitrate) { PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {}); payload_router.SetActive(true); - BitrateAllocation bitrate; + VideoBitrateAllocation bitrate; bitrate.SetBitrate(0, 0, 10000); bitrate.SetBitrate(0, 1, 20000); bitrate.SetBitrate(1, 0, 40000); diff --git a/video/video_send_stream_impl.cc b/video/video_send_stream_impl.cc index 5e032fc565..f2bb8d3d6b 100644 --- a/video/video_send_stream_impl.cc +++ b/video/video_send_stream_impl.cc @@ -583,7 +583,7 @@ void VideoSendStreamImpl::SignalEncoderTimedOut() { } void VideoSendStreamImpl::OnBitrateAllocationUpdated( - const BitrateAllocation& allocation) { + const VideoBitrateAllocation& allocation) { payload_router_.OnBitrateAllocationUpdated(allocation); } diff --git a/video/video_send_stream_impl.h b/video/video_send_stream_impl.h index d237dfdacb..84fca8f12c 100644 --- a/video/video_send_stream_impl.h +++ b/video/video_send_stream_impl.h @@ -126,7 +126,8 @@ class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver, const RTPFragmentationHeader* fragmentation) override; // Implements VideoBitrateAllocationObserver. - void OnBitrateAllocationUpdated(const BitrateAllocation& allocation) override; + void OnBitrateAllocationUpdated( + const VideoBitrateAllocation& allocation) override; // Starts monitoring and sends a keyframe. void StartupVideoSendStream(); diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc index 1073a0c4d1..1b25108d50 100644 --- a/video/video_send_stream_tests.cc +++ b/video/video_send_stream_tests.cc @@ -2052,7 +2052,7 @@ class StartStopBitrateObserver : public test::FakeEncoder { return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); } - int32_t SetRateAllocation(const BitrateAllocation& bitrate, + int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate, uint32_t framerate) override { rtc::CritScope lock(&crit_); bitrate_kbps_ = bitrate.get_sum_kbps(); @@ -2884,7 +2884,7 @@ TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) { maxPayloadSize); } - int32_t SetRateAllocation(const BitrateAllocation& bitrate, + int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate, uint32_t frameRate) override { { rtc::CritScope lock(&crit_); @@ -3657,7 +3657,7 @@ TEST_F(VideoSendStreamTest, RemoveOverheadFromBandwidth) { first_packet_sent_(false), bitrate_changed_event_(false, false) {} - int32_t SetRateAllocation(const BitrateAllocation& bitrate, + int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate, uint32_t frameRate) override { rtc::CritScope lock(&crit_); // Wait for the first sent packet so that videosendstream knows diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index 85d411804a..5289f9a9a5 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -260,7 +260,7 @@ class MockableSendStatisticsProxy : public SendStatisticsProxy { class MockBitrateObserver : public VideoBitrateAllocationObserver { public: - MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&)); + MOCK_METHOD1(OnBitrateAllocationUpdated, void(const VideoBitrateAllocation&)); }; } // namespace @@ -2247,7 +2247,7 @@ TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) { video_stream_encoder_->SetBitrateObserver(&bitrate_observer); const int kDefaultFps = 30; - const BitrateAllocation expected_bitrate = + const VideoBitrateAllocation expected_bitrate = DefaultVideoBitrateAllocator(fake_encoder_.codec_config()) .GetAllocation(kLowTargetBitrateBps, kDefaultFps);