ext/lame/gstlame.*: Get the defaults settings of LAME in the plugin initialization function and return FALSE here if ...

Original commit message from CVS:
* ext/lame/gstlame.c: (gst_lame_class_init), (gst_lame_init),
(gst_lame_chain), (gst_lame_get_default_settings), (plugin_init):
* ext/lame/gstlame.h:
Get the defaults settings of LAME in the plugin initialization
function and return FALSE here if something goes wrong. This removes
the hacky failing instance init function.
Use LAMEs default value for all settings instead of overwriting some
of them. Overwriting some of them gives unexpected results if one only
sets a preset. Fixes bug #498004.
This commit is contained in:
Sebastian Dröge 2008-07-29 16:57:16 +00:00
parent 82c528d3ca
commit 252e387a89
2 changed files with 193 additions and 129 deletions

View file

@ -67,6 +67,10 @@
* Last reviewed on 2007-07-24 (0.10.7) * Last reviewed on 2007-07-24 (0.10.7)
*/ */
/* FIXME 0.11: Remove all properties except the useful ones. Nobody knows what most
* properties are doing and they're intended for LAME developers only.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -82,10 +86,6 @@
GST_DEBUG_CATEGORY_STATIC (debug); GST_DEBUG_CATEGORY_STATIC (debug);
#define GST_CAT_DEFAULT debug #define GST_CAT_DEFAULT debug
#define DEFAULT_MIN_VBR_BITRATE 112
#define DEFAULT_MAX_VBR_BITRATE 160
#define DEFAULT_MEAN_VBR_BITRATE 128
/* elementfactory information */ /* elementfactory information */
static GstElementDetails gst_lame_details = { static GstElementDetails gst_lame_details = {
"L.A.M.E. mp3 encoder", "L.A.M.E. mp3 encoder",
@ -120,6 +120,41 @@ GST_STATIC_PAD_TEMPLATE ("src",
"channels = (int) [ 1, 2 ]") "channels = (int) [ 1, 2 ]")
); );
static struct
{
gint bitrate;
gfloat compression_ratio;
gint quality;
gint mode;
gboolean force_ms;
gboolean free_format;
gboolean copyright;
gboolean original;
gboolean error_protection;
gboolean extension;
gboolean strict_iso;
gboolean disable_reservoir;
gint vbr;
gint vbr_quality;
gint vbr_mean_bitrate;
gint vbr_min_bitrate;
gint vbr_max_bitrate;
gint vbr_hard_min;
gint lowpass_freq;
gint lowpass_width;
gint highpass_freq;
gint highpass_width;
gboolean ath_only;
gboolean ath_short;
gboolean no_ath;
gint ath_type;
gint ath_lower;
gboolean allow_diff_short;
gboolean no_short_blocks;
gboolean emphasis;
gint preset;
} gst_lame_default_settings;
/********** Define useful types for non-programmatic interfaces **********/ /********** Define useful types for non-programmatic interfaces **********/
#define GST_TYPE_LAME_MODE (gst_lame_mode_get_type()) #define GST_TYPE_LAME_MODE (gst_lame_mode_get_type())
static GType static GType
@ -370,42 +405,46 @@ gst_lame_class_init (GstLameClass * klass)
g_param_spec_int ("bitrate", "Bitrate (kb/s)", g_param_spec_int ("bitrate", "Bitrate (kb/s)",
"Bitrate in kbit/sec (8, 16, 24, 32, 40, 48, 56, 64, 80, 96, " "Bitrate in kbit/sec (8, 16, 24, 32, 40, 48, 56, 64, 80, 96, "
"112, 128, 160, 192, 224, 256 or 320)", "112, 128, 160, 192, 224, 256 or 320)",
8, 320, 128, G_PARAM_READWRITE)); 8, 320, gst_lame_default_settings.bitrate, G_PARAM_READWRITE));
/* compression ratio set to 0.0 by default otherwise it overrides the bitrate setting */ /* compression ratio set to 0.0 by default otherwise it overrides the bitrate setting */
g_object_class_install_property (G_OBJECT_CLASS (klass), g_object_class_install_property (G_OBJECT_CLASS (klass),
ARG_COMPRESSION_RATIO, g_param_spec_float ("compression_ratio", ARG_COMPRESSION_RATIO, g_param_spec_float ("compression_ratio",
"Compression Ratio", "Compression Ratio",
"let lame choose bitrate to achieve selected compression ratio", 0.0, "let lame choose bitrate to achieve selected compression ratio", 0.0,
200.0, 0.0, G_PARAM_READWRITE)); 200.0, gst_lame_default_settings.compression_ratio,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
g_param_spec_enum ("quality", "Quality", g_param_spec_enum ("quality", "Quality",
"Quality of algorithm used for encoding", GST_TYPE_LAME_QUALITY, 5, "Quality of algorithm used for encoding", GST_TYPE_LAME_QUALITY,
G_PARAM_READWRITE)); gst_lame_default_settings.quality, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MODE, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MODE,
g_param_spec_enum ("mode", "Mode", "Encoding mode", GST_TYPE_LAME_MODE, 0, g_param_spec_enum ("mode", "Mode", "Encoding mode", GST_TYPE_LAME_MODE,
G_PARAM_READWRITE)); gst_lame_default_settings.mode, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FORCE_MS, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FORCE_MS,
g_param_spec_boolean ("force-ms", "Force ms", g_param_spec_boolean ("force-ms", "Force ms",
"Force ms_stereo on all frames", TRUE, G_PARAM_READWRITE)); "Force ms_stereo on all frames", gst_lame_default_settings.force_ms,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FREE_FORMAT, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FREE_FORMAT,
g_param_spec_boolean ("free-format", "Free format", g_param_spec_boolean ("free-format", "Free format",
"Produce a free format bitstream", TRUE, G_PARAM_READWRITE)); "Produce a free format bitstream",
gst_lame_default_settings.free_format, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_COPYRIGHT, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_COPYRIGHT,
g_param_spec_boolean ("copyright", "Copyright", "Mark as copyright", TRUE, g_param_spec_boolean ("copyright", "Copyright", "Mark as copyright",
G_PARAM_READWRITE)); gst_lame_default_settings.copyright, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ORIGINAL, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ORIGINAL,
g_param_spec_boolean ("original", "Original", "Mark as non-original", g_param_spec_boolean ("original", "Original", "Mark as original",
TRUE, G_PARAM_READWRITE)); gst_lame_default_settings.original, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ERROR_PROTECTION, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ERROR_PROTECTION,
g_param_spec_boolean ("error-protection", "Error protection", g_param_spec_boolean ("error-protection", "Error protection",
"Adds 16 bit checksum to every frame", TRUE, G_PARAM_READWRITE)); "Adds 16 bit checksum to every frame",
gst_lame_default_settings.error_protection, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PADDING_TYPE, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PADDING_TYPE,
g_param_spec_enum ("padding-type", "Padding type", "Padding type " g_param_spec_enum ("padding-type", "Padding type",
"(DEPRECATED: this setting has no effect)", "Padding type " "(DEPRECATED: this setting has no effect)",
GST_TYPE_LAME_PADDING, 0, G_PARAM_READWRITE)); GST_TYPE_LAME_PADDING, FALSE, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXTENSION, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXTENSION,
g_param_spec_boolean ("extension", "Extension", "Extension", TRUE, g_param_spec_boolean ("extension", "Extension", "Extension",
G_PARAM_READWRITE)); gst_lame_default_settings.extension, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STRICT_ISO, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STRICT_ISO,
g_param_spec_boolean ("strict-iso", "Strict ISO", g_param_spec_boolean ("strict-iso", "Strict ISO",
"Comply as much as possible to ISO MPEG spec", TRUE, "Comply as much as possible to ISO MPEG spec", TRUE,
@ -416,57 +455,63 @@ gst_lame_class_init (GstLameClass * klass)
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR,
g_param_spec_enum ("vbr", "VBR", "Specify bitrate mode", g_param_spec_enum ("vbr", "VBR", "Specify bitrate mode",
GST_TYPE_LAME_VBRMODE, vbr_off, G_PARAM_READWRITE)); GST_TYPE_LAME_VBRMODE, gst_lame_default_settings.vbr,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_QUALITY, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_QUALITY,
g_param_spec_enum ("vbr-quality", "VBR Quality", "VBR Quality", g_param_spec_enum ("vbr-quality", "VBR Quality", "VBR Quality",
GST_TYPE_LAME_QUALITY, 5, G_PARAM_READWRITE)); GST_TYPE_LAME_QUALITY, gst_lame_default_settings.vbr_quality,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MEAN_BITRATE, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MEAN_BITRATE,
g_param_spec_int ("vbr-mean-bitrate", "VBR mean bitrate", g_param_spec_int ("vbr-mean-bitrate", "VBR mean bitrate",
"Specify mean VBR bitrate", 8, 320, "Specify mean VBR bitrate", 0, 320,
DEFAULT_MEAN_VBR_BITRATE, G_PARAM_READWRITE)); gst_lame_default_settings.vbr_mean_bitrate, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MIN_BITRATE, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MIN_BITRATE,
g_param_spec_int ("vbr-min-bitrate", "VBR min bitrate", g_param_spec_int ("vbr-min-bitrate", "VBR min bitrate",
"Specify minimum VBR bitrate (8, 16, 24, 32, 40, 48, 56, 64, 80, 96, " "Specify minimum VBR bitrate (8, 16, 24, 32, 40, 48, 56, 64, 80, 96, "
"112, 128, 160, 192, 224, 256 or 320)", "112, 128, 160, 192, 224, 256 or 320)", 0, 320,
8, 320, DEFAULT_MIN_VBR_BITRATE, G_PARAM_READWRITE)); gst_lame_default_settings.vbr_min_bitrate, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MAX_BITRATE, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MAX_BITRATE,
g_param_spec_int ("vbr-max-bitrate", "VBR max bitrate", g_param_spec_int ("vbr-max-bitrate", "VBR max bitrate",
"Specify maximum VBR bitrate (8, 16, 24, 32, 40, 48, 56, 64, 80, 96, " "Specify maximum VBR bitrate (8, 16, 24, 32, 40, 48, 56, 64, 80, 96, "
"112, 128, 160, 192, 224, 256 or 320)", "112, 128, 160, 192, 224, 256 or 320)", 0, 320,
8, 320, DEFAULT_MAX_VBR_BITRATE, G_PARAM_READWRITE)); gst_lame_default_settings.vbr_max_bitrate, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_HARD_MIN, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_HARD_MIN,
g_param_spec_int ("vbr-hard-min", "VBR hard min", g_param_spec_int ("vbr-hard-min", "VBR hard min",
"Specify whether min VBR bitrate is a hard limit. Normally, " "Specify whether min VBR bitrate is a hard limit. Normally, "
"it can be violated for silence", 0, 1, 0, G_PARAM_READWRITE)); "it can be violated for silence", 0, 1,
gst_lame_default_settings.vbr_hard_min, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWPASS_FREQ, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWPASS_FREQ,
g_param_spec_int ("lowpass-freq", "Lowpass freq", g_param_spec_int ("lowpass-freq", "Lowpass freq",
"frequency(kHz), lowpass filter cutoff above freq", 0, 50000, 0, "frequency(kHz), lowpass filter cutoff above freq", 0, 50000,
G_PARAM_READWRITE)); gst_lame_default_settings.lowpass_freq, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWPASS_WIDTH, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWPASS_WIDTH,
g_param_spec_int ("lowpass-width", "Lowpass width", g_param_spec_int ("lowpass-width", "Lowpass width",
"frequency(kHz) - default 15% of lowpass freq", 0, G_MAXINT, 0, "frequency(kHz) - default 15% of lowpass freq", -1, G_MAXINT,
G_PARAM_READWRITE)); gst_lame_default_settings.lowpass_width, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HIGHPASS_FREQ, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HIGHPASS_FREQ,
g_param_spec_int ("highpass-freq", "Highpass freq", g_param_spec_int ("highpass-freq", "Highpass freq",
"frequency(kHz), highpass filter cutoff below freq", 0, 50000, 0, "frequency(kHz), highpass filter cutoff below freq", 0, 50000,
G_PARAM_READWRITE)); gst_lame_default_settings.highpass_freq, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HIGHPASS_WIDTH, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HIGHPASS_WIDTH,
g_param_spec_int ("highpass-width", "Highpass width", g_param_spec_int ("highpass-width", "Highpass width",
"frequency(kHz) - default 15% of highpass freq", 0, G_MAXINT, 0, "frequency(kHz) - default 15% of highpass freq", -1, G_MAXINT,
G_PARAM_READWRITE)); gst_lame_default_settings.highpass_width, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_ONLY, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_ONLY,
g_param_spec_boolean ("ath-only", "ATH only", g_param_spec_boolean ("ath-only", "ATH only",
"Ignore GPSYCHO completely, use ATH only", TRUE, G_PARAM_READWRITE)); "Ignore GPSYCHO completely, use ATH only",
gst_lame_default_settings.ath_only, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_SHORT, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_SHORT,
g_param_spec_boolean ("ath-short", "ATH short", g_param_spec_boolean ("ath-short", "ATH short",
"Ignore GPSYCHO for short blocks, use ATH only", TRUE, "Ignore GPSYCHO for short blocks, use ATH only",
G_PARAM_READWRITE)); gst_lame_default_settings.ath_short, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NO_ATH, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NO_ATH,
g_param_spec_boolean ("no-ath", "No ath", g_param_spec_boolean ("no-ath", "No ath",
"turns ATH down to a flat noise floor", TRUE, G_PARAM_READWRITE)); "turns ATH down to a flat noise floor",
gst_lame_default_settings.no_ath, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_LOWER, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_LOWER,
g_param_spec_int ("ath-lower", "ATH lower", "lowers ATH by x dB", g_param_spec_int ("ath-lower", "ATH lower", "lowers ATH by x dB",
G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); G_MININT, G_MAXINT, gst_lame_default_settings.ath_lower,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CWLIMIT, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CWLIMIT,
g_param_spec_int ("cwlimit", "Cwlimit", g_param_spec_int ("cwlimit", "Cwlimit",
"Compute tonality up to freq (in kHz) default 8.8717 " "Compute tonality up to freq (in kHz) default 8.8717 "
@ -474,21 +519,24 @@ gst_lame_class_init (GstLameClass * klass)
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ALLOW_DIFF_SHORT, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ALLOW_DIFF_SHORT,
g_param_spec_boolean ("allow-diff-short", "Allow diff short", g_param_spec_boolean ("allow-diff-short", "Allow diff short",
"Allow diff short", TRUE, G_PARAM_READWRITE)); "Allow diff short", gst_lame_default_settings.allow_diff_short,
G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NO_SHORT_BLOCKS, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NO_SHORT_BLOCKS,
g_param_spec_boolean ("no-short-blocks", "No short blocks", g_param_spec_boolean ("no-short-blocks", "No short blocks",
"Do not use short blocks", TRUE, G_PARAM_READWRITE)); "Do not use short blocks", gst_lame_default_settings.no_short_blocks,
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EMPHASIS,
g_param_spec_boolean ("emphasis", "Emphasis", "Emphasis", TRUE,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EMPHASIS,
g_param_spec_boolean ("emphasis", "Emphasis", "Emphasis",
gst_lame_default_settings.emphasis, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_XINGHEADER, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_XINGHEADER,
g_param_spec_boolean ("xingheader", "Output Xing Header", g_param_spec_boolean ("xingheader", "Output Xing Header",
"Output Xing Header (BROKEN, use xingmux instead)", "Output Xing Header (BROKEN, use xingmux instead)", FALSE,
FALSE, G_PARAM_READWRITE)); G_PARAM_READWRITE));
#ifdef GSTLAME_PRESET #ifdef GSTLAME_PRESET
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PRESET, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PRESET,
g_param_spec_enum ("preset", "Lame Preset", "Lame Preset", g_param_spec_enum ("preset", "Lame Preset", "Lame Preset",
GST_TYPE_LAME_PRESET, 0, G_PARAM_READWRITE)); GST_TYPE_LAME_PRESET, gst_lame_default_settings.preset,
G_PARAM_READWRITE));
#endif #endif
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_lame_change_state); gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_lame_change_state);
@ -599,79 +647,44 @@ gst_lame_init (GstLame * lame)
GST_DEBUG_FUNCPTR (gst_lame_src_setcaps)); GST_DEBUG_FUNCPTR (gst_lame_src_setcaps));
gst_element_add_pad (GST_ELEMENT (lame), lame->srcpad); gst_element_add_pad (GST_ELEMENT (lame), lame->srcpad);
/* create an encoder state so we can ask about defaults */
lame->lgf = lame_init ();
if (lame->lgf == NULL)
goto init_error;
if (lame_init_params (lame->lgf) < 0)
goto init_error;
lame->samplerate = 44100; lame->samplerate = 44100;
lame->num_channels = 2; lame->num_channels = 2;
lame->setup = FALSE; lame->setup = FALSE;
lame->bitrate = 128; /* lame_get_brate (lame->lgf); /* Set default settings */
* => 0/out of range */ lame->bitrate = gst_lame_default_settings.bitrate;
lame->compression_ratio = 0.0; /* lame_get_compression_ratio (lame->lgf); lame->compression_ratio = gst_lame_default_settings.compression_ratio;
* => 0/out of range ... lame->quality = gst_lame_default_settings.quality;
* NOTE: 0.0 makes bitrate take precedence */ lame->mode = gst_lame_default_settings.mode;
lame->quality = 5; /* lame_get_quality (lame->lgf);
* => -1/out of range */
lame->mode = lame_get_mode (lame->lgf);
lame->requested_mode = lame->mode; lame->requested_mode = lame->mode;
lame->force_ms = lame_get_force_ms (lame->lgf); lame->force_ms = gst_lame_default_settings.force_ms;
lame->free_format = lame_get_free_format (lame->lgf); lame->free_format = gst_lame_default_settings.free_format;
lame->copyright = lame_get_copyright (lame->lgf); lame->copyright = gst_lame_default_settings.copyright;
lame->original = lame_get_original (lame->lgf); lame->original = gst_lame_default_settings.original;
lame->error_protection = lame_get_error_protection (lame->lgf); lame->error_protection = gst_lame_default_settings.error_protection;
lame->extension = lame_get_extension (lame->lgf); lame->extension = gst_lame_default_settings.extension;
lame->strict_iso = lame_get_strict_ISO (lame->lgf); lame->strict_iso = gst_lame_default_settings.strict_iso;
lame->disable_reservoir = lame_get_disable_reservoir (lame->lgf); lame->disable_reservoir = gst_lame_default_settings.disable_reservoir;
lame->vbr = vbr_off; /* lame_get_VBR (lame->lgf); */ lame->vbr = gst_lame_default_settings.vbr;
lame->vbr_quality = 5; lame->vbr_quality = gst_lame_default_settings.vbr_quality;
lame->vbr_mean_bitrate = gst_lame_default_settings.vbr_mean_bitrate;
/* Replaced by our own more informative constants, lame->vbr_min_bitrate = gst_lame_default_settings.vbr_min_bitrate;
rather than LAME's defaults */ lame->vbr_max_bitrate = gst_lame_default_settings.vbr_max_bitrate;
lame->vbr_mean_bitrate = lame_get_VBR_mean_bitrate_kbps (lame->lgf); lame->vbr_hard_min = gst_lame_default_settings.vbr_hard_min;
lame->vbr_min_bitrate = lame_get_VBR_min_bitrate_kbps (lame->lgf); lame->lowpass_freq = gst_lame_default_settings.lowpass_freq;
lame->vbr_max_bitrate = lame_get_VBR_max_bitrate_kbps (lame->lgf); lame->lowpass_width = gst_lame_default_settings.lowpass_width;
/* => 0/no vbr possible */ lame->highpass_freq = gst_lame_default_settings.highpass_freq;
lame->vbr_hard_min = lame_get_VBR_hard_min (lame->lgf); lame->highpass_width = gst_lame_default_settings.highpass_width;
/* lame->lowpass_freq = 50000; lame_get_lowpassfreq (lame->lgf); lame->ath_only = gst_lame_default_settings.ath_only;
* => 0/lowpass on everything ? */ lame->ath_short = gst_lame_default_settings.ath_short;
lame->lowpass_freq = 0; lame->no_ath = gst_lame_default_settings.no_ath;
lame->lowpass_width = 0; /* lame_get_lowpasswidth (lame->lgf); lame->ath_lower = gst_lame_default_settings.ath_lower;
* => -1/out of range */ lame->allow_diff_short = gst_lame_default_settings.allow_diff_short;
lame->highpass_freq = lame_get_highpassfreq (lame->lgf); lame->no_short_blocks = gst_lame_default_settings.no_short_blocks;
lame->highpass_width = 0; /* lame_get_highpasswidth (lame->lgf); lame->emphasis = gst_lame_default_settings.emphasis;
* => -1/out of range */ lame->preset = gst_lame_default_settings.preset;
lame->ath_only = lame_get_ATHonly (lame->lgf);
lame->ath_short = lame_get_ATHshort (lame->lgf);
lame->no_ath = lame_get_noATH (lame->lgf);
/* lame->ath_type = lame_get_ATHtype (lame->lgf); */
lame->ath_lower = lame_get_ATHlower (lame->lgf);
lame->allow_diff_short = lame_get_allow_diff_short (lame->lgf);
lame->no_short_blocks = TRUE; /* lame_get_no_short_blocks (lame->lgf); */
lame->emphasis = lame_get_emphasis (lame->lgf);
lame->preset = 0;
lame_close (lame->lgf);
lame->lgf = NULL;
GST_DEBUG_OBJECT (lame, "done initializing"); GST_DEBUG_OBJECT (lame, "done initializing");
lame->init_error = FALSE;
return;
/* ERRORS */
init_error:
{
GST_ERROR_OBJECT (lame, "error initializing");
lame->init_error = TRUE;
if (lame->lgf) {
lame_close (lame->lgf);
lame->lgf = NULL;
}
}
} }
/* <php-emulation-mode>three underscores for ___rate is really really really /* <php-emulation-mode>three underscores for ___rate is really really really
@ -685,7 +698,9 @@ G_STMT_START { \
gint maxrate = 320; \ gint maxrate = 320; \
gint multiplier = 64; \ gint multiplier = 64; \
if (!free_format) { \ if (!free_format) { \
if (rate <= 64) { \ if (rate == 0) { \
___rate = rate; \
} else if (rate <= 64) { \
maxrate = 64; multiplier = 8; \ maxrate = 64; multiplier = 8; \
if ((rate % 8) != 0) ___rate = GST_ROUND_UP_8 (rate); \ if ((rate % 8) != 0) ___rate = GST_ROUND_UP_8 (rate); \
} else if (rate <= 128) { \ } else if (rate <= 128) { \
@ -1034,9 +1049,6 @@ gst_lame_chain (GstPad * pad, GstBuffer * buf)
GST_LOG_OBJECT (lame, "entered chain"); GST_LOG_OBJECT (lame, "entered chain");
if (lame->init_error)
goto init_error;
if (!lame->setup) if (!lame->setup)
goto not_setup; goto not_setup;
@ -1126,12 +1138,6 @@ not_setup:
("encoder not initialized (input is not audio?)")); ("encoder not initialized (input is not audio?)"));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
init_error:
{
gst_buffer_unref (buf);
GST_ELEMENT_ERROR (lame, LIBRARY, INIT, (NULL), (NULL));
return GST_FLOW_ERROR;
}
} }
/* set up the encoder state */ /* set up the encoder state */
@ -1289,11 +1295,71 @@ gst_lame_change_state (GstElement * element, GstStateChange transition)
return result; return result;
} }
static gboolean
gst_lame_get_default_settings (void)
{
lame_global_flags *lgf = NULL;
lgf = lame_init ();
if (lgf == NULL) {
GST_ERROR ("Error initializing LAME");
return FALSE;
}
if (lame_init_params (lgf) < 0) {
GST_ERROR ("Error getting default settings");
return FALSE;
}
gst_lame_default_settings.bitrate = lame_get_brate (lgf);
gst_lame_default_settings.compression_ratio = 0.0; /* lame_get_compression_ratio (lgf); */
gst_lame_default_settings.quality = lame_get_quality (lgf);
gst_lame_default_settings.mode = lame_get_mode (lgf);
gst_lame_default_settings.force_ms = lame_get_force_ms (lgf);
gst_lame_default_settings.free_format = lame_get_free_format (lgf);
gst_lame_default_settings.copyright = lame_get_copyright (lgf);
gst_lame_default_settings.original = lame_get_original (lgf);
gst_lame_default_settings.error_protection = lame_get_error_protection (lgf);
gst_lame_default_settings.extension = lame_get_extension (lgf);
gst_lame_default_settings.strict_iso = FALSE; /* lame_get_strict_ISO (lgf); */
gst_lame_default_settings.disable_reservoir =
lame_get_disable_reservoir (lgf);
gst_lame_default_settings.vbr = lame_get_VBR (lgf);
gst_lame_default_settings.vbr_quality = lame_get_VBR_q (lgf);
gst_lame_default_settings.vbr_mean_bitrate =
lame_get_VBR_mean_bitrate_kbps (lgf);
gst_lame_default_settings.vbr_min_bitrate =
lame_get_VBR_min_bitrate_kbps (lgf);
gst_lame_default_settings.vbr_max_bitrate =
lame_get_VBR_max_bitrate_kbps (lgf);
gst_lame_default_settings.vbr_hard_min = lame_get_VBR_hard_min (lgf);
gst_lame_default_settings.lowpass_freq = lame_get_lowpassfreq (lgf);
gst_lame_default_settings.lowpass_width = lame_get_lowpasswidth (lgf);
gst_lame_default_settings.highpass_freq = lame_get_highpassfreq (lgf);
gst_lame_default_settings.highpass_width = lame_get_highpasswidth (lgf);
gst_lame_default_settings.ath_only = lame_get_ATHonly (lgf);
gst_lame_default_settings.ath_short = lame_get_ATHshort (lgf);
gst_lame_default_settings.no_ath = lame_get_noATH (lgf);
gst_lame_default_settings.ath_type = lame_get_ATHtype (lgf);
gst_lame_default_settings.ath_lower = lame_get_ATHlower (lgf);
gst_lame_default_settings.allow_diff_short = lame_get_allow_diff_short (lgf);
gst_lame_default_settings.no_short_blocks = lame_get_no_short_blocks (lgf);
gst_lame_default_settings.emphasis = lame_get_emphasis (lgf);
gst_lame_default_settings.preset = 0;
lame_close (lgf);
return TRUE;
}
static gboolean static gboolean
plugin_init (GstPlugin * plugin) plugin_init (GstPlugin * plugin)
{ {
GST_DEBUG_CATEGORY_INIT (debug, "lame", 0, "lame mp3 encoder"); GST_DEBUG_CATEGORY_INIT (debug, "lame", 0, "lame mp3 encoder");
if (!gst_lame_get_default_settings ())
return FALSE;
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE, GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
LOCALEDIR); LOCALEDIR);

View file

@ -53,8 +53,6 @@ struct _GstLame {
/*< private >*/ /*< private >*/
GstPad *srcpad, *sinkpad; GstPad *srcpad, *sinkpad;
gboolean init_error; /* an error occured in the instance init function */
gint samplerate; gint samplerate;
gint num_channels; gint num_channels;
gboolean setup; gboolean setup;