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

Function tak_read_header

libavformat/takdec.c:54–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54static int tak_read_header(AVFormatContext *s)
55{
56 TAKDemuxContext *tc = s->priv_data;
57 AVIOContext *pb = s->pb;
58 GetBitContext gb;
59 AVStream *st;
60 uint8_t *buffer = NULL;
61 int ret;
62
63 st = avformat_new_stream(s, 0);
64 if (!st)
65 return AVERROR(ENOMEM);
66
67 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
68 st->codecpar->codec_id = AV_CODEC_ID_TAK;
69 ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW;
70
71 tc->mlast_frame = 0;
72 if (avio_rl32(pb) != MKTAG('t', 'B', 'a', 'K')) {
73 avio_seek(pb, -4, SEEK_CUR);
74 return 0;
75 }
76
77 while (!avio_feof(pb)) {
78 enum TAKMetaDataType type;
79 int size;
80
81 type = avio_r8(pb) & 0x7f;
82 size = avio_rl24(pb);
83
84 switch (type) {
85 case TAK_METADATA_STREAMINFO:
86 if (st->codecpar->extradata)
87 return AVERROR_INVALIDDATA;
88 case TAK_METADATA_LAST_FRAME:
89 case TAK_METADATA_ENCODER:
90 if (size <= 3)
91 return AVERROR_INVALIDDATA;
92
93 buffer = av_malloc(size - 3 + AV_INPUT_BUFFER_PADDING_SIZE);
94 if (!buffer)
95 return AVERROR(ENOMEM);
96 memset(buffer + size - 3, 0, AV_INPUT_BUFFER_PADDING_SIZE);
97
98 ffio_init_checksum(pb, tak_check_crc, 0xCE04B7U);
99 ret = ffio_read_size(pb, buffer, size - 3);
100 if (ret < 0) {
101 av_freep(&buffer);
102 return ret;
103 }
104 if (ffio_get_checksum(s->pb) != avio_rb24(pb)) {
105 av_log(s, AV_LOG_ERROR, "%d metadata block CRC error.\n", type);
106 if (s->error_recognition & AV_EF_EXPLODE) {
107 av_freep(&buffer);
108 return AVERROR_INVALIDDATA;
109 }
110 }
111

Callers

nothing calls this directly

Calls 15

avformat_new_streamFunction · 0.85
ffstreamFunction · 0.85
avio_rl32Function · 0.85
avio_seekFunction · 0.85
avio_feofFunction · 0.85
avio_r8Function · 0.85
avio_rl24Function · 0.85
ffio_init_checksumFunction · 0.85
ffio_read_sizeFunction · 0.85
av_freepFunction · 0.85
ffio_get_checksumFunction · 0.85
avio_rb24Function · 0.85

Tested by

no test coverage detected