preparations for allowing different network block sizes

This commit is contained in:
Volker Fischer 2006-03-11 20:35:38 +00:00
parent f13b3029a7
commit e904c495ea
7 changed files with 104 additions and 56 deletions

View file

@ -33,20 +33,24 @@
/* Implementation *************************************************************/
int CAudioCompression::Init(const int iNewAudioLen,
const EAudComprType eNewAuCoTy)
int CAudioCompression::Init ( const int iNewAudioLen,
const EAudComprType eNewAuCoTy )
{
eAudComprType = eNewAuCoTy;
switch (eNewAuCoTy)
switch ( eNewAuCoTy )
{
case CT_NONE: return iCodeSize = 2 * iNewAudioLen; /* short = 2 * byte */
case CT_IMAADPCM: return ImaAdpcm.Init(iNewAudioLen);
case CT_NONE:
return iCodeSize = 2 * iNewAudioLen; /* short = 2 * byte */
case CT_IMAADPCM:
return ImaAdpcm.Init ( iNewAudioLen );
default: return 0;
}
}
CVector<unsigned char> CAudioCompression::Encode(const CVector<short>& vecsAudio)
CVector<unsigned char> CAudioCompression::Encode ( const CVector<short>& vecsAudio )
{
if (eAudComprType == CT_NONE)
{
@ -63,10 +67,13 @@ CVector<unsigned char> CAudioCompression::Encode(const CVector<short>& vecsAudio
}
else
{
switch (eAudComprType)
switch ( eAudComprType )
{
case CT_IMAADPCM: return ImaAdpcm.Encode(vecsAudio); /* IMA-ADPCM */
default: return CVector<unsigned char>(0);
case CT_IMAADPCM:
return ImaAdpcm.Encode ( vecsAudio ); /* IMA-ADPCM */
default:
return CVector<unsigned char> ( 0 );
}
}
}
@ -91,10 +98,13 @@ CVector<short> CAudioCompression::Decode(const CVector<unsigned char>& vecbyAdpc
}
else
{
switch (eAudComprType)
switch ( eAudComprType )
{
case CT_IMAADPCM: return ImaAdpcm.Decode(vecbyAdpcm); /* IMA-ADPCM */
default: return CVector<short>(0);
case CT_IMAADPCM:
return ImaAdpcm.Decode ( vecbyAdpcm ); /* IMA-ADPCM */
default:
return CVector<short> ( 0 );
}
}
}

View file

@ -56,12 +56,12 @@ static int ima_step_size[IMA_STEP_SIZE_TAB_LEN] =
class CImaAdpcm
{
public:
CImaAdpcm() : iStepindEnc(0) {}
CImaAdpcm() : iStepindEnc ( 0 ) {}
virtual ~CImaAdpcm() {}
int Init(const int iNewAudioLen);
CVector<unsigned char> Encode(const CVector<short>& vecsAudio);
CVector<short> Decode(const CVector<unsigned char>& vecbyAdpcm);
int Init ( const int iNewAudioLen );
CVector<unsigned char> Encode ( const CVector<short>& vecsAudio );
CVector<short> Decode ( const CVector<unsigned char>& vecbyAdpcm );
protected:
int iAudSize;
@ -69,12 +69,17 @@ protected:
int iStepindEnc;
/* inline functions must be declared in the header */
inline int CheckBounds(const int iData, const int iMin, const int iMax)
inline int CheckBounds ( const int iData, const int iMin, const int iMax )
{
if ( iData > iMax )
{
if (iData > iMax)
return iMax;
if (iData < iMin)
}
if ( iData < iMin )
{
return iMin;
}
return iData;
}
@ -90,9 +95,10 @@ public:
CAudioCompression() {}
virtual ~CAudioCompression() {}
int Init(const int iNewAudioLen, const EAudComprType eNewAuCoTy);
CVector<unsigned char> Encode(const CVector<short>& vecsAudio);
CVector<short> Decode(const CVector<unsigned char>& vecbyAdpcm);
int Init ( const int iNewAudioLen,
const EAudComprType eNewAuCoTy );
CVector<unsigned char> Encode ( const CVector<short>& vecsAudio );
CVector<short> Decode ( const CVector<unsigned char>& vecbyAdpcm );
protected:
EAudComprType eAudComprType;

View file

@ -231,9 +231,9 @@ CChannel::CChannel ()
/* init conversion buffer */
ConvBuf.Init ( BLOCK_SIZE_SAMPLES );
/* init audio compression unit */
iAudComprSize = AudioCompression.Init ( BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
// set initial input and output block size factors
SetNetwInBlSiFact ( NET_BLOCK_SIZE_FACTOR );
SetNetwOutBlSiFact ( NET_BLOCK_SIZE_FACTOR );
/* init time-out for the buffer with zero -> no connection */
iConTimeOut = 0;
@ -251,6 +251,32 @@ CChannel::CChannel ()
SIGNAL ( ReqJittBufSize() ) );
}
void CChannel::SetNetwInBlSiFact ( const int iNewBlockSizeFactor )
{
// store new value
iCurNetwInBlSiFact = iNewBlockSizeFactor;
/* init audio compression unit */
iAudComprSizeIn = AudioCompressionIn.Init (
iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
// initial value for connection time out counter
iConTimeOutStartVal = ( CON_TIME_OUT_SEC_MAX * 1000 ) /
( iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES );
}
void CChannel::SetNetwOutBlSiFact ( const int iNewBlockSizeFactor )
{
/* init audio compression unit */
iAudComprSizeOut = AudioCompressionOut.Init (
iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
/* init conversion buffer */
ConvBuf.Init ( iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES );
}
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
{
// only send messages if we are connected, otherwise delete complete queue
@ -304,11 +330,10 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
EPutDataStat eRet = PS_GEN_ERROR;
/* only process if packet has correct size */
if ( iNumBytes == iAudComprSize )
if ( iNumBytes == iAudComprSizeIn )
{
/* decompress audio */
CVector<short> vecsDecomprAudio ( BLOCK_SIZE_SAMPLES );
vecsDecomprAudio = AudioCompression.Decode ( vecbyData );
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
/* do resampling to compensate for sample rate offsets in the
different sound cards of the clients */
@ -320,9 +345,10 @@ const int iInSize = ResampleObj.Resample(vecdResInData, vecdResOutData,
(double) SAMPLE_RATE / (SAMPLE_RATE - dSamRateOffset));
*/
vecdResOutData.Init(BLOCK_SIZE_SAMPLES);
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
vecdResOutData.Init ( iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES );
for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) {
vecdResOutData[i] = (double) vecsDecomprAudio[i];
}
Mutex.lock (); /* put mutex lock */
@ -342,7 +368,7 @@ for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
const bool bChanWasNotConnected = !IsConnected();
// reset time-out counter
iConTimeOut = CON_TIME_OUT_CNT_MAX;
iConTimeOut = iConTimeOutStartVal;
// if channel was not connected, emit signal to inform that new
// connection was established
@ -404,8 +430,8 @@ CVector<unsigned char> CChannel::PrepSendPacket(const CVector<short>& vecsNPacke
if ( ConvBuf.Put ( vecsNPacket ) )
{
/* a packet is ready, compress audio */
vecbySendBuf.Init ( iAudComprSize );
vecbySendBuf = AudioCompression.Encode ( ConvBuf.Get () );
vecbySendBuf.Init ( iAudComprSizeOut );
vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get () );
}
return vecbySendBuf;

View file

@ -40,7 +40,6 @@
connected to not-connected (the actual time depends on the way the error
correction is implemented) */
#define CON_TIME_OUT_SEC_MAX 5 // seconds
#define CON_TIME_OUT_CNT_MAX ( ( CON_TIME_OUT_SEC_MAX * 1000 ) / BLOCK_DURATION_MS )
/* maximum number of internet connections (channels) */
// if you want to change this paramter, change the connections in this class, too!
@ -77,8 +76,6 @@ public:
bool IsConnected() const { return iConTimeOut > 0; }
int GetComprAudSize() { return iAudComprSize; }
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
bool GetAddress ( CHostAddress& RetAddr );
CHostAddress GetAddress () { return InetAddr; }
@ -98,9 +95,14 @@ public:
void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); }
protected:
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor );
void SetNetwOutBlSiFact ( const int iNewBlockSizeFactor );
/* audio compression */
CAudioCompression AudioCompression;
int iAudComprSize;
CAudioCompression AudioCompressionIn;
int iAudComprSizeIn;
CAudioCompression AudioCompressionOut;
int iAudComprSizeOut;
/* resampling */
CResample ResampleObj;
@ -125,6 +127,9 @@ protected:
int iTimeStampActCnt;
int iConTimeOut;
int iConTimeOutStartVal;
int iCurNetwInBlSiFact;
QMutex Mutex;

