first tests with protocol

This commit is contained in:
Volker Fischer 2006-02-26 10:50:47 +00:00
parent 070158cb33
commit 651f60b625
14 changed files with 256 additions and 129 deletions

View file

@ -39,6 +39,9 @@ llcon_SOURCES = ../src/buffer.cpp \
# these need to be generated before the rest can be compiled
BUILT_SOURCES=moc/moc_server.cpp \
moc/moc_client.cpp \
moc/moc_protocol.cpp \
moc/moc_channel.cpp \
moc/moc_socket.cpp \
moc/moc_multicolorled.cpp \
moc/moc_util.cpp \
@ -57,6 +60,9 @@ dist-hook:
moc/moc_server.cpp: ../src/server.h
$(MOC) ../src/server.h -o moc/moc_server.cpp
moc/moc_client.cpp: ../src/client.h
$(MOC) ../src/client.h -o moc/moc_client.cpp
moc/moc_socket.cpp: ../src/socket.h
$(MOC) ../src/socket.h -o moc/moc_socket.cpp
@ -66,6 +72,11 @@ moc/moc_multicolorled.cpp: ../src/multicolorled.h
moc/moc_util.cpp: ../src/util.h
$(MOC) ../src/util.h -o moc/moc_util.cpp
moc/moc_protocol.cpp: ../src/protocol.h
$(MOC) ../src/protocol.h -o moc/moc_protocol.cpp
moc/moc_channel.cpp: ../src/channel.h
$(MOC) ../src/channel.h -o moc/moc_channel.cpp
moc/moc_aboutdlgbase.cpp: moc/aboutdlgbase.h

View file

@ -198,7 +198,7 @@ for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
/******************************************************************************\
* CChannel *
\******************************************************************************/
CChannel::CChannel()
CChannel::CChannel ()
{
/* init time stamp activation counter */
iTimeStampActCnt = NUM_BL_TIME_STAMPS;
@ -221,6 +221,12 @@ CChannel::CChannel()
/* init sample rate offset estimation object */
SampleOffsetEst.Init();
/* connections ---------------------------------------------------------- */
// just route message through this class
QObject::connect(&Protocol, SIGNAL(MessReadyForSending()),
SIGNAL(MessReadyForSending()));
}
void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )
@ -292,7 +298,7 @@ for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
// TODO add protocol parsing here
ClientProtocol.ParseMessage ( vecbyData, iNumBytes );
Protocol.ParseMessage ( vecbyData, iNumBytes );
@ -304,27 +310,29 @@ ClientProtocol.ParseMessage ( vecbyData, iNumBytes );
return bRet;
}
bool CChannel::GetData(CVector<double>& vecdData)
bool CChannel::GetData ( CVector<double>& vecdData )
{
Mutex.lock(); /* get mutex lock */
Mutex.lock (); /* get mutex lock */
const bool bGetOK = SockBuf.Get(vecdData);
const bool bGetOK = SockBuf.Get ( vecdData );
if (!bGetOK)
if ( !bGetOK )
{
/* decrease time-out counter */
if (iConTimeOut > 0)
if ( iConTimeOut > 0 )
{
iConTimeOut--;
/* if time out is reached, re-init resample offset estimation
module */
if (iConTimeOut == 0)
SampleOffsetEst.Init();
if ( iConTimeOut == 0 )
{
SampleOffsetEst.Init ();
}
}
}
Mutex.unlock(); /* get mutex unlock */
Mutex.unlock (); /* get mutex unlock */
return bGetOK;
}

View file

