avformat/matroskaenc: fix MAX_CUEPOINT_SIZE calculation
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 9 Aug 2014 02:49:09 +0000 (04:49 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 10 Aug 2014 20:40:50 +0000 (22:40 +0200)
Fixes assertion failure
Fixes Ticket3822

as a side-effect this makes some mkv files a few bytes smaller

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 64d029de41ed556b765df50c7080b06fd5a86417)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/matroskaenc.c
tests/ref/lavf/mkv

index 92d091f..fc9c728 100644 (file)
@@ -445,8 +445,21 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra
         ebml_master cuepoint, track_positions;
         mkv_cuepoint *entry = &cues->entries[i];
         uint64_t pts = entry->pts;
         ebml_master cuepoint, track_positions;
         mkv_cuepoint *entry = &cues->entries[i];
         uint64_t pts = entry->pts;
+        int ctp_nb = 0;
 
 
-        cuepoint = start_ebml_master(pb, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(num_tracks));
+        // Calculate the number of entries, so we know the element size
+        for (j = 0; j < num_tracks; j++)
+            tracks[j].has_cue = 0;
+        for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {
+            int tracknum = entry[j].stream_idx;
+            av_assert0(tracknum>=0 && tracknum<num_tracks);
+            if (tracks[tracknum].has_cue && s->streams[tracknum]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE)
+                continue;
+            tracks[tracknum].has_cue = 1;
+            ctp_nb ++;
+        }
+
+        cuepoint = start_ebml_master(pb, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(ctp_nb));
         put_ebml_uint(pb, MATROSKA_ID_CUETIME, pts);
 
         // put all the entries from different tracks that have the exact same
         put_ebml_uint(pb, MATROSKA_ID_CUETIME, pts);
 
         // put all the entries from different tracks that have the exact same
index 97c9864..edbfe60 100644 (file)
@@ -1,5 +1,5 @@
-bda342503392d517955e1112def7b03a *./tests/data/lavf/lavf.mkv
-472671 ./tests/data/lavf/lavf.mkv
+bab98f5a04a9f7991fb960041c996478 *./tests/data/lavf/lavf.mkv
+472668 ./tests/data/lavf/lavf.mkv
 ./tests/data/lavf/lavf.mkv CRC=0xec6c3c68
 c93950920d4ee57eb3ff5ba0cf0c8b19 *./tests/data/lavf/lavf.mkv
 320412 ./tests/data/lavf/lavf.mkv
 ./tests/data/lavf/lavf.mkv CRC=0xec6c3c68
 c93950920d4ee57eb3ff5ba0cf0c8b19 *./tests/data/lavf/lavf.mkv
 320412 ./tests/data/lavf/lavf.mkv