2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstscheduler.c: Default scheduling code for most cases
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 #include "gst_private.h"
25 #include "gstsystemclock.h"
26 #include "gstscheduler.h"
28 #include "gstregistrypool.h"
30 static void gst_scheduler_class_init (GstSchedulerClass * klass);
31 static void gst_scheduler_init (GstScheduler * sched);
32 static void gst_scheduler_dispose (GObject * object);
34 static GstObjectClass *parent_class = NULL;
36 static gchar *_default_name = NULL;
39 gst_scheduler_get_type (void)
41 static GType _gst_scheduler_type = 0;
43 if (!_gst_scheduler_type) {
44 static const GTypeInfo scheduler_info = {
45 sizeof (GstSchedulerClass),
48 (GClassInitFunc) gst_scheduler_class_init,
51 sizeof (GstScheduler),
53 (GInstanceInitFunc) gst_scheduler_init,
58 g_type_register_static (GST_TYPE_OBJECT, "GstScheduler",
59 &scheduler_info, G_TYPE_FLAG_ABSTRACT);
61 return _gst_scheduler_type;
65 gst_scheduler_class_init (GstSchedulerClass * klass)
67 GObjectClass *gobject_class;
69 gobject_class = (GObjectClass *) klass;
71 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
73 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_scheduler_dispose);
77 gst_scheduler_init (GstScheduler * sched)
79 sched->clock_providers = NULL;
80 sched->clock_receivers = NULL;
81 sched->schedulers = NULL;
82 sched->state = GST_SCHEDULER_STATE_NONE;
84 sched->parent_sched = NULL;
89 gst_scheduler_dispose (GObject * object)
91 GstScheduler *sched = GST_SCHEDULER (object);
93 /* thse lists should all be NULL */
94 GST_DEBUG ("scheduler %p dispose %p %p %p",
96 sched->clock_providers, sched->clock_receivers, sched->schedulers);
98 gst_object_replace ((GstObject **) & sched->current_clock, NULL);
99 gst_object_replace ((GstObject **) & sched->clock, NULL);
101 G_OBJECT_CLASS (parent_class)->dispose (object);
105 * gst_scheduler_setup:
106 * @sched: the scheduler
108 * Prepare the scheduler.
111 gst_scheduler_setup (GstScheduler * sched)
113 GstSchedulerClass *sclass;
115 g_return_if_fail (GST_IS_SCHEDULER (sched));
117 sclass = GST_SCHEDULER_GET_CLASS (sched);
120 sclass->setup (sched);
124 * gst_scheduler_reset:
125 * @sched: a #GstScheduler to reset.
127 * Reset the schedulers.
130 gst_scheduler_reset (GstScheduler * sched)
132 GstSchedulerClass *sclass;
134 g_return_if_fail (GST_IS_SCHEDULER (sched));
136 sclass = GST_SCHEDULER_GET_CLASS (sched);
139 sclass->reset (sched);
143 * gst_scheduler_pad_link:
144 * @sched: the scheduler
145 * @srcpad: the srcpad to link
146 * @sinkpad: the sinkpad to link to
148 * Links the srcpad to the given sinkpad.
151 gst_scheduler_pad_link (GstScheduler * sched, GstPad * srcpad, GstPad * sinkpad)
153 GstSchedulerClass *sclass;
155 g_return_if_fail (GST_IS_SCHEDULER (sched));
156 g_return_if_fail (GST_IS_PAD (srcpad));
157 g_return_if_fail (GST_IS_PAD (sinkpad));
159 sclass = GST_SCHEDULER_GET_CLASS (sched);
161 if (sclass->pad_link)
162 sclass->pad_link (sched, srcpad, sinkpad);
166 * gst_scheduler_pad_unlink:
167 * @sched: the scheduler
168 * @srcpad: the srcpad to unlink
169 * @sinkpad: the sinkpad to unlink from
171 * Unlinks the srcpad from the given sinkpad.
174 gst_scheduler_pad_unlink (GstScheduler * sched, GstPad * srcpad,
177 GstSchedulerClass *sclass;
179 g_return_if_fail (GST_IS_SCHEDULER (sched));
180 g_return_if_fail (GST_IS_PAD (srcpad));
181 g_return_if_fail (GST_IS_PAD (sinkpad));
183 sclass = GST_SCHEDULER_GET_CLASS (sched);
185 if (sclass->pad_unlink)
186 sclass->pad_unlink (sched, srcpad, sinkpad);
190 * gst_scheduler_pad_select:
191 * @sched: the scheduler
192 * @padlist: the padlist to select on
194 * register the given padlist for a select operation.
196 * Returns: the pad which received a buffer.
199 gst_scheduler_pad_select (GstScheduler * sched, GList * padlist)
201 g_return_val_if_fail (GST_IS_SCHEDULER (sched), NULL);
202 g_return_val_if_fail (padlist != NULL, NULL);
208 * gst_scheduler_add_element:
209 * @sched: the scheduler
210 * @element: the element to add to the scheduler
212 * Add an element to the scheduler.
215 gst_scheduler_add_element (GstScheduler * sched, GstElement * element)
217 GstSchedulerClass *sclass;
219 g_return_if_fail (GST_IS_SCHEDULER (sched));
220 g_return_if_fail (GST_IS_ELEMENT (element));
222 /* if it's already in this scheduler, don't bother doing anything */
223 if (GST_ELEMENT_SCHED (element) == sched) {
224 GST_CAT_DEBUG (GST_CAT_SCHEDULING, "element %s already in scheduler %p",
225 GST_ELEMENT_NAME (element), sched);
229 /* if it's not inside this scheduler, it has to be NULL */
230 g_assert (GST_ELEMENT_SCHED (element) == NULL);
232 if (gst_element_provides_clock (element)) {
233 sched->clock_providers = g_list_prepend (sched->clock_providers, element);
234 GST_CAT_DEBUG (GST_CAT_CLOCK, "added clock provider %s",
235 GST_ELEMENT_NAME (element));
237 if (gst_element_requires_clock (element)) {
238 sched->clock_receivers = g_list_prepend (sched->clock_receivers, element);
239 GST_CAT_DEBUG (GST_CAT_CLOCK, "added clock receiver %s",
240 GST_ELEMENT_NAME (element));
243 gst_element_set_scheduler (element, sched);
245 sclass = GST_SCHEDULER_GET_CLASS (sched);
247 if (sclass->add_element)
248 sclass->add_element (sched, element);
252 * gst_scheduler_remove_element:
253 * @sched: the scheduler
254 * @element: the element to remove
256 * Remove an element from the scheduler.
259 gst_scheduler_remove_element (GstScheduler * sched, GstElement * element)
261 GstSchedulerClass *sclass;
263 g_return_if_fail (GST_IS_SCHEDULER (sched));
264 g_return_if_fail (GST_IS_ELEMENT (element));
266 sched->clock_providers = g_list_remove (sched->clock_providers, element);
267 sched->clock_receivers = g_list_remove (sched->clock_receivers, element);
269 sclass = GST_SCHEDULER_GET_CLASS (sched);
271 if (sclass->remove_element)
272 sclass->remove_element (sched, element);
274 gst_element_set_scheduler (element, NULL);
278 * gst_scheduler_state_transition:
279 * @sched: the scheduler
280 * @element: the element with the state transition
281 * @transition: the state transition
283 * Tell the scheduler that an element changed its state.
285 * Returns: a GstElementStateReturn indicating success or failure
286 * of the state transition.
288 GstElementStateReturn
289 gst_scheduler_state_transition (GstScheduler * sched, GstElement * element,
292 GstSchedulerClass *sclass;
294 g_return_val_if_fail (GST_IS_SCHEDULER (sched), GST_STATE_FAILURE);
295 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_FAILURE);
297 if (element == sched->parent && sched->parent_sched == NULL) {
298 switch (transition) {
299 case GST_STATE_READY_TO_PAUSED:
301 GstClock *clock = gst_scheduler_get_clock (sched);
303 GST_CAT_DEBUG (GST_CAT_CLOCK,
304 "scheduler READY to PAUSED clock is %p (%s)", clock,
305 (clock ? GST_OBJECT_NAME (clock) : "nil"));
307 gst_scheduler_set_clock (sched, clock);
313 sclass = GST_SCHEDULER_GET_CLASS (sched);
315 if (sclass->state_transition)
316 return sclass->state_transition (sched, element, transition);
318 return GST_STATE_SUCCESS;
322 * gst_scheduler_scheduling_change:
323 * @sched: the scheduler
324 * @element: the element that changed its scheduling strategy
326 * Tell the scheduler that an element changed its scheduling strategy.
327 * An element could, for example, change its loop function or changes
328 * from a loop based element to a chain based element.
331 gst_scheduler_scheduling_change (GstScheduler * sched, GstElement * element)
333 GstSchedulerClass *sclass;
335 g_return_if_fail (GST_IS_SCHEDULER (sched));
336 g_return_if_fail (GST_IS_ELEMENT (element));
338 sclass = GST_SCHEDULER_GET_CLASS (sched);
340 if (sclass->scheduling_change)
341 sclass->scheduling_change (sched, element);
345 * gst_scheduler_add_scheduler:
346 * @sched: a #GstScheduler to add to
347 * @sched2: the #GstScheduler to add
349 * Notifies the scheduler that it has to monitor this scheduler.
352 gst_scheduler_add_scheduler (GstScheduler * sched, GstScheduler * sched2)
354 GstSchedulerClass *sclass;
356 g_return_if_fail (GST_IS_SCHEDULER (sched));
357 g_return_if_fail (GST_IS_SCHEDULER (sched2));
358 g_return_if_fail (sched2->parent_sched == NULL);
360 GST_DEBUG ("gstscheduler: %p add scheduler %p", sched, sched2);
362 gst_object_ref (GST_OBJECT (sched2));
363 gst_object_ref (GST_OBJECT (sched));
365 sched->schedulers = g_list_prepend (sched->schedulers, sched2);
366 sched2->parent_sched = sched;
368 sclass = GST_SCHEDULER_GET_CLASS (sched);
370 if (sclass->add_scheduler)
371 sclass->add_scheduler (sched, sched2);
375 * gst_scheduler_remove_scheduler:
376 * @sched: the scheduler
377 * @sched2: the scheduler to remove
379 a Notifies the scheduler that it can stop monitoring this scheduler.
382 gst_scheduler_remove_scheduler (GstScheduler * sched, GstScheduler * sched2)
384 GstSchedulerClass *sclass;
386 g_return_if_fail (GST_IS_SCHEDULER (sched));
387 g_return_if_fail (GST_IS_SCHEDULER (sched2));
388 g_return_if_fail (sched2->parent_sched == sched);
390 GST_DEBUG ("gstscheduler: %p remove scheduler %p", sched, sched2);
392 sclass = GST_SCHEDULER_GET_CLASS (sched);
394 if (sclass->remove_scheduler)
395 sclass->remove_scheduler (sched, sched2);
397 sched->schedulers = g_list_remove (sched->schedulers, sched2);
398 sched2->parent_sched = NULL;
400 gst_object_unref (GST_OBJECT (sched2));
401 gst_object_unref (GST_OBJECT (sched));
405 * gst_scheduler_lock_element:
406 * @sched: the scheduler
407 * @element: the element to lock
409 * Acquire a lock on the given element in the given scheduler.
412 gst_scheduler_lock_element (GstScheduler * sched, GstElement * element)
414 g_return_if_fail (GST_IS_SCHEDULER (sched));
415 g_return_if_fail (GST_IS_ELEMENT (element));
419 * gst_scheduler_unlock_element:
420 * @sched: the scheduler
421 * @element: the element to unlock
423 * Release the lock on the given element in the given scheduler.
426 gst_scheduler_unlock_element (GstScheduler * sched, GstElement * element)
428 GstSchedulerClass *sclass;
430 g_return_if_fail (GST_IS_SCHEDULER (sched));
431 g_return_if_fail (GST_IS_ELEMENT (element));
433 sclass = GST_SCHEDULER_GET_CLASS (sched);
437 * gst_scheduler_error:
438 * @sched: the scheduler
439 * @element: the element with the error
441 * Tell the scheduler an element was in error
444 gst_scheduler_error (GstScheduler * sched, GstElement * element)
446 GstSchedulerClass *sclass;
448 g_return_if_fail (GST_IS_SCHEDULER (sched));
449 g_return_if_fail (GST_IS_ELEMENT (element));
451 sclass = GST_SCHEDULER_GET_CLASS (sched);
454 sclass->error (sched, element);
458 * gst_scheduler_yield:
459 * @sched: the scheduler
460 * @element: the element requesting a yield
462 * Tell the scheduler to schedule another element.
464 * Returns: TRUE if the element should save its state, FALSE
465 * if the scheduler can perform this action itself.
468 gst_scheduler_yield (GstScheduler * sched, GstElement * element)
470 GstSchedulerClass *sclass;
472 g_return_val_if_fail (GST_IS_SCHEDULER (sched), TRUE);
473 g_return_val_if_fail (GST_IS_ELEMENT (element), TRUE);
475 sclass = GST_SCHEDULER_GET_CLASS (sched);
478 return sclass->yield (sched, element);
484 * gst_scheduler_interrupt:
485 * @sched: the scheduler
486 * @element: the element requesting an interrupt
488 * Tell the scheduler to interrupt execution of this element.
490 * Returns: TRUE if the element should return NULL from the chain/get
494 gst_scheduler_interrupt (GstScheduler * sched, GstElement * element)
496 GstSchedulerClass *sclass;
498 g_return_val_if_fail (GST_IS_SCHEDULER (sched), FALSE);
499 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
501 sclass = GST_SCHEDULER_GET_CLASS (sched);
503 if (sclass->interrupt)
504 return sclass->interrupt (sched, element);
510 * gst_scheduler_get_clock:
511 * @sched: the scheduler
513 * Gets the current clock used by the scheduler.
515 * Returns: a GstClock
518 gst_scheduler_get_clock (GstScheduler * sched)
520 GstClock *clock = NULL;
522 /* if we have a fixed clock, use that one */
523 if (GST_FLAG_IS_SET (sched, GST_SCHEDULER_FLAG_FIXED_CLOCK)) {
524 clock = sched->clock;
526 GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler using fixed clock %p (%s)",
527 clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
529 GList *schedulers = sched->schedulers;
530 GList *providers = sched->clock_providers;
532 /* try to get a clock from one of the schedulers we manage first */
534 GstScheduler *scheduler = GST_SCHEDULER (schedulers->data);
536 clock = gst_scheduler_get_clock (scheduler);
538 GST_CAT_DEBUG (GST_CAT_CLOCK,
539 "scheduler found managed sched clock %p (%s)",
540 clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
544 schedulers = g_list_next (schedulers);
546 /* still no clock, try to find one in the providers */
547 while (!clock && providers) {
548 clock = gst_element_get_clock (GST_ELEMENT (providers->data));
550 GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler found provider clock: %p (%s)",
551 clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
552 providers = g_list_next (providers);
554 /* still no clock, use a system clock */
555 if (!clock && sched->parent_sched == NULL) {
556 clock = gst_system_clock_obtain ();
557 /* we unref since this function is not supposed to increase refcount
558 * of clock object returned; this is ok since the systemclock always
559 * has a refcount of at least one in the current code. */
560 gst_object_unref (GST_OBJECT (clock));
561 GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler obtained system clock: %p (%s)",
562 clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
570 * gst_scheduler_use_clock:
571 * @sched: the scheduler
572 * @clock: the clock to use
574 * Force the scheduler to use the given clock. The scheduler will
575 * always use the given clock even if new clock providers are added
579 gst_scheduler_use_clock (GstScheduler * sched, GstClock * clock)
581 g_return_if_fail (sched != NULL);
582 g_return_if_fail (GST_IS_SCHEDULER (sched));
584 GST_FLAG_SET (sched, GST_SCHEDULER_FLAG_FIXED_CLOCK);
586 gst_object_replace ((GstObject **) & sched->clock, (GstObject *) clock);
588 GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler using fixed clock %p (%s)", clock,
589 (clock ? GST_OBJECT_NAME (clock) : "nil"));
593 * gst_scheduler_set_clock:
594 * @sched: the scheduler
595 * @clock: the clock to set
597 * Set the clock for the scheduler. The clock will be distributed
598 * to all the elements managed by the scheduler.
601 gst_scheduler_set_clock (GstScheduler * sched, GstClock * clock)
606 g_return_if_fail (sched != NULL);
607 g_return_if_fail (GST_IS_SCHEDULER (sched));
609 receivers = sched->clock_receivers;
610 schedulers = sched->schedulers;
612 gst_object_replace ((GstObject **) & sched->current_clock,
613 (GstObject *) clock);
616 GstElement *element = GST_ELEMENT (receivers->data);
618 GST_CAT_DEBUG (GST_CAT_CLOCK,
619 "scheduler setting clock %p (%s) on element %s", clock,
620 (clock ? GST_OBJECT_NAME (clock) : "nil"), GST_ELEMENT_NAME (element));
622 gst_element_set_clock (element, clock);
623 receivers = g_list_next (receivers);
626 GstScheduler *scheduler = GST_SCHEDULER (schedulers->data);
628 GST_CAT_DEBUG (GST_CAT_CLOCK,
629 "scheduler setting clock %p (%s) on scheduler %p", clock,
630 (clock ? GST_OBJECT_NAME (clock) : "nil"), scheduler);
631 gst_scheduler_set_clock (scheduler, clock);
632 schedulers = g_list_next (schedulers);
637 * gst_scheduler_auto_clock:
638 * @sched: the scheduler
640 * Let the scheduler select a clock automatically.
643 gst_scheduler_auto_clock (GstScheduler * sched)
645 g_return_if_fail (sched != NULL);
646 g_return_if_fail (GST_IS_SCHEDULER (sched));
648 GST_FLAG_UNSET (sched, GST_SCHEDULER_FLAG_FIXED_CLOCK);
650 gst_object_replace ((GstObject **) & sched->clock, NULL);
652 GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler using automatic clock");
655 GstClockReturn gst_clock_id_wait (GstClockID id, GstClockTimeDiff * jitter);
658 * gst_scheduler_clock_wait:
659 * @sched: the scheduler
660 * @element: the element that wants to wait
661 * @id: the clockid to use
662 * @jitter: the time difference between requested time and actual time
664 * Wait till the clock reaches a specific time. The ClockID can
665 * be obtained from #gst_clock_new_single_shot_id.
667 * Returns: the status of the operation
670 gst_scheduler_clock_wait (GstScheduler * sched, GstElement * element,
671 GstClockID id, GstClockTimeDiff * jitter)
673 GstSchedulerClass *sclass;
675 g_return_val_if_fail (GST_IS_SCHEDULER (sched), GST_CLOCK_ERROR);
676 g_return_val_if_fail (id != NULL, GST_CLOCK_ERROR);
678 sclass = GST_SCHEDULER_GET_CLASS (sched);
680 if (sclass->clock_wait)
681 return sclass->clock_wait (sched, element, id, jitter);
683 return gst_clock_id_wait (id, jitter);
687 * gst_scheduler_iterate:
688 * @sched: the scheduler
690 * Perform one iteration on the scheduler.
692 * Returns: a boolean indicating something usefull has happened.
695 gst_scheduler_iterate (GstScheduler * sched)
697 GstSchedulerClass *sclass;
698 gboolean res = FALSE;
700 g_return_val_if_fail (GST_IS_SCHEDULER (sched), FALSE);
702 sclass = GST_SCHEDULER_GET_CLASS (sched);
704 if (sclass->iterate) {
705 res = sclass->iterate (sched);
713 * gst_scheduler_show:
714 * @sched: the scheduler
716 * Dump the state of the scheduler
719 gst_scheduler_show (GstScheduler * sched)
721 GstSchedulerClass *sclass;
723 g_return_if_fail (GST_IS_SCHEDULER (sched));
725 sclass = GST_SCHEDULER_GET_CLASS (sched);
728 sclass->show (sched);
732 * Factory stuff starts here
735 static void gst_scheduler_factory_class_init (GstSchedulerFactoryClass * klass);
736 static void gst_scheduler_factory_init (GstSchedulerFactory * factory);
738 static GstPluginFeatureClass *factory_parent_class = NULL;
740 /* static guint gst_scheduler_factory_signals[LAST_SIGNAL] = { 0 }; */
743 gst_scheduler_factory_get_type (void)
745 static GType schedulerfactory_type = 0;
747 if (!schedulerfactory_type) {
748 static const GTypeInfo schedulerfactory_info = {
749 sizeof (GstSchedulerFactoryClass),
752 (GClassInitFunc) gst_scheduler_factory_class_init,
755 sizeof (GstSchedulerFactory),
757 (GInstanceInitFunc) gst_scheduler_factory_init,
761 schedulerfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
762 "GstSchedulerFactory", &schedulerfactory_info, 0);
764 return schedulerfactory_type;
768 gst_scheduler_factory_class_init (GstSchedulerFactoryClass * klass)
770 GObjectClass *gobject_class;
771 GstObjectClass *gstobject_class;
772 GstPluginFeatureClass *gstpluginfeature_class;
774 gobject_class = (GObjectClass *) klass;
775 gstobject_class = (GstObjectClass *) klass;
776 gstpluginfeature_class = (GstPluginFeatureClass *) klass;
778 factory_parent_class = g_type_class_ref (GST_TYPE_PLUGIN_FEATURE);
780 if (!_default_name) {
781 if (g_getenv ("GST_SCHEDULER")) {
782 _default_name = g_strdup (g_getenv ("GST_SCHEDULER"));
784 _default_name = g_strdup (GST_SCHEDULER_DEFAULT_NAME);
787 g_assert (_default_name);
791 gst_scheduler_factory_init (GstSchedulerFactory * factory)
797 * gst_scheduler_register:
798 * @plugin: a #GstPlugin
799 * @name: name of the scheduler to register
800 * @longdesc: description of the scheduler
801 * @type: #GType of the scheduler to register
803 * Registers a scheduler with GStreamer.
805 * Returns: TRUE, if the registering succeeded, FALSE on error.
810 gst_scheduler_register (GstPlugin * plugin, const gchar * name,
811 const gchar * longdesc, GType type)
813 GstSchedulerFactory *factory;
815 g_return_val_if_fail (plugin != NULL, FALSE);
816 g_return_val_if_fail (name != NULL, FALSE);
817 g_return_val_if_fail (longdesc != NULL, FALSE);
818 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_SCHEDULER), FALSE);
820 factory = gst_scheduler_factory_find (name);
822 g_return_val_if_fail (factory->type == 0, FALSE);
823 g_free (factory->longdesc);
824 factory->longdesc = g_strdup (longdesc);
825 factory->type = type;
827 factory = gst_scheduler_factory_new (name, longdesc, type);
828 g_return_val_if_fail (factory, FALSE);
829 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
836 * gst_scheduler_factory_new:
837 * @name: name of schedulerfactory to create
838 * @longdesc: long description of schedulerfactory to create
839 * @type: the gtk type of the GstScheduler element of this factory
841 * Create a new schedulerfactory with the given parameters
843 * Returns: a new #GstSchedulerFactory.
845 GstSchedulerFactory *
846 gst_scheduler_factory_new (const gchar * name, const gchar * longdesc,
849 GstSchedulerFactory *factory;
851 g_return_val_if_fail (name != NULL, NULL);
853 factory = gst_scheduler_factory_find (name);
857 GST_SCHEDULER_FACTORY (g_object_new (GST_TYPE_SCHEDULER_FACTORY, NULL));
858 GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name);
860 g_free (factory->longdesc);
863 factory->longdesc = g_strdup (longdesc);
864 factory->type = type;
870 * gst_scheduler_factory_destroy:
871 * @factory: factory to destroy
873 * Removes the scheduler from the global list.
876 gst_scheduler_factory_destroy (GstSchedulerFactory * factory)
878 g_return_if_fail (factory != NULL);
880 /* we don't free the struct bacause someone might have a handle to it.. */
884 * gst_scheduler_factory_find:
885 * @name: name of schedulerfactory to find
887 * Search for an schedulerfactory of the given name.
889 * Returns: #GstSchedulerFactory if found, NULL otherwise
891 GstSchedulerFactory *
892 gst_scheduler_factory_find (const gchar * name)
894 GstPluginFeature *feature;
896 g_return_val_if_fail (name != NULL, NULL);
898 GST_DEBUG ("gstscheduler: find \"%s\"", name);
900 feature = gst_registry_pool_find_feature (name, GST_TYPE_SCHEDULER_FACTORY);
903 return GST_SCHEDULER_FACTORY (feature);
909 * gst_scheduler_factory_create:
910 * @factory: the factory used to create the instance
911 * @parent: the parent element of this scheduler
913 * Create a new #GstScheduler instance from the
914 * given schedulerfactory with the given parent. @parent will
915 * have its scheduler set to the returned #GstScheduler instance.
917 * Returns: A new #GstScheduler instance with a reference count of %1.
920 gst_scheduler_factory_create (GstSchedulerFactory * factory,
923 GstScheduler *sched = NULL;
925 g_return_val_if_fail (factory != NULL, NULL);
926 g_return_val_if_fail (GST_IS_ELEMENT (parent), NULL);
928 if (gst_plugin_feature_ensure_loaded (GST_PLUGIN_FEATURE (factory))) {
929 g_return_val_if_fail (factory->type != 0, NULL);
931 sched = GST_SCHEDULER (g_object_new (factory->type, NULL));
932 sched->parent = parent;
934 GST_ELEMENT_SCHED (parent) = sched;
936 /* let's refcount the scheduler */
937 gst_object_ref (GST_OBJECT (sched));
938 gst_object_sink (GST_OBJECT (sched));
945 * gst_scheduler_factory_make:
946 * @name: the name of the factory used to create the instance
947 * @parent: the parent element of this scheduler
949 * Create a new #GstScheduler instance from the
950 * schedulerfactory with the given name and parent. @parent will
951 * have its scheduler set to the returned #GstScheduler instance.
952 * If %NULL is passed as @name, the default scheduler name will
955 * Returns: A new #GstScheduler instance with a reference count of %1.
958 gst_scheduler_factory_make (const gchar * name, GstElement * parent)
960 GstSchedulerFactory *factory;
961 const gchar *default_name = gst_scheduler_factory_get_default_name ();
964 factory = gst_scheduler_factory_find (name);
966 /* FIXME: do better error handling */
967 if (default_name == NULL)
968 g_error ("No default scheduler name - do you have a registry ?");
969 factory = gst_scheduler_factory_find (default_name);
975 return gst_scheduler_factory_create (factory, parent);
979 * gst_scheduler_factory_set_default_name:
980 * @name: the name of the factory used as a default
982 * Set the default schedulerfactory name.
985 gst_scheduler_factory_set_default_name (const gchar * name)
987 g_free (_default_name);
989 _default_name = g_strdup (name);
993 * gst_scheduler_factory_get_default_name:
995 * Get the default schedulerfactory name.
997 * Returns: the name of the default scheduler.
1000 gst_scheduler_factory_get_default_name (void)
1002 return _default_name;