summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicodvb <nicodvb@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-05-07 14:50:14 +0000
committernicodvb <nicodvb@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-05-07 14:50:14 +0000
commit5bb432dbbe51cb1f046fb6bdf62203605f1ca795 (patch)
tree23c0709acf68e47f650d8fd7205258b7445e2096
parent08e479c3c65fb364974621721c16253e409e31e5 (diff)
downloadmpv-5bb432dbbe51cb1f046fb6bdf62203605f1ca795.tar.bz2
mpv-5bb432dbbe51cb1f046fb6bdf62203605f1ca795.tar.xz
added twolame mp2 audio encoder
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15360 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--Makefile4
-rw-r--r--cfg-mencoder.h19
-rwxr-xr-xconfigure26
-rw-r--r--libmpcodecs/Makefile4
-rw-r--r--libmpcodecs/ae.c9
-rw-r--r--libmpcodecs/ae.h1
-rw-r--r--libmpcodecs/ae_twolame.c217
-rw-r--r--libmpcodecs/ae_twolame.h14
-rw-r--r--mencoder.c1
9 files changed, 294 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 8086208d41..a5bc2b3b26 100644
--- a/Makefile
+++ b/Makefile
@@ -41,6 +41,10 @@ CFLAGS += $(TOOLAME_EXTRAFLAGS)
CODEC_LIBS += $(TOOLAME_LIB)
endif
+ifeq ($(TWOLAME),yes)
+CODEC_LIBS += $(TWOLAME_LIB)
+endif
+
ifeq ($(FAAC),yes)
CODEC_LIBS += $(FAAC_LIB)
endif
diff --git a/cfg-mencoder.h b/cfg-mencoder.h
index ae42066d71..998274496c 100644
--- a/cfg-mencoder.h
+++ b/cfg-mencoder.h
@@ -33,6 +33,10 @@ extern m_option_t lavcopts_conf[];
extern m_option_t toolameopts_conf[];
#endif
+#ifdef HAVE_TWOLAME
+extern m_option_t twolameopts_conf[];
+#endif
+
#ifdef HAVE_FAAC
extern m_option_t faacopts_conf[];
#endif
@@ -119,6 +123,11 @@ m_option_t oac_conf[]={
#else
{"toolame", "MPlayer was compiled without libtoolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif
+#ifdef HAVE_TWOLAME
+ {"twolame", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_TWOLAME, NULL},
+#else
+ {"twolame", "MPlayer was compiled without libtwolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
+#endif
#ifdef HAVE_FAAC
{"faac", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_FAAC, NULL},
#else
@@ -136,8 +145,11 @@ m_option_t oac_conf[]={
#ifdef HAVE_TOOLAME
" toolame - Toolame MP2 audio encoder\n"
#endif
+#ifdef HAVE_TWOLAME
+ " twolame - Twolame MP2 audio encoder\n"
+#endif
#ifdef HAVE_FAAC
- " faac - FAAC AAC audio encoder\n"
+ " faac - FAAC AAC audio encoder\n"
#endif
"\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
@@ -256,6 +268,11 @@ m_option_t mencoder_opts[]={
#else
{"toolameopts", "MPlayer was compiled without libtoolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif
+#ifdef HAVE_TWOLAME
+ {"twolameopts", twolameopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
+#else
+ {"twolameopts", "MPlayer was compiled without libtwolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
+#endif
#ifdef HAVE_FAAC
{"faacopts", faacopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#else
diff --git a/configure b/configure
index 97e4487859..b1dc66268b 100755
--- a/configure
+++ b/configure
@@ -222,6 +222,7 @@ Codecs:
--disable-libdv disable libdv 0.9.5 en/decoding support [autodetect]
--disable-mad disable libmad (MPEG audio) support [autodetect]
--disable-toolame disable Toolame (MPEG layer 2 audio) support in mencoder [autodetect]
+ --disable-twolame disable Twolame (MPEG layer 2 audio) support in mencoder [autodetect]
--enable-xmms build with XMMS inputplugin support [disabled]
--disable-mp3lib disable builtin mp3lib [enabled]
--disable-liba52 disable builtin liba52 [enabled]
@@ -1325,6 +1326,7 @@ _jack=auto
_liblzo=auto
_mad=auto
_toolame=auto
+_twolame=auto
_tremor_internal=yes
_tremor_low=no
_vorbis=auto
@@ -1510,6 +1512,7 @@ for ac_option do
--enable-mad) _mad=yes ;;
--disable-mad) _mad=no ;;
--disable-toolame) _toolame=no ;;
+ --disable-twolame) _twolame=no ;;
--enable-liblzo) _liblzo=yes ;;
--disable-liblzo) _liblzo=no ;;
--enable-vorbis) _vorbis=yes ;;
@@ -5184,6 +5187,26 @@ else
echores "$_toolame (using $_toolamedir)"
fi
+echocheck "Twolame"
+if test "$_twolame" = auto ; then
+ cat > $TMPC <<EOF
+#include <twolame.h>
+int main(void) { twolame_init(); return 0; }
+EOF
+ _twolame=no
+ _twolame_lib="-ltwolame"
+ cc_check $_twolame_lib $_ld_lm && _twolame=yes
+fi
+if test "$_twolame" = yes ; then
+ _def_twolame='#define HAVE_TWOLAME 1'
+ _codecmodules="$_codecmodules twolame"
+else
+ _def_toolame='#undef HAVE_TWOLAME'
+ _twolame_lib=""
+ _nocodecmodules="twolame $_nocodecmodules"
+fi
+echores "$_twolame"
+
echocheck "OggVorbis support"
if test "$_tremor_internal" = yes; then
_vorbis=yes
@@ -6899,6 +6922,8 @@ MACOSX_COREVIDEO = $_macosx_corevideo
TOOLAME=$_toolame
TOOLAME_EXTRAFLAGS=$_toolame_extraflags
TOOLAME_LIB=$_toolame_lib
+TWOLAME=$_twolame
+TWOLAME_LIB=$_twolame_lib
FAAC=$_faac
FAAC_LIB=$_ld_faac
AMR_NB=$_amr_nb
@@ -7551,6 +7576,7 @@ $_def_aa
$_def_caca
$_def_tga
$_def_toolame
+$_def_twolame
/* used by GUI: */
$_def_xshape
diff --git a/libmpcodecs/Makefile b/libmpcodecs/Makefile
index 061c15916d..c3ad12c6c9 100644
--- a/libmpcodecs/Makefile
+++ b/libmpcodecs/Makefile
@@ -44,6 +44,10 @@ ENCODER_SRCS += ae_toolame.c
EXTRA_INC += $(TOOLAME_EXTRAFLAGS)
endif
+ifeq ($(TWOLAME),yes)
+ENCODER_SRCS += ae_twolame.c
+endif
+
ifeq ($(CONFIG_MP3LAME),yes)
ENCODER_SRCS += ae_lame.c
endif
diff --git a/libmpcodecs/ae.c b/libmpcodecs/ae.c
index 2b1da10d04..af4a2bb751 100644
--- a/libmpcodecs/ae.c
+++ b/libmpcodecs/ae.c
@@ -27,6 +27,10 @@
#include "ae_faac.h"
#endif
+#ifdef HAVE_TWOLAME
+#include "ae_twolame.h"
+#endif
+
audio_encoder_t *new_audio_encoder(muxer_stream_t *stream, audio_encoding_params_t *params)
{
int ris;
@@ -63,6 +67,11 @@ audio_encoder_t *new_audio_encoder(muxer_stream_t *stream, audio_encoding_params
ris = mpae_init_faac(encoder);
break;
#endif
+#ifdef HAVE_TWOLAME
+ case ACODEC_TWOLAME:
+ ris = mpae_init_twolame(encoder);
+ break;
+#endif
}
if(! ris)
diff --git a/libmpcodecs/ae.h b/libmpcodecs/ae.h
index d1da14073d..316af9eb15 100644
--- a/libmpcodecs/ae.h
+++ b/libmpcodecs/ae.h
@@ -9,6 +9,7 @@
#define ACODEC_LAVC 4
#define ACODEC_TOOLAME 5
#define ACODEC_FAAC 6
+#define ACODEC_TWOLAME 7
#define AE_NEEDS_COMPRESSED_INPUT 1
diff --git a/libmpcodecs/ae_twolame.c b/libmpcodecs/ae_twolame.c
new file mode 100644
index 0000000000..b6f06c774a
--- /dev/null
+++ b/libmpcodecs/ae_twolame.c
@@ -0,0 +1,217 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include "m_option.h"
+#include "../mp_msg.h"
+#include "aviheader.h"
+#include "../libaf/af_format.h"
+#include "ms_hdr.h"
+#include "muxer.h"
+#include "ae_twolame.h"
+#include "../libmpdemux/mp3_hdr.h"
+
+
+static int
+ param_bitrate = 192,
+ param_psy = 3,
+ param_maxvbr = 0,
+ param_errprot = 0,
+ param_debug = 0;
+
+static float param_vbr = 0;
+static char *param_mode = "stereo";
+
+m_option_t twolameopts_conf[] = {
+ {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
+ {"mode", &param_mode, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
+ {"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, -50, 50, NULL},
+ {"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
+ {"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
+ {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
+ {NULL, NULL, 0, 0, 0, 0, NULL}
+};
+
+
+static int bind_twolame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
+{
+ mpae_twolame_ctx *ctx = (mpae_twolame_ctx *) encoder->priv;
+
+ mux_a->wf = malloc(sizeof(WAVEFORMATEX)+256);
+ mux_a->wf->wFormatTag = 0x50;
+ mux_a->wf->nChannels = encoder->params.channels;
+ mux_a->wf->nSamplesPerSec = encoder->params.sample_rate;
+ mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8;
+
+ if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec))
+ {
+ mux_a->h.dwScale = encoder->params.samples_per_frame;
+ mux_a->h.dwRate = encoder->params.sample_rate;
+ mux_a->h.dwSampleSize = 0; // Blocksize not constant
+ }
+ else
+ {
+ mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */
+ mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
+ mux_a->h.dwSampleSize = mux_a->h.dwScale;
+ }
+ mux_a->wf->nBlockAlign = mux_a->h.dwScale;
+ mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
+ mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
+
+ mux_a->wf->cbSize = 0; //12;
+ mux_a->wf->wBitsPerSample = 0; /* does not apply */
+ ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
+ ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
+ ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
+ ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
+ ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
+
+ // Fix allocation
+ mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
+
+ encoder->input_format = AF_FORMAT_S16_NE;
+ encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
+ encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
+
+ return 1;
+}
+
+static int encode_twolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
+{
+ mpae_twolame_ctx *ctx = (mpae_twolame_ctx *)encoder->priv;
+ int ret_size = 0, r2;
+
+ len /= (2*encoder->params.channels);
+ ret_size = twolame_encode_buffer_interleaved(ctx->twolame_ctx, src, len, dest, max_size);
+ r2 = mp_decode_mp3_header(dest);
+ mp_msg(MSGT_MENCODER, MSGL_V, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2);
+ if(r2 > 0)
+ ret_size = r2;
+ return ret_size;
+}
+
+int close_twolame(audio_encoder_t *encoder)
+{
+ free(encoder->priv);
+ return 1;
+}
+
+static int get_frame_size(audio_encoder_t *encoder)
+{
+ int sz;
+ if(encoder->stream->buffer_len < 4)
+ return 0;
+ sz = mp_decode_mp3_header(encoder->stream->buffer);
+ if(sz <= 0)
+ return 0;
+ return sz;
+}
+
+
+int mpae_init_twolame(audio_encoder_t *encoder)
+{
+ int mode;
+ mpae_twolame_ctx *ctx = NULL;
+
+ if(encoder->params.channels == 1)
+ {
+ mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_twolame, 1 audio channel, forcing mono mode\n");
+ mode = TWOLAME_MONO;
+ }
+ else if(encoder->params.channels == 2)
+ {
+ if(! strcasecmp(param_mode, "dual"))
+ mode = TWOLAME_DUAL_CHANNEL;
+ else if(! strcasecmp(param_mode, "jstereo"))
+ mode = TWOLAME_JOINT_STEREO;
+ else if(! strcasecmp(param_mode, "stereo"))
+ mode = TWOLAME_STEREO;
+ else
+ {
+ mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, unknown mode %s, exiting\n", param_mode);
+ }
+ }
+ else
+ mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, Twolame can't encode > 2 channels, exiting\n");
+
+ ctx = (mpae_twolame_ctx *) calloc(1, sizeof(mpae_twolame_ctx));
+ if(ctx == NULL)
+ {
+ mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_twolame_ctx));
+ return 0;
+ }
+
+ ctx->twolame_ctx = twolame_init();
+ if(ctx->twolame_ctx == NULL)
+ {
+ mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't initial parameters from libtwolame, exiting\n");
+ free(ctx);
+ return 0;
+ }
+ ctx->vbr = 0;
+
+ if(twolame_set_num_channels(ctx->twolame_ctx, encoder->params.channels) != 0)
+ return 0;
+ if(twolame_set_mode(ctx->twolame_ctx, mode) != 0)
+ return 0;
+
+ if(twolame_set_in_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0)
+ return 0;
+
+ if(twolame_set_out_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0)
+ return 0;
+
+ if(encoder->params.sample_rate < 32000)
+ twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG2);
+ else
+ twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG1);
+
+ if(twolame_set_psymodel(ctx->twolame_ctx, param_psy) != 0)
+ return 0;
+
+ if(twolame_set_bitrate(ctx->twolame_ctx, param_bitrate) != 0)
+ return 0;
+
+ if(param_errprot)
+ if(twolame_set_error_protection(ctx->twolame_ctx, TRUE) != 0)
+ return 0;
+
+ if(param_vbr != 0)
+ {
+ if(twolame_set_VBR(ctx->twolame_ctx, TRUE) != 0)
+ return 0;
+ if(twolame_set_VBR_q(ctx->twolame_ctx, param_vbr) != 0)
+ return 0;
+ if(twolame_set_padding(ctx->twolame_ctx, FALSE) != 0)
+ return 0;
+ if(param_maxvbr)
+ {
+ if(twolame_set_VBR_max_bitrate_kbps(ctx->twolame_ctx, param_maxvbr) != 0)
+ return 0;
+ }
+ ctx->vbr = 1;
+ }
+
+ if(twolame_set_verbosity(ctx->twolame_ctx, param_debug) != 0)
+ return 0;
+
+ if(twolame_init_params(ctx->twolame_ctx) != 0)
+ return 0;
+
+ encoder->params.bitrate = param_bitrate * 1000;
+ encoder->params.samples_per_frame = 1152;
+ encoder->priv = ctx;
+ encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;
+
+ encoder->bind = bind_twolame;
+ encoder->get_frame_size = get_frame_size;
+ encoder->encode = encode_twolame;
+ encoder->close = close_twolame;
+
+ return 1;
+}
+
diff --git a/libmpcodecs/ae_twolame.h b/libmpcodecs/ae_twolame.h
new file mode 100644
index 0000000000..65d3590f9b
--- /dev/null
+++ b/libmpcodecs/ae_twolame.h
@@ -0,0 +1,14 @@
+#ifndef MPAE_TWOLAME_H
+#define MPAE_TWOLAME_H
+
+#include "ae.h"
+#include <twolame.h>
+
+typedef struct {
+ twolame_options *twolame_ctx;
+ int vbr;
+} mpae_twolame_ctx;
+
+int mpae_init_twolame(audio_encoder_t *encoder);
+
+#endif
diff --git a/mencoder.c b/mencoder.c
index 83875247fb..e6398e4f0d 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -18,6 +18,7 @@
#define ACODEC_LAVC 4
#define ACODEC_TOOLAME 5
#define ACODEC_FAAC 6
+#define ACODEC_TWOLAME 7
#include <stdio.h>
#include <stdlib.h>