changeset 9886:e578e4375434

Port vcd to the new API
author albeu
date Wed, 09 Apr 2003 07:31:11 +0000
parents 98712065a08d
children d862231858d5
files libmpdemux/Makefile libmpdemux/open.c libmpdemux/stream.c libmpdemux/stream.h libmpdemux/stream_vcd.c
diffstat 5 files changed, 149 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/Makefile	Tue Apr 08 23:46:35 2003 +0000
+++ b/libmpdemux/Makefile	Wed Apr 09 07:31:11 2003 +0000
@@ -3,7 +3,7 @@
 
 include ../config.mak
 
-SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_pva.c demux_viv.c demuxer.c dvdauth.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c tv.c tvi_dummy.c tvi_v4l.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c demux_bmp.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_oss.c audio_in.c demux_smjpeg.c cue_read.c extension.c demux_gif.c demux_ts.c
+SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_pva.c demux_viv.c demuxer.c dvdauth.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c stream_vcd.c tv.c tvi_dummy.c tvi_v4l.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c demux_bmp.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_oss.c audio_in.c demux_smjpeg.c cue_read.c extension.c demux_gif.c demux_ts.c
 ifeq ($(XMMS_PLUGINS),yes)
 SRCS += demux_xmms.c
 endif 
--- a/libmpdemux/open.c	Tue Apr 08 23:46:35 2003 +0000
+++ b/libmpdemux/open.c	Wed Apr 09 07:31:11 2003 +0000
@@ -144,37 +144,6 @@
    return NULL;
 }
 
