MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / read_header

Function read_header

libavdevice/libcdio.c:54–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52} CDIOContext;
53
54static av_cold int read_header(AVFormatContext *ctx)
55{
56 CDIOContext *s = ctx->priv_data;
57 AVStream *st;
58 int ret, i;
59 char *err = NULL;
60
61 if (!(st = avformat_new_stream(ctx, NULL)))
62 return AVERROR(ENOMEM);
63 s->drive = cdio_cddap_identify(ctx->url, CDDA_MESSAGE_LOGIT, &err);
64 if (!s->drive) {
65 av_log(ctx, AV_LOG_ERROR, "Could not open drive %s.\n", ctx->url);
66 return AVERROR(EINVAL);
67 }
68 if (err) {
69 av_log(ctx, AV_LOG_VERBOSE, "%s\n", err);
70 free(err);
71 }
72 if ((ret = cdio_cddap_open(s->drive)) < 0 || !s->drive->opened) {
73 av_log(ctx, AV_LOG_ERROR, "Could not open disk in drive %s.\n", ctx->url);
74 return AVERROR(EINVAL);
75 }
76
77 cdio_cddap_verbose_set(s->drive, CDDA_MESSAGE_LOGIT, CDDA_MESSAGE_LOGIT);
78 if (s->speed)
79 cdio_cddap_speed_set(s->drive, s->speed);
80
81 s->paranoia = cdio_paranoia_init(s->drive);
82 if (!s->paranoia) {
83 av_log(ctx, AV_LOG_ERROR, "Could not init paranoia.\n");
84 return AVERROR(EINVAL);
85 }
86 cdio_paranoia_modeset(s->paranoia, s->paranoia_mode);
87
88 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
89 if (s->drive->bigendianp)
90 st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
91 else
92 st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
93 st->codecpar->sample_rate = 44100;
94 st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
95 if (s->drive->audio_last_sector != CDIO_INVALID_LSN &&
96 s->drive->audio_first_sector != CDIO_INVALID_LSN)
97 st->duration = s->drive->audio_last_sector - s->drive->audio_first_sector;
98 else if (s->drive->tracks)
99 st->duration = s->drive->disc_toc[s->drive->tracks].dwStartSector;
100 avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW,
101 2 * st->codecpar->ch_layout.nb_channels * st->codecpar->sample_rate);
102
103 for (i = 0; i < s->drive->tracks; i++) {
104 char title[16];
105 snprintf(title, sizeof(title), "track %02d", s->drive->disc_toc[i].bTrack);
106 avpriv_new_chapter(ctx, i, st->time_base, s->drive->disc_toc[i].dwStartSector,
107 s->drive->disc_toc[i+1].dwStartSector, title);
108 }
109
110 s->last_sector = cdio_cddap_disc_lastsector(s->drive);
111

Callers

nothing calls this directly

Calls 4

avformat_new_streamFunction · 0.85
av_logFunction · 0.85
avpriv_set_pts_infoFunction · 0.85
avpriv_new_chapterFunction · 0.85

Tested by

no test coverage detected