From 11bd80b31e0d039b1193f8c68d3bb9e5bf6a4a28 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 13 Feb 2015 21:17:07 +0100 Subject: [PATCH] demux_mkv: return unique file positions for all packets Until now, some packets could return the same file position if they were split off from a Matroska-level packet. This was perfectly fine, because the file position isn't used for anything overly important (it uses it to estimate playback position if no other information is available). The following commit will use the demux_packet.pos field as unique ID (as a simplification), so make the demuxer export more finegrained information. Also, the last_filepos field didn't have to be global, at least not anymore. --- demux/demux_mkv.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 5335a6b8c7..892045a284 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -153,7 +153,6 @@ typedef struct mkv_demuxer { int64_t segment_start, segment_end; double duration, last_pts; - uint64_t last_filepos; mkv_track_t **tracks; int num_tracks; @@ -2028,7 +2027,7 @@ static bool handle_realaudio(demuxer_t *demuxer, mkv_track_t *track, * audio packets in file */ dp->pts = (x * apk_usize % w) ? MP_NOPTS_VALUE : track->audio_timestamp[x * apk_usize / w]; - dp->pos = orig->pos; + dp->pos = orig->pos + x; dp->keyframe = !x; // Mark first packet as keyframe demux_add_packet(track->stream, dp); } @@ -2203,6 +2202,7 @@ static void mkv_parse_and_add_packet(demuxer_t *demuxer, mkv_track_t *track, break; dp->buffer += len; dp->len -= len; + dp->pos += len; if (size) { struct demux_packet *new = new_demux_packet_from(data, size); if (!new) @@ -2358,8 +2358,8 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) } if (use_this_block) { + uint64_t filepos = block_info->filepos; mkv_d->last_pts = current_pts; - mkv_d->last_filepos = block_info->filepos; for (int i = 0; i < laces; i++) { bstr block = bstr_splice(data, 0, lace_size[i]); @@ -2371,7 +2371,7 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) if (!dp) break; dp->keyframe = keyframe; - dp->pos = mkv_d->last_filepos; + dp->pos = filepos; /* If default_duration is 0, assume no pts value is known * for packets after the first one (rather than all pts * values being the same). Also, don't use it for extra @@ -2392,6 +2392,7 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) mkv_parse_and_add_packet(demuxer, track, dp); talloc_free_children(track->parser_tmp); + filepos += block.len; } if (stream->type == STREAM_VIDEO) {