added new file for protocol (just template right now), new code style

This commit is contained in:
Volker Fischer 2006-02-12 14:26:46 +00:00
parent 270725688f
commit dd914c411c
14 changed files with 351 additions and 160 deletions

View file

@ -13,6 +13,7 @@ llcon_SOURCES = ../src/buffer.cpp \
../src/llconserverdlg.cpp \
../src/server.cpp \
../src/settings.cpp \
../src/protocol.cpp \
../src/multicolorled.cpp \
sound.cpp \
../src/buffer.h \
@ -26,6 +27,7 @@ llcon_SOURCES = ../src/buffer.cpp \
../src/client.h \
../src/server.h \
../src/settings.h \
../src/protocol.h \
../src/multicolorled.h \
../src/llconserverdlg.h \
../src/llconclientdlg.h \

View file

@ -77,10 +77,14 @@ bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
iCurChanID = GetFreeChan ();
if ( iCurChanID != INVALID_CHANNEL_ID )
{
vecChannels[iCurChanID].SetAddress ( HostAdr );
}
else
{
bChanOK = false; /* no free channel available */
}
}
/* put received data in jitter buffer ----------------------------------- */
@ -88,10 +92,14 @@ bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
{
/* put packet in socket buffer */
if ( vecChannels[iCurChanID].PutData ( vecbyRecBuf, iNumBytesRead ) )
{
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN, iCurChanID );
}
else
{
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED, iCurChanID );
}
}
Mutex.unlock ();
@ -213,25 +221,6 @@ void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )
Mutex.unlock ();
}
int CChannel::GetTimeStampIdx ()
{
/* only send time stamp index after a pre-defined number of packets */
if ( iTimeStampActCnt > 0 )
{
iTimeStampActCnt--;
return INVALID_TIME_STAMP_IDX;
}
else
{
/* reset time stamp activation counter */
iTimeStampActCnt = NUM_BL_TIME_STAMPS - 1;
/* wraps around automatically */
byTimeStampIdxCnt++;
return byTimeStampIdxCnt;
}
}
bool CChannel::GetAddress(CHostAddress& RetAddr)
{
if (IsConnected())
@ -262,9 +251,6 @@ bool CChannel::PutData(const CVector<unsigned char>& vecbyData,
/* do resampling to compensate for sample rate offsets in the
different sound cards of the clients */
// we should not do resampling here since we already have resampling
// in the client audio path, we could use this resampling for this
// sample rate correction, too
/*
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
vecdResInData[i] = (double) vecsData[i];
@ -339,6 +325,24 @@ CVector<unsigned char> CChannel::PrepSendPacket(const CVector<short>& vecsNPacke
return vecbySendBuf;
}
int CChannel::GetTimeStampIdx ()
{
/* only send time stamp index after a pre-defined number of packets */
if ( iTimeStampActCnt > 0 )
{
iTimeStampActCnt--;
return INVALID_TIME_STAMP_IDX;
}
else
{
/* reset time stamp activation counter */
iTimeStampActCnt = NUM_BL_TIME_STAMPS - 1;
/* wraps around automatically */
byTimeStampIdxCnt++;
return byTimeStampIdxCnt;
}
}
/******************************************************************************\
@ -395,8 +399,6 @@ fflush(pFile);
*/
/* calculate linear regression for sample rate estimation */
/* first, calculate averages */
double dTimeAv = 0;
@ -434,15 +436,10 @@ fflush(pFile);
*/
}
/*
static FILE* pFile = fopen("v.dat", "w");
fprintf(pFile, "%e\n", dSamRateEst);
fflush(pFile);
*/
}

View file

@ -26,12 +26,12 @@
#define CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_
#include <qthread.h>
#include <qdatetime.h>
#include "global.h"
#include "buffer.h"
#include "audiocompr.h"
#include "util.h"
#include "resample.h"
#include "qdatetime.h"
/* Definitions ****************************************************************/

View file

@ -98,7 +98,7 @@
/* time interval of taps for sample rate offset estimation (time stamps) */
#define INTVL_TAPS_SAM_OFF_SET 1 /* s */
#define NUM_BL_TIME_STAMPS ( ( INTVL_TAPS_SAM_OFF_SET * 1000 ) / MIN_BLOCK_DURATION_MS )
#define NUM_BL_TIME_STAMPS ( ( INTVL_TAPS_SAM_OFF_SET * 1000 ) / BLOCK_DURATION_MS )
#define VEC_LEN_SAM_OFFS_EST ( TIME_INT_SAM_OFFS_EST / INTVL_TAPS_SAM_OFF_SET )
/* length of the moving average buffer for response time measurement */

View file

