changeset 17698:14830cce6098

implement STREAM_CTRL_GET_TIME_LENGTH to return the duration of the dvd currently playing
author nicodvb
date Mon, 27 Feb 2006 21:11:28 +0000
parents 3a56bbef9300
children b742a2c71c25
files libmpdemux/stream_dvd.c
diffstat 1 files changed, 60 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/stream_dvd.c	Mon Feb 27 21:08:58 2006 +0000
+++ b/libmpdemux/stream_dvd.c	Mon Feb 27 21:11:28 2006 +0000
@@ -432,6 +432,63 @@
   return msec;
 }
 
+static int mp_get_titleset_length(ifo_handle_t *vts_file, tt_srpt_t *tt_srpt, int vts_no, int title_no)
+{
+    int vts_ttn;  ///< title number within video title set
+    int pgc_no;   ///< program chain number
+    int msec;     ///< time length in milliseconds
+
+    if(!vts_file || !tt_srpt)
+        return 0;
+
+    if(vts_file->vtsi_mat && vts_file->vts_pgcit)
+    {
+        if(tt_srpt->title[title_no].title_set_nr == vts_no)
+        {
+            vts_ttn = tt_srpt->title[title_no].vts_ttn - 1;
+            pgc_no = vts_file->vts_ptt_srpt->title[vts_ttn].ptt[0].pgcn - 1;
+            msec = dvdtimetomsec(&vts_file->vts_pgcit->pgci_srp[pgc_no].pgc->playback_time);
+        }
+    }
+    return msec;
+}
+
+
+static int mp_describe_titleset(dvd_reader_t *dvd, tt_srpt_t *tt_srpt, int vts_no)
+{
+    ifo_handle_t *vts_file;
+    int title_no, msec=0;
+
+    vts_file = ifoOpen(dvd, vts_no);
+    if(!vts_file)
+        return 0;
+
+    if(!vts_file->vtsi_mat || !vts_file->vts_pgcit)
+        return 0;
+
+    for(title_no = 0; title_no < tt_srpt->nr_of_srpts; title_no++)
+    {
+        msec = mp_get_titleset_length(vts_file, tt_srpt, vts_no, title_no);
+        mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title_no + 1, msec / 1000, msec % 1000);
+    }
+    ifoClose(vts_file);
+}
+
+static int control(stream_t *stream,int cmd,void* arg) 
+{
+    switch(cmd) 
+    {
+        case STREAM_CTRL_GET_TIME_LENGTH:
+        {
+            dvd_priv_t *d = stream->priv;
+            *((unsigned int *)arg) = mp_get_titleset_length(d->vts_file, d->tt_srpt, d->cur_title, d->cur_title-1);
+            return 1;
+        }
+    }
+    return STREAM_UNSUPORTED;
+}
+
+
 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
   struct stream_priv_s* p = (struct stream_priv_s*)opts;
   char *filename;
@@ -513,9 +570,6 @@
       unsigned char discid [16]; ///< disk ID, a 128 bit MD5 sum
       int vts_no;   ///< video title set number
       int title_no; ///< title number
-      int vts_ttn;  ///< title number within video title set
-      int pgc_no;   ///< program chain number
-      int msec;     ///< time length in milliseconds
       mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_TITLES=%d\n", tt_srpt->nr_of_srpts);
       for (title_no = 0; title_no < tt_srpt->nr_of_srpts; title_no++)
       {
@@ -523,22 +577,7 @@
         mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_TITLE_%d_ANGLES=%d\n", title_no + 1, tt_srpt->title[title_no].nr_of_angles);
       }
       for (vts_no = 1; vts_no <= vmg_file->vts_atrt->nr_of_vtss; vts_no++)
-      {
-        vts_file = ifoOpen(dvd, vts_no);
-        if (vts_file)
-        {
-          if (vts_file->vtsi_mat && vts_file->vts_pgcit)
-            for (title_no = 0; title_no < tt_srpt->nr_of_srpts; title_no++)
-              if (tt_srpt->title[title_no].title_set_nr == vts_no)
-              {
-                vts_ttn = tt_srpt->title[title_no].vts_ttn - 1;
-                pgc_no = vts_file->vts_ptt_srpt->title[vts_ttn].ptt[0].pgcn - 1;
-                msec = dvdtimetomsec(&vts_file->vts_pgcit->pgci_srp[pgc_no].pgc->playback_time);
-                mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_DVD_TITLE_%d_LENGTH=%d.%03d\n", title_no + 1, msec / 1000, msec % 1000);
-              }
-          ifoClose(vts_file);
-        }
-      }
+        mp_describe_titleset(dvd, tt_srpt, vts_no);
       if (DVDDiscID(dvd, discid) >= 0)
       {
         int i;
@@ -628,6 +667,7 @@
     d->vmg_file=vmg_file;
     d->tt_srpt=tt_srpt;
     d->vts_file=vts_file;
+    d->cur_title = dvd_title+1;
 
     /**
      * Check number of audio channels and types
@@ -780,6 +820,7 @@
     stream->flags = STREAM_READ | STREAM_SEEK;
     stream->fill_buffer = fill_buffer;
     stream->seek = seek;
+    stream->control = control;
     stream->close = stream_dvd_close;
     stream->start_pos = (off_t)d->cur_pack*2048;
     stream->end_pos = (off_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048;