2011-04-23 22:44:09 +02:00
|
|
|
/******************************************************************************\
|
2020-01-01 15:41:43 +01:00
|
|
|
* Copyright (c) 2004-2020
|
2011-04-23 22:44:09 +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
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2019-07-09 08:52:38 +02:00
|
|
|
#pragma once
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-01-02 21:41:04 +01:00
|
|
|
#include <QThread>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
2011-04-23 22:44:09 +02:00
|
|
|
#include "global.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "protocol.h"
|
2014-01-06 16:57:40 +01:00
|
|
|
#include "socket.h"
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Definitions ****************************************************************/
|
2020-03-29 18:03:24 +02:00
|
|
|
// set the time-out for the input buffer until the state changes from
|
2011-04-23 22:44:09 +02:00
|
|
|
// connected to not connected (the actual time depends on the way the error
|
|
|
|
// correction is implemented)
|
2020-04-13 18:13:42 +02:00
|
|
|
#define CON_TIME_OUT_SEC_MAX 30 // seconds
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2020-04-13 18:13:42 +02:00
|
|
|
// number of frames for audio fade-in, 48 kHz, x samples: 3 sec / (x samples / 48 kHz)
|
|
|
|
#define FADE_IN_NUM_FRAMES 2250
|
|
|
|
#define FADE_IN_NUM_FRAMES_DBLE_FRAMESIZE 1125
|
2020-03-29 18:03:24 +02:00
|
|
|
|
|
|
|
|
2011-04-23 22:44:09 +02:00
|
|
|
enum EPutDataStat
|
|
|
|
{
|
|
|
|
PS_GEN_ERROR,
|
|
|
|
PS_AUDIO_OK,
|
|
|
|
PS_AUDIO_ERR,
|
2014-02-16 09:12:07 +01:00
|
|
|
PS_AUDIO_INVALID,
|
2011-04-23 22:44:09 +02:00
|
|
|
PS_PROT_OK,
|
|
|
|
PS_PROT_OK_MESS_NOT_EVALUATED,
|
2014-02-16 09:12:07 +01:00
|
|
|
PS_PROT_ERR,
|
|
|
|
PS_NEW_CONNECTION
|
2011-04-23 22:44:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CChannel : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
// we have to make "server" the default since I do not see a chance to
|
|
|
|
// use constructor initialization in the server for a vector of channels
|
|
|
|
CChannel ( const bool bNIsServer = true );
|
|
|
|
|
2014-02-16 09:12:07 +01:00
|
|
|
void PutProtcolData ( const int iRecCounter,
|
|
|
|
const int iRecID,
|
|
|
|
const CVector<uint8_t>& vecbyMesBodyData,
|
|
|
|
const CHostAddress& RecHostAddr );
|
|
|
|
|
|
|
|
EPutDataStat PutAudioData ( const CVector<uint8_t>& vecbyData,
|
|
|
|
const int iNumBytes,
|
|
|
|
CHostAddress RecHostAddr );
|
|
|
|
|
2014-01-12 10:48:49 +01:00
|
|
|
EGetDataStat GetData ( CVector<uint8_t>& vecbyData,
|
|
|
|
const int iNumBytes );
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2014-02-16 09:12:07 +01:00
|
|
|
void PrepAndSendPacket ( CHighPrioSocket* pSocket,
|
2014-01-12 10:48:49 +01:00
|
|
|
const CVector<uint8_t>& vecbyNPacket,
|
|
|
|
const int iNPacketLen );
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; }
|
|
|
|
bool IsConnected() const { return iConTimeOut > 0; }
|
2011-05-22 11:47:09 +02:00
|
|
|
void Disconnect();
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
void SetEnable ( const bool bNEnStat );
|
|
|
|
bool IsEnabled() { return bIsEnabled; }
|
|
|
|
|
|
|
|
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
|
|
|
bool GetAddress ( CHostAddress& RetAddr );
|
2014-01-06 17:06:04 +01:00
|
|
|
const CHostAddress& GetAddress() const { return InetAddr; }
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-02-11 16:36:47 +01:00
|
|
|
void ResetInfo() { ChannelInfo = CChannelCoreInfo(); } // reset does not emit a message
|
2011-04-23 22:44:09 +02:00
|
|
|
QString GetName();
|
2013-02-11 16:36:47 +01:00
|
|
|
void SetChanInfo ( const CChannelCoreInfo& NChanInf );
|
|
|
|
CChannelCoreInfo& GetChanInfo() { return ChannelInfo; }
|
|
|
|
|
|
|
|
void SetRemoteInfo ( const CChannelCoreInfo ChInfo )
|
2019-05-17 22:06:48 +02:00
|
|
|
{ Protocol.CreateChanInfoMes ( ChInfo ); }
|
|
|
|
|
2013-02-11 16:36:47 +01:00
|
|
|
void CreateReqChanInfoMes() { Protocol.CreateReqChanInfoMes(); }
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
void SetGain ( const int iChanID, const double dNewGain );
|
|
|
|
double GetGain ( const int iChanID );
|
2020-04-13 18:13:42 +02:00
|
|
|
double GetFadeInGain() { return static_cast<double> ( iFadeInCnt ) / iFadeInCntMax; }
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
void SetRemoteChanGain ( const int iId, const double dGain )
|
|
|
|
{ Protocol.CreateChanGainMes ( iId, dGain ); }
|
|
|
|
|
2011-05-17 17:39:33 +02:00
|
|
|
bool SetSockBufNumFrames ( const int iNewNumFrames,
|
|
|
|
const bool bPreserve = false );
|
2011-04-23 22:44:09 +02:00
|
|
|
int GetSockBufNumFrames() const { return iCurSockBufNumFrames; }
|
|
|
|
|
2011-06-16 13:37:17 +02:00
|
|
|
void UpdateSocketBufferSize();
|
2011-05-22 22:40:29 +02:00
|
|
|
|
2011-04-23 22:44:09 +02:00
|
|
|
int GetUploadRateKbps();
|
|
|
|
|
|
|
|
// set/get network out buffer size and size factor
|
2013-02-16 19:06:18 +01:00
|
|
|
void SetAudioStreamProperties ( const EAudComprType eNewAudComprType,
|
|
|
|
const int iNewNetwFrameSize,
|
2011-04-23 22:44:09 +02:00
|
|
|
const int iNewNetwFrameSizeFact,
|
|
|
|
const int iNewNumAudioChannels );
|
2011-05-22 22:40:29 +02:00
|
|
|
|
2011-06-16 13:43:28 +02:00
|
|
|
void SetDoAutoSockBufSize ( const bool bValue )
|
|
|
|
{ bDoAutoSockBufSize = bValue; }
|
|
|
|
|
2011-05-22 22:40:29 +02:00
|
|
|
bool GetDoAutoSockBufSize() const { return bDoAutoSockBufSize; }
|
|
|
|
|
2011-04-23 22:44:09 +02:00
|
|
|
int GetNetwFrameSizeFact() const { return iNetwFrameSizeFact; }
|
|
|
|
int GetNetwFrameSize() const { return iNetwFrameSize; }
|
2011-05-22 22:40:29 +02:00
|
|
|
|
2015-03-14 17:54:36 +01:00
|
|
|
void GetBufErrorRates ( CVector<double>& vecErrRates, double& dLimit, double& dMaxUpLimit )
|
|
|
|
{ SockBuf.GetErrorRates ( vecErrRates, dLimit, dMaxUpLimit ); }
|
2013-02-23 18:49:44 +01:00
|
|
|
|
2013-02-16 19:06:18 +01:00
|
|
|
EAudComprType GetAudioCompressionType() { return eAudioCompressionType; }
|
2011-04-23 22:44:09 +02:00
|
|
|
int GetNumAudioChannels() const { return iNumAudioChannels; }
|
|
|
|
|
|
|
|
// network protocol interface
|
|
|
|
void CreateJitBufMes ( const int iJitBufSize )
|
|
|
|
{
|
|
|
|
if ( ProtocolIsEnabled() )
|
|
|
|
{
|
|
|
|
Protocol.CreateJitBufMes ( iJitBufSize );
|
|
|
|
}
|
|
|
|
}
|
2015-01-23 20:43:18 +01:00
|
|
|
void CreateReqNetwTranspPropsMes() { Protocol.CreateReqNetwTranspPropsMes(); }
|
|
|
|
void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); }
|
|
|
|
void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); }
|
|
|
|
void CreateChatTextMes ( const QString& strChatText ) { Protocol.CreateChatTextMes ( strChatText ); }
|
|
|
|
void CreateLicReqMes ( const ELicenceType eLicenceType ) { Protocol.CreateLicenceRequiredMes ( eLicenceType ); }
|
2020-03-30 22:36:25 +02:00
|
|
|
void CreateReqChannelLevelListMes ( bool bOptIn ) { Protocol.CreateReqChannelLevelListMes ( bOptIn ); }
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-02-11 16:36:47 +01:00
|
|
|
void CreateConClientListMes ( const CVector<CChannelInfo>& vecChanInfo )
|
|
|
|
{ Protocol.CreateConClientListMes ( vecChanInfo ); }
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
CNetworkTransportProps GetNetworkTransportPropsFromCurrentSettings();
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2020-04-05 14:49:36 +02:00
|
|
|
bool ChannelLevelsRequired() const { return bChannelLevelsRequired; }
|
|
|
|
|
2020-04-04 23:57:16 +02:00
|
|
|
double GetPrevLevel() const { return dPrevLevel; }
|
|
|
|
void SetPrevLevel ( const double nPL ) { dPrevLevel = nPL; }
|
|
|
|
|
2011-04-23 22:44:09 +02:00
|
|
|
protected:
|
2013-02-12 16:33:28 +01:00
|
|
|
bool ProtocolIsEnabled();
|
|
|
|
|
|
|
|
void ResetNetworkTransportProperties()
|
|
|
|
{
|
|
|
|
// set it to a state were no decoding is ever possible (since we want
|
|
|
|
// only to decode data when a network transport property message is
|
2013-02-16 19:06:18 +01:00
|
|
|
// received with the correct values)
|
|
|
|
eAudioCompressionType = CT_NONE;
|
|
|
|
iNetwFrameSizeFact = FRAME_SIZE_FACTOR_PREFERRED;
|
|
|
|
iNetwFrameSize = CELT_MINIMUM_NUM_BYTES;
|
|
|
|
iNumAudioChannels = 1; // mono
|
2020-04-04 23:57:16 +02:00
|
|
|
|
|
|
|
dPrevLevel = 0.0;
|
2013-02-12 16:33:28 +01:00
|
|
|
}
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
// connection parameters
|
2013-02-11 16:36:47 +01:00
|
|
|
CHostAddress InetAddr;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-02-11 16:36:47 +01:00
|
|
|
// channel info
|
|
|
|
CChannelCoreInfo ChannelInfo;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
// mixer and effect settings
|
2013-02-11 16:36:47 +01:00
|
|
|
CVector<double> vecdGains;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
// network jitter-buffer
|
2013-02-11 16:36:47 +01:00
|
|
|
CNetBufWithStats SockBuf;
|
|
|
|
int iCurSockBufNumFrames;
|
|
|
|
bool bDoAutoSockBufSize;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
// network output conversion buffer
|
2013-02-11 16:36:47 +01:00
|
|
|
CConvBuf<uint8_t> ConvBuf;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
|
|
|
// network protocol
|
2013-02-11 16:36:47 +01:00
|
|
|
CProtocol Protocol;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-02-11 16:36:47 +01:00
|
|
|
int iConTimeOut;
|
|
|
|
int iConTimeOutStartVal;
|
2020-03-29 18:03:24 +02:00
|
|
|
int iFadeInCnt;
|
2020-04-13 18:13:42 +02:00
|
|
|
int iFadeInCntMax;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-02-11 16:36:47 +01:00
|
|
|
bool bIsEnabled;
|
|
|
|
bool bIsServer;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-02-11 16:36:47 +01:00
|
|
|
int iNetwFrameSizeFact;
|
|
|
|
int iNetwFrameSize;
|
2020-04-13 18:46:04 +02:00
|
|
|
int iAudioFrameSizeSamples;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-02-16 19:06:18 +01:00
|
|
|
EAudComprType eAudioCompressionType;
|
2013-02-11 16:36:47 +01:00
|
|
|
int iNumAudioChannels;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2013-02-11 16:36:47 +01:00
|
|
|
QMutex Mutex;
|
2014-02-13 22:03:33 +01:00
|
|
|
QMutex MutexSocketBuf;
|
|
|
|
QMutex MutexConvBuf;
|
2011-04-23 22:44:09 +02:00
|
|
|
|
2020-04-05 14:49:36 +02:00
|
|
|
bool bChannelLevelsRequired;
|
2020-04-04 23:57:16 +02:00
|
|
|
double dPrevLevel;
|
2020-04-05 14:49:36 +02:00
|
|
|
|
2011-04-23 22:44:09 +02:00
|
|
|
public slots:
|
|
|
|
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
|
|
|
void OnJittBufSizeChange ( int iNewJitBufSize );
|
|
|
|
void OnChangeChanGain ( int iChanID, double dNewGain );
|
2013-02-11 16:36:47 +01:00
|
|
|
void OnChangeChanInfo ( CChannelCoreInfo ChanInfo );
|
2011-04-23 22:44:09 +02:00
|
|
|
void OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
|
|
|
|
void OnReqNetTranspProps();
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
void OnParseMessageBody ( CVector<uint8_t> vecbyMesBodyData,
|
|
|
|
int iRecCounter,
|
2014-01-06 13:52:53 +01:00
|
|
|
int iRecID )
|
|
|
|
{
|
|
|
|
// note that the return value is ignored here
|
|
|
|
Protocol.ParseMessageBody ( vecbyMesBodyData, iRecCounter, iRecID );
|
|
|
|
}
|
2013-06-03 18:07:17 +02:00
|
|
|
|
2014-02-16 09:12:07 +01:00
|
|
|
void OnProtcolMessageReceived ( int iRecCounter,
|
|
|
|
int iRecID,
|
|
|
|
CVector<uint8_t> vecbyMesBodyData,
|
|
|
|
CHostAddress RecHostAddr )
|
|
|
|
{
|
|
|
|
PutProtcolData ( iRecCounter, iRecID, vecbyMesBodyData, RecHostAddr );
|
|
|
|
}
|
2014-02-13 22:03:33 +01:00
|
|
|
|
2014-02-16 09:12:07 +01:00
|
|
|
void OnProtcolCLMessageReceived ( int iRecID,
|
|
|
|
CVector<uint8_t> vecbyMesBodyData,
|
|
|
|
CHostAddress RecHostAddr )
|
|
|
|
{
|
|
|
|
emit DetectedCLMessage ( vecbyMesBodyData, iRecID, RecHostAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnNewConnection() { emit NewConnection(); }
|
2014-02-11 18:35:39 +01:00
|
|
|
|
2020-04-05 14:49:36 +02:00
|
|
|
void OnReqChannelLevelList ( bool bOptIn ) { bChannelLevelsRequired = bOptIn; }
|
|
|
|
|
2011-04-23 22:44:09 +02:00
|
|
|
signals:
|
|
|
|
void MessReadyForSending ( CVector<uint8_t> vecMessage );
|
|
|
|
void NewConnection();
|
|
|
|
void ReqJittBufSize();
|
2011-05-28 14:17:01 +02:00
|
|
|
void JittBufSizeChanged ( int iNewJitBufSize );
|
|
|
|
void ServerAutoSockBufSizeChange ( int iNNumFra );
|
2011-04-23 22:44:09 +02:00
|
|
|
void ReqConnClientsList();
|
2013-02-11 16:36:47 +01:00
|
|
|
void ConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo );
|
|
|
|
void ChanInfoHasChanged();
|
|
|
|
void ReqChanInfo();
|
2011-04-23 22:44:09 +02:00
|
|
|
void ChatTextReceived ( QString strChatText );
|
|
|
|
void ReqNetTranspProps();
|
2015-01-23 20:43:18 +01:00
|
|
|
void LicenceRequired ( ELicenceType eLicenceType );
|
2011-04-23 22:44:09 +02:00
|
|
|
void Disconnected();
|
2013-06-03 18:07:17 +02:00
|
|
|
|
|
|
|
void DetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData,
|
2014-02-16 09:12:07 +01:00
|
|
|
int iRecID,
|
|
|
|
CHostAddress RecHostAddr );
|
2013-06-03 18:07:17 +02:00
|
|
|
|
|
|
|
void ParseMessageBody ( CVector<uint8_t> vecbyMesBodyData,
|
|
|
|
int iRecCounter,
|
|
|
|
int iRecID );
|
2011-04-23 22:44:09 +02:00
|
|
|
};
|