From 12d97f6637f8be25ca4cd98ab2f43339c7bb1b59 Mon Sep 17 00:00:00 2001 From: "pwestin@webrtc.org" Date: Thu, 5 Jan 2012 10:54:44 +0000 Subject: [PATCH] Made send pad data generic (audio and video) Review URL: http://webrtc-codereview.appspot.com/343001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1346 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/modules/rtp_rtcp/source/rtp_sender.cc | 57 +++++++++++++++++++ src/modules/rtp_rtcp/source/rtp_sender.h | 3 + .../rtp_rtcp/source/rtp_sender_video.cc | 49 ---------------- .../rtp_rtcp/source/rtp_sender_video.h | 4 -- 4 files changed, 60 insertions(+), 53 deletions(-) diff --git a/src/modules/rtp_rtcp/source/rtp_sender.cc b/src/modules/rtp_rtcp/source/rtp_sender.cc index 2bc2c87075..d6c9175916 100644 --- a/src/modules/rtp_rtcp/source/rtp_sender.cc +++ b/src/modules/rtp_rtcp/source/rtp_sender.cc @@ -759,6 +759,63 @@ RTPSender::SendOutgoingData(const FrameType frameType, } } +WebRtc_Word32 RTPSender::SendPadData(WebRtc_Word8 payload_type, + WebRtc_UWord32 capture_timestamp, + WebRtc_Word32 bytes) { + // Drop this packet if we're not sending media packets + if (!_sendingMedia) { + return 0; + } + // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. + int max_length = 224; + WebRtc_UWord8 data_buffer[IP_PACKET_SIZE]; + + for (; bytes > 0; bytes -= max_length) { + WebRtc_Word32 header_length; + { + // Correct seq num, timestamp and payload type. + header_length = BuildRTPheader(data_buffer, + payload_type, + false, // No markerbit. + capture_timestamp, + true, // Timestamp provided. + true); // Increment sequence number. + } + data_buffer[0] |= 0x20; // Set padding bit. + WebRtc_Word32* data = + reinterpret_cast(&(data_buffer[header_length])); + + int padding_bytes_in_packet = max_length; + if (bytes < max_length) { + padding_bytes_in_packet = (bytes + 16) & 0xffe0; // Keep our modulus 32. + } + if (padding_bytes_in_packet < 32) { + // Sanity don't send empty packets. + break; + } + // Fill data buffer with random data. + for(int j = 0; j < (padding_bytes_in_packet >> 2); j++) { + data[j] = rand(); + } + // Set number of padding bytes in the last byte of the packet. + data_buffer[header_length + padding_bytes_in_packet - 1] = + padding_bytes_in_packet; + // Send the packet + if (0 > SendToNetwork(data_buffer, + padding_bytes_in_packet, + header_length, + kDontRetransmit)) { + // Error sending the packet. + break; + } + } + if (bytes > 31) { // 31 due to our modulus 32. + // We did not manage to send all bytes. + return -1; + } + return 0; +} + WebRtc_Word32 RTPSender::SetStorePacketsStatus(const bool enable, const WebRtc_UWord16 numberToStore) { diff --git a/src/modules/rtp_rtcp/source/rtp_sender.h b/src/modules/rtp_rtcp/source/rtp_sender.h index a5462218c1..76b0f5221c 100644 --- a/src/modules/rtp_rtcp/source/rtp_sender.h +++ b/src/modules/rtp_rtcp/source/rtp_sender.h @@ -147,6 +147,9 @@ public: VideoCodecInformation* codecInfo = NULL, const RTPVideoTypeHeader* rtpTypeHdr = NULL); + WebRtc_Word32 SendPadData(WebRtc_Word8 payload_type, + WebRtc_UWord32 capture_timestamp, + WebRtc_Word32 bytes); /* * RTP header extension */ diff --git a/src/modules/rtp_rtcp/source/rtp_sender_video.cc b/src/modules/rtp_rtcp/source/rtp_sender_video.cc index 653249c2a9..bbbae187d3 100644 --- a/src/modules/rtp_rtcp/source/rtp_sender_video.cc +++ b/src/modules/rtp_rtcp/source/rtp_sender_video.cc @@ -549,55 +549,6 @@ RTPSenderVideo::SendGeneric(const WebRtc_Word8 payloadType, return 0; } -void RTPSenderVideo::SendPadData(WebRtc_Word8 payload_type, - WebRtc_UWord32 capture_timestamp, - WebRtc_Word32 bytes) { - // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. - int max_length = 224; - WebRtc_UWord8 data_buffer[IP_PACKET_SIZE]; - - for (; bytes > 0; bytes -= max_length) { - WebRtc_Word32 header_length; - { - CriticalSectionScoped cs(_sendVideoCritsect); - - // Correct seq num, timestamp and payload type. - header_length = _rtpSender.BuildRTPheader( - data_buffer, - payload_type, - false, // No markerbit. - capture_timestamp, - true, // Timestamp provided. - true); // Increment sequence number. - - } - data_buffer[0] |= 0x20; // Set padding bit. - WebRtc_Word32* data = - reinterpret_cast(&(data_buffer[header_length])); - - int padding_bytes_in_packet = max_length; - if (bytes < max_length) { - padding_bytes_in_packet = (bytes + 16) & 0xffe0; // Keep our modulus 32. - } - if (padding_bytes_in_packet < 32) { - // Sanity don't send empty packets. - return; - } - // Fill data buffer with random data. - for(int j = 0; j < (padding_bytes_in_packet >> 2); j++) { - data[j] = rand(); - } - // Set number of padding bytes in the last byte of the packet. - data_buffer[header_length + padding_bytes_in_packet - 1] = - padding_bytes_in_packet; - // Send the packet - _rtpSender.SendToNetwork(data_buffer, - padding_bytes_in_packet, - header_length, - kDontRetransmit); - } -} - WebRtc_Word32 RTPSenderVideo::SendMPEG4(const FrameType frameType, const WebRtc_Word8 payloadType, diff --git a/src/modules/rtp_rtcp/source/rtp_sender_video.h b/src/modules/rtp_rtcp/source/rtp_sender_video.h index e45ed8de73..92eb4fa873 100644 --- a/src/modules/rtp_rtcp/source/rtp_sender_video.h +++ b/src/modules/rtp_rtcp/source/rtp_sender_video.h @@ -68,10 +68,6 @@ public: WebRtc_UWord32 MaxConfiguredBitrateVideo() const; - void SendPadData(WebRtc_Word8 payload_type, - WebRtc_UWord32 capture_timestamp, - WebRtc_Word32 bytes); - // FEC WebRtc_Word32 SetGenericFECStatus(const bool enable, const WebRtc_UWord8 payloadTypeRED,