changeset 15476:5eb4994a691f

ported cue:// to the new stream api; note: this stream must still be optimized in its read() and seek() functions
author nicodvb
date Sun, 15 May 2005 07:38:42 +0000
parents ffe2b5261af5
children 15f012150986
files libmpdemux/cue_read.c libmpdemux/cue_read.h libmpdemux/open.c libmpdemux/stream.c
diffstat 4 files changed, 113 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/cue_read.c	Sat May 14 23:51:22 2005 +0000
+++ b/libmpdemux/cue_read.c	Sun May 15 07:38:42 2005 +0000
@@ -16,6 +16,9 @@
 #include "stream.h"
 
 #include "cue_read.h"
+#include "help_mp.h"
+#include "../m_option.h"
+#include "../m_struct.h"
 
 #define byte    unsigned char
 #define SIZERAW 2352
@@ -32,6 +35,25 @@
 #define MODE2_2336 40
 #define UNKNOWN -1
 
+static struct stream_priv_s {
+  char* filename;
+} stream_priv_dflts = {
+  NULL
+};
+
+#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
+/// URL definition
+static m_option_t stream_opts_fields[] = {
+  { "string", ST_OFF(filename), CONF_TYPE_STRING, 0, 0 ,0, NULL},
+  { NULL, NULL, 0, 0, 0, 0,  NULL }
+};
+static struct m_struct_st stream_opts = {
+  "cue",
+  sizeof(struct stream_priv_s),
+  &stream_priv_dflts,
+  stream_opts_fields
+};
+
 static FILE* fd_cue;
 static int fd_bin = 0;
 
@@ -74,7 +96,7 @@
 static int nTracks = 0;
 
 /* presumes Line is preloaded with the "current" line of the file */
