move overall delay estimation algorithm in client class
This commit is contained in:
parent
5414dd190b
commit
35c93ef39a
3 changed files with 48 additions and 42 deletions
|
@ -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 );
|
||||||
|
}
|
||||||
|
|
|
@ -212,6 +212,8 @@ public:
|
||||||
void SendPingMess()
|
void SendPingMess()
|
||||||
{ Channel.CreatePingMes ( PreciseTime.elapsed() ); };
|
{ Channel.CreatePingMes ( PreciseTime.elapsed() ); };
|
||||||
|
|
||||||
|
int EstimatedOverallDelay ( const int iPingTimeMs );
|
||||||
|
|
||||||
CChannel* GetChannel() { return &Channel; }
|
CChannel* GetChannel() { return &Channel; }
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
|
|
|
@ -635,45 +635,8 @@ void CClientSettingsDlg::OnTimerPing()
|
||||||
|
|
||||||
void CClientSettingsDlg::OnPingTimeResult ( int iPingTime )
|
void CClientSettingsDlg::OnPingTimeResult ( int iPingTime )
|
||||||
{
|
{
|
||||||
/*
|
// calculate overall delay
|
||||||
For estimating the overall delay, use the following assumptions:
|
const int iOverallDelayMs = pClient->EstimatedOverallDelay ( iPingTime );
|
||||||
- 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 );
|
|
||||||
|
|
||||||
// apply values to GUI labels, take special care if ping time exceeds
|
// apply values to GUI labels, take special care if ping time exceeds
|
||||||
// a certain value
|
// a certain value
|
||||||
|
@ -689,17 +652,17 @@ void CClientSettingsDlg::OnPingTimeResult ( int iPingTime )
|
||||||
{
|
{
|
||||||
TextLabelPingTime->setText ( QString().setNum ( iPingTime ) + " ms" );
|
TextLabelPingTime->setText ( QString().setNum ( iPingTime ) + " ms" );
|
||||||
TextLabelOverallDelay->setText (
|
TextLabelOverallDelay->setText (
|
||||||
QString().setNum ( iOverallDelay ) + " ms" );
|
QString().setNum ( iOverallDelayMs ) + " ms" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// color definition: < 40 ms green, < 65 ms yellow, otherwise red
|
// color definition: < 40 ms green, < 65 ms yellow, otherwise red
|
||||||
if ( iOverallDelay <= 40 )
|
if ( iOverallDelayMs <= 40 )
|
||||||
{
|
{
|
||||||
CLEDOverallDelay->SetLight ( MUL_COL_LED_GREEN );
|
CLEDOverallDelay->SetLight ( MUL_COL_LED_GREEN );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( iOverallDelay <= 65 )
|
if ( iOverallDelayMs <= 65 )
|
||||||
{
|
{
|
||||||
CLEDOverallDelay->SetLight ( MUL_COL_LED_YELLOW );
|
CLEDOverallDelay->SetLight ( MUL_COL_LED_YELLOW );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue