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

Function wav_read_header

libavformat/wavdec.c:354–690  ·  view source on GitHub ↗

wav input */

Source from the content-addressed store, hash-verified

352
353/* wav input */
354static int wav_read_header(AVFormatContext *s)
355{
356 int64_t size, av_uninit(data_size);
357 int64_t sample_count = 0;
358 int rf64 = 0, bw64 = 0;
359 uint32_t tag;
360 AVIOContext *pb = s->pb;
361 AVStream *st = NULL;
362 WAVDemuxContext *wav = s->priv_data;
363 int ret, got_fmt = 0, got_xma2 = 0;
364 int64_t next_tag_ofs, data_ofs = -1;
365
366 wav->unaligned = avio_tell(s->pb) & 1;
367
368 wav->smv_data_ofs = -1;
369
370 /* read chunk ID */
371 tag = avio_rl32(pb);
372 switch (tag) {
373 case MKTAG('R', 'I', 'F', 'F'):
374 break;
375 case MKTAG('R', 'I', 'F', 'X'):
376 wav->rifx = 1;
377 break;
378 case MKTAG('R', 'F', '6', '4'):
379 rf64 = 1;
380 break;
381 case MKTAG('B', 'W', '6', '4'):
382 bw64 = 1;
383 break;
384 default:
385 av_log(s, AV_LOG_ERROR, "invalid start code %s in RIFF header\n",
386 av_fourcc2str(tag));
387 return AVERROR_INVALIDDATA;
388 }
389
390 /* read chunk size */
391 avio_rl32(pb);
392
393 /* read format */
394 if (avio_rl32(pb) != MKTAG('W', 'A', 'V', 'E')) {
395 av_log(s, AV_LOG_ERROR, "invalid format in RIFF header\n");
396 return AVERROR_INVALIDDATA;
397 }
398
399 if (rf64 || bw64) {
400 if (avio_rl32(pb) != MKTAG('d', 's', '6', '4'))
401 return AVERROR_INVALIDDATA;
402 size = avio_rl32(pb);
403 if (size < 24)
404 return AVERROR_INVALIDDATA;
405 avio_rl64(pb); /* RIFF size */
406
407 data_size = avio_rl64(pb);
408 sample_count = avio_rl64(pb);
409
410 if (data_size < 0 || sample_count < 0) {
411 av_log(s, AV_LOG_ERROR, "negative data_size and/or sample_count in "

Callers

nothing calls this directly

Calls 15

avio_tellFunction · 0.85
avio_rl32Function · 0.85
av_logFunction · 0.85
avio_rl64Function · 0.85
avio_skipFunction · 0.85
avformat_new_streamFunction · 0.85
next_tagFunction · 0.85
avio_feofFunction · 0.85
wav_parse_fmt_tagFunction · 0.85
wav_parse_xma2_tagFunction · 0.85
avio_rb32Function · 0.85
wav_parse_bext_tagFunction · 0.85

Tested by

no test coverage detected