-int cue_getTrackinfo(char *Line, tTrack *track)
+static int cue_getTrackinfo(char *Line, tTrack *track)
 {
   char inum[3];
   char min;
@@ -139,7 +161,7 @@
  * on the arrays to have the same size, thus we need to make
  * sure the sizes are in sync.
  */
-int cue_find_bin (char *firstline) {
+static int cue_find_bin (char *firstline) {
   int i,j;
   char s[256];
   char t[256];
@@ -251,7 +273,7 @@
                            cue_current_pos.frame);
 }
 
-inline void cue_set_msf(unsigned int sect){
+static inline void cue_set_msf(unsigned int sect){
   cue_current_pos.frame=sect%75;
   sect=sect/75;
   cue_current_pos.second=sect%60;
@@ -278,7 +300,7 @@
 }
 
 
-int cue_read_cue (char *in_cue_filename)
+static int cue_read_cue (char *in_cue_filename)
 {
   struct stat filestat;
   char sLine[256];
@@ -410,7 +432,7 @@
 
 
 
-int cue_read_toc_entry() {
+static int cue_read_toc_entry() {
 
   int track = cue_current_pos.track - 1;
 
@@ -440,8 +462,8 @@
   return 0;
 }
 
-int cue_read_raw(char *buf) {
-  int position;
+static int cue_read_raw(char *buf) {
+  unsigned long position;
   int track = cue_current_pos.track - 1;
 
   /* get the mode of the bin file part and calc the positon */
@@ -470,7 +492,7 @@
 
 
 
-int cue_vcd_seek_to_track (int track){
+static int cue_vcd_seek_to_track (int track){
   cue_current_pos.track  = track;
 
   if (cue_read_toc_entry ())
@@ -479,7 +501,7 @@
   return VCD_SECTOR_DATA * cue_get_msf();
 }
 
-int cue_vcd_get_track_end (int track){
+static int cue_vcd_get_track_end (int track){
   cue_current_pos.frame = tracks[track].frame;
   cue_current_pos.second = tracks[track].second;
   cue_current_pos.minute = tracks[track].minute;
@@ -487,13 +509,13 @@
   return VCD_SECTOR_DATA * cue_get_msf();
 }
 
-void cue_vcd_read_toc(){
+static void cue_vcd_read_toc(){
   int i;
   for (i = 0; i < nTracks; ++i) {
 
     mp_msg(MSGT_OPEN,MSGL_INFO,
            "track %02d:  format=%d  %02d:%02d:%02d\n",
-           i,
+           i+1,
            tracks[i].mode,
            tracks[i].minute,
            tracks[i].second,
@@ -505,7 +527,7 @@
 
 static char vcd_buf[VCD_SECTOR_SIZE];
 
-int cue_vcd_read(char *mem){
+static int cue_vcd_read(stream_t *stream, char *mem, int size) {
 
   if (cue_read_raw(vcd_buf)==-1) return 0; // EOF?
 
@@ -523,3 +545,73 @@
 
   return VCD_SECTOR_DATA;
 }
+
+static int seek(stream_t *s,off_t newpos) {
+  s->pos=newpos;
+  cue_set_msf(s->pos/VCD_SECTOR_DATA);
+  return 1;
+}
+
+
+static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
+  struct stream_priv_s* p = (struct stream_priv_s*)opts;
+  int ret,ret2,f,track = 0;
+  char *filename = NULL, *colon = NULL;
+
+  if(mode != STREAM_READ || !p->filename) {
+    m_struct_free(&stream_opts,opts);
+    return STREAM_UNSUPORTED;
+  }
+  filename = strdup(p->filename);
+  if(!filename) {
+    m_struct_free(&stream_opts,opts);
+    return STREAM_UNSUPORTED;
+  }
+  colon = strstr(filename, ":");
+  if(colon) {
+    if(strlen(colon)>1)
+      track = atoi(colon+1);
+    *colon = 0;
+  }
+  if(!track)
+    track = 1;
+  
+  f = cue_read_cue(filename);
+  if(f < 0) {
+    m_struct_free(&stream_opts,opts);
+    return STREAM_UNSUPORTED;
+  }
+  cue_vcd_read_toc();
+  ret2=cue_vcd_get_track_end(track);
+  ret=cue_vcd_seek_to_track(track);
+  if(ret<0){ 
+    mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");
+    return STREAM_UNSUPORTED;
+  }
+  mp_msg(MSGT_OPEN,MSGL_INFO,"CUE stream_open, filename=%s, track=%d, available tracks: %d -> %d\n", filename, track, ret, ret2);
+
+  stream->fd = f;
+  stream->type = STREAMTYPE_VCDBINCUE;
+  stream->sector_size = VCD_SECTOR_DATA;
+  stream->flags = STREAM_READ | STREAM_SEEK_FW;
+  stream->start_pos = ret;
+  stream->end_pos = ret2;
+  stream->fill_buffer = cue_vcd_read;
+  stream->seek = seek;
+
+  free(filename);
+  m_struct_free(&stream_opts,opts);
+  return STREAM_OK;
+}
+
+stream_info_t stream_info_cue = {
+  "CUE track",
+  "cue",
+  "Albeu",
+  "based on the code from ???",
+  open_s,
+  { "cue", NULL },
+  &stream_opts,
+  1 // Urls are an option string
+};
+
--- a/libmpdemux/cue_read.h	Sat May 14 23:51:22 2005 +0000
+++ b/libmpdemux/cue_read.h	Sun May 15 07:38:42 2005 +0000
@@ -1,7 +1,7 @@
 
-int cue_read_cue (char *in_cue_filename);
-int cue_vcd_seek_to_track (int track);
-int cue_vcd_get_track_end (int track);
-void cue_vcd_read_toc ();
-int cue_vcd_read(char *mem);
-inline void cue_set_msf(unsigned int sect);
+//int cue_read_cue (char *in_cue_filename);
+//int cue_vcd_seek_to_track (int track);
+//int cue_vcd_get_track_end (int track);
+//void cue_vcd_read_toc ();
+//int cue_vcd_read(char *mem);
+//inline void cue_set_msf(unsigned int sect);
--- a/libmpdemux/open.c	Sat May 14 23:51:22 2005 +0000
+++ b/libmpdemux/open.c	Sun May 15 07:38:42 2005 +0000
@@ -32,7 +32,6 @@
 
 /// We keep these 2 for the gui atm, but they will be removed.
 int dvd_title=0;
-int vcd_track=0;
 
 int dvd_chapter=1;
 int dvd_last_chapter=0;
@@ -67,10 +66,6 @@
 	{ "mono", "stereo", "unknown", "unknown", "5.1/6.1", "5.1" };
 #endif
 
-#include "cue_read.h"
-
-
-
 // Define function about auth the libsmbclient library
 // FIXME: I really do not not is this function is properly working
 
@@ -126,35 +121,6 @@
    return NULL;
 }
 
-// for opening of vcds in bincue files
-if(strncmp("cue://",filename,6) == 0){
-  int ret,ret2;
-  char* p = filename + 6;
-  vcd_track = 1;
-  p = strchr(p,':');
-  if(p && p[1] != '\0') {
-    vcd_track = strtol(p+1,NULL,0);
-    if(vcd_track < 1){ 
-      mp_msg(MSGT_OPEN,MSGL_ERR,"Invalid cue track %s\n",p+1);
-      return NULL;
-    }
-    p[0] = '\0';
-  }
-  f = cue_read_cue (filename + 6);
-  if(p && p[1] != '\0') p[0] = ':';
-  if (f == -1) return NULL;
-  cue_vcd_read_toc();
-  ret2=cue_vcd_get_track_end(vcd_track);
-  ret=cue_vcd_seek_to_track(vcd_track);
-  if(ret<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");return NULL;}
-  mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X  end: 0x%X\n",ret,ret2);
-
-  stream=new_stream(f,STREAMTYPE_VCDBINCUE);
-  stream->start_pos=ret;
-  stream->end_pos=ret2;
-  return stream;
-}
-
 
 //============ Open DVD title ==============
 #ifdef USE_DVDNAV
@@ -497,7 +463,7 @@
     strncmp("vcd://", filename, 6) && strncmp("dvb://", filename, 6) &&
     strncmp("cdda://", filename, 7) && strncmp("cddb://", filename, 7) &&
     strncmp("mpst://", filename, 7) && strncmp("tivo://", filename, 7) &&
-    strncmp("file://", filename, 7) && 
+    strncmp("file://", filename, 7) && strncmp("cue://", filename, 6) &&
     strstr(filename, "://")) {
      url = url_new(filename);
     }
--- a/libmpdemux/stream.c	Sat May 14 23:51:22 2005 +0000
+++ b/libmpdemux/stream.c	Sun May 15 07:38:42 2005 +0000
@@ -35,8 +35,6 @@
 extern int verbose; // defined in mplayer.c
 void cache_uninit(stream_t *s); // defined in cache2.c
 
-#include "cue_read.h"
-
 //#include "vcd_read_bincue.h"
 
 #ifdef USE_DVDREAD
@@ -68,6 +66,7 @@
 extern stream_info_t stream_info_vstream;
 #endif
 
+extern stream_info_t stream_info_cue;
 extern stream_info_t stream_info_null;
 extern stream_info_t stream_info_file;
 
@@ -90,6 +89,7 @@
 #ifdef HAVE_VSTREAM
   &stream_info_vstream,
 #endif
+  &stream_info_cue,
   &stream_info_null,
   &stream_info_file,
   NULL
@@ -203,8 +203,6 @@
 #else
     len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
 #endif
-  case STREAMTYPE_VCDBINCUE:
-    len=cue_vcd_read(s->buffer);break;
 #ifdef USE_DVDNAV
   case STREAMTYPE_DVDNAV: {
     dvdnav_stream_read((dvdnav_priv_t*)s->priv,s->buffer,&len);
@@ -253,8 +251,6 @@
 #else
     newpos=pos&(~(STREAM_BUFFER_SIZE-1));break;
 #endif
-  case STREAMTYPE_VCDBINCUE:
-    newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break;
   case STREAMTYPE_DVD:
     newpos=pos/2048; newpos*=2048; break;
   default:
@@ -291,10 +287,6 @@
     if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1;
     break;
 #endif
-  case STREAMTYPE_VCDBINCUE:
-    s->pos=newpos; // real seek
-    cue_set_msf(s->pos/VCD_SECTOR_DATA);
-    break;
 #ifdef USE_DVDNAV
   case STREAMTYPE_DVDNAV: {
     if (newpos==0) {