| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 if (prober_->IsProbing()) { | 366 if (prober_->IsProbing()) { |
| 367 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); | 367 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); |
| 368 if (ret >= 0) | 368 if (ret >= 0) |
| 369 return ret; | 369 return ret; |
| 370 } | 370 } |
| 371 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; | 371 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; |
| 372 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; | 372 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; |
| 373 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); | 373 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); |
| 374 } | 374 } |
| 375 | 375 |
| 376 int32_t PacedSender::Process() { | 376 void PacedSender::Process() { |
| 377 int64_t now_us = clock_->TimeInMicroseconds(); | 377 int64_t now_us = clock_->TimeInMicroseconds(); |
| 378 CriticalSectionScoped cs(critsect_.get()); | 378 CriticalSectionScoped cs(critsect_.get()); |
| 379 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; | 379 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; |
| 380 time_last_update_us_ = now_us; | 380 time_last_update_us_ = now_us; |
| 381 int target_bitrate_kbps = max_bitrate_kbps_; | 381 int target_bitrate_kbps = max_bitrate_kbps_; |
| 382 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. | 382 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. |
| 383 if (!paused_ && elapsed_time_ms > 0) { | 383 if (!paused_ && elapsed_time_ms > 0) { |
| 384 size_t queue_size_bytes = packets_->SizeInBytes(); | 384 size_t queue_size_bytes = packets_->SizeInBytes(); |
| 385 if (queue_size_bytes > 0) { | 385 if (queue_size_bytes > 0) { |
| 386 // Assuming equal size packets and input/output rate, the average packet | 386 // Assuming equal size packets and input/output rate, the average packet |
| 387 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if | 387 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if |
| 388 // time constraint shall be met. Determine bitrate needed for that. | 388 // time constraint shall be met. Determine bitrate needed for that. |
| 389 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); | 389 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); |
| 390 int64_t avg_time_left_ms = std::max<int64_t>( | 390 int64_t avg_time_left_ms = std::max<int64_t>( |
| 391 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); | 391 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); |
| 392 int min_bitrate_needed_kbps = | 392 int min_bitrate_needed_kbps = |
| 393 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); | 393 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); |
| 394 if (min_bitrate_needed_kbps > target_bitrate_kbps) | 394 if (min_bitrate_needed_kbps > target_bitrate_kbps) |
| 395 target_bitrate_kbps = min_bitrate_needed_kbps; | 395 target_bitrate_kbps = min_bitrate_needed_kbps; |
| 396 } | 396 } |
| 397 | 397 |
| 398 media_budget_->set_target_rate_kbps(target_bitrate_kbps); | 398 media_budget_->set_target_rate_kbps(target_bitrate_kbps); |
| 399 | 399 |
| 400 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); | 400 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
| 401 UpdateBytesPerInterval(delta_time_ms); | 401 UpdateBytesPerInterval(delta_time_ms); |
| 402 } | 402 } |
| 403 while (!packets_->Empty()) { | 403 while (!packets_->Empty()) { |
| 404 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) | 404 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) |
| 405 return 0; | 405 return; |
| 406 | 406 |
| 407 // Since we need to release the lock in order to send, we first pop the | 407 // Since we need to release the lock in order to send, we first pop the |
| 408 // element from the priority queue but keep it in storage, so that we can | 408 // element from the priority queue but keep it in storage, so that we can |
| 409 // reinsert it if send fails. | 409 // reinsert it if send fails. |
| 410 const paced_sender::Packet& packet = packets_->BeginPop(); | 410 const paced_sender::Packet& packet = packets_->BeginPop(); |
| 411 | 411 |
| 412 if (SendPacket(packet)) { | 412 if (SendPacket(packet)) { |
| 413 // Send succeeded, remove it from the queue. | 413 // Send succeeded, remove it from the queue. |
| 414 packets_->FinalizePop(packet); | 414 packets_->FinalizePop(packet); |
| 415 if (prober_->IsProbing()) | 415 if (prober_->IsProbing()) |
| 416 return 0; | 416 return; |
| 417 } else { | 417 } else { |
| 418 // Send failed, put it back into the queue. | 418 // Send failed, put it back into the queue. |
| 419 packets_->CancelPop(packet); | 419 packets_->CancelPop(packet); |
| 420 return 0; | 420 return; |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 | 423 |
| 424 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. | 424 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. |
| 425 if (paused_ || !packets_->Empty()) | 425 if (paused_ || !packets_->Empty()) |
| 426 return 0; | 426 return; |
| 427 | 427 |
| 428 size_t padding_needed; | 428 size_t padding_needed; |
| 429 if (prober_->IsProbing()) { | 429 if (prober_->IsProbing()) { |
| 430 padding_needed = prober_->RecommendedPacketSize(); | 430 padding_needed = prober_->RecommendedPacketSize(); |
| 431 } else { | 431 } else { |
| 432 padding_needed = padding_budget_->bytes_remaining(); | 432 padding_needed = padding_budget_->bytes_remaining(); |
| 433 } | 433 } |
| 434 | 434 |
| 435 if (padding_needed > 0) | 435 if (padding_needed > 0) |
| 436 SendPadding(static_cast<size_t>(padding_needed)); | 436 SendPadding(static_cast<size_t>(padding_needed)); |
| 437 return 0; | |
| 438 } | 437 } |
| 439 | 438 |
| 440 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { | 439 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { |
| 441 // 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 |
| 442 // 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 |
| 443 // 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. |
| 444 if (paused_ && packet.priority != kHighPriority) | 443 if (paused_ && packet.priority != kHighPriority) |
| 445 return false; | 444 return false; |
| 446 critsect_->Leave(); | 445 critsect_->Leave(); |
| 447 const bool success = callback_->TimeToSendPacket(packet.ssrc, | 446 const bool success = callback_->TimeToSendPacket(packet.ssrc, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 472 media_budget_->UseBudget(bytes_sent); | 471 media_budget_->UseBudget(bytes_sent); |
| 473 padding_budget_->UseBudget(bytes_sent); | 472 padding_budget_->UseBudget(bytes_sent); |
| 474 } | 473 } |
| 475 } | 474 } |
| 476 | 475 |
| 477 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 476 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
| 478 media_budget_->IncreaseBudget(delta_time_ms); | 477 media_budget_->IncreaseBudget(delta_time_ms); |
| 479 padding_budget_->IncreaseBudget(delta_time_ms); | 478 padding_budget_->IncreaseBudget(delta_time_ms); |
| 480 } | 479 } |
| 481 } // namespace webrtc | 480 } // namespace webrtc |
| OLD | NEW |