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.
27 #include <gstfakesrc.h>
29 #define DEFAULT_SIZEMIN 0
30 #define DEFAULT_SIZEMAX 4096
31 #define DEFAULT_PARENTSIZE 4096*10
33 GstElementDetails gst_fakesrc_details = {
37 "Push empty (no data) buffers around",
39 "Erik Walthinsen <omega@cse.ogi.edu>\n"
40 "Wim Taymans <wim.taymans@chello.be>",
45 /* FakeSrc signals and args */
71 GST_PAD_TEMPLATE_FACTORY (fakesrc_src_factory,
78 #define GST_TYPE_FAKESRC_OUTPUT (gst_fakesrc_output_get_type())
80 gst_fakesrc_output_get_type (void)
82 static GType fakesrc_output_type = 0;
83 static GEnumValue fakesrc_output[] = {
84 { FAKESRC_FIRST_LAST_LOOP, "1", "First-Last loop"},
85 { FAKESRC_LAST_FIRST_LOOP, "2", "Last-First loop"},
86 { FAKESRC_PING_PONG, "3", "Ping-Pong"},
87 { FAKESRC_ORDERED_RANDOM, "4", "Ordered Random"},
88 { FAKESRC_RANDOM, "5", "Random"},
89 { FAKESRC_PATTERN_LOOP, "6", "Patttern loop"},
90 { FAKESRC_PING_PONG_PATTERN, "7", "Ping-Pong Pattern"},
91 { FAKESRC_GET_ALWAYS_SUCEEDS, "8", "'_get' Always succeeds"},
94 if (!fakesrc_output_type) {
95 fakesrc_output_type = g_enum_register_static ("GstFakeSrcOutput", fakesrc_output);
97 return fakesrc_output_type;
100 #define GST_TYPE_FAKESRC_DATA (gst_fakesrc_data_get_type())
102 gst_fakesrc_data_get_type (void)
104 static GType fakesrc_data_type = 0;
105 static GEnumValue fakesrc_data[] = {
106 { FAKESRC_DATA_ALLOCATE, "1", "Allocate data"},
107 { FAKESRC_DATA_SUBBUFFER, "2", "Subbuffer data"},
108 { FAKESRC_DATA_BUFFERPOOL, "3", "Use the default buffer pool (forces sizetype=2)"},
111 if (!fakesrc_data_type) {
112 fakesrc_data_type = g_enum_register_static ("GstFakeSrcData", fakesrc_data);
114 return fakesrc_data_type;
117 #define GST_TYPE_FAKESRC_SIZETYPE (gst_fakesrc_sizetype_get_type())
119 gst_fakesrc_sizetype_get_type (void)
121 static GType fakesrc_sizetype_type = 0;
122 static GEnumValue fakesrc_sizetype[] = {
123 { FAKESRC_SIZETYPE_NULL, "1", "Send empty buffers"},
124 { FAKESRC_SIZETYPE_FIXED, "2", "Fixed size buffers (sizemax sized)"},
125 { FAKESRC_SIZETYPE_RANDOM, "3", "Random sized buffers (sizemin <= size <= sizemax)"},
128 if (!fakesrc_sizetype_type) {
129 fakesrc_sizetype_type = g_enum_register_static ("GstFakeSrcSizeType", fakesrc_sizetype);
131 return fakesrc_sizetype_type;
134 #define GST_TYPE_FAKESRC_FILLTYPE (gst_fakesrc_filltype_get_type())
136 gst_fakesrc_filltype_get_type (void)
138 static GType fakesrc_filltype_type = 0;
139 static GEnumValue fakesrc_filltype[] = {
140 { FAKESRC_FILLTYPE_NOTHING, "1", "Leave data as malloced"},
141 { FAKESRC_FILLTYPE_NULL, "2", "Fill buffers with zeros"},
142 { FAKESRC_FILLTYPE_RANDOM, "3", "Fill buffers with random crap"},
143 { FAKESRC_FILLTYPE_PATTERN, "4", "Fill buffers with pattern 0x00 -> 0xff"},
144 { FAKESRC_FILLTYPE_PATTERN_CONT, "5", "Fill buffers with pattern 0x00 -> 0xff that spans buffers"},
147 if (!fakesrc_filltype_type) {
148 fakesrc_filltype_type = g_enum_register_static ("GstFakeSrcFillType", fakesrc_filltype);
150 return fakesrc_filltype_type;
153 static void gst_fakesrc_class_init (GstFakeSrcClass *klass);
154 static void gst_fakesrc_init (GstFakeSrc *fakesrc);
156 static GstPad* gst_fakesrc_request_new_pad (GstElement *element, GstPadTemplate *templ);
157 static void gst_fakesrc_update_functions (GstFakeSrc *src);
158 static void gst_fakesrc_set_property (GObject *object, guint prop_id,
159 const GValue *value, GParamSpec *pspec);
160 static void gst_fakesrc_get_property (GObject *object, guint prop_id,
161 GValue *value, GParamSpec *pspec);
163 static GstElementStateReturn gst_fakesrc_change_state (GstElement *element);
165 static GstBuffer* gst_fakesrc_get (GstPad *pad);
166 static void gst_fakesrc_loop (GstElement *element);
168 static GstElementClass *parent_class = NULL;
169 static guint gst_fakesrc_signals[LAST_SIGNAL] = { 0 };
172 gst_fakesrc_get_type (void)
174 static GType fakesrc_type = 0;
177 static const GTypeInfo fakesrc_info = {
178 sizeof(GstFakeSrcClass),
181 (GClassInitFunc)gst_fakesrc_class_init,
186 (GInstanceInitFunc)gst_fakesrc_init,
188 fakesrc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstFakeSrc", &fakesrc_info, 0);
194 gst_fakesrc_class_init (GstFakeSrcClass *klass)
196 GObjectClass *gobject_class;
197 GstElementClass *gstelement_class;
199 gobject_class = (GObjectClass*)klass;
200 gstelement_class = (GstElementClass*)klass;
202 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
204 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_SOURCES,
205 g_param_spec_int ("num-sources", "num-sources", "Number of sources",
206 1, G_MAXINT, 1, G_PARAM_READABLE));
207 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOOP_BASED,
208 g_param_spec_boolean ("loop-based", "loop-based", "Enable loop-based operation",
209 FALSE, G_PARAM_READWRITE));
210 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_OUTPUT,
211 g_param_spec_enum ("output", "output", "Output method (currently unused)",
212 GST_TYPE_FAKESRC_OUTPUT, FAKESRC_FIRST_LAST_LOOP, G_PARAM_READWRITE));
213 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DATA,
214 g_param_spec_enum ("data", "data", "Data allocation method",
215 GST_TYPE_FAKESRC_DATA, FAKESRC_DATA_ALLOCATE, G_PARAM_READWRITE));
216 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZETYPE,
217 g_param_spec_enum ("sizetype", "sizetype", "How to determine buffer sizes",
218 GST_TYPE_FAKESRC_SIZETYPE, FAKESRC_SIZETYPE_NULL, G_PARAM_READWRITE));
219 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMIN,
220 g_param_spec_int ("sizemin","sizemin","Minimum buffer size",
221 0, G_MAXINT, DEFAULT_SIZEMIN, G_PARAM_READWRITE));
222 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMAX,
223 g_param_spec_int ("sizemax","sizemax","Maximum buffer size",
224 0, G_MAXINT, DEFAULT_SIZEMAX, G_PARAM_READWRITE));
225 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PARENTSIZE,
226 g_param_spec_int ("parentsize","parentsize","Size of parent buffer for sub-buffered allocation",
227 0, G_MAXINT, DEFAULT_PARENTSIZE, G_PARAM_READWRITE));
228 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FILLTYPE,
229 g_param_spec_enum ("filltype", "filltype", "How to fill the buffer, if at all",
230 GST_TYPE_FAKESRC_FILLTYPE, FAKESRC_FILLTYPE_NULL, G_PARAM_READWRITE));
231 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PATTERN,
232 g_param_spec_string ("pattern", "pattern", "pattern",
233 NULL, G_PARAM_READWRITE));
234 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_BUFFERS,
235 g_param_spec_int ("num-buffers", "num-buffers", "Number of buffers to output before sending EOS",
236 G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
237 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EOS,
238 g_param_spec_boolean ("eos", "eos", "Send out the EOS event?",
239 TRUE, G_PARAM_READWRITE));
240 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
241 g_param_spec_string ("last-message", "last-message", "The last status message",
242 NULL, G_PARAM_READABLE));
243 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
244 g_param_spec_boolean ("silent", "Silent", "Don't produce last_message events",
245 FALSE, G_PARAM_READWRITE));
246 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DUMP,
247 g_param_spec_boolean ("dump", "Dump", "Dump produced bytes to stdout",
248 FALSE, G_PARAM_READWRITE));
250 gst_fakesrc_signals[SIGNAL_HANDOFF] =
251 g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
252 G_STRUCT_OFFSET (GstFakeSrcClass, handoff), NULL, NULL,
253 g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
256 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesrc_set_property);
257 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesrc_get_property);
259 gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR (gst_fakesrc_request_new_pad);
260 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_fakesrc_change_state);
264 gst_fakesrc_init (GstFakeSrc *fakesrc)
268 /* create our first output pad */
269 pad = gst_pad_new ("src", GST_PAD_SRC);
270 gst_element_add_pad (GST_ELEMENT (fakesrc), pad);
272 fakesrc->loop_based = FALSE;
273 gst_fakesrc_update_functions (fakesrc);
275 fakesrc->output = FAKESRC_FIRST_LAST_LOOP;
276 fakesrc->segment_start = -1;
277 fakesrc->segment_end = -1;
278 fakesrc->num_buffers = -1;
279 fakesrc->rt_num_buffers = -1;
280 fakesrc->buffer_count = 0;
281 fakesrc->silent = FALSE;
282 fakesrc->dump = FALSE;
283 fakesrc->pattern_byte = 0x00;
284 fakesrc->need_flush = FALSE;
285 fakesrc->data = FAKESRC_DATA_ALLOCATE;
286 fakesrc->sizetype = FAKESRC_SIZETYPE_NULL;
287 fakesrc->filltype = FAKESRC_FILLTYPE_NOTHING;
288 fakesrc->sizemin = DEFAULT_SIZEMIN;
289 fakesrc->sizemax = DEFAULT_SIZEMAX;
290 fakesrc->parent = NULL;
291 fakesrc->parentsize = DEFAULT_PARENTSIZE;
292 fakesrc->last_message = NULL;
296 gst_fakesrc_request_new_pad (GstElement *element, GstPadTemplate *templ)
302 g_return_val_if_fail (GST_IS_FAKESRC (element), NULL);
304 if (templ->direction != GST_PAD_SRC) {
305 g_warning ("gstfakesrc: request new pad that is not a SRC pad\n");
309 fakesrc = GST_FAKESRC (element);
311 name = g_strdup_printf ("src%d", GST_ELEMENT (fakesrc)->numsrcpads);
313 srcpad = gst_pad_new_from_template (templ, name);
314 gst_element_add_pad (GST_ELEMENT (fakesrc), srcpad);
315 gst_fakesrc_update_functions (fakesrc);
322 GST_PAD_FORMATS_FUNCTION (gst_fakesrc_get_formats,
326 GST_PAD_QUERY_TYPE_FUNCTION (gst_fakesrc_get_query_types,
330 GST_QUERY_SEGMENT_END
334 gst_fakesrc_query (GstPad *pad, GstQueryType type,
335 GstFormat *format, gint64 *value)
337 GstFakeSrc *src = GST_FAKESRC (GST_PAD_PARENT (pad));
340 case GST_QUERY_TOTAL:
341 *value = src->num_buffers;
343 case GST_QUERY_POSITION:
344 *value = src->buffer_count;
346 case GST_QUERY_START:
347 *value = src->segment_start;
349 case GST_QUERY_SEGMENT_END:
350 *value = src->segment_end;
358 GST_PAD_EVENT_MASK_FUNCTION (gst_fakesrc_get_event_mask,
359 { GST_EVENT_SEEK, GST_SEEK_FLAG_FLUSH },
360 { GST_EVENT_SEEK_SEGMENT, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SEGMENT_LOOP },
361 { GST_EVENT_FLUSH, 0 }
365 gst_fakesrc_event_handler (GstPad *pad, GstEvent *event)
369 src = GST_FAKESRC (gst_pad_get_parent (pad));
371 switch (GST_EVENT_TYPE (event)) {
373 src->buffer_count = GST_EVENT_SEEK_OFFSET (event);
375 if (!GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH) {
378 /* else we do a flush too */
379 case GST_EVENT_SEEK_SEGMENT:
380 src->segment_start = GST_EVENT_SEEK_OFFSET (event);
381 src->segment_end = GST_EVENT_SEEK_ENDOFFSET (event);
382 src->buffer_count = src->segment_start;
383 src->segment_loop = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_SEGMENT_LOOP;
385 case GST_EVENT_FLUSH:
386 src->need_flush = TRUE;
391 gst_event_unref (event);
397 gst_fakesrc_update_functions (GstFakeSrc *src)
401 if (src->loop_based) {
402 gst_element_set_loop_function (GST_ELEMENT (src), GST_DEBUG_FUNCPTR (gst_fakesrc_loop));
405 gst_element_set_loop_function (GST_ELEMENT (src), NULL);
408 pads = GST_ELEMENT (src)->pads;
410 GstPad *pad = GST_PAD (pads->data);
412 if (src->loop_based) {
413 gst_pad_set_get_function (pad, NULL);
416 gst_pad_set_get_function (pad, GST_DEBUG_FUNCPTR (gst_fakesrc_get));
419 gst_pad_set_event_function (pad, gst_fakesrc_event_handler);
420 gst_pad_set_event_mask_function (pad, gst_fakesrc_get_event_mask);
421 gst_pad_set_query_function (pad, gst_fakesrc_query);
422 gst_pad_set_query_type_function (pad, gst_fakesrc_get_query_types);
423 gst_pad_set_formats_function (pad, gst_fakesrc_get_formats);
424 pads = g_list_next (pads);
429 gst_fakesrc_alloc_parent (GstFakeSrc *src)
433 buf = gst_buffer_new ();
434 GST_BUFFER_DATA (buf) = g_malloc (src->parentsize);
435 GST_BUFFER_SIZE (buf) = src->parentsize;
438 src->parentoffset = 0;
442 gst_fakesrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
446 /* it's not null if we got it, but it might not be ours */
447 src = GST_FAKESRC (object);
451 src->loop_based = g_value_get_boolean (value);
452 gst_fakesrc_update_functions (src);
455 g_warning ("not yet implemented");
458 src->data = g_value_get_enum (value);
460 if (src->data == FAKESRC_DATA_SUBBUFFER) {
462 gst_fakesrc_alloc_parent (src);
465 gst_buffer_unref (src->parent);
470 if (src->data == FAKESRC_DATA_BUFFERPOOL) {
471 if (src->sizetype != FAKESRC_SIZETYPE_FIXED)
472 g_object_set (src, "sizetype", FAKESRC_SIZETYPE_FIXED, NULL);
475 src->pool = gst_buffer_pool_get_default (src->sizemax, 10);
478 gst_buffer_pool_free (src->pool);
484 src->sizetype = g_value_get_enum (value);
487 src->sizemin = g_value_get_int (value);
490 src->sizemax = g_value_get_int (value);
493 src->parentsize = g_value_get_int (value);
496 src->filltype = g_value_get_enum (value);
500 case ARG_NUM_BUFFERS:
501 src->num_buffers = g_value_get_int (value);
504 src->eos = g_value_get_boolean (value);
505 GST_INFO (0, "will EOS on next buffer");
508 src->silent = g_value_get_boolean (value);
511 src->dump = g_value_get_boolean (value);
519 gst_fakesrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
523 /* it's not null if we got it, but it might not be ours */
524 g_return_if_fail (GST_IS_FAKESRC (object));
526 src = GST_FAKESRC (object);
529 case ARG_NUM_SOURCES:
530 g_value_set_int (value, GST_ELEMENT (src)->numsrcpads);
533 g_value_set_boolean (value, src->loop_based);
536 g_value_set_enum (value, src->output);
539 g_value_set_enum (value, src->data);
542 g_value_set_enum (value, src->sizetype);
545 g_value_set_int (value, src->sizemin);
548 g_value_set_int (value, src->sizemax);
551 g_value_set_int (value, src->parentsize);
554 g_value_set_enum (value, src->filltype);
557 g_value_set_string (value, src->pattern);
559 case ARG_NUM_BUFFERS:
560 g_value_set_int (value, src->num_buffers);
563 g_value_set_boolean (value, src->eos);
566 g_value_set_boolean (value, src->silent);
569 g_value_set_boolean (value, src->dump);
571 case ARG_LAST_MESSAGE:
572 g_value_set_string (value, src->last_message);
575 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
581 gst_fakesrc_prepare_buffer (GstFakeSrc *src, GstBuffer *buf)
583 if (GST_BUFFER_SIZE (buf) == 0)
586 switch (src->filltype) {
587 case FAKESRC_FILLTYPE_NULL:
588 memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf));
590 case FAKESRC_FILLTYPE_RANDOM:
593 guint8 *ptr = GST_BUFFER_DATA (buf);
595 for (i = GST_BUFFER_SIZE (buf); i; i--) {
596 *ptr++ = (gint8)((255.0)*rand()/(RAND_MAX));
600 case FAKESRC_FILLTYPE_PATTERN:
601 src->pattern_byte = 0x00;
602 case FAKESRC_FILLTYPE_PATTERN_CONT:
605 guint8 *ptr = GST_BUFFER_DATA (buf);
607 for (i = GST_BUFFER_SIZE (buf); i; i--) {
608 *ptr++ = src->pattern_byte++;
612 case FAKESRC_FILLTYPE_NOTHING:
619 gst_fakesrc_alloc_buffer (GstFakeSrc *src, guint size)
623 buf = gst_buffer_new ();
624 GST_BUFFER_SIZE(buf) = size;
627 switch (src->filltype) {
628 case FAKESRC_FILLTYPE_NOTHING:
629 GST_BUFFER_DATA(buf) = g_malloc (size);
631 case FAKESRC_FILLTYPE_NULL:
632 GST_BUFFER_DATA(buf) = g_malloc0 (size);
634 case FAKESRC_FILLTYPE_RANDOM:
635 case FAKESRC_FILLTYPE_PATTERN:
636 case FAKESRC_FILLTYPE_PATTERN_CONT:
638 GST_BUFFER_DATA(buf) = g_malloc (size);
639 gst_fakesrc_prepare_buffer (src, buf);
648 gst_fakesrc_get_size (GstFakeSrc *src)
652 switch (src->sizetype) {
653 case FAKESRC_SIZETYPE_FIXED:
656 case FAKESRC_SIZETYPE_RANDOM:
657 size = src->sizemin + (guint8)(((gfloat)src->sizemax)*rand()/(RAND_MAX + (gfloat)src->sizemin));
659 case FAKESRC_SIZETYPE_NULL:
669 gst_fakesrc_create_buffer (GstFakeSrc *src)
673 gboolean dump = src->dump;
675 size = gst_fakesrc_get_size (src);
677 return gst_buffer_new();
680 case FAKESRC_DATA_ALLOCATE:
681 buf = gst_fakesrc_alloc_buffer (src, size);
683 case FAKESRC_DATA_SUBBUFFER:
684 /* see if we have a parent to subbuffer */
686 gst_fakesrc_alloc_parent (src);
687 g_assert (src->parent);
689 /* see if it's large enough */
690 if ((GST_BUFFER_SIZE (src->parent) - src->parentoffset) >= size) {
691 buf = gst_buffer_create_sub (src->parent, src->parentoffset, size);
692 src->parentoffset += size;
695 /* the parent is useless now */
696 gst_buffer_unref (src->parent);
698 /* try again (this will allocate a new parent) */
699 return gst_fakesrc_create_buffer (src);
701 gst_fakesrc_prepare_buffer (src, buf);
703 case FAKESRC_DATA_BUFFERPOOL:
704 buf = gst_buffer_new_from_pool (src->pool, 0, 0);
705 gst_fakesrc_prepare_buffer (src, buf);
708 g_warning ("fakesrc: dunno how to allocate buffers !");
709 buf = gst_buffer_new();
713 gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
720 gst_fakesrc_get(GstPad *pad)
725 g_return_val_if_fail (pad != NULL, NULL);
727 src = GST_FAKESRC (gst_pad_get_parent (pad));
729 g_return_val_if_fail (GST_IS_FAKESRC (src), NULL);
731 if (src->need_flush) {
732 src->need_flush = FALSE;
733 return GST_BUFFER(gst_event_new (GST_EVENT_FLUSH));
736 if (src->buffer_count == src->segment_end) {
737 if (src->segment_loop) {
738 return GST_BUFFER(gst_event_new (GST_EVENT_SEGMENT_DONE));
741 gst_element_set_eos (GST_ELEMENT (src));
742 return GST_BUFFER(gst_event_new (GST_EVENT_EOS));
746 if (src->rt_num_buffers == 0) {
747 gst_element_set_eos (GST_ELEMENT (src));
748 return GST_BUFFER(gst_event_new (GST_EVENT_EOS));
751 if (src->rt_num_buffers > 0)
752 src->rt_num_buffers--;
756 GST_INFO (0, "fakesrc is setting eos on pad");
757 return GST_BUFFER(gst_event_new (GST_EVENT_EOS));
760 buf = gst_fakesrc_create_buffer (src);
761 GST_BUFFER_TIMESTAMP (buf) = src->buffer_count++;
764 g_free (src->last_message);
766 src->last_message = g_strdup_printf ("get ******* (%s:%s)> (%d bytes, %llu) %p",
767 GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf), buf);
769 g_object_notify (G_OBJECT (src), "last_message");
772 GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, src, "pre handoff emit");
773 g_signal_emit (G_OBJECT (src), gst_fakesrc_signals[SIGNAL_HANDOFF], 0,
775 GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, src, "post handoff emit");
782 * @element: the faksesrc to loop
784 * generate an empty buffer and push it to the next element.
787 gst_fakesrc_loop(GstElement *element)
792 g_return_if_fail(element != NULL);
793 g_return_if_fail(GST_IS_FAKESRC(element));
795 src = GST_FAKESRC (element);
797 pads = gst_element_get_pad_list (element);
800 GstPad *pad = GST_PAD (pads->data);
803 buf = gst_fakesrc_get (pad);
804 gst_pad_push (pad, buf);
810 pads = g_list_next (pads);
814 static GstElementStateReturn
815 gst_fakesrc_change_state (GstElement *element)
819 g_return_val_if_fail (GST_IS_FAKESRC (element), GST_STATE_FAILURE);
821 fakesrc = GST_FAKESRC (element);
823 switch (GST_STATE_TRANSITION (element)) {
824 case GST_STATE_NULL_TO_READY:
826 case GST_STATE_READY_TO_PAUSED:
827 fakesrc->buffer_count = 0;
828 fakesrc->pattern_byte = 0x00;
829 fakesrc->need_flush = FALSE;
830 fakesrc->eos = FALSE;
831 fakesrc->rt_num_buffers = fakesrc->num_buffers;
833 case GST_STATE_PAUSED_TO_PLAYING:
834 case GST_STATE_PLAYING_TO_PAUSED:
836 case GST_STATE_PAUSED_TO_READY:
837 if (fakesrc->parent) {
838 gst_buffer_unref (fakesrc->parent);
839 fakesrc->parent = NULL;
842 gst_buffer_pool_unref (fakesrc->pool);
843 fakesrc->pool = NULL;
845 g_free (fakesrc->last_message);
846 fakesrc->last_message = NULL;
848 case GST_STATE_READY_TO_NULL:
851 g_assert_not_reached ();
855 if (GST_ELEMENT_CLASS (parent_class)->change_state)
856 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
858 return GST_STATE_SUCCESS;
862 gst_fakesrc_factory_init (GstElementFactory *factory)
864 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (fakesrc_src_factory));