solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "audio/audio_send_stream.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 12 | |
| 13 | #include <string> |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 14 | #include <utility> |
| 15 | #include <vector> |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 16 | |
Niels Möller | fa4e185 | 2018-08-14 09:43:34 +0200 | [diff] [blame] | 17 | #include "absl/memory/memory.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 18 | #include "api/audio_codecs/audio_encoder.h" |
| 19 | #include "api/audio_codecs/audio_encoder_factory.h" |
| 20 | #include "api/audio_codecs/audio_format.h" |
| 21 | #include "api/call/transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "api/crypto/frame_encryptor_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "audio/audio_state.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 24 | #include "audio/channel_send.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "audio/conversion.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 26 | #include "call/rtp_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "call/rtp_transport_controller_send_interface.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 28 | #include "common_audio/vad/include/vad.h" |
Oskar Sundbom | 56ef305 | 2018-10-30 16:11:02 +0100 | [diff] [blame] | 29 | #include "logging/rtc_event_log/events/rtc_event_audio_send_stream_config.h" |
| 30 | #include "logging/rtc_event_log/rtc_event_log.h" |
| 31 | #include "logging/rtc_event_log/rtc_stream_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "modules/audio_coding/codecs/cng/audio_encoder_cng.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 33 | #include "modules/audio_processing/include/audio_processing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "rtc_base/checks.h" |
| 35 | #include "rtc_base/event.h" |
| 36 | #include "rtc_base/function_view.h" |
| 37 | #include "rtc_base/logging.h" |
Jonas Olsson | abbe841 | 2018-04-03 13:40:05 +0200 | [diff] [blame] | 38 | #include "rtc_base/strings/audio_format_to_string.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 39 | #include "rtc_base/task_queue.h" |
Alex Narest | cedd351 | 2017-12-07 20:54:55 +0100 | [diff] [blame] | 40 | #include "system_wrappers/include/field_trial.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 41 | |
| 42 | namespace webrtc { |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 43 | namespace internal { |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 44 | namespace { |
eladalon | edd6eea | 2017-05-25 00:15:35 -0700 | [diff] [blame] | 45 | // TODO(eladalon): Subsequent CL will make these values experiment-dependent. |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 46 | constexpr size_t kPacketLossTrackerMaxWindowSizeMs = 15000; |
| 47 | constexpr size_t kPacketLossRateMinNumAckedPackets = 50; |
| 48 | constexpr size_t kRecoverablePacketLossRateMinNumAckedPairs = 40; |
| 49 | |
Oskar Sundbom | 56ef305 | 2018-10-30 16:11:02 +0100 | [diff] [blame] | 50 | void UpdateEventLogStreamConfig(RtcEventLog* event_log, |
| 51 | const AudioSendStream::Config& config, |
| 52 | const AudioSendStream::Config* old_config) { |
| 53 | using SendCodecSpec = AudioSendStream::Config::SendCodecSpec; |
| 54 | // Only update if any of the things we log have changed. |
| 55 | auto payload_types_equal = [](const absl::optional<SendCodecSpec>& a, |
| 56 | const absl::optional<SendCodecSpec>& b) { |
| 57 | if (a.has_value() && b.has_value()) { |
| 58 | return a->format.name == b->format.name && |
| 59 | a->payload_type == b->payload_type; |
| 60 | } |
| 61 | return !a.has_value() && !b.has_value(); |
| 62 | }; |
| 63 | |
| 64 | if (old_config && config.rtp.ssrc == old_config->rtp.ssrc && |
| 65 | config.rtp.extensions == old_config->rtp.extensions && |
| 66 | payload_types_equal(config.send_codec_spec, |
| 67 | old_config->send_codec_spec)) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | auto rtclog_config = absl::make_unique<rtclog::StreamConfig>(); |
| 72 | rtclog_config->local_ssrc = config.rtp.ssrc; |
| 73 | rtclog_config->rtp_extensions = config.rtp.extensions; |
| 74 | if (config.send_codec_spec) { |
| 75 | rtclog_config->codecs.emplace_back(config.send_codec_spec->format.name, |
| 76 | config.send_codec_spec->payload_type, 0); |
| 77 | } |
| 78 | event_log->Log(absl::make_unique<RtcEventAudioSendStreamConfig>( |
| 79 | std::move(rtclog_config))); |
| 80 | } |
| 81 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 82 | } // namespace |
| 83 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 84 | AudioSendStream::AudioSendStream( |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame^] | 85 | Clock* clock, |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 86 | const webrtc::AudioSendStream::Config& config, |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 87 | const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 88 | rtc::TaskQueue* worker_queue, |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 89 | ProcessThread* module_process_thread, |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 90 | RtpTransportControllerSendInterface* rtp_transport, |
Niels Möller | 67b011d | 2018-10-22 13:00:40 +0200 | [diff] [blame] | 91 | BitrateAllocatorInterface* bitrate_allocator, |
michaelt | 9332b7d | 2016-11-30 07:51:13 -0800 | [diff] [blame] | 92 | RtcEventLog* event_log, |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 93 | RtcpRttStats* rtcp_rtt_stats, |
Sam Zackrisson | ff05816 | 2018-11-20 17:15:13 +0100 | [diff] [blame] | 94 | const absl::optional<RtpState>& suspended_rtp_state) |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame^] | 95 | : AudioSendStream(clock, |
| 96 | config, |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 97 | audio_state, |
| 98 | worker_queue, |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 99 | rtp_transport, |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 100 | bitrate_allocator, |
| 101 | event_log, |
| 102 | rtcp_rtt_stats, |
| 103 | suspended_rtp_state, |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame^] | 104 | voe::CreateChannelSend(clock, |
| 105 | worker_queue, |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 106 | module_process_thread, |
| 107 | config.media_transport, |
Anton Sukhanov | 626015d | 2019-02-04 15:16:06 -0800 | [diff] [blame] | 108 | /*overhead_observer=*/this, |
Niels Möller | e977199 | 2018-11-26 10:55:07 +0100 | [diff] [blame] | 109 | config.send_transport, |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 110 | rtcp_rtt_stats, |
| 111 | event_log, |
| 112 | config.frame_encryptor, |
| 113 | config.crypto_options, |
| 114 | config.rtp.extmap_allow_mixed, |
| 115 | config.rtcp_report_interval_ms)) {} |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 116 | |
| 117 | AudioSendStream::AudioSendStream( |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame^] | 118 | Clock* clock, |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 119 | const webrtc::AudioSendStream::Config& config, |
| 120 | const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 121 | rtc::TaskQueue* worker_queue, |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 122 | RtpTransportControllerSendInterface* rtp_transport, |
Niels Möller | 67b011d | 2018-10-22 13:00:40 +0200 | [diff] [blame] | 123 | BitrateAllocatorInterface* bitrate_allocator, |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 124 | RtcEventLog* event_log, |
| 125 | RtcpRttStats* rtcp_rtt_stats, |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 126 | const absl::optional<RtpState>& suspended_rtp_state, |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 127 | std::unique_ptr<voe::ChannelSendInterface> channel_send) |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame^] | 128 | : clock_(clock), |
| 129 | worker_queue_(worker_queue), |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 130 | config_(Config(/*send_transport=*/nullptr, |
| 131 | /*media_transport=*/nullptr)), |
mflodman | 86cc6ff | 2016-07-26 04:44:06 -0700 | [diff] [blame] | 132 | audio_state_(audio_state), |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 133 | channel_send_(std::move(channel_send)), |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 134 | event_log_(event_log), |
michaelt | f4caaab | 2017-01-16 23:55:07 -0800 | [diff] [blame] | 135 | bitrate_allocator_(bitrate_allocator), |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 136 | rtp_transport_(rtp_transport), |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 137 | packet_loss_tracker_(kPacketLossTrackerMaxWindowSizeMs, |
| 138 | kPacketLossRateMinNumAckedPackets, |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 139 | kRecoverablePacketLossRateMinNumAckedPairs), |
| 140 | rtp_rtcp_module_(nullptr), |
Sam Zackrisson | ff05816 | 2018-11-20 17:15:13 +0100 | [diff] [blame] | 141 | suspended_rtp_state_(suspended_rtp_state) { |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 142 | RTC_LOG(LS_INFO) << "AudioSendStream: " << config.rtp.ssrc; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 143 | RTC_DCHECK(worker_queue_); |
| 144 | RTC_DCHECK(audio_state_); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 145 | RTC_DCHECK(channel_send_); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 146 | RTC_DCHECK(bitrate_allocator_); |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 147 | // TODO(nisse): Eventually, we should have only media_transport. But for the |
| 148 | // time being, we can have either. When media transport is injected, there |
| 149 | // should be no rtp_transport, and below check should be strengthened to XOR |
| 150 | // (either rtp_transport or media_transport but not both). |
| 151 | RTC_DCHECK(rtp_transport || config.media_transport); |
Anton Sukhanov | 626015d | 2019-02-04 15:16:06 -0800 | [diff] [blame] | 152 | if (config.media_transport) { |
| 153 | // TODO(sukhanov): Currently media transport audio overhead is considered |
| 154 | // constant, we will not get overhead_observer calls when using |
| 155 | // media_transport. In the future when we introduce RTP media transport we |
| 156 | // should make audio overhead interface consistent and work for both RTP and |
| 157 | // non-RTP implementations. |
| 158 | audio_overhead_per_packet_bytes_ = |
| 159 | config.media_transport->GetAudioPacketOverhead(); |
| 160 | } |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 161 | rtp_rtcp_module_ = channel_send_->GetRtpRtcp(); |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 162 | RTC_DCHECK(rtp_rtcp_module_); |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 163 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 164 | ConfigureStream(this, config, true); |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 165 | |
| 166 | pacer_thread_checker_.DetachFromThread(); |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 167 | if (rtp_transport_) { |
| 168 | // Signal congestion controller this object is ready for OnPacket* |
| 169 | // callbacks. |
| 170 | rtp_transport_->RegisterPacketFeedbackObserver(this); |
| 171 | } |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | AudioSendStream::~AudioSendStream() { |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 175 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 176 | RTC_LOG(LS_INFO) << "~AudioSendStream: " << config_.rtp.ssrc; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 177 | RTC_DCHECK(!sending_); |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 178 | if (rtp_transport_) { |
| 179 | rtp_transport_->DeRegisterPacketFeedbackObserver(this); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 180 | channel_send_->ResetSenderCongestionControlObjects(); |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 181 | } |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 182 | } |
| 183 | |
eladalon | abbc430 | 2017-07-26 02:09:44 -0700 | [diff] [blame] | 184 | const webrtc::AudioSendStream::Config& AudioSendStream::GetConfig() const { |
| 185 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 186 | return config_; |
| 187 | } |
| 188 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 189 | void AudioSendStream::Reconfigure( |
| 190 | const webrtc::AudioSendStream::Config& new_config) { |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 191 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 192 | ConfigureStream(this, new_config, false); |
| 193 | } |
| 194 | |
Alex Narest | cedd351 | 2017-12-07 20:54:55 +0100 | [diff] [blame] | 195 | AudioSendStream::ExtensionIds AudioSendStream::FindExtensionIds( |
| 196 | const std::vector<RtpExtension>& extensions) { |
| 197 | ExtensionIds ids; |
| 198 | for (const auto& extension : extensions) { |
| 199 | if (extension.uri == RtpExtension::kAudioLevelUri) { |
| 200 | ids.audio_level = extension.id; |
| 201 | } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
| 202 | ids.transport_sequence_number = extension.id; |
Steve Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 203 | } else if (extension.uri == RtpExtension::kMidUri) { |
| 204 | ids.mid = extension.id; |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 205 | } else if (extension.uri == RtpExtension::kRidUri) { |
| 206 | ids.rid = extension.id; |
| 207 | } else if (extension.uri == RtpExtension::kRepairedRidUri) { |
| 208 | ids.repaired_rid = extension.id; |
Alex Narest | cedd351 | 2017-12-07 20:54:55 +0100 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | return ids; |
| 212 | } |
| 213 | |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 214 | int AudioSendStream::TransportSeqNumId(const AudioSendStream::Config& config) { |
| 215 | return FindExtensionIds(config.rtp.extensions).transport_sequence_number; |
| 216 | } |
| 217 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 218 | void AudioSendStream::ConfigureStream( |
| 219 | webrtc::internal::AudioSendStream* stream, |
| 220 | const webrtc::AudioSendStream::Config& new_config, |
| 221 | bool first_time) { |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 222 | RTC_LOG(LS_INFO) << "AudioSendStream::ConfigureStream: " |
| 223 | << new_config.ToString(); |
Oskar Sundbom | 56ef305 | 2018-10-30 16:11:02 +0100 | [diff] [blame] | 224 | UpdateEventLogStreamConfig(stream->event_log_, new_config, |
| 225 | first_time ? nullptr : &stream->config_); |
| 226 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 227 | const auto& channel_send = stream->channel_send_; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 228 | const auto& old_config = stream->config_; |
| 229 | |
Niels Möller | e977199 | 2018-11-26 10:55:07 +0100 | [diff] [blame] | 230 | // Configuration parameters which cannot be changed. |
| 231 | RTC_DCHECK(first_time || |
| 232 | old_config.send_transport == new_config.send_transport); |
| 233 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 234 | if (first_time || old_config.rtp.ssrc != new_config.rtp.ssrc) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 235 | channel_send->SetLocalSSRC(new_config.rtp.ssrc); |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 236 | if (stream->suspended_rtp_state_) { |
| 237 | stream->rtp_rtcp_module_->SetRtpState(*stream->suspended_rtp_state_); |
| 238 | } |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 239 | } |
| 240 | if (first_time || old_config.rtp.c_name != new_config.rtp.c_name) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 241 | channel_send->SetRTCP_CNAME(new_config.rtp.c_name); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 242 | } |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 243 | |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 244 | // Enable the frame encryptor if a new frame encryptor has been provided. |
| 245 | if (first_time || new_config.frame_encryptor != old_config.frame_encryptor) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 246 | channel_send->SetFrameEncryptor(new_config.frame_encryptor); |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 249 | if (first_time || |
| 250 | new_config.rtp.extmap_allow_mixed != old_config.rtp.extmap_allow_mixed) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 251 | channel_send->SetExtmapAllowMixed(new_config.rtp.extmap_allow_mixed); |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Alex Narest | cedd351 | 2017-12-07 20:54:55 +0100 | [diff] [blame] | 254 | const ExtensionIds old_ids = FindExtensionIds(old_config.rtp.extensions); |
| 255 | const ExtensionIds new_ids = FindExtensionIds(new_config.rtp.extensions); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 256 | // Audio level indication |
| 257 | if (first_time || new_ids.audio_level != old_ids.audio_level) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 258 | channel_send->SetSendAudioLevelIndicationStatus(new_ids.audio_level != 0, |
| 259 | new_ids.audio_level); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 260 | } |
Sebastian Jansson | 8d9c540 | 2017-11-15 17:22:16 +0100 | [diff] [blame] | 261 | bool transport_seq_num_id_changed = |
| 262 | new_ids.transport_sequence_number != old_ids.transport_sequence_number; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 263 | if (first_time || (transport_seq_num_id_changed && |
| 264 | !stream->allocation_settings_.ForceNoAudioFeedback())) { |
ossu | 1129df2 | 2017-06-30 01:38:56 -0700 | [diff] [blame] | 265 | if (!first_time) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 266 | channel_send->ResetSenderCongestionControlObjects(); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Sebastian Jansson | 8d9c540 | 2017-11-15 17:22:16 +0100 | [diff] [blame] | 269 | RtcpBandwidthObserver* bandwidth_observer = nullptr; |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 270 | |
Per Kjellander | 914351d | 2019-02-15 10:54:55 +0100 | [diff] [blame] | 271 | if (stream->allocation_settings_.ShouldSendTransportSequenceNumber( |
| 272 | new_ids.transport_sequence_number)) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 273 | channel_send->EnableSendTransportSequenceNumber( |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 274 | new_ids.transport_sequence_number); |
Sebastian Jansson | 8d9c540 | 2017-11-15 17:22:16 +0100 | [diff] [blame] | 275 | // Probing in application limited region is only used in combination with |
| 276 | // send side congestion control, wich depends on feedback packets which |
| 277 | // requires transport sequence numbers to be enabled. |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 278 | if (stream->rtp_transport_) { |
| 279 | stream->rtp_transport_->EnablePeriodicAlrProbing(true); |
| 280 | bandwidth_observer = stream->rtp_transport_->GetBandwidthObserver(); |
| 281 | } |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 282 | } |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 283 | if (stream->rtp_transport_) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 284 | channel_send->RegisterSenderCongestionControlObjects( |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 285 | stream->rtp_transport_, bandwidth_observer); |
| 286 | } |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 287 | } |
Steve Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 288 | // MID RTP header extension. |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 289 | if ((first_time || new_ids.mid != old_ids.mid || |
| 290 | new_config.rtp.mid != old_config.rtp.mid) && |
| 291 | new_ids.mid != 0 && !new_config.rtp.mid.empty()) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 292 | channel_send->SetMid(new_config.rtp.mid, new_ids.mid); |
Steve Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 295 | // RID RTP header extension |
| 296 | if ((first_time || new_ids.rid != old_ids.rid || |
| 297 | new_ids.repaired_rid != old_ids.repaired_rid || |
| 298 | new_config.rtp.rid != old_config.rtp.rid)) { |
| 299 | channel_send->SetRid(new_config.rtp.rid, new_ids.rid, new_ids.repaired_rid); |
| 300 | } |
| 301 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 302 | if (!ReconfigureSendCodec(stream, new_config)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 303 | RTC_LOG(LS_ERROR) << "Failed to set up send codec state."; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Oskar Sundbom | f85e31b | 2017-12-20 16:38:09 +0100 | [diff] [blame] | 306 | if (stream->sending_) { |
| 307 | ReconfigureBitrateObserver(stream, new_config); |
| 308 | } |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 309 | stream->config_ = new_config; |
| 310 | } |
| 311 | |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 312 | void AudioSendStream::Start() { |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 313 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 314 | if (sending_) { |
| 315 | return; |
| 316 | } |
| 317 | |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 318 | if (allocation_settings_.IncludeAudioInAllocationOnStart( |
| 319 | config_.min_bitrate_bps, config_.max_bitrate_bps, config_.has_dscp, |
| 320 | TransportSeqNumId(config_))) { |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 321 | rtp_transport_->packet_sender()->SetAccountForAudioPackets(true); |
Sebastian Jansson | b686396 | 2018-10-10 10:23:13 +0200 | [diff] [blame] | 322 | rtp_rtcp_module_->SetAsPartOfAllocation(true); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 323 | ConfigureBitrateObserver(config_.min_bitrate_bps, config_.max_bitrate_bps, |
Sebastian Jansson | 79f0d4d | 2019-01-23 09:41:43 +0100 | [diff] [blame] | 324 | config_.bitrate_priority); |
Sebastian Jansson | b686396 | 2018-10-10 10:23:13 +0200 | [diff] [blame] | 325 | } else { |
| 326 | rtp_rtcp_module_->SetAsPartOfAllocation(false); |
mflodman | 86cc6ff | 2016-07-26 04:44:06 -0700 | [diff] [blame] | 327 | } |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 328 | channel_send_->StartSend(); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 329 | sending_ = true; |
| 330 | audio_state()->AddSendingStream(this, encoder_sample_rate_hz_, |
| 331 | encoder_num_channels_); |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void AudioSendStream::Stop() { |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 335 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 336 | if (!sending_) { |
| 337 | return; |
| 338 | } |
| 339 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 340 | RemoveBitrateObserver(); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 341 | channel_send_->StopSend(); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 342 | sending_ = false; |
| 343 | audio_state()->RemoveSendingStream(this); |
| 344 | } |
| 345 | |
| 346 | void AudioSendStream::SendAudioData(std::unique_ptr<AudioFrame> audio_frame) { |
| 347 | RTC_CHECK_RUNS_SERIALIZED(&audio_capture_race_checker_); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 348 | channel_send_->ProcessAndEncodeAudio(std::move(audio_frame)); |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 349 | } |
| 350 | |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 351 | bool AudioSendStream::SendTelephoneEvent(int payload_type, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 352 | int payload_frequency, |
| 353 | int event, |
solenberg | 8842c3e | 2016-03-11 03:06:41 -0800 | [diff] [blame] | 354 | int duration_ms) { |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 355 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 356 | return channel_send_->SetSendTelephoneEventPayloadType(payload_type, |
| 357 | payload_frequency) && |
| 358 | channel_send_->SendTelephoneEventOutband(event, duration_ms); |
Fredrik Solenberg | b572768 | 2015-12-04 15:22:19 +0100 | [diff] [blame] | 359 | } |
| 360 | |
solenberg | 9421853 | 2016-06-16 10:53:22 -0700 | [diff] [blame] | 361 | void AudioSendStream::SetMuted(bool muted) { |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 362 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 363 | channel_send_->SetInputMute(muted); |
solenberg | 9421853 | 2016-06-16 10:53:22 -0700 | [diff] [blame] | 364 | } |
| 365 | |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 366 | webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const { |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 367 | return GetStats(true); |
| 368 | } |
| 369 | |
| 370 | webrtc::AudioSendStream::Stats AudioSendStream::GetStats( |
| 371 | bool has_remote_tracks) const { |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 372 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 373 | webrtc::AudioSendStream::Stats stats; |
| 374 | stats.local_ssrc = config_.rtp.ssrc; |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 375 | stats.target_bitrate_bps = channel_send_->GetBitrate(); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 376 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 377 | webrtc::CallSendStatistics call_stats = channel_send_->GetRTCPStatistics(); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 378 | stats.bytes_sent = call_stats.bytesSent; |
| 379 | stats.packets_sent = call_stats.packetsSent; |
solenberg | 8b85de2 | 2015-11-16 09:48:04 -0800 | [diff] [blame] | 380 | // RTT isn't known until a RTCP report is received. Until then, VoiceEngine |
| 381 | // returns 0 to indicate an error value. |
| 382 | if (call_stats.rttMs > 0) { |
| 383 | stats.rtt_ms = call_stats.rttMs; |
| 384 | } |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 385 | if (config_.send_codec_spec) { |
| 386 | const auto& spec = *config_.send_codec_spec; |
| 387 | stats.codec_name = spec.format.name; |
Oskar Sundbom | 2707fb2 | 2017-11-16 10:57:35 +0100 | [diff] [blame] | 388 | stats.codec_payload_type = spec.payload_type; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 389 | |
| 390 | // Get data from the last remote RTCP report. |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 391 | for (const auto& block : channel_send_->GetRemoteRTCPReportBlocks()) { |
solenberg | 8b85de2 | 2015-11-16 09:48:04 -0800 | [diff] [blame] | 392 | // Lookup report for send ssrc only. |
| 393 | if (block.source_SSRC == stats.local_ssrc) { |
| 394 | stats.packets_lost = block.cumulative_num_packets_lost; |
| 395 | stats.fraction_lost = Q8ToFloat(block.fraction_lost); |
| 396 | stats.ext_seqnum = block.extended_highest_sequence_number; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 397 | // Convert timestamps to milliseconds. |
| 398 | if (spec.format.clockrate_hz / 1000 > 0) { |
solenberg | 8b85de2 | 2015-11-16 09:48:04 -0800 | [diff] [blame] | 399 | stats.jitter_ms = |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 400 | block.interarrival_jitter / (spec.format.clockrate_hz / 1000); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 401 | } |
solenberg | 8b85de2 | 2015-11-16 09:48:04 -0800 | [diff] [blame] | 402 | break; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 407 | AudioState::Stats input_stats = audio_state()->GetAudioInputStats(); |
| 408 | stats.audio_level = input_stats.audio_level; |
| 409 | stats.total_input_energy = input_stats.total_energy; |
| 410 | stats.total_input_duration = input_stats.total_duration; |
solenberg | 796b8f9 | 2017-03-01 17:02:23 -0800 | [diff] [blame] | 411 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 412 | stats.typing_noise_detected = audio_state()->typing_noise_detected(); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 413 | stats.ana_statistics = channel_send_->GetANAStatistics(); |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 414 | RTC_DCHECK(audio_state_->audio_processing()); |
| 415 | stats.apm_statistics = |
| 416 | audio_state_->audio_processing()->GetStatistics(has_remote_tracks); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 417 | |
| 418 | return stats; |
| 419 | } |
| 420 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 421 | void AudioSendStream::SignalNetworkState(NetworkState state) { |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 422 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 426 | // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 427 | // calls on the worker thread. We should move towards always using a network |
| 428 | // thread. Then this check can be enabled. |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 429 | // RTC_DCHECK(!worker_thread_checker_.CalledOnValidThread()); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 430 | return channel_send_->ReceivedRTCPPacket(packet, length); |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Sebastian Jansson | c0e4d45 | 2018-10-25 15:08:32 +0200 | [diff] [blame] | 433 | uint32_t AudioSendStream::OnBitrateUpdated(BitrateAllocationUpdate update) { |
stefan | fca900a | 2017-04-10 03:53:00 -0700 | [diff] [blame] | 434 | // A send stream may be allocated a bitrate of zero if the allocator decides |
| 435 | // to disable it. For now we ignore this decision and keep sending on min |
| 436 | // bitrate. |
Sebastian Jansson | 13e5903 | 2018-11-21 19:13:07 +0100 | [diff] [blame] | 437 | if (update.target_bitrate.IsZero()) { |
| 438 | update.target_bitrate = DataRate::bps(config_.min_bitrate_bps); |
stefan | fca900a | 2017-04-10 03:53:00 -0700 | [diff] [blame] | 439 | } |
Sebastian Jansson | 13e5903 | 2018-11-21 19:13:07 +0100 | [diff] [blame] | 440 | RTC_DCHECK_GE(update.target_bitrate.bps<int>(), config_.min_bitrate_bps); |
mflodman | 86cc6ff | 2016-07-26 04:44:06 -0700 | [diff] [blame] | 441 | // The bitrate allocator might allocate an higher than max configured bitrate |
| 442 | // if there is room, to allow for, as example, extra FEC. Ignore that for now. |
Sebastian Jansson | 13e5903 | 2018-11-21 19:13:07 +0100 | [diff] [blame] | 443 | const DataRate max_bitrate = DataRate::bps(config_.max_bitrate_bps); |
| 444 | if (update.target_bitrate > max_bitrate) |
| 445 | update.target_bitrate = max_bitrate; |
mflodman | 86cc6ff | 2016-07-26 04:44:06 -0700 | [diff] [blame] | 446 | |
Sebastian Jansson | 254d869 | 2018-11-21 19:19:00 +0100 | [diff] [blame] | 447 | channel_send_->OnBitrateAllocation(update); |
mflodman | 86cc6ff | 2016-07-26 04:44:06 -0700 | [diff] [blame] | 448 | |
| 449 | // The amount of audio protection is not exposed by the encoder, hence |
| 450 | // always returning 0. |
| 451 | return 0; |
| 452 | } |
| 453 | |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 454 | void AudioSendStream::OnPacketAdded(uint32_t ssrc, uint16_t seq_num) { |
| 455 | RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); |
| 456 | // Only packets that belong to this stream are of interest. |
| 457 | if (ssrc == config_.rtp.ssrc) { |
| 458 | rtc::CritScope lock(&packet_loss_tracker_cs_); |
eladalon | edd6eea | 2017-05-25 00:15:35 -0700 | [diff] [blame] | 459 | // TODO(eladalon): This function call could potentially reset the window, |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 460 | // setting both PLR and RPLR to unknown. Consider (during upcoming |
| 461 | // refactoring) passing an indication of such an event. |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame^] | 462 | packet_loss_tracker_.OnPacketAdded(seq_num, clock_->TimeInMilliseconds()); |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
| 466 | void AudioSendStream::OnPacketFeedbackVector( |
| 467 | const std::vector<PacketFeedback>& packet_feedback_vector) { |
eladalon | 3651fdd | 2017-08-24 07:26:25 -0700 | [diff] [blame] | 468 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 469 | absl::optional<float> plr; |
| 470 | absl::optional<float> rplr; |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 471 | { |
| 472 | rtc::CritScope lock(&packet_loss_tracker_cs_); |
| 473 | packet_loss_tracker_.OnPacketFeedbackVector(packet_feedback_vector); |
| 474 | plr = packet_loss_tracker_.GetPacketLossRate(); |
elad.alon | dadb4dc | 2017-03-23 15:29:50 -0700 | [diff] [blame] | 475 | rplr = packet_loss_tracker_.GetRecoverablePacketLossRate(); |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 476 | } |
eladalon | edd6eea | 2017-05-25 00:15:35 -0700 | [diff] [blame] | 477 | // TODO(eladalon): If R/PLR go back to unknown, no indication is given that |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 478 | // the previously sent value is no longer relevant. This will be taken care |
| 479 | // of with some refactoring which is now being done. |
| 480 | if (plr) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 481 | channel_send_->OnTwccBasedUplinkPacketLossRate(*plr); |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 482 | } |
elad.alon | dadb4dc | 2017-03-23 15:29:50 -0700 | [diff] [blame] | 483 | if (rplr) { |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 484 | channel_send_->OnRecoverableUplinkPacketLossRate(*rplr); |
elad.alon | dadb4dc | 2017-03-23 15:29:50 -0700 | [diff] [blame] | 485 | } |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Anton Sukhanov | 626015d | 2019-02-04 15:16:06 -0800 | [diff] [blame] | 488 | void AudioSendStream::SetTransportOverhead( |
| 489 | int transport_overhead_per_packet_bytes) { |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 490 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Anton Sukhanov | 626015d | 2019-02-04 15:16:06 -0800 | [diff] [blame] | 491 | rtc::CritScope cs(&overhead_per_packet_lock_); |
| 492 | transport_overhead_per_packet_bytes_ = transport_overhead_per_packet_bytes; |
| 493 | UpdateOverheadForEncoder(); |
| 494 | } |
| 495 | |
| 496 | void AudioSendStream::OnOverheadChanged( |
| 497 | size_t overhead_bytes_per_packet_bytes) { |
| 498 | rtc::CritScope cs(&overhead_per_packet_lock_); |
| 499 | audio_overhead_per_packet_bytes_ = overhead_bytes_per_packet_bytes; |
| 500 | UpdateOverheadForEncoder(); |
| 501 | } |
| 502 | |
| 503 | void AudioSendStream::UpdateOverheadForEncoder() { |
| 504 | const size_t overhead_per_packet_bytes = GetPerPacketOverheadBytes(); |
Sebastian Jansson | 14a7cf9 | 2019-02-13 15:11:42 +0100 | [diff] [blame] | 505 | channel_send_->CallEncoder([&](AudioEncoder* encoder) { |
| 506 | encoder->OnReceivedOverhead(overhead_per_packet_bytes); |
Anton Sukhanov | 626015d | 2019-02-04 15:16:06 -0800 | [diff] [blame] | 507 | }); |
| 508 | } |
| 509 | |
| 510 | size_t AudioSendStream::TestOnlyGetPerPacketOverheadBytes() const { |
| 511 | rtc::CritScope cs(&overhead_per_packet_lock_); |
| 512 | return GetPerPacketOverheadBytes(); |
| 513 | } |
| 514 | |
| 515 | size_t AudioSendStream::GetPerPacketOverheadBytes() const { |
| 516 | return transport_overhead_per_packet_bytes_ + |
| 517 | audio_overhead_per_packet_bytes_; |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 518 | } |
| 519 | |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 520 | RtpState AudioSendStream::GetRtpState() const { |
| 521 | return rtp_rtcp_module_->GetRtpState(); |
| 522 | } |
| 523 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 524 | const voe::ChannelSendInterface* AudioSendStream::GetChannel() const { |
| 525 | return channel_send_.get(); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 528 | internal::AudioState* AudioSendStream::audio_state() { |
| 529 | internal::AudioState* audio_state = |
| 530 | static_cast<internal::AudioState*>(audio_state_.get()); |
| 531 | RTC_DCHECK(audio_state); |
| 532 | return audio_state; |
| 533 | } |
| 534 | |
| 535 | const internal::AudioState* AudioSendStream::audio_state() const { |
| 536 | internal::AudioState* audio_state = |
| 537 | static_cast<internal::AudioState*>(audio_state_.get()); |
| 538 | RTC_DCHECK(audio_state); |
| 539 | return audio_state; |
| 540 | } |
| 541 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 542 | void AudioSendStream::StoreEncoderProperties(int sample_rate_hz, |
| 543 | size_t num_channels) { |
| 544 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 545 | encoder_sample_rate_hz_ = sample_rate_hz; |
| 546 | encoder_num_channels_ = num_channels; |
| 547 | if (sending_) { |
| 548 | // Update AudioState's information about the stream. |
| 549 | audio_state()->AddSendingStream(this, sample_rate_hz, num_channels); |
| 550 | } |
| 551 | } |
| 552 | |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 553 | // Apply current codec settings to a single voe::Channel used for sending. |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 554 | bool AudioSendStream::SetupSendCodec(AudioSendStream* stream, |
| 555 | const Config& new_config) { |
| 556 | RTC_DCHECK(new_config.send_codec_spec); |
| 557 | const auto& spec = *new_config.send_codec_spec; |
minyue | 48368ad | 2017-05-10 04:06:11 -0700 | [diff] [blame] | 558 | |
| 559 | RTC_DCHECK(new_config.encoder_factory); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 560 | std::unique_ptr<AudioEncoder> encoder = |
Karl Wiberg | 77490b9 | 2018-03-21 15:18:42 +0100 | [diff] [blame] | 561 | new_config.encoder_factory->MakeAudioEncoder( |
| 562 | spec.payload_type, spec.format, new_config.codec_pair_id); |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 563 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 564 | if (!encoder) { |
Jonas Olsson | abbe841 | 2018-04-03 13:40:05 +0200 | [diff] [blame] | 565 | RTC_DLOG(LS_ERROR) << "Unable to create encoder for " |
| 566 | << rtc::ToString(spec.format); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 567 | return false; |
| 568 | } |
Alex Narest | bbbe4e1 | 2018-07-13 10:32:58 +0200 | [diff] [blame] | 569 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 570 | // If a bitrate has been specified for the codec, use it over the |
| 571 | // codec's default. |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 572 | if (stream->allocation_settings_.UpdateAudioTargetBitrate( |
| 573 | TransportSeqNumId(new_config)) && |
| 574 | spec.target_bitrate_bps) { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 575 | encoder->OnReceivedTargetAudioBitrate(*spec.target_bitrate_bps); |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 576 | } |
| 577 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 578 | // Enable ANA if configured (currently only used by Opus). |
| 579 | if (new_config.audio_network_adaptor_config) { |
| 580 | if (encoder->EnableAudioNetworkAdaptor( |
| 581 | *new_config.audio_network_adaptor_config, stream->event_log_)) { |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 582 | RTC_DLOG(LS_INFO) << "Audio network adaptor enabled on SSRC " |
| 583 | << new_config.rtp.ssrc; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 584 | } else { |
| 585 | RTC_NOTREACHED(); |
minyue | 6b825df | 2016-10-31 04:08:32 -0700 | [diff] [blame] | 586 | } |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 587 | } |
| 588 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 589 | // Wrap the encoder in a an AudioEncoderCNG, if VAD is enabled. |
| 590 | if (spec.cng_payload_type) { |
Karl Wiberg | 2365936 | 2018-11-01 11:13:44 +0100 | [diff] [blame] | 591 | AudioEncoderCngConfig cng_config; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 592 | cng_config.num_channels = encoder->NumChannels(); |
| 593 | cng_config.payload_type = *spec.cng_payload_type; |
| 594 | cng_config.speech_encoder = std::move(encoder); |
| 595 | cng_config.vad_mode = Vad::kVadNormal; |
Karl Wiberg | 2365936 | 2018-11-01 11:13:44 +0100 | [diff] [blame] | 596 | encoder = CreateComfortNoiseEncoder(std::move(cng_config)); |
ossu | 3b9ff38 | 2017-04-27 08:03:42 -0700 | [diff] [blame] | 597 | |
| 598 | stream->RegisterCngPayloadType( |
| 599 | *spec.cng_payload_type, |
| 600 | new_config.send_codec_spec->format.clockrate_hz); |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 601 | } |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 602 | |
Anton Sukhanov | 626015d | 2019-02-04 15:16:06 -0800 | [diff] [blame] | 603 | // Set currently known overhead (used in ANA, opus only). |
| 604 | // If overhead changes later, it will be updated in UpdateOverheadForEncoder. |
| 605 | { |
| 606 | rtc::CritScope cs(&stream->overhead_per_packet_lock_); |
| 607 | encoder->OnReceivedOverhead(stream->GetPerPacketOverheadBytes()); |
| 608 | } |
| 609 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 610 | stream->StoreEncoderProperties(encoder->SampleRateHz(), |
| 611 | encoder->NumChannels()); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 612 | stream->channel_send_->SetEncoder(new_config.send_codec_spec->payload_type, |
| 613 | std::move(encoder)); |
Anton Sukhanov | 626015d | 2019-02-04 15:16:06 -0800 | [diff] [blame] | 614 | |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 615 | return true; |
| 616 | } |
| 617 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 618 | bool AudioSendStream::ReconfigureSendCodec(AudioSendStream* stream, |
| 619 | const Config& new_config) { |
| 620 | const auto& old_config = stream->config_; |
minyue-webrtc | 8de1826 | 2017-07-26 14:18:40 +0200 | [diff] [blame] | 621 | |
| 622 | if (!new_config.send_codec_spec) { |
| 623 | // We cannot de-configure a send codec. So we will do nothing. |
| 624 | // By design, the send codec should have not been configured. |
| 625 | RTC_DCHECK(!old_config.send_codec_spec); |
| 626 | return true; |
| 627 | } |
| 628 | |
| 629 | if (new_config.send_codec_spec == old_config.send_codec_spec && |
| 630 | new_config.audio_network_adaptor_config == |
| 631 | old_config.audio_network_adaptor_config) { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 632 | return true; |
| 633 | } |
| 634 | |
| 635 | // If we have no encoder, or the format or payload type's changed, create a |
| 636 | // new encoder. |
| 637 | if (!old_config.send_codec_spec || |
| 638 | new_config.send_codec_spec->format != |
| 639 | old_config.send_codec_spec->format || |
| 640 | new_config.send_codec_spec->payload_type != |
| 641 | old_config.send_codec_spec->payload_type) { |
| 642 | return SetupSendCodec(stream, new_config); |
| 643 | } |
| 644 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 645 | const absl::optional<int>& new_target_bitrate_bps = |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 646 | new_config.send_codec_spec->target_bitrate_bps; |
| 647 | // If a bitrate has been specified for the codec, use it over the |
| 648 | // codec's default. |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 649 | if (stream->allocation_settings_.UpdateAudioTargetBitrate( |
| 650 | TransportSeqNumId(new_config)) && |
| 651 | new_target_bitrate_bps && |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 652 | new_target_bitrate_bps != |
| 653 | old_config.send_codec_spec->target_bitrate_bps) { |
Sebastian Jansson | 14a7cf9 | 2019-02-13 15:11:42 +0100 | [diff] [blame] | 654 | stream->channel_send_->CallEncoder([&](AudioEncoder* encoder) { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 655 | encoder->OnReceivedTargetAudioBitrate(*new_target_bitrate_bps); |
| 656 | }); |
| 657 | } |
| 658 | |
| 659 | ReconfigureANA(stream, new_config); |
| 660 | ReconfigureCNG(stream, new_config); |
| 661 | |
Anton Sukhanov | 626015d | 2019-02-04 15:16:06 -0800 | [diff] [blame] | 662 | // Set currently known overhead (used in ANA, opus only). |
| 663 | { |
| 664 | rtc::CritScope cs(&stream->overhead_per_packet_lock_); |
| 665 | stream->UpdateOverheadForEncoder(); |
| 666 | } |
| 667 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 668 | return true; |
| 669 | } |
| 670 | |
| 671 | void AudioSendStream::ReconfigureANA(AudioSendStream* stream, |
| 672 | const Config& new_config) { |
| 673 | if (new_config.audio_network_adaptor_config == |
| 674 | stream->config_.audio_network_adaptor_config) { |
| 675 | return; |
| 676 | } |
| 677 | if (new_config.audio_network_adaptor_config) { |
Sebastian Jansson | 14a7cf9 | 2019-02-13 15:11:42 +0100 | [diff] [blame] | 678 | stream->channel_send_->CallEncoder([&](AudioEncoder* encoder) { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 679 | if (encoder->EnableAudioNetworkAdaptor( |
| 680 | *new_config.audio_network_adaptor_config, stream->event_log_)) { |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 681 | RTC_DLOG(LS_INFO) << "Audio network adaptor enabled on SSRC " |
| 682 | << new_config.rtp.ssrc; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 683 | } else { |
| 684 | RTC_NOTREACHED(); |
| 685 | } |
| 686 | }); |
| 687 | } else { |
Sebastian Jansson | 14a7cf9 | 2019-02-13 15:11:42 +0100 | [diff] [blame] | 688 | stream->channel_send_->CallEncoder( |
| 689 | [&](AudioEncoder* encoder) { encoder->DisableAudioNetworkAdaptor(); }); |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 690 | RTC_DLOG(LS_INFO) << "Audio network adaptor disabled on SSRC " |
| 691 | << new_config.rtp.ssrc; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
| 695 | void AudioSendStream::ReconfigureCNG(AudioSendStream* stream, |
| 696 | const Config& new_config) { |
| 697 | if (new_config.send_codec_spec->cng_payload_type == |
| 698 | stream->config_.send_codec_spec->cng_payload_type) { |
| 699 | return; |
| 700 | } |
| 701 | |
ossu | 3b9ff38 | 2017-04-27 08:03:42 -0700 | [diff] [blame] | 702 | // Register the CNG payload type if it's been added, don't do anything if CNG |
| 703 | // is removed. Payload types must not be redefined. |
| 704 | if (new_config.send_codec_spec->cng_payload_type) { |
| 705 | stream->RegisterCngPayloadType( |
| 706 | *new_config.send_codec_spec->cng_payload_type, |
| 707 | new_config.send_codec_spec->format.clockrate_hz); |
| 708 | } |
| 709 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 710 | // Wrap or unwrap the encoder in an AudioEncoderCNG. |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 711 | stream->channel_send_->ModifyEncoder( |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 712 | [&](std::unique_ptr<AudioEncoder>* encoder_ptr) { |
| 713 | std::unique_ptr<AudioEncoder> old_encoder(std::move(*encoder_ptr)); |
| 714 | auto sub_encoders = old_encoder->ReclaimContainedEncoders(); |
| 715 | if (!sub_encoders.empty()) { |
| 716 | // Replace enc with its sub encoder. We need to put the sub |
| 717 | // encoder in a temporary first, since otherwise the old value |
| 718 | // of enc would be destroyed before the new value got assigned, |
| 719 | // which would be bad since the new value is a part of the old |
| 720 | // value. |
| 721 | auto tmp = std::move(sub_encoders[0]); |
| 722 | old_encoder = std::move(tmp); |
| 723 | } |
| 724 | if (new_config.send_codec_spec->cng_payload_type) { |
Karl Wiberg | 2365936 | 2018-11-01 11:13:44 +0100 | [diff] [blame] | 725 | AudioEncoderCngConfig config; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 726 | config.speech_encoder = std::move(old_encoder); |
| 727 | config.num_channels = config.speech_encoder->NumChannels(); |
| 728 | config.payload_type = *new_config.send_codec_spec->cng_payload_type; |
| 729 | config.vad_mode = Vad::kVadNormal; |
Karl Wiberg | 2365936 | 2018-11-01 11:13:44 +0100 | [diff] [blame] | 730 | *encoder_ptr = CreateComfortNoiseEncoder(std::move(config)); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 731 | } else { |
| 732 | *encoder_ptr = std::move(old_encoder); |
| 733 | } |
| 734 | }); |
| 735 | } |
| 736 | |
| 737 | void AudioSendStream::ReconfigureBitrateObserver( |
| 738 | AudioSendStream* stream, |
| 739 | const webrtc::AudioSendStream::Config& new_config) { |
| 740 | // Since the Config's default is for both of these to be -1, this test will |
| 741 | // allow us to configure the bitrate observer if the new config has bitrate |
| 742 | // limits set, but would only have us call RemoveBitrateObserver if we were |
| 743 | // previously configured with bitrate limits. |
| 744 | if (stream->config_.min_bitrate_bps == new_config.min_bitrate_bps && |
Alex Narest | cedd351 | 2017-12-07 20:54:55 +0100 | [diff] [blame] | 745 | stream->config_.max_bitrate_bps == new_config.max_bitrate_bps && |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 746 | stream->config_.bitrate_priority == new_config.bitrate_priority && |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 747 | (TransportSeqNumId(stream->config_) == TransportSeqNumId(new_config) || |
| 748 | stream->allocation_settings_.IgnoreSeqNumIdChange())) { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 749 | return; |
| 750 | } |
| 751 | |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 752 | if (stream->allocation_settings_.IncludeAudioInAllocationOnReconfigure( |
| 753 | new_config.min_bitrate_bps, new_config.max_bitrate_bps, |
| 754 | new_config.has_dscp, TransportSeqNumId(new_config))) { |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 755 | stream->rtp_transport_->packet_sender()->SetAccountForAudioPackets(true); |
Sebastian Jansson | 79f0d4d | 2019-01-23 09:41:43 +0100 | [diff] [blame] | 756 | stream->ConfigureBitrateObserver(new_config.min_bitrate_bps, |
| 757 | new_config.max_bitrate_bps, |
| 758 | new_config.bitrate_priority); |
Sebastian Jansson | 470a5ea | 2019-01-23 12:37:49 +0100 | [diff] [blame] | 759 | stream->rtp_rtcp_module_->SetAsPartOfAllocation(true); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 760 | } else { |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 761 | stream->rtp_transport_->packet_sender()->SetAccountForAudioPackets(false); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 762 | stream->RemoveBitrateObserver(); |
Sebastian Jansson | b686396 | 2018-10-10 10:23:13 +0200 | [diff] [blame] | 763 | stream->rtp_rtcp_module_->SetAsPartOfAllocation(false); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
| 767 | void AudioSendStream::ConfigureBitrateObserver(int min_bitrate_bps, |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 768 | int max_bitrate_bps, |
Sebastian Jansson | 79f0d4d | 2019-01-23 09:41:43 +0100 | [diff] [blame] | 769 | double bitrate_priority) { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 770 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 771 | RTC_DCHECK_GE(max_bitrate_bps, min_bitrate_bps); |
Niels Möller | c572ff3 | 2018-11-07 08:43:50 +0100 | [diff] [blame] | 772 | rtc::Event thread_sync_event; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 773 | worker_queue_->PostTask([&] { |
| 774 | // We may get a callback immediately as the observer is registered, so make |
| 775 | // sure the bitrate limits in config_ are up-to-date. |
| 776 | config_.min_bitrate_bps = min_bitrate_bps; |
| 777 | config_.max_bitrate_bps = max_bitrate_bps; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 778 | config_.bitrate_priority = bitrate_priority; |
| 779 | // This either updates the current observer or adds a new observer. |
Sebastian Jansson | 24ad720 | 2018-04-19 08:25:12 +0200 | [diff] [blame] | 780 | bitrate_allocator_->AddObserver( |
Sebastian Jansson | 464a557 | 2019-02-12 13:32:32 +0100 | [diff] [blame] | 781 | this, MediaStreamAllocationConfig{ |
| 782 | static_cast<uint32_t>(min_bitrate_bps), |
| 783 | static_cast<uint32_t>(max_bitrate_bps), 0, |
| 784 | allocation_settings_.DefaultPriorityBitrate().bps(), true, |
| 785 | config_.track_id, bitrate_priority}); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 786 | thread_sync_event.Set(); |
| 787 | }); |
| 788 | thread_sync_event.Wait(rtc::Event::kForever); |
| 789 | } |
| 790 | |
| 791 | void AudioSendStream::RemoveBitrateObserver() { |
| 792 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Niels Möller | c572ff3 | 2018-11-07 08:43:50 +0100 | [diff] [blame] | 793 | rtc::Event thread_sync_event; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 794 | worker_queue_->PostTask([this, &thread_sync_event] { |
| 795 | bitrate_allocator_->RemoveObserver(this); |
| 796 | thread_sync_event.Set(); |
| 797 | }); |
| 798 | thread_sync_event.Wait(rtc::Event::kForever); |
| 799 | } |
| 800 | |
ossu | 3b9ff38 | 2017-04-27 08:03:42 -0700 | [diff] [blame] | 801 | void AudioSendStream::RegisterCngPayloadType(int payload_type, |
| 802 | int clockrate_hz) { |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 803 | rtp_rtcp_module_->RegisterAudioSendPayload(payload_type, "CN", clockrate_hz, |
| 804 | 1, 0); |
ossu | 3b9ff38 | 2017-04-27 08:03:42 -0700 | [diff] [blame] | 805 | } |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 806 | } // namespace internal |
| 807 | } // namespace webrtc |