-/* GStreamer\r
- * Copyright (C) 2008 Pioneers of the Inevitable <songbird@songbirdnest.com>\r
- *\r
- * Authors: Michael Smith <msmith@songbirdnest.com>\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the\r
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
- * Boston, MA 02111-1307, USA.\r
- */ \r
- \r
-#ifdef HAVE_CONFIG_H\r
-#include "config.h"\r
-#endif /* \r */
- \r
-#include <windows.h>\r
-#include <mmreg.h>\r
-#include <msacm.h>\r
- \r
-#include <gst/gst.h>\r
-#include <gst/riff/riff-media.h>\r
- \r
-#define ACM_BUFFER_SIZE (64 * 1024)\r
- \r
-#define GST_TYPE_ACM_MP3_DEC \\r
- (acmmp3dec_get_type ()) \r
-#define GST_ACM_MP3_DEC(obj) \\r
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ACM_MP3_DEC, ACMMP3Dec)) \r \r
-#define GST_CAT_DEFAULT acmmp3dec_debug\r
- GST_DEBUG_CATEGORY_STATIC (acmmp3dec_debug);
-\r\rstatic const GstElementDetails acmmp3dec_details =
- \rGST_ELEMENT_DETAILS ("ACM MP3 decoder", \r"Codec/Decoder/Audio",
- \r"Decode MP3 using ACM decoder",
- \r"Pioneers of the Inevitable <songbird@songbirdnest.com");
-\r\rstatic GstStaticPadTemplate acmmp3dec_sink_template =
- \rGST_STATIC_PAD_TEMPLATE ("sink", \rGST_PAD_SINK, \rGST_PAD_ALWAYS,
- \rGST_STATIC_CAPS ("audio/x-raw-int, " \r "depth = (int)16, " \r
- "width = (int)16, " \r "endianness = (int)" G_STRINGIFY (G_BYTE_ORDER)
- ", " \r "signed = (boolean)TRUE, " \r "channels = (int) [1,2], " \r
- "rate = (int)[1, MAX]") \r);
-\r\rstatic GstStaticPadTemplate acmmp3dec_src_template =
- \rGST_STATIC_PAD_TEMPLATE ("src", \rGST_PAD_SRC, \rGST_PAD_ALWAYS,
- \rGST_STATIC_CAPS ("audio/mpeg, " \r "mpegversion = (int)1, " \r
- "layer = (int)3, " \r
- "rate = (int){ 8000, 11025, 12000, 16000, 22050, 24000, " \r
- " 32000, 44100, 48000 }, " \r "channels = (int)[1,2], " \r
- "parsed = (boolean) true") \r);
-\r\rtypedef struct _ACMMP3DecClass \r
+/* GStreamer
+ * Copyright (C) 2008 Pioneers of the Inevitable <songbird@songbirdnest.com>
+ *
+ * Authors: Michael Smith <msmith@songbirdnest.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <windows.h>
+#include <mmreg.h>
+#include <msacm.h>
+
+#include <gst/gst.h>
+#include <gst/riff/riff-media.h>
+
+#define ACM_BUFFER_SIZE (64 * 1024)
+
+#define GST_TYPE_ACM_MP3_DEC \
+ (acmmp3dec_get_type())
+#define GST_ACM_MP3_DEC(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ACM_MP3_DEC,ACMMP3Dec))
+
+#define GST_CAT_DEFAULT acmmp3dec_debug
+GST_DEBUG_CATEGORY_STATIC (acmmp3dec_debug);
+
+static const GstElementDetails acmmp3dec_details =
+GST_ELEMENT_DETAILS ("ACM MP3 decoder",
+ "Codec/Decoder/Audio",
+ "Decode MP3 using ACM decoder",
+ "Pioneers of the Inevitable <songbird@songbirdnest.com");
+
+static GstStaticPadTemplate acmmp3dec_src_template =
+GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("audio/x-raw-int, "
+ "depth = (int)16, "
+ "width = (int)16, "
+ "endianness = (int)" G_STRINGIFY (G_BYTE_ORDER) ", "
+ "signed = (boolean)TRUE, "
+ "channels = (int) [1,2], " "rate = (int)[1, MAX]")
+ );
+
+static GstStaticPadTemplate acmmp3dec_sink_template =
+GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("audio/mpeg, "
+ "mpegversion = (int)1, "
+ "layer = (int)3, "
+ "rate = (int){ 8000, 11025, 12000, 16000, 22050, 24000, "
+ " 32000, 44100, 48000 }, "
+ "channels = (int)[1,2], " "parsed = (boolean) true")
+ );
+
+typedef struct _ACMMP3DecClass
{
- \rGstElementClass parent_class;
-\r} ACMMP3DecClass;
-\r\rtypedef struct _ACMMP3Dec \r
+ GstElementClass parent_class;
+} ACMMP3DecClass;
+
+typedef struct _ACMMP3Dec
{
- \rGstElement parent;
- \r\rGstPad * sinkpad;
- \rGstPad * srcpad;
- \r\rgboolean is_setup;
- \r\rWAVEFORMATEX infmt;
- \rWAVEFORMATEX * outfmt;
- \r\rHACMDRIVER driver;
- \rHACMSTREAM stream;
- \rACMSTREAMHEADER header;
- \r\r
- /* Offset into input buffer to write next data */ \r
- int offset;
- \r
- /* Number of bytes written */ \r
- int bytes_output;
- \r\r
- /* From received caps */ \r
+ GstElement parent;
+
+ GstPad *sinkpad;
+ GstPad *srcpad;
+
+ gboolean is_setup;
+
+ MPEGLAYER3WAVEFORMAT infmt;
+ WAVEFORMATEX outfmt;
+
+ HACMSTREAM stream;
+ ACMSTREAMHEADER header;
+
+ /* Next timestamp to push */
+ GstClockTime timestamp;
+
+ /* From received caps */
int rate;
- \rint channels;
- \r\r
- /* Set in properties */ \r
- int selected_bitrate;
- \r\rGstCaps * output_caps;
- \r} ACMMP3Dec;
-\r\rGST_BOILERPLATE (ACMMP3Dec, acmmp3dec, GstElement, GST_TYPE_ELEMENT);
-\r\rstatic GstCaps *\r
-acmmp3dec_caps_from_format (WAVEFORMATEX * fmt) \r
+ int channels;
+
+ GstCaps *output_caps;
+} ACMMP3Dec;
+
+GST_BOILERPLATE (ACMMP3Dec, acmmp3dec, GstElement, GST_TYPE_ELEMENT);
+
+static GstCaps *
+acmmp3dec_caps_from_format (WAVEFORMATEX * fmt)
{
- \rreturn gst_riff_create_audio_caps (fmt->wFormatTag, \rNULL,
- (gst_riff_strf_auds *) fmt, NULL, NULL, NULL);
-\r}
+ return gst_riff_create_audio_caps (fmt->wFormatTag,
+ NULL, (gst_riff_strf_auds *) fmt, NULL, NULL, NULL);
+}
-\r\rgboolean acmmp3dec_set_input_format (ACMMP3Dec * dec) \r
+gboolean
+acmmp3dec_set_input_format (ACMMP3Dec * dec)
{
- \rdec->infmt.wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
- \rdec->infmt.wfx.nChannels = dec->channels;
- \rdec->infmt.wfx.nSamplesPerSec = dec->rate;
- \rdec->infmt.wfx.nAvgBytesPerSec = 0;
- \rdec->infmt.wfx.nBlockAlign = 0;
- \rdec->infmt.wfx.wBitsPerSample = 16;
- \rdec->infmt.wfx.cbSize = MPEGLAYER3_WFX_EXTRA_BYTES;
- \rdec->infmt.wID = MPEGLAYER3_ID_MPEG;
- \rdec->infmt.fdwFlags = MPEGLAYER3_FLAG_PADDING_OFF; // ??\r
- dec->infmt.nBlockSize = 0; // Damn, need to figure this out... Does this\r
- // even make sense for vbr files? Various random\r
- // things suggest 417 for no apparent reason?\r
- // That's the right value for an unpadded\r
- // 128 kbps 44.1kHz stream I think. Let's try\r
- // zero to see if it works though. Or one?\r
+ dec->infmt.wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
+ dec->infmt.wfx.nChannels = dec->channels;
+ dec->infmt.wfx.nSamplesPerSec = dec->rate;
+ dec->infmt.wfx.nAvgBytesPerSec = 8000; /* Has to be set, but actual
+ value doesn't matter */
+ dec->infmt.wfx.nBlockAlign = 1;
+ dec->infmt.wfx.wBitsPerSample = 0;
+ dec->infmt.wfx.cbSize = MPEGLAYER3_WFX_EXTRA_BYTES;
+ dec->infmt.wID = MPEGLAYER3_ID_MPEG;
+ dec->infmt.fdwFlags = MPEGLAYER3_FLAG_PADDING_OFF;
+ dec->infmt.nBlockSize = 1; /* Needs to be non-zero, actual
+ value doesn't matter */
dec->infmt.nFramesPerBlock = 1;
- \rdec->infmt.nCodecDelay = 0; /* Apparently no way to know the correct \r
- value to put here! Encoder-specific and not\r
- stored in the bitstream. */
- \r\rreturn TRUE;
-\r}
-
-\r\rgboolean acmmp3dec_set_output_format (ACMMP3Dec * dec,
- WAVEFORMATEX * outfmt) \r
+ dec->infmt.nCodecDelay = 0;
+
+ return TRUE;
+}
+
+gboolean
+acmmp3dec_set_output_format (ACMMP3Dec * dec)
{
- \rdec->outfmt.wFormatTag = WAVE_FORMAT_PCM;
- \rdec->outfmt.nChannels = dec->channels;
- \rdec->outfmt.nSamplesPerSec = dec->rate;
- \rdec->outfmt.nAvgBytesPerSec = 2 * dec->channels * dec->rate;
- \rdec->outfmt.nBlockAlign = 4;
- \rdec->outfmt.wBitsPerSample = 16;
- \rdec->outfmt.cbSize = 0;
- \r\rreturn TRUE;
-\r}
-\r\rstatic gboolean \r
-acmmp3dec_setup (ACMMP3Dec * dec) \r
+ dec->outfmt.wFormatTag = WAVE_FORMAT_PCM;
+ dec->outfmt.nChannels = dec->channels;
+ dec->outfmt.nSamplesPerSec = dec->rate;
+ dec->outfmt.nAvgBytesPerSec = 2 * dec->channels * dec->rate;
+ dec->outfmt.nBlockAlign = 2 * dec->channels;
+ dec->outfmt.wBitsPerSample = 16;
+ dec->outfmt.cbSize = 0;
+
+ return TRUE;
+}
+
+static gboolean
+acmmp3dec_setup (ACMMP3Dec * dec)
{
- \rMMRESULT res;
- \rint destBufferSize;
-\r\rTODO:Get driverId \r
- \rres = acmDriverOpen (&dec->driver, decclass->driverId, 0);
- \rif (res) {
- \rGST_WARNING ("Failed to open ACM driver: %d", res);
- \rreturn FALSE;
- \r}
- \r\racmmp3dec_set_input_format (dec, &dec->infmt);
- \racmmp3dec_set_output_format (dec, &dec->outfmt);
- \r\rres =
- acmStreamOpen (&dec->stream, dec->driver, &dec->infmt, dec->outfmt, \r0, 0,
- 0, ACM_STREAMOPENF_NONREALTIME);
- \rif (res) {
- \rGST_WARNING_OBJECT (dec, "Failed to open ACM stream");
- \rreturn FALSE;
- \r}
- \r\rdec->header.cbStruct = sizeof (ACMSTREAMHEADER);
- \rdec->header.fdwStatus = 0;
- \rdec->header.dwUser = 0;
- \r\rdec->header.pbSrc = (BYTE *) g_malloc (ACM_BUFFER_SIZE);
- \rdec->header.cbSrcLength = ACM_BUFFER_SIZE;
- \rdec->header.cbSrcLengthUsed = 0;
- \rdec->header.dwSrcUser = 0;
- \r\r
- /* Ask what buffer size we need to use for our output */ \r
- acmStreamSize (dec->stream, ACM_BUFFER_SIZE, \r&destBufferSize,
- ACM_STREAMSIZEF_SOURCE);
- \r\rdec->header.pbDst = (BYTE *) g_malloc (destBufferSize);
- \rdec->header.cbDstLength = destBufferSize;
- \rdec->header.cbDstLengthUsed = 0;
- \rdec->header.dwDstUser = 0;
- \r\rres = acmStreamPrepareHeader (dec->stream, &dec->header, 0);
- \rif (res) {
- \rGST_WARNING_OBJECT (dec, "Failed to prepare ACM stream: %x", res);
- \rreturn FALSE;
- \r}
- \r\rdec->output_caps = acmmp3dec_caps_from_format (dec->outfmt);
- \rif (dec->output_caps) {
- \rgst_pad_set_caps (dec->srcpad, dec->output_caps);
- \r}
- \r\rdec->is_setup = TRUE;
- \rreturn TRUE;
-\r}
-\r\rstatic void \r
-acmmp3dec_teardown (ACMMP3Dec * dec) \r
+ MMRESULT res;
+ int destBufferSize;
+
+ acmmp3dec_set_input_format (dec);
+ acmmp3dec_set_output_format (dec);
+
+ res = acmStreamOpen (&dec->stream, NULL, &dec->infmt, &dec->outfmt,
+ 0, 0, 0, 0);
+ if (res) {
+ GST_WARNING_OBJECT (dec, "Failed to open ACM stream: %d", res);
+ return FALSE;
+ }
+
+ dec->header.cbStruct = sizeof (ACMSTREAMHEADER);
+ dec->header.fdwStatus = 0;
+ dec->header.dwUser = 0;
+
+ dec->header.pbSrc = (BYTE *) g_malloc (ACM_BUFFER_SIZE);
+ dec->header.cbSrcLength = ACM_BUFFER_SIZE;
+ dec->header.cbSrcLengthUsed = 0;
+ dec->header.dwSrcUser = 0;
+
+ /* Ask what buffer size we need to use for our output */
+ acmStreamSize (dec->stream, ACM_BUFFER_SIZE,
+ &destBufferSize, ACM_STREAMSIZEF_SOURCE);
+
+ dec->header.pbDst = (BYTE *) g_malloc (destBufferSize);
+ dec->header.cbDstLength = destBufferSize;
+ dec->header.cbDstLengthUsed = 0;
+ dec->header.dwDstUser = 0;
+
+ res = acmStreamPrepareHeader (dec->stream, &dec->header, 0);
+ if (res) {
+ GST_WARNING_OBJECT (dec, "Failed to prepare ACM stream: %x", res);
+ return FALSE;
+ }
+
+ dec->output_caps = acmmp3dec_caps_from_format (&dec->outfmt);
+ if (dec->output_caps) {
+ gst_pad_set_caps (dec->srcpad, dec->output_caps);
+ }
+
+ dec->timestamp = GST_CLOCK_TIME_NONE;
+ dec->is_setup = TRUE;
+ return TRUE;
+}
+
+static void
+acmmp3dec_teardown (ACMMP3Dec * dec)
{
- \rif (dec->outfmt) {
- \rg_free (dec->outfmt);
- \rdec->outfmt = NULL;
- \r}
- \r\rif (dec->output_caps) {
- \rgst_caps_unref (dec->output_caps);
- \rdec->output_caps = NULL;
- \r}
- \r\rif (dec->header.pbSrc)
- \rg_free (dec->header.pbSrc);
- \rif (dec->header.pbDst)
- \rg_free (dec->header.pbDst);
- \rmemset (&dec->header, 0, sizeof (dec->header));
- \r\rif (dec->stream) {
- \racmStreamClose (dec->stream, 0);
- \rdec->stream = 0;
- \r}
- \rif (dec->driver) {
- \racmDriverClose (dec->driver, 0);
- \rdec->driver = 0;
- \r}
- \r\rdec->bytes_output = 0;
- \rdec->offset = 0;
- \rdec->is_setup = FALSE;
-\r}
-\r\rstatic gboolean
-acmmp3dec_sink_setcaps (GstPad * pad, GstCaps * caps) \r
+ if (dec->output_caps) {
+ gst_caps_unref (dec->output_caps);
+ dec->output_caps = NULL;
+ }
+
+ if (dec->header.fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED)
+ acmStreamUnprepareHeader (dec->stream, &dec->header, 0);
+ if (dec->header.pbSrc)
+ g_free (dec->header.pbSrc);
+ if (dec->header.pbDst)
+ g_free (dec->header.pbDst);
+ memset (&dec->header, 0, sizeof (dec->header));
+
+ if (dec->stream) {
+ acmStreamClose (dec->stream, 0);
+ dec->stream = 0;
+ }
+
+ dec->timestamp = GST_CLOCK_TIME_NONE;
+ dec->is_setup = FALSE;
+}
+
+static gboolean
+acmmp3dec_sink_setcaps (GstPad * pad, GstCaps * caps)
{
- \rACMMP3Dec * dec = (ACMMP3Dec *) GST_PAD_PARENT (pad);
- \rGstStructure * structure;
- \rgboolean ret;
- \r\rstructure = gst_caps_get_structure (caps, 0);
- \rgst_structure_get_int (structure, "channels", &dec->channels);
- \rgst_structure_get_int (structure, "rate", &dec->rate);
- \r\rdec->bytes_per_sample = dec->channels * dec->rate * 2; /* 16 bit output */
- \r\rif (dec->is_setup)
- \racmmp3dec_teardown (dec);
- \rret = acmmp3dec_setup (dec);
- \r\rreturn ret;
-\r}
-\r\rstatic GstFlowReturn \r
-acmmp3dec_push_output (ACMMP3Dec * dec) \r
+ ACMMP3Dec *dec = (ACMMP3Dec *) GST_PAD_PARENT (pad);
+ GstStructure *structure;
+ gboolean ret;
+
+ structure = gst_caps_get_structure (caps, 0);
+ gst_structure_get_int (structure, "channels", &dec->channels);
+ gst_structure_get_int (structure, "rate", &dec->rate);
+
+ if (dec->is_setup)
+ acmmp3dec_teardown (dec);
+ ret = acmmp3dec_setup (dec);
+
+ return ret;
+}
+
+static GstFlowReturn
+acmmp3dec_push_output (ACMMP3Dec * dec)
{
- \rGstFlowReturn ret = GST_FLOW_OK;
- \r\rif (dec->header.cbDstLengthUsed > 0) {
- \rGstBuffer * outbuf =
- gst_buffer_new_and_alloc (dec->header.cbDstLengthUsed);
- \rmemcpy (GST_BUFFER_DATA (outbuf), dec->header.pbDst,
- \rdec->header.cbDstLengthUsed);
- \r\rGST_BUFFER_TIMESTAMP (outbuf) = dec->timestamp;
- \rGST_BUFFER_DURATION (outbuf) =
- gst_util_uint64_scale_int (\rGST_BUFFER_SIZE (outbuf), GST_SECOND,
- dec->bytes_per_sample);
- \r\rdec->timestamp += GST_BUFFER_DURATION (outbuf);
- \r\rGST_DEBUG_OBJECT (dec, "Pushing %d byte decoded buffer",
- \rdec->header.cbDstLengthUsed);
- \rret = gst_pad_push (dec->srcpad, outbuf);
- \r}
- \r\rreturn ret;
-\r}
-\r\rstatic GstFlowReturn
-acmmp3dec_chain (GstPad * pad, GstBuffer * buf) \r
+ GstFlowReturn ret = GST_FLOW_OK;
+
+ if (dec->header.cbDstLengthUsed > 0) {
+ GstBuffer *outbuf = gst_buffer_new_and_alloc (dec->header.cbDstLengthUsed);
+ memcpy (GST_BUFFER_DATA (outbuf), dec->header.pbDst,
+ dec->header.cbDstLengthUsed);
+
+ if (dec->timestamp != GST_CLOCK_TIME_NONE)
+ GST_BUFFER_TIMESTAMP (outbuf) = dec->timestamp;
+ GST_BUFFER_DURATION (outbuf) =
+ gst_util_uint64_scale_int (GST_BUFFER_SIZE (outbuf), GST_SECOND,
+ dec->rate * dec->channels * 2);
+
+ GST_DEBUG_OBJECT (dec, "decoded buffer has ts %d, duration %d",
+ (int) (GST_BUFFER_TIMESTAMP (outbuf)),
+ (int) (GST_BUFFER_DURATION (outbuf)));
+
+ gst_buffer_set_caps (outbuf, dec->output_caps);
+
+ if (dec->timestamp != GST_CLOCK_TIME_NONE)
+ dec->timestamp += GST_BUFFER_DURATION (outbuf);
+
+ GST_DEBUG_OBJECT (dec, "Pushing %d byte decoded buffer",
+ dec->header.cbDstLengthUsed);
+ ret = gst_pad_push (dec->srcpad, outbuf);
+ } else
+ GST_DEBUG_OBJECT (dec, "Not pushing decoded buffer, no output");
+
+
+ return ret;
+}
+
+static GstFlowReturn
+acmmp3dec_chain (GstPad * pad, GstBuffer * buf)
{
- \rMMRESULT res;
- \rACMMP3Dec * dec = (ACMMP3Dec *) GST_PAD_PARENT (pad);
- \rguchar * data = GST_BUFFER_DATA (buf);
- \rgint len = GST_BUFFER_SIZE (buf);
- \rint chunklen;
- \rGstFlowReturn ret = GST_FLOW_OK;
- \r\rif (len > ACM_BUFFER_SIZE) {
- \rGST_WARNING_OBJECT (dec, "Impossibly large mp3 frame!");
- \rreturn GST_FLOW_ERROR;
- \r}
- \r\rif (GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE) {
- \rdec->timestamp = GST_BUFFER_TIMESTAMP (buf);
- \r}
- \r\rmemcpy (dec->header.pbSrc, data, len);
- \rdec->header.cbSrcLength = len;
- \r\r
- /* Now we have a buffer ready to go */ \r
- res =
- acmStreamConvert (dec->stream, &dec->header,
- \rACM_STREAMCONVERTF_BLOCKALIGN);
- \rif (res) {
- \rGST_WARNING_OBJECT (dec, "Failed to decode data");
- \rreturn GST_FLOW_OK; /* Maybe it was just a corrupt frame */
- \r}
- \r\rif (dec->header.cbSrcLengthUsed > 0)
- \r {
- \rif (dec->header.cbSrcLengthUsed != dec->header.cbSrcLength) {
- \rGST_WARNING_OBJECT (dec, "ACM decoder didn't consume all data!");
- \r
- /* We could handle this, but it shouldn't be possible, so don't try\r
- * for now */ \r
- return GST_FLOW_ERROR;
- \r}
- \r\r
- /* Write out any data produced */ \r
- acmmp3dec_push_output (dec);
- \r}
- \rreturn ret;
-\r}
-
-\r\rGstFlowReturn acmmp3dec_finish_stream (ACMMP3Dec * dec) \r
+ MMRESULT res;
+ ACMMP3Dec *dec = (ACMMP3Dec *) GST_PAD_PARENT (pad);
+ guchar *data = GST_BUFFER_DATA (buf);
+ gint len = GST_BUFFER_SIZE (buf);
+ GstFlowReturn ret = GST_FLOW_OK;
+
+ if (len > ACM_BUFFER_SIZE) {
+ GST_WARNING_OBJECT (dec, "Impossibly large mp3 frame!");
+ ret = GST_FLOW_ERROR;
+ goto done;
+ }
+
+ if (GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE &&
+ (dec->timestamp == GST_CLOCK_TIME_NONE ||
+ GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT))) {
+ dec->timestamp = GST_BUFFER_TIMESTAMP (buf);
+ }
+
+ memcpy (dec->header.pbSrc, data, len);
+ dec->header.cbSrcLength = len;
+
+ /* Now we have a buffer ready to go */
+ res = acmStreamConvert (dec->stream, &dec->header,
+ ACM_STREAMCONVERTF_BLOCKALIGN);
+ if (res) {
+ GST_WARNING_OBJECT (dec, "Failed to decode data");
+ ret = GST_FLOW_OK; /* Maybe it was just a corrupt frame */
+ goto done;
+ }
+
+ if (dec->header.cbSrcLengthUsed > 0) {
+ if (dec->header.cbSrcLengthUsed != dec->header.cbSrcLength) {
+ GST_WARNING_OBJECT (dec, "ACM decoder didn't consume all data!");
+ /* We could handle this, but it shouldn't be possible, so don't try
+ * for now */
+ ret = GST_FLOW_ERROR;
+ goto done;
+ }
+
+ /* Write out any data produced */
+ acmmp3dec_push_output (dec);
+ }
+
+done:
+ gst_buffer_unref (buf);
+
+ return ret;
+}
+
+GstFlowReturn
+acmmp3dec_finish_stream (ACMMP3Dec * dec)
{
- \rMMRESULT res;
- \rGstFlowReturn ret = GST_FLOW_OK;
- \rint len;
- \r\rdec->header.cbSrcLength = 0;
- \r\r
- /* Flush out any remaining data internal to the decoder */ \r
- res =
- acmStreamConvert (dec->stream, &dec->header,
- \rACM_STREAMCONVERTF_BLOCKALIGN | ACM_STREAMCONVERTF_END);
- \rif (res) {
- \rGST_WARNING_OBJECT (dec, "Failed to decode data");
- \rreturn ret;
- \r}
- \r\rret = acmmp3dec_push_output (dec);
- \rreturn ret;
-\r}
-\r\rstatic gboolean
-acmmp3dec_sink_event (GstPad * pad, GstEvent * event) \r
+ MMRESULT res;
+ GstFlowReturn ret = GST_FLOW_OK;
+
+ dec->header.cbSrcLength = 0;
+
+ /* Flush out any remaining data internal to the decoder */
+ res = acmStreamConvert (dec->stream, &dec->header,
+ ACM_STREAMCONVERTF_BLOCKALIGN | ACM_STREAMCONVERTF_END);
+ if (res) {
+ GST_WARNING_OBJECT (dec, "Failed to decode data");
+ return ret;
+ }
+
+ ret = acmmp3dec_push_output (dec);
+ return ret;
+}
+
+static gboolean
+acmmp3dec_sink_event (GstPad * pad, GstEvent * event)
{
- \rACMMP3Dec * dec = (ACMMP3Dec *) GST_PAD_PARENT (pad);
- \rgboolean res;
- \r\rswitch (GST_EVENT_TYPE (event)) {
- \rcase GST_EVENT_EOS:
- \racmmp3dec_finish_stream (dec);
- \r\rres = gst_pad_push_event (dec->srcpad, event);
- \rbreak;
- \rcase GST_EVENT_FLUSH_STOP:
- \rbreal;
- \rdefault:
- \rres = gst_pad_push_event (dec->srcpad, event);
- \rbreak;
- \r}
- \r\rreturn res;
-\r}
-\r\rstatic void \r
-acmmp3dec_dispose (GObject * obj) \r
+ ACMMP3Dec *dec = (ACMMP3Dec *) GST_PAD_PARENT (pad);
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_EOS:
+ acmmp3dec_finish_stream (dec);
+ break;
+ case GST_EVENT_FLUSH_STOP:
+ if (dec->stream)
+ acmStreamReset (dec->stream, 0);
+ dec->timestamp = GST_CLOCK_TIME_NONE;
+ break;
+ default:
+ break;
+ }
+
+
+ return gst_pad_push_event (dec->srcpad, event);
+}
+
+static void
+acmmp3dec_dispose (GObject * obj)
{
- \rACMMP3Dec * dec = (ACMMP3Dec *) obj;
- \r\rG_OBJECT_CLASS (parent_class)->dispose (obj);
-\r} \r\rstatic void \r
+ ACMMP3Dec *dec = (ACMMP3Dec *) obj;
+
+ if (dec->is_setup)
+ acmmp3dec_teardown (dec);
+
+ G_OBJECT_CLASS (parent_class)->dispose (obj);
+}
-acmmp3dec_init (ACMMP3Dec * dec) \r
+static void
+acmmp3dec_init (ACMMP3Dec * dec, ACMMP3DecClass * decclass)
{
- \rdec->sinkpad =
+ dec->sinkpad =
gst_pad_new_from_static_template (&acmmp3dec_sink_template, "sink");
- \rgst_pad_set_setcaps_function (dec->sinkpad,
- \rGST_DEBUG_FUNCPTR (acmmp3dec_sink_setcaps));
- \rgst_pad_set_chain_function (dec->sinkpad,
- \rGST_DEBUG_FUNCPTR (acmmp3dec_chain));
- \rgst_pad_set_event_function (dec->sinkpad,
- \rGST_DEBUG_FUNCPTR (acmmp3dec_sink_event));
- \rgst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
- \r\rdec->srcpad =
+ gst_pad_set_setcaps_function (dec->sinkpad,
+ GST_DEBUG_FUNCPTR (acmmp3dec_sink_setcaps));
+ gst_pad_set_chain_function (dec->sinkpad,
+ GST_DEBUG_FUNCPTR (acmmp3dec_chain));
+ gst_pad_set_event_function (dec->sinkpad,
+ GST_DEBUG_FUNCPTR (acmmp3dec_sink_event));
+ gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
+
+ dec->srcpad =
gst_pad_new_from_static_template (&acmmp3dec_src_template, "src");
- \rgst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
-\r\r} \r\rstatic void \r
+ gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
+
+}
-acmmp3dec_class_init (ACMMP3DecClass * klass) \r
+static void
+acmmp3dec_class_init (ACMMP3DecClass * klass)
{
- \rGObjectClass * gobjectclass = (GObjectClass *) klass;
- \rgobjectclass->dispose = acmmp3dec_dispose;
-\r} \r\rstatic void \r
+ GObjectClass *gobjectclass = (GObjectClass *) klass;
+ gobjectclass->dispose = acmmp3dec_dispose;
+}
-acmmp3dec_base_init (ACMMP3DecClass * klass) \r
+static void
+acmmp3dec_base_init (ACMMP3DecClass * klass)
{
- \rGstElementClass * element_class = GST_ELEMENT_CLASS (klass);
- \r\rgst_element_class_add_pad_template (element_class,
- \rgst_static_pad_template_get (&acmmp3dec_sink_template));
- \rgst_element_class_add_pad_template (element_class,
- \rgst_static_pad_template_get (&acmmp3dec_src_template));
- \rgst_element_class_set_details (element_class, &acmmp3dec_details);
-\r} \r\rstatic gboolean \r
-
-plugin_init (GstPlugin * plugin) \r
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&acmmp3dec_sink_template));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&acmmp3dec_src_template));
+ gst_element_class_set_details (element_class, &acmmp3dec_details);
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
{
- \rGST_DEBUG_CATEGORY_INIT (acmmp3dec_debug, "acmmp3dec", \r0, "ACM Decoders");
- \r\rGST_INFO ("Registering ACM MP3 decoder");
- \rif (!gst_element_register (plugin, "acmmp3dec", GST_RANK_PRIMARY,
- \rGST_TYPE_ACM_MP3_DEC)) {
- \rreturn FALSE;
- \r}
- \r\rreturn TRUE;
-\r}
-
-\r\rGST_PLUGIN_DEFINE (GST_VERSION_MAJOR, \rGST_VERSION_MINOR, \r"acmmp3dec",
- \r"ACM MP3 Decoder", \rplugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
- GST_PACKAGE_ORIGIN_ '\r
-\r
+ GST_DEBUG_CATEGORY_INIT (acmmp3dec_debug, "acmmp3dec", 0, "ACM Decoders");
+
+ GST_INFO ("Registering ACM MP3 decoder");
+ if (!gst_element_register (plugin, "acmmp3dec", GST_RANK_PRIMARY,
+ GST_TYPE_ACM_MP3_DEC)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "acmmp3dec",
+ "ACM MP3 Decoder",
+ plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)