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 # these need to be generated before the rest can be compiled
BUILT_SOURCES=moc/moc_server.cpp \ BUILT_SOURCES=moc/moc_server.cpp \
moc/moc_client.cpp \
moc/moc_protocol.cpp \
moc/moc_channel.cpp \
moc/moc_socket.cpp \ moc/moc_socket.cpp \
moc/moc_multicolorled.cpp \ moc/moc_multicolorled.cpp \
moc/moc_util.cpp \ moc/moc_util.cpp \
@ -57,6 +60,9 @@ dist-hook:
moc/moc_server.cpp: ../src/server.h moc/moc_server.cpp: ../src/server.h
$(MOC) ../src/server.h -o moc/moc_server.cpp $(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/moc_socket.cpp: ../src/socket.h
$(MOC) ../src/socket.h -o moc/moc_socket.cpp $(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/moc_util.cpp: ../src/util.h
$(MOC) ../src/util.h -o moc/moc_util.cpp $(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 moc/moc_aboutdlgbase.cpp: moc/aboutdlgbase.h

View file

@ -221,6 +221,12 @@ CChannel::CChannel()
/* init sample rate offset estimation object */ /* init sample rate offset estimation object */
SampleOffsetEst.Init(); 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 ) 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 // 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 /* if time out is reached, re-init resample offset estimation
module */ module */
if ( iConTimeOut == 0 ) if ( iConTimeOut == 0 )
{
SampleOffsetEst.Init (); SampleOffsetEst.Init ();
} }
} }
}
Mutex.unlock (); /* get mutex unlock */ Mutex.unlock (); /* get mutex unlock */

View file

@ -74,8 +74,10 @@ protected:
/* CChannel ----------------------------------------------------------------- */ /* CChannel ----------------------------------------------------------------- */
class CChannel class CChannel : public QObject
{ {
Q_OBJECT
public: public:
CChannel (); CChannel ();
virtual ~CChannel () {} virtual ~CChannel () {}
@ -85,17 +87,27 @@ public:
bool GetData ( CVector<double>& vecdData ); 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 GetAddress(CHostAddress& RetAddr);
CHostAddress GetAddress() {return InetAddr;}
int GetTimeStampIdx();
void SetAddress(const CHostAddress NAddr) {InetAddr = NAddr;}
bool IsConnected () const { return iConTimeOut > 0; } bool IsConnected () const { return iConTimeOut > 0; }
int GetTimeStampIdx ();
int GetComprAudSize () { return iAudComprSize; } int GetComprAudSize () { return iAudComprSize; }
double GetResampleOffset () { return SampleOffsetEst.GetSamRate (); } 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 ); 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: protected:
/* audio compression */ /* audio compression */
CAudioCompression AudioCompression; CAudioCompression AudioCompression;
@ -118,10 +130,8 @@ protected:
/* network output conversion buffer */ /* network output conversion buffer */
CConvBuf ConvBuf; CConvBuf ConvBuf;
// network protocol
// TEST TODO: better implementation, now this object is created in server AND client which is not good CProtocol Protocol;
CClientProtocol ClientProtocol;
/* time stamp index counter */ /* time stamp index counter */
Q_UINT8 byTimeStampIdxCnt; Q_UINT8 byTimeStampIdxCnt;
@ -130,6 +140,9 @@ CClientProtocol ClientProtocol;
int iConTimeOut; int iConTimeOut;
QMutex Mutex; QMutex Mutex;
signals:
void MessReadyForSending ();
}; };

View file

@ -26,6 +26,29 @@
/* Implementation *************************************************************/ /* 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) bool CClient::SetServerAddr(QString strNAddr)
{ {
QHostAddress InetAddr; QHostAddress InetAddr;
@ -113,9 +136,13 @@ void CClient::run()
{ {
/* get audio from sound card (blocking function) */ /* get audio from sound card (blocking function) */
if (Sound.Read(vecsAudioSndCrd)) if (Sound.Read(vecsAudioSndCrd))
{
PostWinMessage(MS_SOUND_IN, MUL_COL_LED_RED); PostWinMessage(MS_SOUND_IN, MUL_COL_LED_RED);
}
else else
{
PostWinMessage(MS_SOUND_IN, MUL_COL_LED_GREEN); PostWinMessage(MS_SOUND_IN, MUL_COL_LED_GREEN);
}
/* copy data from one stereo buffer in two separate buffers */ /* copy data from one stereo buffer in two separate buffers */
iInCnt = 0; iInCnt = 0;
@ -182,9 +209,13 @@ void CClient::run()
/* receive a new block */ /* receive a new block */
if (Channel.GetData(vecdNetwData)) if (Channel.GetData(vecdNetwData))
{
PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_GREEN); PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_GREEN);
}
else else
{
PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_RED); PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_RED);
}
#ifdef _DEBUG_ #ifdef _DEBUG_
#if 0 #if 0
@ -253,14 +284,18 @@ fflush(pFileDelay);
{ {
/* write mono input signal in both sound-card channels */ /* write mono input signal in both sound-card channels */
for (i = 0; i < iBlockSizeSam; i++) for (i = 0; i < iBlockSizeSam; i++)
{
vecdAudioL[i] = vecdAudioR[i] = vecdNetwData[i]; vecdAudioL[i] = vecdAudioR[i] = vecdNetwData[i];
} }
}
else else
{ {
/* if not connected, clear data */ /* if not connected, clear data */
for (i = 0; i < iBlockSizeSam; i++) for (i = 0; i < iBlockSizeSam; i++)
{
vecdAudioL[i] = vecdAudioR[i] = 0.0; vecdAudioL[i] = vecdAudioR[i] = 0.0;
} }
}
/* resample data for each channel separately */ /* resample data for each channel separately */
ResampleObjUpL.Resample(vecdAudioL, vecdAudioSndCrdL); ResampleObjUpL.Resample(vecdAudioL, vecdAudioSndCrdL);
@ -276,9 +311,13 @@ fflush(pFileDelay);
/* play the new block */ /* play the new block */
if (Sound.Write(vecsAudioSndCrd)) if (Sound.Write(vecsAudioSndCrd))
{
PostWinMessage(MS_SOUND_OUT, MUL_COL_LED_RED); PostWinMessage(MS_SOUND_OUT, MUL_COL_LED_RED);
}
else else
{
PostWinMessage(MS_SOUND_OUT, MUL_COL_LED_GREEN); PostWinMessage(MS_SOUND_OUT, MUL_COL_LED_GREEN);
}
/* update response time measurement --------------------------------- */ /* update response time measurement --------------------------------- */

