bug fixes for timing variance calculation, new init parameters for CycleTime class, added CycleTime for channel estimating input network stream variance of timing

This commit is contained in:
Volker Fischer 2009-03-17 06:50:00 +00:00
parent 174ad54c4f
commit 9dd942bec6
7 changed files with 56 additions and 21 deletions

View file

@ -660,9 +660,12 @@ void CChannelSet::WriteHTMLChannelList()
/******************************************************************************\ /******************************************************************************\
* CChannel * * CChannel *
\******************************************************************************/ \******************************************************************************/
CChannel::CChannel ( const bool bNIsServer ) : bIsServer ( bNIsServer ), CChannel::CChannel ( const bool bNIsServer ) :
sName ( "" ), vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ), bIsServer ( bNIsServer ),
bIsEnabled ( false ), iCurNetwOutBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR ) sName ( "" ),
vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ),
bIsEnabled ( false ),
iCurNetwOutBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR )
{ {
// query all possible network in buffer sizes for determining if an // query all possible network in buffer sizes for determining if an
// audio packet was received (the following code only works if all // audio packet was received (the following code only works if all
@ -1122,6 +1125,24 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
{ {
eRet = PS_AUDIO_ERR; eRet = PS_AUDIO_ERR;
} }
// update cycle time variance measurement, take care of
// re-initialization, too, if necessary
if ( iAudioSize != CycleTimeVariance.GetBlockLength() )
{
// re-init
CycleTimeVariance.Init ( iAudioSize, TIME_MOV_AV_RESPONSE );
CycleTimeVariance.Reset();
}
else
{
// TODO only update if time difference of received packets is below
// a limit to avoid having short network troubles incorporated in the
// statistic
CycleTimeVariance.Update();
}
} }
else else
{ {
@ -1156,6 +1177,9 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
Protocol.CreateReqNetwTranspPropsMes(); Protocol.CreateReqNetwTranspPropsMes();
} }
// reset cycle time variance measurement
CycleTimeVariance.Reset();
// inform other objects that new connection was established // inform other objects that new connection was established
emit NewConnection(); emit NewConnection();
} }

View file

@ -115,6 +115,8 @@ public:
int GetAudioBlockSizeIn() { return iCurAudioBlockSizeIn; } int GetAudioBlockSizeIn() { return iCurAudioBlockSizeIn; }
int GetUploadRateKbps(); int GetUploadRateKbps();
double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); }
void SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut ); void SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut );
int GetNetwBufSizeFactOut() { return iCurNetwOutBlSiFact; } int GetNetwBufSizeFactOut() { return iCurNetwOutBlSiFact; }
@ -173,6 +175,8 @@ protected:
CNetBuf SockBuf; CNetBuf SockBuf;
int iCurSockBufSize; int iCurSockBufSize;
CCycleTimeVariance CycleTimeVariance;
// network output conversion buffer // network output conversion buffer
CConvBuf ConvBuf; CConvBuf ConvBuf;

View file

@ -297,8 +297,7 @@ void CClient::Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate )
vecdNetwData.Init ( iMonoBlockSizeSam ); vecdNetwData.Init ( iMonoBlockSizeSam );
// init response time evaluation // init response time evaluation
CycleTimeVariance.Init ( CycleTimeVariance.Init ( iMonoBlockSizeSam, TIME_MOV_AV_RESPONSE );
TIME_MOV_AV_RESPONSE * SYSTEM_SAMPLE_RATE / iMonoBlockSizeSam );
CycleTimeVariance.Reset(); CycleTimeVariance.Reset();
@ -457,12 +456,6 @@ void CClient::UpdateSocketBufferSize()
const double dHysteresis = 0.3; const double dHysteresis = 0.3;
// calculate current buffer setting // calculate current buffer setting
// TODO 2* seems not give optimal results, maybe use 3*?
// add .5 to "round up" -> ceil
// divide by MIN_SERVER_BLOCK_DURATION_MS because this is the size of
// one block in the jitter buffer
// add one block for actual network jitter
// Use worst case scenario: We add the block size of input and // Use worst case scenario: We add the block size of input and
// output. This is not required if the smaller block size is a // output. This is not required if the smaller block size is a
// multiple of the bigger size, but in the general case where // multiple of the bigger size, but in the general case where
@ -472,8 +465,13 @@ void CClient::UpdateSocketBufferSize()
( iMonoBlockSizeSam + Channel.GetAudioBlockSizeIn() ) * 1000 / ( iMonoBlockSizeSam + Channel.GetAudioBlockSizeIn() ) * 1000 /
SYSTEM_SAMPLE_RATE; SYSTEM_SAMPLE_RATE;
const double dEstCurBufSet = 1 + ( dAudioBufferDurationMs + // accumulate the standard deviations of input network stream and
2 * ( CycleTimeVariance.GetStdDev() + 0.5 ) ) / // internal timer,
// add .5 to "round up" -> ceil,
// divide by MIN_SERVER_BLOCK_DURATION_MS because this is the size of
// one block in the jitter buffer
const double dEstCurBufSet = ( dAudioBufferDurationMs +
2 * ( Channel.GetTimingStdDev() + CycleTimeVariance.GetStdDev() + 0.5 ) ) /
MIN_SERVER_BLOCK_DURATION_MS; MIN_SERVER_BLOCK_DURATION_MS;
// upper/lower hysteresis decision // upper/lower hysteresis decision

