preparations for allowing different network block sizes
This commit is contained in:
parent
f13b3029a7
commit
e904c495ea
7 changed files with 104 additions and 56 deletions
|
@ -40,8 +40,12 @@ int CAudioCompression::Init(const int iNewAudioLen,
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +69,11 @@ CVector<unsigned char> CAudioCompression::Encode(const CVector<short>& vecsAudio
|
|||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,8 +100,11 @@ CVector<short> CAudioCompression::Decode(const CVector<unsigned char>& vecbyAdpc
|
|||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,9 +72,14 @@ protected:
|
|||
inline int CheckBounds ( const int iData, const int iMin, const int iMax )
|
||||
{
|
||||
if ( iData > iMax )
|
||||
{
|
||||
return iMax;
|
||||
}
|
||||
|
||||
if ( iData < iMin )
|
||||
{
|
||||
return iMin;
|
||||
}
|
||||
|
||||
return iData;
|
||||
}
|
||||
|
@ -90,7 +95,8 @@ public:
|
|||
CAudioCompression() {}
|
||||
virtual ~CAudioCompression() {}
|
||||
|
||||
int Init(const int iNewAudioLen, const EAudComprType eNewAuCoTy);
|
||||
int Init ( const int iNewAudioLen,
|
||||
const EAudComprType eNewAuCoTy );
|
||||
CVector<unsigned char> Encode ( const CVector<short>& vecsAudio );
|
||||
CVector<short> Decode ( const CVector<unsigned char>& vecbyAdpcm );
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ********************************************************************/
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue