some code cleanup, introduces one more check in protocol

This commit is contained in:
Volker Fischer 2009-03-02 20:11:24 +00:00
parent c064b49576
commit 2efdb7775d
3 changed files with 37 additions and 40 deletions

View file

@ -906,21 +906,16 @@ bool CChannel::GetAddress(CHostAddress& RetAddr)
} }
} }
void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ) void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps )
{ {
QMutexLocker locker ( &Mutex ); QMutexLocker locker ( &Mutex );
// TEST // apply received parameters to internal data struct
// TODO check possiblity of received parameter -> error checking vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize;
// utilize, e.g., MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ vecNetwBufferInProps[0].eAudComprType = NetworkTransportProps.eAudioCodingType;
vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize; vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init (
vecNetwBufferInProps[0].eAudComprType = NetworkTransportProps.eAudioCodingType; vecNetwBufferInProps[0].iAudioBlockSize,
vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init ( vecNetwBufferInProps[0].eAudComprType );
vecNetwBufferInProps[0].iAudioBlockSize,
vecNetwBufferInProps[0].eAudComprType );
} }
void CChannel::OnReqNetTranspProps() void CChannel::OnReqNetTranspProps()
@ -942,9 +937,6 @@ void CChannel::CreateNetTranspPropsMessFromCurrentSettings()
Protocol.CreateNetwTranspPropsMes ( NetworkTransportProps ); Protocol.CreateNetwTranspPropsMes ( NetworkTransportProps );
} }
EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData, EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
int iNumBytes ) int iNumBytes )
{ {
@ -953,13 +945,13 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
// init flags // init flags
bool bIsProtocolPacket = false; bool bIsProtocolPacket = false;
bool bIsAudioPacket = false; bool bIsAudioPacket = false;
bool bNewConnection = false; bool bNewConnection = false;
bool bReinitializeIn = false; bool bReinitializeIn = false;
bool bReinitializeOut = false; bool bReinitializeOut = false;
// intermediate storage for new parameters // intermediate storage for new parameters
int iNewAudioBlockSize; int iNewAudioBlockSize;
EAudComprType eNewAudComprType; EAudComprType eNewAudComprType;
if ( bIsEnabled ) if ( bIsEnabled )
{ {
@ -978,8 +970,8 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
// only try to parse audio if it was not a protocol packet // only try to parse audio if it was not a protocol packet
if ( !bIsProtocolPacket ) if ( !bIsProtocolPacket )
{ {
Mutex.lock(); Mutex.lock();
{ {
// check if this is an audio packet by checking all possible lengths // check if this is an audio packet by checking all possible lengths
const int iPossNetwSizes = vecNetwBufferInProps.Size(); const int iPossNetwSizes = vecNetwBufferInProps.Size();
@ -1000,7 +992,7 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
if ( ( iNewAudioBlockSize != iCurAudioBlockSizeIn ) || if ( ( iNewAudioBlockSize != iCurAudioBlockSizeIn ) ||
( eNewAudComprType != AudioCompressionIn.GetType() ) ) ( eNewAudComprType != AudioCompressionIn.GetType() ) )
{ {
bReinitializeIn = true; bReinitializeIn = true;
} }
@ -1009,29 +1001,29 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
if ( bIsServer ) if ( bIsServer )
{ {
if ( GetAudioCompressionOut() != eNewAudComprType ) if ( GetAudioCompressionOut() != eNewAudComprType )
{ {
bReinitializeOut = true; bReinitializeOut = true;
} }
} }
} }
} }
Mutex.unlock(); Mutex.unlock();
// actual initialization calls have to be made // actual initialization calls have to be made
// outside the mutex region since they internally // outside the mutex region since they internally
// use the same mutex, too // use the same mutex, too
if ( bReinitializeIn ) if ( bReinitializeIn )
{ {
// re-initialize to new value // re-initialize to new value
SetAudioBlockSizeAndComprIn ( SetAudioBlockSizeAndComprIn (
iNewAudioBlockSize, eNewAudComprType ); iNewAudioBlockSize, eNewAudComprType );
} }
if ( bReinitializeOut ) if ( bReinitializeOut )
{ {
SetAudioCompressionOut ( eNewAudComprType ); SetAudioCompressionOut ( eNewAudComprType );
} }
} }

View file

@ -161,7 +161,7 @@ void CClient::Start()
// init object // init object
// TEST // TEST
Init ( 256 ); Init ( 192 );
// enable channel // enable channel
Channel.SetEnable ( true ); Channel.SetEnable ( true );

View file

@ -870,6 +870,11 @@ bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData )
ReceivedNetwTranspProps.iMonoAudioBlockSize = ReceivedNetwTranspProps.iMonoAudioBlockSize =
static_cast<unsigned int> ( GetValFromStream ( vecData, iPos, 4 ) ); static_cast<unsigned int> ( 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) // number of channels of the audio signal, e.g. "2" is stereo (1 byte)
ReceivedNetwTranspProps.iNumAudioChannels = ReceivedNetwTranspProps.iNumAudioChannels =
static_cast<unsigned int> ( GetValFromStream ( vecData, iPos, 1 ) ); static_cast<unsigned int> ( GetValFromStream ( vecData, iPos, 1 ) );