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

Side by Side Diff: webrtc/video_engine/vie_channel_group.cc

Issue 1338203003: Wire up send-side bandwidth estimation. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/video_engine/vie_channel_group.h" 11 #include "webrtc/video_engine/vie_channel_group.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/thread_annotations.h" 14 #include "webrtc/base/thread_annotations.h"
15 #include "webrtc/common.h" 15 #include "webrtc/common.h"
16 #include "webrtc/modules/pacing/include/paced_sender.h" 16 #include "webrtc/modules/pacing/include/paced_sender.h"
17 #include "webrtc/modules/pacing/include/packet_router.h" 17 #include "webrtc/modules/pacing/include/packet_router.h"
18 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" 18 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
19 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" 19 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h"
20 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" 20 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h"
21 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h"
21 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h" 22 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h"
22 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" 23 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
23 #include "webrtc/modules/utility/interface/process_thread.h" 24 #include "webrtc/modules/utility/interface/process_thread.h"
24 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 25 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
25 #include "webrtc/system_wrappers/interface/logging.h" 26 #include "webrtc/system_wrappers/interface/logging.h"
26 #include "webrtc/video_engine/call_stats.h" 27 #include "webrtc/video_engine/call_stats.h"
27 #include "webrtc/video_engine/encoder_state_feedback.h" 28 #include "webrtc/video_engine/encoder_state_feedback.h"
28 #include "webrtc/video_engine/payload_router.h" 29 #include "webrtc/video_engine/payload_router.h"
29 #include "webrtc/video_engine/vie_channel.h" 30 #include "webrtc/video_engine/vie_channel.h"
30 #include "webrtc/video_engine/vie_encoder.h" 31 #include "webrtc/video_engine/vie_encoder.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 PacedSender::kDefaultPaceMultiplier * 154 PacedSender::kDefaultPaceMultiplier *
154 BitrateController::kDefaultStartBitrateKbps, 155 BitrateController::kDefaultStartBitrateKbps,
155 0)), 156 0)),
156 process_thread_(process_thread), 157 process_thread_(process_thread),
157 pacer_thread_(ProcessThread::Create("PacerThread")), 158 pacer_thread_(ProcessThread::Create("PacerThread")),
158 // Constructed last as this object calls the provided callback on 159 // Constructed last as this object calls the provided callback on
159 // construction. 160 // construction.
160 bitrate_controller_( 161 bitrate_controller_(
161 BitrateController::CreateBitrateController(Clock::GetRealTimeClock(), 162 BitrateController::CreateBitrateController(Clock::GetRealTimeClock(),
162 this)) { 163 this)) {
163 remote_bitrate_estimator_.reset(new WrappingBitrateEstimator( 164 Clock* clock = Clock::GetRealTimeClock();
164 remb_.get(), Clock::GetRealTimeClock())); 165 remote_bitrate_estimator_.reset(
166 new WrappingBitrateEstimator(remb_.get(), clock));
167 remote_estimator_proxy_.reset(
168 new RemoteEstimatorProxy(clock, packet_router_.get()));
165 169
166 call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get()); 170 call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get());
167 171
168 pacer_thread_->RegisterModule(pacer_.get()); 172 pacer_thread_->RegisterModule(pacer_.get());
169 pacer_thread_->Start(); 173 pacer_thread_->Start();
170 174
175 process_thread->RegisterModule(remote_estimator_proxy_.get());
171 process_thread->RegisterModule(remote_bitrate_estimator_.get()); 176 process_thread->RegisterModule(remote_bitrate_estimator_.get());
172 process_thread->RegisterModule(call_stats_.get()); 177 process_thread->RegisterModule(call_stats_.get());
173 process_thread->RegisterModule(bitrate_controller_.get()); 178 process_thread->RegisterModule(bitrate_controller_.get());
174 } 179 }
175 180
176 ChannelGroup::~ChannelGroup() { 181 ChannelGroup::~ChannelGroup() {
177 pacer_thread_->Stop(); 182 pacer_thread_->Stop();
178 pacer_thread_->DeRegisterModule(pacer_.get()); 183 pacer_thread_->DeRegisterModule(pacer_.get());
179 process_thread_->DeRegisterModule(bitrate_controller_.get()); 184 process_thread_->DeRegisterModule(bitrate_controller_.get());
180 process_thread_->DeRegisterModule(call_stats_.get()); 185 process_thread_->DeRegisterModule(call_stats_.get());
181 process_thread_->DeRegisterModule(remote_bitrate_estimator_.get()); 186 process_thread_->DeRegisterModule(remote_bitrate_estimator_.get());
187 process_thread_->DeRegisterModule(remote_estimator_proxy_.get());
182 call_stats_->DeregisterStatsObserver(remote_bitrate_estimator_.get()); 188 call_stats_->DeregisterStatsObserver(remote_bitrate_estimator_.get());
189 if (transport_feedback_adapter_.get())
190 call_stats_->DeregisterStatsObserver(transport_feedback_adapter_.get());
183 DCHECK(channel_map_.empty()); 191 DCHECK(channel_map_.empty());
184 DCHECK(!remb_->InUse()); 192 DCHECK(!remb_->InUse());
185 DCHECK(vie_encoder_map_.empty()); 193 DCHECK(vie_encoder_map_.empty());
186 } 194 }
187 195
188 bool ChannelGroup::CreateSendChannel(int channel_id, 196 bool ChannelGroup::CreateSendChannel(int channel_id,
189 int engine_id, 197 int engine_id,
190 Transport* transport, 198 Transport* transport,
191 int number_of_cores, 199 int number_of_cores,
192 const std::vector<uint32_t>& ssrcs) { 200 const VideoSendStream::Config& config) {
201 TransportFeedbackObserver* transport_feedback_observer = nullptr;
202 bool transport_seq_enabled = false;
203 for (const RtpExtension& extension : config.rtp.extensions) {
204 if (extension.name == RtpExtension::kTransportSequenceNumber) {
205 transport_seq_enabled = true;
206 break;
207 }
208 }
209 if (transport_seq_enabled) {
210 if (transport_feedback_adapter_.get() == nullptr) {
211 transport_feedback_adapter_.reset(new TransportFeedbackAdapter(
212 bitrate_controller_->CreateRtcpBandwidthObserver(),
213 Clock::GetRealTimeClock(), process_thread_));
214 transport_feedback_adapter_->SetBitrateEstimator(
215 new RemoteBitrateEstimatorAbsSendTime(
216 transport_feedback_adapter_.get(), Clock::GetRealTimeClock(),
217 RemoteBitrateEstimator::kDefaultMinBitrateBps));
218 call_stats_->RegisterStatsObserver(transport_feedback_adapter_.get());
219 }
220 transport_feedback_observer = transport_feedback_adapter_.get();
221 }
193 // TODO(pbos): Remove checks for empty ssrcs and add this check when there's 222 // TODO(pbos): Remove checks for empty ssrcs and add this check when there's
194 // no base channel. 223 // no base channel.
195 // DCHECK(!ssrcs.empty()); 224 // DCHECK(!ssrcs.empty());
196 rtc::scoped_ptr<ViEEncoder> vie_encoder(new ViEEncoder( 225 rtc::scoped_ptr<ViEEncoder> vie_encoder(new ViEEncoder(
197 channel_id, number_of_cores, *process_thread_, pacer_.get(), 226 channel_id, number_of_cores, *process_thread_, pacer_.get(),
198 bitrate_allocator_.get(), bitrate_controller_.get(), false)); 227 bitrate_allocator_.get(), bitrate_controller_.get(), false));
199 if (!vie_encoder->Init()) { 228 if (!vie_encoder->Init()) {
200 return false; 229 return false;
201 } 230 }
231 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs;
202 ViEEncoder* encoder = vie_encoder.get(); 232 ViEEncoder* encoder = vie_encoder.get();
203 if (!CreateChannel(channel_id, engine_id, transport, number_of_cores, 233 if (!CreateChannel(channel_id, engine_id, transport, number_of_cores,
204 vie_encoder.release(), ssrcs.empty() ? 1 : ssrcs.size(), 234 vie_encoder.release(), ssrcs.empty() ? 1 : ssrcs.size(),
205 true)) { 235 true, remote_bitrate_estimator_.get(),
236 transport_feedback_observer)) {
206 return false; 237 return false;
207 } 238 }
208 ViEChannel* channel = channel_map_[channel_id]; 239 ViEChannel* channel = channel_map_[channel_id];
209 // Connect the encoder with the send packet router, to enable sending. 240 // Connect the encoder with the send packet router, to enable sending.
210 encoder->StartThreadsAndSetSharedMembers(channel->send_payload_router(), 241 encoder->StartThreadsAndSetSharedMembers(channel->send_payload_router(),
211 channel->vcm_protection_callback()); 242 channel->vcm_protection_callback());
212 243
213 if (!ssrcs.empty()) { 244 if (!ssrcs.empty()) {
214 encoder_state_feedback_->AddEncoder(ssrcs, encoder); 245 encoder_state_feedback_->AddEncoder(ssrcs, encoder);
215 std::vector<uint32_t> first_ssrc(1, ssrcs[0]); 246 std::vector<uint32_t> first_ssrc(1, ssrcs[0]);
216 encoder->SetSsrcs(first_ssrc); 247 encoder->SetSsrcs(first_ssrc);
217 } 248 }
218 return true; 249 return true;
219 } 250 }
220 251
221 bool ChannelGroup::CreateReceiveChannel(int channel_id, 252 bool ChannelGroup::CreateReceiveChannel(
222 int engine_id, 253 int channel_id,
223 Transport* transport, 254 int engine_id,
224 int number_of_cores) { 255 Transport* transport,
256 int number_of_cores,
257 const VideoReceiveStream::Config& config) {
258 RemoteBitrateEstimator* bitrate_estimator;
259 TransportFeedbackObserver* feedback_observer;
260 bool send_side_bwe = false;
261 for (const RtpExtension& extension : config.rtp.extensions) {
262 if (extension.name == RtpExtension::kTransportSequenceNumber) {
263 send_side_bwe = true;
264 break;
265 }
266 }
267
268 if (send_side_bwe) {
269 bitrate_estimator = remote_estimator_proxy_.get();
270 feedback_observer = transport_feedback_adapter_.get();
stefan-webrtc 2015/09/17 10:33:19 Why do we have something observing feedback on the
sprang_webrtc 2015/09/17 15:08:28 Oops, copy/paste error.
271 } else {
272 bitrate_estimator = remote_bitrate_estimator_.get();
273 feedback_observer = nullptr;
274 }
225 return CreateChannel(channel_id, engine_id, transport, number_of_cores, 275 return CreateChannel(channel_id, engine_id, transport, number_of_cores,
226 nullptr, 1, false); 276 nullptr, 1, false, bitrate_estimator, feedback_observer);
227 } 277 }
228 278
229 bool ChannelGroup::CreateChannel(int channel_id, 279 bool ChannelGroup::CreateChannel(int channel_id,
230 int engine_id, 280 int engine_id,
231 Transport* transport, 281 Transport* transport,
232 int number_of_cores, 282 int number_of_cores,
233 ViEEncoder* vie_encoder, 283 ViEEncoder* vie_encoder,
234 size_t max_rtp_streams, 284 size_t max_rtp_streams,
235 bool sender) { 285 bool sender,
286 RemoteBitrateEstimator* bitrate_estimator,
287 TransportFeedbackObserver* feedback_observer) {
236 rtc::scoped_ptr<ViEChannel> channel(new ViEChannel( 288 rtc::scoped_ptr<ViEChannel> channel(new ViEChannel(
237 channel_id, engine_id, number_of_cores, transport, process_thread_, 289 channel_id, engine_id, number_of_cores, transport, process_thread_,
238 encoder_state_feedback_->GetRtcpIntraFrameObserver(), 290 encoder_state_feedback_->GetRtcpIntraFrameObserver(),
239 bitrate_controller_->CreateRtcpBandwidthObserver(), nullptr, 291 bitrate_controller_->CreateRtcpBandwidthObserver(), feedback_observer,
240 remote_bitrate_estimator_.get(), call_stats_->rtcp_rtt_stats(), 292 bitrate_estimator, call_stats_->rtcp_rtt_stats(), pacer_.get(),
241 pacer_.get(), packet_router_.get(), max_rtp_streams, sender)); 293 packet_router_.get(), max_rtp_streams, sender));
242 if (channel->Init() != 0) { 294 if (channel->Init() != 0) {
243 return false; 295 return false;
244 } 296 }
245 297
246 // Register the channel to receive stats updates. 298 // Register the channel to receive stats updates.
247 call_stats_->RegisterStatsObserver(channel->GetStatsObserver()); 299 call_stats_->RegisterStatsObserver(channel->GetStatsObserver());
248 300
249 // Store the channel, add it to the channel group and save the vie_encoder. 301 // Store the channel, add it to the channel group and save the vie_encoder.
250 channel_map_[channel_id] = channel.release(); 302 channel_map_[channel_id] = channel.release();
251 if (vie_encoder) { 303 if (vie_encoder) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 rtc::CritScope lock(&encoder_map_crit_); 420 rtc::CritScope lock(&encoder_map_crit_);
369 for (const auto& encoder : vie_encoder_map_) 421 for (const auto& encoder : vie_encoder_map_)
370 pad_up_to_bitrate_bps += encoder.second->GetPaddingNeededBps(); 422 pad_up_to_bitrate_bps += encoder.second->GetPaddingNeededBps();
371 } 423 }
372 pacer_->UpdateBitrate( 424 pacer_->UpdateBitrate(
373 target_bitrate_bps / 1000, 425 target_bitrate_bps / 1000,
374 PacedSender::kDefaultPaceMultiplier * target_bitrate_bps / 1000, 426 PacedSender::kDefaultPaceMultiplier * target_bitrate_bps / 1000,
375 pad_up_to_bitrate_bps / 1000); 427 pad_up_to_bitrate_bps / 1000);
376 } 428 }
377 } // namespace webrtc 429 } // namespace webrtc
OLDNEW
« webrtc/video/rampup_tests.cc ('K') | « webrtc/video_engine/vie_channel_group.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698