@ -68,9 +68,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
OnTimerStatus ();
/* init sample rate offset label */
// TextSamRateOffsValue->setText ( "0 Hz" );
// FIXME disable sample rate estimation result label since estimation does not work
TextSamRateOffsValue->setText ( "---" );
TextSamRateOffsValue->setText ( "0 Hz" );
/* init connection button text */
PushButtonConnect->setText ( CON_BUT_CONNECTTEXT );
@ -275,17 +273,9 @@ void CLlconClientDlg::OnTimerStatus()
TextLabelStatus->setText(tr("disconnected"));
/* update sample rate offset label */
// FIXME disable sample rate estimation result label since estimation does not work
/*
QString strSamRaOffs;
// FIXME: sample rate estimation result must be corrected since we use
// smaller buffers in client now. Actual estimation should be fixed, not here
strSamRaOffs.setNum(pClient->GetChannel()->GetResampleOffset() *
MIN_BLOCK_DURATION_MS / BLOCK_DURATION_MS, 'f', 2);
strSamRaOffs.setNum(pClient->GetChannel()->GetResampleOffset(), 'f', 2);
TextSamRateOffsValue->setText(strSamRaOffs + " Hz");
*/
/* response time */
TextLabelStdDevTimer->setText(QString().

View file

@ -108,6 +108,7 @@ void CLlconServerDlg::OnTimer()
{
CVector<CHostAddress> vecHostAddresses;
CVector<double> vecdSamOffs;
double dCurTiStdDev;
ListViewMutex.lock();
@ -140,9 +141,16 @@ void CLlconServerDlg::OnTimer()
ListViewMutex.unlock();
/* response time */
/* response time (if available) */
if ( Server.GetTimingStdDev ( dCurTiStdDev ) )
{
TextLabelResponseTime->setText(QString().
setNum(Server.GetTimingStdDev(), 'f', 2) + " ms");
setNum(dCurTiStdDev, 'f', 2) + " ms");
}
else
{
TextLabelResponseTime->setText("---");
}
}
void CLlconServerDlg::OnSliderNetBuf(int value)

View file

@ -49,8 +49,10 @@ int main(int argc, char** argv)
/* only "-s" is supported right now */
std::string strShortOpt = "-s";
if ( !strShortOpt.compare ( argv[1] ) )
{
bIsClient = false;
}
}
if ( bIsClient )
{
@ -98,7 +100,8 @@ void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam,
/* In case of simulation no events should be generated */
if ( pApp != NULL )
{
CLlconEvent* LlconEv = new CLlconEvent ( MessID, iMessageParam, iChanNum );
CLlconEvent* LlconEv =
new CLlconEvent ( MessID, iMessageParam, iChanNum );
/* Qt will delete the event object when done */
QThread::postEvent ( pApp->mainWidget (), LlconEv );

31
src/protocol.cpp Executable file
View file

@ -0,0 +1,31 @@
/******************************************************************************\
* Copyright (c) 2004-2006
*
* 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
*
\******************************************************************************/
#include "protocol.h"
/* Implementation *************************************************************/
// TODO

63
src/protocol.h Executable file
View file

@ -0,0 +1,63 @@
/******************************************************************************\
* Copyright (c) 2004-2006
*
* 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(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_)
#define PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_
#include "global.h"
/* Classes ********************************************************************/
class CProtocol
{
public:
CProtocol() {}
virtual ~CProtocol() {}
protected:
};
class CServerProtocol : public CProtocol
{
public:
CServerProtocol() {}
virtual ~CServerProtocol() {}
protected:
};
class CClientProtocol : public CProtocol
{
public:
CClientProtocol() {}
virtual ~CClientProtocol() {}
protected:
};
#endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */

View file

@ -38,6 +38,8 @@ CServer::CServer() : Socket(&ChannelSet)
}
void CServer::Start()
{
if ( !IsRunning () )
{
/* start main timer */
Timer.start(BLOCK_DURATION_MS);
@ -45,6 +47,13 @@ void CServer::Start()
/* init time for response time evaluation */
TimeLastBlock = QTime::currentTime();
}
}
void CServer::Stop()
{
/* stop main timer */
Timer.stop();
}
void CServer::OnTimer()
{
@ -53,28 +62,31 @@ void CServer::OnTimer()
/* get data from all connected clients */
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData );
const int iNumClients = vecvecdData.Size ();
/* Check if at least one client is connected. If not, stop server until
one client is connected */
if ( iNumClients != 0 )
{
/* actual processing of audio data -> mix */
vecsSendData = ProcessData ( vecvecdData );
/* get number of connected clients from vector size */
const int iNumClients = vecvecdData.Size();
/* send the same data to all connected clients */
for ( int i = 0; i < iNumClients; i++ )
{
Socket.SendPacket(ChannelSet.PrepSendPacket(vecChanID[i], vecsSendData),
Socket.SendPacket (
ChannelSet.PrepSendPacket ( vecChanID[i], vecsSendData ),
ChannelSet.GetAddress ( vecChanID[i] ),
ChannelSet.GetTimeStampIdx ( vecChanID[i] ) );
}
/* update response time measurement ------------------------------------- */
/* update response time measurement --------------------------------- */
/* add time difference */
const QTime CurTime = QTime::currentTime ();
/* we want to calculate the standard deviation (we assume that the mean is
correct at the block period time) */
/* we want to calculate the standard deviation (we assume that the mean
is correct at the block period time) */
const double dCurAddVal =
( (double) TimeLastBlock.msecsTo ( CurTime ) - BLOCK_DURATION_MS );
@ -83,6 +95,17 @@ void CServer::OnTimer()
/* store old time value */
TimeLastBlock = CurTime;
}
else
{
/* disable server */
// TODO not yet working since the socket does not have access to the server
// object and cannot restart the server if packets arrive...
// Stop ();
}
}
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
{
@ -111,3 +134,23 @@ CVector<short> CServer::ProcessData(CVector<CVector<double> >& vecvecdData)
return vecsOutData;
}
bool CServer::GetTimingStdDev ( double& dCurTiStdDev )
{
dCurTiStdDev = 0.0; /* init return value */
/* only return value if server is active and the actual measurement is
updated */
if ( IsRunning () )
{
/* we want to return the standard deviation, for that we need to calculate
the sqaure root */
dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage () );
return true;
}
else
{
return false;
}
}

