2002-09-08 17:58:00 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstscheduler.c: Default scheduling code for most cases
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*#define GST_DEBUG_ENABLED */
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
|
|
|
# include "cothreads_compat.h"
|
|
|
|
#else
|
|
|
|
# define COTHREADS_NAME_CAPITAL ""
|
|
|
|
# define COTHREADS_NAME ""
|
|
|
|
#endif
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
#define GST_ELEMENT_SCHED_CONTEXT(elem) ((GstOptSchedulerCtx*) (GST_ELEMENT_CAST (elem)->sched_private))
|
|
|
|
#define GST_ELEMENT_SCHED_GROUP(elem) (GST_ELEMENT_SCHED_CONTEXT (elem)->group)
|
2002-09-12 19:22:03 +00:00
|
|
|
#define GST_PAD_BUFLIST(pad) ((GList*) (GST_REAL_PAD_CAST(pad)->sched_private))
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
#define GST_ELEMENT_COTHREAD_STOPPING GST_ELEMENT_SCHEDULER_PRIVATE1
|
|
|
|
#define GST_ELEMENT_IS_COTHREAD_STOPPING(element) GST_FLAG_IS_SET((element), GST_ELEMENT_COTHREAD_STOPPING)
|
|
|
|
#define GST_ELEMENT_INTERRUPTED GST_ELEMENT_SCHEDULER_PRIVATE2
|
|
|
|
#define GST_ELEMENT_IS_INTERRUPTED(element) GST_FLAG_IS_SET((element), GST_ELEMENT_INTERRUPTED)
|
|
|
|
|
|
|
|
typedef struct _GstOptScheduler GstOptScheduler;
|
|
|
|
typedef struct _GstOptSchedulerClass GstOptSchedulerClass;
|
|
|
|
|
|
|
|
#define GST_TYPE_OPT_SCHEDULER \
|
|
|
|
(gst_opt_scheduler_get_type())
|
|
|
|
#define GST_OPT_SCHEDULER(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OPT_SCHEDULER,GstOptScheduler))
|
|
|
|
#define GST_OPT_SCHEDULER_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OPT_SCHEDULER,GstOptSchedulerClass))
|
|
|
|
#define GST_IS_OPT_SCHEDULER(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OPT_SCHEDULER))
|
|
|
|
#define GST_IS_OPT_SCHEDULER_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OPT_SCHEDULER))
|
|
|
|
|
|
|
|
#define GST_OPT_SCHEDULER_CAST(sched) ((GstOptScheduler *)(sched))
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GST_OPT_SCHEDULER_STATE_NONE,
|
|
|
|
GST_OPT_SCHEDULER_STATE_STOPPED,
|
|
|
|
GST_OPT_SCHEDULER_STATE_ERROR,
|
|
|
|
GST_OPT_SCHEDULER_STATE_RUNNING,
|
2003-01-08 21:33:20 +00:00
|
|
|
GST_OPT_SCHEDULER_STATE_INTERRUPTED
|
2002-09-08 17:58:00 +00:00
|
|
|
} GstOptSchedulerState;
|
|
|
|
|
|
|
|
struct _GstOptScheduler {
|
2002-09-12 19:22:03 +00:00
|
|
|
GstScheduler parent;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
GstOptSchedulerState state;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
2002-09-12 19:22:03 +00:00
|
|
|
cothread_context *context;
|
2002-12-15 18:21:43 +00:00
|
|
|
#endif
|
2002-09-12 19:22:03 +00:00
|
|
|
gint iterations;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
GSList *elements;
|
|
|
|
GSList *chains;
|
|
|
|
|
|
|
|
GList *runqueue;
|
|
|
|
gint recursion;
|
2003-01-01 04:28:33 +00:00
|
|
|
|
|
|
|
gint max_recursion;
|
2002-09-08 17:58:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstOptSchedulerClass {
|
|
|
|
GstSchedulerClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GType _gst_opt_scheduler_type = 0;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GST_OPT_SCHEDULER_CHAIN_DIRTY = (1 << 1),
|
|
|
|
GST_OPT_SCHEDULER_CHAIN_DISABLED = (1 << 2),
|
|
|
|
GST_OPT_SCHEDULER_CHAIN_RUNNING = (1 << 3),
|
|
|
|
} GstOptSchedulerChainFlags;
|
|
|
|
|
|
|
|
#define GST_OPT_SCHEDULER_CHAIN_DISABLE(chain) ((chain)->flags |= GST_OPT_SCHEDULER_CHAIN_DISABLED)
|
|
|
|
#define GST_OPT_SCHEDULER_CHAIN_ENABLE(chain) ((chain)->flags &= ~GST_OPT_SCHEDULER_CHAIN_DISABLED)
|
|
|
|
#define GST_OPT_SCHEDULER_CHAIN_IS_DISABLED(chain) ((chain)->flags & GST_OPT_SCHEDULER_CHAIN_DISABLED)
|
|
|
|
|
|
|
|
typedef struct _GstOptSchedulerChain GstOptSchedulerChain;
|
|
|
|
|
|
|
|
struct _GstOptSchedulerChain {
|
|
|
|
GstOptScheduler *sched;
|
|
|
|
|
|
|
|
GstOptSchedulerChainFlags flags;
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
GSList *groups; /* the groups in this chain */
|
2002-09-08 17:58:00 +00:00
|
|
|
gint num_groups;
|
|
|
|
gint num_enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* elements that are scheduled in one cothread
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
GST_OPT_SCHEDULER_GROUP_DIRTY = (1 << 1), /* this group has been modified */
|
|
|
|
GST_OPT_SCHEDULER_GROUP_COTHREAD_STOPPING = (1 << 2), /* the group's cothread stops after one iteration */
|
|
|
|
GST_OPT_SCHEDULER_GROUP_DISABLED = (1 << 3), /* this group is disabled */
|
|
|
|
GST_OPT_SCHEDULER_GROUP_RUNNING = (1 << 4), /* this group is running */
|
|
|
|
GST_OPT_SCHEDULER_GROUP_SCHEDULABLE = (1 << 5), /* this group is schedulable */
|
|
|
|
} GstOptSchedulerGroupFlags;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GST_OPT_SCHEDULER_GROUP_GET = 1,
|
|
|
|
GST_OPT_SCHEDULER_GROUP_LOOP = 2,
|
|
|
|
} GstOptSchedulerGroupType;
|
|
|
|
|
2002-12-16 21:21:02 +00:00
|
|
|
#define GST_OPT_SCHEDULER_GROUP_SET_FLAG(group,flag) ((group)->flags |= (flag))
|
|
|
|
#define GST_OPT_SCHEDULER_GROUP_UNSET_FLAG(group,flag) ((group)->flags &= (flag))
|
|
|
|
#define GST_OPT_SCHEDULER_GROUP_IS_FLAG_SET(group,flag) ((group)->flags & (flag))
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
#define GST_OPT_SCHEDULER_GROUP_DISABLE(group) ((group)->flags |= GST_OPT_SCHEDULER_GROUP_DISABLED)
|
|
|
|
#define GST_OPT_SCHEDULER_GROUP_ENABLE(group) ((group)->flags &= ~GST_OPT_SCHEDULER_GROUP_DISABLED)
|
2002-09-13 23:02:54 +00:00
|
|
|
#define GST_OPT_SCHEDULER_GROUP_IS_ENABLED(group) (!((group)->flags & GST_OPT_SCHEDULER_GROUP_DISABLED))
|
2002-09-08 17:58:00 +00:00
|
|
|
#define GST_OPT_SCHEDULER_GROUP_IS_DISABLED(group) ((group)->flags & GST_OPT_SCHEDULER_GROUP_DISABLED)
|
|
|
|
|
|
|
|
typedef struct _GstOptSchedulerGroup GstOptSchedulerGroup;
|
|
|
|
|
|
|
|
typedef int (*GroupScheduleFunction) (int argc, char *argv[]);
|
|
|
|
|
|
|
|
struct _GstOptSchedulerGroup {
|
|
|
|
GstOptSchedulerChain *chain; /* the chain this group belongs to */
|
|
|
|
GstOptSchedulerGroupFlags flags; /* flags for this group */
|
|
|
|
GstOptSchedulerGroupType type; /* flags for this group */
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
GSList *elements; /* elements of this group */
|
2002-09-08 17:58:00 +00:00
|
|
|
gint num_elements;
|
|
|
|
gint num_enabled;
|
|
|
|
GstElement *entry; /* the group's entry point */
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
GSList *providers; /* other groups that provide data
|
|
|
|
for this group */
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
2002-11-02 13:54:34 +00:00
|
|
|
cothread *cothread; /* the cothread of this group */
|
2002-12-15 18:21:43 +00:00
|
|
|
#endif
|
2002-09-08 17:58:00 +00:00
|
|
|
GroupScheduleFunction schedulefunc;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scheduler private data for an element
|
|
|
|
*/
|
|
|
|
typedef struct _GstOptSchedulerCtx GstOptSchedulerCtx;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GST_OPT_SCHEDULER_CTX_DISABLED = (1 << 1), /* the element is disabled */
|
|
|
|
} GstOptSchedulerCtxFlags;
|
|
|
|
|
|
|
|
struct _GstOptSchedulerCtx {
|
|
|
|
GstOptSchedulerGroup *group; /* the group this element belongs to */
|
|
|
|
|
|
|
|
GstOptSchedulerCtxFlags flags; /* flags for this element */
|
|
|
|
};
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_ITERATIONS,
|
2003-01-01 04:28:33 +00:00
|
|
|
ARG_MAX_RECURSION,
|
2002-09-12 19:22:03 +00:00
|
|
|
};
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
static void gst_opt_scheduler_class_init (GstOptSchedulerClass *klass);
|
|
|
|
static void gst_opt_scheduler_init (GstOptScheduler *scheduler);
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
static void gst_opt_scheduler_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_opt_scheduler_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
static void gst_opt_scheduler_dispose (GObject *object);
|
|
|
|
|
|
|
|
static void gst_opt_scheduler_setup (GstScheduler *sched);
|
|
|
|
static void gst_opt_scheduler_reset (GstScheduler *sched);
|
|
|
|
static void gst_opt_scheduler_add_element (GstScheduler *sched, GstElement *element);
|
|
|
|
static void gst_opt_scheduler_remove_element (GstScheduler *sched, GstElement *element);
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_opt_scheduler_state_transition (GstScheduler *sched, GstElement *element, gint transition);
|
2002-12-15 12:18:04 +00:00
|
|
|
static void gst_opt_scheduler_scheduling_change (GstScheduler *sched, GstElement *element);
|
2002-09-08 17:58:00 +00:00
|
|
|
static void gst_opt_scheduler_lock_element (GstScheduler *sched, GstElement *element);
|
|
|
|
static void gst_opt_scheduler_unlock_element (GstScheduler *sched, GstElement *element);
|
2003-01-11 16:27:45 +00:00
|
|
|
static gboolean gst_opt_scheduler_yield (GstScheduler *sched, GstElement *element);
|
2002-09-08 17:58:00 +00:00
|
|
|
static gboolean gst_opt_scheduler_interrupt (GstScheduler *sched, GstElement *element);
|
|
|
|
static void gst_opt_scheduler_error (GstScheduler *sched, GstElement *element);
|
2003-01-09 14:15:37 +00:00
|
|
|
static void gst_opt_scheduler_pad_link (GstScheduler *sched, GstPad *srcpad, GstPad *sinkpad);
|
|
|
|
static void gst_opt_scheduler_pad_unlink (GstScheduler *sched, GstPad *srcpad, GstPad *sinkpad);
|
2002-09-08 17:58:00 +00:00
|
|
|
static GstPad* gst_opt_scheduler_pad_select (GstScheduler *sched, GList *padlist);
|
|
|
|
static GstClockReturn gst_opt_scheduler_clock_wait (GstScheduler *sched, GstElement *element,
|
2002-12-27 22:57:13 +00:00
|
|
|
GstClockID id, GstClockTimeDiff *jitter);
|
2002-09-08 17:58:00 +00:00
|
|
|
static GstSchedulerState
|
|
|
|
gst_opt_scheduler_iterate (GstScheduler *sched);
|
|
|
|
|
|
|
|
static void gst_opt_scheduler_show (GstScheduler *sched);
|
|
|
|
|
|
|
|
static GstSchedulerClass *parent_class = NULL;
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gst_opt_scheduler_get_type (void)
|
|
|
|
{
|
|
|
|
if (!_gst_opt_scheduler_type) {
|
|
|
|
static const GTypeInfo scheduler_info = {
|
|
|
|
sizeof (GstOptSchedulerClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_opt_scheduler_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstOptScheduler),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_opt_scheduler_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-11-25 00:20:52 +00:00
|
|
|
_gst_opt_scheduler_type = g_type_register_static (GST_TYPE_SCHEDULER,
|
|
|
|
"GstOpt"COTHREADS_NAME_CAPITAL"Scheduler", &scheduler_info, 0);
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
return _gst_opt_scheduler_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_class_init (GstOptSchedulerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstObjectClass *gstobject_class;
|
|
|
|
GstSchedulerClass *gstscheduler_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstobject_class = (GstObjectClass*)klass;
|
|
|
|
gstscheduler_class = (GstSchedulerClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_SCHEDULER);
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_opt_scheduler_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_opt_scheduler_get_property);
|
2002-09-08 17:58:00 +00:00
|
|
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_opt_scheduler_dispose);
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ITERATIONS,
|
2003-01-01 04:28:33 +00:00
|
|
|
g_param_spec_int ("iterations", "Iterations",
|
|
|
|
"Number of groups to schedule in one iteration (-1 == until EOS/error)",
|
2002-09-12 19:22:03 +00:00
|
|
|
-1, G_MAXINT, 1, G_PARAM_READWRITE));
|
2003-01-01 04:28:33 +00:00
|
|
|
#ifndef USE_COTHREADS
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_RECURSION,
|
|
|
|
g_param_spec_int ("max_recursion", "Max recursion",
|
|
|
|
"Maximum number of recursions",
|
|
|
|
1, G_MAXINT, 100, G_PARAM_READWRITE));
|
|
|
|
#endif
|
2002-09-12 19:22:03 +00:00
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
gstscheduler_class->setup = GST_DEBUG_FUNCPTR (gst_opt_scheduler_setup);
|
|
|
|
gstscheduler_class->reset = GST_DEBUG_FUNCPTR (gst_opt_scheduler_reset);
|
|
|
|
gstscheduler_class->add_element = GST_DEBUG_FUNCPTR (gst_opt_scheduler_add_element);
|
|
|
|
gstscheduler_class->remove_element = GST_DEBUG_FUNCPTR (gst_opt_scheduler_remove_element);
|
|
|
|
gstscheduler_class->state_transition = GST_DEBUG_FUNCPTR (gst_opt_scheduler_state_transition);
|
2002-12-15 12:18:04 +00:00
|
|
|
gstscheduler_class->scheduling_change = GST_DEBUG_FUNCPTR (gst_opt_scheduler_scheduling_change);
|
2002-09-08 17:58:00 +00:00
|
|
|
gstscheduler_class->lock_element = GST_DEBUG_FUNCPTR (gst_opt_scheduler_lock_element);
|
|
|
|
gstscheduler_class->unlock_element = GST_DEBUG_FUNCPTR (gst_opt_scheduler_unlock_element);
|
|
|
|
gstscheduler_class->yield = GST_DEBUG_FUNCPTR (gst_opt_scheduler_yield);
|
|
|
|
gstscheduler_class->interrupt = GST_DEBUG_FUNCPTR (gst_opt_scheduler_interrupt);
|
|
|
|
gstscheduler_class->error = GST_DEBUG_FUNCPTR (gst_opt_scheduler_error);
|
2003-01-09 14:15:37 +00:00
|
|
|
gstscheduler_class->pad_link = GST_DEBUG_FUNCPTR (gst_opt_scheduler_pad_link);
|
|
|
|
gstscheduler_class->pad_unlink = GST_DEBUG_FUNCPTR (gst_opt_scheduler_pad_unlink);
|
2002-09-08 17:58:00 +00:00
|
|
|
gstscheduler_class->pad_select = GST_DEBUG_FUNCPTR (gst_opt_scheduler_pad_select);
|
|
|
|
gstscheduler_class->clock_wait = GST_DEBUG_FUNCPTR (gst_opt_scheduler_clock_wait);
|
|
|
|
gstscheduler_class->iterate = GST_DEBUG_FUNCPTR (gst_opt_scheduler_iterate);
|
|
|
|
gstscheduler_class->show = GST_DEBUG_FUNCPTR (gst_opt_scheduler_show);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_init (GstOptScheduler *scheduler)
|
|
|
|
{
|
|
|
|
scheduler->elements = NULL;
|
2002-09-12 19:22:03 +00:00
|
|
|
scheduler->iterations = 1;
|
2003-01-01 04:28:33 +00:00
|
|
|
scheduler->max_recursion = 100;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstSchedulerFactory *factory;
|
|
|
|
|
|
|
|
gst_plugin_set_longname (plugin, "An optimal scheduler");
|
|
|
|
|
2002-09-12 21:00:57 +00:00
|
|
|
factory = gst_scheduler_factory_new ("opt"COTHREADS_NAME,
|
|
|
|
"An optimal scheduler using "COTHREADS_NAME" cothreads",
|
2002-09-08 17:58:00 +00:00
|
|
|
gst_opt_scheduler_get_type());
|
|
|
|
|
|
|
|
if (factory != NULL) {
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g_warning ("could not register scheduler: optimal");
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2002-09-12 21:00:57 +00:00
|
|
|
"gstopt"COTHREADS_NAME"scheduler",
|
2002-09-08 17:58:00 +00:00
|
|
|
plugin_init
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-12-15 12:18:04 +00:00
|
|
|
delete_chain (GstOptSchedulerChain *chain)
|
2002-09-08 17:58:00 +00:00
|
|
|
{
|
2002-11-07 18:50:06 +00:00
|
|
|
GSList *groups;
|
2002-12-15 12:18:04 +00:00
|
|
|
GstOptScheduler *osched;
|
2002-11-07 18:50:06 +00:00
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "delete chain %p", chain);
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
osched = chain->sched;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
osched->chains = g_slist_remove (osched->chains, chain);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-11-07 18:50:06 +00:00
|
|
|
groups = chain->groups;
|
|
|
|
while (groups) {
|
|
|
|
GstOptSchedulerGroup *group = (GstOptSchedulerGroup *) groups->data;
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
/* clear all group's chain pointers, so they can never reference us again */
|
2002-12-15 12:18:04 +00:00
|
|
|
if (group->chain == chain)
|
|
|
|
group->chain = NULL;
|
2002-11-07 18:50:06 +00:00
|
|
|
|
|
|
|
groups = g_slist_next (groups);
|
|
|
|
}
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
g_slist_free (chain->groups);
|
2002-09-08 17:58:00 +00:00
|
|
|
g_free (chain);
|
|
|
|
}
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
static GstOptSchedulerChain*
|
2002-09-08 17:58:00 +00:00
|
|
|
add_to_chain (GstOptSchedulerChain *chain, GstOptSchedulerGroup *group)
|
|
|
|
{
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "adding group %p to chain %p", group, chain);
|
|
|
|
|
|
|
|
g_assert (group->chain == NULL);
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
chain->groups = g_slist_prepend (chain->groups, group);
|
2002-09-08 17:58:00 +00:00
|
|
|
group->chain = chain;
|
|
|
|
chain->num_groups++;
|
2002-12-15 12:18:04 +00:00
|
|
|
|
|
|
|
return chain;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstOptSchedulerChain*
|
|
|
|
create_chain (GstOptScheduler *osched)
|
|
|
|
{
|
|
|
|
GstOptSchedulerChain *chain;
|
|
|
|
|
|
|
|
chain = g_new0 (GstOptSchedulerChain, 1);
|
|
|
|
chain->sched = osched;
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
osched->chains = g_slist_prepend (osched->chains, chain);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "new chain %p", chain);
|
|
|
|
|
|
|
|
return chain;
|
|
|
|
}
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
static GstOptSchedulerChain*
|
2002-09-08 17:58:00 +00:00
|
|
|
remove_from_chain (GstOptSchedulerChain *chain, GstOptSchedulerGroup *group)
|
|
|
|
{
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "removing group %p from chain %p", group, chain);
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
if (!chain)
|
|
|
|
return NULL;
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
g_assert (group);
|
2002-09-08 17:58:00 +00:00
|
|
|
g_assert (group->chain == chain);
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
chain->groups = g_slist_remove (chain->groups, group);
|
2002-09-08 17:58:00 +00:00
|
|
|
chain->num_groups--;
|
|
|
|
|
|
|
|
group->chain = NULL;
|
2002-12-15 12:18:04 +00:00
|
|
|
|
|
|
|
if (chain->num_groups == 0) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "chain %p is empty, removing", chain);
|
|
|
|
delete_chain (chain);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return chain;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
static GstOptSchedulerChain*
|
2002-09-08 17:58:00 +00:00
|
|
|
merge_chains (GstOptSchedulerChain *chain1, GstOptSchedulerChain *chain2)
|
|
|
|
{
|
2002-09-08 22:42:29 +00:00
|
|
|
GSList *walk;
|
2002-12-15 12:18:04 +00:00
|
|
|
|
|
|
|
g_assert (chain1 != NULL);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "merging chain %p and %p", chain1, chain2);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
if (chain1 == chain2 || chain2 == NULL)
|
|
|
|
return chain1;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
walk = chain2->groups;
|
|
|
|
while (walk) {
|
|
|
|
GstOptSchedulerGroup *group = (GstOptSchedulerGroup *) walk->data;
|
2002-12-19 19:45:13 +00:00
|
|
|
walk = g_slist_next (walk);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
group->chain = NULL;
|
|
|
|
add_to_chain (chain1, group);
|
|
|
|
}
|
2002-12-15 12:18:04 +00:00
|
|
|
delete_chain (chain2);
|
|
|
|
|
|
|
|
return chain1;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chain_group_set_enabled (GstOptSchedulerChain *chain, GstOptSchedulerGroup *group, gboolean enabled)
|
|
|
|
{
|
2002-12-15 12:18:04 +00:00
|
|
|
g_assert (chain != NULL);
|
|
|
|
g_assert (group != NULL);
|
|
|
|
|
2003-01-01 04:28:33 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "request to %d group %p in chain %p, have %d groups enabled out of %d",
|
|
|
|
enabled, group, chain, chain->num_enabled, chain->num_groups);
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
GST_OPT_SCHEDULER_GROUP_ENABLE (group);
|
|
|
|
else
|
|
|
|
GST_OPT_SCHEDULER_GROUP_DISABLE (group);
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
if (enabled) {
|
2003-01-01 04:28:33 +00:00
|
|
|
if (chain->num_enabled < chain->num_groups)
|
|
|
|
chain->num_enabled++;
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "enable group %p in chain %p, now %d groups enabled out of %d", group, chain,
|
|
|
|
chain->num_enabled, chain->num_groups);
|
2003-01-01 04:28:33 +00:00
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
if (chain->num_enabled == chain->num_groups) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "enable chain %p", chain);
|
|
|
|
GST_OPT_SCHEDULER_CHAIN_ENABLE (chain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-01-01 04:28:33 +00:00
|
|
|
if (chain->num_enabled > 0)
|
|
|
|
chain->num_enabled--;
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "disable group %p in chain %p, now %d groups enabled out of %d", group, chain,
|
|
|
|
chain->num_enabled, chain->num_groups);
|
2003-01-01 04:28:33 +00:00
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
if (chain->num_enabled == 0) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "disable chain %p", chain);
|
|
|
|
GST_OPT_SCHEDULER_CHAIN_DISABLE (chain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
static GstOptSchedulerGroup*
|
2002-09-08 17:58:00 +00:00
|
|
|
add_to_group (GstOptSchedulerGroup *group, GstElement *element)
|
|
|
|
{
|
2002-12-15 12:18:04 +00:00
|
|
|
g_assert (group != NULL);
|
|
|
|
g_assert (element != NULL);
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "adding element \"%s\" to group %p", GST_ELEMENT_NAME (element), group);
|
|
|
|
|
|
|
|
if (GST_ELEMENT_IS_DECOUPLED (element)) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "element \"%s\" is decoupled, not adding to group %p", GST_ELEMENT_NAME (element), group);
|
2002-12-15 12:18:04 +00:00
|
|
|
return group;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (GST_ELEMENT_SCHED_GROUP (element) == NULL);
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
group->elements = g_slist_prepend (group->elements, element);
|
2002-09-08 17:58:00 +00:00
|
|
|
group->num_elements++;
|
|
|
|
|
|
|
|
GST_ELEMENT_SCHED_GROUP (element) = group;
|
2002-12-15 12:18:04 +00:00
|
|
|
|
|
|
|
return group;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstOptSchedulerGroup*
|
|
|
|
create_group (GstOptSchedulerChain *chain, GstElement *element)
|
|
|
|
{
|
|
|
|
GstOptSchedulerGroup *group;
|
|
|
|
|
|
|
|
group = g_new0 (GstOptSchedulerGroup, 1);
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "new group %p", group);
|
|
|
|
|
|
|
|
add_to_group (group, element);
|
|
|
|
add_to_chain (chain, group);
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_group_scheduler (GstOptSchedulerGroup *group)
|
|
|
|
{
|
2002-12-15 18:21:43 +00:00
|
|
|
g_assert (group);
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
if (group->flags & GST_OPT_SCHEDULER_GROUP_RUNNING)
|
|
|
|
g_warning ("removing running element");
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
2002-09-08 17:58:00 +00:00
|
|
|
if (group->cothread) {
|
|
|
|
do_cothread_destroy (group->cothread);
|
2002-12-15 22:02:20 +00:00
|
|
|
group->cothread = NULL;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
2002-12-15 22:02:20 +00:00
|
|
|
#else
|
|
|
|
group->schedulefunc = NULL;
|
|
|
|
group->argc = 0;
|
|
|
|
group->argv = NULL;
|
2002-12-15 18:21:43 +00:00
|
|
|
#endif
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
group->flags &= ~GST_OPT_SCHEDULER_GROUP_SCHEDULABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_group (GstOptSchedulerGroup *group)
|
|
|
|
{
|
2002-11-07 18:50:06 +00:00
|
|
|
GSList *elements;
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "delete group %p", group);
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
g_assert (group != NULL);
|
2002-09-08 17:58:00 +00:00
|
|
|
g_assert (group->chain == NULL);
|
|
|
|
|
|
|
|
if (group->flags & GST_OPT_SCHEDULER_GROUP_SCHEDULABLE)
|
|
|
|
destroy_group_scheduler (group);
|
|
|
|
|
2002-11-07 18:50:06 +00:00
|
|
|
/* remove all elements from the group */
|
|
|
|
elements = group->elements;
|
|
|
|
while (elements) {
|
|
|
|
GstElement *element = GST_ELEMENT (elements->data);
|
|
|
|
|
|
|
|
GST_ELEMENT_SCHED_GROUP (element) = NULL;
|
|
|
|
|
|
|
|
elements = g_slist_next (elements);
|
|
|
|
}
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
g_slist_free (group->elements);
|
2002-09-08 17:58:00 +00:00
|
|
|
g_free (group);
|
|
|
|
}
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
static GstOptSchedulerGroup*
|
2002-09-08 17:58:00 +00:00
|
|
|
remove_from_group (GstOptSchedulerGroup *group, GstElement *element)
|
|
|
|
{
|
2002-12-15 12:18:04 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "removing element \"%s\" from group %p", GST_ELEMENT_NAME (element), group);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
g_assert (group != NULL);
|
|
|
|
g_assert (element != NULL);
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
group->elements = g_slist_remove (group->elements, element);
|
2002-09-08 17:58:00 +00:00
|
|
|
group->num_elements--;
|
|
|
|
|
|
|
|
GST_ELEMENT_SCHED_GROUP (element) = NULL;
|
2002-12-15 12:18:04 +00:00
|
|
|
|
|
|
|
if (group->num_elements == 0) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "group %p is empty, deleting", group);
|
|
|
|
remove_from_chain (group->chain, group);
|
|
|
|
delete_group (group);
|
2002-12-26 22:11:04 +00:00
|
|
|
return NULL;
|
2002-12-15 12:18:04 +00:00
|
|
|
}
|
2002-12-26 22:11:04 +00:00
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstOptSchedulerGroup*
|
|
|
|
merge_groups (GstOptSchedulerGroup *group1, GstOptSchedulerGroup *group2)
|
|
|
|
{
|
|
|
|
g_assert (group1 != NULL);
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "merging groups %p and %p", group1, group2);
|
|
|
|
|
|
|
|
if (group1 == group2 || group2 == NULL)
|
|
|
|
return group1;
|
|
|
|
|
|
|
|
while (group2) {
|
|
|
|
GstElement *element = (GstElement *)group2->elements->data;
|
|
|
|
|
|
|
|
group2 = remove_from_group (group2, element);
|
|
|
|
add_to_group (group1, element);
|
|
|
|
}
|
|
|
|
|
|
|
|
return group1;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-12-16 21:21:02 +00:00
|
|
|
static void
|
|
|
|
group_error_handler (GstOptSchedulerGroup *group)
|
|
|
|
{
|
|
|
|
chain_group_set_enabled (group->chain, group, FALSE);
|
|
|
|
group->chain->sched->state = GST_OPT_SCHEDULER_STATE_ERROR;
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* this function enables/disables an element, it will set/clear a flag on the element
|
|
|
|
* and tells the chain that the group is enabled if all elements inside the group are
|
|
|
|
* enabled */
|
2002-09-08 17:58:00 +00:00
|
|
|
static void
|
|
|
|
group_element_set_enabled (GstOptSchedulerGroup *group, GstElement *element, gboolean enabled)
|
|
|
|
{
|
2002-12-15 18:21:43 +00:00
|
|
|
g_assert (group != NULL);
|
|
|
|
g_assert (element != NULL);
|
|
|
|
|
2003-01-01 04:28:33 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "request to %d element %s in group %p, have %d elements enabled out of %d",
|
|
|
|
enabled, GST_ELEMENT_NAME (element), group, group->num_enabled, group->num_elements);
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
if (enabled) {
|
2003-01-01 04:28:33 +00:00
|
|
|
if (group->num_enabled < group->num_elements)
|
|
|
|
group->num_enabled++;
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "enable element %s in group %p, now %d elements enabled out of %d",
|
|
|
|
GST_ELEMENT_NAME (element), group, group->num_enabled, group->num_elements);
|
2003-01-01 04:28:33 +00:00
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
if (group->num_enabled == group->num_elements) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "enable group %p", group);
|
|
|
|
chain_group_set_enabled (group->chain, group, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-01-01 04:28:33 +00:00
|
|
|
if (group->num_enabled > 0)
|
|
|
|
group->num_enabled--;
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "disable element %s in group %p, now %d elements enabled out of %d",
|
|
|
|
GST_ELEMENT_NAME (element), group, group->num_enabled, group->num_elements);
|
2003-01-01 04:28:33 +00:00
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
if (group->num_enabled == 0) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "disable group %p", group);
|
|
|
|
chain_group_set_enabled (group->chain, group, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* a group is scheduled by doing a cothread switch to it or
|
|
|
|
* by calling the schedule function. In the non-cothread case
|
|
|
|
* we cannot run already running groups so we return FALSE here
|
|
|
|
* to indicate this to the caller */
|
|
|
|
static gboolean
|
2002-09-08 17:58:00 +00:00
|
|
|
schedule_group (GstOptSchedulerGroup *group)
|
|
|
|
{
|
2002-12-16 21:21:02 +00:00
|
|
|
if (!group->entry)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
|
|
|
if (group->cothread)
|
|
|
|
do_cothread_switch (group->cothread);
|
2002-12-15 22:02:20 +00:00
|
|
|
else
|
|
|
|
g_warning ("(internal error): trying to schedule group without cothread");
|
2002-12-15 18:21:43 +00:00
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
group->schedulefunc (group->argc, group->argv);
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifndef USE_COTHREADS
|
2002-09-12 19:22:03 +00:00
|
|
|
static void
|
|
|
|
gst_opt_scheduler_schedule_run_queue (GstOptScheduler *osched)
|
2002-09-08 17:58:00 +00:00
|
|
|
{
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "entering scheduler run queue recursion %d", osched->recursion);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2003-01-01 04:28:33 +00:00
|
|
|
/* make sure we don't exceed max_recursion */
|
|
|
|
if (osched->recursion > osched->max_recursion) {
|
|
|
|
osched->state = GST_OPT_SCHEDULER_STATE_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
osched->recursion++;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
while (osched->runqueue) {
|
|
|
|
GstOptSchedulerGroup *group;
|
|
|
|
|
|
|
|
group = (GstOptSchedulerGroup *) osched->runqueue->data;
|
|
|
|
osched->runqueue = g_list_remove (osched->runqueue, group);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "scheduling %p", group);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-12-16 21:21:02 +00:00
|
|
|
if (!schedule_group (group)) {
|
|
|
|
g_warning ("error scheduling group %p", group);
|
|
|
|
group_error_handler (group);
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "done scheduling %p", group);
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "run queue length after scheduling %d", g_list_length (osched->runqueue));
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
osched->recursion--;
|
|
|
|
}
|
2002-12-15 18:21:43 +00:00
|
|
|
#endif
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* a chain is scheduled by picking the first active group and scheduling it */
|
|
|
|
static void
|
|
|
|
schedule_chain (GstOptSchedulerChain *chain)
|
|
|
|
{
|
2002-12-15 22:02:20 +00:00
|
|
|
GSList *groups;
|
|
|
|
GstOptScheduler *osched;
|
|
|
|
|
|
|
|
osched = chain->sched;
|
|
|
|
groups = chain->groups;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
while (groups) {
|
|
|
|
GstOptSchedulerGroup *group = (GstOptSchedulerGroup *) groups->data;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
groups = g_slist_next (groups);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
if (!GST_OPT_SCHEDULER_GROUP_IS_DISABLED (group)) {
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "scheduling group %p in chain %p",
|
|
|
|
group, chain);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
|
|
|
schedule_group (group);
|
|
|
|
#else
|
|
|
|
osched->recursion = 0;
|
|
|
|
osched->runqueue = g_list_append (osched->runqueue, group);
|
|
|
|
gst_opt_scheduler_schedule_run_queue (osched);
|
|
|
|
#endif
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "done scheduling group %p in chain %p",
|
|
|
|
group, chain);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* a get-based group is scheduled by getting a buffer from the get based
|
|
|
|
* entry point and by pushing the buffer to the peer.
|
|
|
|
* We also set the running flag on this group for as long as this
|
|
|
|
* function is running. */
|
2002-09-08 17:58:00 +00:00
|
|
|
static int
|
2002-09-12 19:22:03 +00:00
|
|
|
get_group_schedule_function (int argc, char *argv[])
|
2002-09-08 17:58:00 +00:00
|
|
|
{
|
|
|
|
GstOptSchedulerGroup *group = (GstOptSchedulerGroup *) argv;
|
2002-09-08 22:42:29 +00:00
|
|
|
const GList *pads = gst_element_get_pad_list (group->entry);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "get wrapper of group %p", group);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
group->flags |= GST_OPT_SCHEDULER_GROUP_RUNNING;
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
while (pads) {
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstPad *pad = GST_PAD_CAST (pads->data);
|
|
|
|
pads = g_list_next (pads);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
/* skip sinks and ghostpads */
|
|
|
|
if (!GST_PAD_IS_SRC (pad) || !GST_IS_REAL_PAD (pad))
|
|
|
|
continue;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "doing get and push on pad \"%s:%s\" in group %p",
|
|
|
|
GST_DEBUG_PAD_NAME (pad), group);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
buffer = GST_RPAD_GETFUNC (pad) (pad);
|
2003-01-08 21:33:20 +00:00
|
|
|
if (buffer) {
|
|
|
|
if (GST_EVENT_IS_INTERRUPT (buffer)) {
|
|
|
|
gst_event_unref (GST_EVENT (buffer));
|
|
|
|
break;
|
|
|
|
}
|
2002-09-08 22:42:29 +00:00
|
|
|
gst_pad_push (pad, buffer);
|
2003-01-08 21:33:20 +00:00
|
|
|
}
|
2002-09-08 22:42:29 +00:00
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
group->flags &= ~GST_OPT_SCHEDULER_GROUP_RUNNING;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* a loop-based group is scheduled by calling the loop function
|
|
|
|
* on the entry point.
|
|
|
|
* We also set the running flag on this group for as long as this
|
|
|
|
* function is running. */
|
2002-09-08 22:42:29 +00:00
|
|
|
static int
|
2002-09-12 19:22:03 +00:00
|
|
|
loop_group_schedule_function (int argc, char *argv[])
|
2002-09-08 22:42:29 +00:00
|
|
|
{
|
|
|
|
GstOptSchedulerGroup *group = (GstOptSchedulerGroup *) argv;
|
|
|
|
GstElement *entry = group->entry;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "loop wrapper of group %p", group);
|
|
|
|
|
|
|
|
group->flags |= GST_OPT_SCHEDULER_GROUP_RUNNING;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "calling loopfunc of element %s in group %p",
|
|
|
|
GST_ELEMENT_NAME (entry), group);
|
|
|
|
|
|
|
|
entry->loopfunc (entry);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
group->flags &= ~GST_OPT_SCHEDULER_GROUP_RUNNING;
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* the function to schedule an unkown group, which just gives an error */
|
2002-09-08 22:42:29 +00:00
|
|
|
static int
|
2002-09-12 19:22:03 +00:00
|
|
|
unkown_group_schedule_function (int argc, char *argv[])
|
2002-09-08 22:42:29 +00:00
|
|
|
{
|
|
|
|
GstOptSchedulerGroup *group = (GstOptSchedulerGroup *) argv;
|
|
|
|
|
|
|
|
g_warning ("(internal error) unkown group type %d, disabling\n", group->type);
|
2002-12-16 21:21:02 +00:00
|
|
|
group_error_handler (group);
|
2002-09-08 22:42:29 +00:00
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* this function is called when the first element of a chain-loop or a loop-loop
|
2003-01-09 14:15:37 +00:00
|
|
|
* link performs a push to the loop element. We then schedule the
|
2002-09-12 19:22:03 +00:00
|
|
|
* group with the loop-based element until the bufpen is empty */
|
2002-09-08 17:58:00 +00:00
|
|
|
static void
|
|
|
|
gst_opt_scheduler_loop_wrapper (GstPad *sinkpad, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstOptSchedulerGroup *group;
|
2002-09-12 19:22:03 +00:00
|
|
|
GstOptScheduler *osched;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "loop wrapper, putting buffer in bufpen");
|
|
|
|
|
|
|
|
group = GST_ELEMENT_SCHED_GROUP (GST_PAD_PARENT (sinkpad));
|
2002-09-12 19:22:03 +00:00
|
|
|
osched = group->chain->sched;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
|
|
|
if (GST_PAD_BUFLIST (GST_RPAD_PEER (sinkpad))) {
|
|
|
|
g_warning ("deadlock detected, disabling group %p", group);
|
2002-12-16 21:21:02 +00:00
|
|
|
group_error_handler (group);
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
2002-12-15 12:18:04 +00:00
|
|
|
else {
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_PAD_BUFLIST (GST_RPAD_PEER (sinkpad)) = g_list_append (GST_PAD_BUFLIST (GST_RPAD_PEER (sinkpad)), buffer);
|
2002-12-15 18:21:43 +00:00
|
|
|
schedule_group (group);
|
2002-09-12 19:22:03 +00:00
|
|
|
}
|
2002-12-15 18:21:43 +00:00
|
|
|
#else
|
|
|
|
GST_PAD_BUFLIST (GST_RPAD_PEER (sinkpad)) = g_list_append (GST_PAD_BUFLIST (GST_RPAD_PEER (sinkpad)), buffer);
|
|
|
|
if (!(group->flags & GST_OPT_SCHEDULER_GROUP_RUNNING)) {
|
|
|
|
osched->runqueue = g_list_append (osched->runqueue, group);
|
|
|
|
}
|
|
|
|
#endif
|
2002-09-12 19:22:03 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "after loop wrapper buflist %d",
|
|
|
|
g_list_length (GST_PAD_BUFLIST (GST_RPAD_PEER (sinkpad))));
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* this function is called by a loop based element that performs a
|
|
|
|
* pull on a sinkpad. We schedule the peer group until the bufpen
|
|
|
|
* is filled with the buffer so that this function can return */
|
2002-09-08 17:58:00 +00:00
|
|
|
static GstBuffer*
|
|
|
|
gst_opt_scheduler_get_wrapper (GstPad *srcpad)
|
|
|
|
{
|
2002-09-12 19:22:03 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "get wrapper, removing buffer from bufpen");
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
if (GST_PAD_BUFLIST (srcpad))
|
|
|
|
buffer = GST_PAD_BUFLIST (srcpad)->data;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
while (!buffer) {
|
|
|
|
GstOptSchedulerGroup *group;
|
2002-09-12 19:22:03 +00:00
|
|
|
GstOptScheduler *osched;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
group = GST_ELEMENT_SCHED_GROUP (GST_PAD_PARENT (srcpad));
|
2002-09-12 19:22:03 +00:00
|
|
|
osched = group->chain->sched;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
|
|
|
schedule_group (group);
|
|
|
|
#else
|
|
|
|
if (!(group->flags & GST_OPT_SCHEDULER_GROUP_RUNNING)) {
|
2002-09-12 19:22:03 +00:00
|
|
|
osched->runqueue = g_list_append (osched->runqueue, group);
|
|
|
|
gst_opt_scheduler_schedule_run_queue (osched);
|
|
|
|
}
|
|
|
|
else {
|
2002-09-08 22:42:29 +00:00
|
|
|
g_warning ("deadlock detected, disabling group %p", group);
|
2002-12-16 21:21:02 +00:00
|
|
|
group_error_handler (group);
|
2003-01-08 21:33:20 +00:00
|
|
|
return GST_BUFFER (gst_event_new (GST_EVENT_INTERRUPT));
|
2002-09-08 22:42:29 +00:00
|
|
|
}
|
2002-12-15 18:21:43 +00:00
|
|
|
#endif
|
2003-01-08 21:33:20 +00:00
|
|
|
/* if the scheduler interrupted, make sure we send an INTERRUPTED event to the
|
|
|
|
* > * loop based element */
|
|
|
|
if (osched->state == GST_OPT_SCHEDULER_STATE_INTERRUPTED) {
|
|
|
|
return GST_BUFFER (gst_event_new (GST_EVENT_INTERRUPT));
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
if (GST_PAD_BUFLIST (srcpad)) {
|
|
|
|
buffer = (GstBuffer *) GST_PAD_BUFLIST (srcpad)->data;
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_PAD_BUFLIST (srcpad) = g_list_remove (GST_PAD_BUFLIST (srcpad), buffer);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "get wrapper, returning buffer %d",
|
|
|
|
g_list_length (GST_PAD_BUFLIST (srcpad)));
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* this function is a chain wrapper for non-event-aware plugins,
|
|
|
|
* it'll simply dispatch the events to the (default) event handler */
|
2002-09-08 17:58:00 +00:00
|
|
|
static void
|
|
|
|
gst_opt_scheduler_chain_wrapper (GstPad *sinkpad, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
if (GST_IS_EVENT (buffer)) {
|
|
|
|
gst_pad_send_event (sinkpad, GST_EVENT (buffer));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GST_RPAD_CHAINFUNC (sinkpad) (sinkpad, buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* setup the scheduler context for a group. The right schedule function
|
|
|
|
* is selected based on the group type and cothreads are created if
|
|
|
|
* needed */
|
2002-09-08 17:58:00 +00:00
|
|
|
static void
|
|
|
|
setup_group_scheduler (GstOptScheduler *osched, GstOptSchedulerGroup *group)
|
|
|
|
{
|
2002-09-08 22:42:29 +00:00
|
|
|
GroupScheduleFunction wrapper;
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
wrapper = unkown_group_schedule_function;
|
2002-09-08 22:42:29 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* figure out the wrapper function for this group */
|
2002-09-08 22:42:29 +00:00
|
|
|
if (group->type == GST_OPT_SCHEDULER_GROUP_GET)
|
2002-09-12 19:22:03 +00:00
|
|
|
wrapper = get_group_schedule_function;
|
2002-09-08 22:42:29 +00:00
|
|
|
else if (group->type == GST_OPT_SCHEDULER_GROUP_LOOP)
|
2002-09-12 19:22:03 +00:00
|
|
|
wrapper = loop_group_schedule_function;
|
2002-09-08 22:42:29 +00:00
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
|
|
|
if (!(group->flags & GST_OPT_SCHEDULER_GROUP_SCHEDULABLE)) {
|
|
|
|
do_cothread_create (group->cothread, osched->context,
|
2002-11-02 13:54:34 +00:00
|
|
|
(cothread_func) wrapper, 0, (char **) group);
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-12-15 18:21:43 +00:00
|
|
|
do_cothread_setfunc (group->cothread, osched->context,
|
|
|
|
(cothread_func) wrapper, 0, (char **) group);
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
2002-12-15 18:21:43 +00:00
|
|
|
#else
|
|
|
|
group->schedulefunc = wrapper;
|
|
|
|
group->argc = 0;
|
|
|
|
group->argv = (char **) group;
|
|
|
|
#endif
|
2002-09-08 17:58:00 +00:00
|
|
|
group->flags |= GST_OPT_SCHEDULER_GROUP_SCHEDULABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_opt_scheduler_state_transition (GstScheduler *sched, GstElement *element, gint transition)
|
|
|
|
{
|
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
|
|
|
GstOptSchedulerGroup *group;
|
2002-09-12 19:22:03 +00:00
|
|
|
GstElementStateReturn res = GST_STATE_SUCCESS;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "element \"%s\" state change %d", GST_ELEMENT_NAME (element), transition);
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* we check the state of the managing pipeline here */
|
2002-09-08 17:58:00 +00:00
|
|
|
if (GST_IS_BIN (element)) {
|
|
|
|
if (GST_SCHEDULER_PARENT (sched) == element) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "parent \"%s\" changed state", GST_ELEMENT_NAME (element));
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "setting scheduler state to stopped");
|
|
|
|
GST_SCHEDULER_STATE (sched) = GST_SCHEDULER_STATE_STOPPED;
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "setting scheduler state to running");
|
|
|
|
GST_SCHEDULER_STATE (sched) = GST_SCHEDULER_STATE_RUNNING;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "no interesting state change, doing nothing");
|
|
|
|
}
|
|
|
|
}
|
2002-09-12 19:22:03 +00:00
|
|
|
return res;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* we don't care about decoupled elements after this */
|
2002-09-08 17:58:00 +00:00
|
|
|
if (GST_ELEMENT_IS_DECOUPLED (element))
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* get the group of the element */
|
2002-09-08 17:58:00 +00:00
|
|
|
group = GST_ELEMENT_SCHED_GROUP (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
2003-01-09 14:15:37 +00:00
|
|
|
/* an element withut a group has to be an unlinked src, sink
|
2002-09-12 19:22:03 +00:00
|
|
|
* filter element */
|
|
|
|
if (!group)
|
|
|
|
res = GST_STATE_FAILURE;
|
|
|
|
/* else construct the scheduling context of this group and enable it */
|
|
|
|
else {
|
|
|
|
setup_group_scheduler (osched, group);
|
|
|
|
group_element_set_enabled (group, element, TRUE);
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
2002-09-12 19:22:03 +00:00
|
|
|
/* if the element still has a group, we disable it */
|
|
|
|
if (group)
|
|
|
|
group_element_set_enabled (group, element, FALSE);
|
2002-09-08 17:58:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
return res;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
static void
|
|
|
|
gst_opt_scheduler_scheduling_change (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
|
|
|
g_warning ("scheduling change, implement me");
|
|
|
|
}
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
static void
|
|
|
|
get_group (GstElement *element, GstOptSchedulerGroup **group)
|
|
|
|
{
|
|
|
|
GstOptSchedulerCtx *ctx;
|
|
|
|
|
|
|
|
ctx = GST_ELEMENT_SCHED_CONTEXT (element);
|
|
|
|
if (ctx)
|
|
|
|
*group = ctx->group;
|
|
|
|
else
|
|
|
|
*group = NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
/*
|
|
|
|
* the idea is to put the two elements into the same group.
|
|
|
|
* - When no element is inside a group, we create a new group and add
|
|
|
|
* the elements to it.
|
|
|
|
* - When one of the elements has a group, add the other element to
|
|
|
|
* that group
|
|
|
|
* - if both of the elements have a group, we merge the groups, which
|
|
|
|
* will also merge the chains.
|
|
|
|
*/
|
2002-09-08 17:58:00 +00:00
|
|
|
static GstOptSchedulerGroup*
|
|
|
|
group_elements (GstOptScheduler *osched, GstElement *element1, GstElement *element2)
|
|
|
|
{
|
2002-11-02 13:54:34 +00:00
|
|
|
GstOptSchedulerGroup *group1, *group2, *group = NULL;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
get_group (element1, &group1);
|
|
|
|
get_group (element2, &group2);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
/* none of the elements is added to a group, create a new group
|
|
|
|
* and chain to add the elements to */
|
2002-09-08 17:58:00 +00:00
|
|
|
if (!group1 && !group2) {
|
|
|
|
GstOptSchedulerChain *chain;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "creating new group to hold \"%s\" and \"%s\"",
|
|
|
|
GST_ELEMENT_NAME (element1), GST_ELEMENT_NAME (element2));
|
|
|
|
|
|
|
|
chain = create_chain (osched);
|
|
|
|
group = create_group (chain, element1);
|
|
|
|
add_to_group (group, element2);
|
|
|
|
}
|
2002-09-08 22:42:29 +00:00
|
|
|
/* the first element has a group */
|
2002-09-08 17:58:00 +00:00
|
|
|
else if (group1) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "adding \"%s\" to \"%s\"'s group",
|
|
|
|
GST_ELEMENT_NAME (element2), GST_ELEMENT_NAME (element1));
|
2002-09-08 22:42:29 +00:00
|
|
|
|
|
|
|
/* the second element also has a group, merge */
|
2002-09-08 17:58:00 +00:00
|
|
|
if (group2)
|
|
|
|
merge_groups (group1, group2);
|
2002-09-08 22:42:29 +00:00
|
|
|
/* the second element has no group, add it to the group
|
|
|
|
* of the first element */
|
2002-09-08 17:58:00 +00:00
|
|
|
else
|
|
|
|
add_to_group (group1, element2);
|
|
|
|
|
|
|
|
group = group1;
|
|
|
|
}
|
2002-09-08 22:42:29 +00:00
|
|
|
/* element1 has no group, element2 does. Add element1 to the
|
|
|
|
* group of element2 */
|
2002-09-08 17:58:00 +00:00
|
|
|
else {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "adding \"%s\" to \"%s\"'s group",
|
|
|
|
GST_ELEMENT_NAME (element1), GST_ELEMENT_NAME (element2));
|
|
|
|
add_to_group (group2, element1);
|
|
|
|
group = group2;
|
|
|
|
}
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GST_OPT_INVALID,
|
|
|
|
GST_OPT_GET_TO_CHAIN,
|
|
|
|
GST_OPT_LOOP_TO_CHAIN,
|
|
|
|
GST_OPT_GET_TO_LOOP,
|
|
|
|
GST_OPT_CHAIN_TO_CHAIN,
|
|
|
|
GST_OPT_CHAIN_TO_LOOP,
|
|
|
|
GST_OPT_LOOP_TO_LOOP,
|
2003-01-09 22:59:37 +00:00
|
|
|
} LinkType;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/*
|
|
|
|
* Entry points for this scheduler.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_setup (GstScheduler *sched)
|
|
|
|
{
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
2002-09-12 19:22:03 +00:00
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
|
|
|
|
|
|
|
/* first create thread context */
|
2002-12-15 18:21:43 +00:00
|
|
|
if (osched->context == NULL) {
|
2002-09-12 19:22:03 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "initializing cothread context");
|
|
|
|
osched->context = do_cothread_context_init ();
|
|
|
|
}
|
2002-12-15 18:21:43 +00:00
|
|
|
#endif
|
2002-09-12 19:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_reset (GstScheduler *sched)
|
|
|
|
{
|
2002-12-15 18:21:43 +00:00
|
|
|
#ifdef USE_COTHREADS
|
2002-09-12 19:22:03 +00:00
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
2002-12-20 18:49:17 +00:00
|
|
|
GSList *chains = osched->chains;
|
|
|
|
|
|
|
|
while (chains) {
|
|
|
|
GstOptSchedulerChain *chain = (GstOptSchedulerChain *) chains->data;
|
|
|
|
GSList *groups = chain->groups;
|
|
|
|
|
|
|
|
while (groups) {
|
|
|
|
GstOptSchedulerGroup *group = (GstOptSchedulerGroup *) groups->data;
|
|
|
|
|
|
|
|
destroy_group_scheduler (group);
|
|
|
|
groups = groups->next;
|
|
|
|
}
|
|
|
|
chains = chains->next;
|
|
|
|
}
|
2002-09-12 19:22:03 +00:00
|
|
|
|
2002-12-15 18:21:43 +00:00
|
|
|
if (osched->context) {
|
2002-09-12 19:22:03 +00:00
|
|
|
do_cothread_context_destroy (osched->context);
|
|
|
|
osched->context = NULL;
|
|
|
|
}
|
2002-12-15 18:21:43 +00:00
|
|
|
#endif
|
2002-09-12 19:22:03 +00:00
|
|
|
}
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_add_element (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
|
|
|
GstOptSchedulerCtx *ctx;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "adding element \"%s\" to scheduler", GST_ELEMENT_NAME (element));
|
|
|
|
|
|
|
|
/* decoupled elements are not added to the scheduler lists */
|
|
|
|
if (GST_ELEMENT_IS_DECOUPLED (element))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ctx = g_new0 (GstOptSchedulerCtx, 1);
|
|
|
|
GST_ELEMENT_SCHED_CONTEXT (element) = ctx;
|
|
|
|
|
|
|
|
/* loop based elements *always* end up in their own group. It can eventually
|
2003-01-09 14:15:37 +00:00
|
|
|
* be merged with another group when a link is made */
|
2002-09-12 19:22:03 +00:00
|
|
|
if (element->loopfunc) {
|
|
|
|
GstOptSchedulerGroup *group;
|
|
|
|
GstOptSchedulerChain *chain;
|
|
|
|
|
|
|
|
chain = create_chain (osched);
|
|
|
|
|
|
|
|
group = create_group (chain, element);
|
|
|
|
group->entry = element;
|
|
|
|
group->type = GST_OPT_SCHEDULER_GROUP_LOOP;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "added element \"%s\" as loop based entry", GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_remove_element (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
2002-11-02 13:54:34 +00:00
|
|
|
GstOptSchedulerGroup *group;
|
2002-09-12 19:22:03 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "removing element \"%s\" from scheduler", GST_ELEMENT_NAME (element));
|
|
|
|
|
2002-12-09 22:31:16 +00:00
|
|
|
/* decoupled elements are not added to the scheduler lists and should therefore
|
2002-11-02 13:54:34 +00:00
|
|
|
* no be removed */
|
|
|
|
if (GST_ELEMENT_IS_DECOUPLED (element))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* the element is guaranteed to live in it's own group/chain now */
|
|
|
|
get_group (element, &group);
|
|
|
|
if (group) {
|
2002-12-15 12:18:04 +00:00
|
|
|
GstOptSchedulerChain *chain;
|
2002-11-07 18:50:06 +00:00
|
|
|
|
2002-11-22 23:17:39 +00:00
|
|
|
GST_ELEMENT_SCHED_GROUP (element) = NULL;
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
chain = group->chain;
|
|
|
|
if (chain) {
|
2002-11-07 18:50:06 +00:00
|
|
|
remove_from_chain (chain, group);
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
delete_group (group);
|
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
g_free (GST_ELEMENT_SCHED_CONTEXT (element));
|
|
|
|
GST_ELEMENT_SCHED_CONTEXT (element) = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_lock_element (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
|
|
|
//GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
|
|
|
g_warning ("lock element, implement me");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_unlock_element (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
|
|
|
//GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
|
|
|
g_warning ("unlock element, implement me");
|
|
|
|
}
|
|
|
|
|
2003-01-11 16:27:45 +00:00
|
|
|
static gboolean
|
2002-09-12 19:22:03 +00:00
|
|
|
gst_opt_scheduler_yield (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
2002-12-21 02:25:54 +00:00
|
|
|
#ifdef USE_COTHREADS
|
|
|
|
/* yield hands control to the main cothread context if the requesting
|
|
|
|
* element is the entry point of the group */
|
|
|
|
GstOptSchedulerGroup *group;
|
|
|
|
get_group (element, &group);
|
|
|
|
if (group && group->entry == element)
|
|
|
|
do_cothread_switch (do_cothread_get_main (((GstOptScheduler*)sched)->context));
|
2003-01-11 16:27:45 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
#else
|
|
|
|
g_warning ("element %s performs a yield, please fix the element",
|
|
|
|
GST_ELEMENT_NAME (element));
|
|
|
|
return TRUE;
|
2002-12-21 02:25:54 +00:00
|
|
|
#endif
|
2002-09-12 19:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_opt_scheduler_interrupt (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
2003-01-08 21:33:20 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "interrupt from \"%s\"",
|
|
|
|
GST_ELEMENT_NAME (element));
|
|
|
|
|
2002-12-21 02:25:54 +00:00
|
|
|
#ifdef USE_COTHREADS
|
|
|
|
do_cothread_switch (do_cothread_get_main (((GstOptScheduler*)sched)->context));
|
|
|
|
return FALSE;
|
|
|
|
#else
|
2003-01-08 21:33:20 +00:00
|
|
|
{
|
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
|
|
|
|
|
|
|
osched->state = GST_OPT_SCHEDULER_STATE_INTERRUPTED;
|
|
|
|
}
|
2002-09-12 19:22:03 +00:00
|
|
|
return TRUE;
|
2002-12-21 02:25:54 +00:00
|
|
|
#endif
|
2002-09-12 19:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_error (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
2002-12-16 21:21:02 +00:00
|
|
|
GstOptSchedulerGroup *group;
|
|
|
|
get_group (element, &group);
|
|
|
|
if (group)
|
|
|
|
group_error_handler (group);
|
2002-09-12 19:22:03 +00:00
|
|
|
|
|
|
|
osched->state = GST_OPT_SCHEDULER_STATE_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* link pads, merge groups and chains */
|
2002-09-08 17:58:00 +00:00
|
|
|
static void
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_opt_scheduler_pad_link (GstScheduler *sched, GstPad *srcpad, GstPad *sinkpad)
|
2002-09-08 17:58:00 +00:00
|
|
|
{
|
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
2003-01-09 22:59:37 +00:00
|
|
|
LinkType type = GST_OPT_INVALID;
|
2002-09-08 17:58:00 +00:00
|
|
|
GstElement *element1, *element2;
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "pad link between \"%s:%s\" and \"%s:%s\"",
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
|
|
|
|
|
|
|
|
element1 = GST_PAD_PARENT (srcpad);
|
|
|
|
element2 = GST_PAD_PARENT (sinkpad);
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* first we need to figure out what type of link we're dealing
|
2002-09-08 22:42:29 +00:00
|
|
|
* with */
|
2002-09-08 17:58:00 +00:00
|
|
|
if (element1->loopfunc && element2->loopfunc)
|
|
|
|
type = GST_OPT_LOOP_TO_LOOP;
|
|
|
|
else {
|
|
|
|
if (element1->loopfunc) {
|
|
|
|
if (GST_RPAD_CHAINFUNC (sinkpad))
|
|
|
|
type = GST_OPT_LOOP_TO_CHAIN;
|
|
|
|
}
|
|
|
|
else if (element2->loopfunc) {
|
2002-11-02 13:54:34 +00:00
|
|
|
if (GST_RPAD_GETFUNC (srcpad)) {
|
2002-09-08 17:58:00 +00:00
|
|
|
type = GST_OPT_GET_TO_LOOP;
|
2002-11-02 13:54:34 +00:00
|
|
|
/* this could be tricky, the get based source could
|
|
|
|
* already be part of a loop based group in another pad,
|
|
|
|
* we assert on that for now */
|
2002-12-16 21:21:02 +00:00
|
|
|
if (GST_ELEMENT_SCHED_CONTEXT (element1) != NULL &&
|
2002-11-02 13:54:34 +00:00
|
|
|
GST_ELEMENT_SCHED_GROUP (element1) != NULL)
|
|
|
|
{
|
2002-12-16 21:21:02 +00:00
|
|
|
GstOptSchedulerGroup *group = GST_ELEMENT_SCHED_GROUP (element1);
|
|
|
|
|
|
|
|
/* if the loop based element is the entry point we're ok, if it
|
|
|
|
* isn't then we have multiple loop based elements in this group */
|
|
|
|
if (group->entry != element2) {
|
|
|
|
g_error ("internal error: cannot schedule get to loop in multi-loop based group");
|
|
|
|
return;
|
|
|
|
}
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
else
|
|
|
|
type = GST_OPT_CHAIN_TO_LOOP;
|
|
|
|
}
|
|
|
|
else {
|
2002-11-02 13:54:34 +00:00
|
|
|
if (GST_RPAD_GETFUNC (srcpad) && GST_RPAD_CHAINFUNC (sinkpad)) {
|
2002-09-08 17:58:00 +00:00
|
|
|
type = GST_OPT_GET_TO_CHAIN;
|
2002-11-02 13:54:34 +00:00
|
|
|
/* the get based source could already be part of a loop
|
2002-12-15 22:02:20 +00:00
|
|
|
* based group in another pad, we assert on that for now */
|
2002-12-16 21:21:02 +00:00
|
|
|
if (GST_ELEMENT_SCHED_CONTEXT (element1) != NULL &&
|
2002-11-02 13:54:34 +00:00
|
|
|
GST_ELEMENT_SCHED_GROUP (element1) != NULL)
|
|
|
|
{
|
2002-12-16 21:21:02 +00:00
|
|
|
GstOptSchedulerGroup *group = GST_ELEMENT_SCHED_GROUP (element1);
|
|
|
|
|
|
|
|
/* if the get based element is the entry point we're ok, if it
|
|
|
|
* isn't then we have a mixed loop/chain based group */
|
|
|
|
if (group->entry != element1) {
|
|
|
|
g_error ("internal error: cannot schedule get to chain with mixed loop/chain based group");
|
|
|
|
return;
|
|
|
|
}
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
else
|
|
|
|
type = GST_OPT_CHAIN_TO_CHAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* for each link type, perform specific actions */
|
2002-09-08 17:58:00 +00:00
|
|
|
switch (type) {
|
|
|
|
case GST_OPT_GET_TO_CHAIN:
|
|
|
|
{
|
|
|
|
GstOptSchedulerGroup *group = NULL;
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "get to chain based link");
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
/* setup get/chain handlers */
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_RPAD_GETHANDLER (srcpad) = GST_RPAD_GETFUNC (srcpad);
|
|
|
|
if (GST_ELEMENT_IS_EVENT_AWARE (element2))
|
|
|
|
GST_RPAD_CHAINHANDLER (sinkpad) = GST_RPAD_CHAINFUNC (sinkpad);
|
|
|
|
else
|
|
|
|
GST_RPAD_CHAINHANDLER (sinkpad) = gst_opt_scheduler_chain_wrapper;
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
/* the two elements should be put into the same group,
|
|
|
|
* this also means that they are in the same chain automatically */
|
2002-09-08 17:58:00 +00:00
|
|
|
group = group_elements (osched, element1, element2);
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
/* if there is not yet an entry in the group, select the source
|
|
|
|
* element as the entry point */
|
2002-09-08 17:58:00 +00:00
|
|
|
if (!group->entry) {
|
|
|
|
group->entry = element1;
|
|
|
|
group->type = GST_OPT_SCHEDULER_GROUP_GET;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "setting \"%s\" as entry point of _get-based group %p",
|
|
|
|
GST_ELEMENT_NAME (element1), group);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_OPT_LOOP_TO_CHAIN:
|
|
|
|
case GST_OPT_CHAIN_TO_CHAIN:
|
2003-01-09 14:15:37 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "loop/chain to chain based link");
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
if (GST_ELEMENT_IS_EVENT_AWARE (element2))
|
|
|
|
GST_RPAD_CHAINHANDLER (sinkpad) = GST_RPAD_CHAINFUNC (sinkpad);
|
|
|
|
else
|
|
|
|
GST_RPAD_CHAINHANDLER (sinkpad) = gst_opt_scheduler_chain_wrapper;
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
/* the two elements should be put into the same group,
|
|
|
|
* this also means that they are in the same chain automatically,
|
|
|
|
* in case of a loop-based element1, there will be a group for element1 and
|
|
|
|
* element2 will be added to it. */
|
2002-09-08 17:58:00 +00:00
|
|
|
group_elements (osched, element1, element2);
|
|
|
|
break;
|
|
|
|
case GST_OPT_GET_TO_LOOP:
|
2003-01-09 14:15:37 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "get to loop based link");
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
GST_RPAD_GETHANDLER (srcpad) = GST_RPAD_GETFUNC (srcpad);
|
2002-09-08 22:42:29 +00:00
|
|
|
|
|
|
|
/* the two elements should be put into the same group,
|
|
|
|
* this also means that they are in the same chain automatically,
|
|
|
|
* element2 is loop-based so it already has a group where element1
|
|
|
|
* will be added to */
|
2002-09-08 17:58:00 +00:00
|
|
|
group_elements (osched, element1, element2);
|
|
|
|
break;
|
|
|
|
case GST_OPT_CHAIN_TO_LOOP:
|
|
|
|
case GST_OPT_LOOP_TO_LOOP:
|
|
|
|
{
|
|
|
|
GstOptSchedulerGroup *group1, *group2;
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "chain/loop to loop based link");
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
GST_RPAD_CHAINHANDLER (sinkpad) = gst_opt_scheduler_loop_wrapper;
|
|
|
|
GST_RPAD_GETHANDLER (srcpad) = gst_opt_scheduler_get_wrapper;
|
|
|
|
|
|
|
|
group1 = GST_ELEMENT_SCHED_GROUP (element1);
|
|
|
|
group2 = GST_ELEMENT_SCHED_GROUP (element2);
|
2002-12-15 12:18:04 +00:00
|
|
|
|
2002-12-26 22:11:04 +00:00
|
|
|
g_assert (group2 != NULL);
|
2002-12-15 12:18:04 +00:00
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
/* group2 is guaranteed to exist as it contains a loop-based element.
|
2003-01-09 14:15:37 +00:00
|
|
|
* group1 only exists if element1 is linked to some other element */
|
2002-09-08 17:58:00 +00:00
|
|
|
if (!group1) {
|
2002-09-08 22:42:29 +00:00
|
|
|
/* create a new group for element1 as it cannot be merged into another group
|
|
|
|
* here. we create the group in the same chain as the loop-based element. */
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "creating new group for element %s", GST_ELEMENT_NAME (element1));
|
|
|
|
group1 = create_group (group2->chain, element1);
|
|
|
|
}
|
|
|
|
else {
|
2002-09-08 22:42:29 +00:00
|
|
|
/* both elements are already in a group, make sure they are added to
|
|
|
|
* the same chain */
|
2002-09-08 17:58:00 +00:00
|
|
|
merge_chains (group1->chain, group2->chain);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_OPT_INVALID:
|
2003-01-09 14:15:37 +00:00
|
|
|
g_error ("(internal error) invalid element link, what are you doing?");
|
2002-09-08 17:58:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-15 22:02:20 +00:00
|
|
|
/*
|
2003-01-09 14:15:37 +00:00
|
|
|
* checks if an element is still linked to some other element in the group.
|
2002-12-15 22:02:20 +00:00
|
|
|
* no checking is done on the brokenpad arg
|
|
|
|
* */
|
2002-11-02 13:54:34 +00:00
|
|
|
static gboolean
|
2003-01-09 14:15:37 +00:00
|
|
|
element_has_link_with_group (GstElement *element, GstOptSchedulerGroup *group, GstPad *brokenpad)
|
2002-11-02 13:54:34 +00:00
|
|
|
{
|
2003-01-09 14:15:37 +00:00
|
|
|
gboolean linked = FALSE;
|
2002-11-02 13:54:34 +00:00
|
|
|
const GList *pads;
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* see if the element has no more links to the peer group */
|
2002-11-02 13:54:34 +00:00
|
|
|
pads = gst_element_get_pad_list (element);
|
2003-01-09 14:15:37 +00:00
|
|
|
while (pads && !linked) {
|
2002-11-02 13:54:34 +00:00
|
|
|
GstPad *pad = GST_PAD_CAST (pads->data);
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
/* we only operate on real pads and on the pad that is not broken */
|
|
|
|
if (!GST_IS_REAL_PAD (pad) || pad == brokenpad)
|
2002-11-02 13:54:34 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (GST_PAD_PEER (pad)) {
|
2002-12-15 12:18:04 +00:00
|
|
|
GstElement *parent;
|
|
|
|
GstOptSchedulerGroup *parentgroup;
|
|
|
|
|
|
|
|
/* see in what group this element is */
|
|
|
|
parent = GST_PAD_PARENT (GST_PAD_PEER (pad));
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* links with decoupled elements are valid */
|
2002-12-15 22:52:48 +00:00
|
|
|
if (GST_ELEMENT_IS_DECOUPLED (parent)) {
|
2003-01-09 14:15:37 +00:00
|
|
|
linked = TRUE;
|
2002-12-15 22:52:48 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* for non-decoupled elements we need to check the group */
|
|
|
|
get_group (parent, &parentgroup);
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* if it's in the same group, we're still linked */
|
2002-12-15 22:52:48 +00:00
|
|
|
if (parentgroup == group)
|
2003-01-09 14:15:37 +00:00
|
|
|
linked = TRUE;
|
2002-12-15 22:52:48 +00:00
|
|
|
}
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-09 14:15:37 +00:00
|
|
|
return linked;
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
static void
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_opt_scheduler_pad_unlink (GstScheduler *sched, GstPad *srcpad, GstPad *sinkpad)
|
2002-09-08 17:58:00 +00:00
|
|
|
{
|
|
|
|
//GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
2002-11-02 13:54:34 +00:00
|
|
|
GstElement *element1, *element2;
|
|
|
|
GstOptSchedulerGroup *group1, *group2;
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "pad unlink between \"%s:%s\" and \"%s:%s\"",
|
2002-09-08 17:58:00 +00:00
|
|
|
GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
|
|
|
|
|
2002-11-02 13:54:34 +00:00
|
|
|
element1 = GST_PAD_PARENT (srcpad);
|
|
|
|
element2 = GST_PAD_PARENT (sinkpad);
|
|
|
|
|
|
|
|
get_group (element1, &group1);
|
|
|
|
get_group (element2, &group2);
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
/* if one the elements has no group (anymore) we don't really care
|
2003-01-09 14:15:37 +00:00
|
|
|
* about the link */
|
2002-12-15 12:18:04 +00:00
|
|
|
if (!group1 || !group2) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "one (or both) of the elements is not in a group, not interesting");
|
2002-11-02 13:54:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-15 12:18:04 +00:00
|
|
|
/* easy part, groups are different */
|
|
|
|
if (group1 != group2) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "elements are in different groups");
|
2002-12-15 22:02:20 +00:00
|
|
|
|
|
|
|
/* FIXME, need to eventually break the chain */
|
2003-01-09 14:15:37 +00:00
|
|
|
g_warning ("pad unlink for different groups, implement me");
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
2002-12-15 12:18:04 +00:00
|
|
|
/* hard part, groups are equal */
|
2002-11-02 13:54:34 +00:00
|
|
|
else {
|
2003-01-09 14:15:37 +00:00
|
|
|
gboolean still_link1, still_link2;
|
2002-12-15 22:02:20 +00:00
|
|
|
GstOptSchedulerGroup *group;
|
|
|
|
|
|
|
|
/* since group1 == group2, it doesn't matter which group we take */
|
|
|
|
group = group1;
|
2002-12-15 12:18:04 +00:00
|
|
|
|
2002-12-15 22:02:20 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "elements are in the same group %p", group);
|
2002-12-15 12:18:04 +00:00
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* check if the element is still linked to some other element in the group,
|
|
|
|
* we pass the pad that is broken up as an arg because a link on that pad
|
2002-12-15 22:02:20 +00:00
|
|
|
* is not valid anymore */
|
2003-01-09 14:15:37 +00:00
|
|
|
still_link1 = element_has_link_with_group (element1, group, srcpad);
|
|
|
|
still_link2 = element_has_link_with_group (element2, group, sinkpad);
|
2002-12-15 12:18:04 +00:00
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* if there is still a link, we don't need to break this group */
|
|
|
|
if (still_link1 && still_link2) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "elements still have links with other elements in the group");
|
2002-12-15 22:02:20 +00:00
|
|
|
|
|
|
|
/* FIXME, need to check for breaking up the group */
|
2002-12-15 12:18:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-15 22:02:20 +00:00
|
|
|
/* now check which one of the elements we can remove from the group */
|
2003-01-09 14:15:37 +00:00
|
|
|
if (!still_link1) {
|
2002-12-15 12:18:04 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "element1 is separated from the group");
|
|
|
|
/* see if the element was an entry point for the group */
|
2002-12-15 22:02:20 +00:00
|
|
|
if (group->entry == element1) {
|
|
|
|
/* we're going to remove the element so we need to clear it as the
|
|
|
|
* entry point */
|
|
|
|
group->entry = NULL;
|
2002-12-15 12:18:04 +00:00
|
|
|
}
|
2002-12-15 22:02:20 +00:00
|
|
|
remove_from_group (group, element1);
|
2002-12-15 12:18:04 +00:00
|
|
|
}
|
2003-01-09 14:15:37 +00:00
|
|
|
if (!still_link2) {
|
2002-12-15 12:18:04 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "element2 is separated from the group");
|
|
|
|
|
|
|
|
/* see if the element was an entry point for the group */
|
2002-12-15 22:02:20 +00:00
|
|
|
if (group->entry == element2) {
|
|
|
|
/* we're going to remove the element so we need to clear it as the
|
|
|
|
* entry point */
|
|
|
|
group->entry = NULL;
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
2002-12-15 22:02:20 +00:00
|
|
|
remove_from_group (group, element2);
|
2002-11-02 13:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstPad*
|
|
|
|
gst_opt_scheduler_pad_select (GstScheduler *sched, GList *padlist)
|
|
|
|
{
|
|
|
|
//GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
2002-09-12 19:22:03 +00:00
|
|
|
|
|
|
|
g_warning ("pad select, implement me");
|
|
|
|
|
2002-09-08 17:58:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstClockReturn
|
|
|
|
gst_opt_scheduler_clock_wait (GstScheduler *sched, GstElement *element,
|
2002-12-27 22:57:13 +00:00
|
|
|
GstClockID id, GstClockTimeDiff *jitter)
|
2002-09-08 17:58:00 +00:00
|
|
|
{
|
2002-11-02 13:54:34 +00:00
|
|
|
return gst_clock_id_wait (id, jitter);
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* a scheduler iteration is done by looping and scheduling the active chains */
|
2002-09-08 17:58:00 +00:00
|
|
|
static GstSchedulerState
|
|
|
|
gst_opt_scheduler_iterate (GstScheduler *sched)
|
|
|
|
{
|
2002-09-12 19:22:03 +00:00
|
|
|
GstSchedulerState state = GST_SCHEDULER_STATE_STOPPED;
|
2002-09-08 17:58:00 +00:00
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
2002-09-12 19:22:03 +00:00
|
|
|
gint iterations = osched->iterations;
|
2002-09-08 17:58:00 +00:00
|
|
|
|
|
|
|
osched->state = GST_OPT_SCHEDULER_STATE_RUNNING;
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
while (iterations) {
|
|
|
|
gboolean scheduled = FALSE;
|
|
|
|
GSList *chains;
|
|
|
|
|
|
|
|
/* we have to schedule each of the scheduler chains now */
|
|
|
|
chains = osched->chains;
|
|
|
|
while (chains) {
|
|
|
|
GstOptSchedulerChain *chain = (GstOptSchedulerChain *) chains->data;
|
|
|
|
chains = g_slist_next (chains);
|
2002-09-08 17:58:00 +00:00
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* if the chain is not disabled, schedule it */
|
|
|
|
if (!GST_OPT_SCHEDULER_CHAIN_IS_DISABLED (chain)) {
|
|
|
|
schedule_chain (chain);
|
|
|
|
scheduled = TRUE;
|
|
|
|
}
|
2003-01-08 21:33:20 +00:00
|
|
|
|
|
|
|
/* don't schedule any more chains when interrupted or in error */
|
|
|
|
if (osched->state != GST_OPT_SCHEDULER_STATE_RUNNING)
|
|
|
|
break;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2002-09-12 19:22:03 +00:00
|
|
|
/* at this point it's possible that the scheduler state is
|
|
|
|
* in error, we then return an error */
|
|
|
|
if (osched->state == GST_OPT_SCHEDULER_STATE_ERROR) {
|
|
|
|
state = GST_SCHEDULER_STATE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* if chains were scheduled, return our current state */
|
|
|
|
if (scheduled)
|
|
|
|
state = GST_SCHEDULER_STATE (sched);
|
|
|
|
/* if no chains were scheduled, we say we are stopped */
|
|
|
|
else {
|
|
|
|
state = GST_SCHEDULER_STATE_STOPPED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (iterations > 0)
|
|
|
|
iterations--;
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_show (GstScheduler *sched)
|
|
|
|
{
|
2002-09-08 22:42:29 +00:00
|
|
|
GstOptScheduler *osched = GST_OPT_SCHEDULER_CAST (sched);
|
|
|
|
GSList *chains;
|
|
|
|
|
2003-01-01 04:28:33 +00:00
|
|
|
g_print ("iterations: %d\n", osched->iterations);
|
|
|
|
g_print ("max recursion: %d\n", osched->max_recursion);
|
|
|
|
|
2002-09-08 22:42:29 +00:00
|
|
|
chains = osched->chains;
|
|
|
|
while (chains) {
|
|
|
|
GstOptSchedulerChain *chain = (GstOptSchedulerChain *) chains->data;
|
|
|
|
GSList *groups = chain->groups;
|
|
|
|
chains = g_slist_next (chains);
|
|
|
|
|
|
|
|
g_print ("+- chain %p: %d groups, %d enabled, flags %d\n", chain, chain->num_groups, chain->num_enabled, chain->flags);
|
|
|
|
|
|
|
|
while (groups) {
|
|
|
|
GstOptSchedulerGroup *group = (GstOptSchedulerGroup *) groups->data;
|
|
|
|
GSList *elements = group->elements;
|
|
|
|
groups = g_slist_next (groups);
|
|
|
|
|
|
|
|
g_print (" +- group %p: %d elements, %d enabled, flags %d, entry %s, %s\n",
|
|
|
|
group, group->num_elements, group->num_enabled, group->flags,
|
|
|
|
(group->entry ? GST_ELEMENT_NAME (group->entry): "(none)"),
|
|
|
|
(group->type == GST_OPT_SCHEDULER_GROUP_GET ? "get-based" : "loop-based") );
|
|
|
|
|
|
|
|
while (elements) {
|
|
|
|
GstElement *element = (GstElement *) elements->data;
|
|
|
|
elements = g_slist_next (elements);
|
|
|
|
|
|
|
|
g_print (" +- element %s\n", GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-08 17:58:00 +00:00
|
|
|
}
|
2002-09-12 19:22:03 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstOptScheduler *osched;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_OPT_SCHEDULER (object));
|
|
|
|
|
|
|
|
osched = GST_OPT_SCHEDULER_CAST (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_ITERATIONS:
|
|
|
|
g_value_set_int (value, osched->iterations);
|
|
|
|
break;
|
2003-01-01 04:28:33 +00:00
|
|
|
case ARG_MAX_RECURSION:
|
|
|
|
g_value_set_int (value, osched->max_recursion);
|
|
|
|
break;
|
2002-09-12 19:22:03 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_opt_scheduler_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstOptScheduler *osched;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_OPT_SCHEDULER (object));
|
|
|
|
|
|
|
|
osched = GST_OPT_SCHEDULER_CAST (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_ITERATIONS:
|
|
|
|
osched->iterations = g_value_get_int (value);
|
|
|
|
break;
|
2003-01-01 04:28:33 +00:00
|
|
|
case ARG_MAX_RECURSION:
|
|
|
|
osched->max_recursion = g_value_get_int (value);
|
|
|
|
break;
|
2002-09-12 19:22:03 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|