OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/audio/audio_receive_stream.h" | 11 #include "webrtc/audio/audio_receive_stream.h" |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/api/call/audio_sink.h" | 16 #include "webrtc/api/call/audio_sink.h" |
17 #include "webrtc/audio/audio_send_stream.h" | 17 #include "webrtc/audio/audio_send_stream.h" |
18 #include "webrtc/audio/audio_state.h" | 18 #include "webrtc/audio/audio_state.h" |
19 #include "webrtc/audio/conversion.h" | 19 #include "webrtc/audio/conversion.h" |
20 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/timeutils.h" | 22 #include "webrtc/base/timeutils.h" |
23 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 23 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
| 24 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
| 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
24 #include "webrtc/voice_engine/channel_proxy.h" | 26 #include "webrtc/voice_engine/channel_proxy.h" |
25 #include "webrtc/voice_engine/include/voe_base.h" | 27 #include "webrtc/voice_engine/include/voe_base.h" |
26 #include "webrtc/voice_engine/include/voe_codec.h" | 28 #include "webrtc/voice_engine/include/voe_codec.h" |
27 #include "webrtc/voice_engine/include/voe_neteq_stats.h" | 29 #include "webrtc/voice_engine/include/voe_neteq_stats.h" |
28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | 30 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
29 #include "webrtc/voice_engine/include/voe_video_sync.h" | 31 #include "webrtc/voice_engine/include/voe_video_sync.h" |
30 #include "webrtc/voice_engine/include/voe_volume_control.h" | 32 #include "webrtc/voice_engine/include/voe_volume_control.h" |
31 #include "webrtc/voice_engine/voice_engine_impl.h" | 33 #include "webrtc/voice_engine/voice_engine_impl.h" |
32 | 34 |
33 namespace webrtc { | 35 namespace webrtc { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 config_(config), | 76 config_(config), |
75 audio_state_(audio_state), | 77 audio_state_(audio_state), |
76 rtp_header_parser_(RtpHeaderParser::Create()) { | 78 rtp_header_parser_(RtpHeaderParser::Create()) { |
77 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); | 79 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); |
78 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 80 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
79 RTC_DCHECK(audio_state_.get()); | 81 RTC_DCHECK(audio_state_.get()); |
80 RTC_DCHECK(packet_router); | 82 RTC_DCHECK(packet_router); |
81 RTC_DCHECK(remote_bitrate_estimator); | 83 RTC_DCHECK(remote_bitrate_estimator); |
82 RTC_DCHECK(rtp_header_parser_); | 84 RTC_DCHECK(rtp_header_parser_); |
83 | 85 |
| 86 module_process_thread_checker_.DetachFromThread(); |
| 87 |
84 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 88 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
85 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 89 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
86 channel_proxy_->SetRtcEventLog(event_log); | 90 channel_proxy_->SetRtcEventLog(event_log); |
87 channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc); | 91 channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc); |
88 // TODO(solenberg): Config NACK history window (which is a packet count), | 92 // TODO(solenberg): Config NACK history window (which is a packet count), |
89 // using the actual packet size for the configured codec. | 93 // using the actual packet size for the configured codec. |
90 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, | 94 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, |
91 config_.rtp.nack.rtp_history_ms / 20); | 95 config_.rtp.nack.rtp_history_ms / 20); |
92 | 96 |
93 // TODO(ossu): This is where we'd like to set the decoder factory to | 97 // TODO(ossu): This is where we'd like to set the decoder factory to |
(...skipping 24 matching lines...) Expand all Loading... |
118 RTC_DCHECK(registered); | 122 RTC_DCHECK(registered); |
119 } else { | 123 } else { |
120 RTC_NOTREACHED() << "Unsupported RTP extension."; | 124 RTC_NOTREACHED() << "Unsupported RTP extension."; |
121 } | 125 } |
122 } | 126 } |
123 // Configure bandwidth estimation. | 127 // Configure bandwidth estimation. |
124 channel_proxy_->RegisterReceiverCongestionControlObjects(packet_router); | 128 channel_proxy_->RegisterReceiverCongestionControlObjects(packet_router); |
125 } | 129 } |
126 | 130 |
127 AudioReceiveStream::~AudioReceiveStream() { | 131 AudioReceiveStream::~AudioReceiveStream() { |
128 RTC_DCHECK_RUN_ON(&thread_checker_); | 132 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
129 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 133 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
130 if (playing_) { | 134 if (playing_) { |
131 Stop(); | 135 Stop(); |
132 } | 136 } |
133 channel_proxy_->DisassociateSendChannel(); | 137 channel_proxy_->DisassociateSendChannel(); |
134 channel_proxy_->DeRegisterExternalTransport(); | 138 channel_proxy_->DeRegisterExternalTransport(); |
135 channel_proxy_->ResetCongestionControlObjects(); | 139 channel_proxy_->ResetCongestionControlObjects(); |
136 channel_proxy_->SetRtcEventLog(nullptr); | 140 channel_proxy_->SetRtcEventLog(nullptr); |
137 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); | 141 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); |
138 } | 142 } |
139 | 143 |
140 void AudioReceiveStream::Start() { | 144 void AudioReceiveStream::Start() { |
141 RTC_DCHECK_RUN_ON(&thread_checker_); | 145 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
142 if (playing_) { | 146 if (playing_) { |
143 return; | 147 return; |
144 } | 148 } |
145 | 149 |
146 int error = SetVoiceEnginePlayout(true); | 150 int error = SetVoiceEnginePlayout(true); |
147 if (error != 0) { | 151 if (error != 0) { |
148 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; | 152 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; |
149 return; | 153 return; |
150 } | 154 } |
151 | 155 |
152 if (!audio_state()->mixer()->AddSource(this)) { | 156 if (!audio_state()->mixer()->AddSource(this)) { |
153 LOG(LS_ERROR) << "Failed to add source to mixer."; | 157 LOG(LS_ERROR) << "Failed to add source to mixer."; |
154 SetVoiceEnginePlayout(false); | 158 SetVoiceEnginePlayout(false); |
155 return; | 159 return; |
156 } | 160 } |
157 | 161 |
158 playing_ = true; | 162 playing_ = true; |
159 } | 163 } |
160 | 164 |
161 void AudioReceiveStream::Stop() { | 165 void AudioReceiveStream::Stop() { |
162 RTC_DCHECK_RUN_ON(&thread_checker_); | 166 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
163 if (!playing_) { | 167 if (!playing_) { |
164 return; | 168 return; |
165 } | 169 } |
166 playing_ = false; | 170 playing_ = false; |
167 | 171 |
168 audio_state()->mixer()->RemoveSource(this); | 172 audio_state()->mixer()->RemoveSource(this); |
169 SetVoiceEnginePlayout(false); | 173 SetVoiceEnginePlayout(false); |
170 } | 174 } |
171 | 175 |
172 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { | 176 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
173 RTC_DCHECK_RUN_ON(&thread_checker_); | 177 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
174 webrtc::AudioReceiveStream::Stats stats; | 178 webrtc::AudioReceiveStream::Stats stats; |
175 stats.remote_ssrc = config_.rtp.remote_ssrc; | 179 stats.remote_ssrc = config_.rtp.remote_ssrc; |
176 ScopedVoEInterface<VoECodec> codec(voice_engine()); | 180 ScopedVoEInterface<VoECodec> codec(voice_engine()); |
177 | 181 |
178 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); | 182 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); |
179 webrtc::CodecInst codec_inst = {0}; | 183 webrtc::CodecInst codec_inst = {0}; |
180 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { | 184 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { |
181 return stats; | 185 return stats; |
182 } | 186 } |
183 | 187 |
(...skipping 29 matching lines...) Expand all Loading... |
213 stats.decoding_normal = ds.decoded_normal; | 217 stats.decoding_normal = ds.decoded_normal; |
214 stats.decoding_plc = ds.decoded_plc; | 218 stats.decoding_plc = ds.decoded_plc; |
215 stats.decoding_cng = ds.decoded_cng; | 219 stats.decoding_cng = ds.decoded_cng; |
216 stats.decoding_plc_cng = ds.decoded_plc_cng; | 220 stats.decoding_plc_cng = ds.decoded_plc_cng; |
217 stats.decoding_muted_output = ds.decoded_muted_output; | 221 stats.decoding_muted_output = ds.decoded_muted_output; |
218 | 222 |
219 return stats; | 223 return stats; |
220 } | 224 } |
221 | 225 |
222 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { | 226 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { |
223 RTC_DCHECK_RUN_ON(&thread_checker_); | 227 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
224 channel_proxy_->SetSink(std::move(sink)); | 228 channel_proxy_->SetSink(std::move(sink)); |
225 } | 229 } |
226 | 230 |
227 void AudioReceiveStream::SetGain(float gain) { | 231 void AudioReceiveStream::SetGain(float gain) { |
228 RTC_DCHECK_RUN_ON(&thread_checker_); | 232 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
229 channel_proxy_->SetChannelOutputVolumeScaling(gain); | 233 channel_proxy_->SetChannelOutputVolumeScaling(gain); |
230 } | 234 } |
231 | 235 |
232 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { | 236 AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo( |
233 RTC_DCHECK_RUN_ON(&thread_checker_); | 237 int sample_rate_hz, |
234 return config_; | 238 AudioFrame* audio_frame) { |
| 239 return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame); |
| 240 } |
| 241 |
| 242 int AudioReceiveStream::Ssrc() const { |
| 243 return config_.rtp.remote_ssrc; |
| 244 } |
| 245 |
| 246 int AudioReceiveStream::PreferredSampleRate() const { |
| 247 return channel_proxy_->NeededFrequency(); |
| 248 } |
| 249 |
| 250 int AudioReceiveStream::id() const { |
| 251 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 252 return config_.rtp.remote_ssrc; |
| 253 } |
| 254 |
| 255 rtc::Optional<Syncable::Info> AudioReceiveStream::GetInfo() const { |
| 256 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
| 257 Syncable::Info info; |
| 258 |
| 259 RtpRtcp* rtp_rtcp = nullptr; |
| 260 RtpReceiver* rtp_receiver = nullptr; |
| 261 channel_proxy_->GetRtpRtcp(&rtp_rtcp, &rtp_receiver); |
| 262 RTC_DCHECK(rtp_rtcp); |
| 263 RTC_DCHECK(rtp_receiver); |
| 264 |
| 265 if (!rtp_receiver->Timestamp(&info.latest_received_capture_timestamp)) { |
| 266 return rtc::Optional<Syncable::Info>(); |
| 267 } |
| 268 if (!rtp_receiver->LastReceivedTimeMs(&info.latest_receive_time_ms)) { |
| 269 return rtc::Optional<Syncable::Info>(); |
| 270 } |
| 271 if (rtp_rtcp->RemoteNTP(&info.capture_time_ntp_secs, |
| 272 &info.capture_time_ntp_frac, |
| 273 nullptr, |
| 274 nullptr, |
| 275 &info.capture_time_source_clock) != 0) { |
| 276 return rtc::Optional<Syncable::Info>(); |
| 277 } |
| 278 |
| 279 int jitter_buffer_delay_ms = 0; |
| 280 int playout_buffer_delay_ms = 0; |
| 281 channel_proxy_->GetDelayEstimate(&jitter_buffer_delay_ms, |
| 282 &playout_buffer_delay_ms); |
| 283 info.current_delay_ms = jitter_buffer_delay_ms + playout_buffer_delay_ms; |
| 284 return rtc::Optional<Syncable::Info>(info); |
| 285 } |
| 286 |
| 287 uint32_t AudioReceiveStream::GetPlayoutTimestamp() const { |
| 288 // Called on video capture thread. |
| 289 return channel_proxy_->GetPlayoutTimestamp(); |
| 290 } |
| 291 |
| 292 void AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) { |
| 293 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
| 294 return channel_proxy_->SetMinimumPlayoutDelay(delay_ms); |
235 } | 295 } |
236 | 296 |
237 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { | 297 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { |
238 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 298 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
239 if (send_stream) { | 299 if (send_stream) { |
240 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 300 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
241 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = | 301 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = |
242 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); | 302 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); |
243 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); | 303 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); |
244 } else { | 304 } else { |
245 channel_proxy_->DisassociateSendChannel(); | 305 channel_proxy_->DisassociateSendChannel(); |
246 } | 306 } |
247 } | 307 } |
248 | 308 |
249 void AudioReceiveStream::SignalNetworkState(NetworkState state) { | 309 void AudioReceiveStream::SignalNetworkState(NetworkState state) { |
250 RTC_DCHECK_RUN_ON(&thread_checker_); | 310 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
251 } | 311 } |
252 | 312 |
253 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 313 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
254 // TODO(solenberg): Tests call this function on a network thread, libjingle | 314 // TODO(solenberg): Tests call this function on a network thread, libjingle |
255 // calls on the worker thread. We should move towards always using a network | 315 // calls on the worker thread. We should move towards always using a network |
256 // thread. Then this check can be enabled. | 316 // thread. Then this check can be enabled. |
257 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | 317 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
258 return channel_proxy_->ReceivedRTCPPacket(packet, length); | 318 return channel_proxy_->ReceivedRTCPPacket(packet, length); |
259 } | 319 } |
260 | 320 |
(...skipping 18 matching lines...) Expand all Loading... |
279 if (packet_time.timestamp >= 0) | 339 if (packet_time.timestamp >= 0) |
280 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | 340 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
281 size_t payload_size = length - header.headerLength; | 341 size_t payload_size = length - header.headerLength; |
282 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, | 342 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, |
283 header); | 343 header); |
284 } | 344 } |
285 | 345 |
286 return channel_proxy_->ReceivedRTPPacket(packet, length, packet_time); | 346 return channel_proxy_->ReceivedRTPPacket(packet, length, packet_time); |
287 } | 347 } |
288 | 348 |
289 AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo( | 349 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { |
290 int sample_rate_hz, | 350 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
291 AudioFrame* audio_frame) { | 351 return config_; |
292 return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame); | |
293 } | 352 } |
294 | 353 |
295 int AudioReceiveStream::PreferredSampleRate() const { | 354 VoiceEngine* AudioReceiveStream::voice_engine() const { |
296 return channel_proxy_->NeededFrequency(); | 355 auto* voice_engine = audio_state()->voice_engine(); |
297 } | 356 RTC_DCHECK(voice_engine); |
298 | 357 return voice_engine; |
299 int AudioReceiveStream::Ssrc() const { | |
300 return config_.rtp.remote_ssrc; | |
301 } | 358 } |
302 | 359 |
303 internal::AudioState* AudioReceiveStream::audio_state() const { | 360 internal::AudioState* AudioReceiveStream::audio_state() const { |
304 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get()); | 361 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get()); |
305 RTC_DCHECK(audio_state); | 362 RTC_DCHECK(audio_state); |
306 return audio_state; | 363 return audio_state; |
307 } | 364 } |
308 | 365 |
309 VoiceEngine* AudioReceiveStream::voice_engine() const { | |
310 auto* voice_engine = audio_state()->voice_engine(); | |
311 RTC_DCHECK(voice_engine); | |
312 return voice_engine; | |
313 } | |
314 | |
315 int AudioReceiveStream::SetVoiceEnginePlayout(bool playout) { | 366 int AudioReceiveStream::SetVoiceEnginePlayout(bool playout) { |
316 ScopedVoEInterface<VoEBase> base(voice_engine()); | 367 ScopedVoEInterface<VoEBase> base(voice_engine()); |
317 if (playout) { | 368 if (playout) { |
318 return base->StartPlayout(config_.voe_channel_id); | 369 return base->StartPlayout(config_.voe_channel_id); |
319 } else { | 370 } else { |
320 return base->StopPlayout(config_.voe_channel_id); | 371 return base->StopPlayout(config_.voe_channel_id); |
321 } | 372 } |
322 } | 373 } |
323 | |
324 } // namespace internal | 374 } // namespace internal |
325 } // namespace webrtc | 375 } // namespace webrtc |
OLD | NEW |