changeset 30977:0b45d6af9ffe

Export VCD tracks as chapters, just like for cue:// URLs.
author reimar
date Mon, 05 Apr 2010 16:40:04 +0000
parents 6955998c187e
children 843571a87e21
files stream/stream_vcd.c
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/stream/stream_vcd.c	Mon Apr 05 16:38:40 2010 +0000
+++ b/stream/stream_vcd.c	Mon Apr 05 16:40:04 2010 +0000
@@ -91,6 +91,40 @@
   return 1;
 }
 
+static int control(stream_t *stream, int cmd, void *arg) {
+  struct stream_priv_s *p = stream->priv;
+  switch(cmd) {
+    case STREAM_CTRL_GET_NUM_CHAPTERS:
+    {
+      mp_vcd_priv_t *vcd = vcd_read_toc(stream->fd);
+      if (!vcd)
+        break;
+      *(unsigned int *)arg = vcd->tochdr.cdth_trk1;
+      return STREAM_OK;
+    }
+    case STREAM_CTRL_SEEK_TO_CHAPTER:
+    {
+      int r;
+      unsigned int track = *(unsigned int *)arg + 1;
+      mp_vcd_priv_t *vcd = vcd_read_toc(stream->fd);
+      if (!vcd)
+        break;
+      r = vcd_seek_to_track(vcd, track);
+      if (r >= 0) {
+        p->track = track;
+        return STREAM_OK;
+      }
+      break;
+    }
+    case STREAM_CTRL_GET_CURRENT_CHAPTER:
+    {
+      *(unsigned int *)arg = p->track - 1;
+      return STREAM_OK;
+    }
+  }
+  return STREAM_UNSUPPORTED;
+}
+
 static void close_s(stream_t *stream) {
   free(stream->priv);
 }
@@ -203,6 +237,7 @@
 
   stream->fill_buffer = fill_buffer;
   stream->seek = seek;
+  stream->control = control;
   stream->close = close_s;
   *file_format = DEMUXER_TYPE_MPEG_PS;