Commit e8c55964 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵 Committed by Tim-Philipp Müller
Browse files

ext/wavpack/: Some small clean-ups: use enums instead of hard-coded numbers,...

ext/wavpack/: Some small clean-ups: use enums instead of hard-coded numbers, const-ify element details, re-factor som...

Original commit message from CVS:
Patch by: Sebastian Dröge  <slomo@circular-chaos.org>
* ext/wavpack/gstwavpackdec.c: (gst_wavpack_dec_reset),
(gst_wavpack_dec_init), (gst_wavpack_dec_change_state):
* ext/wavpack/gstwavpackenc.c: (gst_wavpack_enc_base_init),
(gst_wavpack_enc_class_init), (gst_wavpack_enc_reset),
(gst_wavpack_enc_init), (gst_wavpack_enc_set_wp_config),
(gst_wavpack_enc_change_state):
* ext/wavpack/gstwavpackparse.c:
Some small clean-ups: use enums instead of hard-coded numbers,
const-ify element details, re-factor some code into _reset()
functions (#352605).
parent 5c446dc4
......@@ -25,7 +25,7 @@
* SECTION:element-wavpackdec
*
* <refsect2>
* wavpackdec decodes framed (for example by the wavpackparse element)
* WavpackDec decodes framed (for example by the WavpackParse element)
* Wavpack streams and decodes them to raw audio.
* <ulink url="http://www.wavpack.com/">Wavpack</ulink> is an open-source
* audio codec that features both lossless and lossy encoding.
......@@ -115,6 +115,22 @@ gst_wavpack_dec_class_init (GstWavpackDecClass * klass)
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wavpack_dec_finalize);
}
static void
gst_wavpack_dec_reset (GstWavpackDec * dec)
{
dec->wv_id.buffer = NULL;
dec->wv_id.position = dec->wv_id.length = 0;
dec->error_count = 0;
dec->channels = 0;
dec->sample_rate = 0;
dec->width = 0;
dec->depth = 0;
gst_segment_init (&dec->segment, GST_FORMAT_UNDEFINED);
}
static void
gst_wavpack_dec_init (GstWavpackDec * dec, GstWavpackDecClass * gklass)
{
......@@ -132,17 +148,7 @@ gst_wavpack_dec_init (GstWavpackDec * dec, GstWavpackDecClass * gklass)
dec->context = NULL;
dec->stream_reader = gst_wavpack_stream_reader_new ();
dec->wv_id.buffer = NULL;
dec->wv_id.position = dec->wv_id.length = 0;
dec->error_count = 0;
dec->channels = 0;
dec->sample_rate = 0;
dec->width = 0;
dec->depth = 0;
gst_segment_init (&dec->segment, GST_FORMAT_UNDEFINED);
gst_wavpack_dec_reset (dec);
}
static void
......@@ -453,7 +459,6 @@ gst_wavpack_dec_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_NULL_TO_READY:
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
gst_segment_init (&dec->segment, GST_FORMAT_UNDEFINED);
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
......@@ -471,13 +476,8 @@ gst_wavpack_dec_change_state (GstElement * element, GstStateChange transition)
WavpackCloseFile (dec->context);
dec->context = NULL;
}
dec->wv_id.buffer = NULL;
dec->wv_id.position = 0;
dec->wv_id.length = 0;
dec->channels = 0;
dec->sample_rate = 0;
dec->width = 0;
dec->depth = 0;
gst_wavpack_dec_reset (dec);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
break;
......
......@@ -23,7 +23,7 @@
* SECTION:element-wavpackenc
*
* <refsect2>
* Wavpackenc encodes raw audio into a framed Wavpack stream.
* WavpackEnc encodes raw audio into a framed Wavpack stream.
* <ulink url="http://www.wavpack.com/">Wavpack</ulink> is an open-source
* audio codec that features both lossless and lossy encoding.
* <title>Example launch line</title>
......@@ -148,7 +148,15 @@ static GstStaticPadTemplate wvcsrc_factory = GST_STATIC_PAD_TEMPLATE ("wvcsrc",
GST_STATIC_CAPS ("audio/x-wavpack-correction, " "framed = (boolean) TRUE")
);
#define DEFAULT_MODE 2
enum
{
GST_WAVPACK_ENC_MODE_VERY_FAST = 0,
GST_WAVPACK_ENC_MODE_FAST,
GST_WAVPACK_ENC_MODE_DEFAULT,
GST_WAVPACK_ENC_MODE_HIGH,
GST_WAVPACK_ENC_MODE_VERY_HIGH
};
#define GST_TYPE_WAVPACK_ENC_MODE (gst_wavpack_enc_mode_get_type ())
static GType
gst_wavpack_enc_mode_get_type (void)
......@@ -176,7 +184,13 @@ gst_wavpack_enc_mode_get_type (void)
return qtype;
}
#define DEFAULT_CORRECTION_MODE 0
enum
{
GST_WAVPACK_CORRECTION_MODE_OFF = 0,
GST_WAVPACK_CORRECTION_MODE_ON,
GST_WAVPACK_CORRECTION_MODE_OPTIMIZED
};
#define GST_TYPE_WAVPACK_ENC_CORRECTION_MODE (gst_wavpack_enc_correction_mode_get_type ())
static GType
gst_wavpack_enc_correction_mode_get_type (void)
......@@ -196,7 +210,13 @@ gst_wavpack_enc_correction_mode_get_type (void)
return qtype;
}
#define DEFAULT_JS_MODE 0
enum
{
GST_WAVPACK_JS_MODE_AUTO = 0,
GST_WAVPACK_JS_MODE_LEFT_RIGHT,
GST_WAVPACK_JS_MODE_MID_SIDE
};
#define GST_TYPE_WAVPACK_ENC_JOINT_STEREO_MODE (gst_wavpack_enc_joint_stereo_mode_get_type ())
static GType
gst_wavpack_enc_joint_stereo_mode_get_type (void)
......@@ -221,7 +241,7 @@ GST_BOILERPLATE (GstWavpackEnc, gst_wavpack_enc, GstElement, GST_TYPE_ELEMENT);
static void
gst_wavpack_enc_base_init (gpointer klass)
{
static GstElementDetails element_details = {
static const GstElementDetails element_details = {
"Wavpack audio encoder",
"Codec/Encoder/Audio",
"Encodes audio with the Wavpack lossless/lossy audio codec",
......@@ -265,7 +285,8 @@ gst_wavpack_enc_class_init (GstWavpackEncClass * klass)
g_object_class_install_property (gobject_class, ARG_MODE,
g_param_spec_enum ("mode", "Encoding mode",
"Speed versus compression tradeoff.",
GST_TYPE_WAVPACK_ENC_MODE, DEFAULT_MODE, G_PARAM_READWRITE));
GST_TYPE_WAVPACK_ENC_MODE, GST_WAVPACK_ENC_MODE_DEFAULT,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, ARG_BITRATE,
g_param_spec_double ("bitrate", "Bitrate",
"Try to encode with this average bitrate (bits/sec). "
......@@ -279,7 +300,7 @@ gst_wavpack_enc_class_init (GstWavpackEncClass * klass)
g_object_class_install_property (gobject_class, ARG_CORRECTION_MODE,
g_param_spec_enum ("correction-mode", "Correction file mode",
"Use this mode for correction file creation. Only works in lossy mode!",
GST_TYPE_WAVPACK_ENC_CORRECTION_MODE, DEFAULT_CORRECTION_MODE,
GST_TYPE_WAVPACK_ENC_CORRECTION_MODE, GST_WAVPACK_CORRECTION_MODE_OFF,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, ARG_MD5,
g_param_spec_boolean ("md5", "MD5",
......@@ -291,7 +312,40 @@ gst_wavpack_enc_class_init (GstWavpackEncClass * klass)
g_object_class_install_property (gobject_class, ARG_JOINT_STEREO_MODE,
g_param_spec_enum ("joint-stereo-mode", "Joint-Stereo mode",
"Use this joint-stereo mode.", GST_TYPE_WAVPACK_ENC_JOINT_STEREO_MODE,
DEFAULT_JS_MODE, G_PARAM_READWRITE));
GST_WAVPACK_JS_MODE_AUTO, G_PARAM_READWRITE));
}
static void
gst_wavpack_enc_reset (GstWavpackEnc * enc)
{
/* close and free everything stream related if we already did something */
if (enc->wp_context) {
WavpackCloseFile (enc->wp_context);
enc->wp_context = NULL;
}
if (enc->wp_config) {
g_free (enc->wp_config);
enc->wp_config = NULL;
}
if (enc->first_block) {
g_free (enc->first_block);
enc->first_block = NULL;
}
enc->first_block_size = 0;
if (enc->md5_context) {
g_free (enc->md5_context);
enc->md5_context = NULL;
}
/* reset the last returns to GST_FLOW_OK. This is only set to something else
* while WavpackPackSamples() or more specific gst_wavpack_enc_push_block()
* so not valid anymore */
enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
/* reset stream information */
enc->samplerate = 0;
enc->width = 0;
enc->channels = 0;
}
static void
......@@ -314,11 +368,8 @@ gst_wavpack_enc_init (GstWavpackEnc * enc, GstWavpackEncClass * gclass)
enc->wp_config = NULL;
enc->wp_context = NULL;
enc->first_block = NULL;
enc->first_block_size = 0;
enc->md5_context = NULL;
enc->samplerate = 0;
enc->width = 0;
enc->channels = 0;
gst_wavpack_enc_reset (enc);
enc->wv_id = g_new0 (GstWavpackEncWriteID, 1);
enc->wv_id->correction = FALSE;
......@@ -328,12 +379,12 @@ gst_wavpack_enc_init (GstWavpackEnc * enc, GstWavpackEncClass * gclass)
enc->wvc_id->wavpack_enc = enc;
/* set default values of params */
enc->mode = DEFAULT_MODE;
enc->mode = GST_WAVPACK_ENC_MODE_DEFAULT;
enc->bitrate = 0.0;
enc->correction_mode = DEFAULT_CORRECTION_MODE;
enc->correction_mode = GST_WAVPACK_CORRECTION_MODE_OFF;
enc->md5 = FALSE;
enc->extra_processing = FALSE;
enc->joint_stereo_mode = DEFAULT_JS_MODE;
enc->joint_stereo_mode = GST_WAVPACK_JS_MODE_AUTO;
}
static void
......@@ -411,21 +462,21 @@ gst_wavpack_enc_set_wp_config (GstWavpackEnc * enc)
/* Encoding mode */
switch (enc->mode) {
#if 0
case 0:
case GST_WAVPACK_ENC_MODE_VERY_FAST:
enc->wp_config->flags |= CONFIG_VERY_FAST_FLAG;
enc->wp_config->flags |= CONFIG_FAST_FLAG;
break;
#endif
case 1:
case GST_WAVPACK_ENC_MODE_FAST:
enc->wp_config->flags |= CONFIG_FAST_FLAG;
break;
case 2: /* default */
case GST_WAVPACK_ENC_MODE_DEFAULT:
break;
case 3:
case GST_WAVPACK_ENC_MODE_HIGH:
enc->wp_config->flags |= CONFIG_HIGH_FLAG;
break;
#ifndef WAVPACK_OLD_API
case 4:
case GST_WAVPACK_ENC_MODE_VERY_HIGH:
enc->wp_config->flags |= CONFIG_HIGH_FLAG;
enc->wp_config->flags |= CONFIG_VERY_HIGH_FLAG;
break;
......@@ -445,7 +496,7 @@ gst_wavpack_enc_set_wp_config (GstWavpackEnc * enc)
/* Correction Mode, only in lossy mode */
if (enc->wp_config->flags & CONFIG_HYBRID_FLAG) {
if (enc->correction_mode > 0) {
if (enc->correction_mode > GST_WAVPACK_CORRECTION_MODE_OFF) {
enc->wvcsrcpad =
gst_pad_new_from_static_template (&wvcsrc_factory, "wvcsrc");
......@@ -463,14 +514,14 @@ gst_wavpack_enc_set_wp_config (GstWavpackEnc * enc)
gst_pad_set_active (enc->wvcsrcpad, TRUE);
gst_element_add_pad (GST_ELEMENT (enc), enc->wvcsrcpad);
enc->wp_config->flags |= CONFIG_CREATE_WVC;
if (enc->correction_mode == 2) {
if (enc->correction_mode == GST_WAVPACK_CORRECTION_MODE_OPTIMIZED) {
enc->wp_config->flags |= CONFIG_OPTIMIZE_WVC;
}
}
gst_caps_unref (caps);
}
} else {
if (enc->correction_mode > 0) {
if (enc->correction_mode > GST_WAVPACK_CORRECTION_MODE_OFF) {
enc->correction_mode = 0;
GST_WARNING_OBJECT (enc, "setting correction mode only has "
"any effect if a bitrate is provided.");
......@@ -492,13 +543,13 @@ gst_wavpack_enc_set_wp_config (GstWavpackEnc * enc)
/* Joint stereo mode */
switch (enc->joint_stereo_mode) {
case 0: /* default */
case GST_WAVPACK_JS_MODE_AUTO:
break;
case 1:
case GST_WAVPACK_JS_MODE_LEFT_RIGHT:
enc->wp_config->flags |= CONFIG_JOINT_OVERRIDE;
enc->wp_config->flags &= ~CONFIG_JOINT_STEREO;
break;
case 2:
case GST_WAVPACK_JS_MODE_MID_SIDE:
enc->wp_config->flags |= (CONFIG_JOINT_OVERRIDE | CONFIG_JOINT_STEREO);
break;
}
......@@ -804,7 +855,9 @@ gst_wavpack_enc_change_state (GstElement * element, GstStateChange transition)
* as they're only set to something else in WavpackPackSamples() or more
* specific gst_wavpack_enc_push_block() and nothing happened there yet */
enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
default:
break;
......@@ -816,29 +869,7 @@ gst_wavpack_enc_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
/* close and free everything stream related */
if (enc->wp_context) {
WavpackCloseFile (enc->wp_context);
enc->wp_context = NULL;
}
if (enc->wp_config) {
g_free (enc->wp_config);
enc->wp_config = NULL;
}
if (enc->first_block) {
g_free (enc->first_block);
enc->first_block = NULL;
enc->first_block_size = 0;
}
if (enc->md5_context) {
g_free (enc->md5_context);
enc->md5_context = NULL;
}
/* reset the last returns to GST_FLOW_OK. This is only set to something else
* while WavpackPackSamples() or more specific gst_wavpack_enc_push_block()
* so not valid anymore */
enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
gst_wavpack_enc_reset (enc);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
break;
......
......@@ -25,9 +25,11 @@
* SECTION:element-wavpackparse
*
* <refsect2>
* Wavpackparse takes raw, unframed Wavpack streams and splits them into
* WavpackParse takes raw, unframed Wavpack streams and splits them into
* single Wavpack chunks with information like bit depth and the position
* in the stream.
* <ulink url="http://www.wavpack.com/">Wavpack</ulink> is an open-source
* audio codec that features both lossless and lossy encoding.
* <title>Example launch line</title>
* <para>
* <programlisting>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment