diff --git a/src/client.cpp b/src/client.cpp index 88c9fe86..364aee65 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -937,3 +937,44 @@ void CClient::UpdateSocketBufferSize() } } } + +int CClient::EstimatedOverallDelay ( const int iPingTimeMs ) +{ +/* + For estimating the overall delay, use the following assumptions: + - the mean delay of a cyclic buffer is half the buffer size (since + for the average it is assumed that the buffer is half filled) + - consider the jitter buffer on the server side, too +*/ + // 2 times buffers at client and server divided by 2 (half the buffer + // for the delay) is simply the total socket buffer size + const double dTotalJitterBufferDelayMs = + SYSTEM_BLOCK_DURATION_MS_FLOAT * GetSockBufNumFrames(); + + // 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) + // the actual sound card buffer size, also consider delay introduced by + // sound card conversion buffer by using + // "GetSndCrdConvBufAdditionalDelayMonoBlSize" + const double dTotalSoundCardDelayMs = + ( 3 * GetSndCrdActualMonoBlSize() + + GetSndCrdConvBufAdditionalDelayMonoBlSize() ) * + 1000 / SYSTEM_SAMPLE_RATE; + + // network packets are of the same size as the audio packets per definition + // if no sound card conversion buffer is used + const double dDelayToFillNetworkPacketsMs = + GetSystemMonoBlSize() * 1000 / SYSTEM_SAMPLE_RATE; + + // CELT additional delay at small frame sizes is half a frame size + const double dAdditionalAudioCodecDelayMs = + SYSTEM_BLOCK_DURATION_MS_FLOAT / 2; + + const double dTotalBufferDelayMs = + dDelayToFillNetworkPacketsMs + + dTotalJitterBufferDelayMs + + dTotalSoundCardDelayMs + + dAdditionalAudioCodecDelayMs; + + return LlconMath::round ( dTotalBufferDelayMs + iPingTimeMs ); +} diff --git a/src/client.h b/src/client.h index f591db71..41f54003 100755 --- a/src/client.h +++ b/src/client.h @@ -212,6 +212,8 @@ public: void SendPingMess() { Channel.CreatePingMes ( PreciseTime.elapsed() ); }; + int EstimatedOverallDelay ( const int iPingTimeMs ); + CChannel* GetChannel() { return &Channel; } // settings diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 1627ccf7..6498b66a 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -635,45 +635,8 @@ void CClientSettingsDlg::OnTimerPing() void CClientSettingsDlg::OnPingTimeResult ( int iPingTime ) { -/* - For estimating the overall delay, use the following assumptions: - - the mean delay of a cyclic buffer is half the buffer size (since - for the average it is assumed that the buffer is half filled) - - consider the jitter buffer on the server side, too -*/ - // 2 times buffers at client and server divided by 2 (half the buffer - // for the delay) is simply the total socket buffer size - const double dTotalJitterBufferDelayMS = - SYSTEM_BLOCK_DURATION_MS_FLOAT * pClient->GetSockBufNumFrames(); - - // 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) - // the actual sound card buffer size, also consider delay introduced by - // sound card conversion buffer by using - // "GetSndCrdConvBufAdditionalDelayMonoBlSize" - const double dTotalSoundCardDelayMS = - ( 3 * pClient->GetSndCrdActualMonoBlSize() + - pClient->GetSndCrdConvBufAdditionalDelayMonoBlSize() ) * - 1000 / SYSTEM_SAMPLE_RATE; - - // network packets are of the same size as the audio packets per definition - // if no sound card conversion buffer is used - const double dDelayToFillNetworkPackets = - pClient->GetSystemMonoBlSize() * - 1000 / SYSTEM_SAMPLE_RATE; - - // CELT additional delay at small frame sizes is half a frame size - const double dAdditionalAudioCodecDelay = - SYSTEM_BLOCK_DURATION_MS_FLOAT / 2; - - const double dTotalBufferDelay = - dDelayToFillNetworkPackets + - dTotalJitterBufferDelayMS + - dTotalSoundCardDelayMS + - dAdditionalAudioCodecDelay; - - const int iOverallDelay = - LlconMath::round ( dTotalBufferDelay + iPingTime ); + // calculate overall delay + const int iOverallDelayMs = pClient->EstimatedOverallDelay ( iPingTime ); // apply values to GUI labels, take special care if ping time exceeds // a certain value @@ -689,17 +652,17 @@ void CClientSettingsDlg::OnPingTimeResult ( int iPingTime ) { TextLabelPingTime->setText ( QString().setNum ( iPingTime ) + " ms" ); TextLabelOverallDelay->setText ( - QString().setNum ( iOverallDelay ) + " ms" ); + QString().setNum ( iOverallDelayMs ) + " ms" ); } // color definition: < 40 ms green, < 65 ms yellow, otherwise red - if ( iOverallDelay <= 40 ) + if ( iOverallDelayMs <= 40 ) { CLEDOverallDelay->SetLight ( MUL_COL_LED_GREEN ); } else { - if ( iOverallDelay <= 65 ) + if ( iOverallDelayMs <= 65 ) { CLEDOverallDelay->SetLight ( MUL_COL_LED_YELLOW ); }