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 #include <vector> |
| 15 #include <utility> |
14 | 16 |
15 #include "webrtc/audio/audio_state.h" | 17 #include "webrtc/audio/audio_state.h" |
16 #include "webrtc/audio/conversion.h" | 18 #include "webrtc/audio/conversion.h" |
17 #include "webrtc/audio/scoped_voe_interface.h" | 19 #include "webrtc/audio/scoped_voe_interface.h" |
18 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/event.h" | 21 #include "webrtc/base/event.h" |
20 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
| 23 #include "webrtc/base/mod_ops.h" |
21 #include "webrtc/base/task_queue.h" | 24 #include "webrtc/base/task_queue.h" |
22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 25 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
23 #include "webrtc/modules/pacing/paced_sender.h" | 26 #include "webrtc/modules/pacing/paced_sender.h" |
24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 27 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
25 #include "webrtc/voice_engine/channel_proxy.h" | 28 #include "webrtc/voice_engine/channel_proxy.h" |
26 #include "webrtc/voice_engine/include/voe_audio_processing.h" | 29 #include "webrtc/voice_engine/include/voe_audio_processing.h" |
27 #include "webrtc/voice_engine/include/voe_codec.h" | 30 #include "webrtc/voice_engine/include/voe_codec.h" |
28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | 31 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
29 #include "webrtc/voice_engine/include/voe_volume_control.h" | 32 #include "webrtc/voice_engine/include/voe_volume_control.h" |
30 #include "webrtc/voice_engine/voice_engine_impl.h" | 33 #include "webrtc/voice_engine/voice_engine_impl.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 congestion_controller->GetTransportFeedbackObserver(), packet_router); | 72 congestion_controller->GetTransportFeedbackObserver(), packet_router); |
70 channel_proxy_->SetRTCPStatus(true); | 73 channel_proxy_->SetRTCPStatus(true); |
71 channel_proxy_->SetLocalSSRC(config.rtp.ssrc); | 74 channel_proxy_->SetLocalSSRC(config.rtp.ssrc); |
72 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name); | 75 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name); |
73 // TODO(solenberg): Config NACK history window (which is a packet count), | 76 // TODO(solenberg): Config NACK history window (which is a packet count), |
74 // using the actual packet size for the configured codec. | 77 // using the actual packet size for the configured codec. |
75 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, | 78 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, |
76 config_.rtp.nack.rtp_history_ms / 20); | 79 config_.rtp.nack.rtp_history_ms / 20); |
77 | 80 |
78 channel_proxy_->RegisterExternalTransport(config.send_transport); | 81 channel_proxy_->RegisterExternalTransport(config.send_transport); |
| 82 congestion_controller_->RegisterTransportFeedbackAdapterObserver(this); |
79 | 83 |
80 for (const auto& extension : config.rtp.extensions) { | 84 for (const auto& extension : config.rtp.extensions) { |
81 if (extension.uri == RtpExtension::kAudioLevelUri) { | 85 if (extension.uri == RtpExtension::kAudioLevelUri) { |
82 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); | 86 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); |
83 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { | 87 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
84 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); | 88 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); |
85 congestion_controller->EnablePeriodicAlrProbing(true); | 89 congestion_controller->EnablePeriodicAlrProbing(true); |
86 } else { | 90 } else { |
87 RTC_NOTREACHED() << "Registering unsupported RTP extension."; | 91 RTC_NOTREACHED() << "Registering unsupported RTP extension."; |
88 } | 92 } |
89 } | 93 } |
90 if (!SetupSendCodec()) { | 94 if (!SetupSendCodec()) { |
91 LOG(LS_ERROR) << "Failed to set up send codec state."; | 95 LOG(LS_ERROR) << "Failed to set up send codec state."; |
92 } | 96 } |
93 } | 97 } |
94 | 98 |
95 AudioSendStream::~AudioSendStream() { | 99 AudioSendStream::~AudioSendStream() { |
96 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 100 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
97 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 101 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
| 102 congestion_controller_->DeRegisterTransportFeedbackAdapterObserver(this); |
98 channel_proxy_->DeRegisterExternalTransport(); | 103 channel_proxy_->DeRegisterExternalTransport(); |
99 channel_proxy_->ResetCongestionControlObjects(); | 104 channel_proxy_->ResetCongestionControlObjects(); |
100 channel_proxy_->SetRtcEventLog(nullptr); | 105 channel_proxy_->SetRtcEventLog(nullptr); |
101 channel_proxy_->SetRtcpRttStats(nullptr); | 106 channel_proxy_->SetRtcpRttStats(nullptr); |
102 } | 107 } |
103 | 108 |
104 void AudioSendStream::Start() { | 109 void AudioSendStream::Start() { |
105 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 110 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
106 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { | 111 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { |
107 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); | 112 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 if (bitrate_bps > max_bitrate_bps) | 251 if (bitrate_bps > max_bitrate_bps) |
247 bitrate_bps = max_bitrate_bps; | 252 bitrate_bps = max_bitrate_bps; |
248 | 253 |
249 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); | 254 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); |
250 | 255 |
251 // 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 |
252 // always returning 0. | 257 // always returning 0. |
253 return 0; | 258 return 0; |
254 } | 259 } |
255 | 260 |
| 261 void AudioSendStream::OnPacketAdded(uint32_t ssrc, |
| 262 uint16_t transport_sequence_number) { |
| 263 if (ssrc != config_.rtp.ssrc) |
| 264 return; |
| 265 |
| 266 // To make sure everything happens on the same thread, we'll buffer |
| 267 // this information and pass it down with the first OnTransportFeedback, |
| 268 // which is called on the thread which channel_proxy_ mostly works on. |
| 269 rtc::CritScope lock(&packets_sent_since_last_feedback_cs_); |
| 270 |
| 271 // Prevent unbounded memory consumption if OnTransportFeedback ends up |
| 272 // never being called. Messages which are 0x8000 (or more) sequence numbers |
| 273 // away from the newest message will end up having no effect, so we can |
| 274 // discard those. |
| 275 if (!packets_sent_since_last_feedback_.empty() && |
| 276 ForwardDiff(packets_sent_since_last_feedback_[0], |
| 277 transport_sequence_number) >= 0x8000) { |
| 278 // The element are ordered (circularly), so we can batch-remove. No need |
| 279 // for binary search, because we expect to usually find the edge in the |
| 280 // beginning of the container. |
| 281 auto it = packets_sent_since_last_feedback_.cbegin(); |
| 282 while (it != packets_sent_since_last_feedback_.cend() && |
| 283 ForwardDiff(*it, transport_sequence_number) >= 0x8000) { |
| 284 ++it; |
| 285 } |
| 286 packets_sent_since_last_feedback_.erase( |
| 287 packets_sent_since_last_feedback_.cbegin(), it); |
| 288 } |
| 289 |
| 290 packets_sent_since_last_feedback_.push_back(transport_sequence_number); |
| 291 } |
| 292 |
| 293 void AudioSendStream::OnTransportFeedback( |
| 294 const rtcp::TransportFeedback& feedback) { |
| 295 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 296 std::vector<uint16_t> packets_sent_since_last_feedback; |
| 297 { |
| 298 rtc::CritScope lock(&packets_sent_since_last_feedback_cs_); |
| 299 std::swap(packets_sent_since_last_feedback_, |
| 300 packets_sent_since_last_feedback); |
| 301 } |
| 302 channel_proxy_->HandleTransportFeedback( |
| 303 packets_sent_since_last_feedback, feedback); |
| 304 } |
| 305 |
256 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { | 306 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { |
257 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 307 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
258 return config_; | 308 return config_; |
259 } | 309 } |
260 | 310 |
261 void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) { | 311 void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) { |
262 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 312 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
263 congestion_controller_->SetTransportOverhead(transport_overhead_per_packet); | 313 congestion_controller_->SetTransportOverhead(transport_overhead_per_packet); |
264 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet); | 314 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet); |
265 } | 315 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError(); | 436 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError(); |
387 return false; | 437 return false; |
388 } | 438 } |
389 } | 439 } |
390 } | 440 } |
391 return true; | 441 return true; |
392 } | 442 } |
393 | 443 |
394 } // namespace internal | 444 } // namespace internal |
395 } // namespace webrtc | 445 } // namespace webrtc |
OLD | NEW |