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