gxf_muxer_deps="gpl"
libnut_demuxer_deps="libnut"
libnut_muxer_deps="libnut"
+mp3_demuxer_deps="mpegaudio_parser"
ogg_muxer_deps="libogg"
redir_demuxer_deps="network"
rtp_muxer_deps="network mpegts_demuxer"
motion_est.o \
imgconvert.o \
mpeg12.o \
- mpegaudiodec.o mpegaudiodata.o \
+ mpegaudiodec.o mpegaudiodecheader.o mpegaudiodata.o \
simple_idct.o \
ratecontrol.o \
eval.o \
OBJS-$(CONFIG_H264_PARSER) += h264_parser.o
OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_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_PNM_PARSER) += pnm_parser.o pnm.o
OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o
* 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 */
#define MPA_FRAME_SIZE 1152
typedef int32_t MPA_INT;
#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 mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
void ff_mpa_synth_init(MPA_INT *window);
return -1;
return 0;
}
+
+#endif /* MPEGAUDIO_H */
#include "parser.h"
#include "mpegaudio.h"
+#include "mpegaudiodecheader.h"
typedef struct MpegAudioParseContext {
#define SAME_HEADER_MASK \
(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)
{
MpegAudioParseContext *s = s1->priv_data;
#endif
#include "mpegaudio.h"
+#include "mpegaudiodecheader.h"
#include "mathops.h"
/****************/
#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
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 */
static int mp_decode_layer1(MPADecodeContext *s)
{
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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 */