MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / mad_header_decode

Function mad_header_decode

modules/data/mp3/libmad/frame.c:296–428  ·  view source on GitHub ↗

* NAME: header->decode() * DESCRIPTION: read the next frame header from the stream */

Source from the content-addressed store, hash-verified

294 * DESCRIPTION: read the next frame header from the stream
295 */
296int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
297{
298 register unsigned char const *ptr, *end;
299 unsigned int pad_slot, N;
300
301 ptr = stream->next_frame;
302 end = stream->bufend;
303
304 if (ptr == 0) {
305 stream->error = MAD_ERROR_BUFPTR;
306 goto fail;
307 }
308
309 /* stream skip */
310 if (stream->skiplen) {
311 if (!stream->sync)
312 ptr = stream->this_frame;
313
314 if ((unsigned int)(end - ptr) < stream->skiplen) {
315 stream->skiplen -= end - ptr;
316 stream->next_frame = end;
317
318 stream->error = MAD_ERROR_BUFLEN;
319 goto fail;
320 }
321
322 ptr += stream->skiplen;
323 stream->skiplen = 0;
324
325 stream->sync = 1;
326 }
327
328 sync:
329 /* synchronize */
330 if (stream->sync) {
331 if (end - ptr < MAD_BUFFER_GUARD) {
332 stream->next_frame = ptr;
333
334 stream->error = MAD_ERROR_BUFLEN;
335 goto fail;
336 }
337 else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
338 /* mark point where frame sync word was expected */
339 stream->this_frame = ptr;
340 stream->next_frame = ptr + 1;
341
342 stream->error = MAD_ERROR_LOSTSYNC;
343 goto fail;
344 }
345 }
346 else {
347 mad_bit_init(&stream->ptr, ptr);
348
349 if (mad_stream_sync(stream) == -1) {
350 if (end - stream->next_frame >= MAD_BUFFER_GUARD)
351 stream->next_frame = end - MAD_BUFFER_GUARD;
352
353 stream->error = MAD_ERROR_BUFLEN;

Callers 2

mad_frame_decodeFunction · 0.85
run_syncFunction · 0.85

Calls 6

mad_bit_initFunction · 0.85
mad_stream_syncFunction · 0.85
mad_bit_nextbyteFunction · 0.85
decode_headerFunction · 0.85
mad_timer_setFunction · 0.85
free_bitrateFunction · 0.85

Tested by

no test coverage detected