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
11 #include "audio/audio_receive_stream.h"
12
13 #include <string>
14 #include <utility>
15
16 #include "absl/memory/memory.h"
17 #include "api/array_view.h"
18 #include "api/audio_codecs/audio_format.h"
19 #include "api/call/audio_sink.h"
20 #include "api/rtp_parameters.h"
21 #include "api/sequence_checker.h"
22 #include "audio/audio_send_stream.h"
23 #include "audio/audio_state.h"
24 #include "audio/channel_receive.h"
25 #include "audio/conversion.h"
26 #include "call/rtp_config.h"
27 #include "call/rtp_stream_receiver_controller_interface.h"
28 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
29 #include "rtc_base/checks.h"
30 #include "rtc_base/logging.h"
31 #include "rtc_base/strings/string_builder.h"
32 #include "rtc_base/time_utils.h"
33
34 namespace webrtc {
35
ToString() const36 std::string AudioReceiveStreamInterface::Config::Rtp::ToString() const {
37 char ss_buf[1024];
38 rtc::SimpleStringBuilder ss(ss_buf);
39 ss << "{remote_ssrc: " << remote_ssrc;
40 ss << ", local_ssrc: " << local_ssrc;
41 ss << ", transport_cc: " << (transport_cc ? "on" : "off");
42 ss << ", nack: " << nack.ToString();
43 ss << ", extensions: [";
44 for (size_t i = 0; i < extensions.size(); ++i) {
45 ss << extensions[i].ToString();
46 if (i != extensions.size() - 1) {
47 ss << ", ";
48 }
49 }
50 ss << ']';
51 ss << '}';
52 return ss.str();
53 }
54
ToString() const55 std::string AudioReceiveStreamInterface::Config::ToString() const {
56 char ss_buf[1024];
57 rtc::SimpleStringBuilder ss(ss_buf);
58 ss << "{rtp: " << rtp.ToString();
59 ss << ", rtcp_send_transport: "
60 << (rtcp_send_transport ? "(Transport)" : "null");
61 if (!sync_group.empty()) {
62 ss << ", sync_group: " << sync_group;
63 }
64 ss << '}';
65 return ss.str();
66 }
67
68 namespace {
CreateChannelReceive(Clock * clock,webrtc::AudioState * audio_state,NetEqFactory * neteq_factory,const webrtc::AudioReceiveStreamInterface::Config & config,RtcEventLog * event_log)69 std::unique_ptr<voe::ChannelReceiveInterface> CreateChannelReceive(
70 Clock* clock,
71 webrtc::AudioState* audio_state,
72 NetEqFactory* neteq_factory,
73 const webrtc::AudioReceiveStreamInterface::Config& config,
74 RtcEventLog* event_log) {
75 RTC_DCHECK(audio_state);
76 internal::AudioState* internal_audio_state =
77 static_cast<internal::AudioState*>(audio_state);
78 return voe::CreateChannelReceive(
79 clock, neteq_factory, internal_audio_state->audio_device_module(),
80 config.rtcp_send_transport, event_log, config.rtp.local_ssrc,
81 config.rtp.remote_ssrc, config.jitter_buffer_max_packets,
82 config.jitter_buffer_fast_accelerate, config.jitter_buffer_min_delay_ms,
83 config.enable_non_sender_rtt, config.decoder_factory,
84 config.codec_pair_id, std::move(config.frame_decryptor),
85 config.crypto_options, std::move(config.frame_transformer));
86 }
87 } // namespace
88
AudioReceiveStreamImpl(Clock * clock,PacketRouter * packet_router,NetEqFactory * neteq_factory,const webrtc::AudioReceiveStreamInterface::Config & config,const rtc::scoped_refptr<webrtc::AudioState> & audio_state,webrtc::RtcEventLog * event_log)89 AudioReceiveStreamImpl::AudioReceiveStreamImpl(
90 Clock* clock,
91 PacketRouter* packet_router,
92 NetEqFactory* neteq_factory,
93 const webrtc::AudioReceiveStreamInterface::Config& config,
94 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
95 webrtc::RtcEventLog* event_log)
96 : AudioReceiveStreamImpl(clock,
97 packet_router,
98 config,
99 audio_state,
100 event_log,
101 CreateChannelReceive(clock,
102 audio_state.get(),
103 neteq_factory,
104 config,
105 event_log)) {}
106
AudioReceiveStreamImpl(Clock * clock,PacketRouter * packet_router,const webrtc::AudioReceiveStreamInterface::Config & config,const rtc::scoped_refptr<webrtc::AudioState> & audio_state,webrtc::RtcEventLog * event_log,std::unique_ptr<voe::ChannelReceiveInterface> channel_receive)107 AudioReceiveStreamImpl::AudioReceiveStreamImpl(
108 Clock* clock,
109 PacketRouter* packet_router,
110 const webrtc::AudioReceiveStreamInterface::Config& config,
111 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
112 webrtc::RtcEventLog* event_log,
113 std::unique_ptr<voe::ChannelReceiveInterface> channel_receive)
114 : config_(config),
115 audio_state_(audio_state),
116 source_tracker_(clock),
117 channel_receive_(std::move(channel_receive)) {
118 RTC_LOG(LS_INFO) << "AudioReceiveStreamImpl: " << config.rtp.remote_ssrc;
119 RTC_DCHECK(config.decoder_factory);
120 RTC_DCHECK(config.rtcp_send_transport);
121 RTC_DCHECK(audio_state_);
122 RTC_DCHECK(channel_receive_);
123
124 packet_sequence_checker_.Detach();
125
126 RTC_DCHECK(packet_router);
127 // Configure bandwidth estimation.
128 channel_receive_->RegisterReceiverCongestionControlObjects(packet_router);
129
130 // When output is muted, ChannelReceive will directly notify the source
131 // tracker of "delivered" frames, so RtpReceiver information will continue to
132 // be updated.
133 channel_receive_->SetSourceTracker(&source_tracker_);
134
135 // Complete configuration.
136 // TODO(solenberg): Config NACK history window (which is a packet count),
137 // using the actual packet size for the configured codec.
138 channel_receive_->SetNACKStatus(config.rtp.nack.rtp_history_ms != 0,
139 config.rtp.nack.rtp_history_ms / 20);
140 channel_receive_->SetReceiveCodecs(config.decoder_map);
141 // `frame_transformer` and `frame_decryptor` have been given to
142 // `channel_receive_` already.
143 }
144
~AudioReceiveStreamImpl()145 AudioReceiveStreamImpl::~AudioReceiveStreamImpl() {
146 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
147 RTC_LOG(LS_INFO) << "~AudioReceiveStreamImpl: " << remote_ssrc();
148 Stop();
149 channel_receive_->SetAssociatedSendChannel(nullptr);
150 channel_receive_->ResetReceiverCongestionControlObjects();
151 }
152
RegisterWithTransport(RtpStreamReceiverControllerInterface * receiver_controller)153 void AudioReceiveStreamImpl::RegisterWithTransport(
154 RtpStreamReceiverControllerInterface* receiver_controller) {
155 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
156 RTC_DCHECK(!rtp_stream_receiver_);
157 rtp_stream_receiver_ = receiver_controller->CreateReceiver(
158 remote_ssrc(), channel_receive_.get());
159 }
160
UnregisterFromTransport()161 void AudioReceiveStreamImpl::UnregisterFromTransport() {
162 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
163 rtp_stream_receiver_.reset();
164 }
165
ReconfigureForTesting(const webrtc::AudioReceiveStreamInterface::Config & config)166 void AudioReceiveStreamImpl::ReconfigureForTesting(
167 const webrtc::AudioReceiveStreamInterface::Config& config) {
168 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
169
170 // SSRC can't be changed mid-stream.
171 RTC_DCHECK_EQ(remote_ssrc(), config.rtp.remote_ssrc);
172 RTC_DCHECK_EQ(local_ssrc(), config.rtp.local_ssrc);
173
174 // Configuration parameters which cannot be changed.
175 RTC_DCHECK_EQ(config_.rtcp_send_transport, config.rtcp_send_transport);
176 // Decoder factory cannot be changed because it is configured at
177 // voe::Channel construction time.
178 RTC_DCHECK_EQ(config_.decoder_factory, config.decoder_factory);
179
180 // TODO(solenberg): Config NACK history window (which is a packet count),
181 // using the actual packet size for the configured codec.
182 RTC_DCHECK_EQ(config_.rtp.nack.rtp_history_ms, config.rtp.nack.rtp_history_ms)
183 << "Use SetUseTransportCcAndNackHistory";
184
185 RTC_DCHECK(config_.decoder_map == config.decoder_map) << "Use SetDecoderMap";
186 RTC_DCHECK_EQ(config_.frame_transformer, config.frame_transformer)
187 << "Use SetDepacketizerToDecoderFrameTransformer";
188
189 config_ = config;
190 }
191
Start()192 void AudioReceiveStreamImpl::Start() {
193 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
194 if (playing_) {
195 return;
196 }
197 channel_receive_->StartPlayout();
198 playing_ = true;
199 audio_state()->AddReceivingStream(this);
200 }
201
Stop()202 void AudioReceiveStreamImpl::Stop() {
203 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
204 if (!playing_) {
205 return;
206 }
207 channel_receive_->StopPlayout();
208 playing_ = false;
209 audio_state()->RemoveReceivingStream(this);
210 }
211
transport_cc() const212 bool AudioReceiveStreamImpl::transport_cc() const {
213 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
214 return config_.rtp.transport_cc;
215 }
216
SetTransportCc(bool transport_cc)217 void AudioReceiveStreamImpl::SetTransportCc(bool transport_cc) {
218 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
219 config_.rtp.transport_cc = transport_cc;
220 }
221
IsRunning() const222 bool AudioReceiveStreamImpl::IsRunning() const {
223 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
224 return playing_;
225 }
226
SetDepacketizerToDecoderFrameTransformer(rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)227 void AudioReceiveStreamImpl::SetDepacketizerToDecoderFrameTransformer(
228 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) {
229 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
230 channel_receive_->SetDepacketizerToDecoderFrameTransformer(
231 std::move(frame_transformer));
232 }
233
SetDecoderMap(std::map<int,SdpAudioFormat> decoder_map)234 void AudioReceiveStreamImpl::SetDecoderMap(
235 std::map<int, SdpAudioFormat> decoder_map) {
236 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
237 config_.decoder_map = std::move(decoder_map);
238 channel_receive_->SetReceiveCodecs(config_.decoder_map);
239 }
240
SetNackHistory(int history_ms)241 void AudioReceiveStreamImpl::SetNackHistory(int history_ms) {
242 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
243 RTC_DCHECK_GE(history_ms, 0);
244
245 if (config_.rtp.nack.rtp_history_ms == history_ms)
246 return;
247
248 config_.rtp.nack.rtp_history_ms = history_ms;
249 // TODO(solenberg): Config NACK history window (which is a packet count),
250 // using the actual packet size for the configured codec.
251 channel_receive_->SetNACKStatus(history_ms != 0, history_ms / 20);
252 }
253
SetNonSenderRttMeasurement(bool enabled)254 void AudioReceiveStreamImpl::SetNonSenderRttMeasurement(bool enabled) {
255 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
256 config_.enable_non_sender_rtt = enabled;
257 channel_receive_->SetNonSenderRttMeasurement(enabled);
258 }
259
SetFrameDecryptor(rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor)260 void AudioReceiveStreamImpl::SetFrameDecryptor(
261 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor) {
262 // TODO(bugs.webrtc.org/11993): This is called via WebRtcAudioReceiveStream,
263 // expect to be called on the network thread.
264 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
265 channel_receive_->SetFrameDecryptor(std::move(frame_decryptor));
266 }
267
SetRtpExtensions(std::vector<RtpExtension> extensions)268 void AudioReceiveStreamImpl::SetRtpExtensions(
269 std::vector<RtpExtension> extensions) {
270 // TODO(bugs.webrtc.org/11993): This is called via WebRtcAudioReceiveStream,
271 // expect to be called on the network thread.
272 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
273 config_.rtp.extensions = std::move(extensions);
274 }
275
GetRtpExtensions() const276 const std::vector<RtpExtension>& AudioReceiveStreamImpl::GetRtpExtensions()
277 const {
278 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
279 return config_.rtp.extensions;
280 }
281
GetRtpExtensionMap() const282 RtpHeaderExtensionMap AudioReceiveStreamImpl::GetRtpExtensionMap() const {
283 return RtpHeaderExtensionMap(config_.rtp.extensions);
284 }
285
GetStats(bool get_and_clear_legacy_stats) const286 webrtc::AudioReceiveStreamInterface::Stats AudioReceiveStreamImpl::GetStats(
287 bool get_and_clear_legacy_stats) const {
288 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
289 webrtc::AudioReceiveStreamInterface::Stats stats;
290 stats.remote_ssrc = remote_ssrc();
291
292 webrtc::CallReceiveStatistics call_stats =
293 channel_receive_->GetRTCPStatistics();
294 // TODO(solenberg): Don't return here if we can't get the codec - return the
295 // stats we *can* get.
296 auto receive_codec = channel_receive_->GetReceiveCodec();
297 if (!receive_codec) {
298 return stats;
299 }
300
301 stats.payload_bytes_rcvd = call_stats.payload_bytes_rcvd;
302 stats.header_and_padding_bytes_rcvd =
303 call_stats.header_and_padding_bytes_rcvd;
304 stats.packets_rcvd = call_stats.packetsReceived;
305 stats.packets_lost = call_stats.cumulativeLost;
306 stats.nacks_sent = call_stats.nacks_sent;
307 stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
308 stats.last_packet_received_timestamp_ms =
309 call_stats.last_packet_received_timestamp_ms;
310 stats.codec_name = receive_codec->second.name;
311 stats.codec_payload_type = receive_codec->first;
312 int clockrate_khz = receive_codec->second.clockrate_hz / 1000;
313 if (clockrate_khz > 0) {
314 stats.jitter_ms = call_stats.jitterSamples / clockrate_khz;
315 }
316 stats.delay_estimate_ms = channel_receive_->GetDelayEstimate();
317 stats.audio_level = channel_receive_->GetSpeechOutputLevelFullRange();
318 stats.total_output_energy = channel_receive_->GetTotalOutputEnergy();
319 stats.total_output_duration = channel_receive_->GetTotalOutputDuration();
320 stats.estimated_playout_ntp_timestamp_ms =
321 channel_receive_->GetCurrentEstimatedPlayoutNtpTimestampMs(
322 rtc::TimeMillis());
323
324 // Get jitter buffer and total delay (alg + jitter + playout) stats.
325 auto ns = channel_receive_->GetNetworkStatistics(get_and_clear_legacy_stats);
326 stats.packets_discarded = ns.packetsDiscarded;
327 stats.fec_packets_received = ns.fecPacketsReceived;
328 stats.fec_packets_discarded = ns.fecPacketsDiscarded;
329 stats.jitter_buffer_ms = ns.currentBufferSize;
330 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize;
331 stats.total_samples_received = ns.totalSamplesReceived;
332 stats.concealed_samples = ns.concealedSamples;
333 stats.silent_concealed_samples = ns.silentConcealedSamples;
334 stats.concealment_events = ns.concealmentEvents;
335 stats.jitter_buffer_delay_seconds =
336 static_cast<double>(ns.jitterBufferDelayMs) /
337 static_cast<double>(rtc::kNumMillisecsPerSec);
338 stats.jitter_buffer_emitted_count = ns.jitterBufferEmittedCount;
339 stats.jitter_buffer_target_delay_seconds =
340 static_cast<double>(ns.jitterBufferTargetDelayMs) /
341 static_cast<double>(rtc::kNumMillisecsPerSec);
342 stats.jitter_buffer_minimum_delay_seconds =
343 static_cast<double>(ns.jitterBufferMinimumDelayMs) /
344 static_cast<double>(rtc::kNumMillisecsPerSec);
345 stats.inserted_samples_for_deceleration = ns.insertedSamplesForDeceleration;
346 stats.removed_samples_for_acceleration = ns.removedSamplesForAcceleration;
347 stats.expand_rate = Q14ToFloat(ns.currentExpandRate);
348 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate);
349 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate);
350 stats.secondary_discarded_rate = Q14ToFloat(ns.currentSecondaryDiscardedRate);
351 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate);
352 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate);
353 stats.jitter_buffer_flushes = ns.packetBufferFlushes;
354 stats.delayed_packet_outage_samples = ns.delayedPacketOutageSamples;
355 stats.relative_packet_arrival_delay_seconds =
356 static_cast<double>(ns.relativePacketArrivalDelayMs) /
357 static_cast<double>(rtc::kNumMillisecsPerSec);
358 stats.interruption_count = ns.interruptionCount;
359 stats.total_interruption_duration_ms = ns.totalInterruptionDurationMs;
360
361 auto ds = channel_receive_->GetDecodingCallStatistics();
362 stats.decoding_calls_to_silence_generator = ds.calls_to_silence_generator;
363 stats.decoding_calls_to_neteq = ds.calls_to_neteq;
364 stats.decoding_normal = ds.decoded_normal;
365 stats.decoding_plc = ds.decoded_neteq_plc;
366 stats.decoding_codec_plc = ds.decoded_codec_plc;
367 stats.decoding_cng = ds.decoded_cng;
368 stats.decoding_plc_cng = ds.decoded_plc_cng;
369 stats.decoding_muted_output = ds.decoded_muted_output;
370
371 stats.last_sender_report_timestamp_ms =
372 call_stats.last_sender_report_timestamp_ms;
373 stats.last_sender_report_remote_timestamp_ms =
374 call_stats.last_sender_report_remote_timestamp_ms;
375 stats.sender_reports_packets_sent = call_stats.sender_reports_packets_sent;
376 stats.sender_reports_bytes_sent = call_stats.sender_reports_bytes_sent;
377 stats.sender_reports_reports_count = call_stats.sender_reports_reports_count;
378 stats.round_trip_time = call_stats.round_trip_time;
379 stats.round_trip_time_measurements = call_stats.round_trip_time_measurements;
380 stats.total_round_trip_time = call_stats.total_round_trip_time;
381
382 return stats;
383 }
384
SetSink(AudioSinkInterface * sink)385 void AudioReceiveStreamImpl::SetSink(AudioSinkInterface* sink) {
386 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
387 channel_receive_->SetSink(sink);
388 }
389
SetGain(float gain)390 void AudioReceiveStreamImpl::SetGain(float gain) {
391 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
392 channel_receive_->SetChannelOutputVolumeScaling(gain);
393 }
394
SetBaseMinimumPlayoutDelayMs(int delay_ms)395 bool AudioReceiveStreamImpl::SetBaseMinimumPlayoutDelayMs(int delay_ms) {
396 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
397 return channel_receive_->SetBaseMinimumPlayoutDelayMs(delay_ms);
398 }
399
GetBaseMinimumPlayoutDelayMs() const400 int AudioReceiveStreamImpl::GetBaseMinimumPlayoutDelayMs() const {
401 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
402 return channel_receive_->GetBaseMinimumPlayoutDelayMs();
403 }
404
GetSources() const405 std::vector<RtpSource> AudioReceiveStreamImpl::GetSources() const {
406 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
407 return source_tracker_.GetSources();
408 }
409
410 AudioMixer::Source::AudioFrameInfo
GetAudioFrameWithInfo(int sample_rate_hz,AudioFrame * audio_frame)411 AudioReceiveStreamImpl::GetAudioFrameWithInfo(int sample_rate_hz,
412 AudioFrame* audio_frame) {
413 AudioMixer::Source::AudioFrameInfo audio_frame_info =
414 channel_receive_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
415 if (audio_frame_info != AudioMixer::Source::AudioFrameInfo::kError) {
416 source_tracker_.OnFrameDelivered(audio_frame->packet_infos_);
417 }
418 return audio_frame_info;
419 }
420
Ssrc() const421 int AudioReceiveStreamImpl::Ssrc() const {
422 return remote_ssrc();
423 }
424
PreferredSampleRate() const425 int AudioReceiveStreamImpl::PreferredSampleRate() const {
426 return channel_receive_->PreferredSampleRate();
427 }
428
id() const429 uint32_t AudioReceiveStreamImpl::id() const {
430 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
431 return remote_ssrc();
432 }
433
GetInfo() const434 absl::optional<Syncable::Info> AudioReceiveStreamImpl::GetInfo() const {
435 // TODO(bugs.webrtc.org/11993): This is called via RtpStreamsSynchronizer,
436 // expect to be called on the network thread.
437 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
438 return channel_receive_->GetSyncInfo();
439 }
440
GetPlayoutRtpTimestamp(uint32_t * rtp_timestamp,int64_t * time_ms) const441 bool AudioReceiveStreamImpl::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
442 int64_t* time_ms) const {
443 // Called on video capture thread.
444 return channel_receive_->GetPlayoutRtpTimestamp(rtp_timestamp, time_ms);
445 }
446
SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,int64_t time_ms)447 void AudioReceiveStreamImpl::SetEstimatedPlayoutNtpTimestampMs(
448 int64_t ntp_timestamp_ms,
449 int64_t time_ms) {
450 // Called on video capture thread.
451 channel_receive_->SetEstimatedPlayoutNtpTimestampMs(ntp_timestamp_ms,
452 time_ms);
453 }
454
SetMinimumPlayoutDelay(int delay_ms)455 bool AudioReceiveStreamImpl::SetMinimumPlayoutDelay(int delay_ms) {
456 // TODO(bugs.webrtc.org/11993): This is called via RtpStreamsSynchronizer,
457 // expect to be called on the network thread.
458 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
459 return channel_receive_->SetMinimumPlayoutDelay(delay_ms);
460 }
461
AssociateSendStream(internal::AudioSendStream * send_stream)462 void AudioReceiveStreamImpl::AssociateSendStream(
463 internal::AudioSendStream* send_stream) {
464 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
465 channel_receive_->SetAssociatedSendChannel(
466 send_stream ? send_stream->GetChannel() : nullptr);
467 associated_send_stream_ = send_stream;
468 }
469
DeliverRtcp(const uint8_t * packet,size_t length)470 void AudioReceiveStreamImpl::DeliverRtcp(const uint8_t* packet, size_t length) {
471 // TODO(solenberg): Tests call this function on a network thread, libjingle
472 // calls on the worker thread. We should move towards always using a network
473 // thread. Then this check can be enabled.
474 // RTC_DCHECK(!thread_checker_.IsCurrent());
475 channel_receive_->ReceivedRTCPPacket(packet, length);
476 }
477
SetSyncGroup(absl::string_view sync_group)478 void AudioReceiveStreamImpl::SetSyncGroup(absl::string_view sync_group) {
479 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
480 config_.sync_group = std::string(sync_group);
481 }
482
SetLocalSsrc(uint32_t local_ssrc)483 void AudioReceiveStreamImpl::SetLocalSsrc(uint32_t local_ssrc) {
484 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
485 // TODO(tommi): Consider storing local_ssrc in one place.
486 config_.rtp.local_ssrc = local_ssrc;
487 channel_receive_->OnLocalSsrcChange(local_ssrc);
488 }
489
local_ssrc() const490 uint32_t AudioReceiveStreamImpl::local_ssrc() const {
491 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
492 RTC_DCHECK_EQ(config_.rtp.local_ssrc, channel_receive_->GetLocalSsrc());
493 return config_.rtp.local_ssrc;
494 }
495
sync_group() const496 const std::string& AudioReceiveStreamImpl::sync_group() const {
497 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
498 return config_.sync_group;
499 }
500
501 const AudioSendStream*
GetAssociatedSendStreamForTesting() const502 AudioReceiveStreamImpl::GetAssociatedSendStreamForTesting() const {
503 RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
504 return associated_send_stream_;
505 }
506
audio_state() const507 internal::AudioState* AudioReceiveStreamImpl::audio_state() const {
508 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get());
509 RTC_DCHECK(audio_state);
510 return audio_state;
511 }
512 } // namespace webrtc
513