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/congestion_controller/include/congestion_controller.h" | |
24 #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" |
25 #include "webrtc/voice_engine/channel_proxy.h" | 24 #include "webrtc/voice_engine/channel_proxy.h" |
26 #include "webrtc/voice_engine/include/voe_base.h" | 25 #include "webrtc/voice_engine/include/voe_base.h" |
27 #include "webrtc/voice_engine/include/voe_codec.h" | 26 #include "webrtc/voice_engine/include/voe_codec.h" |
28 #include "webrtc/voice_engine/include/voe_neteq_stats.h" | 27 #include "webrtc/voice_engine/include/voe_neteq_stats.h" |
29 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | 28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
30 #include "webrtc/voice_engine/include/voe_video_sync.h" | 29 #include "webrtc/voice_engine/include/voe_video_sync.h" |
31 #include "webrtc/voice_engine/include/voe_volume_control.h" | 30 #include "webrtc/voice_engine/include/voe_volume_control.h" |
32 #include "webrtc/voice_engine/voice_engine_impl.h" | 31 #include "webrtc/voice_engine/voice_engine_impl.h" |
33 | 32 |
34 namespace webrtc { | 33 namespace webrtc { |
35 namespace { | |
36 | |
37 bool UseSendSideBwe(const webrtc::AudioReceiveStream::Config& config) { | |
38 if (!config.rtp.transport_cc) { | |
39 return false; | |
40 } | |
41 for (const auto& extension : config.rtp.extensions) { | |
42 if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { | |
43 return true; | |
44 } | |
45 } | |
46 return false; | |
47 } | |
48 } // namespace | |
49 | 34 |
50 std::string AudioReceiveStream::Config::Rtp::ToString() const { | 35 std::string AudioReceiveStream::Config::Rtp::ToString() const { |
51 std::stringstream ss; | 36 std::stringstream ss; |
52 ss << "{remote_ssrc: " << remote_ssrc; | 37 ss << "{remote_ssrc: " << remote_ssrc; |
53 ss << ", local_ssrc: " << local_ssrc; | 38 ss << ", local_ssrc: " << local_ssrc; |
54 ss << ", transport_cc: " << (transport_cc ? "on" : "off"); | 39 ss << ", transport_cc: " << (transport_cc ? "on" : "off"); |
55 ss << ", nack: " << nack.ToString(); | 40 ss << ", nack: " << nack.ToString(); |
56 ss << ", extensions: ["; | 41 ss << ", extensions: ["; |
57 for (size_t i = 0; i < extensions.size(); ++i) { | 42 for (size_t i = 0; i < extensions.size(); ++i) { |
58 ss << extensions[i].ToString(); | 43 ss << extensions[i].ToString(); |
(...skipping 14 matching lines...) Expand all Loading... |
73 ss << ", voe_channel_id: " << voe_channel_id; | 58 ss << ", voe_channel_id: " << voe_channel_id; |
74 if (!sync_group.empty()) { | 59 if (!sync_group.empty()) { |
75 ss << ", sync_group: " << sync_group; | 60 ss << ", sync_group: " << sync_group; |
76 } | 61 } |
77 ss << '}'; | 62 ss << '}'; |
78 return ss.str(); | 63 return ss.str(); |
79 } | 64 } |
80 | 65 |
81 namespace internal { | 66 namespace internal { |
82 AudioReceiveStream::AudioReceiveStream( | 67 AudioReceiveStream::AudioReceiveStream( |
83 CongestionController* congestion_controller, | 68 PacketRouter* packet_router, |
| 69 RemoteBitrateEstimator* remote_bitrate_estimator, |
84 const webrtc::AudioReceiveStream::Config& config, | 70 const webrtc::AudioReceiveStream::Config& config, |
85 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 71 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
86 webrtc::RtcEventLog* event_log) | 72 webrtc::RtcEventLog* event_log) |
87 : config_(config), | 73 : remote_bitrate_estimator_(remote_bitrate_estimator), |
| 74 config_(config), |
88 audio_state_(audio_state), | 75 audio_state_(audio_state), |
89 rtp_header_parser_(RtpHeaderParser::Create()) { | 76 rtp_header_parser_(RtpHeaderParser::Create()) { |
90 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); | 77 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); |
91 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 78 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
92 RTC_DCHECK(audio_state_.get()); | 79 RTC_DCHECK(audio_state_.get()); |
93 RTC_DCHECK(congestion_controller); | 80 RTC_DCHECK(packet_router); |
| 81 RTC_DCHECK(remote_bitrate_estimator); |
94 RTC_DCHECK(rtp_header_parser_); | 82 RTC_DCHECK(rtp_header_parser_); |
95 | 83 |
96 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 84 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
97 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 85 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
98 channel_proxy_->SetRtcEventLog(event_log); | 86 channel_proxy_->SetRtcEventLog(event_log); |
99 channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc); | 87 channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc); |
100 // TODO(solenberg): Config NACK history window (which is a packet count), | 88 // TODO(solenberg): Config NACK history window (which is a packet count), |
101 // using the actual packet size for the configured codec. | 89 // using the actual packet size for the configured codec. |
102 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, | 90 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0, |
103 config_.rtp.nack.rtp_history_ms / 20); | 91 config_.rtp.nack.rtp_history_ms / 20); |
(...skipping 18 matching lines...) Expand all Loading... |
122 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { | 110 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
123 channel_proxy_->EnableReceiveTransportSequenceNumber(extension.id); | 111 channel_proxy_->EnableReceiveTransportSequenceNumber(extension.id); |
124 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( | 112 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( |
125 kRtpExtensionTransportSequenceNumber, extension.id); | 113 kRtpExtensionTransportSequenceNumber, extension.id); |
126 RTC_DCHECK(registered); | 114 RTC_DCHECK(registered); |
127 } else { | 115 } else { |
128 RTC_NOTREACHED() << "Unsupported RTP extension."; | 116 RTC_NOTREACHED() << "Unsupported RTP extension."; |
129 } | 117 } |
130 } | 118 } |
131 // Configure bandwidth estimation. | 119 // Configure bandwidth estimation. |
132 channel_proxy_->RegisterReceiverCongestionControlObjects( | 120 channel_proxy_->RegisterReceiverCongestionControlObjects(packet_router); |
133 congestion_controller->packet_router()); | |
134 if (UseSendSideBwe(config)) { | |
135 remote_bitrate_estimator_ = | |
136 congestion_controller->GetRemoteBitrateEstimator(true); | |
137 } | |
138 } | 121 } |
139 | 122 |
140 AudioReceiveStream::~AudioReceiveStream() { | 123 AudioReceiveStream::~AudioReceiveStream() { |
141 RTC_DCHECK_RUN_ON(&thread_checker_); | 124 RTC_DCHECK_RUN_ON(&thread_checker_); |
142 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 125 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
143 if (playing_) { | 126 if (playing_) { |
144 Stop(); | 127 Stop(); |
145 } | 128 } |
146 channel_proxy_->DisassociateSendChannel(); | 129 channel_proxy_->DisassociateSendChannel(); |
147 channel_proxy_->DeRegisterExternalTransport(); | 130 channel_proxy_->DeRegisterExternalTransport(); |
148 channel_proxy_->ResetCongestionControlObjects(); | 131 channel_proxy_->ResetCongestionControlObjects(); |
149 channel_proxy_->SetRtcEventLog(nullptr); | 132 channel_proxy_->SetRtcEventLog(nullptr); |
150 if (remote_bitrate_estimator_) { | 133 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); |
151 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); | |
152 } | |
153 } | 134 } |
154 | 135 |
155 void AudioReceiveStream::Start() { | 136 void AudioReceiveStream::Start() { |
156 RTC_DCHECK_RUN_ON(&thread_checker_); | 137 RTC_DCHECK_RUN_ON(&thread_checker_); |
157 if (playing_) { | 138 if (playing_) { |
158 return; | 139 return; |
159 } | 140 } |
160 | 141 |
161 int error = SetVoiceEnginePlayout(true); | 142 int error = SetVoiceEnginePlayout(true); |
162 if (error != 0) { | 143 if (error != 0) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 // thread. Then this check can be enabled. | 262 // thread. Then this check can be enabled. |
282 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | 263 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
283 RTPHeader header; | 264 RTPHeader header; |
284 if (!rtp_header_parser_->Parse(packet, length, &header)) { | 265 if (!rtp_header_parser_->Parse(packet, length, &header)) { |
285 return false; | 266 return false; |
286 } | 267 } |
287 | 268 |
288 // Only forward if the parsed header has one of the headers necessary for | 269 // Only forward if the parsed header has one of the headers necessary for |
289 // bandwidth estimation. RTP timestamps has different rates for audio and | 270 // bandwidth estimation. RTP timestamps has different rates for audio and |
290 // video and shouldn't be mixed. | 271 // video and shouldn't be mixed. |
291 if (remote_bitrate_estimator_ && | 272 if (config_.rtp.transport_cc && |
292 header.extension.hasTransportSequenceNumber) { | 273 header.extension.hasTransportSequenceNumber) { |
293 int64_t arrival_time_ms = rtc::TimeMillis(); | 274 int64_t arrival_time_ms = rtc::TimeMillis(); |
294 if (packet_time.timestamp >= 0) | 275 if (packet_time.timestamp >= 0) |
295 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | 276 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
296 size_t payload_size = length - header.headerLength; | 277 size_t payload_size = length - header.headerLength; |
297 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, | 278 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, |
298 header); | 279 header); |
299 } | 280 } |
300 | 281 |
301 return channel_proxy_->ReceivedRTPPacket(packet, length, packet_time); | 282 return channel_proxy_->ReceivedRTPPacket(packet, length, packet_time); |
(...skipping 29 matching lines...) Expand all Loading... |
331 ScopedVoEInterface<VoEBase> base(voice_engine()); | 312 ScopedVoEInterface<VoEBase> base(voice_engine()); |
332 if (playout) { | 313 if (playout) { |
333 return base->StartPlayout(config_.voe_channel_id); | 314 return base->StartPlayout(config_.voe_channel_id); |
334 } else { | 315 } else { |
335 return base->StopPlayout(config_.voe_channel_id); | 316 return base->StopPlayout(config_.voe_channel_id); |
336 } | 317 } |
337 } | 318 } |
338 | 319 |
339 } // namespace internal | 320 } // namespace internal |
340 } // namespace webrtc | 321 } // namespace webrtc |
OLD | NEW |