Index: webrtc/modules/video_coding/video_sender.cc |
diff --git a/webrtc/modules/video_coding/video_sender.cc b/webrtc/modules/video_coding/video_sender.cc |
index b7664a719b3a7d155d23666df94663928087bc8c..c202d34e859819dabad29201dba1bef82b46d28d 100644 |
--- a/webrtc/modules/video_coding/video_sender.cc |
+++ b/webrtc/modules/video_coding/video_sender.cc |
@@ -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,16 +192,47 @@ 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); |
- |
+EncoderParameters VideoSender::UpdateEncoderParameters( |
+ const EncoderParameters& params, |
+ VideoBitrateAllocator* bitrate_allocator, |
+ uint32_t target_bitrate_bps) { |
+ uint32_t video_target_rate_bps = _mediaOpt.SetTargetRates( |
+ target_bitrate_bps, params.loss_rate, params.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 new_encoder_params = {bitrate_allocation, params.loss_rate, |
+ params.rtt, input_frame_rate}; |
+ return new_encoder_params; |
+} |
+ |
+void VideoSender::UpdateChannelParemeters( |
+ VideoBitrateAllocator* bitrate_allocator) { |
+ rtc::CritScope cs(¶ms_crit_); |
+ encoder_params_ = |
+ UpdateEncoderParameters(encoder_params_, bitrate_allocator, |
+ encoder_params_.target_bitrate.get_sum_bps()); |
+} |
+ |
+int32_t VideoSender::SetChannelParameters( |
+ uint32_t target_bitrate_bps, |
+ uint8_t lossRate, |
+ int64_t rtt, |
+ VideoBitrateAllocator* bitrate_allocator) { |
+ EncoderParameters encoder_params; |
+ encoder_params.loss_rate = lossRate; |
+ encoder_params.rtt = rtt; |
+ encoder_params = UpdateEncoderParameters(encoder_params, bitrate_allocator, |
+ target_bitrate_bps); |
- EncoderParameters encoder_params = {target_rate, lossRate, rtt, |
- input_frame_rate}; |
bool encoder_has_internal_source; |
{ |
rtc::CritScope cs(¶ms_crit_); |
@@ -228,7 +262,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 +302,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; |