--- src/input/input_cdda.c.orig 2010-12-01 20:28:32.934356038 +0200 +++ src/input/input_cdda.c 2010-12-03 18:29:25.232353193 +0200 @@ -54,6 +54,10 @@ #include #include +#ifdef LIBCDIO_CONFIG_H +#include +#endif + #define LOG_MODULE "input_cdda" #define LOG_VERBOSE /* @@ -167,6 +171,9 @@ long (*lpSendCommand)( void* ); #endif +#ifdef LIBCDIO_CONFIG_H + cdrom_drive_t *cdio; +#endif } cdda_input_plugin_t; typedef struct { @@ -388,16 +395,65 @@ free (toc); } -#if defined (__linux__) +#if defined(LIBCDIO_CONFIG_H) + +static int read_cdrom_toc(cdda_input_plugin_t *this_gen, cdrom_toc *toc) { + int i; + + toc->first_track = 1; + toc->last_track = cdio_cddap_tracks(this_gen->cdio); + toc->total_tracks = toc->last_track; + + /* allocate space for the toc entries */ + toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry)); + if (!toc->toc_entries) { + perror("calloc"); + return -1; + } + + for (i = toc->first_track; i <= toc->last_track; i++) { + toc->toc_entries[i-1].track_mode = cdio_cddap_track_audiop(this_gen->cdio, i); + toc->toc_entries[i-1].first_frame = cdio_cddap_track_firstsector(this_gen->cdio, i); + toc->toc_entries[i-1].first_frame_minute = toc->toc_entries[i-1].first_frame / (CD_SECONDS_PER_MINUTE * CD_FRAMES_PER_SECOND); + toc->toc_entries[i-1].first_frame_second = (toc->toc_entries[i-1].first_frame % (CD_SECONDS_PER_MINUTE * CD_FRAMES_PER_SECOND)) / CD_FRAMES_PER_SECOND; + toc->toc_entries[i-1].first_frame_frame = toc->toc_entries[i-1].first_frame % CD_FRAMES_PER_SECOND; + } + + toc->leadout_track.track_mode = 0; + toc->leadout_track.first_frame = cdio_cddap_track_lastsector(this_gen->cdio, i-1) + 1; + toc->leadout_track.first_frame_minute = toc->leadout_track.first_frame / (CD_SECONDS_PER_MINUTE * CD_FRAMES_PER_SECOND); + toc->leadout_track.first_frame_second = (toc->leadout_track.first_frame% (CD_SECONDS_PER_MINUTE * CD_FRAMES_PER_SECOND)) / CD_FRAMES_PER_SECOND; + toc->leadout_track.first_frame_frame = toc->leadout_track.first_frame % CD_FRAMES_PER_SECOND; + + return 0; +} + +static int read_cdrom_frames(cdda_input_plugin_t *this_gen, int frame, int num_frames, + unsigned char *data) { + + while( num_frames ) { + if (cdio_cddap_read(this_gen->cdio, data, frame, 1) != 1) { + perror("cdio_cddap_read"); + return -1; + } + data += CD_RAW_FRAME_SIZE; + frame++; + num_frames--; + } + return 0; +} + +#elif defined (__linux__) #include -static int read_cdrom_toc(int fd, cdrom_toc *toc) { +static int read_cdrom_toc(cdda_input_plugin_t *this_gen, cdrom_toc *toc) { struct cdrom_tochdr tochdr; struct cdrom_tocentry tocentry; struct cdrom_multisession ms; int i; + int fd = this_gen->fd; /* fetch the table of contents */ if (ioctl(fd, CDROMREADTOCHDR, &tochdr) == -1) { @@ -514,11 +570,12 @@ #include -static int read_cdrom_toc(int fd, cdrom_toc *toc) { +static int read_cdrom_toc(cdda_input_plugin_t *this_gen, cdrom_toc *toc) { struct cdrom_tochdr tochdr; struct cdrom_tocentry tocentry; int i; + int fd = this_gen->fd; /* fetch the table of contents */ if (ioctl(fd, CDROMREADTOCHDR, &tochdr) == -1) { @@ -621,7 +678,7 @@ #include #endif -static int read_cdrom_toc(int fd, cdrom_toc *toc) { +static int read_cdrom_toc(cdda_input_plugin_t *this_gen, cdrom_toc *toc) { struct ioc_toc_header tochdr; #if defined(__FreeBSD_kernel__) @@ -631,6 +688,7 @@ struct cd_toc_entry data; #endif int i; + int fd = this_gen->fd; /* fetch the table of contents */ if (ioctl(fd, CDIOREADTOCHEADER, &tochdr) == -1) { @@ -926,7 +984,7 @@ -static int read_cdrom_toc(int fd, cdrom_toc *toc) { +static int read_cdrom_toc(cdda_input_plugin_t *this_gen, cdrom_toc *toc) { /* read_cdrom_toc is not supported on other platforms */ return -1; } @@ -1937,8 +1995,16 @@ * ********** END OF CDDB *************** */ -static int cdda_open(cdda_input_plugin_t *this_gen, +static int _cdda_open(cdda_input_plugin_t *this_gen, const char *cdda_device, cdrom_toc *toc, int *fdd) { +#ifdef LIBCDIO_CONFIG_H + if ( !cdda_device ) return -1; + this_gen->cdio = cdio_cddap_identify(cdda_device, 0, NULL); + if ( this_gen->cdio == NULL) return -1; + if ( cdio_cddap_open(this_gen->cdio) ) return -1; + *fdd = this_gen->fd = 0xcafe; /* dummy value != -1 */ + return 0; +#endif #ifndef WIN32 int fd = -1; @@ -2119,7 +2185,7 @@ return -1; } -static int cdda_close(cdda_input_plugin_t *this_gen) { +static int _cdda_close(cdda_input_plugin_t *this_gen) { if (!this_gen) return 0; @@ -2279,7 +2345,7 @@ _cdda_free_cddb_info(this); - cdda_close(this); + _cdda_close(this); free(this->mrl); @@ -2325,16 +2391,12 @@ if( this->net_fd == -1 ) { - if (cdda_open(this, cdda_device, toc, &fd) == -1) { + if (_cdda_open(this, cdda_device, toc, &fd) == -1) { free_cdrom_toc(toc); return 0; } -#ifndef WIN32 - err = read_cdrom_toc(this->fd, toc); -#else err = read_cdrom_toc(this, toc); -#endif #ifdef LOG print_cdrom_toc(toc); @@ -2346,7 +2408,7 @@ if ( (err < 0) || (toc->first_track > (this->track + 1)) || (toc->last_track < (this->track + 1))) { - cdda_close(this); + _cdda_close(this); free_cdrom_toc(toc); return 0; @@ -2498,25 +2560,21 @@ #endif if (fd == -1) { - if (cdda_open(ip, device, toc, &fd) == -1) { + if (_cdda_open(ip, device, toc, &fd) == -1) { lprintf("cdda_class_get_dir: opening >%s< failed %s\n", device, strerror(errno)); free(ip); return NULL; } -#ifndef WIN32 - err = read_cdrom_toc(fd, toc); -#else err = read_cdrom_toc(ip, toc); -#endif /* WIN32 */ } #ifdef LOG print_cdrom_toc(toc); #endif - cdda_close(ip); + _cdda_close(ip); if ( err < 0 ) { free(ip); @@ -2621,25 +2679,21 @@ #endif if (fd == -1) { - if (cdda_open(ip, this->cdda_device, toc, &fd) == -1) { + if (_cdda_open(ip, this->cdda_device, toc, &fd) == -1) { lprintf("cdda_class_get_autoplay_list: opening >%s< failed %s\n", this->cdda_device, strerror(errno)); if (ip != this->ip) free(ip); return NULL; } -#ifndef WIN32 - err = read_cdrom_toc(fd, toc); -#else err = read_cdrom_toc(ip, toc); -#endif /* WIN32 */ } #ifdef LOG print_cdrom_toc(toc); #endif - cdda_close(ip); + _cdda_close(ip); if ( err < 0 ) { if (ip != this->ip) free(ip);