Valgrind detects that there are racing conditions in RTPReceiver::PacketTimeout and RTPSender

This CL fixes two of them.
Review URL: http://webrtc-codereview.appspot.com/295005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1029 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
xians@webrtc.org 2011-11-25 13:43:53 +00:00
parent 0fcc2eb368
commit 8738d277a1
2 changed files with 23 additions and 16 deletions

View File

@ -457,15 +457,15 @@ From RFC 3550
a value of the RTCP bandwidth below the intended average a value of the RTCP bandwidth below the intended average
*/ */
WebRtc_UWord32 now = ModuleRTPUtility::GetTimeInMS();
CriticalSectionScoped lock(_criticalSectionRTCPSender);
if(_method == kRtcpOff) if(_method == kRtcpOff)
{ {
return false; return false;
} }
WebRtc_UWord32 now = ModuleRTPUtility::GetTimeInMS();
CriticalSectionScoped lock(_criticalSectionRTCPSender);
if(!_audio && sendKeyframeBeforeRTP) if(!_audio && sendKeyframeBeforeRTP)
{ {
// for video key-frames we want to send the RTCP before the large key-frame // for video key-frames we want to send the RTCP before the large key-frame
@ -1564,11 +1564,6 @@ RTCPSender::SendRTCP(const WebRtc_UWord32 packetTypeFlags,
WebRtc_UWord32 pos = 0; WebRtc_UWord32 pos = 0;
WebRtc_UWord8 rtcpbuffer[IP_PACKET_SIZE]; WebRtc_UWord8 rtcpbuffer[IP_PACKET_SIZE];
if(_method == kRtcpOff)
{
WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, "%s invalid state", __FUNCTION__);
return -1;
}
do // only to be able to use break :) (and the critsect must be inside its own scope) do // only to be able to use break :) (and the critsect must be inside its own scope)
{ {
@ -1577,8 +1572,20 @@ RTCPSender::SendRTCP(const WebRtc_UWord32 packetTypeFlags,
bool hasReceived = false; bool hasReceived = false;
WebRtc_UWord32 NTPsec = 0; WebRtc_UWord32 NTPsec = 0;
WebRtc_UWord32 NTPfrac = 0; WebRtc_UWord32 NTPfrac = 0;
bool rtcpCompound = false;
if( _method == kRtcpCompound || {
CriticalSectionScoped lock(_criticalSectionRTCPSender);
if(_method == kRtcpOff)
{
WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id,
"%s invalid state", __FUNCTION__);
return -1;
}
rtcpCompound = (_method == kRtcpCompound) ? true : false;
}
if (rtcpCompound ||
rtcpPacketTypeFlags & kRtcpReport || rtcpPacketTypeFlags & kRtcpReport ||
rtcpPacketTypeFlags & kRtcpSr || rtcpPacketTypeFlags & kRtcpSr ||
rtcpPacketTypeFlags & kRtcpRr) rtcpPacketTypeFlags & kRtcpRr)

View File

@ -236,15 +236,15 @@ RTPReceiver::SetPacketTimeout(const WebRtc_UWord32 timeoutMS)
void RTPReceiver::PacketTimeout() void RTPReceiver::PacketTimeout()
{ {
bool packetTimeOut = false;
{
CriticalSectionScoped lock(_criticalSectionRTPReceiver);
if(_packetTimeOutMS == 0) if(_packetTimeOutMS == 0)
{ {
// not configured // not configured
return; return;
} }
bool packetTimeOut = false;
{
CriticalSectionScoped lock(_criticalSectionRTPReceiver);
if(_lastReceiveTime == 0) if(_lastReceiveTime == 0)
{ {
// not active // not active