diff --git a/linux/sound.h b/linux/sound.h index 07a73879..3c40d891 100755 --- a/linux/sound.h +++ b/linux/sound.h @@ -36,7 +36,7 @@ // the number of periods is critical for latency #define NUM_PERIOD_BLOCKS_IN 2 -#define NUM_PERIOD_BLOCKS_OUT 2 +#define NUM_PERIOD_BLOCKS_OUT 1 #define MAX_SND_BUF_IN 200 #define MAX_SND_BUF_OUT 200 diff --git a/src/channel.cpp b/src/channel.cpp index b1472133..6f903d49 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -914,7 +914,6 @@ void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTranspor QMutexLocker locker ( &Mutex ); // TEST -// TODO use mutex in Put function // TODO check possiblity of received parameter -> error checking // utilize, e.g., MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize; @@ -954,7 +953,13 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, // init flags bool bIsProtocolPacket = false; bool bIsAudioPacket = false; - bool bNewConnection = false; + bool bNewConnection = false; + bool bReinitializeIn = false; + bool bReinitializeOut = false; + + // intermediate storage for new parameters + int iNewAudioBlockSize; + EAudComprType eNewAudComprType; if ( bIsEnabled ) { @@ -973,41 +978,60 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, // only try to parse audio if it was not a protocol packet if ( !bIsProtocolPacket ) - { - // check if this is an audio packet by checking all possible lengths - const int iPossNetwSizes = vecNetwBufferInProps.Size(); - - for ( int i = 0; i < iPossNetwSizes; i++ ) + { + Mutex.lock(); { - // check for low/high quality audio packets and set flags - if ( iNumBytes == vecNetwBufferInProps[i].iNetwInBufSize ) + // check if this is an audio packet by checking all possible lengths + const int iPossNetwSizes = vecNetwBufferInProps.Size(); + + for ( int i = 0; i < iPossNetwSizes; i++ ) { - bIsAudioPacket = true; - - // check if we are correctly initialized - const int iNewAudioBlockSize = - vecNetwBufferInProps[i].iAudioBlockSize; - - const EAudComprType eNewAudComprType = - vecNetwBufferInProps[i].eAudComprType; - - if ( ( iNewAudioBlockSize != iCurAudioBlockSizeIn ) || - ( eNewAudComprType != AudioCompressionIn.GetType() ) ) + // check for low/high quality audio packets and set flags + if ( iNumBytes == vecNetwBufferInProps[i].iNetwInBufSize ) { - // re-initialize to new value - SetAudioBlockSizeAndComprIn ( - iNewAudioBlockSize, eNewAudComprType ); - } + bIsAudioPacket = true; - // in case of a server channel, use the same audio - // compression for output as for the input - if ( bIsServer ) - { - if ( GetAudioCompressionOut() != vecNetwBufferInProps[i].eAudComprType ) - { - SetAudioCompressionOut ( vecNetwBufferInProps[i].eAudComprType ); + // check if we are correctly initialized + iNewAudioBlockSize = + vecNetwBufferInProps[i].iAudioBlockSize; + + eNewAudComprType = + vecNetwBufferInProps[i].eAudComprType; + + if ( ( iNewAudioBlockSize != iCurAudioBlockSizeIn ) || + ( eNewAudComprType != AudioCompressionIn.GetType() ) ) + { + bReinitializeIn = true; } - } + + // in case of a server channel, use the same audio + // compression for output as for the input + if ( bIsServer ) + { + if ( GetAudioCompressionOut() != eNewAudComprType ) + { + bReinitializeOut = true; + } + } + } + } + Mutex.unlock(); + + // actual initialization calls have to be made + // outside the mutex region since they internally + // use the same mutex, too + if ( bReinitializeIn ) + { + // re-initialize to new value + SetAudioBlockSizeAndComprIn ( + iNewAudioBlockSize, eNewAudComprType ); + + } + + if ( bReinitializeOut ) + { + SetAudioCompressionOut ( eNewAudComprType ); + } } diff --git a/src/client.cpp b/src/client.cpp index 3b864b16..d6b44eec 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -161,7 +161,7 @@ void CClient::Start() // init object // TEST -Init ( 192 ); +Init ( 256 ); // enable channel Channel.SetEnable ( true );