From 86dd0ecaa33093801448423295f7428cd1b744d9 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 27 Nov 2006 22:35:22 +0000 Subject: [PATCH] some fixes for protocol --- src/channel.cpp | 23 +++++++++++------------ src/llconclientdlg.cpp | 37 +++++++++++++++++++++++-------------- src/llconclientdlg.h | 2 +- src/protocol.cpp | 39 ++++++++++++++++++++++++++++++--------- src/protocol.h | 20 ++++++++++++-------- src/server.cpp | 29 +++++++++++++---------------- 6 files changed, 90 insertions(+), 60 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index bb323521..d71d72fe 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -58,12 +58,8 @@ CChannelSet::CChannelSet() void CChannelSet::CreateAndSendChanListForAllConClients() { - int i; - CVector vecChanInfo ( 0 ); - - // the channel ID is defined as the order of the channels in the channel - // set where we do not care about not-connected channels - int iCurChanID = 0; + int i; + CVector vecChanInfo ( 0 ); // look for free channels for ( i = 0; i < MAX_NUM_CHANNELS; i++ ) @@ -71,11 +67,10 @@ void CChannelSet::CreateAndSendChanListForAllConClients() if ( vecChannels[i].IsConnected() ) { // append channel ID, IP address and channel name to storing vectors - CChannelShortInfo ChannelShortInfo ( - i, vecChannels[i].GetAddress().InetAddr.ip4Addr(), - vecChannels[i].GetName() ); - - vecChanInfo.Add ( ChannelShortInfo ); + vecChanInfo.Add ( CChannelShortInfo ( + i, // ID + vecChannels[i].GetAddress().InetAddr.ip4Addr(), // IP address + vecChannels[i].GetName() /* name */ ) ); } } @@ -130,7 +125,7 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, const int iNumBytesRead, const CHostAddress& HostAdr ) { - bool bRet = false; + bool bRet = false; bool bCreateChanList = false; Mutex.lock(); @@ -160,6 +155,10 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, { /* no free channel available */ bChanOK = false; + + // create and send "server full" message +// TODO + } } diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 87e294c6..5d101c94 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -29,7 +29,8 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, const char* name, bool modal, WFlags f) : pClient ( pNCliP ), CLlconClientDlgBase ( parent, name, modal, f ), - ClientSettingsDlg ( pNCliP, 0, 0, FALSE, Qt::WStyle_MinMax ) + ClientSettingsDlg ( pNCliP, 0, 0, FALSE, Qt::WStyle_MinMax ), + vecpChanFader ( 0 ) { /* add help text to controls */ QString strInpLevH = tr("Input level meter: Shows the level of the " @@ -171,14 +172,10 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, - - - // TEST -//new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout); -//new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout); -//new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout); -//new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout, "test"); +//vecpChanFader.Init(0); +//vecpChanFader.Add(new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout, "test")); + /* for ( int z = 0; z < 100; z++) @@ -187,6 +184,7 @@ CLlconClientDlg::CChannelFader* pTest = new CLlconClientDlg::CChannelFader(Frame delete pTest; } */ + } @@ -209,7 +207,7 @@ void CLlconClientDlg::closeEvent ( QCloseEvent * Event ) } void CLlconClientDlg::OnConnectDisconBut () -{ +{ /* start/stop client, set button text */ if ( pClient->IsRunning () ) { @@ -292,20 +290,29 @@ void CLlconClientDlg::OnTimerSigMet () void CLlconClientDlg::OnConClientListMesReceived ( CVector vecChanInfo ) { + int i; + // TODO -// TEST -for ( int i = 0; i < vecChanInfo.Size(); i++ ) +// remove old controls +for ( i = 0; i < vecpChanFader.Size(); i++ ) +{ + delete vecpChanFader[i]; +} + + +// TEST add current faders +vecpChanFader.Init ( vecChanInfo.Size() ); +for ( i = 0; i < vecChanInfo.Size(); i++ ) { QHostAddress addrTest ( vecChanInfo[i].veciIpAddr ); - new CLlconClientDlg::CChannelFader ( FrameAudioFaders, + vecpChanFader[i] = new CLlconClientDlg::CChannelFader ( FrameAudioFaders, FrameAudioFadersLayout, addrTest.toString() ); } - } void CLlconClientDlg::UpdateDisplay() @@ -370,8 +377,10 @@ CLlconClientDlg::CChannelFader::CChannelFader ( QWidget* pNW, pFader->setRange ( 0, AUD_MIX_FADER_MAX ); pFader->setTickInterval ( AUD_MIX_FADER_MAX / 9 ); -// TEST set value +// TEST set value and make read only pFader->setValue ( 0 ); +pFader->setEnabled ( FALSE ); + // add label to grid pMainGrid->addWidget( pLabel, 1, 0 ); diff --git a/src/llconclientdlg.h b/src/llconclientdlg.h index cf1522b7..9d3932c6 100755 --- a/src/llconclientdlg.h +++ b/src/llconclientdlg.h @@ -107,7 +107,7 @@ protected: CClientSettingsDlg ClientSettingsDlg; - CVector vecpChanFader; + CVector vecpChanFader; public slots: void OnConnectDisconBut(); diff --git a/src/protocol.cpp b/src/protocol.cpp index 1a6446a1..1821b8e9 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -49,6 +49,11 @@ MESSAGES note: does not have any data -> n = 0 +- Server full message: PROTMESSID_SERVER_FULL + + note: does not have any data -> n = 0 + + - Network buffer block size factor PROTMESSID_NET_BLSI_FACTOR note: size, relative to minimum block size @@ -309,6 +314,11 @@ for ( int i = 0; i < iNumBytes; i++ ) { EvaluateReqJitBufMes ( iPos, vecData ); break; + case PROTMESSID_SERVER_FULL: + + EvaluateServerFullMes ( iPos, vecData ); + break; + case PROTMESSID_NET_BLSI_FACTOR: EvaluateNetwBlSiFactMes ( iPos, vecData ); @@ -348,8 +358,8 @@ for ( int i = 0; i < iNumBytes; i++ ) { /* Access-functions for creating and parsing messages ----------------------- */ void CProtocol::CreateJitBufMes ( const int iJitBufSize ) { - CVector vecData ( 2 ); // 2 bytes of data - unsigned int iPos = 0; // init position pointer + CVector vecData ( 2 ); // 2 bytes of data + unsigned int iPos = 0; // init position pointer // build data vector PutValOnStream ( vecData, iPos, static_cast ( iJitBufSize ), 2 ); @@ -378,6 +388,17 @@ void CProtocol::EvaluateReqJitBufMes ( unsigned int iPos, const CVector emit ReqJittBufSize(); } +void CProtocol::CreateServerFullMes() +{ + CreateAndSendMessage ( PROTMESSID_SERVER_FULL, CVector ( 0 ) ); +} + +void CProtocol::EvaluateServerFullMes ( unsigned int iPos, const CVector& vecData ) +{ + // invoke message action + emit ServerFull(); +} + void CProtocol::CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) { CVector vecData ( 2 ); // 2 bytes of data @@ -435,8 +456,8 @@ void CProtocol::CreateConClientListMes ( const CVector& vecCh const int iNumClients = vecChanInfo.Size(); // build data vector - CVector vecData ( 0 ); - unsigned int iPos = 0; // init position pointer + CVector vecData ( 0 ); + unsigned int iPos = 0; // init position pointer for ( int i = 0; i < iNumClients; i++ ) { @@ -476,9 +497,9 @@ void CProtocol::CreateConClientListMes ( const CVector& vecCh void CProtocol:: EvaluateConClientListMes ( unsigned int iPos, const CVector& vecData ) { - int iData; - const int iDataLen = vecData.Size(); - CVector vecChanInfo ( 0 ); + int iData; + const int iDataLen = vecData.Size(); + CVector vecChanInfo ( 0 ); while ( iPos < iDataLen ) { @@ -583,8 +604,8 @@ bool CProtocol::ParseMessageFrame ( const CVector& vecIn, } uint32_t CProtocol::GetValFromStream ( const CVector& vecIn, - unsigned int& iPos, - const unsigned int iNumOfBytes ) + unsigned int& iPos, + const unsigned int iNumOfBytes ) { /* note: iPos is automatically incremented in this function diff --git a/src/protocol.h b/src/protocol.h index aa581e02..67b590ae 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -39,10 +39,11 @@ #define PROTMESSID_ACKN 1 // acknowledge #define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size #define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size -#define PROTMESSID_PING 12 // for measuring ping time -#define PROTMESSID_NET_BLSI_FACTOR 13 // network buffer size factor -#define PROTMESSID_CHANNEL_GAIN 14 // set channel gain for mix -#define PROTMESSID_CONN_CLIENTS_LIST 15 // connected client list +#define PROTMESSID_SERVER_FULL 12 +#define PROTMESSID_PING 13 // for measuring ping time +#define PROTMESSID_NET_BLSI_FACTOR 14 // network buffer size factor +#define PROTMESSID_CHANNEL_GAIN 15 // set channel gain for mix +#define PROTMESSID_CONN_CLIENTS_LIST 16 // connected client list // lengths of message as defined in protocol.cpp file #define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */ @@ -62,6 +63,7 @@ public: void CreateJitBufMes ( const int iJitBufSize ); void CreateReqJitBufMes(); + void CreateServerFullMes(); void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ); void CreateChanGainMes ( const int iChanID, const double dGain ); @@ -125,10 +127,11 @@ protected: void CreateAndSendMessage ( const int iID, const CVector& vecData ); - void EvaluateJitBufMes ( unsigned int iPos, const CVector& vecData ); - void EvaluateReqJitBufMes ( unsigned int iPos, const CVector& vecData ); - void EvaluateNetwBlSiFactMes ( unsigned int iPos, const CVector& vecData ); - void EvaluateChanGainMes ( unsigned int iPos, const CVector& vecData ); + void EvaluateJitBufMes ( unsigned int iPos, const CVector& vecData ); + void EvaluateReqJitBufMes ( unsigned int iPos, const CVector& vecData ); + void EvaluateServerFullMes ( unsigned int iPos, const CVector& vecData ); + void EvaluateNetwBlSiFactMes ( unsigned int iPos, const CVector& vecData ); + void EvaluateChanGainMes ( unsigned int iPos, const CVector& vecData ); void EvaluateConClientListMes ( unsigned int iPos, const CVector& vecData ); int iOldRecID, iOldRecCnt; @@ -153,6 +156,7 @@ signals: void ChangeChanGain ( int iChanID, double dNewGain ); void ConClientListMesReceived ( CVector vecChanInfo ); void ReqJittBufSize(); + void ServerFull(); }; diff --git a/src/server.cpp b/src/server.cpp index af977f10..9407fcc2 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -85,9 +85,9 @@ void CServer::Stop() void CServer::OnTimer() { - CVector vecChanID; - CVector > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES ); - CVector vecdGains; + CVector vecChanID; + CVector > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES ); + CVector vecdGains; /* get data from all connected clients */ ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData, vecdGains ); @@ -97,15 +97,14 @@ void CServer::OnTimer() one client is connected */ if ( iNumClients != 0 ) { - -// TODO generate a sparate mix for each channel - - /* actual processing of audio data -> mix */ - vecsSendData = ProcessData ( vecvecdData, vecdGains ); - - /* send the same data to all connected clients */ for ( int i = 0; i < iNumClients; i++ ) { +// TODO generate a sparate mix for each channel + +// actual processing of audio data -> mix +vecsSendData = ProcessData ( vecvecdData, vecdGains ); + + // send separate mix to current clients Socket.SendPacket ( ChannelSet.PrepSendPacket ( vecChanID[i], vecsSendData ), ChannelSet.GetAddress ( vecChanID[i] ) ); @@ -139,16 +138,14 @@ void CServer::OnTimer() } CVector CServer::ProcessData ( CVector >& vecvecdData, - CVector& vecdGains ) + CVector& vecdGains ) { - CVector vecsOutData; - vecsOutData.Init ( MIN_BLOCK_SIZE_SAMPLES ); + CVector vecsOutData ( MIN_BLOCK_SIZE_SAMPLES ); const int iNumClients = vecvecdData.Size(); - /* we normalize with sqrt() of N to avoid that the level drops too much - in case that a new client connects */ - const double dNorm = sqrt ( (double) iNumClients ); + // 3 dB offset to avoid overload if all clients are set to gain 1 + const double dNorm = (double) 2.0; /* mix all audio data from all clients together */ for ( int i = 0; i < MIN_BLOCK_SIZE_SAMPLES; i++ )