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.
21 #include "mulaw-decode.h"
22 #include "mulaw-conversion.h"
24 extern GstPadTemplate *mulawdec_src_template, *mulawdec_sink_template;
26 /* elementfactory information */
27 static GstElementDetails mulawdec_details = {
28 "Mu Law to PCM conversion",
29 "Codec/Audio/Decoder",
30 "Convert 8bit mu law to 16bit PCM",
31 "Zaheer Merali <zaheer@bellworldwide.net>"
34 /* Stereo signals and args */
44 static void gst_mulawdec_class_init (GstMuLawDecClass *klass);
45 static void gst_mulawdec_base_init (GstMuLawDecClass *klass);
46 static void gst_mulawdec_init (GstMuLawDec *mulawdec);
48 static void gst_mulawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
49 static void gst_mulawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
51 static void gst_mulawdec_chain (GstPad *pad, GstData *_data);
54 static GstElementClass *parent_class = NULL;
55 /*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 };*/
58 static GstPadLinkReturn
59 mulawdec_link (GstPad *pad, GstCaps *caps)
64 GstMuLawDec* mulawdec = GST_MULAWDEC (GST_OBJECT_PARENT (pad));
66 if (!GST_CAPS_IS_FIXED (caps))
67 return GST_PAD_LINK_DELAYED;
69 if (!gst_caps_get (caps, "rate", &rate,
70 "channels", &channels,
72 return GST_PAD_LINK_DELAYED;
74 tempcaps = GST_CAPS_NEW (
77 "depth", GST_PROPS_INT (16),
78 "width", GST_PROPS_INT (16),
79 "signed", GST_PROPS_BOOLEAN (TRUE),
80 "endianness", GST_PROPS_INT (G_BYTE_ORDER),
81 "rate", GST_PROPS_INT (rate),
82 "channels", GST_PROPS_INT (channels),
85 return gst_pad_try_set_caps (mulawdec->srcpad, tempcaps);
89 gst_mulawdec_get_type(void) {
90 static GType mulawdec_type = 0;
93 static const GTypeInfo mulawdec_info = {
94 sizeof(GstMuLawDecClass),
95 (GBaseInitFunc)gst_mulawdec_base_init,
97 (GClassInitFunc)gst_mulawdec_class_init,
102 (GInstanceInitFunc)gst_mulawdec_init,
104 mulawdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMuLawDec", &mulawdec_info, 0);
106 return mulawdec_type;
110 gst_mulawdec_base_init (GstMuLawDecClass *klass)
112 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
114 gst_element_class_add_pad_template (element_class, mulawdec_src_template);
115 gst_element_class_add_pad_template (element_class, mulawdec_sink_template);
116 gst_element_class_set_details (element_class, &mulawdec_details);
120 gst_mulawdec_class_init (GstMuLawDecClass *klass)
122 GObjectClass *gobject_class;
123 GstElementClass *gstelement_class;
125 gobject_class = (GObjectClass*)klass;
126 gstelement_class = (GstElementClass*)klass;
128 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
130 gobject_class->set_property = gst_mulawdec_set_property;
131 gobject_class->get_property = gst_mulawdec_get_property;
135 gst_mulawdec_init (GstMuLawDec *mulawdec)
137 mulawdec->sinkpad = gst_pad_new_from_template(mulawdec_sink_template,"sink");
138 mulawdec->srcpad = gst_pad_new_from_template(mulawdec_src_template,"src");
139 gst_pad_set_link_function(mulawdec->sinkpad, mulawdec_link);
141 gst_element_add_pad(GST_ELEMENT(mulawdec),mulawdec->sinkpad);
142 gst_pad_set_chain_function(mulawdec->sinkpad,gst_mulawdec_chain);
143 gst_element_add_pad(GST_ELEMENT(mulawdec),mulawdec->srcpad);
147 gst_mulawdec_chain (GstPad *pad,GstData *_data)
149 GstBuffer *buf = GST_BUFFER (_data);
150 GstMuLawDec *mulawdec;
155 g_return_if_fail(pad != NULL);
156 g_return_if_fail(GST_IS_PAD(pad));
157 g_return_if_fail(buf != NULL);
159 mulawdec = GST_MULAWDEC(GST_OBJECT_PARENT (pad));
160 g_return_if_fail(mulawdec != NULL);
161 g_return_if_fail(GST_IS_MULAWDEC(mulawdec));
163 mulaw_data = (guint8 *)GST_BUFFER_DATA(buf);
164 outbuf=gst_buffer_new();
165 GST_BUFFER_DATA(outbuf) = (gchar*)g_new(gint16,GST_BUFFER_SIZE(buf));
166 GST_BUFFER_SIZE(outbuf) = GST_BUFFER_SIZE(buf)*2;
168 linear_data = (gint16*)GST_BUFFER_DATA(outbuf);
169 mulaw_decode(mulaw_data,linear_data,GST_BUFFER_SIZE(buf));
171 gst_buffer_unref(buf);
172 gst_pad_push(mulawdec->srcpad,GST_DATA (outbuf));
176 gst_mulawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
178 GstMuLawDec *mulawdec;
180 /* it's not null if we got it, but it might not be ours */
181 g_return_if_fail(GST_IS_MULAWDEC(object));
182 mulawdec = GST_MULAWDEC(object);
191 gst_mulawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
193 GstMuLawDec *mulawdec;
195 /* it's not null if we got it, but it might not be ours */
196 g_return_if_fail(GST_IS_MULAWDEC(object));
197 mulawdec = GST_MULAWDEC(object);
201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);