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

@ -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 );
@ -320,9 +326,11 @@ bool CChannel::GetData(CVector<double>& vecdData)
/* if time out is reached, re-init resample offset estimation
module */
if ( iConTimeOut == 0 )
{
SampleOffsetEst.Init ();
}
}
}
Mutex.unlock (); /* get mutex unlock */

View File

@ -74,8 +74,10 @@ protected:
/* CChannel ----------------------------------------------------------------- */
class CChannel
class CChannel : public QObject
{
Q_OBJECT
public:
CChannel ();
virtual ~CChannel () {}
@ -85,17 +87,27 @@ public:
bool GetData ( CVector<double>& vecdData );
CVector<unsigned char> PrepSendPacket ( const CVector<short>& vecsNPacket );
CVector<unsigned char> GetSendMessage () { return Protocol.GetSendMessage (); }
bool GetAddress(CHostAddress& RetAddr);
CHostAddress GetAddress() {return InetAddr;}
int GetTimeStampIdx();
void SetAddress(const CHostAddress NAddr) {InetAddr = NAddr;}
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; }
void SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks );
int GetSockBufSize () { return SockBuf.GetSize(); }
// network protocol interface
void CreateJitBufMes ( const int iJitBufSize )
{
Protocol.CreateJitBufMes ( iJitBufSize );
}
protected:
/* audio compression */
CAudioCompression AudioCompression;
@ -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,13 +51,12 @@
/* 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 ();
@ -80,7 +79,22 @@ public:
bool IsReverbOnLeftChan () { return bReverbOnLeftChan; }
void SetReverbOnLeftChan ( const bool bIL )
{bReverbOnLeftChan = bIL; AudioReverb.Clear();}
{
bReverbOnLeftChan = bIL;
AudioReverb.Clear ();
}
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; }
@ -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

@ -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