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

Function hca_read_header

libavformat/hca.c:51–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51static int hca_read_header(AVFormatContext *s)
52{
53 HCADemuxContext *hca = s->priv_data;
54 AVCodecParameters *par;
55 GetByteContext gb;
56 AVIOContext *pb = s->pb;
57 AVStream *st;
58 uint32_t chunk;
59 uint16_t version;
60 uint32_t block_count;
61 uint16_t block_size, data_offset;
62 int ret;
63
64 avio_skip(pb, 4);
65 version = avio_rb16(pb);
66
67 data_offset = avio_rb16(pb);
68 if (data_offset <= 8)
69 return AVERROR_INVALIDDATA;
70
71 st = avformat_new_stream(s, NULL);
72 if (!st)
73 return AVERROR(ENOMEM);
74
75 par = st->codecpar;
76 ret = ff_alloc_extradata(par, data_offset + 10);
77 if (ret < 0)
78 return ret;
79
80 ret = ffio_read_size(pb, par->extradata + 8, par->extradata_size - 8 - 10);
81 if (ret < 0)
82 return AVERROR_INVALIDDATA;
83 AV_WL32(par->extradata, MKTAG('H', 'C', 'A', 0));
84 AV_WB16(par->extradata + 4, version);
85 AV_WB16(par->extradata + 6, data_offset);
86 AV_WB32(par->extradata + par->extradata_size - 10, hca->keyh);
87 AV_WB32(par->extradata + par->extradata_size - 6, hca->keyl);
88 AV_WB16(par->extradata + par->extradata_size - 2, hca->subkey);
89
90 bytestream2_init(&gb, par->extradata + 8, par->extradata_size - 8);
91
92 if ((bytestream2_get_le32(&gb) & HCA_MASK) != MKTAG('f', 'm', 't', 0))
93 return AVERROR_INVALIDDATA;
94
95 par->codec_type = AVMEDIA_TYPE_AUDIO;
96 par->codec_id = AV_CODEC_ID_HCA;
97 par->codec_tag = 0;
98 st->codecpar->ch_layout.nb_channels = bytestream2_get_byte(&gb);
99 par->sample_rate = bytestream2_get_be24(&gb);
100 block_count = bytestream2_get_be32(&gb);
101 bytestream2_skip(&gb, 4);
102 chunk = bytestream2_get_le32(&gb) & HCA_MASK;
103 if (chunk == MKTAG('c', 'o', 'm', 'p')) {
104 block_size = bytestream2_get_be16(&gb);
105 } else if (chunk == MKTAG('d', 'e', 'c', 0)) {
106 block_size = bytestream2_get_be16(&gb);
107 } else {
108 return AVERROR_INVALIDDATA;

Callers

nothing calls this directly

Calls 9

avio_skipFunction · 0.85
avio_rb16Function · 0.85
avformat_new_streamFunction · 0.85
ff_alloc_extradataFunction · 0.85
ffio_read_sizeFunction · 0.85
bytestream2_initFunction · 0.85
bytestream2_skipFunction · 0.85
avio_seekFunction · 0.85
avpriv_set_pts_infoFunction · 0.85

Tested by

no test coverage detected