2006-01-28 12:29:22 +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
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#if !defined(CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_)
|
|
|
|
#define CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_
|
|
|
|
|
|
|
|
#include <qthread.h>
|
2006-02-12 15:26:46 +01:00
|
|
|
#include <qdatetime.h>
|
2006-01-28 12:29:22 +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"
|
|
|
|
#include "protocol.h"
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* 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-02-18 14:36:55 +01:00
|
|
|
correction is implemented) */
|
|
|
|
#define CON_TIME_OUT_SEC_MAX 5 // seconds
|
|
|
|
#define CON_TIME_OUT_CNT_MAX ( ( CON_TIME_OUT_SEC_MAX * 1000 ) / BLOCK_DURATION_MS )
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
/* maximum number of internet connections (channels) */
|
2006-02-18 14:36:55 +01:00
|
|
|
#define MAX_NUM_CHANNELS 10 /* max number channels for server */
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
/* no valid channel number */
|
2006-02-18 14:36:55 +01:00
|
|
|
#define INVALID_CHANNEL_ID (MAX_NUM_CHANNELS + 1)
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CSampleOffsetEst
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSampleOffsetEst() {Init();}
|
|
|
|
virtual ~CSampleOffsetEst() {}
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void AddTimeStampIdx(const int iTimeStampIdx);
|
|
|
|
double GetSamRate() {return dSamRateEst;}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QTime RefTime;
|
|
|
|
int iAccTiStVal;
|
|
|
|
double dSamRateEst;
|
|
|
|
CVector<long int> veciTimeElapsed;
|
|
|
|
CVector<long int> veciTiStIdx;
|
|
|
|
int iInitCnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* CChannel ----------------------------------------------------------------- */
|
2006-02-26 11:50:47 +01:00
|
|
|
class CChannel : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2006-01-28 12:29:22 +01:00
|
|
|
public:
|
2006-02-26 11:50:47 +01:00
|
|
|
CChannel ();
|
|
|
|
virtual ~CChannel () {}
|
|
|
|
|
|
|
|
bool PutData ( const CVector<unsigned char>& vecbyData,
|
|
|
|
int iNumBytes );
|
|
|
|
bool GetData ( CVector<double>& vecdData );
|
|
|
|
|
|
|
|
CVector<unsigned char> PrepSendPacket ( const CVector<short>& vecsNPacket );
|
|
|
|
|
|
|
|
bool IsConnected () const { return iConTimeOut > 0; }
|
|
|
|
|
|
|
|
int GetComprAudSize () { return iAudComprSize; }
|
|
|
|
|
|
|
|
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
|
|
|
|
bool GetAddress ( CHostAddress& RetAddr );
|
|
|
|
CHostAddress GetAddress () { return InetAddr; }
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2006-02-26 11:50:47 +01:00
|
|
|
void SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks );
|
|
|
|
int GetSockBufSize () { return SockBuf.GetSize(); }
|
|
|
|
|
|
|
|
// network protocol interface
|
|
|
|
void CreateJitBufMes ( const int iJitBufSize )
|
|
|
|
{
|
|
|
|
Protocol.CreateJitBufMes ( iJitBufSize );
|
|
|
|
}
|
|
|
|
|
2006-01-28 12:29:22 +01:00
|
|
|
protected:
|
|
|
|
/* audio compression */
|
|
|
|
CAudioCompression AudioCompression;
|
|
|
|
int iAudComprSize;
|
|
|
|
|
|
|
|
/* resampling */
|
|
|
|
CResample ResampleObj;
|
|
|
|
double dSamRateOffset;
|
|
|
|
CVector<double> vecdResInData;
|
|
|
|
CVector<double> vecdResOutData;
|
|
|
|
|
|
|
|
/* connection parameters */
|
|
|
|
CHostAddress InetAddr;
|
|
|
|
|
|
|
|
/* network jitter-buffer */
|
|
|
|
CNetBuf SockBuf;
|
|
|
|
|
|
|
|
/* network output conversion buffer */
|
2006-02-20 22:09:36 +01:00
|
|
|
CConvBuf ConvBuf;
|
|
|
|
|
2006-02-26 11:50:47 +01:00
|
|
|
// network protocol
|
|
|
|
CProtocol Protocol;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
/* time stamp index counter */
|
|
|
|
Q_UINT8 byTimeStampIdxCnt;
|
|
|
|
int iTimeStampActCnt;
|
|
|
|
|
|
|
|
int iConTimeOut;
|
|
|
|
|
2006-02-26 11:50:47 +01:00
|
|
|
QMutex Mutex;
|
|
|
|
|
2006-02-27 20:45:27 +01:00
|
|
|
public slots:
|
|
|
|
void OnJittBufSizeChange ( int iNewJitBufSize );
|
|
|
|
|
2006-02-26 11:50:47 +01:00
|
|
|
signals:
|
2006-03-01 20:46:44 +01:00
|
|
|
void MessReadyForSending ( CVector<uint8_t> vecMessage );
|
2006-01-28 12:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* CChannelSet (for server) ------------------------------------------------- */
|
|
|
|
class CChannelSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CChannelSet() {}
|
|
|
|
virtual ~CChannelSet() {}
|
|
|
|
|
|
|
|
bool PutData(const CVector<unsigned char>& vecbyRecBuf,
|
|
|
|
const int iNumBytesRead, const CHostAddress& HostAdr);
|
|
|
|
|
|
|
|
int GetFreeChan();
|
|
|
|
int CheckAddr(const CHostAddress& Addr);
|
|
|
|
|
|
|
|
void GetBlockAllConC(CVector<int>& vecChanID,
|
|
|
|
CVector<CVector<double> >& vecvecdData);
|
|
|
|
void GetConCliParam(CVector<CHostAddress>& vecHostAddresses,
|
2006-02-20 22:09:36 +01:00
|
|
|
CVector<int>& veciJitBufSize);
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
/* access functions for actual channels */
|
|
|
|
bool IsConnected(const int iChanNum)
|
|
|
|
{return vecChannels[iChanNum].IsConnected();}
|
|
|
|
CVector<unsigned char> PrepSendPacket(const int iChanNum,
|
|
|
|
const CVector<short>& vecsNPacket)
|
|
|
|
{return vecChannels[iChanNum].PrepSendPacket(vecsNPacket);}
|
|
|
|
CHostAddress GetAddress(const int iChanNum)
|
|
|
|
{return vecChannels[iChanNum].GetAddress();}
|
|
|
|
|
|
|
|
void SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks);
|
|
|
|
int GetSockBufSize() {return vecChannels[0].GetSockBufSize();}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/* do not use the vector class since CChannel does not have appropriate
|
|
|
|
copy constructor/operator */
|
|
|
|
CChannel vecChannels[MAX_NUM_CHANNELS];
|
|
|
|
QMutex Mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* !defined(CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_) */
|