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 <utility> | |
15 #include <vector> | |
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/bitrate_controller/include/bitrate_controller.h" | 25 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 26 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
24 #include "webrtc/modules/pacing/paced_sender.h" | 27 #include "webrtc/modules/pacing/paced_sender.h" |
25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 28 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
26 #include "webrtc/voice_engine/channel_proxy.h" | 29 #include "webrtc/voice_engine/channel_proxy.h" |
27 #include "webrtc/voice_engine/include/voe_base.h" | 30 #include "webrtc/voice_engine/include/voe_base.h" |
28 #include "webrtc/voice_engine/transmit_mixer.h" | 31 #include "webrtc/voice_engine/transmit_mixer.h" |
29 #include "webrtc/voice_engine/voice_engine_impl.h" | 32 #include "webrtc/voice_engine/voice_engine_impl.h" |
30 | 33 |
(...skipping 11 matching lines...) Expand all Loading... | |
42 namespace internal { | 45 namespace internal { |
43 AudioSendStream::AudioSendStream( | 46 AudioSendStream::AudioSendStream( |
44 const webrtc::AudioSendStream::Config& config, | 47 const webrtc::AudioSendStream::Config& config, |
45 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 48 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
46 rtc::TaskQueue* worker_queue, | 49 rtc::TaskQueue* worker_queue, |
47 PacketRouter* packet_router, | 50 PacketRouter* packet_router, |
48 CongestionController* congestion_controller, | 51 CongestionController* congestion_controller, |
49 BitrateAllocator* bitrate_allocator, | 52 BitrateAllocator* bitrate_allocator, |
50 RtcEventLog* event_log, | 53 RtcEventLog* event_log, |
51 RtcpRttStats* rtcp_rtt_stats) | 54 RtcpRttStats* rtcp_rtt_stats) |
52 : worker_queue_(worker_queue), | 55 : clock_(Clock::GetRealTimeClock()), |
56 worker_queue_(worker_queue), | |
53 config_(config), | 57 config_(config), |
54 audio_state_(audio_state), | 58 audio_state_(audio_state), |
55 bitrate_allocator_(bitrate_allocator), | 59 bitrate_allocator_(bitrate_allocator), |
56 congestion_controller_(congestion_controller) { | 60 congestion_controller_(congestion_controller) { |
57 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 61 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); |
58 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 62 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
59 RTC_DCHECK(audio_state_.get()); | 63 RTC_DCHECK(audio_state_.get()); |
60 RTC_DCHECK(congestion_controller); | 64 RTC_DCHECK(congestion_controller); |
61 | 65 |
62 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 66 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
63 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 67 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
64 channel_proxy_->SetRtcEventLog(event_log); | 68 channel_proxy_->SetRtcEventLog(event_log); |
65 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats); | 69 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats); |
66 channel_proxy_->SetRTCPStatus(true); | 70 channel_proxy_->SetRTCPStatus(true); |
67 channel_proxy_->SetLocalSSRC(config.rtp.ssrc); | 71 channel_proxy_->SetLocalSSRC(config.rtp.ssrc); |
68 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name); | 72 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name); |
69 // TODO(solenberg): Config NACK history window (which is a packet count), | 73 // TODO(solenberg): Config NACK history window (which is a packet count), |
70 // using the actual packet size for the configured codec. | 74 // using the actual packet size for the configured codec. |
71 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, | 75 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, |
72 config_.rtp.nack.rtp_history_ms / 20); | 76 config_.rtp.nack.rtp_history_ms / 20); |
73 | 77 |
74 channel_proxy_->RegisterExternalTransport(config.send_transport); | 78 channel_proxy_->RegisterExternalTransport(config.send_transport); |
79 congestion_controller_->RegisterTransportFeedbackAdapterObserver(this); | |
75 | 80 |
76 for (const auto& extension : config.rtp.extensions) { | 81 for (const auto& extension : config.rtp.extensions) { |
77 if (extension.uri == RtpExtension::kAudioLevelUri) { | 82 if (extension.uri == RtpExtension::kAudioLevelUri) { |
78 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); | 83 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); |
79 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { | 84 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
80 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); | 85 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); |
81 congestion_controller->EnablePeriodicAlrProbing(true); | 86 congestion_controller->EnablePeriodicAlrProbing(true); |
82 bandwidth_observer_.reset(congestion_controller->GetBitrateController() | 87 bandwidth_observer_.reset(congestion_controller->GetBitrateController() |
83 ->CreateRtcpBandwidthObserver()); | 88 ->CreateRtcpBandwidthObserver()); |
84 } else { | 89 } else { |
85 RTC_NOTREACHED() << "Registering unsupported RTP extension."; | 90 RTC_NOTREACHED() << "Registering unsupported RTP extension."; |
86 } | 91 } |
87 } | 92 } |
88 channel_proxy_->RegisterSenderCongestionControlObjects( | 93 channel_proxy_->RegisterSenderCongestionControlObjects( |
89 congestion_controller->pacer(), congestion_controller, packet_router, | 94 congestion_controller->pacer(), congestion_controller, packet_router, |
90 bandwidth_observer_.get()); | 95 bandwidth_observer_.get()); |
91 if (!SetupSendCodec()) { | 96 if (!SetupSendCodec()) { |
92 LOG(LS_ERROR) << "Failed to set up send codec state."; | 97 LOG(LS_ERROR) << "Failed to set up send codec state."; |
93 } | 98 } |
94 } | 99 } |
95 | 100 |
96 AudioSendStream::~AudioSendStream() { | 101 AudioSendStream::~AudioSendStream() { |
97 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 102 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
98 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 103 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
104 congestion_controller_->DeRegisterTransportFeedbackAdapterObserver(this); | |
99 channel_proxy_->DeRegisterExternalTransport(); | 105 channel_proxy_->DeRegisterExternalTransport(); |
100 channel_proxy_->ResetCongestionControlObjects(); | 106 channel_proxy_->ResetCongestionControlObjects(); |
101 channel_proxy_->SetRtcEventLog(nullptr); | 107 channel_proxy_->SetRtcEventLog(nullptr); |
102 channel_proxy_->SetRtcpRttStats(nullptr); | 108 channel_proxy_->SetRtcpRttStats(nullptr); |
103 } | 109 } |
104 | 110 |
105 void AudioSendStream::Start() { | 111 void AudioSendStream::Start() { |
106 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 112 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
107 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { | 113 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { |
108 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); | 114 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) | 246 if (bitrate_bps > max_bitrate_bps) |
241 bitrate_bps = max_bitrate_bps; | 247 bitrate_bps = max_bitrate_bps; |
242 | 248 |
243 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); | 249 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); |
244 | 250 |
245 // The amount of audio protection is not exposed by the encoder, hence | 251 // The amount of audio protection is not exposed by the encoder, hence |
246 // always returning 0. | 252 // always returning 0. |
247 return 0; | 253 return 0; |
248 } | 254 } |
249 | 255 |
256 void AudioSendStream::OnPacketAdded(uint32_t ssrc, uint16_t seq_num) { | |
257 if (ssrc != config_.rtp.ssrc) | |
258 return; | |
259 | |
260 const int64_t sent_time_ms = clock_->TimeInMilliseconds(); | |
261 | |
262 // To make sure everything happens on the same thread, we'll buffer | |
263 // this information and pass it down with the first OnTransportFeedback, | |
264 // which is called on the thread which channel_proxy_ mostly works on. | |
minyue-webrtc
2017/03/15 10:54:13
second "which" -> that
elad.alon_webrtc.org
2017/03/16 18:37:35
This code no longer exists after the redesign.
| |
265 rtc::CritScope lock(&packets_sent_since_last_feedback_cs_); | |
266 | |
267 // Prevent unbounded memory consumption if OnTransportFeedback ends up | |
minyue-webrtc
2017/03/15 10:54:13
I think this may be better taken care inside the p
elad.alon_webrtc.org
2017/03/16 18:37:34
No longer relevant after redesign, but for posteri
| |
268 // never being called. Messages which are 0x8000 (or more) sequence numbers | |
269 // away from the newest message will end up having no effect, so we can | |
270 // discard those. | |
271 if (!packets_sent_since_last_feedback_.empty() && | |
272 (packets_sent_since_last_feedback_[0].sequence_number == seq_num || | |
273 ForwardDiff(packets_sent_since_last_feedback_[0].sequence_number, | |
274 seq_num) >= 0x8000)) { | |
275 // The element are ordered (circularly), so we can batch-remove. No need | |
276 // for binary search, because we expect to usually find the edge in the | |
277 // beginning of the container. | |
278 auto it = packets_sent_since_last_feedback_.cbegin(); | |
279 while (it != packets_sent_since_last_feedback_.cend() && | |
280 (it->sequence_number == seq_num || | |
281 ForwardDiff(it->sequence_number, seq_num) >= 0x8000)) { | |
282 ++it; | |
283 } | |
284 packets_sent_since_last_feedback_.erase( | |
285 packets_sent_since_last_feedback_.cbegin(), it); | |
286 } | |
287 | |
288 packets_sent_since_last_feedback_.emplace_back( | |
289 SentTransportPacketRecord{seq_num, sent_time_ms}); | |
290 } | |
291 | |
292 void AudioSendStream::OnTransportFeedback( | |
293 const rtcp::TransportFeedback& feedback) { | |
294 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
295 std::vector<SentTransportPacketRecord> packets_sent_since_last_feedback; | |
296 { | |
297 rtc::CritScope lock(&packets_sent_since_last_feedback_cs_); | |
298 std::swap(packets_sent_since_last_feedback_, | |
299 packets_sent_since_last_feedback); | |
300 } | |
301 channel_proxy_->HandleTransportFeedback(packets_sent_since_last_feedback, | |
302 feedback); | |
303 } | |
304 | |
250 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { | 305 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { |
251 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 306 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
252 return config_; | 307 return config_; |
253 } | 308 } |
254 | 309 |
255 void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) { | 310 void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) { |
256 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 311 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
257 congestion_controller_->SetTransportOverhead(transport_overhead_per_packet); | 312 congestion_controller_->SetTransportOverhead(transport_overhead_per_packet); |
258 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet); | 313 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet); |
259 } | 314 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 LOG(LS_WARNING) << "SetVADStatus() failed."; | 428 LOG(LS_WARNING) << "SetVADStatus() failed."; |
374 return false; | 429 return false; |
375 } | 430 } |
376 } | 431 } |
377 } | 432 } |
378 return true; | 433 return true; |
379 } | 434 } |
380 | 435 |
381 } // namespace internal | 436 } // namespace internal |
382 } // namespace webrtc | 437 } // namespace webrtc |
OLD | NEW |