Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Unified Diff: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc

Issue 2546493002: Update smoothed bitrate. (Closed)
Patch Set: Changed cl according to offline discussions. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
index af66cd3634ee1cdabcfab57f18c80c953a0a9391..1212920de955b8cd7daf1cf7b671849271a94d3f 100644
--- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
+++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
@@ -172,7 +172,8 @@ rtc::Optional<int> AudioEncoderOpus::Config::GetNewComplexity() const {
AudioEncoderOpus::AudioEncoderOpus(
const Config& config,
- AudioNetworkAdaptorCreator&& audio_network_adaptor_creator)
+ AudioNetworkAdaptorCreator&& audio_network_adaptor_creator,
+ std::unique_ptr<SmoothingFilter> bitrate_smoother)
: packet_loss_rate_(0.0),
inst_(nullptr),
packet_loss_fraction_smoother_(new PacketLossFractionSmoother(
@@ -183,7 +184,10 @@ AudioEncoderOpus::AudioEncoderOpus(
: [this](const std::string& config_string, const Clock* clock) {
return DefaultAudioNetworkAdaptorCreator(config_string,
clock);
- }) {
+ }),
+ bitrate_smoother_(bitrate_smoother
+ ? std::move(bitrate_smoother) : std::unique_ptr<SmoothingFilter>(
+ new SmoothingFilterImpl(500, config.clock))) {
minyue-webrtc 2016/12/22 14:51:26 need to explain 500
RTC_CHECK(RecreateEncoderInstance(config));
}
@@ -272,13 +276,6 @@ void AudioEncoderOpus::DisableAudioNetworkAdaptor() {
audio_network_adaptor_.reset(nullptr);
}
-void AudioEncoderOpus::OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) {
- if (!audio_network_adaptor_)
- return;
- audio_network_adaptor_->SetUplinkBandwidth(uplink_bandwidth_bps);
- ApplyAudioNetworkAdaptor();
-}
-
void AudioEncoderOpus::OnReceivedUplinkPacketLossFraction(
float uplink_packet_loss_fraction) {
if (!audio_network_adaptor_) {
@@ -292,9 +289,25 @@ void AudioEncoderOpus::OnReceivedUplinkPacketLossFraction(
}
void AudioEncoderOpus::OnReceivedTargetAudioBitrate(
- int target_audio_bitrate_bps) {
+ int target_audio_bitrate_bps,
+ rtc::Optional<int64_t> probing_interval_ms) {
if (audio_network_adaptor_) {
audio_network_adaptor_->SetTargetAudioBitrate(target_audio_bitrate_bps);
+ // We give smoothed bitrate allocation to audio network adaptor as
+ // the uplink bandwidth.
+ // The probing spikes should not affect the bitrate smoother more than 25%.
+ // To simplify the calculations we use a step response as input signal.
+ // The step response of an exponential filter is
+ // u(t) = 1 - e^(-t / time_constant).
+ // In order to limit the affect of a BWE spike within 25% of its value
+ // before
+ // the next probing, we would choose a time constant that fulfills
+ // 1 - e^(-probing_interval_ms / time_constant) < 0.25
+ // Then 4 * probing_interval_ms is a good choice.
+ if (probing_interval_ms)
+ bitrate_smoother_->SetTimeConstantMs(*probing_interval_ms * 4);
+ bitrate_smoother_->AddSample(target_audio_bitrate_bps);
+
ApplyAudioNetworkAdaptor();
} else if (webrtc::field_trial::FindFullName(
"WebRTC-SendSideBwe-WithOverhead") == "Enabled") {
@@ -354,6 +367,7 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeImpl(
uint32_t rtp_timestamp,
rtc::ArrayView<const int16_t> audio,
rtc::Buffer* encoded) {
+ MayUpdateUplinkBandwidth();
if (input_buffer_.empty())
first_timestamp_in_buffer_ = rtp_timestamp;
@@ -523,4 +537,17 @@ AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator(
GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock)));
}
+void AudioEncoderOpus::MayUpdateUplinkBandwidth() {
ossu 2016/12/22 14:01:15 nit: May -> Maybe There are several Maybe functio
michaelt 2016/12/22 14:56:10 Done.
+ if (audio_network_adaptor_) {
+ int64_t now = config_.clock->TimeInMilliseconds();
+ if (!last_smoothed_bandwith_update_ ||
+ now - *last_smoothed_bandwith_update_ >=
+ config_.update_uplink_bandwidth_interval_ms) {
+ audio_network_adaptor_->SetUplinkBandwidth(
+ *bitrate_smoother_->GetAverage());
minyue-webrtc 2016/12/22 14:51:26 shall Dcheck bitrate_smoother_.GetAverage() is not
michaelt 2016/12/22 15:10:10 Added a if since this could relay happens.
+ last_smoothed_bandwith_update_ = rtc::Optional<int64_t>(now);
+ }
+ }
+}
+
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698