View file

@ -111,7 +111,6 @@
// length of the moving average buffer for response time measurement // length of the moving average buffer for response time measurement
#define TIME_MOV_AV_RESPONSE 30 // seconds #define TIME_MOV_AV_RESPONSE 30 // seconds
#define LEN_MOV_AV_RESPONSE_SERVER ( TIME_MOV_AV_RESPONSE * 1000 / MIN_SERVER_BLOCK_DURATION_MS )
// GUI definition: width/heigth size of LED pixmaps // GUI definition: width/heigth size of LED pixmaps
#define LED_WIDTH_HEIGHT_SIZE_PIXEL 20 #define LED_WIDTH_HEIGHT_SIZE_PIXEL 20

View file

@ -393,7 +393,7 @@ void CLlconClientDlg::UpdateDisplay()
} }
// TEST // TEST
//TextLabelStatus->setText ( QString( "Std dev: %1" ).arg ( pClient->GetTimingStdDev() ) ); //TextLabelStatus->setText ( QString( "Time: %1, Netw: %2" ).arg ( pClient->GetTimingStdDev() ).arg ( pClient->GetChannel()->GetTimingStdDev() ) );
} }

View file

@ -37,7 +37,8 @@ CServer::CServer ( const QString& strLoggingFileName,
vecsSendData.Init ( MIN_SERVER_BLOCK_SIZE_SAMPLES ); vecsSendData.Init ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
// init moving average buffer for response time evaluation // init moving average buffer for response time evaluation
CycleTimeVariance.Init ( LEN_MOV_AV_RESPONSE_SERVER ); CycleTimeVariance.Init (
MIN_SERVER_BLOCK_SIZE_SAMPLES, TIME_MOV_AV_RESPONSE );
// connect timer timeout signal // connect timer timeout signal
QObject::connect ( &Timer, SIGNAL ( timeout() ), QObject::connect ( &Timer, SIGNAL ( timeout() ),

View file

@ -610,14 +610,22 @@ protected:
class CCycleTimeVariance class CCycleTimeVariance
{ {
public: public:
CCycleTimeVariance() {} CCycleTimeVariance() : iBlockLengthAtSystemSampleRate ( 0 ) {}
virtual ~CCycleTimeVariance() {} virtual ~CCycleTimeVariance() {}
void Init ( const int iMovingAverageLength ) void Init ( const int iNewBlockLengthAtSystemSampleRate,
const int iHistoryLengthTime )
{ {
RespTimeMoAvBuf.Init ( iMovingAverageLength ); // store block size
iBlockLengthAtSystemSampleRate = iNewBlockLengthAtSystemSampleRate;
// calculate actual moving average length and initialize buffer
RespTimeMoAvBuf.Init ( iHistoryLengthTime *
SYSTEM_SAMPLE_RATE / iNewBlockLengthAtSystemSampleRate );
} }
int GetBlockLength() { return iBlockLengthAtSystemSampleRate; }
void Reset() void Reset()
{ {
TimeLastBlock = PreciseTime.elapsed(); TimeLastBlock = PreciseTime.elapsed();
@ -631,8 +639,8 @@ public:
// we want to calculate the standard deviation (we assume that the mean // we want to calculate the standard deviation (we assume that the mean
// is correct at the block period time) // is correct at the block period time)
const double dCurAddVal = const double dCurAddVal = ( (double) ( CurTime - TimeLastBlock ) -
( (double) ( CurTime - TimeLastBlock ) - MIN_SERVER_BLOCK_DURATION_MS ); ( iBlockLengthAtSystemSampleRate * 1000 / SYSTEM_SAMPLE_RATE ) );
RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); // add squared value RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); // add squared value
@ -650,6 +658,7 @@ protected:
CPreciseTime PreciseTime; CPreciseTime PreciseTime;
CMovingAv<double> RespTimeMoAvBuf; CMovingAv<double> RespTimeMoAvBuf;
int TimeLastBlock; int TimeLastBlock;
int iBlockLengthAtSystemSampleRate;
}; };
#endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */ #endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */