blob: 3be50fdfc5606c856fc72d5e169c29aefe59fa9a [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/call/audio_sink.h"
17#include "audio/audio_send_stream.h"
18#include "audio/audio_state.h"
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010019#include "audio/channel_proxy.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "audio/conversion.h"
21#include "call/rtp_stream_receiver_controller_interface.h"
22#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
23#include "modules/rtp_rtcp/include/rtp_receiver.h"
24#include "modules/rtp_rtcp/include/rtp_rtcp.h"
25#include "rtc_base/checks.h"
26#include "rtc_base/logging.h"
Tommifef05002018-02-27 13:51:08 +010027#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "rtc_base/timeutils.h"
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020029
30namespace webrtc {
Stefan Holmer3842c5c2016-01-12 13:55:00 +010031
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020032std::string AudioReceiveStream::Config::Rtp::ToString() const {
Karl Wiberg881f1682018-03-08 15:03:23 +010033 char ss_buf[1024];
34 rtc::SimpleStringBuilder ss(ss_buf);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020035 ss << "{remote_ssrc: " << remote_ssrc;
solenberg85a04962015-10-27 03:35:21 -070036 ss << ", local_ssrc: " << local_ssrc;
solenberg8189b022016-06-14 12:13:00 -070037 ss << ", transport_cc: " << (transport_cc ? "on" : "off");
38 ss << ", nack: " << nack.ToString();
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020039 ss << ", extensions: [";
40 for (size_t i = 0; i < extensions.size(); ++i) {
41 ss << extensions[i].ToString();
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020042 if (i != extensions.size() - 1) {
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020043 ss << ", ";
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020044 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020045 }
46 ss << ']';
47 ss << '}';
48 return ss.str();
49}
50
51std::string AudioReceiveStream::Config::ToString() const {
Karl Wiberg881f1682018-03-08 15:03:23 +010052 char ss_buf[1024];
53 rtc::SimpleStringBuilder ss(ss_buf);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020054 ss << "{rtp: " << rtp.ToString();
solenberg85a04962015-10-27 03:35:21 -070055 ss << ", rtcp_send_transport: "
deadbeef922246a2017-02-26 04:18:12 -080056 << (rtcp_send_transport ? "(Transport)" : "null");
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020057 if (!sync_group.empty()) {
pbos8fc7fa72015-07-15 08:02:58 -070058 ss << ", sync_group: " << sync_group;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020059 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020060 ss << '}';
61 return ss.str();
62}
63
64namespace internal {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010065namespace {
66std::unique_ptr<voe::ChannelProxy> CreateChannelAndProxy(
67 webrtc::AudioState* audio_state,
68 ProcessThread* module_process_thread,
Niels Möllerfa4e1852018-08-14 09:43:34 +020069 const webrtc::AudioReceiveStream::Config& config,
70 RtcEventLog* event_log) {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010071 RTC_DCHECK(audio_state);
72 internal::AudioState* internal_audio_state =
73 static_cast<internal::AudioState*>(audio_state);
Niels Möllerfa4e1852018-08-14 09:43:34 +020074 return absl::make_unique<voe::ChannelProxy>(absl::make_unique<voe::Channel>(
75 module_process_thread, internal_audio_state->audio_device_module(),
76 nullptr /* RtcpRttStats */, event_log, config.jitter_buffer_max_packets,
77 config.jitter_buffer_fast_accelerate, config.decoder_factory,
78 config.codec_pair_id));
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010079}
80} // namespace
81
82AudioReceiveStream::AudioReceiveStream(
83 RtpStreamReceiverControllerInterface* receiver_controller,
84 PacketRouter* packet_router,
85 ProcessThread* module_process_thread,
86 const webrtc::AudioReceiveStream::Config& config,
87 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
88 webrtc::RtcEventLog* event_log)
89 : AudioReceiveStream(receiver_controller,
90 packet_router,
91 config,
92 audio_state,
93 event_log,
94 CreateChannelAndProxy(audio_state.get(),
95 module_process_thread,
Niels Möllerfa4e1852018-08-14 09:43:34 +020096 config,
97 event_log)) {}
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010098
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020099AudioReceiveStream::AudioReceiveStream(
nisse0f15f922017-06-21 01:05:22 -0700100 RtpStreamReceiverControllerInterface* receiver_controller,
nisse0245da02016-11-30 03:35:20 -0800101 PacketRouter* packet_router,
solenberg566ef242015-11-06 15:34:49 -0800102 const webrtc::AudioReceiveStream::Config& config,
ivoc14d5dbe2016-07-04 07:06:55 -0700103 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100104 webrtc::RtcEventLog* event_log,
105 std::unique_ptr<voe::ChannelProxy> channel_proxy)
Yves Gerey665174f2018-06-19 15:03:05 +0200106 : audio_state_(audio_state), channel_proxy_(std::move(channel_proxy)) {
Jonas Olsson24ea8222018-01-25 10:14:29 +0100107 RTC_LOG(LS_INFO) << "AudioReceiveStream: " << config.rtp.remote_ssrc;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100108 RTC_DCHECK(receiver_controller);
nisse0245da02016-11-30 03:35:20 -0800109 RTC_DCHECK(packet_router);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100110 RTC_DCHECK(config.decoder_factory);
111 RTC_DCHECK(audio_state_);
112 RTC_DCHECK(channel_proxy_);
solenberg7add0582015-11-20 09:59:34 -0800113
solenberg3ebbcb52017-01-31 03:58:40 -0800114 module_process_thread_checker_.DetachFromThread();
115
solenberg1c239d42017-09-29 06:00:28 -0700116 channel_proxy_->RegisterTransport(config.rtcp_send_transport);
kwibergd32bf752017-01-19 07:03:59 -0800117
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100118 // Configure bandwidth estimation.
nisse0245da02016-11-30 03:35:20 -0800119 channel_proxy_->RegisterReceiverCongestionControlObjects(packet_router);
nisse0f15f922017-06-21 01:05:22 -0700120
121 // Register with transport.
Yves Gerey665174f2018-06-19 15:03:05 +0200122 rtp_stream_receiver_ = receiver_controller->CreateReceiver(
123 config.rtp.remote_ssrc, channel_proxy_.get());
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100124
125 ConfigureStream(this, config, true);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200126}
127
pbosa2f30de2015-10-15 05:22:13 -0700128AudioReceiveStream::~AudioReceiveStream() {
solenberg3ebbcb52017-01-31 03:58:40 -0800129 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Jonas Olsson24ea8222018-01-25 10:14:29 +0100130 RTC_LOG(LS_INFO) << "~AudioReceiveStream: " << config_.rtp.remote_ssrc;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100131 Stop();
solenberg7602aab2016-11-14 11:30:07 -0800132 channel_proxy_->DisassociateSendChannel();
solenberg1c239d42017-09-29 06:00:28 -0700133 channel_proxy_->RegisterTransport(nullptr);
nissefdbfdc92017-03-31 05:44:52 -0700134 channel_proxy_->ResetReceiverCongestionControlObjects();
pbosa2f30de2015-10-15 05:22:13 -0700135}
136
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100137void AudioReceiveStream::Reconfigure(
138 const webrtc::AudioReceiveStream::Config& config) {
139 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100140 ConfigureStream(this, config, false);
141}
142
solenberg7add0582015-11-20 09:59:34 -0800143void AudioReceiveStream::Start() {
solenberg3ebbcb52017-01-31 03:58:40 -0800144 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 06:42:53 -0800145 if (playing_) {
146 return;
147 }
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100148 channel_proxy_->StartPlayout();
aleloi04c07222016-11-22 06:42:53 -0800149 playing_ = true;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100150 audio_state()->AddReceivingStream(this);
solenberg7add0582015-11-20 09:59:34 -0800151}
152
153void AudioReceiveStream::Stop() {
solenberg3ebbcb52017-01-31 03:58:40 -0800154 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 06:42:53 -0800155 if (!playing_) {
156 return;
157 }
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100158 channel_proxy_->StopPlayout();
aleloi04c07222016-11-22 06:42:53 -0800159 playing_ = false;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100160 audio_state()->RemoveReceivingStream(this);
solenberg7add0582015-11-20 09:59:34 -0800161}
162
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200163webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
solenberg3ebbcb52017-01-31 03:58:40 -0800164 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200165 webrtc::AudioReceiveStream::Stats stats;
166 stats.remote_ssrc = config_.rtp.remote_ssrc;
solenberg8b85de22015-11-16 09:48:04 -0800167
solenberg358057b2015-11-27 10:46:42 -0800168 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics();
solenbergbd9a77f2017-02-06 12:53:57 -0800169 // TODO(solenberg): Don't return here if we can't get the codec - return the
170 // stats we *can* get.
solenberg85a04962015-10-27 03:35:21 -0700171 webrtc::CodecInst codec_inst = {0};
solenbergbd9a77f2017-02-06 12:53:57 -0800172 if (!channel_proxy_->GetRecCodec(&codec_inst)) {
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200173 return stats;
174 }
175
solenberg85a04962015-10-27 03:35:21 -0700176 stats.bytes_rcvd = call_stats.bytesReceived;
177 stats.packets_rcvd = call_stats.packetsReceived;
178 stats.packets_lost = call_stats.cumulativeLost;
179 stats.fraction_lost = Q8ToFloat(call_stats.fractionLost);
solenberg8b85de22015-11-16 09:48:04 -0800180 stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
solenberg85a04962015-10-27 03:35:21 -0700181 if (codec_inst.pltype != -1) {
182 stats.codec_name = codec_inst.plname;
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100183 stats.codec_payload_type = codec_inst.pltype;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200184 }
solenberg85a04962015-10-27 03:35:21 -0700185 stats.ext_seqnum = call_stats.extendedMax;
186 if (codec_inst.plfreq / 1000 > 0) {
187 stats.jitter_ms = call_stats.jitterSamples / (codec_inst.plfreq / 1000);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200188 }
solenberg358057b2015-11-27 10:46:42 -0800189 stats.delay_estimate_ms = channel_proxy_->GetDelayEstimate();
190 stats.audio_level = channel_proxy_->GetSpeechOutputLevelFullRange();
zsteine76bd3a2017-07-14 12:17:49 -0700191 stats.total_output_energy = channel_proxy_->GetTotalOutputEnergy();
192 stats.total_output_duration = channel_proxy_->GetTotalOutputDuration();
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200193
solenberg8b85de22015-11-16 09:48:04 -0800194 // Get jitter buffer and total delay (alg + jitter + playout) stats.
solenberg358057b2015-11-27 10:46:42 -0800195 auto ns = channel_proxy_->GetNetworkStatistics();
solenberg8b85de22015-11-16 09:48:04 -0800196 stats.jitter_buffer_ms = ns.currentBufferSize;
197 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700198 stats.total_samples_received = ns.totalSamplesReceived;
199 stats.concealed_samples = ns.concealedSamples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200200 stats.concealment_events = ns.concealmentEvents;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200201 stats.jitter_buffer_delay_seconds =
202 static_cast<double>(ns.jitterBufferDelayMs) /
203 static_cast<double>(rtc::kNumMillisecsPerSec);
solenberg8b85de22015-11-16 09:48:04 -0800204 stats.expand_rate = Q14ToFloat(ns.currentExpandRate);
205 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate);
206 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate);
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200207 stats.secondary_discarded_rate = Q14ToFloat(ns.currentSecondaryDiscardedRate);
solenberg8b85de22015-11-16 09:48:04 -0800208 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate);
209 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200210
solenberg358057b2015-11-27 10:46:42 -0800211 auto ds = channel_proxy_->GetDecodingCallStatistics();
solenberg8b85de22015-11-16 09:48:04 -0800212 stats.decoding_calls_to_silence_generator = ds.calls_to_silence_generator;
213 stats.decoding_calls_to_neteq = ds.calls_to_neteq;
214 stats.decoding_normal = ds.decoded_normal;
215 stats.decoding_plc = ds.decoded_plc;
216 stats.decoding_cng = ds.decoded_cng;
217 stats.decoding_plc_cng = ds.decoded_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700218 stats.decoding_muted_output = ds.decoded_muted_output;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200219
220 return stats;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200221}
222
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100223void AudioReceiveStream::SetSink(AudioSinkInterface* sink) {
solenberg3ebbcb52017-01-31 03:58:40 -0800224 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100225 channel_proxy_->SetSink(sink);
Tommif888bb52015-12-12 01:37:01 +0100226}
227
solenberg217fb662016-06-17 08:30:54 -0700228void AudioReceiveStream::SetGain(float gain) {
solenberg3ebbcb52017-01-31 03:58:40 -0800229 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
solenberg217fb662016-06-17 08:30:54 -0700230 channel_proxy_->SetChannelOutputVolumeScaling(gain);
231}
232
hbos8d609f62017-04-10 07:39:05 -0700233std::vector<RtpSource> AudioReceiveStream::GetSources() const {
234 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
235 return channel_proxy_->GetSources();
236}
237
solenberg3ebbcb52017-01-31 03:58:40 -0800238AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo(
239 int sample_rate_hz,
240 AudioFrame* audio_frame) {
241 return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
242}
243
244int AudioReceiveStream::Ssrc() const {
245 return config_.rtp.remote_ssrc;
246}
247
248int AudioReceiveStream::PreferredSampleRate() const {
solenberg2397b9a2017-09-22 06:48:10 -0700249 return channel_proxy_->PreferredSampleRate();
solenberg3ebbcb52017-01-31 03:58:40 -0800250}
251
252int AudioReceiveStream::id() const {
253 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
254 return config_.rtp.remote_ssrc;
255}
256
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200257absl::optional<Syncable::Info> AudioReceiveStream::GetInfo() const {
solenberg3ebbcb52017-01-31 03:58:40 -0800258 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
Niels Möller848d6d32018-08-08 10:49:16 +0200259 absl::optional<Syncable::Info> info = channel_proxy_->GetSyncInfo();
solenberg3ebbcb52017-01-31 03:58:40 -0800260
Niels Möller848d6d32018-08-08 10:49:16 +0200261 if (!info)
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200262 return absl::nullopt;
solenberg3ebbcb52017-01-31 03:58:40 -0800263
Niels Möller848d6d32018-08-08 10:49:16 +0200264 info->current_delay_ms = channel_proxy_->GetDelayEstimate();
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100265 return info;
solenberg3ebbcb52017-01-31 03:58:40 -0800266}
267
268uint32_t AudioReceiveStream::GetPlayoutTimestamp() const {
269 // Called on video capture thread.
270 return channel_proxy_->GetPlayoutTimestamp();
271}
272
273void AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
274 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
275 return channel_proxy_->SetMinimumPlayoutDelay(delay_ms);
pbosa2f30de2015-10-15 05:22:13 -0700276}
277
solenberg7602aab2016-11-14 11:30:07 -0800278void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) {
solenberg3ebbcb52017-01-31 03:58:40 -0800279 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
solenberg7602aab2016-11-14 11:30:07 -0800280 if (send_stream) {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100281 channel_proxy_->AssociateSendChannel(send_stream->GetChannelProxy());
solenberg7602aab2016-11-14 11:30:07 -0800282 } else {
283 channel_proxy_->DisassociateSendChannel();
284 }
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100285 associated_send_stream_ = send_stream;
solenberg7602aab2016-11-14 11:30:07 -0800286}
287
pbos1ba8d392016-05-01 20:18:34 -0700288void AudioReceiveStream::SignalNetworkState(NetworkState state) {
solenberg3ebbcb52017-01-31 03:58:40 -0800289 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
pbos1ba8d392016-05-01 20:18:34 -0700290}
291
292bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
293 // TODO(solenberg): Tests call this function on a network thread, libjingle
294 // calls on the worker thread. We should move towards always using a network
295 // thread. Then this check can be enabled.
296 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
297 return channel_proxy_->ReceivedRTCPPacket(packet, length);
298}
299
nisse657bab22017-02-21 06:28:10 -0800300void AudioReceiveStream::OnRtpPacket(const RtpPacketReceived& packet) {
pbos1ba8d392016-05-01 20:18:34 -0700301 // TODO(solenberg): Tests call this function on a network thread, libjingle
302 // calls on the worker thread. We should move towards always using a network
303 // thread. Then this check can be enabled.
304 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
nisse657bab22017-02-21 06:28:10 -0800305 channel_proxy_->OnRtpPacket(packet);
pbos1ba8d392016-05-01 20:18:34 -0700306}
307
solenberg3ebbcb52017-01-31 03:58:40 -0800308const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const {
309 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
310 return config_;
aleloi04c07222016-11-22 06:42:53 -0800311}
312
Yves Gerey665174f2018-06-19 15:03:05 +0200313const AudioSendStream* AudioReceiveStream::GetAssociatedSendStreamForTesting()
314 const {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100315 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
316 return associated_send_stream_;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200317}
aleloi04c07222016-11-22 06:42:53 -0800318
solenberg3ebbcb52017-01-31 03:58:40 -0800319internal::AudioState* AudioReceiveStream::audio_state() const {
320 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get());
321 RTC_DCHECK(audio_state);
322 return audio_state;
323}
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100324
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100325void AudioReceiveStream::ConfigureStream(AudioReceiveStream* stream,
326 const Config& new_config,
327 bool first_time) {
Jonas Olsson24ea8222018-01-25 10:14:29 +0100328 RTC_LOG(LS_INFO) << "AudioReceiveStream::ConfigureStream: "
329 << new_config.ToString();
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100330 RTC_DCHECK(stream);
331 const auto& channel_proxy = stream->channel_proxy_;
332 const auto& old_config = stream->config_;
333
334 // Configuration parameters which cannot be changed.
335 RTC_DCHECK(first_time ||
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100336 old_config.rtp.remote_ssrc == new_config.rtp.remote_ssrc);
337 RTC_DCHECK(first_time ||
338 old_config.rtcp_send_transport == new_config.rtcp_send_transport);
339 // Decoder factory cannot be changed because it is configured at
340 // voe::Channel construction time.
341 RTC_DCHECK(first_time ||
342 old_config.decoder_factory == new_config.decoder_factory);
343
344 if (first_time || old_config.rtp.local_ssrc != new_config.rtp.local_ssrc) {
345 channel_proxy->SetLocalSSRC(new_config.rtp.local_ssrc);
346 }
Niels Möllerf7824922018-05-25 13:41:10 +0200347
348 if (first_time) {
349 channel_proxy->SetRemoteSSRC(new_config.rtp.remote_ssrc);
350 } else {
351 // Remote ssrc can't be changed mid-stream.
352 RTC_DCHECK_EQ(old_config.rtp.remote_ssrc, new_config.rtp.remote_ssrc);
353 }
354
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100355 // TODO(solenberg): Config NACK history window (which is a packet count),
356 // using the actual packet size for the configured codec.
357 if (first_time || old_config.rtp.nack.rtp_history_ms !=
358 new_config.rtp.nack.rtp_history_ms) {
359 channel_proxy->SetNACKStatus(new_config.rtp.nack.rtp_history_ms != 0,
360 new_config.rtp.nack.rtp_history_ms / 20);
361 }
362 if (first_time || old_config.decoder_map != new_config.decoder_map) {
363 channel_proxy->SetReceiveCodecs(new_config.decoder_map);
364 }
365
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100366 stream->config_ = new_config;
367}
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200368} // namespace internal
369} // namespace webrtc