@ -74,27 +74,39 @@ protected:
/* CChannel ----------------------------------------------------------------- */
class CChannel
class CChannel : public QObject
{
Q_OBJECT
public:
CChannel();
virtual ~CChannel() {}
CChannel ();
virtual ~CChannel () {}
bool PutData(const CVector<unsigned char>& vecbyData,
int iNumBytes);
bool GetData(CVector<double>& vecdData);
bool PutData ( const CVector<unsigned char>& vecbyData,
int iNumBytes );
bool GetData ( CVector<double>& vecdData );
CVector<unsigned char> PrepSendPacket(const CVector<short>& vecsNPacket);
CVector<unsigned char> PrepSendPacket ( const CVector<short>& vecsNPacket );
CVector<unsigned char> GetSendMessage () { return Protocol.GetSendMessage (); }
bool IsConnected () const { return iConTimeOut > 0; }
int GetTimeStampIdx ();
int GetComprAudSize () { return iAudComprSize; }
double GetResampleOffset () { return SampleOffsetEst.GetSamRate (); }
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
bool GetAddress ( CHostAddress& RetAddr );
CHostAddress GetAddress () { return InetAddr; }
bool GetAddress(CHostAddress& RetAddr);
CHostAddress GetAddress() {return InetAddr;}
int GetTimeStampIdx();
void SetAddress(const CHostAddress NAddr) {InetAddr = NAddr;}
bool IsConnected() const {return iConTimeOut > 0;}
int GetComprAudSize() {return iAudComprSize;}
double GetResampleOffset() {return SampleOffsetEst.GetSamRate();}
void SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks );
int GetSockBufSize() {return SockBuf.GetSize();}
int GetSockBufSize () { return SockBuf.GetSize(); }
// network protocol interface
void CreateJitBufMes ( const int iJitBufSize )
{
Protocol.CreateJitBufMes ( iJitBufSize );
}
protected:
/* audio compression */
@ -118,10 +130,8 @@ protected:
/* network output conversion buffer */
CConvBuf ConvBuf;
// TEST TODO: better implementation, now this object is created in server AND client which is not good
CClientProtocol ClientProtocol;
// network protocol
CProtocol Protocol;
/* time stamp index counter */
Q_UINT8 byTimeStampIdxCnt;
@ -130,6 +140,9 @@ CClientProtocol ClientProtocol;
int iConTimeOut;
QMutex Mutex;
signals:
void MessReadyForSending ();
};

View file

@ -26,6 +26,29 @@
/* Implementation *************************************************************/
CClient::CClient () : bRun ( false ), Socket ( &Channel ),
iAudioInFader ( AUD_FADER_IN_MAX / 2 ),
iReverbLevel ( AUD_REVERB_MAX / 6 ),
bReverbOnLeftChan ( false )
{
QObject::connect(&Channel, SIGNAL(MessReadyForSending()),
this, SLOT(OnSendProtMessage()));
}
void CClient::OnSendProtMessage ()
{
// the protocol queries me to call the function to send the message
// send it through the network
Socket.SendPacket ( Channel.GetSendMessage (),
Channel.GetAddress(), Channel.GetTimeStampIdx() );
}
bool CClient::SetServerAddr(QString strNAddr)
{
QHostAddress InetAddr;
@ -113,9 +136,13 @@ void CClient::run()
{
/* get audio from sound card (blocking function) */
if (Sound.Read(vecsAudioSndCrd))
{
PostWinMessage(MS_SOUND_IN, MUL_COL_LED_RED);
}
else
{
PostWinMessage(MS_SOUND_IN, MUL_COL_LED_GREEN);
}
/* copy data from one stereo buffer in two separate buffers */
iInCnt = 0;
@ -182,9 +209,13 @@ void CClient::run()
/* receive a new block */
if (Channel.GetData(vecdNetwData))
{
PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_GREEN);
}
else
{
PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_RED);
}
#ifdef _DEBUG_
#if 0
@ -253,14 +284,18 @@ fflush(pFileDelay);
{
/* write mono input signal in both sound-card channels */
for (i = 0; i < iBlockSizeSam; i++)
{
vecdAudioL[i] = vecdAudioR[i] = vecdNetwData[i];
}
}
else
{
/* if not connected, clear data */
for (i = 0; i < iBlockSizeSam; i++)
{
vecdAudioL[i] = vecdAudioR[i] = 0.0;
}
}
/* resample data for each channel separately */
ResampleObjUpL.Resample(vecdAudioL, vecdAudioSndCrdL);
@ -276,9 +311,13 @@ fflush(pFileDelay);
/* play the new block */
if (Sound.Write(vecsAudioSndCrd))
{
PostWinMessage(MS_SOUND_OUT, MUL_COL_LED_RED);
}
else
{
PostWinMessage(MS_SOUND_OUT, MUL_COL_LED_GREEN);
}
/* update response time measurement --------------------------------- */

