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 )
|
switch ( eNewAuCoTy )
|
||||||
{
|
{
|
||||||
case CT_NONE: return iCodeSize = 2 * iNewAudioLen; /* short = 2 * byte */
|
case CT_NONE:
|
||||||
case CT_IMAADPCM: return ImaAdpcm.Init(iNewAudioLen);
|
return iCodeSize = 2 * iNewAudioLen; /* short = 2 * byte */
|
||||||
|
|
||||||
|
case CT_IMAADPCM:
|
||||||
|
return ImaAdpcm.Init ( iNewAudioLen );
|
||||||
|
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,8 +69,11 @@ CVector<unsigned char> CAudioCompression::Encode(const CVector<short>& vecsAudio
|
||||||
{
|
{
|
||||||
switch ( eAudComprType )
|
switch ( eAudComprType )
|
||||||
{
|
{
|
||||||
case CT_IMAADPCM: return ImaAdpcm.Encode(vecsAudio); /* IMA-ADPCM */
|
case CT_IMAADPCM:
|
||||||
default: return CVector<unsigned char>(0);
|
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 )
|
switch ( eAudComprType )
|
||||||
{
|
{
|
||||||
case CT_IMAADPCM: return ImaAdpcm.Decode(vecbyAdpcm); /* IMA-ADPCM */
|
case CT_IMAADPCM:
|
||||||
default: return CVector<short>(0);
|
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 )
|
inline int CheckBounds ( const int iData, const int iMin, const int iMax )
|
||||||
{
|
{
|
||||||
if ( iData > iMax )
|
if ( iData > iMax )
|
||||||
|
{
|
||||||
return iMax;
|
return iMax;
|
||||||
|
}
|
||||||
|
|
||||||
if ( iData < iMin )
|
if ( iData < iMin )
|
||||||
|
{
|
||||||
return iMin;
|
return iMin;
|
||||||
|
}
|
||||||
|
|
||||||
return iData;
|
return iData;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +95,8 @@ public:
|
||||||
CAudioCompression() {}
|
CAudioCompression() {}
|
||||||
virtual ~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<unsigned char> Encode ( const CVector<short>& vecsAudio );
|
||||||
CVector<short> Decode ( const CVector<unsigned char>& vecbyAdpcm );
|
CVector<short> Decode ( const CVector<unsigned char>& vecbyAdpcm );
|
||||||
|
|
||||||
|
|
|
@ -231,9 +231,9 @@ CChannel::CChannel ()
|
||||||
/* init conversion buffer */
|
/* init conversion buffer */
|
||||||
ConvBuf.Init ( BLOCK_SIZE_SAMPLES );
|
ConvBuf.Init ( BLOCK_SIZE_SAMPLES );
|
||||||
|
|
||||||
/* init audio compression unit */
|
// set initial input and output block size factors
|
||||||
iAudComprSize = AudioCompression.Init ( BLOCK_SIZE_SAMPLES,
|
SetNetwInBlSiFact ( NET_BLOCK_SIZE_FACTOR );
|
||||||
CAudioCompression::CT_IMAADPCM );
|
SetNetwOutBlSiFact ( NET_BLOCK_SIZE_FACTOR );
|
||||||
|
|
||||||
/* init time-out for the buffer with zero -> no connection */
|
/* init time-out for the buffer with zero -> no connection */
|
||||||
iConTimeOut = 0;
|
iConTimeOut = 0;
|
||||||
|
@ -251,6 +251,32 @@ CChannel::CChannel ()
|
||||||
SIGNAL ( ReqJittBufSize() ) );
|
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 )
|
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
||||||
{
|
{
|
||||||
// only send messages if we are connected, otherwise delete complete queue
|
// 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;
|
EPutDataStat eRet = PS_GEN_ERROR;
|
||||||
|
|
||||||
/* only process if packet has correct size */
|
/* only process if packet has correct size */
|
||||||
if ( iNumBytes == iAudComprSize )
|
if ( iNumBytes == iAudComprSizeIn )
|
||||||
{
|
{
|
||||||
/* decompress audio */
|
/* decompress audio */
|
||||||
CVector<short> vecsDecomprAudio ( BLOCK_SIZE_SAMPLES );
|
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
|
||||||
vecsDecomprAudio = AudioCompression.Decode ( vecbyData );
|
|
||||||
|
|
||||||
/* do resampling to compensate for sample rate offsets in the
|
/* do resampling to compensate for sample rate offsets in the
|
||||||
different sound cards of the clients */
|
different sound cards of the clients */
|
||||||
|
@ -320,9 +345,10 @@ const int iInSize = ResampleObj.Resample(vecdResInData, vecdResOutData,
|
||||||
(double) SAMPLE_RATE / (SAMPLE_RATE - dSamRateOffset));
|
(double) SAMPLE_RATE / (SAMPLE_RATE - dSamRateOffset));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
vecdResOutData.Init(BLOCK_SIZE_SAMPLES);
|
vecdResOutData.Init ( iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES );
|
||||||
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
|
for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) {
|
||||||
vecdResOutData[i] = (double) vecsDecomprAudio[i];
|
vecdResOutData[i] = (double) vecsDecomprAudio[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Mutex.lock (); /* put mutex lock */
|
Mutex.lock (); /* put mutex lock */
|
||||||
|
@ -342,7 +368,7 @@ for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
|
||||||
const bool bChanWasNotConnected = !IsConnected();
|
const bool bChanWasNotConnected = !IsConnected();
|
||||||
|
|
||||||
// reset time-out counter
|
// reset time-out counter
|
||||||
iConTimeOut = CON_TIME_OUT_CNT_MAX;
|
iConTimeOut = iConTimeOutStartVal;
|
||||||
|
|
||||||
// if channel was not connected, emit signal to inform that new
|
// if channel was not connected, emit signal to inform that new
|
||||||
// connection was established
|
// connection was established
|
||||||
|
@ -404,8 +430,8 @@ CVector<unsigned char> CChannel::PrepSendPacket(const CVector<short>& vecsNPacke
|
||||||
if ( ConvBuf.Put ( vecsNPacket ) )
|
if ( ConvBuf.Put ( vecsNPacket ) )
|
||||||
{
|
{
|
||||||
/* a packet is ready, compress audio */
|
/* a packet is ready, compress audio */
|
||||||
vecbySendBuf.Init ( iAudComprSize );
|
vecbySendBuf.Init ( iAudComprSizeOut );
|
||||||
vecbySendBuf = AudioCompression.Encode ( ConvBuf.Get () );
|
vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get () );
|
||||||
}
|
}
|
||||||
|
|
||||||
return vecbySendBuf;
|
return vecbySendBuf;
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
connected to not-connected (the actual time depends on the way the error
|
connected to not-connected (the actual time depends on the way the error
|
||||||
correction is implemented) */
|
correction is implemented) */
|
||||||
#define CON_TIME_OUT_SEC_MAX 5 // seconds
|
#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) */
|
/* maximum number of internet connections (channels) */
|
||||||
// if you want to change this paramter, change the connections in this class, too!
|
// 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; }
|
bool IsConnected() const { return iConTimeOut > 0; }
|
||||||
|
|
||||||
int GetComprAudSize() { return iAudComprSize; }
|
|
||||||
|
|
||||||
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
||||||
bool GetAddress ( CHostAddress& RetAddr );
|
bool GetAddress ( CHostAddress& RetAddr );
|
||||||
CHostAddress GetAddress () { return InetAddr; }
|
CHostAddress GetAddress () { return InetAddr; }
|
||||||
|
@ -98,9 +95,14 @@ public:
|
||||||
void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); }
|
void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor );
|
||||||
|
void SetNetwOutBlSiFact ( const int iNewBlockSizeFactor );
|
||||||
|
|
||||||
/* audio compression */
|
/* audio compression */
|
||||||
CAudioCompression AudioCompression;
|
CAudioCompression AudioCompressionIn;
|
||||||
int iAudComprSize;
|
int iAudComprSizeIn;
|
||||||
|
CAudioCompression AudioCompressionOut;
|
||||||
|
int iAudComprSizeOut;
|
||||||
|
|
||||||
/* resampling */
|
/* resampling */
|
||||||
CResample ResampleObj;
|
CResample ResampleObj;
|
||||||
|
@ -125,6 +127,9 @@ protected:
|
||||||
int iTimeStampActCnt;
|
int iTimeStampActCnt;
|
||||||
|
|
||||||
int iConTimeOut;
|
int iConTimeOut;
|
||||||
|
int iConTimeOutStartVal;
|
||||||
|
|
||||||
|
int iCurNetwInBlSiFact;
|
||||||
|
|
||||||
QMutex Mutex;
|
QMutex Mutex;
|
||||||
|
|
||||||
|
|
|
@ -66,10 +66,14 @@
|
||||||
|
|
||||||
/* first tests showed that with 24000 kHz a block time shorter than 5 ms leads to
|
/* 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 */
|
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_DURATION_MS 6 /* ms */
|
||||||
|
|
||||||
#define BLOCK_SIZE_SAMPLES ( BLOCK_DURATION_MS * SAMPLE_RATE / 1000 )
|
#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) */
|
/* maximum network buffer size (which can be chosen by slider) */
|
||||||
#define MAX_NET_BUF_SIZE_NUM_BL 12 /* number of blocks */
|
#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 */
|
/* length of the moving average buffer for response time measurement */
|
||||||
#define TIME_MOV_AV_RESPONSE 30 /* seconds */
|
#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
|
#define _MAXSHORT 32767
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
/* maximum block size for network input buffer. Consider two bytes per sample */
|
/* 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 ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
|
|
|
@ -42,11 +42,8 @@
|
||||||
#define MAX_SND_BUF_IN 200
|
#define MAX_SND_BUF_IN 200
|
||||||
#define MAX_SND_BUF_OUT 200
|
#define MAX_SND_BUF_OUT 200
|
||||||
|
|
||||||
#define NUM_SOUND_BUFFERS_IN (70 / BLOCK_DURATION_MS)
|
#define NUM_SOUND_BUFFERS_IN (70 / MIN_BLOCK_DURATION_MS)
|
||||||
#define NUM_SOUND_BUFFERS_OUT (80 / BLOCK_DURATION_MS)
|
#define NUM_SOUND_BUFFERS_OUT (80 / MIN_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 */
|
|
||||||
|
|
||||||
/* Maximum number of recognized sound cards installed in the system */
|
/* Maximum number of recognized sound cards installed in the system */
|
||||||
#define MAX_NUMBER_SOUND_CARDS 10
|
#define MAX_NUMBER_SOUND_CARDS 10
|
||||||
|
|
Loading…
Reference in a new issue