2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2009-02-22 12:07:18 +01:00
|
|
|
* Copyright (c) 2004-2009
|
2006-12-18 15:39:33 +01: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
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#if !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ )
|
2006-12-18 15:39:33 +01:00
|
|
|
#define PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_
|
|
|
|
|
2008-01-20 19:07:13 +01:00
|
|
|
#include <qglobal.h>
|
|
|
|
#include <qmutex.h>
|
|
|
|
#include <qtimer.h>
|
2008-08-01 22:35:07 +02:00
|
|
|
#include <qdatetime.h>
|
2006-03-04 11:24:40 +01:00
|
|
|
#include <list>
|
2006-02-19 09:14:21 +01:00
|
|
|
#include "global.h"
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "util.h"
|
|
|
|
|
2006-02-12 15:26:46 +01:00
|
|
|
|
2006-02-18 23:05:46 +01:00
|
|
|
/* Definitions ****************************************************************/
|
|
|
|
// protocol message IDs
|
2009-02-24 19:20:33 +01:00
|
|
|
#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
|
2009-07-24 16:31:25 +02:00
|
|
|
#define PROTMESSID_NET_BLSI_FACTOR 12 // network buffer size factor
|
|
|
|
#define PROTMESSID_CHANNEL_GAIN 13 // set channel gain for mix
|
|
|
|
#define PROTMESSID_CONN_CLIENTS_LIST 14 // connected client list
|
|
|
|
#define PROTMESSID_SERVER_FULL 15 // server full message
|
|
|
|
#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
|
|
|
|
#define PROTMESSID_PING_MS 19 // for measuring ping time
|
|
|
|
#define PROTMESSID_NETW_TRANSPORT_PROPS 20 // properties for network transport
|
|
|
|
#define PROTMESSID_REQ_NETW_TRANSPORT_PROPS 21 // request properties for network transport
|
|
|
|
#define PROTMESSID_DISCONNECTION 22 // disconnection
|
2006-02-18 23:05:46 +01:00
|
|
|
|
2006-02-19 17:35:35 +01:00
|
|
|
// lengths of message as defined in protocol.cpp file
|
2007-09-08 12:45:14 +02:00
|
|
|
#define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2)
|
2006-12-10 13:02:28 +01:00
|
|
|
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC (2) */ )
|
2006-02-19 17:35:35 +01:00
|
|
|
|
2006-03-04 11:24:40 +01:00
|
|
|
// time out for message re-send if no acknowledgement was received
|
2006-11-25 15:46:57 +01:00
|
|
|
#define SEND_MESS_TIMEOUT_MS 400 // ms
|
2006-03-04 11:24:40 +01:00
|
|
|
|
2006-02-18 23:05:46 +01:00
|
|
|
|
2006-02-20 22:09:36 +01:00
|
|
|
/* Classes ********************************************************************/
|
2006-02-26 11:50:47 +01:00
|
|
|
class CProtocol : public QObject
|
2006-02-12 15:26:46 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
Q_OBJECT
|
2006-02-26 11:50:47 +01:00
|
|
|
|
2006-02-12 15:26:46 +01:00
|
|
|
public:
|
2006-11-25 15:46:57 +01:00
|
|
|
CProtocol();
|
2006-02-12 15:26:46 +01:00
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
void Reset();
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
void CreateJitBufMes ( const int iJitBufSize );
|
|
|
|
void CreateReqJitBufMes();
|
|
|
|
void CreateNetwBlSiFactMes ( const int iNetwBlSiFact );
|
|
|
|
void CreateChanGainMes ( const int iChanID, const double dGain );
|
2009-02-24 19:20:33 +01:00
|
|
|
void CreateConClientListMes ( const CVector<CChannelShortInfo>& vecChanInfo );
|
|
|
|
void CreateServerFullMes();
|
|
|
|
void CreateReqConnClientsList();
|
2008-01-22 22:15:04 +01:00
|
|
|
void CreateChanNameMes ( const QString strName );
|
2008-07-24 18:20:25 +02:00
|
|
|
void CreateChatTextMes ( const QString strChatText );
|
2008-08-10 23:56:03 +02:00
|
|
|
void CreatePingMes ( const int iMs );
|
2009-02-24 19:20:33 +01:00
|
|
|
void CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps );
|
|
|
|
void CreateReqNetwTranspPropsMes();
|
2009-05-09 10:22:09 +02:00
|
|
|
void CreateDisconnectionMes();
|
2006-02-26 11:50:47 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
void CreateAndSendAcknMess ( const int& iID, const int& iCnt );
|
2006-03-01 20:46:44 +01:00
|
|
|
|
2009-03-28 21:02:21 +01:00
|
|
|
bool ParseMessage ( const CVector<uint8_t>& vecbyData,
|
2006-11-25 15:46:57 +01:00
|
|
|
const int iNumBytes );
|
2006-02-26 11:50:47 +01:00
|
|
|
|
2006-03-04 11:24:40 +01:00
|
|
|
protected:
|
2006-11-25 15:46:57 +01:00
|
|
|
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;
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
iID = NewSendMess.iID;
|
2006-11-25 15:46:57 +01:00
|
|
|
iCnt = NewSendMess.iCnt;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVector<uint8_t> vecMessage;
|
|
|
|
int iID, iCnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
void EnqueueMessage ( CVector<uint8_t>& vecMessage,
|
|
|
|
const int iCnt,
|
|
|
|
const int iID );
|
|
|
|
|
|
|
|
bool ParseMessageFrame ( const CVector<uint8_t>& vecIn,
|
2009-03-28 21:02:21 +01:00
|
|
|
const int iNumBytesIn,
|
2006-11-25 15:46:57 +01:00
|
|
|
int& iCnt,
|
|
|
|
int& iID,
|
|
|
|
CVector<uint8_t>& vecData );
|
|
|
|
|
|
|
|
void GenMessageFrame ( CVector<uint8_t>& vecOut,
|
|
|
|
const int iCnt,
|
|
|
|
const int iID,
|
|
|
|
const CVector<uint8_t>& vecData );
|
|
|
|
|
|
|
|
void PutValOnStream ( CVector<uint8_t>& vecIn,
|
|
|
|
unsigned int& iPos,
|
|
|
|
const uint32_t iVal,
|
|
|
|
const unsigned int iNumOfBytes );
|
|
|
|
|
|
|
|
uint32_t GetValFromStream ( const CVector<uint8_t>& vecIn,
|
|
|
|
unsigned int& iPos,
|
|
|
|
const unsigned int iNumOfBytes );
|
|
|
|
|
|
|
|
void SendMessage();
|
|
|
|
|
|
|
|
void CreateAndSendMessage ( const int iID, const CVector<uint8_t>& vecData );
|
|
|
|
|
2009-02-24 19:20:33 +01:00
|
|
|
bool EvaluateJitBufMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateReqJitBufMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateNetwBlSiFactMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateChanGainMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateConClientListMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateServerFullMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateReqConnClientsList ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateChanNameMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateChatTextMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluatePingMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData );
|
|
|
|
bool EvaluateReqNetwTranspPropsMes ( const CVector<uint8_t>& vecData );
|
2009-05-09 10:22:09 +02:00
|
|
|
bool EvaluateDisconnectionMes ( const CVector<uint8_t>& vecData );
|
2006-11-25 15:46:57 +01:00
|
|
|
|
|
|
|
int iOldRecID, iOldRecCnt;
|
|
|
|
|
|
|
|
// these two objects must be sequred by a mutex
|
|
|
|
uint8_t iCounter;
|
|
|
|
std::list<CSendMessage> SendMessQueue;
|
|
|
|
|
|
|
|
QTimer TimerSendMess;
|
|
|
|
QMutex Mutex;
|
2006-03-04 11:24:40 +01:00
|
|
|
|
|
|
|
public slots:
|
2006-11-25 15:46:57 +01:00
|
|
|
void OnTimerSendMess() { SendMessage(); }
|
2006-02-20 22:09:36 +01:00
|
|
|
|
2006-02-26 11:50:47 +01:00
|
|
|
signals:
|
2006-11-25 15:46:57 +01:00
|
|
|
// transmitting
|
|
|
|
void MessReadyForSending ( CVector<uint8_t> vecMessage );
|
|
|
|
|
|
|
|
// receiving
|
|
|
|
void ChangeJittBufSize ( int iNewJitBufSize );
|
2009-02-24 19:20:33 +01:00
|
|
|
void ReqJittBufSize();
|
2006-11-25 15:46:57 +01:00
|
|
|
void ChangeNetwBlSiFact ( int iNewNetwBlSiFact );
|
|
|
|
void ChangeChanGain ( int iChanID, double dNewGain );
|
2009-02-24 19:20:33 +01:00
|
|
|
void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo );
|
|
|
|
void ServerFull();
|
|
|
|
void ReqConnClientsList();
|
2008-01-22 22:15:04 +01:00
|
|
|
void ChangeChanName ( QString strName );
|
2008-07-24 18:20:25 +02:00
|
|
|
void ChatTextReceived ( QString strChatText );
|
2008-08-10 23:56:03 +02:00
|
|
|
void PingReceived ( int iMs );
|
2009-02-24 19:20:33 +01:00
|
|
|
void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
|
|
|
|
void ReqNetTranspProps();
|
2009-05-09 10:22:09 +02:00
|
|
|
void Disconnection();
|
2006-02-12 15:26:46 +01:00
|
|
|
};
|
2006-02-18 23:05:46 +01:00
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */
|