timeshift: move the pts_delta init code to a function
This commit is contained in:
parent
c23eca2b0b
commit
ad5f59ce14
1 changed files with 33 additions and 23 deletions
|
@ -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))) {
|
||||
|
|
Loading…
Add table
Reference in a new issue