-//============ Open VideoCD track ==============
-#ifdef HAVE_VCD
-if(strncmp("vcd://",filename,6) == 0){
-  int ret,ret2;
-  if(!cdrom_device) cdrom_device=strdup(DEFAULT_CDROM_DEVICE);
-  f=open(cdrom_device,O_RDONLY);
-  if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,cdrom_device);return NULL; }
-  vcd_track = filename[6] == '\0' ? 1 : strtol(filename+6,NULL,0);
-  if(vcd_track < 1){ 
-    mp_msg(MSGT_OPEN,MSGL_ERR,"Invalid vcd track %s\n",filename+6);
-    return NULL;
-  }
-  vcd_read_toc(f);
-  ret2=vcd_get_track_end(f,vcd_track);
-  if(ret2<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");return NULL;}
-  ret=vcd_seek_to_track(f,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);
-#ifdef __FreeBSD__
-  if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
-        perror ( "Error in CDRIOCSETBLOCKSIZE");
-  }
-#endif
-  stream=new_stream(f,STREAMTYPE_VCD);
-  stream->start_pos=ret;
-  stream->end_pos=ret2;
-  return stream;
-}
-#endif
-
-
 // for opening of vcds in bincue files
 if(strncmp("cue://",filename,6) == 0){
   int ret,ret2;
--- a/libmpdemux/stream.c	Tue Apr 08 23:46:35 2003 +0000
+++ b/libmpdemux/stream.c	Wed Apr 09 07:31:11 2003 +0000
@@ -29,18 +29,6 @@
 
 #include "cue_read.h"
 
-#ifdef HAVE_VCD
-
-#ifdef __FreeBSD__
-#include "vcd_read_fbsd.h" 
-#elif defined(__NetBSD__)
-#include "vcd_read_nbsd.h" 
-#else
-#include "vcd_read.h"
-#endif
-
-#endif
-
 //#include "vcd_read_bincue.h"
 
 #ifdef USE_DVDREAD
@@ -49,16 +37,13 @@
 void dvd_close(dvd_priv_t *d);
 #endif
 
-#ifdef HAVE_CDDA
-int read_cdda(stream_t* s);
-void seek_cdda(stream_t* s);
-void close_cdda(stream_t* s);
-#endif
-
 #ifdef LIBSMBCLIENT
 #include "libsmbclient.h"
 #endif
 
+#ifdef HAVE_VCD
+extern stream_info_t stream_info_vcd;
+#endif
 #ifdef HAVE_CDDA
 extern stream_info_t stream_info_cdda;
 #endif
@@ -68,6 +53,9 @@
 extern stream_info_t stream_info_file;
 
 stream_info_t* auto_open_streams[] = {
+#ifdef HAVE_VCD
+  &stream_info_vcd,
+#endif
 #ifdef HAVE_CDDA
   &stream_info_cdda,
 #endif
@@ -186,10 +174,6 @@
 #else
     len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
 #endif
-#ifdef HAVE_VCD
-  case STREAMTYPE_VCD:
-    len=vcd_read(s->fd,s->buffer);break;
-#endif
   case STREAMTYPE_VCDBINCUE:
     len=cue_vcd_read(s->buffer);break;
 #ifdef USE_DVDNAV
@@ -247,8 +231,6 @@
 #else
     newpos=pos&(~(STREAM_BUFFER_SIZE-1));break;
 #endif
-  case STREAMTYPE_VCD:
-    newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break;
   case STREAMTYPE_VCDBINCUE:
     newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break;
   case STREAMTYPE_DVD:
@@ -287,12 +269,6 @@
     if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1;
     break;
 #endif
-#ifdef HAVE_VCD
-  case STREAMTYPE_VCD:
-    s->pos=newpos; // real seek
-    vcd_set_msf(s->pos/VCD_SECTOR_DATA);
-    break;
-#endif
   case STREAMTYPE_VCDBINCUE:
     s->pos=newpos; // real seek
     cue_set_msf(s->pos/VCD_SECTOR_DATA);
--- a/libmpdemux/stream.h	Tue Apr 08 23:46:35 2003 +0000
+++ b/libmpdemux/stream.h	Wed Apr 09 07:31:11 2003 +0000
@@ -51,9 +51,6 @@
 #include "network.h"
 #endif
 
-int vcd_seek_to_track(int fd,int track);
-void vcd_read_toc(int fd);
-
 struct stream_st;
 typedef struct stream_info_st {
   const char *info;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpdemux/stream_vcd.c	Wed Apr 09 07:31:11 2003 +0000
@@ -0,0 +1,142 @@
+
+#include "config.h"
+
+#ifdef HAVE_VCD
+#include "mp_msg.h"
+#include "stream.h"
+#include "help_mp.h"
+#include "../m_option.h"
+#include "../m_struct.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+#ifdef __FreeBSD__
+#include <sys/cdrio.h>
+#include "vcd_read_fbsd.h" 
+#elif defined(__NetBSD__)
+#include "vcd_read_nbsd.h" 
+#else
+#include "vcd_read.h"
+#endif
+
+static struct stream_priv_s {
+  int track;
+  char* device;
+} stream_priv_dflts = {
+  1,
+  DEFAULT_CDROM_DEVICE
+};
+
+#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
+/// URL definition
+static m_option_t stream_opts_fields[] = {
+  { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
+  { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
+  /// For url parsing
+  { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
+  { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
+  { NULL, NULL, 0, 0, 0, 0,  NULL }
+};
+static struct m_struct_st stream_opts = {
+  "vcd",
+  sizeof(struct stream_priv_s),
+  &stream_priv_dflts,
+  stream_opts_fields
+};
+
+static int fill_buffer(stream_t *s, char* buffer, int max_len){
+  return vcd_read(s->priv,buffer);
+}
+
+static int seek(stream_t *s,off_t newpos) {
+  s->pos = newpos;
+  vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA);
+  return 1;
+}
+
+static void close_s(stream_t *stream) {
+  free(stream->priv);
+}
+
+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;
+  mp_vcd_priv_t* vcd;
+#ifdef __FreeBSD__
+  int bsize = VCD_SECTOR_SIZE;
+#endif
+
+  if(mode != STREAM_READ) {
+    m_struct_free(&stream_opts,opts);
+    return STREAM_UNSUPORTED;
+  }
+
+  f=open(p->device,O_RDONLY);
+  if(f<0){ 
+    mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device);
+    close(f);
+    m_struct_free(&stream_opts,opts);
+    return STREAM_ERROR;
+  }
+
+  vcd = vcd_read_toc(f);
+  if(!vcd) {
+    mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n");
+    close(f);
+    m_struct_free(&stream_opts,opts);
+    return STREAM_ERROR;
+  }
+  ret2=vcd_get_track_end(vcd,p->track);
+  if(ret2<0){
+    mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");
+    close(f);
+    free(vcd);
+    m_struct_free(&stream_opts,opts);
+    return STREAM_ERROR;
+  }
+  ret=vcd_seek_to_track(vcd,p->track);
+  if(ret<0){
+    mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");
+    close(f);
+    free(vcd);
+    m_struct_free(&stream_opts,opts);
+    return STREAM_ERROR;
+  }
+  mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X  end: 0x%X\n",ret,ret2);
+
+#ifdef __FreeBSD__
+  if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
+    mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE");
+  }
+#endif
+
+  stream->fd = f;
+  stream->type = STREAMTYPE_VCD;
+  stream->sector_size = VCD_SECTOR_DATA;
+  stream->start_pos=ret;
+  stream->end_pos=ret2;
+  stream->priv = vcd;
+
+  stream->fill_buffer = fill_buffer;
+  stream->seek = seek;
+  stream->close = close_s;
+
+  m_struct_free(&stream_opts,opts);
+  return STREAM_OK;
+}
+
+stream_info_t stream_info_vcd = {
+  "Video CD",
+  "vcd",
+  "Albeu",
+  "based on the code from ???",
+  open_s,
+  { "vcd", NULL },
+  &stream_opts,
+  1 // Urls are an option string
+};
+
+#endif