diff utils.c @ 3323:4bf98e198eec libavformat

Add id to AVChapter, untested (where do i find matroska files with chapters?).
author michael
date Fri, 23 May 2008 13:02:27 +0000
parents f63630e08b59
children 56b8145afb23
line wrap: on
line diff
--- a/utils.c	Fri May 23 12:45:03 2008 +0000
+++ b/utils.c	Fri May 23 13:02:27 2008 +0000
@@ -2234,18 +2234,29 @@
     }
 }
 
-int ff_new_chapter(AVFormatContext *s, int64_t start, int64_t end, const char *title)
+int ff_new_chapter(AVFormatContext *s, int id, int64_t start, int64_t end, const char *title)
 {
-    AVChapter *chapter = av_mallocz(sizeof(AVChapter));
+    AVChapter *chapter = NULL;
+    int i;
+
+    for(i=0; i<s->num_chapters; i++)
+        if(s->chapters[i]->id == id)
+            chapter = s->chapters[i];
+
+    if(!chapter){
+        chapter= av_mallocz(sizeof(AVChapter));
     if(!chapter)
         return AVERROR(ENOMEM);
+        dynarray_add(&s->chapters, &s->num_chapters, chapter);
+    }
+    if(chapter->title)
+        av_free(chapter->title);
     if (title)
         chapter->title = av_strdup(title);
+    chapter->id    = id;
     chapter->start = start;
     chapter->end = end;
 
-    dynarray_add(&s->chapters, &s->num_chapters, chapter);
-
     return 0;
 }