From c8ed04fe005ac461570a745f69b5be8fd5ebbbd8 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Wed, 10 Feb 2016 12:02:44 -0700 Subject: sync: fix subtitle timestamps that go backwards This should be really difficult to trigger, but someone found a sample that does. --- libhb/sync.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'libhb/sync.c') diff --git a/libhb/sync.c b/libhb/sync.c index dd8c54adc..282c18bbd 100644 --- a/libhb/sync.c +++ b/libhb/sync.c @@ -736,9 +736,18 @@ static void streamFlush( sync_stream_t * stream ) { buf->s.start = stream->next_pts; buf->s.stop = stream->next_pts + buf->s.duration; + stream->next_pts += buf->s.duration; + } + else + { + // Last ditch effort to prevent timestamps from going backwards + // This can (and should only) affect subtitle streams. + if (buf->s.start < stream->next_pts) + { + buf->s.start = stream->next_pts; + } + stream->next_pts = buf->s.start; } - - stream->next_pts += buf->s.duration; if (buf->s.stop > 0) { @@ -967,9 +976,19 @@ static void OutputBuffer( sync_common_t * common ) { buf->s.start = out_stream->next_pts; buf->s.stop = out_stream->next_pts + buf->s.duration; + out_stream->next_pts += buf->s.duration; + } + else + { + // Last ditch effort to prevent timestamps from going backwards + // This can (and should only) affect subtitle streams. + if (buf->s.start < out_stream->next_pts) + { + buf->s.start = out_stream->next_pts; + } + out_stream->next_pts = buf->s.start; } - out_stream->next_pts += buf->s.duration; if (buf->s.stop > 0) { -- cgit v1.2.3