2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2005 Wim Taymans <wim@fluendo.com>
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 * @short_description: black hole for data
25 * @see_also: #GstFakeSrc
27 * Dummy sink that swallows everything.
34 #include "gstfakesink.h"
35 #include <gst/gstmarshal.h>
37 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
42 GST_DEBUG_CATEGORY_STATIC (gst_fake_sink_debug);
43 #define GST_CAT_DEFAULT gst_fake_sink_debug
45 GstElementDetails gst_fake_sink_details = GST_ELEMENT_DETAILS ("Fake Sink",
47 "Black hole for data",
48 "Erik Walthinsen <omega@cse.ogi.edu>, "
49 "Wim Taymans <wim@fluendo.com>, "
50 "Mr. 'frag-me-more' Vanderwingo <wingo@fluendo.com>");
53 /* FakeSink signals and args */
61 #define DEFAULT_STATE_ERROR FAKE_SINK_STATE_ERROR_NONE
62 #define DEFAULT_SILENT FALSE
63 #define DEFAULT_DUMP FALSE
64 #define DEFAULT_SYNC FALSE
65 #define DEFAULT_SIGNAL_HANDOFFS FALSE
66 #define DEFAULT_LAST_MESSAGE NULL
67 #define DEFAULT_CAN_ACTIVATE_PUSH TRUE
68 #define DEFAULT_CAN_ACTIVATE_PULL FALSE
79 PROP_CAN_ACTIVATE_PUSH,
80 PROP_CAN_ACTIVATE_PULL
83 #define GST_TYPE_FAKE_SINK_STATE_ERROR (gst_fake_sink_state_error_get_type())
85 gst_fake_sink_state_error_get_type (void)
87 static GType fakesink_state_error_type = 0;
88 static GEnumValue fakesink_state_error[] = {
89 {FAKE_SINK_STATE_ERROR_NONE, "0", "No state change errors"},
90 {FAKE_SINK_STATE_ERROR_NULL_READY, "1",
91 "Fail state change from NULL to READY"},
92 {FAKE_SINK_STATE_ERROR_READY_PAUSED, "2",
93 "Fail state change from READY to PAUSED"},
94 {FAKE_SINK_STATE_ERROR_PAUSED_PLAYING, "3",
95 "Fail state change from PAUSED to PLAYING"},
96 {FAKE_SINK_STATE_ERROR_PLAYING_PAUSED, "4",
97 "Fail state change from PLAYING to PAUSED"},
98 {FAKE_SINK_STATE_ERROR_PAUSED_READY, "5",
99 "Fail state change from PAUSED to READY"},
100 {FAKE_SINK_STATE_ERROR_READY_NULL, "6",
101 "Fail state change from READY to NULL"},
105 if (!fakesink_state_error_type) {
106 fakesink_state_error_type =
107 g_enum_register_static ("GstFakeSinkStateError", fakesink_state_error);
109 return fakesink_state_error_type;
112 #define _do_init(bla) \
113 GST_DEBUG_CATEGORY_INIT (gst_fake_sink_debug, "fakesink", 0, "fakesink element");
115 GST_BOILERPLATE_FULL (GstFakeSink, gst_fake_sink, GstBaseSink,
116 GST_TYPE_BASE_SINK, _do_init);
118 static void gst_fake_sink_set_property (GObject * object, guint prop_id,
119 const GValue * value, GParamSpec * pspec);
120 static void gst_fake_sink_get_property (GObject * object, guint prop_id,
121 GValue * value, GParamSpec * pspec);
123 static GstStateChangeReturn gst_fake_sink_change_state (GstElement * element,
124 GstStateChange transition);
126 static GstFlowReturn gst_fake_sink_preroll (GstBaseSink * bsink,
128 static GstFlowReturn gst_fake_sink_render (GstBaseSink * bsink,
130 static gboolean gst_fake_sink_event (GstBaseSink * bsink, GstEvent * event);
131 static void gst_fake_sink_get_times (GstBaseSink * bsink, GstBuffer * buffer,
132 GstClockTime * start, GstClockTime * end);
134 static guint gst_fake_sink_signals[LAST_SIGNAL] = { 0 };
137 gst_fake_sink_base_init (gpointer g_class)
139 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
141 gst_element_class_add_pad_template (gstelement_class,
142 gst_static_pad_template_get (&sinktemplate));
143 gst_element_class_set_details (gstelement_class, &gst_fake_sink_details);
147 gst_fake_sink_class_init (GstFakeSinkClass * klass)
149 GObjectClass *gobject_class;
150 GstElementClass *gstelement_class;
151 GstBaseSinkClass *gstbase_sink_class;
153 gobject_class = (GObjectClass *) klass;
154 gstelement_class = (GstElementClass *) klass;
155 gstbase_sink_class = (GstBaseSinkClass *) klass;
157 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fake_sink_set_property);
158 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fake_sink_get_property);
160 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_STATE_ERROR,
161 g_param_spec_enum ("state_error", "State Error",
162 "Generate a state change error", GST_TYPE_FAKE_SINK_STATE_ERROR,
163 DEFAULT_STATE_ERROR, G_PARAM_READWRITE));
164 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LAST_MESSAGE,
165 g_param_spec_string ("last_message", "Last Message",
166 "The message describing current status", DEFAULT_LAST_MESSAGE,
168 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SYNC,
169 g_param_spec_boolean ("sync", "Sync", "Sync on the clock", DEFAULT_SYNC,
171 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SIGNAL_HANDOFFS,
172 g_param_spec_boolean ("signal-handoffs", "Signal handoffs",
173 "Send a signal before unreffing the buffer", DEFAULT_SIGNAL_HANDOFFS,
175 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SILENT,
176 g_param_spec_boolean ("silent", "Silent",
177 "Don't produce last_message events", DEFAULT_SILENT,
179 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DUMP,
180 g_param_spec_boolean ("dump", "Dump", "Dump received bytes to stdout",
181 DEFAULT_DUMP, G_PARAM_READWRITE));
182 g_object_class_install_property (G_OBJECT_CLASS (klass),
183 PROP_CAN_ACTIVATE_PUSH,
184 g_param_spec_boolean ("can-activate-push", "Can activate push",
185 "Can activate in push mode", DEFAULT_CAN_ACTIVATE_PUSH,
187 g_object_class_install_property (G_OBJECT_CLASS (klass),
188 PROP_CAN_ACTIVATE_PULL,
189 g_param_spec_boolean ("can-activate-pull", "Can activate pull",
190 "Can activate in pull mode", DEFAULT_CAN_ACTIVATE_PULL,
194 * GstFakeSink::handoff:
195 * @fakesink: the fakesink instance
196 * @buffer: the buffer that just has been received
197 * @pad: the pad that received it
199 * This signal gets emitted before unreffing the buffer.
201 gst_fake_sink_signals[SIGNAL_HANDOFF] =
202 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
203 G_STRUCT_OFFSET (GstFakeSinkClass, handoff), NULL, NULL,
204 gst_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2,
205 GST_TYPE_BUFFER, GST_TYPE_PAD);
207 gstelement_class->change_state =
208 GST_DEBUG_FUNCPTR (gst_fake_sink_change_state);
210 gstbase_sink_class->event = GST_DEBUG_FUNCPTR (gst_fake_sink_event);
211 gstbase_sink_class->preroll = GST_DEBUG_FUNCPTR (gst_fake_sink_preroll);
212 gstbase_sink_class->render = GST_DEBUG_FUNCPTR (gst_fake_sink_render);
213 gstbase_sink_class->get_times = GST_DEBUG_FUNCPTR (gst_fake_sink_get_times);
217 gst_fake_sink_init (GstFakeSink * fakesink, GstFakeSinkClass * g_class)
219 fakesink->silent = DEFAULT_SILENT;
220 fakesink->dump = DEFAULT_DUMP;
221 fakesink->sync = DEFAULT_SYNC;
222 fakesink->last_message = g_strdup (DEFAULT_LAST_MESSAGE);
223 fakesink->state_error = DEFAULT_STATE_ERROR;
224 fakesink->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS;
228 gst_fake_sink_set_property (GObject * object, guint prop_id,
229 const GValue * value, GParamSpec * pspec)
233 sink = GST_FAKE_SINK (object);
237 sink->silent = g_value_get_boolean (value);
239 case PROP_STATE_ERROR:
240 sink->state_error = g_value_get_enum (value);
243 sink->dump = g_value_get_boolean (value);
246 sink->sync = g_value_get_boolean (value);
248 case PROP_SIGNAL_HANDOFFS:
249 sink->signal_handoffs = g_value_get_boolean (value);
251 case PROP_CAN_ACTIVATE_PUSH:
252 GST_BASE_SINK (sink)->can_activate_push = g_value_get_boolean (value);
254 case PROP_CAN_ACTIVATE_PULL:
255 GST_BASE_SINK (sink)->can_activate_pull = g_value_get_boolean (value);
258 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
264 gst_fake_sink_get_property (GObject * object, guint prop_id, GValue * value,
269 sink = GST_FAKE_SINK (object);
272 case PROP_STATE_ERROR:
273 g_value_set_enum (value, sink->state_error);
276 g_value_set_boolean (value, sink->silent);
279 g_value_set_boolean (value, sink->dump);
282 g_value_set_boolean (value, sink->sync);
284 case PROP_SIGNAL_HANDOFFS:
285 g_value_set_boolean (value, sink->signal_handoffs);
287 case PROP_LAST_MESSAGE:
288 g_value_set_string (value, sink->last_message);
290 case PROP_CAN_ACTIVATE_PUSH:
291 g_value_set_boolean (value, GST_BASE_SINK (sink)->can_activate_push);
293 case PROP_CAN_ACTIVATE_PULL:
294 g_value_set_boolean (value, GST_BASE_SINK (sink)->can_activate_pull);
297 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
303 gst_fake_sink_get_times (GstBaseSink * bsink, GstBuffer * buffer,
304 GstClockTime * start, GstClockTime * end)
306 GstFakeSink *sink = GST_FAKE_SINK (bsink);
309 GST_BASE_SINK_CLASS (parent_class)->get_times (bsink, buffer, start, end);
314 gst_fake_sink_event (GstBaseSink * bsink, GstEvent * event)
316 GstFakeSink *sink = GST_FAKE_SINK (bsink);
317 const GstStructure *s;
322 g_free (sink->last_message);
324 if ((s = gst_event_get_structure (event)))
325 sstr = gst_structure_to_string (s);
327 sstr = g_strdup ("");
330 g_strdup_printf ("event ******* E (type: %d, %s) %p",
331 GST_EVENT_TYPE (event), sstr, event);
334 g_object_notify (G_OBJECT (sink), "last_message");
341 gst_fake_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
343 GstFakeSink *sink = GST_FAKE_SINK (bsink);
346 g_free (sink->last_message);
348 sink->last_message = g_strdup_printf ("preroll ******* ");
350 g_object_notify (G_OBJECT (sink), "last_message");
356 gst_fake_sink_render (GstBaseSink * bsink, GstBuffer * buf)
358 GstFakeSink *sink = GST_FAKE_SINK (bsink);
361 g_free (sink->last_message);
364 g_strdup_printf ("chain ******* < (%d bytes, timestamp: %"
365 GST_TIME_FORMAT ", duration: %" GST_TIME_FORMAT ", offset: %"
366 G_GINT64_FORMAT ", offset_end: %" G_GINT64_FORMAT ", flags: %d) %p",
367 GST_BUFFER_SIZE (buf),
368 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
369 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf),
370 GST_BUFFER_OFFSET_END (buf), GST_MINI_OBJECT (buf)->flags, buf);
372 g_object_notify (G_OBJECT (sink), "last_message");
374 if (sink->signal_handoffs)
375 g_signal_emit (G_OBJECT (sink), gst_fake_sink_signals[SIGNAL_HANDOFF], 0,
376 buf, bsink->sinkpad);
379 gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
385 static GstStateChangeReturn
386 gst_fake_sink_change_state (GstElement * element, GstStateChange transition)
388 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
389 GstFakeSink *fakesink = GST_FAKE_SINK (element);
391 switch (transition) {
392 case GST_STATE_CHANGE_NULL_TO_READY:
393 if (fakesink->state_error == FAKE_SINK_STATE_ERROR_NULL_READY)
396 case GST_STATE_CHANGE_READY_TO_PAUSED:
397 if (fakesink->state_error == FAKE_SINK_STATE_ERROR_READY_PAUSED)
400 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
401 if (fakesink->state_error == FAKE_SINK_STATE_ERROR_PAUSED_PLAYING)
408 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
410 switch (transition) {
411 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
412 if (fakesink->state_error == FAKE_SINK_STATE_ERROR_PLAYING_PAUSED)
415 case GST_STATE_CHANGE_PAUSED_TO_READY:
416 if (fakesink->state_error == FAKE_SINK_STATE_ERROR_PAUSED_READY)
419 case GST_STATE_CHANGE_READY_TO_NULL:
420 if (fakesink->state_error == FAKE_SINK_STATE_ERROR_READY_NULL)
422 g_free (fakesink->last_message);
423 fakesink->last_message = NULL;
432 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
433 return GST_STATE_CHANGE_FAILURE;