Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(969)

Side by Side Diff: webrtc/audio/audio_receive_stream.cc

Issue 1535963002: Wire-up BWE feedback for audio receive streams. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comment addressed. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/audio/audio_receive_stream.h ('k') | webrtc/audio/audio_receive_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/audio/audio_sink.h" 16 #include "webrtc/audio/audio_sink.h"
17 #include "webrtc/audio/audio_state.h" 17 #include "webrtc/audio/audio_state.h"
18 #include "webrtc/audio/conversion.h" 18 #include "webrtc/audio/conversion.h"
19 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
20 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
21 #include "webrtc/call/congestion_controller.h"
21 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" 22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h"
22 #include "webrtc/system_wrappers/include/tick_util.h" 23 #include "webrtc/system_wrappers/include/tick_util.h"
23 #include "webrtc/voice_engine/channel_proxy.h" 24 #include "webrtc/voice_engine/channel_proxy.h"
24 #include "webrtc/voice_engine/include/voe_base.h" 25 #include "webrtc/voice_engine/include/voe_base.h"
25 #include "webrtc/voice_engine/include/voe_codec.h" 26 #include "webrtc/voice_engine/include/voe_codec.h"
26 #include "webrtc/voice_engine/include/voe_neteq_stats.h" 27 #include "webrtc/voice_engine/include/voe_neteq_stats.h"
27 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" 28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
28 #include "webrtc/voice_engine/include/voe_video_sync.h" 29 #include "webrtc/voice_engine/include/voe_video_sync.h"
29 #include "webrtc/voice_engine/include/voe_volume_control.h" 30 #include "webrtc/voice_engine/include/voe_volume_control.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 {
34 namespace {
35
36 bool UseSendSideBwe(const webrtc::AudioReceiveStream::Config& config) {
37 if (!config.rtp.transport_cc) {
38 return false;
39 }
40 for (const auto& extension : config.rtp.extensions) {
41 if (extension.name == RtpExtension::kTransportSequenceNumber) {
42 return true;
43 }
44 }
45 return false;
46 }
47 } // namespace
48
33 std::string AudioReceiveStream::Config::Rtp::ToString() const { 49 std::string AudioReceiveStream::Config::Rtp::ToString() const {
34 std::stringstream ss; 50 std::stringstream ss;
35 ss << "{remote_ssrc: " << remote_ssrc; 51 ss << "{remote_ssrc: " << remote_ssrc;
36 ss << ", local_ssrc: " << local_ssrc; 52 ss << ", local_ssrc: " << local_ssrc;
37 ss << ", extensions: ["; 53 ss << ", extensions: [";
38 for (size_t i = 0; i < extensions.size(); ++i) { 54 for (size_t i = 0; i < extensions.size(); ++i) {
39 ss << extensions[i].ToString(); 55 ss << extensions[i].ToString();
40 if (i != extensions.size() - 1) { 56 if (i != extensions.size() - 1) {
41 ss << ", "; 57 ss << ", ";
42 } 58 }
(...skipping 15 matching lines...) Expand all
58 ss << ", sync_group: " << sync_group; 74 ss << ", sync_group: " << sync_group;
59 } 75 }
60 ss << ", combined_audio_video_bwe: " 76 ss << ", combined_audio_video_bwe: "
61 << (combined_audio_video_bwe ? "true" : "false"); 77 << (combined_audio_video_bwe ? "true" : "false");
62 ss << '}'; 78 ss << '}';
63 return ss.str(); 79 return ss.str();
64 } 80 }
65 81
66 namespace internal { 82 namespace internal {
67 AudioReceiveStream::AudioReceiveStream( 83 AudioReceiveStream::AudioReceiveStream(
68 RemoteBitrateEstimator* remote_bitrate_estimator, 84 CongestionController* congestion_controller,
69 const webrtc::AudioReceiveStream::Config& config, 85 const webrtc::AudioReceiveStream::Config& config,
70 const rtc::scoped_refptr<webrtc::AudioState>& audio_state) 86 const rtc::scoped_refptr<webrtc::AudioState>& audio_state)
71 : remote_bitrate_estimator_(remote_bitrate_estimator), 87 : config_(config),
72 config_(config),
73 audio_state_(audio_state), 88 audio_state_(audio_state),
74 rtp_header_parser_(RtpHeaderParser::Create()) { 89 rtp_header_parser_(RtpHeaderParser::Create()) {
75 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); 90 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString();
76 RTC_DCHECK_NE(config_.voe_channel_id, -1); 91 RTC_DCHECK_NE(config_.voe_channel_id, -1);
77 RTC_DCHECK(remote_bitrate_estimator_);
78 RTC_DCHECK(audio_state_.get()); 92 RTC_DCHECK(audio_state_.get());
93 RTC_DCHECK(congestion_controller);
79 RTC_DCHECK(rtp_header_parser_); 94 RTC_DCHECK(rtp_header_parser_);
80 95
81 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); 96 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine());
82 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); 97 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id);
83 channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc); 98 channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc);
84 for (const auto& extension : config.rtp.extensions) { 99 for (const auto& extension : config.rtp.extensions) {
85 if (extension.name == RtpExtension::kAudioLevel) { 100 if (extension.name == RtpExtension::kAudioLevel) {
86 channel_proxy_->SetReceiveAudioLevelIndicationStatus(true, extension.id); 101 channel_proxy_->SetReceiveAudioLevelIndicationStatus(true, extension.id);
87 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( 102 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension(
88 kRtpExtensionAudioLevel, extension.id); 103 kRtpExtensionAudioLevel, extension.id);
89 RTC_DCHECK(registered); 104 RTC_DCHECK(registered);
90 } else if (extension.name == RtpExtension::kAbsSendTime) { 105 } else if (extension.name == RtpExtension::kAbsSendTime) {
91 channel_proxy_->SetReceiveAbsoluteSenderTimeStatus(true, extension.id); 106 channel_proxy_->SetReceiveAbsoluteSenderTimeStatus(true, extension.id);
92 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( 107 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension(
93 kRtpExtensionAbsoluteSendTime, extension.id); 108 kRtpExtensionAbsoluteSendTime, extension.id);
94 RTC_DCHECK(registered); 109 RTC_DCHECK(registered);
95 } else if (extension.name == RtpExtension::kTransportSequenceNumber) { 110 } else if (extension.name == RtpExtension::kTransportSequenceNumber) {
96 // TODO(holmer): Need to do something here or in DeliverRtp() to actually
97 // handle audio packets with this header extension.
98 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( 111 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension(
99 kRtpExtensionTransportSequenceNumber, extension.id); 112 kRtpExtensionTransportSequenceNumber, extension.id);
100 RTC_DCHECK(registered); 113 RTC_DCHECK(registered);
101 } else { 114 } else {
102 RTC_NOTREACHED() << "Unsupported RTP extension."; 115 RTC_NOTREACHED() << "Unsupported RTP extension.";
103 } 116 }
104 } 117 }
118 // Configure bandwidth estimation.
119 channel_proxy_->SetCongestionControlObjects(
120 nullptr, nullptr, congestion_controller->packet_router());
121 if (config.combined_audio_video_bwe) {
122 if (UseSendSideBwe(config)) {
123 remote_bitrate_estimator_ =
124 congestion_controller->GetRemoteBitrateEstimator(true);
125 } else {
126 remote_bitrate_estimator_ =
127 congestion_controller->GetRemoteBitrateEstimator(false);
128 }
129 RTC_DCHECK(remote_bitrate_estimator_);
130 }
105 } 131 }
106 132
107 AudioReceiveStream::~AudioReceiveStream() { 133 AudioReceiveStream::~AudioReceiveStream() {
108 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 134 RTC_DCHECK(thread_checker_.CalledOnValidThread());
109 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); 135 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString();
136 channel_proxy_->SetCongestionControlObjects(nullptr, nullptr, nullptr);
137 if (remote_bitrate_estimator_) {
138 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc);
139 }
110 } 140 }
111 141
112 void AudioReceiveStream::Start() { 142 void AudioReceiveStream::Start() {
113 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 143 RTC_DCHECK(thread_checker_.CalledOnValidThread());
114 } 144 }
115 145
116 void AudioReceiveStream::Stop() { 146 void AudioReceiveStream::Stop() {
117 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 147 RTC_DCHECK(thread_checker_.CalledOnValidThread());
118 } 148 }
119 149
(...skipping 14 matching lines...) Expand all
134 const PacketTime& packet_time) { 164 const PacketTime& packet_time) {
135 // TODO(solenberg): Tests call this function on a network thread, libjingle 165 // TODO(solenberg): Tests call this function on a network thread, libjingle
136 // calls on the worker thread. We should move towards always using a network 166 // calls on the worker thread. We should move towards always using a network
137 // thread. Then this check can be enabled. 167 // thread. Then this check can be enabled.
138 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); 168 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
139 RTPHeader header; 169 RTPHeader header;
140 if (!rtp_header_parser_->Parse(packet, length, &header)) { 170 if (!rtp_header_parser_->Parse(packet, length, &header)) {
141 return false; 171 return false;
142 } 172 }
143 173
144 // Only forward if the parsed header has absolute sender time. RTP timestamps 174 // Only forward if the parsed header has one of the headers necessary for
145 // may have different rates for audio and video and shouldn't be mixed. 175 // bandwidth estimation. RTP timestamps has different rates for audio and
146 if (config_.combined_audio_video_bwe && 176 // video and shouldn't be mixed.
147 header.extension.hasAbsoluteSendTime) { 177 if (remote_bitrate_estimator_ &&
178 (header.extension.hasAbsoluteSendTime ||
179 header.extension.hasTransportSequenceNumber)) {
148 int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); 180 int64_t arrival_time_ms = TickTime::MillisecondTimestamp();
149 if (packet_time.timestamp >= 0) 181 if (packet_time.timestamp >= 0)
150 arrival_time_ms = (packet_time.timestamp + 500) / 1000; 182 arrival_time_ms = (packet_time.timestamp + 500) / 1000;
151 size_t payload_size = length - header.headerLength; 183 size_t payload_size = length - header.headerLength;
152 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, 184 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size,
153 header, false); 185 header, false);
154 } 186 }
155 return true; 187 return true;
156 } 188 }
157 189
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 247
216 VoiceEngine* AudioReceiveStream::voice_engine() const { 248 VoiceEngine* AudioReceiveStream::voice_engine() const {
217 internal::AudioState* audio_state = 249 internal::AudioState* audio_state =
218 static_cast<internal::AudioState*>(audio_state_.get()); 250 static_cast<internal::AudioState*>(audio_state_.get());
219 VoiceEngine* voice_engine = audio_state->voice_engine(); 251 VoiceEngine* voice_engine = audio_state->voice_engine();
220 RTC_DCHECK(voice_engine); 252 RTC_DCHECK(voice_engine);
221 return voice_engine; 253 return voice_engine;
222 } 254 }
223 } // namespace internal 255 } // namespace internal
224 } // namespace webrtc 256 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/audio/audio_receive_stream.h ('k') | webrtc/audio/audio_receive_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698