View file

@ -51,46 +51,60 @@
/* Classes ********************************************************************/
class CClient : public QThread
class CClient : public QObject, public QThread
{
Q_OBJECT
public:
CClient() : bRun ( false ), Socket ( &Channel ),
iAudioInFader ( AUD_FADER_IN_MAX / 2 ),
iReverbLevel ( AUD_REVERB_MAX / 6 ),
bReverbOnLeftChan ( false ) {}
CClient();
virtual ~CClient () {}
void Init();
bool Stop();
bool IsRunning() {return bRun;}
bool SetServerAddr(QString strNAddr);
double MicLevelL() {return SignalLevelMeterL.MicLevel();}
double MicLevelR() {return SignalLevelMeterR.MicLevel();}
bool IsConnected() {return Channel.IsConnected();}
void Init ();
bool Stop ();
bool IsRunning () { return bRun; }
bool SetServerAddr ( QString strNAddr );
double MicLevelL () { return SignalLevelMeterL.MicLevel (); }
double MicLevelR () { return SignalLevelMeterR.MicLevel (); }
bool IsConnected () { return Channel.IsConnected (); }
/* we want to return the standard deviation. For that we need to calculate
the sqaure root */
double GetTimingStdDev() {return sqrt(RespTimeMoAvBuf.GetAverage());}
double GetTimingStdDev () { return sqrt ( RespTimeMoAvBuf.GetAverage () ); }
int GetAudioInFader() {return iAudioInFader;}
void SetAudioInFader(const int iNV) {iAudioInFader = iNV;}
int GetAudioInFader () { return iAudioInFader; }
void SetAudioInFader ( const int iNV ) { iAudioInFader = iNV; }
int GetReverbLevel() {return iReverbLevel;}
void SetReverbLevel(const int iNL) {iReverbLevel = iNL;}
int GetReverbLevel () { return iReverbLevel; }
void SetReverbLevel ( const int iNL ) { iReverbLevel = iNL; }
bool IsReverbOnLeftChan() {return bReverbOnLeftChan;}
void SetReverbOnLeftChan(const bool bIL)
{bReverbOnLeftChan = bIL; AudioReverb.Clear();}
bool IsReverbOnLeftChan () { return bReverbOnLeftChan; }
void SetReverbOnLeftChan ( const bool bIL )
{
bReverbOnLeftChan = bIL;
AudioReverb.Clear ();
}
CSound* GetSndInterface() {return &Sound;}
CChannel* GetChannel() {return &Channel;}
void SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )
{
// set the new socket size
Channel.SetSockBufSize ( iNewBlockSize, iNumBlocks );
// tell the server that size has changed
Channel.CreateJitBufMes ( iNumBlocks );
}
int GetSockBufSize () { return Channel.GetSockBufSize (); }
CSound* GetSndInterface () { return &Sound; }
CChannel* GetChannel () { return &Channel; }
// settings
string strIPAddress;
protected:
virtual void run();
virtual void run ();
/* only one channel is needed for client application */
CChannel Channel;
@ -129,6 +143,9 @@ protected:
/* debugging, evaluating */
CMovingAv<double> RespTimeMoAvBuf;
QTime TimeLastBlock;
public slots:
void OnSendProtMessage ();
};

View file