View file

@ -66,10 +66,14 @@
/* first tests showed that with 24000 kHz a block time shorter than 5 ms leads to
much higher DSL network latencies. A length of 6 ms seems to be optimal */
#define NET_BLOCK_SIZE_FACTOR 3 // 3 * 2 ms = 6 ms
// maximum value of factor for network block size
#define NET_BLOCK_SIZE_FACTOR_MAX 10
#define BLOCK_DURATION_MS 6 /* ms */
#define BLOCK_SIZE_SAMPLES ( BLOCK_DURATION_MS * SAMPLE_RATE / 1000 )
#define SND_CRD_BLOCK_SIZE_SAMPLES ( BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000 )
/* maximum network buffer size (which can be chosen by slider) */
#define MAX_NET_BUF_SIZE_NUM_BL 12 /* number of blocks */
@ -97,7 +101,7 @@
/* length of the moving average buffer for response time measurement */
#define TIME_MOV_AV_RESPONSE 30 /* seconds */
#define LEN_MOV_AV_RESPONSE (TIME_MOV_AV_RESPONSE * 1000 / BLOCK_DURATION_MS)
#define LEN_MOV_AV_RESPONSE (TIME_MOV_AV_RESPONSE * 1000 / MIN_BLOCK_DURATION_MS)
#define _MAXSHORT 32767

View file

@ -38,7 +38,7 @@
/* Definitions ****************************************************************/
/* maximum block size for network input buffer. Consider two bytes per sample */
#define MAX_SIZE_BYTES_NETW_BUF (BLOCK_SIZE_SAMPLES * 2)
#define MAX_SIZE_BYTES_NETW_BUF ( NET_BLOCK_SIZE_FACTOR_MAX * MIN_BLOCK_SIZE_SAMPLES * 2 )
/* Classes ********************************************************************/

View file

@ -42,11 +42,8 @@
#define MAX_SND_BUF_IN 200
#define MAX_SND_BUF_OUT 200
#define NUM_SOUND_BUFFERS_IN (70 / BLOCK_DURATION_MS)
#define NUM_SOUND_BUFFERS_OUT (80 / BLOCK_DURATION_MS)
//#define NUM_SOUND_BUFFERS_IN 7//200 /* Number of sound card buffers */
//#define NUM_SOUND_BUFFERS_OUT 8//100//15 /* Number of sound card buffers */
#define NUM_SOUND_BUFFERS_IN (70 / MIN_BLOCK_DURATION_MS)
#define NUM_SOUND_BUFFERS_OUT (80 / MIN_BLOCK_DURATION_MS)
/* Maximum number of recognized sound cards installed in the system */
#define MAX_NUMBER_SOUND_CARDS 10