From 2cd15abb8a89aa50d6d30836d01eeaf381bd045f Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 24 Feb 2009 18:20:33 +0000 Subject: [PATCH] added new protocol messages for network transport properties; removed unnecessary protocol events --- src/channel.cpp | 6 --- src/channel.h | 1 - src/client.cpp | 16 ------ src/client.h | 1 - src/global.h | 7 +-- src/protocol.cpp | 136 ++++++++++++++++++++++++++++++++++++++++++++++- src/protocol.h | 69 +++++++++++++----------- src/socket.cpp | 2 +- src/util.h | 29 ++++++++++ 9 files changed, 207 insertions(+), 60 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index eee236ee..cdff9126 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -858,9 +858,6 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, // set status flags eRet = PS_PROT_OK; bIsProtocolPacket = true; - - // create message for protocol status - emit ProtocolStatus ( true ); } } @@ -941,9 +938,6 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, // the protocol parsing failed and this was no audio block, // we treat this as protocol error (unkown packet) eRet = PS_PROT_ERR; - - // create message for protocol status - emit ProtocolStatus ( false ); } } diff --git a/src/channel.h b/src/channel.h index c1fd97a0..b8c727e8 100755 --- a/src/channel.h +++ b/src/channel.h @@ -208,7 +208,6 @@ signals: void ReqJittBufSize(); void ReqConnClientsList(); void ConClientListMesReceived ( CVector vecChanInfo ); - void ProtocolStatus ( bool bOk ); void NameHasChanged(); void ChatTextReceived ( QString strChatText ); void PingReceived ( int iMs ); diff --git a/src/client.cpp b/src/client.cpp index 40e742e3..2c243ce4 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -47,9 +47,6 @@ CClient::CClient ( const quint16 iPortNumber ) : QObject::connect ( &Channel, SIGNAL ( ReqJittBufSize() ), this, SLOT ( OnReqJittBufSize() ) ); - QObject::connect ( &Channel, SIGNAL ( ProtocolStatus ( bool ) ), - this, SLOT ( OnProtocolStatus ( bool ) ) ); - QObject::connect ( &Channel, SIGNAL ( ConClientListMesReceived ( CVector ) ), SIGNAL ( ConClientListMesReceived ( CVector ) ) ); @@ -157,19 +154,6 @@ bool CClient::SetServerAddr ( QString strNAddr ) return true; } -void CClient::OnProtocolStatus ( bool bOk ) -{ - // show protocol status in GUI - if ( bOk ) - { - PostWinMessage ( MS_PROTOCOL, MUL_COL_LED_RED ); - } - else - { - PostWinMessage ( MS_PROTOCOL, MUL_COL_LED_GREEN ); - } -} - void CClient::Start() { // init object diff --git a/src/client.h b/src/client.h index d5e25986..0c52be7b 100755 --- a/src/client.h +++ b/src/client.h @@ -201,7 +201,6 @@ protected: public slots: void OnSendProtMessage ( CVector vecMessage ); void OnReqJittBufSize(); - void OnProtocolStatus ( bool bOk ); void OnNewConnection(); void OnReceivePingMessage ( int iMs ); diff --git a/src/global.h b/src/global.h index 3574f8ce..30222e67 100755 --- a/src/global.h +++ b/src/global.h @@ -93,6 +93,8 @@ // if you want to change this paramter, there has to be done code modifications // on other places, too! The code tag "MAX_NUM_CHANNELS_TAG" shows these places // (just search for the tag in the entire code) +// note: since in the protocol messages the channel ID is only a byte, a +// maximum of 8 channels are possible, see e.g. "PROTMESSID_CHANNEL_GAIN"! #define MAX_NUM_CHANNELS 6 // max number channels for server // length of the moving average buffer for response time measurement @@ -130,9 +132,8 @@ typedef unsigned int _MESSAGE_IDENT; #define MS_JIT_BUF_PUT 3 #define MS_JIT_BUF_GET 4 #define MS_PACKET_RECEIVED 5 -#define MS_PROTOCOL 6 -#define MS_ERROR_IN_THREAD 7 -#define MS_SET_JIT_BUF_SIZE 8 +#define MS_ERROR_IN_THREAD 6 +#define MS_SET_JIT_BUF_SIZE 7 #define MUL_COL_LED_RED 0 #define MUL_COL_LED_YELLOW 1 diff --git a/src/protocol.cpp b/src/protocol.cpp index d88072ae..ece0edcd 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -104,6 +104,27 @@ MESSAGES | 4 bytes transmit time in ms | +-----------------------------+ +- Properties for network transport: PROTMESSID_NETW_TRANSPORT_PROPS + + +-------------------+------------------+-----------------+------------------+-----------------------+----------------------+ + | 4 bytes netw size | 4 bytes aud size | 1 byte num chan | 4 bytes sam rate | 2 bytes audiocod type | 4 bytes audiocod arg | + +-------------------+------------------+-----------------+------------------+-----------------------+----------------------+ + + - "netw size": length of the network packet in bytes + - "aud size": length of the mono audio block size in samples + - "num chan": number of channels of the audio signal, e.g. "2" is stereo + - "sam rate": sample rate of the audio stream + - "audiocod type": audio coding type, the following types are supported: + - 0: none, no audio coding applied + - 1: IMA-ADPCM + - 2: MS-ADPCM + - "audiocod arg": argument for the audio coder, if not used this value shall be set to 0 + +- Request properties for network transport: PROTMESSID_REQ_NETW_TRANSPORT_PROPS + + note: does not have any data -> n = 0 + + ****************************************************************************** * * This program is free software; you can redistribute it and/or modify it under @@ -369,6 +390,16 @@ for ( int i = 0; i < iNumBytes; i++ ) { bRet = EvaluatePingMes ( vecData ); break; + + case PROTMESSID_NETW_TRANSPORT_PROPS: + + bRet = EvaluateNetwTranspPropsMes ( vecData ); + break; + + case PROTMESSID_REQ_NETW_TRANSPORT_PROPS: + + bRet = EvaluateReqNetwTranspPropsMes ( vecData ); + break; } // send acknowledge message @@ -691,7 +722,7 @@ void CProtocol::CreateChatTextMes ( const QString strChatText ) unsigned int iPos = 0; // init position pointer const int iStrLen = strChatText.size(); // get string size - // size of current list entry + // size of message body const int iEntrLen = 2 /* string size */ + iStrLen; // build data vector @@ -774,6 +805,109 @@ bool CProtocol::EvaluatePingMes ( const CVector& vecData ) return false; // no error } +void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps ) +{ + unsigned int iPos = 0; // init position pointer + + // size of current message body + const int iEntrLen = 4 /* netw size */ + 4 /* aud size */ + 1 /* num chan */ + + 4 /* sam rate */ + 2 /* audiocod type */ + 4 /* audiocod arg */; + + // build data vector + CVector vecData ( iEntrLen ); + + // length of the network packet in bytes (4 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( NetTrProps.iNetworkPacketSize ), 4 ); + + // length of the mono audio block size in samples (4 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( NetTrProps.iMonoAudioBlockSize ), 4 ); + + // number of channels of the audio signal, e.g. "2" is stereo (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( NetTrProps.iNumAudioChannels ), 1 ); + + // sample rate of the audio stream (4 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( NetTrProps.iSampleRate ), 4 ); + + // audio coding type (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( NetTrProps.eAudioCodingType ), 2 ); + + // argument for the audio coder (4 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( NetTrProps.iAudioCodingArg ), 4 ); + + CreateAndSendMessage ( PROTMESSID_NETW_TRANSPORT_PROPS, vecData ); +} + +bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector& vecData ) +{ + unsigned int iPos = 0; // init position pointer + CNetworkTransportProps ReceivedNetwTranspProps; + + // size of current message body + const int iEntrLen = 4 /* netw size */ + 4 /* aud size */ + 1 /* num chan */ + + 4 /* sam rate */ + 2 /* audiocod type */ + 4 /* audiocod arg */; + + // check size + if ( vecData.Size() != iEntrLen ) + { + return true; + } + + // length of the network packet in bytes (4 bytes) + ReceivedNetwTranspProps.iNetworkPacketSize = + static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + + // length of the mono audio block size in samples (4 bytes) + ReceivedNetwTranspProps.iMonoAudioBlockSize = + static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + + // number of channels of the audio signal, e.g. "2" is stereo (1 byte) + ReceivedNetwTranspProps.iNumAudioChannels = + static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + + // sample rate of the audio stream (4 bytes) + ReceivedNetwTranspProps.iSampleRate = + static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + + // audio coding type (2 bytes) with error check + const int iRecCodingType = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + if ( ( iRecCodingType != CNetworkTransportProps::ACT_NONE ) && + ( iRecCodingType != CNetworkTransportProps::ACT_IMA_ADPCM ) && + ( iRecCodingType != CNetworkTransportProps::ACT_MS_ADPCM ) ) + { + return true; + } + + // argument for the audio coder (4 bytes) + ReceivedNetwTranspProps.iAudioCodingArg = + static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + + // invoke message action + emit NetTranspPropsReceived ( ReceivedNetwTranspProps ); + + return false; // no error +} + +void CProtocol::CreateReqNetwTranspPropsMes() +{ + CreateAndSendMessage ( PROTMESSID_REQ_NETW_TRANSPORT_PROPS, CVector ( 0 ) ); +} + +bool CProtocol::EvaluateReqNetwTranspPropsMes ( const CVector& vecData ) +{ + // invoke message action + emit ReqNetTranspProps(); + + return false; // no error +} + /******************************************************************************\ diff --git a/src/protocol.h b/src/protocol.h index 948ba792..bbf4859b 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -36,19 +36,21 @@ /* Definitions ****************************************************************/ // protocol message IDs -#define PROTMESSID_ILLEGAL 0 // illegal ID -#define PROTMESSID_ACKN 1 // acknowledge -#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size -#define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size -#define PROTMESSID_PING 12 // OLD, not used anymore -#define PROTMESSID_NET_BLSI_FACTOR 13 // network buffer size factor -#define PROTMESSID_CHANNEL_GAIN 14 // set channel gain for mix -#define PROTMESSID_CONN_CLIENTS_LIST 15 // connected client list -#define PROTMESSID_SERVER_FULL 16 // server full message -#define PROTMESSID_REQ_CONN_CLIENTS_LIST 17 // request connected client list -#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag -#define PROTMESSID_CHAT_TEXT 19 // contains a chat text -#define PROTMESSID_PING_MS 20 // for measuring ping time +#define PROTMESSID_ILLEGAL 0 // illegal ID +#define PROTMESSID_ACKN 1 // acknowledge +#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size +#define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size +#define PROTMESSID_PING 12 // OLD, not used anymore +#define PROTMESSID_NET_BLSI_FACTOR 13 // network buffer size factor +#define PROTMESSID_CHANNEL_GAIN 14 // set channel gain for mix +#define PROTMESSID_CONN_CLIENTS_LIST 15 // connected client list +#define PROTMESSID_SERVER_FULL 16 // server full message +#define PROTMESSID_REQ_CONN_CLIENTS_LIST 17 // request connected client list +#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag +#define PROTMESSID_CHAT_TEXT 19 // contains a chat text +#define PROTMESSID_PING_MS 20 // for measuring ping time +#define PROTMESSID_NETW_TRANSPORT_PROPS 21 // properties for network transport +#define PROTMESSID_REQ_NETW_TRANSPORT_PROPS 22 // request properties for network transport // lengths of message as defined in protocol.cpp file #define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2) @@ -68,15 +70,16 @@ public: void CreateJitBufMes ( const int iJitBufSize ); void CreateReqJitBufMes(); - void CreateReqConnClientsList(); - void CreateServerFullMes(); void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ); void CreateChanGainMes ( const int iChanID, const double dGain ); + void CreateConClientListMes ( const CVector& vecChanInfo ); + void CreateServerFullMes(); + void CreateReqConnClientsList(); void CreateChanNameMes ( const QString strName ); void CreateChatTextMes ( const QString strChatText ); void CreatePingMes ( const int iMs ); - - void CreateConClientListMes ( const CVector& vecChanInfo ); + void CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps ); + void CreateReqNetwTranspPropsMes(); void CreateAndSendAcknMess ( const int& iID, const int& iCnt ); @@ -136,16 +139,18 @@ protected: void CreateAndSendMessage ( const int iID, const CVector& vecData ); - bool EvaluateJitBufMes ( const CVector& vecData ); - bool EvaluateReqJitBufMes ( const CVector& vecData ); - bool EvaluateReqConnClientsList ( const CVector& vecData ); - bool EvaluateServerFullMes ( const CVector& vecData ); - bool EvaluateNetwBlSiFactMes ( const CVector& vecData ); - bool EvaluateChanGainMes ( const CVector& vecData ); - bool EvaluateChanNameMes ( const CVector& vecData ); - bool EvaluateChatTextMes ( const CVector& vecData ); - bool EvaluateConClientListMes ( const CVector& vecData ); - bool EvaluatePingMes ( const CVector& vecData ); + bool EvaluateJitBufMes ( const CVector& vecData ); + bool EvaluateReqJitBufMes ( const CVector& vecData ); + bool EvaluateNetwBlSiFactMes ( const CVector& vecData ); + bool EvaluateChanGainMes ( const CVector& vecData ); + bool EvaluateConClientListMes ( const CVector& vecData ); + bool EvaluateServerFullMes ( const CVector& vecData ); + bool EvaluateReqConnClientsList ( const CVector& vecData ); + bool EvaluateChanNameMes ( const CVector& vecData ); + bool EvaluateChatTextMes ( const CVector& vecData ); + bool EvaluatePingMes ( const CVector& vecData ); + bool EvaluateNetwTranspPropsMes ( const CVector& vecData ); + bool EvaluateReqNetwTranspPropsMes ( const CVector& vecData ); int iOldRecID, iOldRecCnt; @@ -165,15 +170,17 @@ signals: // receiving void ChangeJittBufSize ( int iNewJitBufSize ); + void ReqJittBufSize(); void ChangeNetwBlSiFact ( int iNewNetwBlSiFact ); void ChangeChanGain ( int iChanID, double dNewGain ); + void ConClientListMesReceived ( CVector vecChanInfo ); + void ServerFull(); + void ReqConnClientsList(); void ChangeChanName ( QString strName ); void ChatTextReceived ( QString strChatText ); void PingReceived ( int iMs ); - void ConClientListMesReceived ( CVector vecChanInfo ); - void ReqJittBufSize(); - void ReqConnClientsList(); - void ServerFull(); + void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ); + void ReqNetTranspProps(); }; #endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */ diff --git a/src/socket.cpp b/src/socket.cpp index a23dc25e..642fe68e 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -97,7 +97,7 @@ void CSocket::OnDataReceived() { // client // check if packet comes from the server we want to connect - if ( ! ( pChannel->GetAddress() == RecHostAddr ) ) + if ( !( pChannel->GetAddress() == RecHostAddr ) ) { return; } diff --git a/src/util.h b/src/util.h index e1f67f3c..c71d84b7 100755 --- a/src/util.h +++ b/src/util.h @@ -407,6 +407,35 @@ public: QString strName; }; +class CNetworkTransportProps +{ +public: + enum EAudioCodingType + { + ACT_NONE = 0, + ACT_IMA_ADPCM = 1, + ACT_MS_ADPCM = 2 + }; + + CNetworkTransportProps() : iNetworkPacketSize ( 0 ), iMonoAudioBlockSize ( 0 ), + iNumAudioChannels ( 0 ), iSampleRate ( 0 ), + eAudioCodingType ( ACT_NONE ), iAudioCodingArg ( 0 ) {} + + CNetworkTransportProps ( const unsigned int iNNPS, const unsigned int iNMABS, + const unsigned int iNNACH, const unsigned int iNSR, + const EAudioCodingType eNACT, const int iNACA ) : + iNetworkPacketSize ( iNNPS ), iMonoAudioBlockSize ( iNMABS ), + iNumAudioChannels ( iNNACH ), iSampleRate ( iNSR ), eAudioCodingType ( eNACT ), + iAudioCodingArg ( iNACA ) {} + + unsigned int iNetworkPacketSize; + unsigned int iMonoAudioBlockSize; + unsigned int iNumAudioChannels; + unsigned int iSampleRate; + EAudioCodingType eAudioCodingType; + int iAudioCodingArg; +}; + // Audio Reverbration ---------------------------------------------------------- class CAudioReverb