From edd40fc9c02178434d14a7054a34014d7e3c0d31 Mon Sep 17 00:00:00 2001 From: John Cox Date: Mon, 7 Oct 2013 15:02:38 +0100 Subject: [PATCH] Refine section discontinuity detection in pcapreport Instead of having a fixed skew at which we say "new section" we look for a skew, pcr, or packet_time discontinuity to define the break. This allows more plausible handling of sections that are deliberately fast/slow --- pcapreport.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pcapreport.c b/pcapreport.c index b09bdd1..690412a 100644 --- a/pcapreport.c +++ b/pcapreport.c @@ -86,6 +86,7 @@ struct pcapreport_section_struct { uint64_t time_final; uint64_t pcr_start; // 90kHz uint64_t pcr_last; + int64_t skew_last; uint64_t ts_byte_start; uint64_t ts_byte_final; int32_t rtp_skew_min; @@ -386,6 +387,13 @@ pts_diff(const uint64_t a, const uint64_t b) return ((int64_t)(a - b) << 31) >> 31; } +static int64_t +pts_diff_abs(const uint64_t a, const uint64_t b) +{ + const int64_t t = pts_diff(a, b); + return t < 0 ? -t : t; +} + static int digest_times(pcapreport_ctx_t * const ctx, pcapreport_stream_t * const st, @@ -541,13 +549,20 @@ static int digest_times(pcapreport_ctx_t * const ctx, skew = tsect->pcr_count == 0 ? 0LL : pcr_time_offset - pts_diff(tsect->time_first, tsect->pcr_start); - // Change section if skew too big - if (st->skew_discontinuity_threshold > 0 && - (skew > st->skew_discontinuity_threshold || - skew < -st->skew_discontinuity_threshold)) + // Change section if discontinuity too big + if (st->skew_discontinuity_threshold > 0 && tsect->pcr_count != 0) { - section_create(ctx, st, pcap_pkt_hdr); - tsect = st->section_last; + const int64_t pcr_delta = pts_diff_abs(pcr, tsect->pcr_last); + const int64_t time_delta = pts_diff_abs(t_pcr, tsect->time_last); + const int64_t skew_delta = skew - tsect->skew_last; + + if (pcr_delta > st->skew_discontinuity_threshold || + time_delta > st->skew_discontinuity_threshold || + skew_delta > st->skew_discontinuity_threshold) + { + section_create(ctx, st, pcap_pkt_hdr); + tsect = st->section_last; + } } if (tsect->pcr_count == 0) @@ -628,6 +643,7 @@ static int digest_times(pcapreport_ctx_t * const ctx, // Remember where we are for posterity tsect->pcr_last = pcr; tsect->time_last = t_pcr; + tsect->skew_last = skew; st->last_time_offset = pcr_time_offset; ++tsect->pcr_count;