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;
27 /* Stereo signals and args */
37 static void gst_mulawdec_class_init (GstMuLawDecClass *klass);
38 static void gst_mulawdec_init (GstMuLawDec *mulawdec);
40 static void gst_mulawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
41 static void gst_mulawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
43 static void gst_mulawdec_chain (GstPad *pad, GstBuffer *buf);
46 static GstElementClass *parent_class = NULL;
47 //static guint gst_stereo_signals[LAST_SIGNAL] = { 0 };
49 static GstPadNegotiateReturn
50 mulawdec_negotiate_sink (GstPad *pad, GstCaps **caps, gint counter)
54 GstMuLawDec* mulawdec=GST_MULAWDEC (GST_OBJECT_PARENT (pad));
57 return GST_PAD_NEGOTIATE_FAIL;
59 tempcaps = gst_caps_copy(*caps);
61 gst_caps_set(tempcaps,"format",GST_PROPS_STRING("int"));
62 gst_caps_set(tempcaps,"law",GST_PROPS_INT(0));
63 gst_caps_set(tempcaps,"depth",GST_PROPS_INT(16));
64 gst_caps_set(tempcaps,"width",GST_PROPS_INT(16));
65 gst_caps_set(tempcaps,"signed",GST_PROPS_BOOLEAN(TRUE));
67 if (gst_pad_set_caps (mulawdec->srcpad, tempcaps))
69 return GST_PAD_NEGOTIATE_AGREE;
72 gst_caps_unref (tempcaps);
73 return GST_PAD_NEGOTIATE_FAIL;
78 gst_mulawdec_get_type(void) {
79 static GType mulawdec_type = 0;
82 static const GTypeInfo mulawdec_info = {
83 sizeof(GstMuLawDecClass), NULL,
85 (GClassInitFunc)gst_mulawdec_class_init,
90 (GInstanceInitFunc)gst_mulawdec_init,
92 mulawdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMuLawDec", &mulawdec_info, 0);
98 gst_mulawdec_class_init (GstMuLawDecClass *klass)
100 GObjectClass *gobject_class;
101 GstElementClass *gstelement_class;
103 gobject_class = (GObjectClass*)klass;
104 gstelement_class = (GstElementClass*)klass;
106 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
108 gobject_class->set_property = gst_mulawdec_set_property;
109 gobject_class->get_property = gst_mulawdec_get_property;
113 gst_mulawdec_init (GstMuLawDec *mulawdec)
115 mulawdec->sinkpad = gst_pad_new_from_template(mulawdec_sink_template,"sink");
116 mulawdec->srcpad = gst_pad_new_from_template(mulawdec_src_template,"src");
117 gst_pad_set_negotiate_function(mulawdec->sinkpad, mulawdec_negotiate_sink);
119 gst_element_add_pad(GST_ELEMENT(mulawdec),mulawdec->sinkpad);
120 gst_pad_set_chain_function(mulawdec->sinkpad,gst_mulawdec_chain);
121 gst_element_add_pad(GST_ELEMENT(mulawdec),mulawdec->srcpad);
125 gst_mulawdec_chain (GstPad *pad,GstBuffer *buf)
127 GstMuLawDec *mulawdec;
132 g_return_if_fail(pad != NULL);
133 g_return_if_fail(GST_IS_PAD(pad));
134 g_return_if_fail(buf != NULL);
136 mulawdec = GST_MULAWDEC(GST_OBJECT_PARENT (pad));
137 g_return_if_fail(mulawdec != NULL);
138 g_return_if_fail(GST_IS_MULAWDEC(mulawdec));
140 mulaw_data = (guint8 *)GST_BUFFER_DATA(buf);
141 outbuf=gst_buffer_new();
142 GST_BUFFER_DATA(outbuf) = (gchar*)g_new(gint16,GST_BUFFER_SIZE(buf));
143 GST_BUFFER_SIZE(outbuf) = GST_BUFFER_SIZE(buf)*2;
145 linear_data = (gint16*)GST_BUFFER_DATA(outbuf);
146 mulaw_decode(mulaw_data,linear_data,GST_BUFFER_SIZE(buf));
148 gst_buffer_unref(buf);
149 gst_pad_push(mulawdec->srcpad,outbuf);
153 gst_mulawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
155 GstMuLawDec *mulawdec;
157 /* it's not null if we got it, but it might not be ours */
158 g_return_if_fail(GST_IS_MULAWDEC(object));
159 mulawdec = GST_MULAWDEC(object);
168 gst_mulawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
170 GstMuLawDec *mulawdec;
172 /* it's not null if we got it, but it might not be ours */
173 g_return_if_fail(GST_IS_MULAWDEC(object));
174 mulawdec = GST_MULAWDEC(object);
178 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);