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

Function mad_layer_III

modules/data/mp3/libmad/layer3.c:2605–2770  ·  view source on GitHub ↗

NAME: layer->III() DESCRIPTION: decode a single Layer III frame */

Source from the content-addressed store, hash-verified

2603 DESCRIPTION: decode a single Layer III frame
2604*/
2605int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame)
2606{
2607 struct mad_header *header = &frame->header;
2608 unsigned int nch, priv_bitlen, next_md_begin = 0;
2609 unsigned int si_len, data_bitlen, md_len;
2610 unsigned int frame_space, frame_used, frame_free;
2611 struct mad_bitptr ptr;
2612 struct sideinfo si;
2613 enum mad_error error;
2614 int result = 0;
2615 stack(__FUNCTION__, __FILE__, __LINE__);
2616
2617 nch = MAD_NCHANNELS(header);
2618 si_len = (header->flags & MAD_FLAG_LSF_EXT) ?
2619 (nch == 1 ? 9 : 17) : (nch == 1 ? 17 : 32);
2620
2621 /* check frame sanity */
2622
2623 if (stream->next_frame - mad_bit_nextbyte(&stream->ptr) <
2624 (signed int) si_len) {
2625 stream->error = MAD_ERROR_BADFRAMELEN;
2626 stream->md_len = 0;
2627 return -1;
2628 }
2629
2630 /* check CRC word */
2631
2632 if (header->flags & MAD_FLAG_PROTECTION) {
2633 header->crc_check =
2634 mad_bit_crc(stream->ptr, si_len * CHAR_BIT, header->crc_check);
2635
2636 if (header->crc_check != header->crc_target &&
2637 !(frame->options & MAD_OPTION_IGNORECRC)) {
2638 stream->error = MAD_ERROR_BADCRC;
2639 result = -1;
2640 }
2641 }
2642
2643 /* decode frame side information */
2644
2645 error = III_sideinfo(&stream->ptr, nch, header->flags & MAD_FLAG_LSF_EXT,
2646 &si, &data_bitlen, &priv_bitlen);
2647 if (error && result == 0) {
2648 stream->error = error;
2649 result = -1;
2650 }
2651
2652 header->flags |= priv_bitlen;
2653 header->private_bits |= si.private_bits;
2654
2655 /* find main_data of next frame */
2656
2657 {
2658 struct mad_bitptr peek;
2659 unsigned long header;
2660
2661 mad_bit_init(&peek, stream->next_frame);
2662

Callers

nothing calls this directly

Calls 8

mad_bit_nextbyteFunction · 0.85
mad_bit_crcFunction · 0.85
III_sideinfoFunction · 0.85
mad_bit_initFunction · 0.85
mad_bit_readFunction · 0.85
mad_bit_skipFunction · 0.85
III_decodeFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected