From d4f607e70ad85102b77cf0beba8f11e2599e8f99 Mon Sep 17 00:00:00 2001 From: "stefan@webrtc.org" Date: Mon, 19 Aug 2013 15:55:01 +0000 Subject: [PATCH] Fixes to padding when driven by encoder. - Allow padding to be sent on an ssrc which doesn't produce video, therefore never having the last_packet_marker_bit_ set. - Add the random timestamp offset to all padding packets. - Store the capture time of padding packets to properly create an offset. BUG=2258 TEST=trybots and a new test which will be committed separately. R=mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2060005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4566 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/rtp_rtcp/source/rtp_sender.cc | 20 +++++++++++++++----- webrtc/modules/rtp_rtcp/source/rtp_sender.h | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index 5fa756639..e5ca8d995 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -408,8 +408,17 @@ bool RTPSender::SendPaddingAccordingToBitrate( bytes = bytes_cap; } } - int bytes_sent = SendPadData(payload_type, capture_timestamp, capture_time_ms, - bytes, kDontRetransmit, false); + uint32_t timestamp; + { + CriticalSectionScoped cs(send_critsect_); + // Add the random RTP timestamp offset and store the capture time for + // later calculation of the send time offset. + timestamp = start_time_stamp_ + capture_timestamp; + timestamp_ = timestamp; + capture_time_ms_ = capture_time_ms; + } + int bytes_sent = SendPadData(payload_type, timestamp, capture_time_ms, + bytes, kDontRetransmit, false, false); // We did not manage to send all bytes. Comparing with 31 due to modulus 32. return bytes - bytes_sent < 31; } @@ -435,7 +444,8 @@ int RTPSender::BuildPaddingPacket(uint8_t* packet, int header_length, int RTPSender::SendPadData(int payload_type, uint32_t timestamp, int64_t capture_time_ms, int32_t bytes, - StorageType store, bool force_full_size_packets) { + StorageType store, bool force_full_size_packets, + bool only_pad_after_markerbit) { // Drop this packet if we're not sending media packets. if (!sending_media_) { return bytes; @@ -464,7 +474,7 @@ int RTPSender::SendPadData(int payload_type, uint32_t timestamp, CriticalSectionScoped cs(send_critsect_); // Only send padding packets following the last packet of a frame, // indicated by the marker bit. - if (!last_packet_marker_bit_) + if (only_pad_after_markerbit && !last_packet_marker_bit_) return bytes_sent; if (rtx_ == kRtxOff) { ssrc = ssrc_; @@ -750,7 +760,7 @@ int RTPSender::TimeToSendPadding(int bytes) { capture_time_ms = capture_time_ms_; } return SendPadData(payload_type, timestamp, capture_time_ms, bytes, - kDontStore, true); + kDontStore, true, true); } // TODO(pwestin): send in the RTPHeaderParser to avoid parsing it again. diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.h b/webrtc/modules/rtp_rtcp/source/rtp_sender.h index 91041faf6..85d1ff86b 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.h @@ -137,7 +137,7 @@ class RTPSender : public Bitrate, public RTPSenderInterface { int BuildPaddingPacket(uint8_t* packet, int header_length, int32_t bytes); int SendPadData(int payload_type, uint32_t timestamp, int64_t capture_time_ms, int32_t bytes, StorageType store, - bool force_full_size_packets); + bool force_full_size_packets, bool only_pad_after_markerbit); // RTP header extension int32_t SetTransmissionTimeOffset( const int32_t transmission_time_offset);