jamulus/src/protocol.h

161 lines
5.2 KiB
C
Raw Normal View History

/******************************************************************************\
* Copyright (c) 2004-2006
*
* 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_
2006-02-19 09:14:21 +01:00
#include <qglobal.h>
2006-02-26 11:50:47 +01:00
#include <qthread.h>
2006-03-04 11:24:40 +01:00
#include <qtimer.h>
#include <list>
2006-02-19 09:14:21 +01:00
#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_PING 12 // for measuring ping time
#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
2006-02-19 17:35:35 +01:00
// lengths of message as defined in protocol.cpp file
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ )
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
#define SEND_MESS_TIMEOUT_MS 400 // ms
2006-03-04 11:24:40 +01:00
/* Classes ********************************************************************/
2006-02-26 11:50:47 +01:00
class CProtocol : public QObject
{
2006-02-26 11:50:47 +01:00
Q_OBJECT
public:
2006-03-04 11:24:40 +01:00
CProtocol();
2006-02-26 11:50:47 +01:00
void CreateJitBufMes ( const int iJitBufSize );
void CreateReqJitBufMes();
void CreateNetwBlSiFactMes ( const int iNetwBlSiFact );
void CreateChanGainMes ( const int iChanID, const double dGain );
void CreateConClientListMes ( const CVector<int>& veciChanIDs,
const CVector<uint32_t>& veciIpAddrs,
const CVector<std::string>& vecstrNames );
2006-02-26 11:50:47 +01:00
2006-03-01 20:46:44 +01:00
void CreateAndSendAcknMess ( const int& iID, const int& iCnt );
2006-02-26 11:50:47 +01:00
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
const int iNumBytes );
2006-03-04 11:24:40 +01:00
void DeleteSendMessQueue ();
2006-02-26 11:50:47 +01:00
2006-03-04 11:24:40 +01: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 );
2006-02-26 11:50:47 +01:00
bool ParseMessageFrame ( const CVector<uint8_t>& vecIn,
int& iCnt,
int& iID,
CVector<uint8_t>& vecData );
2006-02-19 17:35:35 +01:00
void GenMessageFrame ( CVector<uint8_t>& vecOut,
const int iCnt,
const int iID,
2006-03-08 21:13:42 +01:00
const CVector<uint8_t>& vecData );
void PutValOnStream ( CVector<uint8_t>& vecIn,
unsigned int& iPos,
const uint32_t iVal,
const unsigned int iNumOfBytes );
2006-02-19 17:35:35 +01:00
uint32_t GetValFromStream ( const CVector<uint8_t>& vecIn,
unsigned int& iPos,
const unsigned int iNumOfBytes );
2006-03-04 11:24:40 +01:00
void SendMessage();
2006-03-08 21:13:42 +01:00
void CreateAndSendMessage ( const int iID, const CVector<uint8_t>& vecData );
void EvaluateJitBufMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateReqJitBufMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateNetwBlSiFactMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateChanGainMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateConClientListMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
2006-03-04 11:24:40 +01:00
int iOldRecID, iOldRecCnt;
// these two objects must be sequred by a mutex
uint8_t iCounter;
2006-03-04 11:24:40 +01:00
std::list<CSendMessage> SendMessQueue;
2006-03-06 18:04:07 +01:00
2006-03-04 11:24:40 +01:00
QTimer TimerSendMess;
QMutex Mutex;
public slots:
void OnTimerSendMess() { SendMessage(); }
2006-02-26 11:50:47 +01:00
signals:
// transmitting
2006-03-01 20:46:44 +01:00
void MessReadyForSending ( CVector<uint8_t> vecMessage );
// receiving
void ChangeJittBufSize ( int iNewJitBufSize );
void ChangeNetwBlSiFact ( int iNewNetwBlSiFact );
void ChangeChanGain ( int iChanID, double dNewGain );
void ReqJittBufSize();
};
#endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */