diff --git a/src/channel.cpp b/src/channel.cpp index d16b18e1..217510c0 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -229,8 +229,7 @@ CChannel::CChannel () SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL ); // set initial input and output block size factors - SetNetwInBlSiFact ( NET_BLOCK_SIZE_FACTOR ); - SetNetwOutBlSiFact ( NET_BLOCK_SIZE_FACTOR ); + SetNetwBufSizeFact ( NET_BLOCK_SIZE_FACTOR ); /* init time-out for the buffer with zero -> no connection */ iConTimeOut = 0; @@ -246,6 +245,9 @@ CChannel::CChannel () QObject::connect ( &Protocol, SIGNAL ( ReqJittBufSize() ), SIGNAL ( ReqJittBufSize() ) ); + + QObject::connect ( &Protocol, SIGNAL ( ChangeNetwBlSiFact ( int ) ), + this, SLOT ( OnNetwBlSiFactChange ( int ) ) ); } void CChannel::SetNetwInBlSiFact ( const int iNewBlockSizeFactor ) @@ -288,7 +290,9 @@ void CChannel::OnSendProtMessage ( CVector vecMessage ) Protocol.DeleteSendMessQueue(); } } - + + +// socket buffer size void CChannel::SetSockBufSize ( const int iNumBlocks ) { /* this opperation must be done with mutex */ @@ -319,7 +323,31 @@ qDebug ( "new jitter buffer size: %d", iNewJitBufSize ); SetSockBufSize ( iNewJitBufSize ); } - + + +// network buffer size factor +void CChannel::SetNetwBufSizeFact ( const int iNetNetwBlSiFact ) +{ + /* this opperation must be done with mutex */ + Mutex.lock (); + { + iCurNetwBlSiFact = iNetNetwBlSiFact; + + SetNetwInBlSiFact ( iNetNetwBlSiFact ); + SetNetwOutBlSiFact ( iNetNetwBlSiFact ); + } + Mutex.unlock (); +} + +void CChannel::OnNetwBlSiFactChange ( int iNewNetwBlSiFact ) +{ +// TEST +qDebug ( "new network block size factor: %d", iNewNetwBlSiFact ); + + SetNetwBufSizeFact ( iNewNetwBlSiFact ); +} + + bool CChannel::GetAddress(CHostAddress& RetAddr) { if (IsConnected()) @@ -403,7 +431,7 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) { // TEST debug output CHostAddress address ( GetAddress() ); -qDebug ( "new connection with IP %s\n", address.InetAddr.toString().latin1() ); +qDebug ( "new connection with IP %s", address.InetAddr.toString().latin1() ); emit NewConnection(); } diff --git a/src/channel.h b/src/channel.h index 5e2aee75..04e54c62 100755 --- a/src/channel.h +++ b/src/channel.h @@ -83,6 +83,9 @@ public: void SetSockBufSize ( const int iNumBlocks ); int GetSockBufSize(); + void SetNetwBufSizeFact ( const int iNetNetwBlSiFact ); + int GetNetwBufSizeFact() { return iCurNetwBlSiFact; } + // network protocol interface void CreateJitBufMes ( const int iJitBufSize ) { @@ -91,9 +94,17 @@ public: Protocol.CreateJitBufMes ( iJitBufSize ); } } - void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } + void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) + { + if ( IsConnected() ) + { + Protocol.CreateNetwBlSiFactMes ( iNetwBlSiFact ); + } + } + + protected: void SetNetwInBlSiFact ( const int iNewBlockSizeFactor ); void SetNetwOutBlSiFact ( const int iNewBlockSizeFactor ); @@ -129,13 +140,16 @@ protected: int iConTimeOut; int iConTimeOutStartVal; - int iCurNetwInBlSiFact; + int iCurNetwInBlSiFact; + + int iCurNetwBlSiFact; // TODO, will be replaced by in/out settings QMutex Mutex; public slots: void OnSendProtMessage ( CVector vecMessage ); void OnJittBufSizeChange ( int iNewJitBufSize ); + void OnNetwBlSiFactChange ( int iNewNetwBlSiFact ); signals: void MessReadyForSending ( CVector vecMessage ); diff --git a/src/client.h b/src/client.h index cc9a4930..3f282e85 100755 --- a/src/client.h +++ b/src/client.h @@ -57,34 +57,33 @@ class CClient : public QObject, public QThread public: CClient(); - virtual ~CClient () {} + virtual ~CClient() {} - void Init (); - bool Stop (); - bool IsRunning () { return bRun; } + void Init(); + bool Stop(); + bool IsRunning() { return bRun; } bool SetServerAddr ( QString strNAddr ); - double MicLevelL () { return SignalLevelMeterL.MicLevel (); } - double MicLevelR () { return SignalLevelMeterR.MicLevel (); } - bool IsConnected () { return Channel.IsConnected (); } + double MicLevelL() { return SignalLevelMeterL.MicLevel(); } + double MicLevelR() { return SignalLevelMeterR.MicLevel(); } + bool IsConnected() { return Channel.IsConnected(); } /* we want to return the standard deviation. For that we need to calculate the sqaure root */ - double GetTimingStdDev () { return sqrt ( RespTimeMoAvBuf.GetAverage () ); } + double GetTimingStdDev() { return sqrt ( RespTimeMoAvBuf.GetAverage() ); } - int GetAudioInFader () { return iAudioInFader; } + int GetAudioInFader() { return iAudioInFader; } void SetAudioInFader ( const int iNV ) { iAudioInFader = iNV; } - int GetReverbLevel () { return iReverbLevel; } + int GetReverbLevel() { return iReverbLevel; } void SetReverbLevel ( const int iNL ) { iReverbLevel = iNL; } - bool IsReverbOnLeftChan () { return bReverbOnLeftChan; } + bool IsReverbOnLeftChan() { return bReverbOnLeftChan; } void SetReverbOnLeftChan ( const bool bIL ) { bReverbOnLeftChan = bIL; - AudioReverb.Clear (); + AudioReverb.Clear(); } - void SetSockBufSize ( const int iNumBlocks ) { // set the new socket size @@ -93,11 +92,23 @@ public: // tell the server that size has changed Channel.CreateJitBufMes ( iNumBlocks ); } - int GetSockBufSize () { return Channel.GetSockBufSize (); } + int GetSockBufSize() { return Channel.GetSockBufSize (); } + + + + void SetNetwBufSizeFact ( const int iNetNetwBlSiFact ) + { + // set the new socket size + Channel.SetNetwBufSizeFact ( iNetNetwBlSiFact ); + + // tell the server that size has changed + Channel.CreateNetwBlSiFactMes ( iNetNetwBlSiFact ); + } + int GetNetwBufSizeFact() { return Channel.GetNetwBufSizeFact(); } - CSound* GetSndInterface () { return &Sound; } - CChannel* GetChannel () { return &Channel; } + CSound* GetSndInterface() { return &Sound; } + CChannel* GetChannel() { return &Channel; } // settings diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 5af64a81..24dbe696 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -58,8 +58,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, /* set text for version and application name */ TextLabelNameVersion-> - setText(QString(APP_NAME) + tr(" client ") + QString(VERSION) + - " (" + QString().setNum(MIN_BLOCK_DURATION_MS * NET_BLOCK_SIZE_FACTOR) + " ms)"); + setText(QString(APP_NAME) + tr(" client ") + QString(VERSION)); /* init server address line edit */ LineEditServerAddr->setText ( pClient->strIPAddress.c_str () ); @@ -99,6 +98,12 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, SliderNetBuf->setValue(iCurNumNetBuf); TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf)); + /* network buffer size factor */ + SliderNetBufSiFact->setRange(1, NET_BLOCK_SIZE_FACTOR_MAX); + const int iCurNetBufSiFact = pClient->GetNetwBufSizeFact(); + SliderNetBufSiFact->setValue(iCurNetBufSiFact); + TextNetBufSiFact->setText("Fact.: " + QString().setNum(iCurNetBufSiFact)); + /* audio in fader */ SliderAudInFader->setRange(0, AUD_FADER_IN_MAX); const int iCurAudInFader = pClient->GetAudioInFader(); @@ -145,9 +150,12 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, QObject::connect(SliderSndBufIn, SIGNAL(valueChanged(int)), this, SLOT(OnSliderSndBufInChange(int))); QObject::connect(SliderSndBufOut, SIGNAL(valueChanged(int)), - this, SLOT(OnSliderSndBufOutChange(int))); + this, SLOT(OnSliderSndBufOutChange(int))); + QObject::connect(SliderNetBuf, SIGNAL(valueChanged(int)), this, SLOT(OnSliderNetBuf(int))); + QObject::connect(SliderNetBufSiFact, SIGNAL(valueChanged(int)), + this, SLOT(OnSliderNetBufSiFact(int))); QObject::connect(SliderAudInFader, SIGNAL(valueChanged(int)), this, SLOT(OnSliderAudInFader(int))); @@ -240,6 +248,12 @@ void CLlconClientDlg::OnSliderNetBuf(int value) pClient->SetSockBufSize ( value ); TextNetBuf->setText("Size: " + QString().setNum(value)); } + +void CLlconClientDlg::OnSliderNetBufSiFact(int value) +{ + pClient->SetNetwBufSizeFact ( value ); + TextNetBufSiFact->setText("Fact.: " + QString().setNum(value)); +} void CLlconClientDlg::OnTimerSigMet () { diff --git a/src/llconclientdlg.h b/src/llconclientdlg.h index c136540e..aac3273d 100755 --- a/src/llconclientdlg.h +++ b/src/llconclientdlg.h @@ -88,6 +88,7 @@ public slots: void OnSliderSndBufInChange ( int value ); void OnSliderSndBufOutChange ( int value ); void OnSliderNetBuf ( int value ); + void OnSliderNetBufSiFact ( int value ); void OnSliderAudInFader ( int value ) { pClient->SetAudioInFader(value); } void OnSliderAudReverb ( int value ) { pClient->SetReverbLevel ( AUD_REVERB_MAX - value ); } diff --git a/src/llconclientdlgbase.ui b/src/llconclientdlgbase.ui index 509d3523..fafcb72c 100755 --- a/src/llconclientdlgbase.ui +++ b/src/llconclientdlgbase.ui @@ -11,8 +11,8 @@ 0 0 - 814 - 287 + 890 + 288 @@ -733,6 +733,64 @@ + + QGroupBox + + name + GroupBoxNetwBuf + + + title + Block Size + + + + margin + 11 + + + spacing + 6 + + + QLabel + + name + TextNetBufSiFact + + + text + Size + + + alignment + AlignCenter + + + hAlign + + + + QSlider + + name + SliderNetBufSiFact + + + pageStep + 1 + + + orientation + Vertical + + + tickmarks + Both + + + + QGroupBox diff --git a/src/llconserverdlg.cpp b/src/llconserverdlg.cpp index 88acef31..8495c726 100755 --- a/src/llconserverdlg.cpp +++ b/src/llconserverdlg.cpp @@ -32,8 +32,7 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent, { /* set text for version and application name */ TextLabelNameVersion-> - setText(QString(APP_NAME) + tr(" server ") + QString(VERSION) + - " (" + QString().setNum(MIN_BLOCK_DURATION_MS * NET_BLOCK_SIZE_FACTOR) + " ms)"); + setText(QString(APP_NAME) + tr(" server ") + QString(VERSION)); /* Create bitmaps */ /* Define size of the bitmaps */ diff --git a/src/protocol.cpp b/src/protocol.cpp index 2988103a..0b1070f0 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -30,7 +30,7 @@ MAIN FRAME MESSAGES -------- -- Acknowledgement message: PROTMESSID_ACKN +- Acknowledgement message: PROTMESSID_ACKN +-----------------------------------+ | 2 bytes ID of message to be ackn. | @@ -39,16 +39,23 @@ MESSAGES note: the cnt value is the same as of the message to be acknowledged -- Jitter buffer size: PROTMESSID_JITT_BUF_SIZE +- Jitter buffer size: PROTMESSID_JITT_BUF_SIZE +--------------------------+ | 2 bytes number of blocks | +--------------------------+ -- Request jitter buffer size: PROTMESSID_REQ_JITT_BUF_SIZE +- Request jitter buffer size: PROTMESSID_REQ_JITT_BUF_SIZE note: does not have any data -> n = 0 +- network buffer block size factor PROTMESSID_NET_BLSI_FACTOR + + note: size, relative to minimum block size + + +----------------+ + | 2 bytes factor | + +----------------+ @@ -297,6 +304,20 @@ vecbyDataConv[i] = static_cast ( vecbyData[i] ); // 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; } } @@ -333,6 +354,17 @@ void CProtocol::CreateReqJitBufMes() CreateAndSendMessage ( PROTMESSID_REQ_JITT_BUF_SIZE, CVector ( 0 ) ); } +void CProtocol::CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) +{ + CVector vecData ( 2 ); // 2 bytes of data + unsigned int iPos = 0; // init position pointer + + // build data vector + PutValOnStream ( vecData, iPos, static_cast ( iNetwBlSiFact ), 2 ); + + CreateAndSendMessage ( PROTMESSID_NET_BLSI_FACTOR, vecData ); +} + /******************************************************************************\ * Message generation (parsing) * diff --git a/src/protocol.h b/src/protocol.h index ec0d9bf8..9828923a 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -40,6 +40,7 @@ #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 // lengths of message as defined in protocol.cpp file #define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */ @@ -60,6 +61,7 @@ public: void CreateJitBufMes ( const int iJitBufSize ); void CreateReqJitBufMes(); + void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ); void CreateAndSendAcknMess ( const int& iID, const int& iCnt ); @@ -137,6 +139,7 @@ signals: // receiving void ChangeJittBufSize ( int iNewJitBufSize ); + void ChangeNetwBlSiFact ( int iNewNetwBlSiFact ); void ReqJittBufSize(); }; diff --git a/src/settings.cpp b/src/settings.cpp index a156ecbc..1d3d6c0d 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -26,16 +26,16 @@ /* Implementation *************************************************************/ -void CSettings::Load () +void CSettings::Load() { /* load settings from init-file */ - ReadIniFile (); + ReadIniFile(); } void CSettings::Save() { /* write settings in init-file */ - WriteIniFile (); + WriteIniFile(); } @@ -81,6 +81,11 @@ void CSettings::ReadIniFile() if ( GetNumericIniSet(ini, "Client", "jitbuf", 0, MAX_NET_BUF_SIZE_NUM_BL, iValue ) == TRUE ) { pClient->SetSockBufSize ( iValue ); } + + // network buffer size factor + if ( GetNumericIniSet(ini, "Client", "netwbusifact", 1, NET_BLOCK_SIZE_FACTOR_MAX, iValue ) == TRUE ) { + pClient->SetNetwBufSizeFact ( iValue ); + } } void CSettings::WriteIniFile() @@ -91,22 +96,25 @@ void CSettings::WriteIniFile() PutIniSetting ( ini, "Client", "ipaddress", pClient->strIPAddress.c_str() ); // audio fader - SetNumericIniSet ( ini, "Client", "audfad", pClient->GetAudioInFader () ); + SetNumericIniSet ( ini, "Client", "audfad", pClient->GetAudioInFader() ); // reverberation level - SetNumericIniSet ( ini, "Client", "revlev", pClient->GetReverbLevel () ); + SetNumericIniSet ( ini, "Client", "revlev", pClient->GetReverbLevel() ); // reverberation channel assignment - SetFlagIniSet ( ini, "Client", "reverblchan", pClient->IsReverbOnLeftChan () ); + SetFlagIniSet ( ini, "Client", "reverblchan", pClient->IsReverbOnLeftChan() ); // sound card in number of buffers - SetNumericIniSet ( ini, "Client", "audinbuf", pClient->GetSndInterface()->GetInNumBuf () ); + SetNumericIniSet ( ini, "Client", "audinbuf", pClient->GetSndInterface()->GetInNumBuf() ); // sound card out number of buffers - SetNumericIniSet ( ini, "Client", "audoutbuf", pClient->GetSndInterface()->GetOutNumBuf () ); + SetNumericIniSet ( ini, "Client", "audoutbuf", pClient->GetSndInterface()->GetOutNumBuf() ); // network jitter buffer size - SetNumericIniSet ( ini, "Client", "jitbuf", pClient->GetSockBufSize () ); + SetNumericIniSet ( ini, "Client", "jitbuf", pClient->GetSockBufSize() ); + + // network buffer size factor + SetNumericIniSet ( ini, "Client", "netwbusifact", pClient->GetNetwBufSizeFact() ); /* Save settings in init-file */ @@ -121,7 +129,7 @@ bool CSettings::GetNumericIniSet ( INIFile& theINI, string strSection, bool bReturn = FALSE; const string strGetIni = - GetIniSetting ( theINI, strSection.c_str (), strKey.c_str () ); + GetIniSetting ( theINI, strSection.c_str(), strKey.c_str() ); /* Check if it is a valid parameter */ if ( !strGetIni.empty () ) @@ -144,7 +152,7 @@ void CSettings::SetNumericIniSet ( INIFile& theINI, string strSection, char cString[256]; sprintf ( cString, "%d", iValue ); - PutIniSetting ( theINI, strSection.c_str (), strKey.c_str (), cString ); + PutIniSetting ( theINI, strSection.c_str(), strKey.c_str(), cString ); } bool CSettings::GetFlagIniSet ( INIFile& theINI, string strSection, @@ -154,11 +162,11 @@ bool CSettings::GetFlagIniSet ( INIFile& theINI, string strSection, bool bReturn = FALSE; const string strGetIni = - GetIniSetting ( theINI, strSection.c_str (), strKey.c_str () ); + GetIniSetting ( theINI, strSection.c_str(), strKey.c_str() ); - if ( !strGetIni.empty () ) + if ( !strGetIni.empty() ) { - if ( atoi ( strGetIni.c_str () ) ) + if ( atoi ( strGetIni.c_str() ) ) { bValue = TRUE; } @@ -178,11 +186,11 @@ void CSettings::SetFlagIniSet ( INIFile& theINI, string strSection, string strKe { if ( bValue == TRUE ) { - PutIniSetting ( theINI, strSection.c_str (), strKey.c_str (), "1" ); + PutIniSetting ( theINI, strSection.c_str(), strKey.c_str(), "1" ); } else { - PutIniSetting ( theINI, strSection.c_str (), strKey.c_str (), "0" ); + PutIniSetting ( theINI, strSection.c_str(), strKey.c_str(), "0" ); } }