summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2006-11-15 12:35:46 +0000
committerTim-Philipp Müller <tim@centricular.net>2006-11-15 12:35:46 +0000
commite7794502baeb5808c5749dfc464de17761c49c80 (patch)
treef713dd60b92299ea4613e8e703288694a01ca6d3 /ext
parent71b09a611ae4991e1a125e5be1af47a2f2f8afec (diff)
downloadgst-plugins-bad-e7794502baeb5808c5749dfc464de17761c49c80.tar.gz
gst-plugins-bad-e7794502baeb5808c5749dfc464de17761c49c80.tar.bz2
gst-plugins-bad-e7794502baeb5808c5749dfc464de17761c49c80.zip
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).
Diffstat (limited to 'ext')
-rw-r--r--ext/wavpack/gstwavpackdec.c40
-rw-r--r--ext/wavpack/gstwavpackenc.c129
-rw-r--r--ext/wavpack/gstwavpackparse.c4
3 files changed, 103 insertions, 70 deletions
diff --git a/ext/wavpack/gstwavpackdec.c b/ext/wavpack/gstwavpackdec.c
index 88074e80..a05d1946 100644
--- a/ext/wavpack/gstwavpackdec.c
+++ b/ext/wavpack/gstwavpackdec.c
@@ -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.
@@ -116,6 +116,22 @@ gst_wavpack_dec_class_init (GstWavpackDecClass * klass)
}
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)
{
dec->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
@@ -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;
diff --git a/ext/wavpack/gstwavpackenc.c b/ext/wavpack/gstwavpackenc.c
index f4fab948..336580c4 100644
--- a/ext/wavpack/gstwavpackenc.c
+++ b/ext/wavpack/gstwavpackenc.c
@@ -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;
diff --git a/ext/wavpack/gstwavpackparse.c b/ext/wavpack/gstwavpackparse.c
index 62bb8efd..45b6e2d2 100644
--- a/ext/wavpack/gstwavpackparse.c
+++ b/ext/wavpack/gstwavpackparse.c
@@ -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>