ext/wavpack/: More clean-ups: use shorter variable names to make code easier to read; prefix structures we define wit...

Original commit message from CVS:
* ext/wavpack/gstwavpackenc.c: (gst_wavpack_enc_init),
(gst_wavpack_enc_finalize), (gst_wavpack_enc_sink_set_caps),
(gst_wavpack_enc_set_wp_config), (gst_wavpack_enc_format_samples),
(gst_wavpack_enc_push_block), (gst_wavpack_enc_chain),
(gst_wavpack_enc_rewrite_first_block),
(gst_wavpack_enc_sink_event), (gst_wavpack_enc_change_state),
(gst_wavpack_enc_set_property), (gst_wavpack_enc_get_property):
* ext/wavpack/gstwavpackenc.h:
* ext/wavpack/gstwavpackparse.c: (gst_wavpack_parse_reset),
(gst_wavpack_parse_src_query), (gst_wavpack_parse_src_event),
(gst_wavpack_parse_init), (gst_wavpack_parse_get_upstream_length),
(gst_wavpack_parse_loop):
More clean-ups: use shorter variable names to make code easier to
read; prefix structures we define with 'Gst' to make it clearer
where they come from.
This commit is contained in:
Tim-Philipp Müller 2006-08-21 13:59:52 +00:00
parent aea5c4eca3
commit 11fc25f7af
4 changed files with 298 additions and 288 deletions

View file

@ -1,3 +1,21 @@
2006-08-21 Tim-Philipp Müller <tim at centricular dot net>
* ext/wavpack/gstwavpackenc.c: (gst_wavpack_enc_init),
(gst_wavpack_enc_finalize), (gst_wavpack_enc_sink_set_caps),
(gst_wavpack_enc_set_wp_config), (gst_wavpack_enc_format_samples),
(gst_wavpack_enc_push_block), (gst_wavpack_enc_chain),
(gst_wavpack_enc_rewrite_first_block),
(gst_wavpack_enc_sink_event), (gst_wavpack_enc_change_state),
(gst_wavpack_enc_set_property), (gst_wavpack_enc_get_property):
* ext/wavpack/gstwavpackenc.h:
* ext/wavpack/gstwavpackparse.c: (gst_wavpack_parse_reset),
(gst_wavpack_parse_src_query), (gst_wavpack_parse_src_event),
(gst_wavpack_parse_init), (gst_wavpack_parse_get_upstream_length),
(gst_wavpack_parse_loop):
More clean-ups: use shorter variable names to make code easier to
read; prefix structures we define with 'Gst' to make it clearer
where they come from.
2006-08-21 Tim-Philipp Müller <tim at centricular dot net> 2006-08-21 Tim-Philipp Müller <tim at centricular dot net>
* ext/wavpack/gstwavpackenc.c: (gst_wavpack_enc_init), * ext/wavpack/gstwavpackenc.c: (gst_wavpack_enc_init),

View file

