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

Review-Url: https://codereview.webrtc.org/2434073003
Cr-Commit-Position: refs/heads/master@{#14998}
This commit is contained in:
sprang
2016-11-09 05:09:06 -08:00
committed by Commit bot
parent 592baaf89a
commit 8f46c679d2
63 changed files with 1681 additions and 843 deletions

View File

@ -14,9 +14,12 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/common_types.h"
#include "webrtc/common_video/include/video_bitrate_allocator.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
#include "webrtc/modules/video_coding/include/video_codec_interface.h"
#include "webrtc/modules/video_coding/encoded_frame.h"
#include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h"
#include "webrtc/modules/video_coding/utility/quality_scaler.h"
#include "webrtc/modules/video_coding/video_coding_impl.h"
#include "webrtc/system_wrappers/include/clock.h"
@ -36,7 +39,7 @@ VideoSender::VideoSender(Clock* clock,
frame_dropper_enabled_(true),
_sendStatsTimer(1000, clock_),
current_codec_(),
encoder_params_({0, 0, 0, 0}),
encoder_params_({BitrateAllocation(), 0, 0, 0}),
encoder_has_internal_source_(false),
next_frame_types_(1, kVideoFrameDelta) {
_mediaOpt.Reset();
@ -172,7 +175,7 @@ int VideoSender::Bitrate(unsigned int* bitrate) const {
if (!_encoder)
return VCM_UNINITIALIZED;
*bitrate = _encoder->GetEncoderParameters().target_bitrate;
*bitrate = _encoder->GetEncoderParameters().target_bitrate.get_sum_bps();
return 0;
}
@ -189,15 +192,38 @@ int VideoSender::FrameRate(unsigned int* framerate) const {
return 0;
}
int32_t VideoSender::SetChannelParameters(uint32_t target_bitrate,
uint8_t lossRate,
int64_t rtt) {
uint32_t target_rate =
_mediaOpt.SetTargetRates(target_bitrate, lossRate, rtt);
int32_t VideoSender::UpdateChannelParemeters(
VideoBitrateAllocator* bitrate_allocator) {
EncoderParameters encoder_params;
{
rtc::CritScope cs(&params_crit_);
encoder_params = encoder_params_;
}
return SetChannelParameters(encoder_params.target_bitrate.get_sum_bps(),
encoder_params.loss_rate, encoder_params.rtt,
bitrate_allocator);
}
int32_t VideoSender::SetChannelParameters(
uint32_t target_bitrate_bps,
uint8_t lossRate,
int64_t rtt,
VideoBitrateAllocator* bitrate_allocator) {
uint32_t video_target_rate_bps =
_mediaOpt.SetTargetRates(target_bitrate_bps, lossRate, rtt);
uint32_t input_frame_rate = _mediaOpt.InputFrameRate();
BitrateAllocation bitrate_allocation;
if (bitrate_allocator) {
bitrate_allocation = bitrate_allocator->GetAllocation(video_target_rate_bps,
input_frame_rate);
} else {
DefaultVideoBitrateAllocator default_allocator(current_codec_);
bitrate_allocation = default_allocator.GetAllocation(video_target_rate_bps,
input_frame_rate);
}
EncoderParameters encoder_params = {target_rate, lossRate, rtt,
EncoderParameters encoder_params = {bitrate_allocation, lossRate, rtt,
input_frame_rate};
bool encoder_has_internal_source;
{
@ -228,7 +254,7 @@ void VideoSender::SetEncoderParameters(EncoderParameters params,
// encoder implementations behave when given a zero target bitrate.
// TODO(perkj): Make sure all known encoder implementations handle zero
// target bitrate and remove this check.
if (!has_internal_source && params.target_bitrate == 0)
if (!has_internal_source && params.target_bitrate.get_sum_bps() == 0)
return;
if (params.input_frame_rate == 0) {
@ -268,7 +294,8 @@ int32_t VideoSender::AddVideoFrame(const VideoFrame& videoFrame,
SetEncoderParameters(encoder_params, encoder_has_internal_source);
if (_mediaOpt.DropFrame()) {
LOG(LS_VERBOSE) << "Drop Frame "
<< "target bitrate " << encoder_params.target_bitrate
<< "target bitrate "
<< encoder_params.target_bitrate.get_sum_bps()
<< " loss rate " << encoder_params.loss_rate << " rtt "
<< encoder_params.rtt << " input frame rate "
<< encoder_params.input_frame_rate;