2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
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.
26 #include "gstspeexdec.h"
28 static GstPadTemplate *speexdec_src_template, *speexdec_sink_template;
30 /* elementfactory information */
31 GstElementDetails gst_speexdec_details = {
32 "speex audio decoder",
33 "Codec/Audio/Decoder",
35 "Wim Taymans <wim.taymans@chello.be>",
38 /* SpeexDec signals and args */
51 static void gst_speexdec_base_init (gpointer g_class);
52 static void gst_speexdec_class_init (GstSpeexDec * klass);
53 static void gst_speexdec_init (GstSpeexDec * speexdec);
55 static void gst_speexdec_chain (GstPad * pad, GstData * _data);
56 static GstPadLinkReturn gst_speexdec_sinkconnect (GstPad * pad,
57 const GstCaps * caps);
59 static GstElementClass *parent_class = NULL;
61 /*static guint gst_speexdec_signals[LAST_SIGNAL] = { 0 }; */
64 gst_speexdec_get_type (void)
66 static GType speexdec_type = 0;
69 static const GTypeInfo speexdec_info = {
70 sizeof (GstSpeexDecClass),
71 gst_speexdec_base_init,
73 (GClassInitFunc) gst_speexdec_class_init,
78 (GInstanceInitFunc) gst_speexdec_init,
81 g_type_register_static (GST_TYPE_ELEMENT, "GstSpeexDec", &speexdec_info,
87 static GstStaticPadTemplate speex_sink_template =
88 GST_STATIC_PAD_TEMPLATE ("sink",
91 GST_STATIC_CAPS ("audio/x-speex, "
92 "rate = (int) [ 1000, 48000 ], " "channels = (int) 1")
95 static GstStaticPadTemplate speex_src_template = GST_STATIC_PAD_TEMPLATE ("src",
98 GST_STATIC_CAPS ("audio/x-raw-int, "
99 "endianness = (int) BYTE_ORDER, "
100 "signed = (boolean) true, "
103 "rate = (int) [ 1000, 48000 ], " "channels = (int) 1")
107 gst_speexdec_base_init (gpointer g_class)
109 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
111 gst_element_class_add_pad_template (element_class,
112 gst_static_pad_template_get (&speex_src_template));
113 gst_element_class_add_pad_template (element_class,
114 gst_static_pad_template_get (&speex_sink_template));
116 gst_element_class_set_details (element_class, &gst_speexdec_details);
120 gst_speexdec_class_init (GstSpeexDec * klass)
122 GstElementClass *gstelement_class;
124 gstelement_class = (GstElementClass *) klass;
126 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
130 gst_speexdec_init (GstSpeexDec * speexdec)
132 GST_DEBUG ("gst_speexdec_init: initializing");
134 /* create the sink and src pads */
136 gst_pad_new_from_template (speexdec_sink_template, "sink");
137 gst_element_add_pad (GST_ELEMENT (speexdec), speexdec->sinkpad);
138 gst_pad_set_chain_function (speexdec->sinkpad, gst_speexdec_chain);
139 gst_pad_set_link_function (speexdec->sinkpad, gst_speexdec_sinkconnect);
141 speexdec->srcpad = gst_pad_new_from_template (speexdec_src_template, "src");
142 gst_pad_use_explicit_caps (speexdec->srcpad);
143 gst_element_add_pad (GST_ELEMENT (speexdec), speexdec->srcpad);
147 static GstPadLinkReturn
148 gst_speexdec_sinkconnect (GstPad * pad, const GstCaps * caps)
150 GstSpeexDec *speexdec;
152 GstStructure *structure;
154 speexdec = GST_SPEEXDEC (gst_pad_get_parent (pad));
156 structure = gst_caps_get_structure (caps, 0);
157 gst_structure_get_int (structure, "rate", &rate);
159 if (gst_pad_set_explicit_caps (speexdec->srcpad,
160 gst_caps_new_simple ("audio/x-raw-int",
161 "endianness", G_TYPE_INT, G_BYTE_ORDER,
162 "signed", G_TYPE_BOOLEAN, TRUE,
163 "width", G_TYPE_INT, 16,
164 "depth", G_TYPE_INT, 16,
165 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, 1, NULL))) {
166 return GST_PAD_LINK_OK;
168 return GST_PAD_LINK_REFUSED;
172 gst_speexdec_chain (GstPad * pad, GstData * _data)
174 GstBuffer *buf = GST_BUFFER (_data);
175 GstSpeexDec *speexdec;
179 g_return_if_fail (pad != NULL);
180 g_return_if_fail (GST_IS_PAD (pad));
181 g_return_if_fail (buf != NULL);
182 /*g_return_if_fail(GST_IS_BUFFER(buf)); */
184 speexdec = GST_SPEEXDEC (gst_pad_get_parent (pad));
186 data = GST_BUFFER_DATA (buf);
187 size = GST_BUFFER_SIZE (buf);
189 gst_buffer_unref (buf);