/******************************************************************************\ * Copyright (c) 2004-2009 * * 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 ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) #define CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ #include #include #include #include #include #include #include "celt.h" #include "global.h" #include "socket.h" #include "channel.h" #include "util.h" #ifdef _WIN32 # include "../windows/sound.h" #else # include "../linux/sound.h" # include # include # include #endif /* Definitions ****************************************************************/ // audio in fader range #define AUD_FADER_IN_MIN 0 #define AUD_FADER_IN_MAX 100 #define AUD_FADER_IN_MIDDLE ( AUD_FADER_IN_MAX / 2 ) // audio reverberation range #define AUD_REVERB_MAX 100 // CELT number of coded bytes per audio packet // 22: low/normal quality 150 kbsp (128) / 108 kbps (256) // 44: high quality 216 kbps (128) / 174 kbps (256) #define CELT_NUM_BYTES_NORMAL_QUALITY 22 #define CELT_NUM_BYTES_HIGH_QUALITY 44 /* Classes ********************************************************************/ class CClient : public QObject { Q_OBJECT public: CClient ( const quint16 iPortNumber ); virtual ~CClient() {} void Start(); void Stop(); bool IsRunning() { return Sound.IsRunning(); } bool SetServerAddr ( QString strNAddr ); double MicLevelL() { return SignalLevelMeter.MicLevelLeft(); } double MicLevelR() { return SignalLevelMeter.MicLevelRight(); } bool IsConnected() { return Channel.IsConnected(); } double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); } bool GetOpenChatOnNewMessage() { return bOpenChatOnNewMessage; } void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; } bool GetCELTHighQuality() { return bCeltDoHighQuality; } void SetCELTHighQuality ( const bool bNCeltHighQualityFlag ); int GetAudioInFader() { return iAudioInFader; } void SetAudioInFader ( const int iNV ) { iAudioInFader = iNV; } int GetReverbLevel() { return iReverbLevel; } void SetReverbLevel ( const int iNL ) { iReverbLevel = iNL; } bool IsReverbOnLeftChan() { return bReverbOnLeftChan; } void SetReverbOnLeftChan ( const bool bIL ) { bReverbOnLeftChan = bIL; AudioReverb.Clear(); } void SetDoAutoSockBufSize ( const bool bValue ) { bDoAutoSockBufSize = bValue; } bool GetDoAutoSockBufSize() { return bDoAutoSockBufSize; } void SetSockBufNumFrames ( const int iNumBlocks ) { // only change parameter if new parameter is different from current one if ( Channel.GetSockBufNumFrames() != iNumBlocks ) { // set the new socket size (number of frames) if ( !Channel.SetSockBufNumFrames ( iNumBlocks ) ) { // if setting of socket buffer size was successful, // tell the server that size has changed Channel.CreateJitBufMes ( iNumBlocks ); } } } int GetSockBufNumFrames() { return Channel.GetSockBufNumFrames(); } int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); } int GetSndCrdNumDev() { return Sound.GetNumDev(); } std::string GetSndCrdDeviceName ( const int iDiD ) { return Sound.GetDeviceName ( iDiD ); } QString SetSndCrdDev ( const int iNewDev ); int GetSndCrdDev() { return Sound.GetDev(); } void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); } void SetSndCrdPrefFrameSizeFactor ( const int iNewFactor ); int GetSndCrdPrefFrameSizeFactor() { return iSndCrdPrefFrameSizeFactor; } int GetSndCrdActualMonoBlSize() { return iMonoBlockSizeSam; } void SetRemoteChanGain ( const int iId, const double dGain ) { Channel.SetRemoteChanGain ( iId, dGain ); } void SetRemoteName() { Channel.SetRemoteName ( strName ); } void SendTextMess ( const QString& strChatText ) { Channel.CreateChatTextMes ( strChatText ); } void SendPingMess() { Channel.CreatePingMes ( PreciseTime.elapsed() ); }; CChannel* GetChannel() { return &Channel; } // settings CVector vstrIPAddress; QString strName; protected: // callback function must be static, otherwise it does not work static void AudioCallback ( CVector& psData, void* arg ); void Init(); void ProcessAudioData ( CVector& vecsStereoSndCrd ); void UpdateSocketBufferSize(); // only one channel is needed for client application CChannel Channel; bool bDoAutoSockBufSize; // audio encoder/decoder CELTMode* CeltMode; CELTEncoder* CeltEncoder; CELTDecoder* CeltDecoder; int iCeltNumCodedBytes; bool bCeltDoHighQuality; CVector vecCeltData; CSocket Socket; CSound Sound; CStereoSignalLevelMeter SignalLevelMeter; CVector vecbyNetwData; int iAudioInFader; bool bReverbOnLeftChan; int iReverbLevel; CAudioReverb AudioReverb; int iSndCrdPrefFrameSizeFactor; int iSndCrdFrameSizeFactor; int iMonoBlockSizeSam; int iStereoBlockSizeSam; bool bOpenChatOnNewMessage; CVector vecsAudioSndCrdMono; CVector vecsAudioSndCrdStereo; CVector vecdAudioStereo; CVector vecsNetwork; // for ping measurement CPreciseTime PreciseTime; CCycleTimeVariance CycleTimeVariance; public slots: void OnSendProtMessage ( CVector vecMessage ); void OnReqJittBufSize(); void OnNewConnection(); void OnReceivePingMessage ( int iMs ); void OnSndCrdReinitRequest(); signals: void ConClientListMesReceived ( CVector vecChanInfo ); void ChatTextReceived ( QString strChatText ); void PingTimeReceived ( int iPingTime ); }; #endif /* !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */