static av_cold int read_header(AVFormatContext *ctx, AVFormatParameters *ap) { CDIOContext *s = ctx->priv_data; AVStream *st; int ret, i; char *err = NULL; if (!(st = av_new_stream(ctx, 0))) 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 = CODEC_ID_PCM_S16BE; else st->codec->codec_id = 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; av_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); ff_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 AVChapter *read_chapter(AVFormatContext *s) { uint8_t line[256]; int64_t start, end; AVRational tb = {1, 1e9}; get_line(s->pb, line, sizeof(line)); if (sscanf(line, "TIMEBASE=%d/%d", &tb.num, &tb.den)) get_line(s->pb, line, sizeof(line)); if (!sscanf(line, "START=%lld", &start)) { av_log(s, AV_LOG_ERROR, "Expected chapter start timestamp, found %s.\n", line); start = (s->nb_chapters && s->chapters[s->nb_chapters - 1]->end != AV_NOPTS_VALUE) ? s->chapters[s->nb_chapters - 1]->end : 0; } else get_line(s->pb, line, sizeof(line)); if (!sscanf(line, "END=%lld", &end)) { av_log(s, AV_LOG_ERROR, "Expected chapter end timestamp, found %s.\n", line); end = AV_NOPTS_VALUE; } return ff_new_chapter(s, s->nb_chapters, tb, start, end, NULL); }