Skip to content

Commit

Permalink
timeshift: for initial pts value, scan more packets (now 6)
Browse files Browse the repository at this point in the history
  • Loading branch information
perexg committed Oct 23, 2014
1 parent 6106b71 commit 82b17a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/timeshift.c
Expand Up @@ -170,8 +170,21 @@ static void timeshift_input

/* Record (one-off) PTS delta */
if (sm->sm_type == SMT_PACKET && ts->pts_delta == PTS_UNSET) {
if (pkt->pkt_pts != PTS_UNSET)
ts->pts_delta = getmonoclock() - ts_rescale(pkt->pkt_pts, 1000000);
if (pkt->pkt_pts != PTS_UNSET) {
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);
}
}

This comment has been minimized.

Copy link
@ksooo

ksooo Oct 23, 2014

Contributor

@perexg Could you please add some comments here? My feeling is that after some weeks nobody will ever remember what this "magic" code is good for.

This comment has been minimized.

Copy link
@perexg

perexg Oct 23, 2014

Author Contributor

@ksooo : OK, but the real fix is in the second patch (to ensure that ALL streams are synced together). This code just makes more robust the delta decision based on multiple pts values from encoders which may use "pts" shuffling to create cbr streams..

This comment has been minimized.

Copy link
@ksooo

ksooo Oct 23, 2014

Contributor

@perexg: You just phrased the text for the code comment, didn't you. ;-)

This comment has been minimized.

Copy link
@perexg

perexg Oct 24, 2014

Author Contributor

Moved to separate function in commit ad5f59c .


/* Buffer to disk */
Expand Down Expand Up @@ -256,6 +269,7 @@ streaming_target_t *timeshift_create
(streaming_target_t *out, time_t max_time)
{
timeshift_t *ts = calloc(1, sizeof(timeshift_t));
int i;

/* Must hold global lock */
lock_assert(&global_lock);
Expand All @@ -271,6 +285,8 @@ streaming_target_t *timeshift_create
ts->id = timeshift_index;
ts->ondemand = timeshift_ondemand;
ts->pts_delta = PTS_UNSET;
for (i = 0; i < ARRAY_SIZE(ts->pts_val); i++)
ts->pts_val[i] = PTS_UNSET;
pthread_mutex_init(&ts->rdwr_mutex, NULL);
pthread_mutex_init(&ts->state_mutex, NULL);

Expand Down
1 change: 1 addition & 0 deletions src/timeshift/private.h
Expand Up @@ -83,6 +83,7 @@ typedef struct timeshift {
time_t max_time; ///< Maximum period to shift
int ondemand; ///< Whether this is an on-demand timeshift
int64_t pts_delta; ///< Delta between system clock and PTS
int64_t pts_val[6]; ///< Decision PTS values for multiple packets

enum {
TS_INIT,
Expand Down

0 comments on commit 82b17a7

Please sign in to comment.