Revert "Remove remains of WEBRTC_NO_STL." (rev 6641).

Reason breaks linux_memcheck.

TBR=stefan@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6645 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andresp@webrtc.org 2014-07-10 07:41:59 +00:00
parent e91ba268e3
commit 5ac876bae0
2 changed files with 103 additions and 0 deletions

View File

@ -57,12 +57,45 @@ SSRCDatabase::CreateSSRC()
uint32_t ssrc = GenerateRandom();
#ifndef WEBRTC_NO_STL
while(_ssrcMap.find(ssrc) != _ssrcMap.end())
{
ssrc = GenerateRandom();
}
_ssrcMap[ssrc] = 0;
#else
if(_sizeOfSSRC <= _numberOfSSRC)
{
// allocate more space
const int newSize = _sizeOfSSRC + 10;
uint32_t* tempSSRCVector = new uint32_t[newSize];
memcpy(tempSSRCVector, _ssrcVector, _sizeOfSSRC*sizeof(uint32_t));
delete [] _ssrcVector;
_ssrcVector = tempSSRCVector;
_sizeOfSSRC = newSize;
}
// check if in DB
if(_ssrcVector)
{
for (int i=0; i<_numberOfSSRC; i++)
{
if (_ssrcVector[i] == ssrc)
{
// we have a match
i = 0; // start over with a new ssrc
ssrc = GenerateRandom();
}
}
// add to database
_ssrcVector[_numberOfSSRC] = ssrc;
_numberOfSSRC++;
}
#endif
return ssrc;
}
@ -70,7 +103,39 @@ int32_t
SSRCDatabase::RegisterSSRC(const uint32_t ssrc)
{
CriticalSectionScoped lock(_critSect);
#ifndef WEBRTC_NO_STL
_ssrcMap[ssrc] = 0;
#else
if(_sizeOfSSRC <= _numberOfSSRC)
{
// allocate more space
const int newSize = _sizeOfSSRC + 10;
uint32_t* tempSSRCVector = new uint32_t[newSize];
memcpy(tempSSRCVector, _ssrcVector, _sizeOfSSRC*sizeof(uint32_t));
delete [] _ssrcVector;
_ssrcVector = tempSSRCVector;
_sizeOfSSRC = newSize;
}
// check if in DB
if(_ssrcVector)
{
for (int i=0; i<_numberOfSSRC; i++)
{
if (_ssrcVector[i] == ssrc)
{
// we have a match
return -1;
}
}
// add to database
_ssrcVector[_numberOfSSRC] = ssrc;
_numberOfSSRC++;
}
#endif
return 0;
}
@ -78,7 +143,26 @@ int32_t
SSRCDatabase::ReturnSSRC(const uint32_t ssrc)
{
CriticalSectionScoped lock(_critSect);
#ifndef WEBRTC_NO_STL
_ssrcMap.erase(ssrc);
#else
if(_ssrcVector)
{
for (int i=0; i<_numberOfSSRC; i++)
{
if (_ssrcVector[i] == ssrc)
{
// we have a match
// remove from database
_ssrcVector[i] = _ssrcVector[_numberOfSSRC-1];
_numberOfSSRC--;
break;
}
}
}
#endif
return 0;
}
@ -94,12 +178,22 @@ SSRCDatabase::SSRCDatabase()
srand(tv.tv_usec);
#endif
#ifdef WEBRTC_NO_STL
_sizeOfSSRC = 10;
_numberOfSSRC = 0;
_ssrcVector = new uint32_t[10];
#endif
_critSect = CriticalSectionWrapper::CreateCriticalSection();
}
SSRCDatabase::~SSRCDatabase()
{
#ifdef WEBRTC_NO_STL
delete [] _ssrcVector;
#else
_ssrcMap.clear();
#endif
delete _critSect;
}
uint32_t SSRCDatabase::GenerateRandom()

View File

@ -11,7 +11,9 @@
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_
#ifndef WEBRTC_NO_STL
#include <map>
#endif
#include "webrtc/system_wrappers/interface/static_instance.h"
#include "webrtc/typedefs.h"
@ -44,7 +46,14 @@ private:
uint32_t GenerateRandom();
#ifdef WEBRTC_NO_STL
int _numberOfSSRC;
int _sizeOfSSRC;
uint32_t* _ssrcVector;
#else
std::map<uint32_t, uint32_t> _ssrcMap;
#endif
CriticalSectionWrapper* _critSect;
};