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

Function pcm_read_header

libavformat/pcmdec.c:41–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39} PCMAudioDemuxerContext;
40
41static int pcm_read_header(AVFormatContext *s)
42{
43 PCMAudioDemuxerContext *s1 = s->priv_data;
44 AVCodecParameters *par;
45 AVStream *st;
46 uint8_t *mime_type = NULL;
47 int ret;
48
49 st = avformat_new_stream(s, NULL);
50 if (!st)
51 return AVERROR(ENOMEM);
52 par = st->codecpar;
53
54 par->codec_type = AVMEDIA_TYPE_AUDIO;
55 par->codec_id = ffifmt(s->iformat)->raw_codec_id;
56 par->sample_rate = s1->sample_rate;
57 ret = av_channel_layout_copy(&par->ch_layout, &s1->ch_layout);
58 if (ret < 0)
59 return ret;
60
61 av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type);
62 if (mime_type && s->iformat->mime_type) {
63 int rate = 0, channels = 0, little_endian = 0;
64 const char *options;
65 if (av_stristart(mime_type, s->iformat->mime_type, &options)) { /* audio/L16 */
66 while (options = strchr(options, ';')) {
67 options++;
68 if (!rate)
69 sscanf(options, " rate=%d", &rate);
70 if (!channels)
71 sscanf(options, " channels=%d", &channels);
72 if (!little_endian) {
73 char val[sizeof("little-endian")];
74 if (sscanf(options, " endianness=%13s", val) == 1) {
75 little_endian = strcmp(val, "little-endian") == 0;
76 }
77 }
78 }
79 if (rate <= 0) {
80 av_log(s, AV_LOG_ERROR,
81 "Invalid sample_rate found in mime_type \"%s\"\n",
82 mime_type);
83 av_freep(&mime_type);
84 return AVERROR_INVALIDDATA;
85 }
86 par->sample_rate = rate;
87 if (channels > 0) {
88 av_channel_layout_uninit(&par->ch_layout);
89 par->ch_layout.nb_channels = channels;
90 }
91 if (little_endian)
92 par->codec_id = AV_CODEC_ID_PCM_S16LE;
93 }
94 }
95 av_freep(&mime_type);
96
97 par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id);
98

Callers

nothing calls this directly

Calls 10

avformat_new_streamFunction · 0.85
ffifmtFunction · 0.85
av_channel_layout_copyFunction · 0.85
av_opt_getFunction · 0.85
av_stristartFunction · 0.85
av_logFunction · 0.85
av_freepFunction · 0.85
av_channel_layout_uninitFunction · 0.85
av_get_bits_per_sampleFunction · 0.85
avpriv_set_pts_infoFunction · 0.85

Tested by

no test coverage detected