From ffe1b17b57a6f617f33a85ff43905a145b4fed92 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Thu, 21 Nov 2013 13:53:13 +0000 Subject: [PATCH] Lock access to ModuleRtpRtcpImpl::simulcast_. Fixes race between RegisterSendPayload and SendOutgoingData. BUG= R=stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/4099006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5152 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index 6c5aff9f5..44b33a855 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -352,7 +352,12 @@ int32_t ModuleRtpRtcpImpl::RegisterSendPayload( video_codec.plType); send_video_codec_ = video_codec; - simulcast_ = (video_codec.numberOfSimulcastStreams > 1) ? true : false; + { + // simulcast_ is accessed when accessing child_modules_, so this write needs + // to be protected by the same lock. + CriticalSectionScoped lock(critical_section_module_ptrs_.get()); + simulcast_ = video_codec.numberOfSimulcastStreams > 1; + } return rtp_sender_.RegisterPayload(video_codec.plName, video_codec.plType, 90000, @@ -606,12 +611,12 @@ int32_t ModuleRtpRtcpImpl::SendOutgoingData( &(rtp_video_hdr->codecHeader)); } int32_t ret_val = -1; + CriticalSectionScoped lock(critical_section_module_ptrs_.get()); if (simulcast_) { if (rtp_video_hdr == NULL) { return -1; } int idx = 0; - CriticalSectionScoped lock(critical_section_module_ptrs_.get()); std::list::iterator it = child_modules_.begin(); for (; idx < rtp_video_hdr->simulcastIdx; ++it) { if (it == child_modules_.end()) { @@ -644,7 +649,6 @@ int32_t ModuleRtpRtcpImpl::SendOutgoingData( fragmentation, rtp_video_hdr); } else { - CriticalSectionScoped lock(critical_section_module_ptrs_.get()); std::list::iterator it = child_modules_.begin(); // Send to all "child" modules while (it != child_modules_.end()) {