From 6c4cc0f640874f6098ef98bad54c3fc0fa7c615f Mon Sep 17 00:00:00 2001 From: Aaron Colwell Date: Thu, 22 Sep 2011 07:51:00 -0700 Subject: [PATCH] matroskadec: Fix seeking for matroska files with CUES before first cluster This change fixes a bug where seeking doesn't work properly for matroska files that have the CUES element before the first cluster. This bug was accidentally introduced a few months ago by my deferred CUES loading patch . When the CUES element appears before the first cluster in the file, the data is parsed and placed in matroska->index but that data is never added to the seek index. Currently the transfer from matroska->index to the seek index only happens when matroska_parse_cues() is called. Matroska_parse_cues() only gets called on a seek if cues_parsing_deferred is set. Cues_parsing_deferred only gets set if parsing the CUES requires seeking past the first cluster. There is no code to handle the case where CUES is before the first cluster. This fix essentially restores the matroska->index processing that was happening at the end of matroska_read_header() before I made my CUES deferral change. In the case where CUES is before the first cluster, matroska->index will have data and the seek index will be updated. In the case where CUES is later in the file, matroska->index will be empty and cues_parsing_deferred will be set so loading will happen later. Signed-off-by: Michael Niedermayer --- libavformat/matroskadec.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 43eb58f46a..e359fdc3ca 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1236,21 +1236,12 @@ static void matroska_execute_seekhead(MatroskaDemuxContext *matroska) } } -static void matroska_parse_cues(MatroskaDemuxContext *matroska) { - EbmlList *seekhead_list = &matroska->seekhead; - MatroskaSeekhead *seekhead = seekhead_list->elem; +static void matroska_add_index_entries(MatroskaDemuxContext *matroska) { EbmlList *index_list; MatroskaIndex *index; int index_scale = 1; int i, j; - for (i = 0; i < seekhead_list->nb_elem; i++) - if (seekhead[i].id == MATROSKA_ID_CUES) - break; - assert(i <= seekhead_list->nb_elem); - - matroska_parse_seekhead_entry(matroska, i); - index_list = &matroska->index; index = index_list->elem; if (index_list->nb_elem @@ -1272,6 +1263,20 @@ static void matroska_parse_cues(MatroskaDemuxContext *matroska) { } } +static void matroska_parse_cues(MatroskaDemuxContext *matroska) { + EbmlList *seekhead_list = &matroska->seekhead; + MatroskaSeekhead *seekhead = seekhead_list->elem; + int i; + + for (i = 0; i < seekhead_list->nb_elem; i++) + if (seekhead[i].id == MATROSKA_ID_CUES) + break; + assert(i <= seekhead_list->nb_elem); + + matroska_parse_seekhead_entry(matroska, i); + matroska_add_index_entries(matroska); +} + static int matroska_aac_profile(char *codec_id) { static const char * const aac_profiles[] = { "MAIN", "LC", "SSR" }; @@ -1659,6 +1664,8 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) max_start = chapters[i].start; } + matroska_add_index_entries(matroska); + matroska_convert_tags(s); return 0;