Skip to content

Commit

Permalink
lavf/utils: use stream PTS wrap-around values as default if smaller o…
Browse files Browse the repository at this point in the history
…r much larger than default

Seems to fix mistaken cases of discontinuity handling in MPEG-TS files
when streams get added in.

Additional changes to patch from its original state by Jan Ekström.
  • Loading branch information
maki-rxrz authored and jeeb committed Mar 12, 2018
1 parent 8fb0e51 commit dfeeeb2
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions libavformat/utils.c
Expand Up @@ -810,8 +810,46 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in
while (program) {
if (program->pts_wrap_reference != pts_wrap_reference) {
for (i = 0; i<program->nb_stream_indexes; i++) {
s->streams[program->stream_index[i]]->pts_wrap_reference = pts_wrap_reference;
s->streams[program->stream_index[i]]->pts_wrap_behavior = pts_wrap_behavior;
int64_t *stream_pts_wrap_reference = &(s->streams[program->stream_index[i]]->pts_wrap_reference);
int *stream_pts_wrap_behavior = &(s->streams[program->stream_index[i]]->pts_wrap_behavior);

if (*stream_pts_wrap_reference != AV_NOPTS_VALUE &&
(*stream_pts_wrap_reference - pts_wrap_reference > 1ULL << (st->pts_wrap_bits - 3) ||
*stream_pts_wrap_reference < pts_wrap_reference)) {
/*
* Utilize the current stream's wrap-around reference
* as the default reference if this stream's
* wrap-around reference is already not NOPTS,
* and either:
* 1) the stream's wrap-around reference is
* after the default program's reference
* by at least the most significant bit's value
* of (pts_wrap_bits - 3).
* 2) the stream's wrap-around reference is
* before the default one.
*/
av_log(s, AV_LOG_VERBOSE,
"Updating default PTS wrap reference "
"%"PRId64" and PTS wrap behavior %d to "
"stream PTS wrap reference %"PRId64" and "
"PTS wrap behavior %d (program=%d, stream=%d, "
"stream_id=%d)\n", pts_wrap_reference,
pts_wrap_behavior,
*stream_pts_wrap_reference,
*stream_pts_wrap_behavior,
program->id, program->stream_index[i],
s->streams[program->stream_index[i]]->id);

pts_wrap_reference = *stream_pts_wrap_reference;
pts_wrap_behavior = *stream_pts_wrap_behavior;
} else {
/*
* otherwise just utilize the default program's
* wrap-around reference for this stream.
*/
*stream_pts_wrap_reference = pts_wrap_reference;
*stream_pts_wrap_behavior = pts_wrap_behavior;
}
}

program->pts_wrap_reference = pts_wrap_reference;
Expand Down

0 comments on commit dfeeeb2

Please sign in to comment.