@ -42,7 +42,7 @@
/* version and application name */
#ifndef VERSION
# define VERSION "0.9.3cvs"
# define VERSION "0.9.4cvs"
#endif
#define APP_NAME "llcon"

View file

@ -98,7 +98,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
/* network buffer */
SliderNetBuf->setRange(1, MAX_NET_BUF_SIZE_NUM_BL);
const int iCurNumNetBuf = pClient->GetChannel()->GetSockBufSize();
const int iCurNumNetBuf = pClient->GetSockBufSize();
SliderNetBuf->setValue(iCurNumNetBuf);
TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf));
@ -240,7 +240,7 @@ void CLlconClientDlg::OnSliderSndBufOutChange(int value)
void CLlconClientDlg::OnSliderNetBuf(int value)
{
pClient->GetChannel()->SetSockBufSize ( MIN_BLOCK_SIZE_SAMPLES, value );
pClient->SetSockBufSize ( MIN_BLOCK_SIZE_SAMPLES, value );
TextNetBuf->setText("Size: " + QString().setNum(value));
}

View file

@ -58,8 +58,36 @@ MESSAGES
/* Implementation *************************************************************/
CVector<unsigned char> CProtocol::GetSendMessage ()
{
// TEST, TODO implement protocol handling here (timers, etc.)
bool CClientProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
// convert unsigned uint8_t in char, TODO convert all buffers in uint8_t
CVector<unsigned char> vecbyDataConv ( vecMessage.Size () );
for ( int i = 0; i < vecMessage.Size (); i++ ) {
vecbyDataConv[i] = static_cast<unsigned char> ( vecMessage[i] );
}
return vecbyDataConv;
}
void CProtocol::EnqueueMessage ( CVector<uint8_t>& vecMessage )
{
/* TODO */
emit MessReadyForSending ();
}
bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
const int iNumBytes )
{
/*
@ -68,6 +96,11 @@ bool CClientProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
int iRecCounter, iRecID;
CVector<uint8_t> vecData;
// TEST
qDebug ( "parser entered" );
// convert unsigned char in uint8_t, TODO convert all buffers in uint8_t
CVector<uint8_t> vecbyDataConv ( vecbyData.Size () );
for ( int i = 0; i < vecbyData.Size (); i++ ) {
@ -95,7 +128,7 @@ for ( int i = 0; i < vecbyData.Size (); i++ ) {
}
}
void CClientProtocol::CreateJitBufMes ( const int iJitBufSize )
void CProtocol::CreateJitBufMes ( const int iJitBufSize )
{
CVector<uint8_t> vecData ( 2 );
unsigned int iPos = 0;
@ -105,6 +138,13 @@ void CClientProtocol::CreateJitBufMes ( const int iJitBufSize )
// build complete message
GenMessageFrame ( vecMessage, iCounter, PROTMESSID_JITT_BUF_SIZE, vecData );
// increase counter (wraps around automatically)
// TODO: make it thread safe!!!!!!!!!!!!
iCounter++;
// enqueue message
EnqueueMessage ( vecMessage );
}

View file

@ -26,6 +26,7 @@
#define PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_
#include <qglobal.h>
#include <qthread.h>
#include "global.h"
#include "util.h"
@ -42,13 +43,25 @@
/* Classes ********************************************************************/
class CProtocol
class CProtocol : public QObject
{
Q_OBJECT
public:
CProtocol () : iCounter ( 0 ) {}
virtual ~CProtocol () {}
void CreateJitBufMes ( const int iJitBufSize );
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
const int iNumBytes );
CVector<unsigned char> GetSendMessage ();
protected:
void EnqueueMessage ( CVector<uint8_t>& vecMessage );
bool ParseMessageFrame ( const CVector<uint8_t>& vecIn,
int& iCnt,
int& iID,
@ -70,42 +83,12 @@ protected:
CVector<uint8_t> vecMessage;
uint8_t iCounter;
bool bIsClient;
signals:
void MessReadyForSending ();
};
class CClientProtocol : public CProtocol
{
public:
CClientProtocol () {}
virtual ~CClientProtocol () {}
void CreateJitBufMes ( const int iJitBufSize );
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
const int iNumBytes );
protected:
};
class CServerProtocol : public CProtocol
{
public:
CServerProtocol () {}
virtual ~CServerProtocol () {}
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
const int iNumBytes );
protected:
};
#endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */

