2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2009-02-22 12:07:18 +01:00
|
|
|
* Copyright (c) 2004-2009
|
2006-12-18 15:39:33 +01:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
2010-01-03 14:29:42 +01:00
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
2006-12-18 15:39:33 +01:00
|
|
|
* version.
|
|
|
|
*
|
2010-01-03 14:29:42 +01:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
2006-12-18 15:39:33 +01:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2010-01-03 14:29:42 +01:00
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
2006-12-18 15:39:33 +01:00
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
2010-01-03 14:29:42 +01:00
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
2006-12-18 15:39:33 +01:00
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#if !defined ( BUFFER_H__3B123453_4344_BB23945IUHF1912__INCLUDED_ )
|
2006-12-18 15:39:33 +01:00
|
|
|
#define BUFFER_H__3B123453_4344_BB23945IUHF1912__INCLUDED_
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "global.h"
|
|
|
|
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2010-01-03 14:29:42 +01:00
|
|
|
/* Definitions ****************************************************************/
|
|
|
|
// each regular buffer access lead to a count for put and get, assuming 2.33 ms
|
|
|
|
// blocks we have 30 s / 2.33 ms * 2 = 25714
|
|
|
|
#define MAX_STATISTIC_COUNT 25714
|
|
|
|
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
/* Classes ********************************************************************/
|
2010-01-03 14:29:42 +01:00
|
|
|
// Network buffer (jitter buffer) ----------------------------------------------
|
2006-12-18 15:39:33 +01:00
|
|
|
class CNetBuf
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CNetBuf() {}
|
|
|
|
virtual ~CNetBuf() {}
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
void Init ( const int iNewBlockSize, const int iNewNumBlocks );
|
|
|
|
int GetSize() { return iMemSize / iBlockSize; }
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2009-07-31 20:53:40 +02:00
|
|
|
bool Put ( const CVector<uint8_t>& vecbyData, const int iInSize );
|
2009-07-24 16:31:25 +02:00
|
|
|
bool Get ( CVector<uint8_t>& vecbyData );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2010-01-03 14:29:42 +01:00
|
|
|
double GetErrorRate() { return ErrorRateStatistic.GetAverage(); }
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
protected:
|
2007-09-08 12:45:14 +02:00
|
|
|
enum EBufState { BS_OK, BS_FULL, BS_EMPTY };
|
|
|
|
enum EClearType { CT_PUT, CT_GET };
|
|
|
|
void Clear ( const EClearType eClearType );
|
2006-12-18 15:39:33 +01:00
|
|
|
int GetAvailSpace() const;
|
2006-11-25 15:46:57 +01:00
|
|
|
int GetAvailData() const;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2009-07-24 16:31:25 +02:00
|
|
|
CVector<uint8_t> vecbyMemory;
|
|
|
|
int iMemSize;
|
|
|
|
int iBlockSize;
|
2009-08-22 18:13:21 +02:00
|
|
|
int iNumInvalidElements;
|
2009-07-24 16:31:25 +02:00
|
|
|
int iGetPos, iPutPos;
|
|
|
|
EBufState eBufState;
|
2010-01-03 14:29:42 +01:00
|
|
|
|
|
|
|
// statistic
|
|
|
|
CErrorRate ErrorRateStatistic;
|
2006-12-18 15:39:33 +01:00
|
|
|
};
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
|
2010-01-03 14:29:42 +01:00
|
|
|
// Conversion buffer (very simple buffer) --------------------------------------
|
2009-07-28 22:31:23 +02:00
|
|
|
template<class TData> class CConvBuf
|
2006-01-28 12:29:22 +01:00
|
|
|
{
|
|
|
|
public:
|
2009-08-11 11:10:23 +02:00
|
|
|
CConvBuf() { Init ( 0 ); }
|
2007-09-08 12:45:14 +02:00
|
|
|
virtual ~CConvBuf() {}
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2009-07-28 22:31:23 +02:00
|
|
|
void Init ( const int iNewMemSize )
|
|
|
|
{
|
|
|
|
// set memory size
|
|
|
|
iMemSize = iNewMemSize;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2009-07-28 22:31:23 +02:00
|
|
|
// allocate and clear memory for actual data buffer
|
|
|
|
vecsMemory.Init ( iMemSize );
|
|
|
|
|
|
|
|
iPutPos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetSize() const { return iMemSize; }
|
|
|
|
|
2009-07-30 20:36:37 +02:00
|
|
|
bool Put ( const CVector<TData>& vecsData )
|
2009-07-28 22:31:23 +02:00
|
|
|
{
|
|
|
|
const int iVecSize = vecsData.Size();
|
|
|
|
|
|
|
|
// copy new data in internal buffer
|
|
|
|
int iCurPos = 0;
|
|
|
|
const int iEnd = iPutPos + iVecSize;
|
2009-08-11 11:10:23 +02:00
|
|
|
|
|
|
|
// first check for buffer overrun
|
|
|
|
if ( iEnd <= iMemSize )
|
2009-07-28 22:31:23 +02:00
|
|
|
{
|
2009-08-11 11:10:23 +02:00
|
|
|
// actual copy operation
|
|
|
|
while ( iPutPos < iEnd )
|
|
|
|
{
|
|
|
|
vecsMemory[iPutPos++] = vecsData[iCurPos++];
|
|
|
|
}
|
|
|
|
|
|
|
|
// return "buffer is ready for readout" flag
|
|
|
|
return ( iEnd == iMemSize );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// buffer overrun or not initialized, return "not ready"
|
|
|
|
return false;
|
2009-07-28 22:31:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-30 20:36:37 +02:00
|
|
|
CVector<TData> Get()
|
2009-07-28 22:31:23 +02:00
|
|
|
{
|
|
|
|
iPutPos = 0;
|
|
|
|
return vecsMemory;
|
|
|
|
}
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
protected:
|
2009-07-28 22:31:23 +02:00
|
|
|
CVector<TData> vecsMemory;
|
|
|
|
int iMemSize;
|
|
|
|
int iPutPos;
|
2006-01-28 12:29:22 +01:00
|
|
|
};
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#endif /* !defined ( BUFFER_H__3B123453_4344_BB23945IUHF1912__INCLUDED_ ) */
|