@ -256,56 +256,55 @@ gst_wavpack_enc_class_init (GstWavpackEncClass * klass)
} }
static void static void
gst_wavpack_enc_init (GstWavpackEnc * wavpack_enc, GstWavpackEncClass * gclass) gst_wavpack_enc_init (GstWavpackEnc * enc, GstWavpackEncClass * gclass)
{ {
wavpack_enc->sinkpad = enc->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
gst_pad_new_from_static_template (&sink_factory, "sink"); gst_pad_set_setcaps_function (enc->sinkpad,
gst_pad_set_setcaps_function (wavpack_enc->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_enc_sink_set_caps)); GST_DEBUG_FUNCPTR (gst_wavpack_enc_sink_set_caps));
gst_pad_set_chain_function (wavpack_enc->sinkpad, gst_pad_set_chain_function (enc->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_enc_chain)); GST_DEBUG_FUNCPTR (gst_wavpack_enc_chain));
gst_pad_set_event_function (wavpack_enc->sinkpad, gst_pad_set_event_function (enc->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_enc_sink_event)); GST_DEBUG_FUNCPTR (gst_wavpack_enc_sink_event));
gst_element_add_pad (GST_ELEMENT (wavpack_enc), wavpack_enc->sinkpad); gst_element_add_pad (GST_ELEMENT (enc), enc->sinkpad);
/* setup src pad */ /* setup src pad */
wavpack_enc->srcpad = gst_pad_new_from_static_template (&src_factory, "src"); enc->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
gst_element_add_pad (GST_ELEMENT (wavpack_enc), wavpack_enc->srcpad); gst_element_add_pad (GST_ELEMENT (enc), enc->srcpad);
/* initialize object attributes */ /* initialize object attributes */
wavpack_enc->wp_config = NULL; enc->wp_config = NULL;
wavpack_enc->wp_context = NULL; enc->wp_context = NULL;
wavpack_enc->first_block = NULL; enc->first_block = NULL;
wavpack_enc->first_block_size = 0; enc->first_block_size = 0;
wavpack_enc->md5_context = NULL; enc->md5_context = NULL;
wavpack_enc->samplerate = 0; enc->samplerate = 0;
wavpack_enc->width = 0; enc->width = 0;
wavpack_enc->channels = 0; enc->channels = 0;
wavpack_enc->wv_id = (write_id *) g_malloc0 (sizeof (write_id)); enc->wv_id = g_new0 (GstWavpackEncWriteID, 1);
wavpack_enc->wv_id->correction = FALSE; enc->wv_id->correction = FALSE;
wavpack_enc->wv_id->wavpack_enc = wavpack_enc; enc->wv_id->wavpack_enc = enc;
wavpack_enc->wvc_id = (write_id *) g_malloc0 (sizeof (write_id)); enc->wvc_id = g_new0 (GstWavpackEncWriteID, 1);
wavpack_enc->wvc_id->correction = TRUE; enc->wvc_id->correction = TRUE;
wavpack_enc->wvc_id->wavpack_enc = wavpack_enc; enc->wvc_id->wavpack_enc = enc;
/* set default values of params */ /* set default values of params */
wavpack_enc->mode = 1; enc->mode = 1;
wavpack_enc->bitrate = 0.0; enc->bitrate = 0.0;
wavpack_enc->correction_mode = 0; enc->correction_mode = 0;
wavpack_enc->md5 = FALSE; enc->md5 = FALSE;
wavpack_enc->extra_processing = FALSE; enc->extra_processing = FALSE;
wavpack_enc->joint_stereo_mode = 0; enc->joint_stereo_mode = 0;
} }
static void static void
gst_wavpack_enc_finalize (GObject * object) gst_wavpack_enc_finalize (GObject * object)
{ {
GstWavpackEnc *wavpack_enc = GST_WAVPACK_ENC (object); GstWavpackEnc *enc = GST_WAVPACK_ENC (object);
/* free the blockout helpers */ /* free the blockout helpers */
g_free (wavpack_enc->wv_id); g_free (enc->wv_id);
g_free (wavpack_enc->wvc_id); g_free (enc->wvc_id);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -313,146 +312,144 @@ gst_wavpack_enc_finalize (GObject * object)
static gboolean static gboolean
gst_wavpack_enc_sink_set_caps (GstPad * pad, GstCaps * caps) gst_wavpack_enc_sink_set_caps (GstPad * pad, GstCaps * caps)
{ {
GstWavpackEnc *wavpack_enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad)); GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad));
GstStructure *structure = gst_caps_get_structure (caps, 0); GstStructure *structure = gst_caps_get_structure (caps, 0);
int depth = 0; int depth = 0;
/* check caps and put relevant parts into our object attributes */ /* check caps and put relevant parts into our object attributes */
if ((!gst_structure_get_int (structure, "channels", &wavpack_enc->channels)) if (!gst_structure_get_int (structure, "channels", &enc->channels) ||
|| (!gst_structure_get_int (structure, "rate", &wavpack_enc->samplerate)) !gst_structure_get_int (structure, "rate", &enc->samplerate) ||
|| (!gst_structure_get_int (structure, "width", &wavpack_enc->width)) !gst_structure_get_int (structure, "width", &enc->width) ||
|| (!(gst_structure_get_int (structure, "depth", &depth)) !(gst_structure_get_int (structure, "depth", &depth) ||
|| depth != wavpack_enc->width)) { depth != enc->width)) {
GST_ELEMENT_ERROR (wavpack_enc, LIBRARY, INIT, (NULL), GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL),
("got invalid caps: %", GST_PTR_FORMAT, caps)); ("got invalid caps: %", GST_PTR_FORMAT, caps));
gst_object_unref (wavpack_enc); gst_object_unref (enc);
return FALSE; return FALSE;
} }
/* set fixed src pad caps now that we know what we will get */ /* set fixed src pad caps now that we know what we will get */
caps = gst_caps_new_simple ("audio/x-wavpack", caps = gst_caps_new_simple ("audio/x-wavpack",
"channels", G_TYPE_INT, wavpack_enc->channels, "channels", G_TYPE_INT, enc->channels,
"rate", G_TYPE_INT, wavpack_enc->samplerate, "rate", G_TYPE_INT, enc->samplerate,
"width", G_TYPE_INT, wavpack_enc->width, "width", G_TYPE_INT, enc->width, "framed", G_TYPE_BOOLEAN, TRUE, NULL);
"framed", G_TYPE_BOOLEAN, TRUE, NULL);
if (!gst_pad_set_caps (wavpack_enc->srcpad, caps)) { if (!gst_pad_set_caps (enc->srcpad, caps)) {
GST_ELEMENT_ERROR (wavpack_enc, LIBRARY, INIT, (NULL), GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL),
("setting caps failed: %", GST_PTR_FORMAT, caps)); ("setting caps failed: %", GST_PTR_FORMAT, caps));
gst_caps_unref (caps); gst_caps_unref (caps);
gst_object_unref (wavpack_enc); gst_object_unref (enc);
return FALSE; return FALSE;
} }
gst_pad_use_fixed_caps (wavpack_enc->srcpad); gst_pad_use_fixed_caps (enc->srcpad);
gst_caps_unref (caps); gst_caps_unref (caps);
gst_object_unref (wavpack_enc); gst_object_unref (enc);
return TRUE; return TRUE;
} }
static void static void
gst_wavpack_enc_set_wp_config (GstWavpackEnc * wavpack_enc) gst_wavpack_enc_set_wp_config (GstWavpackEnc * enc)
{ {
wavpack_enc->wp_config = (WavpackConfig *) g_malloc0 (sizeof (WavpackConfig)); enc->wp_config = g_new0 (WavpackConfig, 1);
/* set general stream informations in the WavpackConfig */ /* set general stream informations in the WavpackConfig */
wavpack_enc->wp_config->bytes_per_sample = (wavpack_enc->width + 7) >> 3; enc->wp_config->bytes_per_sample = (enc->width + 7) >> 3;
wavpack_enc->wp_config->bits_per_sample = wavpack_enc->width; enc->wp_config->bits_per_sample = enc->width;
wavpack_enc->wp_config->num_channels = wavpack_enc->channels; enc->wp_config->num_channels = enc->channels;
/* TODO: handle more than 2 channels correctly! */ /* TODO: handle more than 2 channels correctly! */
if (wavpack_enc->channels == 1) { if (enc->channels == 1) {
wavpack_enc->wp_config->channel_mask = 0x4; enc->wp_config->channel_mask = 0x4;
} else if (wavpack_enc->channels == 2) { } else if (enc->channels == 2) {
wavpack_enc->wp_config->channel_mask = 0x2 | 0x1; enc->wp_config->channel_mask = 0x2 | 0x1;
} }
wavpack_enc->wp_config->sample_rate = wavpack_enc->samplerate; enc->wp_config->sample_rate = enc->samplerate;
/* /*
* Set parameters in WavpackConfig * Set parameters in WavpackConfig
*/ */
/* Encoding mode */ /* Encoding mode */
switch (wavpack_enc->mode) { switch (enc->mode) {
case 0: case 0:
wavpack_enc->wp_config->flags |= CONFIG_FAST_FLAG; enc->wp_config->flags |= CONFIG_FAST_FLAG;
break; break;
case 1: /* default */ case 1: /* default */
break; break;
case 2: case 2:
wavpack_enc->wp_config->flags |= CONFIG_HIGH_FLAG; enc->wp_config->flags |= CONFIG_HIGH_FLAG;
break; break;
} }
/* Bitrate, enables lossy mode */ /* Bitrate, enables lossy mode */
if (wavpack_enc->bitrate >= 2.0) { if (enc->bitrate >= 2.0) {
wavpack_enc->wp_config->flags |= CONFIG_HYBRID_FLAG; enc->wp_config->flags |= CONFIG_HYBRID_FLAG;
if (wavpack_enc->bitrate >= 24000.0) { if (enc->bitrate >= 24000.0) {
wavpack_enc->wp_config->bitrate = wavpack_enc->bitrate / 1000.0; enc->wp_config->bitrate = enc->bitrate / 1000.0;
wavpack_enc->wp_config->flags |= CONFIG_BITRATE_KBPS; enc->wp_config->flags |= CONFIG_BITRATE_KBPS;
} else { } else {
wavpack_enc->wp_config->bitrate = wavpack_enc->bitrate; enc->wp_config->bitrate = enc->bitrate;
} }
} }
/* Correction Mode, only in lossy mode */ /* Correction Mode, only in lossy mode */
if (wavpack_enc->wp_config->flags & CONFIG_HYBRID_FLAG) { if (enc->wp_config->flags & CONFIG_HYBRID_FLAG) {
if (wavpack_enc->correction_mode > 0) { if (enc->correction_mode > 0) {
wavpack_enc->wvcsrcpad = enc->wvcsrcpad =
gst_pad_new_from_static_template (&wvcsrc_factory, "wvcsrc"); gst_pad_new_from_static_template (&wvcsrc_factory, "wvcsrc");
/* try to add correction src pad, don't set correction mode on failure */ /* try to add correction src pad, don't set correction mode on failure */
GstCaps *caps = gst_caps_new_simple ("audio/x-wavpack-correction", GstCaps *caps = gst_caps_new_simple ("audio/x-wavpack-correction",
"framed", G_TYPE_BOOLEAN, TRUE, NULL); "framed", G_TYPE_BOOLEAN, TRUE, NULL);
gst_element_no_more_pads (GST_ELEMENT (wavpack_enc)); gst_element_no_more_pads (GST_ELEMENT (enc));
GST_DEBUG_OBJECT (wavpack_enc, "Adding correction pad with caps %" GST_DEBUG_OBJECT (enc, "Adding correction pad with caps %"
GST_PTR_FORMAT, caps); GST_PTR_FORMAT, caps);
if (!gst_pad_set_caps (wavpack_enc->wvcsrcpad, caps)) { if (!gst_pad_set_caps (enc->wvcsrcpad, caps)) {
wavpack_enc->correction_mode = 0; enc->correction_mode = 0;
GST_WARNING_OBJECT (wavpack_enc, "setting correction caps failed"); GST_WARNING_OBJECT (enc, "setting correction caps failed");
} else { } else {
gst_pad_use_fixed_caps (wavpack_enc->wvcsrcpad); gst_pad_use_fixed_caps (enc->wvcsrcpad);
gst_element_add_pad (GST_ELEMENT (wavpack_enc), wavpack_enc->wvcsrcpad); gst_element_add_pad (GST_ELEMENT (enc), enc->wvcsrcpad);
wavpack_enc->wp_config->flags |= CONFIG_CREATE_WVC; enc->wp_config->flags |= CONFIG_CREATE_WVC;
if (wavpack_enc->correction_mode == 2) { if (enc->correction_mode == 2) {
wavpack_enc->wp_config->flags |= CONFIG_OPTIMIZE_WVC; enc->wp_config->flags |= CONFIG_OPTIMIZE_WVC;
} }
} }
gst_caps_unref (caps); gst_caps_unref (caps);
} }
} else { } else {
if (wavpack_enc->correction_mode > 0) { if (enc->correction_mode > 0) {
wavpack_enc->correction_mode = 0; enc->correction_mode = 0;
GST_WARNING_OBJECT (wavpack_enc, "setting correction mode only has " GST_WARNING_OBJECT (enc, "setting correction mode only has "
"any effect if a bitrate is provided."); "any effect if a bitrate is provided.");
} }
} }
gst_element_no_more_pads (GST_ELEMENT (wavpack_enc)); gst_element_no_more_pads (GST_ELEMENT (enc));
/* MD5, setup MD5 context */ /* MD5, setup MD5 context */
if ((wavpack_enc->md5) && !(wavpack_enc->md5_context)) { if ((enc->md5) && !(enc->md5_context)) {
wavpack_enc->wp_config->flags |= CONFIG_MD5_CHECKSUM; enc->wp_config->flags |= CONFIG_MD5_CHECKSUM;
wavpack_enc->md5_context = (MD5_CTX *) g_malloc0 (sizeof (MD5_CTX)); enc->md5_context = g_new0 (MD5_CTX, 1);
MD5Init (wavpack_enc->md5_context); MD5Init (enc->md5_context);
} }
/* Extra encode processing */ /* Extra encode processing */
if (wavpack_enc->extra_processing) { if (enc->extra_processing) {
wavpack_enc->wp_config->flags |= CONFIG_EXTRA_MODE; enc->wp_config->flags |= CONFIG_EXTRA_MODE;
} }
/* Joint stereo mode */ /* Joint stereo mode */
switch (wavpack_enc->joint_stereo_mode) { switch (enc->joint_stereo_mode) {
case 0: /* default */ case 0: /* default */
break; break;
case 1: case 1:
wavpack_enc->wp_config->flags |= CONFIG_JOINT_OVERRIDE; enc->wp_config->flags |= CONFIG_JOINT_OVERRIDE;
wavpack_enc->wp_config->flags &= ~CONFIG_JOINT_STEREO; enc->wp_config->flags &= ~CONFIG_JOINT_STEREO;
break; break;
case 2: case 2:
wavpack_enc->wp_config->flags |= enc->wp_config->flags |= (CONFIG_JOINT_OVERRIDE | CONFIG_JOINT_STEREO);
(CONFIG_JOINT_OVERRIDE | CONFIG_JOINT_STEREO);
break; break;
} }
} }
@ -461,7 +458,7 @@ static int32_t *
gst_wavpack_enc_format_samples (const uchar * src_data, uint32_t sample_count, gst_wavpack_enc_format_samples (const uchar * src_data, uint32_t sample_count,
guint width) guint width)
{ {
int32_t *data = (int32_t *) g_malloc0 (sizeof (int32_t) * sample_count); int32_t *data = g_new0 (int32_t, sample_count);
/* put all samples into an int32_t*, no matter what /* put all samples into an int32_t*, no matter what
* width we have and convert them from little endian * width we have and convert them from little endian
@ -500,23 +497,23 @@ gst_wavpack_enc_format_samples (const uchar * src_data, uint32_t sample_count,
static int static int
gst_wavpack_enc_push_block (void *id, void *data, int32_t count) gst_wavpack_enc_push_block (void *id, void *data, int32_t count)
{ {
write_id *wid = (write_id *) id; GstWavpackEncWriteID *wid = (GstWavpackEncWriteID *) id;
GstWavpackEnc *wavpack_enc = GST_WAVPACK_ENC (wid->wavpack_enc); GstWavpackEnc *enc = GST_WAVPACK_ENC (wid->wavpack_enc);
GstFlowReturn *flow; GstFlowReturn *flow;
GstBuffer *buffer; GstBuffer *buffer;
GstPad *pad; GstPad *pad;
guchar *block = (guchar *) data; guchar *block = (guchar *) data;
pad = (wid->correction) ? wavpack_enc->wvcsrcpad : wavpack_enc->srcpad; pad = (wid->correction) ? enc->wvcsrcpad : enc->srcpad;
flow = flow =
(wid->correction) ? &wavpack_enc->wvcsrcpad_last_return : &wavpack_enc-> (wid->correction) ? &enc->wvcsrcpad_last_return : &enc->
srcpad_last_return; srcpad_last_return;
*flow = gst_pad_alloc_buffer_and_set_caps (pad, GST_BUFFER_OFFSET_NONE, *flow = gst_pad_alloc_buffer_and_set_caps (pad, GST_BUFFER_OFFSET_NONE,
count, GST_PAD_CAPS (pad), &buffer); count, GST_PAD_CAPS (pad), &buffer);
if (*flow != GST_FLOW_OK) { if (*flow != GST_FLOW_OK) {
GST_WARNING_OBJECT (wavpack_enc, "flow on %s:%s = %s", GST_WARNING_OBJECT (enc, "flow on %s:%s = %s",
GST_DEBUG_PAD_NAME (pad), gst_flow_get_name (*flow)); GST_DEBUG_PAD_NAME (pad), gst_flow_get_name (*flow));
return FALSE; return FALSE;
} }
@ -527,7 +524,7 @@ gst_wavpack_enc_push_block (void *id, void *data, int32_t count)
/* if it's a Wavpack block set buffer timestamp and duration, etc */ /* if it's a Wavpack block set buffer timestamp and duration, etc */
WavpackHeader wph; WavpackHeader wph;
GST_LOG_OBJECT (wavpack_enc, "got %d bytes of encoded wavpack %sdata", GST_LOG_OBJECT (enc, "got %d bytes of encoded wavpack %sdata",
count, (wid->correction) ? "correction " : ""); count, (wid->correction) ? "correction " : "");
gst_wavpack_read_header (&wph, block); gst_wavpack_read_header (&wph, block);
@ -539,10 +536,10 @@ gst_wavpack_enc_push_block (void *id, void *data, int32_t count)
/* save header for later reference, so we can re-send it later on /* save header for later reference, so we can re-send it later on
* EOS with fixed up values for total sample count etc. */ * EOS with fixed up values for total sample count etc. */
if (wavpack_enc->first_block == NULL && !wid->correction) { if (enc->first_block == NULL && !wid->correction) {
gst_pad_push_event (wavpack_enc->srcpad, event); gst_pad_push_event (enc->srcpad, event);
wavpack_enc->first_block = g_memdup (block, count); enc->first_block = g_memdup (block, count);
wavpack_enc->first_block_size = count; enc->first_block_size = count;
} }
} }
@ -550,15 +547,15 @@ gst_wavpack_enc_push_block (void *id, void *data, int32_t count)
* the wavpack header */ * the wavpack header */
GST_BUFFER_TIMESTAMP (buffer) = GST_BUFFER_TIMESTAMP (buffer) =
gst_util_uint64_scale_int (GST_SECOND, wph.block_index, gst_util_uint64_scale_int (GST_SECOND, wph.block_index,
wavpack_enc->samplerate); enc->samplerate);
GST_BUFFER_DURATION (buffer) = GST_BUFFER_DURATION (buffer) =
gst_util_uint64_scale_int (GST_SECOND, wph.block_samples, gst_util_uint64_scale_int (GST_SECOND, wph.block_samples,
wavpack_enc->samplerate); enc->samplerate);
GST_BUFFER_OFFSET (buffer) = wph.block_index; GST_BUFFER_OFFSET (buffer) = wph.block_index;
GST_BUFFER_OFFSET_END (buffer) = wph.block_index + wph.block_samples; GST_BUFFER_OFFSET_END (buffer) = wph.block_index + wph.block_samples;
} else { } else {
/* if it's something else set no timestamp and duration on the buffer */ /* if it's something else set no timestamp and duration on the buffer */
GST_DEBUG_OBJECT (wavpack_enc, "got %d bytes of unknown data", count); GST_DEBUG_OBJECT (enc, "got %d bytes of unknown data", count);
GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE; GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE; GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
@ -568,7 +565,7 @@ gst_wavpack_enc_push_block (void *id, void *data, int32_t count)
*flow = gst_pad_push (pad, buffer); *flow = gst_pad_push (pad, buffer);
if (*flow != GST_FLOW_OK) { if (*flow != GST_FLOW_OK) {
GST_WARNING_OBJECT (wavpack_enc, "flow on %s:%s = %s", GST_WARNING_OBJECT (enc, "flow on %s:%s = %s",
GST_DEBUG_PAD_NAME (pad), gst_flow_get_name (*flow)); GST_DEBUG_PAD_NAME (pad), gst_flow_get_name (*flow));
return FALSE; return FALSE;
} }
@ -579,46 +576,44 @@ gst_wavpack_enc_push_block (void *id, void *data, int32_t count)
static GstFlowReturn static GstFlowReturn
gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buf) gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buf)
{ {
GstWavpackEnc *wavpack_enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad)); GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad));
uint32_t sample_count = uint32_t sample_count = GST_BUFFER_SIZE (buf) / ((enc->width + 7) >> 3);
GST_BUFFER_SIZE (buf) / ((wavpack_enc->width + 7) >> 3);
int32_t *data; int32_t *data;
GstFlowReturn ret; GstFlowReturn ret;
/* reset the last returns to GST_FLOW_OK. This is only set to something else /* 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() * while WavpackPackSamples() or more specific gst_wavpack_enc_push_block()
* so not valid anymore */ * so not valid anymore */
wavpack_enc->srcpad_last_return = wavpack_enc->wvcsrcpad_last_return = enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
GST_FLOW_OK;
GST_DEBUG ("got %u raw samples", sample_count); GST_DEBUG ("got %u raw samples", sample_count);
/* check if we already have a valid WavpackContext, otherwise make one */ /* check if we already have a valid WavpackContext, otherwise make one */
if (!wavpack_enc->wp_context) { if (!enc->wp_context) {
/* create raw context */ /* create raw context */
wavpack_enc->wp_context = enc->wp_context =
WavpackOpenFileOutput (gst_wavpack_enc_push_block, wavpack_enc->wv_id, WavpackOpenFileOutput (gst_wavpack_enc_push_block, enc->wv_id,
(wavpack_enc->correction_mode > 0) ? wavpack_enc->wvc_id : NULL); (enc->correction_mode > 0) ? enc->wvc_id : NULL);
if (!wavpack_enc->wp_context) { if (!enc->wp_context) {
GST_ELEMENT_ERROR (wavpack_enc, LIBRARY, INIT, (NULL), GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL),
("error creating Wavpack context")); ("error creating Wavpack context"));
gst_object_unref (wavpack_enc); gst_object_unref (enc);
gst_buffer_unref (buf); gst_buffer_unref (buf);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
/* set the WavpackConfig according to our parameters */ /* set the WavpackConfig according to our parameters */
gst_wavpack_enc_set_wp_config (wavpack_enc); gst_wavpack_enc_set_wp_config (enc);
/* set the configuration to the context now that we know everything /* set the configuration to the context now that we know everything
* and initialize the encoder */ * and initialize the encoder */
if (!WavpackSetConfiguration (wavpack_enc->wp_context, if (!WavpackSetConfiguration (enc->wp_context,
wavpack_enc->wp_config, (uint32_t) (-1)) enc->wp_config, (uint32_t) (-1))
|| !WavpackPackInit (wavpack_enc->wp_context)) { || !WavpackPackInit (enc->wp_context)) {
GST_ELEMENT_ERROR (wavpack_enc, LIBRARY, SETTINGS, (NULL), GST_ELEMENT_ERROR (enc, LIBRARY, SETTINGS, (NULL),
("error setting up wavpack encoding context")); ("error setting up wavpack encoding context"));
WavpackCloseFile (wavpack_enc->wp_context); WavpackCloseFile (enc->wp_context);
gst_object_unref (wavpack_enc); gst_object_unref (enc);
gst_buffer_unref (buf); gst_buffer_unref (buf);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
@ -627,9 +622,8 @@ gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buf)
/* if we want to append the MD5 sum to the stream update it here /* if we want to append the MD5 sum to the stream update it here
* with the current raw samples */ * with the current raw samples */
if (wavpack_enc->md5) { if (enc->md5) {
MD5Update (wavpack_enc->md5_context, GST_BUFFER_DATA (buf), MD5Update (enc->md5_context, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
GST_BUFFER_SIZE (buf));
} }
/* put all samples into an int32_t*, no matter what /* put all samples into an int32_t*, no matter what
@ -637,62 +631,61 @@ gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buf)
* to host byte order */ * to host byte order */
data = data =
gst_wavpack_enc_format_samples (GST_BUFFER_DATA (buf), sample_count, gst_wavpack_enc_format_samples (GST_BUFFER_DATA (buf), sample_count,
wavpack_enc->width); enc->width);
gst_buffer_unref (buf); gst_buffer_unref (buf);
/* encode and handle return values from encoding */ /* encode and handle return values from encoding */
if (WavpackPackSamples (wavpack_enc->wp_context, data, if (WavpackPackSamples (enc->wp_context, data, sample_count / enc->channels)) {
sample_count / wavpack_enc->channels)) {
GST_DEBUG ("encoding samples successful"); GST_DEBUG ("encoding samples successful");
ret = GST_FLOW_OK; ret = GST_FLOW_OK;
} else { } else {
if ((wavpack_enc->srcpad_last_return == GST_FLOW_RESEND) || if ((enc->srcpad_last_return == GST_FLOW_RESEND) ||
(wavpack_enc->wvcsrcpad_last_return == GST_FLOW_RESEND)) { (enc->wvcsrcpad_last_return == GST_FLOW_RESEND)) {
ret = GST_FLOW_RESEND; ret = GST_FLOW_RESEND;
} else if ((wavpack_enc->srcpad_last_return == GST_FLOW_OK) || } else if ((enc->srcpad_last_return == GST_FLOW_OK) ||
(wavpack_enc->wvcsrcpad_last_return == GST_FLOW_OK)) { (enc->wvcsrcpad_last_return == GST_FLOW_OK)) {
ret = GST_FLOW_OK; ret = GST_FLOW_OK;
} else if ((wavpack_enc->srcpad_last_return == GST_FLOW_NOT_LINKED) && } else if ((enc->srcpad_last_return == GST_FLOW_NOT_LINKED) &&
(wavpack_enc->wvcsrcpad_last_return == GST_FLOW_NOT_LINKED)) { (enc->wvcsrcpad_last_return == GST_FLOW_NOT_LINKED)) {
ret = GST_FLOW_NOT_LINKED; ret = GST_FLOW_NOT_LINKED;
} else if ((wavpack_enc->srcpad_last_return == GST_FLOW_WRONG_STATE) && } else if ((enc->srcpad_last_return == GST_FLOW_WRONG_STATE) &&
(wavpack_enc->wvcsrcpad_last_return == GST_FLOW_WRONG_STATE)) { (enc->wvcsrcpad_last_return == GST_FLOW_WRONG_STATE)) {
ret = GST_FLOW_WRONG_STATE; ret = GST_FLOW_WRONG_STATE;
} else { } else {
GST_ELEMENT_ERROR (wavpack_enc, LIBRARY, ENCODE, (NULL), GST_ELEMENT_ERROR (enc, LIBRARY, ENCODE, (NULL),
("encoding samples failed")); ("encoding samples failed"));
ret = GST_FLOW_ERROR; ret = GST_FLOW_ERROR;
} }
} }
g_free (data); g_free (data);
gst_object_unref (wavpack_enc); gst_object_unref (enc);
return ret; return ret;
} }
static void static void
gst_wavpack_enc_rewrite_first_block (GstWavpackEnc * wavpack_enc) gst_wavpack_enc_rewrite_first_block (GstWavpackEnc * enc)
{ {
GstEvent *event = gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, GstEvent *event = gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES,
0, GST_BUFFER_OFFSET_NONE, 0); 0, GST_BUFFER_OFFSET_NONE, 0);
gboolean ret; gboolean ret;
g_return_if_fail (wavpack_enc); g_return_if_fail (enc);
g_return_if_fail (wavpack_enc->first_block); g_return_if_fail (enc->first_block);
/* update the sample count in the first block */ /* update the sample count in the first block */
WavpackUpdateNumSamples (wavpack_enc->wp_context, wavpack_enc->first_block); WavpackUpdateNumSamples (enc->wp_context, enc->first_block);
/* try to seek to the beginning of the output */ /* try to seek to the beginning of the output */
ret = gst_pad_push_event (wavpack_enc->srcpad, event); ret = gst_pad_push_event (enc->srcpad, event);
if (ret) { if (ret) {
/* try to rewrite the first block */ /* try to rewrite the first block */
GST_DEBUG_OBJECT (wavpack_enc, "rewriting first block ..."); GST_DEBUG_OBJECT (enc, "rewriting first block ...");
ret = gst_wavpack_enc_push_block (wavpack_enc->wv_id, ret = gst_wavpack_enc_push_block (enc->wv_id,
wavpack_enc->first_block, wavpack_enc->first_block_size); enc->first_block, enc->first_block_size);
} else { } else {
GST_WARNING_OBJECT (wavpack_enc, "rewriting of first block failed. " GST_WARNING_OBJECT (enc, "rewriting of first block failed. "
"Seeking to first block failed!"); "Seeking to first block failed!");
} }
} }
@ -700,7 +693,7 @@ gst_wavpack_enc_rewrite_first_block (GstWavpackEnc * wavpack_enc)
static gboolean static gboolean
gst_wavpack_enc_sink_event (GstPad * pad, GstEvent * event) gst_wavpack_enc_sink_event (GstPad * pad, GstEvent * event)
{ {
GstWavpackEnc *wavpack_enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad)); GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad));
gboolean ret = TRUE; gboolean ret = TRUE;
GST_DEBUG ("Received %s event on sinkpad", GST_EVENT_TYPE_NAME (event)); GST_DEBUG ("Received %s event on sinkpad", GST_EVENT_TYPE_NAME (event));
@ -708,31 +701,31 @@ gst_wavpack_enc_sink_event (GstPad * pad, GstEvent * event)
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS: case GST_EVENT_EOS:
/* Encode all remaining samples and flush them to the src pads */ /* Encode all remaining samples and flush them to the src pads */
WavpackFlushSamples (wavpack_enc->wp_context); WavpackFlushSamples (enc->wp_context);
/* write the MD5 sum if we have to write one */ /* write the MD5 sum if we have to write one */
if ((wavpack_enc->md5) && (wavpack_enc->md5_context)) { if ((enc->md5) && (enc->md5_context)) {
guchar md5_digest[16]; guchar md5_digest[16];
MD5Final (md5_digest, wavpack_enc->md5_context); MD5Final (md5_digest, enc->md5_context);
WavpackStoreMD5Sum (wavpack_enc->wp_context, md5_digest); WavpackStoreMD5Sum (enc->wp_context, md5_digest);
} }
/* Try to rewrite the first frame with the correct sample number */ /* Try to rewrite the first frame with the correct sample number */
if (wavpack_enc->first_block) if (enc->first_block)
gst_wavpack_enc_rewrite_first_block (wavpack_enc); gst_wavpack_enc_rewrite_first_block (enc);
/* close the context if not already happened */ /* close the context if not already happened */
if (wavpack_enc->wp_context) { if (enc->wp_context) {
WavpackCloseFile (wavpack_enc->wp_context); WavpackCloseFile (enc->wp_context);
wavpack_enc->wp_context = NULL; enc->wp_context = NULL;
} }
ret = gst_pad_event_default (pad, event); ret = gst_pad_event_default (pad, event);
break; break;
case GST_EVENT_NEWSEGMENT: case GST_EVENT_NEWSEGMENT:
if (wavpack_enc->wp_context) { if (enc->wp_context) {
GST_WARNING_OBJECT (wavpack_enc, "got NEWSEGMENT after encoding " GST_WARNING_OBJECT (enc, "got NEWSEGMENT after encoding "
"already started"); "already started");
} }
/* drop NEWSEGMENT events, we create our own when pushing /* drop NEWSEGMENT events, we create our own when pushing
@ -745,7 +738,7 @@ gst_wavpack_enc_sink_event (GstPad * pad, GstEvent * event)
break; break;
} }
gst_object_unref (wavpack_enc); gst_object_unref (enc);
return ret; return ret;
} }
@ -753,15 +746,14 @@ static GstStateChangeReturn
gst_wavpack_enc_change_state (GstElement * element, GstStateChange transition) gst_wavpack_enc_change_state (GstElement * element, GstStateChange transition)
{ {
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstWavpackEnc *wavpack_enc = GST_WAVPACK_ENC (element); GstWavpackEnc *enc = GST_WAVPACK_ENC (element);
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY: case GST_STATE_CHANGE_NULL_TO_READY:
/* set the last returned GstFlowReturns of the two pads to GST_FLOW_OK /* set the last returned GstFlowReturns of the two pads to GST_FLOW_OK
* as they're only set to something else in WavpackPackSamples() or more * as they're only set to something else in WavpackPackSamples() or more
* specific gst_wavpack_enc_push_block() and nothing happened there yet */ * specific gst_wavpack_enc_push_block() and nothing happened there yet */
wavpack_enc->srcpad_last_return = wavpack_enc->wvcsrcpad_last_return = enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
GST_FLOW_OK;
case GST_STATE_CHANGE_READY_TO_PAUSED: case GST_STATE_CHANGE_READY_TO_PAUSED:
case GST_STATE_CHANGE_PAUSED_TO_PLAYING: case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
default: default:
@ -775,29 +767,28 @@ gst_wavpack_enc_change_state (GstElement * element, GstStateChange transition)
break; break;
case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_PAUSED_TO_READY:
/* close and free everything stream related */ /* close and free everything stream related */
if (wavpack_enc->wp_context) { if (enc->wp_context) {
WavpackCloseFile (wavpack_enc->wp_context); WavpackCloseFile (enc->wp_context);
wavpack_enc->wp_context = NULL; enc->wp_context = NULL;
} }
if (wavpack_enc->wp_config) { if (enc->wp_config) {
g_free (wavpack_enc->wp_config); g_free (enc->wp_config);
wavpack_enc->wp_config = NULL; enc->wp_config = NULL;
} }
if (wavpack_enc->first_block) { if (enc->first_block) {
g_free (wavpack_enc->first_block); g_free (enc->first_block);
wavpack_enc->first_block = NULL; enc->first_block = NULL;
wavpack_enc->first_block_size = 0; enc->first_block_size = 0;
} }
if (wavpack_enc->md5_context) { if (enc->md5_context) {
g_free (wavpack_enc->md5_context); g_free (enc->md5_context);
wavpack_enc->md5_context = NULL; enc->md5_context = NULL;
} }
/* reset the last returns to GST_FLOW_OK. This is only set to something else /* 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() * while WavpackPackSamples() or more specific gst_wavpack_enc_push_block()
* so not valid anymore */ * so not valid anymore */
wavpack_enc->srcpad_last_return = wavpack_enc->wvcsrcpad_last_return = enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
GST_FLOW_OK;
break; break;
case GST_STATE_CHANGE_READY_TO_NULL: case GST_STATE_CHANGE_READY_TO_NULL:
break; break;
@ -812,19 +803,19 @@ static void
gst_wavpack_enc_set_property (GObject * object, guint prop_id, gst_wavpack_enc_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
{ {
GstWavpackEnc *wavpack_enc = GST_WAVPACK_ENC (object); GstWavpackEnc *enc = GST_WAVPACK_ENC (object);
switch (prop_id) { switch (prop_id) {
case ARG_MODE: case ARG_MODE:
wavpack_enc->mode = g_value_get_enum (value); enc->mode = g_value_get_enum (value);
break; break;
case ARG_BITRATE:{ case ARG_BITRATE:{
gdouble val = g_value_get_double (value); gdouble val = g_value_get_double (value);
if ((val >= 24000.0) && (val <= 9600000.0)) { if ((val >= 24000.0) && (val <= 9600000.0)) {
wavpack_enc->bitrate = val; enc->bitrate = val;
} else { } else {
wavpack_enc->bitrate = 0.0; enc->bitrate = 0.0;
} }
break; break;
} }
@ -832,23 +823,23 @@ gst_wavpack_enc_set_property (GObject * object, guint prop_id,
gdouble val = g_value_get_double (value); gdouble val = g_value_get_double (value);
if ((val >= 2.0) && (val <= 24.0)) { if ((val >= 2.0) && (val <= 24.0)) {
wavpack_enc->bitrate = val; enc->bitrate = val;
} else { } else {
wavpack_enc->bitrate = 0.0; enc->bitrate = 0.0;
} }
break; break;
} }
case ARG_CORRECTION_MODE: case ARG_CORRECTION_MODE:
wavpack_enc->correction_mode = g_value_get_enum (value); enc->correction_mode = g_value_get_enum (value);
break; break;
case ARG_MD5: case ARG_MD5:
wavpack_enc->md5 = g_value_get_boolean (value); enc->md5 = g_value_get_boolean (value);
break; break;
case ARG_EXTRA_PROCESSING: case ARG_EXTRA_PROCESSING:
wavpack_enc->extra_processing = g_value_get_boolean (value); enc->extra_processing = g_value_get_boolean (value);
break; break;
case ARG_JOINT_STEREO_MODE: case ARG_JOINT_STEREO_MODE:
wavpack_enc->joint_stereo_mode = g_value_get_enum (value); enc->joint_stereo_mode = g_value_get_enum (value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -860,37 +851,37 @@ static void
gst_wavpack_enc_get_property (GObject * object, guint prop_id, GValue * value, gst_wavpack_enc_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec) GParamSpec * pspec)
{ {
GstWavpackEnc *wavpack_enc = GST_WAVPACK_ENC (object); GstWavpackEnc *enc = GST_WAVPACK_ENC (object);
switch (prop_id) { switch (prop_id) {
case ARG_MODE: case ARG_MODE:
g_value_set_enum (value, wavpack_enc->mode); g_value_set_enum (value, enc->mode);
break; break;
case ARG_BITRATE: case ARG_BITRATE:
if (wavpack_enc->bitrate >= 24000.0) { if (enc->bitrate >= 24000.0) {
g_value_set_double (value, wavpack_enc->bitrate); g_value_set_double (value, enc->bitrate);
} else { } else {
g_value_set_double (value, 0.0); g_value_set_double (value, 0.0);
} }
break; break;
case ARG_BITSPERSAMPLE: case ARG_BITSPERSAMPLE:
if (wavpack_enc->bitrate <= 24.0) { if (enc->bitrate <= 24.0) {
g_value_set_double (value, wavpack_enc->bitrate); g_value_set_double (value, enc->bitrate);
} else { } else {
g_value_set_double (value, 0.0); g_value_set_double (value, 0.0);
} }
break; break;
case ARG_CORRECTION_MODE: case ARG_CORRECTION_MODE:
g_value_set_enum (value, wavpack_enc->correction_mode); g_value_set_enum (value, enc->correction_mode);
break; break;
case ARG_MD5: case ARG_MD5:
g_value_set_boolean (value, wavpack_enc->md5); g_value_set_boolean (value, enc->md5);
break; break;
case ARG_EXTRA_PROCESSING: case ARG_EXTRA_PROCESSING:
g_value_set_boolean (value, wavpack_enc->extra_processing); g_value_set_boolean (value, enc->extra_processing);
break; break;
case ARG_JOINT_STEREO_MODE: case ARG_JOINT_STEREO_MODE:
g_value_set_enum (value, wavpack_enc->joint_stereo_mode); g_value_set_enum (value, enc->joint_stereo_mode);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);

View file

@ -28,7 +28,8 @@
#include <wavpack/md5.h> #include <wavpack/md5.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/* #define's don't like whitespacey bits */
/* defines don't like whitespacey bits */
#define GST_TYPE_WAVPACK_ENC \ #define GST_TYPE_WAVPACK_ENC \
(gst_wavpack_enc_get_type()) (gst_wavpack_enc_get_type())
#define GST_WAVPACK_ENC(obj) \ #define GST_WAVPACK_ENC(obj) \
@ -39,6 +40,7 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WAVPACK_ENC)) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WAVPACK_ENC))
#define GST_IS_WAVPACK_ENC_CLASS(obj) \ #define GST_IS_WAVPACK_ENC_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WAVPACK_ENC)) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WAVPACK_ENC))
typedef struct _GstWavpackEnc GstWavpackEnc; typedef struct _GstWavpackEnc GstWavpackEnc;
typedef struct _GstWavpackEncClass GstWavpackEncClass; typedef struct _GstWavpackEncClass GstWavpackEncClass;
@ -46,7 +48,7 @@ typedef struct
{ {
gboolean correction; gboolean correction;
GstWavpackEnc *wavpack_enc; GstWavpackEnc *wavpack_enc;
} write_id; } GstWavpackEncWriteID;
struct _GstWavpackEnc struct _GstWavpackEnc
@ -66,7 +68,8 @@ struct _GstWavpackEnc
gint channels; gint channels;
gint width; gint width;
write_id *wv_id, *wvc_id; GstWavpackEncWriteID *wv_id;
GstWavpackEncWriteID *wvc_id;
guint mode; guint mode;
gdouble bitrate; gdouble bitrate;
@ -90,4 +93,5 @@ GType gst_wavpack_enc_get_type (void);
gboolean gst_wavpack_enc_plugin_init (GstPlugin * plugin); gboolean gst_wavpack_enc_plugin_init (GstPlugin * plugin);
G_END_DECLS G_END_DECLS
#endif /* __GST_WAVPACK_ENC_H__ */ #endif /* __GST_WAVPACK_ENC_H__ */

View file

@ -64,7 +64,7 @@ gst_wavpack_parse_sink_activate_pull (GstPad * sinkpad, gboolean active);
static void gst_wavpack_parse_loop (GstElement * element); static void gst_wavpack_parse_loop (GstElement * element);
static GstStateChangeReturn gst_wavpack_parse_change_state (GstElement * static GstStateChangeReturn gst_wavpack_parse_change_state (GstElement *
element, GstStateChange transition); element, GstStateChange transition);
static void gst_wavpack_parse_reset (GstWavpackParse * wavpackparse); static void gst_wavpack_parse_reset (GstWavpackParse * parse);
static gint64 gst_wavpack_parse_get_upstream_length (GstWavpackParse * wvparse); static gint64 gst_wavpack_parse_get_upstream_length (GstWavpackParse * wvparse);
static GstBuffer *gst_wavpack_parse_pull_buffer (GstWavpackParse * wvparse, static GstBuffer *gst_wavpack_parse_pull_buffer (GstWavpackParse * wvparse,
gint64 offset, guint size, GstFlowReturn * flow); gint64 offset, guint size, GstFlowReturn * flow);
@ -187,44 +187,42 @@ gst_wavpack_parse_index_append_entry (GstWavpackParse * wvparse,
} }
static void static void
gst_wavpack_parse_reset (GstWavpackParse * wavpackparse) gst_wavpack_parse_reset (GstWavpackParse * parse)
{ {
wavpackparse->total_samples = -1; parse->total_samples = -1;
wavpackparse->samplerate = 0; parse->samplerate = 0;
wavpackparse->channels = 0; parse->channels = 0;
gst_segment_init (&wavpackparse->segment, GST_FORMAT_UNDEFINED); gst_segment_init (&parse->segment, GST_FORMAT_UNDEFINED);
wavpackparse->current_offset = 0; parse->current_offset = 0;
wavpackparse->need_newsegment = TRUE; parse->need_newsegment = TRUE;
wavpackparse->upstream_length = -1; parse->upstream_length = -1;
if (wavpackparse->entries) { if (parse->entries) {
g_array_free (wavpackparse->entries, TRUE); g_array_free (parse->entries, TRUE);
wavpackparse->entries = NULL; parse->entries = NULL;
} }
if (wavpackparse->adapter) { if (parse->adapter) {
gst_adapter_clear (wavpackparse->adapter); gst_adapter_clear (parse->adapter);
g_object_unref (wavpackparse->adapter); g_object_unref (parse->adapter);
wavpackparse->adapter = NULL; parse->adapter = NULL;
} }
if (wavpackparse->srcpad != NULL) { if (parse->srcpad != NULL) {
gboolean res; gboolean res;
GST_DEBUG_OBJECT (wavpackparse, "Removing src pad"); GST_DEBUG_OBJECT (parse, "Removing src pad");
res = gst_element_remove_pad (GST_ELEMENT (wavpackparse), res = gst_element_remove_pad (GST_ELEMENT (parse), parse->srcpad);
wavpackparse->srcpad);
g_return_if_fail (res != FALSE); g_return_if_fail (res != FALSE);
gst_object_unref (wavpackparse->srcpad); gst_object_unref (parse->srcpad);
wavpackparse->srcpad = NULL; parse->srcpad = NULL;
} }
g_list_foreach (wavpackparse->queued_events, (GFunc) gst_mini_object_unref, g_list_foreach (parse->queued_events, (GFunc) gst_mini_object_unref, NULL);
NULL); g_list_free (parse->queued_events);
g_list_free (wavpackparse->queued_events); parse->queued_events = NULL;
wavpackparse->queued_events = NULL;
} }
static const GstQueryType * static const GstQueryType *
@ -243,7 +241,7 @@ gst_wavpack_parse_get_src_query_types (GstPad * pad)
static gboolean static gboolean
gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query) gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
{ {
GstWavpackParse *wavpackparse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad)); GstWavpackParse *parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
GstFormat format; GstFormat format;
gboolean ret = FALSE; gboolean ret = FALSE;
@ -252,14 +250,14 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
gint64 cur, len; gint64 cur, len;
guint rate; guint rate;
GST_OBJECT_LOCK (wavpackparse); GST_OBJECT_LOCK (parse);
cur = wavpackparse->segment.last_stop; cur = parse->segment.last_stop;
len = wavpackparse->total_samples; len = parse->total_samples;
rate = wavpackparse->samplerate; rate = parse->samplerate;
GST_OBJECT_UNLOCK (wavpackparse); GST_OBJECT_UNLOCK (parse);
if (len <= 0 || rate == 0) { if (len <= 0 || rate == 0) {
GST_DEBUG_OBJECT (wavpackparse, "haven't read header yet"); GST_DEBUG_OBJECT (parse, "haven't read header yet");
break; break;
} }
@ -276,7 +274,7 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
ret = TRUE; ret = TRUE;
break; break;
default: default:
GST_DEBUG_OBJECT (wavpackparse, "cannot handle position query in " GST_DEBUG_OBJECT (parse, "cannot handle position query in "
"%s format", gst_format_get_name (format)); "%s format", gst_format_get_name (format));
break; break;
} }
@ -286,15 +284,15 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
gint64 len; gint64 len;
guint rate; guint rate;
GST_OBJECT_LOCK (wavpackparse); GST_OBJECT_LOCK (parse);
rate = wavpackparse->samplerate; rate = parse->samplerate;
/* FIXME: return 0 if we work in push based mode to let totem /* FIXME: return 0 if we work in push based mode to let totem
* recognize that we can't seek */ * recognize that we can't seek */
len = (wavpackparse->adapter) ? 0 : wavpackparse->total_samples; len = (parse->adapter) ? 0 : parse->total_samples;
GST_OBJECT_UNLOCK (wavpackparse); GST_OBJECT_UNLOCK (parse);
if (len < 0 || rate == 0) { if (len < 0 || rate == 0) {
GST_DEBUG_OBJECT (wavpackparse, "haven't read header yet"); GST_DEBUG_OBJECT (parse, "haven't read header yet");
break; break;
} }
@ -311,7 +309,7 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
ret = TRUE; ret = TRUE;
break; break;
default: default:
GST_DEBUG_OBJECT (wavpackparse, "cannot handle duration query in " GST_DEBUG_OBJECT (parse, "cannot handle duration query in "
"%s format", gst_format_get_name (format)); "%s format", gst_format_get_name (format));
break; break;
} }
@ -326,9 +324,9 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
gst_pad_query_duration (pad, &format, &duration); gst_pad_query_duration (pad, &format, &duration);
/* can't seek in streaming mode yet */ /* can't seek in streaming mode yet */
GST_OBJECT_LOCK (wavpackparse); GST_OBJECT_LOCK (parse);
seekable = (wavpackparse->adapter != NULL); seekable = (parse->adapter != NULL);
GST_OBJECT_UNLOCK (wavpackparse); GST_OBJECT_UNLOCK (parse);
gst_query_set_seeking (query, GST_FORMAT_TIME, seekable, 0, duration); gst_query_set_seeking (query, GST_FORMAT_TIME, seekable, 0, duration);
ret = TRUE; ret = TRUE;
@ -341,7 +339,7 @@ gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
} }
} }
gst_object_unref (wavpackparse); gst_object_unref (parse);
return ret; return ret;
} }
@ -632,57 +630,56 @@ gst_wavpack_parse_sink_event (GstPad * pad, GstEvent * event)
static gboolean static gboolean
gst_wavpack_parse_src_event (GstPad * pad, GstEvent * event) gst_wavpack_parse_src_event (GstPad * pad, GstEvent * event)
{ {
GstWavpackParse *wavpackparse; GstWavpackParse *parse;
gboolean ret; gboolean ret;
wavpackparse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad)); parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_SEEK: case GST_EVENT_SEEK:
ret = gst_wavpack_parse_handle_seek_event (wavpackparse, event); ret = gst_wavpack_parse_handle_seek_event (parse, event);
break; break;
default: default:
ret = gst_pad_event_default (pad, event); ret = gst_pad_event_default (pad, event);
break; break;
} }
gst_object_unref (wavpackparse); gst_object_unref (parse);
return ret; return ret;
} }
static void static void
gst_wavpack_parse_init (GstWavpackParse * wavpackparse, gst_wavpack_parse_init (GstWavpackParse * parse, GstWavpackParseClass * gclass)
GstWavpackParseClass * gclass)
{ {
GstElementClass *klass = GST_ELEMENT_GET_CLASS (wavpackparse); GstElementClass *klass = GST_ELEMENT_GET_CLASS (parse);
GstPadTemplate *tmpl; GstPadTemplate *tmpl;
tmpl = gst_element_class_get_pad_template (klass, "sink"); tmpl = gst_element_class_get_pad_template (klass, "sink");
wavpackparse->sinkpad = gst_pad_new_from_template (tmpl, "sink"); parse->sinkpad = gst_pad_new_from_template (tmpl, "sink");
gst_pad_set_activate_function (wavpackparse->sinkpad, gst_pad_set_activate_function (parse->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_activate)); GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_activate));
gst_pad_set_activatepull_function (wavpackparse->sinkpad, gst_pad_set_activatepull_function (parse->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_activate_pull)); GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_activate_pull));
gst_pad_set_event_function (wavpackparse->sinkpad, gst_pad_set_event_function (parse->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_event)); GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_event));
gst_pad_set_chain_function (wavpackparse->sinkpad, gst_pad_set_chain_function (parse->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_parse_chain)); GST_DEBUG_FUNCPTR (gst_wavpack_parse_chain));
gst_element_add_pad (GST_ELEMENT (wavpackparse), wavpackparse->sinkpad); gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad);
wavpackparse->srcpad = NULL; parse->srcpad = NULL;
gst_wavpack_parse_reset (wavpackparse); gst_wavpack_parse_reset (parse);
} }
static gint64 static gint64
gst_wavpack_parse_get_upstream_length (GstWavpackParse * wavpackparse) gst_wavpack_parse_get_upstream_length (GstWavpackParse * parse)
{ {
gint64 length = -1; gint64 length = -1;
GstFormat format = GST_FORMAT_BYTES; GstFormat format = GST_FORMAT_BYTES;
if (!gst_pad_query_peer_duration (wavpackparse->sinkpad, &format, &length)) { if (!gst_pad_query_peer_duration (parse->sinkpad, &format, &length)) {
length = -1; length = -1;
} else { } else {
GST_DEBUG ("upstream length: %" G_GINT64_FORMAT, length); GST_DEBUG ("upstream length: %" G_GINT64_FORMAT, length);
@ -943,12 +940,12 @@ gst_wavpack_parse_resync_loop (GstWavpackParse * parse, WavpackHeader * header)
static void static void
gst_wavpack_parse_loop (GstElement * element) gst_wavpack_parse_loop (GstElement * element)
{ {
GstWavpackParse *wavpackparse = GST_WAVPACK_PARSE (element); GstWavpackParse *parse = GST_WAVPACK_PARSE (element);
GstFlowReturn flow_ret; GstFlowReturn flow_ret;
WavpackHeader header = { {0,}, 0, }; WavpackHeader header = { {0,}, 0, };
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
flow_ret = gst_wavpack_parse_resync_loop (wavpackparse, &header); flow_ret = gst_wavpack_parse_resync_loop (parse, &header);
if (flow_ret == GST_FLOW_UNEXPECTED) { if (flow_ret == GST_FLOW_UNEXPECTED) {
goto eos; goto eos;
@ -956,11 +953,11 @@ gst_wavpack_parse_loop (GstElement * element)
goto pause; goto pause;
} }
GST_LOG_OBJECT (wavpackparse, "Read header at offset %" G_GINT64_FORMAT GST_LOG_OBJECT (parse, "Read header at offset %" G_GINT64_FORMAT
": chunk size = %u+8", wavpackparse->current_offset, header.ckSize); ": chunk size = %u+8", parse->current_offset, header.ckSize);
buf = gst_wavpack_parse_pull_buffer (wavpackparse, buf = gst_wavpack_parse_pull_buffer (parse, parse->current_offset,
wavpackparse->current_offset, header.ckSize + 8, &flow_ret); header.ckSize + 8, &flow_ret);
if (buf == NULL && flow_ret == GST_FLOW_UNEXPECTED) { if (buf == NULL && flow_ret == GST_FLOW_UNEXPECTED) {
goto eos; goto eos;
@ -968,19 +965,19 @@ gst_wavpack_parse_loop (GstElement * element)
goto pause; goto pause;
} }
if (wavpackparse->srcpad == NULL) { if (parse->srcpad == NULL) {
if (!gst_wavpack_parse_create_src_pad (wavpackparse, buf, &header)) { if (!gst_wavpack_parse_create_src_pad (parse, buf, &header)) {
GST_ELEMENT_ERROR (wavpackparse, STREAM, DECODE, (NULL), (NULL)); GST_ELEMENT_ERROR (parse, STREAM, DECODE, (NULL), (NULL));
goto pause; goto pause;
} }
} }
gst_wavpack_parse_index_append_entry (wavpackparse, gst_wavpack_parse_index_append_entry (parse, parse->current_offset,
wavpackparse->current_offset, header.block_index, header.block_samples); header.block_index, header.block_samples);
flow_ret = gst_wavpack_parse_push_buffer (wavpackparse, buf, &header); flow_ret = gst_wavpack_parse_push_buffer (parse, buf, &header);
if (flow_ret != GST_FLOW_OK) { if (flow_ret != GST_FLOW_OK) {
GST_DEBUG_OBJECT (wavpackparse, "Push failed, flow: %s", GST_DEBUG_OBJECT (parse, "Push failed, flow: %s",
gst_flow_get_name (flow_ret)); gst_flow_get_name (flow_ret));
goto pause; goto pause;
} }
@ -989,16 +986,16 @@ gst_wavpack_parse_loop (GstElement * element)
eos: eos:
{ {
GST_DEBUG_OBJECT (wavpackparse, "sending EOS"); GST_DEBUG_OBJECT (parse, "sending EOS");
if (wavpackparse->srcpad) { if (parse->srcpad) {
gst_pad_push_event (wavpackparse->srcpad, gst_event_new_eos ()); gst_pad_push_event (parse->srcpad, gst_event_new_eos ());
} }
/* fall through and pause task */ /* fall through and pause task */
} }
pause: pause:
{ {
GST_DEBUG_OBJECT (wavpackparse, "Pausing task"); GST_DEBUG_OBJECT (parse, "Pausing task");
gst_pad_pause_task (wavpackparse->sinkpad); gst_pad_pause_task (parse->sinkpad);
return; return;
} }
} }