2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:22:05 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2004-01-27 09:00:01 +00:00
|
|
|
/* Element-Checklist-Version: 5 */
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
/* 2001/04/03 - Updated parseau to use caps nego
|
2004-12-11 13:43:19 +00:00
|
|
|
* Zaheer Abbas Merali <zaheerabbas at merali dot org>
|
2001-12-22 23:22:05 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2005-12-12 10:30:20 +00:00
|
|
|
|
2001-12-22 23:22:05 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-07-26 22:11:21 +00:00
|
|
|
#include "gstauparse.h"
|
2003-12-22 01:47:09 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
2005-12-12 10:30:20 +00:00
|
|
|
static GstElementDetails gst_au_parse_details =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_ELEMENT_DETAILS (".au parser",
|
2004-05-13 21:42:13 +00:00
|
|
|
"Codec/Demuxer/Audio",
|
2004-03-14 22:34:33 +00:00
|
|
|
"Parse an .au file into raw audio",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
static GstStaticPadTemplate gst_au_parse_sink_template =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-au")
|
|
|
|
);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
#define GST_AU_PARSE_ALAW_PAD_TEMPLATE_CAPS \
|
|
|
|
"audio/x-alaw, " \
|
|
|
|
"rate = (int) [ 8000, 192000 ], " \
|
|
|
|
"channels = (int) [ 1, 2 ]"
|
|
|
|
|
|
|
|
#define GST_AU_PARSE_MULAW_PAD_TEMPLATE_CAPS \
|
|
|
|
"audio/x-mulaw, " \
|
|
|
|
"rate = (int) [ 8000, 192000 ], " \
|
|
|
|
"channels = (int) [ 1, 2 ]"
|
|
|
|
|
|
|
|
/* Nothing to decode those ADPCM streams for now */
|
|
|
|
#define GST_AU_PARSE_ADPCM_PAD_TEMPLATE_CAPS \
|
|
|
|
"audio/x-adpcm, " \
|
|
|
|
"layout = (string) { g721, g722, g723_3, g723_5 }"
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_au_parse_src_template =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
2005-12-12 10:30:20 +00:00
|
|
|
GST_PAD_SOMETIMES,
|
2004-12-19 16:54:46 +00:00
|
|
|
GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
|
2005-12-12 10:30:20 +00:00
|
|
|
GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS ";"
|
|
|
|
GST_AU_PARSE_ALAW_PAD_TEMPLATE_CAPS ";"
|
|
|
|
GST_AU_PARSE_MULAW_PAD_TEMPLATE_CAPS ";"
|
|
|
|
GST_AU_PARSE_ADPCM_PAD_TEMPLATE_CAPS));
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
static void gst_au_parse_dispose (GObject * object);
|
|
|
|
static GstFlowReturn gst_au_parse_chain (GstPad * pad, GstBuffer * buf);
|
|
|
|
static GstStateChangeReturn gst_au_parse_change_state (GstElement * element,
|
2005-09-02 15:44:50 +00:00
|
|
|
GstStateChange transition);
|
2004-05-11 00:20:02 +00:00
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
GST_BOILERPLATE (GstAuParse, gst_au_parse, GstElement, GST_TYPE_ELEMENT)
|
2005-09-22 22:38:48 +00:00
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
static void gst_au_parse_base_init (gpointer g_class)
|
2003-11-01 01:32:29 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_static_pad_template_get (&gst_au_parse_sink_template));
|
2003-11-01 01:32:29 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_static_pad_template_get (&gst_au_parse_src_template));
|
|
|
|
gst_element_class_set_details (element_class, &gst_au_parse_details);
|
2003-11-01 01:32:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:22:05 +00:00
|
|
|
static void
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_au_parse_class_init (GstAuParseClass * klass)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
2005-11-21 17:18:01 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-12-22 23:22:05 +00:00
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
2004-03-14 22:34:33 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2004-05-11 00:20:02 +00:00
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
gobject_class->dispose = gst_au_parse_dispose;
|
2005-11-21 17:18:01 +00:00
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_au_parse_change_state);
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_au_parse_init (GstAuParse * auparse, GstAuParseClass * klass)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
2005-12-12 10:30:20 +00:00
|
|
|
(&gst_au_parse_sink_template), "sink");
|
2002-02-17 02:06:04 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_pad_set_chain_function (auparse->sinkpad, gst_au_parse_chain);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2005-10-31 19:08:27 +00:00
|
|
|
auparse->srcpad = gst_pad_new_from_template (gst_static_pad_template_get
|
2005-12-12 10:30:20 +00:00
|
|
|
(&gst_au_parse_src_template), "src");
|
2005-09-22 22:38:48 +00:00
|
|
|
gst_pad_use_fixed_caps (auparse->srcpad);
|
2005-10-31 19:08:27 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
auparse->offset = 0;
|
2005-11-21 17:18:01 +00:00
|
|
|
auparse->buffer_offset = 0;
|
|
|
|
auparse->adapter = gst_adapter_new ();
|
2002-02-17 02:06:04 +00:00
|
|
|
auparse->size = 0;
|
|
|
|
auparse->encoding = 0;
|
|
|
|
auparse->frequency = 0;
|
|
|
|
auparse->channels = 0;
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
static void
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_au_parse_dispose (GObject * object)
|
2005-11-21 17:18:01 +00:00
|
|
|
{
|
2005-12-12 10:30:20 +00:00
|
|
|
GstAuParse *au = GST_AU_PARSE (object);
|
2005-11-21 17:18:01 +00:00
|
|
|
|
|
|
|
if (au->adapter != NULL) {
|
2005-12-29 11:26:12 +00:00
|
|
|
g_object_unref (au->adapter);
|
2005-11-21 17:18:01 +00:00
|
|
|
au->adapter = NULL;
|
|
|
|
}
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2005-09-22 22:38:48 +00:00
|
|
|
static GstFlowReturn
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_au_parse_chain (GstPad * pad, GstBuffer * buf)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
2005-09-22 22:38:48 +00:00
|
|
|
GstFlowReturn ret;
|
2002-02-17 02:06:04 +00:00
|
|
|
GstAuParse *auparse;
|
2005-09-23 04:23:00 +00:00
|
|
|
guchar *data;
|
2001-12-22 23:22:05 +00:00
|
|
|
glong size;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstCaps *tempcaps;
|
2004-05-14 12:36:29 +00:00
|
|
|
gint law = 0, depth = 0, ieee = 0;
|
2004-05-14 10:01:23 +00:00
|
|
|
gchar layout[7];
|
2005-11-21 17:18:01 +00:00
|
|
|
GstBuffer *subbuf;
|
|
|
|
GstEvent *event;
|
2004-05-14 10:01:23 +00:00
|
|
|
|
|
|
|
layout[0] = 0;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
auparse = GST_AU_PARSE (gst_pad_get_parent (pad));
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
data = GST_BUFFER_DATA (buf);
|
|
|
|
size = GST_BUFFER_SIZE (buf);
|
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
GST_DEBUG_OBJECT (auparse, "got buffer of size %ld", size);
|
|
|
|
|
2001-12-22 23:22:05 +00:00
|
|
|
/* if we haven't seen any data yet... */
|
2002-02-17 02:06:04 +00:00
|
|
|
if (auparse->size == 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
guint32 *head = (guint32 *) data;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
/* normal format is big endian (au is a Sparc format) */
|
2004-05-14 10:01:23 +00:00
|
|
|
if (GST_READ_UINT32_BE (head) == 0x2e736e64) { /* ".snd" */
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2002-02-17 02:06:04 +00:00
|
|
|
auparse->le = 0;
|
2004-05-14 10:01:23 +00:00
|
|
|
auparse->offset = GST_READ_UINT32_BE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-14 10:01:23 +00:00
|
|
|
/* Do not trust size, could be set to -1 : unknown */
|
|
|
|
auparse->size = GST_READ_UINT32_BE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-14 10:01:23 +00:00
|
|
|
auparse->encoding = GST_READ_UINT32_BE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-14 10:01:23 +00:00
|
|
|
auparse->frequency = GST_READ_UINT32_BE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-14 10:01:23 +00:00
|
|
|
auparse->channels = GST_READ_UINT32_BE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
/* and of course, someone had to invent a little endian
|
|
|
|
* version. Used by DEC systems. */
|
2004-05-14 10:01:23 +00:00
|
|
|
} else if (GST_READ_UINT32_LE (head) == 0x0064732E) { /* other source say it is "dns." */
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-10 23:55:17 +00:00
|
|
|
auparse->le = 1;
|
2004-05-14 10:01:23 +00:00
|
|
|
auparse->offset = GST_READ_UINT32_LE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-14 10:01:23 +00:00
|
|
|
/* Do not trust size, could be set to -1 : unknown */
|
|
|
|
auparse->size = GST_READ_UINT32_LE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-17 12:06:20 +00:00
|
|
|
auparse->encoding = GST_READ_UINT32_LE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-17 12:06:20 +00:00
|
|
|
auparse->frequency = GST_READ_UINT32_LE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-05-17 12:06:20 +00:00
|
|
|
auparse->channels = GST_READ_UINT32_LE (head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
} else {
|
2004-10-09 20:49:45 +00:00
|
|
|
GST_ELEMENT_ERROR (auparse, STREAM, WRONG_TYPE, (NULL), (NULL));
|
2005-10-31 19:08:27 +00:00
|
|
|
gst_buffer_unref (buf);
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_object_unref (auparse);
|
2005-09-22 22:38:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG
|
2005-09-22 22:38:48 +00:00
|
|
|
("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld\n",
|
2004-03-15 19:32:27 +00:00
|
|
|
auparse->offset, auparse->size, auparse->encoding, auparse->frequency,
|
|
|
|
auparse->channels);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-05-10 23:55:17 +00:00
|
|
|
/*
|
|
|
|
Docs :
|
2005-12-06 19:44:58 +00:00
|
|
|
http://www.opengroup.org/public/pubs/external/auformat.html
|
|
|
|
http://astronomy.swin.edu.au/~pbourke/dataformats/au/
|
|
|
|
Solaris headers : /usr/include/audio/au.h
|
|
|
|
libsndfile : src/au.c
|
2004-05-10 23:55:17 +00:00
|
|
|
Samples :
|
2005-12-06 19:44:58 +00:00
|
|
|
http://www.tsp.ece.mcgill.ca/MMSP/Documents/AudioFormats/AU/Samples.html
|
2004-05-10 23:55:17 +00:00
|
|
|
*/
|
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
switch (auparse->encoding) {
|
2004-05-10 23:55:17 +00:00
|
|
|
|
2004-05-11 22:55:35 +00:00
|
|
|
case 1: /* 8-bit ISDN mu-law G.711 */
|
2004-03-15 19:32:27 +00:00
|
|
|
law = 1;
|
|
|
|
depth = 8;
|
|
|
|
break;
|
2004-05-11 22:55:35 +00:00
|
|
|
case 27: /* 8-bit ISDN A-law G.711 */
|
|
|
|
law = 2;
|
|
|
|
depth = 8;
|
|
|
|
break;
|
2004-05-10 23:55:17 +00:00
|
|
|
|
2004-05-11 22:55:35 +00:00
|
|
|
case 2: /* 8-bit linear PCM */
|
2004-03-15 19:32:27 +00:00
|
|
|
depth = 8;
|
|
|
|
break;
|
2004-05-10 23:55:17 +00:00
|
|
|
case 3: /* 16-bit linear PCM */
|
2004-03-15 19:32:27 +00:00
|
|
|
depth = 16;
|
|
|
|
break;
|
2004-05-10 23:55:17 +00:00
|
|
|
case 4: /* 24-bit linear PCM */
|
|
|
|
depth = 24;
|
|
|
|
break;
|
|
|
|
case 5: /* 32-bit linear PCM */
|
|
|
|
depth = 32;
|
|
|
|
break;
|
|
|
|
|
2004-05-11 22:55:35 +00:00
|
|
|
case 6: /* 32-bit IEEE floating point */
|
2004-05-10 23:55:17 +00:00
|
|
|
ieee = 1;
|
|
|
|
depth = 32;
|
|
|
|
break;
|
2004-05-11 22:55:35 +00:00
|
|
|
case 7: /* 64-bit IEEE floating point */
|
2004-05-10 23:55:17 +00:00
|
|
|
ieee = 1;
|
|
|
|
depth = 64;
|
|
|
|
break;
|
|
|
|
|
2004-05-14 10:01:23 +00:00
|
|
|
case 23: /* 4-bit CCITT G.721 ADPCM 32kbps -> modplug/libsndfile (compressed 8-bit mu-law) */
|
|
|
|
strcpy (layout, "g721");
|
|
|
|
break;
|
|
|
|
case 24: /* 8-bit CCITT G.722 ADPCM -> rtp */
|
|
|
|
strcpy (layout, "g722");
|
|
|
|
break;
|
|
|
|
case 25: /* 3-bit CCITT G.723.3 ADPCM 24kbps -> rtp/xine/modplug/libsndfile */
|
|
|
|
strcpy (layout, "g723_3");
|
|
|
|
break;
|
|
|
|
case 26: /* 5-bit CCITT G.723.5 ADPCM 40kbps -> rtp/xine/modplug/libsndfile */
|
|
|
|
strcpy (layout, "g723_5");
|
|
|
|
break;
|
|
|
|
|
2004-05-11 22:55:35 +00:00
|
|
|
case 8: /* Fragmented sample data */
|
|
|
|
case 9: /* AU_ENCODING_NESTED */
|
|
|
|
|
|
|
|
case 10: /* DSP program */
|
|
|
|
case 11: /* DSP 8-bit fixed point */
|
|
|
|
case 12: /* DSP 16-bit fixed point */
|
|
|
|
case 13: /* DSP 24-bit fixed point */
|
|
|
|
case 14: /* DSP 32-bit fixed point */
|
|
|
|
|
|
|
|
case 16: /* AU_ENCODING_DISPLAY : non-audio display data */
|
|
|
|
case 17: /* AU_ENCODING_MULAW_SQUELCH */
|
|
|
|
|
|
|
|
case 18: /* 16-bit linear with emphasis */
|
2004-05-13 11:32:38 +00:00
|
|
|
case 19: /* 16-bit linear compressed (NeXT) */
|
2004-05-11 22:55:35 +00:00
|
|
|
case 20: /* 16-bit linear with emphasis and compression */
|
|
|
|
|
|
|
|
case 21: /* Music kit DSP commands */
|
|
|
|
case 22: /* Music kit DSP commands samples */
|
|
|
|
|
2001-12-22 23:22:05 +00:00
|
|
|
default:
|
2004-05-11 00:20:02 +00:00
|
|
|
GST_ELEMENT_ERROR (auparse, STREAM, FORMAT, (NULL), (NULL));
|
2005-10-31 19:08:27 +00:00
|
|
|
gst_buffer_unref (buf);
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_object_unref (auparse);
|
2005-09-22 22:38:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
if (law) {
|
2004-05-10 23:55:17 +00:00
|
|
|
tempcaps =
|
|
|
|
gst_caps_new_simple ((law == 1) ? "audio/x-mulaw" : "audio/x-alaw",
|
2004-12-19 16:54:46 +00:00
|
|
|
"rate", G_TYPE_INT, auparse->frequency,
|
|
|
|
"channels", G_TYPE_INT, auparse->channels, NULL);
|
2005-11-21 17:18:01 +00:00
|
|
|
auparse->sample_size = auparse->channels;
|
2004-05-10 23:55:17 +00:00
|
|
|
} else if (ieee) {
|
|
|
|
tempcaps = gst_caps_new_simple ("audio/x-raw-float",
|
2004-12-19 16:54:46 +00:00
|
|
|
"rate", G_TYPE_INT, auparse->frequency,
|
|
|
|
"channels", G_TYPE_INT, auparse->channels,
|
2004-05-10 23:55:17 +00:00
|
|
|
"endianness", G_TYPE_INT,
|
2005-11-21 17:18:01 +00:00
|
|
|
auparse->le ? G_LITTLE_ENDIAN : G_BIG_ENDIAN,
|
|
|
|
"width", G_TYPE_INT, depth, NULL);
|
|
|
|
auparse->sample_size = auparse->channels * depth / 8;
|
2004-05-14 10:01:23 +00:00
|
|
|
} else if (layout[0]) {
|
2004-05-13 21:27:14 +00:00
|
|
|
tempcaps = gst_caps_new_simple ("audio/x-adpcm",
|
|
|
|
"layout", G_TYPE_STRING, layout, NULL);
|
2005-11-21 17:18:01 +00:00
|
|
|
auparse->sample_size = 0;
|
2003-07-06 20:49:52 +00:00
|
|
|
} else {
|
2003-12-22 01:47:09 +00:00
|
|
|
tempcaps = gst_caps_new_simple ("audio/x-raw-int",
|
2004-12-19 16:54:46 +00:00
|
|
|
"rate", G_TYPE_INT, auparse->frequency,
|
|
|
|
"channels", G_TYPE_INT, auparse->channels,
|
2004-05-10 23:55:17 +00:00
|
|
|
"endianness", G_TYPE_INT,
|
2004-12-19 16:54:46 +00:00
|
|
|
auparse->le ? G_LITTLE_ENDIAN : G_BIG_ENDIAN, "depth", G_TYPE_INT,
|
|
|
|
depth, "width", G_TYPE_INT, depth, "signed", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
NULL);
|
2005-11-21 17:18:01 +00:00
|
|
|
auparse->sample_size = auparse->channels * depth / 8;
|
2003-07-06 20:49:52 +00:00
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2005-09-22 22:38:48 +00:00
|
|
|
gst_pad_set_active (auparse->srcpad, TRUE);
|
|
|
|
gst_pad_set_caps (auparse->srcpad, tempcaps);
|
|
|
|
|
2005-11-22 11:53:34 +00:00
|
|
|
event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_DEFAULT,
|
2005-11-21 17:18:01 +00:00
|
|
|
0, GST_CLOCK_TIME_NONE, 0);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
gst_pad_push_event (auparse->srcpad, event);
|
2004-05-11 00:20:02 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
subbuf = gst_buffer_create_sub (buf, auparse->offset,
|
|
|
|
size - auparse->offset);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
gst_buffer_unref (buf);
|
2005-09-22 22:38:48 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
gst_adapter_push (auparse->adapter, subbuf);
|
|
|
|
} else {
|
|
|
|
gst_adapter_push (auparse->adapter, buf);
|
|
|
|
}
|
2005-09-22 22:38:48 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
if (auparse->sample_size) {
|
|
|
|
/* Ensure we push a buffer that's a multiple of the frame size downstream */
|
|
|
|
int avail = gst_adapter_available (auparse->adapter);
|
2005-09-22 22:38:48 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
avail -= avail % auparse->sample_size;
|
2005-09-22 22:38:48 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
if (avail > 0) {
|
|
|
|
const guint8 *data = gst_adapter_peek (auparse->adapter, avail);
|
|
|
|
GstBuffer *newbuf;
|
2005-09-22 22:38:48 +00:00
|
|
|
|
2005-12-05 13:03:00 +00:00
|
|
|
if ((ret =
|
|
|
|
gst_pad_alloc_buffer_and_set_caps (auparse->srcpad,
|
|
|
|
auparse->buffer_offset, avail, GST_PAD_CAPS (auparse->srcpad),
|
2005-11-21 17:18:01 +00:00
|
|
|
&newbuf)) == GST_FLOW_OK) {
|
|
|
|
|
|
|
|
memcpy (GST_BUFFER_DATA (newbuf), data, avail);
|
|
|
|
gst_adapter_flush (auparse->adapter, avail);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
auparse->buffer_offset += avail;
|
|
|
|
|
|
|
|
ret = gst_pad_push (auparse->srcpad, newbuf);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
} else {
|
|
|
|
/* It's something non-trivial (such as ADPCM), we don't understand it, so
|
|
|
|
* just push downstream and assume this will know what to do with it */
|
|
|
|
ret = gst_pad_push (auparse->srcpad, buf);
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_object_unref (auparse);
|
2005-09-22 22:38:48 +00:00
|
|
|
|
2005-11-21 17:18:01 +00:00
|
|
|
return ret;
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2005-09-02 15:44:50 +00:00
|
|
|
static GstStateChangeReturn
|
2005-12-12 10:30:20 +00:00
|
|
|
gst_au_parse_change_state (GstElement * element, GstStateChange transition)
|
2004-05-11 00:20:02 +00:00
|
|
|
{
|
2005-12-12 10:30:20 +00:00
|
|
|
GstAuParse *auparse = GST_AU_PARSE (element);
|
2005-10-31 19:08:27 +00:00
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
2005-12-12 10:30:20 +00:00
|
|
|
ret = parent_class->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
2005-10-31 19:08:27 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2005-11-21 17:18:01 +00:00
|
|
|
gst_adapter_clear (auparse->adapter);
|
|
|
|
auparse->buffer_offset = 0;
|
2005-10-31 19:08:27 +00:00
|
|
|
auparse->offset = 0;
|
|
|
|
auparse->size = 0;
|
|
|
|
auparse->encoding = 0;
|
|
|
|
auparse->frequency = 0;
|
|
|
|
auparse->channels = 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-05-11 00:20:02 +00:00
|
|
|
|
2005-10-31 19:08:27 +00:00
|
|
|
return ret;
|
2004-05-11 00:20:02 +00:00
|
|
|
}
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
2003-11-01 01:32:29 +00:00
|
|
|
if (!gst_element_register (plugin, "auparse", GST_RANK_SECONDARY,
|
2005-12-12 10:30:20 +00:00
|
|
|
GST_TYPE_AU_PARSE)) {
|
2003-11-01 01:32:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"auparse",
|
2005-11-14 02:13:35 +00:00
|
|
|
"parses au streams", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
|
|
|
|
GST_PACKAGE_ORIGIN)
|