Move BitrateAllocation to api/ and rename it VideoBitrateAllocation
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 <kwiberg@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Commit-Queue: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22986}
This commit is contained in:
parent
5c14725d53
commit
566124a6df
1
BUILD.gn
1
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",
|
||||
|
||||
15
api/BUILD.gn
15
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") {
|
||||
|
||||
168
api/video/video_bitrate_allocation.cc
Normal file
168
api/video/video_bitrate_allocation.cc
Normal file
@ -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 <limits>
|
||||
|
||||
#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<uint32_t>& 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<uint32_t>(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<uint32_t> VideoBitrateAllocation::GetTemporalLayerAllocation(
|
||||
size_t spatial_index) const {
|
||||
RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
|
||||
std::vector<uint32_t> 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
|
||||
85
api/video/video_bitrate_allocation.h
Normal file
85
api/video/video_bitrate_allocation.h
Normal file
@ -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 <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<uint32_t>::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<uint32_t> 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<uint32_t> bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // API_VIDEO_VIDEO_BITRATE_ALLOCATION_H_
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 &&
|
||||
|
||||
133
common_types.cc
133
common_types.cc
@ -174,137 +174,4 @@ VideoCodecType PayloadStringToCodecType(const std::string& name) {
|
||||
return kVideoCodecGeneric;
|
||||
}
|
||||
|
||||
const uint32_t BitrateAllocation::kMaxBitrateBps =
|
||||
std::numeric_limits<uint32_t>::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<uint32_t>(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<uint32_t> BitrateAllocation::GetTemporalLayerAllocation(
|
||||
size_t spatial_index) const {
|
||||
RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
|
||||
std::vector<uint32_t> 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
|
||||
|
||||
@ -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<uint32_t> 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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ class ScopedVideoEncoder : public webrtc::VideoEncoder {
|
||||
const std::vector<webrtc::FrameType>* 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);
|
||||
}
|
||||
|
||||
@ -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<uint32_t> 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));
|
||||
|
||||
@ -47,7 +47,7 @@ class SimulcastEncoderAdapter : public VP8Encoder {
|
||||
const std::vector<FrameType>* 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
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -42,7 +42,7 @@ class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder {
|
||||
const CodecSpecificInfo* codec_specific_info,
|
||||
const std::vector<FrameType>* 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.
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ class VP8EncoderSimulcastProxy : public VP8Encoder {
|
||||
const std::vector<FrameType>* 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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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_;
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@ struct RTCPReceiver::PacketInformation {
|
||||
int64_t rtt_ms = 0;
|
||||
uint32_t receiver_estimated_max_bitrate_bps = 0;
|
||||
std::unique_ptr<rtcp::TransportFeedback> transport_feedback;
|
||||
rtc::Optional<BitrateAllocation> target_bitrate_allocation;
|
||||
rtc::Optional<VideoBitrateAllocation> 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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -149,7 +149,7 @@ class RTCPSender {
|
||||
void SetCsrcs(const std::vector<uint32_t>& 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<BitrateAllocation> video_bitrate_allocation_
|
||||
rtc::Optional<VideoBitrateAllocation> video_bitrate_allocation_
|
||||
RTC_GUARDED_BY(critical_section_rtcp_sender_);
|
||||
|
||||
void SetFlag(uint32_t type, bool is_volatile)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 ||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -927,7 +927,7 @@ StreamDataCountersCallback*
|
||||
}
|
||||
|
||||
void ModuleRtpRtcpImpl::SetVideoBitrateAllocation(
|
||||
const BitrateAllocation& bitrate) {
|
||||
const VideoBitrateAllocation& bitrate) {
|
||||
rtcp_sender_.SetVideoBitrateAllocation(bitrate);
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -46,7 +46,7 @@ class MultiplexEncoderAdapter : public VideoEncoder {
|
||||
const std::vector<FrameType>* 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;
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -188,7 +188,7 @@ class VideoProcessor {
|
||||
webrtc::VideoEncoder* const encoder_;
|
||||
VideoDecoderList* const decoders_;
|
||||
const std::unique_ptr<VideoBitrateAllocator> 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.
|
||||
|
||||
@ -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); });
|
||||
|
||||
@ -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<uint32_t> stream_bitrates;
|
||||
for (int i = 0; i == 0 || i < inst->numberOfSimulcastStreams; ++i) {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<int>(codec_.numberOfSimulcastStreams));
|
||||
|
||||
|
||||
@ -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<uint32_t> DefaultTemporalLayerAllocation(int bitrate_kbps,
|
||||
int max_bitrate_kbps,
|
||||
int framerate,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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() {}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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));
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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());
|
||||
|
||||
|
||||
@ -65,7 +65,8 @@ class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> {
|
||||
}
|
||||
|
||||
template <size_t S>
|
||||
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<bool> {
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
@ -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<uint32_t>(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<uint32_t>(streams_[0].max_bitrate_bps),
|
||||
bitrate_allocation.get_sum_bps());
|
||||
EXPECT_EQ(static_cast<uint32_t>(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<uint32_t>(streams_[0].target_bitrate_bps),
|
||||
|
||||
@ -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_ =
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<jobject> VideoEncoderWrapper::ToJavaBitrateAllocation(
|
||||
JNIEnv* jni,
|
||||
const BitrateAllocation& allocation) {
|
||||
const VideoBitrateAllocation& allocation) {
|
||||
ScopedJavaLocalRef<jobjectArray> j_allocation_array(
|
||||
jni, jni->NewObjectArray(kMaxSpatialLayers, int_array_class_.obj(),
|
||||
nullptr /* initial */));
|
||||
|
||||
@ -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<jobject> ToJavaBitrateAllocation(
|
||||
JNIEnv* jni,
|
||||
const BitrateAllocation& allocation);
|
||||
const VideoBitrateAllocation& allocation);
|
||||
std::string GetImplementationName(JNIEnv* jni) const;
|
||||
|
||||
const ScopedJavaGlobalRef<jobject> encoder_;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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_);
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -583,7 +583,7 @@ void VideoSendStreamImpl::SignalEncoderTimedOut() {
|
||||
}
|
||||
|
||||
void VideoSendStreamImpl::OnBitrateAllocationUpdated(
|
||||
const BitrateAllocation& allocation) {
|
||||
const VideoBitrateAllocation& allocation) {
|
||||
payload_router_.OnBitrateAllocationUpdated(allocation);
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user