[FFmpeg-devel] [PATCH] lavc: add fixed point mp2 encoder
Paul B Mahol
onemda at gmail.com
Mon Jul 30 17:02:20 CEST 2012
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavcodec/Makefile | 4 +++-
libavcodec/allcodecs.c | 2 +-
libavcodec/mpegaudioenc.c | 10 +++++++---
libavcodec/mpegaudioenc_fixed.c | 39 +++++++++++++++++++++++++++++++++++++++
4 files changed, 50 insertions(+), 5 deletions(-)
create mode 100644 libavcodec/mpegaudioenc_fixed.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b4138e8..250033a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -273,10 +273,12 @@ OBJS-$(CONFIG_MP1FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodecheade
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP2_DECODER) += mpegaudiodec.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
-OBJS-$(CONFIG_MP2_ENCODER) += mpegaudioenc.o mpegaudio.o \
+OBJS-$(CONFIG_MP2_ENCODER) += mpegaudioenc_fixed.o mpegaudioenc.o mpegaudio.o \
mpegaudiodata.o
OBJS-$(CONFIG_MP2FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
+OBJS-$(CONFIG_MP2FLOAT_ENCODER) += mpegaudioenc.o mpegaudio.o \
+ mpegaudiodata.o
OBJS-$(CONFIG_MP3ADU_DECODER) += mpegaudiodec.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP3ADUFLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodecheader.o \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 6bcc3c2..4226569 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -300,7 +300,7 @@ void avcodec_register_all(void)
REGISTER_DECODER (MP1, mp1);
REGISTER_DECODER (MP1FLOAT, mp1float);
REGISTER_ENCDEC (MP2, mp2);
- REGISTER_DECODER (MP2FLOAT, mp2float);
+ REGISTER_ENCDEC (MP2FLOAT, mp2float);
REGISTER_DECODER (MP3, mp3);
REGISTER_DECODER (MP3FLOAT, mp3float);
REGISTER_DECODER (MP3ADU, mp3adu);
diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c
index ea9e55a..d1bc816 100644
--- a/libavcodec/mpegaudioenc.c
+++ b/libavcodec/mpegaudioenc.c
@@ -58,8 +58,10 @@ typedef struct MpegAudioContext {
const unsigned char *alloc_table;
} MpegAudioContext;
+#ifndef USE_FLOATS
/* define it to use floats in quantization (I don't like floats !) */
-#define USE_FLOATS
+#define USE_FLOATS 1
+#endif
#include "mpegaudiodata.h"
#include "mpegaudiotab.h"
@@ -779,8 +781,9 @@ static const AVCodecDefault mp2_defaults[] = {
{ NULL },
};
-AVCodec ff_mp2_encoder = {
- .name = "mp2",
+#if USE_FLOATS
+AVCodec ff_mp2float_encoder = {
+ .name = "mp2float",
.type = AVMEDIA_TYPE_AUDIO,
.id = CODEC_ID_MP2,
.priv_data_size = sizeof(MpegAudioContext),
@@ -795,3 +798,4 @@ AVCodec ff_mp2_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
.defaults = mp2_defaults,
};
+#endif
diff --git a/libavcodec/mpegaudioenc_fixed.c b/libavcodec/mpegaudioenc_fixed.c
new file mode 100644
index 0000000..fdcaa78
--- /dev/null
+++ b/libavcodec/mpegaudioenc_fixed.c
@@ -0,0 +1,39 @@
+/*
+ * Fixed point MPEG Audio layer 2 encoder
+ *
+ * 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
+ */
+
+#define USE_FLOATS 0
+#include "mpegaudioenc.c"
+
+AVCodec ff_mp2_encoder = {
+ .name = "mp2",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_MP2,
+ .priv_data_size = sizeof(MpegAudioContext),
+ .init = MPA_encode_init,
+ .encode2 = MPA_encode_frame,
+ .close = MPA_encode_close,
+ .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
+ AV_SAMPLE_FMT_NONE },
+ .supported_samplerates = (const int[]){
+ 44100, 48000, 32000, 22050, 24000, 16000, 0
+ },
+ .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
+ .defaults = mp2_defaults,
+};
--
1.7.7
More information about the ffmpeg-devel
mailing list