| 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_send_stream.h" | 11 #include "webrtc/audio/audio_send_stream.h" |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "webrtc/audio/audio_state.h" | 15 #include "webrtc/audio/audio_state.h" |
| 16 #include "webrtc/audio/conversion.h" | 16 #include "webrtc/audio/conversion.h" |
| 17 #include "webrtc/audio/scoped_voe_interface.h" | 17 #include "webrtc/audio/scoped_voe_interface.h" |
| 18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/event.h" | 19 #include "webrtc/base/event.h" |
| 20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/task_queue.h" | 21 #include "webrtc/base/task_queue.h" |
| 22 #include "webrtc/base/timeutils.h" | 22 #include "webrtc/base/timeutils.h" |
| 23 #include "webrtc/call/rtp_transport_controller_send.h" |
| 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 24 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 24 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont
roller.h" | 25 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont
roller.h" |
| 25 #include "webrtc/modules/pacing/paced_sender.h" | 26 #include "webrtc/modules/pacing/paced_sender.h" |
| 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 27 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 27 #include "webrtc/voice_engine/channel_proxy.h" | 28 #include "webrtc/voice_engine/channel_proxy.h" |
| 28 #include "webrtc/voice_engine/include/voe_base.h" | 29 #include "webrtc/voice_engine/include/voe_base.h" |
| 29 #include "webrtc/voice_engine/transmit_mixer.h" | 30 #include "webrtc/voice_engine/transmit_mixer.h" |
| 30 #include "webrtc/voice_engine/voice_engine_impl.h" | 31 #include "webrtc/voice_engine/voice_engine_impl.h" |
| 31 | 32 |
| 32 namespace webrtc { | 33 namespace webrtc { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 namespace internal { | 44 namespace internal { |
| 44 // TODO(elad.alon): Subsequent CL will make these values experiment-dependent. | 45 // TODO(elad.alon): Subsequent CL will make these values experiment-dependent. |
| 45 constexpr size_t kPacketLossTrackerMaxWindowSizeMs = 15000; | 46 constexpr size_t kPacketLossTrackerMaxWindowSizeMs = 15000; |
| 46 constexpr size_t kPacketLossRateMinNumAckedPackets = 50; | 47 constexpr size_t kPacketLossRateMinNumAckedPackets = 50; |
| 47 constexpr size_t kRecoverablePacketLossRateMinNumAckedPairs = 40; | 48 constexpr size_t kRecoverablePacketLossRateMinNumAckedPairs = 40; |
| 48 | 49 |
| 49 AudioSendStream::AudioSendStream( | 50 AudioSendStream::AudioSendStream( |
| 50 const webrtc::AudioSendStream::Config& config, | 51 const webrtc::AudioSendStream::Config& config, |
| 51 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 52 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 52 rtc::TaskQueue* worker_queue, | 53 rtc::TaskQueue* worker_queue, |
| 53 PacketRouter* packet_router, | 54 RtpTransportControllerSendInterface* transport, |
| 54 SendSideCongestionController* send_side_cc, | |
| 55 BitrateAllocator* bitrate_allocator, | 55 BitrateAllocator* bitrate_allocator, |
| 56 RtcEventLog* event_log, | 56 RtcEventLog* event_log, |
| 57 RtcpRttStats* rtcp_rtt_stats) | 57 RtcpRttStats* rtcp_rtt_stats) |
| 58 : worker_queue_(worker_queue), | 58 : worker_queue_(worker_queue), |
| 59 config_(config), | 59 config_(config), |
| 60 audio_state_(audio_state), | 60 audio_state_(audio_state), |
| 61 bitrate_allocator_(bitrate_allocator), | 61 bitrate_allocator_(bitrate_allocator), |
| 62 send_side_cc_(send_side_cc), | 62 transport_(transport), |
| 63 packet_loss_tracker_(kPacketLossTrackerMaxWindowSizeMs, | 63 packet_loss_tracker_(kPacketLossTrackerMaxWindowSizeMs, |
| 64 kPacketLossRateMinNumAckedPackets, | 64 kPacketLossRateMinNumAckedPackets, |
| 65 kRecoverablePacketLossRateMinNumAckedPairs) { | 65 kRecoverablePacketLossRateMinNumAckedPairs) { |
| 66 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 66 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); |
| 67 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 67 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
| 68 RTC_DCHECK(audio_state_.get()); | 68 RTC_DCHECK(audio_state_.get()); |
| 69 RTC_DCHECK(send_side_cc); | 69 RTC_DCHECK(transport); |
| 70 RTC_DCHECK(transport->send_side_cc()); |
| 70 | 71 |
| 71 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 72 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
| 72 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 73 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
| 73 channel_proxy_->SetRtcEventLog(event_log); | 74 channel_proxy_->SetRtcEventLog(event_log); |
| 74 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats); | 75 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats); |
| 75 channel_proxy_->SetRTCPStatus(true); | 76 channel_proxy_->SetRTCPStatus(true); |
| 76 channel_proxy_->SetLocalSSRC(config.rtp.ssrc); | 77 channel_proxy_->SetLocalSSRC(config.rtp.ssrc); |
| 77 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name); | 78 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name); |
| 78 // TODO(solenberg): Config NACK history window (which is a packet count), | 79 // TODO(solenberg): Config NACK history window (which is a packet count), |
| 79 // using the actual packet size for the configured codec. | 80 // using the actual packet size for the configured codec. |
| 80 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, | 81 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, |
| 81 config_.rtp.nack.rtp_history_ms / 20); | 82 config_.rtp.nack.rtp_history_ms / 20); |
| 82 | 83 |
| 83 channel_proxy_->RegisterExternalTransport(config.send_transport); | 84 channel_proxy_->RegisterExternalTransport(config.send_transport); |
| 84 send_side_cc_->RegisterPacketFeedbackObserver(this); | 85 transport_->send_side_cc()->RegisterPacketFeedbackObserver(this); |
| 85 | 86 |
| 86 for (const auto& extension : config.rtp.extensions) { | 87 for (const auto& extension : config.rtp.extensions) { |
| 87 if (extension.uri == RtpExtension::kAudioLevelUri) { | 88 if (extension.uri == RtpExtension::kAudioLevelUri) { |
| 88 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); | 89 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); |
| 89 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { | 90 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
| 90 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); | 91 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); |
| 91 send_side_cc->EnablePeriodicAlrProbing(true); | 92 transport->send_side_cc()->EnablePeriodicAlrProbing(true); |
| 92 bandwidth_observer_.reset( | 93 bandwidth_observer_.reset(transport->send_side_cc() |
| 93 send_side_cc->GetBitrateController()->CreateRtcpBandwidthObserver()); | 94 ->GetBitrateController() |
| 95 ->CreateRtcpBandwidthObserver()); |
| 94 } else { | 96 } else { |
| 95 RTC_NOTREACHED() << "Registering unsupported RTP extension."; | 97 RTC_NOTREACHED() << "Registering unsupported RTP extension."; |
| 96 } | 98 } |
| 97 } | 99 } |
| 98 channel_proxy_->RegisterSenderCongestionControlObjects( | 100 channel_proxy_->RegisterSenderCongestionControlObjects( |
| 99 send_side_cc->pacer(), send_side_cc, packet_router, | 101 transport, bandwidth_observer_.get()); |
| 100 bandwidth_observer_.get()); | |
| 101 if (!SetupSendCodec()) { | 102 if (!SetupSendCodec()) { |
| 102 LOG(LS_ERROR) << "Failed to set up send codec state."; | 103 LOG(LS_ERROR) << "Failed to set up send codec state."; |
| 103 } | 104 } |
| 104 | 105 |
| 105 pacer_thread_checker_.DetachFromThread(); | 106 pacer_thread_checker_.DetachFromThread(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 AudioSendStream::~AudioSendStream() { | 109 AudioSendStream::~AudioSendStream() { |
| 109 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 110 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 110 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 111 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
| 111 send_side_cc_->DeRegisterPacketFeedbackObserver(this); | 112 transport_->send_side_cc()->DeRegisterPacketFeedbackObserver(this); |
| 112 channel_proxy_->DeRegisterExternalTransport(); | 113 channel_proxy_->DeRegisterExternalTransport(); |
| 113 channel_proxy_->ResetCongestionControlObjects(); | 114 channel_proxy_->ResetCongestionControlObjects(); |
| 114 channel_proxy_->SetRtcEventLog(nullptr); | 115 channel_proxy_->SetRtcEventLog(nullptr); |
| 115 channel_proxy_->SetRtcpRttStats(nullptr); | 116 channel_proxy_->SetRtcpRttStats(nullptr); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void AudioSendStream::Start() { | 119 void AudioSendStream::Start() { |
| 119 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 120 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 120 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { | 121 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { |
| 121 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); | 122 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 296 } |
| 296 } | 297 } |
| 297 | 298 |
| 298 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { | 299 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { |
| 299 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 300 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 300 return config_; | 301 return config_; |
| 301 } | 302 } |
| 302 | 303 |
| 303 void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) { | 304 void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) { |
| 304 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 305 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 305 send_side_cc_->SetTransportOverhead(transport_overhead_per_packet); | 306 transport_->send_side_cc()->SetTransportOverhead( |
| 307 transport_overhead_per_packet); |
| 306 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet); | 308 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet); |
| 307 } | 309 } |
| 308 | 310 |
| 309 VoiceEngine* AudioSendStream::voice_engine() const { | 311 VoiceEngine* AudioSendStream::voice_engine() const { |
| 310 internal::AudioState* audio_state = | 312 internal::AudioState* audio_state = |
| 311 static_cast<internal::AudioState*>(audio_state_.get()); | 313 static_cast<internal::AudioState*>(audio_state_.get()); |
| 312 VoiceEngine* voice_engine = audio_state->voice_engine(); | 314 VoiceEngine* voice_engine = audio_state->voice_engine(); |
| 313 RTC_DCHECK(voice_engine); | 315 RTC_DCHECK(voice_engine); |
| 314 return voice_engine; | 316 return voice_engine; |
| 315 } | 317 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 LOG(LS_WARNING) << "SetVADStatus() failed."; | 423 LOG(LS_WARNING) << "SetVADStatus() failed."; |
| 422 return false; | 424 return false; |
| 423 } | 425 } |
| 424 } | 426 } |
| 425 } | 427 } |
| 426 return true; | 428 return true; |
| 427 } | 429 } |
| 428 | 430 |
| 429 } // namespace internal | 431 } // namespace internal |
| 430 } // namespace webrtc | 432 } // namespace webrtc |
| OLD | NEW |