2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
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.
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.
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.
24 #include <gstidentity.h>
27 GstElementDetails gst_identity_details = {
30 "Pass data without modification",
32 "Erik Walthinsen <omega@cse.ogi.edu>",
37 /* Identity signals and args */
52 static void gst_identity_class_init (GstIdentityClass *klass);
53 static void gst_identity_init (GstIdentity *identity);
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);
58 static void gst_identity_chain (GstPad *pad, GstBuffer *buf);
60 static GstElementClass *parent_class = NULL;
61 static guint gst_identity_signals[LAST_SIGNAL] = { 0 };
64 gst_identity_get_type (void)
66 static GType identity_type = 0;
69 static const GTypeInfo identity_info = {
70 sizeof(GstIdentityClass), NULL,
72 (GClassInitFunc)gst_identity_class_init,
77 (GInstanceInitFunc)gst_identity_init,
79 identity_type = g_type_register_static (GST_TYPE_ELEMENT, "GstIdentity", &identity_info, 0);
85 gst_identity_class_init (GstIdentityClass *klass)
87 GObjectClass *gobject_class;
89 gobject_class = (GObjectClass*)klass;
91 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
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
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,
109 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_identity_set_property);
110 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_identity_get_property);
113 static GstBufferPool*
114 gst_identity_get_bufferpool (GstPad *pad)
116 GstIdentity *identity;
118 identity = GST_IDENTITY (gst_pad_get_parent (pad));
120 return gst_pad_get_bufferpool (identity->srcpad);
123 static GstPadNegotiateReturn
124 gst_identity_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data)
126 GstIdentity *identity;
128 identity = GST_IDENTITY (gst_pad_get_parent (pad));
130 return gst_pad_negotiate_proxy (pad, identity->sinkpad, caps);
133 static GstPadNegotiateReturn
134 gst_identity_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data)
136 GstIdentity *identity;
138 identity = GST_IDENTITY (gst_pad_get_parent (pad));
140 return gst_pad_negotiate_proxy (pad, identity->srcpad, caps);
144 gst_identity_init (GstIdentity *identity)
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);
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);
156 identity->loop_based = FALSE;
157 identity->sleep_time = 0;
158 identity->silent = FALSE;
162 gst_identity_chain (GstPad *pad, GstBuffer *buf)
164 GstIdentity *identity;
166 g_return_if_fail (pad != NULL);
167 g_return_if_fail (GST_IS_PAD (pad));
168 g_return_if_fail (buf != NULL);
170 identity = GST_IDENTITY (gst_pad_get_parent (pad));
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));
176 g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
179 gst_pad_push (identity->srcpad, buf);
181 if (identity->sleep_time)
182 usleep (identity->sleep_time);
186 gst_identity_loop (GstElement *element)
188 GstIdentity *identity;
191 g_return_if_fail (element != NULL);
192 g_return_if_fail (GST_IS_IDENTITY (element));
194 identity = GST_IDENTITY (element);
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));
202 g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
205 gst_pad_push (identity->srcpad, buf);
207 if (identity->sleep_time)
208 usleep (identity->sleep_time);
210 } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element));
214 gst_identity_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
216 GstIdentity *identity;
218 /* it's not null if we got it, but it might not be ours */
219 g_return_if_fail (GST_IS_IDENTITY (object));
221 identity = GST_IDENTITY (object);
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);
231 gst_pad_set_chain_function (identity->sinkpad, gst_identity_chain);
232 gst_element_set_loop_function (GST_ELEMENT (identity), NULL);
236 identity->sleep_time = g_value_get_uint (value);
239 identity->silent = g_value_get_boolean (value);
246 static void gst_identity_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {
247 GstIdentity *identity;
249 /* it's not null if we got it, but it might not be ours */
250 g_return_if_fail (GST_IS_IDENTITY (object));
252 identity = GST_IDENTITY (object);
256 g_value_set_boolean (value, identity->loop_based);
259 g_value_set_uint (value, identity->sleep_time);
262 g_value_set_boolean (value, identity->silent);
265 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);