From 24ce20479e39f3217ecfe6753a7dd50561435d99 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sun, 1 Mar 2009 20:53:12 +0000 Subject: [PATCH] implemented network transport properties protocol mechanism --- src/channel.cpp | 91 +++++++++++++++++++++++++++++++----------------- src/channel.h | 4 +++ src/client.cpp | 6 ++++ src/client.h | 9 ++++- src/protocol.cpp | 5 ++- 5 files changed, 82 insertions(+), 33 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 85aae405..b1472133 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -569,16 +569,10 @@ CChannel::CChannel ( const bool bNIsServer ) : bIsServer ( bNIsServer ), vecNetwBufferInProps.Init ( iNumSupportedAudComprTypes * MAX_NET_BLOCK_SIZE_FACTOR + 1 ); - // init special mode - -// TEST -> 128 -vecNetwBufferInProps[0].iAudioBlockSize = 128; -vecNetwBufferInProps[0].eAudComprType = CT_NONE; -vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init ( - vecNetwBufferInProps[0].iAudioBlockSize, - vecNetwBufferInProps[0].eAudComprType ); - - + // init special mode (with invalid data) + vecNetwBufferInProps[0].iAudioBlockSize = 0; + vecNetwBufferInProps[0].eAudComprType = CT_NONE; + vecNetwBufferInProps[0].iNetwInBufSize = 0; for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ ) { @@ -669,6 +663,10 @@ vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init ( QObject::connect ( &Protocol, SIGNAL ( NetTranspPropsReceived ( CNetworkTransportProps ) ), this, SLOT ( OnNetTranspPropsReceived ( CNetworkTransportProps ) ) ); + + QObject::connect ( &Protocol, + SIGNAL ( ReqNetTranspProps() ), + this, SLOT ( OnReqNetTranspProps() ) ); } bool CChannel::ProtocolIsEnabled() @@ -727,6 +725,9 @@ void CChannel::SetAudioBlockSizeAndComprIn ( const int iNewBlockSize, 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; } @@ -889,26 +890,6 @@ void CChannel::OnChangeChanName ( QString strName ) SetName ( strName ); } - - - -void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ) -{ - QMutexLocker locker ( &Mutex ); - -// TEST -// TODO use mutex in Put function -// TODO check possiblity of received parameter -> error checking -vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize; -vecNetwBufferInProps[0].eAudComprType = NetworkTransportProps.eAudioCodingType; -vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init ( - vecNetwBufferInProps[0].iAudioBlockSize, - vecNetwBufferInProps[0].eAudComprType ); -} - - - - bool CChannel::GetAddress(CHostAddress& RetAddr) { QMutexLocker locker ( &Mutex ); @@ -925,6 +906,46 @@ bool CChannel::GetAddress(CHostAddress& RetAddr) } } + + + +void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ) +{ + 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; +vecNetwBufferInProps[0].eAudComprType = NetworkTransportProps.eAudioCodingType; +vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init ( + vecNetwBufferInProps[0].iAudioBlockSize, + vecNetwBufferInProps[0].eAudComprType ); +} + +void CChannel::OnReqNetTranspProps() +{ + CreateNetTranspPropsMessFromCurrentSettings(); +} + +void CChannel::CreateNetTranspPropsMessFromCurrentSettings() +{ + CNetworkTransportProps NetworkTransportProps ( + iAudComprSizeOut, + iCurAudioBlockSizeOut, + 1, // right now we only use mono + SYSTEM_SAMPLE_RATE, // right now only one sample rate is supported + AudioCompressionOut.GetType(), + 0 ); + + // send current network transport properties + Protocol.CreateNetwTranspPropsMes ( NetworkTransportProps ); +} + + + + EPutDataStat CChannel::PutData ( const CVector& vecbyData, int iNumBytes ) { @@ -1038,9 +1059,17 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, Mutex.unlock(); } - // inform other objects that new connection was established if ( bNewConnection ) { + // if this is a new connection and the current network packet is + // neither an audio or protocol packet, we have to query the + // network transport properties for the audio packets + if ( ( !bIsProtocolPacket ) && ( !bIsAudioPacket ) ) + { + Protocol.CreateReqNetwTranspPropsMes(); + } + + // inform other objects that new connection was established emit NewConnection(); } } diff --git a/src/channel.h b/src/channel.h index 44b4d347..467b1d46 100755 --- a/src/channel.h +++ b/src/channel.h @@ -145,6 +145,8 @@ void SetNetwBufSizeOut ( const int iNewAudioBlockSizeOut ); Protocol.CreateConClientListMes ( vecChanInfo ); } + void CreateNetTranspPropsMessFromCurrentSettings(); + protected: void SetAudioBlockSizeAndComprIn ( const int iNewBlockSize, const EAudComprType eNewAudComprType ); @@ -205,6 +207,7 @@ public slots: void OnChangeChanGain ( int iChanID, double dNewGain ); void OnChangeChanName ( QString strName ); void OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ); + void OnReqNetTranspProps(); signals: void MessReadyForSending ( CVector vecMessage ); @@ -215,6 +218,7 @@ signals: void NameHasChanged(); void ChatTextReceived ( QString strChatText ); void PingReceived ( int iMs ); + void ReqNetTranspProps(); }; diff --git a/src/client.cpp b/src/client.cpp index 32f5f8eb..47477955 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -58,6 +58,9 @@ CClient::CClient ( const quint16 iPortNumber ) : QObject::connect ( &Channel, SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnReceivePingMessage ( int ) ) ); + + QObject::connect ( &Channel, SIGNAL ( ReqNetTranspProps() ), + this, SLOT ( OnReqNetTranspProps() ) ); } void CClient::OnSendProtMessage ( CVector vecMessage ) @@ -77,6 +80,9 @@ for ( int i = 0; i < vecMessage.Size(); i++ ) { void CClient::OnReqJittBufSize() { + +// TODO cant we implement this OnReqJjittBufSize inside the channel object? + Channel.CreateJitBufMes ( Channel.GetSockBufSize() ); // FIXME: we set the network buffer size factor here, too -> in the diff --git a/src/client.h b/src/client.h index 41dca427..88d36bd8 100755 --- a/src/client.h +++ b/src/client.h @@ -127,7 +127,14 @@ public: int GetNetwBufSizeFactOut() { return Channel.GetNetwBufSizeFactOut(); } void SetAudioCompressionOut ( const EAudComprType eNewAudComprTypeOut ) - { Channel.SetAudioCompressionOut ( eNewAudComprTypeOut ); } + { + Channel.SetAudioCompressionOut ( eNewAudComprTypeOut ); + + // tell the server that audio coding has changed (it + // is important to call this function AFTER we have applied + // the new setting to the channel!) + Channel.CreateNetTranspPropsMessFromCurrentSettings(); + } EAudComprType GetAudioCompressionOut() { return Channel.GetAudioCompressionOut(); } void SetRemoteChanGain ( const int iId, const double dGain ) diff --git a/src/protocol.cpp b/src/protocol.cpp index 26adf92e..9a33f0c3 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -880,7 +880,7 @@ bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector& vecData ) // audio coding type (2 bytes) with error check const int iRecCodingType = - static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); if ( ( iRecCodingType != CT_NONE ) && ( iRecCodingType != CT_IMAADPCM ) && @@ -889,6 +889,9 @@ bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector& vecData ) return true; } + ReceivedNetwTranspProps.eAudioCodingType = + static_cast ( iRecCodingType ); + // argument for the audio coder (4 bytes) ReceivedNetwTranspProps.iAudioCodingArg = static_cast ( GetValFromStream ( vecData, iPos, 4 ) );