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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); | 382 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); |
383 if (min_bitrate_needed_kbps > target_bitrate_kbps) | 383 if (min_bitrate_needed_kbps > target_bitrate_kbps) |
384 target_bitrate_kbps = min_bitrate_needed_kbps; | 384 target_bitrate_kbps = min_bitrate_needed_kbps; |
385 } | 385 } |
386 | 386 |
387 media_budget_->set_target_rate_kbps(target_bitrate_kbps); | 387 media_budget_->set_target_rate_kbps(target_bitrate_kbps); |
388 | 388 |
389 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); | 389 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
390 UpdateBytesPerInterval(delta_time_ms); | 390 UpdateBytesPerInterval(delta_time_ms); |
391 } | 391 } |
| 392 |
| 393 int probe_cluster_id = prober_->IsProbing() ? prober_->CurrentClusterId() |
| 394 : PacketInfo::kNotAProbe; |
392 while (!packets_->Empty()) { | 395 while (!packets_->Empty()) { |
393 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) | 396 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) |
394 return; | 397 return; |
395 | 398 |
396 // Since we need to release the lock in order to send, we first pop the | 399 // Since we need to release the lock in order to send, we first pop the |
397 // element from the priority queue but keep it in storage, so that we can | 400 // element from the priority queue but keep it in storage, so that we can |
398 // reinsert it if send fails. | 401 // reinsert it if send fails. |
399 const paced_sender::Packet& packet = packets_->BeginPop(); | 402 const paced_sender::Packet& packet = packets_->BeginPop(); |
400 int probe_cluster_id = | |
401 prober_->IsProbing() ? prober_->CurrentClusterId() : -1; | |
402 | 403 |
403 if (SendPacket(packet, probe_cluster_id)) { | 404 if (SendPacket(packet, probe_cluster_id)) { |
404 // Send succeeded, remove it from the queue. | 405 // Send succeeded, remove it from the queue. |
405 packets_->FinalizePop(packet); | 406 packets_->FinalizePop(packet); |
406 if (prober_->IsProbing()) | 407 if (prober_->IsProbing()) |
407 return; | 408 return; |
408 } else { | 409 } else { |
409 // Send failed, put it back into the queue. | 410 // Send failed, put it back into the queue. |
410 packets_->CancelPop(packet); | 411 packets_->CancelPop(packet); |
411 return; | 412 return; |
412 } | 413 } |
413 } | 414 } |
414 | 415 |
415 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. | 416 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. |
416 if (paused_ || !packets_->Empty()) | 417 if (paused_ || !packets_->Empty()) |
417 return; | 418 return; |
418 | 419 |
419 size_t padding_needed; | 420 size_t padding_needed; |
420 if (prober_->IsProbing()) { | 421 if (prober_->IsProbing()) { |
421 padding_needed = prober_->RecommendedPacketSize(); | 422 padding_needed = prober_->RecommendedPacketSize(); |
422 } else { | 423 } else { |
423 padding_needed = padding_budget_->bytes_remaining(); | 424 padding_needed = padding_budget_->bytes_remaining(); |
424 } | 425 } |
425 | 426 |
426 if (padding_needed > 0) | 427 if (padding_needed > 0) |
427 SendPadding(static_cast<size_t>(padding_needed)); | 428 SendPadding(padding_needed, probe_cluster_id); |
428 } | 429 } |
429 | 430 |
430 bool PacedSender::SendPacket(const paced_sender::Packet& packet, | 431 bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
431 int probe_cluster_id) { | 432 int probe_cluster_id) { |
432 // TODO(holmer): Because of this bug issue 5307 we have to send audio | 433 // TODO(holmer): Because of this bug issue 5307 we have to send audio |
433 // packets even when the pacer is paused. Here we assume audio packets are | 434 // packets even when the pacer is paused. Here we assume audio packets are |
434 // always high priority and that they are the only high priority packets. | 435 // always high priority and that they are the only high priority packets. |
435 if (paused_ && packet.priority != kHighPriority) | 436 if (paused_ && packet.priority != kHighPriority) |
436 return false; | 437 return false; |
437 critsect_->Leave(); | 438 critsect_->Leave(); |
438 const bool success = packet_sender_->TimeToSendPacket( | 439 const bool success = packet_sender_->TimeToSendPacket( |
439 packet.ssrc, packet.sequence_number, packet.capture_time_ms, | 440 packet.ssrc, packet.sequence_number, packet.capture_time_ms, |
440 packet.retransmission, probe_cluster_id); | 441 packet.retransmission, probe_cluster_id); |
441 critsect_->Enter(); | 442 critsect_->Enter(); |
442 | 443 |
443 if (success) { | 444 if (success) { |
444 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); | 445 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); |
445 // 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 |
446 // are allocating bandwidth for audio. | 447 // are allocating bandwidth for audio. |
447 if (packet.priority != kHighPriority) { | 448 if (packet.priority != kHighPriority) { |
448 // Update media bytes sent. | 449 // Update media bytes sent. |
449 media_budget_->UseBudget(packet.bytes); | 450 media_budget_->UseBudget(packet.bytes); |
450 padding_budget_->UseBudget(packet.bytes); | 451 padding_budget_->UseBudget(packet.bytes); |
451 } | 452 } |
452 } | 453 } |
453 | 454 |
454 return success; | 455 return success; |
455 } | 456 } |
456 | 457 |
457 void PacedSender::SendPadding(size_t padding_needed) { | 458 void PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { |
458 critsect_->Leave(); | 459 critsect_->Leave(); |
459 size_t bytes_sent = packet_sender_->TimeToSendPadding(padding_needed); | 460 size_t bytes_sent = |
| 461 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); |
460 critsect_->Enter(); | 462 critsect_->Enter(); |
461 | 463 |
462 if (bytes_sent > 0) { | 464 if (bytes_sent > 0) { |
463 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); | 465 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); |
464 media_budget_->UseBudget(bytes_sent); | 466 media_budget_->UseBudget(bytes_sent); |
465 padding_budget_->UseBudget(bytes_sent); | 467 padding_budget_->UseBudget(bytes_sent); |
466 } | 468 } |
467 } | 469 } |
468 | 470 |
469 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 471 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
470 media_budget_->IncreaseBudget(delta_time_ms); | 472 media_budget_->IncreaseBudget(delta_time_ms); |
471 padding_budget_->IncreaseBudget(delta_time_ms); | 473 padding_budget_->IncreaseBudget(delta_time_ms); |
472 } | 474 } |
473 } // namespace webrtc | 475 } // namespace webrtc |
OLD | NEW |