2003-10-29 23:50:00 +00:00
|
|
|
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
|
2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:27:31 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:27:31 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gstwavparse.h>
|
|
|
|
|
2003-11-02 19:28:08 +00:00
|
|
|
static void gst_wavparse_base_init (gpointer g_class);
|
2003-03-01 18:34:38 +00:00
|
|
|
static void gst_wavparse_class_init (GstWavParseClass *klass);
|
|
|
|
static void gst_wavparse_init (GstWavParse *wavparse);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-06-13 22:11:56 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_wavparse_change_state (GstElement *element);
|
|
|
|
|
2002-11-03 13:59:35 +00:00
|
|
|
static const GstFormat* gst_wavparse_get_formats (GstPad *pad);
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType *
|
2002-11-03 13:59:35 +00:00
|
|
|
gst_wavparse_get_query_types (GstPad *pad);
|
2003-03-01 18:34:38 +00:00
|
|
|
static gboolean gst_wavparse_pad_query (GstPad *pad,
|
|
|
|
GstQueryType type,
|
|
|
|
GstFormat *format,
|
|
|
|
gint64 *value);
|
|
|
|
static gboolean gst_wavparse_pad_convert (GstPad *pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value,
|
|
|
|
GstFormat *dest_format,
|
|
|
|
gint64 *dest_value);
|
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
static void gst_wavparse_loop (GstElement *element);
|
2003-03-01 18:34:38 +00:00
|
|
|
static const GstEventMask*
|
|
|
|
gst_wavparse_get_event_masks (GstPad *pad);
|
|
|
|
static gboolean gst_wavparse_srcpad_event (GstPad *pad, GstEvent *event);
|
2003-10-17 00:29:44 +00:00
|
|
|
static void gst_wavparse_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
2003-11-02 19:28:08 +00:00
|
|
|
static GstElementDetails gst_wavparse_details = GST_ELEMENT_DETAILS (
|
2003-11-16 22:02:22 +00:00
|
|
|
".wav demuxer",
|
|
|
|
"Codec/Demuxer",
|
2001-12-22 23:27:31 +00:00
|
|
|
"Parse a .wav file into raw audio",
|
2003-11-02 19:28:08 +00:00
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>"
|
|
|
|
);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate sink_template_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
2002-01-30 10:20:58 +00:00
|
|
|
"wavparse_sink",
|
2001-12-22 23:27:31 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-wav")
|
|
|
|
);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate src_template_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
2002-01-30 10:20:58 +00:00
|
|
|
"wavparse_src",
|
2001-12-22 23:27:31 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_STATIC_CAPS_ANY
|
|
|
|
);
|
|
|
|
#if 0
|
|
|
|
GST_STATIC_CAPS (
|
2003-01-14 14:01:49 +00:00
|
|
|
"wavparse_raw",
|
2003-07-06 20:49:52 +00:00
|
|
|
"audio/x-raw-int",
|
2003-12-22 01:47:09 +00:00
|
|
|
"endianness", G_TYPE_INT (G_LITTLE_ENDIAN),
|
2002-12-08 12:23:48 +00:00
|
|
|
"signed", GST_PROPS_LIST (
|
2003-12-22 01:47:09 +00:00
|
|
|
G_TYPE_BOOLEAN (FALSE),
|
|
|
|
G_TYPE_BOOLEAN (TRUE)
|
2002-12-08 12:23:48 +00:00
|
|
|
),
|
2001-12-22 23:27:31 +00:00
|
|
|
"width", GST_PROPS_LIST (
|
2003-12-22 01:47:09 +00:00
|
|
|
G_TYPE_INT (8),
|
|
|
|
G_TYPE_INT (16)
|
2001-12-22 23:27:31 +00:00
|
|
|
),
|
|
|
|
"depth", GST_PROPS_LIST (
|
2003-12-22 01:47:09 +00:00
|
|
|
G_TYPE_INT (8),
|
|
|
|
G_TYPE_INT (16)
|
2001-12-22 23:27:31 +00:00
|
|
|
),
|
2003-12-22 01:47:09 +00:00
|
|
|
"rate", G_TYPE_INT_RANGE (8000, 48000),
|
|
|
|
"channels", G_TYPE_INT_RANGE (1, 2)
|
2003-01-14 14:01:49 +00:00
|
|
|
),
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_STATIC_CAPS (
|
2003-07-06 20:49:52 +00:00
|
|
|
"wavparse_mpeg",
|
|
|
|
"audio/mpeg",
|
2003-12-22 01:47:09 +00:00
|
|
|
"mpegversion", G_TYPE_INT, 1,
|
|
|
|
"rate", G_TYPE_INT_RANGE (8000, 48000),
|
|
|
|
"channels", G_TYPE_INT_RANGE (1, 2),
|
|
|
|
"layer", G_TYPE_INT_RANGE (1, 3)
|
2003-04-11 21:52:18 +00:00
|
|
|
),
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_STATIC_CAPS (
|
2003-04-11 21:52:18 +00:00
|
|
|
"parsewav_law",
|
2003-07-06 20:49:52 +00:00
|
|
|
"audio/x-alaw",
|
2003-12-22 01:47:09 +00:00
|
|
|
"rate", G_TYPE_INT_RANGE (8000, 48000),
|
|
|
|
"channels", G_TYPE_INT_RANGE (1, 2)
|
2003-07-06 20:49:52 +00:00
|
|
|
),
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_STATIC_CAPS (
|
2003-07-06 20:49:52 +00:00
|
|
|
"parsewav_law",
|
|
|
|
"audio/x-mulaw",
|
2003-12-22 01:47:09 +00:00
|
|
|
"rate", G_TYPE_INT_RANGE (8000, 48000),
|
|
|
|
"channels", G_TYPE_INT_RANGE (1, 2)
|
2001-12-22 23:27:31 +00:00
|
|
|
)
|
2003-12-22 01:47:09 +00:00
|
|
|
#endif
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-30 10:20:58 +00:00
|
|
|
/* WavParse signals and args */
|
2001-12-22 23:27:31 +00:00
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2003-10-17 00:29:44 +00:00
|
|
|
PROP_0,
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-03-19 04:10:05 +00:00
|
|
|
/*static guint gst_wavparse_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
GType
|
2002-01-30 10:20:58 +00:00
|
|
|
gst_wavparse_get_type (void)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2002-01-30 10:20:58 +00:00
|
|
|
static GType wavparse_type = 0;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-30 10:20:58 +00:00
|
|
|
if (!wavparse_type) {
|
|
|
|
static const GTypeInfo wavparse_info = {
|
2003-11-02 19:28:08 +00:00
|
|
|
sizeof(GstWavParseClass),
|
|
|
|
gst_wavparse_base_init,
|
2001-12-22 23:27:31 +00:00
|
|
|
NULL,
|
2002-01-30 10:20:58 +00:00
|
|
|
(GClassInitFunc) gst_wavparse_class_init,
|
2001-12-22 23:27:31 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-01-30 10:20:58 +00:00
|
|
|
sizeof(GstWavParse),
|
2001-12-22 23:27:31 +00:00
|
|
|
0,
|
2002-01-30 10:20:58 +00:00
|
|
|
(GInstanceInitFunc) gst_wavparse_init,
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
2002-01-30 10:20:58 +00:00
|
|
|
wavparse_type = g_type_register_static (GST_TYPE_ELEMENT, "GstWavParse", &wavparse_info, 0);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2002-01-30 10:20:58 +00:00
|
|
|
return wavparse_type;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 19:28:08 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wavparse_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_wavparse_details);
|
|
|
|
|
|
|
|
/* register src pads */
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&sink_template_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_template_factory));
|
2003-11-02 19:28:08 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
static void
|
2002-01-30 10:20:58 +00:00
|
|
|
gst_wavparse_class_init (GstWavParseClass *klass)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class;
|
2003-10-17 00:29:44 +00:00
|
|
|
GObjectClass *object_class;
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
gstelement_class = (GstElementClass*) klass;
|
2003-10-17 00:29:44 +00:00
|
|
|
object_class = (GObjectClass *) klass;
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2003-06-13 22:11:56 +00:00
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
object_class->get_property = gst_wavparse_get_property;
|
2003-06-13 22:11:56 +00:00
|
|
|
gstelement_class->change_state = gst_wavparse_change_state;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-01-30 10:20:58 +00:00
|
|
|
gst_wavparse_init (GstWavParse *wavparse)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2002-11-03 13:59:35 +00:00
|
|
|
/* sink */
|
2003-12-22 01:47:09 +00:00
|
|
|
wavparse->sinkpad = gst_pad_new_from_template (gst_static_pad_template_get (&sink_template_factory), "sink");
|
2002-01-30 10:20:58 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (wavparse), wavparse->sinkpad);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-11-03 13:59:35 +00:00
|
|
|
gst_pad_set_formats_function (wavparse->sinkpad, gst_wavparse_get_formats);
|
|
|
|
gst_pad_set_convert_function (wavparse->sinkpad, gst_wavparse_pad_convert);
|
|
|
|
gst_pad_set_query_type_function (wavparse->sinkpad,
|
|
|
|
gst_wavparse_get_query_types);
|
|
|
|
gst_pad_set_query_function (wavparse->sinkpad, gst_wavparse_pad_query);
|
|
|
|
|
|
|
|
/* source */
|
2003-12-22 01:47:09 +00:00
|
|
|
wavparse->srcpad = gst_pad_new_from_template (gst_static_pad_template_get (&src_template_factory), "src");
|
2004-01-14 10:48:18 +00:00
|
|
|
gst_pad_use_explicit_caps (wavparse->srcpad);
|
2002-01-30 10:20:58 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (wavparse), wavparse->srcpad);
|
2002-11-03 13:59:35 +00:00
|
|
|
gst_pad_set_formats_function (wavparse->srcpad, gst_wavparse_get_formats);
|
|
|
|
gst_pad_set_convert_function (wavparse->srcpad, gst_wavparse_pad_convert);
|
2003-01-14 14:01:49 +00:00
|
|
|
gst_pad_set_query_type_function (wavparse->srcpad,
|
2002-11-03 13:59:35 +00:00
|
|
|
gst_wavparse_get_query_types);
|
|
|
|
gst_pad_set_query_function (wavparse->srcpad, gst_wavparse_pad_query);
|
2003-03-01 18:34:38 +00:00
|
|
|
gst_pad_set_event_function (wavparse->srcpad, gst_wavparse_srcpad_event);
|
|
|
|
gst_pad_set_event_mask_function (wavparse->srcpad, gst_wavparse_get_event_masks);
|
2002-11-03 13:59:35 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_element_set_loop_function (GST_ELEMENT (wavparse), gst_wavparse_loop);
|
2002-11-03 13:59:35 +00:00
|
|
|
|
2002-01-30 10:20:58 +00:00
|
|
|
wavparse->state = GST_WAVPARSE_UNKNOWN;
|
|
|
|
wavparse->bps = 0;
|
2003-10-29 23:50:00 +00:00
|
|
|
wavparse->seek_pending = FALSE;
|
|
|
|
wavparse->seek_offset = 0;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
static void
|
|
|
|
gst_wavparse_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstWavParse *wavparse;
|
|
|
|
|
|
|
|
wavparse = GST_WAVPARSE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
#if 0
|
2003-10-17 00:29:44 +00:00
|
|
|
static void
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_wavparse_parse_adtl (GstWavParse *wavparse,
|
|
|
|
int len)
|
2003-10-17 00:29:44 +00:00
|
|
|
{
|
2003-10-29 23:50:00 +00:00
|
|
|
guint32 got_bytes;
|
|
|
|
GstByteStream *bs = wavparse->bs;
|
2003-10-17 00:29:44 +00:00
|
|
|
gst_riff_chunk *temp_chunk, chunk;
|
2003-10-29 23:50:00 +00:00
|
|
|
guint8 *tempdata;
|
|
|
|
struct _gst_riff_labl labl, *temp_labl;
|
|
|
|
struct _gst_riff_ltxt ltxt, *temp_ltxt;
|
|
|
|
struct _gst_riff_note note, *temp_note;
|
|
|
|
char *label_name;
|
2003-10-17 00:29:44 +00:00
|
|
|
GstProps *props;
|
2003-10-29 23:50:00 +00:00
|
|
|
GstPropsEntry *entry;
|
|
|
|
GstCaps *new_caps;
|
|
|
|
GList *caps = NULL;
|
2003-10-17 00:29:44 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
props = wavparse->metadata->properties;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, sizeof (gst_riff_chunk));
|
|
|
|
if (got_bytes != sizeof (gst_riff_chunk)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
temp_chunk = (gst_riff_chunk *) tempdata;
|
|
|
|
|
|
|
|
chunk.id = GUINT32_FROM_LE (temp_chunk->id);
|
|
|
|
chunk.size = GUINT32_FROM_LE (temp_chunk->size);
|
|
|
|
|
|
|
|
if (chunk.size == 0) {
|
|
|
|
gst_bytestream_flush (bs, sizeof (gst_riff_chunk));
|
|
|
|
len -= sizeof (gst_riff_chunk);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (chunk.id) {
|
|
|
|
case GST_RIFF_adtl_labl:
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, sizeof (struct _gst_riff_labl));
|
|
|
|
if (got_bytes != sizeof (struct _gst_riff_labl)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp_labl = (struct _gst_riff_labl *) tempdata;
|
|
|
|
labl.id = GUINT32_FROM_LE (temp_labl->id);
|
|
|
|
labl.size = GUINT32_FROM_LE (temp_labl->size);
|
|
|
|
labl.identifier = GUINT32_FROM_LE (temp_labl->identifier);
|
|
|
|
|
|
|
|
gst_bytestream_flush (bs, sizeof (struct _gst_riff_labl));
|
|
|
|
len -= sizeof (struct _gst_riff_labl);
|
|
|
|
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, labl.size - 4);
|
|
|
|
if (got_bytes != labl.size - 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
label_name = (char *) tempdata;
|
|
|
|
|
|
|
|
gst_bytestream_flush (bs, ((labl.size - 4) + 1) & ~1);
|
|
|
|
len -= (( (labl.size - 4) + 1) & ~1);
|
|
|
|
|
|
|
|
new_caps = gst_caps_new ("label",
|
|
|
|
"application/x-gst-metadata",
|
|
|
|
gst_props_new (
|
2003-12-22 01:47:09 +00:00
|
|
|
"identifier", G_TYPE_INT (labl.identifier),
|
|
|
|
"name", G_TYPE_STRING (label_name),
|
2003-10-29 23:50:00 +00:00
|
|
|
NULL));
|
|
|
|
|
|
|
|
if (gst_props_get (props, "labels", &caps, NULL)) {
|
|
|
|
caps = g_list_append (caps, new_caps);
|
|
|
|
} else {
|
|
|
|
caps = g_list_append (NULL, new_caps);
|
|
|
|
|
|
|
|
entry = gst_props_entry_new ("labels", GST_PROPS_GLIST (caps));
|
|
|
|
gst_props_add_entry (props, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_adtl_ltxt:
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, sizeof (struct _gst_riff_ltxt));
|
|
|
|
if (got_bytes != sizeof (struct _gst_riff_ltxt)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp_ltxt = (struct _gst_riff_ltxt *) tempdata;
|
|
|
|
ltxt.id = GUINT32_FROM_LE (temp_ltxt->id);
|
|
|
|
ltxt.size = GUINT32_FROM_LE (temp_ltxt->size);
|
|
|
|
ltxt.identifier = GUINT32_FROM_LE (temp_ltxt->identifier);
|
|
|
|
ltxt.length = GUINT32_FROM_LE (temp_ltxt->length);
|
|
|
|
ltxt.purpose = GUINT32_FROM_LE (temp_ltxt->purpose);
|
|
|
|
ltxt.country = GUINT16_FROM_LE (temp_ltxt->country);
|
|
|
|
ltxt.language = GUINT16_FROM_LE (temp_ltxt->language);
|
|
|
|
ltxt.dialect = GUINT16_FROM_LE (temp_ltxt->dialect);
|
|
|
|
ltxt.codepage = GUINT16_FROM_LE (temp_ltxt->codepage);
|
|
|
|
|
|
|
|
gst_bytestream_flush (bs, sizeof (struct _gst_riff_ltxt));
|
|
|
|
len -= sizeof (struct _gst_riff_ltxt);
|
|
|
|
|
|
|
|
if (ltxt.size - 20 > 0) {
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, ltxt.size - 20);
|
|
|
|
if (got_bytes != ltxt.size - 20) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_bytestream_flush (bs, ((ltxt.size - 20) + 1) & ~1);
|
|
|
|
len -= (( (ltxt.size - 20) + 1) & ~1);
|
|
|
|
|
|
|
|
label_name = (char *) tempdata;
|
|
|
|
} else {
|
|
|
|
label_name = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
new_caps = gst_caps_new ("ltxt",
|
|
|
|
"application/x-gst-metadata",
|
|
|
|
gst_props_new (
|
2003-12-22 01:47:09 +00:00
|
|
|
"identifier", G_TYPE_INT (ltxt.identifier),
|
|
|
|
"name", G_TYPE_STRING (label_name),
|
|
|
|
"length", G_TYPE_INT (ltxt.length),
|
2003-10-29 23:50:00 +00:00
|
|
|
NULL));
|
|
|
|
|
|
|
|
if (gst_props_get (props, "ltxts", &caps, NULL)) {
|
|
|
|
caps = g_list_append (caps, new_caps);
|
|
|
|
} else {
|
|
|
|
caps = g_list_append (NULL, new_caps);
|
|
|
|
|
|
|
|
entry = gst_props_entry_new ("ltxts", GST_PROPS_GLIST (caps));
|
|
|
|
gst_props_add_entry (props, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_adtl_note:
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, sizeof (struct _gst_riff_note));
|
|
|
|
if (got_bytes != sizeof (struct _gst_riff_note)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp_note = (struct _gst_riff_note *) tempdata;
|
|
|
|
note.id = GUINT32_FROM_LE (temp_note->id);
|
|
|
|
note.size = GUINT32_FROM_LE (temp_note->size);
|
|
|
|
note.identifier = GUINT32_FROM_LE (temp_note->identifier);
|
|
|
|
|
|
|
|
gst_bytestream_flush (bs, sizeof (struct _gst_riff_note));
|
|
|
|
len -= sizeof (struct _gst_riff_note);
|
|
|
|
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, note.size - 4);
|
|
|
|
if (got_bytes != note.size - 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_bytestream_flush (bs, ((note.size - 4) + 1) & ~1);
|
|
|
|
len -= (( (note.size - 4) + 1) & ~1);
|
|
|
|
|
|
|
|
label_name = (char *) tempdata;
|
|
|
|
|
|
|
|
new_caps = gst_caps_new ("note",
|
|
|
|
"application/x-gst-metadata",
|
|
|
|
gst_props_new (
|
2003-12-22 01:47:09 +00:00
|
|
|
"identifier", G_TYPE_INT (note.identifier),
|
|
|
|
"name", G_TYPE_STRING (label_name),
|
2003-10-29 23:50:00 +00:00
|
|
|
NULL));
|
|
|
|
|
|
|
|
if (gst_props_get (props, "notes", &caps, NULL)) {
|
|
|
|
caps = g_list_append (caps, new_caps);
|
|
|
|
} else {
|
|
|
|
caps = g_list_append (NULL, new_caps);
|
|
|
|
|
|
|
|
entry = gst_props_entry_new ("notes", GST_PROPS_GLIST (caps));
|
|
|
|
gst_props_add_entry (props, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_print ("Unknown chunk: " GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS(chunk.id));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-11-14 15:02:42 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (wavparse), "metadata");
|
2003-10-29 23:50:00 +00:00
|
|
|
}
|
2004-01-02 08:12:12 +00:00
|
|
|
#endif
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2004-01-02 08:12:12 +00:00
|
|
|
#if 0
|
2003-10-29 23:50:00 +00:00
|
|
|
static void
|
|
|
|
gst_wavparse_parse_info (GstWavParse *wavparse,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
gst_riff_chunk *temp_chunk, chunk;
|
|
|
|
GstByteStream *bs = wavparse->bs;
|
|
|
|
guint8 *tempdata;
|
|
|
|
guint32 got_bytes;
|
|
|
|
char *name, *type;
|
2003-10-17 00:29:44 +00:00
|
|
|
|
|
|
|
while (len > 0) {
|
2003-10-29 23:50:00 +00:00
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, sizeof (gst_riff_chunk));
|
|
|
|
temp_chunk = (gst_riff_chunk *) tempdata;
|
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
chunk.id = GUINT32_FROM_LE (temp_chunk->id);
|
|
|
|
chunk.size = GUINT32_FROM_LE (temp_chunk->size);
|
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_bytestream_flush (bs, sizeof (gst_riff_chunk));
|
|
|
|
if (got_bytes != sizeof (gst_riff_chunk)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
/* move our pointer on past the header */
|
|
|
|
len -= sizeof (gst_riff_chunk);
|
|
|
|
|
|
|
|
if (chunk.size == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, chunk.size);
|
|
|
|
name = (char *) tempdata;
|
|
|
|
if (got_bytes != chunk.size) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
/* move our pointer on past the data ... on an even boundary */
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_bytestream_flush (bs, (chunk.size + 1) & ~1);
|
2003-10-17 00:29:44 +00:00
|
|
|
len -= ((chunk.size + 1) & ~1);
|
|
|
|
|
|
|
|
/* We now have an info string in 'name' of type chunk.id
|
|
|
|
- find type */
|
|
|
|
switch (chunk.id) {
|
|
|
|
case GST_RIFF_INFO_IARL:
|
|
|
|
type = "Location";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_IART:
|
|
|
|
type = "Artist";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_ICMS:
|
|
|
|
type = "Commissioner";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_ICMT:
|
|
|
|
type = "Comment";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_ICOP:
|
|
|
|
type = "Copyright";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_ICRD:
|
|
|
|
type = "Creation Date";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_IENG:
|
|
|
|
type = "Engineer";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_IGNR:
|
|
|
|
type = "Genre";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_IKEY:
|
|
|
|
type = "Keywords";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_INAM:
|
|
|
|
type = "Title"; /* name */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_IPRD:
|
|
|
|
type = "Product";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_ISBJ:
|
|
|
|
type = "Subject";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_ISFT:
|
|
|
|
type = "Software";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_INFO_ITCH:
|
|
|
|
type = "Technician";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-11-14 15:02:42 +00:00
|
|
|
g_print ("Unknown: %4.4s\n", (char *) &chunk.id);
|
2003-10-17 00:29:44 +00:00
|
|
|
type = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
if (type) {
|
2003-10-29 23:50:00 +00:00
|
|
|
GstPropsEntry *entry;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
entry = gst_props_entry_new (type, G_TYPE_STRING (name));
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_props_add_entry (wavparse->metadata->properties, entry);
|
2003-10-17 00:29:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (wavparse), "metadata");
|
|
|
|
}
|
2004-01-02 08:12:12 +00:00
|
|
|
#endif
|
2003-10-17 00:29:44 +00:00
|
|
|
|
2004-01-02 08:12:12 +00:00
|
|
|
#if 0
|
2003-10-29 23:50:00 +00:00
|
|
|
static void
|
|
|
|
gst_wavparse_parse_cues (GstWavParse *wavparse,
|
|
|
|
int len)
|
2003-08-13 06:41:09 +00:00
|
|
|
{
|
2003-10-29 23:50:00 +00:00
|
|
|
guint32 got_bytes;
|
|
|
|
GstByteStream *bs = wavparse->bs;
|
|
|
|
struct _gst_riff_cue *temp_cue, cue;
|
|
|
|
struct _gst_riff_cuepoints *points;
|
|
|
|
guint8 *tempdata;
|
|
|
|
int i;
|
|
|
|
GList *cues = NULL;
|
|
|
|
GstPropsEntry *entry;
|
2003-08-13 06:41:09 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
while (len > 0) {
|
2003-11-14 15:02:42 +00:00
|
|
|
int required;
|
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, sizeof (struct _gst_riff_cue));
|
|
|
|
temp_cue = (struct _gst_riff_cue *) tempdata;
|
2003-08-13 06:41:09 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
/* fixup for our big endian friends */
|
|
|
|
cue.id = GUINT32_FROM_LE (temp_cue->id);
|
|
|
|
cue.size = GUINT32_FROM_LE (temp_cue->size);
|
|
|
|
cue.cuepoints = GUINT32_FROM_LE (temp_cue->cuepoints);
|
|
|
|
|
|
|
|
gst_bytestream_flush (bs, sizeof (struct _gst_riff_cue));
|
|
|
|
if (got_bytes != sizeof (struct _gst_riff_cue)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len -= sizeof (struct _gst_riff_cue);
|
|
|
|
|
|
|
|
/* -4 because cue.size contains the cuepoints size
|
|
|
|
and we've already flushed that out of the system */
|
2003-11-14 15:02:42 +00:00
|
|
|
required = cue.size - 4;
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, required);
|
|
|
|
gst_bytestream_flush (bs, ((required) + 1) & ~1);
|
|
|
|
if (got_bytes != required) {
|
2003-10-29 23:50:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len -= ( ((cue.size - 4) + 1) & ~1);
|
|
|
|
|
|
|
|
/* now we have an array of struct _gst_riff_cuepoints in tempdata */
|
|
|
|
points = (struct _gst_riff_cuepoints *) tempdata;
|
2003-10-17 00:29:44 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
for (i = 0; i < cue.cuepoints; i++) {
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_caps_new ("cues",
|
|
|
|
"application/x-gst-metadata",
|
|
|
|
gst_props_new (
|
2003-12-22 01:47:09 +00:00
|
|
|
"identifier", G_TYPE_INT (points[i].identifier),
|
|
|
|
"position", G_TYPE_INT (points[i].offset),
|
2003-10-29 23:50:00 +00:00
|
|
|
NULL));
|
|
|
|
cues = g_list_append (cues, caps);
|
|
|
|
}
|
2003-10-17 00:29:44 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
entry = gst_props_entry_new ("cues", GST_PROPS_GLIST (cues));
|
|
|
|
gst_props_add_entry (wavparse->metadata->properties, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (wavparse), "metadata");
|
|
|
|
}
|
2004-01-02 08:12:12 +00:00
|
|
|
#endif
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
static void
|
2004-01-14 10:48:18 +00:00
|
|
|
gst_wavparse_parse_fmt (GstWavParse *wavparse, guint size)
|
2003-10-29 23:50:00 +00:00
|
|
|
{
|
|
|
|
GstWavParseFormat *format;
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
guint8 *fmtdata;
|
|
|
|
GstByteStream *bs = wavparse->bs;
|
|
|
|
guint32 got_bytes;
|
|
|
|
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &fmtdata, sizeof (GstWavParseFormat));
|
|
|
|
format = (GstWavParseFormat *) fmtdata;
|
|
|
|
|
|
|
|
if (got_bytes == sizeof (GstWavParseFormat)) {
|
2004-01-14 10:48:18 +00:00
|
|
|
gst_bytestream_flush (bs, size);
|
2003-10-29 23:50:00 +00:00
|
|
|
wavparse->bps = GUINT16_FROM_LE (format->wBlockAlign);
|
|
|
|
wavparse->rate = GUINT32_FROM_LE (format->dwSamplesPerSec);
|
|
|
|
wavparse->channels = GUINT16_FROM_LE (format->wChannels);
|
|
|
|
wavparse->width = GUINT16_FROM_LE (format->wBitsPerSample);
|
|
|
|
wavparse->format = GINT16_FROM_LE (format->wFormatTag);
|
|
|
|
|
2003-08-13 06:41:09 +00:00
|
|
|
/* set the caps on the src pad */
|
|
|
|
/* FIXME: handle all of the other formats as well */
|
2003-10-17 00:29:44 +00:00
|
|
|
switch (wavparse->format) {
|
|
|
|
case GST_RIFF_WAVE_FORMAT_ALAW:
|
|
|
|
case GST_RIFF_WAVE_FORMAT_MULAW: {
|
2003-10-29 23:50:00 +00:00
|
|
|
char *mime = (wavparse->format == GST_RIFF_WAVE_FORMAT_ALAW) ?
|
|
|
|
"audio/x-alaw" : "audio/x-mulaw";
|
|
|
|
if (wavparse->width != 8) {
|
|
|
|
g_warning ("Ignoring invalid width %d", wavparse->width);
|
|
|
|
return;
|
2003-10-17 00:29:44 +00:00
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
caps = gst_caps_new_simple (mime,
|
|
|
|
"rate", G_TYPE_INT, wavparse->rate,
|
|
|
|
"channels", G_TYPE_INT, wavparse->channels,
|
|
|
|
NULL);
|
2003-08-13 06:41:09 +00:00
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
case GST_RIFF_WAVE_FORMAT_PCM:
|
2003-12-22 01:47:09 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw-int",
|
|
|
|
"endianness", G_TYPE_INT, G_LITTLE_ENDIAN,
|
|
|
|
"signed", G_TYPE_BOOLEAN, (wavparse->width > 8) ? TRUE : FALSE,
|
|
|
|
"width", G_TYPE_INT, wavparse->width,
|
|
|
|
"depth", G_TYPE_INT, wavparse->width,
|
|
|
|
"rate", G_TYPE_INT, wavparse->rate,
|
|
|
|
"channels", G_TYPE_INT, wavparse->channels,
|
|
|
|
NULL);
|
2003-10-17 00:29:44 +00:00
|
|
|
break;
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
case GST_RIFF_WAVE_FORMAT_MPEGL12:
|
|
|
|
case GST_RIFF_WAVE_FORMAT_MPEGL3: {
|
2003-10-29 23:50:00 +00:00
|
|
|
int layer = (wavparse->format == GST_RIFF_WAVE_FORMAT_MPEGL12) ? 2 : 3;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/mpeg",
|
|
|
|
"mpegversion", G_TYPE_INT, 1,
|
|
|
|
"layer", G_TYPE_INT, layer,
|
|
|
|
"rate", G_TYPE_INT, wavparse->rate,
|
|
|
|
"channels", G_TYPE_INT, wavparse->channels,
|
|
|
|
NULL);
|
2003-10-17 00:29:44 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-10-17 00:29:44 +00:00
|
|
|
default:
|
|
|
|
gst_element_error (GST_ELEMENT (wavparse), "wavparse: format %d not handled", wavparse->format);
|
|
|
|
return;
|
|
|
|
}
|
2004-01-04 15:23:03 +00:00
|
|
|
|
|
|
|
if (caps)
|
2004-01-14 10:48:18 +00:00
|
|
|
gst_pad_set_explicit_caps (wavparse->srcpad, caps);
|
2004-01-02 07:09:23 +00:00
|
|
|
|
2003-08-13 06:41:09 +00:00
|
|
|
GST_DEBUG ("frequency %d, channels %d",
|
2003-10-29 23:50:00 +00:00
|
|
|
wavparse->rate, wavparse->channels);
|
|
|
|
}
|
|
|
|
}
|
2003-08-13 06:41:09 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
static gboolean
|
|
|
|
gst_wavparse_handle_sink_event (GstWavParse *wavparse)
|
|
|
|
{
|
|
|
|
guint32 remaining;
|
|
|
|
GstEvent *event;
|
|
|
|
GstEventType type;
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
gst_bytestream_get_status (wavparse->bs, &remaining, &event);
|
|
|
|
|
|
|
|
type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
|
|
|
|
GST_DEBUG ("wavparse: event %p %d", event, type);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
gst_bytestream_flush (wavparse->bs, remaining);
|
|
|
|
gst_pad_event_default (wavparse->sinkpad, event);
|
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
case GST_EVENT_FLUSH:
|
|
|
|
g_warning ("Wavparse: Flush event");
|
2003-10-17 00:29:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-10-29 23:50:00 +00:00
|
|
|
g_warning ("Wavparse: Unhandled event %d", type);
|
2003-10-17 00:29:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-08-13 06:41:09 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_wavparse_loop (GstElement *element)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2002-01-30 10:20:58 +00:00
|
|
|
GstWavParse *wavparse;
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_riff_riff chunk;
|
|
|
|
guint32 flush = 0;
|
|
|
|
guint32 got_bytes;
|
|
|
|
GstByteStream *bs;
|
2003-03-01 18:34:38 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
wavparse = GST_WAVPARSE (element);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
bs = wavparse->bs;
|
2003-08-13 06:41:09 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
if (wavparse->seek_pending) {
|
|
|
|
GST_DEBUG ("wavparse: seek pending to %" G_GINT64_FORMAT " %08llx",
|
|
|
|
wavparse->seek_offset,
|
|
|
|
(unsigned long long) wavparse->seek_offset);
|
|
|
|
|
|
|
|
if (!gst_bytestream_seek (bs, wavparse->seek_offset, GST_SEEK_METHOD_SET)) {
|
|
|
|
GST_INFO ("wavparse: Could not seek");
|
2003-01-14 14:01:49 +00:00
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
wavparse->seek_pending = FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 15:02:42 +00:00
|
|
|
if (wavparse->state == GST_WAVPARSE_DATA) {
|
2003-10-29 23:50:00 +00:00
|
|
|
GstBuffer *buf;
|
|
|
|
int desired;
|
|
|
|
|
|
|
|
/* This seems to want the whole chunk,
|
|
|
|
Will this screw up streaming?
|
|
|
|
Does anyone care about streaming wavs?
|
|
|
|
FIXME: Should we have a decent buffer size? */
|
|
|
|
|
|
|
|
#define MAX_BUFFER_SIZE 1024
|
|
|
|
|
|
|
|
if (wavparse->dataleft > 0) {
|
2003-11-14 15:02:42 +00:00
|
|
|
desired = MIN (wavparse->dataleft, MAX_BUFFER_SIZE);
|
|
|
|
got_bytes = gst_bytestream_peek (bs, &buf, desired);
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2004-01-04 15:23:03 +00:00
|
|
|
if (got_bytes != desired) {
|
|
|
|
/* EOS? */
|
|
|
|
GstEvent *event;
|
|
|
|
guint32 remaining;
|
|
|
|
gst_bytestream_get_status (bs, &remaining, &event);
|
|
|
|
if (event && GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
|
|
|
gst_pad_event_default (wavparse->sinkpad, event);
|
|
|
|
} else {
|
|
|
|
gst_element_error (element, "Read failure");
|
|
|
|
}
|
2003-11-14 15:02:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-11-14 15:02:42 +00:00
|
|
|
wavparse->dataleft -= got_bytes;
|
|
|
|
wavparse->byteoffset += got_bytes;
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-11-14 15:02:42 +00:00
|
|
|
gst_bytestream_flush (bs, got_bytes);
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-11-14 15:02:42 +00:00
|
|
|
gst_pad_push (wavparse->srcpad, GST_DATA (buf));
|
|
|
|
return;
|
2003-10-29 23:50:00 +00:00
|
|
|
} else {
|
2003-11-14 15:02:42 +00:00
|
|
|
wavparse->state = GST_WAVPARSE_OTHER;
|
|
|
|
}
|
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
gst_riff_riff *temp_chunk;
|
|
|
|
guint8 *tempdata;
|
|
|
|
guint32 skipsize;
|
|
|
|
|
|
|
|
/* read first two dwords to get chunktype and size */
|
|
|
|
while (TRUE) {
|
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, sizeof (gst_riff_chunk));
|
|
|
|
temp_chunk = (gst_riff_riff *) tempdata;
|
|
|
|
|
|
|
|
if (got_bytes < sizeof (gst_riff_chunk)) {
|
|
|
|
if (!gst_wavparse_handle_sink_event (wavparse)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
2003-03-01 18:34:38 +00:00
|
|
|
}
|
2003-05-17 16:09:59 +00:00
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
chunk.id = GUINT32_FROM_LE (temp_chunk->id);
|
|
|
|
chunk.size = GUINT32_FROM_LE (temp_chunk->size);
|
2003-03-01 18:34:38 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
switch (chunk.id) {
|
|
|
|
case GST_RIFF_TAG_RIFF:
|
|
|
|
case GST_RIFF_TAG_LIST:
|
|
|
|
/* Read complete list chunk */
|
|
|
|
while (TRUE) {
|
2003-11-14 15:02:42 +00:00
|
|
|
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, sizeof (gst_riff_list));
|
|
|
|
temp_chunk = (gst_riff_riff *) tempdata;
|
|
|
|
if (got_bytes < sizeof (gst_riff_list)) {
|
|
|
|
if (!gst_wavparse_handle_sink_event (wavparse)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chunk.type = GUINT32_FROM_LE (temp_chunk->type);
|
|
|
|
skipsize = sizeof (gst_riff_list);
|
|
|
|
break;
|
2003-01-14 14:01:49 +00:00
|
|
|
|
2003-11-14 15:02:42 +00:00
|
|
|
case GST_RIFF_TAG_cue:
|
|
|
|
skipsize = 0;
|
|
|
|
break;
|
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
default:
|
2003-11-14 15:02:42 +00:00
|
|
|
skipsize = sizeof (gst_riff_chunk);
|
2003-10-29 23:50:00 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_bytestream_flush (bs, skipsize);
|
|
|
|
} while (FALSE);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
/* need to flush an even number of bytes at the end */
|
|
|
|
flush = (chunk.size + 1) & ~1;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
switch (wavparse->state) {
|
|
|
|
case GST_WAVPARSE_START:
|
|
|
|
if (chunk.id != GST_RIFF_TAG_RIFF &&
|
|
|
|
chunk.type != GST_RIFF_RIFF_WAVE) {
|
|
|
|
gst_element_error (element, "This doesn't appear to be a WAV file %08x %08x", chunk.id, chunk.type);
|
|
|
|
return;
|
2003-08-13 06:41:09 +00:00
|
|
|
}
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
wavparse->state = GST_WAVPARSE_OTHER;
|
|
|
|
/* We are not going to flush lists */
|
|
|
|
flush = 0;
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
case GST_WAVPARSE_OTHER:
|
|
|
|
GST_DEBUG ("riff tag: %4.4s %08x", (char *) &chunk.id, chunk.size);
|
|
|
|
|
|
|
|
switch (chunk.id) {
|
|
|
|
case GST_RIFF_TAG_data:
|
|
|
|
wavparse->state = GST_WAVPARSE_DATA;
|
2004-01-02 08:12:12 +00:00
|
|
|
wavparse->dataleft = chunk.size;
|
|
|
|
wavparse->byteoffset = 0;
|
|
|
|
flush = 0;
|
2003-10-29 23:50:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_TAG_fmt:
|
2004-01-14 10:48:18 +00:00
|
|
|
gst_wavparse_parse_fmt (wavparse, chunk.size);
|
|
|
|
flush = 0;
|
2003-10-29 23:50:00 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
case GST_RIFF_TAG_cue:
|
2003-12-22 01:47:09 +00:00
|
|
|
//gst_wavparse_parse_cues (wavparse, chunk.size);
|
2003-10-29 23:50:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_RIFF_TAG_LIST:
|
|
|
|
GST_DEBUG ("list type: %4.4s", (char *) &chunk.type);
|
|
|
|
switch (chunk.type) {
|
|
|
|
case GST_RIFF_LIST_INFO:
|
2003-12-22 01:47:09 +00:00
|
|
|
//gst_wavparse_parse_info (wavparse, chunk.size - 4);
|
2004-01-14 10:48:18 +00:00
|
|
|
//flush = 0;
|
2003-10-29 23:50:00 +00:00
|
|
|
|
2003-11-14 15:02:42 +00:00
|
|
|
break;
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
case GST_RIFF_LIST_adtl:
|
2003-12-22 01:47:09 +00:00
|
|
|
//gst_wavparse_parse_adtl (wavparse, chunk.size - 4);
|
2004-01-14 10:48:18 +00:00
|
|
|
//flush = 0;
|
2003-11-14 15:02:42 +00:00
|
|
|
break;
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
default:
|
2004-01-14 10:48:18 +00:00
|
|
|
//flush = 0;
|
2003-11-14 15:02:42 +00:00
|
|
|
break;
|
2003-10-29 23:50:00 +00:00
|
|
|
}
|
|
|
|
|
2004-01-14 10:48:18 +00:00
|
|
|
default:
|
|
|
|
GST_DEBUG (" ***** unknown chunkid %08x", chunk.id);
|
|
|
|
//flush = 0;
|
2003-10-29 23:50:00 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2004-01-14 10:48:18 +00:00
|
|
|
break;
|
2003-10-29 23:50:00 +00:00
|
|
|
|
|
|
|
case GST_WAVPARSE_DATA:
|
|
|
|
/* Should have been handled up there ^^^^ */
|
|
|
|
flush = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Unknown */
|
2004-01-14 10:48:18 +00:00
|
|
|
g_warning ("Unknown state %d\n", wavparse->state);
|
|
|
|
//GST_DEBUG (" ***** unknown chunkid %08x", chunk.id);
|
2003-10-29 23:50:00 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
if (flush > 0) {
|
|
|
|
gboolean res;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
res = gst_bytestream_flush (bs, flush);
|
|
|
|
if (!res) {
|
|
|
|
guint32 remaining;
|
|
|
|
GstEvent *event;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_bytestream_get_status (bs, &remaining, &event);
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-03 13:59:35 +00:00
|
|
|
/* convert and query stuff */
|
|
|
|
static const GstFormat *
|
|
|
|
gst_wavparse_get_formats (GstPad *pad)
|
|
|
|
{
|
|
|
|
static GstFormat formats[] = {
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_BYTES,
|
2003-05-24 10:41:21 +00:00
|
|
|
GST_FORMAT_DEFAULT, /* a "frame", ie a set of samples per Hz */
|
2002-11-03 13:59:35 +00:00
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_wavparse_pad_convert (GstPad *pad,
|
|
|
|
GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gint bytes_per_sample;
|
|
|
|
glong byterate;
|
|
|
|
GstWavParse *wavparse;
|
|
|
|
|
|
|
|
wavparse = GST_WAVPARSE (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
bytes_per_sample = wavparse->channels * wavparse->width / 8;
|
|
|
|
if (bytes_per_sample == 0) {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("bytes_per_sample is 0, probably an mp3 - channels %d, width %d\n",
|
2003-04-29 21:54:47 +00:00
|
|
|
wavparse->channels, wavparse->width);
|
2003-03-01 18:34:38 +00:00
|
|
|
return FALSE;
|
2002-11-03 13:59:35 +00:00
|
|
|
}
|
|
|
|
byterate = (glong) (bytes_per_sample * wavparse->rate);
|
|
|
|
if (byterate == 0) {
|
2003-03-01 18:34:38 +00:00
|
|
|
g_warning ("byterate is 0, internal error\n");
|
|
|
|
return FALSE;
|
2002-11-03 13:59:35 +00:00
|
|
|
}
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("bytes per sample: %d\n", bytes_per_sample);
|
2002-11-03 13:59:35 +00:00
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
2003-05-24 10:41:21 +00:00
|
|
|
if (*dest_format == GST_FORMAT_DEFAULT)
|
2002-11-03 13:59:35 +00:00
|
|
|
*dest_value = src_value / bytes_per_sample;
|
|
|
|
else if (*dest_format == GST_FORMAT_TIME)
|
|
|
|
*dest_value = src_value * GST_SECOND / byterate;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
break;
|
2003-05-24 10:41:21 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-11-03 13:59:35 +00:00
|
|
|
if (*dest_format == GST_FORMAT_BYTES)
|
|
|
|
*dest_value = src_value * bytes_per_sample;
|
|
|
|
else if (*dest_format == GST_FORMAT_TIME)
|
|
|
|
*dest_value = src_value * GST_SECOND / wavparse->rate;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
if (*dest_format == GST_FORMAT_BYTES)
|
|
|
|
*dest_value = src_value * byterate / GST_SECOND;
|
2003-05-24 10:41:21 +00:00
|
|
|
else if (*dest_format == GST_FORMAT_DEFAULT)
|
2003-03-01 18:34:38 +00:00
|
|
|
*dest_value = src_value * wavparse->rate / GST_SECOND;
|
2002-11-03 13:59:35 +00:00
|
|
|
else
|
|
|
|
return FALSE;
|
2003-03-01 18:34:38 +00:00
|
|
|
|
|
|
|
*dest_value = *dest_value & ~(bytes_per_sample - 1);
|
2002-11-03 13:59:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("unhandled format for wavparse\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType *
|
2002-11-03 13:59:35 +00:00
|
|
|
gst_wavparse_get_query_types (GstPad *pad)
|
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
2003-01-14 21:10:53 +00:00
|
|
|
GST_QUERY_POSITION,
|
|
|
|
0
|
2002-11-03 13:59:35 +00:00
|
|
|
};
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle queries for location and length in requested format */
|
|
|
|
static gboolean
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_wavparse_pad_query (GstPad *pad, GstQueryType type,
|
2002-11-03 13:59:35 +00:00
|
|
|
GstFormat *format, gint64 *value)
|
|
|
|
{
|
|
|
|
GstFormat peer_format = GST_FORMAT_BYTES;
|
|
|
|
gint64 peer_value;
|
|
|
|
GstWavParse *wavparse;
|
|
|
|
|
|
|
|
/* probe sink's peer pad, convert value, and that's it :) */
|
|
|
|
/* FIXME: ideally we'd loop over possible formats of peer instead
|
|
|
|
* of only using BYTE */
|
|
|
|
wavparse = GST_WAVPARSE (gst_pad_get_parent (pad));
|
|
|
|
if (!gst_pad_query (GST_PAD_PEER (wavparse->sinkpad), type,
|
|
|
|
&peer_format, &peer_value)) {
|
|
|
|
g_warning ("Could not query sink pad's peer\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!gst_pad_convert (wavparse->sinkpad, peer_format, peer_value,
|
|
|
|
format, value)) {
|
|
|
|
g_warning ("Could not query sink pad's peer\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("pad_query done, value %" G_GINT64_FORMAT "\n", *value);
|
2002-11-03 13:59:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-03-01 18:34:38 +00:00
|
|
|
static const GstEventMask*
|
|
|
|
gst_wavparse_get_event_masks (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstEventMask gst_wavparse_src_event_masks[] = {
|
|
|
|
{ GST_EVENT_SEEK, GST_SEEK_METHOD_SET |
|
|
|
|
GST_SEEK_FLAG_FLUSH },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
return gst_wavparse_src_event_masks;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_wavparse_srcpad_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
2003-10-29 23:50:00 +00:00
|
|
|
#if 0
|
2003-03-01 18:34:38 +00:00
|
|
|
GstWavParse *wavparse = GST_WAVPARSE (GST_PAD_PARENT (pad));
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("event %d", GST_EVENT_TYPE (event));
|
2003-03-01 18:34:38 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
gint64 byteoffset;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
/* we can only seek when in the DATA state */
|
|
|
|
if (wavparse->state != GST_WAVPARSE_DATA) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
format = GST_FORMAT_BYTES;
|
|
|
|
|
|
|
|
/* bring format to bytes for the peer element,
|
|
|
|
* FIXME be smarter here */
|
|
|
|
res = gst_pad_convert (pad,
|
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
&format,
|
|
|
|
&byteoffset);
|
|
|
|
|
|
|
|
if (res) {
|
2003-10-29 23:50:00 +00:00
|
|
|
/* ok, seek worked, update our state */
|
|
|
|
wavparse->seek_offset = byteoffset;
|
|
|
|
wavparse->seek_pending = TRUE;
|
|
|
|
wavparse->need_discont = TRUE;
|
2003-03-01 18:34:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
return res;
|
2003-10-29 23:50:00 +00:00
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
2003-03-01 18:34:38 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-06-13 22:11:56 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_wavparse_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstWavParse *wavparse = GST_WAVPARSE (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2003-10-29 23:50:00 +00:00
|
|
|
wavparse->bs = gst_bytestream_new (wavparse->sinkpad);
|
|
|
|
wavparse->state = GST_WAVPARSE_START;
|
2003-06-13 22:11:56 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2003-10-29 23:50:00 +00:00
|
|
|
gst_bytestream_destroy (wavparse->bs);
|
2003-06-13 22:11:56 +00:00
|
|
|
wavparse->state = GST_WAVPARSE_UNKNOWN;
|
|
|
|
wavparse->bps = 0;
|
2003-10-29 23:50:00 +00:00
|
|
|
wavparse->seek_pending = FALSE;
|
|
|
|
wavparse->seek_offset = 0;
|
2003-06-13 22:11:56 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static gboolean
|
2003-11-02 19:28:08 +00:00
|
|
|
plugin_init (GstPlugin *plugin)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2003-10-29 23:50:00 +00:00
|
|
|
if (!gst_library_load ("gstbytestream")) {
|
2003-08-13 04:48:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-02 19:28:08 +00:00
|
|
|
return gst_element_register (plugin, "wavparse", GST_RANK_SECONDARY, GST_TYPE_WAVPARSE);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 19:28:08 +00:00
|
|
|
GST_PLUGIN_DEFINE (
|
2001-12-22 23:27:31 +00:00
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2002-01-30 10:20:58 +00:00
|
|
|
"wavparse",
|
2003-11-02 19:28:08 +00:00
|
|
|
"Parse a .wav file into raw audio",
|
|
|
|
plugin_init,
|
|
|
|
VERSION,
|
|
|
|
GST_LICENSE,
|
|
|
|
GST_PACKAGE,
|
|
|
|
GST_ORIGIN
|
|
|
|
)
|