From 2f8d5f330279f42ac79174dbbc2e4722f5cf535e Mon Sep 17 00:00:00 2001 From: "stefan@webrtc.org" Date: Tue, 15 Apr 2014 12:28:46 +0000 Subject: [PATCH] Check if a header extension is registered before updating it and fail silently if it's not. BUG= R=andresp@webrtc.org Review URL: https://webrtc-codereview.appspot.com/12039004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5909 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../rtp_rtcp/source/rtp_header_extension.h | 2 + webrtc/modules/rtp_rtcp/source/rtp_sender.cc | 41 +++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extension.h b/webrtc/modules/rtp_rtcp/source/rtp_header_extension.h index b41653c8b..edffe8aec 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_header_extension.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extension.h @@ -62,6 +62,8 @@ class RtpHeaderExtensionMap { int32_t Deregister(const RTPExtensionType type); + bool IsRegistered(RTPExtensionType type) const; + int32_t GetType(const uint8_t id, RTPExtensionType* type) const; int32_t GetId(const RTPExtensionType type, uint8_t* id) const; diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index 1e5fb3cb5..c86c137a8 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -1234,7 +1234,13 @@ bool RTPSender::UpdateTransmissionTimeOffset( uint8_t *rtp_packet, const uint16_t rtp_packet_length, const RTPHeader &rtp_header, const int64_t time_diff_ms) const { CriticalSectionScoped cs(send_critsect_); - + // Get id. + uint8_t id = 0; + if (rtp_header_extension_map_.GetId(kRtpExtensionTransmissionTimeOffset, + &id) != 0) { + // Not registered. + return false; + } // Get length until start of header extension block. int extension_block_pos = rtp_header_extension_map_.GetLengthUntilBlockStartInBytes( @@ -1259,13 +1265,6 @@ bool RTPSender::UpdateTransmissionTimeOffset( "extension not found."; return false; } - // Get id. - uint8_t id = 0; - if (rtp_header_extension_map_.GetId(kRtpExtensionTransmissionTimeOffset, - &id) != 0) { - LOG(LS_WARNING) << "Failed to update transmission time offset, no id."; - return false; - } // Verify first byte in block. const uint8_t first_block_byte = (id << 4) + 2; if (rtp_packet[block_pos] != first_block_byte) { @@ -1285,6 +1284,12 @@ bool RTPSender::UpdateAudioLevel(uint8_t *rtp_packet, const uint8_t dBov) const { CriticalSectionScoped cs(send_critsect_); + // Get id. + uint8_t id = 0; + if (rtp_header_extension_map_.GetId(kRtpExtensionAudioLevel, &id) != 0) { + // Not registered. + return false; + } // Get length until start of header extension block. int extension_block_pos = rtp_header_extension_map_.GetLengthUntilBlockStartInBytes( @@ -1305,12 +1310,6 @@ bool RTPSender::UpdateAudioLevel(uint8_t *rtp_packet, LOG(LS_WARNING) << "Failed to update audio level, hdr extension not found."; return false; } - // Get id. - uint8_t id = 0; - if (rtp_header_extension_map_.GetId(kRtpExtensionAudioLevel, &id) != 0) { - LOG(LS_WARNING) << "Failed to update audio level, no id."; - return false; - } // Verify first byte in block. const uint8_t first_block_byte = (id << 4) + 0; if (rtp_packet[block_pos] != first_block_byte) { @@ -1326,6 +1325,13 @@ bool RTPSender::UpdateAbsoluteSendTime( const RTPHeader &rtp_header, const int64_t now_ms) const { CriticalSectionScoped cs(send_critsect_); + // Get id. + uint8_t id = 0; + if (rtp_header_extension_map_.GetId(kRtpExtensionAbsoluteSendTime, + &id) != 0) { + // Not registered. + return false; + } // Get length until start of header extension block. int extension_block_pos = rtp_header_extension_map_.GetLengthUntilBlockStartInBytes( @@ -1347,13 +1353,6 @@ bool RTPSender::UpdateAbsoluteSendTime( << "Failed to update absolute send time, hdr extension not found."; return false; } - // Get id. - uint8_t id = 0; - if (rtp_header_extension_map_.GetId(kRtpExtensionAbsoluteSendTime, - &id) != 0) { - LOG(LS_WARNING) << "Failed to update absolute send time, no id."; - return false; - } // Verify first byte in block. const uint8_t first_block_byte = (id << 4) + 2; if (rtp_packet[block_pos] != first_block_byte) {