View file

@ -79,7 +79,7 @@ void CSettings::ReadIniFile()
// network jitter buffer size
if ( GetNumericIniSet(ini, "Client", "jitbuf", 0, MAX_NET_BUF_SIZE_NUM_BL, iValue ) == TRUE ) {
pClient->GetChannel()->SetSockBufSize ( MIN_BLOCK_SIZE_SAMPLES, iValue );
pClient->SetSockBufSize ( MIN_BLOCK_SIZE_SAMPLES, iValue );
}
}
@ -106,7 +106,7 @@ void CSettings::WriteIniFile()
SetNumericIniSet ( ini, "Client", "audoutbuf", pClient->GetSndInterface()->GetOutNumBuf () );
// network jitter buffer size
SetNumericIniSet ( ini, "Client", "jitbuf", pClient->GetChannel()->GetSockBufSize () );
SetNumericIniSet ( ini, "Client", "jitbuf", pClient->GetSockBufSize () );
/* Save settings in init-file */

View file

@ -76,7 +76,7 @@ void CSocket::SendPacket( const CVector<unsigned char>& vecbySendBuf,
{
/* send packet through network */
SocketDevice.writeBlock (
(const char*) &((CVector<unsigned char>) vecbySendBuf)[0],
(const char*) &( (CVector<unsigned char>) vecbySendBuf )[0],
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort );
}
@ -93,7 +93,7 @@ void CSocket::OnDataReceived ()
{
/* read block from network interface */
const int iNumBytesRead = SocketDevice.readBlock( (char*) &vecbyRecBuf[0],
MAX_SIZE_BYTES_NETW_BUF);
MAX_SIZE_BYTES_NETW_BUF );
/* check if an error occurred */
if ( iNumBytesRead < 0 )

View file

@ -69,6 +69,7 @@ protected:
CChannel* pChannel; /* for client */
CChannelSet* pChannelSet; /* for server */
QObject* pServer;
bool bIsClient;

View file

@ -31,7 +31,10 @@ rem .h --------------
%qtdir%\bin\moc.exe ..\src\llconclientdlg.h -o moc\moc_llconclientdlg.cpp
%qtdir%\bin\moc.exe ..\src\llconserverdlg.h -o moc\moc_llconserverdlg.cpp
%qtdir%\bin\moc.exe ..\src\server.h -o moc\moc_server.cpp
%qtdir%\bin\moc.exe ..\src\client.h -o moc\moc_client.cpp
%qtdir%\bin\moc.exe ..\src\socket.h -o moc\moc_socket.cpp
%qtdir%\bin\moc.exe ..\src\protocol.h -o moc\moc_protocol.cpp
%qtdir%\bin\moc.exe ..\src\channel.h -o moc\moc_channel.cpp
rem .ui -------------

View file

@ -113,6 +113,14 @@ SOURCE=.\moc\moc_aboutdlgbase.cpp
# End Source File
# Begin Source File
SOURCE=.\moc\moc_channel.cpp
# End Source File
# Begin Source File
SOURCE=.\moc\moc_client.cpp
# End Source File
# Begin Source File
SOURCE=.\moc\moc_llconclientdlg.cpp
# End Source File
# Begin Source File
@ -133,6 +141,10 @@ SOURCE=.\moc\moc_multicolorled.cpp
# End Source File
# Begin Source File
SOURCE=.\moc\moc_protocol.cpp
# End Source File
# Begin Source File
SOURCE=.\moc\moc_server.cpp
# End Source File
# Begin Source File