int main(int argc, const char *argv[]) { track_t i_first_track; track_t i_tracks; CdIo_t *p_cdio = cdio_open ("../test/cdda.cue", DRIVER_BINCUE); if (NULL == p_cdio) { printf("Couldn't open ../test/cdda.cue with BIN/CUE driver.\n"); } else { i_first_track = cdio_get_first_track_num(p_cdio); i_tracks = cdio_get_num_tracks(p_cdio); print_disc_info(p_cdio, i_tracks, i_first_track); cdio_destroy(p_cdio); } p_cdio = cdio_open (NULL, DRIVER_DEVICE); i_first_track = cdio_get_first_track_num(p_cdio); i_tracks = cdio_get_num_tracks(p_cdio); if (NULL == p_cdio) { printf("Couldn't find CD\n"); return 1; } else { print_disc_info(p_cdio, i_tracks, i_first_track); } cdio_destroy(p_cdio); return 0; }
int main(int argc, const char *argv[]) { CdIo_t *cdObj; track_t i_track; lsn_t lsn; cdio_log_set_handler (log_handler); if (cdio_have_driver(DRIVER_BINCUE)) { cdObj = cdio_open(DATA_DIR "/cdda.cue", DRIVER_UNKNOWN); } else if (cdio_have_driver(DRIVER_CDRDAO)) { cdObj = cdio_open(DATA_DIR "/cdda.toc", DRIVER_UNKNOWN); } else { printf("-- You don't have enough drivers for this test\n"); return 77; } i_track = cdio_get_track(cdObj, 1000); if (i_track != CDIO_INVALID_TRACK) { printf("LSN 1000 is too large should have gotten CDIO_INVALID_TRACK back\n"); return 1; } for(lsn=0; lsn<10; lsn++) { i_track = cdio_get_track(cdObj, lsn); if (i_track != 1) { printf("LSN %d should return 1. Got %d\n", lsn, i_track); return 3; } } i_track = cdio_get_track(cdObj, 302); if (i_track != CDIO_CDROM_LEADOUT_TRACK) { printf("LSN %d should return leadout. Got %d\n", 302, i_track); return 4; } for(lsn=301; lsn > 300; lsn--) { i_track = cdio_get_track(cdObj, lsn); if (i_track != 1) { printf("LSN %d should return 1. Got %d\n", lsn, i_track); return 4; } } cdio_destroy(cdObj); return 0; }
int main(int argc, const char *argv[]) { CdIo_t *p_cdio = cdio_open (NULL, DRIVER_UNKNOWN); driver_id_t driver_id; if (NULL != p_cdio) { char *default_device = cdio_get_default_device(p_cdio); cdio_drive_read_cap_t i_read_cap; cdio_drive_write_cap_t i_write_cap; cdio_drive_misc_cap_t i_misc_cap; printf("The driver selected is %s\n", cdio_get_driver_name(p_cdio)); if (default_device) printf("The default device for this driver is %s\n", default_device); cdio_get_drive_cap(p_cdio, &i_read_cap, &i_write_cap, &i_misc_cap); print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap); free(default_device); cdio_destroy(p_cdio); printf("\n"); } else { printf("Problem in trying to find a driver.\n\n"); } for (driver_id=CDIO_MIN_DRIVER; driver_id<=CDIO_MAX_DRIVER; ++driver_id) if (cdio_have_driver(driver_id)) printf("We have: %s\n", cdio_driver_describe(driver_id)); else printf("We don't have: %s\n", cdio_driver_describe(driver_id)); return 0; }
static void device_open(ripncode_t *r) { char *msg = NULL; r->cdio = cdio_open(r->device, driver_id(r)); if (r->cdio == NULL) ripncode_fatal(r, "failed to open CdIo device '%s' with driver '%s'", r->device, r->driver); r->cdda = cdio_cddap_identify_cdio(r->cdio, CDDA_MESSAGE_LOGIT, &msg); if (r->cdda == NULL) ripncode_fatal(r, "failed to identify CDDA device '%s' (%s)", r->device, msg ? msg : "unknown error"); cdio_cddap_free_messages(msg); if (cdio_cddap_open(r->cdda) < 0) ripncode_fatal(r, "failed to open CDDA device '%s' (%d: %s)", r->device, errno, strerror(errno)); r->cdpa = cdio_paranoia_init(r->cdda); if (r->cdpa == NULL) ripncode_fatal(r, "failed to open CD-Paranoia device '%s'", r->device); r->endian = data_bigendianp(r->cdda); ripncode_info(r, "Drive endianness: %d\n", r->endian); }
/***************************************************************************** * ioctl_Open: Opens a VCD device or file and returns an opaque handle *****************************************************************************/ cddev_t *ioctl_Open( vlc_object_t *p_this, const char *psz_dev ) { cddev_t *p_cddev; if( !psz_dev ) return NULL; /* * Initialize structure with default values */ p_cddev = (cddev_t *)malloc( sizeof(cddev_t) ); if( p_cddev == NULL ) { msg_Err( p_this, "out of memory" ); return NULL; } /* Set where to log errors messages from libcdio. */ cdio_log_set_handler ( cd_log_handler ); p_cddev->cdio = cdio_open(psz_dev, DRIVER_UNKNOWN); if( p_cddev->cdio == NULL ) { free( p_cddev ); p_cddev = NULL; } return p_cddev; }
/* * Private stuff */ static CdIo_t * open_cd (xmms_xform_t *xform) { CdIo_t *cdio; xmms_config_property_t *val; const gchar *device; const gchar *accessmode; cdio_log_set_handler (log_handler); val = xmms_xform_config_lookup (xform, "device"); device = xmms_config_property_get_string (val); val = xmms_xform_config_lookup (xform, "accessmode"); accessmode = xmms_config_property_get_string (val); XMMS_DBG ("Trying to open device '%s', using '%s' access mode.", device, accessmode); if (g_ascii_strcasecmp (accessmode, "default") == 0) { cdio = cdio_open (device, DRIVER_UNKNOWN); } else { cdio = cdio_open_am (device, DRIVER_UNKNOWN, accessmode); } if (!cdio) { xmms_log_error ("Failed to open device '%s'.", device); } else { cdio_set_speed (cdio, 1); xmms_log_info ("Opened device '%s'.", device); } return cdio; }
int main(int argc, const char *argv[]) { CdIo_t *p_cdio = cdio_open (NULL, DRIVER_UNKNOWN); track_t i_first_track; track_t i_tracks; int j, i; if (NULL == p_cdio) { printf("Couldn't find a driver.. leaving.\n"); return 1; } printf("Disc last LSN: %d\n", cdio_get_disc_last_lsn(p_cdio)); i_tracks = cdio_get_num_tracks(p_cdio); i_first_track = i = cdio_get_first_track_num(p_cdio); printf("CD-ROM Track List (%i - %i)\n", i_first_track, i_first_track+i_tracks-1); printf(" #: LSN\n"); for (j = 0; j < i_tracks; i++, j++) { lsn_t lsn = cdio_get_track_lsn(p_cdio, i); if (CDIO_INVALID_LSN != lsn) printf("%3d: %06lu\n", (int) i, (long unsigned int) lsn); } printf("%3X: %06lu leadout\n", CDIO_CDROM_LEADOUT_TRACK, (long unsigned int) cdio_get_track_lsn(p_cdio, CDIO_CDROM_LEADOUT_TRACK)); cdio_destroy(p_cdio); return 0; }
int main(int argc, const char *argv[]) { CdIo_t *p_cdio; const char *psz_drive = NULL; if (argc > 1) psz_drive = argv[1]; p_cdio = cdio_open (psz_drive, DRIVER_UNKNOWN); if (!p_cdio) { printf("Couldn't find CD\n"); return 1; } else { uint8_t buf[22] = { 0, }; /* Place to hold returned data */ char *psz_cd = cdio_get_default_device(p_cdio); if (DRIVER_OP_SUCCESS == mmc_mode_sense_6(p_cdio, buf, sizeof(buf), CDIO_MMC_CAPABILITIES_PAGE) ) { print_mode_sense(psz_cd, "6", buf); } else { printf("Couldn't get MODE_SENSE 6 data.\n"); } if (DRIVER_OP_SUCCESS == mmc_mode_sense_10(p_cdio, buf, sizeof(buf), CDIO_MMC_CAPABILITIES_PAGE) ) { print_mode_sense(psz_cd, "10", buf); } else { printf("Couldn't get MODE_SENSE 10 data.\n"); } free(psz_cd); } cdio_destroy(p_cdio); return 0; }
int bgav_check_device_vcd(const char * device, char ** name) { CdIo_t * cdio; cdio_drive_read_cap_t read_cap; cdio_drive_write_cap_t write_cap; cdio_drive_misc_cap_t misc_cap; cdio = cdio_open (device, DRIVER_DEVICE); if(!cdio) return 0; cdio_get_drive_cap(cdio, &read_cap, &write_cap, &misc_cap); if(!(read_cap & CDIO_DRIVE_CAP_READ_MODE2_FORM2)) { cdio_destroy(cdio); return 0; } /* Seems the drive is ok */ if(name) *name = get_device_name(cdio, read_cap, write_cap, device); cdio_destroy(cdio); return 1; }
char *libunieject_defaultdevice() { CdIo_t *cdio = cdio_open(NULL, DRIVER_UNKNOWN); char *device = cdio_get_default_device(cdio); cdio_destroy(cdio); return device; }
int main(int argc, const char *argv[]) { CdIo_t *p_cdio; unsigned long i_sleep_ms = (30 * 1000000); if (argc > 1) { p_cdio = cdio_open (argv[1], DRIVER_DEVICE); if (argc > 2) { errno = 0; i_sleep_ms = strtol(argv[2], (char **)NULL, 10) * 1000000; if ( (LONG_MIN == i_sleep_ms || LONG_MAX == i_sleep_ms) && errno != 0 ) { printf("Invalid sleep parameter %s\n", argv[2]); printf("Error reported back from strtol: %s\n", strerror(errno)); return 2; } } } else { p_cdio = cdio_open (NULL, DRIVER_DEVICE); } if (NULL == p_cdio) { printf("Couldn't find a driver.. leaving.\n"); return 1; } if (cdio_get_media_changed(p_cdio)) printf("Initial media status: changed\n"); else printf("Initial media status: not changed\n"); printf("Giving you %g seconds to change CD if you want to do so.\n", i_sleep_ms / 1000000.0); { int i_ret = usleep(i_sleep_ms); if (0 != i_ret) fprintf(stderr, "Something went wrong with usleep\n"); } if (cdio_get_media_changed(p_cdio)) printf("Media status: changed\n"); else printf("Media status: not changed\n"); cdio_destroy(p_cdio); return 0; }
QString CddaLister::MakeFriendlyName(const QString& id) { CdIo_t *cdio = cdio_open (id.toLocal8Bit().constData(), DRIVER_DEVICE); cdio_hwinfo_t cd_info; if (cdio_get_hwinfo(cdio, &cd_info)) { cdio_destroy(cdio); return QString(cd_info.psz_model); } cdio_destroy(cdio); return QString("CD (") + id + ")"; }
QString CddaLister::DeviceModel(const QString& id) { CdIo_t *cdio = cdio_open (id.toLocal8Bit().constData(), DRIVER_DEVICE); cdio_hwinfo_t cd_info; if (cdio_get_hwinfo(cdio, &cd_info)) { cdio_destroy(cdio); return QString(cd_info.psz_model); } cdio_destroy(cdio); return QString(); }
/*! Eject media in CD drive if there is a routine to do so. If you want to scan for any CD-ROM and eject that, pass NULL for psz_drive. @param psz_drive the CD object to be acted upon. If NULL is given as the drive, we'll use the default driver device. */ driver_return_code_t cdio_eject_media_drive (const char *psz_drive) { CdIo_t *p_cdio = cdio_open (psz_drive, DRIVER_DEVICE); if (p_cdio) { return cdio_eject_media(&p_cdio); } else { return DRIVER_OP_UNINIT; } }
void cdda_record__do_eject(cdda_drive_t * drive) { CdIo_t * cdio = cdio_open(drive->device_path, DRIVER_DEVICE); if (cdio) { cdio_eject_media(&cdio); if (cdio != NULL) { cdio_destroy(cdio); } } }
static int cdpa_open(rnc_dev_t *dev, const char *device) { cdpa_t *cdpa; char *msg; mrp_debug("opening device '%s' with cdparanoia", device); msg = NULL; cdpa = dev->data = mrp_allocz(sizeof(*cdpa)); if (cdpa == NULL) goto fail; cdpa->cdio = cdio_open(device, DRIVER_LINUX); if (cdpa->cdio == NULL) { msg = "failed open device"; goto fail; } cdpa->cdda = cdio_cddap_identify_cdio(cdpa->cdio, CDDA_MESSAGE_LOGIT, &msg); if (cdpa->cdda == NULL) goto fail; cdio_cddap_free_messages(msg); msg = NULL; if (cdio_cddap_open(cdpa->cdda) < 0) { msg = "failed to CDDAP-open device"; goto fail; } cdpa->cdpa = cdio_paranoia_init(cdpa->cdda); if (cdpa->cdpa == NULL) { msg = "failed to initialize cd-paranoia"; goto fail; } cdpa->ctrack = -1; return 0; fail: if (cdpa != NULL && msg != NULL) cdpa->errmsg = mrp_strdup(msg); return -1; }
void CddaImpl::open() { driver_id_t driver_id = DRIVER_UNKNOWN; if (_device.empty()) { char **ppsz_cd_drives = cdio_get_devices_with_cap_ret(NULL, CDIO_FS_AUDIO, false, &driver_id); if (ppsz_cd_drives && *ppsz_cd_drives) _device = ppsz_cd_drives[0]; cdio_free_device_list(ppsz_cd_drives); } _cdio = cdio_open(_device.c_str(), driver_id); if (_cdio == NULL) { THROW_EXCEPTION(CddaException, "Could not open device."); } // Detect empty drive if (cdio_get_first_track_num(_cdio) == CDIO_INVALID_TRACK) { close(); return; } _cdrom = cdio_cddap_identify_cdio(_cdio, CDDA_MESSAGE_LOGIT, NULL); if (_cdrom == NULL) { THROW_EXCEPTION(CddaException, "Could not read cdrom structure."); } cdio_cddap_verbose_set(_cdrom, CDDA_MESSAGE_LOGIT, CDDA_MESSAGE_LOGIT); int ret = cdio_cddap_open(_cdrom); if (ret != 0) { THROW_EXCEPTION(CddaException, cdda_error_message(ret)); } _is_open = true; read_toc(); //read_cddb(); }
int main(int argc, const char *argv[]) { CdIo_t *p_cdio; const char *psz_drive = NULL; if (argc > 1) psz_drive = argv[1]; p_cdio = cdio_open (psz_drive, DRIVER_UNKNOWN); if (NULL == p_cdio) { printf("Couldn't find CD\n"); return 1; } else { int i_status; /* Result of MMC command */ char buf[36] = { 0, }; /* Place to hold returned data */ mmc_cdb_t cdb = {{0, }}; /* Command Descriptor Buffer */ CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_INQUIRY); cdb.field[4] = sizeof(buf); i_status = mmc_run_cmd(p_cdio, DEFAULT_TIMEOUT_MS, &cdb, SCSI_MMC_DATA_READ, sizeof(buf), &buf); if (i_status == 0) { char psz_vendor[CDIO_MMC_HW_VENDOR_LEN+1]; char psz_model[CDIO_MMC_HW_MODEL_LEN+1]; char psz_rev[CDIO_MMC_HW_REVISION_LEN+1]; memcpy(psz_vendor, buf + 8, sizeof(psz_vendor)-1); psz_vendor[sizeof(psz_vendor)-1] = '\0'; memcpy(psz_model, buf + 8 + CDIO_MMC_HW_VENDOR_LEN, sizeof(psz_model)-1); psz_model[sizeof(psz_model)-1] = '\0'; memcpy(psz_rev, buf + 8 + CDIO_MMC_HW_VENDOR_LEN +CDIO_MMC_HW_MODEL_LEN, sizeof(psz_rev)-1); psz_rev[sizeof(psz_rev)-1] = '\0'; printf("Vendor: %s\nModel: %s\nRevision: %s\n", psz_vendor, psz_model, psz_rev); } else { printf("Couldn't get INQUIRY data (vendor, model, and revision).\n"); } } cdio_destroy(p_cdio); return 0; }
/** Returns a paranoia CD-ROM drive object with a CD-DA in it or NULL if there was an error. @see cdio_cddap_identify_cdio */ cdrom_drive_t * cdio_cddap_identify(const char *psz_dev, int messagedest, char **ppsz_messages) { CdIo_t *p_cdio = NULL; if (psz_dev) idmessage(messagedest, ppsz_messages, "Checking %s for cdrom...", psz_dev); else idmessage(messagedest, ppsz_messages, "Checking for cdrom...", NULL); #ifdef DEVICE_IN_FILESYSTEM if (psz_dev) { char *psz_device = test_resolve_symlink(psz_dev, messagedest, ppsz_messages); if ( psz_device ) { cdrom_drive_t *d=NULL; p_cdio = cdio_open(psz_device, DRIVER_UNKNOWN); d = cdda_identify_device_cdio(p_cdio, psz_device, messagedest, ppsz_messages); free(psz_device); return d; } } #endif p_cdio = cdio_open(psz_dev, DRIVER_UNKNOWN); if (p_cdio) { if (!psz_dev) { psz_dev = cdio_get_arg(p_cdio, "source"); } return cdda_identify_device_cdio(p_cdio, psz_dev, messagedest, ppsz_messages); } return NULL; }
bool CDIntfInit(void) { #ifdef HAVE_LIB_CDIO cdioPtr = cdio_open(NULL, DRIVER_DEVICE); if (cdioPtr == NULL) { #endif WriteLog("CDINTF: No suitable CD-ROM driver found.\n"); return false; #ifdef HAVE_LIB_CDIO } WriteLog("CDINTF: Successfully opened CD-ROM interface.\n"); return true; #endif }
// Open a cdio device static CdIo_t * openCdio(const QString& name) { // Setup log handler static int s_logging; if (!s_logging) { s_logging = 1; cdio_log_set_handler(&logger); } CdIo_t *cdio = cdio_open(name.toAscii(), DRIVER_DEVICE); if (!cdio) { LOG(VB_MEDIA, LOG_INFO, QString("CdDecoder: cdio_open(%1) failed"). arg(name)); } return cdio; }
int main(int argc, char **argv) { gtk_init(&argc, &argv); #ifdef LIB_DEBUG cddb_log_set_level(CDDB_LOG_DEBUG); #endif CdIo_t *p_cdio = cdio_open(NULL, DRIVER_DEVICE); device_name = cdio_get_default_device(p_cdio); if (p_cdio == NULL) { fputs("Unable to read the CD drive!\n", stderr); return 1; } ui_loading_screen(); cddb_disc_t *disc = cddb_disc_new(); enum giles_cddb_err get_cddb_info_err = get_cddb_info_for_device(p_cdio, disc); switch (get_cddb_info_err) { case giles_cddb_err_no_conn: fputs("Could not connect to CDDB database.\n", stderr); break; case giles_cddb_err_no_match: fputs("Could not find a match for the CD in the CDDB database.\n", stderr); break; default: break; } cdio_destroy(p_cdio); ui_loading_screen_done(); ui_show_disc_info(disc); gtk_main(); return 0; }
int main(int argc, const char *argv[]) { CdIo_t *cdObj; const char *image; lsn_t pregap; int i; int rc = 0; cdio_log_set_handler (log_handler); if (! (cdio_have_driver(DRIVER_NRG) && cdio_have_driver(DRIVER_BINCUE) && cdio_have_driver(DRIVER_CDRDAO)) ) { printf("You don't have enough drivers for this test\n"); exit(77); } for (i = 0; i < NELEMS(pregapList); ++i) { image = pregapList[i].image; cdObj = cdio_open(image, DRIVER_UNKNOWN); if (!cdObj) { printf("unrecognized image: %s\n", image); return 50; } pregap = cdio_get_track_pregap_lsn(cdObj, pregapList[i].track); if (pregap != pregapList[i].pregap) { printf("%s should have had pregap of lsn=%d instead of lsn=%d\n", image, pregapList[i].pregap, pregap); rc = i + 1; } else { printf("%s had expected pregap\n", image); } cdio_destroy(cdObj); } return rc; }
QList< Playlist::Entry > AudioCDDemux::getTracks( const QString &_device ) { QList< Playlist::Entry > tracks; Playlist::Entry entry; device = _device; cdio_close_tray( device.toLocal8Bit(), NULL ); if ( ( cdio = cdio_open( device.toLocal8Bit(), DRIVER_UNKNOWN ) ) ) { numTracks = cdio_get_num_tracks( cdio ); if ( cdio_get_discmode( cdio ) != CDIO_DISC_MODE_ERROR && numTracks > 0 && numTracks != CDIO_INVALID_TRACK ) { cddb_disc_t *cddb_disc = NULL; bool cddb_ok = useCDDB; for ( trackNo = 1 ; trackNo <= numTracks ; ++trackNo ) { chn = cdio_get_track_channels( cdio, trackNo ); if ( chn != 2 && chn != 4 ) continue; if ( useCDTEXT ) readCDText( trackNo ); isData = cdio_get_track_format( cdio, trackNo ) != TRACK_FORMAT_AUDIO; duration = CD_BLOCKSIZE / chn / ( double )srate; numSectors = cdio_get_track_last_lsn( cdio, trackNo ) - cdio_get_track_lsn( cdio, trackNo ); if ( cddb_ok && ( cddb_disc || ( Title.isEmpty() && ( cddb_ok = freedb_query( cddb_disc ) ) ) ) ) freedb_get_track_info( cddb_disc ); entry.name = title(); entry.url = AudioCDName"://" + QString::number( trackNo ) + "?device=" + device; entry.length = length(); tracks += entry; } cddb_disc_destroy( cddb_disc ); } } return tracks; }
int main(int argc, const char *argv[]) { iso9660_stat_t *p_statbuf; FILE *p_outfd; int i; char const *psz_image; char const *psz_fname; char translated_name[256]; char untranslated_name[256] = ISO9660_PATH; CdIo_t *p_cdio; unsigned int i_fname=sizeof(ISO9660_FILENAME); if (argc > 3) { printf("usage %s [CD-ROM-or-image [filename]]\n", argv[0]); printf("Extracts filename from CD-ROM-or-image.\n"); return 1; } if (argc > 1) psz_image = argv[1]; else psz_image = ISO9660_IMAGE; if (argc > 2) { psz_fname = argv[2]; i_fname = strlen(psz_fname)+1; } else psz_fname = ISO9660_FILENAME; strncat(untranslated_name, psz_fname, i_fname); p_cdio = cdio_open (psz_image, DRIVER_UNKNOWN); if (!p_cdio) { fprintf(stderr, "Sorry, couldn't open %s\n", psz_image); return 1; } p_statbuf = iso9660_fs_stat (p_cdio, untranslated_name); if (NULL == p_statbuf) { fprintf(stderr, "Could not get ISO-9660 file information for file %s\n", untranslated_name); cdio_destroy(p_cdio); return 2; } iso9660_name_translate(psz_fname, translated_name); if (!(p_outfd = fopen (translated_name, "wb"))) { perror ("fopen()"); cdio_destroy(p_cdio); free(p_statbuf); return 3; } /* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */ { const unsigned int i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE); for (i = 0; i < i_blocks; i ++) { char buf[ISO_BLOCKSIZE]; const lsn_t lsn = p_statbuf->lsn + i; memset (buf, 0, ISO_BLOCKSIZE); if ( 0 != cdio_read_data_sectors (p_cdio, buf, lsn, ISO_BLOCKSIZE, 1) ) { fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n", (long unsigned int) p_statbuf->lsn); my_exit(4); } fwrite (buf, ISO_BLOCKSIZE, 1, p_outfd); if (ferror (p_outfd)) { perror ("fwrite()"); my_exit(5); } } } fflush (p_outfd); /* Make sure the file size has the exact same byte size. Without the truncate below, the file will a multiple of ISO_BLOCKSIZE. */ if (ftruncate (fileno (p_outfd), p_statbuf->size)) perror ("ftruncate()"); printf("Extraction of file '%s' from '%s' successful.\n", translated_name, untranslated_name); my_exit(0); }
int main(int argc, const char *argv[]) { CdIo_t *p_cdio=NULL; init(); /* Parse our arguments; every option seen by `parse_opt' will be reflected in `arguments'. */ parse_options(argc, argv); print_version(program_name, CDIO_VERSION, false, opts.version_only); if (opts.debug_level == 3) { cdio_loglevel_default = CDIO_LOG_INFO; } else if (opts.debug_level >= 4) { cdio_loglevel_default = CDIO_LOG_DEBUG; } if (NULL == source_name) { char *default_device; p_cdio = cdio_open (NULL, DRIVER_DEVICE); if (NULL == p_cdio) { printf("No loaded CD-ROM device accessible.\n"); } else { default_device = cdio_get_default_device(p_cdio); printf("The driver selected is %s\n", cdio_get_driver_name(p_cdio)); if (default_device) { printf("The default device for this driver is %s\n", default_device); } free(default_device); cdio_destroy(p_cdio); p_cdio=NULL; printf("\n"); } } /* Print out a drivers available */ { driver_id_t driver_id; printf("Drivers available...\n"); for (driver_id=CDIO_MIN_DRIVER; driver_id<=CDIO_MAX_DRIVER; driver_id++) if (cdio_have_driver(driver_id)) { printf(" %-35s\n", cdio_driver_describe(driver_id)); } printf("\n"); } if (NULL == source_name) { /* Print out a list of CD-drives */ char **ppsz_cdrives=NULL, **ppsz_cd; driver_id_t driver_id = DRIVER_DEVICE; ppsz_cdrives = cdio_get_devices_ret(&driver_id); if (NULL != ppsz_cdrives) for( ppsz_cd = ppsz_cdrives; *ppsz_cd != NULL; ppsz_cd++ ) { cdio_drive_read_cap_t i_read_cap; cdio_drive_write_cap_t i_write_cap; cdio_drive_misc_cap_t i_misc_cap; cdio_hwinfo_t hwinfo; CdIo_t *p_cdio = cdio_open(*ppsz_cd, driver_id); printf("%28s: %s\n", "Drive", *ppsz_cd); if (p_cdio) { if (cdio_get_hwinfo(p_cdio, &hwinfo)) { printf("%-28s: %s\n%-28s: %s\n%-28s: %s\n", "Vendor" , hwinfo.psz_vendor, "Model" , hwinfo.psz_model, "Revision", hwinfo.psz_revision); } print_mmc_drive_features(p_cdio); cdio_get_drive_cap(p_cdio, &i_read_cap, &i_write_cap, &i_misc_cap); print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap); } printf("\n"); if (p_cdio) cdio_destroy(p_cdio); } cdio_free_device_list(ppsz_cdrives); free(ppsz_cdrives); ppsz_cdrives = NULL; } else { /* Print CD-drive info for given source */ cdio_drive_read_cap_t i_read_cap; cdio_drive_write_cap_t i_write_cap; cdio_drive_misc_cap_t i_misc_cap; cdio_hwinfo_t hwinfo; printf("Drive %s\n", source_name); p_cdio = cdio_open (source_name, DRIVER_UNKNOWN); if (NULL != p_cdio) { if (cdio_get_hwinfo(p_cdio, &hwinfo)) { printf("%-28s: %s\n%-28s: %s\n%-28s: %s\n", "Vendor" , hwinfo.psz_vendor, "Model" , hwinfo.psz_model, "Revision", hwinfo.psz_revision); } print_mmc_drive_features(p_cdio); } cdio_get_drive_cap_dev(source_name, &i_read_cap, &i_write_cap, &i_misc_cap); print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap); printf("\n"); } myexit(p_cdio, EXIT_SUCCESS); /* Not reached:*/ return(EXIT_SUCCESS); }
static int cda_init (DB_fileinfo_t *_info, DB_playItem_t *it) { cdda_info_t *info = (cdda_info_t *)_info; trace ("cdda: init %s\n", deadbeef->pl_find_meta (it, ":URI")); size_t l = strlen (deadbeef->pl_find_meta (it, ":URI")); char location[l+1]; memcpy (location, deadbeef->pl_find_meta (it, ":URI"), l+1); char *nr = strchr (location, '#'); if (nr) { *nr = 0; nr++; } else { trace ("cdda: bad name: %s\n", deadbeef->pl_find_meta (it, ":URI")); return -1; } int track_nr = atoi (nr); char *fname = (*location) ? location : NULL; //NULL if empty string; means pysical CD drive info->cdio = cdio_open (fname, DRIVER_UNKNOWN); if (!info->cdio) { trace ("cdda: Could not open CD\n"); return -1; } track_t first_track = cdio_get_first_track_num (info->cdio); if (first_track == 0xff) { trace ("cdda: no medium found\n"); return -1; } track_t tracks = cdio_get_num_tracks (info->cdio); track_t i; cddb_track_t *track; cddb_disc_t *disc = cddb_disc_new(); cddb_disc_set_length (disc, cdio_get_track_lba (info->cdio, CDIO_CDROM_LEADOUT_TRACK) / CDIO_CD_FRAMES_PER_SEC); for (i = 0; i < tracks; i++) { lsn_t offset = cdio_get_track_lba (info->cdio, i+first_track); track = cddb_track_new(); cddb_track_set_frame_offset (track, offset); cddb_disc_add_track (disc, track); } cddb_disc_calc_discid (disc); int discid = cddb_disc_get_discid (disc); int trk_discid = deadbeef->pl_find_meta_int (it, ":CDIO_DISCID", 0); if (trk_discid != discid) { cddb_disc_destroy (disc); trace ("cdda: the track belongs to another disc, skipped\n"); return -1; } cddb_disc_destroy (disc); if (TRACK_FORMAT_AUDIO != cdio_get_track_format (info->cdio, track_nr)) { trace ("cdda: Not an audio track (%d)\n", track_nr); return -1; } int channels = cdio_get_track_channels (info->cdio, track_nr); trace ("cdio nchannels: %d\n", channels); _info->plugin = &plugin; _info->fmt.bps = 16; _info->fmt.channels = 2; _info->fmt.samplerate = 44100; _info->fmt.channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT; _info->readpos = 0; info->first_sector = cdio_get_track_lsn (info->cdio, track_nr); info->sector_count = cdio_get_track_sec_count (info->cdio, track_nr); info->current_sector = info->first_sector; info->tail_len = 0; info->current_sample = 0; return 0; }
static DB_playItem_t * cda_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { trace ("CDA insert: %s\n", fname); CdIo_t* cdio = NULL; int track_nr; DB_playItem_t *res; const char* shortname = strrchr (fname, '/'); if (shortname) { shortname++; } else { shortname = fname; } const char *ext = strrchr (shortname, '.') + 1; int is_image = ext && (0 == strcmp (ext, "nrg")); if (is_image && !deadbeef->conf_get_int ("cdda.enable_nrg", 0)) { return NULL; } if (0 == strcmp (ext, "cda")) { cdio = cdio_open (NULL, DRIVER_UNKNOWN); } else if (is_image) { cdio = cdio_open (fname, DRIVER_NRG); } if (!cdio) { trace ("not an audio disc/image, or file not found (%s)\n", fname); return NULL; } // calculate discid track_t first_track = cdio_get_first_track_num (cdio); if (first_track == 0xff) { trace ("cdda: no medium found\n"); cdio_destroy (cdio); return NULL; } track_t tracks = cdio_get_num_tracks (cdio); track_t i; cddb_track_t *track; cddb_disc_t *disc = cddb_disc_new(); cddb_disc_set_length (disc, cdio_get_track_lba (cdio, CDIO_CDROM_LEADOUT_TRACK) / CDIO_CD_FRAMES_PER_SEC); for (i = 0; i < tracks; i++) { lsn_t offset = cdio_get_track_lba (cdio, i+first_track); track = cddb_track_new(); cddb_track_set_frame_offset (track, offset); cddb_disc_add_track (disc, track); } cddb_disc_calc_discid (disc); int discid = cddb_disc_get_discid (disc); if (0 == strcasecmp (shortname, "all.cda") || is_image) { track_t i; res = after; struct cddb_thread_params *p = malloc (sizeof (struct cddb_thread_params)); memset (p, 0, sizeof (struct cddb_thread_params)); p->cdio = cdio; int enable_cddb = deadbeef->conf_get_int ("cdda.freedb.enable", DEFAULT_USE_CDDB); for (i = 0; i < tracks; i++) { trace ("inserting track %d\n", i); res = insert_single_track (cdio, plt, res, is_image ? fname : NULL, i+first_track, discid); if (res) { p->items[i] = res; } } int got_cdtext = read_disc_cdtext (p); int prefer_cdtext = deadbeef->conf_get_int ("cdda.prefer_cdtext", DEFAULT_PREFER_CDTEXT); if ((!got_cdtext || !prefer_cdtext) && enable_cddb) { trace ("cdda: querying freedb...\n"); intptr_t tid = deadbeef->thread_start (cddb_thread, p); //will destroy cdio deadbeef->thread_detach (tid); } else cleanup_thread_params (p); } else { track_nr = atoi (shortname); res = insert_single_track (cdio, plt, after, NULL, track_nr, discid); if (res) { read_track_cdtext (cdio, track_nr, res); deadbeef->pl_item_unref (res); } cdio_destroy (cdio); } cddb_disc_destroy (disc); return res; }
static DB_playItem_t * cda_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *path) { trace("CDA insert: %s\n", path); cdio_close_tray(NULL, NULL); /* Deal with any NRG files and get them out of the way */ const char *ext = strrchr(path, '.'); if (ext && !strcasecmp(ext, ".nrg")) { if (!deadbeef->conf_get_int("cdda.enable_nrg", 0)) { trace("cda: NRG found but disabled in preferences\n"); return NULL; } CdIo_t* cdio = cdio_open(path, DRIVER_NRG); if (!cdio) { trace("not an NRG image, or file not found (%s)\n", path); return NULL; } DB_playItem_t *inserted = insert_disc(plt, after, path, 0, cdio); cdio_destroy(cdio); return inserted; } /* Get a list of all devices containing CD audio */ driver_id_t driver_id; char **device_list = cdio_get_devices_with_cap_ret(NULL, CDIO_FS_AUDIO, false, &driver_id); if (!device_list) { trace("cda: no audio drives found\n"); return NULL; } /* Match the device name for the requested insert (invalid devices may crash cdio) */ const char *sep = strrchr(path, '/'); char *drive_device = NULL; if (sep) { char *real_path = realpath(path, NULL); if (!real_path) { const size_t device_length = sep - path; char device_path[device_length+1]; strncpy(device_path, path, device_length); device_path[device_length] = '\0'; real_path = realpath(device_path, NULL); } if (real_path) { for (size_t i = 0; device_list[i] && !drive_device; i++) { char *real_device = realpath(device_list[i], NULL); if (real_device) { if (!strcmp(real_device, real_path)) { drive_device = device_list[i]; } free(real_device); } } free(real_path); } } else { drive_device = device_list[0]; } /* Open the device and insert the requested track(s) */ DB_playItem_t *inserted = NULL; if (drive_device) { trace("cda: try to open device %s\n", drive_device); CdIo_t* cdio = cdio_open(drive_device, driver_id); if (cdio) { char *track_end; const unsigned long track_nr = strtoul(sep ? sep + 1 : path, &track_end, 10); const track_t single_track = strcmp(track_end, ".cda") || track_nr > CDIO_CD_MAX_TRACKS ? 0 : track_nr; inserted = insert_disc(plt, after, drive_device, single_track, cdio); cdio_destroy(cdio); } } cdio_free_device_list(device_list); return inserted; }
static int cda_init (DB_fileinfo_t *_info, DB_playItem_t *it) { deadbeef->pl_lock(); const char *uri = deadbeef->pl_find_meta(it, ":URI"); const char *nr = uri ? strchr(uri, '#') : NULL; if (!nr || nr == uri) { deadbeef->pl_unlock(); trace ("cdda: bad name: %s\n", uri); return -1; } trace ("cdda: init %s\n", uri); const int track_nr = atoi(nr+1); const size_t device_length = nr - uri; char device[device_length+1]; strncpy(device, uri, device_length); device[device_length] = '\0'; deadbeef->pl_unlock(); cdda_info_t *info = (cdda_info_t *)_info; info->cdio = cdio_open(device, DRIVER_UNKNOWN); if (!info->cdio) { trace ("cdda: Could not open CD device\n"); return -1; } const int need_bitrate = info->hints & DDB_DECODER_HINT_NEED_BITRATE; const int drive_speed = deadbeef->conf_get_int("cdda.drive_speed", 2); cdio_set_speed(info->cdio, need_bitrate && drive_speed < 5 ? 1<<drive_speed : -1); cddb_disc_t *disc = create_disc(info->cdio); if (!disc) { return -1; } const unsigned long discid = cddb_disc_get_discid(disc); cddb_disc_destroy(disc); deadbeef->pl_lock(); const char *discid_hex = deadbeef->pl_find_meta(it, CDDB_DISCID_TAG); const unsigned long trk_discid = discid_hex ? strtoul(discid_hex, NULL, 16) : 0; deadbeef->pl_unlock(); if (trk_discid != discid) { trace ("cdda: the track belongs to another disc (%x vs %x), skipped\n", trk_discid, discid); return -1; } if (cdio_get_track_format(info->cdio, track_nr) != TRACK_FORMAT_AUDIO) { trace ("cdda: Not an audio track (%d)\n", track_nr); return -1; } info->first_sector = cdio_get_track_lsn(info->cdio, track_nr); info->current_sector = info->first_sector; info->last_sector = info->first_sector + cdio_get_track_sec_count(info->cdio, track_nr) - 1; trace("cdio nchannels (should always be 2 for an audio track): %d\n", cdio_get_track_channels (info->cdio, track_nr)); if (info->first_sector == CDIO_INVALID_LSN || info->last_sector <= info->first_sector) { trace ("cdda: invalid track\n"); return -1; } #if USE_PARANOIA if (cdio_get_driver_id(info->cdio) != DRIVER_NRG) { info->cdrom = cdda_identify(device, CDDA_MESSAGE_FORGETIT, NULL); if (info->cdrom) { cdda_open(info->cdrom); info->paranoia = paranoia_init(info->cdrom); } if (!info->paranoia) { trace ("cdda: cannot re-open %s for paranoia\n", device); return -1; } const int no_paranoia = need_bitrate || !deadbeef->conf_get_int("cdda.paranoia", 0); if (no_paranoia) { paranoia_cachemodel_size(info->paranoia, 100); } paranoia_modeset(info->paranoia, no_paranoia ? PARANOIA_MODE_DISABLE : PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP); paranoia_seek(info->paranoia, info->first_sector, SEEK_SET); } #endif return 0; }