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.
24 #include "mulaw-decode.h"
25 #include "mulaw-conversion.h"
27 extern GstPadTemplate *mulawdec_src_template, *mulawdec_sink_template;
29 /* elementfactory information */
30 static GstElementDetails mulawdec_details = {
31 "Mu Law to PCM conversion",
32 "Codec/Decoder/Audio",
33 "Convert 8bit mu law to 16bit PCM",
34 "Zaheer Merali <zaheer@bellworldwide.net>"
37 /* Stereo signals and args */
49 static void gst_mulawdec_class_init (GstMuLawDecClass * klass);
50 static void gst_mulawdec_base_init (GstMuLawDecClass * klass);
51 static void gst_mulawdec_init (GstMuLawDec * mulawdec);
53 static void gst_mulawdec_set_property (GObject * object, guint prop_id,
54 const GValue * value, GParamSpec * pspec);
55 static void gst_mulawdec_get_property (GObject * object, guint prop_id,
56 GValue * value, GParamSpec * pspec);
58 static void gst_mulawdec_chain (GstPad * pad, GstData * _data);
61 static GstElementClass *parent_class = NULL;
63 /*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 };*/
66 static GstPadLinkReturn
67 mulawdec_link (GstPad * pad, const GstCaps * caps)
71 GstStructure *structure;
74 GstMuLawDec *mulawdec = GST_MULAWDEC (GST_OBJECT_PARENT (pad));
76 structure = gst_caps_get_structure (caps, 0);
77 ret = gst_structure_get_int (structure, "rate", &rate);
78 ret = gst_structure_get_int (structure, "channels", &channels);
80 return GST_PAD_LINK_REFUSED;
82 tempcaps = gst_caps_new_simple ("audio/x-raw-int",
83 "depth", G_TYPE_INT, 16,
84 "width", G_TYPE_INT, 16,
85 "signed", G_TYPE_BOOLEAN, TRUE,
86 "endianness", G_TYPE_INT, G_BYTE_ORDER,
87 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
89 return gst_pad_try_set_caps (mulawdec->srcpad, tempcaps);
93 gst_mulawdec_get_type (void)
95 static GType mulawdec_type = 0;
98 static const GTypeInfo mulawdec_info = {
99 sizeof (GstMuLawDecClass),
100 (GBaseInitFunc) gst_mulawdec_base_init,
102 (GClassInitFunc) gst_mulawdec_class_init,
105 sizeof (GstMuLawDec),
107 (GInstanceInitFunc) gst_mulawdec_init,
110 g_type_register_static (GST_TYPE_ELEMENT, "GstMuLawDec", &mulawdec_info,
113 return mulawdec_type;
117 gst_mulawdec_base_init (GstMuLawDecClass * klass)
119 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
121 gst_element_class_add_pad_template (element_class, mulawdec_src_template);
122 gst_element_class_add_pad_template (element_class, mulawdec_sink_template);
123 gst_element_class_set_details (element_class, &mulawdec_details);
127 gst_mulawdec_class_init (GstMuLawDecClass * klass)
129 GObjectClass *gobject_class;
130 GstElementClass *gstelement_class;
132 gobject_class = (GObjectClass *) klass;
133 gstelement_class = (GstElementClass *) klass;
135 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
137 gobject_class->set_property = gst_mulawdec_set_property;
138 gobject_class->get_property = gst_mulawdec_get_property;
142 gst_mulawdec_init (GstMuLawDec * mulawdec)
145 gst_pad_new_from_template (mulawdec_sink_template, "sink");
146 mulawdec->srcpad = gst_pad_new_from_template (mulawdec_src_template, "src");
147 gst_pad_set_link_function (mulawdec->sinkpad, mulawdec_link);
149 gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->sinkpad);
150 gst_pad_set_chain_function (mulawdec->sinkpad, gst_mulawdec_chain);
151 gst_element_add_pad (GST_ELEMENT (mulawdec), mulawdec->srcpad);
155 gst_mulawdec_chain (GstPad * pad, GstData * _data)
157 GstBuffer *buf = GST_BUFFER (_data);
158 GstMuLawDec *mulawdec;
163 g_return_if_fail (pad != NULL);
164 g_return_if_fail (GST_IS_PAD (pad));
165 g_return_if_fail (buf != NULL);
167 mulawdec = GST_MULAWDEC (GST_OBJECT_PARENT (pad));
168 g_return_if_fail (mulawdec != NULL);
169 g_return_if_fail (GST_IS_MULAWDEC (mulawdec));
171 mulaw_data = (guint8 *) GST_BUFFER_DATA (buf);
172 outbuf = gst_buffer_new ();
173 GST_BUFFER_DATA (outbuf) = (gchar *) g_new (gint16, GST_BUFFER_SIZE (buf));
174 GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf) * 2;
176 linear_data = (gint16 *) GST_BUFFER_DATA (outbuf);
177 mulaw_decode (mulaw_data, linear_data, GST_BUFFER_SIZE (buf));
179 gst_buffer_unref (buf);
180 gst_pad_push (mulawdec->srcpad, GST_DATA (outbuf));
184 gst_mulawdec_set_property (GObject * object, guint prop_id,
185 const GValue * value, GParamSpec * pspec)
187 GstMuLawDec *mulawdec;
189 /* it's not null if we got it, but it might not be ours */
190 g_return_if_fail (GST_IS_MULAWDEC (object));
191 mulawdec = GST_MULAWDEC (object);
200 gst_mulawdec_get_property (GObject * object, guint prop_id, GValue * value,
203 GstMuLawDec *mulawdec;
205 /* it's not null if we got it, but it might not be ours */
206 g_return_if_fail (GST_IS_MULAWDEC (object));
207 mulawdec = GST_MULAWDEC (object);
211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);