2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#if !defined ( CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_ )
|
2006-12-18 15:39:33 +01:00
|
|
|
#define CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_
|
|
|
|
|
2008-01-20 19:07:13 +01:00
|
|
|
#include <qthread.h>
|
|
|
|
#include <qdatetime.h>
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "audiocompr.h"
|
|
|
|
#include "util.h"
|
2006-02-20 22:09:36 +01:00
|
|
|
#include "resample.h"
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "protocol.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Definitions ****************************************************************/
|
|
|
|
// Set the time-out for the input buffer until the state changes from
|
|
|
|
// connected to not-connected (the actual time depends on the way the error
|
2006-12-09 11:04:27 +01:00
|
|
|
// correction is implemented)
|
|
|
|
#define CON_TIME_OUT_SEC_MAX 5 // seconds
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
// no valid channel number
|
2007-09-08 12:45:14 +02:00
|
|
|
#define INVALID_CHANNEL_ID ( MAX_NUM_CHANNELS + 1 )
|
2006-03-06 18:04:07 +01:00
|
|
|
|
|
|
|
enum EPutDataStat
|
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
PS_GEN_ERROR,
|
|
|
|
PS_AUDIO_OK,
|
|
|
|
PS_AUDIO_ERR,
|
|
|
|
PS_PROT_OK,
|
|
|
|
PS_PROT_ERR
|
2006-12-09 11:40:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum EGetDataStat
|
|
|
|
{
|
|
|
|
GS_BUFFER_OK,
|
|
|
|
GS_BUFFER_UNDERRUN,
|
|
|
|
GS_CHAN_NOW_DISCONNECTED,
|
|
|
|
GS_CHAN_NOT_CONNECTED
|
2006-12-18 15:39:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
// CChannel --------------------------------------------------------------------
|
|
|
|
class CChannel : public QObject
|
2006-02-26 11:50:47 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
Q_OBJECT
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
CChannel();
|
|
|
|
virtual ~CChannel() {}
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
EPutDataStat PutData ( const CVector<unsigned char>& vecbyData,
|
2006-12-18 15:39:33 +01:00
|
|
|
int iNumBytes );
|
|
|
|
EGetDataStat GetData ( CVector<double>& vecdData );
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
CVector<unsigned char> PrepSendPacket ( const CVector<short>& vecsNPacket );
|
2006-02-26 11:50:47 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
bool IsConnected() const { return iConTimeOut > 0; }
|
2006-12-09 11:04:27 +01:00
|
|
|
|
|
|
|
void SetEnable ( const bool bNEnStat );
|
|
|
|
bool IsEnabled() { return bIsEnabled; }
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
|
|
|
bool GetAddress ( CHostAddress& RetAddr );
|
2007-09-08 12:45:14 +02:00
|
|
|
CHostAddress GetAddress() { return InetAddr; }
|
2006-10-30 22:14:44 +01:00
|
|
|
|
2008-01-22 22:15:04 +01:00
|
|
|
void SetName ( const QString sNNa ) { sName = sNNa; }
|
|
|
|
QString GetName() { return sName; }
|
2006-11-04 10:57:59 +01:00
|
|
|
|
2008-01-22 22:15:04 +01:00
|
|
|
void SetRemoteName ( const QString strName )
|
2006-12-10 12:06:14 +01:00
|
|
|
{ Protocol.CreateChanNameMes ( strName ); }
|
|
|
|
|
2006-11-26 22:25:56 +01:00
|
|
|
void SetGain ( const int iNID, const double dNG ) { vecdGains[iNID] = dNG; }
|
|
|
|
double GetGain( const int iNID ) { return vecdGains[iNID]; }
|
2006-12-09 16:00:24 +01:00
|
|
|
|
|
|
|
void SetRemoteChanGain ( const int iId, const double dGain )
|
|
|
|
{ Protocol.CreateChanGainMes ( iId, dGain ); }
|
2006-12-10 12:06:14 +01:00
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
void SetSockBufSize ( const int iNumBlocks );
|
2006-11-25 15:46:57 +01:00
|
|
|
int GetSockBufSize() { return iCurSockBufSize; }
|
2006-02-26 11:50:47 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
void SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut );
|
|
|
|
int GetNetwBufSizeFactOut() { return iCurNetwOutBlSiFact; }
|
2006-03-12 12:50:35 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
int GetNetwBufSizeFactIn() { return iCurNetwInBlSiFact; }
|
2006-09-16 13:26:15 +02:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
// network protocol interface
|
|
|
|
void CreateJitBufMes ( const int iJitBufSize )
|
|
|
|
{
|
|
|
|
if ( IsConnected() )
|
|
|
|
{
|
|
|
|
Protocol.CreateJitBufMes ( iJitBufSize );
|
|
|
|
}
|
|
|
|
}
|
2006-12-09 11:04:27 +01:00
|
|
|
void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); }
|
2006-12-08 19:19:16 +01:00
|
|
|
void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); }
|
2006-02-26 11:50:47 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
void CreateNetwBlSiFactMes ( const int iNetwBlSiFact )
|
|
|
|
{
|
|
|
|
if ( IsConnected() )
|
|
|
|
{
|
|
|
|
Protocol.CreateNetwBlSiFactMes ( iNetwBlSiFact );
|
|
|
|
}
|
|
|
|
}
|
2006-03-12 12:50:35 +01:00
|
|
|
|
2006-11-26 22:25:56 +01:00
|
|
|
void CreateConClientListMes ( const CVector<CChannelShortInfo>& vecChanInfo )
|
2006-11-25 15:46:57 +01:00
|
|
|
{
|
2006-11-26 22:25:56 +01:00
|
|
|
Protocol.CreateConClientListMes ( vecChanInfo );
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2006-03-12 12:50:35 +01:00
|
|
|
|
2006-03-11 21:35:38 +01:00
|
|
|
protected:
|
2006-11-25 15:46:57 +01:00
|
|
|
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
// audio compression
|
|
|
|
CAudioCompression AudioCompressionIn;
|
|
|
|
int iAudComprSizeIn;
|
2006-11-25 15:46:57 +01:00
|
|
|
CAudioCompression AudioCompressionOut;
|
|
|
|
int iAudComprSizeOut;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
// resampling
|
|
|
|
CResample ResampleObj;
|
|
|
|
double dSamRateOffset;
|
|
|
|
CVector<double> vecdResInData;
|
|
|
|
CVector<double> vecdResOutData;
|
|
|
|
|
|
|
|
// connection parameters
|
2006-11-25 15:46:57 +01:00
|
|
|
CHostAddress InetAddr;
|
2006-10-30 22:14:44 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
// channel name
|
2008-01-22 22:15:04 +01:00
|
|
|
QString sName;
|
2006-11-04 10:57:59 +01:00
|
|
|
|
2006-11-26 22:25:56 +01:00
|
|
|
// mixer and effect settings
|
2006-12-18 15:39:33 +01:00
|
|
|
CVector<double> vecdGains;
|
|
|
|
|
|
|
|
// network jitter-buffer
|
2006-11-25 15:46:57 +01:00
|
|
|
CNetBuf SockBuf;
|
|
|
|
int iCurSockBufSize;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
// network output conversion buffer
|
|
|
|
CConvBuf ConvBuf;
|
2006-02-20 22:09:36 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
// network protocol
|
|
|
|
CProtocol Protocol;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
int iConTimeOut;
|
|
|
|
int iConTimeOutStartVal;
|
2006-03-11 21:35:38 +01:00
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
bool bIsEnabled;
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
int vecNetwInBufSizes[MAX_NET_BLOCK_SIZE_FACTOR];
|
2006-03-13 20:32:23 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
int iCurNetwInBlSiFact;
|
2006-12-18 15:39:33 +01:00
|
|
|
int iCurNetwOutBlSiFact;
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
QMutex Mutex;
|
2006-02-26 11:50:47 +01:00
|
|
|
|
2006-02-27 20:45:27 +01:00
|
|
|
public slots:
|
2006-11-25 15:46:57 +01:00
|
|
|
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
|
|
|
void OnJittBufSizeChange ( int iNewJitBufSize );
|
|
|
|
void OnNetwBlSiFactChange ( int iNewNetwBlSiFact );
|
2006-12-06 21:22:41 +01:00
|
|
|
void OnChangeChanGain ( int iChanID, double dNewGain );
|
2008-01-22 22:15:04 +01:00
|
|
|
void OnChangeChanName ( QString strName );
|
2006-02-27 20:45:27 +01:00
|
|
|
|
2006-02-26 11:50:47 +01:00
|
|
|
signals:
|
2006-11-25 15:46:57 +01:00
|
|
|
void MessReadyForSending ( CVector<uint8_t> vecMessage );
|
|
|
|
void NewConnection();
|
|
|
|
void ReqJittBufSize();
|
2006-12-08 19:19:16 +01:00
|
|
|
void ReqConnClientsList();
|
2006-11-26 22:25:56 +01:00
|
|
|
void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo );
|
2006-11-25 15:46:57 +01:00
|
|
|
void ProtocolStatus ( bool bOk );
|
2006-12-10 12:06:14 +01:00
|
|
|
void NameHasChanged();
|
2006-11-26 22:25:56 +01:00
|
|
|
};
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
// CChannelSet (for server) ----------------------------------------------------
|
|
|
|
class CChannelSet : public QObject
|
2006-03-04 12:11:26 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
Q_OBJECT
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
CChannelSet();
|
|
|
|
virtual ~CChannelSet() {}
|
|
|
|
|
|
|
|
bool PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
|
|
|
const int iNumBytesRead, const CHostAddress& HostAdr );
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
int GetFreeChan();
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
int CheckAddr ( const CHostAddress& Addr );
|
|
|
|
|
|
|
|
void GetBlockAllConC ( CVector<int>& vecChanID,
|
2006-11-25 15:46:57 +01:00
|
|
|
CVector<CVector<double> >& vecvecdData,
|
2006-12-06 21:22:41 +01:00
|
|
|
CVector<CVector<double> >& vecvecdGains );
|
2006-09-16 13:26:15 +02:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
2008-01-22 22:15:04 +01:00
|
|
|
CVector<QString>& vecsName,
|
2006-11-25 15:46:57 +01:00
|
|
|
CVector<int>& veciJitBufSize,
|
|
|
|
CVector<int>& veciNetwOutBlSiFact,
|
2006-12-18 15:39:33 +01:00
|
|
|
CVector<int>& veciNetwInBlSiFact );
|
|
|
|
|
|
|
|
// access functions for actual channels
|
|
|
|
bool IsConnected ( const int iChanNum )
|
2006-11-25 15:46:57 +01:00
|
|
|
{ return vecChannels[iChanNum].IsConnected(); }
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
CVector<unsigned char> PrepSendPacket ( const int iChanNum,
|
2006-12-18 15:39:33 +01:00
|
|
|
const CVector<short>& vecsNPacket )
|
2006-11-25 15:46:57 +01:00
|
|
|
{ return vecChannels[iChanNum].PrepSendPacket ( vecsNPacket ); }
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
CHostAddress GetAddress ( const int iChanNum )
|
|
|
|
{ return vecChannels[iChanNum].GetAddress(); }
|
|
|
|
|
2006-11-04 14:09:42 +01:00
|
|
|
protected:
|
2006-12-09 11:04:27 +01:00
|
|
|
CVector<CChannelShortInfo> CreateChannelList();
|
2006-12-09 11:40:18 +01:00
|
|
|
void CreateAndSendChanListForAllConChannels();
|
2006-12-09 11:04:27 +01:00
|
|
|
void CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID );
|
|
|
|
void CreateAndSendChanListForThisChan ( const int iCurChanID );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
/* do not use the vector class since CChannel does not have appropriate
|
|
|
|
copy constructor/operator */
|
|
|
|
CChannel vecChannels[MAX_NUM_CHANNELS];
|
2006-11-25 15:46:57 +01:00
|
|
|
QMutex Mutex;
|
2006-03-04 12:11:26 +01:00
|
|
|
|
|
|
|
public slots:
|
2006-12-09 19:37:40 +01:00
|
|
|
// CODE TAG: MAX_NUM_CHANNELS_TAG
|
2006-11-25 15:46:57 +01:00
|
|
|
// make sure we have MAX_NUM_CHANNELS connections!!!
|
|
|
|
// send message
|
|
|
|
void OnSendProtMessCh0(CVector<uint8_t> mess) {emit MessReadyForSending(0,mess);}
|
|
|
|
void OnSendProtMessCh1(CVector<uint8_t> mess) {emit MessReadyForSending(1,mess);}
|
|
|
|
void OnSendProtMessCh2(CVector<uint8_t> mess) {emit MessReadyForSending(2,mess);}
|
|
|
|
void OnSendProtMessCh3(CVector<uint8_t> mess) {emit MessReadyForSending(3,mess);}
|
|
|
|
void OnSendProtMessCh4(CVector<uint8_t> mess) {emit MessReadyForSending(4,mess);}
|
|
|
|
void OnSendProtMessCh5(CVector<uint8_t> mess) {emit MessReadyForSending(5,mess);}
|
|
|
|
void OnSendProtMessCh6(CVector<uint8_t> mess) {emit MessReadyForSending(6,mess);}
|
|
|
|
void OnSendProtMessCh7(CVector<uint8_t> mess) {emit MessReadyForSending(7,mess);}
|
|
|
|
void OnSendProtMessCh8(CVector<uint8_t> mess) {emit MessReadyForSending(8,mess);}
|
|
|
|
void OnSendProtMessCh9(CVector<uint8_t> mess) {emit MessReadyForSending(9,mess);}
|
2006-03-07 22:26:40 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
void OnNewConnectionCh0() {vecChannels[0].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh1() {vecChannels[1].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh2() {vecChannels[2].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh3() {vecChannels[3].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh4() {vecChannels[4].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh5() {vecChannels[5].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh6() {vecChannels[6].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh7() {vecChannels[7].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh8() {vecChannels[8].CreateReqJitBufMes();}
|
|
|
|
void OnNewConnectionCh9() {vecChannels[9].CreateReqJitBufMes();}
|
2006-03-04 12:11:26 +01:00
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
void OnReqConnClientsListCh0() { CreateAndSendChanListForThisChan ( 0 ); }
|
|
|
|
void OnReqConnClientsListCh1() { CreateAndSendChanListForThisChan ( 1 ); }
|
|
|
|
void OnReqConnClientsListCh2() { CreateAndSendChanListForThisChan ( 2 ); }
|
|
|
|
void OnReqConnClientsListCh3() { CreateAndSendChanListForThisChan ( 3 ); }
|
|
|
|
void OnReqConnClientsListCh4() { CreateAndSendChanListForThisChan ( 4 ); }
|
|
|
|
void OnReqConnClientsListCh5() { CreateAndSendChanListForThisChan ( 5 ); }
|
|
|
|
void OnReqConnClientsListCh6() { CreateAndSendChanListForThisChan ( 6 ); }
|
|
|
|
void OnReqConnClientsListCh7() { CreateAndSendChanListForThisChan ( 7 ); }
|
|
|
|
void OnReqConnClientsListCh8() { CreateAndSendChanListForThisChan ( 8 ); }
|
|
|
|
void OnReqConnClientsListCh9() { CreateAndSendChanListForThisChan ( 9 ); }
|
2006-12-08 19:19:16 +01:00
|
|
|
|
2006-12-10 12:06:14 +01:00
|
|
|
void OnNameHasChangedCh0() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh1() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh2() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh3() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh4() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh5() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh6() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh7() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh8() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
void OnNameHasChangedCh9() { CreateAndSendChanListForAllConChannels(); }
|
|
|
|
|
2006-03-04 12:11:26 +01:00
|
|
|
signals:
|
2006-11-25 15:46:57 +01:00
|
|
|
void MessReadyForSending ( int iChID, CVector<uint8_t> vecMessage );
|
2006-12-18 15:39:33 +01:00
|
|
|
};
|
2006-03-06 18:04:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Sample rate offset estimation -------------------------------------------- */
|
|
|
|
class CSampleOffsetEst
|
|
|
|
{
|
|
|
|
public:
|
2006-11-25 15:46:57 +01:00
|
|
|
CSampleOffsetEst() { Init(); }
|
|
|
|
virtual ~CSampleOffsetEst() {}
|
2006-03-06 18:04:07 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
void Init();
|
|
|
|
void AddTimeStampIdx ( const int iTimeStampIdx );
|
|
|
|
double GetSamRate() { return dSamRateEst; }
|
2006-03-06 18:04:07 +01:00
|
|
|
|
|
|
|
protected:
|
2006-11-25 15:46:57 +01:00
|
|
|
QTime RefTime;
|
|
|
|
int iAccTiStVal;
|
|
|
|
double dSamRateEst;
|
|
|
|
CVector<long int> veciTimeElapsed;
|
|
|
|
CVector<long int> veciTiStIdx;
|
|
|
|
int iInitCnt;
|
2006-03-06 18:04:07 +01:00
|
|
|
};
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#endif /* !defined ( CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */
|