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>
30 GstElementDetails gst_fakesrc_details = {
33 "Push empty (no data) buffers around",
35 "Erik Walthinsen <omega@cse.ogi.edu>\n"
36 "Wim Taymans <wim.taymans@chello.be>",
41 /* FakeSrc signals and args */
67 GST_PAD_TEMPLATE_FACTORY (fakesrc_src_factory,
74 #define GST_TYPE_FAKESRC_OUTPUT (gst_fakesrc_output_get_type())
76 gst_fakesrc_output_get_type (void)
78 static GType fakesrc_output_type = 0;
79 static GEnumValue fakesrc_output[] = {
80 { FAKESRC_FIRST_LAST_LOOP, "1", "First-Last loop"},
81 { FAKESRC_LAST_FIRST_LOOP, "2", "Last-First loop"},
82 { FAKESRC_PING_PONG, "3", "Ping-Pong"},
83 { FAKESRC_ORDERED_RANDOM, "4", "Ordered Random"},
84 { FAKESRC_RANDOM, "5", "Random"},
85 { FAKESRC_PATTERN_LOOP, "6", "Patttern loop"},
86 { FAKESRC_PING_PONG_PATTERN, "7", "Ping-Pong Pattern"},
87 { FAKESRC_GET_ALWAYS_SUCEEDS, "8", "'_get' Always succeeds"},
90 if (!fakesrc_output_type) {
91 fakesrc_output_type = g_enum_register_static ("GstFakeSrcOutput", fakesrc_output);
93 return fakesrc_output_type;
96 #define GST_TYPE_FAKESRC_DATA (gst_fakesrc_data_get_type())
98 gst_fakesrc_data_get_type (void)
100 static GType fakesrc_data_type = 0;
101 static GEnumValue fakesrc_data[] = {
102 { FAKESRC_DATA_ALLOCATE, "1", "Allocate data"},
103 { FAKESRC_DATA_SUBBUFFER, "2", "Subbuffer data"},
104 { FAKESRC_DATA_BUFFERPOOL, "3", "Use the default buffer pool (forces sizetype=2)"},
107 if (!fakesrc_data_type) {
108 fakesrc_data_type = g_enum_register_static ("GstFakeSrcData", fakesrc_data);
110 return fakesrc_data_type;
113 #define GST_TYPE_FAKESRC_SIZETYPE (gst_fakesrc_sizetype_get_type())
115 gst_fakesrc_sizetype_get_type (void)
117 static GType fakesrc_sizetype_type = 0;
118 static GEnumValue fakesrc_sizetype[] = {
119 { FAKESRC_SIZETYPE_NULL, "1", "Send empty buffers"},
120 { FAKESRC_SIZETYPE_FIXED, "2", "Fixed size buffers (sizemax sized)"},
121 { FAKESRC_SIZETYPE_RANDOM, "3", "Random sized buffers (sizemin <= size <= sizemax)"},
124 if (!fakesrc_sizetype_type) {
125 fakesrc_sizetype_type = g_enum_register_static ("GstFakeSrcSizeType", fakesrc_sizetype);
127 return fakesrc_sizetype_type;
130 #define GST_TYPE_FAKESRC_FILLTYPE (gst_fakesrc_filltype_get_type())
132 gst_fakesrc_filltype_get_type (void)
134 static GType fakesrc_filltype_type = 0;
135 static GEnumValue fakesrc_filltype[] = {
136 { FAKESRC_FILLTYPE_NOTHING, "1", "Leave data as malloced"},
137 { FAKESRC_FILLTYPE_NULL, "2", "Fill buffers with zeros"},
138 { FAKESRC_FILLTYPE_RANDOM, "3", "Fill buffers with random crap"},
139 { FAKESRC_FILLTYPE_PATTERN, "4", "Fill buffers with pattern 0x00 -> 0xff"},
140 { FAKESRC_FILLTYPE_PATTERN_CONT, "5", "Fill buffers with pattern 0x00 -> 0xff that spans buffers"},
143 if (!fakesrc_filltype_type) {
144 fakesrc_filltype_type = g_enum_register_static ("GstFakeSrcFillType", fakesrc_filltype);
146 return fakesrc_filltype_type;
149 static void gst_fakesrc_class_init (GstFakeSrcClass *klass);
150 static void gst_fakesrc_init (GstFakeSrc *fakesrc);
152 static GstPad* gst_fakesrc_request_new_pad (GstElement *element, GstPadTemplate *templ);
153 static void gst_fakesrc_update_functions (GstFakeSrc *src);
154 static void gst_fakesrc_set_property (GObject *object, guint prop_id,
155 const GValue *value, GParamSpec *pspec);
156 static void gst_fakesrc_get_property (GObject *object, guint prop_id,
157 GValue *value, GParamSpec *pspec);
159 static GstElementStateReturn gst_fakesrc_change_state (GstElement *element);
161 static GstBuffer* gst_fakesrc_get (GstPad *pad);
162 static void gst_fakesrc_loop (GstElement *element);
164 static GstElementClass *parent_class = NULL;
165 static guint gst_fakesrc_signals[LAST_SIGNAL] = { 0 };
168 gst_fakesrc_get_type (void)
170 static GType fakesrc_type = 0;
173 static const GTypeInfo fakesrc_info = {
174 sizeof(GstFakeSrcClass),
177 (GClassInitFunc)gst_fakesrc_class_init,
182 (GInstanceInitFunc)gst_fakesrc_init,
184 fakesrc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstFakeSrc", &fakesrc_info, 0);
190 gst_fakesrc_class_init (GstFakeSrcClass *klass)
192 GObjectClass *gobject_class;
193 GstElementClass *gstelement_class;
195 gobject_class = (GObjectClass*)klass;
196 gstelement_class = (GstElementClass*)klass;
198 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
200 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_SOURCES,
201 g_param_spec_int ("num-sources", "num-sources", "Number of sources",
202 1, G_MAXINT, 1, G_PARAM_READABLE));
203 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LOOP_BASED,
204 g_param_spec_boolean("loop-based","loop-based","Enable loop-based operation",
205 FALSE, G_PARAM_READWRITE));
206 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_OUTPUT,
207 g_param_spec_enum("output","output","Output method (currently unused)",
208 GST_TYPE_FAKESRC_OUTPUT,FAKESRC_FIRST_LAST_LOOP,G_PARAM_READWRITE));
209 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DATA,
210 g_param_spec_enum ("data", "data", "Data allocation method",
211 GST_TYPE_FAKESRC_DATA, FAKESRC_DATA_ALLOCATE, G_PARAM_READWRITE));
212 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZETYPE,
213 g_param_spec_enum ("sizetype", "sizetype", "How to determine buffer sizes",
214 GST_TYPE_FAKESRC_SIZETYPE, FAKESRC_SIZETYPE_NULL, G_PARAM_READWRITE));
215 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMIN,
216 g_param_spec_int ("sizemin","sizemin","Minimum buffer size",
217 0, G_MAXINT, 0, G_PARAM_READWRITE));
218 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMAX,
219 g_param_spec_int ("sizemax","sizemax","Maximum buffer size",
220 0, G_MAXINT, 4096, G_PARAM_READWRITE));
221 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PARENTSIZE,
222 g_param_spec_int ("parentsize","parentsize","Size of parent buffer for sub-buffered allocation",
223 0, G_MAXINT, 4096 * 10, G_PARAM_READWRITE));
224 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FILLTYPE,
225 g_param_spec_enum ("filltype", "filltype", "How to fill the buffer, if at all",
226 GST_TYPE_FAKESRC_FILLTYPE, FAKESRC_FILLTYPE_NULL, G_PARAM_READWRITE));
227 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_PATTERN,
228 g_param_spec_string("pattern","pattern","pattern",
229 NULL, G_PARAM_READWRITE));
230 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_NUM_BUFFERS,
231 g_param_spec_int("num-buffers","num-buffers","Number of buffers to output before sending EOS",
232 G_MININT,G_MAXINT,0,G_PARAM_READWRITE));
233 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_EOS,
234 g_param_spec_boolean("eos","eos","Send out the EOS event?",
235 TRUE,G_PARAM_READWRITE));
236 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
237 g_param_spec_string ("last-message", "last-message", "The last status message",
238 NULL, G_PARAM_READABLE));
240 gst_element_class_install_std_props (
241 GST_ELEMENT_CLASS (klass),
242 "silent", ARG_SILENT, G_PARAM_READWRITE,
243 "dump", ARG_DUMP, G_PARAM_READWRITE,
246 gst_fakesrc_signals[SIGNAL_HANDOFF] =
247 g_signal_new ("handoff", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
248 G_STRUCT_OFFSET (GstFakeSrcClass, handoff), NULL, NULL,
249 g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
252 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesrc_set_property);
253 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesrc_get_property);
255 gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR (gst_fakesrc_request_new_pad);
256 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_fakesrc_change_state);
260 gst_fakesrc_init (GstFakeSrc *fakesrc)
264 /* create our first output pad */
265 pad = gst_pad_new ("src", GST_PAD_SRC);
266 gst_element_add_pad (GST_ELEMENT (fakesrc), pad);
268 fakesrc->loop_based = FALSE;
269 gst_fakesrc_update_functions (fakesrc);
271 fakesrc->output = FAKESRC_FIRST_LAST_LOOP;
272 fakesrc->segment_start = -1;
273 fakesrc->segment_end = -1;
274 fakesrc->num_buffers = -1;
275 fakesrc->rt_num_buffers = -1;
276 fakesrc->buffer_count = 0;
277 fakesrc->silent = FALSE;
278 fakesrc->dump = FALSE;
279 fakesrc->pattern_byte = 0x00;
280 fakesrc->need_flush = FALSE;
281 fakesrc->data = FAKESRC_DATA_ALLOCATE;
282 fakesrc->sizetype = FAKESRC_SIZETYPE_NULL;
283 fakesrc->filltype = FAKESRC_FILLTYPE_NOTHING;
284 fakesrc->sizemin = 0;
285 fakesrc->sizemax = 4096;
286 fakesrc->parent = NULL;
287 fakesrc->parentsize = 4096 * 10;
288 fakesrc->last_message = NULL;
292 gst_fakesrc_request_new_pad (GstElement *element, GstPadTemplate *templ)
298 g_return_val_if_fail (GST_IS_FAKESRC (element), NULL);
300 if (templ->direction != GST_PAD_SRC) {
301 g_warning ("gstfakesrc: request new pad that is not a SRC pad\n");
305 fakesrc = GST_FAKESRC (element);
307 name = g_strdup_printf ("src%d", GST_ELEMENT (fakesrc)->numsrcpads);
309 srcpad = gst_pad_new_from_template (templ, name);
310 gst_element_add_pad (GST_ELEMENT (fakesrc), srcpad);
311 gst_fakesrc_update_functions (fakesrc);
318 GST_FORMATS_FUNCTION (gst_fakesrc_get_formats,
322 GST_PAD_QUERY_TYPE_FUNCTION (gst_fakesrc_get_query_types,
324 GST_PAD_QUERY_POSITION,
326 GST_PAD_QUERY_SEGMENT_END
330 gst_fakesrc_query (GstPad *pad, GstPadQueryType type,
331 GstFormat *format, gint64 *value)
333 GstFakeSrc *src = GST_FAKESRC (GST_PAD_PARENT (pad));
336 case GST_PAD_QUERY_TOTAL:
337 *value = src->num_buffers;
339 case GST_PAD_QUERY_POSITION:
340 *value = src->buffer_count;
342 case GST_PAD_QUERY_START:
343 *value = src->segment_start;
345 case GST_PAD_QUERY_SEGMENT_END:
346 *value = src->segment_end;
354 GST_EVENT_MASK_FUNCTION (gst_fakesrc_get_event_mask,
355 { GST_EVENT_SEEK, GST_SEEK_FLAG_FLUSH },
356 { GST_EVENT_SEEK_SEGMENT, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SEGMENT_LOOP },
357 { GST_EVENT_FLUSH, 0 }
361 gst_fakesrc_event_handler (GstPad *pad, GstEvent *event)
365 src = GST_FAKESRC (gst_pad_get_parent (pad));
367 switch (GST_EVENT_TYPE (event)) {
369 src->buffer_count = GST_EVENT_SEEK_OFFSET (event);
371 if (!GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH) {
374 /* else we do a flush too */
375 case GST_EVENT_SEEK_SEGMENT:
376 src->segment_start = GST_EVENT_SEEK_OFFSET (event);
377 src->segment_end = GST_EVENT_SEEK_ENDOFFSET (event);
378 src->buffer_count = src->segment_start;
379 src->segment_loop = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_SEGMENT_LOOP;
381 case GST_EVENT_FLUSH:
382 src->need_flush = TRUE;
387 gst_event_unref (event);
393 gst_fakesrc_update_functions (GstFakeSrc *src)
397 if (src->loop_based) {
398 gst_element_set_loop_function (GST_ELEMENT (src), GST_DEBUG_FUNCPTR (gst_fakesrc_loop));
401 gst_element_set_loop_function (GST_ELEMENT (src), NULL);
404 pads = GST_ELEMENT (src)->pads;
406 GstPad *pad = GST_PAD (pads->data);
408 if (src->loop_based) {
409 gst_pad_set_get_function (pad, NULL);
412 gst_pad_set_get_function (pad, GST_DEBUG_FUNCPTR (gst_fakesrc_get));
415 gst_pad_set_event_function (pad, gst_fakesrc_event_handler);
416 gst_pad_set_event_mask_function (pad, gst_fakesrc_get_event_mask);
417 gst_pad_set_query_function (pad, gst_fakesrc_query);
418 gst_pad_set_query_type_function (pad, gst_fakesrc_get_query_types);
419 gst_pad_set_formats_function (pad, gst_fakesrc_get_formats);
420 pads = g_list_next (pads);
425 gst_fakesrc_alloc_parent (GstFakeSrc *src)
429 buf = gst_buffer_new ();
430 GST_BUFFER_DATA (buf) = g_malloc (src->parentsize);
431 GST_BUFFER_SIZE (buf) = src->parentsize;
434 src->parentoffset = 0;
438 gst_fakesrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
442 /* it's not null if we got it, but it might not be ours */
443 src = GST_FAKESRC (object);
447 src->loop_based = g_value_get_boolean (value);
448 gst_fakesrc_update_functions (src);
451 g_warning ("not yet implemented");
454 src->data = g_value_get_enum (value);
456 if (src->data == FAKESRC_DATA_SUBBUFFER) {
458 gst_fakesrc_alloc_parent (src);
461 gst_buffer_unref (src->parent);
466 if (src->data == FAKESRC_DATA_BUFFERPOOL) {
467 if (src->sizetype != FAKESRC_SIZETYPE_FIXED)
468 g_object_set (src, "sizetype", FAKESRC_SIZETYPE_FIXED, NULL);
471 src->pool = gst_buffer_pool_get_default (src->sizemax, 10);
474 gst_buffer_pool_free (src->pool);
480 src->sizetype = g_value_get_enum (value);
483 src->sizemin = g_value_get_int (value);
486 src->sizemax = g_value_get_int (value);
489 src->parentsize = g_value_get_int (value);
492 src->filltype = g_value_get_enum (value);
496 case ARG_NUM_BUFFERS:
497 src->num_buffers = g_value_get_int (value);
500 src->eos = g_value_get_boolean (value);
501 GST_INFO (0, "will EOS on next buffer");
504 src->silent = g_value_get_boolean (value);
507 src->dump = g_value_get_boolean (value);
515 gst_fakesrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
519 /* it's not null if we got it, but it might not be ours */
520 g_return_if_fail (GST_IS_FAKESRC (object));
522 src = GST_FAKESRC (object);
525 case ARG_NUM_SOURCES:
526 g_value_set_int (value, GST_ELEMENT (src)->numsrcpads);
529 g_value_set_boolean (value, src->loop_based);
532 g_value_set_enum (value, src->output);
535 g_value_set_enum (value, src->data);
538 g_value_set_enum (value, src->sizetype);
541 g_value_set_int (value, src->sizemin);
544 g_value_set_int (value, src->sizemax);
547 g_value_set_int (value, src->parentsize);
550 g_value_set_enum (value, src->filltype);
553 g_value_set_string (value, src->pattern);
555 case ARG_NUM_BUFFERS:
556 g_value_set_int (value, src->num_buffers);
559 g_value_set_boolean (value, src->eos);
562 g_value_set_boolean (value, src->silent);
565 g_value_set_boolean (value, src->dump);
567 case ARG_LAST_MESSAGE:
568 g_value_set_string (value, src->last_message);
571 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
577 gst_fakesrc_prepare_buffer (GstFakeSrc *src, GstBuffer *buf)
579 if (GST_BUFFER_SIZE (buf) == 0)
582 switch (src->filltype) {
583 case FAKESRC_FILLTYPE_NULL:
584 memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf));
586 case FAKESRC_FILLTYPE_RANDOM:
589 guint8 *ptr = GST_BUFFER_DATA (buf);
591 for (i = GST_BUFFER_SIZE (buf); i; i--) {
592 *ptr++ = (gint8)((255.0)*rand()/(RAND_MAX));
596 case FAKESRC_FILLTYPE_PATTERN:
597 src->pattern_byte = 0x00;
598 case FAKESRC_FILLTYPE_PATTERN_CONT:
601 guint8 *ptr = GST_BUFFER_DATA (buf);
603 for (i = GST_BUFFER_SIZE (buf); i; i--) {
604 *ptr++ = src->pattern_byte++;
608 case FAKESRC_FILLTYPE_NOTHING:
615 gst_fakesrc_alloc_buffer (GstFakeSrc *src, guint size)
619 buf = gst_buffer_new ();
620 GST_BUFFER_SIZE(buf) = size;
623 switch (src->filltype) {
624 case FAKESRC_FILLTYPE_NOTHING:
625 GST_BUFFER_DATA(buf) = g_malloc (size);
627 case FAKESRC_FILLTYPE_NULL:
628 GST_BUFFER_DATA(buf) = g_malloc0 (size);
630 case FAKESRC_FILLTYPE_RANDOM:
631 case FAKESRC_FILLTYPE_PATTERN:
632 case FAKESRC_FILLTYPE_PATTERN_CONT:
634 GST_BUFFER_DATA(buf) = g_malloc (size);
635 gst_fakesrc_prepare_buffer (src, buf);
644 gst_fakesrc_get_size (GstFakeSrc *src)
648 switch (src->sizetype) {
649 case FAKESRC_SIZETYPE_FIXED:
652 case FAKESRC_SIZETYPE_RANDOM:
653 size = src->sizemin + (guint8)(((gfloat)src->sizemax)*rand()/(RAND_MAX + (gfloat)src->sizemin));
655 case FAKESRC_SIZETYPE_NULL:
665 gst_fakesrc_create_buffer (GstFakeSrc *src)
669 gboolean dump = src->dump;
671 size = gst_fakesrc_get_size (src);
673 return gst_buffer_new();
676 case FAKESRC_DATA_ALLOCATE:
677 buf = gst_fakesrc_alloc_buffer (src, size);
679 case FAKESRC_DATA_SUBBUFFER:
680 /* see if we have a parent to subbuffer */
682 gst_fakesrc_alloc_parent (src);
683 g_assert (src->parent);
685 /* see if it's large enough */
686 if ((GST_BUFFER_SIZE (src->parent) - src->parentoffset) >= size) {
687 buf = gst_buffer_create_sub (src->parent, src->parentoffset, size);
688 src->parentoffset += size;
691 /* the parent is useless now */
692 gst_buffer_unref (src->parent);
694 /* try again (this will allocate a new parent) */
695 return gst_fakesrc_create_buffer (src);
697 gst_fakesrc_prepare_buffer (src, buf);
699 case FAKESRC_DATA_BUFFERPOOL:
700 buf = gst_buffer_new_from_pool (src->pool, 0, 0);
701 gst_fakesrc_prepare_buffer (src, buf);
704 g_warning ("fakesrc: dunno how to allocate buffers !");
705 buf = gst_buffer_new();
709 gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
716 gst_fakesrc_get(GstPad *pad)
721 g_return_val_if_fail (pad != NULL, NULL);
723 src = GST_FAKESRC (gst_pad_get_parent (pad));
725 g_return_val_if_fail (GST_IS_FAKESRC (src), NULL);
727 if (src->need_flush) {
728 src->need_flush = FALSE;
729 return GST_BUFFER(gst_event_new (GST_EVENT_FLUSH));
732 if (src->buffer_count == src->segment_end) {
733 if (src->segment_loop) {
734 return GST_BUFFER(gst_event_new (GST_EVENT_SEGMENT_DONE));
737 gst_element_set_eos (GST_ELEMENT (src));
738 return GST_BUFFER(gst_event_new (GST_EVENT_EOS));
742 if (src->rt_num_buffers == 0) {
743 gst_element_set_eos (GST_ELEMENT (src));
744 return GST_BUFFER(gst_event_new (GST_EVENT_EOS));
747 if (src->rt_num_buffers > 0)
748 src->rt_num_buffers--;
752 GST_INFO (0, "fakesrc is setting eos on pad");
753 return GST_BUFFER(gst_event_new (GST_EVENT_EOS));
756 buf = gst_fakesrc_create_buffer (src);
757 GST_BUFFER_TIMESTAMP (buf) = src->buffer_count++;
760 if (src->last_message)
761 g_free (src->last_message);
763 src->last_message = g_strdup_printf ("get ******* (%s:%s)> (%d bytes, %llu) %p",
764 GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf), buf);
766 g_object_notify (G_OBJECT (src), "last_message");
769 GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, src, "pre handoff emit");
770 g_signal_emit (G_OBJECT (src), gst_fakesrc_signals[SIGNAL_HANDOFF], 0,
772 GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, src, "post handoff emit");
779 * @element: the faksesrc to loop
781 * generate an empty buffer and push it to the next element.
784 gst_fakesrc_loop(GstElement *element)
789 g_return_if_fail(element != NULL);
790 g_return_if_fail(GST_IS_FAKESRC(element));
792 src = GST_FAKESRC (element);
794 pads = gst_element_get_pad_list (element);
797 GstPad *pad = GST_PAD (pads->data);
800 buf = gst_fakesrc_get (pad);
801 gst_pad_push (pad, buf);
807 pads = g_list_next (pads);
811 static GstElementStateReturn
812 gst_fakesrc_change_state (GstElement *element)
816 g_return_val_if_fail (GST_IS_FAKESRC (element), GST_STATE_FAILURE);
818 fakesrc = GST_FAKESRC (element);
820 switch (GST_STATE_TRANSITION (element)) {
821 case GST_STATE_PAUSED_TO_READY:
822 case GST_STATE_NULL_TO_READY:
823 fakesrc->buffer_count = 0;
824 fakesrc->pattern_byte = 0x00;
825 fakesrc->need_flush = FALSE;
826 fakesrc->eos = FALSE;
827 fakesrc->rt_num_buffers = fakesrc->num_buffers;
829 case GST_STATE_READY_TO_PAUSED:
830 case GST_STATE_PAUSED_TO_PLAYING:
831 case GST_STATE_PLAYING_TO_PAUSED:
833 case GST_STATE_READY_TO_NULL:
834 if (fakesrc->parent) {
835 gst_buffer_unref (fakesrc->parent);
836 fakesrc->parent = NULL;
839 gst_buffer_pool_unref (fakesrc->pool);
840 fakesrc->pool = NULL;
844 g_assert_not_reached ();
848 if (GST_ELEMENT_CLASS (parent_class)->change_state)
849 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
851 return GST_STATE_SUCCESS;
855 gst_fakesrc_factory_init (GstElementFactory *factory)
857 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (fakesrc_src_factory));