From 14c0bebf4b587eb747649987eb09aeab3e31dbe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 30 Mar 2007 04:50:11 +0000 Subject: ext/wavpack/: Don't play audioconvert. As wavpack wants/outputs all samples with width==32 and depth=[1,32] accept th... Original commit message from CVS: * ext/wavpack/gstwavpackdec.c: (gst_wavpack_dec_reset), (gst_wavpack_dec_init), (gst_wavpack_dec_sink_set_caps), (gst_wavpack_dec_clip_outgoing_buffer), (gst_wavpack_dec_post_tags), (gst_wavpack_dec_chain): * ext/wavpack/gstwavpackdec.h: * ext/wavpack/gstwavpackenc.c: (gst_wavpack_enc_reset), (gst_wavpack_enc_sink_set_caps), (gst_wavpack_enc_set_wp_config), (gst_wavpack_enc_chain): * ext/wavpack/gstwavpackenc.h: * ext/wavpack/gstwavpackparse.c: Don't play audioconvert. As wavpack wants/outputs all samples with width==32 and depth=[1,32] accept this and let audioconvert convert to accepted formats instead of doing it in the element for n*8 depths. This also adds support for non-n*8 depths and prevents some useless memory allocations. Fixes #421598 Also add a workaround for bug #421542 in wavpackenc for now... * tests/check/elements/wavpackdec.c: (GST_START_TEST): * tests/check/elements/wavpackenc.c: (GST_START_TEST): * tests/check/elements/wavpackparse.c: (GST_START_TEST): Consider the change above in the unit tests and test if the correct caps are accepted and set. Also check for GST_BUFFER_OFFSET_END in the wavpackparse unit test. * ext/wavpack/gstwavpackdec.c: (gst_wavpack_dec_init), (gst_wavpack_dec_sink_set_caps): Set caps on the src pad as soon as possible. * ext/wavpack/gstwavpackdec.h: * ext/wavpack/gstwavpackcommon.h: * ext/wavpack/gstwavpackenc.h: * ext/wavpack/gstwavpackparse.h: Fix indention. gst-indent is now called by cicl. --- ext/wavpack/gstwavpackenc.c | 98 +++++++-------------------------------------- 1 file changed, 15 insertions(+), 83 deletions(-) (limited to 'ext/wavpack/gstwavpackenc.c') diff --git a/ext/wavpack/gstwavpackenc.c b/ext/wavpack/gstwavpackenc.c index 57610136..c1d25964 100644 --- a/ext/wavpack/gstwavpackenc.c +++ b/ext/wavpack/gstwavpackenc.c @@ -108,26 +108,8 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-raw-int, " "width = (int) 32, " - "depth = (int) 32, " - "endianness = (int) LITTLE_ENDIAN, " - "channels = (int) [ 1, 2 ], " - "rate = (int) [ 6000, 192000 ]," "signed = (boolean) TRUE;" - "audio/x-raw-int, " - "width = (int) 24, " - "depth = (int) 24, " - "endianness = (int) LITTLE_ENDIAN, " - "channels = (int) [ 1, 2 ], " - "rate = (int) [ 6000, 192000 ]," "signed = (boolean) TRUE;" - "audio/x-raw-int, " - "width = (int) 16, " - "depth = (int) 16, " - "endianness = (int) LITTLE_ENDIAN, " - "channels = (int) [ 1, 2 ], " - "rate = (int) [ 6000, 192000 ]," "signed = (boolean) TRUE;" - "audio/x-raw-int, " - "width = (int) 8, " - "depth = (int) 8, " - "endianness = (int) LITTLE_ENDIAN, " + "depth = (int) [ 1, 32], " + "endianness = (int) BYTE_ORDER, " "channels = (int) [ 1, 2 ], " "rate = (int) [ 6000, 192000 ]," "signed = (boolean) TRUE") ); @@ -136,7 +118,7 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-wavpack, " - "width = (int) { 8, 16, 24, 32 }, " + "width = (int) [ 1, 32 ], " "channels = (int) [ 1, 2 ], " "rate = (int) [ 6000, 192000 ], " "framed = (boolean) TRUE") ); @@ -343,7 +325,7 @@ gst_wavpack_enc_reset (GstWavpackEnc * enc) /* reset stream information */ enc->samplerate = 0; - enc->width = 0; + enc->depth = 0; enc->channels = 0; } @@ -389,14 +371,13 @@ gst_wavpack_enc_sink_set_caps (GstPad * pad, GstCaps * caps) { GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad)); GstStructure *structure = gst_caps_get_structure (caps, 0); - int depth = 0; + /* FIXME: Workaround for bug #421543: calls gst_pad_accept_caps() */ /* check caps and put relevant parts into our object attributes */ - if (!gst_structure_get_int (structure, "channels", &enc->channels) || + if (!gst_pad_accept_caps (pad, caps) || + !gst_structure_get_int (structure, "channels", &enc->channels) || !gst_structure_get_int (structure, "rate", &enc->samplerate) || - !gst_structure_get_int (structure, "width", &enc->width) || - !(gst_structure_get_int (structure, "depth", &depth) || - depth != enc->width)) { + !gst_structure_get_int (structure, "depth", &enc->depth)) { GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL), ("got invalid caps: %" GST_PTR_FORMAT, caps)); gst_object_unref (enc); @@ -407,7 +388,7 @@ gst_wavpack_enc_sink_set_caps (GstPad * pad, GstCaps * caps) caps = gst_caps_new_simple ("audio/x-wavpack", "channels", G_TYPE_INT, enc->channels, "rate", G_TYPE_INT, enc->samplerate, - "width", G_TYPE_INT, enc->width, "framed", G_TYPE_BOOLEAN, TRUE, NULL); + "width", G_TYPE_INT, enc->depth, "framed", G_TYPE_BOOLEAN, TRUE, NULL); if (!gst_pad_set_caps (enc->srcpad, caps)) { GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL), @@ -428,8 +409,8 @@ gst_wavpack_enc_set_wp_config (GstWavpackEnc * enc) { enc->wp_config = g_new0 (WavpackConfig, 1); /* set general stream informations in the WavpackConfig */ - enc->wp_config->bytes_per_sample = (enc->width + 7) >> 3; - enc->wp_config->bits_per_sample = enc->width; + enc->wp_config->bytes_per_sample = GST_ROUND_UP_8 (enc->depth) / 8; + enc->wp_config->bits_per_sample = enc->depth; enc->wp_config->num_channels = enc->channels; /* TODO: handle more than 2 channels correctly! */ @@ -540,46 +521,6 @@ gst_wavpack_enc_set_wp_config (GstWavpackEnc * enc) } } -static int32_t * -gst_wavpack_enc_format_samples (const uchar * src_data, uint32_t sample_count, - guint width) -{ - int32_t *data = g_new0 (int32_t, sample_count); - - /* put all samples into an int32_t*, no matter what - * width we have and convert them from little endian - * to host byte order */ - - switch (width) { - int i; - - case 8: - for (i = 0; i < sample_count; i++) - data[i] = (int32_t) (int8_t) src_data[i]; - break; - case 16: - for (i = 0; i < sample_count; i++) - data[i] = (int32_t) src_data[2 * i] - | ((int32_t) (int8_t) src_data[2 * i + 1] << 8); - break; - case 24: - for (i = 0; i < sample_count; i++) - data[i] = (int32_t) src_data[3 * i] - | ((int32_t) src_data[3 * i + 1] << 8) - | ((int32_t) (int8_t) src_data[3 * i + 2] << 16); - break; - case 32: - for (i = 0; i < sample_count; i++) - data[i] = (int32_t) src_data[4 * i] - | ((int32_t) src_data[4 * i + 1] << 8) - | ((int32_t) src_data[4 * i + 2] << 16) - | ((int32_t) (int8_t) src_data[4 * i + 3] << 24); - break; - } - - return data; -} - static int gst_wavpack_enc_push_block (void *id, void *data, int32_t count) { @@ -663,8 +604,7 @@ static GstFlowReturn gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buf) { GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad)); - uint32_t sample_count = GST_BUFFER_SIZE (buf) / ((enc->width + 7) >> 3); - int32_t *data; + uint32_t sample_count = GST_BUFFER_SIZE (buf) / 4; GstFlowReturn ret; /* reset the last returns to GST_FLOW_OK. This is only set to something else @@ -712,17 +652,9 @@ gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buf) MD5Update (enc->md5_context, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); } - /* put all samples into an int32_t*, no matter what - * width we have and convert them from little endian - * to host byte order */ - data = - gst_wavpack_enc_format_samples (GST_BUFFER_DATA (buf), sample_count, - enc->width); - - gst_buffer_unref (buf); - /* encode and handle return values from encoding */ - if (WavpackPackSamples (enc->wp_context, data, sample_count / enc->channels)) { + if (WavpackPackSamples (enc->wp_context, (int32_t *) GST_BUFFER_DATA (buf), + sample_count / enc->channels)) { GST_DEBUG ("encoding samples successful"); ret = GST_FLOW_OK; } else { @@ -745,7 +677,7 @@ gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buf) } } - g_free (data); + gst_buffer_unref (buf); gst_object_unref (enc); return ret; } -- cgit v1.2.1