diff --git a/ChangeLog b/ChangeLog index 73e728ee57..b70ca84713 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2004-06-08 Thomas Vander Stichele + + * ext/vorbis/Makefile.am: + * ext/vorbis/vorbis.c: (plugin_init): + * ext/vorbis/vorbisparse.c: (gst_vorbis_parse_base_init), + (gst_vorbis_parse_class_init), (gst_vorbis_parse_init), + (vorbis_parse_set_header_on_caps), (vorbis_parse_chain), + (vorbis_parse_change_state): + * ext/vorbis/vorbisparse.h: + adding a vorbisparse element that marks the buffers, streaming + raw vorbis using GDP now works, whee + 2004-06-08 Wim Taymans * ext/jpeg/Makefile.am: diff --git a/ext/vorbis/Makefile.am b/ext/vorbis/Makefile.am index e248bdfd16..380be3114a 100644 --- a/ext/vorbis/Makefile.am +++ b/ext/vorbis/Makefile.am @@ -1,10 +1,10 @@ - plugin_LTLIBRARIES = libgstvorbis.la -libgstvorbis_la_SOURCES = vorbis.c vorbisdec.c vorbisenc.c oggvorbisenc.c +libgstvorbis_la_SOURCES = vorbis.c \ + vorbisdec.c vorbisenc.c oggvorbisenc.c vorbisparse.c libgstvorbis_la_CFLAGS = $(GST_CFLAGS) $(VORBIS_CFLAGS) ## AM_PATH_VORBIS also sets VORBISENC_LIBS libgstvorbis_la_LIBADD = $(VORBIS_LIBS) $(VORBISENC_LIBS) $(VORBISFILE_LIBS) libgstvorbis_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -noinst_HEADERS = vorbisenc.h vorbisdec.h oggvorbisenc.h +noinst_HEADERS = vorbisenc.h vorbisdec.h oggvorbisenc.h vorbisparse.h diff --git a/ext/vorbis/vorbis.c b/ext/vorbis/vorbis.c index 237d6dd3a9..1046f8a928 100644 --- a/ext/vorbis/vorbis.c +++ b/ext/vorbis/vorbis.c @@ -24,8 +24,10 @@ #include "vorbisenc.h" #include "oggvorbisenc.h" #include "vorbisdec.h" +#include "vorbisparse.h" GST_DEBUG_CATEGORY (vorbisdec_debug); +GST_DEBUG_CATEGORY (vorbisparse_debug); static gboolean plugin_init (GstPlugin * plugin) @@ -48,8 +50,14 @@ plugin_init (GstPlugin * plugin) gst_vorbis_dec_get_type ())) return FALSE; + if (!gst_element_register (plugin, "vorbisparse", GST_RANK_NONE, + gst_vorbis_parse_get_type ())) + return FALSE; + GST_DEBUG_CATEGORY_INIT (vorbisdec_debug, "vorbisdec", 0, "vorbis decoding element"); + GST_DEBUG_CATEGORY_INIT (vorbisparse_debug, "vorbisparse", 0, + "vorbis parsing element"); return TRUE; } diff --git a/ext/vorbis/vorbisparse.c b/ext/vorbis/vorbisparse.c new file mode 100644 index 0000000000..63e5a359f7 --- /dev/null +++ b/ext/vorbis/vorbisparse.c @@ -0,0 +1,201 @@ +/* GStreamer + * Copyright (C) <2004> Thomas Vander Stichele + * + * 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 "vorbisparse.h" + +GST_DEBUG_CATEGORY_EXTERN (vorbisparse_debug); +#define GST_CAT_DEFAULT vorbisparse_debug + +static GstElementDetails vorbis_parse_details = { + "VorbisParse", + "Codec/Parser/Audio", + "parse raw vorbis streams", + "Thomas Vander Stichele " +}; + +/* Filter signals and args */ +enum +{ + /* FILL ME */ + LAST_SIGNAL +}; + +enum +{ + ARG_0 +}; + +static GstStaticPadTemplate vorbis_parse_sink_factory = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-vorbis") + ); + +static GstStaticPadTemplate vorbis_parse_src_factory = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-vorbis") + ); + +GST_BOILERPLATE (GstVorbisParse, gst_vorbis_parse, GstElement, + GST_TYPE_ELEMENT); + +static void vorbis_parse_chain (GstPad * pad, GstData * data); +static GstElementStateReturn vorbis_parse_change_state (GstElement * element); + +static void +gst_vorbis_parse_base_init (gpointer g_class) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&vorbis_parse_src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&vorbis_parse_sink_factory)); + gst_element_class_set_details (element_class, &vorbis_parse_details); +} + +static void +gst_vorbis_parse_class_init (GstVorbisParseClass * klass) +{ + GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); + + gstelement_class->change_state = vorbis_parse_change_state; +} + +static void +gst_vorbis_parse_init (GstVorbisParse * parse) +{ + parse->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&vorbis_parse_sink_factory), "sink"); + gst_pad_set_chain_function (parse->sinkpad, vorbis_parse_chain); + gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad); + + parse->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&vorbis_parse_src_factory), "src"); + gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad); +} +static void +vorbis_parse_set_header_on_caps (GstVorbisParse * parse, GstCaps * caps) +{ + GstBuffer *buf1, *buf2, *buf3; + + g_assert (parse); + g_assert (parse->streamheader); + g_assert (parse->streamheader->next); + g_assert (parse->streamheader->next->next); + buf1 = parse->streamheader->data; + g_assert (buf1); + buf2 = parse->streamheader->next->data; + g_assert (buf2); + buf3 = parse->streamheader->next->next->data; + g_assert (buf3); + + GstStructure *structure = gst_caps_get_structure (caps, 0); + GValue list = { 0 }; + GValue value = { 0 }; + + /* mark buffers */ + GST_BUFFER_FLAG_SET (buf1, GST_BUFFER_IN_CAPS); + GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_IN_CAPS); + GST_BUFFER_FLAG_SET (buf3, GST_BUFFER_IN_CAPS); + + /* put buffers in a fixed list */ + g_value_init (&list, GST_TYPE_FIXED_LIST); + g_value_init (&value, GST_TYPE_BUFFER); + g_value_set_boxed (&value, buf1); + gst_value_list_append_value (&list, &value); + g_value_unset (&value); + g_value_init (&value, GST_TYPE_BUFFER); + g_value_set_boxed (&value, buf2); + gst_value_list_append_value (&list, &value); + g_value_unset (&value); + g_value_init (&value, GST_TYPE_BUFFER); + g_value_set_boxed (&value, buf3); + gst_value_list_append_value (&list, &value); + gst_structure_set_value (structure, "streamheader", &list); + g_value_unset (&value); + g_value_unset (&list); +} + +static void +vorbis_parse_chain (GstPad * pad, GstData * data) +{ + GstBuffer *buf; + GstVorbisParse *parse; + + parse = GST_VORBIS_PARSE (gst_pad_get_parent (pad)); + g_assert (parse); + + buf = GST_BUFFER (data); + parse->packetno++; + + /* if 1 <= packetno <= 3, it's streamheader, + * so put it on the streamheader list and return */ + if (parse->packetno <= 3) { + parse->streamheader = g_list_append (parse->streamheader, buf); + return; + } + + /* else, if we haven't sent streamheader buffers yet, + * set caps again, and send out the streamheader buffers */ + if (!parse->streamheader_sent) { + /* mark and put on caps */ + GstCaps *caps = gst_pad_get_caps (parse->srcpad); + + vorbis_parse_set_header_on_caps (parse, caps); + + /* negotiate with these caps */ + GST_DEBUG ("here are the caps: %" GST_PTR_FORMAT, caps); + gst_pad_try_set_caps (parse->srcpad, caps); + + /* push out buffers */ + gst_pad_push (parse->srcpad, parse->streamheader->data); + gst_pad_push (parse->srcpad, parse->streamheader->next->data); + gst_pad_push (parse->srcpad, parse->streamheader->next->next->data); + + parse->streamheader_sent = TRUE; + } + /* just send on buffer by default */ + gst_pad_push (parse->srcpad, data); +} + +static GstElementStateReturn +vorbis_parse_change_state (GstElement * element) +{ + GstVorbisParse *parse = GST_VORBIS_PARSE (element); + + switch (GST_STATE_TRANSITION (element)) { + case GST_STATE_PAUSED_TO_READY: + parse->packetno = 0; + break; + default: + break; + } + + return parent_class->change_state (element); +} diff --git a/ext/vorbis/vorbisparse.h b/ext/vorbis/vorbisparse.h new file mode 100644 index 0000000000..d6ce6fffc9 --- /dev/null +++ b/ext/vorbis/vorbisparse.h @@ -0,0 +1,69 @@ +/* -*- c-basic-offset: 2 -*- + * GStreamer + * Copyright (C) <2004> Thomas Vander Stichele + * + * 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. + */ + + +#ifndef __GST_VORBIS_PARSE_H__ +#define __GST_VORBIS_PARSE_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#define GST_TYPE_VORBIS_PARSE \ + (gst_vorbis_parse_get_type()) +#define GST_VORBIS_PARSE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VORBIS_PARSE,GstVorbisParse)) +#define GST_VORBIS_PARSE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VORBIS_PARSE,GstVorbisParse)) +#define GST_IS_VORBIS_PARSE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VORBIS_PARSE)) +#define GST_IS_VORBIS_PARSE_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VORBIS_PARSE)) + +typedef struct _GstVorbisParse GstVorbisParse; +typedef struct _GstVorbisParseClass GstVorbisParseClass; + +struct _GstVorbisParse { + GstElement element; + + GstPad * sinkpad; + GstPad * srcpad; + + guint packetno; + gboolean streamheader_sent; + GList * streamheader; +}; + +struct _GstVorbisParseClass { + GstElementClass parent_class; +}; + +GType gst_vorbis_parse_get_type(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __GST_VORBIS_PARSE_H__ */