From ad5f59ce14d11b072532dc641b7a8d9c3c3d8661 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 24 Oct 2014 09:02:21 +0200 Subject: [PATCH] timeshift: move the pts_delta init code to a function --- src/timeshift.c | 56 +++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/timeshift.c b/src/timeshift.c index 6f1ab5de..c6775312 100644 --- a/src/timeshift.c +++ b/src/timeshift.c @@ -111,6 +111,37 @@ void timeshift_save ( void ) hts_settings_save(m, "timeshift/config"); } +/* + * Decode initial time diff + * + * Gather some packets and select the lowest pts to identify + * the correct start. Note that for timeshift, the tsfix + * stream plugin is applied, so the starting pts should be + * near zero. If not - it's a bug. + */ +static void +timeshift_set_pts_delta ( timeshift_t *ts, int64_t pts ) +{ + int i; + int64_t smallest = INT64_MAX; + + if (pts == PTS_UNSET) + return; + + for (i = 0; i < ARRAY_SIZE(ts->pts_val); i++) { + int64_t i64 = ts->pts_val[i]; + if (i64 == PTS_UNSET) { + ts->pts_val[i] = pts; + break; + } + if (i64 < smallest) + smallest = i64; + } + + if (i >= ARRAY_SIZE(ts->pts_val)) + ts->pts_delta = getmonoclock() - ts_rescale(smallest, 1000000); +} + /* * Receive data */ @@ -169,29 +200,8 @@ static void timeshift_input exit = 1; /* Record (one-off) PTS delta */ - if (sm->sm_type == SMT_PACKET && ts->pts_delta == PTS_UNSET) { - if (pkt->pkt_pts != PTS_UNSET) { - /* - * Gather some packets and select the lowest pts to identify - * the correct start. Note that for timeshift, the tsfix - * stream plugin is applied, so the starting pts should be - * near zero. If not - it's a bug. - */ - int i; - int64_t smallest = INT64_MAX; - for (i = 0; i < ARRAY_SIZE(ts->pts_val); i++) { - int64_t i64 = ts->pts_val[i]; - if (i64 == PTS_UNSET) { - ts->pts_val[i] = pkt->pkt_pts; - break; - } - if (i64 < smallest) - smallest = i64; - } - if (i >= ARRAY_SIZE(ts->pts_val)) - ts->pts_delta = getmonoclock() - ts_rescale(smallest, 1000000); - } - } + if (sm->sm_type == SMT_PACKET && ts->pts_delta == PTS_UNSET) + timeshift_set_pts_delta(ts, pkt->pkt_pts); /* Buffer to disk */ if ((ts->state > TS_LIVE) || (!ts->ondemand && (ts->state == TS_LIVE))) {