Index: webrtc/modules/rtp_rtcp/source/rtp_sender.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc |
index 6fdac6f63fb08507ec68781c4bff1e59b6ca693e..60f8cd540dbd81ff4cc48a34b452679b26b9102e 100644 |
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc |
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc |
@@ -442,33 +442,46 @@ size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send, |
int bytes_left = static_cast<int>(bytes_to_send); |
while (bytes_left > 0) { |
std::unique_ptr<RtpPacketToSend> packet = |
- packet_history_.GetBestFittingPacket(bytes_left); |
+ packet_history_.GetBestFittingPacket(bytes_left, |
+ send_side_bwe_with_overhead_); |
if (!packet) |
break; |
- size_t payload_size = packet->payload_size(); |
+ // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget |
+ // includes overhead. |
+ const size_t used_bytes = |
+ send_side_bwe_with_overhead_ |
+ ? packet->payload_size() + packet->headers_size() |
+ : packet->payload_size(); |
if (!PrepareAndSendPacket(std::move(packet), true, false, pacing_info)) |
break; |
- bytes_left -= payload_size; |
+ bytes_left -= used_bytes; |
} |
return bytes_to_send - bytes_left; |
} |
size_t RTPSender::SendPadData(size_t bytes, |
const PacedPacketInfo& pacing_info) { |
- size_t padding_bytes_in_packet; |
+ // Always send full padding packets. This is accounted for by the |
+ // RtpPacketSender, which will make sure we don't send too much padding even |
+ // if a single packet is larger than requested. |
+ // We do this to avoid frequently sending small packets on higher bitrates. |
+ size_t padding_bytes_in_packet = |
+ std::min(MaxPayloadSize(), kMaxPaddingLength); |
+ |
if (audio_configured_) { |
// Allow smaller padding packets for audio. |
+ |
+ // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget |
+ // includes overhead. |
+ const size_t padding_bytes_if_one_packet = |
+ send_side_bwe_with_overhead_ |
+ ? std::max<int>(0, bytes - RtpHeaderLength()) |
minyue-webrtc
2017/04/11 09:35:14
This was wrong, since bytes - RtpHeaderLength() ca
|
+ : bytes; |
padding_bytes_in_packet = |
- std::min(std::max(bytes, kMinAudioPaddingLength), MaxPayloadSize()); |
- if (padding_bytes_in_packet > kMaxPaddingLength) |
- padding_bytes_in_packet = kMaxPaddingLength; |
- } else { |
- // Always send full padding packets. This is accounted for by the |
- // RtpPacketSender, which will make sure we don't send too much padding even |
- // if a single packet is larger than requested. |
- // We do this to avoid frequently sending small packets on higher bitrates. |
- padding_bytes_in_packet = std::min(MaxPayloadSize(), kMaxPaddingLength); |
+ std::min(padding_bytes_in_packet, |
+ std::max(padding_bytes_if_one_packet, kMinAudioPaddingLength)); |
} |
+ |
size_t bytes_sent = 0; |
while (bytes_sent < bytes) { |
int64_t now_ms = clock_->TimeInMilliseconds(); |
@@ -553,6 +566,7 @@ size_t RTPSender::SendPadData(size_t bytes, |
PacketOptions options; |
bool has_transport_seq_num = |
UpdateTransportSequenceNumber(&padding_packet, &options.packet_id); |
+ |
padding_packet.SetPadding(padding_bytes_in_packet, &random_); |
if (has_transport_seq_num) { |
@@ -563,7 +577,12 @@ size_t RTPSender::SendPadData(size_t bytes, |
if (!SendPacketToNetwork(padding_packet, options, pacing_info)) |
break; |
- bytes_sent += padding_bytes_in_packet; |
+ // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget |
+ // includes overhead. |
+ bytes_sent += |
+ send_side_bwe_with_overhead_ |
+ ? padding_packet.padding_size() + padding_packet.headers_size() |
+ : padding_packet.padding_size(); |
UpdateRtpStats(padding_packet, over_rtx, false); |
} |
@@ -597,10 +616,13 @@ int32_t RTPSender::ReSendPacket(uint16_t packet_id, int64_t min_resend_time) { |
// TickTime. |
int64_t corrected_capture_tims_ms = |
packet->capture_time_ms() + clock_delta_ms_; |
+ const size_t packet_size = |
+ send_side_bwe_with_overhead_ |
+ ? packet->payload_size() + packet->headers_size() |
+ : packet->payload_size(); |
paced_sender_->InsertPacket(RtpPacketSender::kNormalPriority, |
packet->Ssrc(), packet->SequenceNumber(), |
- corrected_capture_tims_ms, |
- packet->payload_size(), true); |
+ corrected_capture_tims_ms, packet_size, true); |
return packet->size(); |
} |
@@ -842,7 +864,10 @@ bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, |
// Correct offset between implementations of millisecond time stamps in |
// TickTime and Clock. |
int64_t corrected_time_ms = packet->capture_time_ms() + clock_delta_ms_; |
- size_t payload_length = packet->payload_size(); |
+ const size_t packet_size = |
+ send_side_bwe_with_overhead_ |
+ ? packet->payload_size() + packet->headers_size() |
+ : packet->payload_size(); |
if (ssrc == flexfec_ssrc) { |
// Store FlexFEC packets in the history here, so they can be found |
// when the pacer calls TimeToSendPacket. |
@@ -852,7 +877,8 @@ bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, |
} |
paced_sender_->InsertPacket(priority, ssrc, seq_no, corrected_time_ms, |
- payload_length, false); |
+ packet_size, false); |
+ |
if (last_capture_time_ms_sent_ == 0 || |
corrected_time_ms > last_capture_time_ms_sent_) { |
last_capture_time_ms_sent_ = corrected_time_ms; |
@@ -1237,11 +1263,10 @@ void RTPSender::AddPacketToTransportFeedback( |
uint16_t packet_id, |
const RtpPacketToSend& packet, |
const PacedPacketInfo& pacing_info) { |
- size_t packet_size = packet.payload_size() + packet.padding_size(); |
- if (send_side_bwe_with_overhead_) { |
- packet_size = packet.size(); |
- } |
- |
+ const size_t packet_size = |
minyue-webrtc
2017/04/11 09:35:14
this is a simple refactoring
|
+ send_side_bwe_with_overhead_ |
+ ? packet.size() |
+ : packet.payload_size() + packet.padding_size(); |
if (transport_feedback_observer_) { |
transport_feedback_observer_->AddPacket(SSRC(), packet_id, packet_size, |
pacing_info); |