From 24680bbab4c644774e02e67519f442652702694e Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sun, 12 Mar 2006 10:43:48 +0000 Subject: [PATCH] jitter buffer settings only allow settings for buffers larger than the network buffer block size --- src/channel.cpp | 58 +++++++++++++++++++++++++----------------- src/channel.h | 2 +- src/global.h | 3 +-- src/llconclientdlg.cpp | 2 +- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 0539fe16..7799c46c 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -293,12 +293,25 @@ void CChannel::SetSockBufSize ( const int iNumBlocks ) { /* this opperation must be done with mutex */ Mutex.lock (); - { - SockBuf.Init ( MIN_BLOCK_SIZE_SAMPLES, iNumBlocks ); + { + // the idea of setting the jitter buffer is as follows: + // The network block size is a multiple of the internal minimal + // block size. Therefore, the minimum jitter buffer size must be + // so that it can take one network buffer -> NET_BLOCK_SIZE_FACTOR. + // The actual jitter compensation are then the additional blocks of + // the internal block size, which is set with SetSockBufSize + SockBuf.Init ( MIN_BLOCK_SIZE_SAMPLES, + iNumBlocks + NET_BLOCK_SIZE_FACTOR ); } Mutex.unlock (); } +int CChannel::GetSockBufSize() +{ + // see comment in SetSockBufSize function + return SockBuf.GetSize() - NET_BLOCK_SIZE_FACTOR; +} + void CChannel::OnJittBufSizeChange ( int iNewJitBufSize ) { // TEST @@ -324,16 +337,19 @@ bool CChannel::GetAddress(CHostAddress& RetAddr) EPutDataStat CChannel::PutData ( const CVector& vecbyData, int iNumBytes ) { - EPutDataStat eRet = PS_GEN_ERROR; + EPutDataStat eRet = PS_GEN_ERROR; + bool bNewConnection = false; /* only process if packet has correct size */ if ( iNumBytes == iAudComprSizeIn ) { - /* decompress audio */ - CVector vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) ); + Mutex.lock (); + { + /* decompress audio */ + CVector vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) ); - /* do resampling to compensate for sample rate offsets in the - different sound cards of the clients */ + /* do resampling to compensate for sample rate offsets in the + different sound cards of the clients */ /* for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++) vecdResInData[i] = (double) vecsData[i]; @@ -347,9 +363,6 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) { vecdResOutData[i] = (double) vecsDecomprAudio[i]; } - - Mutex.lock (); /* put mutex lock */ - { if ( SockBuf.Put ( vecdResOutData ) ) { eRet = PS_AUDIO_OK; @@ -358,21 +371,14 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) { { eRet = PS_AUDIO_ERR; } - } - Mutex.unlock (); /* put mutex unlock */ - // check if channel was not connected - const bool bChanWasNotConnected = !IsConnected(); + // check if channel was not connected, this is a new connection + bNewConnection = !IsConnected(); - // reset time-out counter - iConTimeOut = iConTimeOutStartVal; - - // if channel was not connected, emit signal to inform that new - // connection was established - if ( bChanWasNotConnected ) - { - emit NewConnection(); + // reset time-out counter + iConTimeOut = iConTimeOutStartVal; } + Mutex.unlock (); } else { @@ -389,7 +395,13 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) { eRet = PS_PROT_ERR; } } - } + } + + // inform other objects that new connection was established + if ( bNewConnection ) + { + emit NewConnection(); + } return eRet; } diff --git a/src/channel.h b/src/channel.h index d0758669..5e2aee75 100755 --- a/src/channel.h +++ b/src/channel.h @@ -81,7 +81,7 @@ public: CHostAddress GetAddress () { return InetAddr; } void SetSockBufSize ( const int iNumBlocks ); - int GetSockBufSize() { return SockBuf.GetSize(); } + int GetSockBufSize(); // network protocol interface void CreateJitBufMes ( const int iJitBufSize ) diff --git a/src/global.h b/src/global.h index cf9e20d4..32728532 100755 --- a/src/global.h +++ b/src/global.h @@ -72,8 +72,7 @@ #define NET_BLOCK_SIZE_FACTOR_MAX 10 /* maximum network buffer size (which can be chosen by slider) */ -#define MAX_NET_BUF_SIZE_NUM_BL 12 /* number of blocks */ -#define MIN_NET_BUF_SIZE_NUM_BL NET_BLOCK_SIZE_FACTOR +#define MAX_NET_BUF_SIZE_NUM_BL 10 /* number of blocks */ /* default network buffer size */ #define DEF_NET_BUF_SIZE_NUM_BL 5 /* number of blocks */ diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 6907421b..5af64a81 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -94,7 +94,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, TextSndBufOut->setText("Out: " + QString().setNum(iCurNumOutBuf)); /* network buffer */ - SliderNetBuf->setRange(MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL); + SliderNetBuf->setRange(0, MAX_NET_BUF_SIZE_NUM_BL); const int iCurNumNetBuf = pClient->GetSockBufSize(); SliderNetBuf->setValue(iCurNumNetBuf); TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf));