long cdda_read(cdrom_drive *d, void *buffer, long beginsector, long sectors){ if(d->opened){ if(sectors>0){ sectors=d->read_audio(d,buffer,beginsector,sectors); if(sectors!=-1){ /* byteswap? */ if(d->bigendianp==-1) /* not determined yet */ d->bigendianp=data_bigendianp(d); if(d->bigendianp!=bigendianp()){ int i; u_int16_t *p=(u_int16_t *)buffer; long els=sectors*CD_FRAMESIZE_RAW/2; for(i=0;i<els;i++)p[i]=swap16(p[i]); } } } return(sectors); } cderror(d,"400: Device not open\n"); return(-400); }
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); }
/* finish initializing the drive! */ int cdio_cddap_open(cdrom_drive_t *d) { int ret; if(d->opened)return(0); if ( (ret=cddap_init_drive(d)) ) return(ret); /* Check TOC, enable for CDDA */ /* Some drives happily return a TOC even if there is no disc... */ { int i; for(i=0; i<d->tracks; i++) if(d->disc_toc[i].dwStartSector<0 || d->disc_toc[i+1].dwStartSector==0){ d->opened=0; cderror(d,"009: CDROM reporting illegal table of contents\n"); return(-9); } } if((ret=d->enable_cdda(d,1))) return(ret); /* d->select_speed(d,d->maxspeed); most drives are full speed by default */ if ( -1 == d->bigendianp ) { d->bigendianp = data_bigendianp(d); } return(0); }
/* finish initializing the drive! */ int cdio_cddap_open(cdrom_drive_t *d) { int ret; if(d->opened)return(0); #if HAVE_SCSI_HANDLING switch(d->interface){ case GENERIC_SCSI: if((ret=scsi_init_drive(d))) return(ret); break; case COOKED_IOCTL: if((ret=cooked_init_drive(d))) return(ret); break; default: cderror(d, "100: Interface not supported\n"); return(-100); } #else d->cdpinterface = COOKED_IOCTL; if ( (ret=cooked_init_drive(d)) ) return(ret); #endif /* Check TOC, enable for CDDA */ /* Some drives happily return a TOC even if there is no disc... */ { int i; for(i=0; i<d->tracks; i++) if(d->disc_toc[i].dwStartSector<0 || d->disc_toc[i+1].dwStartSector==0){ d->opened=0; cderror(d,"009: CDROM reporting illegal table of contents\n"); return(-9); } } if((ret=d->enable_cdda(d,1))) return(ret); /* d->select_speed(d,d->maxspeed); most drives are full speed by default */ if (d->bigendianp==-1) d->bigendianp=data_bigendianp(d); return(0); }
static uint32_t cdpa_get_format(rnc_dev_t *dev) { cdpa_t *cdpa = dev->data; int cmap = RNC_CHANNELMAP_LEFTRIGHT; int cmpr = RNC_ENCODING_PCM; int chnl = 2; int rate = RNC_SAMPLERATE_44100; int bits = 16; int frmt = RNC_SAMPLE_SIGNED; int endn = data_bigendianp(cdpa->cdda) ? RNC_ENDIAN_BIG : RNC_ENDIAN_LITTLE; mrp_debug("getting active device format"); return RNC_FORMAT_ID(cmap, cmpr, chnl, rate, bits, frmt, endn); }
static int cdpa_get_formats(rnc_dev_t *dev, uint32_t *buf, size_t size) { cdpa_t *cdpa = dev->data; int cmap = RNC_CHANNELMAP_LEFTRIGHT; int cmpr = RNC_ENCODING_PCM; int chnl = 2; int rate = RNC_SAMPLERATE_44100; int bits = 16; int frmt = RNC_SAMPLE_SIGNED; int endn = data_bigendianp(cdpa->cdda) ? RNC_ENDIAN_BIG : RNC_ENDIAN_LITTLE; mrp_debug("getting supported device format(s)"); if (size > 0) *buf = RNC_FORMAT_ID(cmap, cmpr, chnl, rate, bits, frmt, endn); return 1; }
long cdio_cddap_read(cdrom_drive_t *d, void *buffer, lsn_t beginsector, long sectors) { if (d->opened) { if (sectors>0) { sectors=d->read_audio(d, buffer, beginsector, sectors); if (sectors > 0) { /* byteswap? */ if ( d->bigendianp == -1 ) /* not determined yet */ d->bigendianp = data_bigendianp(d); if ( d->b_swap_bytes && d->bigendianp != bigendianp() ) { int i; uint16_t *p=(uint16_t *)buffer; long els=sectors*CDIO_CD_FRAMESIZE_RAW/2; /* Note: Something perhaps in the original cdparanoia code might cause the code to access outside of the allocated range of buffer. This comment is just to serve as a marker for the loop where the data got clobbered. I don't think this code however is wrong. See the comment in i_read_c_block of paranioa.c */ for(i=0;i<els;i++) p[i]=UINT16_SWAP_LE_BE_C(p[i]); } } } return(sectors); } cderror(d,"400: Device not open\n"); return(-400); }
static struct input_stream * input_cdio_open(const char *uri, GMutex *mutex, GCond *cond, GError **error_r) { struct input_cdio_paranoia *i; struct cdio_uri parsed_uri; if (!parse_cdio_uri(&parsed_uri, uri, error_r)) return NULL; i = g_new(struct input_cdio_paranoia, 1); input_stream_init(&i->base, &input_plugin_cdio_paranoia, uri, mutex, cond); /* initialize everything (should be already) */ i->drv = NULL; i->cdio = NULL; i->para = NULL; i->trackno = parsed_uri.track; pcm_buffer_init(&i->conv_buffer); /* get list of CD's supporting CD-DA */ char *device = parsed_uri.device[0] != 0 ? g_strdup(parsed_uri.device) : cdio_detect_device(); if (device == NULL) { g_set_error(error_r, cdio_quark(), 0, "Unable find or access a CD-ROM drive with an audio CD in it."); input_cdio_close(&i->base); return NULL; } /* Found such a CD-ROM with a CD-DA loaded. Use the first drive in the list. */ i->cdio = cdio_open(device, DRIVER_UNKNOWN); g_free(device); i->drv = cdio_cddap_identify_cdio(i->cdio, 1, NULL); if ( !i->drv ) { g_set_error(error_r, cdio_quark(), 0, "Unable to identify audio CD disc."); input_cdio_close(&i->base); return NULL; } cdda_verbose_set(i->drv, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT); if ( 0 != cdio_cddap_open(i->drv) ) { g_set_error(error_r, cdio_quark(), 0, "Unable to open disc."); input_cdio_close(&i->base); return NULL; } i->endian = data_bigendianp(i->drv); switch (i->endian) { case -1: g_debug("cdda: drive returns unknown audio data, assuming Little Endian"); i->endian = 0; break; case 0: g_debug("cdda: drive returns audio data Little Endian."); break; case 1: g_debug("cdda: drive returns audio data Big Endian."); break; default: g_set_error(error_r, cdio_quark(), 0, "Drive returns unknown data type %d", i->endian); input_cdio_close(&i->base); return NULL; } i->lsn_relofs = 0; if (i->trackno >= 0) { i->lsn_from = cdio_get_track_lsn(i->cdio, i->trackno); i->lsn_to = cdio_get_track_last_lsn(i->cdio, i->trackno); } else { i->lsn_from = 0; i->lsn_to = cdio_get_disc_last_lsn(i->cdio); } i->para = cdio_paranoia_init(i->drv); /* Set reading mode for full paranoia, but allow skipping sectors. */ paranoia_modeset(i->para, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP); /* seek to beginning of the track */ cdio_paranoia_seek(i->para, i->lsn_from, SEEK_SET); i->base.ready = true; i->base.seekable = true; i->base.size = (i->lsn_to - i->lsn_from + 1) * CDIO_CD_FRAMESIZE_RAW; /* hack to make MPD select the "pcm" decoder plugin */ i->base.mime = g_strdup("audio/x-mpd-cdda-pcm"); return &i->base; }