[FFmpeg-cvslog] libmp3lame: add 'reservoir' private option.

Anton Khirnov git at videolan.org
Thu Sep 1 00:03:06 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Aug 27 10:09:09 2011 +0200| [a7cec3a09407f7cf494d84549665d242ad31fc4e] | committer: Anton Khirnov

libmp3lame: add 'reservoir' private option.

Deprecate CODEC_FLAG2_BIT_RESERVOIR

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a7cec3a09407f7cf494d84549665d242ad31fc4e
---

 libavcodec/avcodec.h    |    2 ++
 libavcodec/libmp3lame.c |   23 ++++++++++++++++++++++-
 libavcodec/options.c    |    2 ++
 libavcodec/version.h    |    3 +++
 4 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index f8a8006..6422683 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -628,7 +628,9 @@ typedef struct RcOverride{
 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
 #define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer.
 #endif
+#if FF_API_LAME_GLOBAL_OPTS
 #define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible
+#endif
 #define CODEC_FLAG2_MBTREE        0x00040000 ///< Use macroblock tree ratecontrol (x264 only)
 #define CODEC_FLAG2_PSY           0x00080000 ///< Use psycho visual optimizations.
 #if FF_API_X264_GLOBAL_OPTS
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 2eeb97d..b46ce42 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -25,16 +25,20 @@
  */
 
 #include "libavutil/intreadwrite.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
 #include "avcodec.h"
 #include "mpegaudio.h"
 #include <lame/lame.h>
 
 #define BUFFER_SIZE (7200 + 2*MPA_FRAME_SIZE + MPA_FRAME_SIZE/4)
 typedef struct Mp3AudioContext {
+    AVClass *class;
     lame_global_flags *gfp;
     int stereo;
     uint8_t buffer[BUFFER_SIZE];
     int buffer_index;
+    int reservoir;
 } Mp3AudioContext;
 
 static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
@@ -64,7 +68,10 @@ static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
         lame_set_VBR_quality(s->gfp, avctx->global_quality/(float)FF_QP2LAMBDA);
     }
     lame_set_bWriteVbrTag(s->gfp,0);
-    lame_set_disable_reservoir(s->gfp, avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR ? 0 : 1);
+#if FF_API_LAME_GLOBAL_OPTIONS
+    s->reservoir = avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR;
+#endif
+    lame_set_disable_reservoir(s->gfp, !s->reservoir);
     if (lame_init_params(s->gfp) < 0)
         goto err_close;
 
@@ -213,6 +220,19 @@ static av_cold int MP3lame_encode_close(AVCodecContext *avctx)
     return 0;
 }
 
+#define OFFSET(x) offsetof(Mp3AudioContext, x)
+#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    { "reservoir",      "Use bit reservoir.",   OFFSET(reservoir),  FF_OPT_TYPE_INT, { 1 }, 0, 1, AE },
+    { NULL },
+};
+
+static const AVClass libmp3lame_class = {
+    .class_name = "libmp3lame encoder",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
 
 AVCodec ff_libmp3lame_encoder = {
     .name           = "libmp3lame",
@@ -226,4 +246,5 @@ AVCodec ff_libmp3lame_encoder = {
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
     .supported_samplerates= sSampleRates,
     .long_name= NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"),
+    .priv_class     = &libmp3lame_class,
 };
diff --git a/libavcodec/options.c b/libavcodec/options.c
index b991881..1344a89 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -431,7 +431,9 @@ static const AVOption options[]={
 #if FF_API_DRC_SCALE
 {"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0.0, 1.0, A|D},
 #endif
+#if FF_API_LAME_GLOBAL_OPTS
 {"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BIT_RESERVOIR }, INT_MIN, INT_MAX, A|E, "flags2"},
+#endif
 {"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_MBTREE }, INT_MIN, INT_MAX, V|E, "flags2"},
 {"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
 {"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, {.dbl = DEFAULT }, 0, INT64_MAX, A|E|D, "channel_layout"},
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 928513f..0de224b 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -89,5 +89,8 @@
 #ifndef FF_API_MPEGVIDEO_GLOBAL_OPTS
 #define FF_API_MPEGVIDEO_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
 #endif
+#ifndef FF_API_LAME_GLOBAL_OPTS
+#define FF_API_LAME_GLOBAL_OPTS  (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
 
 #endif /* AVCODEC_VERSION_H */



More information about the ffmpeg-cvslog mailing list