blob: 143c6f77f1c63d057f3e1b1e97be9f87f9ce6ddb [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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "audio/conversion.h"
Yves Gerey988cc082018-10-23 12:03:01 +020025#include "call/rtp_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "call/rtp_stream_receiver_controller_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "rtc_base/checks.h"
28#include "rtc_base/logging.h"
Tommifef05002018-02-27 13:51:08 +010029#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "rtc_base/timeutils.h"
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020031
32namespace webrtc {
Stefan Holmer3842c5c2016-01-12 13:55:00 +010033
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020034std::string AudioReceiveStream::Config::Rtp::ToString() const {
Karl Wiberg881f1682018-03-08 15:03:23 +010035 char ss_buf[1024];
36 rtc::SimpleStringBuilder ss(ss_buf);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020037 ss << "{remote_ssrc: " << remote_ssrc;
solenberg85a04962015-10-27 03:35:21 -070038 ss << ", local_ssrc: " << local_ssrc;
solenberg8189b022016-06-14 12:13:00 -070039 ss << ", transport_cc: " << (transport_cc ? "on" : "off");
40 ss << ", nack: " << nack.ToString();
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020041 ss << ", extensions: [";
42 for (size_t i = 0; i < extensions.size(); ++i) {
43 ss << extensions[i].ToString();
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020044 if (i != extensions.size() - 1) {
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020045 ss << ", ";
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020046 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020047 }
48 ss << ']';
49 ss << '}';
50 return ss.str();
51}
52
53std::string AudioReceiveStream::Config::ToString() const {
Karl Wiberg881f1682018-03-08 15:03:23 +010054 char ss_buf[1024];
55 rtc::SimpleStringBuilder ss(ss_buf);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020056 ss << "{rtp: " << rtp.ToString();
solenberg85a04962015-10-27 03:35:21 -070057 ss << ", rtcp_send_transport: "
deadbeef922246a2017-02-26 04:18:12 -080058 << (rtcp_send_transport ? "(Transport)" : "null");
Niels Möller7d76a312018-10-26 12:57:07 +020059 ss << ", media_transport: " << (media_transport ? "(Transport)" : "null");
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020060 if (!sync_group.empty()) {
pbos8fc7fa72015-07-15 08:02:58 -070061 ss << ", sync_group: " << sync_group;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020062 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020063 ss << '}';
64 return ss.str();
65}
66
67namespace internal {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010068namespace {
Niels Möller349ade32018-11-16 09:50:42 +010069std::unique_ptr<voe::ChannelReceiveInterface> CreateChannelReceive(
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010070 webrtc::AudioState* audio_state,
71 ProcessThread* module_process_thread,
Niels Möllerfa4e1852018-08-14 09:43:34 +020072 const webrtc::AudioReceiveStream::Config& config,
73 RtcEventLog* event_log) {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010074 RTC_DCHECK(audio_state);
75 internal::AudioState* internal_audio_state =
76 static_cast<internal::AudioState*>(audio_state);
Niels Möller349ade32018-11-16 09:50:42 +010077 return voe::CreateChannelReceive(
78 module_process_thread, internal_audio_state->audio_device_module(),
79 config.media_transport, config.rtcp_send_transport, event_log,
80 config.rtp.remote_ssrc, config.jitter_buffer_max_packets,
Jakob Ivarsson10403ae2018-11-27 15:45:20 +010081 config.jitter_buffer_fast_accelerate, config.jitter_buffer_min_delay_ms,
82 config.decoder_factory, config.codec_pair_id, config.frame_decryptor,
83 config.crypto_options);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010084}
85} // namespace
86
87AudioReceiveStream::AudioReceiveStream(
88 RtpStreamReceiverControllerInterface* receiver_controller,
89 PacketRouter* packet_router,
90 ProcessThread* module_process_thread,
91 const webrtc::AudioReceiveStream::Config& config,
92 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
93 webrtc::RtcEventLog* event_log)
94 : AudioReceiveStream(receiver_controller,
95 packet_router,
96 config,
97 audio_state,
98 event_log,
Niels Möller349ade32018-11-16 09:50:42 +010099 CreateChannelReceive(audio_state.get(),
100 module_process_thread,
101 config,
102 event_log)) {}
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100103
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200104AudioReceiveStream::AudioReceiveStream(
nisse0f15f922017-06-21 01:05:22 -0700105 RtpStreamReceiverControllerInterface* receiver_controller,
nisse0245da02016-11-30 03:35:20 -0800106 PacketRouter* packet_router,
solenberg566ef242015-11-06 15:34:49 -0800107 const webrtc::AudioReceiveStream::Config& config,
ivoc14d5dbe2016-07-04 07:06:55 -0700108 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100109 webrtc::RtcEventLog* event_log,
Niels Möller349ade32018-11-16 09:50:42 +0100110 std::unique_ptr<voe::ChannelReceiveInterface> channel_receive)
111 : audio_state_(audio_state), channel_receive_(std::move(channel_receive)) {
Jonas Olsson24ea8222018-01-25 10:14:29 +0100112 RTC_LOG(LS_INFO) << "AudioReceiveStream: " << config.rtp.remote_ssrc;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100113 RTC_DCHECK(config.decoder_factory);
Niels Möllerae4237e2018-10-05 11:28:38 +0200114 RTC_DCHECK(config.rtcp_send_transport);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100115 RTC_DCHECK(audio_state_);
Niels Möller349ade32018-11-16 09:50:42 +0100116 RTC_DCHECK(channel_receive_);
solenberg7add0582015-11-20 09:59:34 -0800117
solenberg3ebbcb52017-01-31 03:58:40 -0800118 module_process_thread_checker_.DetachFromThread();
119
Niels Möller7d76a312018-10-26 12:57:07 +0200120 if (!config.media_transport) {
121 RTC_DCHECK(receiver_controller);
122 RTC_DCHECK(packet_router);
123 // Configure bandwidth estimation.
Niels Möller349ade32018-11-16 09:50:42 +0100124 channel_receive_->RegisterReceiverCongestionControlObjects(packet_router);
nisse0f15f922017-06-21 01:05:22 -0700125
Niels Möller7d76a312018-10-26 12:57:07 +0200126 // Register with transport.
127 rtp_stream_receiver_ = receiver_controller->CreateReceiver(
Niels Möller349ade32018-11-16 09:50:42 +0100128 config.rtp.remote_ssrc, channel_receive_.get());
Niels Möller7d76a312018-10-26 12:57:07 +0200129 }
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100130 ConfigureStream(this, config, true);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200131}
132
pbosa2f30de2015-10-15 05:22:13 -0700133AudioReceiveStream::~AudioReceiveStream() {
solenberg3ebbcb52017-01-31 03:58:40 -0800134 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Jonas Olsson24ea8222018-01-25 10:14:29 +0100135 RTC_LOG(LS_INFO) << "~AudioReceiveStream: " << config_.rtp.remote_ssrc;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100136 Stop();
Niels Möller349ade32018-11-16 09:50:42 +0100137 channel_receive_->SetAssociatedSendChannel(nullptr);
Niels Möller7d76a312018-10-26 12:57:07 +0200138 if (!config_.media_transport) {
Niels Möller349ade32018-11-16 09:50:42 +0100139 channel_receive_->ResetReceiverCongestionControlObjects();
Niels Möller7d76a312018-10-26 12:57:07 +0200140 }
pbosa2f30de2015-10-15 05:22:13 -0700141}
142
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100143void AudioReceiveStream::Reconfigure(
144 const webrtc::AudioReceiveStream::Config& config) {
145 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100146 ConfigureStream(this, config, false);
147}
148
solenberg7add0582015-11-20 09:59:34 -0800149void AudioReceiveStream::Start() {
solenberg3ebbcb52017-01-31 03:58:40 -0800150 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 06:42:53 -0800151 if (playing_) {
152 return;
153 }
Niels Möller349ade32018-11-16 09:50:42 +0100154 channel_receive_->StartPlayout();
aleloi04c07222016-11-22 06:42:53 -0800155 playing_ = true;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100156 audio_state()->AddReceivingStream(this);
solenberg7add0582015-11-20 09:59:34 -0800157}
158
159void AudioReceiveStream::Stop() {
solenberg3ebbcb52017-01-31 03:58:40 -0800160 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 06:42:53 -0800161 if (!playing_) {
162 return;
163 }
Niels Möller349ade32018-11-16 09:50:42 +0100164 channel_receive_->StopPlayout();
aleloi04c07222016-11-22 06:42:53 -0800165 playing_ = false;
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100166 audio_state()->RemoveReceivingStream(this);
solenberg7add0582015-11-20 09:59:34 -0800167}
168
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200169webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
solenberg3ebbcb52017-01-31 03:58:40 -0800170 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200171 webrtc::AudioReceiveStream::Stats stats;
172 stats.remote_ssrc = config_.rtp.remote_ssrc;
solenberg8b85de22015-11-16 09:48:04 -0800173
Niels Möller530ead42018-10-04 14:28:39 +0200174 webrtc::CallReceiveStatistics call_stats =
Niels Möller349ade32018-11-16 09:50:42 +0100175 channel_receive_->GetRTCPStatistics();
solenbergbd9a77f2017-02-06 12:53:57 -0800176 // TODO(solenberg): Don't return here if we can't get the codec - return the
177 // stats we *can* get.
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100178 auto receive_codec = channel_receive_->GetReceiveCodec();
179 if (!receive_codec) {
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200180 return stats;
181 }
182
solenberg85a04962015-10-27 03:35:21 -0700183 stats.bytes_rcvd = call_stats.bytesReceived;
184 stats.packets_rcvd = call_stats.packetsReceived;
185 stats.packets_lost = call_stats.cumulativeLost;
186 stats.fraction_lost = Q8ToFloat(call_stats.fractionLost);
solenberg8b85de22015-11-16 09:48:04 -0800187 stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100188 stats.codec_name = receive_codec->second.name;
189 stats.codec_payload_type = receive_codec->first;
solenberg85a04962015-10-27 03:35:21 -0700190 stats.ext_seqnum = call_stats.extendedMax;
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100191 int clockrate_khz = receive_codec->second.clockrate_hz / 1000;
192 if (clockrate_khz > 0) {
193 stats.jitter_ms = call_stats.jitterSamples / clockrate_khz;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200194 }
Niels Möller349ade32018-11-16 09:50:42 +0100195 stats.delay_estimate_ms = channel_receive_->GetDelayEstimate();
196 stats.audio_level = channel_receive_->GetSpeechOutputLevelFullRange();
197 stats.total_output_energy = channel_receive_->GetTotalOutputEnergy();
198 stats.total_output_duration = channel_receive_->GetTotalOutputDuration();
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200199
solenberg8b85de22015-11-16 09:48:04 -0800200 // Get jitter buffer and total delay (alg + jitter + playout) stats.
Niels Möller349ade32018-11-16 09:50:42 +0100201 auto ns = channel_receive_->GetNetworkStatistics();
solenberg8b85de22015-11-16 09:48:04 -0800202 stats.jitter_buffer_ms = ns.currentBufferSize;
203 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700204 stats.total_samples_received = ns.totalSamplesReceived;
205 stats.concealed_samples = ns.concealedSamples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200206 stats.concealment_events = ns.concealmentEvents;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200207 stats.jitter_buffer_delay_seconds =
208 static_cast<double>(ns.jitterBufferDelayMs) /
209 static_cast<double>(rtc::kNumMillisecsPerSec);
solenberg8b85de22015-11-16 09:48:04 -0800210 stats.expand_rate = Q14ToFloat(ns.currentExpandRate);
211 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate);
212 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate);
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200213 stats.secondary_discarded_rate = Q14ToFloat(ns.currentSecondaryDiscardedRate);
solenberg8b85de22015-11-16 09:48:04 -0800214 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate);
215 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate);
Ruslan Burakov8af88962018-11-22 17:21:10 +0100216 stats.jitter_buffer_flushes = ns.packetBufferFlushes;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100217 stats.delayed_packet_outage_samples = ns.delayedPacketOutageSamples;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200218
Niels Möller349ade32018-11-16 09:50:42 +0100219 auto ds = channel_receive_->GetDecodingCallStatistics();
solenberg8b85de22015-11-16 09:48:04 -0800220 stats.decoding_calls_to_silence_generator = ds.calls_to_silence_generator;
221 stats.decoding_calls_to_neteq = ds.calls_to_neteq;
222 stats.decoding_normal = ds.decoded_normal;
223 stats.decoding_plc = ds.decoded_plc;
224 stats.decoding_cng = ds.decoded_cng;
225 stats.decoding_plc_cng = ds.decoded_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700226 stats.decoding_muted_output = ds.decoded_muted_output;
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200227
228 return stats;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200229}
230
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100231void AudioReceiveStream::SetSink(AudioSinkInterface* sink) {
solenberg3ebbcb52017-01-31 03:58:40 -0800232 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Niels Möller349ade32018-11-16 09:50:42 +0100233 channel_receive_->SetSink(sink);
Tommif888bb52015-12-12 01:37:01 +0100234}
235
solenberg217fb662016-06-17 08:30:54 -0700236void AudioReceiveStream::SetGain(float gain) {
solenberg3ebbcb52017-01-31 03:58:40 -0800237 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Niels Möller349ade32018-11-16 09:50:42 +0100238 channel_receive_->SetChannelOutputVolumeScaling(gain);
solenberg217fb662016-06-17 08:30:54 -0700239}
240
hbos8d609f62017-04-10 07:39:05 -0700241std::vector<RtpSource> AudioReceiveStream::GetSources() const {
242 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Niels Möller349ade32018-11-16 09:50:42 +0100243 return channel_receive_->GetSources();
hbos8d609f62017-04-10 07:39:05 -0700244}
245
solenberg3ebbcb52017-01-31 03:58:40 -0800246AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo(
247 int sample_rate_hz,
248 AudioFrame* audio_frame) {
Niels Möller349ade32018-11-16 09:50:42 +0100249 return channel_receive_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
solenberg3ebbcb52017-01-31 03:58:40 -0800250}
251
252int AudioReceiveStream::Ssrc() const {
253 return config_.rtp.remote_ssrc;
254}
255
256int AudioReceiveStream::PreferredSampleRate() const {
Niels Möller349ade32018-11-16 09:50:42 +0100257 return channel_receive_->PreferredSampleRate();
solenberg3ebbcb52017-01-31 03:58:40 -0800258}
259
260int AudioReceiveStream::id() const {
261 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
262 return config_.rtp.remote_ssrc;
263}
264
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200265absl::optional<Syncable::Info> AudioReceiveStream::GetInfo() const {
solenberg3ebbcb52017-01-31 03:58:40 -0800266 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
Niels Möller349ade32018-11-16 09:50:42 +0100267 absl::optional<Syncable::Info> info = channel_receive_->GetSyncInfo();
solenberg3ebbcb52017-01-31 03:58:40 -0800268
Niels Möller848d6d32018-08-08 10:49:16 +0200269 if (!info)
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200270 return absl::nullopt;
solenberg3ebbcb52017-01-31 03:58:40 -0800271
Niels Möller349ade32018-11-16 09:50:42 +0100272 info->current_delay_ms = channel_receive_->GetDelayEstimate();
Oskar Sundbom2707fb22017-11-16 10:57:35 +0100273 return info;
solenberg3ebbcb52017-01-31 03:58:40 -0800274}
275
276uint32_t AudioReceiveStream::GetPlayoutTimestamp() const {
277 // Called on video capture thread.
Niels Möller349ade32018-11-16 09:50:42 +0100278 return channel_receive_->GetPlayoutTimestamp();
solenberg3ebbcb52017-01-31 03:58:40 -0800279}
280
281void AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
282 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
Niels Möller349ade32018-11-16 09:50:42 +0100283 return channel_receive_->SetMinimumPlayoutDelay(delay_ms);
pbosa2f30de2015-10-15 05:22:13 -0700284}
285
solenberg7602aab2016-11-14 11:30:07 -0800286void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) {
solenberg3ebbcb52017-01-31 03:58:40 -0800287 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Niels Möller349ade32018-11-16 09:50:42 +0100288 channel_receive_->SetAssociatedSendChannel(
289 send_stream ? send_stream->GetChannel() : nullptr);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100290 associated_send_stream_ = send_stream;
solenberg7602aab2016-11-14 11:30:07 -0800291}
292
pbos1ba8d392016-05-01 20:18:34 -0700293void AudioReceiveStream::SignalNetworkState(NetworkState state) {
solenberg3ebbcb52017-01-31 03:58:40 -0800294 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
pbos1ba8d392016-05-01 20:18:34 -0700295}
296
297bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
298 // TODO(solenberg): Tests call this function on a network thread, libjingle
299 // calls on the worker thread. We should move towards always using a network
300 // thread. Then this check can be enabled.
301 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
Niels Möller349ade32018-11-16 09:50:42 +0100302 return channel_receive_->ReceivedRTCPPacket(packet, length);
pbos1ba8d392016-05-01 20:18:34 -0700303}
304
nisse657bab22017-02-21 06:28:10 -0800305void AudioReceiveStream::OnRtpPacket(const RtpPacketReceived& packet) {
pbos1ba8d392016-05-01 20:18:34 -0700306 // TODO(solenberg): Tests call this function on a network thread, libjingle
307 // calls on the worker thread. We should move towards always using a network
308 // thread. Then this check can be enabled.
309 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
Niels Möller349ade32018-11-16 09:50:42 +0100310 channel_receive_->OnRtpPacket(packet);
pbos1ba8d392016-05-01 20:18:34 -0700311}
312
solenberg3ebbcb52017-01-31 03:58:40 -0800313const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const {
314 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
315 return config_;
aleloi04c07222016-11-22 06:42:53 -0800316}
317
Yves Gerey665174f2018-06-19 15:03:05 +0200318const AudioSendStream* AudioReceiveStream::GetAssociatedSendStreamForTesting()
319 const {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100320 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
321 return associated_send_stream_;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200322}
aleloi04c07222016-11-22 06:42:53 -0800323
solenberg3ebbcb52017-01-31 03:58:40 -0800324internal::AudioState* AudioReceiveStream::audio_state() const {
325 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get());
326 RTC_DCHECK(audio_state);
327 return audio_state;
328}
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100329
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100330void AudioReceiveStream::ConfigureStream(AudioReceiveStream* stream,
331 const Config& new_config,
332 bool first_time) {
Jonas Olsson24ea8222018-01-25 10:14:29 +0100333 RTC_LOG(LS_INFO) << "AudioReceiveStream::ConfigureStream: "
334 << new_config.ToString();
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100335 RTC_DCHECK(stream);
Niels Möller349ade32018-11-16 09:50:42 +0100336 const auto& channel_receive = stream->channel_receive_;
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100337 const auto& old_config = stream->config_;
338
339 // Configuration parameters which cannot be changed.
340 RTC_DCHECK(first_time ||
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100341 old_config.rtp.remote_ssrc == new_config.rtp.remote_ssrc);
342 RTC_DCHECK(first_time ||
343 old_config.rtcp_send_transport == new_config.rtcp_send_transport);
344 // Decoder factory cannot be changed because it is configured at
345 // voe::Channel construction time.
346 RTC_DCHECK(first_time ||
347 old_config.decoder_factory == new_config.decoder_factory);
348
349 if (first_time || old_config.rtp.local_ssrc != new_config.rtp.local_ssrc) {
Niels Möller349ade32018-11-16 09:50:42 +0100350 channel_receive->SetLocalSSRC(new_config.rtp.local_ssrc);
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100351 }
Niels Möllerf7824922018-05-25 13:41:10 +0200352
Niels Möller30b48392018-08-15 15:05:26 +0200353 if (!first_time) {
Niels Möllerf7824922018-05-25 13:41:10 +0200354 // Remote ssrc can't be changed mid-stream.
355 RTC_DCHECK_EQ(old_config.rtp.remote_ssrc, new_config.rtp.remote_ssrc);
356 }
357
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100358 // TODO(solenberg): Config NACK history window (which is a packet count),
359 // using the actual packet size for the configured codec.
360 if (first_time || old_config.rtp.nack.rtp_history_ms !=
361 new_config.rtp.nack.rtp_history_ms) {
Niels Möller349ade32018-11-16 09:50:42 +0100362 channel_receive->SetNACKStatus(new_config.rtp.nack.rtp_history_ms != 0,
363 new_config.rtp.nack.rtp_history_ms / 20);
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100364 }
365 if (first_time || old_config.decoder_map != new_config.decoder_map) {
Niels Möller349ade32018-11-16 09:50:42 +0100366 channel_receive->SetReceiveCodecs(new_config.decoder_map);
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100367 }
368
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100369 stream->config_ = new_config;
370}
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200371} // namespace internal
372} // namespace webrtc