From c86cbcabdb58c6175d12de60d3964e09bf068c9f Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 13 Mar 2006 19:32:23 +0000 Subject: [PATCH] new management of network block size factors --- src/audiocompr.h | 2 +- src/channel.cpp | 76 +++++++++++++++++++++++++++++------------------- src/channel.h | 2 ++ src/client.cpp | 4 --- src/global.h | 2 +- 5 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/audiocompr.h b/src/audiocompr.h index 81ce88ce..2bfdbe98 100755 --- a/src/audiocompr.h +++ b/src/audiocompr.h @@ -90,7 +90,7 @@ protected: class CAudioCompression { public: - enum EAudComprType {CT_NONE, CT_IMAADPCM}; + enum EAudComprType { CT_NONE, CT_IMAADPCM }; CAudioCompression() {} virtual ~CAudioCompression() {} diff --git a/src/channel.cpp b/src/channel.cpp index 8af6ea30..59378eca 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -221,19 +221,29 @@ void CChannelSet::GetConCliParam ( CVector& vecHostAddresses, * CChannel * \******************************************************************************/ CChannel::CChannel() -{ - /* init time stamp index counter */ +{ + // query all possible network in buffer sizes for determining if an + // audio packet was received + for ( int i = 0; i < ( NET_BLOCK_SIZE_FACTOR_MAX - 1 ); i++ ) + { + // network block size factor must start from 1 -> ( i + 1 ) + vecNetwInBufSizes[i] = AudioCompressionIn.Init ( + ( i + 1 ) * MIN_BLOCK_SIZE_SAMPLES, + CAudioCompression::CT_IMAADPCM ); + } + + /* init time stamp index counter */ byTimeStampIdxCnt = 0; - iCurNetwInBlSiFact = NET_BLOCK_SIZE_FACTOR; - - /* init the socket buffer */ + iCurNetwInBlSiFact = NET_BLOCK_SIZE_FACTOR; + + /* init the socket buffer */ SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL ); // set initial input and output block size factors SetNetwBufSizeFact ( 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; @@ -283,21 +293,17 @@ void CChannel::SetNetwOutBlSiFact ( const int iNewBlockSizeFactor ) void CChannel::OnSendProtMessage ( CVector vecMessage ) { - -// must be disabled to be able to receive network buffer size factor changes -// FIXME check, if this condition must be checked somewhere else! - -// // only send messages if we are connected, otherwise delete complete queue -// if ( IsConnected() ) -// { + // only send messages if we are connected, otherwise delete complete queue + if ( IsConnected() ) + { // emit message to actually send the data emit MessReadyForSending ( vecMessage ); -// } -// else -// { -// // delete send message queue -// Protocol.DeleteSendMessQueue(); -// } + } + else + { + // delete send message queue + Protocol.DeleteSendMessQueue(); + } } @@ -366,10 +372,27 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, int iNumBytes ) { EPutDataStat eRet = PS_GEN_ERROR; - bool bNewConnection = false; + bool bNewConnection = false; + bool bIsAudioPacket = false; + + // check if this is an audio packet by checking all possible lengths + for ( int i = 0; i < ( NET_BLOCK_SIZE_FACTOR_MAX - 1 ); i++ ) + { + if ( iNumBytes == vecNetwInBufSizes[i] ) + { + bIsAudioPacket = true; + + // check if we are correctly initialized + if ( iAudComprSizeIn != vecNetwInBufSizes[i] ) + { + // re-initialize to new value + SetNetwBufSizeFact ( i + 1 ); + } + } + } /* only process if packet has correct size */ - if ( iNumBytes == iAudComprSizeIn ) + if ( bIsAudioPacket ) { Mutex.lock(); { @@ -456,7 +479,7 @@ bool CChannel::GetData ( CVector& vecdData ) /* decrease time-out counter */ if ( iConTimeOut > 0 ) { - iConTimeOut--; + iConTimeOut--; } } } @@ -479,13 +502,6 @@ CVector CChannel::PrepSendPacket ( const CVector& vecsNPac vecbySendBuf.Init ( iAudComprSizeOut ); vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get() ); } - - // if we are not connected, send network buffer size factor so that the - // server is able to process our audio packets - if ( !IsConnected() ) - { - Protocol.CreateNetwBlSiFactMes ( iCurNetwBlSiFact ); - } return vecbySendBuf; } diff --git a/src/channel.h b/src/channel.h index 5cbcc5d1..c54e7e49 100755 --- a/src/channel.h +++ b/src/channel.h @@ -141,6 +141,8 @@ protected: int iConTimeOut; int iConTimeOutStartVal; + int vecNetwInBufSizes[NET_BLOCK_SIZE_FACTOR_MAX]; + int iCurNetwInBlSiFact; int iCurNetwBlSiFact; // TODO, will be replaced by in/out settings diff --git a/src/client.cpp b/src/client.cpp index a91018ae..c3a8e74b 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -57,10 +57,6 @@ for ( int i = 0; i < vecMessage.Size (); i++ ) { void CClient::OnReqJittBufSize() { Channel.CreateJitBufMes ( Channel.GetSockBufSize() ); - -// FIXME: we set the network buffer size factor here, too -> in the -// future a separate request function for this parameter should be created - Channel.CreateNetwBlSiFactMes ( Channel.GetNetwBufSizeFact() ); } bool CClient::SetServerAddr(QString strNAddr) diff --git a/src/global.h b/src/global.h index 32728532..20fd7a72 100755 --- a/src/global.h +++ b/src/global.h @@ -69,7 +69,7 @@ #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 NET_BLOCK_SIZE_FACTOR_MAX 15 /* maximum network buffer size (which can be chosen by slider) */ #define MAX_NET_BUF_SIZE_NUM_BL 10 /* number of blocks */