2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 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.
23 * SECTION:element-fakesrc
24 * @see_also: #GstFakeSink
26 * The fakesrc element is a multipurpose element that can generate
27 * a wide range of buffers and can operate in various scheduling modes.
29 * It is mostly used as a testing element, one trivial example for testing
30 * basic <application>GStreamer</application> core functionality is:
33 * <title>Example launch line</title>
35 * gst-launch -v fakesrc num-buffers=5 ! fakesink
36 * ]| This pipeline will push 5 empty buffers to the fakesink element and then
40 * Last reviewed on 2008-06-20 (0.10.21)
43 /* FIXME: this ignores basesrc::blocksize property, which could be used as an
44 * alias to ::sizemax (see gst_base_src_get_blocksize()).
54 #include "gstfakesrc.h"
55 #include <gst/gstmarshal.h>
57 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
62 GST_DEBUG_CATEGORY_STATIC (gst_fake_src_debug);
63 #define GST_CAT_DEFAULT gst_fake_src_debug
65 /* FakeSrc signals and args */
73 #define DEFAULT_OUTPUT FAKE_SRC_FIRST_LAST_LOOP
74 #define DEFAULT_DATA FAKE_SRC_DATA_ALLOCATE
75 #define DEFAULT_SIZETYPE FAKE_SRC_SIZETYPE_EMPTY
76 #define DEFAULT_SIZEMIN 0
77 #define DEFAULT_SIZEMAX 4096
78 #define DEFAULT_FILLTYPE FAKE_SRC_FILLTYPE_ZERO
79 #define DEFAULT_DATARATE 0
80 #define DEFAULT_SYNC FALSE
81 #define DEFAULT_PATTERN NULL
82 #define DEFAULT_EOS FALSE
83 #define DEFAULT_SIGNAL_HANDOFFS FALSE
84 #define DEFAULT_SILENT FALSE
85 #define DEFAULT_DUMP FALSE
86 #define DEFAULT_PARENTSIZE 4096*10
87 #define DEFAULT_CAN_ACTIVATE_PULL TRUE
88 #define DEFAULT_CAN_ACTIVATE_PUSH TRUE
89 #define DEFAULT_FORMAT GST_FORMAT_BYTES
104 PROP_SIGNAL_HANDOFFS,
109 PROP_CAN_ACTIVATE_PULL,
110 PROP_CAN_ACTIVATE_PUSH,
117 #define GST_TYPE_FAKE_SRC_OUTPUT (gst_fake_src_output_get_type())
119 gst_fake_src_output_get_type (void)
121 static GType fakesrc_output_type = 0;
122 static const GEnumValue fakesrc_output[] = {
123 {FAKE_SRC_FIRST_LAST_LOOP, "1", "First-Last loop"},
124 {FAKE_SRC_LAST_FIRST_LOOP, "2", "Last-First loop"},
125 {FAKE_SRC_PING_PONG, "3", "Ping-Pong"},
126 {FAKE_SRC_ORDERED_RANDOM, "4", "Ordered Random"},
127 {FAKE_SRC_RANDOM, "5", "Random"},
128 {FAKE_SRC_PATTERN_LOOP, "6", "Patttern loop"},
129 {FAKE_SRC_PING_PONG_PATTERN, "7", "Ping-Pong Pattern"},
130 {FAKE_SRC_GET_ALWAYS_SUCEEDS, "8", "'_get' Always succeeds"},
134 if (!fakesrc_output_type) {
135 fakesrc_output_type =
136 g_enum_register_static ("GstFakeSrcOutput", fakesrc_output);
138 return fakesrc_output_type;
142 #define GST_TYPE_FAKE_SRC_DATA (gst_fake_src_data_get_type())
144 gst_fake_src_data_get_type (void)
146 static GType fakesrc_data_type = 0;
147 static const GEnumValue fakesrc_data[] = {
148 {FAKE_SRC_DATA_ALLOCATE, "Allocate data", "allocate"},
149 {FAKE_SRC_DATA_SUBBUFFER, "Subbuffer data", "subbuffer"},
153 if (!fakesrc_data_type) {
155 g_enum_register_static ("GstFakeSrcDataType", fakesrc_data);
157 return fakesrc_data_type;
160 #define GST_TYPE_FAKE_SRC_SIZETYPE (gst_fake_src_sizetype_get_type())
162 gst_fake_src_sizetype_get_type (void)
164 static GType fakesrc_sizetype_type = 0;
165 static const GEnumValue fakesrc_sizetype[] = {
166 {FAKE_SRC_SIZETYPE_EMPTY, "Send empty buffers", "empty"},
167 {FAKE_SRC_SIZETYPE_FIXED, "Fixed size buffers (sizemax sized)", "fixed"},
168 {FAKE_SRC_SIZETYPE_RANDOM,
169 "Random sized buffers (sizemin <= size <= sizemax)", "random"},
173 if (!fakesrc_sizetype_type) {
174 fakesrc_sizetype_type =
175 g_enum_register_static ("GstFakeSrcSizeType", fakesrc_sizetype);
177 return fakesrc_sizetype_type;
180 #define GST_TYPE_FAKE_SRC_FILLTYPE (gst_fake_src_filltype_get_type())
182 gst_fake_src_filltype_get_type (void)
184 static GType fakesrc_filltype_type = 0;
185 static const GEnumValue fakesrc_filltype[] = {
186 {FAKE_SRC_FILLTYPE_NOTHING, "Leave data as malloced", "nothing"},
187 {FAKE_SRC_FILLTYPE_ZERO, "Fill buffers with zeros", "zero"},
188 {FAKE_SRC_FILLTYPE_RANDOM, "Fill buffers with random crap", "random"},
189 {FAKE_SRC_FILLTYPE_PATTERN, "Fill buffers with pattern 0x00 -> 0xff",
191 {FAKE_SRC_FILLTYPE_PATTERN_CONT,
192 "Fill buffers with pattern 0x00 -> 0xff that spans buffers",
197 if (!fakesrc_filltype_type) {
198 fakesrc_filltype_type =
199 g_enum_register_static ("GstFakeSrcFillType", fakesrc_filltype);
201 return fakesrc_filltype_type;
205 GST_DEBUG_CATEGORY_INIT (gst_fake_src_debug, "fakesrc", 0, "fakesrc element");
206 #define gst_fake_src_parent_class parent_class
207 G_DEFINE_TYPE_WITH_CODE (GstFakeSrc, gst_fake_src, GST_TYPE_BASE_SRC, _do_init);
209 static void gst_fake_src_finalize (GObject * object);
210 static void gst_fake_src_set_property (GObject * object, guint prop_id,
211 const GValue * value, GParamSpec * pspec);
212 static void gst_fake_src_get_property (GObject * object, guint prop_id,
213 GValue * value, GParamSpec * pspec);
215 static gboolean gst_fake_src_start (GstBaseSrc * basesrc);
216 static gboolean gst_fake_src_stop (GstBaseSrc * basesrc);
217 static gboolean gst_fake_src_is_seekable (GstBaseSrc * basesrc);
219 static gboolean gst_fake_src_event_handler (GstBaseSrc * src, GstEvent * event);
220 static void gst_fake_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
221 GstClockTime * start, GstClockTime * end);
222 static GstFlowReturn gst_fake_src_create (GstBaseSrc * src, guint64 offset,
223 guint length, GstBuffer ** buf);
225 static guint gst_fake_src_signals[LAST_SIGNAL] = { 0 };
227 static GParamSpec *pspec_last_message = NULL;
230 marshal_VOID__MINIOBJECT_OBJECT (GClosure * closure, GValue * return_value,
231 guint n_param_values, const GValue * param_values, gpointer invocation_hint,
232 gpointer marshal_data)
234 typedef void (*marshalfunc_VOID__MINIOBJECT_OBJECT) (gpointer obj,
235 gpointer arg1, gpointer arg2, gpointer data2);
236 register marshalfunc_VOID__MINIOBJECT_OBJECT callback;
237 register GCClosure *cc = (GCClosure *) closure;
238 register gpointer data1, data2;
240 g_return_if_fail (n_param_values == 3);
242 if (G_CCLOSURE_SWAP_DATA (closure)) {
243 data1 = closure->data;
244 data2 = g_value_peek_pointer (param_values + 0);
246 data1 = g_value_peek_pointer (param_values + 0);
247 data2 = closure->data;
250 (marshalfunc_VOID__MINIOBJECT_OBJECT) (marshal_data ? marshal_data :
253 callback (data1, g_value_get_boxed (param_values + 1),
254 g_value_get_object (param_values + 2), data2);
258 gst_fake_src_class_init (GstFakeSrcClass * klass)
260 GObjectClass *gobject_class;
261 GstElementClass *gstelement_class;
262 GstBaseSrcClass *gstbase_src_class;
264 gobject_class = G_OBJECT_CLASS (klass);
265 gstelement_class = GST_ELEMENT_CLASS (klass);
266 gstbase_src_class = GST_BASE_SRC_CLASS (klass);
268 gobject_class->finalize = gst_fake_src_finalize;
270 gobject_class->set_property = gst_fake_src_set_property;
271 gobject_class->get_property = gst_fake_src_get_property;
274 FIXME: this is not implemented; would make sense once basesrc and fakesrc
275 support multiple pads
276 g_object_class_install_property (gobject_class, PROP_OUTPUT,
277 g_param_spec_enum ("output", "output", "Output method (currently unused)",
278 GST_TYPE_FAKE_SRC_OUTPUT, DEFAULT_OUTPUT, G_PARAM_READWRITE));
280 g_object_class_install_property (gobject_class, PROP_DATA,
281 g_param_spec_enum ("data", "data", "Data allocation method",
282 GST_TYPE_FAKE_SRC_DATA, DEFAULT_DATA,
283 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
284 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SIZETYPE,
285 g_param_spec_enum ("sizetype", "sizetype",
286 "How to determine buffer sizes", GST_TYPE_FAKE_SRC_SIZETYPE,
287 DEFAULT_SIZETYPE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
288 g_object_class_install_property (gobject_class, PROP_SIZEMIN,
289 g_param_spec_int ("sizemin", "sizemin", "Minimum buffer size", 0,
290 G_MAXINT, DEFAULT_SIZEMIN,
291 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
292 g_object_class_install_property (gobject_class, PROP_SIZEMAX,
293 g_param_spec_int ("sizemax", "sizemax", "Maximum buffer size", 0,
294 G_MAXINT, DEFAULT_SIZEMAX,
295 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
296 g_object_class_install_property (gobject_class, PROP_PARENTSIZE,
297 g_param_spec_int ("parentsize", "parentsize",
298 "Size of parent buffer for sub-buffered allocation", 0, G_MAXINT,
299 DEFAULT_PARENTSIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
300 g_object_class_install_property (gobject_class, PROP_FILLTYPE,
301 g_param_spec_enum ("filltype", "filltype",
302 "How to fill the buffer, if at all", GST_TYPE_FAKE_SRC_FILLTYPE,
303 DEFAULT_FILLTYPE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
304 g_object_class_install_property (gobject_class, PROP_DATARATE,
305 g_param_spec_int ("datarate", "Datarate",
306 "Timestamps buffers with number of bytes per second (0 = none)", 0,
307 G_MAXINT, DEFAULT_DATARATE,
308 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
309 g_object_class_install_property (gobject_class, PROP_SYNC,
310 g_param_spec_boolean ("sync", "Sync", "Sync to the clock to the datarate",
311 DEFAULT_SYNC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
312 g_object_class_install_property (gobject_class, PROP_PATTERN,
313 g_param_spec_string ("pattern", "pattern", "pattern", DEFAULT_PATTERN,
314 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
315 pspec_last_message = g_param_spec_string ("last-message", "last-message",
316 "The last status message", NULL,
317 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
318 g_object_class_install_property (gobject_class, PROP_LAST_MESSAGE,
320 g_object_class_install_property (gobject_class, PROP_SILENT,
321 g_param_spec_boolean ("silent", "Silent",
322 "Don't produce last_message events", DEFAULT_SILENT,
323 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
324 g_object_class_install_property (gobject_class, PROP_SIGNAL_HANDOFFS,
325 g_param_spec_boolean ("signal-handoffs", "Signal handoffs",
326 "Send a signal before pushing the buffer", DEFAULT_SIGNAL_HANDOFFS,
327 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
328 g_object_class_install_property (gobject_class, PROP_DUMP,
329 g_param_spec_boolean ("dump", "Dump", "Dump buffer contents to stdout",
330 DEFAULT_DUMP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
331 g_object_class_install_property (gobject_class, PROP_CAN_ACTIVATE_PUSH,
332 g_param_spec_boolean ("can-activate-push", "Can activate push",
333 "Can activate in push mode", DEFAULT_CAN_ACTIVATE_PUSH,
334 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
335 g_object_class_install_property (gobject_class, PROP_CAN_ACTIVATE_PULL,
336 g_param_spec_boolean ("can-activate-pull", "Can activate pull",
337 "Can activate in pull mode", DEFAULT_CAN_ACTIVATE_PULL,
338 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
339 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
340 g_param_spec_boolean ("is-live", "Is this a live source",
341 "True if the element cannot produce data in PAUSED", FALSE,
342 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
346 * Set the format of the newsegment events to produce.
350 g_object_class_install_property (gobject_class, PROP_FORMAT,
351 g_param_spec_enum ("format", "Format",
352 "The format of the segment events", GST_TYPE_FORMAT,
353 DEFAULT_FORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
356 * GstFakeSrc::handoff:
357 * @fakesrc: the fakesrc instance
358 * @buffer: the buffer that will be pushed
359 * @pad: the pad that will sent it
361 * This signal gets emitted before sending the buffer.
363 gst_fake_src_signals[SIGNAL_HANDOFF] =
364 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
365 G_STRUCT_OFFSET (GstFakeSrcClass, handoff), NULL, NULL,
366 marshal_VOID__MINIOBJECT_OBJECT, G_TYPE_NONE, 2, GST_TYPE_BUFFER,
369 gst_element_class_set_details_simple (gstelement_class,
372 "Push empty (no data) buffers around",
373 "Erik Walthinsen <omega@cse.ogi.edu>, " "Wim Taymans <wim@fluendo.com>");
374 gst_element_class_add_pad_template (gstelement_class,
375 gst_static_pad_template_get (&srctemplate));
377 gstbase_src_class->is_seekable = GST_DEBUG_FUNCPTR (gst_fake_src_is_seekable);
378 gstbase_src_class->start = GST_DEBUG_FUNCPTR (gst_fake_src_start);
379 gstbase_src_class->stop = GST_DEBUG_FUNCPTR (gst_fake_src_stop);
380 gstbase_src_class->event = GST_DEBUG_FUNCPTR (gst_fake_src_event_handler);
381 gstbase_src_class->get_times = GST_DEBUG_FUNCPTR (gst_fake_src_get_times);
382 gstbase_src_class->create = GST_DEBUG_FUNCPTR (gst_fake_src_create);
386 gst_fake_src_init (GstFakeSrc * fakesrc)
388 fakesrc->output = FAKE_SRC_FIRST_LAST_LOOP;
389 fakesrc->buffer_count = 0;
390 fakesrc->silent = DEFAULT_SILENT;
391 fakesrc->signal_handoffs = DEFAULT_SIGNAL_HANDOFFS;
392 fakesrc->dump = DEFAULT_DUMP;
393 fakesrc->pattern_byte = 0x00;
394 fakesrc->data = FAKE_SRC_DATA_ALLOCATE;
395 fakesrc->sizetype = FAKE_SRC_SIZETYPE_EMPTY;
396 fakesrc->filltype = FAKE_SRC_FILLTYPE_NOTHING;
397 fakesrc->sizemin = DEFAULT_SIZEMIN;
398 fakesrc->sizemax = DEFAULT_SIZEMAX;
399 fakesrc->parent = NULL;
400 fakesrc->parentsize = DEFAULT_PARENTSIZE;
401 fakesrc->last_message = NULL;
402 fakesrc->datarate = DEFAULT_DATARATE;
403 fakesrc->sync = DEFAULT_SYNC;
404 fakesrc->format = DEFAULT_FORMAT;
408 gst_fake_src_finalize (GObject * object)
412 src = GST_FAKE_SRC (object);
414 g_free (src->last_message);
416 gst_buffer_unref (src->parent);
420 G_OBJECT_CLASS (parent_class)->finalize (object);
424 gst_fake_src_event_handler (GstBaseSrc * basesrc, GstEvent * event)
428 src = GST_FAKE_SRC (basesrc);
431 const GstStructure *s;
434 GST_OBJECT_LOCK (src);
435 g_free (src->last_message);
437 if ((s = gst_event_get_structure (event)))
438 sstr = gst_structure_to_string (s);
440 sstr = g_strdup ("");
443 g_strdup_printf ("event ******* E (type: %d, %s) %p",
444 GST_EVENT_TYPE (event), sstr, event);
446 GST_OBJECT_UNLOCK (src);
448 #if !GLIB_CHECK_VERSION(2,26,0)
449 g_object_notify ((GObject *) src, "last-message");
451 g_object_notify_by_pspec ((GObject *) src, pspec_last_message);
455 return GST_BASE_SRC_CLASS (parent_class)->event (basesrc, event);
459 gst_fake_src_alloc_parent (GstFakeSrc * src)
463 buf = gst_buffer_new_allocate (NULL, src->parentsize, 0);
466 src->parentoffset = 0;
470 gst_fake_src_set_property (GObject * object, guint prop_id,
471 const GValue * value, GParamSpec * pspec)
476 src = GST_FAKE_SRC (object);
477 basesrc = GST_BASE_SRC (object);
481 g_warning ("not yet implemented");
484 src->data = g_value_get_enum (value);
486 if (src->data == FAKE_SRC_DATA_SUBBUFFER) {
488 gst_fake_src_alloc_parent (src);
491 gst_buffer_unref (src->parent);
497 src->sizetype = g_value_get_enum (value);
500 src->sizemin = g_value_get_int (value);
503 src->sizemax = g_value_get_int (value);
505 case PROP_PARENTSIZE:
506 src->parentsize = g_value_get_int (value);
509 src->filltype = g_value_get_enum (value);
512 src->datarate = g_value_get_int (value);
515 src->sync = g_value_get_boolean (value);
520 src->silent = g_value_get_boolean (value);
522 case PROP_SIGNAL_HANDOFFS:
523 src->signal_handoffs = g_value_get_boolean (value);
526 src->dump = g_value_get_boolean (value);
528 case PROP_CAN_ACTIVATE_PUSH:
529 g_return_if_fail (!GST_OBJECT_FLAG_IS_SET (object,
530 GST_BASE_SRC_FLAG_STARTED));
531 GST_BASE_SRC (src)->can_activate_push = g_value_get_boolean (value);
533 case PROP_CAN_ACTIVATE_PULL:
534 g_return_if_fail (!GST_OBJECT_FLAG_IS_SET (object,
535 GST_BASE_SRC_FLAG_STARTED));
536 src->can_activate_pull = g_value_get_boolean (value);
539 gst_base_src_set_live (basesrc, g_value_get_boolean (value));
542 src->format = g_value_get_enum (value);
545 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
551 gst_fake_src_get_property (GObject * object, guint prop_id, GValue * value,
557 g_return_if_fail (GST_IS_FAKE_SRC (object));
559 src = GST_FAKE_SRC (object);
560 basesrc = GST_BASE_SRC (object);
564 g_value_set_enum (value, src->output);
567 g_value_set_enum (value, src->data);
570 g_value_set_enum (value, src->sizetype);
573 g_value_set_int (value, src->sizemin);
576 g_value_set_int (value, src->sizemax);
578 case PROP_PARENTSIZE:
579 g_value_set_int (value, src->parentsize);
582 g_value_set_enum (value, src->filltype);
585 g_value_set_int (value, src->datarate);
588 g_value_set_boolean (value, src->sync);
591 g_value_set_string (value, src->pattern);
594 g_value_set_boolean (value, src->silent);
596 case PROP_SIGNAL_HANDOFFS:
597 g_value_set_boolean (value, src->signal_handoffs);
600 g_value_set_boolean (value, src->dump);
602 case PROP_LAST_MESSAGE:
603 GST_OBJECT_LOCK (src);
604 g_value_set_string (value, src->last_message);
605 GST_OBJECT_UNLOCK (src);
607 case PROP_CAN_ACTIVATE_PUSH:
608 g_value_set_boolean (value, GST_BASE_SRC (src)->can_activate_push);
610 case PROP_CAN_ACTIVATE_PULL:
611 g_value_set_boolean (value, src->can_activate_pull);
614 g_value_set_boolean (value, gst_base_src_is_live (basesrc));
617 g_value_set_enum (value, src->format);
620 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
626 gst_fake_src_prepare_buffer (GstFakeSrc * src, guint8 * data, gsize size)
631 switch (src->filltype) {
632 case FAKE_SRC_FILLTYPE_ZERO:
633 memset (data, 0, size);
635 case FAKE_SRC_FILLTYPE_RANDOM:
640 for (i = size; i; i--) {
641 *ptr++ = g_random_int_range (0, 256);
645 case FAKE_SRC_FILLTYPE_PATTERN:
646 src->pattern_byte = 0x00;
647 case FAKE_SRC_FILLTYPE_PATTERN_CONT:
652 for (i = size; i; i--) {
653 *ptr++ = src->pattern_byte++;
657 case FAKE_SRC_FILLTYPE_NOTHING:
664 gst_fake_src_alloc_buffer (GstFakeSrc * src, guint size)
668 gboolean do_prepare = FALSE;
670 buf = gst_buffer_new ();
673 switch (src->filltype) {
674 case FAKE_SRC_FILLTYPE_NOTHING:
675 data = g_malloc (size);
677 case FAKE_SRC_FILLTYPE_ZERO:
678 data = g_malloc0 (size);
680 case FAKE_SRC_FILLTYPE_RANDOM:
681 case FAKE_SRC_FILLTYPE_PATTERN:
682 case FAKE_SRC_FILLTYPE_PATTERN_CONT:
684 data = g_malloc (size);
689 gst_fake_src_prepare_buffer (src, data, size);
691 gst_buffer_take_memory (buf, -1,
692 gst_memory_new_wrapped (0, data, g_free, size, 0, size));
699 gst_fake_src_get_size (GstFakeSrc * src)
703 switch (src->sizetype) {
704 case FAKE_SRC_SIZETYPE_FIXED:
707 case FAKE_SRC_SIZETYPE_RANDOM:
708 size = g_random_int_range (src->sizemin, src->sizemax);
710 case FAKE_SRC_SIZETYPE_EMPTY:
720 gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize)
723 gsize size = gst_fake_src_get_size (src);
724 gboolean dump = src->dump;
730 case FAKE_SRC_DATA_ALLOCATE:
731 buf = gst_fake_src_alloc_buffer (src, size);
733 case FAKE_SRC_DATA_SUBBUFFER:
734 /* see if we have a parent to subbuffer */
736 gst_fake_src_alloc_parent (src);
737 g_assert (src->parent);
739 /* see if it's large enough */
740 if ((src->parentsize - src->parentoffset) >= size) {
742 gst_buffer_copy_region (src->parent, GST_BUFFER_COPY_ALL,
743 src->parentoffset, size);
744 src->parentoffset += size;
746 /* the parent is useless now */
747 gst_buffer_unref (src->parent);
749 /* try again (this will allocate a new parent) */
750 return gst_fake_src_create_buffer (src, bufsize);
752 data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE);
753 gst_fake_src_prepare_buffer (src, data, size);
754 gst_buffer_unmap (buf, data, size);
757 g_warning ("fakesrc: dunno how to allocate buffers !");
758 buf = gst_buffer_new ();
762 data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
763 gst_util_dump_mem (data, size);
764 gst_buffer_unmap (buf, data, size);
771 gst_fake_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
772 GstClockTime * start, GstClockTime * end)
776 src = GST_FAKE_SRC (basesrc);
778 /* sync on the timestamp of the buffer if requested. */
780 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
782 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
783 /* get duration to calculate end time */
784 GstClockTime duration = GST_BUFFER_DURATION (buffer);
786 if (GST_CLOCK_TIME_IS_VALID (duration)) {
787 *end = timestamp + duration;
798 gst_fake_src_create (GstBaseSrc * basesrc, guint64 offset, guint length,
806 src = GST_FAKE_SRC (basesrc);
808 buf = gst_fake_src_create_buffer (src, &size);
809 GST_BUFFER_OFFSET (buf) = src->buffer_count++;
811 if (src->datarate > 0) {
812 time = (src->bytes_sent * GST_SECOND) / src->datarate;
814 GST_BUFFER_DURATION (buf) = size * GST_SECOND / src->datarate;
815 } else if (gst_base_src_is_live (basesrc)) {
818 clock = gst_element_get_clock (GST_ELEMENT (src));
821 time = gst_clock_get_time (clock);
822 time -= gst_element_get_base_time (GST_ELEMENT (src));
823 gst_object_unref (clock);
825 /* not an error not to have a clock */
826 time = GST_CLOCK_TIME_NONE;
829 time = GST_CLOCK_TIME_NONE;
832 GST_BUFFER_TIMESTAMP (buf) = time;
835 gchar ts_str[64], dur_str[64];
837 GST_OBJECT_LOCK (src);
838 g_free (src->last_message);
840 if (GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE) {
841 g_snprintf (ts_str, sizeof (ts_str), "%" GST_TIME_FORMAT,
842 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
844 g_strlcpy (ts_str, "none", sizeof (ts_str));
847 if (GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE) {
848 g_snprintf (dur_str, sizeof (dur_str), "%" GST_TIME_FORMAT,
849 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
851 g_strlcpy (dur_str, "none", sizeof (dur_str));
855 g_strdup_printf ("get ******* > (%5d bytes, timestamp: %s"
856 ", duration: %s, offset: %" G_GINT64_FORMAT ", offset_end: %"
857 G_GINT64_FORMAT ", flags: %d) %p", (gint) size, ts_str,
858 dur_str, GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
859 GST_MINI_OBJECT_CAST (buf)->flags, buf);
860 GST_OBJECT_UNLOCK (src);
862 #if !GLIB_CHECK_VERSION(2,26,0)
863 g_object_notify ((GObject *) src, "last-message");
865 g_object_notify_by_pspec ((GObject *) src, pspec_last_message);
869 if (src->signal_handoffs) {
870 GST_LOG_OBJECT (src, "pre handoff emit");
871 g_signal_emit (src, gst_fake_src_signals[SIGNAL_HANDOFF], 0, buf,
873 GST_LOG_OBJECT (src, "post handoff emit");
876 src->bytes_sent += size;
883 gst_fake_src_start (GstBaseSrc * basesrc)
887 src = GST_FAKE_SRC (basesrc);
889 src->buffer_count = 0;
890 src->pattern_byte = 0x00;
893 gst_base_src_set_format (basesrc, src->format);
899 gst_fake_src_stop (GstBaseSrc * basesrc)
903 src = GST_FAKE_SRC (basesrc);
905 GST_OBJECT_LOCK (src);
907 gst_buffer_unref (src->parent);
910 g_free (src->last_message);
911 src->last_message = NULL;
912 GST_OBJECT_UNLOCK (src);
918 gst_fake_src_is_seekable (GstBaseSrc * basesrc)
920 GstFakeSrc *src = GST_FAKE_SRC (basesrc);
922 return src->can_activate_pull;