Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeshift: move the pts_delta init code to a function
  • Loading branch information
perexg committed Oct 24, 2014
1 parent c23eca2 commit ad5f59c
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions src/timeshift.c
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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))) {
Expand Down

0 comments on commit ad5f59c

Please sign in to comment.