Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 13 | namespace webrtc { |
| 14 | namespace { |
| 15 | // For SendSideBwe, Opus bitrate should be in the range between 6000 and 32000. |
| 16 | const int kOpusMinBitrateBps = 6000; |
| 17 | const int kOpusBitrateFbBps = 32000; |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 18 | // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12) |
| 19 | constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 20 | } // namespace |
| 21 | AudioAllocationSettings::AudioAllocationSettings() |
| 22 | : audio_send_side_bwe_("Enabled"), |
| 23 | allocate_audio_without_feedback_("Enabled"), |
| 24 | force_no_audio_feedback_("Enabled"), |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 25 | 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 Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 29 | 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 Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 35 | |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 36 | ParseFieldTrial({&send_side_bwe_with_overhead_}, |
| 37 | field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead")); |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 38 | ParseFieldTrial( |
| 39 | {&default_min_bitrate_, &default_max_bitrate_, &priority_bitrate_}, |
| 40 | field_trial::FindFullName("WebRTC-Audio-Allocation")); |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 41 | |
| 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 Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 46 | min_overhead_bps_ = kOverheadPerPacket * 8 * 1000 / kMaxPacketSizeMs; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | AudioAllocationSettings::~AudioAllocationSettings() {} |
| 51 | |
| 52 | bool AudioAllocationSettings::ForceNoAudioFeedback() const { |
| 53 | return force_no_audio_feedback_; |
| 54 | } |
| 55 | |
| 56 | bool AudioAllocationSettings::IgnoreSeqNumIdChange() const { |
| 57 | return !audio_send_side_bwe_; |
| 58 | } |
| 59 | |
| 60 | bool AudioAllocationSettings::ConfigureRateAllocationRange() const { |
| 61 | return audio_send_side_bwe_; |
| 62 | } |
| 63 | |
Per Kjellander | 914351d | 2019-02-15 10:54:55 +0100 | [diff] [blame] | 64 | bool AudioAllocationSettings::ShouldSendTransportSequenceNumber( |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 65 | int transport_seq_num_extension_header_id) const { |
| 66 | if (force_no_audio_feedback_) |
| 67 | return false; |
Per Kjellander | 914351d | 2019-02-15 10:54:55 +0100 | [diff] [blame] | 68 | return audio_send_side_bwe_ && !allocate_audio_without_feedback_ && |
| 69 | transport_seq_num_extension_header_id != 0; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 72 | bool 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 | |
| 88 | bool 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 | |
| 103 | int AudioAllocationSettings::MinBitrateBps() const { |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 104 | return default_min_bitrate_->bps() + min_overhead_bps_; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | int 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 Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 121 | return default_max_bitrate_->bps() + min_overhead_bps_; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 122 | } |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 123 | DataRate 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 Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 132 | } // namespace webrtc |