Mercurial > libavcodec.hg
comparison mpegaudiodec.c @ 2432:d9cf90e66883 libavcodec
Decode MP3 in ADU format
author | rtognimp |
---|---|
date | Sat, 15 Jan 2005 14:59:47 +0000 |
parents | 87b7fbed8609 |
children | 1addaf6facbb |
comparison
equal
deleted
inserted
replaced
2431:d67740c88f86 | 2432:d9cf90e66883 |
---|---|
96 int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ | 96 int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ |
97 #ifdef DEBUG | 97 #ifdef DEBUG |
98 int frame_count; | 98 int frame_count; |
99 #endif | 99 #endif |
100 void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g); | 100 void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g); |
101 int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 | |
101 } MPADecodeContext; | 102 } MPADecodeContext; |
102 | 103 |
103 /* layer 3 "granule" */ | 104 /* layer 3 "granule" */ |
104 typedef struct GranuleDef { | 105 typedef struct GranuleDef { |
105 uint8_t scfsi; | 106 uint8_t scfsi; |
530 s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE]; | 531 s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE]; |
531 s->inbuf_ptr = s->inbuf; | 532 s->inbuf_ptr = s->inbuf; |
532 #ifdef DEBUG | 533 #ifdef DEBUG |
533 s->frame_count = 0; | 534 s->frame_count = 0; |
534 #endif | 535 #endif |
536 if (avctx->codec_id == CODEC_ID_MP3ADU) | |
537 s->adu_mode = 1; | |
535 return 0; | 538 return 0; |
536 } | 539 } |
537 | 540 |
538 /* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */ | 541 /* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */ |
539 | 542 |
2296 dprintf("block_type=%d switch_point=%d\n", | 2299 dprintf("block_type=%d switch_point=%d\n", |
2297 g->block_type, g->switch_point); | 2300 g->block_type, g->switch_point); |
2298 } | 2301 } |
2299 } | 2302 } |
2300 | 2303 |
2304 if (!s->adu_mode) { | |
2301 /* now we get bits from the main_data_begin offset */ | 2305 /* now we get bits from the main_data_begin offset */ |
2302 dprintf("seekback: %d\n", main_data_begin); | 2306 dprintf("seekback: %d\n", main_data_begin); |
2303 seek_to_maindata(s, main_data_begin); | 2307 seek_to_maindata(s, main_data_begin); |
2308 } | |
2304 | 2309 |
2305 for(gr=0;gr<nb_granules;gr++) { | 2310 for(gr=0;gr<nb_granules;gr++) { |
2306 for(ch=0;ch<s->nb_channels;ch++) { | 2311 for(ch=0;ch<s->nb_channels;ch++) { |
2307 g = &granules[ch][gr]; | 2312 g = &granules[ch][gr]; |
2308 | 2313 |
2667 } | 2672 } |
2668 } | 2673 } |
2669 return buf_ptr - buf; | 2674 return buf_ptr - buf; |
2670 } | 2675 } |
2671 | 2676 |
2677 | |
2678 static int decode_frame_adu(AVCodecContext * avctx, | |
2679 void *data, int *data_size, | |
2680 uint8_t * buf, int buf_size) | |
2681 { | |
2682 MPADecodeContext *s = avctx->priv_data; | |
2683 uint32_t header; | |
2684 int len, out_size; | |
2685 short *out_samples = data; | |
2686 | |
2687 len = buf_size; | |
2688 | |
2689 // Discard too short frames | |
2690 if (buf_size < HEADER_SIZE) { | |
2691 *data_size = 0; | |
2692 return buf_size; | |
2693 } | |
2694 | |
2695 | |
2696 if (len > MPA_MAX_CODED_FRAME_SIZE) | |
2697 len = MPA_MAX_CODED_FRAME_SIZE; | |
2698 | |
2699 memcpy(s->inbuf, buf, len); | |
2700 s->inbuf_ptr = s->inbuf + len; | |
2701 | |
2702 // Get header and restore sync word | |
2703 header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | | |
2704 (s->inbuf[2] << 8) | s->inbuf[3] | 0xffe00000; | |
2705 | |
2706 if (check_header(header) < 0) { // Bad header, discard frame | |
2707 *data_size = 0; | |
2708 return buf_size; | |
2709 } | |
2710 | |
2711 decode_header(s, header); | |
2712 /* update codec info */ | |
2713 avctx->sample_rate = s->sample_rate; | |
2714 avctx->channels = s->nb_channels; | |
2715 avctx->bit_rate = s->bit_rate; | |
2716 avctx->sub_id = s->layer; | |
2717 | |
2718 avctx->frame_size=s->frame_size = len; | |
2719 | |
2720 if (avctx->parse_only) { | |
2721 /* simply return the frame data */ | |
2722 *(uint8_t **)data = s->inbuf; | |
2723 out_size = s->inbuf_ptr - s->inbuf; | |
2724 } else { | |
2725 out_size = mp_decode_frame(s, out_samples); | |
2726 } | |
2727 | |
2728 *data_size = out_size; | |
2729 return buf_size; | |
2730 } | |
2731 | |
2732 | |
2672 AVCodec mp2_decoder = | 2733 AVCodec mp2_decoder = |
2673 { | 2734 { |
2674 "mp2", | 2735 "mp2", |
2675 CODEC_TYPE_AUDIO, | 2736 CODEC_TYPE_AUDIO, |
2676 CODEC_ID_MP2, | 2737 CODEC_ID_MP2, |
2692 NULL, | 2753 NULL, |
2693 NULL, | 2754 NULL, |
2694 decode_frame, | 2755 decode_frame, |
2695 CODEC_CAP_PARSE_ONLY, | 2756 CODEC_CAP_PARSE_ONLY, |
2696 }; | 2757 }; |
2758 | |
2759 AVCodec mp3adu_decoder = | |
2760 { | |
2761 "mp3adu", | |
2762 CODEC_TYPE_AUDIO, | |
2763 CODEC_ID_MP3ADU, | |
2764 sizeof(MPADecodeContext), | |
2765 decode_init, | |
2766 NULL, | |
2767 NULL, | |
2768 decode_frame_adu, | |
2769 CODEC_CAP_PARSE_ONLY, | |
2770 }; |