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

Side by Side Diff: webrtc/modules/pacing/paced_sender.cc

Issue 2182603002: Bitrate prober and paced sender improvements (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Bitrate prober and paced sender improvements Created 4 years, 4 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
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } // namespace paced_sender 243 } // namespace paced_sender
244 244
245 const int64_t PacedSender::kMaxQueueLengthMs = 2000; 245 const int64_t PacedSender::kMaxQueueLengthMs = 2000;
246 const float PacedSender::kDefaultPaceMultiplier = 2.5f; 246 const float PacedSender::kDefaultPaceMultiplier = 2.5f;
247 247
248 PacedSender::PacedSender(Clock* clock, PacketSender* packet_sender) 248 PacedSender::PacedSender(Clock* clock, PacketSender* packet_sender)
249 : clock_(clock), 249 : clock_(clock),
250 packet_sender_(packet_sender), 250 packet_sender_(packet_sender),
251 critsect_(CriticalSectionWrapper::CreateCriticalSection()), 251 critsect_(CriticalSectionWrapper::CreateCriticalSection()),
252 paused_(false), 252 paused_(false),
253 probing_enabled_(true),
254 media_budget_(new paced_sender::IntervalBudget(0)), 253 media_budget_(new paced_sender::IntervalBudget(0)),
255 padding_budget_(new paced_sender::IntervalBudget(0)), 254 padding_budget_(new paced_sender::IntervalBudget(0)),
256 prober_(new BitrateProber()), 255 prober_(new BitrateProber()),
257 estimated_bitrate_bps_(0), 256 estimated_bitrate_bps_(0),
258 min_send_bitrate_kbps_(0u), 257 min_send_bitrate_kbps_(0u),
259 max_padding_bitrate_kbps_(0u), 258 max_padding_bitrate_kbps_(0u),
260 pacing_bitrate_kbps_(0), 259 pacing_bitrate_kbps_(0),
261 time_last_update_us_(clock->TimeInMicroseconds()), 260 time_last_update_us_(clock->TimeInMicroseconds()),
262 packets_(new paced_sender::PacketQueue(clock)), 261 packets_(new paced_sender::PacketQueue(clock)),
263 packet_counter_(0) { 262 packet_counter_(0) {
264 UpdateBytesPerInterval(kMinPacketLimitMs); 263 UpdateBytesPerInterval(kMinPacketLimitMs);
265 } 264 }
266 265
267 PacedSender::~PacedSender() {} 266 PacedSender::~PacedSender() {}
268 267
269 void PacedSender::Pause() { 268 void PacedSender::Pause() {
270 CriticalSectionScoped cs(critsect_.get()); 269 CriticalSectionScoped cs(critsect_.get());
271 paused_ = true; 270 paused_ = true;
272 } 271 }
273 272
274 void PacedSender::Resume() { 273 void PacedSender::Resume() {
275 CriticalSectionScoped cs(critsect_.get()); 274 CriticalSectionScoped cs(critsect_.get());
276 paused_ = false; 275 paused_ = false;
277 } 276 }
278 277
279 void PacedSender::SetProbingEnabled(bool enabled) { 278 void PacedSender::SetProbingEnabled(bool enabled) {
280 RTC_CHECK_EQ(0u, packet_counter_); 279 RTC_CHECK_EQ(0u, packet_counter_);
281 probing_enabled_ = enabled; 280 CriticalSectionScoped cs(critsect_.get());
281 prober_->SetEnabled(enabled);
282 } 282 }
283 283
284 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { 284 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) {
285 CriticalSectionScoped cs(critsect_.get()); 285 CriticalSectionScoped cs(critsect_.get());
286 estimated_bitrate_bps_ = bitrate_bps; 286 estimated_bitrate_bps_ = bitrate_bps;
287 padding_budget_->set_target_rate_kbps( 287 padding_budget_->set_target_rate_kbps(
288 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); 288 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_));
289 pacing_bitrate_kbps_ = 289 pacing_bitrate_kbps_ =
290 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * 290 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) *
291 kDefaultPaceMultiplier; 291 kDefaultPaceMultiplier;
(...skipping 14 matching lines...) Expand all
306 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, 306 void PacedSender::InsertPacket(RtpPacketSender::Priority priority,
307 uint32_t ssrc, 307 uint32_t ssrc,
308 uint16_t sequence_number, 308 uint16_t sequence_number,
309 int64_t capture_time_ms, 309 int64_t capture_time_ms,
310 size_t bytes, 310 size_t bytes,
311 bool retransmission) { 311 bool retransmission) {
312 CriticalSectionScoped cs(critsect_.get()); 312 CriticalSectionScoped cs(critsect_.get());
313 RTC_DCHECK(estimated_bitrate_bps_ > 0) 313 RTC_DCHECK(estimated_bitrate_bps_ > 0)
314 << "SetEstimatedBitrate must be called before InsertPacket."; 314 << "SetEstimatedBitrate must be called before InsertPacket.";
315 315
316 if (probing_enabled_ && !prober_->IsProbing())
317 prober_->SetEnabled(true);
318 int64_t now_ms = clock_->TimeInMilliseconds(); 316 int64_t now_ms = clock_->TimeInMilliseconds();
319 prober_->OnIncomingPacket(estimated_bitrate_bps_, bytes, now_ms); 317 prober_->OnIncomingPacket(estimated_bitrate_bps_, bytes, now_ms);
320 318
321 if (capture_time_ms < 0) 319 if (capture_time_ms < 0)
322 capture_time_ms = now_ms; 320 capture_time_ms = now_ms;
323 321
324 packets_->Push(paced_sender::Packet(priority, ssrc, sequence_number, 322 packets_->Push(paced_sender::Packet(priority, ssrc, sequence_number,
325 capture_time_ms, now_ms, bytes, 323 capture_time_ms, now_ms, bytes,
326 retransmission, packet_counter_++)); 324 retransmission, packet_counter_++));
327 } 325 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; 363 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000;
366 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); 364 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0);
367 } 365 }
368 366
369 void PacedSender::Process() { 367 void PacedSender::Process() {
370 int64_t now_us = clock_->TimeInMicroseconds(); 368 int64_t now_us = clock_->TimeInMicroseconds();
371 CriticalSectionScoped cs(critsect_.get()); 369 CriticalSectionScoped cs(critsect_.get());
372 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; 370 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000;
373 time_last_update_us_ = now_us; 371 time_last_update_us_ = now_us;
374 int target_bitrate_kbps = pacing_bitrate_kbps_; 372 int target_bitrate_kbps = pacing_bitrate_kbps_;
375 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. 373 if (paused_)
376 if (!paused_ && elapsed_time_ms > 0) { 374 return;
375 if (elapsed_time_ms > 0) {
377 size_t queue_size_bytes = packets_->SizeInBytes(); 376 size_t queue_size_bytes = packets_->SizeInBytes();
378 if (queue_size_bytes > 0) { 377 if (queue_size_bytes > 0) {
379 // Assuming equal size packets and input/output rate, the average packet 378 // Assuming equal size packets and input/output rate, the average packet
380 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if 379 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if
381 // time constraint shall be met. Determine bitrate needed for that. 380 // time constraint shall be met. Determine bitrate needed for that.
382 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); 381 packets_->UpdateQueueTime(clock_->TimeInMilliseconds());
383 int64_t avg_time_left_ms = std::max<int64_t>( 382 int64_t avg_time_left_ms = std::max<int64_t>(
384 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); 383 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs());
385 int min_bitrate_needed_kbps = 384 int min_bitrate_needed_kbps =
386 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); 385 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms);
(...skipping 24 matching lines...) Expand all
411 packets_->FinalizePop(packet); 410 packets_->FinalizePop(packet);
412 if (is_probing) 411 if (is_probing)
413 return; 412 return;
414 } else { 413 } else {
415 // Send failed, put it back into the queue. 414 // Send failed, put it back into the queue.
416 packets_->CancelPop(packet); 415 packets_->CancelPop(packet);
417 return; 416 return;
418 } 417 }
419 } 418 }
420 419
421 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. 420 if (!packets_->Empty())
422 if (paused_ || !packets_->Empty())
423 return; 421 return;
424 422
425 // We can not send padding unless a normal packet has first been sent. If we 423 // We can not send padding unless a normal packet has first been sent. If we
426 // do, timestamps get messed up. 424 // do, timestamps get messed up.
427 if (packet_counter_ > 0) { 425 if (packet_counter_ > 0) {
428 size_t padding_needed = is_probing ? prober_->RecommendedPacketSize() 426 size_t padding_needed = is_probing ? prober_->RecommendedPacketSize()
429 : padding_budget_->bytes_remaining(); 427 : padding_budget_->bytes_remaining();
430 428
431 if (padding_needed > 0) 429 if (padding_needed > 0)
432 SendPadding(padding_needed, probe_cluster_id); 430 SendPadding(padding_needed, probe_cluster_id);
433 } 431 }
434 } 432 }
435 433
436 bool PacedSender::SendPacket(const paced_sender::Packet& packet, 434 bool PacedSender::SendPacket(const paced_sender::Packet& packet,
437 int probe_cluster_id) { 435 int probe_cluster_id) {
438 // TODO(holmer): Because of this bug issue 5307 we have to send audio 436 if (paused_)
439 // packets even when the pacer is paused. Here we assume audio packets are
440 // always high priority and that they are the only high priority packets.
441 if (paused_ && packet.priority != kHighPriority)
stefan-webrtc 2016/07/29 07:12:07 If there're still bugs in the network layer code w
Irfan 2016/08/01 18:29:47 ok I will pull the paused changes into a seperate
442 return false; 437 return false;
443 critsect_->Leave(); 438 critsect_->Leave();
444 const bool success = packet_sender_->TimeToSendPacket( 439 const bool success = packet_sender_->TimeToSendPacket(
445 packet.ssrc, packet.sequence_number, packet.capture_time_ms, 440 packet.ssrc, packet.sequence_number, packet.capture_time_ms,
446 packet.retransmission, probe_cluster_id); 441 packet.retransmission, probe_cluster_id);
447 critsect_->Enter(); 442 critsect_->Enter();
448 443
449 if (success) { 444 if (success) {
450 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); 445 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes);
451 // TODO(holmer): High priority packets should only be accounted for if we 446 // TODO(holmer): High priority packets should only be accounted for if we
(...skipping 19 matching lines...) Expand all
471 media_budget_->UseBudget(bytes_sent); 466 media_budget_->UseBudget(bytes_sent);
472 padding_budget_->UseBudget(bytes_sent); 467 padding_budget_->UseBudget(bytes_sent);
473 } 468 }
474 } 469 }
475 470
476 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { 471 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) {
477 media_budget_->IncreaseBudget(delta_time_ms); 472 media_budget_->IncreaseBudget(delta_time_ms);
478 padding_budget_->IncreaseBudget(delta_time_ms); 473 padding_budget_->IncreaseBudget(delta_time_ms);
479 } 474 }
480 } // namespace webrtc 475 } // namespace webrtc
OLDNEW
« webrtc/modules/pacing/bitrate_prober_unittest.cc ('K') | « webrtc/modules/pacing/paced_sender.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698