Initial revision
[platform/upstream/gstreamer.git] / gst / law / mulaw-decode.c
1 /* Gnome-Streamer
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 #include <gst/gst.h>
21 #include "mulaw-decode.h"
22 #include "mulaw-conversion.h"
23
24 extern GstPadTemplate *mulawdec_src_template, *mulawdec_sink_template;
25
26
27 /* Stereo signals and args */
28 enum {
29   /* FILL ME */
30   LAST_SIGNAL
31 };
32
33 enum {
34   ARG_0
35 };
36
37 static void             gst_mulawdec_class_init         (GstMuLawDecClass *klass);
38 static void             gst_mulawdec_init                       (GstMuLawDec *mulawdec);
39
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);
42
43 static void             gst_mulawdec_chain                      (GstPad *pad, GstBuffer *buf);
44
45
46 static GstElementClass *parent_class = NULL;
47 //static guint gst_stereo_signals[LAST_SIGNAL] = { 0 };
48
49 static GstPadNegotiateReturn
50 mulawdec_negotiate_sink (GstPad *pad, GstCaps **caps, gint counter)
51 {
52   GstCaps* tempcaps;
53   
54   GstMuLawDec* mulawdec=GST_MULAWDEC (GST_OBJECT_PARENT (pad));
55   
56   if (*caps==NULL) 
57     return GST_PAD_NEGOTIATE_FAIL;
58
59   tempcaps = gst_caps_copy(*caps);
60
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));
66
67   if (gst_pad_set_caps (mulawdec->srcpad, tempcaps))
68   {
69     return GST_PAD_NEGOTIATE_AGREE;
70   }
71   else {
72     gst_caps_unref (tempcaps);
73     return GST_PAD_NEGOTIATE_FAIL;
74   }
75 }               
76
77 GType
78 gst_mulawdec_get_type(void) {
79   static GType mulawdec_type = 0;
80
81   if (!mulawdec_type) {
82     static const GTypeInfo mulawdec_info = {
83       sizeof(GstMuLawDecClass),      NULL,
84       NULL,
85       (GClassInitFunc)gst_mulawdec_class_init,
86       NULL,
87       NULL,
88       sizeof(GstMuLawDec),
89       0,
90       (GInstanceInitFunc)gst_mulawdec_init,
91     };
92     mulawdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMuLawDec", &mulawdec_info, 0);
93   }
94   return mulawdec_type;
95 }
96
97 static void
98 gst_mulawdec_class_init (GstMuLawDecClass *klass)
99 {
100   GObjectClass *gobject_class;
101   GstElementClass *gstelement_class;
102
103   gobject_class = (GObjectClass*)klass;
104   gstelement_class = (GstElementClass*)klass;
105
106   parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
107
108   gobject_class->set_property = gst_mulawdec_set_property;
109   gobject_class->get_property = gst_mulawdec_get_property;
110 }
111
112 static void
113 gst_mulawdec_init (GstMuLawDec *mulawdec)
114 {
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);
118
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);
122 }
123
124 static void
125 gst_mulawdec_chain (GstPad *pad,GstBuffer *buf)
126 {
127   GstMuLawDec *mulawdec;
128   gint16 *linear_data;
129   guint8 *mulaw_data;
130   GstBuffer* outbuf;
131
132   g_return_if_fail(pad != NULL);
133   g_return_if_fail(GST_IS_PAD(pad));
134   g_return_if_fail(buf != NULL);
135
136   mulawdec = GST_MULAWDEC(GST_OBJECT_PARENT (pad));
137   g_return_if_fail(mulawdec != NULL);
138   g_return_if_fail(GST_IS_MULAWDEC(mulawdec));
139
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;
144
145   linear_data = (gint16*)GST_BUFFER_DATA(outbuf);
146   mulaw_decode(mulaw_data,linear_data,GST_BUFFER_SIZE(buf));
147
148   gst_buffer_unref(buf);
149   gst_pad_push(mulawdec->srcpad,outbuf);
150 }
151
152 static void
153 gst_mulawdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
154 {
155   GstMuLawDec *mulawdec;
156
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);
160
161   switch (prop_id) {
162     default:
163       break;
164   }
165 }
166
167 static void
168 gst_mulawdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
169 {
170   GstMuLawDec *mulawdec;
171
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);
175
176   switch (prop_id) {
177     default:
178       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
179       break;
180   }
181 }