From bb76f4d911ee6695414cdaee23cc8c8ef41a7b8a Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sun, 5 Nov 2006 10:09:32 +0000 Subject: [PATCH] some cleanup of protocol implementation, cleanup main client GUI a bit, new version number --- src/channel.cpp | 6 ++ src/channel.h | 1 + src/client.cpp | 18 +++- src/client.h | 9 +- src/clientsettingsdlg.cpp | 8 +- src/clientsettingsdlgbase.ui | 112 +++++++++++++++++--- src/global.h | 3 +- src/llconclientdlg.cpp | 35 ++++-- src/llconclientdlgbase.ui | 13 +-- src/protocol.cpp | 200 +++++++++++++++++++---------------- src/protocol.h | 13 ++- src/util.cpp | 2 +- 12 files changed, 277 insertions(+), 143 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index b542fde6..c70e5b95 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -485,10 +485,16 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) { if ( Protocol.ParseMessage ( vecbyData, iNumBytes ) ) { eRet = PS_PROT_OK; + + // create message for protocol status + emit ProtocolStatus ( true ); } else { eRet = PS_PROT_ERR; + + // create message for protocol status + emit ProtocolStatus ( false ); } } } diff --git a/src/channel.h b/src/channel.h index bef76025..428388bd 100755 --- a/src/channel.h +++ b/src/channel.h @@ -172,6 +172,7 @@ signals: void MessReadyForSending ( CVector vecMessage ); void NewConnection(); void ReqJittBufSize(); + void ProtocolStatus ( bool bOk ); }; diff --git a/src/client.cpp b/src/client.cpp index d38fe84c..5abd362c 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -38,6 +38,9 @@ CClient::CClient () : bRun ( false ), Socket ( &Channel ), QObject::connect ( &Channel, SIGNAL ( ReqJittBufSize() ), this, SLOT ( OnReqJittBufSize() ) ); + + QObject::connect ( &Channel, SIGNAL ( ProtocolStatus ( bool ) ), + this, SLOT ( OnProtocolStatus ( bool ) ) ); } void CClient::OnSendProtMessage ( CVector vecMessage ) @@ -79,7 +82,20 @@ bool CClient::SetServerAddr(QString strNAddr) { return false; /* invalid address */ } -} +} + +void CClient::OnProtocolStatus ( bool bOk ) +{ + // show protocol status in GUI + if ( bOk ) + { + PostWinMessage ( MS_PROTOCOL, MUL_COL_LED_RED ); + } + else + { + PostWinMessage ( MS_PROTOCOL, MUL_COL_LED_GREEN ); + } +} void CClient::Init() { diff --git a/src/client.h b/src/client.h index 425b5cf7..79a0a282 100755 --- a/src/client.h +++ b/src/client.h @@ -8,16 +8,16 @@ * * 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 + * 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 + * 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 + * 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., + * this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * \******************************************************************************/ @@ -164,6 +164,7 @@ protected: public slots: void OnSendProtMessage ( CVector vecMessage ); void OnReqJittBufSize(); + void OnProtocolStatus ( bool bOk ); }; diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 757ced62..765ee064 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -158,13 +158,17 @@ void CClientSettingsDlg::SetStatus ( const int iMessType, const int iStatus ) case MS_JIT_BUF_GET: CLEDNetwGet->SetLight(iStatus); - break; + break; + + case MS_PROTOCOL: + CLEDProtocolStatus->SetLight(iStatus); case MS_RESET_ALL: CLEDSoundIn->Reset(); CLEDSoundOut->Reset(); CLEDNetwPut->Reset(); - CLEDNetwGet->Reset(); + CLEDNetwGet->Reset(); + CLEDProtocolStatus->Reset(); break; } } diff --git a/src/clientsettingsdlgbase.ui b/src/clientsettingsdlgbase.ui index eeb19627..ff751afb 100755 --- a/src/clientsettingsdlgbase.ui +++ b/src/clientsettingsdlgbase.ui @@ -11,8 +11,8 @@ 0 0 - 361 - 263 + 410 + 249 @@ -322,6 +322,13 @@ name GroupBoxSoundCardBuffers + + sizePolicy + + 1 + 5 + + title Sndcard Buffers @@ -374,7 +381,7 @@ sizePolicy - 3 + 1 1 @@ -442,7 +449,7 @@ sizePolicy - 3 + 1 1 @@ -573,6 +580,13 @@ name GroupBoxMeasureResults + + sizePolicy + + 3 + 5 + + title Debug @@ -587,26 +601,92 @@ 6 - QLabel + QLayoutWidget name - TextLabelStdDevTimerLabel - - - text - StdDev: + Layout6 + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + TextLabelStdDevTimerLabel + + + text + StdDev: + + + + QLabel + + name + TextLabelStdDevTimer + + + text + val + + + - QLabel + QLayoutWidget name - TextLabelStdDevTimer - - - text - val + Layout8 + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + TextLabel1_2 + + + text + Protocol Status: + + + + CMultiColorLED + + name + CLEDProtocolStatus + + + minimumSize + + 13 + 13 + + + + maximumSize + + 13 + 13 + + + + diff --git a/src/global.h b/src/global.h index 4e1ce9d7..a756c272 100755 --- a/src/global.h +++ b/src/global.h @@ -42,7 +42,7 @@ /* version and application name (always use this version) */ #undef VERSION -#define VERSION "0.9.7cvs" +#define VERSION "0.9.8cvs" #define APP_NAME "llcon" @@ -124,6 +124,7 @@ typedef unsigned int _MESSAGE_IDENT; #define MS_JIT_BUF_PUT 3 #define MS_JIT_BUF_GET 4 #define MS_PACKET_RECEIVED 5 +#define MS_PROTOCOL 6 #define MUL_COL_LED_RED 0 #define MUL_COL_LED_YELLOW 1 diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 4aeb5c4d..bb740100 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -44,9 +44,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, "to be specified before. If the client is connected, pressing this " "button will disconnect the connection.")); - QWhatsThis::add(TextLabelNameVersion, tr("Version: Shows the " - "current version of the software.")); - QWhatsThis::add(TextLabelStatus, tr("Status Bar: In the status bar " "different messages are displayed. E.g., if an error ocurred or the " "status of the connection is shown.")); @@ -55,11 +52,33 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, "the IP address of the server can be set. If an invalid address was " "chosen, an error message is shown in the status bar."); QWhatsThis::add(TextLabelServerAddr, strServAddrH); - QWhatsThis::add(LineEditServerAddr, strServAddrH); - - /* set text for version and application name */ - TextLabelNameVersion-> - setText(QString(APP_NAME) + tr(" client ") + QString(VERSION)); + QWhatsThis::add(LineEditServerAddr, strServAddrH); + + QString strAudFader = tr ( "Audio Fader: With the audio fader " + "control the level of left and right audio input channels can " + "be controlled." ); + QWhatsThis::add ( TextAudInFader, strAudFader ); + QWhatsThis::add ( SliderAudInFader, strAudFader ); + + QString strAudReverb = tr ( "Reverberation Level: The level of " + "reverberation effect can be set with this control. The channel to " + "which that reverberation effect shall be applied can be chosen " + "with the Reverberation Channel Selection radio buttons." ); + QWhatsThis::add ( TextLabelAudReverb, strAudReverb ); + QWhatsThis::add ( SliderAudReverb, strAudReverb ); + + QString strRevChanSel = tr ( "Reverberation Channel Selection: " + "With these radio buttons the audio input channel on which the " + "reverberation effect is applied can be chosen. Either the left " + "or right input channel can be selected." ); + QWhatsThis::add ( TextLabelReverbSelection, strRevChanSel ); + QWhatsThis::add ( RadioButtonRevSelL, strRevChanSel ); + QWhatsThis::add ( RadioButtonRevSelR, strRevChanSel ); + + QWhatsThis::add ( CLEDOverallStatus, tr ( "Overall Status: " + "The overall status of the software is shown. If either the " + "network or sound interface has bad status, this LED will show " + "red color." ) ); /* init server address line edit */ LineEditServerAddr->setText ( pClient->strIPAddress.c_str () ); diff --git a/src/llconclientdlgbase.ui b/src/llconclientdlgbase.ui index fe6c9508..aea1117f 100755 --- a/src/llconclientdlgbase.ui +++ b/src/llconclientdlgbase.ui @@ -318,17 +318,6 @@ spacing 6 - - QLabel - - name - TextLabelNameVersion - - - text - TextLabelNameVersion - - name @@ -587,7 +576,7 @@ Level text - Reverb Chan. + Reverb Chan Selection diff --git a/src/protocol.cpp b/src/protocol.cpp index dbfc281b..0d360c9a 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -230,11 +230,9 @@ bool CProtocol::ParseMessage ( const CVector& vecbyData, return code: true -> ok; false -> error */ bool bRet, bSendNextMess; - int iRecCounter, iRecID, iData, iDataLen, iStringLen, iCurID; + int iRecCounter, iRecID; unsigned int iPos; CVector vecData; - std::string strCurString; - double dNewGain; // convert unsigned char in uint8_t, TODO convert all buffers in uint8_t @@ -262,14 +260,13 @@ for ( int i = 0; i < iNumBytes; i++ ) { } else { - // check which type of message we received and do action - switch ( iRecID ) + // special treatment for acknowledge messages + if ( iRecID == PROTMESSID_ACKN ) { - case PROTMESSID_ACKN: - // extract data from stream and emit signal for received value iPos = 0; - iData = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + const int iData = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); Mutex.lock(); { @@ -294,105 +291,44 @@ for ( int i = 0; i < iNumBytes; i++ ) { { SendMessage(); } - - break; - - case PROTMESSID_JITT_BUF_SIZE: - - // extract data from stream and emit signal for received value - iPos = 0; - iData = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); - - // invoke message action - emit ChangeJittBufSize ( iData ); - - // send acknowledge message - CreateAndSendAcknMess ( iRecID, iRecCounter ); - - break; - - case PROTMESSID_REQ_JITT_BUF_SIZE: - - // invoke message action - emit ReqJittBufSize(); - - // send acknowledge message - CreateAndSendAcknMess ( iRecID, iRecCounter ); - - break; - - case PROTMESSID_NET_BLSI_FACTOR: - - // extract data from stream and emit signal for received value - iPos = 0; - iData = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); - - // invoke message action - emit ChangeNetwBlSiFact ( iData ); - - // send acknowledge message - CreateAndSendAcknMess ( iRecID, iRecCounter ); - - break; - - case PROTMESSID_CHANNEL_GAIN: - - // extract data from stream and emit signal for received value + } + else + { + // init position pointer which is used for extracting data from + // received data vector iPos = 0; - // channel ID - iCurID = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); - - // actual gain, we convert from integer to double with range 0..1 - iData = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); - dNewGain = (double) iData / ( 1 << 16 ); - - // invoke message action - emit ChangeChanGain ( iCurID, dNewGain ); - - // send acknowledge message - CreateAndSendAcknMess ( iRecID, iRecCounter ); - - break; - - case PROTMESSID_CONN_CLIENTS_LIST: - - // extract data from stream and emit signal for received value - iPos = 0; - iDataLen = vecData.Size(); - - while ( iPos < iDataLen ) + // check which type of message we received and do action + switch ( iRecID ) { + case PROTMESSID_JITT_BUF_SIZE: - // IP address (4 bytes) - iData = static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + EvaluateJitBufMes ( iPos, vecData ); + break; -// TODO do something with the received IP address "iData" + case PROTMESSID_REQ_JITT_BUF_SIZE: -// TEST -QHostAddress addrTest ( iData ); -printf ( "%s ", addrTest.toString().latin1() ); + EvaluateReqJitBufMes ( iPos, vecData ); + break; - // number of bytes for name string (2 bytes) - iStringLen = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + case PROTMESSID_NET_BLSI_FACTOR: - // name string (n bytes) - strCurString = ""; - for ( int j = 0; j < iStringLen; j++ ) - { - // byte-by-byte copying of the string data - iData = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); - strCurString += std::string ( (char*) &iData ); - } + EvaluateNetwBlSiFactMes ( iPos, vecData ); + break; -// TODO do something with the received name string "strCurString" + case PROTMESSID_CHANNEL_GAIN: + EvaluateChanGainMes ( iPos, vecData ); + break; + + case PROTMESSID_CONN_CLIENTS_LIST: + + EvaluateConClientListMes ( iPos, vecData ); + break; } // send acknowledge message CreateAndSendAcknMess ( iRecID, iRecCounter ); - - break; } } @@ -411,7 +347,7 @@ printf ( "%s ", addrTest.toString().latin1() ); } -/* Access-functions for creating messages ----------------------------------- */ +/* Access-functions for creating and parsing messages ----------------------- */ void CProtocol::CreateJitBufMes ( const int iJitBufSize ) { CVector vecData ( 2 ); // 2 bytes of data @@ -423,11 +359,27 @@ void CProtocol::CreateJitBufMes ( const int iJitBufSize ) CreateAndSendMessage ( PROTMESSID_JITT_BUF_SIZE, vecData ); } +void CProtocol::EvaluateJitBufMes ( unsigned int iPos, const CVector& vecData ) +{ + // extract jitter buffer size + const int iData = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + // invoke message action + emit ChangeJittBufSize ( iData ); +} + void CProtocol::CreateReqJitBufMes() { CreateAndSendMessage ( PROTMESSID_REQ_JITT_BUF_SIZE, CVector ( 0 ) ); } +void CProtocol::EvaluateReqJitBufMes ( unsigned int iPos, const CVector& vecData ) +{ + // invoke message action + emit ReqJittBufSize(); +} + void CProtocol::CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) { CVector vecData ( 2 ); // 2 bytes of data @@ -439,6 +391,15 @@ void CProtocol::CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) CreateAndSendMessage ( PROTMESSID_NET_BLSI_FACTOR, vecData ); } +void CProtocol::EvaluateNetwBlSiFactMes ( unsigned int iPos, const CVector& vecData ) +{ + const int iData = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + // invoke message action + emit ChangeNetwBlSiFact ( iData ); +} + void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) { CVector vecData ( 4 ); // 4 bytes of data @@ -455,6 +416,22 @@ void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) CreateAndSendMessage ( PROTMESSID_CHANNEL_GAIN, vecData ); } +void CProtocol::EvaluateChanGainMes ( unsigned int iPos, const CVector& vecData ) +{ + // channel ID + const int iCurID = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + // actual gain, we convert from integer to double with range 0..1 + const int iData = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + const double dNewGain = (double) iData / ( 1 << 16 ); + + // invoke message action + emit ChangeChanGain ( iCurID, dNewGain ); +} + void CProtocol::CreateConClientListMes ( const CVector& veciIpAddrs, const CVector& vecstrNames ) { @@ -496,6 +473,41 @@ void CProtocol::CreateConClientListMes ( const CVector& veciIpAddrs, CreateAndSendMessage ( PROTMESSID_CONN_CLIENTS_LIST, vecData ); } +void CProtocol:: EvaluateConClientListMes ( unsigned int iPos, const CVector& vecData ) +{ + int iData; + const int iDataLen = vecData.Size(); + + while ( iPos < iDataLen ) + { + + // IP address (4 bytes) + iData = static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + +// TODO do something with the received IP address "iData" + +// TEST +QHostAddress addrTest ( iData ); +printf ( "%s ", addrTest.toString().latin1() ); + + // number of bytes for name string (2 bytes) + const int iStringLen = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + // name string (n bytes) + std::string strCurString = ""; + for ( int j = 0; j < iStringLen; j++ ) + { + // byte-by-byte copying of the string data + iData = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + strCurString += std::string ( (char*) &iData ); + } + +// TODO do something with the received name string "strCurString" + + } +} + /******************************************************************************\ * Message generation (parsing) * diff --git a/src/protocol.h b/src/protocol.h index 02c3bf4f..859f3bb0 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -45,11 +45,11 @@ #define PROTMESSID_CONN_CLIENTS_LIST 15 // connected client list // lengths of message as defined in protocol.cpp file -#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */ -#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ ) +#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */ +#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ ) // time out for message re-send if no acknowledgement was received -#define SEND_MESS_TIMEOUT_MS 400 // ms +#define SEND_MESS_TIMEOUT_MS 400 // ms /* Classes ********************************************************************/ @@ -59,7 +59,6 @@ class CProtocol : public QObject public: CProtocol(); - virtual ~CProtocol() {} void CreateJitBufMes ( const int iJitBufSize ); void CreateReqJitBufMes(); @@ -127,6 +126,12 @@ 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 EvaluateConClientListMes ( unsigned int iPos, const CVector& vecData ); + int iOldRecID, iOldRecCnt; // these two objects must be sequred by a mutex diff --git a/src/util.cpp b/src/util.cpp index 33582b42..c8c94898 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -315,7 +315,7 @@ QString CAboutDlg::GetVersionAndNameStr ( const bool bWithHtml ) strVersionText += "\n"; } - strVersionText += tr("llcon, Low-Latency (Internet) Connection"); + strVersionText += tr("llcon, Low-Latency (internet) CONnection"); if ( bWithHtml ) {