blob: c5e2b16c20b54cf5511c79ffe7c79f65759395ef [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"
27#include "rtc_base/timeutils.h"
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020028
29namespace webrtc {
Stefan Holmer3842c5c2016-01-12 13:55:00 +010030
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020031std::string AudioReceiveStream::Config::Rtp::ToString() const {
32 std::stringstream ss;
33 ss << "{remote_ssrc: " << remote_ssrc;
solenberg85a04962015-10-27 03:35:21 -070034 ss << ", local_ssrc: " << local_ssrc;
solenberg8189b022016-06-14 12:13:00 -070035 ss << ", transport_cc: " << (transport_cc ? "on" : "off");
36 ss << ", nack: " << nack.ToString();
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020037 ss << ", extensions: [";
38 for (size_t i = 0; i < extensions.size(); ++i) {
39 ss << extensions[i].ToString();
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020040 if (i != extensions.size() - 1) {
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020041 ss << ", ";
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020042 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020043 }
44 ss << ']';
45 ss << '}';
46 return ss.str();
47}
48
49std::string AudioReceiveStream::Config::ToString() const {
50 std::stringstream ss;
51 ss << "{rtp: " << rtp.ToString();
solenberg85a04962015-10-27 03:35:21 -070052 ss << ", rtcp_send_transport: "
deadbeef922246a2017-02-26 04:18:12 -080053 << (rtcp_send_transport ? "(Transport)" : "null");
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020054 if (!sync_group.empty()) {
pbos8fc7fa72015-07-15 08:02:58 -070055 ss << ", sync_group: " << sync_group;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020056 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020057 ss << '}';
58 return ss.str();
59}
60
61namespace internal {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010062namespace {
63std::unique_ptr<voe::ChannelProxy> CreateChannelAndProxy(
64 webrtc::AudioState* audio_state,
65 ProcessThread* module_process_thread,
66 const webrtc::AudioReceiveStream::Config& config) {
67 RTC_DCHECK(audio_state);
68 internal::AudioState* internal_audio_state =
69 static_cast<internal::AudioState*>(audio_state);
70 return std::unique_ptr<voe::ChannelProxy>(new voe::ChannelProxy(
71 std::unique_ptr<voe::Channel>(new voe::Channel(
72 module_process_thread,
73 internal_audio_state->audio_device_module(),
74 config.jitter_buffer_max_packets,
75 config.jitter_buffer_fast_accelerate,
76 config.decoder_factory))));
77}
78} // namespace
79
80AudioReceiveStream::AudioReceiveStream(
81 RtpStreamReceiverControllerInterface* receiver_controller,
82 PacketRouter* packet_router,
83 ProcessThread* module_process_thread,
84 const webrtc::AudioReceiveStream::Config& config,
85 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
86 webrtc::RtcEventLog* event_log)
87 : AudioReceiveStream(receiver_controller,
88 packet_router,
89 config,
90 audio_state,
91 event_log,
92 CreateChannelAndProxy(audio_state.get(),
93 module_process_thread,
94 config)) {}
95
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020096AudioReceiveStream::AudioReceiveStream(
nisse0f15f922017-06-21 01:05:22 -070097 RtpStreamReceiverControllerInterface* receiver_controller,
nisse0245da02016-11-30 03:35:20 -080098 PacketRouter* packet_router,
solenberg566ef242015-11-06 15:34:49 -080099 const webrtc::AudioReceiveStream::Config& config,
ivoc14d5dbe2016-07-04 07:06:55 -0700100 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100101 webrtc::RtcEventLog* event_log,
102 std::unique_ptr<voe::ChannelProxy> channel_proxy)
103 : audio_state_(audio_state),
104 channel_proxy_(std::move(channel_proxy)) {
Jonas Olsson24ea8222018-01-25 10:14:29 +0100105 RTC_LOG(LS_INFO) << "AudioReceiveStream: " << config.rtp.remote_ssrc;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100106 RTC_DCHECK(receiver_controller);
nisse0245da02016-11-30 03:35:20 -0800107 RTC_DCHECK(packet_router);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100108 RTC_DCHECK(config.decoder_factory);
109 RTC_DCHECK(audio_state_);
110 RTC_DCHECK(channel_proxy_);
solenberg7add0582015-11-20 09:59:34 -0800111
solenberg3ebbcb52017-01-31 03:58:40 -0800112 module_process_thread_checker_.DetachFromThread();
113
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100114 channel_proxy_->SetRtcEventLog(event_log);
solenberg1c239d42017-09-29 06:00:28 -0700115 channel_proxy_->RegisterTransport(config.rtcp_send_transport);
kwibergd32bf752017-01-19 07:03:59 -0800116
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100117 // Configure bandwidth estimation.
nisse0245da02016-11-30 03:35:20 -0800118 channel_proxy_->RegisterReceiverCongestionControlObjects(packet_router);
nisse0f15f922017-06-21 01:05:22 -0700119
120 // Register with transport.
121 rtp_stream_receiver_ =
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100122 receiver_controller->CreateReceiver(config.rtp.remote_ssrc,
nisse0f15f922017-06-21 01:05:22 -0700123 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();
ivoc14d5dbe2016-07-04 07:06:55 -0700135 channel_proxy_->SetRtcEventLog(nullptr);
pbosa2f30de2015-10-15 05:22:13 -0700136}
137
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100138void AudioReceiveStream::Reconfigure(
139 const webrtc::AudioReceiveStream::Config& config) {
140 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100141 ConfigureStream(this, config, false);
142}
143
solenberg7add0582015-11-20 09:59:34 -0800144void AudioReceiveStream::Start() {
solenberg3ebbcb52017-01-31 03:58:40 -0800145 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 06:42:53 -0800146 if (playing_) {
147 return;
148 }
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100149 channel_proxy_->StartPlayout();
aleloi04c07222016-11-22 06:42:53 -0800150 playing_ = true;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100151 audio_state()->AddReceivingStream(this);
solenberg7add0582015-11-20 09:59:34 -0800152}
153
154void AudioReceiveStream::Stop() {
solenberg3ebbcb52017-01-31 03:58:40 -0800155 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 06:42:53 -0800156 if (!playing_) {
157 return;
158 }
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100159 channel_proxy_->StopPlayout();
aleloi04c07222016-11-22 06:42:53 -0800160 playing_ = false;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100161 audio_state()->RemoveReceivingStream(this);
solenberg7add0582015-11-20 09:59:34 -0800162}
163
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200164webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
solenberg3ebbcb52017-01-31 03:58:40 -0800165 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200166 webrtc::AudioReceiveStream::Stats stats;
167 stats.remote_ssrc = config_.rtp.remote_ssrc;
solenberg8b85de22015-11-16 09:48:04 -0800168
solenberg358057b2015-11-27 10:46:42 -0800169 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics();
solenbergbd9a77f2017-02-06 12:53:57 -0800170 // TODO(solenberg): Don't return here if we can't get the codec - return the
171 // stats we *can* get.
solenberg85a04962015-10-27 03:35:21 -0700172 webrtc::CodecInst codec_inst = {0};
solenbergbd9a77f2017-02-06 12:53:57 -0800173 if (!channel_proxy_->GetRecCodec(&codec_inst)) {
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200174 return stats;
175 }
176
solenberg85a04962015-10-27 03:35:21 -0700177 stats.bytes_rcvd = call_stats.bytesReceived;
178 stats.packets_rcvd = call_stats.packetsReceived;
179 stats.packets_lost = call_stats.cumulativeLost;
180 stats.fraction_lost = Q8ToFloat(call_stats.fractionLost);
solenberg8b85de22015-11-16 09:48:04 -0800181 stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
solenberg85a04962015-10-27 03:35:21 -0700182 if (codec_inst.pltype != -1) {
183 stats.codec_name = codec_inst.plname;
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100184 stats.codec_payload_type = codec_inst.pltype;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200185 }
solenberg85a04962015-10-27 03:35:21 -0700186 stats.ext_seqnum = call_stats.extendedMax;
187 if (codec_inst.plfreq / 1000 > 0) {
188 stats.jitter_ms = call_stats.jitterSamples / (codec_inst.plfreq / 1000);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200189 }
solenberg358057b2015-11-27 10:46:42 -0800190 stats.delay_estimate_ms = channel_proxy_->GetDelayEstimate();
191 stats.audio_level = channel_proxy_->GetSpeechOutputLevelFullRange();
zsteine76bd3a2017-07-14 12:17:49 -0700192 stats.total_output_energy = channel_proxy_->GetTotalOutputEnergy();
193 stats.total_output_duration = channel_proxy_->GetTotalOutputDuration();
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200194
solenberg8b85de22015-11-16 09:48:04 -0800195 // Get jitter buffer and total delay (alg + jitter + playout) stats.
solenberg358057b2015-11-27 10:46:42 -0800196 auto ns = channel_proxy_->GetNetworkStatistics();
solenberg8b85de22015-11-16 09:48:04 -0800197 stats.jitter_buffer_ms = ns.currentBufferSize;
198 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700199 stats.total_samples_received = ns.totalSamplesReceived;
200 stats.concealed_samples = ns.concealedSamples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200201 stats.concealment_events = ns.concealmentEvents;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200202 stats.jitter_buffer_delay_seconds =
203 static_cast<double>(ns.jitterBufferDelayMs) /
204 static_cast<double>(rtc::kNumMillisecsPerSec);
solenberg8b85de22015-11-16 09:48:04 -0800205 stats.expand_rate = Q14ToFloat(ns.currentExpandRate);
206 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate);
207 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate);
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200208 stats.secondary_discarded_rate = Q14ToFloat(ns.currentSecondaryDiscardedRate);
solenberg8b85de22015-11-16 09:48:04 -0800209 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate);
210 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200211
solenberg358057b2015-11-27 10:46:42 -0800212 auto ds = channel_proxy_->GetDecodingCallStatistics();
solenberg8b85de22015-11-16 09:48:04 -0800213 stats.decoding_calls_to_silence_generator = ds.calls_to_silence_generator;
214 stats.decoding_calls_to_neteq = ds.calls_to_neteq;
215 stats.decoding_normal = ds.decoded_normal;
216 stats.decoding_plc = ds.decoded_plc;
217 stats.decoding_cng = ds.decoded_cng;
218 stats.decoding_plc_cng = ds.decoded_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700219 stats.decoding_muted_output = ds.decoded_muted_output;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200220
221 return stats;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200222}
223
solenberg796b8f92017-03-01 17:02:23 -0800224int AudioReceiveStream::GetOutputLevel() const {
225 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
226 return channel_proxy_->GetSpeechOutputLevel();
227}
228
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100229void AudioReceiveStream::SetSink(AudioSinkInterface* sink) {
solenberg3ebbcb52017-01-31 03:58:40 -0800230 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100231 channel_proxy_->SetSink(sink);
Tommif888bb52015-12-12 01:37:01 +0100232}
233
solenberg217fb662016-06-17 08:30:54 -0700234void AudioReceiveStream::SetGain(float gain) {
solenberg3ebbcb52017-01-31 03:58:40 -0800235 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
solenberg217fb662016-06-17 08:30:54 -0700236 channel_proxy_->SetChannelOutputVolumeScaling(gain);
237}
238
hbos8d609f62017-04-10 07:39:05 -0700239std::vector<RtpSource> AudioReceiveStream::GetSources() const {
240 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
241 return channel_proxy_->GetSources();
242}
243
solenberg3ebbcb52017-01-31 03:58:40 -0800244AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo(
245 int sample_rate_hz,
246 AudioFrame* audio_frame) {
247 return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
248}
249
250int AudioReceiveStream::Ssrc() const {
251 return config_.rtp.remote_ssrc;
252}
253
254int AudioReceiveStream::PreferredSampleRate() const {
solenberg2397b9a2017-09-22 06:48:10 -0700255 return channel_proxy_->PreferredSampleRate();
solenberg3ebbcb52017-01-31 03:58:40 -0800256}
257
258int AudioReceiveStream::id() const {
259 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
260 return config_.rtp.remote_ssrc;
261}
262
263rtc::Optional<Syncable::Info> AudioReceiveStream::GetInfo() const {
264 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
265 Syncable::Info info;
266
267 RtpRtcp* rtp_rtcp = nullptr;
268 RtpReceiver* rtp_receiver = nullptr;
269 channel_proxy_->GetRtpRtcp(&rtp_rtcp, &rtp_receiver);
270 RTC_DCHECK(rtp_rtcp);
271 RTC_DCHECK(rtp_receiver);
272
Niels Möllerc3fa8e12017-10-03 15:28:26 +0200273 if (!rtp_receiver->GetLatestTimestamps(
274 &info.latest_received_capture_timestamp,
275 &info.latest_receive_time_ms)) {
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100276 return rtc::nullopt;
solenberg3ebbcb52017-01-31 03:58:40 -0800277 }
278 if (rtp_rtcp->RemoteNTP(&info.capture_time_ntp_secs,
279 &info.capture_time_ntp_frac,
280 nullptr,
281 nullptr,
282 &info.capture_time_source_clock) != 0) {
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100283 return rtc::nullopt;
solenberg3ebbcb52017-01-31 03:58:40 -0800284 }
285
solenberg08b19df2017-02-15 00:42:31 -0800286 info.current_delay_ms = channel_proxy_->GetDelayEstimate();
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100287 return info;
solenberg3ebbcb52017-01-31 03:58:40 -0800288}
289
290uint32_t AudioReceiveStream::GetPlayoutTimestamp() const {
291 // Called on video capture thread.
292 return channel_proxy_->GetPlayoutTimestamp();
293}
294
295void AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
296 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
297 return channel_proxy_->SetMinimumPlayoutDelay(delay_ms);
pbosa2f30de2015-10-15 05:22:13 -0700298}
299
solenberg7602aab2016-11-14 11:30:07 -0800300void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) {
solenberg3ebbcb52017-01-31 03:58:40 -0800301 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
solenberg7602aab2016-11-14 11:30:07 -0800302 if (send_stream) {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100303 channel_proxy_->AssociateSendChannel(send_stream->GetChannelProxy());
solenberg7602aab2016-11-14 11:30:07 -0800304 } else {
305 channel_proxy_->DisassociateSendChannel();
306 }
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100307 associated_send_stream_ = send_stream;
solenberg7602aab2016-11-14 11:30:07 -0800308}
309
pbos1ba8d392016-05-01 20:18:34 -0700310void AudioReceiveStream::SignalNetworkState(NetworkState state) {
solenberg3ebbcb52017-01-31 03:58:40 -0800311 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
pbos1ba8d392016-05-01 20:18:34 -0700312}
313
314bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
315 // TODO(solenberg): Tests call this function on a network thread, libjingle
316 // calls on the worker thread. We should move towards always using a network
317 // thread. Then this check can be enabled.
318 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
319 return channel_proxy_->ReceivedRTCPPacket(packet, length);
320}
321
nisse657bab22017-02-21 06:28:10 -0800322void AudioReceiveStream::OnRtpPacket(const RtpPacketReceived& packet) {
pbos1ba8d392016-05-01 20:18:34 -0700323 // TODO(solenberg): Tests call this function on a network thread, libjingle
324 // calls on the worker thread. We should move towards always using a network
325 // thread. Then this check can be enabled.
326 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
nisse657bab22017-02-21 06:28:10 -0800327 channel_proxy_->OnRtpPacket(packet);
pbos1ba8d392016-05-01 20:18:34 -0700328}
329
solenberg3ebbcb52017-01-31 03:58:40 -0800330const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const {
331 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
332 return config_;
aleloi04c07222016-11-22 06:42:53 -0800333}
334
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100335const AudioSendStream*
336 AudioReceiveStream::GetAssociatedSendStreamForTesting() const {
337 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
338 return associated_send_stream_;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200339}
aleloi04c07222016-11-22 06:42:53 -0800340
solenberg3ebbcb52017-01-31 03:58:40 -0800341internal::AudioState* AudioReceiveStream::audio_state() const {
342 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get());
343 RTC_DCHECK(audio_state);
344 return audio_state;
345}
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100346
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100347void AudioReceiveStream::ConfigureStream(AudioReceiveStream* stream,
348 const Config& new_config,
349 bool first_time) {
Jonas Olsson24ea8222018-01-25 10:14:29 +0100350 RTC_LOG(LS_INFO) << "AudioReceiveStream::ConfigureStream: "
351 << new_config.ToString();
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100352 RTC_DCHECK(stream);
353 const auto& channel_proxy = stream->channel_proxy_;
354 const auto& old_config = stream->config_;
355
356 // Configuration parameters which cannot be changed.
357 RTC_DCHECK(first_time ||
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100358 old_config.rtp.remote_ssrc == new_config.rtp.remote_ssrc);
359 RTC_DCHECK(first_time ||
360 old_config.rtcp_send_transport == new_config.rtcp_send_transport);
361 // Decoder factory cannot be changed because it is configured at
362 // voe::Channel construction time.
363 RTC_DCHECK(first_time ||
364 old_config.decoder_factory == new_config.decoder_factory);
365
366 if (first_time || old_config.rtp.local_ssrc != new_config.rtp.local_ssrc) {
367 channel_proxy->SetLocalSSRC(new_config.rtp.local_ssrc);
368 }
369 // TODO(solenberg): Config NACK history window (which is a packet count),
370 // using the actual packet size for the configured codec.
371 if (first_time || old_config.rtp.nack.rtp_history_ms !=
372 new_config.rtp.nack.rtp_history_ms) {
373 channel_proxy->SetNACKStatus(new_config.rtp.nack.rtp_history_ms != 0,
374 new_config.rtp.nack.rtp_history_ms / 20);
375 }
376 if (first_time || old_config.decoder_map != new_config.decoder_map) {
377 channel_proxy->SetReceiveCodecs(new_config.decoder_map);
378 }
379
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100380 stream->config_ = new_config;
381}
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200382} // namespace internal
383} // namespace webrtc