gst-indent
[platform/upstream/gst-plugins-good.git] / ext / speex / gstspeexdec.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 #include <string.h>
25
26 #include "gstspeexdec.h"
27
28 static GstPadTemplate *speexdec_src_template, *speexdec_sink_template;
29
30 /* elementfactory information */
31 GstElementDetails gst_speexdec_details = {
32   "speex audio decoder",
33   "Codec/Audio/Decoder",
34   ".speex",
35   "Wim Taymans <wim.taymans@chello.be>",
36 };
37
38 /* SpeexDec signals and args */
39 enum
40 {
41   /* FILL ME */
42   LAST_SIGNAL
43 };
44
45 enum
46 {
47   ARG_0,
48   /* FILL ME */
49 };
50
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);
54
55 static void gst_speexdec_chain (GstPad * pad, GstData * _data);
56 static GstPadLinkReturn gst_speexdec_sinkconnect (GstPad * pad,
57     const GstCaps * caps);
58
59 static GstElementClass *parent_class = NULL;
60
61 /*static guint gst_speexdec_signals[LAST_SIGNAL] = { 0 }; */
62
63 GType
64 gst_speexdec_get_type (void)
65 {
66   static GType speexdec_type = 0;
67
68   if (!speexdec_type) {
69     static const GTypeInfo speexdec_info = {
70       sizeof (GstSpeexDecClass),
71       gst_speexdec_base_init,
72       NULL,
73       (GClassInitFunc) gst_speexdec_class_init,
74       NULL,
75       NULL,
76       sizeof (GstSpeexDec),
77       0,
78       (GInstanceInitFunc) gst_speexdec_init,
79     };
80     speexdec_type =
81         g_type_register_static (GST_TYPE_ELEMENT, "GstSpeexDec", &speexdec_info,
82         0);
83   }
84   return speexdec_type;
85 }
86
87 static GstStaticPadTemplate speex_sink_template =
88 GST_STATIC_PAD_TEMPLATE ("sink",
89     GST_PAD_SINK,
90     GST_PAD_ALWAYS,
91     GST_STATIC_CAPS ("audio/x-speex, "
92         "rate = (int) [ 1000, 48000 ], " "channels = (int) 1")
93     );
94
95 static GstStaticPadTemplate speex_src_template = GST_STATIC_PAD_TEMPLATE ("src",
96     GST_PAD_SRC,
97     GST_PAD_ALWAYS,
98     GST_STATIC_CAPS ("audio/x-raw-int, "
99         "endianness = (int) BYTE_ORDER, "
100         "signed = (boolean) true, "
101         "width = (int) 16, "
102         "depth = (int) 16, "
103         "rate = (int) [ 1000, 48000 ], " "channels = (int) 1")
104     );
105
106 static void
107 gst_speexdec_base_init (gpointer g_class)
108 {
109   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
110
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));
115
116   gst_element_class_set_details (element_class, &gst_speexdec_details);
117 }
118
119 static void
120 gst_speexdec_class_init (GstSpeexDec * klass)
121 {
122   GstElementClass *gstelement_class;
123
124   gstelement_class = (GstElementClass *) klass;
125
126   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
127 }
128
129 static void
130 gst_speexdec_init (GstSpeexDec * speexdec)
131 {
132   GST_DEBUG ("gst_speexdec_init: initializing");
133
134   /* create the sink and src pads */
135   speexdec->sinkpad =
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);
140
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);
144
145 }
146
147 static GstPadLinkReturn
148 gst_speexdec_sinkconnect (GstPad * pad, const GstCaps * caps)
149 {
150   GstSpeexDec *speexdec;
151   gint rate;
152   GstStructure *structure;
153
154   speexdec = GST_SPEEXDEC (gst_pad_get_parent (pad));
155
156   structure = gst_caps_get_structure (caps, 0);
157   gst_structure_get_int (structure, "rate", &rate);
158
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;
167   }
168   return GST_PAD_LINK_REFUSED;
169 }
170
171 static void
172 gst_speexdec_chain (GstPad * pad, GstData * _data)
173 {
174   GstBuffer *buf = GST_BUFFER (_data);
175   GstSpeexDec *speexdec;
176   gchar *data;
177   guint size;
178
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)); */
183
184   speexdec = GST_SPEEXDEC (gst_pad_get_parent (pad));
185
186   data = GST_BUFFER_DATA (buf);
187   size = GST_BUFFER_SIZE (buf);
188
189   gst_buffer_unref (buf);
190 }