Update VideoBitrateAllocator allocate to take a struct with more fields
We want to evaluate more data in order to make better choices in the bitrate allocators. In order to freely update the parameter list without breaking the API many times for projects customizing them, we'll use a struct instead. Bug: webrtc:10126 Change-Id: I443f86781c5134950294cdd1e3197a47447cf973 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/141418 Commit-Queue: Florent Castelli <orphis@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28748}
This commit is contained in:
committed by
Commit Bot
parent
9a9f18a736
commit
8bbdb5b9bd
@ -294,8 +294,9 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* inst,
|
||||
}
|
||||
|
||||
SimulcastRateAllocator init_allocator(codec_);
|
||||
VideoBitrateAllocation allocation = init_allocator.GetAllocation(
|
||||
codec_.startBitrate * 1000, codec_.maxFramerate);
|
||||
VideoBitrateAllocation allocation =
|
||||
init_allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
DataRate::kbps(codec_.startBitrate), codec_.maxFramerate));
|
||||
SetRates(RateControlParameters(allocation, codec_.maxFramerate));
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
@ -305,8 +305,9 @@ void VideoProcessor::ProcessFrame() {
|
||||
void VideoProcessor::SetRates(size_t bitrate_kbps, double framerate_fps) {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
framerate_fps_ = framerate_fps;
|
||||
bitrate_allocation_ = bitrate_allocator_->GetAllocation(
|
||||
static_cast<uint32_t>(bitrate_kbps * 1000), framerate_fps_);
|
||||
bitrate_allocation_ =
|
||||
bitrate_allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
static_cast<uint32_t>(bitrate_kbps * 1000), framerate_fps_));
|
||||
encoder_->SetRates(
|
||||
VideoEncoder::RateControlParameters(bitrate_allocation_, framerate_fps_));
|
||||
}
|
||||
|
||||
@ -96,7 +96,9 @@ std::vector<uint32_t> GetTemporalLayerRates(int target_bitrate_kbps,
|
||||
codec.simulcastStream[0].numberOfTemporalLayers = num_temporal_layers;
|
||||
codec.simulcastStream[0].active = true;
|
||||
SimulcastRateAllocator allocator(codec);
|
||||
return allocator.GetAllocation(target_bitrate_kbps, framerate_fps)
|
||||
return allocator
|
||||
.Allocate(
|
||||
VideoBitrateAllocationParameters(target_bitrate_kbps, framerate_fps))
|
||||
.GetTemporalLayerAllocation(0);
|
||||
}
|
||||
|
||||
|
||||
@ -642,8 +642,9 @@ int LibvpxVp8Encoder::InitEncode(const VideoCodec* inst,
|
||||
// at position 0 and they have highest resolution at position 0.
|
||||
const size_t stream_idx_cfg_0 = encoders_.size() - 1;
|
||||
SimulcastRateAllocator init_allocator(codec_);
|
||||
VideoBitrateAllocation allocation = init_allocator.GetAllocation(
|
||||
inst->startBitrate * 1000, inst->maxFramerate);
|
||||
VideoBitrateAllocation allocation =
|
||||
init_allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
inst->startBitrate * 1000, inst->maxFramerate));
|
||||
std::vector<uint32_t> stream_bitrates;
|
||||
for (int i = 0; i == 0 || i < inst->numberOfSimulcastStreams; ++i) {
|
||||
uint32_t bitrate = allocation.GetSpatialLayerSum(i) / 1000;
|
||||
|
||||
@ -103,18 +103,18 @@ SvcRateAllocator::SvcRateAllocator(const VideoCodec& codec) : codec_(codec) {
|
||||
RTC_DCHECK_GT(codec.VP9().numberOfTemporalLayers, 0u);
|
||||
}
|
||||
|
||||
VideoBitrateAllocation SvcRateAllocator::GetAllocation(
|
||||
uint32_t total_bitrate_bps,
|
||||
uint32_t framerate_fps) {
|
||||
VideoBitrateAllocation SvcRateAllocator::Allocate(
|
||||
VideoBitrateAllocationParameters parameters) {
|
||||
DataRate total_bitrate = parameters.total_bitrate;
|
||||
if (codec_.maxBitrate != 0) {
|
||||
total_bitrate_bps = std::min(total_bitrate_bps, codec_.maxBitrate * 1000);
|
||||
total_bitrate = std::min(total_bitrate, DataRate::kbps(codec_.maxBitrate));
|
||||
}
|
||||
|
||||
if (codec_.spatialLayers[0].targetBitrate == 0) {
|
||||
// Delegate rate distribution to VP9 encoder wrapper if bitrate thresholds
|
||||
// are not set.
|
||||
VideoBitrateAllocation bitrate_allocation;
|
||||
bitrate_allocation.SetBitrate(0, 0, total_bitrate_bps);
|
||||
bitrate_allocation.SetBitrate(0, 0, total_bitrate.bps());
|
||||
return bitrate_allocation;
|
||||
}
|
||||
|
||||
@ -124,9 +124,9 @@ VideoBitrateAllocation SvcRateAllocator::GetAllocation(
|
||||
}
|
||||
|
||||
if (codec_.mode == VideoCodecMode::kRealtimeVideo) {
|
||||
return GetAllocationNormalVideo(total_bitrate_bps, num_spatial_layers);
|
||||
return GetAllocationNormalVideo(total_bitrate.bps(), num_spatial_layers);
|
||||
} else {
|
||||
return GetAllocationScreenSharing(total_bitrate_bps, num_spatial_layers);
|
||||
return GetAllocationScreenSharing(total_bitrate.bps(), num_spatial_layers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,8 +26,8 @@ class SvcRateAllocator : public VideoBitrateAllocator {
|
||||
public:
|
||||
explicit SvcRateAllocator(const VideoCodec& codec);
|
||||
|
||||
VideoBitrateAllocation GetAllocation(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate_fps) override;
|
||||
VideoBitrateAllocation Allocate(
|
||||
VideoBitrateAllocationParameters parameters) override;
|
||||
|
||||
static uint32_t GetMaxBitrateBps(const VideoCodec& codec);
|
||||
static uint32_t GetPaddingBitrateBps(const VideoCodec& codec);
|
||||
|
||||
@ -52,7 +52,8 @@ TEST(SvcRateAllocatorTest, SingleLayerFor320x180Input) {
|
||||
VideoCodec codec = Configure(320, 180, 3, 3, false);
|
||||
SvcRateAllocator allocator = SvcRateAllocator(codec);
|
||||
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.Allocate(VideoBitrateAllocationParameters(1000 * 1000, 30));
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(1), 0u);
|
||||
@ -62,7 +63,8 @@ TEST(SvcRateAllocatorTest, TwoLayersFor640x360Input) {
|
||||
VideoCodec codec = Configure(640, 360, 3, 3, false);
|
||||
SvcRateAllocator allocator = SvcRateAllocator(codec);
|
||||
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.Allocate(VideoBitrateAllocationParameters(1000 * 1000, 30));
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(1), 0u);
|
||||
@ -73,7 +75,8 @@ TEST(SvcRateAllocatorTest, ThreeLayersFor1280x720Input) {
|
||||
VideoCodec codec = Configure(1280, 720, 3, 3, false);
|
||||
SvcRateAllocator allocator = SvcRateAllocator(codec);
|
||||
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(1000 * 1000, 30);
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.Allocate(VideoBitrateAllocationParameters(1000 * 1000, 30));
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(1), 0u);
|
||||
@ -87,8 +90,8 @@ TEST(SvcRateAllocatorTest,
|
||||
|
||||
const SpatialLayer* layers = codec.spatialLayers;
|
||||
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.GetAllocation(layers[0].minBitrate * 1000 / 2, 30);
|
||||
VideoBitrateAllocation allocation = allocator.Allocate(
|
||||
VideoBitrateAllocationParameters(layers[0].minBitrate * 1000 / 2, 30));
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_LT(allocation.GetSpatialLayerSum(0), layers[0].minBitrate * 1000);
|
||||
@ -104,8 +107,9 @@ TEST(SvcRateAllocatorTest, Disable640x360Layer) {
|
||||
size_t min_bitrate_for_640x360_layer_kbps =
|
||||
layers[0].minBitrate + layers[1].minBitrate;
|
||||
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(
|
||||
min_bitrate_for_640x360_layer_kbps * 1000 - 1, 30);
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
min_bitrate_for_640x360_layer_kbps * 1000 - 1, 30));
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(1), 0u);
|
||||
@ -120,8 +124,9 @@ TEST(SvcRateAllocatorTest, Disable1280x720Layer) {
|
||||
size_t min_bitrate_for_1280x720_layer_kbps =
|
||||
layers[0].minBitrate + layers[1].minBitrate + layers[2].minBitrate;
|
||||
|
||||
VideoBitrateAllocation allocation = allocator.GetAllocation(
|
||||
min_bitrate_for_1280x720_layer_kbps * 1000 - 1, 30);
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
min_bitrate_for_1280x720_layer_kbps * 1000 - 1, 30));
|
||||
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0u);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(1), 0u);
|
||||
@ -135,8 +140,8 @@ TEST(SvcRateAllocatorTest, BitrateIsCapped) {
|
||||
const SpatialLayer* layers = codec.spatialLayers;
|
||||
|
||||
const uint32_t link_mbps = 100;
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.GetAllocation(link_mbps * 1000000, 30);
|
||||
VideoBitrateAllocation allocation = allocator.Allocate(
|
||||
VideoBitrateAllocationParameters(link_mbps * 1000000, 30));
|
||||
|
||||
EXPECT_EQ(allocation.get_sum_kbps(),
|
||||
layers[0].maxBitrate + layers[1].maxBitrate + layers[2].maxBitrate);
|
||||
@ -153,13 +158,13 @@ TEST(SvcRateAllocatorTest, MinBitrateToGetQualityLayer) {
|
||||
|
||||
EXPECT_LE(codec.VP9()->numberOfSpatialLayers, 3U);
|
||||
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.GetAllocation(layers[0].minBitrate * 1000, 30);
|
||||
VideoBitrateAllocation allocation = allocator.Allocate(
|
||||
VideoBitrateAllocationParameters(layers[0].minBitrate * 1000, 30));
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(0) / 1000, layers[0].minBitrate);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(1), 0UL);
|
||||
|
||||
allocation = allocator.GetAllocation(
|
||||
(layers[0].targetBitrate + layers[1].minBitrate) * 1000, 30);
|
||||
allocation = allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
(layers[0].targetBitrate + layers[1].minBitrate) * 1000, 30));
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(0) / 1000, layers[0].targetBitrate);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(1) / 1000, layers[1].minBitrate);
|
||||
}
|
||||
@ -173,8 +178,8 @@ TEST(SvcRateAllocatorTest, DeativateLayers) {
|
||||
|
||||
SvcRateAllocator allocator = SvcRateAllocator(codec);
|
||||
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.GetAllocation(10 * 1000 * 1000, 30);
|
||||
VideoBitrateAllocation allocation = allocator.Allocate(
|
||||
VideoBitrateAllocationParameters(10 * 1000 * 1000, 30));
|
||||
|
||||
// Ensure layers spatial_idx < deactivated_idx are activated.
|
||||
for (int spatial_idx = 0; spatial_idx < deactivated_idx; ++spatial_idx) {
|
||||
@ -227,14 +232,15 @@ TEST_P(SvcRateAllocatorTestParametrizedContentType, PaddingBitrate) {
|
||||
|
||||
uint32_t padding_bitrate_bps = SvcRateAllocator::GetPaddingBitrateBps(codec);
|
||||
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator.GetAllocation(padding_bitrate_bps, 30);
|
||||
VideoBitrateAllocation allocation = allocator.Allocate(
|
||||
VideoBitrateAllocationParameters(padding_bitrate_bps, 30));
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0UL);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(1), 0UL);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(2), 0UL);
|
||||
|
||||
// Allocate 90% of padding bitrate. Top layer should be disabled.
|
||||
allocation = allocator.GetAllocation(9 * padding_bitrate_bps / 10, 30);
|
||||
allocation = allocator.Allocate(
|
||||
VideoBitrateAllocationParameters(9 * padding_bitrate_bps / 10, 30));
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0UL);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(1), 0UL);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(2), 0UL);
|
||||
@ -243,12 +249,14 @@ TEST_P(SvcRateAllocatorTestParametrizedContentType, PaddingBitrate) {
|
||||
codec.spatialLayers[2].active = false;
|
||||
|
||||
padding_bitrate_bps = SvcRateAllocator::GetPaddingBitrateBps(codec);
|
||||
allocation = allocator.GetAllocation(padding_bitrate_bps, 30);
|
||||
allocation = allocator.Allocate(
|
||||
VideoBitrateAllocationParameters(padding_bitrate_bps, 30));
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0UL);
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(1), 0UL);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(2), 0UL);
|
||||
|
||||
allocation = allocator.GetAllocation(9 * padding_bitrate_bps / 10, 30);
|
||||
allocation = allocator.Allocate(
|
||||
VideoBitrateAllocationParameters(9 * padding_bitrate_bps / 10, 30));
|
||||
EXPECT_GT(allocation.GetSpatialLayerSum(0), 0UL);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(1), 0UL);
|
||||
EXPECT_EQ(allocation.GetSpatialLayerSum(2), 0UL);
|
||||
|
||||
@ -659,8 +659,9 @@ int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) {
|
||||
}
|
||||
|
||||
SvcRateAllocator init_allocator(codec_);
|
||||
current_bitrate_allocation_ = init_allocator.GetAllocation(
|
||||
inst->startBitrate * 1000, inst->maxFramerate);
|
||||
current_bitrate_allocation_ =
|
||||
init_allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
inst->startBitrate * 1000, inst->maxFramerate));
|
||||
if (!SetSvcRates(current_bitrate_allocation_)) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
}
|
||||
|
||||
@ -25,14 +25,13 @@ DefaultVideoBitrateAllocator::~DefaultVideoBitrateAllocator() {}
|
||||
|
||||
// TODO(http://crbug.com/webrtc/9671): Do not split bitrate between simulcast
|
||||
// streams, but allocate everything to the first stream.
|
||||
VideoBitrateAllocation DefaultVideoBitrateAllocator::GetAllocation(
|
||||
uint32_t total_bitrate_bps,
|
||||
uint32_t framerate) {
|
||||
VideoBitrateAllocation DefaultVideoBitrateAllocator::Allocate(
|
||||
VideoBitrateAllocationParameters parameters) {
|
||||
VideoBitrateAllocation allocation;
|
||||
if (total_bitrate_bps == 0 || !codec_.active)
|
||||
if (parameters.total_bitrate.IsZero() || !codec_.active)
|
||||
return allocation;
|
||||
|
||||
uint32_t allocated_bitrate_bps = total_bitrate_bps;
|
||||
uint32_t allocated_bitrate_bps = parameters.total_bitrate.bps();
|
||||
allocated_bitrate_bps =
|
||||
std::max(allocated_bitrate_bps, codec_.minBitrate * 1000);
|
||||
if (codec_.maxBitrate > 0) {
|
||||
|
||||
@ -24,8 +24,8 @@ class DefaultVideoBitrateAllocator : public VideoBitrateAllocator {
|
||||
explicit DefaultVideoBitrateAllocator(const VideoCodec& codec);
|
||||
~DefaultVideoBitrateAllocator() override;
|
||||
|
||||
VideoBitrateAllocation GetAllocation(uint32_t total_bitrate,
|
||||
uint32_t framerate) override;
|
||||
VideoBitrateAllocation Allocate(
|
||||
VideoBitrateAllocationParameters parameters) override;
|
||||
|
||||
private:
|
||||
const VideoCodec codec_;
|
||||
|
||||
@ -42,7 +42,7 @@ class DefaultVideoBitrateAllocatorTest : public ::testing::Test {
|
||||
|
||||
TEST_F(DefaultVideoBitrateAllocatorTest, ZeroIsOff) {
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->GetAllocation(0, kMaxFramerate);
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(0, kMaxFramerate));
|
||||
EXPECT_EQ(0u, allocation.get_sum_bps());
|
||||
}
|
||||
|
||||
@ -50,41 +50,45 @@ TEST_F(DefaultVideoBitrateAllocatorTest, Inactive) {
|
||||
codec_.active = false;
|
||||
allocator_.reset(new DefaultVideoBitrateAllocator(codec_));
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->GetAllocation(1, kMaxFramerate);
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(1, kMaxFramerate));
|
||||
EXPECT_EQ(0u, allocation.get_sum_bps());
|
||||
}
|
||||
|
||||
TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMin) {
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->GetAllocation(1, kMaxFramerate);
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(1, kMaxFramerate));
|
||||
EXPECT_EQ(kMinBitrateBps, allocation.get_sum_bps());
|
||||
|
||||
allocation = allocator_->GetAllocation(kMinBitrateBps - 1, kMaxFramerate);
|
||||
allocation = allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(kMinBitrateBps - 1, kMaxFramerate));
|
||||
EXPECT_EQ(kMinBitrateBps, allocation.get_sum_bps());
|
||||
|
||||
allocation = allocator_->GetAllocation(kMinBitrateBps, kMaxFramerate);
|
||||
allocation = allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(kMinBitrateBps, kMaxFramerate));
|
||||
EXPECT_EQ(kMinBitrateBps, allocation.get_sum_bps());
|
||||
}
|
||||
|
||||
TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMax) {
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->GetAllocation(kMaxBitrateBps, kMaxFramerate);
|
||||
VideoBitrateAllocation allocation = allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(kMaxBitrateBps, kMaxFramerate));
|
||||
EXPECT_EQ(kMaxBitrateBps, allocation.get_sum_bps());
|
||||
|
||||
allocation = allocator_->GetAllocation(kMaxBitrateBps + 1, kMaxFramerate);
|
||||
allocation = allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(kMaxBitrateBps + 1, kMaxFramerate));
|
||||
EXPECT_EQ(kMaxBitrateBps, allocation.get_sum_bps());
|
||||
|
||||
allocation = allocator_->GetAllocation(std::numeric_limits<uint32_t>::max(),
|
||||
kMaxFramerate);
|
||||
allocation = allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
std::numeric_limits<uint32_t>::max(), kMaxFramerate));
|
||||
EXPECT_EQ(kMaxBitrateBps, allocation.get_sum_bps());
|
||||
}
|
||||
|
||||
TEST_F(DefaultVideoBitrateAllocatorTest, GoodInBetween) {
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->GetAllocation(kMinBitrateBps + 1, kMaxFramerate);
|
||||
VideoBitrateAllocation allocation = allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(kMinBitrateBps + 1, kMaxFramerate));
|
||||
EXPECT_EQ(kMinBitrateBps + 1, allocation.get_sum_bps());
|
||||
|
||||
allocation = allocator_->GetAllocation(kMaxBitrateBps - 1, kMaxFramerate);
|
||||
allocation = allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(kMaxBitrateBps - 1, kMaxFramerate));
|
||||
EXPECT_EQ(kMaxBitrateBps - 1, allocation.get_sum_bps());
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
@ -63,13 +64,13 @@ SimulcastRateAllocator::SimulcastRateAllocator(const VideoCodec& codec)
|
||||
|
||||
SimulcastRateAllocator::~SimulcastRateAllocator() = default;
|
||||
|
||||
VideoBitrateAllocation SimulcastRateAllocator::GetAllocation(
|
||||
uint32_t total_bitrate_bps,
|
||||
uint32_t framerate) {
|
||||
VideoBitrateAllocation SimulcastRateAllocator::Allocate(
|
||||
VideoBitrateAllocationParameters parameters) {
|
||||
VideoBitrateAllocation allocated_bitrates_bps;
|
||||
DistributeAllocationToSimulcastLayers(total_bitrate_bps,
|
||||
DistributeAllocationToSimulcastLayers(parameters.total_bitrate.bps(),
|
||||
&allocated_bitrates_bps);
|
||||
DistributeAllocationToTemporalLayers(framerate, &allocated_bitrates_bps);
|
||||
DistributeAllocationToTemporalLayers(std::ceil(parameters.framerate),
|
||||
&allocated_bitrates_bps);
|
||||
return allocated_bitrates_bps;
|
||||
}
|
||||
|
||||
|
||||
@ -28,8 +28,8 @@ class SimulcastRateAllocator : public VideoBitrateAllocator {
|
||||
explicit SimulcastRateAllocator(const VideoCodec& codec);
|
||||
~SimulcastRateAllocator() override;
|
||||
|
||||
VideoBitrateAllocation GetAllocation(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate) override;
|
||||
VideoBitrateAllocation Allocate(
|
||||
VideoBitrateAllocationParameters parameters) override;
|
||||
const VideoCodec& GetCodec() const;
|
||||
|
||||
static float GetTemporalRateAllocation(int num_layers, int temporal_id);
|
||||
|
||||
@ -132,7 +132,8 @@ class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> {
|
||||
}
|
||||
|
||||
VideoBitrateAllocation GetAllocation(uint32_t target_bitrate) {
|
||||
return allocator_->GetAllocation(target_bitrate * 1000U, kDefaultFrameRate);
|
||||
return allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
DataRate::kbps(target_bitrate), kDefaultFrameRate));
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -563,8 +564,9 @@ TEST_P(ScreenshareRateAllocationTest, BitrateBelowTl0) {
|
||||
SetupConferenceScreenshare(GetParam());
|
||||
CreateAllocator();
|
||||
|
||||
VideoBitrateAllocation allocation = allocator_->GetAllocation(
|
||||
kLegacyScreenshareTargetBitrateKbps * 1000, kFramerateFps);
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
kLegacyScreenshareTargetBitrateKbps * 1000, kFramerateFps));
|
||||
|
||||
// All allocation should go in TL0.
|
||||
EXPECT_EQ(kLegacyScreenshareTargetBitrateKbps, allocation.get_sum_kbps());
|
||||
@ -580,7 +582,8 @@ TEST_P(ScreenshareRateAllocationTest, BitrateAboveTl0) {
|
||||
(kLegacyScreenshareTargetBitrateKbps + kLegacyScreenshareMaxBitrateKbps) /
|
||||
2;
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->GetAllocation(target_bitrate_kbps * 1000, kFramerateFps);
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
target_bitrate_kbps * 1000, kFramerateFps));
|
||||
|
||||
// Fill TL0, then put the rest in TL1.
|
||||
EXPECT_EQ(target_bitrate_kbps, allocation.get_sum_kbps());
|
||||
@ -595,8 +598,9 @@ TEST_F(ScreenshareRateAllocationTest, BitrateAboveTl1) {
|
||||
SetupConferenceScreenshare(false);
|
||||
CreateAllocator();
|
||||
|
||||
VideoBitrateAllocation allocation = allocator_->GetAllocation(
|
||||
kLegacyScreenshareMaxBitrateKbps * 2000, kFramerateFps);
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
kLegacyScreenshareMaxBitrateKbps * 2000, kFramerateFps));
|
||||
|
||||
// Fill both TL0 and TL1, but no more.
|
||||
EXPECT_EQ(kLegacyScreenshareMaxBitrateKbps, allocation.get_sum_kbps());
|
||||
@ -618,7 +622,8 @@ TEST_P(ScreenshareRateAllocationTest, InactiveScreenshare) {
|
||||
(kLegacyScreenshareTargetBitrateKbps + kLegacyScreenshareMaxBitrateKbps) /
|
||||
2;
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->GetAllocation(target_bitrate_kbps * 1000, kFramerateFps);
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
target_bitrate_kbps * 1000, kFramerateFps));
|
||||
|
||||
EXPECT_EQ(0U, allocation.get_sum_kbps());
|
||||
}
|
||||
|
||||
@ -302,7 +302,8 @@ void SimulcastTestFixtureImpl::SetUpRateAllocator() {
|
||||
|
||||
void SimulcastTestFixtureImpl::SetRates(uint32_t bitrate_kbps, uint32_t fps) {
|
||||
encoder_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(bitrate_kbps * 1000, fps),
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(bitrate_kbps * 1000, fps)),
|
||||
static_cast<double>(fps)));
|
||||
}
|
||||
|
||||
|
||||
@ -151,8 +151,9 @@ TEST_F(VideoCodecInitializerTest, SingleStreamVp8Screenshare) {
|
||||
streams_.push_back(DefaultStream());
|
||||
EXPECT_TRUE(InitializeCodec());
|
||||
|
||||
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
|
||||
kDefaultTargetBitrateBps, kDefaultFrameRate);
|
||||
VideoBitrateAllocation bitrate_allocation =
|
||||
bitrate_allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
kDefaultTargetBitrateBps, kDefaultFrameRate));
|
||||
EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams);
|
||||
EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers);
|
||||
EXPECT_EQ(kDefaultTargetBitrateBps, bitrate_allocation.get_sum_bps());
|
||||
@ -165,8 +166,9 @@ TEST_F(VideoCodecInitializerTest, SingleStreamVp8ScreenshareInactive) {
|
||||
streams_.push_back(inactive_stream);
|
||||
EXPECT_TRUE(InitializeCodec());
|
||||
|
||||
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
|
||||
kDefaultTargetBitrateBps, kDefaultFrameRate);
|
||||
VideoBitrateAllocation bitrate_allocation =
|
||||
bitrate_allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
kDefaultTargetBitrateBps, kDefaultFrameRate));
|
||||
EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams);
|
||||
EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers);
|
||||
EXPECT_EQ(0U, bitrate_allocation.get_sum_bps());
|
||||
@ -179,8 +181,9 @@ TEST_F(VideoCodecInitializerTest, TemporalLayeredVp8Screenshare) {
|
||||
|
||||
EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams);
|
||||
EXPECT_EQ(2u, codec_out_.VP8()->numberOfTemporalLayers);
|
||||
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
|
||||
kScreenshareCodecTargetBitrateBps, kScreenshareDefaultFramerate);
|
||||
VideoBitrateAllocation bitrate_allocation =
|
||||
bitrate_allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
kScreenshareCodecTargetBitrateBps, kScreenshareDefaultFramerate));
|
||||
EXPECT_EQ(kScreenshareCodecTargetBitrateBps,
|
||||
bitrate_allocation.get_sum_bps());
|
||||
EXPECT_EQ(kScreenshareTl0BitrateBps, bitrate_allocation.GetBitrate(0, 0));
|
||||
@ -198,8 +201,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;
|
||||
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
|
||||
max_bitrate_bps, kScreenshareDefaultFramerate);
|
||||
VideoBitrateAllocation bitrate_allocation =
|
||||
bitrate_allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
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));
|
||||
@ -222,8 +226,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;
|
||||
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
|
||||
target_bitrate, kScreenshareDefaultFramerate);
|
||||
VideoBitrateAllocation bitrate_allocation =
|
||||
bitrate_allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
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),
|
||||
@ -245,8 +250,8 @@ 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;
|
||||
VideoBitrateAllocation bitrate_allocation =
|
||||
bitrate_allocator_->GetAllocation(max_bitrate_bps, kDefaultFrameRate);
|
||||
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(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),
|
||||
bitrate_allocation.GetSpatialLayerSum(0));
|
||||
|
||||
Reference in New Issue
Block a user