diff --git a/src/lib_ccx/ccx_demuxer.c b/src/lib_ccx/ccx_demuxer.c index f87e99584..4a34055ce 100644 --- a/src/lib_ccx/ccx_demuxer.c +++ b/src/lib_ccx/ccx_demuxer.c @@ -452,6 +452,7 @@ struct demuxer_data *alloc_demuxer_data(void) data->len = 0; data->pts = CCX_NOPTS; data->rollover_bits = 0; + data->prev_pts_33 = 0; data->tb.num = 1; data->tb.den = 90000; data->next_stream = 0; diff --git a/src/lib_ccx/ccx_demuxer.h b/src/lib_ccx/ccx_demuxer.h index 16cd6c10c..fcbf0d932 100644 --- a/src/lib_ccx/ccx_demuxer.h +++ b/src/lib_ccx/ccx_demuxer.h @@ -174,6 +174,7 @@ struct demuxer_data unsigned char *buffer; size_t len; unsigned int rollover_bits; // The PTS rolls over every 26 hours and that can happen in the middle of a stream. + LLONG prev_pts_33; // Previous 33-bit PTS for this stream's rollover detection (per-stream, not shared) LLONG pts; struct ccx_rational tb; struct demuxer_data *next_stream; diff --git a/src/lib_ccx/stream_functions.c b/src/lib_ccx/stream_functions.c index 9f6000fa9..3472107f5 100644 --- a/src/lib_ccx/stream_functions.c +++ b/src/lib_ccx/stream_functions.c @@ -297,7 +297,6 @@ int read_video_pes_header(struct ccx_demuxer *ctx, struct demuxer_data *data, un long long result; unsigned peslen = nextheader[4] << 8 | nextheader[5]; unsigned payloadlength = 0; // Length of packet data bytes - static LLONG current_pts_33 = 0; // Last PTS from the header, without rollover bits if (!sbuflen) { @@ -437,14 +436,14 @@ int read_video_pes_header(struct ccx_demuxer *ctx, struct demuxer_data *data, un if (data->pts != CCX_NOPTS) // Otherwise can't check for rollovers yet { - if (!bits_9 && ((current_pts_33 >> 30) & 7) == 7) // PTS about to rollover + if (!bits_9 && ((data->prev_pts_33 >> 30) & 7) == 7) // PTS about to rollover data->rollover_bits++; - if ((bits_9 >> 30) == 7 && ((current_pts_33 >> 30) & 7) == 0) // PTS rollback? Rare and if happens it would mean out of order frames + if ((bits_9 >> 30) == 7 && ((data->prev_pts_33 >> 30) & 7) == 0) // PTS rollback? Rare and if happens it would mean out of order frames data->rollover_bits--; } - current_pts_33 = bits_9 | bits_10 | bits_11 | bits_12 | bits_13; - data->pts = (LLONG)data->rollover_bits << 33 | current_pts_33; + data->prev_pts_33 = bits_9 | bits_10 | bits_11 | bits_12 | bits_13; + data->pts = (LLONG)data->rollover_bits << 33 | data->prev_pts_33; /* The user data holding the captions seems to come between GOP and * the first frame. The sync PTS (sync_pts) (set at picture 0)