diff --git a/src/buffer.cpp b/src/buffer.cpp index 8751c877..cab70344 100755 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -118,6 +118,12 @@ bool CNetBuf::Get ( CVector& vecbyData ) // get size of data to be get from the buffer const int iInSize = vecbyData.Size(); + // check size + if ( iInSize != iBlockSize ) + { + return false; + } + // Check if there is not enough data available -> correct if ( GetAvailData() < iInSize ) { @@ -250,7 +256,7 @@ void CNetBuf::Clear ( const EClearType eClearType ) iPutPos = 0; iGetPos = iMiddleOfBuffer; - /* check for special case */ + // check for special case if ( iPutPos == iGetPos ) { eBufState = CNetBuf::BS_FULL; diff --git a/src/channel.cpp b/src/channel.cpp index ba476352..3ebfe837 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -43,7 +43,7 @@ CChannel::CChannel ( const bool bNIsServer ) : iConTimeOut = 0; // init the socket buffer - SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL ); + SetSockBufNumFrames ( DEF_NET_BUF_SIZE_NUM_BL ); // connections ------------------------------------------------------------- @@ -145,19 +145,20 @@ void CChannel::SetNetwFrameSizeAndFact ( const int iNewNetwFrameSize, CreateNetTranspPropsMessFromCurrentSettings(); } -bool CChannel::SetSockBufSize ( const int iNumBlocks ) +bool CChannel::SetSockBufNumFrames ( const int iNewNumFrames ) { QMutexLocker locker ( &Mutex ); // this opperation must be done with mutex // first check for valid input parameter range - if ( ( iNumBlocks >= MIN_NET_BUF_SIZE_NUM_BL ) && - ( iNumBlocks <= MAX_NET_BUF_SIZE_NUM_BL ) ) + if ( ( iNewNumFrames >= MIN_NET_BUF_SIZE_NUM_BL ) && + ( iNewNumFrames <= MAX_NET_BUF_SIZE_NUM_BL ) ) { - iCurSockBufSize = iNumBlocks; + // store new value + iCurSockBufNumFrames = iNewNumFrames; - // the network block size is a multiple of the internal minimal + // the network block size is a multiple of the minimum network // block size - SockBuf.Init ( SYSTEM_BLOCK_FRAME_SAMPLES, iNumBlocks ); + SockBuf.Init ( iNetwFrameSize, iNewNumFrames ); return false; // -> no error } @@ -240,7 +241,7 @@ void CChannel::OnSendProtMessage ( CVector vecMessage ) void CChannel::OnJittBufSizeChange ( int iNewJitBufSize ) { - SetSockBufSize ( iNewJitBufSize ); + SetSockBufNumFrames ( iNewJitBufSize ); } void CChannel::OnChangeChanGain ( int iChanID, double dNewGain ) @@ -281,6 +282,13 @@ void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTranspor iNetwFrameSize = NetworkTransportProps.iNetworkPacketSize / NetworkTransportProps.iBlockSizeFact; + + // update socket buffer (the network block size is a multiple of the + // minimum network frame size + SockBuf.Init ( iNetwFrameSize, iCurSockBufNumFrames ); + + // fire message + emit NetwFrameSizeHasChanged ( iNetwFrameSize ); } } @@ -435,7 +443,7 @@ EGetDataStat CChannel::GetData ( CVector& vecbyData ) // where the atomic block size is "SYSTEM_BLOCK_FRAME_SAMPLES") // TODO this code only works with the above assumption -> better -// implementation so that we are not depending on assumptions +// implementation so that we are not depending on assumptions iConTimeOut -= SYSTEM_BLOCK_FRAME_SAMPLES; diff --git a/src/channel.h b/src/channel.h index a49090c9..7c2a47d8 100755 --- a/src/channel.h +++ b/src/channel.h @@ -88,8 +88,8 @@ public: void SetRemoteChanGain ( const int iId, const double dGain ) { Protocol.CreateChanGainMes ( iId, dGain ); } - bool SetSockBufSize ( const int iNumBlocks ); - int GetSockBufSize() const { return iCurSockBufSize; } + bool SetSockBufNumFrames ( const int iNewNumFrames ); + int GetSockBufNumFrames() const { return iCurSockBufNumFrames; } int GetUploadRateKbps(); @@ -145,7 +145,7 @@ protected: // network jitter-buffer CNetBuf SockBuf; - int iCurSockBufSize; + int iCurSockBufNumFrames; CCycleTimeVariance CycleTimeVariance; @@ -182,6 +182,7 @@ signals: void ReqConnClientsList(); void ConClientListMesReceived ( CVector vecChanInfo ); void NameHasChanged(); + void NetwFrameSizeHasChanged ( int iNewFrameSize ); void ChatTextReceived ( QString strChatText ); void PingReceived ( int iMs ); void ReqNetTranspProps(); diff --git a/src/client.cpp b/src/client.cpp index 8c0aabfe..4148b675 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -73,7 +73,7 @@ void CClient::OnSendProtMessage ( CVector vecMessage ) void CClient::OnReqJittBufSize() { // TODO cant we implement this OnReqJjittBufSize inside the channel object? - Channel.CreateJitBufMes ( Channel.GetSockBufSize() ); + Channel.CreateJitBufMes ( Channel.GetSockBufNumFrames() ); } void CClient::OnNewConnection() @@ -514,8 +514,8 @@ void CClient::UpdateSocketBufferSize() { // we are in the middle of the decision region, use // previous setting for determing the new decision - if ( !( ( GetSockBufSize() == iUpperHystDec ) || - ( GetSockBufSize() == iLowerHystDec ) ) ) + if ( !( ( GetSockBufNumFrames() == iUpperHystDec ) || + ( GetSockBufNumFrames() == iLowerHystDec ) ) ) { // The old result is not near the new decision, // use per definition the upper decision. diff --git a/src/client.h b/src/client.h index 39c32ec2..cfbdbcc9 100755 --- a/src/client.h +++ b/src/client.h @@ -93,13 +93,13 @@ public: void SetDoAutoSockBufSize ( const bool bValue ) { bDoAutoSockBufSize = bValue; } bool GetDoAutoSockBufSize() { return bDoAutoSockBufSize; } - void SetSockBufSize ( const int iNumBlocks ) + void SetSockBufNumFrames ( const int iNumBlocks ) { // only change parameter if new parameter is different from current one - if ( Channel.GetSockBufSize() != iNumBlocks ) + if ( Channel.GetSockBufNumFrames() != iNumBlocks ) { - // set the new socket size - if ( !Channel.SetSockBufSize ( iNumBlocks ) ) + // set the new socket size (number of frames) + if ( !Channel.SetSockBufNumFrames ( iNumBlocks ) ) { // if setting of socket buffer size was successful, // tell the server that size has changed @@ -107,7 +107,7 @@ public: } } } - int GetSockBufSize() { return Channel.GetSockBufSize(); } + int GetSockBufNumFrames() { return Channel.GetSockBufNumFrames(); } int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); } diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 27dc7602..971ed511 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -154,7 +154,7 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, void CClientSettingsDlg::UpdateJitterBufferFrame() { // update slider value and text - const int iCurNumNetBuf = pClient->GetSockBufSize(); + const int iCurNumNetBuf = pClient->GetSockBufNumFrames(); SliderNetBuf->setValue ( iCurNumNetBuf ); TextNetBuf->setText ( "Size: " + QString().setNum ( iCurNumNetBuf ) ); @@ -220,7 +220,7 @@ void CClientSettingsDlg::OnDriverSetupBut() void CClientSettingsDlg::OnSliderNetBuf ( int value ) { - pClient->SetSockBufSize ( value ); + pClient->SetSockBufNumFrames ( value ); UpdateJitterBufferFrame(); } @@ -296,7 +296,7 @@ void CClientSettingsDlg::OnPingTimeResult ( int iPingTime ) */ const int iTotalJitterBufferDelayMS = SYSTEM_BLOCK_DURATION_MS_FLOAT * - ( 2 /* buffer at client and server */ * pClient->GetSockBufSize() ) / 2; + ( 2 /* buffer at client and server */ * pClient->GetSockBufNumFrames() ) / 2; // we assume that we have two period sizes for the input and one for the // output, therefore we have "3 *" instead of "2 *" (for input and output) diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 2aa0b3c6..669ab69d 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -485,7 +485,7 @@ void CLlconClientDlg::customEvent ( QEvent* Event ) break; case MS_SET_JIT_BUF_SIZE: - pClient->SetSockBufSize ( iStatus ); + pClient->SetSockBufNumFrames ( iStatus ); break; } diff --git a/src/llconserverdlg.cpp b/src/llconserverdlg.cpp index f3f5a042..45e83933 100755 --- a/src/llconserverdlg.cpp +++ b/src/llconserverdlg.cpp @@ -77,13 +77,13 @@ void CLlconServerDlg::OnTimer() { CVector vecHostAddresses; CVector vecsName; - CVector veciJitBufSize; + CVector veciJitBufNumFrames; CVector veciNetwFrameSizeFact; double dCurTiStdDev; ListViewMutex.lock(); - pServer->GetConCliParam ( vecHostAddresses, vecsName, veciJitBufSize, + pServer->GetConCliParam ( vecHostAddresses, vecsName, veciJitBufNumFrames, veciNetwFrameSizeFact ); // fill list with connected clients @@ -101,7 +101,7 @@ void CLlconServerDlg::OnTimer() // jitter buffer size (polling for updates) vecpListViewItems[i]->setText ( 4, - QString().setNum ( veciJitBufSize[i] ) ); + QString().setNum ( veciJitBufNumFrames[i] ) ); // out network block size vecpListViewItems[i]->setText ( 5, diff --git a/src/server.cpp b/src/server.cpp index 8be9c83d..960ee0c2 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -318,6 +318,29 @@ void CServer::OnTimer() { for ( int i = 0; i < iNumClients; i++ ) { + + +/* +// TEST CELT +CVector vecsAudioSndCrdMono ( iMonoBlockSizeSam ); + +celt_decode ( CeltDecoder, + &vecbyNetwData[0], + iCeltNumCodedBytes, + &vecsAudioSndCrdMono[0] ); + +for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 ) +{ + vecsStereoSndCrd[j] = vecsStereoSndCrd[j + 1] = + vecsAudioSndCrdMono[i]; +} +*/ + + +// TODO first ALL channels must be decoded before process data can +// be called!!! + + // generate a sparate mix for each channel // actual processing of audio data -> mix vecsSendData = ProcessData ( vecvecdData, vecvecdGains[i] ); @@ -326,6 +349,17 @@ void CServer::OnTimer() // Socket.SendPacket ( // PrepSendPacket ( vecChanID[i], vecsSendData ), // GetAddress ( vecChanID[i] ) ); + +/* +celt_encode ( CeltEncoder, + &vecsNetwork[0], + NULL, + &vecCeltData[0], + iCeltNumCodedBytes ); + +Socket.SendPacket ( vecCeltData, Channel.GetAddress() ); +*/ + } } else @@ -363,8 +397,29 @@ void CServer::GetBlockAllConC ( CVector& vecChanID, // read out all input buffers to decrease timeout counter on // disconnected channels // const EGetDataStat eGetStat = vecChannels[i].GetData ( vecdData ); + const EGetDataStat eGetStat=GS_BUFFER_OK;//TEST +// TEST +/* +// TEST CELT +CVector vecsAudioSndCrdMono ( iMonoBlockSizeSam ); + +celt_decode ( CeltDecoder, + &vecbyNetwData[0], + iCeltNumCodedBytes, + &vecsAudioSndCrdMono[0] ); + +for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 ) +{ + vecsStereoSndCrd[j] = vecsStereoSndCrd[j + 1] = + vecsAudioSndCrdMono[i]; +} +*/ + + + + // if channel was just disconnected, set flag that connected // client list is sent to all other clients if ( eGetStat == GS_CHAN_NOW_DISCONNECTED ) @@ -672,7 +727,7 @@ bAudioOK = true; void CServer::GetConCliParam ( CVector& vecHostAddresses, CVector& vecsName, - CVector& veciJitBufSize, + CVector& veciJitBufNumFrames, CVector& veciNetwFrameSizeFact ) { CHostAddress InetAddr; @@ -680,7 +735,7 @@ void CServer::GetConCliParam ( CVector& vecHostAddresses, // init return values vecHostAddresses.Init ( USED_NUM_CHANNELS ); vecsName.Init ( USED_NUM_CHANNELS ); - veciJitBufSize.Init ( USED_NUM_CHANNELS ); + veciJitBufNumFrames.Init ( USED_NUM_CHANNELS ); veciNetwFrameSizeFact.Init ( USED_NUM_CHANNELS ); // check all possible channels @@ -691,7 +746,7 @@ void CServer::GetConCliParam ( CVector& vecHostAddresses, // get requested data vecHostAddresses[i] = InetAddr; vecsName[i] = vecChannels[i].GetName(); - veciJitBufSize[i] = vecChannels[i].GetSockBufSize(); + veciJitBufNumFrames[i] = vecChannels[i].GetSockBufNumFrames(); veciNetwFrameSizeFact[i] = vecChannels[i].GetNetwFrameSizeFact(); } } diff --git a/src/server.h b/src/server.h index 41458e55..8dc177d9 100755 --- a/src/server.h +++ b/src/server.h @@ -94,7 +94,7 @@ public: void GetConCliParam ( CVector& vecHostAddresses, CVector& vecsName, - CVector& veciJitBufSize, + CVector& veciJitBufNumFrames, CVector& veciNetwFrameSizeFact ); protected: @@ -130,8 +130,8 @@ protected: virtual void customEvent ( QEvent* Event ); - /* do not use the vector class since CChannel does not have appropriate - copy constructor/operator */ + // do not use the vector class since CChannel does not have appropriate + // copy constructor/operator CChannel vecChannels[MAX_NUM_CHANNELS]; QMutex Mutex; diff --git a/src/settings.cpp b/src/settings.cpp index 9c650ba6..75312758 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -125,7 +125,7 @@ void CSettings::ReadIniFile ( const QString& sFileName ) if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbuf", MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) ) { - pClient->SetSockBufSize ( iValue ); + pClient->SetSockBufNumFrames ( iValue ); } // flag whether the chat window shall be opened on a new chat message @@ -180,7 +180,7 @@ void CSettings::WriteIniFile ( const QString& sFileName ) // network jitter buffer size SetNumericIniSet ( IniXMLDocument, "client", "jitbuf", - pClient->GetSockBufSize() ); + pClient->GetSockBufNumFrames() ); // flag whether the chat window shall be opened on a new chat message SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage",