2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2009-02-22 12:07:18 +01:00
|
|
|
* Copyright (c) 2004-2009
|
2006-12-18 15:39:33 +01: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
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#if !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ )
|
2006-12-18 15:39:33 +01:00
|
|
|
#define CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_
|
|
|
|
|
2009-02-23 00:13:59 +01:00
|
|
|
#include <qglobal.h>
|
2008-01-20 19:07:13 +01:00
|
|
|
#include <qhostaddress.h>
|
|
|
|
#include <qhostinfo.h>
|
|
|
|
#include <qstring.h>
|
|
|
|
#include <qdatetime.h>
|
2008-07-15 22:33:41 +02:00
|
|
|
#include <qmessagebox.h>
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "socket.h"
|
|
|
|
#include "resample.h"
|
|
|
|
#include "channel.h"
|
2008-08-10 10:14:30 +02:00
|
|
|
#include "audiocompr.h"
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "util.h"
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include "../windows/sound.h"
|
|
|
|
#else
|
2006-01-28 12:29:22 +01:00
|
|
|
# include "../linux/sound.h"
|
2006-12-18 15:39:33 +01:00
|
|
|
# include <sched.h>
|
2007-02-24 10:49:52 +01:00
|
|
|
# include <socket.h>
|
|
|
|
# include <netdb.h>
|
2006-12-18 15:39:33 +01:00
|
|
|
#endif
|
|
|
|
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
/* Definitions ****************************************************************/
|
2006-11-05 12:43:25 +01:00
|
|
|
// audio in fader range
|
2009-02-17 12:58:27 +01:00
|
|
|
#define AUD_FADER_IN_MIN 0
|
2006-11-25 15:46:57 +01:00
|
|
|
#define AUD_FADER_IN_MAX 100
|
2009-02-17 12:58:27 +01:00
|
|
|
#define AUD_FADER_IN_MIDDLE ( AUD_FADER_IN_MAX / 2 )
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2006-11-05 12:43:25 +01:00
|
|
|
// audio reverberation range
|
2006-11-25 15:46:57 +01:00
|
|
|
#define AUD_REVERB_MAX 100
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
2009-02-23 00:13:59 +01:00
|
|
|
class CClient : 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:
|
2008-08-13 21:08:45 +02:00
|
|
|
CClient ( const quint16 iPortNumber );
|
2006-12-18 15:39:33 +01:00
|
|
|
virtual ~CClient() {}
|
|
|
|
|
2009-02-21 18:37:15 +01:00
|
|
|
void Start();
|
|
|
|
void Stop();
|
2009-02-23 00:13:59 +01:00
|
|
|
bool IsRunning() { return Sound.IsRunning(); }
|
2006-12-18 15:39:33 +01:00
|
|
|
bool SetServerAddr ( QString strNAddr );
|
2009-02-14 01:46:58 +01:00
|
|
|
double MicLevelL() { return SignalLevelMeter.MicLevelLeft(); }
|
|
|
|
double MicLevelR() { return SignalLevelMeter.MicLevelRight(); }
|
2006-12-09 16:00:24 +01:00
|
|
|
bool IsConnected() { return Channel.IsConnected(); }
|
2006-11-25 15:46:57 +01:00
|
|
|
|
2009-03-07 11:52:06 +01:00
|
|
|
double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); }
|
2006-11-25 15:46:57 +01:00
|
|
|
|
2008-07-24 18:20:25 +02:00
|
|
|
bool GetOpenChatOnNewMessage() { return bOpenChatOnNewMessage; }
|
|
|
|
void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; }
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
int GetAudioInFader() { return iAudioInFader; }
|
2006-12-18 15:39:33 +01:00
|
|
|
void SetAudioInFader ( const int iNV ) { iAudioInFader = iNV; }
|
2006-11-25 15:46:57 +01:00
|
|
|
|
|
|
|
int GetReverbLevel() { return iReverbLevel; }
|
|
|
|
void SetReverbLevel ( const int iNL ) { iReverbLevel = iNL; }
|
|
|
|
|
|
|
|
bool IsReverbOnLeftChan() { return bReverbOnLeftChan; }
|
|
|
|
void SetReverbOnLeftChan ( const bool bIL )
|
|
|
|
{
|
|
|
|
bReverbOnLeftChan = bIL;
|
|
|
|
AudioReverb.Clear();
|
|
|
|
}
|
|
|
|
|
2009-02-12 15:48:35 +01:00
|
|
|
void SetDoAutoSockBufSize ( const bool bValue ) { bDoAutoSockBufSize = bValue; }
|
2009-02-22 12:07:18 +01:00
|
|
|
bool GetDoAutoSockBufSize() { return bDoAutoSockBufSize; }
|
2006-11-25 15:46:57 +01:00
|
|
|
void SetSockBufSize ( const int iNumBlocks )
|
|
|
|
{
|
2009-05-13 09:14:08 +02:00
|
|
|
// only change parameter if new parameter is different from current one
|
2009-02-11 19:37:26 +01:00
|
|
|
if ( Channel.GetSockBufSize() != iNumBlocks )
|
2009-02-12 15:48:35 +01:00
|
|
|
{
|
2009-05-13 09:14:08 +02:00
|
|
|
// set the new socket size
|
|
|
|
if ( !Channel.SetSockBufSize ( iNumBlocks ) )
|
2009-02-11 19:45:22 +01:00
|
|
|
{
|
2009-05-13 09:14:08 +02:00
|
|
|
// if setting of socket buffer size was successful,
|
2009-02-11 19:45:22 +01:00
|
|
|
// tell the server that size has changed
|
2009-02-12 15:48:35 +01:00
|
|
|
Channel.CreateJitBufMes ( iNumBlocks );
|
2009-02-11 19:45:22 +01:00
|
|
|
}
|
2009-02-11 19:37:26 +01:00
|
|
|
}
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2007-09-08 12:45:14 +02:00
|
|
|
int GetSockBufSize() { return Channel.GetSockBufSize(); }
|
2006-11-25 15:46:57 +01:00
|
|
|
|
2009-03-03 19:04:51 +01:00
|
|
|
int GetNetwBufSizeOut() { return Channel.GetNetwBufSizeOut(); }
|
|
|
|
int GetAudioBlockSizeIn() { return Channel.GetAudioBlockSizeIn(); }
|
2009-03-03 23:46:36 +01:00
|
|
|
int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); }
|
2009-03-03 19:04:51 +01:00
|
|
|
|
2009-03-07 21:45:00 +01:00
|
|
|
int GetSndCrdNumDev() { return Sound.GetNumDev(); }
|
|
|
|
std::string GetSndCrdDeviceName ( const int iDiD )
|
|
|
|
{ return Sound.GetDeviceName ( iDiD ); }
|
|
|
|
|
2009-03-08 18:14:37 +01:00
|
|
|
QString SetSndCrdDev ( const int iNewDev );
|
2009-03-07 21:45:00 +01:00
|
|
|
int GetSndCrdDev() { return Sound.GetDev(); }
|
|
|
|
void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); }
|
|
|
|
|
2009-03-04 08:57:44 +01:00
|
|
|
void SetSndCrdPreferredMonoBlSizeIndex ( const int iNewIdx );
|
|
|
|
int GetSndCrdPreferredMonoBlSizeIndex()
|
|
|
|
{ return iSndCrdPreferredMonoBlSizeIndex; }
|
2009-03-05 21:45:36 +01:00
|
|
|
int GetSndCrdActualMonoBlSize() { return iSndCrdMonoBlockSizeSam; }
|
2009-03-04 08:57:44 +01:00
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
void SetAudioCompressionOut ( const EAudComprType eNewAudComprTypeOut )
|
2009-03-01 21:53:12 +01:00
|
|
|
{
|
|
|
|
Channel.SetAudioCompressionOut ( eNewAudComprTypeOut );
|
|
|
|
|
|
|
|
// tell the server that audio coding has changed (it
|
|
|
|
// is important to call this function AFTER we have applied
|
|
|
|
// the new setting to the channel!)
|
|
|
|
Channel.CreateNetTranspPropsMessFromCurrentSettings();
|
|
|
|
}
|
2009-03-01 12:17:35 +01:00
|
|
|
EAudComprType GetAudioCompressionOut() { return Channel.GetAudioCompressionOut(); }
|
2008-08-10 10:14:30 +02:00
|
|
|
|
2006-12-09 16:00:24 +01:00
|
|
|
void SetRemoteChanGain ( const int iId, const double dGain )
|
|
|
|
{ Channel.SetRemoteChanGain ( iId, dGain ); }
|
|
|
|
|
2006-12-10 12:06:14 +01:00
|
|
|
void SetRemoteName() { Channel.SetRemoteName ( strName ); }
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2008-07-24 18:20:25 +02:00
|
|
|
void SendTextMess ( const QString& strChatText )
|
|
|
|
{ Channel.CreateChatTextMes ( strChatText ); }
|
|
|
|
|
2008-08-02 09:28:21 +02:00
|
|
|
void SendPingMess()
|
2008-08-11 19:21:09 +02:00
|
|
|
{ Channel.CreatePingMes ( PreciseTime.elapsed() ); };
|
2008-08-02 09:28:21 +02:00
|
|
|
|
2009-03-07 21:45:00 +01:00
|
|
|
CChannel* GetChannel() { return &Channel; }
|
2006-01-28 12:29:22 +01:00
|
|
|
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
// settings
|
2009-05-04 13:27:05 +02:00
|
|
|
CVector<QString> vstrIPAddress;
|
2009-02-14 01:46:58 +01:00
|
|
|
QString strName;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
protected:
|
2009-02-23 00:13:59 +01:00
|
|
|
// callback function must be static, otherwise it does not work
|
|
|
|
static void AudioCallback ( CVector<short>& psData, void* arg );
|
|
|
|
|
2009-03-05 21:07:41 +01:00
|
|
|
void Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate );
|
2009-02-21 18:37:15 +01:00
|
|
|
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
|
2009-02-14 01:46:58 +01:00
|
|
|
void UpdateSocketBufferSize();
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
// only one channel is needed for client application
|
2009-02-14 01:46:58 +01:00
|
|
|
CChannel Channel;
|
|
|
|
bool bDoAutoSockBufSize;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2009-02-14 01:46:58 +01:00
|
|
|
CSocket Socket;
|
|
|
|
CSound Sound;
|
|
|
|
CStereoSignalLevelMeter SignalLevelMeter;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2009-02-14 01:46:58 +01:00
|
|
|
CVector<double> vecdNetwData;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2009-02-14 01:46:58 +01:00
|
|
|
int iAudioInFader;
|
|
|
|
bool bReverbOnLeftChan;
|
|
|
|
int iReverbLevel;
|
|
|
|
CAudioReverb AudioReverb;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2009-03-04 08:57:44 +01:00
|
|
|
int iSndCrdPreferredMonoBlSizeIndex;
|
|
|
|
|
2009-02-14 01:46:58 +01:00
|
|
|
int iSndCrdMonoBlockSizeSam;
|
|
|
|
int iSndCrdStereoBlockSizeSam;
|
|
|
|
int iMonoBlockSizeSam;
|
|
|
|
int iStereoBlockSizeSam;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2009-02-14 01:46:58 +01:00
|
|
|
bool bOpenChatOnNewMessage;
|
2008-07-24 18:20:25 +02:00
|
|
|
|
2009-02-17 12:58:27 +01:00
|
|
|
CVector<short> vecsAudioSndCrdStereo;
|
|
|
|
CVector<double> vecdAudioSndCrdMono;
|
|
|
|
CVector<double> vecdAudioSndCrdStereo;
|
|
|
|
CVector<double> vecdAudioStereo;
|
2009-02-14 01:46:58 +01:00
|
|
|
CVector<short> vecsNetwork;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
// resample objects
|
2009-02-14 01:46:58 +01:00
|
|
|
CStereoAudioResample ResampleObjDown;
|
|
|
|
CStereoAudioResample ResampleObjUp;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2009-03-07 11:52:06 +01:00
|
|
|
// for ping measurement
|
2009-02-14 01:46:58 +01:00
|
|
|
CPreciseTime PreciseTime;
|
2008-08-11 19:21:09 +02:00
|
|
|
|
2009-03-07 11:52:06 +01:00
|
|
|
CCycleTimeVariance CycleTimeVariance;
|
2006-02-26 11:50:47 +01:00
|
|
|
|
|
|
|
public slots:
|
2006-11-25 15:46:57 +01:00
|
|
|
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
|
|
|
void OnReqJittBufSize();
|
2006-12-10 12:06:14 +01:00
|
|
|
void OnNewConnection();
|
2008-08-10 23:56:03 +02:00
|
|
|
void OnReceivePingMessage ( int iMs );
|
2009-03-12 14:07:43 +01:00
|
|
|
void OnSndCrdReinitRequest();
|
2006-11-26 22:25:56 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo );
|
2008-07-24 18:20:25 +02:00
|
|
|
void ChatTextReceived ( QString strChatText );
|
2008-08-02 09:28:21 +02:00
|
|
|
void PingTimeReceived ( int iPingTime );
|
2006-12-18 15:39:33 +01:00
|
|
|
};
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#endif /* !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
|