ext/wavpack/gstwavpackdec.*: More clean-ups: remove most of the disfunctional correction pad stuff for now, if it eve...

Original commit message from CVS:
* ext/wavpack/gstwavpackdec.c: (gst_wavpack_dec_base_init),
(gst_wavpack_dec_class_init), (gst_wavpack_dec_init),
(gst_wavpack_dec_finalize), (gst_wavpack_dec_format_samples),
(gst_wavpack_dec_clip_outgoing_buffer), (gst_wavpack_dec_chain),
(gst_wavpack_dec_sink_event), (gst_wavpack_dec_change_state):
* ext/wavpack/gstwavpackdec.h:
More clean-ups: remove most of the disfunctional correction
pad stuff for now, if it ever gets implemented a lot of stuff
will have to be rewritten anyway; redo chain function, move
errors to end, error out instead of g_assert()ing. Also rename
overly long variable 'wavpackdec' to just 'dec'; miscellaneous
other small stuff.
This commit is contained in:
Tim-Philipp Müller 2006-07-18 15:53:35 +00:00
parent 8dd45c0027
commit 37fe4c9cc7
3 changed files with 159 additions and 271 deletions

View file

@ -1,3 +1,18 @@
2006-07-18 Tim-Philipp Müller <tim at centricular dot net>
* ext/wavpack/gstwavpackdec.c: (gst_wavpack_dec_base_init),
(gst_wavpack_dec_class_init), (gst_wavpack_dec_init),
(gst_wavpack_dec_finalize), (gst_wavpack_dec_format_samples),
(gst_wavpack_dec_clip_outgoing_buffer), (gst_wavpack_dec_chain),
(gst_wavpack_dec_sink_event), (gst_wavpack_dec_change_state):
* ext/wavpack/gstwavpackdec.h:
More clean-ups: remove most of the disfunctional correction
pad stuff for now, if it ever gets implemented a lot of stuff
will have to be rewritten anyway; redo chain function, move
errors to end, error out instead of g_assert()ing. Also rename
overly long variable 'wavpackdec' to just 'dec'; miscellaneous
other small stuff.
2006-07-18 Tim-Philipp Müller <tim at centricular dot net> 2006-07-18 Tim-Philipp Müller <tim at centricular dot net>
Patch by: Sebastian Dröge <slomo at circular-chaos.org> Patch by: Sebastian Dröge <slomo at circular-chaos.org>

View file

