]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
mkv muxer: always create first chapter at position 0
authorJaroslav Kysela <perex@perex.cz>
Thu, 18 May 2017 06:41:18 +0000 (08:41 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 22 May 2017 12:02:57 +0000 (14:02 +0200)
src/muxer/muxer_mkv.c

index 016a90be60210096c772e67efc7696871805965e..8cdee2c1862cdeb6aa0c2446396da84a595b85ab 100644 (file)
@@ -88,7 +88,7 @@ typedef struct mk_cue {
  */
 typedef struct mk_chapter {
   TAILQ_ENTRY(mk_chapter) link;
-  int uuid;
+  uint32_t uuid;
   int64_t ts;
 } mk_chapter_t;
 
@@ -911,6 +911,22 @@ addcue(mk_muxer_t *mk, int64_t pts, int tracknum)
 }
 
 
+/**
+ *
+ */
+static void
+mk_add_chapter0(mk_muxer_t *mk, uint32_t uuid, int64_t ts)
+{
+  mk_chapter_t *ch;
+
+  ch = malloc(sizeof(mk_chapter_t));
+
+  ch->uuid = uuid;
+  ch->ts = ts;
+
+  TAILQ_INSERT_TAIL(&mk->chapters, ch, link);
+}
+
 /**
  *
  */
@@ -922,23 +938,21 @@ mk_add_chapter(mk_muxer_t *mk, int64_t ts)
 
   ch = TAILQ_LAST(&mk->chapters, mk_chapter_queue);
   if(ch) {
-    // don't add a new chapter if the previous one was
-    // added less than 10s ago
-    if(ts - ch->ts < 10000)
+    /* don't add a new chapter if the previous one was added less than 5s ago */
+    if(ts - ch->ts < 5000)
       return;
 
     uuid = ch->uuid + 1;
-  }
-  else {
+  } else {
     uuid = 1;
+    /* create first chapter at zero position */
+    if (ts >= 5000) {
+      mk_add_chapter0(mk, uuid++, ts);
+    } else {
+      ts = 0;
+    }
   }
-
-  ch = malloc(sizeof(mk_chapter_t));
-
-  ch->uuid = uuid;
-  ch->ts = ts;
-
-  TAILQ_INSERT_TAIL(&mk->chapters, ch, link);
+  mk_add_chapter0(mk, uuid, ts);
 }
 
 /**
@@ -1329,6 +1343,7 @@ mkv_muxer_open_stream(muxer_t *m, int fd)
   mk->filename = strdup("Live stream");
   mk->fd = fd;
   mk->cluster_maxsize = 0;
+  mk->totduration = 0;
 
   return 0;
 }
@@ -1365,6 +1380,7 @@ mkv_muxer_open_file(muxer_t *m, const char *filename)
   mk->fd = fd;
   mk->cluster_maxsize = 2000000;
   mk->seekable = 1;
+  mk->totduration = 0;
 
   return 0;
 }