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,
57 _gst_scheduler_type = g_type_register_static (GST_TYPE_OBJECT, "GstScheduler",
58 &scheduler_info, G_TYPE_FLAG_ABSTRACT);
60 return _gst_scheduler_type;
64 gst_scheduler_class_init (GstSchedulerClass *klass)
66 GObjectClass *gobject_class;
68 gobject_class = (GObjectClass*) klass;
70 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
72 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_scheduler_dispose);
76 gst_scheduler_init (GstScheduler *sched)
78 sched->clock_providers = NULL;
79 sched->clock_receivers = NULL;
80 sched->schedulers = NULL;
81 sched->state = GST_SCHEDULER_STATE_NONE;
83 sched->parent_sched = NULL;
88 gst_scheduler_dispose (GObject *object)
90 GstScheduler *sched = GST_SCHEDULER (object);
92 /* thse lists should all be NULL */
93 GST_DEBUG (0, "scheduler %p dispose %p %p %p",
95 sched->clock_providers,
96 sched->clock_receivers,
99 gst_object_replace ((GstObject **)&sched->current_clock, NULL);
100 gst_object_replace ((GstObject **)&sched->clock, NULL);
102 G_OBJECT_CLASS (parent_class)->dispose (object);
106 * gst_scheduler_setup:
107 * @sched: the scheduler
109 * Prepare the scheduler.
112 gst_scheduler_setup (GstScheduler *sched)
114 GstSchedulerClass *sclass;
116 g_return_if_fail (GST_IS_SCHEDULER (sched));
118 sclass = GST_SCHEDULER_GET_CLASS (sched);
121 sclass->setup (sched);
125 * gst_scheduler_reset:
126 * @sched: a #GstScheduler to reset.
128 * Reset the schedulers.
131 gst_scheduler_reset (GstScheduler *sched)
133 GstSchedulerClass *sclass;
135 g_return_if_fail (GST_IS_SCHEDULER (sched));
137 sclass = GST_SCHEDULER_GET_CLASS (sched);
140 sclass->reset (sched);
144 * gst_scheduler_pad_link:
145 * @sched: the scheduler
146 * @srcpad: the srcpad to link
147 * @sinkpad: the sinkpad to link to
149 * Links the srcpad to the given sinkpad.
152 gst_scheduler_pad_link (GstScheduler *sched, GstPad *srcpad, GstPad *sinkpad)
154 GstSchedulerClass *sclass;
156 g_return_if_fail (GST_IS_SCHEDULER (sched));
157 g_return_if_fail (GST_IS_PAD (srcpad));
158 g_return_if_fail (GST_IS_PAD (sinkpad));
160 sclass = GST_SCHEDULER_GET_CLASS (sched);
162 if (sclass->pad_link)
163 sclass->pad_link (sched, srcpad, sinkpad);
167 * gst_scheduler_pad_unlink:
168 * @sched: the scheduler
169 * @srcpad: the srcpad to unlink
170 * @sinkpad: the sinkpad to unlink from
172 * Unlinks the srcpad from the given sinkpad.
175 gst_scheduler_pad_unlink (GstScheduler *sched, GstPad *srcpad, GstPad *sinkpad)
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 GstSchedulerClass *sclass;
203 g_return_val_if_fail (GST_IS_SCHEDULER (sched), NULL);
204 g_return_val_if_fail (padlist != NULL, NULL);
206 sclass = GST_SCHEDULER_GET_CLASS (sched);
208 if (sclass->pad_select)
209 sclass->pad_select (sched, padlist);
215 * gst_scheduler_add_element:
216 * @sched: the scheduler
217 * @element: the element to add to the scheduler
219 * Add an element to the scheduler.
222 gst_scheduler_add_element (GstScheduler *sched, GstElement *element)
224 GstSchedulerClass *sclass;
226 g_return_if_fail (GST_IS_SCHEDULER (sched));
227 g_return_if_fail (GST_IS_ELEMENT (element));
229 /* if it's already in this scheduler, don't bother doing anything */
230 if (GST_ELEMENT_SCHED (element) == sched) {
231 GST_DEBUG (GST_CAT_SCHEDULING, "element %s already in scheduler %p",
232 GST_ELEMENT_NAME (element), sched);
236 /* if it's not inside this scheduler, it has to be NULL */
237 g_assert (GST_ELEMENT_SCHED (element) == NULL);
239 if (gst_element_provides_clock (element)) {
240 sched->clock_providers = g_list_prepend (sched->clock_providers, element);
241 GST_DEBUG (GST_CAT_CLOCK, "added clock provider %s", GST_ELEMENT_NAME (element));
243 if (gst_element_requires_clock (element)) {
244 sched->clock_receivers = g_list_prepend (sched->clock_receivers, element);
245 GST_DEBUG (GST_CAT_CLOCK, "added clock receiver %s", GST_ELEMENT_NAME (element));
248 gst_element_set_scheduler (element, sched);
250 sclass = GST_SCHEDULER_GET_CLASS (sched);
252 if (sclass->add_element)
253 sclass->add_element (sched, element);
257 * gst_scheduler_remove_element:
258 * @sched: the scheduler
259 * @element: the element to remove
261 * Remove an element from the scheduler.
264 gst_scheduler_remove_element (GstScheduler *sched, GstElement *element)
266 GstSchedulerClass *sclass;
268 g_return_if_fail (GST_IS_SCHEDULER (sched));
269 g_return_if_fail (GST_IS_ELEMENT (element));
271 sched->clock_providers = g_list_remove (sched->clock_providers, element);
272 sched->clock_receivers = g_list_remove (sched->clock_receivers, element);
274 sclass = GST_SCHEDULER_GET_CLASS (sched);
276 if (sclass->remove_element)
277 sclass->remove_element (sched, element);
279 gst_element_set_scheduler (element, NULL);
283 * gst_scheduler_state_transition:
284 * @sched: the scheduler
285 * @element: the element with the state transition
286 * @transition: the state transition
288 * Tell the scheduler that an element changed its state.
290 * Returns: a GstElementStateReturn indicating success or failure
291 * of the state transition.
293 GstElementStateReturn
294 gst_scheduler_state_transition (GstScheduler *sched, GstElement *element, gint transition)
296 GstSchedulerClass *sclass;
298 g_return_val_if_fail (GST_IS_SCHEDULER (sched), GST_STATE_FAILURE);
299 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_FAILURE);
301 if (element == sched->parent && sched->parent_sched == NULL) {
302 switch (transition) {
303 case GST_STATE_READY_TO_PAUSED:
305 GstClock *clock = gst_scheduler_get_clock (sched);
308 gst_clock_reset (clock);
310 GST_DEBUG (GST_CAT_CLOCK, "scheduler READY to PAUSED clock is %p (%s)", clock,
311 (clock ? GST_OBJECT_NAME (clock) : "nil"));
313 gst_object_replace ((GstObject **)&sched->current_clock, (GstObject *)clock);
316 case GST_STATE_PAUSED_TO_PLAYING:
318 GstClock *clock = gst_scheduler_get_clock (sched);
320 GST_DEBUG (GST_CAT_CLOCK, "scheduler PAUSED to PLAYING clock is %p (%s)", clock,
321 (clock ? GST_OBJECT_NAME (clock) : "nil"));
323 gst_scheduler_set_clock (sched, clock);
325 GST_DEBUG (GST_CAT_CLOCK, "enabling clock %p (%s)", clock,
326 GST_OBJECT_NAME (clock));
327 gst_clock_set_active (clock, TRUE);
331 case GST_STATE_PLAYING_TO_PAUSED:
332 if (sched->current_clock) {
333 GST_DEBUG (GST_CAT_CLOCK, "disabling clock %p (%s)", sched->current_clock,
334 GST_OBJECT_NAME (sched->current_clock));
335 gst_clock_set_active (sched->current_clock, FALSE);
341 sclass = GST_SCHEDULER_GET_CLASS (sched);
343 if (sclass->state_transition)
344 return sclass->state_transition (sched, element, transition);
346 return GST_STATE_SUCCESS;
350 * gst_scheduler_scheduling_change:
351 * @sched: the scheduler
352 * @element: the element that changed its scheduling strategy
354 * Tell the scheduler that an element changed its scheduling strategy.
355 * An element could, for example, change its loop function or changes
356 * from a loop based element to a chain based element.
359 gst_scheduler_scheduling_change (GstScheduler *sched, GstElement *element)
361 GstSchedulerClass *sclass;
363 g_return_if_fail (GST_IS_SCHEDULER (sched));
364 g_return_if_fail (GST_IS_ELEMENT (element));
366 sclass = GST_SCHEDULER_GET_CLASS (sched);
368 if (sclass->scheduling_change)
369 sclass->scheduling_change (sched, element);
373 * gst_scheduler_add_scheduler:
374 * @sched: a #GstScheduler to add to
375 * @sched2: the #GstScheduler to add
377 * Notifies the scheduler that it has to monitor this scheduler.
380 gst_scheduler_add_scheduler (GstScheduler *sched, GstScheduler *sched2)
382 GstSchedulerClass *sclass;
384 g_return_if_fail (GST_IS_SCHEDULER (sched));
385 g_return_if_fail (GST_IS_SCHEDULER (sched2));
386 g_return_if_fail (sched2->parent_sched == NULL);
388 GST_DEBUG (0,"gstscheduler: %p add scheduler %p", sched, sched2);
390 gst_object_ref (GST_OBJECT (sched2));
391 gst_object_ref (GST_OBJECT (sched));
393 sched->schedulers = g_list_prepend (sched->schedulers, sched2);
394 sched2->parent_sched = sched;
396 sclass = GST_SCHEDULER_GET_CLASS (sched);
398 if (sclass->add_scheduler)
399 sclass->add_scheduler (sched, sched2);
403 * gst_scheduler_remove_scheduler:
404 * @sched: the scheduler
405 * @sched2: the scheduler to remove
407 a Notifies the scheduler that it can stop monitoring this scheduler.
410 gst_scheduler_remove_scheduler (GstScheduler *sched, GstScheduler *sched2)
412 GstSchedulerClass *sclass;
414 g_return_if_fail (GST_IS_SCHEDULER (sched));
415 g_return_if_fail (GST_IS_SCHEDULER (sched2));
416 g_return_if_fail (sched2->parent_sched == sched);
418 GST_DEBUG (0,"gstscheduler: %p remove scheduler %p", sched, sched2);
420 sclass = GST_SCHEDULER_GET_CLASS (sched);
422 if (sclass->remove_scheduler)
423 sclass->remove_scheduler (sched, sched2);
425 sched->schedulers = g_list_remove (sched->schedulers, sched2);
426 sched2->parent_sched = NULL;
428 gst_object_unref (GST_OBJECT (sched2));
429 gst_object_unref (GST_OBJECT (sched));
433 * gst_scheduler_lock_element:
434 * @sched: the scheduler
435 * @element: the element to lock
437 * Acquire a lock on the given element in the given scheduler.
440 gst_scheduler_lock_element (GstScheduler *sched, GstElement *element)
442 GstSchedulerClass *sclass;
444 g_return_if_fail (GST_IS_SCHEDULER (sched));
445 g_return_if_fail (GST_IS_ELEMENT (element));
447 sclass = GST_SCHEDULER_GET_CLASS (sched);
449 if (sclass->lock_element)
450 sclass->lock_element (sched, element);
454 * gst_scheduler_unlock_element:
455 * @sched: the scheduler
456 * @element: the element to unlock
458 * Release the lock on the given element in the given scheduler.
461 gst_scheduler_unlock_element (GstScheduler *sched, GstElement *element)
463 GstSchedulerClass *sclass;
465 g_return_if_fail (GST_IS_SCHEDULER (sched));
466 g_return_if_fail (GST_IS_ELEMENT (element));
468 sclass = GST_SCHEDULER_GET_CLASS (sched);
470 if (sclass->unlock_element)
471 sclass->unlock_element (sched, element);
475 * gst_scheduler_error:
476 * @sched: the scheduler
477 * @element: the element with the error
479 * Tell the scheduler an element was in error
482 gst_scheduler_error (GstScheduler *sched, GstElement *element)
484 GstSchedulerClass *sclass;
486 g_return_if_fail (GST_IS_SCHEDULER (sched));
487 g_return_if_fail (GST_IS_ELEMENT (element));
489 sclass = GST_SCHEDULER_GET_CLASS (sched);
492 sclass->error (sched, element);
496 * gst_scheduler_yield:
497 * @sched: the scheduler
498 * @element: the element requesting a yield
500 * Tell the scheduler to schedule another element.
502 * Returns: TRUE if the element should save its state, FALSE
503 * if the scheduler can perform this action itself.
506 gst_scheduler_yield (GstScheduler *sched, GstElement *element)
508 GstSchedulerClass *sclass;
510 g_return_val_if_fail (GST_IS_SCHEDULER (sched), TRUE);
511 g_return_val_if_fail (GST_IS_ELEMENT (element), TRUE);
513 sclass = GST_SCHEDULER_GET_CLASS (sched);
516 return sclass->yield (sched, element);
522 * gst_scheduler_interrupt:
523 * @sched: the scheduler
524 * @element: the element requesting an interrupt
526 * Tell the scheduler to interrupt execution of this element.
528 * Returns: TRUE if the element should return NULL from the chain/get
532 gst_scheduler_interrupt (GstScheduler *sched, GstElement *element)
534 GstSchedulerClass *sclass;
536 g_return_val_if_fail (GST_IS_SCHEDULER (sched), FALSE);
537 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
539 sclass = GST_SCHEDULER_GET_CLASS (sched);
541 if (sclass->interrupt)
542 return sclass->interrupt (sched, element);
548 * gst_scheduler_get_clock:
549 * @sched: the scheduler
551 * Get the current clock used by the scheduler
553 * Returns: a GstClock
556 gst_scheduler_get_clock (GstScheduler *sched)
558 GstClock *clock = NULL;
560 /* if we have a fixed clock, use that one */
561 if (GST_FLAG_IS_SET (sched, GST_SCHEDULER_FLAG_FIXED_CLOCK)) {
562 clock = sched->clock;
564 GST_DEBUG (GST_CAT_CLOCK, "scheduler using fixed clock %p (%s)", clock,
565 (clock ? GST_OBJECT_NAME (clock) : "nil"));
568 GList *schedulers = sched->schedulers;
569 GList *providers = sched->clock_providers;
571 /* try to get a clock from one of the schedulers we manage first */
573 GstScheduler *scheduler = GST_SCHEDULER (schedulers->data);
575 clock = gst_scheduler_get_clock (scheduler);
579 schedulers = g_list_next (schedulers);
581 /* still no clock, try to find one in the providers */
582 while (!clock && providers) {
583 clock = gst_element_get_clock (GST_ELEMENT (providers->data));
585 providers = g_list_next (providers);
587 /* still no clock, use a system clock */
588 if (!clock && sched->parent_sched == NULL) {
589 clock = gst_system_clock_obtain ();
592 GST_DEBUG (GST_CAT_CLOCK, "scheduler selected clock %p (%s)", clock,
593 (clock ? GST_OBJECT_NAME (clock) : "nil"));
599 * gst_scheduler_use_clock:
600 * @sched: the scheduler
601 * @clock: the clock to use
603 * Force the scheduler to use the given clock. The scheduler will
604 * always use the given clock even if new clock providers are added
608 gst_scheduler_use_clock (GstScheduler *sched, GstClock *clock)
610 g_return_if_fail (sched != NULL);
611 g_return_if_fail (GST_IS_SCHEDULER (sched));
613 GST_FLAG_SET (sched, GST_SCHEDULER_FLAG_FIXED_CLOCK);
615 gst_object_replace ((GstObject **)&sched->clock, (GstObject *)clock);
617 GST_DEBUG (GST_CAT_CLOCK, "scheduler using fixed clock %p (%s)", clock,
618 (clock ? GST_OBJECT_NAME (clock) : "nil"));
622 * gst_scheduler_set_clock:
623 * @sched: the scheduler
624 * @clock: the clock to set
626 * Set the clock for the scheduler. The clock will be distributed
627 * to all the elements managed by the scheduler.
630 gst_scheduler_set_clock (GstScheduler *sched, GstClock *clock)
635 g_return_if_fail (sched != NULL);
636 g_return_if_fail (GST_IS_SCHEDULER (sched));
638 receivers = sched->clock_receivers;
639 schedulers = sched->schedulers;
641 gst_object_replace ((GstObject **)&sched->current_clock, (GstObject *)clock);
644 GstElement *element = GST_ELEMENT (receivers->data);
646 GST_DEBUG (GST_CAT_CLOCK, "scheduler setting clock %p (%s) on element %s", clock,
647 (clock ? GST_OBJECT_NAME (clock) : "nil"), GST_ELEMENT_NAME (element));
649 gst_element_set_clock (element, clock);
650 receivers = g_list_next (receivers);
653 GstScheduler *scheduler = GST_SCHEDULER (schedulers->data);
655 GST_DEBUG (GST_CAT_CLOCK, "scheduler setting clock %p (%s) on scheduler %p", clock,
656 (clock ? GST_OBJECT_NAME (clock) : "nil"), scheduler);
657 gst_scheduler_set_clock (scheduler, clock);
658 schedulers = g_list_next (schedulers);
663 * gst_scheduler_auto_clock:
664 * @sched: the scheduler
666 * Let the scheduler select a clock automatically.
669 gst_scheduler_auto_clock (GstScheduler *sched)
671 g_return_if_fail (sched != NULL);
672 g_return_if_fail (GST_IS_SCHEDULER (sched));
674 GST_FLAG_UNSET (sched, GST_SCHEDULER_FLAG_FIXED_CLOCK);
676 gst_object_replace ((GstObject **)&sched->clock, NULL);
678 GST_DEBUG (GST_CAT_CLOCK, "scheduler using automatic clock");
682 * gst_scheduler_clock_wait:
683 * @sched: the scheduler
684 * @element: the element that wants to wait
685 * @id: the clockid to use
686 * @jitter: the time difference between requested time and actual time
688 * Wait till the clock reaches a specific time. The ClockID can
689 * be obtained from #gst_clock_new_single_shot_id.
691 * Returns: the status of the operation
694 gst_scheduler_clock_wait (GstScheduler *sched, GstElement *element,
695 GstClockID id, GstClockTimeDiff *jitter)
697 GstSchedulerClass *sclass;
699 g_return_val_if_fail (GST_IS_SCHEDULER (sched), GST_CLOCK_ERROR);
700 g_return_val_if_fail (id != NULL, GST_CLOCK_ERROR);
702 sclass = GST_SCHEDULER_GET_CLASS (sched);
704 if (sclass->clock_wait)
705 return sclass->clock_wait (sched, element, id, jitter);
707 return gst_clock_id_wait (id, jitter);
711 * gst_scheduler_iterate:
712 * @sched: the scheduler
714 * Perform one iteration on the scheduler.
716 * Returns: a boolean indicating something usefull has happened.
719 gst_scheduler_iterate (GstScheduler *sched)
721 GstSchedulerClass *sclass;
722 gboolean res = FALSE;
724 g_return_val_if_fail (GST_IS_SCHEDULER (sched), FALSE);
726 sclass = GST_SCHEDULER_GET_CLASS (sched);
728 if (sclass->iterate) {
729 res = sclass->iterate (sched);
737 * gst_scheduler_show:
738 * @sched: the scheduler
740 * Dump the state of the scheduler
743 gst_scheduler_show (GstScheduler *sched)
745 GstSchedulerClass *sclass;
747 g_return_if_fail (GST_IS_SCHEDULER (sched));
749 sclass = GST_SCHEDULER_GET_CLASS (sched);
752 sclass->show (sched);
756 * Factory stuff starts here
759 static void gst_scheduler_factory_class_init (GstSchedulerFactoryClass *klass);
760 static void gst_scheduler_factory_init (GstSchedulerFactory *factory);
762 static GstPluginFeatureClass *factory_parent_class = NULL;
763 /* static guint gst_scheduler_factory_signals[LAST_SIGNAL] = { 0 }; */
766 gst_scheduler_factory_get_type (void)
768 static GType schedulerfactory_type = 0;
770 if (!schedulerfactory_type) {
771 static const GTypeInfo schedulerfactory_info = {
772 sizeof (GstSchedulerFactoryClass),
775 (GClassInitFunc) gst_scheduler_factory_class_init,
778 sizeof(GstSchedulerFactory),
780 (GInstanceInitFunc) gst_scheduler_factory_init,
783 schedulerfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
784 "GstSchedulerFactory", &schedulerfactory_info, 0);
786 return schedulerfactory_type;
790 gst_scheduler_factory_class_init (GstSchedulerFactoryClass *klass)
792 GObjectClass *gobject_class;
793 GstObjectClass *gstobject_class;
794 GstPluginFeatureClass *gstpluginfeature_class;
796 gobject_class = (GObjectClass*)klass;
797 gstobject_class = (GstObjectClass*)klass;
798 gstpluginfeature_class = (GstPluginFeatureClass*) klass;
800 factory_parent_class = g_type_class_ref (GST_TYPE_PLUGIN_FEATURE);
803 _default_name = g_strdup (GST_SCHEDULER_DEFAULT_NAME);
807 gst_scheduler_factory_init (GstSchedulerFactory *factory)
813 * gst_scheduler_factory_new:
814 * @name: name of schedulerfactory to create
815 * @longdesc: long description of schedulerfactory to create
816 * @type: the gtk type of the GstScheduler element of this factory
818 * Create a new schedulerfactory with the given parameters
820 * Returns: a new #GstSchedulerFactory.
823 gst_scheduler_factory_new (const gchar *name, const gchar *longdesc, GType type)
825 GstSchedulerFactory *factory;
827 g_return_val_if_fail (name != NULL, NULL);
829 factory = gst_scheduler_factory_find (name);
832 factory = GST_SCHEDULER_FACTORY (g_object_new (GST_TYPE_SCHEDULER_FACTORY, NULL));
833 GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name);
836 g_free (factory->longdesc);
839 factory->longdesc = g_strdup (longdesc);
840 factory->type = type;
846 * gst_scheduler_factory_destroy:
847 * @factory: factory to destroy
849 * Removes the scheduler from the global list.
852 gst_scheduler_factory_destroy (GstSchedulerFactory *factory)
854 g_return_if_fail (factory != NULL);
856 /* we don't free the struct bacause someone might have a handle to it.. */
860 * gst_scheduler_factory_find:
861 * @name: name of schedulerfactory to find
863 * Search for an schedulerfactory of the given name.
865 * Returns: #GstSchedulerFactory if found, NULL otherwise
868 gst_scheduler_factory_find (const gchar *name)
870 GstPluginFeature *feature;
872 g_return_val_if_fail (name != NULL, NULL);
874 GST_DEBUG (0,"gstscheduler: find \"%s\"", name);
876 feature = gst_registry_pool_find_feature (name, GST_TYPE_SCHEDULER_FACTORY);
879 return GST_SCHEDULER_FACTORY (feature);
885 * gst_scheduler_factory_create:
886 * @factory: the factory used to create the instance
887 * @parent: the parent element of this scheduler
889 * Create a new #GstScheduler instance from the
890 * given schedulerfactory with the given parent. @parent will
891 * have its scheduler set to the returned #GstScheduler instance.
893 * Returns: A new #GstScheduler instance with a reference count of %1.
896 gst_scheduler_factory_create (GstSchedulerFactory *factory, GstElement *parent)
898 GstScheduler *sched = NULL;
900 g_return_val_if_fail (factory != NULL, NULL);
901 g_return_val_if_fail (GST_IS_ELEMENT (parent), NULL);
903 if (gst_plugin_feature_ensure_loaded (GST_PLUGIN_FEATURE (factory))) {
904 g_return_val_if_fail (factory->type != 0, NULL);
906 sched = GST_SCHEDULER (g_object_new (factory->type, NULL));
907 sched->parent = parent;
909 GST_ELEMENT_SCHED (parent) = sched;
911 /* let's refcount the scheduler */
912 gst_object_ref (GST_OBJECT (sched));
913 gst_object_sink (GST_OBJECT (sched));
920 * gst_scheduler_factory_make:
921 * @name: the name of the factory used to create the instance
922 * @parent: the parent element of this scheduler
924 * Create a new #GstScheduler instance from the
925 * schedulerfactory with the given name and parent. @parent will
926 * have its scheduler set to the returned #GstScheduler instance.
927 * If %NULL is passed as @name, the default scheduler name will
930 * Returns: A new #GstScheduler instance with a reference count of %1.
933 gst_scheduler_factory_make (const gchar *name, GstElement *parent)
935 GstSchedulerFactory *factory;
936 const gchar *default_name = gst_scheduler_factory_get_default_name ();
939 factory = gst_scheduler_factory_find (name);
942 /* FIXME: do better error handling */
943 if (default_name == NULL)
944 g_error ("No default scheduler name - do you have a registry ?");
945 factory = gst_scheduler_factory_find (default_name);
951 return gst_scheduler_factory_create (factory, parent);
955 * gst_scheduler_factory_set_default_name:
956 * @name: the name of the factory used as a default
958 * Set the default schedulerfactory name.
961 gst_scheduler_factory_set_default_name (const gchar* name)
963 g_free (_default_name);
965 _default_name = g_strdup (name);
969 * gst_scheduler_factory_get_default_name:
971 * Get the default schedulerfactory name.
973 * Returns: the name of the default scheduler.
976 gst_scheduler_factory_get_default_name (void)
978 return _default_name;