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

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

Issue 2193183003: Send audio packets immediately instead of pacing them. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove debug printf 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
« no previous file with comments | « no previous file | webrtc/modules/pacing/paced_sender_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) 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 pacing_bitrate_kbps_(0), 260 pacing_bitrate_kbps_(0),
261 time_last_update_us_(clock->TimeInMicroseconds()), 261 time_last_update_us_(clock->TimeInMicroseconds()),
262 packets_(new paced_sender::PacketQueue(clock)), 262 packets_(new paced_sender::PacketQueue(clock)),
263 packet_counter_(0) { 263 packet_counter_(0) {
264 UpdateBytesPerInterval(kMinPacketLimitMs); 264 UpdateBytesPerInterval(kMinPacketLimitMs);
265 } 265 }
266 266
267 PacedSender::~PacedSender() {} 267 PacedSender::~PacedSender() {}
268 268
269 void PacedSender::Pause() { 269 void PacedSender::Pause() {
270 LOG(LS_INFO) << "PacedSender paused.";
270 CriticalSectionScoped cs(critsect_.get()); 271 CriticalSectionScoped cs(critsect_.get());
271 paused_ = true; 272 paused_ = true;
272 } 273 }
273 274
274 void PacedSender::Resume() { 275 void PacedSender::Resume() {
276 LOG(LS_INFO) << "PacedSender resumed.";
275 CriticalSectionScoped cs(critsect_.get()); 277 CriticalSectionScoped cs(critsect_.get());
276 paused_ = false; 278 paused_ = false;
277 } 279 }
278 280
279 void PacedSender::SetProbingEnabled(bool enabled) { 281 void PacedSender::SetProbingEnabled(bool enabled) {
280 RTC_CHECK_EQ(0u, packet_counter_); 282 RTC_CHECK_EQ(0u, packet_counter_);
281 probing_enabled_ = enabled; 283 probing_enabled_ = enabled;
282 } 284 }
283 285
284 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { 286 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) {
287 if (bitrate_bps == 0)
288 LOG(LS_ERROR) << "PacedSender is not designed to handle 0 bitrate.";
stefan-webrtc 2016/07/29 15:05:13 Change to an RTC_DCHECK instead?
terelius 2016/07/30 18:14:14 I would like to see if this ever happens in produc
285 CriticalSectionScoped cs(critsect_.get()); 289 CriticalSectionScoped cs(critsect_.get());
286 estimated_bitrate_bps_ = bitrate_bps; 290 estimated_bitrate_bps_ = bitrate_bps;
287 padding_budget_->set_target_rate_kbps( 291 padding_budget_->set_target_rate_kbps(
288 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); 292 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_));
289 pacing_bitrate_kbps_ = 293 pacing_bitrate_kbps_ =
290 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * 294 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) *
291 kDefaultPaceMultiplier; 295 kDefaultPaceMultiplier;
292 } 296 }
293 297
294 void PacedSender::SetSendBitrateLimits(int min_send_bitrate_bps, 298 void PacedSender::SetSendBitrateLimits(int min_send_bitrate_bps,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 media_budget_->set_target_rate_kbps(target_bitrate_kbps); 395 media_budget_->set_target_rate_kbps(target_bitrate_kbps);
392 396
393 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); 397 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms);
394 UpdateBytesPerInterval(delta_time_ms); 398 UpdateBytesPerInterval(delta_time_ms);
395 } 399 }
396 400
397 bool is_probing = prober_->IsProbing(); 401 bool is_probing = prober_->IsProbing();
398 int probe_cluster_id = is_probing ? prober_->CurrentClusterId() 402 int probe_cluster_id = is_probing ? prober_->CurrentClusterId()
399 : PacketInfo::kNotAProbe; 403 : PacketInfo::kNotAProbe;
400 while (!packets_->Empty()) { 404 while (!packets_->Empty()) {
401 if (media_budget_->bytes_remaining() == 0 && !is_probing)
402 return;
403
404 // Since we need to release the lock in order to send, we first pop the 405 // Since we need to release the lock in order to send, we first pop the
405 // element from the priority queue but keep it in storage, so that we can 406 // element from the priority queue but keep it in storage, so that we can
406 // reinsert it if send fails. 407 // reinsert it if send fails.
407 const paced_sender::Packet& packet = packets_->BeginPop(); 408 const paced_sender::Packet& packet = packets_->BeginPop();
408 409
409 if (SendPacket(packet, probe_cluster_id)) { 410 if (SendPacket(packet, probe_cluster_id)) {
410 // Send succeeded, remove it from the queue. 411 // Send succeeded, remove it from the queue.
411 packets_->FinalizePop(packet); 412 packets_->FinalizePop(packet);
412 if (is_probing) 413 if (is_probing)
413 return; 414 return;
414 } else { 415 } else {
415 // Send failed, put it back into the queue. 416 // Send failed, put it back into the queue.
416 packets_->CancelPop(packet); 417 packets_->CancelPop(packet);
417 return; 418 return;
418 } 419 }
419 } 420 }
420 421
422 RTC_DCHECK(packets_->Empty());
421 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. 423 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed.
422 if (paused_ || !packets_->Empty()) 424 if (paused_)
423 return; 425 return;
424 426
425 // We can not send padding unless a normal packet has first been sent. If we 427 // We can not send padding unless a normal packet has first been sent. If we
426 // do, timestamps get messed up. 428 // do, timestamps get messed up.
427 if (packet_counter_ > 0) { 429 if (packet_counter_ > 0) {
428 size_t padding_needed = is_probing ? prober_->RecommendedPacketSize() 430 size_t padding_needed = is_probing ? prober_->RecommendedPacketSize()
429 : padding_budget_->bytes_remaining(); 431 : padding_budget_->bytes_remaining();
430 432
431 if (padding_needed > 0) 433 if (padding_needed > 0)
432 SendPadding(padding_needed, probe_cluster_id); 434 SendPadding(padding_needed, probe_cluster_id);
433 } 435 }
434 } 436 }
435 437
436 bool PacedSender::SendPacket(const paced_sender::Packet& packet, 438 bool PacedSender::SendPacket(const paced_sender::Packet& packet,
437 int probe_cluster_id) { 439 int probe_cluster_id) {
438 // TODO(holmer): Because of this bug issue 5307 we have to send audio 440 // TODO(holmer): Because of this bug issue 5307 we have to send audio
439 // packets even when the pacer is paused. Here we assume audio packets are 441 // 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. 442 // always high priority and that they are the only high priority packets.
441 if (paused_ && packet.priority != kHighPriority) 443 if (packet.priority != kHighPriority) {
442 return false; 444 if (paused_)
445 return false;
446 if (media_budget_->bytes_remaining() == 0 &&
447 probe_cluster_id == PacketInfo::kNotAProbe)
stefan-webrtc 2016/07/29 15:05:13 {}
terelius 2016/07/30 18:14:14 Done.
448 return false;
449 }
443 critsect_->Leave(); 450 critsect_->Leave();
444 const bool success = packet_sender_->TimeToSendPacket( 451 const bool success = packet_sender_->TimeToSendPacket(
445 packet.ssrc, packet.sequence_number, packet.capture_time_ms, 452 packet.ssrc, packet.sequence_number, packet.capture_time_ms,
446 packet.retransmission, probe_cluster_id); 453 packet.retransmission, probe_cluster_id);
447 critsect_->Enter(); 454 critsect_->Enter();
448 455
449 if (success) { 456 if (success) {
450 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); 457 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes);
451 // TODO(holmer): High priority packets should only be accounted for if we 458 // TODO(holmer): High priority packets should only be accounted for if we
452 // are allocating bandwidth for audio. 459 // are allocating bandwidth for audio.
(...skipping 18 matching lines...) Expand all
471 media_budget_->UseBudget(bytes_sent); 478 media_budget_->UseBudget(bytes_sent);
472 padding_budget_->UseBudget(bytes_sent); 479 padding_budget_->UseBudget(bytes_sent);
473 } 480 }
474 } 481 }
475 482
476 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { 483 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) {
477 media_budget_->IncreaseBudget(delta_time_ms); 484 media_budget_->IncreaseBudget(delta_time_ms);
478 padding_budget_->IncreaseBudget(delta_time_ms); 485 padding_budget_->IncreaseBudget(delta_time_ms);
479 } 486 }
480 } // namespace webrtc 487 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/pacing/paced_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698