2001-12-04 22:12:50 +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.
|
|
|
|
*/
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/*#define GST_DEBUG_ENABLED */
|
2002-05-26 03:23:25 +00:00
|
|
|
#include "../gst.h"
|
2002-05-06 19:23:37 +00:00
|
|
|
|
|
|
|
#include "cothreads_compat.h"
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
typedef struct _GstSchedulerChain GstSchedulerChain;
|
|
|
|
|
2002-05-06 19:23:37 +00:00
|
|
|
#define GST_ELEMENT_THREADSTATE(elem) (cothread*) (GST_ELEMENT_CAST (elem)->sched_private)
|
2002-09-12 20:52:03 +00:00
|
|
|
#define GST_RPAD_BUFPEN(pad) (GstBuffer*) (GST_REAL_PAD_CAST(pad)->sched_private)
|
2001-12-22 21:18:17 +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)
|
|
|
|
|
|
|
|
typedef struct _GstBasicScheduler GstBasicScheduler;
|
|
|
|
typedef struct _GstBasicSchedulerClass GstBasicSchedulerClass;
|
|
|
|
|
2002-06-16 21:20:07 +00:00
|
|
|
#ifdef _COTHREADS_STANDARD
|
|
|
|
# define _SCHEDULER_NAME "standard"
|
|
|
|
#else
|
|
|
|
# define _SCHEDULER_NAME "basic"
|
|
|
|
#endif
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
struct _GstSchedulerChain {
|
2001-12-22 21:18:17 +00:00
|
|
|
GstBasicScheduler *sched;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
GList *disabled;
|
|
|
|
|
|
|
|
GList *elements;
|
|
|
|
gint num_elements;
|
|
|
|
|
|
|
|
GstElement *entry;
|
|
|
|
|
|
|
|
gint cothreaded_elements;
|
|
|
|
gboolean schedule;
|
|
|
|
};
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
#define GST_TYPE_BASIC_SCHEDULER \
|
|
|
|
(gst_basic_scheduler_get_type())
|
|
|
|
#define GST_BASIC_SCHEDULER(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASIC_SCHEDULER,GstBasicScheduler))
|
|
|
|
#define GST_BASIC_SCHEDULER_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASIC_SCHEDULER,GstBasicSchedulerClass))
|
|
|
|
#define GST_IS_BASIC_SCHEDULER(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASIC_SCHEDULER))
|
|
|
|
#define GST_IS_BASIC_SCHEDULER_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASIC_SCHEDULER))
|
|
|
|
|
|
|
|
#define GST_BASIC_SCHEDULER_CAST(sched) ((GstBasicScheduler *)(sched))
|
2002-05-26 03:23:25 +00:00
|
|
|
#define SCHED(element) GST_BASIC_SCHEDULER_CAST (GST_ELEMENT_SCHED (element))
|
2001-12-22 21:18:17 +00:00
|
|
|
|
2001-12-24 15:14:03 +00:00
|
|
|
typedef enum {
|
|
|
|
GST_BASIC_SCHEDULER_STATE_NONE,
|
|
|
|
GST_BASIC_SCHEDULER_STATE_STOPPED,
|
|
|
|
GST_BASIC_SCHEDULER_STATE_ERROR,
|
|
|
|
GST_BASIC_SCHEDULER_STATE_RUNNING,
|
|
|
|
} GstBasicSchedulerState;
|
|
|
|
|
2002-01-28 00:40:11 +00:00
|
|
|
typedef enum {
|
|
|
|
/* something important has changed inside the scheduler */
|
2002-03-30 17:05:03 +00:00
|
|
|
GST_BASIC_SCHEDULER_CHANGE = GST_SCHEDULER_FLAG_LAST,
|
2002-01-28 00:40:11 +00:00
|
|
|
} GstBasicSchedulerFlags;
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
struct _GstBasicScheduler {
|
|
|
|
GstScheduler parent;
|
|
|
|
|
|
|
|
GList *elements;
|
|
|
|
gint num_elements;
|
|
|
|
|
|
|
|
GList *chains;
|
|
|
|
gint num_chains;
|
2001-12-24 15:14:03 +00:00
|
|
|
|
|
|
|
GstBasicSchedulerState state;
|
2002-05-06 19:23:37 +00:00
|
|
|
|
|
|
|
cothread_context *context;
|
2002-05-26 03:23:25 +00:00
|
|
|
GstElement *current;
|
2001-12-22 21:18:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstBasicSchedulerClass {
|
|
|
|
GstSchedulerClass parent_class;
|
|
|
|
};
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
static GType _gst_basic_scheduler_type = 0;
|
|
|
|
|
2001-12-24 15:14:03 +00:00
|
|
|
static void gst_basic_scheduler_class_init (GstBasicSchedulerClass * klass);
|
|
|
|
static void gst_basic_scheduler_init (GstBasicScheduler * scheduler);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-24 15:14:03 +00:00
|
|
|
static void gst_basic_scheduler_dispose (GObject *object);
|
2001-12-15 22:37:35 +00:00
|
|
|
|
2001-12-24 15:14:03 +00:00
|
|
|
static void gst_basic_scheduler_setup (GstScheduler *sched);
|
2002-06-27 23:55:27 +00:00
|
|
|
static gboolean gst_basic_scheduler_get_preferred_stack (GstScheduler *sched, gpointer *stack, gulong *size);
|
2001-12-24 15:14:03 +00:00
|
|
|
static void gst_basic_scheduler_reset (GstScheduler *sched);
|
|
|
|
static void gst_basic_scheduler_add_element (GstScheduler *sched, GstElement *element);
|
|
|
|
static void gst_basic_scheduler_remove_element (GstScheduler *sched, GstElement *element);
|
2001-12-22 21:18:17 +00:00
|
|
|
static GstElementStateReturn
|
2001-12-24 15:14:03 +00:00
|
|
|
gst_basic_scheduler_state_transition (GstScheduler *sched, GstElement *element, gint transition);
|
|
|
|
static void gst_basic_scheduler_lock_element (GstScheduler *sched, GstElement *element);
|
|
|
|
static void gst_basic_scheduler_unlock_element (GstScheduler *sched, GstElement *element);
|
|
|
|
static void gst_basic_scheduler_yield (GstScheduler *sched, GstElement *element);
|
2001-12-27 00:47:41 +00:00
|
|
|
static gboolean gst_basic_scheduler_interrupt (GstScheduler *sched, GstElement *element);
|
2001-12-24 15:14:03 +00:00
|
|
|
static void gst_basic_scheduler_error (GstScheduler *sched, GstElement *element);
|
|
|
|
static void gst_basic_scheduler_pad_connect (GstScheduler *sched, GstPad *srcpad, GstPad *sinkpad);
|
|
|
|
static void gst_basic_scheduler_pad_disconnect (GstScheduler *sched, GstPad *srcpad, GstPad *sinkpad);
|
|
|
|
static GstPad* gst_basic_scheduler_pad_select (GstScheduler *sched, GList *padlist);
|
2002-03-30 17:05:03 +00:00
|
|
|
static GstClockReturn gst_basic_scheduler_clock_wait (GstScheduler *sched, GstElement *element,
|
2002-05-26 21:54:27 +00:00
|
|
|
GstClock *clock, GstClockTime time, GstClockTimeDiff *jitter);
|
2001-12-24 15:14:03 +00:00
|
|
|
static GstSchedulerState
|
|
|
|
gst_basic_scheduler_iterate (GstScheduler *sched);
|
|
|
|
|
|
|
|
static void gst_basic_scheduler_show (GstScheduler *sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
static GstSchedulerClass *parent_class = NULL;
|
|
|
|
|
2002-06-02 16:20:09 +00:00
|
|
|
/* for threaded bins, these pre- and post-run functions lock and unlock the
|
|
|
|
* elements. we have to avoid deadlocks, so we make these convenience macros
|
|
|
|
* that will avoid using do_cothread_switch from within the scheduler. */
|
|
|
|
|
2002-05-26 03:23:25 +00:00
|
|
|
#define do_element_switch(element) G_STMT_START{ \
|
|
|
|
GstElement *from = SCHED (element)->current; \
|
2002-06-04 23:00:36 +00:00
|
|
|
if (from && from->post_run_func) \
|
2002-05-26 03:23:25 +00:00
|
|
|
from->post_run_func (from); \
|
|
|
|
SCHED (element)->current = element; \
|
2002-05-27 04:48:57 +00:00
|
|
|
if (element->pre_run_func) \
|
|
|
|
element->pre_run_func (element); \
|
2002-05-26 03:23:25 +00:00
|
|
|
do_cothread_switch (GST_ELEMENT_THREADSTATE (element)); \
|
|
|
|
}G_STMT_END
|
|
|
|
|
2002-06-02 16:20:09 +00:00
|
|
|
#define do_switch_to_main(sched) G_STMT_START{ \
|
|
|
|
GstElement *current = ((GstBasicScheduler*)sched)->current; \
|
2002-06-04 23:00:36 +00:00
|
|
|
if (current && current->post_run_func) \
|
2002-06-02 16:20:09 +00:00
|
|
|
current->post_run_func (current); \
|
|
|
|
SCHED (current)->current = NULL; \
|
|
|
|
do_cothread_switch \
|
|
|
|
(do_cothread_get_main \
|
|
|
|
(((GstBasicScheduler*)sched)->context)); \
|
|
|
|
}G_STMT_END
|
|
|
|
|
|
|
|
#define do_switch_from_main(entry) G_STMT_START{ \
|
|
|
|
if (entry->pre_run_func) \
|
|
|
|
entry->pre_run_func (entry); \
|
|
|
|
SCHED (entry)->current = entry; \
|
|
|
|
do_cothread_switch (GST_ELEMENT_THREADSTATE (entry)); \
|
|
|
|
}G_STMT_END
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
static GType
|
|
|
|
gst_basic_scheduler_get_type (void)
|
|
|
|
{
|
|
|
|
if (!_gst_basic_scheduler_type) {
|
|
|
|
static const GTypeInfo scheduler_info = {
|
2001-12-22 21:18:17 +00:00
|
|
|
sizeof (GstBasicSchedulerClass),
|
2001-12-04 22:12:50 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_basic_scheduler_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2001-12-22 21:18:17 +00:00
|
|
|
sizeof (GstBasicScheduler),
|
2001-12-04 22:12:50 +00:00
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_basic_scheduler_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-05-06 19:23:37 +00:00
|
|
|
_gst_basic_scheduler_type = g_type_register_static (GST_TYPE_SCHEDULER, "Gst"COTHREADS_NAME_CAPITAL"Scheduler", &scheduler_info, 0);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
return _gst_basic_scheduler_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_basic_scheduler_class_init (GstBasicSchedulerClass * klass)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstObjectClass *gstobject_class;
|
2001-12-22 21:18:17 +00:00
|
|
|
GstSchedulerClass *gstscheduler_class;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstobject_class = (GstObjectClass*)klass;
|
2001-12-22 21:18:17 +00:00
|
|
|
gstscheduler_class = (GstSchedulerClass*)klass;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_SCHEDULER);
|
|
|
|
|
2001-12-15 22:37:35 +00:00
|
|
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_basic_scheduler_dispose);
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
gstscheduler_class->setup = GST_DEBUG_FUNCPTR (gst_basic_scheduler_setup);
|
2002-06-27 23:55:27 +00:00
|
|
|
gstscheduler_class->get_preferred_stack= GST_DEBUG_FUNCPTR (gst_basic_scheduler_get_preferred_stack);
|
2001-12-22 21:18:17 +00:00
|
|
|
gstscheduler_class->reset = GST_DEBUG_FUNCPTR (gst_basic_scheduler_reset);
|
|
|
|
gstscheduler_class->add_element = GST_DEBUG_FUNCPTR (gst_basic_scheduler_add_element);
|
|
|
|
gstscheduler_class->remove_element = GST_DEBUG_FUNCPTR (gst_basic_scheduler_remove_element);
|
|
|
|
gstscheduler_class->state_transition = GST_DEBUG_FUNCPTR (gst_basic_scheduler_state_transition);
|
|
|
|
gstscheduler_class->lock_element = GST_DEBUG_FUNCPTR (gst_basic_scheduler_lock_element);
|
|
|
|
gstscheduler_class->unlock_element = GST_DEBUG_FUNCPTR (gst_basic_scheduler_unlock_element);
|
|
|
|
gstscheduler_class->yield = GST_DEBUG_FUNCPTR (gst_basic_scheduler_yield);
|
|
|
|
gstscheduler_class->interrupt = GST_DEBUG_FUNCPTR (gst_basic_scheduler_interrupt);
|
|
|
|
gstscheduler_class->error = GST_DEBUG_FUNCPTR (gst_basic_scheduler_error);
|
|
|
|
gstscheduler_class->pad_connect = GST_DEBUG_FUNCPTR (gst_basic_scheduler_pad_connect);
|
|
|
|
gstscheduler_class->pad_disconnect = GST_DEBUG_FUNCPTR (gst_basic_scheduler_pad_disconnect);
|
|
|
|
gstscheduler_class->pad_select = GST_DEBUG_FUNCPTR (gst_basic_scheduler_pad_select);
|
2002-03-30 17:05:03 +00:00
|
|
|
gstscheduler_class->clock_wait = GST_DEBUG_FUNCPTR (gst_basic_scheduler_clock_wait);
|
2001-12-22 21:18:17 +00:00
|
|
|
gstscheduler_class->iterate = GST_DEBUG_FUNCPTR (gst_basic_scheduler_iterate);
|
2002-02-02 13:27:33 +00:00
|
|
|
|
|
|
|
gstscheduler_class->show = GST_DEBUG_FUNCPTR (gst_basic_scheduler_show);
|
2002-05-06 19:23:37 +00:00
|
|
|
|
|
|
|
do_cothreads_init(NULL);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_basic_scheduler_init (GstBasicScheduler *scheduler)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
2001-12-22 21:18:17 +00:00
|
|
|
scheduler->elements = NULL;
|
|
|
|
scheduler->num_elements = 0;
|
|
|
|
scheduler->chains = NULL;
|
|
|
|
scheduler->num_chains = 0;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
2001-12-15 22:37:35 +00:00
|
|
|
static void
|
|
|
|
gst_basic_scheduler_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstSchedulerFactory *factory;
|
|
|
|
|
|
|
|
gst_plugin_set_longname (plugin, "A basic scheduler");
|
|
|
|
|
2002-09-12 19:23:41 +00:00
|
|
|
factory = gst_scheduler_factory_new ("basic"COTHREADS_NAME,
|
2002-06-23 04:31:45 +00:00
|
|
|
"A basic scheduler using "COTHREADS_NAME" cothreads",
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_basic_scheduler_get_type());
|
|
|
|
|
|
|
|
if (factory != NULL) {
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
}
|
|
|
|
else {
|
2002-05-06 19:23:37 +00:00
|
|
|
g_warning ("could not register scheduler: "COTHREADS_NAME);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2002-09-12 19:23:41 +00:00
|
|
|
"gstbasic"COTHREADS_NAME"scheduler",
|
2001-12-04 22:12:50 +00:00
|
|
|
plugin_init
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
gst_basic_scheduler_loopfunc_wrapper (int argc, char *argv[])
|
|
|
|
{
|
2001-12-22 21:18:17 +00:00
|
|
|
GstElement *element = GST_ELEMENT_CAST (argv);
|
2001-12-04 22:12:50 +00:00
|
|
|
G_GNUC_UNUSED const gchar *name = GST_ELEMENT_NAME (element);
|
|
|
|
|
|
|
|
GST_DEBUG_ENTER ("(%d,'%s')", argc, name);
|
|
|
|
|
2002-06-23 12:50:12 +00:00
|
|
|
gst_object_ref (GST_OBJECT (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
do {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "calling loopfunc %s for element %s",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_FUNCPTR_NAME (element->loopfunc), name);
|
|
|
|
(element->loopfunc) (element);
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "element %s ended loop function", name);
|
2001-12-22 21:18:17 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
} while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element));
|
|
|
|
GST_FLAG_UNSET (element, GST_ELEMENT_COTHREAD_STOPPING);
|
|
|
|
|
2002-06-23 12:50:12 +00:00
|
|
|
/* due to oddities in the cothreads code, when this function returns it will
|
|
|
|
* switch to the main cothread. thus, we need to unlock the current element. */
|
|
|
|
if (SCHED (element)) {
|
|
|
|
if (SCHED (element)->current && SCHED (element)->current->post_run_func) {
|
|
|
|
SCHED (element)->current->post_run_func (SCHED (element)->current);
|
|
|
|
}
|
|
|
|
SCHED (element)->current = NULL;
|
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_LEAVE ("(%d,'%s')", argc, name);
|
2002-06-23 12:50:12 +00:00
|
|
|
gst_object_unref (GST_OBJECT (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gst_basic_scheduler_chain_wrapper (int argc, char *argv[])
|
|
|
|
{
|
2001-12-22 21:18:17 +00:00
|
|
|
GstElement *element = GST_ELEMENT_CAST (argv);
|
2001-12-04 22:12:50 +00:00
|
|
|
G_GNUC_UNUSED const gchar *name = GST_ELEMENT_NAME (element);
|
|
|
|
|
|
|
|
GST_DEBUG_ENTER ("(\"%s\")", name);
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "stepping through pads");
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-05-08 20:40:48 +00:00
|
|
|
gst_object_ref (GST_OBJECT (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
do {
|
|
|
|
GList *pads = element->pads;
|
|
|
|
|
|
|
|
while (pads) {
|
|
|
|
GstPad *pad = GST_PAD (pads->data);
|
|
|
|
GstRealPad *realpad;
|
|
|
|
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
if (!GST_IS_REAL_PAD (pad))
|
|
|
|
continue;
|
2001-12-22 21:18:17 +00:00
|
|
|
|
|
|
|
realpad = GST_REAL_PAD_CAST (pad);
|
|
|
|
|
2002-08-28 10:11:26 +00:00
|
|
|
if (GST_RPAD_DIRECTION (realpad) == GST_PAD_SINK &&
|
|
|
|
GST_PAD_IS_USABLE (realpad)) {
|
2001-12-04 22:12:50 +00:00
|
|
|
GstBuffer *buf;
|
|
|
|
|
2002-08-28 10:11:26 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "pulling data from %s:%s", name,
|
|
|
|
GST_PAD_NAME (pad));
|
2001-12-04 22:12:50 +00:00
|
|
|
buf = gst_pad_pull (pad);
|
|
|
|
if (buf) {
|
|
|
|
if (GST_IS_EVENT (buf) && !GST_ELEMENT_IS_EVENT_AWARE (element)) {
|
|
|
|
gst_pad_send_event (pad, GST_EVENT (buf));
|
|
|
|
}
|
|
|
|
else {
|
2002-08-28 10:11:26 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "calling chain function of %s:%s %p",
|
|
|
|
name, GST_PAD_NAME (pad), buf);
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_RPAD_CHAINFUNC (realpad) (pad, buf);
|
2002-08-28 10:11:26 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW,
|
|
|
|
"calling chain function of element %s done", name);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element));
|
2002-08-28 10:11:26 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_FLAG_UNSET (element, GST_ELEMENT_COTHREAD_STOPPING);
|
|
|
|
|
2002-06-02 16:20:09 +00:00
|
|
|
/* due to oddities in the cothreads code, when this function returns it will
|
|
|
|
* switch to the main cothread. thus, we need to unlock the current element. */
|
2002-06-02 17:44:20 +00:00
|
|
|
if (SCHED (element)) {
|
|
|
|
if (SCHED (element)->current && SCHED (element)->current->post_run_func) {
|
|
|
|
SCHED (element)->current->post_run_func (SCHED (element)->current);
|
|
|
|
}
|
|
|
|
SCHED (element)->current = NULL;
|
|
|
|
}
|
2002-05-27 04:48:57 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_LEAVE ("(%d,'%s')", argc, name);
|
2002-05-29 15:09:36 +00:00
|
|
|
gst_object_unref (GST_OBJECT (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gst_basic_scheduler_src_wrapper (int argc, char *argv[])
|
|
|
|
{
|
2001-12-22 21:18:17 +00:00
|
|
|
GstElement *element = GST_ELEMENT_CAST (argv);
|
2001-12-04 22:12:50 +00:00
|
|
|
GList *pads;
|
|
|
|
GstRealPad *realpad;
|
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
G_GNUC_UNUSED const gchar *name = GST_ELEMENT_NAME (element);
|
|
|
|
|
|
|
|
GST_DEBUG_ENTER ("(%d,\"%s\")", argc, name);
|
|
|
|
|
|
|
|
do {
|
|
|
|
pads = element->pads;
|
|
|
|
while (pads) {
|
2001-12-22 21:18:17 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
if (!GST_IS_REAL_PAD (pads->data))
|
|
|
|
continue;
|
2001-12-22 21:18:17 +00:00
|
|
|
|
|
|
|
realpad = GST_REAL_PAD_CAST (pads->data);
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
pads = g_list_next (pads);
|
2002-07-24 21:09:46 +00:00
|
|
|
if (GST_RPAD_DIRECTION (realpad) == GST_PAD_SRC && GST_PAD_IS_USABLE (realpad)) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "calling _getfunc for %s:%s", GST_DEBUG_PAD_NAME (realpad));
|
2002-05-26 21:54:27 +00:00
|
|
|
g_return_val_if_fail (GST_RPAD_GETFUNC (realpad) != NULL, 0);
|
|
|
|
buf = GST_RPAD_GETFUNC (realpad) (GST_PAD_CAST (realpad));
|
|
|
|
if (buf) {
|
2002-07-02 18:42:00 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "calling gst_pad_push on pad %s:%s %p",
|
|
|
|
GST_DEBUG_PAD_NAME (realpad), buf);
|
2002-05-26 21:54:27 +00:00
|
|
|
gst_pad_push (GST_PAD_CAST (realpad), buf);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element));
|
2002-02-02 13:27:33 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_FLAG_UNSET (element, GST_ELEMENT_COTHREAD_STOPPING);
|
|
|
|
|
2002-06-02 16:20:09 +00:00
|
|
|
/* due to oddities in the cothreads code, when this function returns it will
|
|
|
|
* switch to the main cothread. thus, we need to unlock the current element. */
|
|
|
|
if (SCHED (element)->current->post_run_func)
|
|
|
|
SCHED (element)->current->post_run_func (SCHED (element)->current);
|
|
|
|
SCHED (element)->current = NULL;
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_LEAVE ("");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_chainhandler_proxy (GstPad * pad, GstBuffer * buf)
|
|
|
|
{
|
2002-01-01 13:51:04 +00:00
|
|
|
gint loop_count = 100;
|
2002-05-26 03:23:25 +00:00
|
|
|
GstElement *parent;
|
|
|
|
GstRealPad *peer;
|
|
|
|
|
|
|
|
parent = GST_PAD_PARENT (pad);
|
|
|
|
peer = GST_RPAD_PEER (pad);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "putting buffer %p in peer \"%s:%s\"'s pen", buf,
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_PAD_NAME (peer));
|
|
|
|
|
2002-01-01 13:51:04 +00:00
|
|
|
/*
|
2001-12-17 18:51:40 +00:00
|
|
|
* loop until the bufferpen is empty so we can fill it up again
|
|
|
|
*/
|
2002-01-01 13:51:04 +00:00
|
|
|
while (GST_RPAD_BUFPEN (GST_RPAD_PEER (pad)) != NULL && --loop_count) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "switching to %p to empty bufpen %d",
|
2002-05-26 03:23:25 +00:00
|
|
|
GST_ELEMENT_THREADSTATE (parent), loop_count);
|
|
|
|
|
|
|
|
do_element_switch (parent);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* we may no longer be the same pad, check. */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_RPAD_PEER (peer) != (GstRealPad *) pad) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "new pad in mid-switch!");
|
2001-12-04 22:12:50 +00:00
|
|
|
pad = (GstPad *) GST_RPAD_PEER (peer);
|
|
|
|
}
|
2002-05-29 15:09:36 +00:00
|
|
|
parent = GST_PAD_PARENT (pad);
|
|
|
|
peer = GST_RPAD_PEER (pad);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-01 13:51:04 +00:00
|
|
|
if (loop_count == 0) {
|
2002-05-26 03:23:25 +00:00
|
|
|
gst_element_error (parent,
|
2002-09-30 10:58:40 +00:00
|
|
|
"(internal error) basic: maximum number of switches exceeded");
|
2002-01-01 13:51:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-05-26 03:23:25 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
g_assert (GST_RPAD_BUFPEN (GST_RPAD_PEER (pad)) == NULL);
|
2002-05-26 03:23:25 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* now fill the bufferpen and switch so it can be consumed */
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_RPAD_BUFPEN (GST_RPAD_PEER (pad)) = buf;
|
2002-07-02 18:42:00 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "switching to %p to consume buffer %p",
|
|
|
|
GST_ELEMENT_THREADSTATE (GST_PAD_PARENT (pad)), buf);
|
2002-05-26 03:23:25 +00:00
|
|
|
|
|
|
|
do_element_switch (parent);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "done switching");
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_select_proxy (GstPad * pad, GstBuffer * buf)
|
|
|
|
{
|
2002-05-26 03:23:25 +00:00
|
|
|
GstElement *parent;
|
|
|
|
|
|
|
|
parent = GST_PAD_PARENT (pad);
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "putting buffer %p in peer's pen", buf);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
g_assert (GST_RPAD_BUFPEN (GST_RPAD_PEER (pad)) == NULL);
|
2001-12-17 18:51:40 +00:00
|
|
|
/* now fill the bufferpen and switch so it can be consumed */
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_RPAD_BUFPEN (GST_RPAD_PEER (pad)) = buf;
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "switching to %p",
|
2002-05-26 03:23:25 +00:00
|
|
|
GST_ELEMENT_THREADSTATE (parent));
|
|
|
|
parent->select_pad = pad;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-05-26 03:23:25 +00:00
|
|
|
do_element_switch (parent);
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "done switching");
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstBuffer *
|
|
|
|
gst_basic_scheduler_gethandler_proxy (GstPad * pad)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
2002-05-26 03:23:25 +00:00
|
|
|
GstElement *parent;
|
|
|
|
GstRealPad *peer;
|
|
|
|
|
2002-05-29 15:09:36 +00:00
|
|
|
GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
2002-05-26 03:23:25 +00:00
|
|
|
parent = GST_PAD_PARENT (pad);
|
|
|
|
peer = GST_RPAD_PEER (pad);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* FIXME this should be bounded */
|
|
|
|
/* we will loop switching to the peer until it's filled up the bufferpen */
|
2001-12-04 22:12:50 +00:00
|
|
|
while (GST_RPAD_BUFPEN (pad) == NULL) {
|
2002-05-29 15:09:36 +00:00
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "switching to \"%s\": %p to fill bufpen",
|
2002-05-26 03:23:25 +00:00
|
|
|
GST_ELEMENT_NAME (parent),
|
|
|
|
GST_ELEMENT_THREADSTATE (parent));
|
|
|
|
|
|
|
|
do_element_switch (parent);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* we may no longer be the same pad, check. */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_RPAD_PEER (peer) != (GstRealPad *) pad) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "new pad in mid-switch!");
|
2001-12-04 22:12:50 +00:00
|
|
|
pad = (GstPad *) GST_RPAD_PEER (peer);
|
2002-03-30 17:05:03 +00:00
|
|
|
if (!pad) {
|
2002-05-26 03:23:25 +00:00
|
|
|
gst_element_error (parent, "pad unconnected");
|
2002-03-30 17:05:03 +00:00
|
|
|
}
|
2002-05-29 15:09:36 +00:00
|
|
|
parent = GST_PAD_PARENT (pad);
|
|
|
|
peer = GST_RPAD_PEER (pad);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "done switching");
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* now grab the buffer from the pen, clear the pen, and return the buffer */
|
2001-12-04 22:12:50 +00:00
|
|
|
buf = GST_RPAD_BUFPEN (pad);
|
|
|
|
GST_RPAD_BUFPEN (pad) = NULL;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
static gboolean
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_basic_scheduler_cothreaded_chain (GstBin * bin, GstSchedulerChain * chain)
|
|
|
|
{
|
|
|
|
GList *elements;
|
|
|
|
GstElement *element;
|
|
|
|
cothread_func wrapper_function;
|
2002-09-12 20:52:03 +00:00
|
|
|
const GList *pads;
|
2001-12-04 22:12:50 +00:00
|
|
|
GstPad *pad;
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "chain is using COTHREADS");
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-05-06 19:23:37 +00:00
|
|
|
g_assert (chain->sched->context != NULL);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* walk through all the chain's elements */
|
2001-12-04 22:12:50 +00:00
|
|
|
elements = chain->elements;
|
|
|
|
while (elements) {
|
2001-12-22 21:18:17 +00:00
|
|
|
gboolean decoupled;
|
|
|
|
|
|
|
|
element = GST_ELEMENT_CAST (elements->data);
|
2001-12-04 22:12:50 +00:00
|
|
|
elements = g_list_next (elements);
|
|
|
|
|
2002-09-12 18:54:16 +00:00
|
|
|
decoupled = GST_FLAG_IS_SET (element, GST_ELEMENT_DECOUPLED);
|
2001-12-22 21:18:17 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* start out without a wrapper function, we select it later */
|
2001-12-04 22:12:50 +00:00
|
|
|
wrapper_function = NULL;
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* if the element has a loopfunc... */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (element->loopfunc != NULL) {
|
|
|
|
wrapper_function = GST_DEBUG_FUNCPTR (gst_basic_scheduler_loopfunc_wrapper);
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "element '%s' is a loop-based",
|
|
|
|
GST_ELEMENT_NAME (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-09-12 18:54:16 +00:00
|
|
|
/* otherwise we need to decide what kind of cothread
|
|
|
|
* if it's not DECOUPLED, we decide based on
|
|
|
|
* whether it's a source or not */
|
2001-12-22 21:18:17 +00:00
|
|
|
if (!decoupled) {
|
2001-12-17 18:51:40 +00:00
|
|
|
/* if it doesn't have any sinks, it must be a source (duh) */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (element->numsinkpads == 0) {
|
|
|
|
wrapper_function = GST_DEBUG_FUNCPTR (gst_basic_scheduler_src_wrapper);
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"element '%s' is a source, using _src_wrapper",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wrapper_function = GST_DEBUG_FUNCPTR (gst_basic_scheduler_chain_wrapper);
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"element '%s' is a filter, using _chain_wrapper",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* now we have to walk through the pads to set up their state */
|
2001-12-04 22:12:50 +00:00
|
|
|
pads = gst_element_get_pad_list (element);
|
|
|
|
while (pads) {
|
2001-12-22 21:18:17 +00:00
|
|
|
GstPad *peerpad;
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
pad = GST_PAD (pads->data);
|
|
|
|
pads = g_list_next (pads);
|
2001-12-22 21:18:17 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
if (!GST_IS_REAL_PAD (pad))
|
|
|
|
continue;
|
2001-12-22 21:18:17 +00:00
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
peerpad = GST_PAD_PEER (pad);
|
2002-06-04 21:03:35 +00:00
|
|
|
if (peerpad) {
|
|
|
|
GstElement *peerelement = GST_ELEMENT_CAST (GST_PAD_PARENT (peerpad));
|
|
|
|
gboolean different_sched = (peerelement->sched != GST_SCHEDULER (chain->sched));
|
|
|
|
gboolean peer_decoupled = GST_FLAG_IS_SET (peerelement, GST_ELEMENT_DECOUPLED);
|
|
|
|
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"inspecting pad %s:%s", GST_DEBUG_PAD_NAME (peerpad));
|
2002-06-04 21:03:35 +00:00
|
|
|
|
|
|
|
/* we don't need to check this for decoupled elements */
|
|
|
|
if (!decoupled) {
|
2002-09-12 18:54:16 +00:00
|
|
|
/* if the peer element is in another schedule,
|
|
|
|
* it's not decoupled and we are not decoupled
|
2002-06-04 21:03:35 +00:00
|
|
|
* either, we have an error */
|
|
|
|
if (different_sched && !peer_decoupled)
|
|
|
|
{
|
2002-09-12 18:54:16 +00:00
|
|
|
gst_element_error (element,
|
|
|
|
"element \"%s\" is not decoupled but has pads "
|
|
|
|
"in different schedulers",
|
|
|
|
GST_ELEMENT_NAME (element), NULL);
|
2002-06-04 21:03:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-09-12 18:54:16 +00:00
|
|
|
/* ok, the peer is in a different scheduler and is decoupled,
|
|
|
|
* we need to set the
|
2002-06-04 21:03:35 +00:00
|
|
|
* handlers so we can talk with it */
|
|
|
|
else if (different_sched) {
|
|
|
|
if (GST_RPAD_DIRECTION (peerpad) == GST_PAD_SINK) {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"copying chain func into push proxy for peer %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (peerpad));
|
2002-06-04 21:03:35 +00:00
|
|
|
GST_RPAD_CHAINHANDLER (peerpad) = GST_RPAD_CHAINFUNC (peerpad);
|
|
|
|
}
|
|
|
|
else {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"copying get func into pull proxy for peer %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (peerpad));
|
2002-06-04 21:03:35 +00:00
|
|
|
GST_RPAD_GETHANDLER (peerpad) = GST_RPAD_GETFUNC (peerpad);
|
|
|
|
}
|
|
|
|
}
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
2002-06-04 21:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if the element is DECOUPLED or outside the manager, we have to chain */
|
|
|
|
if (decoupled) {
|
2001-12-17 18:51:40 +00:00
|
|
|
/* set the chain proxies */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_RPAD_DIRECTION (pad) == GST_PAD_SINK) {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"copying chain function into push proxy for %s:%s",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
|
|
|
GST_RPAD_CHAINHANDLER (pad) = GST_RPAD_CHAINFUNC (pad);
|
|
|
|
}
|
|
|
|
else {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"copying get function into pull proxy for %s:%s",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
|
|
|
GST_RPAD_GETHANDLER (pad) = GST_RPAD_GETFUNC (pad);
|
|
|
|
}
|
|
|
|
}
|
2001-12-22 21:18:17 +00:00
|
|
|
/* otherwise we really are a cothread */
|
2001-12-04 22:12:50 +00:00
|
|
|
else {
|
2002-06-04 21:03:35 +00:00
|
|
|
if (GST_RPAD_DIRECTION (pad) == GST_PAD_SINK) {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"setting cothreaded push proxy for sinkpad %s:%s",
|
2001-12-22 21:18:17 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_RPAD_CHAINHANDLER (pad) = GST_DEBUG_FUNCPTR (gst_basic_scheduler_chainhandler_proxy);
|
|
|
|
}
|
|
|
|
else {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"setting cothreaded pull proxy for srcpad %s:%s",
|
2001-12-22 21:18:17 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_RPAD_GETHANDLER (pad) = GST_DEBUG_FUNCPTR (gst_basic_scheduler_gethandler_proxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* need to set up the cothread now */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (wrapper_function != NULL) {
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_ELEMENT_THREADSTATE (element) == NULL) {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"about to create a cothread, wrapper for '%s' is &%s",
|
|
|
|
GST_ELEMENT_NAME (element),
|
|
|
|
GST_DEBUG_FUNCPTR_NAME (wrapper_function));
|
|
|
|
do_cothread_create (GST_ELEMENT_THREADSTATE (element),
|
|
|
|
chain->sched->context,
|
2002-05-06 19:23:37 +00:00
|
|
|
wrapper_function, 0, (char **) element);
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_ELEMENT_THREADSTATE (element) == NULL) {
|
|
|
|
gst_element_error (element, "could not create cothread for \"%s\"",
|
|
|
|
GST_ELEMENT_NAME (element), NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "created cothread %p for '%s'",
|
2001-12-22 21:18:17 +00:00
|
|
|
GST_ELEMENT_THREADSTATE (element),
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_ELEMENT_NAME (element));
|
2002-05-06 19:23:37 +00:00
|
|
|
} else {
|
2002-06-16 17:34:14 +00:00
|
|
|
/* set the cothread wrapper function */
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"about to set the wrapper function for '%s' to &%s",
|
|
|
|
GST_ELEMENT_NAME (element),
|
|
|
|
GST_DEBUG_FUNCPTR_NAME (wrapper_function));
|
|
|
|
do_cothread_setfunc (GST_ELEMENT_THREADSTATE (element),
|
|
|
|
chain->sched->context,
|
2002-06-16 17:34:14 +00:00
|
|
|
wrapper_function, 0, (char **) element);
|
2002-05-06 19:23:37 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "set wrapper function for '%s' to &%s",
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_ELEMENT_NAME (element),
|
|
|
|
GST_DEBUG_FUNCPTR_NAME (wrapper_function));
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-22 21:18:17 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstSchedulerChain *
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_basic_scheduler_chain_new (GstBasicScheduler * sched)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
|
|
|
GstSchedulerChain *chain = g_new (GstSchedulerChain, 1);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* initialize the chain with sane values */
|
2001-12-04 22:12:50 +00:00
|
|
|
chain->sched = sched;
|
|
|
|
chain->disabled = NULL;
|
|
|
|
chain->elements = NULL;
|
|
|
|
chain->num_elements = 0;
|
|
|
|
chain->entry = NULL;
|
|
|
|
chain->cothreaded_elements = 0;
|
|
|
|
chain->schedule = FALSE;
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* add the chain to the schedulers' list of chains */
|
2001-12-04 22:12:50 +00:00
|
|
|
sched->chains = g_list_prepend (sched->chains, chain);
|
|
|
|
sched->num_chains++;
|
|
|
|
|
2002-01-28 00:40:11 +00:00
|
|
|
/* notify the scheduler that something changed */
|
|
|
|
GST_FLAG_SET(sched, GST_BASIC_SCHEDULER_CHANGE);
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "created new chain %p, now are %d chains in sched %p",
|
|
|
|
chain, sched->num_chains, sched);
|
|
|
|
|
|
|
|
return chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_chain_destroy (GstSchedulerChain * chain)
|
|
|
|
{
|
2001-12-22 21:18:17 +00:00
|
|
|
GstBasicScheduler *sched = chain->sched;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* remove the chain from the schedulers' list of chains */
|
2001-12-15 22:37:35 +00:00
|
|
|
sched->chains = g_list_remove (sched->chains, chain);
|
|
|
|
sched->num_chains--;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* destroy the chain */
|
|
|
|
g_list_free (chain->disabled); /* should be empty... */
|
|
|
|
g_list_free (chain->elements); /* ditto */
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "destroyed chain %p, now are %d chains in sched %p", chain,
|
|
|
|
sched->num_chains, sched);
|
2001-12-15 22:37:35 +00:00
|
|
|
|
|
|
|
g_free (chain);
|
2002-01-28 00:40:11 +00:00
|
|
|
|
|
|
|
/* notify the scheduler that something changed */
|
|
|
|
GST_FLAG_SET(sched, GST_BASIC_SCHEDULER_CHANGE);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_chain_add_element (GstSchedulerChain * chain, GstElement * element)
|
|
|
|
{
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "adding element \"%s\" to chain %p", GST_ELEMENT_NAME (element),
|
|
|
|
chain);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* set the sched pointer for the element */
|
2001-12-22 21:18:17 +00:00
|
|
|
element->sched = GST_SCHEDULER (chain->sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* add the element to the list of 'disabled' elements */
|
2001-12-04 22:12:50 +00:00
|
|
|
chain->disabled = g_list_prepend (chain->disabled, element);
|
|
|
|
chain->num_elements++;
|
2002-01-28 00:40:11 +00:00
|
|
|
|
|
|
|
/* notify the scheduler that something changed */
|
|
|
|
GST_FLAG_SET(chain->sched, GST_BASIC_SCHEDULER_CHANGE);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
static gboolean
|
2002-09-12 18:54:16 +00:00
|
|
|
gst_basic_scheduler_chain_enable_element (GstSchedulerChain * chain,
|
|
|
|
GstElement * element)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "enabling element \"%s\" in chain %p",
|
|
|
|
GST_ELEMENT_NAME (element), chain);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* remove from disabled list */
|
2001-12-04 22:12:50 +00:00
|
|
|
chain->disabled = g_list_remove (chain->disabled, element);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* add to elements list */
|
2001-12-04 22:12:50 +00:00
|
|
|
chain->elements = g_list_prepend (chain->elements, element);
|
|
|
|
|
2002-01-28 00:40:11 +00:00
|
|
|
/* notify the scheduler that something changed */
|
|
|
|
GST_FLAG_SET(chain->sched, GST_BASIC_SCHEDULER_CHANGE);
|
2002-04-14 14:59:34 +00:00
|
|
|
/* GST_FLAG_UNSET(element, GST_ELEMENT_COTHREAD_STOPPING); */
|
2002-01-28 00:40:11 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* reschedule the chain */
|
2001-12-22 21:18:17 +00:00
|
|
|
return gst_basic_scheduler_cothreaded_chain (GST_BIN (GST_SCHEDULER (chain->sched)->parent), chain);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-09-12 18:54:16 +00:00
|
|
|
gst_basic_scheduler_chain_disable_element (GstSchedulerChain * chain,
|
|
|
|
GstElement * element)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "disabling element \"%s\" in chain %p",
|
|
|
|
GST_ELEMENT_NAME (element), chain);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* remove from elements list */
|
2001-12-04 22:12:50 +00:00
|
|
|
chain->elements = g_list_remove (chain->elements, element);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* add to disabled list */
|
2001-12-04 22:12:50 +00:00
|
|
|
chain->disabled = g_list_prepend (chain->disabled, element);
|
|
|
|
|
2002-01-28 00:40:11 +00:00
|
|
|
/* notify the scheduler that something changed */
|
|
|
|
GST_FLAG_SET(chain->sched, GST_BASIC_SCHEDULER_CHANGE);
|
2002-03-30 17:05:03 +00:00
|
|
|
GST_FLAG_SET(element, GST_ELEMENT_COTHREAD_STOPPING);
|
2002-01-28 00:40:11 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* reschedule the chain */
|
|
|
|
/* FIXME this should be done only if manager state != NULL */
|
|
|
|
/* gst_basic_scheduler_cothreaded_chain(GST_BIN(chain->sched->parent),chain); */
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_chain_remove_element (GstSchedulerChain * chain, GstElement * element)
|
|
|
|
{
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "removing element \"%s\" from chain %p", GST_ELEMENT_NAME (element),
|
|
|
|
chain);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* if it's active, deactivate it */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (g_list_find (chain->elements, element)) {
|
|
|
|
gst_basic_scheduler_chain_disable_element (chain, element);
|
|
|
|
}
|
2001-12-20 20:03:10 +00:00
|
|
|
/* we have to check for a threadstate here because a queue doesn't have one */
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_ELEMENT_THREADSTATE (element)) {
|
2002-05-06 19:23:37 +00:00
|
|
|
do_cothread_destroy (GST_ELEMENT_THREADSTATE (element));
|
2001-12-22 21:18:17 +00:00
|
|
|
GST_ELEMENT_THREADSTATE (element) = NULL;
|
2001-12-20 20:03:10 +00:00
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* remove the element from the list of elements */
|
2001-12-04 22:12:50 +00:00
|
|
|
chain->disabled = g_list_remove (chain->disabled, element);
|
|
|
|
chain->num_elements--;
|
|
|
|
|
2002-01-28 00:40:11 +00:00
|
|
|
/* notify the scheduler that something changed */
|
|
|
|
GST_FLAG_SET(chain->sched, GST_BASIC_SCHEDULER_CHANGE);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* if there are no more elements in the chain, destroy the chain */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (chain->num_elements == 0)
|
|
|
|
gst_basic_scheduler_chain_destroy (chain);
|
2002-01-28 00:40:11 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_basic_scheduler_chain_elements (GstBasicScheduler * sched, GstElement * element1, GstElement * element2)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
|
|
|
GList *chains;
|
|
|
|
GstSchedulerChain *chain;
|
|
|
|
GstSchedulerChain *chain1 = NULL, *chain2 = NULL;
|
|
|
|
GstElement *element;
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* first find the chains that hold the two */
|
2001-12-04 22:12:50 +00:00
|
|
|
chains = sched->chains;
|
|
|
|
while (chains) {
|
|
|
|
chain = (GstSchedulerChain *) (chains->data);
|
|
|
|
chains = g_list_next (chains);
|
|
|
|
|
|
|
|
if (g_list_find (chain->disabled, element1))
|
|
|
|
chain1 = chain;
|
|
|
|
else if (g_list_find (chain->elements, element1))
|
|
|
|
chain1 = chain;
|
|
|
|
|
|
|
|
if (g_list_find (chain->disabled, element2))
|
|
|
|
chain2 = chain;
|
|
|
|
else if (g_list_find (chain->elements, element2))
|
|
|
|
chain2 = chain;
|
|
|
|
}
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* first check to see if they're in the same chain, we're done if that's the case */
|
2001-12-04 22:12:50 +00:00
|
|
|
if ((chain1 != NULL) && (chain1 == chain2)) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "elements are already in the same chain");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* now, if neither element has a chain, create one */
|
2001-12-04 22:12:50 +00:00
|
|
|
if ((chain1 == NULL) && (chain2 == NULL)) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "creating new chain to hold two new elements");
|
|
|
|
chain = gst_basic_scheduler_chain_new (sched);
|
|
|
|
gst_basic_scheduler_chain_add_element (chain, element1);
|
|
|
|
gst_basic_scheduler_chain_add_element (chain, element2);
|
2001-12-17 18:51:40 +00:00
|
|
|
/* FIXME chain changed here */
|
|
|
|
/* gst_basic_scheduler_cothreaded_chain(chain->sched->parent,chain); */
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* otherwise if both have chains already, join them */
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
else if ((chain1 != NULL) && (chain2 != NULL)) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "merging chain %p into chain %p", chain2, chain1);
|
2001-12-17 18:51:40 +00:00
|
|
|
/* take the contents of chain2 and merge them into chain1 */
|
2001-12-04 22:12:50 +00:00
|
|
|
chain1->disabled = g_list_concat (chain1->disabled, g_list_copy (chain2->disabled));
|
|
|
|
chain1->elements = g_list_concat (chain1->elements, g_list_copy (chain2->elements));
|
|
|
|
chain1->num_elements += chain2->num_elements;
|
2001-12-17 18:51:40 +00:00
|
|
|
/* FIXME chain changed here */
|
|
|
|
/* gst_basic_scheduler_cothreaded_chain(chain->sched->parent,chain); */
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
gst_basic_scheduler_chain_destroy (chain2);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* otherwise one has a chain already, the other doesn't */
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-12-17 18:51:40 +00:00
|
|
|
/* pick out which one has the chain, and which doesn't */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (chain1 != NULL)
|
|
|
|
chain = chain1, element = element2;
|
|
|
|
else
|
|
|
|
chain = chain2, element = element1;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "adding element to existing chain");
|
|
|
|
gst_basic_scheduler_chain_add_element (chain, element);
|
2001-12-17 18:51:40 +00:00
|
|
|
/* FIXME chain changed here */
|
|
|
|
/* gst_basic_scheduler_cothreaded_chain(chain->sched->parent,chain); */
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
2002-02-02 13:27:33 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* find the chain within the scheduler that holds the element, if any */
|
2001-12-04 22:12:50 +00:00
|
|
|
static GstSchedulerChain *
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_basic_scheduler_find_chain (GstBasicScheduler * sched, GstElement * element)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
|
|
|
GList *chains;
|
|
|
|
GstSchedulerChain *chain;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "searching for element \"%s\" in chains",
|
|
|
|
GST_ELEMENT_NAME (element));
|
|
|
|
|
|
|
|
chains = sched->chains;
|
|
|
|
while (chains) {
|
|
|
|
chain = (GstSchedulerChain *) (chains->data);
|
|
|
|
chains = g_list_next (chains);
|
|
|
|
|
|
|
|
if (g_list_find (chain->elements, element))
|
|
|
|
return chain;
|
|
|
|
if (g_list_find (chain->disabled, element))
|
|
|
|
return chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_chain_recursive_add (GstSchedulerChain * chain, GstElement * element)
|
|
|
|
{
|
|
|
|
GList *pads;
|
|
|
|
GstPad *pad;
|
|
|
|
GstElement *peerelement;
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* add the element to the chain */
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_basic_scheduler_chain_add_element (chain, element);
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "recursing on element \"%s\"", GST_ELEMENT_NAME (element));
|
2001-12-17 18:51:40 +00:00
|
|
|
/* now go through all the pads and see which peers can be added */
|
2001-12-04 22:12:50 +00:00
|
|
|
pads = element->pads;
|
|
|
|
while (pads) {
|
|
|
|
pad = GST_PAD (pads->data);
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "have pad %s:%s, checking for valid peer",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2001-12-17 18:51:40 +00:00
|
|
|
/* if the peer exists and could be in the same chain */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_PAD_PEER (pad)) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "has peer %s:%s", GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)));
|
2001-12-04 22:12:50 +00:00
|
|
|
peerelement = GST_PAD_PARENT (GST_PAD_PEER (pad));
|
|
|
|
if (GST_ELEMENT_SCHED (GST_PAD_PARENT (pad)) == GST_ELEMENT_SCHED (peerelement)) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "peer \"%s\" is valid for same chain",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_ELEMENT_NAME (peerelement));
|
2001-12-17 18:51:40 +00:00
|
|
|
/* if it's not already in a chain, add it to this one */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (gst_basic_scheduler_find_chain (chain->sched, peerelement) == NULL) {
|
|
|
|
gst_basic_scheduler_chain_recursive_add (chain, peerelement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Entry points for this scheduler.
|
|
|
|
*/
|
2001-12-19 19:22:53 +00:00
|
|
|
static void
|
|
|
|
gst_basic_scheduler_setup (GstScheduler *sched)
|
|
|
|
{
|
|
|
|
/* first create thread context */
|
2002-05-06 19:23:37 +00:00
|
|
|
if (GST_BASIC_SCHEDULER_CAST (sched)->context == NULL) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "initializing cothread context");
|
2002-05-06 19:23:37 +00:00
|
|
|
GST_BASIC_SCHEDULER_CAST (sched)->context = do_cothread_context_init ();
|
2001-12-19 19:22:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-19 18:13:28 +00:00
|
|
|
static gboolean
|
2002-09-12 18:54:16 +00:00
|
|
|
gst_basic_scheduler_get_preferred_stack (GstScheduler *sched,
|
|
|
|
gpointer *stack, gulong *size)
|
2002-06-19 18:13:28 +00:00
|
|
|
{
|
|
|
|
if (do_cothreads_stackquery (stack, size)) {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING,
|
|
|
|
"getting preferred stack size as %p and %lu", *stack, *size);
|
2002-06-19 18:13:28 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-12-19 19:22:53 +00:00
|
|
|
static void
|
|
|
|
gst_basic_scheduler_reset (GstScheduler *sched)
|
|
|
|
{
|
|
|
|
cothread_context *ctx;
|
2001-12-22 21:18:17 +00:00
|
|
|
GList *elements = GST_BASIC_SCHEDULER_CAST (sched)->elements;
|
2001-12-19 19:22:53 +00:00
|
|
|
|
|
|
|
while (elements) {
|
2002-05-06 19:23:37 +00:00
|
|
|
/* FIXME: wingo, do we need to destroy the cothreads here? */
|
2001-12-22 21:18:17 +00:00
|
|
|
GST_ELEMENT_THREADSTATE (elements->data) = NULL;
|
2001-12-19 19:22:53 +00:00
|
|
|
elements = g_list_next (elements);
|
|
|
|
}
|
|
|
|
|
2002-05-06 19:23:37 +00:00
|
|
|
ctx = GST_BASIC_SCHEDULER_CAST (sched)->context;
|
2001-12-19 19:22:53 +00:00
|
|
|
|
2002-05-06 19:23:37 +00:00
|
|
|
do_cothread_context_destroy (ctx);
|
2001-12-19 19:22:53 +00:00
|
|
|
|
2002-05-06 19:23:37 +00:00
|
|
|
GST_BASIC_SCHEDULER_CAST (sched)->context = NULL;
|
2001-12-19 19:22:53 +00:00
|
|
|
}
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
static void
|
|
|
|
gst_basic_scheduler_add_element (GstScheduler * sched, GstElement * element)
|
|
|
|
{
|
|
|
|
GstSchedulerChain *chain;
|
2001-12-22 21:18:17 +00:00
|
|
|
GstBasicScheduler *bsched = GST_BASIC_SCHEDULER (sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "adding element \"%s\" to scheduler", GST_ELEMENT_NAME (element));
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* only deal with elements after this point, not bins */
|
|
|
|
/* exception is made for Bin's that are schedulable, like the autoplugger */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_IS_BIN (element) && !GST_FLAG_IS_SET (element, GST_BIN_SELF_SCHEDULABLE))
|
|
|
|
return;
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* first add it to the list of elements that are to be scheduled */
|
2001-12-22 21:18:17 +00:00
|
|
|
bsched->elements = g_list_prepend (bsched->elements, element);
|
|
|
|
bsched->num_elements++;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* create a chain to hold it, and add */
|
2001-12-22 21:18:17 +00:00
|
|
|
chain = gst_basic_scheduler_chain_new (bsched);
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_basic_scheduler_chain_add_element (chain, element);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_remove_element (GstScheduler * sched, GstElement * element)
|
|
|
|
{
|
|
|
|
GstSchedulerChain *chain;
|
2001-12-22 21:18:17 +00:00
|
|
|
GstBasicScheduler *bsched = GST_BASIC_SCHEDULER (sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
if (g_list_find (bsched->elements, element)) {
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "removing element \"%s\" from scheduler",
|
|
|
|
GST_ELEMENT_NAME (element));
|
|
|
|
|
2002-05-29 15:09:36 +00:00
|
|
|
/* if we are removing the currently scheduled element */
|
|
|
|
if (bsched->current == element) {
|
|
|
|
GST_FLAG_SET(element, GST_ELEMENT_COTHREAD_STOPPING);
|
|
|
|
if (element->post_run_func)
|
|
|
|
element->post_run_func (element);
|
|
|
|
bsched->current = NULL;
|
|
|
|
}
|
2001-12-17 18:51:40 +00:00
|
|
|
/* find what chain the element is in */
|
2001-12-22 21:18:17 +00:00
|
|
|
chain = gst_basic_scheduler_find_chain (bsched, element);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* remove it from its chain */
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_basic_scheduler_chain_remove_element (chain, element);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* remove it from the list of elements */
|
2001-12-22 21:18:17 +00:00
|
|
|
bsched->elements = g_list_remove (bsched->elements, element);
|
|
|
|
bsched->num_elements--;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* unset the scheduler pointer in the element */
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
static GstElementStateReturn
|
2001-12-20 20:03:10 +00:00
|
|
|
gst_basic_scheduler_state_transition (GstScheduler *sched, GstElement *element, gint transition)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
|
|
|
GstSchedulerChain *chain;
|
2001-12-22 21:18:17 +00:00
|
|
|
GstBasicScheduler *bsched = GST_BASIC_SCHEDULER (sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-24 15:14:03 +00:00
|
|
|
/* check if our parent changed state */
|
|
|
|
if (GST_SCHEDULER_PARENT (sched) == element) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "parent \"%s\" changed state", GST_ELEMENT_NAME (element));
|
|
|
|
if (transition == GST_STATE_PLAYING_TO_PAUSED) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "setting scheduler state to stopped");
|
|
|
|
GST_SCHEDULER_STATE (sched) = GST_SCHEDULER_STATE_STOPPED;
|
|
|
|
}
|
|
|
|
else if (transition == GST_STATE_PAUSED_TO_PLAYING) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "setting scheduler state to running");
|
|
|
|
GST_SCHEDULER_STATE (sched) = GST_SCHEDULER_STATE_RUNNING;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "no interesting state change, doing nothing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (transition == GST_STATE_PLAYING_TO_PAUSED ||
|
|
|
|
transition == GST_STATE_PAUSED_TO_PLAYING) {
|
|
|
|
/* find the chain the element is in */
|
|
|
|
chain = gst_basic_scheduler_find_chain (bsched, element);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-24 15:14:03 +00:00
|
|
|
/* remove it from the chain */
|
|
|
|
if (chain) {
|
|
|
|
if (transition == GST_STATE_PLAYING_TO_PAUSED) {
|
|
|
|
gst_basic_scheduler_chain_disable_element (chain, element);
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
2001-12-24 15:14:03 +00:00
|
|
|
else if (transition == GST_STATE_PAUSED_TO_PLAYING) {
|
|
|
|
if (!gst_basic_scheduler_chain_enable_element (chain, element)) {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING,
|
|
|
|
"could not enable element \"%s\"",
|
|
|
|
GST_ELEMENT_NAME (element));
|
2001-12-24 15:14:03 +00:00
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-09-12 18:54:16 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING,
|
|
|
|
"element \"%s\" not found in any chain, no state change",
|
|
|
|
GST_ELEMENT_NAME (element));
|
2001-12-24 15:14:03 +00:00
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
2001-12-22 21:18:17 +00:00
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_lock_element (GstScheduler * sched, GstElement * element)
|
|
|
|
{
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_ELEMENT_THREADSTATE (element))
|
2002-05-06 19:23:37 +00:00
|
|
|
do_cothread_lock (GST_ELEMENT_THREADSTATE (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_unlock_element (GstScheduler * sched, GstElement * element)
|
|
|
|
{
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_ELEMENT_THREADSTATE (element))
|
2002-05-06 19:23:37 +00:00
|
|
|
do_cothread_unlock (GST_ELEMENT_THREADSTATE (element));
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_yield (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
|
|
|
if (GST_ELEMENT_IS_COTHREAD_STOPPING (element)) {
|
2002-06-02 16:20:09 +00:00
|
|
|
|
|
|
|
do_switch_to_main (sched);
|
2002-05-26 03:23:25 +00:00
|
|
|
|
|
|
|
/* no need to do a pre_run, the cothread is stopping */
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-27 00:47:41 +00:00
|
|
|
static gboolean
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_basic_scheduler_interrupt (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
2002-05-26 03:23:25 +00:00
|
|
|
|
2002-06-04 23:00:36 +00:00
|
|
|
GST_FLAG_SET (element, GST_ELEMENT_COTHREAD_STOPPING);
|
2002-06-02 16:20:09 +00:00
|
|
|
do_switch_to_main (sched);
|
2001-12-27 00:47:41 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_basic_scheduler_error (GstScheduler *sched, GstElement *element)
|
|
|
|
{
|
|
|
|
GstBasicScheduler *bsched = GST_BASIC_SCHEDULER (sched);
|
|
|
|
|
|
|
|
if (GST_ELEMENT_THREADSTATE (element)) {
|
|
|
|
GstSchedulerChain *chain;
|
|
|
|
|
|
|
|
chain = gst_basic_scheduler_find_chain (bsched, element);
|
|
|
|
if (chain)
|
|
|
|
gst_basic_scheduler_chain_disable_element (chain, element);
|
|
|
|
|
2001-12-24 15:14:03 +00:00
|
|
|
GST_SCHEDULER_STATE (sched) = GST_SCHEDULER_STATE_ERROR;
|
2001-12-22 21:18:17 +00:00
|
|
|
|
2002-06-02 16:20:09 +00:00
|
|
|
do_switch_to_main (sched);
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_pad_connect (GstScheduler * sched, GstPad *srcpad, GstPad *sinkpad)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
|
|
|
GstElement *srcelement, *sinkelement;
|
2001-12-22 21:18:17 +00:00
|
|
|
GstBasicScheduler *bsched = GST_BASIC_SCHEDULER (sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
srcelement = GST_PAD_PARENT (srcpad);
|
|
|
|
g_return_if_fail (srcelement != NULL);
|
|
|
|
sinkelement = GST_PAD_PARENT (sinkpad);
|
|
|
|
g_return_if_fail (sinkelement != NULL);
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "have pad connected callback on %s:%s to %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "srcpad sched is %p, sinkpad sched is %p",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_ELEMENT_SCHED (srcelement), GST_ELEMENT_SCHED (sinkelement));
|
|
|
|
|
|
|
|
if (GST_ELEMENT_SCHED (srcelement) == GST_ELEMENT_SCHED (sinkelement)) {
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "peer %s:%s is in same scheduler, chaining together",
|
|
|
|
GST_DEBUG_PAD_NAME (sinkpad));
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_basic_scheduler_chain_elements (bsched, srcelement, sinkelement);
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_pad_disconnect (GstScheduler * sched, GstPad * srcpad, GstPad * sinkpad)
|
|
|
|
{
|
|
|
|
GstElement *element1, *element2;
|
|
|
|
GstSchedulerChain *chain1, *chain2;
|
2001-12-22 21:18:17 +00:00
|
|
|
GstBasicScheduler *bsched = GST_BASIC_SCHEDULER (sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "disconnecting pads %s:%s and %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* we need to have the parent elements of each pad */
|
2001-12-22 21:18:17 +00:00
|
|
|
element1 = GST_ELEMENT_CAST (GST_PAD_PARENT (srcpad));
|
|
|
|
element2 = GST_ELEMENT_CAST (GST_PAD_PARENT (sinkpad));
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* first task is to remove the old chain they belonged to.
|
|
|
|
* this can be accomplished by taking either of the elements,
|
|
|
|
* since they are guaranteed to be in the same chain
|
|
|
|
* FIXME is it potentially better to make an attempt at splitting cleaner??
|
|
|
|
*/
|
2001-12-22 21:18:17 +00:00
|
|
|
chain1 = gst_basic_scheduler_find_chain (bsched, element1);
|
|
|
|
chain2 = gst_basic_scheduler_find_chain (bsched, element2);
|
2001-12-19 19:22:53 +00:00
|
|
|
|
|
|
|
if (chain1 != chain2) {
|
2001-12-20 02:41:34 +00:00
|
|
|
/* elements not in the same chain don't need to be separated */
|
2001-12-19 19:22:53 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "elements not in the same chain");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chain1) {
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "destroying chain");
|
2001-12-19 19:22:53 +00:00
|
|
|
gst_basic_scheduler_chain_destroy (chain1);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* now create a new chain to hold element1 and build it from scratch */
|
2001-12-22 21:18:17 +00:00
|
|
|
chain1 = gst_basic_scheduler_chain_new (bsched);
|
2001-12-15 22:37:35 +00:00
|
|
|
gst_basic_scheduler_chain_recursive_add (chain1, element1);
|
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* check the other element to see if it landed in the newly created chain */
|
2001-12-22 21:18:17 +00:00
|
|
|
if (gst_basic_scheduler_find_chain (bsched, element2) == NULL) {
|
2001-12-17 18:51:40 +00:00
|
|
|
/* if not in chain, create chain and build from scratch */
|
2001-12-22 21:18:17 +00:00
|
|
|
chain2 = gst_basic_scheduler_chain_new (bsched);
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_basic_scheduler_chain_recursive_add (chain2, element2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPad *
|
|
|
|
gst_basic_scheduler_pad_select (GstScheduler * sched, GList * padlist)
|
|
|
|
{
|
|
|
|
GstPad *pad = NULL;
|
|
|
|
GList *padlist2 = padlist;
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_SCHEDULING, "performing select");
|
|
|
|
|
|
|
|
while (padlist2) {
|
|
|
|
pad = GST_PAD (padlist2->data);
|
|
|
|
|
|
|
|
|
|
|
|
padlist2 = g_list_next (padlist2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* else there is nothing ready to consume, set up the select functions */
|
|
|
|
while (padlist) {
|
|
|
|
pad = GST_PAD (padlist->data);
|
|
|
|
|
|
|
|
GST_RPAD_CHAINHANDLER (pad) = GST_DEBUG_FUNCPTR (gst_basic_scheduler_select_proxy);
|
|
|
|
|
|
|
|
padlist = g_list_next (padlist);
|
|
|
|
}
|
|
|
|
if (pad != NULL) {
|
|
|
|
GstRealPad *peer = GST_RPAD_PEER (pad);
|
|
|
|
|
2002-05-26 03:23:25 +00:00
|
|
|
do_element_switch (GST_PAD_PARENT (peer));
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
pad = GST_ELEMENT (GST_PAD_PARENT (pad))->select_pad;
|
|
|
|
|
|
|
|
g_assert (pad != NULL);
|
|
|
|
}
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
static GstClockReturn
|
|
|
|
gst_basic_scheduler_clock_wait (GstScheduler *sched, GstElement *element,
|
2002-05-26 21:54:27 +00:00
|
|
|
GstClock *clock, GstClockTime time, GstClockTimeDiff *jitter)
|
2002-03-30 17:05:03 +00:00
|
|
|
{
|
2002-11-02 13:54:34 +00:00
|
|
|
GstClockID id;
|
|
|
|
|
|
|
|
id = gst_clock_new_single_shot_id (clock, time);
|
|
|
|
|
|
|
|
return gst_clock_id_wait (id, jitter);
|
2002-03-30 17:05:03 +00:00
|
|
|
}
|
|
|
|
|
2001-12-24 15:14:03 +00:00
|
|
|
static GstSchedulerState
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_basic_scheduler_iterate (GstScheduler * sched)
|
|
|
|
{
|
|
|
|
GstBin *bin = GST_BIN (sched->parent);
|
|
|
|
GList *chains;
|
|
|
|
GstSchedulerChain *chain;
|
|
|
|
GstElement *entry;
|
|
|
|
GList *elements;
|
2001-12-22 21:18:17 +00:00
|
|
|
gint scheduled = 0;
|
|
|
|
GstBasicScheduler *bsched = GST_BASIC_SCHEDULER (sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
GST_DEBUG_ENTER ("(\"%s\")", GST_ELEMENT_NAME (bin));
|
|
|
|
|
2002-01-28 00:40:11 +00:00
|
|
|
/* clear the changes flag */
|
|
|
|
GST_FLAG_UNSET(bsched, GST_BASIC_SCHEDULER_CHANGE);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* step through all the chains */
|
2001-12-22 21:18:17 +00:00
|
|
|
chains = bsched->chains;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-20 02:41:34 +00:00
|
|
|
if (chains == NULL)
|
2001-12-24 15:14:03 +00:00
|
|
|
return GST_SCHEDULER_STATE_STOPPED;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
while (chains) {
|
|
|
|
chain = (GstSchedulerChain *) (chains->data);
|
|
|
|
chains = g_list_next (chains);
|
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* all we really have to do is switch to the first child */
|
|
|
|
/* FIXME this should be lots more intelligent about where to start */
|
2002-06-16 21:20:07 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "starting iteration via cothreads using %s scheduler",
|
|
|
|
_SCHEDULER_NAME);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
if (chain->elements) {
|
2001-12-17 18:51:40 +00:00
|
|
|
entry = NULL; /*MattH ADDED?*/
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "there are %d elements in this chain", chain->num_elements);
|
2001-12-04 22:12:50 +00:00
|
|
|
elements = chain->elements;
|
|
|
|
while (elements) {
|
2001-12-22 21:18:17 +00:00
|
|
|
entry = GST_ELEMENT_CAST (elements->data);
|
2001-12-04 22:12:50 +00:00
|
|
|
elements = g_list_next (elements);
|
|
|
|
if (GST_FLAG_IS_SET (entry, GST_ELEMENT_DECOUPLED)) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "entry \"%s\" is DECOUPLED, skipping",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_ELEMENT_NAME (entry));
|
|
|
|
entry = NULL;
|
|
|
|
}
|
2001-12-22 21:18:17 +00:00
|
|
|
else if (GST_FLAG_IS_SET (entry, GST_ELEMENT_INFINITE_LOOP)) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_SCHEDULING, "entry \"%s\" is not valid, skipping",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_ELEMENT_NAME (entry));
|
|
|
|
entry = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (entry) {
|
2001-12-24 15:14:03 +00:00
|
|
|
GstSchedulerState state;
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_FLAG_SET (entry, GST_ELEMENT_COTHREAD_STOPPING);
|
2001-12-24 15:14:03 +00:00
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "set COTHREAD_STOPPING flag on \"%s\"(@%p)",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_ELEMENT_NAME (entry), entry);
|
2001-12-22 21:18:17 +00:00
|
|
|
if (GST_ELEMENT_THREADSTATE (entry)) {
|
2002-05-26 03:23:25 +00:00
|
|
|
|
2002-06-02 16:20:09 +00:00
|
|
|
do_switch_from_main (entry);
|
2002-05-29 15:09:36 +00:00
|
|
|
|
2002-05-09 15:15:49 +00:00
|
|
|
state = GST_SCHEDULER_STATE (sched);
|
2002-01-28 00:40:11 +00:00
|
|
|
/* if something changed, return - go on else */
|
2002-05-09 15:15:49 +00:00
|
|
|
if (GST_FLAG_IS_SET(bsched, GST_BASIC_SCHEDULER_CHANGE) &&
|
|
|
|
state != GST_SCHEDULER_STATE_ERROR)
|
2002-01-28 00:40:11 +00:00
|
|
|
return GST_SCHEDULER_STATE_RUNNING;
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "cothread switch not possible, element has no threadstate");
|
2001-12-24 15:14:03 +00:00
|
|
|
return GST_SCHEDULER_STATE_ERROR;
|
2001-12-22 21:18:17 +00:00
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-17 18:51:40 +00:00
|
|
|
/* following is a check to see if the chain was interrupted due to a
|
|
|
|
* top-half state_change(). (i.e., if there's a pending state.)
|
|
|
|
*
|
|
|
|
* if it was, return to gstthread.c::gst_thread_main_loop() to
|
|
|
|
* execute the state change.
|
|
|
|
*/
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "cothread switch ended or interrupted");
|
2001-12-24 15:14:03 +00:00
|
|
|
|
|
|
|
if (state != GST_SCHEDULER_STATE_RUNNING) {
|
|
|
|
GST_INFO (GST_CAT_DATAFLOW, "scheduler is not running, in state %d", state);
|
|
|
|
return state;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
2001-12-24 15:14:03 +00:00
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
scheduled++;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-12-24 15:14:03 +00:00
|
|
|
GST_INFO (GST_CAT_DATAFLOW, "no entry in this chain, trying the next one");
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-12-24 15:14:03 +00:00
|
|
|
GST_INFO (GST_CAT_DATAFLOW, "no enabled elements in this chain, trying the next one");
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_DATAFLOW, "leaving (%s)", GST_ELEMENT_NAME (bin));
|
2001-12-24 15:14:03 +00:00
|
|
|
if (scheduled == 0) {
|
|
|
|
GST_INFO (GST_CAT_DATAFLOW, "nothing was scheduled, return STOPPED");
|
|
|
|
return GST_SCHEDULER_STATE_STOPPED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GST_INFO (GST_CAT_DATAFLOW, "scheduler still running, return RUNNING");
|
|
|
|
return GST_SCHEDULER_STATE_RUNNING;
|
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_basic_scheduler_show (GstScheduler * sched)
|
|
|
|
{
|
|
|
|
GList *chains, *elements;
|
|
|
|
GstElement *element;
|
|
|
|
GstSchedulerChain *chain;
|
2001-12-22 21:18:17 +00:00
|
|
|
GstBasicScheduler *bsched = GST_BASIC_SCHEDULER (sched);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
if (sched == NULL) {
|
|
|
|
g_print ("scheduler doesn't exist for this element\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_SCHEDULER (sched));
|
|
|
|
|
|
|
|
g_print ("SCHEDULER DUMP FOR MANAGING BIN \"%s\"\n", GST_ELEMENT_NAME (sched->parent));
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
g_print ("scheduler has %d elements in it: ", bsched->num_elements);
|
|
|
|
elements = bsched->elements;
|
2001-12-04 22:12:50 +00:00
|
|
|
while (elements) {
|
|
|
|
element = GST_ELEMENT (elements->data);
|
|
|
|
elements = g_list_next (elements);
|
|
|
|
|
|
|
|
g_print ("%s, ", GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
g_print ("\n");
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
g_print ("scheduler has %d chains in it\n", bsched->num_chains);
|
|
|
|
chains = bsched->chains;
|
2001-12-04 22:12:50 +00:00
|
|
|
while (chains) {
|
|
|
|
chain = (GstSchedulerChain *) (chains->data);
|
|
|
|
chains = g_list_next (chains);
|
|
|
|
|
|
|
|
g_print ("%p: ", chain);
|
|
|
|
|
|
|
|
elements = chain->disabled;
|
|
|
|
while (elements) {
|
|
|
|
element = GST_ELEMENT (elements->data);
|
|
|
|
elements = g_list_next (elements);
|
|
|
|
|
|
|
|
g_print ("!%s, ", GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
|
|
|
|
elements = chain->elements;
|
|
|
|
while (elements) {
|
|
|
|
element = GST_ELEMENT (elements->data);
|
|
|
|
elements = g_list_next (elements);
|
|
|
|
|
|
|
|
g_print ("%s, ", GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
}
|