blob: a601cce34066a20268656ac8bc7d4c4b8cc57cb0 [file] [log] [blame]
Sebastian Jansson470a5ea2019-01-23 12:37:49 +01001/*
2 * Copyright 2019 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#include "rtc_base/experiments/audio_allocation_settings.h"
11#include "system_wrappers/include/field_trial.h"
12
13namespace webrtc {
14namespace {
15// For SendSideBwe, Opus bitrate should be in the range between 6000 and 32000.
16const int kOpusMinBitrateBps = 6000;
17const int kOpusBitrateFbBps = 32000;
Sebastian Jansson464a5572019-02-12 13:32:32 +010018// OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12)
19constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12;
Sebastian Jansson470a5ea2019-01-23 12:37:49 +010020} // namespace
21AudioAllocationSettings::AudioAllocationSettings()
22 : audio_send_side_bwe_("Enabled"),
23 allocate_audio_without_feedback_("Enabled"),
24 force_no_audio_feedback_("Enabled"),
Sebastian Jansson464a5572019-02-12 13:32:32 +010025 send_side_bwe_with_overhead_("Enabled"),
26 default_min_bitrate_("min", DataRate::bps(kOpusMinBitrateBps)),
27 default_max_bitrate_("max", DataRate::bps(kOpusBitrateFbBps)),
28 priority_bitrate_("prio", DataRate::Zero()) {
Sebastian Jansson470a5ea2019-01-23 12:37:49 +010029 ParseFieldTrial({&audio_send_side_bwe_},
30 field_trial::FindFullName("WebRTC-Audio-SendSideBwe"));
31 ParseFieldTrial({&allocate_audio_without_feedback_},
32 field_trial::FindFullName("WebRTC-Audio-ABWENoTWCC"));
33 ParseFieldTrial({&force_no_audio_feedback_},
34 field_trial::FindFullName("WebRTC-Audio-ForceNoTWCC"));
Sebastian Jansson464a5572019-02-12 13:32:32 +010035
Sebastian Jansson470a5ea2019-01-23 12:37:49 +010036 ParseFieldTrial({&send_side_bwe_with_overhead_},
37 field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead"));
Sebastian Jansson464a5572019-02-12 13:32:32 +010038 ParseFieldTrial(
39 {&default_min_bitrate_, &default_max_bitrate_, &priority_bitrate_},
40 field_trial::FindFullName("WebRTC-Audio-Allocation"));
Sebastian Jansson470a5ea2019-01-23 12:37:49 +010041
42 // TODO(mflodman): Keep testing this and set proper values.
43 // Note: This is an early experiment currently only supported by Opus.
44 if (send_side_bwe_with_overhead_) {
45 constexpr int kMaxPacketSizeMs = WEBRTC_OPUS_SUPPORT_120MS_PTIME ? 120 : 60;
Sebastian Jansson470a5ea2019-01-23 12:37:49 +010046 min_overhead_bps_ = kOverheadPerPacket * 8 * 1000 / kMaxPacketSizeMs;
47 }
48}
49
50AudioAllocationSettings::~AudioAllocationSettings() {}
51
52bool AudioAllocationSettings::ForceNoAudioFeedback() const {
53 return force_no_audio_feedback_;
54}
55
56bool AudioAllocationSettings::IgnoreSeqNumIdChange() const {
57 return !audio_send_side_bwe_;
58}
59
60bool AudioAllocationSettings::ConfigureRateAllocationRange() const {
61 return audio_send_side_bwe_;
62}
63
Per Kjellander914351d2019-02-15 10:54:55 +010064bool AudioAllocationSettings::ShouldSendTransportSequenceNumber(
Sebastian Jansson470a5ea2019-01-23 12:37:49 +010065 int transport_seq_num_extension_header_id) const {
66 if (force_no_audio_feedback_)
67 return false;
Per Kjellander914351d2019-02-15 10:54:55 +010068 return audio_send_side_bwe_ && !allocate_audio_without_feedback_ &&
69 transport_seq_num_extension_header_id != 0;
Sebastian Jansson470a5ea2019-01-23 12:37:49 +010070}
71
Sebastian Jansson470a5ea2019-01-23 12:37:49 +010072bool AudioAllocationSettings::IncludeAudioInAllocationOnStart(
73 int min_bitrate_bps,
74 int max_bitrate_bps,
75 bool has_dscp,
76 int transport_seq_num_extension_header_id) const {
77 if (has_dscp || min_bitrate_bps == -1 || max_bitrate_bps == -1)
78 return false;
79 if (transport_seq_num_extension_header_id != 0 && !force_no_audio_feedback_)
80 return true;
81 if (allocate_audio_without_feedback_)
82 return true;
83 if (audio_send_side_bwe_)
84 return false;
85 return true;
86}
87
88bool AudioAllocationSettings::IncludeAudioInAllocationOnReconfigure(
89 int min_bitrate_bps,
90 int max_bitrate_bps,
91 bool has_dscp,
92 int transport_seq_num_extension_header_id) const {
93 // TODO(srte): Make this match include_audio_in_allocation_on_start.
94 if (has_dscp || min_bitrate_bps == -1 || max_bitrate_bps == -1)
95 return false;
96 if (transport_seq_num_extension_header_id != 0)
97 return true;
98 if (audio_send_side_bwe_)
99 return false;
100 return true;
101}
102
103int AudioAllocationSettings::MinBitrateBps() const {
Sebastian Jansson464a5572019-02-12 13:32:32 +0100104 return default_min_bitrate_->bps() + min_overhead_bps_;
Sebastian Jansson470a5ea2019-01-23 12:37:49 +0100105}
106
107int AudioAllocationSettings::MaxBitrateBps(
108 absl::optional<int> rtp_parameter_max_bitrate_bps) const {
109 // We assume that the max is a hard limit on the payload bitrate, so we add
110 // min_overhead_bps to it to ensure that, when overhead is deducted, the
111 // payload rate never goes beyond the limit. Note: this also means that if a
112 // higher overhead is forced, we cannot reach the limit.
113 // TODO(minyue): Reconsider this when the signaling to BWE is done
114 // through a dedicated API.
115
116 // This means that when RtpParameters is reset, we may change the
117 // encoder's bit rate immediately (through ReconfigureAudioSendStream()),
118 // meanwhile change the cap to the output of BWE.
119 if (rtp_parameter_max_bitrate_bps)
120 return *rtp_parameter_max_bitrate_bps + min_overhead_bps_;
Sebastian Jansson464a5572019-02-12 13:32:32 +0100121 return default_max_bitrate_->bps() + min_overhead_bps_;
Sebastian Jansson470a5ea2019-01-23 12:37:49 +0100122}
Sebastian Jansson464a5572019-02-12 13:32:32 +0100123DataRate AudioAllocationSettings::DefaultPriorityBitrate() const {
124 DataRate max_overhead = DataRate::Zero();
125 if (send_side_bwe_with_overhead_) {
126 const TimeDelta kMinPacketDuration = TimeDelta::ms(20);
127 max_overhead = DataSize::bytes(kOverheadPerPacket) / kMinPacketDuration;
128 }
129 return priority_bitrate_.Get() + max_overhead;
130}
131
Sebastian Jansson470a5ea2019-01-23 12:37:49 +0100132} // namespace webrtc