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; }
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(); }
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"); } }
static void cued_rip_prologue(rip_context_t *rip) { rip->mmcBuf = NULL; rip->allocatedSectors = 0; #ifdef CUED_HAVE_PARANOIA if (ripUseParanoia) { char *msg = 0; int rc; // N.B. this behavior does not match documentation: // the 0 here appears to prevent the message "Checking <filename> for cdrom..." rip->paranoiaCtlObj = cdio_cddap_identify_cdio(rip->cdObj, 0, &msg); if (rip->paranoiaCtlObj) { if (msg) { cdio_warn("identify returned paranoia message(s) \"%s\"", msg); } cdio_cddap_verbose_set(rip->paranoiaCtlObj, CDDA_MESSAGE_LOGIT, CDDA_MESSAGE_LOGIT); rc = cdio_cddap_open(rip->paranoiaCtlObj); cdio2_paranoia_msg(rip->paranoiaCtlObj, "open of device"); if (!rc) { rip->paranoiaRipObj = cdio_paranoia_init(rip->paranoiaCtlObj); cdio2_paranoia_msg(rip->paranoiaCtlObj, "initialization of paranoia"); if (!rip->paranoiaRipObj) { cdio2_abort("out of memory initializing paranoia"); } cdio_paranoia_modeset(rip->paranoiaRipObj, PARANOIA_MODE_FULL ^ PARANOIA_MODE_NEVERSKIP); // N.B. not needed at the moment cdio2_paranoia_msg(rip->paranoiaCtlObj, "setting of paranoia mode"); rip->save_read_paranoid = rip->paranoiaCtlObj->read_audio; rip->paranoiaCtlObj->read_audio = cued_read_paranoid; } else { cdio_cddap_close_no_free_cdio(rip->paranoiaCtlObj); cdio_error("disabling paranoia"); CLRF(RIP_F_USE_PARANOIA, rip->flags); } } else { cdio_error("disabling paranoia due to the following message(s):\n%s", msg); CLRF(RIP_F_USE_PARANOIA, rip->flags); } } #endif // CUED_HAVE_PARANOIA if (rip->qSubChannelFileName) { if (!strcmp("-", rip->qSubChannelFileName)) { rip->qSubChannelFile = stdout; } else { (void) format_get_file_path(rip->cdObj, rip->cddbObj, rip->qSubChannelFileName, "", 0, rip->fileNameBuffer, rip->bufferSize); // replaced O_EXCL with O_TRUNC to allow using /dev/null for testing rip->qSubChannelFile = fopen2(rip->fileNameBuffer, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0666); if (!rip->qSubChannelFile) { cdio2_unix_error("fopen2", rip->fileNameBuffer, 0); cdio_error("not creating sub-channel file \"%s\"", rip->fileNameBuffer); rip->qSubChannelFileName = 0; } } } rip->endOfDiscSector = cdio_get_disc_last_lsn(rip->cdObj); if (CDIO_INVALID_LSN == rip->endOfDiscSector) { cdio2_abort("failed to get last sector number"); } else { //cdio_debug("end of disc sector is %d", rip->endOfDiscSector); } }
// pure virtual bool CdDecoder::initialize() { if (m_inited) return true; m_inited = m_user_stop = m_finish = false; m_freq = m_bitrate = 0L; m_stat = DecoderEvent::Error; m_chan = 0; m_seekTime = -1.; if (output()) output()->PauseUntilBuffered(); QFile* file = dynamic_cast< QFile* >(input()); // From QIODevice* if (file) { setFilename(file->fileName()); m_tracknum = getFilename().section('.', 0, 0).toUInt(); } QMutexLocker lock(&getCdioMutex()); m_cdio = openCdio(m_devicename); if (!m_cdio) return false; m_start = cdio_get_track_lsn(m_cdio, m_tracknum); m_end = cdio_get_track_last_lsn(m_cdio, m_tracknum); if (CDIO_INVALID_LSN == m_start || CDIO_INVALID_LSN == m_end) { LOG(VB_MEDIA, LOG_INFO, "CdDecoder: No tracks on " + m_devicename); cdio_destroy(m_cdio), m_cdio = 0; return false; } LOG(VB_MEDIA, LOG_DEBUG, QString("CdDecoder track=%1 lsn start=%2 end=%3") .arg(m_tracknum).arg(m_start).arg(m_end)); m_curpos = m_start; m_device = cdio_cddap_identify_cdio(m_cdio, 0, NULL); if (NULL == m_device) { LOG(VB_GENERAL, LOG_ERR, QString("Error: CdDecoder: cdio_cddap_identify(%1) failed") .arg(m_devicename)); cdio_destroy(m_cdio), m_cdio = 0; return false; } cdio_cddap_verbose_set(m_device, VERBOSE_LEVEL_CHECK(VB_MEDIA, LOG_ANY) ? CDDA_MESSAGE_PRINTIT : CDDA_MESSAGE_FORGETIT, VERBOSE_LEVEL_CHECK(VB_MEDIA, LOG_DEBUG) ? CDDA_MESSAGE_PRINTIT : CDDA_MESSAGE_FORGETIT); if (DRIVER_OP_SUCCESS == cdio_cddap_open(m_device)) { // cdio_get_track_last_lsn is unreliable on discs with data at end lsn_t end2 = cdio_cddap_track_lastsector(m_device, m_tracknum); if (end2 < m_end) { LOG(VB_MEDIA, LOG_INFO, QString("CdDecoder: trim last lsn from %1 to %2") .arg(m_end).arg(end2)); m_end = end2; } m_paranoia = cdio_paranoia_init(m_device); if (NULL != m_paranoia) { cdio_paranoia_modeset(m_paranoia, PARANOIA_MODE_DISABLE); (void)cdio_paranoia_seek(m_paranoia, m_start, SEEK_SET); } else { LOG(VB_GENERAL, LOG_ERR, "Warn: CD reading with paranoia is disabled"); } } else { LOG(VB_GENERAL, LOG_ERR, QString("Warn: drive '%1' is not cdda capable"). arg(m_devicename)); } int chnls = cdio_get_track_channels(m_cdio, m_tracknum); m_chan = chnls > 0 ? chnls : 2; m_freq = kSamplesPerSec; if (output()) { const AudioSettings settings(FORMAT_S16, m_chan, CODEC_ID_PCM_S16LE, m_freq, false /* AC3/DTS passthru */); output()->Reconfigure(settings); output()->SetSourceBitrate(m_freq * m_chan * 16); } // 20ms worth m_bks = (m_freq * m_chan * 2) / 50; m_bksFrames = m_freq / 50; // decode 8 bks worth of samples each time we need more m_decodeBytes = m_bks << 3; m_output_buf = reinterpret_cast< char* >( ::av_malloc(m_decodeBytes + CDIO_CD_FRAMESIZE_RAW * 2)); m_output_at = 0; setCDSpeed(2); m_inited = true; return m_inited; }