implemented network transport properties protocol mechanism

This commit is contained in:
Volker Fischer 2009-03-01 20:53:12 +00:00
parent 91071384d2
commit 24ce20479e
5 changed files with 82 additions and 33 deletions

View file

@ -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<unsigned char>& vecbyData,
int iNumBytes )
{
@ -1038,9 +1059,17 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& 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();
}
}

View file

@ -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<uint8_t> vecMessage );
@ -215,6 +218,7 @@ signals:
void NameHasChanged();
void ChatTextReceived ( QString strChatText );
void PingReceived ( int iMs );
void ReqNetTranspProps();
};

View file

@ -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<uint8_t> 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

View file

@ -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 )

View file

@ -880,7 +880,7 @@ bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData )
// audio coding type (2 bytes) with error check
const int iRecCodingType =
static_cast<unsigned short> ( GetValFromStream ( vecData, iPos, 2 ) );
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
if ( ( iRecCodingType != CT_NONE ) &&
( iRecCodingType != CT_IMAADPCM ) &&
@ -889,6 +889,9 @@ bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData )
return true;
}
ReceivedNetwTranspProps.eAudioCodingType =
static_cast<EAudComprType> ( iRecCodingType );
// argument for the audio coder (4 bytes)
ReceivedNetwTranspProps.iAudioCodingArg =
static_cast<unsigned int> ( GetValFromStream ( vecData, iPos, 4 ) );