diff options
Diffstat (limited to 'src/input/input_vcd.c')
-rw-r--r-- | src/input/input_vcd.c | 542 |
1 files changed, 379 insertions, 163 deletions
diff --git a/src/input/input_vcd.c b/src/input/input_vcd.c index 1a4229eb4..2698a620a 100644 --- a/src/input/input_vcd.c +++ b/src/input/input_vcd.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: input_vcd.c,v 1.2 2001/04/19 09:46:57 f1rmb Exp $ + * $Id: input_vcd.c,v 1.3 2001/05/06 02:37:59 f1rmb Exp $ */ #ifdef HAVE_CONFIG_H @@ -60,6 +60,12 @@ typedef struct { } cdsector_t; typedef struct { + + input_plugin_t input_plugin; + + char *mrl; + config_values_t *config; + int fd; #if defined (__linux__) @@ -79,101 +85,105 @@ typedef struct { char *filelist[100]; -} input_vcd_t; - -static input_vcd_t gVCD; - -static void input_plugin_init (void) { - int i; - - gVCD.fd = -1; - for (i=0; i<100; i++) - gVCD.filelist[i] = (char *) malloc (256); -} +} vcd_input_plugin_t; +/* ***************************************************************** */ +/* Private functions */ +/* ***************************************************************** */ #if defined (__linux__) -static int input_vcd_read_toc (void) { +static int input_vcd_read_toc (vcd_input_plugin_t *this) { int i; /* read TOC header */ - if ( ioctl(gVCD.fd, CDROMREADTOCHDR, &gVCD.tochdr) == -1 ) { + if ( ioctl(this->fd, CDROMREADTOCHDR, &this->tochdr) == -1 ) { fprintf (stderr, "input_vcd : error in ioctl CDROMREADTOCHDR\n"); return -1; } /* read individual tracks */ - for (i=gVCD.tochdr.cdth_trk0; i<=gVCD.tochdr.cdth_trk1; i++) { - gVCD.tocent[i-1].cdte_track = i; - gVCD.tocent[i-1].cdte_format = CDROM_MSF; - if ( ioctl(gVCD.fd, CDROMREADTOCENTRY, &gVCD.tocent[i-1]) == -1 ) { + for (i=this->tochdr.cdth_trk0; i<=this->tochdr.cdth_trk1; i++) { + this->tocent[i-1].cdte_track = i; + this->tocent[i-1].cdte_format = CDROM_MSF; + if ( ioctl(this->fd, CDROMREADTOCENTRY, &this->tocent[i-1]) == -1 ) { fprintf (stderr, "input_vcd: error in ioctl CDROMREADTOCENTRY\n"); return -1; } } /* read the lead-out track */ - gVCD.tocent[gVCD.tochdr.cdth_trk1].cdte_track = CDROM_LEADOUT; - gVCD.tocent[gVCD.tochdr.cdth_trk1].cdte_format = CDROM_MSF; + this->tocent[this->tochdr.cdth_trk1].cdte_track = CDROM_LEADOUT; + this->tocent[this->tochdr.cdth_trk1].cdte_format = CDROM_MSF; - if (ioctl(gVCD.fd, CDROMREADTOCENTRY, &gVCD.tocent[gVCD.tochdr.cdth_trk1]) == -1 ) { + if (ioctl(this->fd, CDROMREADTOCENTRY, + &this->tocent[this->tochdr.cdth_trk1]) == -1 ) { fprintf (stderr, "input_vcd: error in ioctl CDROMREADTOCENTRY\n"); return -1; } - gVCD.total_tracks = gVCD.tochdr.cdth_trk1; + this->total_tracks = this->tochdr.cdth_trk1; return 0; } #elif defined (__FreeBSD__) -static int input_vcd_read_toc (void) { +static int input_vcd_read_toc (vcd_input_plugin_t *this) { struct ioc_read_toc_entry te; int ntracks; /* read TOC header */ - if ( ioctl(gVCD.fd, CDIOREADTOCHEADER, &gVCD.tochdr) == -1 ) { + if ( ioctl(this->fd, CDIOREADTOCHEADER, &this->tochdr) == -1 ) { fprintf (stderr, "input_vcd : error in ioctl CDROMREADTOCHDR\n"); return -1; } - ntracks = gVCD.tochdr.ending_track - - gVCD.tochdr.starting_track + 2; - gVCD.tocent = (struct cd_toc_entry *)malloc(sizeof(*gVCD.tocent) * ntracks); + ntracks = this->tochdr.ending_track + - this->tochdr.starting_track + 2; + this->tocent = (struct cd_toc_entry *) + malloc(sizeof(*this->tocent) * ntracks); te.address_format = CD_LBA_FORMAT; te.starting_track = 0; te.data_len = ntracks * sizeof(struct cd_toc_entry); te.data = gVCD.tocent; - if ( ioctl(gVCD.fd, CDIOREADTOCENTRYS, &te) == -1 ){ + if ( ioctl(this->fd, CDIOREADTOCENTRYS, &te) == -1 ){ fprintf (stderr, "input_vcd: error in ioctl CDROMREADTOCENTRY\n"); return -1; } - gVCD.total_tracks = gVCD.tochdr.ending_track - - gVCD.tochdr.starting_track +1; + this->total_tracks = this->tochdr.ending_track + - this->tochdr.starting_track +1; return 0; } #endif +/* ***************************************************************** */ +/* END OF PRIVATES */ +/* ***************************************************************** */ -static int input_plugin_open (const char *mrl) { +/* + * + */ +static int vcd_plugin_open (input_plugin_t *this_gen, char *mrl) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; char *filename; + this->mrl = mrl; + if (strncasecmp (mrl, "vcd://",6)) return 0; - gVCD.fd = open (CDROM, O_RDONLY); + this->fd = open (CDROM, O_RDONLY); - if (gVCD.fd == -1) { + if (this->fd == -1) { return 0; } - if (input_vcd_read_toc ()) { - close (gVCD.fd); - gVCD.fd = -1; + if (input_vcd_read_toc (this)) { + close (this->fd); + this->fd = -1; return 0; } @@ -181,36 +191,36 @@ static int input_plugin_open (const char *mrl) { xprintf (VERBOSE|INPUT, "Opening >%s<\n",filename); - if (sscanf (filename, "%d", &gVCD.cur_track) != 1) { + if (sscanf (filename, "%d", &this->cur_track) != 1) { fprintf (stderr, "input_vcd: malformed MRL. Use vcd://<track #>\n"); - close (gVCD.fd); - gVCD.fd = -1; + close (this->fd); + this->fd = -1; return 0; } - if (gVCD.cur_track>=gVCD.total_tracks) { + if (this->cur_track>=this->total_tracks) { fprintf (stderr, "input_vcd: invalid track %d (valid range: 0 .. %d)\n", - gVCD.cur_track, gVCD.total_tracks-1); - close (gVCD.fd); - gVCD.fd = -1; + this->cur_track, this->total_tracks-1); + close (this->fd); + this->fd = -1; return 0; } #if defined (__linux__) - gVCD.cur_min = gVCD.tocent[gVCD.cur_track].cdte_addr.msf.minute; - gVCD.cur_sec = gVCD.tocent[gVCD.cur_track].cdte_addr.msf.second; - gVCD.cur_frame = gVCD.tocent[gVCD.cur_track].cdte_addr.msf.frame; + this->cur_min = this->tocent[this->cur_track].cdte_addr.msf.minute; + this->cur_sec = this->tocent[this->cur_track].cdte_addr.msf.second; + this->cur_frame = this->tocent[this->cur_track].cdte_addr.msf.frame; #elif defined (__FreeBSD__) { int bsize = 2352; - if (ioctl (gVCD.fd, CDRIOCSETBLOCKSIZE, &bsize) == -1) { + if (ioctl (this->fd, CDRIOCSETBLOCKSIZE, &bsize) == -1) { fprintf (stderr, "input_vcd: error in CDRIOCSETBLOCKSIZE %d\n", errno); return 0; } - gVCD.cur_sector = - ntohl(gVCD.tocent - [gVCD.cur_track+1 - gVCD.tochdr.starting_track].addr.lba); + this->cur_sector = + ntohl(this->tocent + [this->cur_track+1 - this->tochdr.starting_track].addr.lba); } #endif @@ -218,11 +228,14 @@ static int input_plugin_open (const char *mrl) { return 1; } - - +/* + * + */ #if defined (__linux__) -static uint32_t input_plugin_read (char *buf, uint32_t nlen) { - +static off_t vcd_plugin_read (input_plugin_t *this_gen, + char *buf, off_t nlen) { + + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; static struct cdrom_msf msf ; static cdsector_t data; struct cdrom_msf0 *end_msf; @@ -232,37 +245,37 @@ static uint32_t input_plugin_read (char *buf, uint32_t nlen) { do { - end_msf = &gVCD.tocent[gVCD.cur_track+1].cdte_addr.msf; + end_msf = &this->tocent[this->cur_track+1].cdte_addr.msf; /* printf ("cur: %02d:%02d:%02d end: %02d:%02d:%02d\n", - gVCD.cur_min, gVCD.cur_sec, gVCD.cur_frame, + this->cur_min, this->cur_sec, this->cur_frame, end_msf->minute, end_msf->second, end_msf->frame); */ - if ( (gVCD.cur_min>=end_msf->minute) && (gVCD.cur_sec>=end_msf->second) - && (gVCD.cur_frame>=end_msf->frame)) + if ( (this->cur_min>=end_msf->minute) && (this->cur_sec>=end_msf->second) + && (this->cur_frame>=end_msf->frame)) return 0; - msf.cdmsf_min0 = gVCD.cur_min; - msf.cdmsf_sec0 = gVCD.cur_sec; - msf.cdmsf_frame0 = gVCD.cur_frame; + msf.cdmsf_min0 = this->cur_min; + msf.cdmsf_sec0 = this->cur_sec; + msf.cdmsf_frame0 = this->cur_frame; memcpy (&data, &msf, sizeof (msf)); - if (ioctl (gVCD.fd, CDROMREADRAW, &data) == -1) { + if (ioctl (this->fd, CDROMREADRAW, &data) == -1) { fprintf (stderr, "input_vcd: error in CDROMREADRAW\n"); return 0; } - gVCD.cur_frame++; - if (gVCD.cur_frame>=75) { - gVCD.cur_frame = 0; - gVCD.cur_sec++; - if (gVCD.cur_sec>=60) { - gVCD.cur_sec = 0; - gVCD.cur_min++; + this->cur_frame++; + if (this->cur_frame>=75) { + this->cur_frame = 0; + this->cur_sec++; + if (this->cur_sec>=60) { + this->cur_sec = 0; + this->cur_min++; } } @@ -275,7 +288,9 @@ static uint32_t input_plugin_read (char *buf, uint32_t nlen) { return VCDSECTORSIZE; } #elif defined (__FreeBSD__) -static uint32_t input_plugin_read (char *buf, uint32_t nlen) { +static off_t vcd_plugin_read (input_plugin_t *this_gen, + char *buf, off_t nlen) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; static cdsector_t data; int bsize = 2352; @@ -283,42 +298,137 @@ static uint32_t input_plugin_read (char *buf, uint32_t nlen) { return 0; do { - if (lseek (gVCD.fd, gVCD.cur_sector * bsize, SEEK_SET) == -1) { + if (lseek (this->fd, this->cur_sector * bsize, SEEK_SET) == -1) { fprintf (stderr, "input_vcd: seek error %d\n", errno); return 0; } - if (read (gVCD.fd, &data, bsize) == -1) { + if (read (this->fd, &data, bsize) == -1) { fprintf (stderr, "input_vcd: read error %d\n", errno); return 0; } - gVCD.cur_sector++; + this->cur_sector++; } while ((data.subheader[2]&~0x01)==0x60); memcpy (buf, data.data, VCDSECTORSIZE); return VCDSECTORSIZE; } #endif +/* + * + */ +#if defined (__linux__) +static buf_element_t *vcd_plugin_read_block (input_plugin_t *this_gen, + fifo_buffer_t *fifo, off_t nlen) { + + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; + buf_element_t *buf = fifo->buffer_pool_alloc (fifo); + static struct cdrom_msf msf ; + static cdsector_t data; + struct cdrom_msf0 *end_msf; + + if (nlen != VCDSECTORSIZE) + return NULL; + + do + { + end_msf = &this->tocent[this->cur_track+1].cdte_addr.msf; + + /* + printf ("cur: %02d:%02d:%02d end: %02d:%02d:%02d\n", + this->cur_min, this->cur_sec, this->cur_frame, + end_msf->minute, end_msf->second, end_msf->frame); + */ + + if ( (this->cur_min>=end_msf->minute) && (this->cur_sec>=end_msf->second) + && (this->cur_frame>=end_msf->frame)) + return NULL; + + msf.cdmsf_min0 = this->cur_min; + msf.cdmsf_sec0 = this->cur_sec; + msf.cdmsf_frame0 = this->cur_frame; + + memcpy (&data, &msf, sizeof (msf)); + + if (ioctl (this->fd, CDROMREADRAW, &data) == -1) { + fprintf (stderr, "input_vcd: error in CDROMREADRAW\n"); + return NULL; + } + + + this->cur_frame++; + if (this->cur_frame>=75) { + this->cur_frame = 0; + this->cur_sec++; + if (this->cur_sec>=60) { + this->cur_sec = 0; + this->cur_min++; + } + } + + /* Header ID check for padding sector. VCD uses this to keep constant + bitrate so the CD doesn't stop/start */ + } + while((data.subheader[2]&~0x01)==0x60); + + memcpy (buf, data.data, VCDSECTORSIZE); /* FIXME */ + return buf; +} +#elif defined (__FreeBSD__) +static buf_element_t *vcd_plugin_read_block (input_plugin_t *this_gen, + fifo_buffer_t *fifo, off_t nlen) { + + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; + buf_element_t *buf = fifo->buffer_pool_alloc (fifo); + static cdsector_t data; + int bsize = 2352; + + if (nlen != VCDSECTORSIZE) + return NULL; + + do { + if (lseek (this->fd, this->cur_sector * bsize, SEEK_SET) == -1) { + fprintf (stderr, "input_vcd: seek error %d\n", errno); + return NULL; + } + if (read (this->fd, &data, bsize) == -1) { + fprintf (stderr, "input_vcd: read error %d\n", errno); + return NULL; + } + this->cur_sector++; + } while ((data.subheader[2]&~0x01)==0x60); + memcpy (buf, data.data, VCDSECTORSIZE); + return buf; +} +#endif + +// +/* + * + */ #if defined (__linux__) -static off_t input_plugin_seek (off_t offset, int origin) { +static off_t vcd_plugin_seek (input_plugin_t *this_gen, + off_t offset, int origin) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; struct cdrom_msf0 *start_msf; uint32_t dist ; off_t sector_pos; - start_msf = &gVCD.tocent[gVCD.cur_track].cdte_addr.msf; + start_msf = &this->tocent[this->cur_track].cdte_addr.msf; switch (origin) { case SEEK_SET: dist = offset / VCDSECTORSIZE; - gVCD.cur_min = dist / (60*75) + start_msf->minute; + this->cur_min = dist / (60*75) + start_msf->minute; dist %= 60; - gVCD.cur_sec = dist / 75 + start_msf->second; + this->cur_sec = dist / 75 + start_msf->second; dist %= 75; - gVCD.cur_frame = dist + start_msf->frame; + this->cur_frame = dist + start_msf->frame; - xprintf (VERBOSE|INPUT, "%d => %02d:%02d:%02d\n",offset,gVCD.cur_min,gVCD.cur_sec,gVCD.cur_frame); + xprintf (VERBOSE|INPUT, "%d => %02d:%02d:%02d\n", offset, + this->cur_min, this->cur_sec, this->cur_frame); break; case SEEK_CUR: @@ -330,12 +440,12 @@ static off_t input_plugin_seek (off_t offset, int origin) { if (start_msf->second<60) sector_pos += (59 - start_msf->second) * 75; - if ( gVCD.cur_min > start_msf->minute) { - sector_pos += (gVCD.cur_min - start_msf->minute-1) * 60 * 75; + if ( this->cur_min > start_msf->minute) { + sector_pos += (this->cur_min - start_msf->minute-1) * 60 * 75; - sector_pos += gVCD.cur_sec * 60; + sector_pos += this->cur_sec * 60; - sector_pos += gVCD.cur_frame ; + sector_pos += this->cur_frame ; } return sector_pos * VCDSECTORSIZE; @@ -350,16 +460,18 @@ static off_t input_plugin_seek (off_t offset, int origin) { return offset ; /* FIXME */ } #elif defined (__FreeBSD__) -static off_t input_plugin_seek (off_t offset, int origin) { +static off_t vcd_plugin_seek (input_plugin_t *this_gen, + off_t offset, int origin) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; u_long start; uint32_t dist ; off_t sector_pos; start = - ntohl(gVCD.tocent - [gVCD.cur_track+1 - gVCD.tochdr.starting_track].addr.lba); + ntohl(this->tocent + [this->cur_track+1 - this->tochdr.starting_track].addr.lba); /* printf("seek: start sector:%lu, origin: %d, offset:%qu\n", start, origin, offset); @@ -368,14 +480,14 @@ static off_t input_plugin_seek (off_t offset, int origin) { switch (origin) { case SEEK_SET: dist = offset / VCDSECTORSIZE; - gVCD.cur_sector = start + dist; + this->cur_sector = start + dist; break; case SEEK_CUR: if (offset) fprintf (stderr, "input_vcd: SEEK_CUR not implemented for offset != 0\n"); - sector_pos = gVCD.cur_sector; + sector_pos = this->cur_sector; return sector_pos * VCDSECTORSIZE; @@ -390,13 +502,17 @@ static off_t input_plugin_seek (off_t offset, int origin) { } #endif +/* + * + */ #if defined (__linux__) -static off_t input_plugin_get_length (void) { +static off_t vcd_plugin_get_length (input_plugin_t *this_gen) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; struct cdrom_msf0 *end_msf, *start_msf; off_t len ; - start_msf = &gVCD.tocent[gVCD.cur_track].cdte_addr.msf; - end_msf = &gVCD.tocent[gVCD.cur_track+1].cdte_addr.msf; + start_msf = &this->tocent[this->cur_track].cdte_addr.msf; + end_msf = &this->tocent[this->cur_track+1].cdte_addr.msf; len = 75 - start_msf->frame; @@ -414,46 +530,67 @@ static off_t input_plugin_get_length (void) { return len * VCDSECTORSIZE; } #elif defined (__FreeBSD__) -static off_t input_plugin_get_length (void) { - +static off_t vcd_plugin_get_length (input_plugin_t *this_gen) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; off_t len ; len = - ntohl(gVCD.tocent - [gVCD.cur_track+2 - - gVCD.tochdr.starting_track].addr.lba) - - ntohl(gVCD.tocent - [gVCD.cur_track+1 - - gVCD.tochdr.starting_track].addr.lba); + ntohl(this->tocent + [this->cur_track+2 + - this->tochdr.starting_track].addr.lba) + - ntohl(this->tocent + [this->cur_track+1 + - this->tochdr.starting_track].addr.lba); return len * 2352; /*VCDSECTORSIZE;*/ } #endif -static uint32_t input_plugin_get_capabilities (void) { +/* + * + */ +static off_t vcd_plugin_get_current_pos (input_plugin_t *this_gen){ + + + return (vcd_plugin_seek (this_gen, 0, SEEK_CUR)); +} + +/* + * + */ +static uint32_t vcd_plugin_get_capabilities (input_plugin_t *this_gen) { + return INPUT_CAP_SEEKABLE | INPUT_CAP_BLOCK | INPUT_CAP_AUTOPLAY; } -static uint32_t input_plugin_get_blocksize (void) { +/* + * + */ +static uint32_t vcd_plugin_get_blocksize (input_plugin_t *this_gen) { + return VCDSECTORSIZE; } +/* + * + */ #if defined (__linux__) -static int input_plugin_eject (void) { +static int vcd_plugin_eject_media (input_plugin_t *this_gen) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; int ret, status; - if((gVCD.fd = open(CDROM, O_RDONLY|O_NONBLOCK)) > -1) { - if((status = ioctl(gVCD.fd, CDROM_DRIVE_STATUS, CDSL_CURRENT)) > 0) { + if((this->fd = open(CDROM, O_RDONLY|O_NONBLOCK)) > -1) { + if((status = ioctl(this->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT)) > 0) { switch(status) { case CDS_TRAY_OPEN: - if((ret = ioctl(gVCD.fd, CDROMCLOSETRAY)) != 0) { + if((ret = ioctl(this->fd, CDROMCLOSETRAY)) != 0) { xprintf(VERBOSE|INPUT, "CDROMCLOSETRAY failed: %s\n", strerror(errno)); } break; case CDS_DISC_OK: - if((ret = ioctl(gVCD.fd, CDROMEJECT)) != 0) { + if((ret = ioctl(this->fd, CDROMEJECT)) != 0) { xprintf(VERBOSE|INPUT, "CDROMEJECT failed: %s\n", strerror(errno)); } break; @@ -462,17 +599,17 @@ static int input_plugin_eject (void) { else { xprintf(VERBOSE|INPUT, "CDROM_DRIVE_STATUS failed: %s\n", strerror(errno)); - close(gVCD.fd); + close(this->fd); return 0; } } - close(gVCD.fd); + close(this->fd); return 1; } #elif defined (__FreeBSD__) -static int input_plugin_eject (void) { +static int vcd_plugin_eject_media (input_plugin_t *this_gen) { int fd; if ((fd = open(CDROM, O_RDONLY|O_NONBLOCK)) > -1) { @@ -490,97 +627,176 @@ static int input_plugin_eject (void) { } #endif -static void input_plugin_close (void) { +/* + * + */ +static void vcd_plugin_close (input_plugin_t *this_gen) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; + xprintf (VERBOSE|INPUT, "closing input\n"); - close(gVCD.fd); - gVCD.fd = -1; + close(this->fd); + this->fd = -1; } -static char *input_plugin_get_identifier (void) { +/* + * + */ +static char *vcd_plugin_get_description (input_plugin_t *this_gen) { + return "plain file input plugin as shipped with xine"; +} + +/* + * + */ +static char *vcd_plugin_get_identifier (input_plugin_t *this_gen) { return "VCD"; } -static char **input_plugin_get_autoplay_list (int *nFiles) { +/* + * + */ +static char **vcd_plugin_get_dir (input_plugin_t *this_gen, + char *filename, int *nEntries) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; int i; - gVCD.fd = open (CDROM, O_RDONLY); + if (filename) { + *nEntries = 0; + return NULL; + } + + this->fd = open (CDROM, O_RDONLY); - if (gVCD.fd == -1) { + if (this->fd == -1) { perror ("unable to open /dev/cdrom"); return NULL; } - if (input_vcd_read_toc ()) { - close (gVCD.fd); - gVCD.fd = -1; + if (input_vcd_read_toc (this)) { + close (this->fd); + this->fd = -1; printf ("vcd_read_toc failed\n"); return NULL; } - close (gVCD.fd); - gVCD.fd = -1; + close (this->fd); + this->fd = -1; - *nFiles = gVCD.total_tracks; + *nEntries = this->total_tracks; - /* printf ("%d tracks\n",gVCD.total_tracks); */ + /* printf ("%d tracks\n", this->total_tracks); */ - for (i=1; i<gVCD.total_tracks; i++) { /* FIXME: check if track 0 contains valid data */ - sprintf (gVCD.filelist[i-1], "vcd://%d",i); - /* printf ("list[%d] : %d %s\n", i, gVCD.filelist[i-1], gVCD.filelist[i-1]); */ + for (i=1; i<this->total_tracks; i++) { /* FIXME: check if track 0 contains valid data */ + sprintf (this->filelist[i-1], "vcd://%d",i); + /* printf ("list[%d] : %d %s\n", i, this->filelist[i-1], this->filelist[i-1]); */ } - return gVCD.filelist; + return this->filelist; } -static int input_plugin_is_branch_possible (const char *next_mrl) { +/* + * + */ +static char **vcd_plugin_get_autoplay_list (input_plugin_t *this_gen, + int *nFiles) { + + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; + int i; - char *filename; - int track; + this->fd = open (CDROM, O_RDONLY); - if (strncasecmp (next_mrl, "vcd://",6)) - return 0; - - filename = (char *) &next_mrl[6]; + if (this->fd == -1) { + perror ("unable to open /dev/cdrom"); + return NULL; + } - if (sscanf (filename, "%d", &track) != 1) { - return 0; + if (input_vcd_read_toc (this)) { + close (this->fd); + this->fd = -1; + + printf ("vcd_read_toc failed\n"); + + return NULL; } - if ((track>=gVCD.total_tracks) || (track != (gVCD.cur_track+1))) - return 0; + close (this->fd); + this->fd = -1; + + *nFiles = this->total_tracks; - return 1; + /* printf ("%d tracks\n", this->total_tracks); */ + + for (i=1; i<this->total_tracks; i++) { /* FIXME: check if track 0 contains valid data */ + sprintf (this->filelist[i-1], "vcd://%d",i); + /* printf ("list[%d] : %d %s\n", i, this->filelist[i-1], this->filelist[i-1]); */ + } + + return this->filelist; } +/* + * + */ +static char* vcd_plugin_get_mrl (input_plugin_t *this_gen) { + vcd_input_plugin_t *this = (vcd_input_plugin_t *) this_gen; -static input_plugin_t plugin_op = { - NULL, - NULL, - input_plugin_init, - input_plugin_open, - input_plugin_read, - input_plugin_seek, - input_plugin_get_length, - input_plugin_get_capabilities, - NULL, - input_plugin_get_blocksize, - input_plugin_eject, - input_plugin_close, - input_plugin_get_identifier, - input_plugin_get_autoplay_list, - input_plugin_is_branch_possible, - NULL -}; - -input_plugin_t *input_plugin_getinfo(uint32_t dbglvl) { - - xine_debug = dbglvl; - - return &plugin_op; + return this->mrl; } +/* + * + */ +input_plugin_t *init_input_plugin (int iface, config_values_t *config) { + vcd_input_plugin_t *this; + + xine_debug = config->lookup_int (config, "xine_debug", 0); + + switch (iface) { + case 1: { + int i; + + this = (vcd_input_plugin_t *) malloc (sizeof (vcd_input_plugin_t)); + + for (i=0; i<100; i++) + this->filelist[i] = (char *) malloc (256); + + this->input_plugin.interface_version = INPUT_PLUGIN_IFACE_VERSION; + this->input_plugin.get_capabilities = vcd_plugin_get_capabilities; + this->input_plugin.open = vcd_plugin_open; + this->input_plugin.read = vcd_plugin_read; + this->input_plugin.read_block = vcd_plugin_read_block; + this->input_plugin.seek = vcd_plugin_seek; + this->input_plugin.get_current_pos = vcd_plugin_get_current_pos; + this->input_plugin.get_length = vcd_plugin_get_length; + this->input_plugin.get_blocksize = vcd_plugin_get_blocksize; + this->input_plugin.eject_media = vcd_plugin_eject_media; + this->input_plugin.close = vcd_plugin_close; + this->input_plugin.get_identifier = vcd_plugin_get_identifier; + this->input_plugin.get_description = vcd_plugin_get_description; + this->input_plugin.get_dir = vcd_plugin_get_dir; + this->input_plugin.get_mrl = vcd_plugin_get_mrl; + this->input_plugin.get_autoplay_list = vcd_plugin_get_autoplay_list; + this->input_plugin.get_clut = NULL; + + this->fd = -1; + this->mrl = NULL; + this->config = config; + + return (input_plugin_t *) this; + } + break; + default: + fprintf(stderr, + "Dvd input plugin doesn't support plugin API version %d.\n" + "PLUGIN DISABLED.\n" + "This means there's a version mismatch between xine and this input" + "plugin.\nInstalling current input plugins should help.\n", + iface); + return NULL; + } +} |