added derived class for network buffer for the purpose of statistical calculations
This commit is contained in:
parent
793b21f9d9
commit
1a99b76365
3 changed files with 63 additions and 35 deletions
|
@ -28,7 +28,7 @@
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Network buffer implementation **********************************************/
|
||||||
void CNetBuf::Init ( const int iNewBlockSize,
|
void CNetBuf::Init ( const int iNewBlockSize,
|
||||||
const int iNewNumBlocks )
|
const int iNewNumBlocks )
|
||||||
{
|
{
|
||||||
|
@ -40,9 +40,6 @@ void CNetBuf::Init ( const int iNewBlockSize,
|
||||||
|
|
||||||
// use the "get" flag to make sure the buffer is cleared
|
// use the "get" flag to make sure the buffer is cleared
|
||||||
Clear ( CT_GET );
|
Clear ( CT_GET );
|
||||||
|
|
||||||
// init statistic
|
|
||||||
ErrorRateStatistic.Init ( MAX_STATISTIC_COUNT );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CNetBuf::Put ( const CVector<uint8_t>& vecbyData,
|
bool CNetBuf::Put ( const CVector<uint8_t>& vecbyData,
|
||||||
|
@ -70,9 +67,6 @@ bool CNetBuf::Put ( const CVector<uint8_t>& vecbyData,
|
||||||
// copy new data in internal buffer (implemented in base class)
|
// copy new data in internal buffer (implemented in base class)
|
||||||
CBufferBase<uint8_t>::Put ( vecbyData, iInSize );
|
CBufferBase<uint8_t>::Put ( vecbyData, iInSize );
|
||||||
|
|
||||||
// update statistic
|
|
||||||
ErrorRateStatistic.Update ( !bPutOK );
|
|
||||||
|
|
||||||
return bPutOK;
|
return bPutOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +114,6 @@ bool CNetBuf::Get ( CVector<uint8_t>& vecbyData )
|
||||||
// class)
|
// class)
|
||||||
CBufferBase<uint8_t>::Get ( vecbyData );
|
CBufferBase<uint8_t>::Get ( vecbyData );
|
||||||
|
|
||||||
// update statistic
|
|
||||||
ErrorRateStatistic.Update ( !bGetOK );
|
|
||||||
|
|
||||||
return bGetOK;
|
return bGetOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,3 +230,38 @@ void CNetBuf::Clear ( const EClearType eClearType )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Network buffer with statistic calculations implementation ******************/
|
||||||
|
void CNetBufWithStats::Init ( const int iNewBlockSize,
|
||||||
|
const int iNewNumBlocks )
|
||||||
|
{
|
||||||
|
// call base class Init
|
||||||
|
CNetBuf::Init ( iNewBlockSize, iNewNumBlocks );
|
||||||
|
|
||||||
|
// init statistic
|
||||||
|
ErrorRateStatistic.Init ( MAX_STATISTIC_COUNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CNetBufWithStats::Put ( const CVector<uint8_t>& vecbyData,
|
||||||
|
const int iInSize )
|
||||||
|
{
|
||||||
|
// call base class Put
|
||||||
|
const bool bPutOK = CNetBuf::Put ( vecbyData, iInSize );
|
||||||
|
|
||||||
|
// update statistic
|
||||||
|
ErrorRateStatistic.Update ( !bPutOK );
|
||||||
|
|
||||||
|
return bPutOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CNetBufWithStats::Get ( CVector<uint8_t>& vecbyData )
|
||||||
|
{
|
||||||
|
// call base class Get
|
||||||
|
const bool bGetOK = CNetBuf::Get ( vecbyData );
|
||||||
|
|
||||||
|
// update statistic
|
||||||
|
ErrorRateStatistic.Update ( !bGetOK );
|
||||||
|
|
||||||
|
return bGetOK;
|
||||||
|
}
|
||||||
|
|
50
src/buffer.h
50
src/buffer.h
|
@ -193,15 +193,10 @@ protected:
|
||||||
{
|
{
|
||||||
// in this simulation only the buffer pointers and the buffer state
|
// in this simulation only the buffer pointers and the buffer state
|
||||||
// is updated, no actual data is transferred
|
// is updated, no actual data is transferred
|
||||||
if ( iPutPos + iInSize > iMemSize )
|
iPutPos += iInSize;
|
||||||
|
if ( iPutPos >= iMemSize )
|
||||||
{
|
{
|
||||||
// data must be written in two steps because of wrap around
|
iPutPos -= iMemSize;
|
||||||
iPutPos += iInSize - iMemSize - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// data can be written in one step
|
|
||||||
iPutPos += iInSize - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set buffer state flag
|
// set buffer state flag
|
||||||
|
@ -219,15 +214,10 @@ protected:
|
||||||
{
|
{
|
||||||
// in this simulation only the buffer pointers and the buffer state
|
// in this simulation only the buffer pointers and the buffer state
|
||||||
// is updated, no actual data is transferred
|
// is updated, no actual data is transferred
|
||||||
if ( iGetPos + iInSize > iMemSize )
|
iGetPos += iInSize;
|
||||||
|
if ( iGetPos >= iMemSize )
|
||||||
{
|
{
|
||||||
// data must be read in two steps because of wrap around
|
iGetPos -= iMemSize;
|
||||||
iGetPos += iInSize - iMemSize - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// data can be read in one step
|
|
||||||
iGetPos += iInSize - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set buffer state flag
|
// set buffer state flag
|
||||||
|
@ -252,24 +242,36 @@ protected:
|
||||||
class CNetBuf : public CBufferBase<uint8_t>
|
class CNetBuf : public CBufferBase<uint8_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Init ( const int iNewBlockSize, const int iNewNumBlocks );
|
virtual void Init ( const int iNewBlockSize, const int iNewNumBlocks );
|
||||||
int GetSize() { return iMemSize / iBlockSize; }
|
int GetSize() { return iMemSize / iBlockSize; }
|
||||||
|
|
||||||
bool Put ( const CVector<uint8_t>& vecbyData, const int iInSize );
|
virtual bool Put ( const CVector<uint8_t>& vecbyData, const int iInSize );
|
||||||
bool Get ( CVector<uint8_t>& vecbyData );
|
virtual bool Get ( CVector<uint8_t>& vecbyData );
|
||||||
|
|
||||||
double GetErrorRate() { return ErrorRateStatistic.GetAverage(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum EClearType { CT_PUT, CT_GET };
|
enum EClearType { CT_PUT, CT_GET };
|
||||||
|
|
||||||
void Clear ( const EClearType eClearType );
|
void Clear ( const EClearType eClearType );
|
||||||
|
|
||||||
int iBlockSize;
|
int iBlockSize;
|
||||||
int iNumInvalidElements;
|
int iNumInvalidElements;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Network buffer (jitter buffer) with statistic calculations ------------------
|
||||||
|
class CNetBufWithStats : public CNetBuf
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Init ( const int iNewBlockSize, const int iNewNumBlocks );
|
||||||
|
|
||||||
|
virtual bool Put ( const CVector<uint8_t>& vecbyData, const int iInSize );
|
||||||
|
virtual bool Get ( CVector<uint8_t>& vecbyData );
|
||||||
|
|
||||||
|
double GetErrorRate() { return ErrorRateStatistic.GetAverage(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
// statistic
|
// statistic
|
||||||
CErrorRate ErrorRateStatistic;
|
CErrorRate ErrorRateStatistic;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ protected:
|
||||||
CVector<double> vecdGains;
|
CVector<double> vecdGains;
|
||||||
|
|
||||||
// network jitter-buffer
|
// network jitter-buffer
|
||||||
CNetBuf SockBuf;
|
CNetBufWithStats SockBuf;
|
||||||
int iCurSockBufNumFrames;
|
int iCurSockBufNumFrames;
|
||||||
|
|
||||||
CCycleTimeVariance CycleTimeVariance;
|
CCycleTimeVariance CycleTimeVariance;
|
||||||
|
|
Loading…
Reference in a new issue