View file

@ -51,13 +51,12 @@
/* Classes ********************************************************************/ /* Classes ********************************************************************/
class CClient : public QThread class CClient : public QObject, public QThread
{ {
Q_OBJECT
public: public:
CClient() : bRun ( false ), Socket ( &Channel ), CClient();
iAudioInFader ( AUD_FADER_IN_MAX / 2 ),
iReverbLevel ( AUD_REVERB_MAX / 6 ),
bReverbOnLeftChan ( false ) {}
virtual ~CClient () {} virtual ~CClient () {}
void Init (); void Init ();
@ -80,7 +79,22 @@ public:
bool IsReverbOnLeftChan () { return bReverbOnLeftChan; } bool IsReverbOnLeftChan () { return bReverbOnLeftChan; }
void SetReverbOnLeftChan ( const bool bIL ) 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; } CSound* GetSndInterface () { return &Sound; }
CChannel* GetChannel () { return &Channel; } CChannel* GetChannel () { return &Channel; }
@ -129,6 +143,9 @@ protected:
/* debugging, evaluating */ /* debugging, evaluating */
CMovingAv<double> RespTimeMoAvBuf; CMovingAv<double> RespTimeMoAvBuf;
QTime TimeLastBlock; QTime TimeLastBlock;
public slots:
void OnSendProtMessage ();
}; };

View file

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

View file

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

View file

@ -58,8 +58,36 @@ MESSAGES
/* Implementation *************************************************************/ /* 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 ) const int iNumBytes )
{ {
/* /*
@ -68,6 +96,11 @@ bool CClientProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
int iRecCounter, iRecID; int iRecCounter, iRecID;
CVector<uint8_t> vecData; CVector<uint8_t> vecData;
// TEST
qDebug ( "parser entered" );
// convert unsigned char in uint8_t, TODO convert all buffers in uint8_t // convert unsigned char in uint8_t, TODO convert all buffers in uint8_t
CVector<uint8_t> vecbyDataConv ( vecbyData.Size () ); CVector<uint8_t> vecbyDataConv ( vecbyData.Size () );
for ( int i = 0; i < vecbyData.Size (); i++ ) { 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 ); CVector<uint8_t> vecData ( 2 );
unsigned int iPos = 0; unsigned int iPos = 0;
@ -105,6 +138,13 @@ void CClientProtocol::CreateJitBufMes ( const int iJitBufSize )
// build complete message // build complete message
GenMessageFrame ( vecMessage, iCounter, PROTMESSID_JITT_BUF_SIZE, vecData ); 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_ #define PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_
#include <qglobal.h> #include <qglobal.h>
#include <qthread.h>
#include "global.h" #include "global.h"
#include "util.h" #include "util.h"
@ -42,13 +43,25 @@
/* Classes ********************************************************************/ /* Classes ********************************************************************/
class CProtocol class CProtocol : public QObject
{ {
Q_OBJECT
public: public:
CProtocol () : iCounter ( 0 ) {} CProtocol () : iCounter ( 0 ) {}
virtual ~CProtocol () {} virtual ~CProtocol () {}
void CreateJitBufMes ( const int iJitBufSize );
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
const int iNumBytes );
CVector<unsigned char> GetSendMessage ();
protected: protected:
void EnqueueMessage ( CVector<uint8_t>& vecMessage );
bool ParseMessageFrame ( const CVector<uint8_t>& vecIn, bool ParseMessageFrame ( const CVector<uint8_t>& vecIn,
int& iCnt, int& iCnt,
int& iID, int& iID,
@ -70,42 +83,12 @@ protected:
CVector<uint8_t> vecMessage; CVector<uint8_t> vecMessage;
uint8_t iCounter; 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_) */ #endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */

View file

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

View file

@ -69,6 +69,7 @@ protected:
CChannel* pChannel; /* for client */ CChannel* pChannel; /* for client */
CChannelSet* pChannelSet; /* for server */ CChannelSet* pChannelSet; /* for server */
QObject* pServer; QObject* pServer;
bool bIsClient; 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\llconclientdlg.h -o moc\moc_llconclientdlg.cpp
%qtdir%\bin\moc.exe ..\src\llconserverdlg.h -o moc\moc_llconserverdlg.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\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\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 ------------- rem .ui -------------

View file

@ -113,6 +113,14 @@ SOURCE=.\moc\moc_aboutdlgbase.cpp
# End Source File # End Source File
# Begin 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 SOURCE=.\moc\moc_llconclientdlg.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@ -133,6 +141,10 @@ SOURCE=.\moc\moc_multicolorled.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\moc\moc_protocol.cpp
# End Source File
# Begin Source File
SOURCE=.\moc\moc_server.cpp SOURCE=.\moc\moc_server.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File