MCPcopy Create free account
hub / github.com/FastLED/FastLED / parseAvcC

Function parseAvcC

src/fl/codec/mp4_parser.cpp.hpp:46–102  ·  view source on GitHub ↗

Parse avcC (AVC Decoder Configuration Record) at given offset. ISO 14496-15 section 5.2.4.1

Source from the content-addressed store, hash-verified

44// Parse avcC (AVC Decoder Configuration Record) at given offset.
45// ISO 14496-15 section 5.2.4.1
46bool parseAvcC(fl::span<const fl::u8> data, fl::size offset, fl::size boxEnd,
47 Mp4TrackInfo& info) {
48 // avcC box: 8 bytes header, then:
49 // u8 configVersion (1)
50 // u8 profile_idc
51 // u8 profile_compat
52 // u8 level_idc
53 // u8 lengthSizeMinusOne (& 0x03)
54 // u8 numSPS (& 0x1F)
55 // for each SPS: u16 spsLength, u8[] spsData
56 // u8 numPPS
57 // for each PPS: u16 ppsLength, u8[] ppsData
58
59 fl::size pos = offset + 8; // skip box header
60 if (pos + 6 > boxEnd) return false;
61
62 fl::u8 configVersion = data[pos++];
63 if (configVersion != 1) return false;
64
65 info.profile = data[pos++];
66 pos++; // profile_compat
67 info.level = data[pos++];
68 info.lengthSizeMinusOne = data[pos++] & 0x03;
69
70 fl::u8 numSPS = data[pos++] & 0x1F;
71 for (fl::u8 i = 0; i < numSPS; i++) {
72 bool ok = true;
73 fl::u16 spsLen = readU16BE(data, pos, ok);
74 if (!ok) return false;
75 pos += 2;
76 if (pos + spsLen > boxEnd) return false;
77 fl::vector<fl::u8> sps(spsLen);
78 for (fl::u16 j = 0; j < spsLen; j++) {
79 sps[j] = data[pos + j];
80 }
81 info.sps.push_back(sps);
82 pos += spsLen;
83 }
84
85 if (pos >= boxEnd) return false;
86 fl::u8 numPPS = data[pos++];
87 for (fl::u8 i = 0; i < numPPS; i++) {
88 bool ok = true;
89 fl::u16 ppsLen = readU16BE(data, pos, ok);
90 if (!ok) return false;
91 pos += 2;
92 if (pos + ppsLen > boxEnd) return false;
93 fl::vector<fl::u8> pps(ppsLen);
94 for (fl::u16 j = 0; j < ppsLen; j++) {
95 pps[j] = data[pos + j];
96 }
97 info.pps.push_back(pps);
98 pos += ppsLen;
99 }
100
101 return true;
102}
103

Callers 1

parseMp4Function · 0.85

Calls 2

readU16BEFunction · 0.85
push_backMethod · 0.45

Tested by

no test coverage detected