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" |
Jonas Olsson | 8f119ca | 2019-05-08 10:56:23 +0200 | [diff] [blame] | 11 | |
Christoffer Rodbro | 7f8dbe1 | 2019-07-17 15:54:51 +0200 | [diff] [blame] | 12 | #include "rtc_base/logging.h" |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 13 | #include "system_wrappers/include/field_trial.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | namespace { |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 17 | // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12) |
| 18 | constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 19 | } // namespace |
| 20 | AudioAllocationSettings::AudioAllocationSettings() |
Sebastian Jansson | d9b4f33 | 2019-05-23 16:39:42 +0200 | [diff] [blame] | 21 | : audio_send_side_bwe_(field_trial::IsEnabled("WebRTC-Audio-SendSideBwe")), |
| 22 | allocate_audio_without_feedback_( |
| 23 | field_trial::IsEnabled("WebRTC-Audio-ABWENoTWCC")), |
| 24 | force_no_audio_feedback_( |
| 25 | field_trial::IsEnabled("WebRTC-Audio-ForceNoTWCC")), |
| 26 | enable_audio_alr_probing_( |
| 27 | !field_trial::IsDisabled("WebRTC-Audio-AlrProbing")), |
| 28 | send_side_bwe_with_overhead_( |
| 29 | field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), |
Daniel Lee | 9356252 | 2019-05-03 14:40:13 +0200 | [diff] [blame] | 30 | min_bitrate_("min"), |
| 31 | max_bitrate_("max"), |
Jonas Olsson | 8f119ca | 2019-05-08 10:56:23 +0200 | [diff] [blame] | 32 | priority_bitrate_("prio_rate", DataRate::Zero()), |
Christoffer Rodbro | 7f8dbe1 | 2019-07-17 15:54:51 +0200 | [diff] [blame] | 33 | priority_bitrate_raw_("prio_rate_raw"), |
Jonas Olsson | 8f119ca | 2019-05-08 10:56:23 +0200 | [diff] [blame] | 34 | bitrate_priority_("rate_prio") { |
Christoffer Rodbro | 7f8dbe1 | 2019-07-17 15:54:51 +0200 | [diff] [blame] | 35 | ParseFieldTrial({&min_bitrate_, &max_bitrate_, &priority_bitrate_, |
| 36 | &priority_bitrate_raw_, &bitrate_priority_}, |
| 37 | field_trial::FindFullName("WebRTC-Audio-Allocation")); |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 38 | |
| 39 | // TODO(mflodman): Keep testing this and set proper values. |
| 40 | // Note: This is an early experiment currently only supported by Opus. |
| 41 | if (send_side_bwe_with_overhead_) { |
| 42 | constexpr int kMaxPacketSizeMs = WEBRTC_OPUS_SUPPORT_120MS_PTIME ? 120 : 60; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 43 | min_overhead_bps_ = kOverheadPerPacket * 8 * 1000 / kMaxPacketSizeMs; |
| 44 | } |
Christoffer Rodbro | 7f8dbe1 | 2019-07-17 15:54:51 +0200 | [diff] [blame] | 45 | // priority_bitrate_raw will override priority_bitrate. |
| 46 | if (priority_bitrate_raw_ && !priority_bitrate_->IsZero()) { |
| 47 | RTC_LOG(LS_WARNING) << "'priority_bitrate' and '_raw' are mutually " |
| 48 | "exclusive but both were configured."; |
| 49 | } |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | AudioAllocationSettings::~AudioAllocationSettings() {} |
| 53 | |
| 54 | bool AudioAllocationSettings::ForceNoAudioFeedback() const { |
| 55 | return force_no_audio_feedback_; |
| 56 | } |
| 57 | |
| 58 | bool AudioAllocationSettings::IgnoreSeqNumIdChange() const { |
| 59 | return !audio_send_side_bwe_; |
| 60 | } |
| 61 | |
| 62 | bool AudioAllocationSettings::ConfigureRateAllocationRange() const { |
| 63 | return audio_send_side_bwe_; |
| 64 | } |
| 65 | |
Per Kjellander | 914351d | 2019-02-15 10:54:55 +0100 | [diff] [blame] | 66 | bool AudioAllocationSettings::ShouldSendTransportSequenceNumber( |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 67 | int transport_seq_num_extension_header_id) const { |
| 68 | if (force_no_audio_feedback_) |
| 69 | return false; |
Per Kjellander | 914351d | 2019-02-15 10:54:55 +0100 | [diff] [blame] | 70 | return audio_send_side_bwe_ && !allocate_audio_without_feedback_ && |
| 71 | transport_seq_num_extension_header_id != 0; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 72 | } |
| 73 | |
Christoffer Rodbro | a352248 | 2019-05-23 12:12:48 +0200 | [diff] [blame] | 74 | bool AudioAllocationSettings::RequestAlrProbing() const { |
Sebastian Jansson | d9b4f33 | 2019-05-23 16:39:42 +0200 | [diff] [blame] | 75 | return enable_audio_alr_probing_; |
Christoffer Rodbro | a352248 | 2019-05-23 12:12:48 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 78 | bool AudioAllocationSettings::IncludeAudioInAllocationOnStart( |
| 79 | int min_bitrate_bps, |
| 80 | int max_bitrate_bps, |
| 81 | bool has_dscp, |
| 82 | int transport_seq_num_extension_header_id) const { |
| 83 | if (has_dscp || min_bitrate_bps == -1 || max_bitrate_bps == -1) |
| 84 | return false; |
| 85 | if (transport_seq_num_extension_header_id != 0 && !force_no_audio_feedback_) |
| 86 | return true; |
| 87 | if (allocate_audio_without_feedback_) |
| 88 | return true; |
| 89 | if (audio_send_side_bwe_) |
| 90 | return false; |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | bool AudioAllocationSettings::IncludeAudioInAllocationOnReconfigure( |
| 95 | int min_bitrate_bps, |
| 96 | int max_bitrate_bps, |
| 97 | bool has_dscp, |
| 98 | int transport_seq_num_extension_header_id) const { |
| 99 | // TODO(srte): Make this match include_audio_in_allocation_on_start. |
| 100 | if (has_dscp || min_bitrate_bps == -1 || max_bitrate_bps == -1) |
| 101 | return false; |
| 102 | if (transport_seq_num_extension_header_id != 0) |
| 103 | return true; |
| 104 | if (audio_send_side_bwe_) |
| 105 | return false; |
| 106 | return true; |
| 107 | } |
| 108 | |
Daniel Lee | 9356252 | 2019-05-03 14:40:13 +0200 | [diff] [blame] | 109 | bool AudioAllocationSettings::IncludeOverheadInAudioAllocation() const { |
| 110 | return send_side_bwe_with_overhead_; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Daniel Lee | 9356252 | 2019-05-03 14:40:13 +0200 | [diff] [blame] | 113 | absl::optional<DataRate> AudioAllocationSettings::MinBitrate() const { |
| 114 | return min_bitrate_.GetOptional(); |
| 115 | } |
| 116 | absl::optional<DataRate> AudioAllocationSettings::MaxBitrate() const { |
| 117 | return max_bitrate_.GetOptional(); |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 118 | } |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 119 | DataRate AudioAllocationSettings::DefaultPriorityBitrate() const { |
| 120 | DataRate max_overhead = DataRate::Zero(); |
Christoffer Rodbro | 7f8dbe1 | 2019-07-17 15:54:51 +0200 | [diff] [blame] | 121 | if (priority_bitrate_raw_) { |
| 122 | return *priority_bitrate_raw_; |
| 123 | } |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 124 | if (send_side_bwe_with_overhead_) { |
| 125 | const TimeDelta kMinPacketDuration = TimeDelta::ms(20); |
| 126 | max_overhead = DataSize::bytes(kOverheadPerPacket) / kMinPacketDuration; |
| 127 | } |
| 128 | return priority_bitrate_.Get() + max_overhead; |
| 129 | } |
Jonas Olsson | 8f119ca | 2019-05-08 10:56:23 +0200 | [diff] [blame] | 130 | absl::optional<double> AudioAllocationSettings::BitratePriority() const { |
| 131 | return bitrate_priority_.GetOptional(); |
| 132 | } |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 133 | |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 134 | } // namespace webrtc |