OLD | NEW |
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; | 351 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; |
352 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; | 352 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; |
353 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); | 353 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); |
354 } | 354 } |
355 | 355 |
356 int32_t PacedSender::Process() { | 356 int32_t PacedSender::Process() { |
357 int64_t now_us = clock_->TimeInMicroseconds(); | 357 int64_t now_us = clock_->TimeInMicroseconds(); |
358 CriticalSectionScoped cs(critsect_.get()); | 358 CriticalSectionScoped cs(critsect_.get()); |
359 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; | 359 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; |
360 time_last_update_us_ = now_us; | 360 time_last_update_us_ = now_us; |
361 if (paused_) | |
362 return 0; | |
363 int target_bitrate_kbps = max_bitrate_kbps_; | 361 int target_bitrate_kbps = max_bitrate_kbps_; |
364 if (elapsed_time_ms > 0) { | 362 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. |
| 363 if (!paused_ && elapsed_time_ms > 0) { |
365 size_t queue_size_bytes = packets_->SizeInBytes(); | 364 size_t queue_size_bytes = packets_->SizeInBytes(); |
366 if (queue_size_bytes > 0) { | 365 if (queue_size_bytes > 0) { |
367 // Assuming equal size packets and input/output rate, the average packet | 366 // Assuming equal size packets and input/output rate, the average packet |
368 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if | 367 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if |
369 // time constraint shall be met. Determine bitrate needed for that. | 368 // time constraint shall be met. Determine bitrate needed for that. |
370 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); | 369 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); |
371 int64_t avg_time_left_ms = std::max<int64_t>( | 370 int64_t avg_time_left_ms = std::max<int64_t>( |
372 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); | 371 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); |
373 int min_bitrate_needed_kbps = | 372 int min_bitrate_needed_kbps = |
374 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); | 373 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); |
375 if (min_bitrate_needed_kbps > target_bitrate_kbps) | 374 if (min_bitrate_needed_kbps > target_bitrate_kbps) |
376 target_bitrate_kbps = min_bitrate_needed_kbps; | 375 target_bitrate_kbps = min_bitrate_needed_kbps; |
377 } | 376 } |
378 | 377 |
379 media_budget_->set_target_rate_kbps(target_bitrate_kbps); | 378 media_budget_->set_target_rate_kbps(target_bitrate_kbps); |
380 | 379 |
381 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); | 380 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
382 UpdateBytesPerInterval(delta_time_ms); | 381 UpdateBytesPerInterval(delta_time_ms); |
383 } | 382 } |
384 while (!packets_->Empty()) { | 383 while (!packets_->Empty()) { |
385 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) | 384 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) |
386 return 0; | 385 return 0; |
387 | 386 |
388 // Since we need to release the lock in order to send, we first pop the | 387 // Since we need to release the lock in order to send, we first pop the |
389 // element from the priority queue but keep it in storage, so that we can | 388 // element from the priority queue but keep it in storage, so that we can |
390 // reinsert it if send fails. | 389 // reinsert it if send fails. |
391 const paced_sender::Packet& packet = packets_->BeginPop(); | 390 const paced_sender::Packet& packet = packets_->BeginPop(); |
392 if (SendPacket(packet)) { | 391 |
| 392 // TODO(holmer): Because of this bug issue 5307 we have to send audio |
| 393 // packets even when the pacer is paused. Here we assume audio packets are |
| 394 // always high priority and that they are the only high priority packets. |
| 395 if ((!paused_ || packet.priority == kHighPriority) && SendPacket(packet)) { |
393 // Send succeeded, remove it from the queue. | 396 // Send succeeded, remove it from the queue. |
394 packets_->FinalizePop(packet); | 397 packets_->FinalizePop(packet); |
395 if (prober_->IsProbing()) | 398 if (prober_->IsProbing()) |
396 return 0; | 399 return 0; |
397 } else { | 400 } else { |
398 // Send failed, put it back into the queue. | 401 // Send failed, put it back into the queue. |
399 packets_->CancelPop(packet); | 402 packets_->CancelPop(packet); |
400 return 0; | 403 return 0; |
401 } | 404 } |
402 } | 405 } |
403 | 406 |
404 if (!packets_->Empty()) | 407 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. |
| 408 if (paused_ || !packets_->Empty()) |
405 return 0; | 409 return 0; |
406 | 410 |
407 size_t padding_needed; | 411 size_t padding_needed; |
408 if (prober_->IsProbing()) { | 412 if (prober_->IsProbing()) { |
409 padding_needed = prober_->RecommendedPacketSize(); | 413 padding_needed = prober_->RecommendedPacketSize(); |
410 } else { | 414 } else { |
411 padding_needed = padding_budget_->bytes_remaining(); | 415 padding_needed = padding_budget_->bytes_remaining(); |
412 } | 416 } |
413 | 417 |
414 if (padding_needed > 0) | 418 if (padding_needed > 0) |
(...skipping 29 matching lines...) Expand all Loading... |
444 media_budget_->UseBudget(bytes_sent); | 448 media_budget_->UseBudget(bytes_sent); |
445 padding_budget_->UseBudget(bytes_sent); | 449 padding_budget_->UseBudget(bytes_sent); |
446 } | 450 } |
447 } | 451 } |
448 | 452 |
449 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 453 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
450 media_budget_->IncreaseBudget(delta_time_ms); | 454 media_budget_->IncreaseBudget(delta_time_ms); |
451 padding_budget_->IncreaseBudget(delta_time_ms); | 455 padding_budget_->IncreaseBudget(delta_time_ms); |
452 } | 456 } |
453 } // namespace webrtc | 457 } // namespace webrtc |
OLD | NEW |