diff --git a/src/buffer.cpp b/src/buffer.cpp index 90fd49a4..af506903 100755 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -28,7 +28,7 @@ #include "buffer.h" -/* Implementation *************************************************************/ +/* Network buffer implementation **********************************************/ void CNetBuf::Init ( const int iNewBlockSize, const int iNewNumBlocks ) { @@ -40,9 +40,6 @@ void CNetBuf::Init ( const int iNewBlockSize, // use the "get" flag to make sure the buffer is cleared Clear ( CT_GET ); - - // init statistic - ErrorRateStatistic.Init ( MAX_STATISTIC_COUNT ); } bool CNetBuf::Put ( const CVector& vecbyData, @@ -70,9 +67,6 @@ bool CNetBuf::Put ( const CVector& vecbyData, // copy new data in internal buffer (implemented in base class) CBufferBase::Put ( vecbyData, iInSize ); - // update statistic - ErrorRateStatistic.Update ( !bPutOK ); - return bPutOK; } @@ -120,9 +114,6 @@ bool CNetBuf::Get ( CVector& vecbyData ) // class) CBufferBase::Get ( vecbyData ); - // update statistic - ErrorRateStatistic.Update ( !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& 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& vecbyData ) +{ + // call base class Get + const bool bGetOK = CNetBuf::Get ( vecbyData ); + + // update statistic + ErrorRateStatistic.Update ( !bGetOK ); + + return bGetOK; +} diff --git a/src/buffer.h b/src/buffer.h index f48a1c87..eb12fee6 100755 --- a/src/buffer.h +++ b/src/buffer.h @@ -193,15 +193,10 @@ protected: { // in this simulation only the buffer pointers and the buffer state // 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 += iInSize - iMemSize - 1; - } - else - { - // data can be written in one step - iPutPos += iInSize - 1; + iPutPos -= iMemSize; } // set buffer state flag @@ -219,15 +214,10 @@ protected: { // in this simulation only the buffer pointers and the buffer state // 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 += iInSize - iMemSize - 1; - } - else - { - // data can be read in one step - iGetPos += iInSize - 1; + iGetPos -= iMemSize; } // set buffer state flag @@ -252,24 +242,36 @@ protected: class CNetBuf : public CBufferBase { public: - void Init ( const int iNewBlockSize, const int iNewNumBlocks ); + virtual void Init ( const int iNewBlockSize, const int iNewNumBlocks ); int GetSize() { return iMemSize / iBlockSize; } - bool Put ( const CVector& vecbyData, const int iInSize ); - bool Get ( CVector& vecbyData ); - - double GetErrorRate() { return ErrorRateStatistic.GetAverage(); } + virtual bool Put ( const CVector& vecbyData, const int iInSize ); + virtual bool Get ( CVector& vecbyData ); protected: enum EClearType { CT_PUT, CT_GET }; void Clear ( const EClearType eClearType ); - int iBlockSize; - int iNumInvalidElements; + int iBlockSize; + 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& vecbyData, const int iInSize ); + virtual bool Get ( CVector& vecbyData ); + + double GetErrorRate() { return ErrorRateStatistic.GetAverage(); } + +protected: // statistic - CErrorRate ErrorRateStatistic; + CErrorRate ErrorRateStatistic; }; diff --git a/src/channel.h b/src/channel.h index 09badca5..e0123c36 100755 --- a/src/channel.h +++ b/src/channel.h @@ -143,7 +143,7 @@ protected: CVector vecdGains; // network jitter-buffer - CNetBuf SockBuf; + CNetBufWithStats SockBuf; int iCurSockBufNumFrames; CCycleTimeVariance CycleTimeVariance;