avformat/matroskadec: Fix rounding error with codec_delay
authorMichael Niedermayer <michael@niedermayer.cc>
Mon, 6 Jun 2016 02:23:16 +0000 (04:23 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 6 Jun 2016 03:01:34 +0000 (05:01 +0200)
Fixes Ticket5509

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/matroskadec.c

index 1ef2001..3270009 100644 (file)
@@ -219,6 +219,7 @@ typedef struct MatroskaTrack {
     MatroskaTrackOperation operation;
     EbmlList encodings;
     uint64_t codec_delay;
+    uint64_t codec_delay_in_track_tb;
 
     AVStream *stream;
     int64_t end_timecode;
@@ -2239,7 +2240,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
                             1000 * 1000 * 1000);    /* 64 bit pts in ns */
 
         /* convert the delay from ns to the track timebase */
-        track->codec_delay = av_rescale_q(track->codec_delay,
+        track->codec_delay_in_track_tb = av_rescale_q(track->codec_delay,
                                           (AVRational){ 1, 1000000000 },
                                           st->time_base);
 
@@ -2351,7 +2352,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
                 st->need_parsing = AVSTREAM_PARSE_HEADERS;
             if (track->codec_delay > 0) {
                 st->codecpar->initial_padding = av_rescale_q(track->codec_delay,
-                                                             st->time_base,
+                                                             (AVRational){1, 1000000000},
                                                              (AVRational){1, st->codecpar->sample_rate});
             }
             if (track->seek_preroll > 0) {
@@ -3132,7 +3133,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
 
     if (cluster_time != (uint64_t) -1 &&
         (block_time >= 0 || cluster_time >= -block_time)) {
-        timecode = cluster_time + block_time - track->codec_delay;
+        timecode = cluster_time + block_time - track->codec_delay_in_track_tb;
         if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE &&
             timecode < track->end_timecode)
             is_keyframe = 0;  /* overlapping subtitles are not key frame */