| 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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 constexpr char kOpusCodecName[] = "opus"; | 35 constexpr char kOpusCodecName[] = "opus"; |
| 36 | 36 |
| 37 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { | 37 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { |
| 38 return (STR_CASE_CMP(codec.plname, ref_name) == 0); | 38 return (STR_CASE_CMP(codec.plname, ref_name) == 0); |
| 39 } | 39 } |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 namespace internal { | 42 namespace internal { |
| 43 // TODO(elad.alon): Subsequent CL will make these values experiment-dependent. |
| 44 constexpr size_t kPacketLossTrackerMaxWindowSizeMs = 15000; |
| 45 constexpr size_t kPlrMinNumAckedPackets = 50; |
| 46 constexpr size_t kRplrMinNumAckedPairs = 40; |
| 47 |
| 43 AudioSendStream::AudioSendStream( | 48 AudioSendStream::AudioSendStream( |
| 44 const webrtc::AudioSendStream::Config& config, | 49 const webrtc::AudioSendStream::Config& config, |
| 45 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 50 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 46 rtc::TaskQueue* worker_queue, | 51 rtc::TaskQueue* worker_queue, |
| 47 PacketRouter* packet_router, | 52 PacketRouter* packet_router, |
| 48 CongestionController* congestion_controller, | 53 CongestionController* congestion_controller, |
| 49 BitrateAllocator* bitrate_allocator, | 54 BitrateAllocator* bitrate_allocator, |
| 50 RtcEventLog* event_log, | 55 RtcEventLog* event_log, |
| 51 RtcpRttStats* rtcp_rtt_stats) | 56 RtcpRttStats* rtcp_rtt_stats) |
| 52 : worker_queue_(worker_queue), | 57 : clock_(Clock::GetRealTimeClock()), |
| 58 worker_queue_(worker_queue), |
| 53 config_(config), | 59 config_(config), |
| 54 audio_state_(audio_state), | 60 audio_state_(audio_state), |
| 55 bitrate_allocator_(bitrate_allocator), | 61 bitrate_allocator_(bitrate_allocator), |
| 56 congestion_controller_(congestion_controller) { | 62 congestion_controller_(congestion_controller), |
| 63 packet_loss_tracker_(kPacketLossTrackerMaxWindowSizeMs, |
| 64 kPlrMinNumAckedPackets, |
| 65 kRplrMinNumAckedPairs) { |
| 57 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 66 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); |
| 58 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 67 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
| 59 RTC_DCHECK(audio_state_.get()); | 68 RTC_DCHECK(audio_state_.get()); |
| 60 RTC_DCHECK(congestion_controller); | 69 RTC_DCHECK(congestion_controller); |
| 61 | 70 |
| 62 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 71 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
| 63 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 72 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
| 64 channel_proxy_->SetRtcEventLog(event_log); | 73 channel_proxy_->SetRtcEventLog(event_log); |
| 65 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats); | 74 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats); |
| 66 channel_proxy_->SetRTCPStatus(true); | 75 channel_proxy_->SetRTCPStatus(true); |
| 67 channel_proxy_->SetLocalSSRC(config.rtp.ssrc); | 76 channel_proxy_->SetLocalSSRC(config.rtp.ssrc); |
| 68 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name); | 77 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name); |
| 69 // TODO(solenberg): Config NACK history window (which is a packet count), | 78 // TODO(solenberg): Config NACK history window (which is a packet count), |
| 70 // using the actual packet size for the configured codec. | 79 // using the actual packet size for the configured codec. |
| 71 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, | 80 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, |
| 72 config_.rtp.nack.rtp_history_ms / 20); | 81 config_.rtp.nack.rtp_history_ms / 20); |
| 73 | 82 |
| 74 channel_proxy_->RegisterExternalTransport(config.send_transport); | 83 channel_proxy_->RegisterExternalTransport(config.send_transport); |
| 84 congestion_controller_->RegisterTransportFeedbackAdapterObserver(this); |
| 75 | 85 |
| 76 for (const auto& extension : config.rtp.extensions) { | 86 for (const auto& extension : config.rtp.extensions) { |
| 77 if (extension.uri == RtpExtension::kAudioLevelUri) { | 87 if (extension.uri == RtpExtension::kAudioLevelUri) { |
| 78 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); | 88 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); |
| 79 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { | 89 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
| 80 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); | 90 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); |
| 81 congestion_controller->EnablePeriodicAlrProbing(true); | 91 congestion_controller->EnablePeriodicAlrProbing(true); |
| 82 bandwidth_observer_.reset(congestion_controller->GetBitrateController() | 92 bandwidth_observer_.reset(congestion_controller->GetBitrateController() |
| 83 ->CreateRtcpBandwidthObserver()); | 93 ->CreateRtcpBandwidthObserver()); |
| 84 } else { | 94 } else { |
| 85 RTC_NOTREACHED() << "Registering unsupported RTP extension."; | 95 RTC_NOTREACHED() << "Registering unsupported RTP extension."; |
| 86 } | 96 } |
| 87 } | 97 } |
| 88 channel_proxy_->RegisterSenderCongestionControlObjects( | 98 channel_proxy_->RegisterSenderCongestionControlObjects( |
| 89 congestion_controller->pacer(), congestion_controller, packet_router, | 99 congestion_controller->pacer(), congestion_controller, packet_router, |
| 90 bandwidth_observer_.get()); | 100 bandwidth_observer_.get()); |
| 91 if (!SetupSendCodec()) { | 101 if (!SetupSendCodec()) { |
| 92 LOG(LS_ERROR) << "Failed to set up send codec state."; | 102 LOG(LS_ERROR) << "Failed to set up send codec state."; |
| 93 } | 103 } |
| 94 } | 104 } |
| 95 | 105 |
| 96 AudioSendStream::~AudioSendStream() { | 106 AudioSendStream::~AudioSendStream() { |
| 97 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 107 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 98 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 108 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
| 109 congestion_controller_->DeRegisterTransportFeedbackAdapterObserver(this); |
| 99 channel_proxy_->DeRegisterExternalTransport(); | 110 channel_proxy_->DeRegisterExternalTransport(); |
| 100 channel_proxy_->ResetCongestionControlObjects(); | 111 channel_proxy_->ResetCongestionControlObjects(); |
| 101 channel_proxy_->SetRtcEventLog(nullptr); | 112 channel_proxy_->SetRtcEventLog(nullptr); |
| 102 channel_proxy_->SetRtcpRttStats(nullptr); | 113 channel_proxy_->SetRtcpRttStats(nullptr); |
| 103 } | 114 } |
| 104 | 115 |
| 105 void AudioSendStream::Start() { | 116 void AudioSendStream::Start() { |
| 106 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 117 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 107 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { | 118 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { |
| 108 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); | 119 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (bitrate_bps > max_bitrate_bps) | 251 if (bitrate_bps > max_bitrate_bps) |
| 241 bitrate_bps = max_bitrate_bps; | 252 bitrate_bps = max_bitrate_bps; |
| 242 | 253 |
| 243 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); | 254 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); |
| 244 | 255 |
| 245 // The amount of audio protection is not exposed by the encoder, hence | 256 // The amount of audio protection is not exposed by the encoder, hence |
| 246 // always returning 0. | 257 // always returning 0. |
| 247 return 0; | 258 return 0; |
| 248 } | 259 } |
| 249 | 260 |
| 261 void AudioSendStream::OnPacketAdded(uint32_t ssrc, uint16_t seq_num) { |
| 262 // Only packets that belong to this stream are of interest. |
| 263 if (ssrc == config_.rtp.ssrc) { |
| 264 rtc::CritScope lock(&packet_loss_tracker_cs_); |
| 265 packet_loss_tracker_.OnPacketAdded(seq_num, clock_->TimeInMilliseconds()); |
| 266 } |
| 267 } |
| 268 |
| 269 void AudioSendStream::OnNewTransportFeedbacks( |
| 270 const std::vector<PacketFeedback>& packet_feedbacks) { |
| 271 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 272 rtc::CritScope lock(&packet_loss_tracker_cs_); |
| 273 packet_loss_tracker_.OnNewTransportFeedbacks(packet_feedbacks); |
| 274 channel_proxy_->OnTwccBasedUplinkPacketLossRate( |
| 275 packet_loss_tracker_.GetPacketLossRate()); |
| 276 } |
| 277 |
| 250 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { | 278 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { |
| 251 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 279 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 252 return config_; | 280 return config_; |
| 253 } | 281 } |
| 254 | 282 |
| 255 void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) { | 283 void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) { |
| 256 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 284 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 257 congestion_controller_->SetTransportOverhead(transport_overhead_per_packet); | 285 congestion_controller_->SetTransportOverhead(transport_overhead_per_packet); |
| 258 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet); | 286 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet); |
| 259 } | 287 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 LOG(LS_WARNING) << "SetVADStatus() failed."; | 401 LOG(LS_WARNING) << "SetVADStatus() failed."; |
| 374 return false; | 402 return false; |
| 375 } | 403 } |
| 376 } | 404 } |
| 377 } | 405 } |
| 378 return true; | 406 return true; |
| 379 } | 407 } |
| 380 | 408 |
| 381 } // namespace internal | 409 } // namespace internal |
| 382 } // namespace webrtc | 410 } // namespace webrtc |
| OLD | NEW |