@ -47,15 +47,6 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
"rate = (int) [ 6000, 192000 ], " "framed = (boolean) true") "rate = (int) [ 6000, 192000 ], " "framed = (boolean) true")
); );
#if 0
static GstStaticPadTemplate wvc_sink_factory =
GST_STATIC_PAD_TEMPLATE ("wvcsink",
GST_PAD_SINK,
GST_PAD_REQUEST,
GST_STATIC_CAPS ("audio/x-wavpack-correction, " "framed = (boolean) true")
);
#endif
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
@ -74,24 +65,8 @@ static GstStateChangeReturn gst_wavpack_dec_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
static gboolean gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event); static gboolean gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event);
#if 0
static GstPad *gst_wavpack_dec_request_new_pad (GstElement * element,
GstPadTemplate * templ, const gchar * name);
#endif
GST_BOILERPLATE (GstWavpackDec, gst_wavpack_dec, GstElement, GST_TYPE_ELEMENT); GST_BOILERPLATE (GstWavpackDec, gst_wavpack_dec, GstElement, GST_TYPE_ELEMENT);
#if 0
static GstPadLinkReturn
gst_wavpack_dec_wvclink (GstPad * pad, GstPad * peer)
{
if (!gst_caps_is_fixed (GST_PAD_CAPS (peer)))
return GST_PAD_LINK_REFUSED;
return GST_PAD_LINK_OK;
}
#endif
static void static void
gst_wavpack_dec_base_init (gpointer klass) gst_wavpack_dec_base_init (gpointer klass)
{ {
@ -107,10 +82,6 @@ gst_wavpack_dec_base_init (gpointer klass)
gst_static_pad_template_get (&src_factory)); gst_static_pad_template_get (&src_factory));
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory)); gst_static_pad_template_get (&sink_factory));
#if 0
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&wvc_sink_factory));
#endif
gst_element_class_set_details (element_class, &plugin_details); gst_element_class_set_details (element_class, &plugin_details);
} }
@ -122,93 +93,76 @@ gst_wavpack_dec_class_init (GstWavpackDecClass * klass)
gstelement_class->change_state = gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_wavpack_dec_change_state); GST_DEBUG_FUNCPTR (gst_wavpack_dec_change_state);
#if 0
gstelement_class->request_new_pad =
GST_DEBUG_FUNCPTR (gst_wavpack_dec_request_new_pad);
#endif
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wavpack_dec_finalize); gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wavpack_dec_finalize);
} }
static void static void
gst_wavpack_dec_init (GstWavpackDec * wavpackdec, GstWavpackDecClass * gklass) gst_wavpack_dec_init (GstWavpackDec * dec, GstWavpackDecClass * gklass)
{ {
GstElementClass *klass = GST_ELEMENT_GET_CLASS (wavpackdec); dec->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
gst_pad_set_chain_function (dec->sinkpad,
wavpackdec->sinkpad =
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
"sink"), "sink");
gst_pad_set_chain_function (wavpackdec->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_dec_chain)); GST_DEBUG_FUNCPTR (gst_wavpack_dec_chain));
gst_pad_set_event_function (wavpackdec->sinkpad, gst_pad_set_event_function (dec->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavpack_dec_sink_event)); GST_DEBUG_FUNCPTR (gst_wavpack_dec_sink_event));
gst_element_add_pad (GST_ELEMENT (wavpackdec), wavpackdec->sinkpad); gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
wavpackdec->srcpad = dec->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
gst_pad_new_from_template (gst_element_class_get_pad_template (klass, gst_pad_use_fixed_caps (dec->srcpad);
"src"), "src"); gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
gst_pad_use_fixed_caps (wavpackdec->srcpad);
gst_element_add_pad (GST_ELEMENT (wavpackdec), wavpackdec->srcpad);
wavpackdec->context = NULL; dec->context = NULL;
wavpackdec->stream_reader = gst_wavpack_stream_reader_new (); dec->stream_reader = gst_wavpack_stream_reader_new ();
wavpackdec->wv_id.buffer = NULL; dec->wv_id.buffer = NULL;
wavpackdec->wv_id.position = wavpackdec->wv_id.length = 0; dec->wv_id.position = dec->wv_id.length = 0;
/* dec->error_count = 0;
wavpackdec->wvc_id.buffer = NULL;
wavpackdec->wvc_id.position = wavpackdec->wvc_id.length = 0;
wavpackdec->wvcsinkpad = NULL;
*/
wavpackdec->error_count = 0; dec->channels = 0;
dec->sample_rate = 0;
dec->width = 0;
gst_segment_init (&dec->segment, GST_FORMAT_UNDEFINED);
wavpackdec->channels = 0;
wavpackdec->sample_rate = 0;
wavpackdec->width = 0;
gst_segment_init (&wavpackdec->segment, GST_FORMAT_UNDEFINED);
} }
static void static void
gst_wavpack_dec_finalize (GObject * object) gst_wavpack_dec_finalize (GObject * object)
{ {
GstWavpackDec *wavpackdec = GST_WAVPACK_DEC (object); GstWavpackDec *dec = GST_WAVPACK_DEC (object);
g_free (wavpackdec->stream_reader); g_free (dec->stream_reader);
wavpackdec->stream_reader = NULL; dec->stream_reader = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
static void static void
gst_wavpack_dec_format_samples (GstWavpackDec * wavpackdec, guint8 * dst, gst_wavpack_dec_format_samples (GstWavpackDec * dec, guint8 * dst,
int32_t * samples, guint num_samples) int32_t * samples, guint num_samples)
{ {
gint i; gint i;
int32_t temp; int32_t temp;
switch (wavpackdec->width) { switch (dec->width) {
case 8: case 8:
for (i = 0; i < num_samples * wavpackdec->channels; ++i) for (i = 0; i < num_samples * dec->channels; ++i)
*dst++ = (guint8) (*samples++); *dst++ = (guint8) (*samples++);
break; break;
case 16: case 16:
for (i = 0; i < num_samples * wavpackdec->channels; ++i) { for (i = 0; i < num_samples * dec->channels; ++i) {
*dst++ = (guint8) (temp = *samples++); *dst++ = (guint8) (temp = *samples++);
*dst++ = (guint8) (temp >> 8); *dst++ = (guint8) (temp >> 8);
} }
break; break;
case 24: case 24:
for (i = 0; i < num_samples * wavpackdec->channels; ++i) { for (i = 0; i < num_samples * dec->channels; ++i) {
*dst++ = (guint8) (temp = *samples++); *dst++ = (guint8) (temp = *samples++);
*dst++ = (guint8) (temp >> 8); *dst++ = (guint8) (temp >> 8);
*dst++ = (guint8) (temp >> 16); *dst++ = (guint8) (temp >> 16);
} }
break; break;
case 32: case 32:
for (i = 0; i < num_samples * wavpackdec->channels; ++i) { for (i = 0; i < num_samples * dec->channels; ++i) {
*dst++ = (guint8) (temp = *samples++); *dst++ = (guint8) (temp = *samples++);
*dst++ = (guint8) (temp >> 8); *dst++ = (guint8) (temp >> 8);
*dst++ = (guint8) (temp >> 16); *dst++ = (guint8) (temp >> 16);
@ -221,18 +175,17 @@ gst_wavpack_dec_format_samples (GstWavpackDec * wavpackdec, guint8 * dst,
} }
static gboolean static gboolean
gst_wavpack_dec_clip_outgoing_buffer (GstWavpackDec * wavpackdec, gst_wavpack_dec_clip_outgoing_buffer (GstWavpackDec * dec, GstBuffer * buf)
GstBuffer * buf)
{ {
gint64 start, stop, cstart, cstop, diff; gint64 start, stop, cstart, cstop, diff;
if (wavpackdec->segment.format != GST_FORMAT_TIME) if (dec->segment.format != GST_FORMAT_TIME)
return TRUE; return TRUE;
start = GST_BUFFER_TIMESTAMP (buf); start = GST_BUFFER_TIMESTAMP (buf);
stop = start + GST_BUFFER_DURATION (buf); stop = start + GST_BUFFER_DURATION (buf);
if (gst_segment_clip (&wavpackdec->segment, GST_FORMAT_TIME, if (gst_segment_clip (&dec->segment, GST_FORMAT_TIME,
start, stop, &cstart, &cstop)) { start, stop, &cstart, &cstop)) {
diff = cstart - start; diff = cstart - start;
@ -240,8 +193,8 @@ gst_wavpack_dec_clip_outgoing_buffer (GstWavpackDec * wavpackdec,
GST_BUFFER_TIMESTAMP (buf) = cstart; GST_BUFFER_TIMESTAMP (buf) = cstart;
GST_BUFFER_DURATION (buf) -= diff; GST_BUFFER_DURATION (buf) -= diff;
diff = ((wavpackdec->width + 7) >> 3) * wavpackdec->channels diff = ((dec->width + 7) >> 3) * dec->channels
* GST_CLOCK_TIME_TO_FRAMES (diff, wavpackdec->sample_rate); * GST_CLOCK_TIME_TO_FRAMES (diff, dec->sample_rate);
GST_BUFFER_DATA (buf) += diff; GST_BUFFER_DATA (buf) += diff;
GST_BUFFER_SIZE (buf) -= diff; GST_BUFFER_SIZE (buf) -= diff;
} }
@ -250,12 +203,12 @@ gst_wavpack_dec_clip_outgoing_buffer (GstWavpackDec * wavpackdec,
if (diff > 0) { if (diff > 0) {
GST_BUFFER_DURATION (buf) -= diff; GST_BUFFER_DURATION (buf) -= diff;
diff = ((wavpackdec->width + 7) >> 3) * wavpackdec->channels diff = ((dec->width + 7) >> 3) * dec->channels
* GST_CLOCK_TIME_TO_FRAMES (diff, wavpackdec->sample_rate); * GST_CLOCK_TIME_TO_FRAMES (diff, dec->sample_rate);
GST_BUFFER_SIZE (buf) -= diff; GST_BUFFER_SIZE (buf) -= diff;
} }
} else { } else {
GST_DEBUG_OBJECT (wavpackdec, "buffer is outside configured segment"); GST_DEBUG_OBJECT (dec, "buffer is outside configured segment");
return FALSE; return FALSE;
} }
@ -265,198 +218,149 @@ gst_wavpack_dec_clip_outgoing_buffer (GstWavpackDec * wavpackdec,
static GstFlowReturn static GstFlowReturn
gst_wavpack_dec_chain (GstPad * pad, GstBuffer * buf) gst_wavpack_dec_chain (GstPad * pad, GstBuffer * buf)
{ {
GstWavpackDec *dec;
GstWavpackDec *wavpackdec;
GstBuffer *outbuf; GstBuffer *outbuf;
GstBuffer *cbuf = NULL;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
WavpackHeader wph; WavpackHeader wph;
int32_t *unpack_buf; int32_t *unpack_buf = NULL;
int32_t unpacked_sample_count; int32_t decoded, unpacked_size;
gboolean format_changed;
wavpackdec = GST_WAVPACK_DEC (GST_PAD_PARENT (pad)); dec = GST_WAVPACK_DEC (GST_PAD_PARENT (pad));
/* we only accept framed input with complete chunks */ /* check input, we only accept framed input with complete chunks */
g_assert (GST_BUFFER_SIZE (buf) >= sizeof (WavpackHeader)); if (GST_BUFFER_SIZE (buf) < sizeof (WavpackHeader))
gst_wavpack_read_header (&wph, GST_BUFFER_DATA (buf)); goto input_not_framed;
g_assert (GST_BUFFER_SIZE (buf) ==
wph.ckSize + 4 * sizeof (char) + sizeof (uint32_t));
wavpackdec->wv_id.buffer = GST_BUFFER_DATA (buf); if (!gst_wavpack_read_header (&wph, GST_BUFFER_DATA (buf)))
wavpackdec->wv_id.length = GST_BUFFER_SIZE (buf); goto invalid_header;
wavpackdec->wv_id.position = 0;
#if 0 if (GST_BUFFER_SIZE (buf) != wph.ckSize + 4 * 1 + 4)
/* check whether the correction pad is linked and we can get goto input_not_framed;
* the correction chunk that corresponds to our current data */
if (gst_pad_is_linked (wavpackdec->wvcsinkpad)) { dec->wv_id.buffer = GST_BUFFER_DATA (buf);
if (GST_FLOW_OK != gst_pad_pull_range (wavpackdec->wvcsinkpad, dec->wv_id.length = GST_BUFFER_SIZE (buf);
GST_BUFFER_OFFSET (buf), -1, &cbuf)) { dec->wv_id.position = 0;
cbuf = NULL;
} else {
/* this won't work (tpm) */
if (!(GST_BUFFER_TIMESTAMP (cbuf) == GST_BUFFER_TIMESTAMP (buf)) ||
!(GST_BUFFER_DURATION (cbuf) == GST_BUFFER_DURATION (buf)) ||
!(GST_BUFFER_OFFSET (cbuf) == GST_BUFFER_OFFSET (buf)) ||
!(GST_BUFFER_OFFSET_END (cbuf) == GST_BUFFER_OFFSET (buf))) {
gst_buffer_unref (cbuf);
cbuf = NULL;
} else {
wavpackdec->wvc_id.buffer = GST_BUFFER_DATA (cbuf);
wavpackdec->wvc_id.length = GST_BUFFER_SIZE (cbuf);
wavpackdec->wvc_id.position = 0;
}
}
}
#endif
/* create a new wavpack context if there is none yet but if there /* create a new wavpack context if there is none yet but if there
* was already one (i.e. caps were set on the srcpad) check whether * was already one (i.e. caps were set on the srcpad) check whether
* the new one has the same caps */ * the new one has the same caps */
if (!wavpackdec->context) { if (!dec->context) {
gchar error_msg[80]; gchar error_msg[80];
/* dec->context = WavpackOpenFileInputEx (dec->stream_reader,
wavpackdec->context = &dec->wv_id, NULL, error_msg, OPEN_STREAMING, 0);
WavpackOpenFileInputEx (wavpackdec->stream_reader, &wavpackdec->wv_id,
(cbuf) ? &wavpackdec->wvc_id : NULL, error_msg, OPEN_STREAMING, 0);
*/
wavpackdec->context = WavpackOpenFileInputEx (wavpackdec->stream_reader, if (!dec->context) {
&wavpackdec->wv_id, NULL, error_msg, OPEN_STREAMING, 0); GST_WARNING ("Couldn't decode buffer: %s", error_msg);
dec->error_count++;
if (!wavpackdec->context) { if (dec->error_count <= WAVPACK_DEC_MAX_ERRORS) {
wavpackdec->error_count++; goto out; /* just return OK for now */
GST_ELEMENT_WARNING (wavpackdec, LIBRARY, INIT, (NULL),
("Couldn't open buffer for decoding: %s", error_msg));
if (wavpackdec->error_count <= WAVPACK_DEC_MAX_ERRORS) {
ret = GST_FLOW_OK;
} else { } else {
ret = GST_FLOW_ERROR; goto decode_error;
}
gst_buffer_unref (buf);
if (cbuf) {
gst_buffer_unref (cbuf);
}
return ret;
}
if (GST_PAD_CAPS (wavpackdec->srcpad)) {
if ((wavpackdec->sample_rate !=
WavpackGetSampleRate (wavpackdec->context))
|| (wavpackdec->channels !=
WavpackGetNumChannels (wavpackdec->context))
|| (wavpackdec->width !=
WavpackGetBitsPerSample (wavpackdec->context))) {
gst_buffer_unref (buf);
if (cbuf) {
gst_buffer_unref (cbuf);
}
/* FIXME: use the right error */
GST_ELEMENT_ERROR (wavpackdec, LIBRARY, INIT, (NULL),
("Got Wavpack chunk with changed format settings!"));
return GST_FLOW_ERROR;
} }
} }
} }
wavpackdec->error_count = 0;
if (!GST_PAD_CAPS (wavpackdec->srcpad)) { g_assert (dec->context != NULL);
dec->error_count = 0;
format_changed =
(dec->sample_rate != WavpackGetSampleRate (dec->context)) ||
(dec->channels != WavpackGetNumChannels (dec->context)) ||
(dec->width != WavpackGetBitsPerSample (dec->context));
if (!GST_PAD_CAPS (dec->srcpad) || format_changed) {
GstCaps *caps; GstCaps *caps;
g_assert (wavpackdec->context); dec->sample_rate = WavpackGetSampleRate (dec->context);
dec->channels = WavpackGetNumChannels (dec->context);
dec->width = WavpackGetBitsPerSample (dec->context);
wavpackdec->sample_rate = WavpackGetSampleRate (wavpackdec->context);
wavpackdec->channels = WavpackGetNumChannels (wavpackdec->context);
wavpackdec->width = WavpackGetBitsPerSample (wavpackdec->context);
caps = gst_caps_new_simple ("audio/x-raw-int", caps = gst_caps_new_simple ("audio/x-raw-int",
"rate", G_TYPE_INT, wavpackdec->sample_rate, "rate", G_TYPE_INT, dec->sample_rate,
"channels", G_TYPE_INT, wavpackdec->channels, "channels", G_TYPE_INT, dec->channels,
"depth", G_TYPE_INT, wavpackdec->width, "depth", G_TYPE_INT, dec->width,
"width", G_TYPE_INT, wavpackdec->width, "width", G_TYPE_INT, dec->width,
"endianness", G_TYPE_INT, G_LITTLE_ENDIAN, "endianness", G_TYPE_INT, G_LITTLE_ENDIAN,
"signed", G_TYPE_BOOLEAN, TRUE, NULL); "signed", G_TYPE_BOOLEAN, TRUE, NULL);
if (!gst_pad_set_caps (wavpackdec->srcpad, caps)) { GST_DEBUG_OBJECT (dec, "setting caps %" GST_PTR_FORMAT, caps);
gst_caps_unref (caps);
WavpackCloseFile (wavpackdec->context); /* should always succeed */
wavpackdec->context = NULL; gst_pad_set_caps (dec->srcpad, caps);
gst_buffer_unref (buf);
if (cbuf) {
gst_buffer_unref (cbuf);
}
/* FIXME: use the right error */
GST_ELEMENT_ERROR (wavpackdec, LIBRARY, INIT, (NULL),
("Couldn't set caps on source pad: %" GST_PTR_FORMAT, caps));
return GST_FLOW_ERROR;
}
gst_caps_unref (caps); gst_caps_unref (caps);
gst_pad_use_fixed_caps (wavpackdec->srcpad);
} }
g_assert (wavpackdec->context); unpacked_size = wph.block_samples * ((dec->width + 7) >> 3) * dec->channels;
unpack_buf =
(int32_t *) g_malloc (sizeof (int32_t) * wph.block_samples *
wavpackdec->channels);
unpacked_sample_count =
WavpackUnpackSamples (wavpackdec->context, unpack_buf, wph.block_samples);
g_assert (unpacked_sample_count == wph.block_samples);
ret = /* alloc buffer */
gst_pad_alloc_buffer_and_set_caps (wavpackdec->srcpad, ret = gst_pad_alloc_buffer (dec->srcpad, GST_BUFFER_OFFSET (buf),
GST_BUFFER_OFFSET (buf), unpacked_size, GST_PAD_CAPS (dec->srcpad), &outbuf);
wph.block_samples * ((wavpackdec->width +
7) >> 3) * wavpackdec->channels,
GST_PAD_CAPS (wavpackdec->srcpad), &outbuf);
if (GST_FLOW_IS_FATAL (ret)) { if (ret != GST_FLOW_OK)
WavpackCloseFile (wavpackdec->context); goto out;
wavpackdec->context = NULL;
g_free (unpack_buf);
gst_buffer_unref (buf);
if (cbuf) {
gst_buffer_unref (cbuf);
}
return ret;
} else if (ret != GST_FLOW_OK) {
g_free (unpack_buf);
gst_buffer_unref (buf);
if (cbuf) {
gst_buffer_unref (cbuf);
}
return ret;
}
gst_wavpack_dec_format_samples (wavpackdec, GST_BUFFER_DATA (outbuf), /* decode */
unpack_buf = g_new (int32_t, wph.block_samples * dec->channels);
decoded = WavpackUnpackSamples (dec->context, unpack_buf, wph.block_samples);
if (decoded != wph.block_samples)
goto decode_error;
/* put samples into outbuf buffer */
gst_wavpack_dec_format_samples (dec, GST_BUFFER_DATA (outbuf),
unpack_buf, wph.block_samples); unpack_buf, wph.block_samples);
g_free (unpack_buf);
gst_buffer_stamp (outbuf, buf); gst_buffer_stamp (outbuf, buf);
gst_buffer_unref (buf);
if (cbuf) {
gst_buffer_unref (cbuf);
}
if (gst_wavpack_dec_clip_outgoing_buffer (wavpackdec, outbuf)) { if (gst_wavpack_dec_clip_outgoing_buffer (dec, outbuf)) {
GST_LOG_OBJECT (wavpackdec, "pushing buffer with time %" GST_TIME_FORMAT, GST_LOG_OBJECT (dec, "pushing buffer with time %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf))); GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)));
ret = gst_pad_push (wavpackdec->srcpad, outbuf); ret = gst_pad_push (dec->srcpad, outbuf);
if (ret != GST_FLOW_OK) {
GST_DEBUG_OBJECT (wavpackdec, "pad_push: %s", gst_flow_get_name (ret));
}
} else { } else {
gst_buffer_unref (outbuf); gst_buffer_unref (outbuf);
} }
out:
if (G_UNLIKELY (ret != GST_FLOW_OK)) {
GST_DEBUG_OBJECT (dec, "flow: %s", gst_flow_get_name (ret));
}
g_free (unpack_buf);
gst_buffer_unref (buf);
return ret; return ret;
/* ERRORS */
input_not_framed:
{
GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("Expected framed input"));
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
invalid_header:
{
GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("Invalid wavpack header"));
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
decode_error:
{
GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
("Failed to decode wavpack stream"));
g_free (unpack_buf);
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
} }
static gboolean static gboolean
gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event) gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event)
{ {
GstWavpackDec *wavpackdec = GST_WAVPACK_DEC (gst_pad_get_parent (pad)); GstWavpackDec *dec = GST_WAVPACK_DEC (gst_pad_get_parent (pad));
GST_LOG_OBJECT (wavpackdec, "Received %s event", GST_EVENT_TYPE_NAME (event)); GST_LOG_OBJECT (dec, "Received %s event", GST_EVENT_TYPE_NAME (event));
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NEWSEGMENT:{ case GST_EVENT_NEWSEGMENT:{
GstFormat fmt; GstFormat fmt;
@ -470,10 +374,10 @@ gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event)
GST_DEBUG ("Got NEWSEGMENT event in GST_FORMAT_TIME, passing on (%" GST_DEBUG ("Got NEWSEGMENT event in GST_FORMAT_TIME, passing on (%"
GST_TIME_FORMAT " - %" GST_TIME_FORMAT ")", GST_TIME_ARGS (start), GST_TIME_FORMAT " - %" GST_TIME_FORMAT ")", GST_TIME_ARGS (start),
GST_TIME_ARGS (end)); GST_TIME_ARGS (end));
gst_segment_set_newsegment (&wavpackdec->segment, is_update, rate, fmt, gst_segment_set_newsegment (&dec->segment, is_update, rate, fmt,
start, end, base); start, end, base);
} else { } else {
gst_segment_init (&wavpackdec->segment, GST_FORMAT_UNDEFINED); gst_segment_init (&dec->segment, GST_FORMAT_UNDEFINED);
} }
break; break;
} }
@ -481,7 +385,7 @@ gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event)
break; break;
} }
gst_object_unref (wavpackdec); gst_object_unref (dec);
return gst_pad_event_default (pad, event); return gst_pad_event_default (pad, event);
} }
@ -489,13 +393,13 @@ static GstStateChangeReturn
gst_wavpack_dec_change_state (GstElement * element, GstStateChange transition) gst_wavpack_dec_change_state (GstElement * element, GstStateChange transition)
{ {
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstWavpackDec *wavpackdec = GST_WAVPACK_DEC (element); GstWavpackDec *dec = GST_WAVPACK_DEC (element);
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY: case GST_STATE_CHANGE_NULL_TO_READY:
break; break;
case GST_STATE_CHANGE_READY_TO_PAUSED: case GST_STATE_CHANGE_READY_TO_PAUSED:
gst_segment_init (&wavpackdec->segment, GST_FORMAT_UNDEFINED); gst_segment_init (&dec->segment, GST_FORMAT_UNDEFINED);
break; break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING: case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break; break;
@ -509,23 +413,16 @@ gst_wavpack_dec_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_PLAYING_TO_PAUSED: case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break; break;
case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_PAUSED_TO_READY:
if (wavpackdec->context) { if (dec->context) {
WavpackCloseFile (wavpackdec->context); WavpackCloseFile (dec->context);
wavpackdec->context = NULL; dec->context = NULL;
} }
wavpackdec->wv_id.buffer = NULL; dec->wv_id.buffer = NULL;
wavpackdec->wv_id.position = 0; dec->wv_id.position = 0;
wavpackdec->wv_id.length = 0; dec->wv_id.length = 0;
/* dec->channels = 0;
wavpackdec->wvc_id.buffer = NULL; dec->sample_rate = 0;
wavpackdec->wvc_id.position = 0; dec->width = 0;
wavpackdec->wvc_id.length = 0;
wavpackdec->error_count = 0;
wavpackdec->wvcsinkpad = NULL;
*/
wavpackdec->channels = 0;
wavpackdec->sample_rate = 0;
wavpackdec->width = 0;
break; break;
case GST_STATE_CHANGE_READY_TO_NULL: case GST_STATE_CHANGE_READY_TO_NULL:
break; break;
@ -536,28 +433,6 @@ gst_wavpack_dec_change_state (GstElement * element, GstStateChange transition)
return ret; return ret;
} }
#if 0
static GstPad *
gst_wavpack_dec_request_new_pad (GstElement * element,
GstPadTemplate * templ, const gchar * name)
{
GstWavpackDec *wavpackdec = GST_WAVPACK_DEC (element);
GstPad *pad;
if (wavpackdec->wvcsinkpad == NULL) {
wavpackdec->wvcsinkpad = gst_pad_new_from_template (template, name);
gst_pad_set_link_function (wavpackdec->wvcsinkpad, gst_wavpack_dec_wvclink);
gst_pad_use_fixed_caps (wavpackdec->wvcsinkpad);
gst_element_add_pad (GST_ELEMENT (wavpackdec), wavpackdec->wvcsinkpad);
gst_element_no_more_pads (GST_ELEMENT (wavpackdec));
} else {
pad = NULL;
}
return pad;
}
#endif
gboolean gboolean
gst_wavpack_dec_plugin_init (GstPlugin * plugin) gst_wavpack_dec_plugin_init (GstPlugin * plugin)
{ {

View file

@ -48,7 +48,6 @@ struct _GstWavpackDec
{ {
GstElement element; GstElement element;
/* GstPad *wvcsinkpad; */
GstPad *sinkpad; GstPad *sinkpad;
GstPad *srcpad; GstPad *srcpad;
@ -56,7 +55,6 @@ struct _GstWavpackDec
WavpackStreamReader *stream_reader; WavpackStreamReader *stream_reader;
read_id wv_id; read_id wv_id;
/* read_id wvc_id; */
GstSegment segment; /* used for clipping, TIME format */ GstSegment segment; /* used for clipping, TIME format */