| 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 20 matching lines...) Expand all Loading... |
| 114 RTC_DCHECK(registered); | 118 RTC_DCHECK(registered); |
| 115 } else { | 119 } else { |
| 116 RTC_NOTREACHED() << "Unsupported RTP extension."; | 120 RTC_NOTREACHED() << "Unsupported RTP extension."; |
| 117 } | 121 } |
| 118 } | 122 } |
| 119 // Configure bandwidth estimation. | 123 // Configure bandwidth estimation. |
| 120 channel_proxy_->RegisterReceiverCongestionControlObjects(packet_router); | 124 channel_proxy_->RegisterReceiverCongestionControlObjects(packet_router); |
| 121 } | 125 } |
| 122 | 126 |
| 123 AudioReceiveStream::~AudioReceiveStream() { | 127 AudioReceiveStream::~AudioReceiveStream() { |
| 124 RTC_DCHECK_RUN_ON(&thread_checker_); | 128 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 125 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 129 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
| 126 if (playing_) { | 130 if (playing_) { |
| 127 Stop(); | 131 Stop(); |
| 128 } | 132 } |
| 129 channel_proxy_->DisassociateSendChannel(); | 133 channel_proxy_->DisassociateSendChannel(); |
| 130 channel_proxy_->DeRegisterExternalTransport(); | 134 channel_proxy_->DeRegisterExternalTransport(); |
| 131 channel_proxy_->ResetCongestionControlObjects(); | 135 channel_proxy_->ResetCongestionControlObjects(); |
| 132 channel_proxy_->SetRtcEventLog(nullptr); | 136 channel_proxy_->SetRtcEventLog(nullptr); |
| 133 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); | 137 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); |
| 134 } | 138 } |
| 135 | 139 |
| 136 void AudioReceiveStream::Start() { | 140 void AudioReceiveStream::Start() { |
| 137 RTC_DCHECK_RUN_ON(&thread_checker_); | 141 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 138 if (playing_) { | 142 if (playing_) { |
| 139 return; | 143 return; |
| 140 } | 144 } |
| 141 | 145 |
| 142 int error = SetVoiceEnginePlayout(true); | 146 int error = SetVoiceEnginePlayout(true); |
| 143 if (error != 0) { | 147 if (error != 0) { |
| 144 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; | 148 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; |
| 145 return; | 149 return; |
| 146 } | 150 } |
| 147 | 151 |
| 148 if (!audio_state()->mixer()->AddSource(this)) { | 152 if (!audio_state()->mixer()->AddSource(this)) { |
| 149 LOG(LS_ERROR) << "Failed to add source to mixer."; | 153 LOG(LS_ERROR) << "Failed to add source to mixer."; |
| 150 SetVoiceEnginePlayout(false); | 154 SetVoiceEnginePlayout(false); |
| 151 return; | 155 return; |
| 152 } | 156 } |
| 153 | 157 |
| 154 playing_ = true; | 158 playing_ = true; |
| 155 } | 159 } |
| 156 | 160 |
| 157 void AudioReceiveStream::Stop() { | 161 void AudioReceiveStream::Stop() { |
| 158 RTC_DCHECK_RUN_ON(&thread_checker_); | 162 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 159 if (!playing_) { | 163 if (!playing_) { |
| 160 return; | 164 return; |
| 161 } | 165 } |
| 162 playing_ = false; | 166 playing_ = false; |
| 163 | 167 |
| 164 audio_state()->mixer()->RemoveSource(this); | 168 audio_state()->mixer()->RemoveSource(this); |
| 165 SetVoiceEnginePlayout(false); | 169 SetVoiceEnginePlayout(false); |
| 166 } | 170 } |
| 167 | 171 |
| 168 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { | 172 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
| 169 RTC_DCHECK_RUN_ON(&thread_checker_); | 173 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 170 webrtc::AudioReceiveStream::Stats stats; | 174 webrtc::AudioReceiveStream::Stats stats; |
| 171 stats.remote_ssrc = config_.rtp.remote_ssrc; | 175 stats.remote_ssrc = config_.rtp.remote_ssrc; |
| 172 ScopedVoEInterface<VoECodec> codec(voice_engine()); | 176 ScopedVoEInterface<VoECodec> codec(voice_engine()); |
| 173 | 177 |
| 174 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); | 178 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); |
| 175 webrtc::CodecInst codec_inst = {0}; | 179 webrtc::CodecInst codec_inst = {0}; |
| 176 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { | 180 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { |
| 177 return stats; | 181 return stats; |
| 178 } | 182 } |
| 179 | 183 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 209 stats.decoding_normal = ds.decoded_normal; | 213 stats.decoding_normal = ds.decoded_normal; |
| 210 stats.decoding_plc = ds.decoded_plc; | 214 stats.decoding_plc = ds.decoded_plc; |
| 211 stats.decoding_cng = ds.decoded_cng; | 215 stats.decoding_cng = ds.decoded_cng; |
| 212 stats.decoding_plc_cng = ds.decoded_plc_cng; | 216 stats.decoding_plc_cng = ds.decoded_plc_cng; |
| 213 stats.decoding_muted_output = ds.decoded_muted_output; | 217 stats.decoding_muted_output = ds.decoded_muted_output; |
| 214 | 218 |
| 215 return stats; | 219 return stats; |
| 216 } | 220 } |
| 217 | 221 |
| 218 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { | 222 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { |
| 219 RTC_DCHECK_RUN_ON(&thread_checker_); | 223 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 220 channel_proxy_->SetSink(std::move(sink)); | 224 channel_proxy_->SetSink(std::move(sink)); |
| 221 } | 225 } |
| 222 | 226 |
| 223 void AudioReceiveStream::SetGain(float gain) { | 227 void AudioReceiveStream::SetGain(float gain) { |
| 224 RTC_DCHECK_RUN_ON(&thread_checker_); | 228 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 225 channel_proxy_->SetChannelOutputVolumeScaling(gain); | 229 channel_proxy_->SetChannelOutputVolumeScaling(gain); |
| 226 } | 230 } |
| 227 | 231 |
| 228 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { | 232 AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo( |
| 229 RTC_DCHECK_RUN_ON(&thread_checker_); | 233 int sample_rate_hz, |
| 230 return config_; | 234 AudioFrame* audio_frame) { |
| 235 return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame); |
| 236 } |
| 237 |
| 238 int AudioReceiveStream::Ssrc() const { |
| 239 return config_.rtp.remote_ssrc; |
| 240 } |
| 241 |
| 242 int AudioReceiveStream::PreferredSampleRate() const { |
| 243 return channel_proxy_->NeededFrequency(); |
| 244 } |
| 245 |
| 246 int AudioReceiveStream::id() const { |
| 247 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 248 return config_.rtp.remote_ssrc; |
| 249 } |
| 250 |
| 251 rtc::Optional<Syncable::Info> AudioReceiveStream::GetInfo() const { |
| 252 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
| 253 Syncable::Info info; |
| 254 |
| 255 RtpRtcp* rtp_rtcp = nullptr; |
| 256 RtpReceiver* rtp_receiver = nullptr; |
| 257 channel_proxy_->GetRtpRtcp(&rtp_rtcp, &rtp_receiver); |
| 258 RTC_DCHECK(rtp_rtcp); |
| 259 RTC_DCHECK(rtp_receiver); |
| 260 |
| 261 if (!rtp_receiver->Timestamp(&info.latest_receive_timestamp)) { |
| 262 return rtc::Optional<Syncable::Info>(); |
| 263 } |
| 264 if (!rtp_receiver->LastReceivedTimeMs(&info.latest_receive_time_ms)) { |
| 265 return rtc::Optional<Syncable::Info>(); |
| 266 } |
| 267 if (rtp_rtcp->RemoteNTP(&info.ntp_secs, &info.ntp_frac, nullptr, nullptr, |
| 268 &info.rtp_timestamp) != 0) { |
| 269 return rtc::Optional<Syncable::Info>(); |
| 270 } |
| 271 |
| 272 int jitter_buffer_delay_ms = 0; |
| 273 int playout_buffer_delay_ms = 0; |
| 274 channel_proxy_->GetDelayEstimate(&jitter_buffer_delay_ms, |
| 275 &playout_buffer_delay_ms); |
| 276 info.current_delay_ms = jitter_buffer_delay_ms + playout_buffer_delay_ms; |
| 277 return rtc::Optional<Syncable::Info>(info); |
| 278 } |
| 279 |
| 280 uint32_t AudioReceiveStream::GetPlayoutTimestamp() const { |
| 281 // Called on video capture thread. |
| 282 return channel_proxy_->GetPlayoutTimestamp(); |
| 283 } |
| 284 |
| 285 void AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) { |
| 286 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
| 287 return channel_proxy_->SetMinimumPlayoutDelay(delay_ms); |
| 231 } | 288 } |
| 232 | 289 |
| 233 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { | 290 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { |
| 234 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 291 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 235 if (send_stream) { | 292 if (send_stream) { |
| 236 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 293 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
| 237 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = | 294 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = |
| 238 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); | 295 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); |
| 239 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); | 296 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); |
| 240 } else { | 297 } else { |
| 241 channel_proxy_->DisassociateSendChannel(); | 298 channel_proxy_->DisassociateSendChannel(); |
| 242 } | 299 } |
| 243 } | 300 } |
| 244 | 301 |
| 245 void AudioReceiveStream::SignalNetworkState(NetworkState state) { | 302 void AudioReceiveStream::SignalNetworkState(NetworkState state) { |
| 246 RTC_DCHECK_RUN_ON(&thread_checker_); | 303 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 247 } | 304 } |
| 248 | 305 |
| 249 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 306 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 250 // TODO(solenberg): Tests call this function on a network thread, libjingle | 307 // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 251 // calls on the worker thread. We should move towards always using a network | 308 // calls on the worker thread. We should move towards always using a network |
| 252 // thread. Then this check can be enabled. | 309 // thread. Then this check can be enabled. |
| 253 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | 310 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
| 254 return channel_proxy_->ReceivedRTCPPacket(packet, length); | 311 return channel_proxy_->ReceivedRTCPPacket(packet, length); |
| 255 } | 312 } |
| 256 | 313 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 275 if (packet_time.timestamp >= 0) | 332 if (packet_time.timestamp >= 0) |
| 276 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | 333 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
| 277 size_t payload_size = length - header.headerLength; | 334 size_t payload_size = length - header.headerLength; |
| 278 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, | 335 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, |
| 279 header); | 336 header); |
| 280 } | 337 } |
| 281 | 338 |
| 282 return channel_proxy_->ReceivedRTPPacket(packet, length, packet_time); | 339 return channel_proxy_->ReceivedRTPPacket(packet, length, packet_time); |
| 283 } | 340 } |
| 284 | 341 |
| 285 AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo( | 342 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { |
| 286 int sample_rate_hz, | 343 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 287 AudioFrame* audio_frame) { | 344 return config_; |
| 288 return channel_proxy_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame); | |
| 289 } | 345 } |
| 290 | 346 |
| 291 int AudioReceiveStream::PreferredSampleRate() const { | 347 VoiceEngine* AudioReceiveStream::voice_engine() const { |
| 292 return channel_proxy_->NeededFrequency(); | 348 auto* voice_engine = audio_state()->voice_engine(); |
| 293 } | 349 RTC_DCHECK(voice_engine); |
| 294 | 350 return voice_engine; |
| 295 int AudioReceiveStream::Ssrc() const { | |
| 296 return config_.rtp.remote_ssrc; | |
| 297 } | 351 } |
| 298 | 352 |
| 299 internal::AudioState* AudioReceiveStream::audio_state() const { | 353 internal::AudioState* AudioReceiveStream::audio_state() const { |
| 300 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get()); | 354 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get()); |
| 301 RTC_DCHECK(audio_state); | 355 RTC_DCHECK(audio_state); |
| 302 return audio_state; | 356 return audio_state; |
| 303 } | 357 } |
| 304 | 358 |
| 305 VoiceEngine* AudioReceiveStream::voice_engine() const { | |
| 306 auto* voice_engine = audio_state()->voice_engine(); | |
| 307 RTC_DCHECK(voice_engine); | |
| 308 return voice_engine; | |
| 309 } | |
| 310 | |
| 311 int AudioReceiveStream::SetVoiceEnginePlayout(bool playout) { | 359 int AudioReceiveStream::SetVoiceEnginePlayout(bool playout) { |
| 312 ScopedVoEInterface<VoEBase> base(voice_engine()); | 360 ScopedVoEInterface<VoEBase> base(voice_engine()); |
| 313 if (playout) { | 361 if (playout) { |
| 314 return base->StartPlayout(config_.voe_channel_id); | 362 return base->StartPlayout(config_.voe_channel_id); |
| 315 } else { | 363 } else { |
| 316 return base->StopPlayout(config_.voe_channel_id); | 364 return base->StopPlayout(config_.voe_channel_id); |
| 317 } | 365 } |
| 318 } | 366 } |
| 319 | |
| 320 } // namespace internal | 367 } // namespace internal |
| 321 } // namespace webrtc | 368 } // namespace webrtc |
| OLD | NEW |