Added DEBUG_FUNCPTR to most plugins.
[platform/upstream/gstreamer.git] / gst / elements / gstidentity.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstidentity.c: 
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23
24 #include <gstidentity.h>
25
26
27 GstElementDetails gst_identity_details = {
28   "Identity",
29   "Filter",
30   "Pass data without modification",
31   VERSION,
32   "Erik Walthinsen <omega@cse.ogi.edu>",
33   "(C) 1999",
34 };
35
36
37 /* Identity signals and args */
38 enum {
39   SIGNAL_HANDOFF,
40   /* FILL ME */
41   LAST_SIGNAL
42 };
43
44 enum {
45   ARG_0,
46   ARG_LOOP_BASED,
47   ARG_SLEEP_TIME,
48   ARG_SILENT,
49 };
50
51
52 static void gst_identity_class_init     (GstIdentityClass *klass);
53 static void gst_identity_init           (GstIdentity *identity);
54
55 static void gst_identity_set_property   (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
56 static void gst_identity_get_property   (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
57
58 static void gst_identity_chain          (GstPad *pad, GstBuffer *buf);
59
60 static GstElementClass *parent_class = NULL;
61 static guint gst_identity_signals[LAST_SIGNAL] = { 0 };
62
63 GType
64 gst_identity_get_type (void) 
65 {
66   static GType identity_type = 0;
67
68   if (!identity_type) {
69     static const GTypeInfo identity_info = {
70       sizeof(GstIdentityClass),      NULL,
71       NULL,
72       (GClassInitFunc)gst_identity_class_init,
73       NULL,
74       NULL,
75       sizeof(GstIdentity),
76       0,
77       (GInstanceInitFunc)gst_identity_init,
78     };
79     identity_type = g_type_register_static (GST_TYPE_ELEMENT, "GstIdentity", &identity_info, 0);
80   }
81   return identity_type;
82 }
83
84 static void 
85 gst_identity_class_init (GstIdentityClass *klass) 
86 {
87   GObjectClass *gobject_class;
88
89   gobject_class = (GObjectClass*)klass;
90
91   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
92
93   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LOOP_BASED,
94     g_param_spec_boolean("loop_based","loop_based","loop_based",
95                          TRUE,G_PARAM_READWRITE)); // CHECKME
96   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SLEEP_TIME,
97     g_param_spec_uint("sleep_time","sleep_time","sleep_time",
98                      0,G_MAXUINT,0,G_PARAM_READWRITE)); // CHECKME
99   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SILENT,
100     g_param_spec_boolean("silent","silent","silent",
101                          TRUE,G_PARAM_READWRITE)); // CHECKME
102
103   gst_identity_signals[SIGNAL_HANDOFF] =
104     g_signal_newc ("handoff", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
105                    G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
106                    g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
107                    G_TYPE_POINTER);
108
109   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_identity_set_property);  
110   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_identity_get_property);
111 }
112
113 static GstBufferPool*
114 gst_identity_get_bufferpool (GstPad *pad)
115 {
116   GstIdentity *identity;
117
118   identity = GST_IDENTITY (gst_pad_get_parent (pad));
119
120   return gst_pad_get_bufferpool (identity->srcpad);
121 }
122
123 static GstPadNegotiateReturn
124 gst_identity_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data)
125 {
126   GstIdentity *identity;
127
128   identity = GST_IDENTITY (gst_pad_get_parent (pad));
129
130   return gst_pad_negotiate_proxy (pad, identity->sinkpad, caps);
131 }
132
133 static GstPadNegotiateReturn
134 gst_identity_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data)
135 {
136   GstIdentity *identity;
137
138   identity = GST_IDENTITY (gst_pad_get_parent (pad));
139
140   return gst_pad_negotiate_proxy (pad, identity->srcpad, caps);
141 }
142
143 static void 
144 gst_identity_init (GstIdentity *identity) 
145 {
146   identity->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
147   gst_element_add_pad (GST_ELEMENT (identity), identity->sinkpad);
148   gst_pad_set_chain_function (identity->sinkpad, GST_DEBUG_FUNCPTR (gst_identity_chain));
149   gst_pad_set_bufferpool_function (identity->sinkpad, gst_identity_get_bufferpool);
150   gst_pad_set_negotiate_function (identity->sinkpad, gst_identity_negotiate_sink);
151   
152   identity->srcpad = gst_pad_new ("src", GST_PAD_SRC);
153   gst_element_add_pad (GST_ELEMENT (identity), identity->srcpad);
154   gst_pad_set_negotiate_function (identity->srcpad, gst_identity_negotiate_src);
155
156   identity->loop_based = FALSE;
157   identity->sleep_time = 0;
158   identity->silent = FALSE;
159 }
160
161 static void 
162 gst_identity_chain (GstPad *pad, GstBuffer *buf) 
163 {
164   GstIdentity *identity;
165
166   g_return_if_fail (pad != NULL);
167   g_return_if_fail (GST_IS_PAD (pad));
168   g_return_if_fail (buf != NULL);
169
170   identity = GST_IDENTITY (gst_pad_get_parent (pad));
171
172   if (!identity->silent)
173     g_print("identity: chain ******* (%s:%s)i (%d bytes, %llu) \n",
174               GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
175   
176   g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
177                                buf);
178
179   gst_pad_push (identity->srcpad, buf);
180
181   if (identity->sleep_time)
182     usleep (identity->sleep_time);
183 }
184
185 static void 
186 gst_identity_loop (GstElement *element) 
187 {
188   GstIdentity *identity;
189   GstBuffer *buf;
190
191   g_return_if_fail (element != NULL);
192   g_return_if_fail (GST_IS_IDENTITY (element));
193
194   identity = GST_IDENTITY (element);
195   
196   do {
197     buf = gst_pad_pull (identity->sinkpad);
198     if (!identity->silent)
199       g_print("identity: loop  ******* (%s:%s)i (%d bytes, %llu) \n",
200                       GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
201
202     g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
203                                buf);
204
205     gst_pad_push (identity->srcpad, buf);
206
207     if (identity->sleep_time)
208       usleep (identity->sleep_time);
209
210   } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element));
211 }
212
213 static void 
214 gst_identity_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) 
215 {
216   GstIdentity *identity;
217
218   /* it's not null if we got it, but it might not be ours */
219   g_return_if_fail (GST_IS_IDENTITY (object));
220   
221   identity = GST_IDENTITY (object);
222
223   switch (prop_id) {
224     case ARG_LOOP_BASED:
225       identity->loop_based = g_value_get_boolean (value);
226       if (identity->loop_based) {
227         gst_element_set_loop_function (GST_ELEMENT (identity), gst_identity_loop);
228         gst_pad_set_chain_function (identity->sinkpad, NULL);
229       }
230       else {
231         gst_pad_set_chain_function (identity->sinkpad, gst_identity_chain);
232         gst_element_set_loop_function (GST_ELEMENT (identity), NULL);
233       }
234       break;
235     case ARG_SLEEP_TIME:
236       identity->sleep_time = g_value_get_uint (value);
237       break;
238     case ARG_SILENT:
239       identity->silent = g_value_get_boolean (value);
240       break;
241     default:
242       break;
243   }
244 }
245
246 static void gst_identity_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {
247   GstIdentity *identity;
248
249   /* it's not null if we got it, but it might not be ours */
250   g_return_if_fail (GST_IS_IDENTITY (object));
251   
252   identity = GST_IDENTITY (object);
253
254   switch (prop_id) {
255     case ARG_LOOP_BASED:
256       g_value_set_boolean (value, identity->loop_based);
257       break;
258     case ARG_SLEEP_TIME:
259       g_value_set_uint (value, identity->sleep_time);
260       break;
261     case ARG_SILENT:
262       g_value_set_boolean (value, identity->silent);
263       break;
264     default:
265       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
266       break;
267   }
268 }