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:
parent
9a9f18a736
commit
8bbdb5b9bd
@ -17,9 +17,9 @@
|
||||
namespace webrtc {
|
||||
|
||||
class MockVideoBitrateAllocator : public webrtc::VideoBitrateAllocator {
|
||||
MOCK_METHOD2(GetAllocation,
|
||||
VideoBitrateAllocation(uint32_t total_bitrate,
|
||||
uint32_t framerate));
|
||||
MOCK_METHOD1(
|
||||
Allocate,
|
||||
VideoBitrateAllocation(VideoBitrateAllocationParameters parameters));
|
||||
MOCK_METHOD1(GetPreferredBitrateBps, uint32_t(uint32_t framerate));
|
||||
};
|
||||
|
||||
|
||||
@ -159,10 +159,12 @@ rtc_source_set("video_bitrate_allocation") {
|
||||
rtc_source_set("video_bitrate_allocator") {
|
||||
visibility = [ "*" ]
|
||||
sources = [
|
||||
"video_bitrate_allocator.cc",
|
||||
"video_bitrate_allocator.h",
|
||||
]
|
||||
deps = [
|
||||
":video_bitrate_allocation",
|
||||
"../units:data_rate",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
52
api/video/video_bitrate_allocator.cc
Normal file
52
api/video/video_bitrate_allocator.cc
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2019 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_allocator.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
VideoBitrateAllocationParameters::VideoBitrateAllocationParameters(
|
||||
uint32_t total_bitrate_bps,
|
||||
uint32_t framerate)
|
||||
: total_bitrate(DataRate::bps(total_bitrate_bps)),
|
||||
stable_bitrate(DataRate::bps(total_bitrate_bps)),
|
||||
framerate(static_cast<double>(framerate)) {}
|
||||
|
||||
VideoBitrateAllocationParameters::VideoBitrateAllocationParameters(
|
||||
DataRate total_bitrate,
|
||||
double framerate)
|
||||
: total_bitrate(total_bitrate),
|
||||
stable_bitrate(total_bitrate),
|
||||
framerate(framerate) {}
|
||||
|
||||
VideoBitrateAllocationParameters::VideoBitrateAllocationParameters(
|
||||
DataRate total_bitrate,
|
||||
DataRate stable_bitrate,
|
||||
double framerate)
|
||||
: total_bitrate(total_bitrate),
|
||||
stable_bitrate(stable_bitrate),
|
||||
framerate(framerate) {}
|
||||
|
||||
VideoBitrateAllocationParameters::~VideoBitrateAllocationParameters() = default;
|
||||
|
||||
VideoBitrateAllocation VideoBitrateAllocator::GetAllocation(
|
||||
uint32_t total_bitrate_bps,
|
||||
uint32_t framerate) {
|
||||
return Allocate({DataRate::bps(total_bitrate_bps),
|
||||
DataRate::bps(total_bitrate_bps),
|
||||
static_cast<double>(framerate)});
|
||||
}
|
||||
|
||||
VideoBitrateAllocation VideoBitrateAllocator::Allocate(
|
||||
VideoBitrateAllocationParameters parameters) {
|
||||
return GetAllocation(parameters.total_bitrate.bps(), parameters.framerate);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -11,17 +11,35 @@
|
||||
#ifndef API_VIDEO_VIDEO_BITRATE_ALLOCATOR_H_
|
||||
#define API_VIDEO_VIDEO_BITRATE_ALLOCATOR_H_
|
||||
|
||||
#include "api/units/data_rate.h"
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
struct VideoBitrateAllocationParameters {
|
||||
VideoBitrateAllocationParameters(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate);
|
||||
VideoBitrateAllocationParameters(DataRate total_bitrate, double framerate);
|
||||
VideoBitrateAllocationParameters(DataRate total_bitrate,
|
||||
DataRate stable_bitrate,
|
||||
double framerate);
|
||||
~VideoBitrateAllocationParameters();
|
||||
|
||||
DataRate total_bitrate;
|
||||
DataRate stable_bitrate;
|
||||
double framerate;
|
||||
};
|
||||
|
||||
class VideoBitrateAllocator {
|
||||
public:
|
||||
VideoBitrateAllocator() {}
|
||||
virtual ~VideoBitrateAllocator() {}
|
||||
|
||||
virtual VideoBitrateAllocation GetAllocation(uint32_t total_bitrate_bps,
|
||||
uint32_t framerate) = 0;
|
||||
uint32_t framerate);
|
||||
|
||||
virtual VideoBitrateAllocation Allocate(
|
||||
VideoBitrateAllocationParameters parameters);
|
||||
};
|
||||
|
||||
class VideoBitrateAllocationObserver {
|
||||
|
||||
@ -217,7 +217,9 @@ void VideoEncoderSoftwareFallbackWrapperTest::UtilizeFallbackEncoder() {
|
||||
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
||||
fallback_wrapper_->InitEncode(&codec_, kSettings));
|
||||
fallback_wrapper_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(300000, kFramerate), kFramerate));
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(300000, kFramerate)),
|
||||
kFramerate));
|
||||
|
||||
int callback_count = callback_.callback_count_;
|
||||
int encode_count = fake_encoder_->encode_count_;
|
||||
@ -236,7 +238,9 @@ void VideoEncoderSoftwareFallbackWrapperTest::FallbackFromEncodeRequest() {
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
fallback_wrapper_->InitEncode(&codec_, kSettings);
|
||||
fallback_wrapper_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(300000, kFramerate), kFramerate));
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(300000, kFramerate)),
|
||||
kFramerate));
|
||||
EXPECT_EQ(1, fake_encoder_->init_encode_count_);
|
||||
|
||||
// Have the non-fallback encoder request a software fallback.
|
||||
@ -395,7 +399,8 @@ class ForcedFallbackTest : public VideoEncoderSoftwareFallbackWrapperTest {
|
||||
|
||||
void SetRateAllocation(uint32_t bitrate_kbps) {
|
||||
fallback_wrapper_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(bitrate_kbps * 1000, kFramerate),
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(bitrate_kbps * 1000, kFramerate)),
|
||||
kFramerate));
|
||||
}
|
||||
|
||||
|
||||
@ -200,8 +200,9 @@ int SimulcastEncoderAdapter::InitEncode(
|
||||
|
||||
codec_ = *inst;
|
||||
SimulcastRateAllocator rate_allocator(codec_);
|
||||
VideoBitrateAllocation allocation = rate_allocator.GetAllocation(
|
||||
codec_.startBitrate * 1000, codec_.maxFramerate);
|
||||
VideoBitrateAllocation allocation =
|
||||
rate_allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
codec_.startBitrate * 1000, codec_.maxFramerate));
|
||||
std::vector<uint32_t> start_bitrates;
|
||||
for (int i = 0; i < kMaxSimulcastStreams; ++i) {
|
||||
uint32_t stream_bitrate = allocation.GetSpatialLayerSum(i) / 1000;
|
||||
|
||||
@ -506,7 +506,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) {
|
||||
|
||||
// Set bitrates so that we send all layers.
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(1200, 30), 30.0));
|
||||
rate_allocator_->Allocate(VideoBitrateAllocationParameters(1200, 30)),
|
||||
30.0));
|
||||
|
||||
// At this point, the simulcast encoder adapter should have 3 streams: HD,
|
||||
// quarter HD, and quarter quarter HD. We're going to mostly ignore the exact
|
||||
@ -567,7 +568,9 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
VerifyCodecSettings();
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(target_bitrate, 30)),
|
||||
30.0));
|
||||
|
||||
std::vector<MockVideoEncoder*> original_encoders =
|
||||
helper_->factory()->encoders();
|
||||
@ -594,7 +597,9 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
codec_.numberOfSimulcastStreams = 2;
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(target_bitrate, 30)),
|
||||
30.0));
|
||||
std::vector<MockVideoEncoder*> new_encoders = helper_->factory()->encoders();
|
||||
ASSERT_EQ(2u, new_encoders.size());
|
||||
ASSERT_EQ(original_encoders[0], new_encoders[0]);
|
||||
@ -617,7 +622,9 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
codec_.numberOfSimulcastStreams = 1;
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(target_bitrate, 30)),
|
||||
30.0));
|
||||
new_encoders = helper_->factory()->encoders();
|
||||
ASSERT_EQ(1u, new_encoders.size());
|
||||
ASSERT_EQ(original_encoders[0], new_encoders[0]);
|
||||
@ -635,7 +642,9 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
codec_.numberOfSimulcastStreams = 3;
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(target_bitrate, 30)),
|
||||
30.0));
|
||||
new_encoders = helper_->factory()->encoders();
|
||||
ASSERT_EQ(3u, new_encoders.size());
|
||||
// The first encoder is reused.
|
||||
@ -719,7 +728,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderEncoderSettings) {
|
||||
TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderFrameSimulcastIdx) {
|
||||
SetupCodec();
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(1200, 30), 30.0));
|
||||
rate_allocator_->Allocate(VideoBitrateAllocationParameters(1200, 30)),
|
||||
30.0));
|
||||
VerifyCodecSettings();
|
||||
|
||||
// Send frames on all streams.
|
||||
@ -744,7 +754,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderFrameSimulcastIdx) {
|
||||
EXPECT_EQ(0, adapter_->Release());
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(1200, 30), 30.0));
|
||||
rate_allocator_->Allocate(VideoBitrateAllocationParameters(1200, 30)),
|
||||
30.0));
|
||||
|
||||
// Verify that the same encoder sends out frames on the same simulcast index.
|
||||
encoders[0]->SendEncodedImage(1152, 704);
|
||||
@ -786,15 +797,15 @@ TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) {
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
|
||||
// Above min should be respected.
|
||||
VideoBitrateAllocation target_bitrate =
|
||||
rate_allocator_->GetAllocation(codec_.minBitrate * 1000, 30);
|
||||
VideoBitrateAllocation target_bitrate = rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(codec_.minBitrate * 1000, 30));
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(target_bitrate, 30.0));
|
||||
EXPECT_EQ(target_bitrate,
|
||||
helper_->factory()->encoders()[0]->last_set_rates().bitrate);
|
||||
|
||||
// Below min but non-zero should be replaced with the min bitrate.
|
||||
VideoBitrateAllocation too_low_bitrate =
|
||||
rate_allocator_->GetAllocation((codec_.minBitrate - 1) * 1000, 30);
|
||||
VideoBitrateAllocation too_low_bitrate = rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters((codec_.minBitrate - 1) * 1000, 30));
|
||||
adapter_->SetRates(
|
||||
VideoEncoder::RateControlParameters(too_low_bitrate, 30.0));
|
||||
EXPECT_EQ(target_bitrate,
|
||||
@ -1184,8 +1195,9 @@ TEST_F(TestSimulcastEncoderAdapterFake, SetRateDistributesBandwithAllocation) {
|
||||
|
||||
// Set bitrates so that we send all layers.
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate.bps(), 30), 30.0,
|
||||
bandwidth_allocation));
|
||||
rate_allocator_->Allocate(
|
||||
VideoBitrateAllocationParameters(target_bitrate.bps(), 30)),
|
||||
30.0, bandwidth_allocation));
|
||||
|
||||
std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
|
||||
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -1103,9 +1103,9 @@ VideoStreamEncoder::UpdateBitrateAllocationAndNotifyObserver(
|
||||
// Only call allocators if bitrate > 0 (ie, not suspended), otherwise they
|
||||
// might cap the bitrate to the min bitrate configured.
|
||||
if (rate_allocator_ && rate_settings.encoder_target > DataRate::Zero()) {
|
||||
new_allocation = rate_allocator_->GetAllocation(
|
||||
new_allocation = rate_allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
rate_settings.encoder_target.bps(),
|
||||
static_cast<uint32_t>(rate_settings.framerate_fps + 0.5));
|
||||
static_cast<uint32_t>(rate_settings.framerate_fps + 0.5)));
|
||||
}
|
||||
|
||||
if (bitrate_observer_ && new_allocation.get_sum_bps() > 0) {
|
||||
|
||||
@ -2685,7 +2685,8 @@ TEST_F(VideoStreamEncoderTest, CallsBitrateObserver) {
|
||||
const int kDefaultFps = 30;
|
||||
const VideoBitrateAllocation expected_bitrate =
|
||||
DefaultVideoBitrateAllocator(fake_encoder_.codec_config())
|
||||
.GetAllocation(kLowTargetBitrateBps, kDefaultFps);
|
||||
.Allocate(VideoBitrateAllocationParameters(kLowTargetBitrateBps,
|
||||
kDefaultFps));
|
||||
|
||||
EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
|
||||
.Times(1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user