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 <gstfakesink.h>
27 GstElementDetails gst_fakesink_details = {
31 "Black hole for data",
33 "Erik Walthinsen <omega@cse.ogi.edu>",
38 /* FakeSink signals and args */
54 GST_PAD_TEMPLATE_FACTORY (fakesink_sink_factory,
62 static void gst_fakesink_class_init (GstFakeSinkClass *klass);
63 static void gst_fakesink_init (GstFakeSink *fakesink);
65 static void gst_fakesink_set_clock (GstElement *element, GstClock *clock);
66 static GstPad* gst_fakesink_request_new_pad (GstElement *element, GstPadTemplate *templ, const
69 static void gst_fakesink_set_property (GObject *object, guint prop_id,
70 const GValue *value, GParamSpec *pspec);
71 static void gst_fakesink_get_property (GObject *object, guint prop_id,
72 GValue *value, GParamSpec *pspec);
74 static void gst_fakesink_chain (GstPad *pad, GstBuffer *buf);
76 static GstElementClass *parent_class = NULL;
77 static guint gst_fakesink_signals[LAST_SIGNAL] = { 0 };
80 gst_fakesink_get_type (void)
82 static GType fakesink_type = 0;
85 static const GTypeInfo fakesink_info = {
86 sizeof(GstFakeSinkClass), NULL,
88 (GClassInitFunc)gst_fakesink_class_init,
93 (GInstanceInitFunc)gst_fakesink_init,
95 fakesink_type = g_type_register_static (GST_TYPE_ELEMENT, "GstFakeSink", &fakesink_info, 0);
101 gst_fakesink_class_init (GstFakeSinkClass *klass)
103 GObjectClass *gobject_class;
104 GstElementClass *gstelement_class;
106 gobject_class = (GObjectClass*)klass;
107 gstelement_class = (GstElementClass*)klass;
109 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
111 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_SINKS,
112 g_param_spec_int ("num_sinks", "Number of sinks", "The number of sinkpads",
113 1, G_MAXINT, 1, G_PARAM_READABLE));
114 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
115 g_param_spec_string ("last_message", "Last Message", "The message describing current status",
116 NULL, G_PARAM_READABLE));
117 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SYNC,
118 g_param_spec_boolean ("sync", "Sync", "Sync on the clock",
119 FALSE, G_PARAM_READWRITE));
120 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
121 g_param_spec_boolean ("silent", "Silent", "Don't produce last_message events",
122 FALSE, G_PARAM_READWRITE));
123 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DUMP,
124 g_param_spec_boolean ("dump", "Dump", "Dump received bytes to stdout",
125 FALSE, G_PARAM_READWRITE));
127 gst_fakesink_signals[SIGNAL_HANDOFF] =
128 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
129 G_STRUCT_OFFSET (GstFakeSinkClass, handoff), NULL, NULL,
130 g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
133 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesink_set_property);
134 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesink_get_property);
136 gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR (gst_fakesink_request_new_pad);
137 gstelement_class->set_clock = GST_DEBUG_FUNCPTR (gst_fakesink_set_clock);
141 gst_fakesink_init (GstFakeSink *fakesink)
145 pad = gst_pad_new ("sink", GST_PAD_SINK);
146 gst_element_add_pad (GST_ELEMENT (fakesink), pad);
147 gst_pad_set_chain_function (pad, GST_DEBUG_FUNCPTR (gst_fakesink_chain));
149 fakesink->silent = FALSE;
150 fakesink->dump = FALSE;
151 fakesink->sync = FALSE;
152 fakesink->last_message = NULL;
154 GST_FLAG_SET (fakesink, GST_ELEMENT_EVENT_AWARE);
158 gst_fakesink_set_clock (GstElement *element, GstClock *clock)
162 sink = GST_FAKESINK (element);
168 gst_fakesink_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused)
172 GstFakeSink *fakesink;
174 g_return_val_if_fail (GST_IS_FAKESINK (element), NULL);
176 if (templ->direction != GST_PAD_SINK) {
177 g_warning ("gstfakesink: request new pad that is not a SINK pad\n");
181 fakesink = GST_FAKESINK (element);
183 name = g_strdup_printf ("sink%d", GST_ELEMENT (fakesink)->numsinkpads);
185 sinkpad = gst_pad_new_from_template (templ, name);
188 gst_element_add_pad (GST_ELEMENT (fakesink), sinkpad);
194 gst_fakesink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
198 /* it's not null if we got it, but it might not be ours */
199 sink = GST_FAKESINK (object);
203 sink->silent = g_value_get_boolean (value);
206 sink->dump = g_value_get_boolean (value);
209 sink->sync = g_value_get_boolean (value);
217 gst_fakesink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
221 /* it's not null if we got it, but it might not be ours */
222 g_return_if_fail (GST_IS_FAKESINK (object));
224 sink = GST_FAKESINK (object);
228 g_value_set_int (value, GST_ELEMENT (sink)->numsinkpads);
231 g_value_set_boolean (value, sink->silent);
234 g_value_set_boolean (value, sink->dump);
237 g_value_set_boolean (value, sink->sync);
239 case ARG_LAST_MESSAGE:
240 g_value_set_string (value, sink->last_message);
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 gst_fakesink_chain (GstPad *pad, GstBuffer *buf)
251 GstFakeSink *fakesink;
253 g_return_if_fail (pad != NULL);
254 g_return_if_fail (GST_IS_PAD (pad));
255 g_return_if_fail (buf != NULL);
257 fakesink = GST_FAKESINK (gst_pad_get_parent (pad));
259 if (GST_IS_EVENT (buf)) {
260 GstEvent *event = GST_EVENT (buf);
262 if (!fakesink->silent) {
263 g_free (fakesink->last_message);
265 fakesink->last_message = g_strdup_printf ("chain ******* (%s:%s)E (type: %d) %p",
266 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE (event), event);
268 g_object_notify (G_OBJECT (fakesink), "last_message");
271 switch (GST_EVENT_TYPE (event)) {
272 case GST_EVENT_DISCONTINUOUS:
273 if (fakesink->sync && fakesink->clock) {
274 gint64 value = GST_EVENT_DISCONT_OFFSET (event, 0).value;
275 gst_clock_handle_discont (fakesink->clock, value);
278 gst_pad_event_default (pad, event);
284 if (fakesink->sync && fakesink->clock) {
285 GstClockID id = gst_clock_new_single_shot_id (fakesink->clock, GST_BUFFER_TIMESTAMP (buf));
287 gst_element_clock_wait (GST_ELEMENT (fakesink), id, NULL);
288 gst_clock_id_free (id);
291 if (!fakesink->silent) {
292 g_free (fakesink->last_message);
294 fakesink->last_message = g_strdup_printf ("chain ******* (%s:%s)< (%d bytes, %lld, %d) %p",
295 GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf),
296 GST_BUFFER_FLAGS (buf), buf);
298 g_object_notify (G_OBJECT (fakesink), "last_message");
301 g_signal_emit (G_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF], 0, buf, pad);
303 if (fakesink->dump) {
304 gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
307 gst_buffer_unref (buf);
311 gst_fakesink_factory_init (GstElementFactory *factory)
313 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (fakesink_sink_factory));