View file

@ -46,13 +46,13 @@ public:
virtual ~CServer () {}
void Start ();
void Stop ();
bool IsRunning() { return Timer.isActive (); }
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<double>& vecdSamOffs )
{ ChannelSet.GetConCliParam ( vecHostAddresses, vecdSamOffs ); }
/* we want to return the standard deviation. For that we need to calculate
the sqaure root */
double GetTimingStdDev() {return sqrt(RespTimeMoAvBuf.GetAverage());}
bool GetTimingStdDev ( double& dCurTiStdDev );
CChannelSet* GetChannelSet () { return &ChannelSet; }

View file

@ -42,8 +42,8 @@ void CSocket::Init()
{
/* if server and client is on same machine, decrease port number by
one by definition */
bSuccess =
SocketDevice.bind(QHostAddress((Q_UINT32) 0) /* INADDR_ANY */,
bSuccess = SocketDevice.bind (
QHostAddress( (Q_UINT32) 0 ) /* INADDR_ANY */,
LLCON_PORT_NUMBER - 1 );
}
}
@ -67,14 +67,16 @@ void CSocket::Init()
}
void CSocket::SendPacket( const CVector<unsigned char>& vecbySendBuf,
const CHostAddress& HostAddr, const int iTimeStampIdx)
const CHostAddress& HostAddr,
const int iTimeStampIdx )
{
const int iVecSizeOut = vecbySendBuf.Size ();
if ( iVecSizeOut != 0 )
{
/* send packet through network */
SocketDevice.writeBlock ((const char*) &((CVector<unsigned char>) vecbySendBuf)[0],
SocketDevice.writeBlock (
(const char*) &((CVector<unsigned char>) vecbySendBuf)[0],
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort );
}
@ -95,7 +97,9 @@ void CSocket::OnDataReceived()
/* check if an error occurred */
if ( iNumBytesRead < 0 )
{
return;
}
/* get host address of client */
CHostAddress RecHostAddr ( SocketDevice.peerAddress (),
@ -109,10 +113,14 @@ void CSocket::OnDataReceived()
return;
if ( pChannel->PutData( vecbyRecBuf, iNumBytesRead ) )
{
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN );
}
else
{
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED );
}
}
else
{
/* server */

View file

@ -30,6 +30,7 @@
#include <qwhatsthis.h>
#include <qtextview.h>
#include <qlabel.h>
#include <qdatetime.h>
#include <vector>
#include "global.h"
using namespace std; /* Because of the library: "vector" */
@ -378,4 +379,41 @@ protected:
};
/* Time conversion ---------------------------------------------------------- */
// needed for ping measurement
class CTimeConv
{
public:
// QTime to network time vector
static CVector<unsigned char> QTi2NetTi ( const QTime qTiIn )
{
// vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms
CVector<unsigned char> veccNetTi ( 5 );
veccNetTi[0] = static_cast<unsigned char> ( qTiIn.hour () );
veccNetTi[1] = static_cast<unsigned char> ( qTiIn.minute () );
veccNetTi[2] = static_cast<unsigned char> ( qTiIn.second () );
const int iMs = qTiIn.msec ();
veccNetTi[3] = static_cast<unsigned char> ( ( iMs >> 8 ) & 255 );
veccNetTi[4] = static_cast<unsigned char> ( iMs & 255 );
return veccNetTi;
}
// network time vector to QTime
static QTime NetTi2QTi ( const CVector<unsigned char> netTiIn )
{
// vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms
return QTime (
static_cast<int> ( netTiIn[0] ), // hour
static_cast<int> ( netTiIn[1] ), // minute
static_cast<int> ( netTiIn[2] ), // seconds
// msec
static_cast<int> ( ( netTiIn[3] << 8 ) | netTiIn[4] )
);
}
};
#endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */

View file

@ -178,6 +178,10 @@ SOURCE=..\src\multicolorled.cpp
# End Source File
# Begin Source File
SOURCE=..\src\protocol.cpp
# End Source File
# Begin Source File
SOURCE=..\src\resample.cpp
# End Source File
# Begin Source File
@ -238,6 +242,10 @@ SOURCE=..\src\multicolorled.h
# End Source File
# Begin Source File
SOURCE=..\src\protocol.h
# End Source File
# Begin Source File
SOURCE=..\src\resample.h
# End Source File
# Begin Source File