73 if (*ptr >= end || val > INT_MAX - 254)
101 pkt->
code = (i ) & 0x3;
102 pkt->
stereo = (i >> 2) & 0x1;
103 pkt->
config = (i >> 3) & 0x1F;
106 if (pkt->
code >= 2 && buf_size < 2)
115 if (self_delimiting) {
117 if (len < 0 || len > end - ptr)
120 buf_size = end -
buf;
123 frame_bytes = end - ptr;
134 if (self_delimiting) {
136 if (len < 0 || 2 * len > end - ptr)
139 buf_size = end -
buf;
142 frame_bytes = end - ptr;
160 if (self_delimiting) {
162 if (len < 0 || len + frame_bytes > end - ptr)
164 end = ptr + frame_bytes +
len;
165 buf_size = end -
buf;
182 padding = (i >> 6) & 0x01;
183 pkt->
vbr = (i >> 7) & 0x01;
205 total_bytes += frame_bytes;
208 if (self_delimiting) {
210 if (len < 0 || len + total_bytes + padding > end - ptr)
212 end = ptr + total_bytes + len + padding;
213 buf_size = end -
buf;
216 frame_bytes = end - ptr - padding;
217 if (total_bytes > frame_bytes)
226 if (self_delimiting) {
228 if (frame_bytes < 0 || pkt->frame_count * frame_bytes + padding > end - ptr)
230 end = ptr + pkt->
frame_count * frame_bytes + padding;
231 buf_size = end -
buf;
233 frame_bytes = end - ptr - padding;
261 }
else if (pkt->
config < 16) {
275 memset(pkt, 0,
sizeof(*pkt));
292 static const uint8_t default_channel_map[2] = { 0, 1 };
298 int version, channels, map_type, streams, stereo_streams, i, j;
304 "Multichannel configuration without extradata.\n");
314 if (extradata_size < 19) {
320 version = extradata[8];
338 map_type = extradata[18];
342 "Channel mapping 0 is only specified for up to 2 channels\n");
347 stereo_streams = channels - 1;
348 channel_map = default_channel_map;
349 }
else if (map_type == 1 || map_type == 255) {
350 if (extradata_size < 21 + channels) {
356 streams = extradata[19];
357 stereo_streams = extradata[20];
358 if (!streams || stereo_streams > streams ||
359 streams + stereo_streams > 255) {
361 "Invalid stream/stereo stream count: %d/%d\n", streams, stereo_streams);
368 "Channel mapping 1 is only specified for up to 8 channels\n");
376 channel_map = extradata + 21;
386 for (i = 0; i < channels; i++) {
388 uint8_t idx = channel_map[channel_reorder(channels, i)];
393 }
else if (idx >= streams + stereo_streams) {
395 "Invalid channel map for output channel %d: %d\n", i, idx);
401 for (j = 0; j < i; j++)
402 if (channel_map[channel_reorder(channels, j)] == idx) {
408 if (idx < 2 * stereo_streams) {