Originally committed as revision 9080 to svn://svn.ffmpeg.org/ffmpeg/trunktags/v0.5
| @@ -726,6 +726,7 @@ dv1394_demuxer_deps="dv1394" | |||||
| gxf_muxer_deps="gpl" | gxf_muxer_deps="gpl" | ||||
| libnut_demuxer_deps="libnut" | libnut_demuxer_deps="libnut" | ||||
| libnut_muxer_deps="libnut" | libnut_muxer_deps="libnut" | ||||
| mp3_demuxer_deps="mpegaudio_parser" | |||||
| ogg_muxer_deps="libogg" | ogg_muxer_deps="libogg" | ||||
| redir_demuxer_deps="network" | redir_demuxer_deps="network" | ||||
| rtp_muxer_deps="network mpegts_demuxer" | rtp_muxer_deps="network mpegts_demuxer" | ||||
| @@ -19,7 +19,7 @@ OBJS= bitstream.o \ | |||||
| motion_est.o \ | motion_est.o \ | ||||
| imgconvert.o \ | imgconvert.o \ | ||||
| mpeg12.o \ | mpeg12.o \ | ||||
| mpegaudiodec.o mpegaudiodata.o \ | |||||
| mpegaudiodec.o mpegaudiodecheader.o mpegaudiodata.o \ | |||||
| simple_idct.o \ | simple_idct.o \ | ||||
| ratecontrol.o \ | ratecontrol.o \ | ||||
| eval.o \ | eval.o \ | ||||
| @@ -300,7 +300,7 @@ OBJS-$(CONFIG_H263_PARSER) += h263_parser.o | |||||
| OBJS-$(CONFIG_H264_PARSER) += h264_parser.o | OBJS-$(CONFIG_H264_PARSER) += h264_parser.o | ||||
| OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o | OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o | ||||
| OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o | OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o | ||||
| OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o | |||||
| OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o mpegaudiodecheader.o | |||||
| OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o | OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o | ||||
| OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o | OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o | ||||
| OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o | OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o | ||||
| @@ -23,6 +23,12 @@ | |||||
| * mpeg audio declarations for both encoder and decoder. | * mpeg audio declarations for both encoder and decoder. | ||||
| */ | */ | ||||
| #ifndef MPEGAUDIO_H | |||||
| #define MPEGAUDIO_H | |||||
| #include "bitstream.h" | |||||
| #include "dsputil.h" | |||||
| /* max frame size, in samples */ | /* max frame size, in samples */ | ||||
| #define MPA_FRAME_SIZE 1152 | #define MPA_FRAME_SIZE 1152 | ||||
| @@ -73,6 +79,42 @@ typedef int16_t MPA_INT; | |||||
| typedef int32_t MPA_INT; | typedef int32_t MPA_INT; | ||||
| #endif | #endif | ||||
| #define BACKSTEP_SIZE 512 | |||||
| #define EXTRABYTES 24 | |||||
| struct GranuleDef; | |||||
| typedef struct MPADecodeContext { | |||||
| DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]); | |||||
| int last_buf_size; | |||||
| int frame_size; | |||||
| /* next header (used in free format parsing) */ | |||||
| uint32_t free_format_next_header; | |||||
| int error_protection; | |||||
| int layer; | |||||
| int sample_rate; | |||||
| int sample_rate_index; /* between 0 and 8 */ | |||||
| int bit_rate; | |||||
| GetBitContext gb; | |||||
| GetBitContext in_gb; | |||||
| int nb_channels; | |||||
| int mode; | |||||
| int mode_ext; | |||||
| int lsf; | |||||
| DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]); | |||||
| int synth_buf_offset[MPA_MAX_CHANNELS]; | |||||
| DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]); | |||||
| int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ | |||||
| #ifdef DEBUG | |||||
| int frame_count; | |||||
| #endif | |||||
| void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g); | |||||
| int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 | |||||
| int dither_state; | |||||
| int error_resilience; | |||||
| AVCodecContext* avctx; | |||||
| } MPADecodeContext; | |||||
| int l2_select_table(int bitrate, int nb_channels, int freq, int lsf); | int l2_select_table(int bitrate, int nb_channels, int freq, int lsf); | ||||
| int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate); | int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate); | ||||
| void ff_mpa_synth_init(MPA_INT *window); | void ff_mpa_synth_init(MPA_INT *window); | ||||
| @@ -97,3 +139,5 @@ static inline int ff_mpa_check_header(uint32_t header){ | |||||
| return -1; | return -1; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| #endif /* MPEGAUDIO_H */ | |||||
| @@ -22,6 +22,7 @@ | |||||
| #include "parser.h" | #include "parser.h" | ||||
| #include "mpegaudio.h" | #include "mpegaudio.h" | ||||
| #include "mpegaudiodecheader.h" | |||||
| typedef struct MpegAudioParseContext { | typedef struct MpegAudioParseContext { | ||||
| @@ -41,6 +42,43 @@ typedef struct MpegAudioParseContext { | |||||
| #define SAME_HEADER_MASK \ | #define SAME_HEADER_MASK \ | ||||
| (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19)) | (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19)) | ||||
| /* useful helper to get mpeg audio stream infos. Return -1 if error in | |||||
| header, otherwise the coded frame size in bytes */ | |||||
| int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate) | |||||
| { | |||||
| MPADecodeContext s1, *s = &s1; | |||||
| s1.avctx = avctx; | |||||
| if (ff_mpa_check_header(head) != 0) | |||||
| return -1; | |||||
| if (decode_header(s, head) != 0) { | |||||
| return -1; | |||||
| } | |||||
| switch(s->layer) { | |||||
| case 1: | |||||
| avctx->frame_size = 384; | |||||
| break; | |||||
| case 2: | |||||
| avctx->frame_size = 1152; | |||||
| break; | |||||
| default: | |||||
| case 3: | |||||
| if (s->lsf) | |||||
| avctx->frame_size = 576; | |||||
| else | |||||
| avctx->frame_size = 1152; | |||||
| break; | |||||
| } | |||||
| *sample_rate = s->sample_rate; | |||||
| avctx->channels = s->nb_channels; | |||||
| avctx->bit_rate = s->bit_rate; | |||||
| avctx->sub_id = s->layer; | |||||
| return s->frame_size; | |||||
| } | |||||
| static int mpegaudio_parse_init(AVCodecParserContext *s1) | static int mpegaudio_parse_init(AVCodecParserContext *s1) | ||||
| { | { | ||||
| MpegAudioParseContext *s = s1->priv_data; | MpegAudioParseContext *s = s1->priv_data; | ||||
| @@ -42,6 +42,7 @@ | |||||
| #endif | #endif | ||||
| #include "mpegaudio.h" | #include "mpegaudio.h" | ||||
| #include "mpegaudiodecheader.h" | |||||
| #include "mathops.h" | #include "mathops.h" | ||||
| @@ -57,41 +58,6 @@ | |||||
| /****************/ | /****************/ | ||||
| #define HEADER_SIZE 4 | #define HEADER_SIZE 4 | ||||
| #define BACKSTEP_SIZE 512 | |||||
| #define EXTRABYTES 24 | |||||
| struct GranuleDef; | |||||
| typedef struct MPADecodeContext { | |||||
| DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]); | |||||
| int last_buf_size; | |||||
| int frame_size; | |||||
| /* next header (used in free format parsing) */ | |||||
| uint32_t free_format_next_header; | |||||
| int error_protection; | |||||
| int layer; | |||||
| int sample_rate; | |||||
| int sample_rate_index; /* between 0 and 8 */ | |||||
| int bit_rate; | |||||
| GetBitContext gb; | |||||
| GetBitContext in_gb; | |||||
| int nb_channels; | |||||
| int mode; | |||||
| int mode_ext; | |||||
| int lsf; | |||||
| DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]); | |||||
| int synth_buf_offset[MPA_MAX_CHANNELS]; | |||||
| DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]); | |||||
| int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ | |||||
| #ifdef DEBUG | |||||
| int frame_count; | |||||
| #endif | |||||
| void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g); | |||||
| int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 | |||||
| int dither_state; | |||||
| int error_resilience; | |||||
| AVCodecContext* avctx; | |||||
| } MPADecodeContext; | |||||
| /** | /** | ||||
| * Context for MP3On4 decoder | * Context for MP3On4 decoder | ||||
| @@ -1107,124 +1073,6 @@ static void imdct36(int *out, int *buf, int *in, int *win) | |||||
| buf[8 - 4] = MULH(t0, win[18 + 8 - 4]); | buf[8 - 4] = MULH(t0, win[18 + 8 - 4]); | ||||
| } | } | ||||
| /* header decoding. MUST check the header before because no | |||||
| consistency check is done there. Return 1 if free format found and | |||||
| that the frame size must be computed externally */ | |||||
| static int decode_header(MPADecodeContext *s, uint32_t header) | |||||
| { | |||||
| int sample_rate, frame_size, mpeg25, padding; | |||||
| int sample_rate_index, bitrate_index; | |||||
| if (header & (1<<20)) { | |||||
| s->lsf = (header & (1<<19)) ? 0 : 1; | |||||
| mpeg25 = 0; | |||||
| } else { | |||||
| s->lsf = 1; | |||||
| mpeg25 = 1; | |||||
| } | |||||
| s->layer = 4 - ((header >> 17) & 3); | |||||
| /* extract frequency */ | |||||
| sample_rate_index = (header >> 10) & 3; | |||||
| sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); | |||||
| sample_rate_index += 3 * (s->lsf + mpeg25); | |||||
| s->sample_rate_index = sample_rate_index; | |||||
| s->error_protection = ((header >> 16) & 1) ^ 1; | |||||
| s->sample_rate = sample_rate; | |||||
| bitrate_index = (header >> 12) & 0xf; | |||||
| padding = (header >> 9) & 1; | |||||
| //extension = (header >> 8) & 1; | |||||
| s->mode = (header >> 6) & 3; | |||||
| s->mode_ext = (header >> 4) & 3; | |||||
| //copyright = (header >> 3) & 1; | |||||
| //original = (header >> 2) & 1; | |||||
| //emphasis = header & 3; | |||||
| if (s->mode == MPA_MONO) | |||||
| s->nb_channels = 1; | |||||
| else | |||||
| s->nb_channels = 2; | |||||
| if (bitrate_index != 0) { | |||||
| frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; | |||||
| s->bit_rate = frame_size * 1000; | |||||
| switch(s->layer) { | |||||
| case 1: | |||||
| frame_size = (frame_size * 12000) / sample_rate; | |||||
| frame_size = (frame_size + padding) * 4; | |||||
| break; | |||||
| case 2: | |||||
| frame_size = (frame_size * 144000) / sample_rate; | |||||
| frame_size += padding; | |||||
| break; | |||||
| default: | |||||
| case 3: | |||||
| frame_size = (frame_size * 144000) / (sample_rate << s->lsf); | |||||
| frame_size += padding; | |||||
| break; | |||||
| } | |||||
| s->frame_size = frame_size; | |||||
| } else { | |||||
| /* if no frame size computed, signal it */ | |||||
| return 1; | |||||
| } | |||||
| #if defined(DEBUG) | |||||
| dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ", | |||||
| s->layer, s->sample_rate, s->bit_rate); | |||||
| if (s->nb_channels == 2) { | |||||
| if (s->layer == 3) { | |||||
| if (s->mode_ext & MODE_EXT_MS_STEREO) | |||||
| dprintf(s->avctx, "ms-"); | |||||
| if (s->mode_ext & MODE_EXT_I_STEREO) | |||||
| dprintf(s->avctx, "i-"); | |||||
| } | |||||
| dprintf(s->avctx, "stereo"); | |||||
| } else { | |||||
| dprintf(s->avctx, "mono"); | |||||
| } | |||||
| dprintf(s->avctx, "\n"); | |||||
| #endif | |||||
| return 0; | |||||
| } | |||||
| /* useful helper to get mpeg audio stream infos. Return -1 if error in | |||||
| header, otherwise the coded frame size in bytes */ | |||||
| int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate) | |||||
| { | |||||
| MPADecodeContext s1, *s = &s1; | |||||
| s1.avctx = avctx; | |||||
| if (ff_mpa_check_header(head) != 0) | |||||
| return -1; | |||||
| if (decode_header(s, head) != 0) { | |||||
| return -1; | |||||
| } | |||||
| switch(s->layer) { | |||||
| case 1: | |||||
| avctx->frame_size = 384; | |||||
| break; | |||||
| case 2: | |||||
| avctx->frame_size = 1152; | |||||
| break; | |||||
| default: | |||||
| case 3: | |||||
| if (s->lsf) | |||||
| avctx->frame_size = 576; | |||||
| else | |||||
| avctx->frame_size = 1152; | |||||
| break; | |||||
| } | |||||
| *sample_rate = s->sample_rate; | |||||
| avctx->channels = s->nb_channels; | |||||
| avctx->bit_rate = s->bit_rate; | |||||
| avctx->sub_id = s->layer; | |||||
| return s->frame_size; | |||||
| } | |||||
| /* return the number of decoded frames */ | /* return the number of decoded frames */ | ||||
| static int mp_decode_layer1(MPADecodeContext *s) | static int mp_decode_layer1(MPADecodeContext *s) | ||||
| { | { | ||||
| @@ -0,0 +1,109 @@ | |||||
| /* | |||||
| * MPEG Audio header decoder | |||||
| * Copyright (c) 2001, 2002 Fabrice Bellard. | |||||
| * | |||||
| * This file is part of FFmpeg. | |||||
| * | |||||
| * FFmpeg is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU Lesser General Public | |||||
| * License as published by the Free Software Foundation; either | |||||
| * version 2.1 of the License, or (at your option) any later version. | |||||
| * | |||||
| * FFmpeg is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
| * Lesser General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU Lesser General Public | |||||
| * License along with FFmpeg; if not, write to the Free Software | |||||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||||
| */ | |||||
| /** | |||||
| * @file mpegaudiodecheader.c | |||||
| * MPEG Audio header decoder. | |||||
| */ | |||||
| //#define DEBUG | |||||
| #include "avcodec.h" | |||||
| #include "mpegaudio.h" | |||||
| #include "mpegaudiodata.h" | |||||
| int decode_header(MPADecodeContext *s, uint32_t header) | |||||
| { | |||||
| int sample_rate, frame_size, mpeg25, padding; | |||||
| int sample_rate_index, bitrate_index; | |||||
| if (header & (1<<20)) { | |||||
| s->lsf = (header & (1<<19)) ? 0 : 1; | |||||
| mpeg25 = 0; | |||||
| } else { | |||||
| s->lsf = 1; | |||||
| mpeg25 = 1; | |||||
| } | |||||
| s->layer = 4 - ((header >> 17) & 3); | |||||
| /* extract frequency */ | |||||
| sample_rate_index = (header >> 10) & 3; | |||||
| sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); | |||||
| sample_rate_index += 3 * (s->lsf + mpeg25); | |||||
| s->sample_rate_index = sample_rate_index; | |||||
| s->error_protection = ((header >> 16) & 1) ^ 1; | |||||
| s->sample_rate = sample_rate; | |||||
| bitrate_index = (header >> 12) & 0xf; | |||||
| padding = (header >> 9) & 1; | |||||
| //extension = (header >> 8) & 1; | |||||
| s->mode = (header >> 6) & 3; | |||||
| s->mode_ext = (header >> 4) & 3; | |||||
| //copyright = (header >> 3) & 1; | |||||
| //original = (header >> 2) & 1; | |||||
| //emphasis = header & 3; | |||||
| if (s->mode == MPA_MONO) | |||||
| s->nb_channels = 1; | |||||
| else | |||||
| s->nb_channels = 2; | |||||
| if (bitrate_index != 0) { | |||||
| frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; | |||||
| s->bit_rate = frame_size * 1000; | |||||
| switch(s->layer) { | |||||
| case 1: | |||||
| frame_size = (frame_size * 12000) / sample_rate; | |||||
| frame_size = (frame_size + padding) * 4; | |||||
| break; | |||||
| case 2: | |||||
| frame_size = (frame_size * 144000) / sample_rate; | |||||
| frame_size += padding; | |||||
| break; | |||||
| default: | |||||
| case 3: | |||||
| frame_size = (frame_size * 144000) / (sample_rate << s->lsf); | |||||
| frame_size += padding; | |||||
| break; | |||||
| } | |||||
| s->frame_size = frame_size; | |||||
| } else { | |||||
| /* if no frame size computed, signal it */ | |||||
| return 1; | |||||
| } | |||||
| #if defined(DEBUG) | |||||
| dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ", | |||||
| s->layer, s->sample_rate, s->bit_rate); | |||||
| if (s->nb_channels == 2) { | |||||
| if (s->layer == 3) { | |||||
| if (s->mode_ext & MODE_EXT_MS_STEREO) | |||||
| dprintf(s->avctx, "ms-"); | |||||
| if (s->mode_ext & MODE_EXT_I_STEREO) | |||||
| dprintf(s->avctx, "i-"); | |||||
| } | |||||
| dprintf(s->avctx, "stereo"); | |||||
| } else { | |||||
| dprintf(s->avctx, "mono"); | |||||
| } | |||||
| dprintf(s->avctx, "\n"); | |||||
| #endif | |||||
| return 0; | |||||
| } | |||||
| @@ -0,0 +1,39 @@ | |||||
| /* | |||||
| * MPEG Audio header decoder | |||||
| * Copyright (c) 2001, 2002 Fabrice Bellard. | |||||
| * | |||||
| * This file is part of FFmpeg. | |||||
| * | |||||
| * FFmpeg is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU Lesser General Public | |||||
| * License as published by the Free Software Foundation; either | |||||
| * version 2.1 of the License, or (at your option) any later version. | |||||
| * | |||||
| * FFmpeg is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
| * Lesser General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU Lesser General Public | |||||
| * License along with FFmpeg; if not, write to the Free Software | |||||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||||
| */ | |||||
| /** | |||||
| * @file mpegaudiodecheader.c | |||||
| * MPEG Audio header decoder. | |||||
| */ | |||||
| #ifndef MPEGAUDIODECHEADER_H | |||||
| #define MPEGAUDIODECHEADER_H | |||||
| #include "common.h" | |||||
| #include "mpegaudio.h" | |||||
| /* header decoding. MUST check the header before because no | |||||
| consistency check is done there. Return 1 if free format found and | |||||
| that the frame size must be computed externally */ | |||||
| int decode_header(MPADecodeContext *s, uint32_t header); | |||||
| #endif /* MPEGAUDIODECHEADER_H */ | |||||