From a7a1549fe5c75eb0808b342a1e9184fa8c33c8a3 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sun, 29 Mar 2020 18:00:07 +0100 Subject: [PATCH] Define new protocol messages --- src/protocol.cpp | 130 +++++++++++++++++++++++++++++++++++++++++++++++ src/protocol.h | 26 +++++++--- 2 files changed, 149 insertions(+), 7 deletions(-) diff --git a/src/protocol.cpp b/src/protocol.cpp index de15bb84..0dce5f30 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -153,6 +153,14 @@ MESSAGES (with connection) | 1 byte licence type | +---------------------+ +- PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST: Opt in or out of the channel level list + + +---------------+ + | 1 byte option | + +---------------+ + + option is boolean, true to opt in, false to opt out + // #### COMPATIBILITY OLD VERSION, TO BE REMOVED #### - PROTMESSID_OPUS_SUPPORTED: Informs that OPUS codec is supported @@ -276,6 +284,27 @@ CONNECTION LESS MESSAGES note: does not have any data -> n = 0 +- PROTMESSID_CLM_CHANNEL_LEVEL_LIST: The channel level list + + +----------------------------------+ + | ( ( n + 1 ) / 2 ) * 4 bit values | + +----------------------------------+ + + n is number of connected clients + + the values are the maximum channel levels for a client frame converted + to the range of CMultiColorLEDBar in 4 bits, two entries per byte + with the earlier channel in the lower half of the byte + + where an odd number of clients is connected, there will be four unused + upper bits in the final byte, containing 0xF (which is out of range) + + the server may compute them message when any client has used + PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST to opt in + + the server may issue to message only to a client that has used + PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST to opt in + ****************************************************************************** * @@ -549,6 +578,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; case PROTMESSID_LICENCE_REQUIRED: bRet = EvaluateLicenceRequiredMes ( vecbyMesBodyData ); break; + + case PROTMESSID_REQ_CHANNEL_LEVEL_LIST: + bRet = EvaluateReqChannelLevelListMes ( vecbyMesBodyData ); + break; } // immediately send acknowledge message @@ -634,6 +667,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; case PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST: bRet = EvaluateCLReqConnClientsListMes ( InetAddr ); break; + + case PROTMESSID_CLM_CHANNEL_LEVEL_LIST: + bRet = EvaluateCLChannelLevelListMes ( InetAddr, vecbyMesBodyData ); + break; } } else @@ -1234,6 +1271,40 @@ void CProtocol::CreateOpusSupportedMes() CVector ( 0 ) ); } +void CProtocol::CreateReqChannelLevelListMes ( const bool bRCL ) +{ + CVector vecData ( 1 ); // 1 byte of data + int iPos = 0; // init position pointer + PutValOnStream ( vecData, iPos, + static_cast ( bRCL ), 1 ); + + CreateAndSendMessage ( PROTMESSID_REQ_CHANNEL_LEVEL_LIST, vecData ); +} + +bool CProtocol::EvaluateReqChannelLevelListMes ( const CVector& vecData ) +{ + int iPos = 0; // init position pointer + + // check size + if ( vecData.Size() != 1 ) + { + return true; // return error code + } + + // extract opt in / out for channel levels + uint32_t val = GetValFromStream ( vecData, iPos, 1 ); + + if ( val != 0 && val != 1 ) + { + return true; // return error code + } + + // invoke message action + emit ReqChannelLevelList ( static_cast ( val ) ); + + return false; // no error +} + // Connection less messages ---------------------------------------------------- void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ) @@ -1936,6 +2007,65 @@ bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr ) return false; // no error } +void CProtocol::CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, + const CVector& vecLevelList, + const int iNumClients ) +{ + // This must be a multiple of bytes at four bits per client + const int iNumBytes = ( iNumClients + 1 ) / 2; + CVector vecData( iNumBytes ); + int iPos = 0; // init position pointer + + for ( int i = 0, j = 0; i < iNumClients; i += 2 /* pack two per byte */, j++ ) + { + uint16_t levelLo = vecLevelList[i] & 0x0F; + uint16_t levelHi = ( i + 1 < iNumClients ) ? vecLevelList[i + 1] & 0x0F : 0x0F; + uint8_t byte = static_cast ( levelLo | ( levelHi << 4 ) ); + + PutValOnStream ( vecData, iPos, + static_cast ( byte ), 1 ); + } + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CHANNEL_LEVEL_LIST, + vecData, + InetAddr ); +} + +bool CProtocol::EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr, + const CVector& vecData ) +{ + int iPos = 0; // init position pointer + const int iDataLen = vecData.Size(); // four bits per channel, 2 channels per byte + // may have one too many entries, last being 0xF + int iVecLen = iDataLen * 2; // one ushort per channel + + CVector vecLevelList ( iVecLen ); + + for (int i = 0, j = 0; i < iDataLen; i++, j += 2 ) + { + uint8_t byte = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + uint16_t levelLo = byte & 0x0F; + uint16_t levelHi = ( byte >> 4 ) & 0x0F; + + vecLevelList[j] = levelLo; + + if ( levelHi != 0x0F ) + { + vecLevelList[j + 1] = levelHi; + } + else + { + vecLevelList.resize ( iVecLen - 1 ); + break; + } + } + + // invoke message action + emit CLChannelLevelListReceived ( InetAddr, vecLevelList ); + + return false; // no error +} + /******************************************************************************\ * Message generation and parsing * diff --git a/src/protocol.h b/src/protocol.h index 617092c0..91dfa77d 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -54,6 +54,7 @@ #define PROTMESSID_CHANNEL_INFOS 25 // set channel infos #define PROTMESSID_OPUS_SUPPORTED 26 // tells that OPUS codec is supported #define PROTMESSID_LICENCE_REQUIRED 27 // licence required +#define PROTMESSID_REQ_CHANNEL_LEVEL_LIST 28 // request the channel level list // message IDs of connection less messages (CLM) // DEFINITION -> start at 1000, end at 1999, see IsConnectionLessMessageID @@ -71,6 +72,7 @@ #define PROTMESSID_CLM_REQ_VERSION_AND_OS 1012 // request version number and operating system #define PROTMESSID_CLM_CONN_CLIENTS_LIST 1013 // channel infos for connected clients #define PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST 1014 // request the connected clients list +#define PROTMESSID_CLM_CHANNEL_LEVEL_LIST 1015 // channel level list // lengths of message as defined in protocol.cpp file #define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2) @@ -102,6 +104,7 @@ public: void CreateReqNetwTranspPropsMes(); void CreateLicenceRequiredMes ( const ELicenceType eLicenceType ); void CreateOpusSupportedMes(); + void CreateReqChannelLevelListMes ( const bool bRCL ); void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ); void CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, @@ -123,6 +126,9 @@ public: void CreateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecChanInfo ); void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr ); + void CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, + const CVector& vecLevelList, + const int iNumClients ); static bool ParseMessageFrame ( const CVector& vecbyData, const int iNumBytesIn, @@ -205,17 +211,18 @@ protected: const CVector& vecData, const CHostAddress& InetAddr ); - bool EvaluateJitBufMes ( const CVector& vecData ); + bool EvaluateJitBufMes ( const CVector& vecData ); bool EvaluateReqJitBufMes(); - bool EvaluateChanGainMes ( const CVector& vecData ); - bool EvaluateConClientListMes ( const CVector& vecData ); + bool EvaluateChanGainMes ( const CVector& vecData ); + bool EvaluateConClientListMes ( const CVector& vecData ); bool EvaluateReqConnClientsList(); - bool EvaluateChanInfoMes ( const CVector& vecData ); + bool EvaluateChanInfoMes ( const CVector& vecData ); bool EvaluateReqChanInfoMes(); - bool EvaluateChatTextMes ( const CVector& vecData ); - bool EvaluateNetwTranspPropsMes ( const CVector& vecData ); + bool EvaluateChatTextMes ( const CVector& vecData ); + bool EvaluateNetwTranspPropsMes ( const CVector& vecData ); bool EvaluateReqNetwTranspPropsMes(); - bool EvaluateLicenceRequiredMes ( const CVector& vecData ); + bool EvaluateLicenceRequiredMes ( const CVector& vecData ); + bool EvaluateReqChannelLevelListMes ( const CVector& vecData ); bool EvaluateCLPingMes ( const CHostAddress& InetAddr, const CVector& vecData ); @@ -236,6 +243,8 @@ protected: bool EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr ); + bool EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr, + const CVector& vecData ); int iOldRecID; int iOldRecCnt; @@ -270,6 +279,7 @@ signals: void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ); void ReqNetTranspProps(); void LicenceRequired ( ELicenceType eLicenceType ); + void ReqChannelLevelList ( bool bOptIn ); void CLPingReceived ( CHostAddress InetAddr, int iMs ); @@ -291,4 +301,6 @@ signals: void CLConnClientsListMesReceived ( CHostAddress InetAddr, CVector vecChanInfo ); void CLReqConnClientsList ( CHostAddress InetAddr ); + void CLChannelLevelListReceived ( CHostAddress InetAddr, + CVector vecLevelList ); };