From 2efdb7775dd6f213321cf1686fa8f05f7108f93a Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 2 Mar 2009 20:11:24 +0000 Subject: [PATCH] some code cleanup, introduces one more check in protocol --- src/channel.cpp | 70 +++++++++++++++++++++--------------------------- src/client.cpp | 2 +- src/protocol.cpp | 5 ++++ 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 6f903d49..d1c89c2b 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -906,21 +906,16 @@ bool CChannel::GetAddress(CHostAddress& RetAddr) } } - - - void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ) { QMutexLocker locker ( &Mutex ); -// TEST -// TODO check possiblity of received parameter -> error checking -// utilize, e.g., MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ -vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize; -vecNetwBufferInProps[0].eAudComprType = NetworkTransportProps.eAudioCodingType; -vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init ( - vecNetwBufferInProps[0].iAudioBlockSize, - vecNetwBufferInProps[0].eAudComprType ); + // apply received parameters to internal data struct + vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize; + vecNetwBufferInProps[0].eAudComprType = NetworkTransportProps.eAudioCodingType; + vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init ( + vecNetwBufferInProps[0].iAudioBlockSize, + vecNetwBufferInProps[0].eAudComprType ); } void CChannel::OnReqNetTranspProps() @@ -942,9 +937,6 @@ void CChannel::CreateNetTranspPropsMessFromCurrentSettings() Protocol.CreateNetwTranspPropsMes ( NetworkTransportProps ); } - - - EPutDataStat CChannel::PutData ( const CVector& vecbyData, int iNumBytes ) { @@ -953,13 +945,13 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, // init flags bool bIsProtocolPacket = false; bool bIsAudioPacket = false; - bool bNewConnection = false; - bool bReinitializeIn = false; + bool bNewConnection = false; + bool bReinitializeIn = false; bool bReinitializeOut = false; - - // intermediate storage for new parameters - int iNewAudioBlockSize; - EAudComprType eNewAudComprType; + + // intermediate storage for new parameters + int iNewAudioBlockSize; + EAudComprType eNewAudComprType; if ( bIsEnabled ) { @@ -978,8 +970,8 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, // only try to parse audio if it was not a protocol packet if ( !bIsProtocolPacket ) - { - Mutex.lock(); + { + Mutex.lock(); { // check if this is an audio packet by checking all possible lengths const int iPossNetwSizes = vecNetwBufferInProps.Size(); @@ -1000,7 +992,7 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, if ( ( iNewAudioBlockSize != iCurAudioBlockSizeIn ) || ( eNewAudComprType != AudioCompressionIn.GetType() ) ) - { + { bReinitializeIn = true; } @@ -1009,29 +1001,29 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, 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 ) - { + } + } + 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 ) - { + + } + + if ( bReinitializeOut ) + { SetAudioCompressionOut ( eNewAudComprType ); - + } } diff --git a/src/client.cpp b/src/client.cpp index d6b44eec..3b864b16 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -161,7 +161,7 @@ void CClient::Start() // init object // TEST -Init ( 256 ); +Init ( 192 ); // enable channel Channel.SetEnable ( true ); diff --git a/src/protocol.cpp b/src/protocol.cpp index 9a33f0c3..462eae32 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -870,6 +870,11 @@ bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector& vecData ) ReceivedNetwTranspProps.iMonoAudioBlockSize = static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + if ( ReceivedNetwTranspProps.iMonoAudioBlockSize > MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ ) + { + return true; // maximum audio size exceeded, return error + } + // number of channels of the audio signal, e.g. "2" is stereo (1 byte) ReceivedNetwTranspProps.iNumAudioChannels = static_cast ( GetValFromStream ( vecData, iPos, 1 ) );