Web lists-archives.com

[MPlayer-dev-eng] [PATCH] Automatically detect the first media data track in the cue driver




The first track of a Video CD usually stores metadata inside an ISO 9660
filesystem and media data starts from track 2. However, the ISO 9660
filesystem can be absent and media data can start from track 1. (Audio
CD images always start with track 1.)

To find out which track to start playback with (if no track has been
given), check for an ISO 9660 filesystem in track 1 instead of using
track 1 unconditionally.

Ingo
Index: stream/stream_cue.c
===================================================================
--- stream/stream_cue.c	(revision 37464)
+++ stream/stream_cue.c	(working copy)
@@ -274,6 +274,19 @@
   return fd_bin;
 }
 
+static int cue_get_first_track(int fd_bin) {
+  char vol_descriptor[5];
+
+  if (lseek(fd_bin, 16 * VCD_SECTOR_SIZE + VCD_SECTOR_OFFS + 1, SEEK_SET) != -1)
+    if (read(fd_bin, vol_descriptor, 5) == 5)
+      if (strncmp(vol_descriptor, "CD001", 5) == 0)
+        /* ISO 9660 filesystem, so data starting in track 2 */
+        return 2;
+
+  /* data starting in track 1 */
+  return 1;
+}
+
 static inline int cue_msf_2_sector(int minute, int second, int frame) {
  return frame + (second + minute * 60 ) * 75;
 }
@@ -599,6 +612,9 @@
   filename = strdup(p->filename);
   if(!filename)
     goto err_out;
+  f = cue_read_cue(filename);
+  if(f < 0)
+    goto err_out;
   colon = strstr(filename, ":");
   if(colon) {
     if(strlen(colon)>1)
@@ -606,11 +622,8 @@
     *colon = 0;
   }
   if(!track)
-    track = 1;
+    track = cue_get_first_track(f);
 
-  f = cue_read_cue(filename);
-  if(f < 0)
-    goto err_out;
   cue_read_toc();
   ret=cue_seek_to_track(stream, track);
   if(ret<0){
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng