From e6a55ac3d2792a6b0042bbf8efc62e1e83865ea3 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 22 May 2006 10:48:11 +0000 Subject: Change jitter calculation in sound test (sndtest) to show the worst jitter value git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@471 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/samples/sndtest.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'pjsip-apps') diff --git a/pjsip-apps/src/samples/sndtest.c b/pjsip-apps/src/samples/sndtest.c index 0b9e28ec..2c469775 100644 --- a/pjsip-apps/src/samples/sndtest.c +++ b/pjsip-apps/src/samples/sndtest.c @@ -252,6 +252,7 @@ static void print_stream_data(const char *title, int verbose) { unsigned i, dur; + int ptime; unsigned min_jitter, max_jitter, sum_jitter, avg_jitter=0; PJ_LOG(3,(THIS_FILE, " %s stream report:", title)); @@ -297,16 +298,36 @@ static void print_stream_data(const char *title, pj_log_set_decor(decor); } + /* Calculate frame ptime in usec */ + ptime = test_data->samples_per_frame * 1000000 / + test_data->clock_rate; + /* Calculate jitter */ min_jitter = 0xFFFFF; max_jitter = 0; sum_jitter = 0; for (i=1; icounter; ++i) { - int jitter; - jitter = strm_data->delay[i] - strm_data->delay[i-1]; - if (jitter < 0) jitter = -jitter; + int jitter1, jitter2, jitter; + + /* jitter1 is interarrival difference */ + jitter1 = strm_data->delay[i] - strm_data->delay[i-1]; + if (jitter1 < 0) jitter1 = -jitter1; + /* jitter2 is difference between actual and scheduled arrival. + * This is intended to capture situation when frames are coming + * instantaneously, which will calculate as zero jitter with + * jitter1 calculation. + */ + jitter2 = ptime - strm_data->delay[i]; + if (jitter2 < 0) jitter2 = -jitter2; + + /* Set jitter as the maximum of the two jitter calculations. + * This is intended to show the worst result. + */ + jitter = (jitter1>jitter2) ? jitter1 : jitter2; + + /* Calculate min, max, avg jitter */ if (jitter < (int)min_jitter) min_jitter = jitter; if (jitter > (int)max_jitter) max_jitter = jitter; -- cgit v1.2.3