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 */
47 static void gst_mulawdec_class_init (GstMuLawDecClass *klass);
48 static void gst_mulawdec_base_init (GstMuLawDecClass *klass);
49 static void gst_mulawdec_init (GstMuLawDec *mulawdec);
51 static void gst_mulawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
52 static void gst_mulawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
54 static void gst_mulawdec_chain (GstPad *pad, GstData *_data);
57 static GstElementClass *parent_class = NULL;
58 /*static guint gst_stereo_signals[LAST_SIGNAL] = { 0 };*/
61 static GstPadLinkReturn
62 mulawdec_link (GstPad *pad, const GstCaps *caps)
66 GstStructure *structure;
69 GstMuLawDec* mulawdec = GST_MULAWDEC (GST_OBJECT_PARENT (pad));
71 structure = gst_caps_get_structure (caps, 0);
72 ret = gst_structure_get_int (structure, "rate", &rate);
73 ret = gst_structure_get_int (structure, "channels", &channels);
74 if (!ret) return GST_PAD_LINK_REFUSED;
76 tempcaps = gst_caps_new_simple ("audio/x-mulaw",
77 "depth", G_TYPE_INT, 16,
78 "width", G_TYPE_INT, 16,
79 "signed", G_TYPE_BOOLEAN, TRUE,
80 "endianness", G_TYPE_INT, G_BYTE_ORDER,
81 "rate", G_TYPE_INT, rate,
82 "channels", G_TYPE_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);