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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_sender.cc

Issue 2766323006: Correcting the amount of padding when send side bwe includes RTP overhead.
Patch Set: on comments` Created 3 years, 8 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 rtc::CritScope lock(&send_critsect_); 448 rtc::CritScope lock(&send_critsect_);
449 if (!sending_media_) 449 if (!sending_media_)
450 return 0; 450 return 0;
451 if ((rtx_ & kRtxRedundantPayloads) == 0) 451 if ((rtx_ & kRtxRedundantPayloads) == 0)
452 return 0; 452 return 0;
453 } 453 }
454 454
455 int bytes_left = static_cast<int>(bytes_to_send); 455 int bytes_left = static_cast<int>(bytes_to_send);
456 while (bytes_left > 0) { 456 while (bytes_left > 0) {
457 std::unique_ptr<RtpPacketToSend> packet = 457 std::unique_ptr<RtpPacketToSend> packet =
458 packet_history_.GetBestFittingPacket(bytes_left); 458 packet_history_.GetBestFittingPacket(bytes_left,
459 send_side_bwe_with_overhead_);
459 if (!packet) 460 if (!packet)
460 break; 461 break;
461 size_t payload_size = packet->payload_size(); 462 // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget
463 // includes overhead.
464 const size_t used_bytes = send_side_bwe_with_overhead_
465 ? packet->size()
466 : packet->size() - packet->headers_size();
462 if (!PrepareAndSendPacket(std::move(packet), true, false, pacing_info)) 467 if (!PrepareAndSendPacket(std::move(packet), true, false, pacing_info))
463 break; 468 break;
464 bytes_left -= payload_size; 469 bytes_left -= used_bytes;
465 } 470 }
466 return bytes_to_send - bytes_left; 471 return bytes_to_send - bytes_left;
467 } 472 }
468 473
469 size_t RTPSender::SendPadData(size_t bytes, 474 size_t RTPSender::SendPadData(size_t bytes,
470 const PacedPacketInfo& pacing_info) { 475 const PacedPacketInfo& pacing_info) {
471 size_t padding_bytes_in_packet; 476 // Always send full padding packets. This is accounted for by the
477 // RtpPacketSender, which will make sure we don't send too much padding even
478 // if a single packet is larger than requested.
479 // We do this to avoid frequently sending small packets on higher bitrates.
480 size_t padding_bytes_in_packet =
481 std::min(MaxPayloadSize(), kMaxPaddingLength);
482
472 if (audio_configured_) { 483 if (audio_configured_) {
473 // Allow smaller padding packets for audio. 484 // Allow smaller padding packets for audio.
485
486 // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget
487 // includes overhead.
488 const size_t padding_bytes_if_one_packet =
489 send_side_bwe_with_overhead_ ? bytes - RtpHeaderLength() : bytes;
474 padding_bytes_in_packet = 490 padding_bytes_in_packet =
475 std::min(std::max(bytes, kMinAudioPaddingLength), MaxPayloadSize()); 491 std::min(padding_bytes_in_packet,
476 if (padding_bytes_in_packet > kMaxPaddingLength) 492 std::max(padding_bytes_if_one_packet, kMinAudioPaddingLength));
477 padding_bytes_in_packet = kMaxPaddingLength;
478 } else {
479 // Always send full padding packets. This is accounted for by the
480 // RtpPacketSender, which will make sure we don't send too much padding even
481 // if a single packet is larger than requested.
482 // We do this to avoid frequently sending small packets on higher bitrates.
483 padding_bytes_in_packet = std::min(MaxPayloadSize(), kMaxPaddingLength);
484 } 493 }
494
485 size_t bytes_sent = 0; 495 size_t bytes_sent = 0;
486 while (bytes_sent < bytes) { 496 while (bytes_sent < bytes) {
487 int64_t now_ms = clock_->TimeInMilliseconds(); 497 int64_t now_ms = clock_->TimeInMilliseconds();
488 uint32_t ssrc; 498 uint32_t ssrc;
489 uint32_t timestamp; 499 uint32_t timestamp;
490 int64_t capture_time_ms; 500 int64_t capture_time_ms;
491 uint16_t sequence_number; 501 uint16_t sequence_number;
492 int payload_type; 502 int payload_type;
493 bool over_rtx; 503 bool over_rtx;
494 { 504 {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 padding_packet.SetSsrc(ssrc); 569 padding_packet.SetSsrc(ssrc);
560 570
561 if (capture_time_ms > 0) { 571 if (capture_time_ms > 0) {
562 padding_packet.SetExtension<TransmissionOffset>( 572 padding_packet.SetExtension<TransmissionOffset>(
563 (now_ms - capture_time_ms) * kTimestampTicksPerMs); 573 (now_ms - capture_time_ms) * kTimestampTicksPerMs);
564 } 574 }
565 padding_packet.SetExtension<AbsoluteSendTime>(now_ms); 575 padding_packet.SetExtension<AbsoluteSendTime>(now_ms);
566 PacketOptions options; 576 PacketOptions options;
567 bool has_transport_seq_num = 577 bool has_transport_seq_num =
568 UpdateTransportSequenceNumber(&padding_packet, &options.packet_id); 578 UpdateTransportSequenceNumber(&padding_packet, &options.packet_id);
579
569 padding_packet.SetPadding(padding_bytes_in_packet, &random_); 580 padding_packet.SetPadding(padding_bytes_in_packet, &random_);
570 581
571 if (has_transport_seq_num) { 582 if (has_transport_seq_num) {
572 AddPacketToTransportFeedback(options.packet_id, padding_packet, 583 AddPacketToTransportFeedback(options.packet_id, padding_packet,
573 pacing_info); 584 pacing_info);
574 } 585 }
575 586
576 if (!SendPacketToNetwork(padding_packet, options, pacing_info)) 587 if (!SendPacketToNetwork(padding_packet, options, pacing_info))
577 break; 588 break;
578 589
579 bytes_sent += padding_bytes_in_packet; 590 // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget
591 // includes overhead.
592 bytes_sent += send_side_bwe_with_overhead_ ? padding_packet.size()
593 : padding_packet.padding_size();
stefan-webrtc 2017/04/04 08:13:38 Maybe for consistency use: packet->size() - packet
minyue-webrtc 2017/04/11 09:35:14 I would rather do padding_size + headers_size I h
danilchap 2017/04/11 14:25:18 personally prefer size() function too: size_t pack
minyue-webrtc 2017/04/11 14:30:51 You are right here. I realized that we should incl
580 UpdateRtpStats(padding_packet, over_rtx, false); 594 UpdateRtpStats(padding_packet, over_rtx, false);
581 } 595 }
582 596
583 return bytes_sent; 597 return bytes_sent;
584 } 598 }
585 599
586 void RTPSender::SetStorePacketsStatus(bool enable, uint16_t number_to_store) { 600 void RTPSender::SetStorePacketsStatus(bool enable, uint16_t number_to_store) {
587 packet_history_.SetStorePacketsStatus(enable, number_to_store); 601 packet_history_.SetStorePacketsStatus(enable, number_to_store);
588 } 602 }
589 603
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { 1284 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) {
1271 return; 1285 return;
1272 } 1286 }
1273 rtp_overhead_bytes_per_packet_ = packet.headers_size(); 1287 rtp_overhead_bytes_per_packet_ = packet.headers_size();
1274 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; 1288 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_;
1275 } 1289 }
1276 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); 1290 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet);
1277 } 1291 }
1278 1292
1279 } // namespace webrtc 1293 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698