/******************************************************************************\ * 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 #include #include "global.h" #include "buffer.h" #include "audiocompr.h" #include "util.h" #include "resample.h" #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 correction is implemented) */ #define CON_TIME_OUT_SEC_MAX 5 // seconds /* maximum number of internet connections (channels) */ // if you want to change this paramter, change the connections in this class, too! #define MAX_NUM_CHANNELS 10 /* max number channels for server */ /* no valid channel number */ #define INVALID_CHANNEL_ID (MAX_NUM_CHANNELS + 1) enum EPutDataStat { PS_GEN_ERROR, PS_AUDIO_OK, PS_AUDIO_ERR, PS_PROT_OK, PS_PROT_ERR }; /* Classes ********************************************************************/ /* CChannel ----------------------------------------------------------------- */ class CChannel : public QObject { Q_OBJECT public: CChannel(); virtual ~CChannel() {} EPutDataStat PutData ( const CVector& vecbyData, int iNumBytes ); bool GetData ( CVector& vecdData ); CVector PrepSendPacket ( const CVector& vecsNPacket ); bool IsConnected() const { return iConTimeOut > 0; } void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; } bool GetAddress ( CHostAddress& RetAddr ); CHostAddress GetAddress () { return InetAddr; } void SetSockBufSize ( const int iNumBlocks ); int GetSockBufSize(); // network protocol interface void CreateJitBufMes ( const int iJitBufSize ) { if ( IsConnected() ) { Protocol.CreateJitBufMes ( iJitBufSize ); } } void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } protected: void SetNetwInBlSiFact ( const int iNewBlockSizeFactor ); void SetNetwOutBlSiFact ( const int iNewBlockSizeFactor ); /* audio compression */ CAudioCompression AudioCompressionIn; int iAudComprSizeIn; CAudioCompression AudioCompressionOut; int iAudComprSizeOut; /* resampling */ CResample ResampleObj; double dSamRateOffset; CVector vecdResInData; CVector vecdResOutData; /* connection parameters */ CHostAddress InetAddr; /* network jitter-buffer */ CNetBuf SockBuf; /* network output conversion buffer */ CConvBuf ConvBuf; // network protocol CProtocol Protocol; /* time stamp index counter */ Q_UINT8 byTimeStampIdxCnt; int iTimeStampActCnt; int iConTimeOut; int iConTimeOutStartVal; int iCurNetwInBlSiFact; QMutex Mutex; public slots: void OnSendProtMessage ( CVector vecMessage ); void OnJittBufSizeChange ( int iNewJitBufSize ); signals: void MessReadyForSending ( CVector vecMessage ); void NewConnection(); void ReqJittBufSize(); }; /* CChannelSet (for server) ------------------------------------------------- */ class CChannelSet : public QObject { Q_OBJECT public: CChannelSet(); virtual ~CChannelSet() {} bool PutData ( const CVector& vecbyRecBuf, const int iNumBytesRead, const CHostAddress& HostAdr ); int GetFreeChan(); int CheckAddr ( const CHostAddress& Addr ); void GetBlockAllConC ( CVector& vecChanID, CVector >& vecvecdData ); void GetConCliParam( CVector& vecHostAddresses, CVector& veciJitBufSize ); /* access functions for actual channels */ bool IsConnected ( const int iChanNum ) { return vecChannels[iChanNum].IsConnected(); } CVector PrepSendPacket ( const int iChanNum, const CVector& vecsNPacket ) { return vecChannels[iChanNum].PrepSendPacket ( vecsNPacket ); } CHostAddress GetAddress ( const int iChanNum ) { return vecChannels[iChanNum].GetAddress(); } protected: /* do not use the vector class since CChannel does not have appropriate copy constructor/operator */ CChannel vecChannels[MAX_NUM_CHANNELS]; QMutex Mutex; public slots: // make sure we have MAX_NUM_CHANNELS connections!!! // send message void OnSendProtMessCh0(CVector mess) {emit MessReadyForSending(0,mess);} void OnSendProtMessCh1(CVector mess) {emit MessReadyForSending(1,mess);} void OnSendProtMessCh2(CVector mess) {emit MessReadyForSending(2,mess);} void OnSendProtMessCh3(CVector mess) {emit MessReadyForSending(3,mess);} void OnSendProtMessCh4(CVector mess) {emit MessReadyForSending(4,mess);} void OnSendProtMessCh5(CVector mess) {emit MessReadyForSending(5,mess);} void OnSendProtMessCh6(CVector mess) {emit MessReadyForSending(6,mess);} void OnSendProtMessCh7(CVector mess) {emit MessReadyForSending(7,mess);} void OnSendProtMessCh8(CVector mess) {emit MessReadyForSending(8,mess);} void OnSendProtMessCh9(CVector mess) {emit MessReadyForSending(9,mess);} 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();} signals: void MessReadyForSending ( int iChID, CVector vecMessage ); }; /* Sample rate offset estimation -------------------------------------------- */ 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 veciTimeElapsed; CVector veciTiStIdx; int iInitCnt; }; #endif /* !defined(CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_) */