From 5579381f1c8e6245486e7e16a31071aea0acc86b Mon Sep 17 00:00:00 2001 From: Nico Grunbaum Date: Thu, 22 Jun 2017 00:46:07 -0700 Subject: [PATCH] Bug 1305813 - do not send empty StreamId;r=drno Also moving RID (StreamID) storage to the stack to clear up the TODO item and simplify the code. When unset the StreamID is stored as an empty string. Added missing GUARDED_BY on rid_ Added a check to shortcut checking strlen on the StreamId when it is an empty string (which is most of the time). MozReview-Commit-ID: EPUlPNBXYsQ --HG-- extra : rebase_source : 08e1b9ea796c991d141164424014d2311ff9341c --- .../modules/rtp_rtcp/source/rtp_sender.cc | 19 +++++++------------ .../modules/rtp_rtcp/source/rtp_sender.h | 2 +- .../rtp_rtcp/source/rtp_sender_video.cc | 8 ++++++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index e18b7195d0bb..d3bde18730d6 100644 --- a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -97,7 +97,7 @@ RTPSender::RTPSender( payload_type_(-1), payload_type_map_(), rtp_header_extension_map_(), - rid_(NULL), + rid_{0}, packet_history_(clock), flexfec_packet_history_(clock), // Statistics @@ -166,10 +166,6 @@ RTPSender::~RTPSender() { delete it->second; payload_type_map_.erase(it); } - - if (rid_) { - delete[] rid_; - } } uint16_t RTPSender::ActualSendBitrateKbit() const { @@ -200,13 +196,12 @@ uint32_t RTPSender::NackOverheadRate() const { int32_t RTPSender::SetRID(const char* rid) { rtc::CritScope lock(&send_critsect_); - // TODO(jesup) avoid allocations - if (!rid_ || strlen(rid_) < strlen(rid)) { - // rid rarely changes length.... - delete [] rid_; - rid_ = new char[strlen(rid)+1]; + const size_t len = rid ? strlen(rid) : 0; + if (!len || len >= sizeof(rid_)) { + rid_[0] = '\0'; + } else { + memmove(&rid_[0], rid, len + 1); } - strcpy(rid_, rid); return 0; } @@ -455,7 +450,7 @@ bool RTPSender::SendOutgoingData(FrameType frame_type, result = video_->SendVideo(video_type, frame_type, payload_type, rtp_timestamp, capture_time_ms, payload_data, payload_size, fragmentation, rtp_header, - rid_); + &rid_[0]); } rtc::CritScope cs(&statistics_crit_); diff --git a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender.h b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender.h index b3da02e6ef32..f1b6aa78e1d4 100644 --- a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender.h +++ b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender.h @@ -280,7 +280,7 @@ class RTPSender { RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(send_critsect_); - char* rid_; + char rid_[kRIDSize + 1] GUARDED_BY(send_critsect_); // Tracks the current request for playout delay limits from application // and decides whether the current RTP frame should include the playout diff --git a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc index 4167fc6fcd6b..06319771be5d 100644 --- a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc +++ b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc @@ -17,6 +17,7 @@ #include #include +#include "webrtc/common_types.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/base/trace_event.h" @@ -324,8 +325,11 @@ bool RTPSenderVideo::SendVideo(RtpVideoCodecTypes video_type, rtp_header->SetExtension(current_rotation); last_rotation_ = current_rotation; } - if (rid) { - rtp_header->SetExtensionWithLength(strlen(rid)-1, rid); + if (rid && rid[0]) { + const size_t len = strlen(rid); + if (len) { + rtp_header->SetExtensionWithLength(len - 1, rid); + } } // FEC settings.