Reland #2 of Issue 2434073003: Extract bitrate allocation ...

This is yet another reland of https://codereview.webrtc.org/2434073003/
including two fixes:

1. SimulcastRateAllocator did not handle the screenshare settings properly for numSimulcastStreams = 1. Additional test case was added for that.
2. In VideoSender, when rate allocation is updated after setting a new VideoCodec config, only update the state of the EncoderParameters, but don't actually run SetRateAllocation on the encoder itself. This caused some problems upstreams.

Please review only the changes after patch set 1.

Original description:

Extract bitrate allocation of spatial/temporal layers out of codec impl.

This CL makes a number of intervowen changes:

* Add BitrateAllocation struct, that contains a codec independent view
  of how the target bitrate is distributed over spatial and temporal
  layers.

* Adds the BitrateAllocator interface, which takes a bitrate and frame
  rate and produces a BitrateAllocation.

* A default (non layered) implementation is added, and
  SimulcastRateAllocator is extended to fully handle VP8 allocation.
  This includes capturing TemporalLayer instances created by the
  encoder.

* ViEEncoder now owns both the bitrate allocator and the temporal layer
  factories for VP8. This allows allocation to happen fully outside of
  the encoder implementation.

This refactoring will make it possible for ViEEncoder to signal the
full picture of target bitrates to the RTCP module.

BUG=webrtc:6301
R=stefan@webrtc.org

Review URL: https://codereview.webrtc.org/2510583002 .

Cr-Commit-Position: refs/heads/master@{#15105}
This commit is contained in:
Erik Språng
2016-11-16 16:41:30 +01:00
parent 779017d989
commit 08127a9449
65 changed files with 1857 additions and 892 deletions

View File

@ -640,8 +640,9 @@ TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) {
FakeEncoder(Clock::GetRealTimeClock()),
time_to_reconfigure_(false, false),
encoder_inits_(0),
last_set_bitrate_(0),
send_stream_(nullptr) {}
last_set_bitrate_kbps_(0),
send_stream_(nullptr),
frame_generator_(nullptr) {}
int32_t InitEncode(const VideoCodec* config,
int32_t number_of_cores,
@ -651,8 +652,9 @@ TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) {
// First time initialization. Frame size is known.
// |expected_bitrate| is affected by bandwidth estimation before the
// first frame arrives to the encoder.
uint32_t expected_bitrate =
last_set_bitrate_ > 0 ? last_set_bitrate_ : kInitialBitrateKbps;
uint32_t expected_bitrate = last_set_bitrate_kbps_ > 0
? last_set_bitrate_kbps_
: kInitialBitrateKbps;
EXPECT_EQ(expected_bitrate, config->startBitrate)
<< "Encoder not initialized at expected bitrate.";
EXPECT_EQ(kDefaultWidth, config->width);
@ -660,9 +662,8 @@ TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) {
} else if (encoder_inits_ == 2) {
EXPECT_EQ(2 * kDefaultWidth, config->width);
EXPECT_EQ(2 * kDefaultHeight, config->height);
EXPECT_GE(last_set_bitrate_, kReconfigureThresholdKbps);
EXPECT_NEAR(config->startBitrate,
last_set_bitrate_,
EXPECT_GE(last_set_bitrate_kbps_, kReconfigureThresholdKbps);
EXPECT_NEAR(config->startBitrate, last_set_bitrate_kbps_,
kPermittedReconfiguredBitrateDiffKbps)
<< "Encoder reconfigured with bitrate too far away from last set.";
observation_complete_.Set();
@ -670,14 +671,14 @@ TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) {
return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
}
int32_t SetRates(uint32_t new_target_bitrate_kbps,
uint32_t framerate) override {
last_set_bitrate_ = new_target_bitrate_kbps;
int32_t SetRateAllocation(const BitrateAllocation& rate_allocation,
uint32_t framerate) override {
last_set_bitrate_kbps_ = rate_allocation.get_sum_kbps();
if (encoder_inits_ == 1 &&
new_target_bitrate_kbps > kReconfigureThresholdKbps) {
rate_allocation.get_sum_kbps() > kReconfigureThresholdKbps) {
time_to_reconfigure_.Set();
}
return FakeEncoder::SetRates(new_target_bitrate_kbps, framerate);
return FakeEncoder::SetRateAllocation(rate_allocation, framerate);
}
Call::Config GetSenderCallConfig() override {
@ -723,7 +724,7 @@ TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) {
private:
rtc::Event time_to_reconfigure_;
int encoder_inits_;
uint32_t last_set_bitrate_;
uint32_t last_set_bitrate_kbps_;
VideoSendStream* send_stream_;
test::FrameGeneratorCapturer* frame_generator_;
VideoEncoderConfig encoder_config_;