2 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include "vorbisparse.h"
26 GST_DEBUG_CATEGORY_EXTERN (vorbisparse_debug);
27 #define GST_CAT_DEFAULT vorbisparse_debug
29 static GstElementDetails vorbis_parse_details = {
32 "parse raw vorbis streams",
33 "Thomas Vander Stichele <thomas at apestaart dot org>"
36 /* Filter signals and args */
48 static GstStaticPadTemplate vorbis_parse_sink_factory =
49 GST_STATIC_PAD_TEMPLATE ("sink",
52 GST_STATIC_CAPS ("audio/x-vorbis")
55 static GstStaticPadTemplate vorbis_parse_src_factory =
56 GST_STATIC_PAD_TEMPLATE ("src",
59 GST_STATIC_CAPS ("audio/x-vorbis")
62 GST_BOILERPLATE (GstVorbisParse, gst_vorbis_parse, GstElement,
65 static GstFlowReturn vorbis_parse_chain (GstPad * pad, GstBuffer * buffer);
66 static GstStateChangeReturn vorbis_parse_change_state (GstElement * element,
67 GstStateChange transition);
70 gst_vorbis_parse_base_init (gpointer g_class)
72 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
74 gst_element_class_add_pad_template (element_class,
75 gst_static_pad_template_get (&vorbis_parse_src_factory));
76 gst_element_class_add_pad_template (element_class,
77 gst_static_pad_template_get (&vorbis_parse_sink_factory));
78 gst_element_class_set_details (element_class, &vorbis_parse_details);
82 gst_vorbis_parse_class_init (GstVorbisParseClass * klass)
84 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
86 gstelement_class->change_state = vorbis_parse_change_state;
90 gst_vorbis_parse_init (GstVorbisParse * parse, GstVorbisParseClass * g_class)
93 gst_pad_new_from_template (gst_static_pad_template_get
94 (&vorbis_parse_sink_factory), "sink");
95 gst_pad_set_chain_function (parse->sinkpad, vorbis_parse_chain);
96 gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad);
99 gst_pad_new_from_template (gst_static_pad_template_get
100 (&vorbis_parse_src_factory), "src");
101 gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad);
104 vorbis_parse_set_header_on_caps (GstVorbisParse * parse, GstCaps * caps)
106 GstBuffer *buf1, *buf2, *buf3;
107 GstStructure *structure;
109 GValue value = { 0 };
112 g_assert (parse->streamheader);
113 g_assert (parse->streamheader->next);
114 g_assert (parse->streamheader->next->next);
115 buf1 = parse->streamheader->data;
117 buf2 = parse->streamheader->next->data;
119 buf3 = parse->streamheader->next->next->data;
122 structure = gst_caps_get_structure (caps, 0);
125 GST_BUFFER_FLAG_SET (buf1, GST_BUFFER_FLAG_IN_CAPS);
126 GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_FLAG_IN_CAPS);
127 GST_BUFFER_FLAG_SET (buf3, GST_BUFFER_FLAG_IN_CAPS);
129 /* put buffers in a fixed list */
130 g_value_init (&list, GST_TYPE_ARRAY);
131 g_value_init (&value, GST_TYPE_BUFFER);
132 g_value_set_boxed (&value, buf1);
133 gst_value_list_append_value (&list, &value);
134 g_value_unset (&value);
135 g_value_init (&value, GST_TYPE_BUFFER);
136 g_value_set_boxed (&value, buf2);
137 gst_value_list_append_value (&list, &value);
138 g_value_unset (&value);
139 g_value_init (&value, GST_TYPE_BUFFER);
140 g_value_set_boxed (&value, buf3);
141 gst_value_list_append_value (&list, &value);
142 gst_structure_set_value (structure, "streamheader", &list);
143 g_value_unset (&value);
144 g_value_unset (&list);
148 vorbis_parse_chain (GstPad * pad, GstBuffer * buffer)
151 GstVorbisParse *parse;
153 parse = GST_VORBIS_PARSE (GST_PAD_PARENT (pad));
155 buf = GST_BUFFER (buffer);
158 /* if 1 <= packetno <= 3, it's streamheader,
159 * so put it on the streamheader list and return */
160 if (parse->packetno <= 3) {
161 parse->streamheader = g_list_append (parse->streamheader, buf);
165 /* else, if we haven't sent streamheader buffers yet,
166 * set caps again, and send out the streamheader buffers */
167 if (!parse->streamheader_sent) {
168 /* mark and put on caps */
169 GstCaps *caps = gst_pad_get_caps (parse->srcpad);
171 vorbis_parse_set_header_on_caps (parse, caps);
173 /* negotiate with these caps */
174 GST_DEBUG ("here are the caps: %" GST_PTR_FORMAT, caps);
175 gst_pad_set_caps (parse->srcpad, caps);
177 /* push out buffers */
178 gst_pad_push (parse->srcpad, parse->streamheader->data);
179 gst_pad_push (parse->srcpad, parse->streamheader->next->data);
180 gst_pad_push (parse->srcpad, parse->streamheader->next->next->data);
182 parse->streamheader_sent = TRUE;
184 /* just send on buffer by default */
185 gst_pad_push (parse->srcpad, buf);
190 static GstStateChangeReturn
191 vorbis_parse_change_state (GstElement * element, GstStateChange transition)
193 GstVorbisParse *parse = GST_VORBIS_PARSE (element);
195 switch (transition) {
196 case GST_STATE_CHANGE_PAUSED_TO_READY:
203 return parent_class->change_state (element, transition);