blob: e1041beb841036bfd60a3e7c0fbd8d677050be30 [file] [log] [blame]
Fredrik Solenberg23fba1f2015-04-29 13:24:011/*
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 04:47:3111#include "audio/audio_receive_stream.h"
Fredrik Solenberg23fba1f2015-04-29 13:24:0112
13#include <string>
Tommif888bb52015-12-12 00:37:0114#include <utility>
Fredrik Solenberg23fba1f2015-04-29 13:24:0115
Yves Gerey988cc082018-10-23 10:03:0116#include "absl/memory/memory.h"
17#include "api/array_view.h"
18#include "api/audio_codecs/audio_format.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "api/call/audio_sink.h"
Steve Anton10542f22019-01-11 17:11:0020#include "api/rtp_parameters.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "audio/audio_send_stream.h"
22#include "audio/audio_state.h"
Yves Gerey988cc082018-10-23 10:03:0123#include "audio/channel_receive.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "audio/conversion.h"
Yves Gerey988cc082018-10-23 10:03:0125#include "call/rtp_config.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3126#include "call/rtp_stream_receiver_controller_interface.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3127#include "rtc_base/checks.h"
28#include "rtc_base/logging.h"
Tommifef05002018-02-27 12:51:0829#include "rtc_base/strings/string_builder.h"
Steve Anton10542f22019-01-11 17:11:0030#include "rtc_base/time_utils.h"
Fredrik Solenberg23fba1f2015-04-29 13:24:0131
32namespace webrtc {
Stefan Holmer3842c5c2016-01-12 12:55:0033
Fredrik Solenberg23fba1f2015-04-29 13:24:0134std::string AudioReceiveStream::Config::Rtp::ToString() const {
Karl Wiberg881f1682018-03-08 14:03:2335 char ss_buf[1024];
36 rtc::SimpleStringBuilder ss(ss_buf);
Fredrik Solenberg23fba1f2015-04-29 13:24:0137 ss << "{remote_ssrc: " << remote_ssrc;
solenberg85a04962015-10-27 10:35:2138 ss << ", local_ssrc: " << local_ssrc;
solenberg8189b022016-06-14 19:13:0039 ss << ", transport_cc: " << (transport_cc ? "on" : "off");
40 ss << ", nack: " << nack.ToString();
Fredrik Solenberg23fba1f2015-04-29 13:24:0141 ss << ", extensions: [";
42 for (size_t i = 0; i < extensions.size(); ++i) {
43 ss << extensions[i].ToString();
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2744 if (i != extensions.size() - 1) {
Fredrik Solenberg23fba1f2015-04-29 13:24:0145 ss << ", ";
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2746 }
Fredrik Solenberg23fba1f2015-04-29 13:24:0147 }
48 ss << ']';
49 ss << '}';
50 return ss.str();
51}
52
53std::string AudioReceiveStream::Config::ToString() const {
Karl Wiberg881f1682018-03-08 14:03:2354 char ss_buf[1024];
55 rtc::SimpleStringBuilder ss(ss_buf);
Fredrik Solenberg23fba1f2015-04-29 13:24:0156 ss << "{rtp: " << rtp.ToString();
solenberg85a04962015-10-27 10:35:2157 ss << ", rtcp_send_transport: "
deadbeef922246a2017-02-26 12:18:1258 << (rtcp_send_transport ? "(Transport)" : "null");
Anton Sukhanov4f08faa2019-05-21 18:12:5759 ss << ", media_transport_config: " << media_transport_config.DebugString();
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2760 if (!sync_group.empty()) {
pbos8fc7fa72015-07-15 15:02:5861 ss << ", sync_group: " << sync_group;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2762 }
Fredrik Solenberg23fba1f2015-04-29 13:24:0163 ss << '}';
64 return ss.str();
65}
66
67namespace internal {
Fredrik Solenberg8f5787a2018-01-11 12:52:3068namespace {
Niels Möller349ade32018-11-16 08:50:4269std::unique_ptr<voe::ChannelReceiveInterface> CreateChannelReceive(
Sebastian Jansson977b3352019-03-04 16:43:3470 Clock* clock,
Fredrik Solenberg8f5787a2018-01-11 12:52:3071 webrtc::AudioState* audio_state,
72 ProcessThread* module_process_thread,
Ivo Creusenc3d1f9b2019-11-01 10:47:5173 NetEqFactory* neteq_factory,
Niels Möllerfa4e1852018-08-14 07:43:3474 const webrtc::AudioReceiveStream::Config& config,
75 RtcEventLog* event_log) {
Fredrik Solenberg8f5787a2018-01-11 12:52:3076 RTC_DCHECK(audio_state);
77 internal::AudioState* internal_audio_state =
78 static_cast<internal::AudioState*>(audio_state);
Niels Möller349ade32018-11-16 08:50:4279 return voe::CreateChannelReceive(
Ivo Creusenc3d1f9b2019-11-01 10:47:5180 clock, module_process_thread, neteq_factory,
81 internal_audio_state->audio_device_module(),
Anton Sukhanov4f08faa2019-05-21 18:12:5782 config.media_transport_config, config.rtcp_send_transport, event_log,
Erik Språng70efdde2019-08-21 11:36:2083 config.rtp.local_ssrc, config.rtp.remote_ssrc,
84 config.jitter_buffer_max_packets, config.jitter_buffer_fast_accelerate,
85 config.jitter_buffer_min_delay_ms,
Jakob Ivarsson53eae872019-01-10 14:58:3686 config.jitter_buffer_enable_rtx_handling, config.decoder_factory,
87 config.codec_pair_id, config.frame_decryptor, config.crypto_options);
Fredrik Solenberg8f5787a2018-01-11 12:52:3088}
89} // namespace
90
91AudioReceiveStream::AudioReceiveStream(
Sebastian Jansson977b3352019-03-04 16:43:3492 Clock* clock,
Fredrik Solenberg8f5787a2018-01-11 12:52:3093 RtpStreamReceiverControllerInterface* receiver_controller,
94 PacketRouter* packet_router,
95 ProcessThread* module_process_thread,
Ivo Creusenc3d1f9b2019-11-01 10:47:5196 NetEqFactory* neteq_factory,
Fredrik Solenberg8f5787a2018-01-11 12:52:3097 const webrtc::AudioReceiveStream::Config& config,
98 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
99 webrtc::RtcEventLog* event_log)
Sebastian Jansson977b3352019-03-04 16:43:34100 : AudioReceiveStream(clock,
101 receiver_controller,
Fredrik Solenberg8f5787a2018-01-11 12:52:30102 packet_router,
103 config,
104 audio_state,
105 event_log,
Sebastian Jansson977b3352019-03-04 16:43:34106 CreateChannelReceive(clock,
107 audio_state.get(),
Niels Möller349ade32018-11-16 08:50:42108 module_process_thread,
Ivo Creusenc3d1f9b2019-11-01 10:47:51109 neteq_factory,
Niels Möller349ade32018-11-16 08:50:42110 config,
111 event_log)) {}
Fredrik Solenberg8f5787a2018-01-11 12:52:30112
Fredrik Solenberg23fba1f2015-04-29 13:24:01113AudioReceiveStream::AudioReceiveStream(
Sebastian Jansson977b3352019-03-04 16:43:34114 Clock* clock,
nisse0f15f922017-06-21 08:05:22115 RtpStreamReceiverControllerInterface* receiver_controller,
nisse0245da02016-11-30 11:35:20116 PacketRouter* packet_router,
solenberg566ef242015-11-06 23:34:49117 const webrtc::AudioReceiveStream::Config& config,
ivoc14d5dbe2016-07-04 14:06:55118 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
Fredrik Solenberg8f5787a2018-01-11 12:52:30119 webrtc::RtcEventLog* event_log,
Niels Möller349ade32018-11-16 08:50:42120 std::unique_ptr<voe::ChannelReceiveInterface> channel_receive)
Chen Xing054e3bb2019-08-02 10:29:26121 : audio_state_(audio_state),
122 channel_receive_(std::move(channel_receive)),
123 source_tracker_(clock) {
Jonas Olsson24ea8222018-01-25 09:14:29124 RTC_LOG(LS_INFO) << "AudioReceiveStream: " << config.rtp.remote_ssrc;
Fredrik Solenberg8f5787a2018-01-11 12:52:30125 RTC_DCHECK(config.decoder_factory);
Niels Möllerae4237e2018-10-05 09:28:38126 RTC_DCHECK(config.rtcp_send_transport);
Fredrik Solenberg8f5787a2018-01-11 12:52:30127 RTC_DCHECK(audio_state_);
Niels Möller349ade32018-11-16 08:50:42128 RTC_DCHECK(channel_receive_);
solenberg7add0582015-11-20 17:59:34129
Sebastian Janssonc01367d2019-04-08 13:20:44130 module_process_thread_checker_.Detach();
solenberg3ebbcb52017-01-31 11:58:40131
Anton Sukhanov4f08faa2019-05-21 18:12:57132 if (!config.media_transport_config.media_transport) {
Niels Möller7d76a312018-10-26 10:57:07133 RTC_DCHECK(receiver_controller);
134 RTC_DCHECK(packet_router);
135 // Configure bandwidth estimation.
Niels Möller349ade32018-11-16 08:50:42136 channel_receive_->RegisterReceiverCongestionControlObjects(packet_router);
nisse0f15f922017-06-21 08:05:22137
Niels Möller7d76a312018-10-26 10:57:07138 // Register with transport.
139 rtp_stream_receiver_ = receiver_controller->CreateReceiver(
Niels Möller349ade32018-11-16 08:50:42140 config.rtp.remote_ssrc, channel_receive_.get());
Niels Möller7d76a312018-10-26 10:57:07141 }
Fredrik Solenberg3b903d02018-01-10 14:17:10142 ConfigureStream(this, config, true);
Fredrik Solenberg23fba1f2015-04-29 13:24:01143}
144
pbosa2f30de2015-10-15 12:22:13145AudioReceiveStream::~AudioReceiveStream() {
solenberg3ebbcb52017-01-31 11:58:40146 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Jonas Olsson24ea8222018-01-25 09:14:29147 RTC_LOG(LS_INFO) << "~AudioReceiveStream: " << config_.rtp.remote_ssrc;
Fredrik Solenbergd5247512017-12-18 21:41:03148 Stop();
Niels Möller349ade32018-11-16 08:50:42149 channel_receive_->SetAssociatedSendChannel(nullptr);
Anton Sukhanov4f08faa2019-05-21 18:12:57150 if (!config_.media_transport_config.media_transport) {
Niels Möller349ade32018-11-16 08:50:42151 channel_receive_->ResetReceiverCongestionControlObjects();
Niels Möller7d76a312018-10-26 10:57:07152 }
pbosa2f30de2015-10-15 12:22:13153}
154
Fredrik Solenberg3b903d02018-01-10 14:17:10155void AudioReceiveStream::Reconfigure(
156 const webrtc::AudioReceiveStream::Config& config) {
Sebastian Janssonc01367d2019-04-08 13:20:44157 RTC_DCHECK(worker_thread_checker_.IsCurrent());
Fredrik Solenberg3b903d02018-01-10 14:17:10158 ConfigureStream(this, config, false);
159}
160
solenberg7add0582015-11-20 17:59:34161void AudioReceiveStream::Start() {
solenberg3ebbcb52017-01-31 11:58:40162 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 14:42:53163 if (playing_) {
164 return;
165 }
Niels Möller349ade32018-11-16 08:50:42166 channel_receive_->StartPlayout();
aleloi04c07222016-11-22 14:42:53167 playing_ = true;
Fredrik Solenbergd5247512017-12-18 21:41:03168 audio_state()->AddReceivingStream(this);
solenberg7add0582015-11-20 17:59:34169}
170
171void AudioReceiveStream::Stop() {
solenberg3ebbcb52017-01-31 11:58:40172 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
aleloi04c07222016-11-22 14:42:53173 if (!playing_) {
174 return;
175 }
Niels Möller349ade32018-11-16 08:50:42176 channel_receive_->StopPlayout();
aleloi04c07222016-11-22 14:42:53177 playing_ = false;
Fredrik Solenbergd5247512017-12-18 21:41:03178 audio_state()->RemoveReceivingStream(this);
solenberg7add0582015-11-20 17:59:34179}
180
Fredrik Solenberg04f49312015-06-08 11:04:56181webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
solenberg3ebbcb52017-01-31 11:58:40182 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Fredrik Solenberg4f4ec0a2015-10-22 08:49:27183 webrtc::AudioReceiveStream::Stats stats;
184 stats.remote_ssrc = config_.rtp.remote_ssrc;
solenberg8b85de22015-11-16 17:48:04185
Niels Möller530ead42018-10-04 12:28:39186 webrtc::CallReceiveStatistics call_stats =
Niels Möller349ade32018-11-16 08:50:42187 channel_receive_->GetRTCPStatistics();
solenbergbd9a77f2017-02-06 20:53:57188 // TODO(solenberg): Don't return here if we can't get the codec - return the
189 // stats we *can* get.
Fredrik Solenbergf693bfa2018-12-11 11:22:10190 auto receive_codec = channel_receive_->GetReceiveCodec();
191 if (!receive_codec) {
Fredrik Solenberg4f4ec0a2015-10-22 08:49:27192 return stats;
193 }
194
Niels Möllerac0a4cb2019-10-09 13:01:33195 stats.payload_bytes_rcvd = call_stats.payload_bytes_rcvd;
196 stats.header_and_padding_bytes_rcvd =
197 call_stats.header_and_padding_bytes_rcvd;
solenberg85a04962015-10-27 10:35:21198 stats.packets_rcvd = call_stats.packetsReceived;
199 stats.packets_lost = call_stats.cumulativeLost;
solenberg8b85de22015-11-16 17:48:04200 stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
Henrik Boström01738c62019-04-15 15:32:00201 stats.last_packet_received_timestamp_ms =
202 call_stats.last_packet_received_timestamp_ms;
Fredrik Solenbergf693bfa2018-12-11 11:22:10203 stats.codec_name = receive_codec->second.name;
204 stats.codec_payload_type = receive_codec->first;
Fredrik Solenbergf693bfa2018-12-11 11:22:10205 int clockrate_khz = receive_codec->second.clockrate_hz / 1000;
206 if (clockrate_khz > 0) {
207 stats.jitter_ms = call_stats.jitterSamples / clockrate_khz;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:27208 }
Niels Möller349ade32018-11-16 08:50:42209 stats.delay_estimate_ms = channel_receive_->GetDelayEstimate();
210 stats.audio_level = channel_receive_->GetSpeechOutputLevelFullRange();
211 stats.total_output_energy = channel_receive_->GetTotalOutputEnergy();
212 stats.total_output_duration = channel_receive_->GetTotalOutputDuration();
Åsa Perssonfcf79cc2019-10-22 13:23:44213 stats.estimated_playout_ntp_timestamp_ms =
214 channel_receive_->GetCurrentEstimatedPlayoutNtpTimestampMs(
215 rtc::TimeMillis());
Fredrik Solenberg4f4ec0a2015-10-22 08:49:27216
solenberg8b85de22015-11-16 17:48:04217 // Get jitter buffer and total delay (alg + jitter + playout) stats.
Niels Möller349ade32018-11-16 08:50:42218 auto ns = channel_receive_->GetNetworkStatistics();
Ivo Creusen8d8ffdb2019-04-30 07:45:21219 stats.fec_packets_received = ns.fecPacketsReceived;
220 stats.fec_packets_discarded = ns.fecPacketsDiscarded;
solenberg8b85de22015-11-16 17:48:04221 stats.jitter_buffer_ms = ns.currentBufferSize;
222 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize;
Steve Anton2dbc69f2017-08-25 00:15:13223 stats.total_samples_received = ns.totalSamplesReceived;
224 stats.concealed_samples = ns.concealedSamples;
Ivo Creusen8d8ffdb2019-04-30 07:45:21225 stats.silent_concealed_samples = ns.silentConcealedSamples;
Gustaf Ullberg9a2e9062017-09-18 07:28:20226 stats.concealment_events = ns.concealmentEvents;
Gustaf Ullbergb0a02072017-10-02 10:00:34227 stats.jitter_buffer_delay_seconds =
228 static_cast<double>(ns.jitterBufferDelayMs) /
229 static_cast<double>(rtc::kNumMillisecsPerSec);
Chen Xing0acffb52019-01-15 14:46:29230 stats.jitter_buffer_emitted_count = ns.jitterBufferEmittedCount;
Ivo Creusen8d8ffdb2019-04-30 07:45:21231 stats.inserted_samples_for_deceleration = ns.insertedSamplesForDeceleration;
232 stats.removed_samples_for_acceleration = ns.removedSamplesForAcceleration;
solenberg8b85de22015-11-16 17:48:04233 stats.expand_rate = Q14ToFloat(ns.currentExpandRate);
234 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate);
235 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate);
minyue-webrtc0e320ec2017-08-28 11:51:27236 stats.secondary_discarded_rate = Q14ToFloat(ns.currentSecondaryDiscardedRate);
solenberg8b85de22015-11-16 17:48:04237 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate);
238 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate);
Ruslan Burakov8af88962018-11-22 16:21:10239 stats.jitter_buffer_flushes = ns.packetBufferFlushes;
Jakob Ivarsson352ce5c2018-11-27 11:52:16240 stats.delayed_packet_outage_samples = ns.delayedPacketOutageSamples;
Jakob Ivarsson232b3fd2019-03-06 08:18:40241 stats.relative_packet_arrival_delay_seconds =
242 static_cast<double>(ns.relativePacketArrivalDelayMs) /
243 static_cast<double>(rtc::kNumMillisecsPerSec);
Henrik Lundin44125fa2019-04-29 15:00:46244 stats.interruption_count = ns.interruptionCount;
245 stats.total_interruption_duration_ms = ns.totalInterruptionDurationMs;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:27246
Niels Möller349ade32018-11-16 08:50:42247 auto ds = channel_receive_->GetDecodingCallStatistics();
solenberg8b85de22015-11-16 17:48:04248 stats.decoding_calls_to_silence_generator = ds.calls_to_silence_generator;
249 stats.decoding_calls_to_neteq = ds.calls_to_neteq;
250 stats.decoding_normal = ds.decoded_normal;
Alex Narest5b5d97c2019-08-07 16:15:08251 stats.decoding_plc = ds.decoded_neteq_plc;
252 stats.decoding_codec_plc = ds.decoded_codec_plc;
solenberg8b85de22015-11-16 17:48:04253 stats.decoding_cng = ds.decoded_cng;
254 stats.decoding_plc_cng = ds.decoded_plc_cng;
henrik.lundin63489782016-09-20 08:47:12255 stats.decoding_muted_output = ds.decoded_muted_output;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:27256
257 return stats;
Fredrik Solenberg04f49312015-06-08 11:04:56258}
259
Fredrik Solenberg8f5787a2018-01-11 12:52:30260void AudioReceiveStream::SetSink(AudioSinkInterface* sink) {
solenberg3ebbcb52017-01-31 11:58:40261 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Niels Möller349ade32018-11-16 08:50:42262 channel_receive_->SetSink(sink);
Tommif888bb52015-12-12 00:37:01263}
264
solenberg217fb662016-06-17 15:30:54265void AudioReceiveStream::SetGain(float gain) {
solenberg3ebbcb52017-01-31 11:58:40266 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Niels Möller349ade32018-11-16 08:50:42267 channel_receive_->SetChannelOutputVolumeScaling(gain);
solenberg217fb662016-06-17 15:30:54268}
269
Ruslan Burakov3b50f9f2019-02-06 08:45:56270bool AudioReceiveStream::SetBaseMinimumPlayoutDelayMs(int delay_ms) {
271 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
272 return channel_receive_->SetBaseMinimumPlayoutDelayMs(delay_ms);
273}
274
275int AudioReceiveStream::GetBaseMinimumPlayoutDelayMs() const {
276 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
277 return channel_receive_->GetBaseMinimumPlayoutDelayMs();
278}
279
hbos8d609f62017-04-10 14:39:05280std::vector<RtpSource> AudioReceiveStream::GetSources() const {
281 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Chen Xing054e3bb2019-08-02 10:29:26282 return source_tracker_.GetSources();
hbos8d609f62017-04-10 14:39:05283}
284
solenberg3ebbcb52017-01-31 11:58:40285AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo(
286 int sample_rate_hz,
287 AudioFrame* audio_frame) {
Chen Xing054e3bb2019-08-02 10:29:26288 AudioMixer::Source::AudioFrameInfo audio_frame_info =
289 channel_receive_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
290 if (audio_frame_info != AudioMixer::Source::AudioFrameInfo::kError) {
291 source_tracker_.OnFrameDelivered(audio_frame->packet_infos_);
292 }
293 return audio_frame_info;
solenberg3ebbcb52017-01-31 11:58:40294}
295
296int AudioReceiveStream::Ssrc() const {
297 return config_.rtp.remote_ssrc;
298}
299
300int AudioReceiveStream::PreferredSampleRate() const {
Niels Möller349ade32018-11-16 08:50:42301 return channel_receive_->PreferredSampleRate();
solenberg3ebbcb52017-01-31 11:58:40302}
303
304int AudioReceiveStream::id() const {
305 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
306 return config_.rtp.remote_ssrc;
307}
308
Danil Chapovalovb9b146c2018-06-15 10:28:07309absl::optional<Syncable::Info> AudioReceiveStream::GetInfo() const {
solenberg3ebbcb52017-01-31 11:58:40310 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
Niels Möller349ade32018-11-16 08:50:42311 absl::optional<Syncable::Info> info = channel_receive_->GetSyncInfo();
solenberg3ebbcb52017-01-31 11:58:40312
Niels Möller848d6d32018-08-08 08:49:16313 if (!info)
Danil Chapovalovb9b146c2018-06-15 10:28:07314 return absl::nullopt;
solenberg3ebbcb52017-01-31 11:58:40315
Niels Möller349ade32018-11-16 08:50:42316 info->current_delay_ms = channel_receive_->GetDelayEstimate();
Oskar Sundbom2707fb22017-11-16 09:57:35317 return info;
solenberg3ebbcb52017-01-31 11:58:40318}
319
Åsa Perssonfcf79cc2019-10-22 13:23:44320bool AudioReceiveStream::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
321 int64_t* time_ms) const {
solenberg3ebbcb52017-01-31 11:58:40322 // Called on video capture thread.
Åsa Perssonfcf79cc2019-10-22 13:23:44323 return channel_receive_->GetPlayoutRtpTimestamp(rtp_timestamp, time_ms);
324}
325
326void AudioReceiveStream::SetEstimatedPlayoutNtpTimestampMs(
327 int64_t ntp_timestamp_ms,
328 int64_t time_ms) {
329 // Called on video capture thread.
330 channel_receive_->SetEstimatedPlayoutNtpTimestampMs(ntp_timestamp_ms,
331 time_ms);
solenberg3ebbcb52017-01-31 11:58:40332}
333
334void AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
335 RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
Niels Möller349ade32018-11-16 08:50:42336 return channel_receive_->SetMinimumPlayoutDelay(delay_ms);
pbosa2f30de2015-10-15 12:22:13337}
338
solenberg7602aab2016-11-14 19:30:07339void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) {
solenberg3ebbcb52017-01-31 11:58:40340 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Niels Möller349ade32018-11-16 08:50:42341 channel_receive_->SetAssociatedSendChannel(
342 send_stream ? send_stream->GetChannel() : nullptr);
Fredrik Solenberg8f5787a2018-01-11 12:52:30343 associated_send_stream_ = send_stream;
solenberg7602aab2016-11-14 19:30:07344}
345
Niels Möller8fb1a6a2019-03-05 13:29:42346void AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
pbos1ba8d392016-05-02 03:18:34347 // TODO(solenberg): Tests call this function on a network thread, libjingle
348 // calls on the worker thread. We should move towards always using a network
349 // thread. Then this check can be enabled.
Sebastian Janssonc01367d2019-04-08 13:20:44350 // RTC_DCHECK(!thread_checker_.IsCurrent());
Niels Möller8fb1a6a2019-03-05 13:29:42351 channel_receive_->ReceivedRTCPPacket(packet, length);
pbos1ba8d392016-05-02 03:18:34352}
353
nisse657bab22017-02-21 14:28:10354void AudioReceiveStream::OnRtpPacket(const RtpPacketReceived& packet) {
pbos1ba8d392016-05-02 03:18:34355 // TODO(solenberg): Tests call this function on a network thread, libjingle
356 // calls on the worker thread. We should move towards always using a network
357 // thread. Then this check can be enabled.
Sebastian Janssonc01367d2019-04-08 13:20:44358 // RTC_DCHECK(!thread_checker_.IsCurrent());
Niels Möller349ade32018-11-16 08:50:42359 channel_receive_->OnRtpPacket(packet);
pbos1ba8d392016-05-02 03:18:34360}
361
solenberg3ebbcb52017-01-31 11:58:40362const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const {
363 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
364 return config_;
aleloi04c07222016-11-22 14:42:53365}
366
Yves Gerey665174f2018-06-19 13:03:05367const AudioSendStream* AudioReceiveStream::GetAssociatedSendStreamForTesting()
368 const {
Fredrik Solenberg8f5787a2018-01-11 12:52:30369 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
370 return associated_send_stream_;
Fredrik Solenberg23fba1f2015-04-29 13:24:01371}
aleloi04c07222016-11-22 14:42:53372
solenberg3ebbcb52017-01-31 11:58:40373internal::AudioState* AudioReceiveStream::audio_state() const {
374 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get());
375 RTC_DCHECK(audio_state);
376 return audio_state;
377}
Fredrik Solenberg3b903d02018-01-10 14:17:10378
Fredrik Solenberg3b903d02018-01-10 14:17:10379void AudioReceiveStream::ConfigureStream(AudioReceiveStream* stream,
380 const Config& new_config,
381 bool first_time) {
Jonas Olsson24ea8222018-01-25 09:14:29382 RTC_LOG(LS_INFO) << "AudioReceiveStream::ConfigureStream: "
383 << new_config.ToString();
Fredrik Solenberg3b903d02018-01-10 14:17:10384 RTC_DCHECK(stream);
Niels Möller349ade32018-11-16 08:50:42385 const auto& channel_receive = stream->channel_receive_;
Fredrik Solenberg3b903d02018-01-10 14:17:10386 const auto& old_config = stream->config_;
387
388 // Configuration parameters which cannot be changed.
389 RTC_DCHECK(first_time ||
Fredrik Solenberg3b903d02018-01-10 14:17:10390 old_config.rtp.remote_ssrc == new_config.rtp.remote_ssrc);
391 RTC_DCHECK(first_time ||
392 old_config.rtcp_send_transport == new_config.rtcp_send_transport);
393 // Decoder factory cannot be changed because it is configured at
394 // voe::Channel construction time.
395 RTC_DCHECK(first_time ||
396 old_config.decoder_factory == new_config.decoder_factory);
397
Niels Möller30b48392018-08-15 13:05:26398 if (!first_time) {
Erik Språng70efdde2019-08-21 11:36:20399 // SSRC can't be changed mid-stream.
400 RTC_DCHECK_EQ(old_config.rtp.local_ssrc, new_config.rtp.local_ssrc);
Niels Möllerf7824922018-05-25 11:41:10401 RTC_DCHECK_EQ(old_config.rtp.remote_ssrc, new_config.rtp.remote_ssrc);
402 }
403
Fredrik Solenberg3b903d02018-01-10 14:17:10404 // TODO(solenberg): Config NACK history window (which is a packet count),
405 // using the actual packet size for the configured codec.
406 if (first_time || old_config.rtp.nack.rtp_history_ms !=
407 new_config.rtp.nack.rtp_history_ms) {
Niels Möller349ade32018-11-16 08:50:42408 channel_receive->SetNACKStatus(new_config.rtp.nack.rtp_history_ms != 0,
409 new_config.rtp.nack.rtp_history_ms / 20);
Fredrik Solenberg3b903d02018-01-10 14:17:10410 }
411 if (first_time || old_config.decoder_map != new_config.decoder_map) {
Niels Möller349ade32018-11-16 08:50:42412 channel_receive->SetReceiveCodecs(new_config.decoder_map);
Fredrik Solenberg3b903d02018-01-10 14:17:10413 }
414
Fredrik Solenberg3b903d02018-01-10 14:17:10415 stream->config_ = new_config;
416}
Fredrik Solenberg23fba1f2015-04-29 13:24:01417} // namespace internal
418} // namespace webrtc