static int CDDA_init(cdio_CDDAObject *self, PyObject *args, PyObject *kwds) { const char *drive = NULL; self->pcm_module = NULL; if (!PyArg_ParseTuple(args, "s", &drive)) return -1; if ((self->pcm_module = PyImport_ImportModule("audiotools.pcm")) == NULL) return -1; self->cdrom_drive = cdio_cddap_identify(drive, 0, NULL); if (self->cdrom_drive == NULL) { PyErr_SetString(PyExc_IOError, "error opening CD-ROM"); return -1; } if (0 != cdio_cddap_open(self->cdrom_drive)) { PyErr_SetString(PyExc_IOError, "error opening CD-ROM"); return -1; } self->paranoia = cdio_paranoia_init(self->cdrom_drive); paranoia_modeset(self->paranoia, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP); return 0; }
static av_cold int read_header(AVFormatContext *ctx) { CDIOContext *s = ctx->priv_data; AVStream *st; int ret, i; char *err = NULL; if (!(st = avformat_new_stream(ctx, NULL))) return AVERROR(ENOMEM); s->drive = cdio_cddap_identify(ctx->filename, CDDA_MESSAGE_LOGIT, &err); if (!s->drive) { av_log(ctx, AV_LOG_ERROR, "Could not open drive %s.\n", ctx->filename); return AVERROR(EINVAL); } if (err) { av_log(ctx, AV_LOG_VERBOSE, "%s\n", err); free(err); } if ((ret = cdio_cddap_open(s->drive)) < 0 || !s->drive->opened) { av_log(ctx, AV_LOG_ERROR, "Could not open disk in drive %s.\n", ctx->filename); return AVERROR(EINVAL); } cdio_cddap_verbose_set(s->drive, CDDA_MESSAGE_LOGIT, CDDA_MESSAGE_LOGIT); if (s->speed) cdio_cddap_speed_set(s->drive, s->speed); s->paranoia = cdio_paranoia_init(s->drive); if (!s->paranoia) { av_log(ctx, AV_LOG_ERROR, "Could not init paranoia.\n"); return AVERROR(EINVAL); } cdio_paranoia_modeset(s->paranoia, s->paranoia_mode); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; if (s->drive->bigendianp) st->codec->codec_id = AV_CODEC_ID_PCM_S16BE; else st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; st->codec->sample_rate = 44100; st->codec->channels = 2; if (s->drive->audio_last_sector != CDIO_INVALID_LSN && s->drive->audio_first_sector != CDIO_INVALID_LSN) st->duration = s->drive->audio_last_sector - s->drive->audio_first_sector; else if (s->drive->tracks) st->duration = s->drive->disc_toc[s->drive->tracks].dwStartSector; avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2*st->codec->channels*st->codec->sample_rate); for (i = 0; i < s->drive->tracks; i++) { char title[16]; snprintf(title, sizeof(title), "track %02d", s->drive->disc_toc[i].bTrack); avpriv_new_chapter(ctx, i, st->time_base, s->drive->disc_toc[i].dwStartSector, s->drive->disc_toc[i+1].dwStartSector, title); } s->last_sector = cdio_cddap_disc_lastsector(s->drive); return 0; }
static int CDDAReader_init_device(cdio_CDDAReader *self, const char *device) { self->_.drive.drive = NULL; self->_.drive.paranoia = NULL; self->_.drive.current_sector = 0; self->_.drive.final_sector = 0; if ((self->_.drive.drive = cdio_cddap_identify(device, 0, NULL)) == NULL) { PyErr_SetString(PyExc_IOError, "error opening CD-ROM"); return -1; } if (cdio_cddap_open(self->_.drive.drive) != 0) { PyErr_SetString(PyExc_IOError, "error opening CD-ROM"); return -1; } self->_.drive.paranoia = cdio_paranoia_init(self->_.drive.drive); paranoia_modeset(self->_.drive.paranoia, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP); self->first_track_num = CDDAReader_first_track_num_device; self->last_track_num = CDDAReader_last_track_num_device; self->track_lsn = CDDAReader_track_lsn_device; self->track_last_lsn = CDDAReader_track_last_lsn_device; self->first_sector = CDDAReader_first_sector_device; self->last_sector = CDDAReader_last_sector_device; self->read = CDDAReader_read_device; self->seek = CDDAReader_seek_device; self->set_speed = CDDAReader_set_speed_device; self->dealloc = CDDAReader_dealloc_device; self->_.drive.final_sector = self->last_sector(self); if ((self->_.drive.final_sector == -1) || (self->first_sector(self) == -1)) { PyErr_SetString(PyExc_IOError, "no disc in CD-ROM drive"); return -1; } return 0; }
cdio() { /* See if we can find a device with a loaded CD-DA in it. */ ppsz_cd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false); if (ppsz_cd_drives) { /* Found such a CD-ROM with a CD-DA loaded. Use the first drive in the list. */ d = cdio_cddap_identify(*ppsz_cd_drives, 1, NULL); } else { printf("Unable find or access a CD-ROM drive with an audio CD in it.\n"); } /* Don't need a list of CD's with CD-DA's any more. */ if (ppsz_cd_drives) cdio_free_device_list(ppsz_cd_drives); /* We'll set for verbose paranoia messages. */ if (d) cdio_cddap_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT); if ( d && cdio_cddap_open(d) != 0 ) { printf("Unable to open disc.\n"); } }