Index: webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.cc |
diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.cc b/webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.cc |
index ac0045ec4dee39dc0127c82df9de25258759673f..2f64df066b36bba2ec8bd963627bf594e3c66dd0 100644 |
--- a/webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.cc |
+++ b/webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.cc |
@@ -13,17 +13,11 @@ |
#include <algorithm> |
#include "webrtc/base/checks.h" |
+#include "webrtc/system_wrappers/include/field_trial.h" |
namespace webrtc { |
namespace audio_network_adaptor { |
-namespace { |
-// TODO(minyue): consider passing this from a higher layer through |
-// SetConstraints(). |
-// L2(14B) + IPv4(20B) + UDP(8B) + RTP(12B) + SRTP_AUTH(10B) = 64B = 512 bits |
-constexpr int kPacketOverheadBits = 512; |
-} |
- |
BitrateController::Config::Config(int initial_bitrate_bps, |
int initial_frame_length_ms) |
: initial_bitrate_bps(initial_bitrate_bps), |
@@ -34,10 +28,9 @@ BitrateController::Config::~Config() = default; |
BitrateController::BitrateController(const Config& config) |
: config_(config), |
bitrate_bps_(config_.initial_bitrate_bps), |
- overhead_rate_bps_(kPacketOverheadBits * 1000 / |
- config_.initial_frame_length_ms) { |
+ frame_length_ms_(config_.initial_frame_length_ms) { |
RTC_DCHECK_GT(bitrate_bps_, 0); |
- RTC_DCHECK_GT(overhead_rate_bps_, 0); |
+ RTC_DCHECK_GT(frame_length_ms_, 0); |
} |
void BitrateController::MakeDecision( |
@@ -45,23 +38,18 @@ void BitrateController::MakeDecision( |
AudioNetworkAdaptor::EncoderRuntimeConfig* config) { |
// Decision on |bitrate_bps| should not have been made. |
RTC_DCHECK(!config->bitrate_bps); |
- |
- if (metrics.target_audio_bitrate_bps) { |
- int overhead_rate = |
- config->frame_length_ms |
- ? kPacketOverheadBits * 1000 / *config->frame_length_ms |
- : overhead_rate_bps_; |
- // If |metrics.target_audio_bitrate_bps| had included overhead, we would |
- // simply do: |
- // bitrate_bps_ = metrics.target_audio_bitrate_bps - overhead_rate; |
- // Follow https://bugs.chromium.org/p/webrtc/issues/detail?id=6315 to track |
- // progress regarding this. |
- // Now we assume that |metrics.target_audio_bitrate_bps| can handle the |
- // overhead of most recent packets. |
- bitrate_bps_ = std::max(0, *metrics.target_audio_bitrate_bps + |
- overhead_rate_bps_ - overhead_rate); |
- // TODO(minyue): apply a smoothing on the |overhead_rate_bps_|. |
- overhead_rate_bps_ = overhead_rate; |
+ if (metrics.target_audio_bitrate_bps && metrics.overhead_bytes_per_packet) { |
+ // Current implementation of BitrateController can only work when |
+ // |metrics.target_audio_bitrate_bps| includes overhead is enabled. This is |
+ // currently governed by the following field trial. |
+ RTC_DCHECK_EQ("Enabled", webrtc::field_trial::FindFullName( |
+ "WebRTC-SendSideBwe-WithOverhead")); |
+ if (config->frame_length_ms) |
+ frame_length_ms_ = *config->frame_length_ms; |
+ int overhead_rate_bps = |
+ *metrics.overhead_bytes_per_packet * 8 * 1000 / frame_length_ms_; |
+ bitrate_bps_ = |
+ std::max(0, *metrics.target_audio_bitrate_bps - overhead_rate_bps); |
} |
config->bitrate_bps = rtc::Optional<int>(bitrate_bps_); |
} |