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.
31 #include "gstfakesrc.h"
32 #include <gst/gstmarshal.h>
34 #define DEFAULT_SIZEMIN 0
35 #define DEFAULT_SIZEMAX 4096
36 #define DEFAULT_PARENTSIZE 4096*10
37 #define DEFAULT_DATARATE 0
38 #define DEFAULT_SYNC FALSE
40 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
45 GST_DEBUG_CATEGORY_STATIC (gst_fakesrc_debug);
46 #define GST_CAT_DEFAULT gst_fakesrc_debug
48 GstElementDetails gst_fakesrc_details = GST_ELEMENT_DETAILS ("Fake Source",
50 "Push empty (no data) buffers around",
51 "Erik Walthinsen <omega@cse.ogi.edu>, "
52 "Wim Taymans <wim.taymans@chello.be>");
55 /* FakeSrc signals and args */
86 GstStaticPadTemplate fakesrc_src_template = GST_STATIC_PAD_TEMPLATE ("src%d",
91 #define GST_TYPE_FAKESRC_OUTPUT (gst_fakesrc_output_get_type())
93 gst_fakesrc_output_get_type (void)
95 static GType fakesrc_output_type = 0;
96 static GEnumValue fakesrc_output[] = {
97 {FAKESRC_FIRST_LAST_LOOP, "1", "First-Last loop"},
98 {FAKESRC_LAST_FIRST_LOOP, "2", "Last-First loop"},
99 {FAKESRC_PING_PONG, "3", "Ping-Pong"},
100 {FAKESRC_ORDERED_RANDOM, "4", "Ordered Random"},
101 {FAKESRC_RANDOM, "5", "Random"},
102 {FAKESRC_PATTERN_LOOP, "6", "Patttern loop"},
103 {FAKESRC_PING_PONG_PATTERN, "7", "Ping-Pong Pattern"},
104 {FAKESRC_GET_ALWAYS_SUCEEDS, "8", "'_get' Always succeeds"},
108 if (!fakesrc_output_type) {
109 fakesrc_output_type =
110 g_enum_register_static ("GstFakeSrcOutput", fakesrc_output);
112 return fakesrc_output_type;
115 #define GST_TYPE_FAKESRC_DATA (gst_fakesrc_data_get_type())
117 gst_fakesrc_data_get_type (void)
119 static GType fakesrc_data_type = 0;
120 static GEnumValue fakesrc_data[] = {
121 {FAKESRC_DATA_ALLOCATE, "1", "Allocate data"},
122 {FAKESRC_DATA_SUBBUFFER, "2", "Subbuffer data"},
126 if (!fakesrc_data_type) {
127 fakesrc_data_type = g_enum_register_static ("GstFakeSrcData", fakesrc_data);
129 return fakesrc_data_type;
132 #define GST_TYPE_FAKESRC_SIZETYPE (gst_fakesrc_sizetype_get_type())
134 gst_fakesrc_sizetype_get_type (void)
136 static GType fakesrc_sizetype_type = 0;
137 static GEnumValue fakesrc_sizetype[] = {
138 {FAKESRC_SIZETYPE_NULL, "1", "Send empty buffers"},
139 {FAKESRC_SIZETYPE_FIXED, "2", "Fixed size buffers (sizemax sized)"},
140 {FAKESRC_SIZETYPE_RANDOM, "3",
141 "Random sized buffers (sizemin <= size <= sizemax)"},
145 if (!fakesrc_sizetype_type) {
146 fakesrc_sizetype_type =
147 g_enum_register_static ("GstFakeSrcSizeType", fakesrc_sizetype);
149 return fakesrc_sizetype_type;
152 #define GST_TYPE_FAKESRC_FILLTYPE (gst_fakesrc_filltype_get_type())
154 gst_fakesrc_filltype_get_type (void)
156 static GType fakesrc_filltype_type = 0;
157 static GEnumValue fakesrc_filltype[] = {
158 {FAKESRC_FILLTYPE_NOTHING, "1", "Leave data as malloced"},
159 {FAKESRC_FILLTYPE_NULL, "2", "Fill buffers with zeros"},
160 {FAKESRC_FILLTYPE_RANDOM, "3", "Fill buffers with random crap"},
161 {FAKESRC_FILLTYPE_PATTERN, "4", "Fill buffers with pattern 0x00 -> 0xff"},
162 {FAKESRC_FILLTYPE_PATTERN_CONT, "5",
163 "Fill buffers with pattern 0x00 -> 0xff that spans buffers"},
167 if (!fakesrc_filltype_type) {
168 fakesrc_filltype_type =
169 g_enum_register_static ("GstFakeSrcFillType", fakesrc_filltype);
171 return fakesrc_filltype_type;
174 #define _do_init(bla) \
175 GST_DEBUG_CATEGORY_INIT (gst_fakesrc_debug, "fakesrc", 0, "fakesrc element");
177 GST_BOILERPLATE_FULL (GstFakeSrc, gst_fakesrc, GstElement, GST_TYPE_ELEMENT,
180 static GstPad *gst_fakesrc_request_new_pad (GstElement * element,
181 GstPadTemplate * templ, const gchar * unused);
182 static void gst_fakesrc_update_functions (GstFakeSrc * src);
183 static void gst_fakesrc_set_property (GObject * object, guint prop_id,
184 const GValue * value, GParamSpec * pspec);
185 static void gst_fakesrc_get_property (GObject * object, guint prop_id,
186 GValue * value, GParamSpec * pspec);
187 static void gst_fakesrc_set_clock (GstElement * element, GstClock * clock);
189 static GstElementStateReturn gst_fakesrc_change_state (GstElement * element);
191 static GstData *gst_fakesrc_get (GstPad * pad);
192 static void gst_fakesrc_loop (GstElement * element);
194 static guint gst_fakesrc_signals[LAST_SIGNAL] = { 0 };
197 gst_fakesrc_base_init (gpointer g_class)
199 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
201 gst_element_class_add_pad_template (gstelement_class,
202 gst_static_pad_template_get (&srctemplate));
203 gst_element_class_set_details (gstelement_class, &gst_fakesrc_details);
204 gst_element_class_add_pad_template (gstelement_class,
205 gst_static_pad_template_get (&fakesrc_src_template));
209 gst_fakesrc_class_init (GstFakeSrcClass * klass)
211 GObjectClass *gobject_class;
212 GstElementClass *gstelement_class;
214 gobject_class = (GObjectClass *) klass;
215 gstelement_class = (GstElementClass *) klass;
218 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_SOURCES,
219 g_param_spec_int ("num-sources", "num-sources", "Number of sources",
220 1, G_MAXINT, 1, G_PARAM_READABLE));
221 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOOP_BASED,
222 g_param_spec_boolean ("loop-based", "loop-based",
223 "Enable loop-based operation", FALSE, G_PARAM_READWRITE));
224 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_OUTPUT,
225 g_param_spec_enum ("output", "output", "Output method (currently unused)",
226 GST_TYPE_FAKESRC_OUTPUT, FAKESRC_FIRST_LAST_LOOP, G_PARAM_READWRITE));
227 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DATA,
228 g_param_spec_enum ("data", "data", "Data allocation method",
229 GST_TYPE_FAKESRC_DATA, FAKESRC_DATA_ALLOCATE, G_PARAM_READWRITE));
230 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZETYPE,
231 g_param_spec_enum ("sizetype", "sizetype",
232 "How to determine buffer sizes", GST_TYPE_FAKESRC_SIZETYPE,
233 FAKESRC_SIZETYPE_NULL, G_PARAM_READWRITE));
234 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMIN,
235 g_param_spec_int ("sizemin", "sizemin", "Minimum buffer size", 0,
236 G_MAXINT, DEFAULT_SIZEMIN, G_PARAM_READWRITE));
237 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMAX,
238 g_param_spec_int ("sizemax", "sizemax", "Maximum buffer size", 0,
239 G_MAXINT, DEFAULT_SIZEMAX, G_PARAM_READWRITE));
240 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PARENTSIZE,
241 g_param_spec_int ("parentsize", "parentsize",
242 "Size of parent buffer for sub-buffered allocation", 0, G_MAXINT,
243 DEFAULT_PARENTSIZE, G_PARAM_READWRITE));
244 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FILLTYPE,
245 g_param_spec_enum ("filltype", "filltype",
246 "How to fill the buffer, if at all", GST_TYPE_FAKESRC_FILLTYPE,
247 FAKESRC_FILLTYPE_NULL, G_PARAM_READWRITE));
248 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DATARATE,
249 g_param_spec_int ("datarate", "Datarate",
250 "Timestamps buffers with number of bytes per second (0 = none)", 0,
251 G_MAXINT, DEFAULT_DATARATE, G_PARAM_READWRITE));
252 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SYNC,
253 g_param_spec_boolean ("sync", "Sync", "Sync to the clock to the datarate",
254 DEFAULT_SYNC, G_PARAM_READWRITE));
255 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PATTERN,
256 g_param_spec_string ("pattern", "pattern", "pattern", NULL,
258 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_BUFFERS,
259 g_param_spec_int ("num-buffers", "num-buffers",
260 "Number of buffers to output before sending EOS", -1, G_MAXINT, 0,
262 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EOS,
263 g_param_spec_boolean ("eos", "eos", "Send out the EOS event?", TRUE,
265 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
266 g_param_spec_string ("last-message", "last-message",
267 "The last status message", NULL, G_PARAM_READABLE));
268 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
269 g_param_spec_boolean ("silent", "Silent",
270 "Don't produce last_message events", FALSE, G_PARAM_READWRITE));
271 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIGNAL_HANDOFFS,
272 g_param_spec_boolean ("signal-handoffs", "Signal handoffs",
273 "Send a signal before pushing the buffer", FALSE, G_PARAM_READWRITE));
274 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DUMP,
275 g_param_spec_boolean ("dump", "Dump", "Dump produced bytes to stdout",
276 FALSE, G_PARAM_READWRITE));
278 gst_fakesrc_signals[SIGNAL_HANDOFF] =
279 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
280 G_STRUCT_OFFSET (GstFakeSrcClass, handoff), NULL, NULL,
281 gst_marshal_VOID__BOXED_OBJECT, G_TYPE_NONE, 2,
282 GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE, GST_TYPE_PAD);
284 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesrc_set_property);
285 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesrc_get_property);
287 gstelement_class->request_new_pad =
288 GST_DEBUG_FUNCPTR (gst_fakesrc_request_new_pad);
289 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_fakesrc_change_state);
290 gstelement_class->set_clock = GST_DEBUG_FUNCPTR (gst_fakesrc_set_clock);
294 gst_fakesrc_init (GstFakeSrc * fakesrc)
298 /* create our first output pad */
300 gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate),
302 gst_element_add_pad (GST_ELEMENT (fakesrc), pad);
304 fakesrc->loop_based = FALSE;
305 gst_fakesrc_update_functions (fakesrc);
307 fakesrc->output = FAKESRC_FIRST_LAST_LOOP;
308 fakesrc->segment_start = -1;
309 fakesrc->segment_end = -1;
310 fakesrc->num_buffers = -1;
311 fakesrc->rt_num_buffers = -1;
312 fakesrc->buffer_count = 0;
313 fakesrc->silent = FALSE;
314 fakesrc->signal_handoffs = FALSE;
315 fakesrc->dump = FALSE;
316 fakesrc->pattern_byte = 0x00;
317 fakesrc->need_flush = FALSE;
318 fakesrc->data = FAKESRC_DATA_ALLOCATE;
319 fakesrc->sizetype = FAKESRC_SIZETYPE_NULL;
320 fakesrc->filltype = FAKESRC_FILLTYPE_NOTHING;
321 fakesrc->sizemin = DEFAULT_SIZEMIN;
322 fakesrc->sizemax = DEFAULT_SIZEMAX;
323 fakesrc->parent = NULL;
324 fakesrc->parentsize = DEFAULT_PARENTSIZE;
325 fakesrc->last_message = NULL;
326 fakesrc->datarate = DEFAULT_DATARATE;
327 fakesrc->sync = DEFAULT_SYNC;
331 gst_fakesrc_set_clock (GstElement * element, GstClock * clock)
335 src = GST_FAKESRC (element);
342 gst_fakesrc_request_new_pad (GstElement * element, GstPadTemplate * templ,
343 const gchar * unused)
349 g_return_val_if_fail (GST_IS_FAKESRC (element), NULL);
351 if (templ->direction != GST_PAD_SRC) {
352 g_warning ("gstfakesrc: request new pad that is not a SRC pad\n");
356 fakesrc = GST_FAKESRC (element);
358 name = g_strdup_printf ("src%d", GST_ELEMENT (fakesrc)->numsrcpads);
360 srcpad = gst_pad_new_from_template (templ, name);
361 gst_element_add_pad (GST_ELEMENT (fakesrc), srcpad);
362 gst_fakesrc_update_functions (fakesrc);
369 static const GstFormat *
370 gst_fakesrc_get_formats (GstPad * pad)
372 static const GstFormat formats[] = {
380 static const GstQueryType *
381 gst_fakesrc_get_query_types (GstPad * pad)
383 static const GstQueryType types[] = {
387 GST_QUERY_SEGMENT_END,
395 gst_fakesrc_query (GstPad * pad, GstQueryType type,
396 GstFormat * format, gint64 * value)
398 GstFakeSrc *src = GST_FAKESRC (GST_PAD_PARENT (pad));
401 case GST_QUERY_TOTAL:
402 *value = src->num_buffers;
404 case GST_QUERY_POSITION:
405 *value = src->buffer_count;
407 case GST_QUERY_START:
408 *value = src->segment_start;
410 case GST_QUERY_SEGMENT_END:
411 *value = src->segment_end;
419 static const GstEventMask *
420 gst_fakesrc_get_event_mask (GstPad * pad)
422 static const GstEventMask masks[] = {
423 {GST_EVENT_SEEK, GST_SEEK_FLAG_FLUSH},
424 {GST_EVENT_SEEK_SEGMENT, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SEGMENT_LOOP},
425 {GST_EVENT_FLUSH, 0},
433 gst_fakesrc_event_handler (GstPad * pad, GstEvent * event)
437 src = GST_FAKESRC (gst_pad_get_parent (pad));
439 switch (GST_EVENT_TYPE (event)) {
441 src->buffer_count = GST_EVENT_SEEK_OFFSET (event);
443 if (!GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH) {
446 /* else we do a flush too */
447 case GST_EVENT_SEEK_SEGMENT:
448 src->segment_start = GST_EVENT_SEEK_OFFSET (event);
449 src->segment_end = GST_EVENT_SEEK_ENDOFFSET (event);
450 src->buffer_count = src->segment_start;
452 GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_SEGMENT_LOOP;
454 case GST_EVENT_FLUSH:
455 src->need_flush = TRUE;
460 gst_event_unref (event);
466 gst_fakesrc_update_functions (GstFakeSrc * src)
470 if (src->loop_based) {
471 gst_element_set_loop_function (GST_ELEMENT (src),
472 GST_DEBUG_FUNCPTR (gst_fakesrc_loop));
474 gst_element_set_loop_function (GST_ELEMENT (src), NULL);
477 pads = GST_ELEMENT (src)->pads;
479 GstPad *pad = GST_PAD (pads->data);
481 if (src->loop_based) {
482 gst_pad_set_get_function (pad, NULL);
484 gst_pad_set_get_function (pad, GST_DEBUG_FUNCPTR (gst_fakesrc_get));
487 gst_pad_set_event_function (pad, gst_fakesrc_event_handler);
488 gst_pad_set_event_mask_function (pad, gst_fakesrc_get_event_mask);
489 gst_pad_set_query_function (pad, gst_fakesrc_query);
490 gst_pad_set_query_type_function (pad, gst_fakesrc_get_query_types);
491 gst_pad_set_formats_function (pad, gst_fakesrc_get_formats);
492 pads = g_list_next (pads);
497 gst_fakesrc_alloc_parent (GstFakeSrc * src)
501 buf = gst_buffer_new ();
502 GST_BUFFER_DATA (buf) = g_malloc (src->parentsize);
503 GST_BUFFER_SIZE (buf) = src->parentsize;
506 src->parentoffset = 0;
510 gst_fakesrc_set_property (GObject * object, guint prop_id, const GValue * value,
515 /* it's not null if we got it, but it might not be ours */
516 src = GST_FAKESRC (object);
520 src->loop_based = g_value_get_boolean (value);
521 gst_fakesrc_update_functions (src);
524 g_warning ("not yet implemented");
527 src->data = g_value_get_enum (value);
529 if (src->data == FAKESRC_DATA_SUBBUFFER) {
531 gst_fakesrc_alloc_parent (src);
534 gst_buffer_unref (src->parent);
540 src->sizetype = g_value_get_enum (value);
543 src->sizemin = g_value_get_int (value);
546 src->sizemax = g_value_get_int (value);
549 src->parentsize = g_value_get_int (value);
552 src->filltype = g_value_get_enum (value);
555 src->datarate = g_value_get_int (value);
558 src->sync = g_value_get_boolean (value);
562 case ARG_NUM_BUFFERS:
563 src->num_buffers = g_value_get_int (value);
566 src->eos = g_value_get_boolean (value);
567 GST_INFO ("will EOS on next buffer");
570 src->silent = g_value_get_boolean (value);
572 case ARG_SIGNAL_HANDOFFS:
573 src->signal_handoffs = g_value_get_boolean (value);
576 src->dump = g_value_get_boolean (value);
579 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
585 gst_fakesrc_get_property (GObject * object, guint prop_id, GValue * value,
590 /* it's not null if we got it, but it might not be ours */
591 g_return_if_fail (GST_IS_FAKESRC (object));
593 src = GST_FAKESRC (object);
596 case ARG_NUM_SOURCES:
597 g_value_set_int (value, GST_ELEMENT (src)->numsrcpads);
600 g_value_set_boolean (value, src->loop_based);
603 g_value_set_enum (value, src->output);
606 g_value_set_enum (value, src->data);
609 g_value_set_enum (value, src->sizetype);
612 g_value_set_int (value, src->sizemin);
615 g_value_set_int (value, src->sizemax);
618 g_value_set_int (value, src->parentsize);
621 g_value_set_enum (value, src->filltype);
624 g_value_set_int (value, src->datarate);
627 g_value_set_boolean (value, src->sync);
630 g_value_set_string (value, src->pattern);
632 case ARG_NUM_BUFFERS:
633 g_value_set_int (value, src->num_buffers);
636 g_value_set_boolean (value, src->eos);
639 g_value_set_boolean (value, src->silent);
641 case ARG_SIGNAL_HANDOFFS:
642 g_value_set_boolean (value, src->signal_handoffs);
645 g_value_set_boolean (value, src->dump);
647 case ARG_LAST_MESSAGE:
648 g_value_set_string (value, src->last_message);
651 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
657 gst_fakesrc_prepare_buffer (GstFakeSrc * src, GstBuffer * buf)
659 if (GST_BUFFER_SIZE (buf) == 0)
662 switch (src->filltype) {
663 case FAKESRC_FILLTYPE_NULL:
664 memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf));
666 case FAKESRC_FILLTYPE_RANDOM:
669 guint8 *ptr = GST_BUFFER_DATA (buf);
671 for (i = GST_BUFFER_SIZE (buf); i; i--) {
672 *ptr++ = (gint8) ((255.0) * rand () / (RAND_MAX));
676 case FAKESRC_FILLTYPE_PATTERN:
677 src->pattern_byte = 0x00;
678 case FAKESRC_FILLTYPE_PATTERN_CONT:
681 guint8 *ptr = GST_BUFFER_DATA (buf);
683 for (i = GST_BUFFER_SIZE (buf); i; i--) {
684 *ptr++ = src->pattern_byte++;
688 case FAKESRC_FILLTYPE_NOTHING:
695 gst_fakesrc_alloc_buffer (GstFakeSrc * src, guint size)
699 buf = gst_buffer_new ();
700 GST_BUFFER_SIZE (buf) = size;
703 switch (src->filltype) {
704 case FAKESRC_FILLTYPE_NOTHING:
705 GST_BUFFER_DATA (buf) = g_malloc (size);
707 case FAKESRC_FILLTYPE_NULL:
708 GST_BUFFER_DATA (buf) = g_malloc0 (size);
710 case FAKESRC_FILLTYPE_RANDOM:
711 case FAKESRC_FILLTYPE_PATTERN:
712 case FAKESRC_FILLTYPE_PATTERN_CONT:
714 GST_BUFFER_DATA (buf) = g_malloc (size);
715 gst_fakesrc_prepare_buffer (src, buf);
724 gst_fakesrc_get_size (GstFakeSrc * src)
728 switch (src->sizetype) {
729 case FAKESRC_SIZETYPE_FIXED:
732 case FAKESRC_SIZETYPE_RANDOM:
735 (guint8) (((gfloat) src->sizemax) * rand () / (RAND_MAX +
736 (gfloat) src->sizemin));
738 case FAKESRC_SIZETYPE_NULL:
748 gst_fakesrc_create_buffer (GstFakeSrc * src)
752 gboolean dump = src->dump;
754 size = gst_fakesrc_get_size (src);
756 return gst_buffer_new ();
759 case FAKESRC_DATA_ALLOCATE:
760 buf = gst_fakesrc_alloc_buffer (src, size);
762 case FAKESRC_DATA_SUBBUFFER:
763 /* see if we have a parent to subbuffer */
765 gst_fakesrc_alloc_parent (src);
766 g_assert (src->parent);
768 /* see if it's large enough */
769 if ((GST_BUFFER_SIZE (src->parent) - src->parentoffset) >= size) {
770 buf = gst_buffer_create_sub (src->parent, src->parentoffset, size);
771 src->parentoffset += size;
773 /* the parent is useless now */
774 gst_buffer_unref (src->parent);
776 /* try again (this will allocate a new parent) */
777 return gst_fakesrc_create_buffer (src);
779 gst_fakesrc_prepare_buffer (src, buf);
782 g_warning ("fakesrc: dunno how to allocate buffers !");
783 buf = gst_buffer_new ();
787 gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
794 gst_fakesrc_get (GstPad * pad)
800 g_return_val_if_fail (pad != NULL, NULL);
802 src = GST_FAKESRC (GST_OBJECT_PARENT (pad));
804 g_return_val_if_fail (GST_IS_FAKESRC (src), NULL);
806 if (src->need_flush) {
807 src->need_flush = FALSE;
808 return GST_DATA (gst_event_new (GST_EVENT_FLUSH));
811 if (src->buffer_count == src->segment_end) {
812 if (src->segment_loop) {
813 return GST_DATA (gst_event_new (GST_EVENT_SEGMENT_DONE));
815 gst_element_set_eos (GST_ELEMENT (src));
816 return GST_DATA (gst_event_new (GST_EVENT_EOS));
820 if (src->rt_num_buffers == 0) {
821 gst_element_set_eos (GST_ELEMENT (src));
822 return GST_DATA (gst_event_new (GST_EVENT_EOS));
824 if (src->rt_num_buffers > 0)
825 src->rt_num_buffers--;
829 GST_INFO ("fakesrc is setting eos on pad");
830 gst_element_set_eos (GST_ELEMENT (src));
831 return GST_DATA (gst_event_new (GST_EVENT_EOS));
834 buf = gst_fakesrc_create_buffer (src);
835 GST_BUFFER_OFFSET (buf) = src->buffer_count++;
837 time = GST_CLOCK_TIME_NONE;
839 if (src->datarate > 0) {
840 time = (src->bytes_sent * GST_SECOND) / src->datarate;
842 gst_element_wait (GST_ELEMENT (src), time);
845 GST_BUFFER_DURATION (buf) =
846 GST_BUFFER_SIZE (buf) * GST_SECOND / src->datarate;
848 GST_BUFFER_TIMESTAMP (buf) = time;
851 g_free (src->last_message);
854 g_strdup_printf ("get ******* (%s:%s)> (%d bytes, %"
855 G_GUINT64_FORMAT " ) %p", GST_DEBUG_PAD_NAME (pad),
856 GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf), buf);
858 g_object_notify (G_OBJECT (src), "last_message");
861 if (src->signal_handoffs) {
862 GST_LOG_OBJECT (src, "pre handoff emit");
863 g_signal_emit (G_OBJECT (src), gst_fakesrc_signals[SIGNAL_HANDOFF], 0,
865 GST_LOG_OBJECT (src, "post handoff emit");
868 src->bytes_sent += GST_BUFFER_SIZE (buf);
870 return GST_DATA (buf);
875 * @element: the faksesrc to loop
877 * generate an empty buffer and push it to the next element.
880 gst_fakesrc_loop (GstElement * element)
885 g_return_if_fail (element != NULL);
886 g_return_if_fail (GST_IS_FAKESRC (element));
888 src = GST_FAKESRC (element);
890 pads = element->pads;
893 GstPad *pad = GST_PAD (pads->data);
896 data = gst_fakesrc_get (pad);
897 gst_pad_push (pad, data);
903 pads = g_list_next (pads);
907 static GstElementStateReturn
908 gst_fakesrc_change_state (GstElement * element)
912 g_return_val_if_fail (GST_IS_FAKESRC (element), GST_STATE_FAILURE);
914 fakesrc = GST_FAKESRC (element);
916 switch (GST_STATE_TRANSITION (element)) {
917 case GST_STATE_NULL_TO_READY:
919 case GST_STATE_READY_TO_PAUSED:
920 fakesrc->buffer_count = 0;
921 fakesrc->pattern_byte = 0x00;
922 fakesrc->need_flush = FALSE;
923 fakesrc->eos = FALSE;
924 fakesrc->bytes_sent = 0;
925 fakesrc->rt_num_buffers = fakesrc->num_buffers;
927 case GST_STATE_PAUSED_TO_PLAYING:
928 case GST_STATE_PLAYING_TO_PAUSED:
930 case GST_STATE_PAUSED_TO_READY:
931 if (fakesrc->parent) {
932 gst_buffer_unref (fakesrc->parent);
933 fakesrc->parent = NULL;
935 g_free (fakesrc->last_message);
936 fakesrc->last_message = NULL;
938 case GST_STATE_READY_TO_NULL:
944 if (GST_ELEMENT_CLASS (parent_class)->change_state)
945 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
947 return GST_STATE_SUCCESS;