blob: 4f2e29c75ef0b5d9b4725f0efe1be099a5a4e5f7 [file] [log] [blame]
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +02001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "audio/audio_receive_stream.h"
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020012
13#include <string>
Tommif888bb52015-12-12 01:37:01 +010014#include <utility>
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020015
Yves Gerey988cc082018-10-23 12:03:01 +020016#include "absl/memory/memory.h"
17#include "api/array_view.h"
18#include "api/audio_codecs/audio_format.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/call/audio_sink.h"
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "api/rtpparameters.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "audio/audio_send_stream.h"
22#include "audio/audio_state.h"
Yves Gerey988cc082018-10-23 12:03:01 +020023#include "audio/channel_receive.h"
Niels Möllerb222f492018-10-03 16:50:08 +020024#include "audio/channel_receive_proxy.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "audio/conversion.h"
Yves Gerey988cc082018-10-23 12:03:01 +020026#include "call/rtp_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "call/rtp_stream_receiver_controller_interface.h"
Yves Gerey988cc082018-10-23 12:03:01 +020028#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "rtc_base/checks.h"
30#include "rtc_base/logging.h"
Tommifef05002018-02-27 13:51:08 +010031#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "rtc_base/timeutils.h"
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020033
34namespace webrtc {
Stefan Holmer3842c5c2016-01-12 13:55:00 +010035
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020036std::string AudioReceiveStream::Config::Rtp::ToString() const {
Karl Wiberg881f1682018-03-08 15:03:23 +010037 char ss_buf[1024];
38 rtc::SimpleStringBuilder ss(ss_buf);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020039 ss << "{remote_ssrc: " << remote_ssrc;
solenberg85a04962015-10-27 03:35:21 -070040 ss << ", local_ssrc: " << local_ssrc;
solenberg8189b022016-06-14 12:13:00 -070041 ss << ", transport_cc: " << (transport_cc ? "on" : "off");
42 ss << ", nack: " << nack.ToString();
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020043 ss << ", extensions: [";
44 for (size_t i = 0; i < extensions.size(); ++i) {
45 ss << extensions[i].ToString();
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020046 if (i != extensions.size() - 1) {
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020047 ss << ", ";
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020048 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020049 }
50 ss << ']';
51 ss << '}';
52 return ss.str();
53}
54
55std::string AudioReceiveStream::Config::ToString() const {
Karl Wiberg881f1682018-03-08 15:03:23 +010056 char ss_buf[1024];
57 rtc::SimpleStringBuilder ss(ss_buf);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020058 ss << "{rtp: " << rtp.ToString();
solenberg85a04962015-10-27 03:35:21 -070059 ss << ", rtcp_send_transport: "
deadbeef922246a2017-02-26 04:18:12 -080060 << (rtcp_send_transport ? "(Transport)" : "null");
Niels Möller7d76a312018-10-26 12:57:07 +020061 ss << ", media_transport: " << (media_transport ? "(Transport)" : "null");
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020062 if (!sync_group.empty()) {
pbos8fc7fa72015-07-15 08:02:58 -070063 ss << ", sync_group: " << sync_group;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020064 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020065 ss << '}';
66 return ss.str();
67}
68
69namespace internal {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010070namespace {
Niels Möllerb222f492018-10-03 16:50:08 +020071std::unique_ptr<voe::ChannelReceiveProxy> CreateChannelAndProxy(
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010072 webrtc::AudioState* audio_state,
73 ProcessThread* module_process_thread,
Niels Möllerfa4e1852018-08-14 09:43:34 +020074 const webrtc::AudioReceiveStream::Config& config,
75 RtcEventLog* event_log) {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010076 RTC_DCHECK(audio_state);
77 internal::AudioState* internal_audio_state =
78 static_cast<internal::AudioState*>(audio_state);
Niels Möllerb222f492018-10-03 16:50:08 +020079 return absl::make_unique<voe::ChannelReceiveProxy>(
Niels Möller530ead42018-10-04 14:28:39 +020080 absl::make_unique<voe::ChannelReceive>(
Niels Möllerb222f492018-10-03 16:50:08 +020081 module_process_thread, internal_audio_state->audio_device_module(),
Niels Möller7d76a312018-10-26 12:57:07 +020082 config.media_transport, config.rtcp_send_transport, event_log,
83 config.rtp.remote_ssrc, config.jitter_buffer_max_packets,
Niels Möllerb222f492018-10-03 16:50:08 +020084 config.jitter_buffer_fast_accelerate, config.decoder_factory,
Benjamin Wrightbfb444c2018-10-15 10:20:24 -070085 config.codec_pair_id, config.frame_decryptor, config.crypto_options));
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010086}
87} // namespace
88
89AudioReceiveStream::AudioReceiveStream(
90 RtpStreamReceiverControllerInterface* receiver_controller,
91 PacketRouter* packet_router,
92 ProcessThread* module_process_thread,
93 const webrtc::AudioReceiveStream::Config& config,
94 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
95 webrtc::RtcEventLog* event_log)
96 : AudioReceiveStream(receiver_controller,
97 packet_router,
98 config,
99 audio_state,
100 event_log,
101 CreateChannelAndProxy(audio_state.get(),
102 module_process_thread,
Niels Möllerfa4e1852018-08-14 09:43:34 +0200103 config,
104 event_log)) {}
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100105
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200106AudioReceiveStream::AudioReceiveStream(
nisse0f15f922017-06-21 01:05:22 -0700107 RtpStreamReceiverControllerInterface* receiver_controller,
nisse0245da02016-11-30 03:35:20 -0800108 PacketRouter* packet_router,
solenberg566ef242015-11-06 15:34:49 -0800109 const webrtc::AudioReceiveStream::Config& config,
ivoc14d5dbe2016-07-04 07:06:55 -0700110 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100111 webrtc::RtcEventLog* event_log,
Niels Möllerb222f492018-10-03 16:50:08 +0200112 std::unique_ptr<voe::ChannelReceiveProxy> channel_proxy)
Yves Gerey665174f2018-06-19 15:03:05 +0200113 : audio_state_(audio_state), channel_proxy_(std::move(channel_proxy)) {
Jonas Olsson24ea8222018-01-25 10:14:29 +0100114 RTC_LOG(LS_INFO) << "AudioReceiveStream: " << config.rtp.remote_ssrc;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100115 RTC_DCHECK(config.decoder_factory);
Niels Möllerae4237e2018-10-05 11:28:38 +0200116 RTC_DCHECK(config.rtcp_send_transport);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100117 RTC_DCHECK(audio_state_);
118 RTC_DCHECK(channel_proxy_);
solenberg7add0582015-11-20 09:59:34 -0800119
solenberg3ebbcb52017-01-31 03:58:40 -0800120 module_process_thread_checker_.DetachFromThread();
121
Niels Möller7d76a312018-10-26 12:57:07 +0200122 if (!config.media_transport) {
123 RTC_DCHECK(receiver_controller);
124 RTC_DCHECK(packet_router);
125 // Configure bandwidth estimation.
126 channel_proxy_->RegisterReceiverCongestionControlObjects(packet_router);
nisse0f15f922017-06-21 01:05:22 -0700127
Niels Möller7d76a312018-10-26 12:57:07 +0200128 // Register with transport.
129 rtp_stream_receiver_ = receiver_controller->CreateReceiver(
130 config.rtp.remote_ssrc, channel_proxy_.get());
131 }
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100132 ConfigureStream(this, config, true);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200133}
134
pbosa2f30de2015-10-15 05:22:13 -0700135AudioReceiveStream::~AudioReceiveStream() {
solenberg3ebbcb52017-01-31 03:58:40 -0800136 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Jonas Olsson24ea8222018-01-25 10:14:29 +0100137 RTC_LOG(LS_INFO) << "~AudioReceiveStream: " << config_.rtp.remote_ssrc;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100138 Stop();
solenberg7602aab2016-11-14 11:30:07 -0800139 channel_proxy_->DisassociateSendChannel();
Niels Möller7d76a312018-10-26 12:57:07 +0200140 if (!config_.media_transport) {
141 channel_proxy_->ResetReceiverCongestionControlObjects();
142 }
pbosa2f30de2015-10-15 05:22:13 -0700143}
144
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100145void AudioReceiveStream::Reconfigure(
146 const webrtc::AudioReceiveStream::Config& config) {
147 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100148 ConfigureStream(this, config, false);
149}
150
solenberg7add0582015-11-20 09:59:34 -0800151void AudioReceiveStream::Start() {
solenberg3ebbcb52017-01-31 03:58:40 -0800152 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 06:42:53 -0800153 if (playing_) {
154 return;
155 }
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100156 channel_proxy_->StartPlayout();
aleloi04c07222016-11-22 06:42:53 -0800157 playing_ = true;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100158 audio_state()->AddReceivingStream(this);
solenberg7add0582015-11-20 09:59:34 -0800159}
160
161void AudioReceiveStream::Stop() {
solenberg3ebbcb52017-01-31 03:58:40 -0800162 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 06:42:53 -0800163 if (!playing_) {
164 return;
165 }
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100166 channel_proxy_->StopPlayout();
aleloi04c07222016-11-22 06:42:53 -0800167 playing_ = false;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100168 audio_state()->RemoveReceivingStream(this);
solenberg7add0582015-11-20 09:59:34 -0800169}
170
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200171webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
solenberg3ebbcb52017-01-31 03:58:40 -0800172 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200173 webrtc::AudioReceiveStream::Stats stats;
174 stats.remote_ssrc = config_.rtp.remote_ssrc;
solenberg8b85de22015-11-16 09:48:04 -0800175
Niels Möller530ead42018-10-04 14:28:39 +0200176 webrtc::CallReceiveStatistics call_stats =
177 channel_proxy_->GetRTCPStatistics();
solenbergbd9a77f2017-02-06 12:53:57 -0800178 // TODO(solenberg): Don't return here if we can't get the codec - return the
179 // stats we *can* get.
solenberg85a04962015-10-27 03:35:21 -0700180 webrtc::CodecInst codec_inst = {0};
solenbergbd9a77f2017-02-06 12:53:57 -0800181 if (!channel_proxy_->GetRecCodec(&codec_inst)) {
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200182 return stats;
183 }
184
solenberg85a04962015-10-27 03:35:21 -0700185 stats.bytes_rcvd = call_stats.bytesReceived;
186 stats.packets_rcvd = call_stats.packetsReceived;
187 stats.packets_lost = call_stats.cumulativeLost;
188 stats.fraction_lost = Q8ToFloat(call_stats.fractionLost);
solenberg8b85de22015-11-16 09:48:04 -0800189 stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
solenberg85a04962015-10-27 03:35:21 -0700190 if (codec_inst.pltype != -1) {
191 stats.codec_name = codec_inst.plname;
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100192 stats.codec_payload_type = codec_inst.pltype;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200193 }
solenberg85a04962015-10-27 03:35:21 -0700194 stats.ext_seqnum = call_stats.extendedMax;
195 if (codec_inst.plfreq / 1000 > 0) {
196 stats.jitter_ms = call_stats.jitterSamples / (codec_inst.plfreq / 1000);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200197 }
solenberg358057b2015-11-27 10:46:42 -0800198 stats.delay_estimate_ms = channel_proxy_->GetDelayEstimate();
199 stats.audio_level = channel_proxy_->GetSpeechOutputLevelFullRange();
zsteine76bd3a2017-07-14 12:17:49 -0700200 stats.total_output_energy = channel_proxy_->GetTotalOutputEnergy();
201 stats.total_output_duration = channel_proxy_->GetTotalOutputDuration();
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200202
solenberg8b85de22015-11-16 09:48:04 -0800203 // Get jitter buffer and total delay (alg + jitter + playout) stats.
solenberg358057b2015-11-27 10:46:42 -0800204 auto ns = channel_proxy_->GetNetworkStatistics();
solenberg8b85de22015-11-16 09:48:04 -0800205 stats.jitter_buffer_ms = ns.currentBufferSize;
206 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700207 stats.total_samples_received = ns.totalSamplesReceived;
208 stats.concealed_samples = ns.concealedSamples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200209 stats.concealment_events = ns.concealmentEvents;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200210 stats.jitter_buffer_delay_seconds =
211 static_cast<double>(ns.jitterBufferDelayMs) /
212 static_cast<double>(rtc::kNumMillisecsPerSec);
solenberg8b85de22015-11-16 09:48:04 -0800213 stats.expand_rate = Q14ToFloat(ns.currentExpandRate);
214 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate);
215 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate);
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200216 stats.secondary_discarded_rate = Q14ToFloat(ns.currentSecondaryDiscardedRate);
solenberg8b85de22015-11-16 09:48:04 -0800217 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate);
218 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200219
solenberg358057b2015-11-27 10:46:42 -0800220 auto ds = channel_proxy_->GetDecodingCallStatistics();
solenberg8b85de22015-11-16 09:48:04 -0800221 stats.decoding_calls_to_silence_generator = ds.calls_to_silence_generator;
222 stats.decoding_calls_to_neteq = ds.calls_to_neteq;
223 stats.decoding_normal = ds.decoded_normal;
224 stats.decoding_plc = ds.decoded_plc;
225 stats.decoding_cng = ds.decoded_cng;
226 stats.decoding_plc_cng = ds.decoded_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700227 stats.decoding_muted_output = ds.decoded_muted_output;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200228
229 return stats;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200230}
231
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100232void AudioReceiveStream::SetSink(AudioSinkInterface* sink) {
solenberg3ebbcb52017-01-31 03:58:40 -0800233 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100234 channel_proxy_->SetSink(sink);
Tommif888bb52015-12-12 01:37:01 +0100235}
236
solenberg217fb662016-06-17 08:30:54 -0700237void AudioReceiveStream::SetGain(float gain) {
solenberg3ebbcb52017-01-31 03:58:40 -0800238 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
solenberg217fb662016-06-17 08:30:54 -0700239 channel_proxy_->SetChannelOutputVolumeScaling(gain);
240}
241
hbos8d609f62017-04-10 07:39:05 -0700242std::vector<RtpSource> AudioReceiveStream::GetSources() const {
243 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
244 return channel_proxy_->GetSources();
245}
246
solenberg3ebbcb52017-01-31 03:58:40 -0800247AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo(
248 int sample_rate_hz,
249 AudioFrame* audio_frame) {
250 return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
251}
252
253int AudioReceiveStream::Ssrc() const {
254 return config_.rtp.remote_ssrc;
255}
256
257int AudioReceiveStream::PreferredSampleRate() const {
solenberg2397b9a2017-09-22 06:48:10 -0700258 return channel_proxy_->PreferredSampleRate();
solenberg3ebbcb52017-01-31 03:58:40 -0800259}
260
261int AudioReceiveStream::id() const {
262 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
263 return config_.rtp.remote_ssrc;
264}
265
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200266absl::optional<Syncable::Info> AudioReceiveStream::GetInfo() const {
solenberg3ebbcb52017-01-31 03:58:40 -0800267 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
Niels Möller848d6d32018-08-08 10:49:16 +0200268 absl::optional<Syncable::Info> info = channel_proxy_->GetSyncInfo();
solenberg3ebbcb52017-01-31 03:58:40 -0800269
Niels Möller848d6d32018-08-08 10:49:16 +0200270 if (!info)
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200271 return absl::nullopt;
solenberg3ebbcb52017-01-31 03:58:40 -0800272
Niels Möller848d6d32018-08-08 10:49:16 +0200273 info->current_delay_ms = channel_proxy_->GetDelayEstimate();
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100274 return info;
solenberg3ebbcb52017-01-31 03:58:40 -0800275}
276
277uint32_t AudioReceiveStream::GetPlayoutTimestamp() const {
278 // Called on video capture thread.
279 return channel_proxy_->GetPlayoutTimestamp();
280}
281
282void AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
283 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
284 return channel_proxy_->SetMinimumPlayoutDelay(delay_ms);
pbosa2f30de2015-10-15 05:22:13 -0700285}
286
solenberg7602aab2016-11-14 11:30:07 -0800287void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) {
solenberg3ebbcb52017-01-31 03:58:40 -0800288 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
solenberg7602aab2016-11-14 11:30:07 -0800289 if (send_stream) {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100290 channel_proxy_->AssociateSendChannel(send_stream->GetChannelProxy());
solenberg7602aab2016-11-14 11:30:07 -0800291 } else {
292 channel_proxy_->DisassociateSendChannel();
293 }
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100294 associated_send_stream_ = send_stream;
solenberg7602aab2016-11-14 11:30:07 -0800295}
296
pbos1ba8d392016-05-01 20:18:34 -0700297void AudioReceiveStream::SignalNetworkState(NetworkState state) {
solenberg3ebbcb52017-01-31 03:58:40 -0800298 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
pbos1ba8d392016-05-01 20:18:34 -0700299}
300
301bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
302 // TODO(solenberg): Tests call this function on a network thread, libjingle
303 // calls on the worker thread. We should move towards always using a network
304 // thread. Then this check can be enabled.
305 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
306 return channel_proxy_->ReceivedRTCPPacket(packet, length);
307}
308
nisse657bab22017-02-21 06:28:10 -0800309void AudioReceiveStream::OnRtpPacket(const RtpPacketReceived& packet) {
pbos1ba8d392016-05-01 20:18:34 -0700310 // TODO(solenberg): Tests call this function on a network thread, libjingle
311 // calls on the worker thread. We should move towards always using a network
312 // thread. Then this check can be enabled.
313 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
nisse657bab22017-02-21 06:28:10 -0800314 channel_proxy_->OnRtpPacket(packet);
pbos1ba8d392016-05-01 20:18:34 -0700315}
316
solenberg3ebbcb52017-01-31 03:58:40 -0800317const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const {
318 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
319 return config_;
aleloi04c07222016-11-22 06:42:53 -0800320}
321
Yves Gerey665174f2018-06-19 15:03:05 +0200322const AudioSendStream* AudioReceiveStream::GetAssociatedSendStreamForTesting()
323 const {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100324 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
325 return associated_send_stream_;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200326}
aleloi04c07222016-11-22 06:42:53 -0800327
solenberg3ebbcb52017-01-31 03:58:40 -0800328internal::AudioState* AudioReceiveStream::audio_state() const {
329 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get());
330 RTC_DCHECK(audio_state);
331 return audio_state;
332}
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100333
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100334void AudioReceiveStream::ConfigureStream(AudioReceiveStream* stream,
335 const Config& new_config,
336 bool first_time) {
Jonas Olsson24ea8222018-01-25 10:14:29 +0100337 RTC_LOG(LS_INFO) << "AudioReceiveStream::ConfigureStream: "
338 << new_config.ToString();
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100339 RTC_DCHECK(stream);
340 const auto& channel_proxy = stream->channel_proxy_;
341 const auto& old_config = stream->config_;
342
343 // Configuration parameters which cannot be changed.
344 RTC_DCHECK(first_time ||
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100345 old_config.rtp.remote_ssrc == new_config.rtp.remote_ssrc);
346 RTC_DCHECK(first_time ||
347 old_config.rtcp_send_transport == new_config.rtcp_send_transport);
348 // Decoder factory cannot be changed because it is configured at
349 // voe::Channel construction time.
350 RTC_DCHECK(first_time ||
351 old_config.decoder_factory == new_config.decoder_factory);
352
353 if (first_time || old_config.rtp.local_ssrc != new_config.rtp.local_ssrc) {
354 channel_proxy->SetLocalSSRC(new_config.rtp.local_ssrc);
355 }
Niels Möllerf7824922018-05-25 13:41:10 +0200356
Niels Möller30b48392018-08-15 15:05:26 +0200357 if (!first_time) {
Niels Möllerf7824922018-05-25 13:41:10 +0200358 // Remote ssrc can't be changed mid-stream.
359 RTC_DCHECK_EQ(old_config.rtp.remote_ssrc, new_config.rtp.remote_ssrc);
360 }
361
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100362 // TODO(solenberg): Config NACK history window (which is a packet count),
363 // using the actual packet size for the configured codec.
364 if (first_time || old_config.rtp.nack.rtp_history_ms !=
365 new_config.rtp.nack.rtp_history_ms) {
366 channel_proxy->SetNACKStatus(new_config.rtp.nack.rtp_history_ms != 0,
367 new_config.rtp.nack.rtp_history_ms / 20);
368 }
369 if (first_time || old_config.decoder_map != new_config.decoder_map) {
370 channel_proxy->SetReceiveCodecs(new_config.decoder_map);
371 }
372
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100373 stream->config_ = new_config;
374}
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200375} // namespace internal
376} // namespace webrtc