2011-04-25 12:51:57 +02:00
|
|
|
/******************************************************************************\
|
2015-02-04 19:17:23 +01:00
|
|
|
* Copyright (c) 2004-2015
|
2011-04-25 12:51:57 +02:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#if !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ )
|
|
|
|
#define PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_
|
|
|
|
|
2013-01-02 21:41:04 +01:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QDateTime>
|
2011-04-25 12:51:57 +02:00
|
|
|
#include <list>
|
|
|
|
#include "global.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* 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_NET_BLSI_FACTOR 12 // OLD (not used anymore)
|
|
|
|
#define PROTMESSID_CHANNEL_GAIN 13 // set channel gain for mix
|
2013-02-11 16:21:53 +01:00
|
|
|
#define PROTMESSID_CONN_CLIENTS_LIST_NAME 14 // connected client list
|
2011-04-25 12:51:57 +02:00
|
|
|
#define PROTMESSID_SERVER_FULL 15 // OLD (not used anymore)
|
|
|
|
#define PROTMESSID_REQ_CONN_CLIENTS_LIST 16 // request connected client list
|
|
|
|
#define PROTMESSID_CHANNEL_NAME 17 // set channel name for fader tag
|
|
|
|
#define PROTMESSID_CHAT_TEXT 18 // contains a chat text
|
2015-11-22 18:56:42 +01:00
|
|
|
#define PROTMESSID_PING_MS 19 // OLD (not used anymore)
|
2011-04-25 12:51:57 +02:00
|
|
|
#define PROTMESSID_NETW_TRANSPORT_PROPS 20 // properties for network transport
|
|
|
|
#define PROTMESSID_REQ_NETW_TRANSPORT_PROPS 21 // request properties for network transport
|
2011-05-23 21:06:02 +02:00
|
|
|
#define PROTMESSID_DISCONNECTION 22 // OLD (not used anymore)
|
2013-02-11 16:21:53 +01:00
|
|
|
#define PROTMESSID_REQ_CHANNEL_INFOS 23 // request channel infos for fader tag
|
|
|
|
#define PROTMESSID_CONN_CLIENTS_LIST 24 // channel infos for connected clients
|
|
|
|
#define PROTMESSID_CHANNEL_INFOS 25 // set channel infos
|
2013-02-16 19:01:51 +01:00
|
|
|
#define PROTMESSID_OPUS_SUPPORTED 26 // tells that OPUS codec is supported
|
2015-01-18 22:23:47 +01:00
|
|
|
#define PROTMESSID_LICENCE_REQUIRED 27 // licence required
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// message IDs of connection less messages (CLM)
|
|
|
|
// DEFINITION -> start at 1000, end at 1999, see IsConnectionLessMessageID
|
|
|
|
#define PROTMESSID_CLM_PING_MS 1001 // for measuring ping time
|
|
|
|
#define PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS 1002 // for ping time and num. of clients info
|
|
|
|
#define PROTMESSID_CLM_SERVER_FULL 1003 // server full message
|
|
|
|
#define PROTMESSID_CLM_REGISTER_SERVER 1004 // register server
|
2011-05-03 22:37:06 +02:00
|
|
|
#define PROTMESSID_CLM_UNREGISTER_SERVER 1005 // unregister server
|
2011-04-25 12:51:57 +02:00
|
|
|
#define PROTMESSID_CLM_SERVER_LIST 1006 // server list
|
|
|
|
#define PROTMESSID_CLM_REQ_SERVER_LIST 1007 // request server list
|
|
|
|
#define PROTMESSID_CLM_SEND_EMPTY_MESSAGE 1008 // an empty message shall be send
|
|
|
|
#define PROTMESSID_CLM_EMPTY_MESSAGE 1009 // empty message
|
2011-05-22 11:47:09 +02:00
|
|
|
#define PROTMESSID_CLM_DISCONNECTION 1010 // disconnection
|
2014-02-21 22:25:26 +01:00
|
|
|
#define PROTMESSID_CLM_VERSION_AND_OS 1011 // version number and operating system
|
|
|
|
#define PROTMESSID_CLM_REQ_VERSION_AND_OS 1012 // request version number and operating system
|
2015-12-06 18:51:06 +01:00
|
|
|
#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
|
2014-02-14 23:00:42 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
// lengths of message as defined in protocol.cpp file
|
|
|
|
#define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2)
|
|
|
|
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC (2) */ )
|
|
|
|
|
|
|
|
// time out for message re-send if no acknowledgement was received
|
|
|
|
#define SEND_MESS_TIMEOUT_MS 400 // ms
|
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CProtocol : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
CProtocol();
|
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
void CreateJitBufMes ( const int iJitBufSize );
|
|
|
|
void CreateReqJitBufMes();
|
|
|
|
void CreateChanGainMes ( const int iChanID, const double dGain );
|
2013-02-11 16:21:53 +01:00
|
|
|
void CreateConClientListNameMes ( const CVector<CChannelInfo>& vecChanInfo );
|
|
|
|
void CreateConClientListMes ( const CVector<CChannelInfo>& vecChanInfo );
|
2011-04-25 12:51:57 +02:00
|
|
|
void CreateReqConnClientsList();
|
|
|
|
void CreateChanNameMes ( const QString strName );
|
2013-02-11 16:21:53 +01:00
|
|
|
void CreateChanInfoMes ( const CChannelCoreInfo ChanInfo );
|
|
|
|
void CreateReqChanInfoMes();
|
2011-04-25 12:51:57 +02:00
|
|
|
void CreateChatTextMes ( const QString strChatText );
|
|
|
|
void CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps );
|
|
|
|
void CreateReqNetwTranspPropsMes();
|
2015-01-18 22:23:47 +01:00
|
|
|
void CreateLicenceRequiredMes ( const ELicenceType eLicenceType );
|
2013-02-16 19:01:51 +01:00
|
|
|
void CreateOpusSupportedMes();
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2014-02-21 22:25:26 +01:00
|
|
|
void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs );
|
2011-04-25 12:51:57 +02:00
|
|
|
void CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
|
2011-05-24 20:44:51 +02:00
|
|
|
const int iMs,
|
|
|
|
const int iNumClients );
|
2014-02-21 22:25:26 +01:00
|
|
|
void CreateCLServerFullMes ( const CHostAddress& InetAddr );
|
|
|
|
void CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
|
|
|
const CServerCoreInfo& ServerInfo );
|
|
|
|
void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr );
|
|
|
|
void CreateCLServerListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<CServerInfo> vecServerInfo );
|
|
|
|
void CreateCLReqServerListMes ( const CHostAddress& InetAddr );
|
|
|
|
void CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
|
|
|
|
const CHostAddress& TargetInetAddr );
|
|
|
|
void CreateCLEmptyMes ( const CHostAddress& InetAddr );
|
|
|
|
void CreateCLDisconnection ( const CHostAddress& InetAddr );
|
|
|
|
void CreateCLVersionAndOSMes ( const CHostAddress& InetAddr );
|
|
|
|
void CreateCLReqVersionAndOSMes ( const CHostAddress& InetAddr );
|
2015-12-06 18:51:06 +01:00
|
|
|
void CreateCLConnClientsListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<CChannelInfo>& vecChanInfo );
|
2015-12-09 16:50:30 +01:00
|
|
|
void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2014-02-14 23:00:42 +01:00
|
|
|
static bool ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
|
|
|
|
const int iNumBytesIn,
|
|
|
|
CVector<uint8_t>& vecbyMesBodyData,
|
|
|
|
int& iRecCounter,
|
|
|
|
int& iRecID );
|
2013-06-03 18:07:17 +02:00
|
|
|
|
|
|
|
bool ParseMessageBody ( const CVector<uint8_t>& vecbyMesBodyData,
|
|
|
|
const int iRecCounter,
|
|
|
|
const int iRecID );
|
|
|
|
|
|
|
|
bool ParseConnectionLessMessageBody ( const CVector<uint8_t>& vecbyMesBodyData,
|
|
|
|
const int iRecID,
|
|
|
|
const CHostAddress& InetAddr );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2014-02-16 08:17:48 +01:00
|
|
|
static bool IsConnectionLessMessageID ( const int iID )
|
|
|
|
{ return ( iID >= 1000 ) && ( iID < 2000 ); }
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2011-05-22 11:47:09 +02:00
|
|
|
// this function is public because we need it in the test bench
|
|
|
|
void CreateAndImmSendAcknMess ( const int& iID,
|
|
|
|
const int& iCnt );
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
protected:
|
|
|
|
class CSendMessage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSendMessage() : vecMessage ( 0 ), iID ( PROTMESSID_ILLEGAL ),
|
|
|
|
iCnt ( 0 ) {}
|
|
|
|
CSendMessage ( const CVector<uint8_t>& nMess, const int iNCnt,
|
|
|
|
const int iNID ) : vecMessage ( nMess ), iID ( iNID ),
|
|
|
|
iCnt ( iNCnt ) {}
|
|
|
|
|
|
|
|
CSendMessage& operator= ( const CSendMessage& NewSendMess )
|
|
|
|
{
|
|
|
|
vecMessage.Init ( NewSendMess.vecMessage.Size() );
|
|
|
|
vecMessage = NewSendMess.vecMessage;
|
|
|
|
|
|
|
|
iID = NewSendMess.iID;
|
|
|
|
iCnt = NewSendMess.iCnt;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVector<uint8_t> vecMessage;
|
|
|
|
int iID, iCnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
void EnqueueMessage ( CVector<uint8_t>& vecMessage,
|
|
|
|
const int iCnt,
|
|
|
|
const int iID );
|
|
|
|
|
|
|
|
void GenMessageFrame ( CVector<uint8_t>& vecOut,
|
|
|
|
const int iCnt,
|
|
|
|
const int iID,
|
|
|
|
const CVector<uint8_t>& vecData );
|
|
|
|
|
2013-01-13 20:56:50 +01:00
|
|
|
void PutValOnStream ( CVector<uint8_t>& vecIn,
|
|
|
|
int& iPos,
|
|
|
|
const uint32_t iVal,
|
|
|
|
const int iNumOfBytes );
|
|
|
|
|
|
|
|
void PutStringUTF8OnStream ( CVector<uint8_t>& vecIn,
|
|
|
|
int& iPos,
|
|
|
|
const QByteArray& sStringUTF8 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2014-02-14 23:00:42 +01:00
|
|
|
static uint32_t GetValFromStream ( const CVector<uint8_t>& vecIn,
|
|
|
|
int& iPos,
|
|
|
|
const int iNumOfBytes );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
bool GetStringFromStream ( const CVector<uint8_t>& vecIn,
|
|
|
|
int& iPos,
|
|
|
|
const int iMaxStringLen,
|
|
|
|
QString& strOut );
|
|
|
|
|
|
|
|
void SendMessage();
|
|
|
|
|
|
|
|
void CreateAndSendMessage ( const int iID,
|
|
|
|
const CVector<uint8_t>& vecData );
|
|
|
|
|
|
|
|
void CreateAndImmSendConLessMessage ( const int iID,
|
|
|
|
const CVector<uint8_t>& vecData,
|
|
|
|
const CHostAddress& InetAddr );
|
|
|
|
|
2013-12-14 23:10:38 +01:00
|
|
|
bool EvaluateJitBufMes ( const CVector<uint8_t>& vecData );
|
2011-04-25 12:51:57 +02:00
|
|
|
bool EvaluateReqJitBufMes();
|
2013-12-14 23:10:38 +01:00
|
|
|
bool EvaluateChanGainMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateConClientListNameMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateConClientListMes ( const CVector<uint8_t>& vecData );
|
2011-04-25 12:51:57 +02:00
|
|
|
bool EvaluateReqConnClientsList();
|
2013-12-14 23:10:38 +01:00
|
|
|
bool EvaluateChanNameMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateChanInfoMes ( const CVector<uint8_t>& vecData );
|
2013-02-11 16:21:53 +01:00
|
|
|
bool EvaluateReqChanInfoMes();
|
2013-12-14 23:10:38 +01:00
|
|
|
bool EvaluateChatTextMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData );
|
2011-04-25 12:51:57 +02:00
|
|
|
bool EvaluateReqNetwTranspPropsMes();
|
2015-01-18 22:23:47 +01:00
|
|
|
bool EvaluateLicenceRequiredMes ( const CVector<uint8_t>& vecData );
|
2014-07-26 07:58:01 +02:00
|
|
|
#ifdef USE_LEGACY_CELT
|
2013-02-16 19:01:51 +01:00
|
|
|
bool EvaluateOpusSupportedMes();
|
2014-07-26 07:58:01 +02:00
|
|
|
#endif
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2011-05-03 22:37:06 +02:00
|
|
|
bool EvaluateCLPingMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData );
|
2011-04-25 12:51:57 +02:00
|
|
|
bool EvaluateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateCLServerFullMes();
|
2011-05-03 22:37:06 +02:00
|
|
|
bool EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr );
|
|
|
|
bool EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData );
|
2015-12-09 16:50:30 +01:00
|
|
|
bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr );
|
2011-05-03 22:37:06 +02:00
|
|
|
bool EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData );
|
2015-12-09 16:50:30 +01:00
|
|
|
bool EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr );
|
2014-02-21 22:25:26 +01:00
|
|
|
bool EvaluateCLVersionAndOSMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData );
|
2015-12-09 16:50:30 +01:00
|
|
|
bool EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr );
|
2015-12-06 18:51:06 +01:00
|
|
|
bool EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData );
|
2015-12-09 16:50:30 +01:00
|
|
|
bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
int iOldRecID;
|
|
|
|
int iOldRecCnt;
|
|
|
|
|
|
|
|
// these two objects must be sequred by a mutex
|
|
|
|
uint8_t iCounter;
|
|
|
|
std::list<CSendMessage> SendMessQueue;
|
|
|
|
|
|
|
|
QTimer TimerSendMess;
|
|
|
|
QMutex Mutex;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void OnTimerSendMess() { SendMessage(); }
|
|
|
|
|
|
|
|
signals:
|
|
|
|
// transmitting
|
2011-05-23 21:06:02 +02:00
|
|
|
void MessReadyForSending ( CVector<uint8_t> vecMessage );
|
2011-04-25 12:51:57 +02:00
|
|
|
void CLMessReadyForSending ( CHostAddress InetAddr,
|
|
|
|
CVector<uint8_t> vecMessage );
|
|
|
|
|
|
|
|
// receiving
|
|
|
|
void ChangeJittBufSize ( int iNewJitBufSize );
|
|
|
|
void ReqJittBufSize();
|
|
|
|
void ChangeNetwBlSiFact ( int iNewNetwBlSiFact );
|
|
|
|
void ChangeChanGain ( int iChanID, double dNewGain );
|
2013-02-11 16:21:53 +01:00
|
|
|
void ConClientListNameMesReceived ( CVector<CChannelInfo> vecChanInfo );
|
|
|
|
void ConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo );
|
2011-04-25 12:51:57 +02:00
|
|
|
void ServerFullMesReceived();
|
|
|
|
void ReqConnClientsList();
|
|
|
|
void ChangeChanName ( QString strName );
|
2013-02-11 16:21:53 +01:00
|
|
|
void ChangeChanInfo ( CChannelCoreInfo ChanInfo );
|
|
|
|
void ReqChanInfo();
|
2013-02-16 19:01:51 +01:00
|
|
|
void OpusSupported();
|
2011-04-25 12:51:57 +02:00
|
|
|
void ChatTextReceived ( QString strChatText );
|
|
|
|
void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
|
|
|
|
void ReqNetTranspProps();
|
2015-01-18 22:23:47 +01:00
|
|
|
void LicenceRequired ( ELicenceType eLicenceType );
|
2011-05-23 21:06:02 +02:00
|
|
|
|
2014-02-21 22:25:26 +01:00
|
|
|
void CLPingReceived ( CHostAddress InetAddr,
|
|
|
|
int iMs );
|
|
|
|
void CLPingWithNumClientsReceived ( CHostAddress InetAddr,
|
|
|
|
int iMs,
|
|
|
|
int iNumClients );
|
|
|
|
void CLRegisterServerReceived ( CHostAddress InetAddr,
|
|
|
|
CServerCoreInfo ServerInfo );
|
|
|
|
void CLUnregisterServerReceived ( CHostAddress InetAddr );
|
|
|
|
void CLServerListReceived ( CHostAddress InetAddr,
|
|
|
|
CVector<CServerInfo> vecServerInfo );
|
|
|
|
void CLReqServerList ( CHostAddress InetAddr );
|
|
|
|
void CLSendEmptyMes ( CHostAddress TargetInetAddr );
|
|
|
|
void CLDisconnection ( CHostAddress InetAddr );
|
|
|
|
void CLVersionAndOSReceived ( CHostAddress InetAddr,
|
|
|
|
COSUtil::EOpSystemType eOSType,
|
|
|
|
QString strVersion );
|
|
|
|
void CLReqVersionAndOS ( CHostAddress InetAddr );
|
2015-12-06 18:51:06 +01:00
|
|
|
void CLConnClientsListMesReceived ( CHostAddress InetAddr,
|
|
|
|
CVector<CChannelInfo> vecChanInfo );
|
2015-12-09 16:50:30 +01:00
|
|
|
void CLReqConnClientsList ( CHostAddress InetAddr );
|
2011-04-25 12:51:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */
|