From 24a7740438130d4e7d2bc1ff4afdaacfd2385f88 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 3 Mar 2009 08:35:28 +0000 Subject: [PATCH] bug fix with channel time out, set the default time out to 20 seconds --- src/channel.cpp | 58 +++++++++++++++++++++++++++---------------------- src/channel.h | 2 +- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index d1c89c2b..9b643d49 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -606,6 +606,14 @@ CChannel::CChannel ( const bool bNIsServer ) : bIsServer ( bNIsServer ), vecNetwBufferInProps[iMSIdx].eAudComprType ); } + // initial value for connection time out counter, we calculate the total + // number of samples here and subtract the number of samples of the block + // which we take out of the buffer to be independent of block sizes + iConTimeOutStartVal = CON_TIME_OUT_SEC_MAX * SYSTEM_SAMPLE_RATE; + + // init time-out for the buffer with zero -> no connection + iConTimeOut = 0; + // init the socket buffer SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL ); @@ -619,10 +627,6 @@ CChannel::CChannel ( const bool bNIsServer ) : bIsServer ( bNIsServer ), // set initial audio compression format for output SetAudioCompressionOut ( CT_MSADPCM ); - // init time-out for the buffer with zero -> no connection - iConTimeOut = 0; - - // connections ------------------------------------------------------------- QObject::connect ( &Protocol, SIGNAL ( MessReadyForSending ( CVector ) ), @@ -723,13 +727,6 @@ void CChannel::SetAudioBlockSizeAndComprIn ( const int iNewBlockSize, // init audio compression unit AudioCompressionIn.Init ( iNewBlockSize, eNewAudComprType ); - - // initial value for connection time out counter - -// TODO FIXME this does not work correctly -> bug -// (the calculation is correct but the value is not correctly applied) - iConTimeOutStartVal = - ( CON_TIME_OUT_SEC_MAX * SYSTEM_SAMPLE_RATE ) / iNewBlockSize; } void CChannel::SetNetwBufSizeOut ( const int iNewAudioBlockSizeOut ) @@ -1097,20 +1094,29 @@ EGetDataStat CChannel::GetData ( CVector& vecdData ) { QMutexLocker locker ( &Mutex ); - // init with ok flag - EGetDataStat eGetStatus = GS_BUFFER_OK; + EGetDataStat eGetStatus; - if ( !SockBuf.Get ( vecdData ) ) + const bool bSockBufState = SockBuf.Get ( vecdData ); + + // decrease time-out counter + if ( iConTimeOut > 0 ) { - // decrease time-out counter - if ( iConTimeOut > 0 ) - { - iConTimeOut--; + // subtract the number of samples of the current block since the + // time out counter is based on samples not on blocks + iConTimeOut -= vecdData.Size(); - if ( iConTimeOut == 0 ) + if ( iConTimeOut <= 0 ) + { + // channel is just disconnected + eGetStatus = GS_CHAN_NOW_DISCONNECTED; + iConTimeOut = 0; // make sure we do not have negative values + } + else + { + if ( bSockBufState ) { - // channel is just disconnected - eGetStatus = GS_CHAN_NOW_DISCONNECTED; + // everything is ok + eGetStatus = GS_BUFFER_OK; } else { @@ -1118,11 +1124,11 @@ EGetDataStat CChannel::GetData ( CVector& vecdData ) eGetStatus = GS_BUFFER_UNDERRUN; } } - else - { - // channel is disconnected - eGetStatus = GS_CHAN_NOT_CONNECTED; - } + } + else + { + // channel is disconnected + eGetStatus = GS_CHAN_NOT_CONNECTED; } return eGetStatus; diff --git a/src/channel.h b/src/channel.h index 467b1d46..4d846665 100755 --- a/src/channel.h +++ b/src/channel.h @@ -41,7 +41,7 @@ // Set the time-out for the input buffer until the state changes from // 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_SEC_MAX 20 // seconds // no valid channel number #define INVALID_CHANNEL_ID ( MAX_NUM_CHANNELS + 1 )