Coverty: cleanup CheckCSRC.

Review URL: https://webrtc-codereview.appspot.com/369014

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1564 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pwestin@webrtc.org
2012-01-27 13:47:19 +00:00
parent 2f7740973d
commit 04cf69a714

View File

@ -1337,10 +1337,7 @@ WebRtc_Word32 RTPReceiver::CheckPayloadChanged(
} }
// no criticalsection when called // no criticalsection when called
void void RTPReceiver::CheckCSRC(const WebRtcRTPHeader* rtpHeader) {
RTPReceiver::CheckCSRC(const WebRtcRTPHeader* rtpHeader)
{
bool checkChanged = false;
WebRtc_Word32 numCSRCsDiff = 0; WebRtc_Word32 numCSRCsDiff = 0;
WebRtc_UWord32 oldRemoteCSRC[kRtpCsrcSize]; WebRtc_UWord32 oldRemoteCSRC[kRtpCsrcSize];
WebRtc_UWord8 oldNumCSRCs = 0; WebRtc_UWord8 oldNumCSRCs = 0;
@ -1348,115 +1345,88 @@ RTPReceiver::CheckCSRC(const WebRtcRTPHeader* rtpHeader)
{ {
CriticalSectionScoped lock(_criticalSectionRTPReceiver); CriticalSectionScoped lock(_criticalSectionRTPReceiver);
if(TelephoneEventPayloadType(rtpHeader->header.payloadType)) if (TelephoneEventPayloadType(rtpHeader->header.payloadType)) {
{ // Don't do this for DTMF packets
// don't do this for DTMF packets return;
return ;
} }
_numEnergy = rtpHeader->type.Audio.numEnergy; _numEnergy = rtpHeader->type.Audio.numEnergy;
if(rtpHeader->type.Audio.numEnergy > 0 && rtpHeader->type.Audio.numEnergy <= kRtpCsrcSize) if (rtpHeader->type.Audio.numEnergy > 0 &&
{ rtpHeader->type.Audio.numEnergy <= kRtpCsrcSize) {
memcpy(_currentRemoteEnergy, rtpHeader->type.Audio.arrOfEnergy, rtpHeader->type.Audio.numEnergy); memcpy(_currentRemoteEnergy,
rtpHeader->type.Audio.arrOfEnergy,
rtpHeader->type.Audio.numEnergy);
} }
oldNumCSRCs = _numCSRCs; oldNumCSRCs = _numCSRCs;
if (oldNumCSRCs > 0) {
// Make a copy of old.
memcpy(oldRemoteCSRC, _currentRemoteCSRC,
_numCSRCs * sizeof(WebRtc_UWord32));
}
const WebRtc_UWord8 numCSRCs = rtpHeader->header.numCSRCs; const WebRtc_UWord8 numCSRCs = rtpHeader->header.numCSRCs;
if ((numCSRCs > 0) && (numCSRCs <= kRtpCsrcSize)) {
if(((numCSRCs > 0) && (numCSRCs <= kRtpCsrcSize)) || oldNumCSRCs) // Copy new
{ memcpy(_currentRemoteCSRC,
if(oldNumCSRCs > 0) rtpHeader->header.arrOfCSRCs,
{ numCSRCs * sizeof(WebRtc_UWord32));
// make a copy of old
memcpy(oldRemoteCSRC, _currentRemoteCSRC, _numCSRCs * sizeof(WebRtc_UWord32));
}
if(numCSRCs > 0)
{
// copy new
memcpy(_currentRemoteCSRC, rtpHeader->header.arrOfCSRCs, numCSRCs * sizeof(WebRtc_UWord32));
} }
if (numCSRCs > 0 || oldNumCSRCs > 0) {
numCSRCsDiff = numCSRCs - oldNumCSRCs; numCSRCsDiff = numCSRCs - oldNumCSRCs;
_numCSRCs = numCSRCs; //update stored CSRCs _numCSRCs = numCSRCs; // Update stored CSRCs.
checkChanged = true; } else {
// No change.
return;
}
} // End scoped CriticalSection.
}else
{
if(_numCSRCs != 0)
{
checkChanged = true;
numCSRCsDiff = numCSRCs - oldNumCSRCs;
}
_numCSRCs = 0;
}
}
if(checkChanged )
{
CriticalSectionScoped lock(_criticalSectionCbs); CriticalSectionScoped lock(_criticalSectionCbs);
if(_cbRtpFeedback) if (_cbRtpFeedback == NULL) {
{ return;
}
bool haveCalledCallback = false; bool haveCalledCallback = false;
// search for new CSRC in old array // Search for new CSRC in old array.
for (WebRtc_UWord8 i = 0; i < rtpHeader->header.numCSRCs; ++i) for (WebRtc_UWord8 i = 0; i < rtpHeader->header.numCSRCs; ++i) {
{
const WebRtc_UWord32 csrc = rtpHeader->header.arrOfCSRCs[i]; const WebRtc_UWord32 csrc = rtpHeader->header.arrOfCSRCs[i];
bool foundMatch = false; bool foundMatch = false;
for (WebRtc_UWord8 j = 0; j < oldNumCSRCs; ++j) for (WebRtc_UWord8 j = 0; j < oldNumCSRCs; ++j) {
{ if (csrc == oldRemoteCSRC[j]) { // old list
if (csrc == oldRemoteCSRC[j]) // old list
{
foundMatch = true; foundMatch = true;
break; break;
} }
} }
if (!foundMatch && csrc) if (!foundMatch && csrc) {
{ // Didn't find it, report it as new.
// didn't find it
// report it as new
haveCalledCallback = true; haveCalledCallback = true;
_cbRtpFeedback->OnIncomingCSRCChanged(_id, csrc, true); _cbRtpFeedback->OnIncomingCSRCChanged(_id, csrc, true);
} }
} }
// Search for old CSRC in new array.
// search for old CSRC in new array for (WebRtc_UWord8 i = 0; i < oldNumCSRCs; ++i) {
for (WebRtc_UWord8 i = 0; i < oldNumCSRCs; ++i)
{
const WebRtc_UWord32 csrc = oldRemoteCSRC[i]; const WebRtc_UWord32 csrc = oldRemoteCSRC[i];
bool foundMatch = false; bool foundMatch = false;
for (WebRtc_UWord8 j = 0; j < rtpHeader->header.numCSRCs; ++j) for (WebRtc_UWord8 j = 0; j < rtpHeader->header.numCSRCs; ++j) {
{ if (csrc == rtpHeader->header.arrOfCSRCs[j]) {
if (csrc == rtpHeader->header.arrOfCSRCs[j])
{
foundMatch = true; foundMatch = true;
break; break;
} }
} }
if (!foundMatch && csrc) if (!foundMatch && csrc) {
{ // Did not find it, report as removed.
// did not find it
// report as removed
haveCalledCallback = true; haveCalledCallback = true;
_cbRtpFeedback->OnIncomingCSRCChanged(_id, csrc, false); _cbRtpFeedback->OnIncomingCSRCChanged(_id, csrc, false);
} }
} }
if(!haveCalledCallback) if (!haveCalledCallback) {
{ // If the CSRC list contain non-unique entries we will endup here.
// Layout change for less mixed streams than slots in the layout // Using CSRC 0 to signal this event, not interop safe, other
// won't trigger a callback above. // implementations might have CSRC 0 as avalid value.
if (numCSRCsDiff > 0) if (numCSRCsDiff > 0) {
{
_cbRtpFeedback->OnIncomingCSRCChanged(_id, 0, true); _cbRtpFeedback->OnIncomingCSRCChanged(_id, 0, true);
} } else if (numCSRCsDiff < 0) {
else if (numCSRCsDiff < 0)
{
_cbRtpFeedback->OnIncomingCSRCChanged(_id, 0, false); _cbRtpFeedback->OnIncomingCSRCChanged(_id, 0, false);
} }
} }
}
}
} }
WebRtc_Word32 WebRtc_Word32