Skip to content

Commit

Permalink
Commit current snapshot of the jitter tracking code, still WiP,
Browse files Browse the repository at this point in the history
so its own branch.
  • Loading branch information
sobomax committed Dec 16, 2015
1 parent 077af1b commit e545b08
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions extractaudio/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ load_session(const char *path, struct channels *channels, enum origin origin)
(unsigned int)stat.last.seq_offset, (unsigned int)stat.last.ssrc, (unsigned int)stat.last.duplicates);
printf("ssrc_changes=%u, psent=%u, precvd=%u, plost=%d\n", stat.ssrc_changes, stat.psent, stat.precvd,
stat.psent - stat.precvd);
printf("last_jitter=%f,average_jitter=%f,max_jitter=%f\n",
stat.jitter.jval,stat.jitter.jtotal / (double)(stat.jitter.pcount - 1),
stat.jitter.jmax);

loader->destroy(loader);

Expand Down
56 changes: 56 additions & 0 deletions src/rtp_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ rtp_ts2dtime(uint32_t ts)
return ((double)ts) / ((double)8000);
}

static uint64_t
rtp_dtime2time_ts64(double dtime)
{

return (uint64_t)(dtime * 8000.0);
}

/* rlog can be null in this context, when compiled for the extractaudio context */
#define LOGD_IF_NOT_NULL(log, args...) \
if ((log) != NULL) { \
Expand All @@ -57,6 +64,54 @@ rtp_ts2dtime(uint32_t ts)
RTPP_LOG((log), RTPP_LOG_INFO, ## args); \
}

static void
update_jitter_stats(struct rtpp_session_stat_jitter *jp,
struct rtp_info *rinfo, double rtime)
{
int64_t dval, rtime_ts_delta;
uint64_t rtime_ts, wrcorr;

rtime_ts = rtp_dtime2time_ts64(rtime);
if (jp->prev_rtime_ts != 0) {
rtime_ts_delta = jp->prev_rtime_ts - rtime_ts;
if (jp->prev_ts > rinfo->ts) {
if ((jp->prev_ts - rinfo->ts) > (1 << 31)) {
/* Normal case, timestamp wrap */
wrcorr = (uint64_t)1 << 32;
} else if (rtime_ts_delta != 0 && (jp->prev_ts - rinfo->ts) >
ABS(rtime_ts_delta) * 10) {
/* Timestamp reset */
jp->ts_rcount++;
goto saveandexit;
} else {
wrcorr = 0;
}
} else {
if (rtime_ts_delta != 0 && (rinfo->ts - jp->prev_ts) >
ABS(rtime_ts_delta) * 1024) {
/* Timestamp jump */
jp->ts_jcount++;
goto saveandexit;
}
wrcorr = 0;
}
dval = (rtime_ts - ((uint64_t)rinfo->ts + wrcorr)) -
(jp->prev_rtime_ts - jp->prev_ts);
jp->jval = jp->jval + (double)(ABS(dval) - jp->jval) / 16.0;
if (jp->jval > jp->jmax) {
jp->jmax = jp->jval;
}
jp->jtotal += jp->jval;
}
fprintf(stderr, "0x%.8X,%lld,%llu,%u,%f\n", rinfo->ssrc, jp->pcount,
rtime_ts, rinfo->ts, jp->jval);
jp->pcount++;
saveandexit:
jp->prev_rtime_ts = rtime_ts;
jp->prev_ts = rinfo->ts;
}


enum update_rtpp_stats_rval
update_rtpp_stats(struct rtpp_log *rlog, struct rtpp_session_stat *stat, rtp_hdr_t *header,
struct rtp_info *rinfo, double rtime)
Expand All @@ -65,6 +120,7 @@ update_rtpp_stats(struct rtpp_log *rlog, struct rtpp_session_stat *stat, rtp_hdr
uint16_t idx;
uint32_t mask;

update_jitter_stats(&stat->jitter, rinfo, rtime);
seq = rinfo->seq;
if (stat->ssrc_changes == 0) {
assert(stat->last.pcount == 0);
Expand Down
12 changes: 12 additions & 0 deletions src/rtp_analyze.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@

struct rtpp_log;

struct rtpp_session_stat_jitter {
uint64_t prev_rtime_ts;
uint32_t prev_ts;
double jval;
double jmax;
double jtotal;
long long pcount;
long long ts_rcount;
long long ts_jcount;
};

struct rtpp_session_stat_last {
long long pcount;
uint32_t min_seq;
Expand All @@ -52,6 +63,7 @@ struct rtpp_session_stat {
uint32_t desync_count;
uint32_t seq_res_count;
struct rtpp_session_stat_last last;
struct rtpp_session_stat_jitter jitter;
};

enum update_rtpp_stats_rval {UPDATE_OK = 0, UPDATE_SSRC_CHG = 1, UPDATE_ERR = -1};
Expand Down

0 comments on commit e545b08

Please sign in to comment.