2000-12-28 22:12:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
2003-04-18 23:35:34 +00:00
|
|
|
* 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
2000-12-28 22:12:02 +00:00
|
|
|
*
|
|
|
|
* gstthread.c: Threaded container object
|
2000-01-30 09:03:00 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gstthread.h"
|
2001-05-25 21:00:07 +00:00
|
|
|
#include "gstscheduler.h"
|
2003-04-18 23:35:34 +00:00
|
|
|
#include "gstinfo.h"
|
|
|
|
#include "gstlog.h"
|
2000-08-18 20:35:48 +00:00
|
|
|
|
2003-07-27 13:26:38 +00:00
|
|
|
#define GST_CAT_DEFAULT GST_CAT_THREAD
|
2002-11-01 21:38:39 +00:00
|
|
|
#define STACK_SIZE 0x200000
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
GstElementDetails gst_thread_details = {
|
|
|
|
"Threaded container",
|
2002-04-20 21:42:53 +00:00
|
|
|
"Generic/Bin",
|
2002-09-29 18:12:52 +00:00
|
|
|
"LGPL",
|
2000-01-30 09:03:00 +00:00
|
|
|
"Container that creates/manages a thread",
|
|
|
|
VERSION,
|
2003-07-08 17:10:49 +00:00
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>, "
|
2003-04-18 23:35:34 +00:00
|
|
|
"Benjamin Otte <in7y118@informatik.uni-hamburg.de",
|
|
|
|
"(C) 1999-2003",
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Thread signals and args */
|
|
|
|
enum {
|
2002-07-08 19:07:30 +00:00
|
|
|
SHUTDOWN,
|
2000-01-30 09:03:00 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
enum {
|
|
|
|
SPINUP=0,
|
|
|
|
STATECHANGE,
|
|
|
|
STARTUP
|
|
|
|
};
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
enum {
|
|
|
|
ARG_0,
|
2002-07-08 19:07:30 +00:00
|
|
|
ARG_PRIORITY,
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-11-28 21:24:01 +00:00
|
|
|
static void gst_thread_class_init (GstThreadClass *klass);
|
|
|
|
static void gst_thread_init (GstThread *thread);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-11-28 21:24:01 +00:00
|
|
|
static void gst_thread_dispose (GObject *object);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
static void gst_thread_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_thread_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
2003-04-18 23:35:34 +00:00
|
|
|
static GstElementStateReturn gst_thread_change_state (GstElement *element);
|
|
|
|
static void gst_thread_child_state_change (GstBin *bin, GstElementState oldstate,
|
|
|
|
GstElementState newstate, GstElement *element);
|
|
|
|
|
|
|
|
static void gst_thread_catch (GstThread *thread);
|
|
|
|
static void gst_thread_release (GstThread *thread);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 06:45:56 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2002-11-28 21:24:01 +00:00
|
|
|
static xmlNodePtr gst_thread_save_thyself (GstObject *object,
|
|
|
|
xmlNodePtr parent);
|
|
|
|
static void gst_thread_restore_thyself (GstObject *object,
|
|
|
|
xmlNodePtr self);
|
2001-06-24 21:18:28 +00:00
|
|
|
#endif
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
static void * gst_thread_main_loop (void *arg);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
#define GST_TYPE_THREAD_PRIORITY (gst_thread_priority_get_type())
|
2002-07-08 19:07:30 +00:00
|
|
|
static GType
|
2002-12-14 13:02:16 +00:00
|
|
|
gst_thread_priority_get_type(void)
|
|
|
|
{
|
|
|
|
static GType thread_priority_type = 0;
|
|
|
|
static GEnumValue thread_priority[] =
|
|
|
|
{
|
|
|
|
{ G_THREAD_PRIORITY_LOW, "LOW", "Low Priority Scheduling" },
|
|
|
|
{ G_THREAD_PRIORITY_NORMAL, "NORMAL", "Normal Scheduling" },
|
|
|
|
{ G_THREAD_PRIORITY_HIGH, "HIGH", "High Priority Scheduling" },
|
|
|
|
{ G_THREAD_PRIORITY_URGENT, "URGENT", "Urgent Scheduling" },
|
|
|
|
{ 0, NULL, NULL },
|
2002-07-08 19:07:30 +00:00
|
|
|
};
|
2002-12-14 13:02:16 +00:00
|
|
|
if (!thread_priority_type) {
|
|
|
|
thread_priority_type = g_enum_register_static("GstThreadPriority", thread_priority);
|
2002-07-08 19:07:30 +00:00
|
|
|
}
|
2002-12-14 13:02:16 +00:00
|
|
|
return thread_priority_type;
|
2002-07-08 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
WARNING: Don't grab this updated unless you're really, REALLY sure.
Original commit message from CVS:
WARNING: Don't grab this updated unless you're really, REALLY sure.
WARNING: Wait for the next one.
Whole lotta changes here, including a few random bits:
examples/*/Makefile: updated to use `libtool gcc`, not just `gcc`
gst/
gstbuffer.h: updated to new flag style
gst.c, gstdebug.h: added new debugging for function ptrs
gstpipeline.c: set type of parent_class to the class, not the object
gstthread.c: ditto
plugins/
cdparanoia/cdparanoia.c: added an argument type, updated some defaults
cobin/spindentity.c: updated to new do/while loopfunction style
mp3encode/lame/gstlame.c: argument types, whole lotta lame options
tests/: various changes
Now, for the big changes: Once again, the scheduling system has changed.
And once again, it broke a whole bunch of things. The gist of the change
is that there is now a function pointer for gst_pad_push and gst_pad_pull,
instead of a hard-wired function. Well, currently they are functions, but
that's for debugging purposes only, they just call the function pointer
after spewing lots of DEBUG().
This changed the GstPad structure a bit, and the GstPad API as well.
Where elements used to provide chain() and pull() functions, they provide
chain() and get() functions. gst_pad_set_pull[region]_function has been
changed to get_pad_set_get[region]_function. This means all the elements
out there that used to have pull functions need to be updated. The calls
to that function have been changed in the normal elements, but the names
of the functions passed is still _pull[region](), which is an aesthetic
issue more than anything.
As for what doesn't work yet, just about anything dealing with Connections
is hosed, meaning threaded stuff won't work. This will be fixed about 12
hours from now, after I've slept, etc. The simplefake.c test works in
both cothreaded and chained cases, but not much else will work due to the
Connection problem. Needless to say, don't grab this unless you *need*
these features *now*, else wait to update this stuff until tomorrow.
I'm going to sleep now.
2000-12-16 10:18:09 +00:00
|
|
|
static GstBinClass *parent_class = NULL;
|
2002-11-28 21:24:01 +00:00
|
|
|
static guint gst_thread_signals[LAST_SIGNAL] = { 0 };
|
2003-04-18 23:35:34 +00:00
|
|
|
GPrivate *gst_thread_current;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
GType
|
2000-01-30 09:03:00 +00:00
|
|
|
gst_thread_get_type(void) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType thread_type = 0;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
if (!thread_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static const GTypeInfo thread_info = {
|
2002-11-28 21:24:01 +00:00
|
|
|
sizeof (GstThreadClass), NULL, NULL,
|
|
|
|
(GClassInitFunc) gst_thread_class_init, NULL, NULL,
|
|
|
|
sizeof (GstThread),
|
2001-06-25 01:20:11 +00:00
|
|
|
4,
|
2002-11-28 21:24:01 +00:00
|
|
|
(GInstanceInitFunc) gst_thread_init,
|
2001-09-14 22:16:47 +00:00
|
|
|
NULL
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
2002-11-28 21:24:01 +00:00
|
|
|
thread_type = g_type_register_static (GST_TYPE_BIN, "GstThread",
|
|
|
|
&thread_info, 0);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
return thread_type;
|
|
|
|
}
|
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
static void do_nothing (gpointer hi) {}
|
2000-01-30 09:03:00 +00:00
|
|
|
static void
|
2001-01-21 16:06:42 +00:00
|
|
|
gst_thread_class_init (GstThreadClass *klass)
|
2000-11-04 18:54:07 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
GObjectClass *gobject_class;
|
2000-01-30 09:03:00 +00:00
|
|
|
GstObjectClass *gstobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2000-09-24 14:29:49 +00:00
|
|
|
GstBinClass *gstbin_class;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
/* setup gst_thread_current */
|
|
|
|
gst_thread_current = g_private_new (do_nothing);
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class = (GObjectClass*)klass;
|
2001-01-21 16:06:42 +00:00
|
|
|
gstobject_class = (GstObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
gstbin_class = (GstBinClass*)klass;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_BIN);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PRIORITY,
|
|
|
|
g_param_spec_enum ("priority", "Scheduling Policy", "The scheduling priority of the thread",
|
|
|
|
GST_TYPE_THREAD_PRIORITY, G_THREAD_PRIORITY_NORMAL, G_PARAM_READWRITE));
|
2002-07-08 19:07:30 +00:00
|
|
|
|
|
|
|
gst_thread_signals[SHUTDOWN] =
|
|
|
|
g_signal_new ("shutdown", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstThreadClass, shutdown), NULL, NULL,
|
|
|
|
gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
|
|
|
2001-09-28 19:16:02 +00:00
|
|
|
gobject_class->dispose = gst_thread_dispose;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-06-25 06:45:56 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2001-10-17 10:21:27 +00:00
|
|
|
gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_thread_save_thyself);
|
2002-05-04 18:59:24 +00:00
|
|
|
gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR (gst_thread_restore_thyself);
|
2001-06-24 21:18:28 +00:00
|
|
|
#endif
|
2001-01-29 00:06:02 +00:00
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_thread_change_state);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_thread_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_thread_get_property);
|
2000-09-24 22:45:48 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
gstbin_class->child_state_change = GST_DEBUG_FUNCPTR (gst_thread_child_state_change);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2001-01-21 16:06:42 +00:00
|
|
|
static void
|
|
|
|
gst_thread_init (GstThread *thread)
|
2000-11-04 18:54:07 +00:00
|
|
|
{
|
2001-12-27 00:47:41 +00:00
|
|
|
GstScheduler *scheduler;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_DEBUG ("initializing thread");
|
2000-12-26 23:51:04 +00:00
|
|
|
|
2002-05-04 18:59:24 +00:00
|
|
|
/* threads are managing bins and iterate themselves */
|
2002-04-12 09:38:47 +00:00
|
|
|
/* CR1: the GstBin code checks these flags */
|
2000-12-20 09:39:43 +00:00
|
|
|
GST_FLAG_SET (thread, GST_BIN_FLAG_MANAGER);
|
2002-03-30 17:05:03 +00:00
|
|
|
GST_FLAG_SET (thread, GST_BIN_SELF_SCHEDULABLE);
|
2000-12-20 09:39:43 +00:00
|
|
|
|
2002-05-04 18:59:24 +00:00
|
|
|
scheduler = gst_scheduler_factory_make (NULL, GST_ELEMENT (thread));
|
2002-12-07 14:15:52 +00:00
|
|
|
g_assert (scheduler);
|
2001-12-27 00:47:41 +00:00
|
|
|
|
|
|
|
thread->lock = g_mutex_new ();
|
2003-04-18 23:35:34 +00:00
|
|
|
thread->cond = g_cond_new ();
|
2001-12-27 00:47:41 +00:00
|
|
|
|
2002-12-07 14:15:52 +00:00
|
|
|
thread->thread_id = (GThread *) NULL; /* set in NULL -> READY */
|
2002-12-14 13:02:16 +00:00
|
|
|
thread->priority = G_THREAD_PRIORITY_NORMAL;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2001-01-21 16:06:42 +00:00
|
|
|
static void
|
2001-09-28 19:16:02 +00:00
|
|
|
gst_thread_dispose (GObject *object)
|
2001-01-21 16:06:42 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
GstThread *thread = GST_THREAD (object);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "GstThread: dispose");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2002-11-19 23:15:23 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
g_assert (GST_STATE (thread) == GST_STATE_NULL);
|
2002-11-19 23:15:23 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
g_mutex_free (thread->lock);
|
2003-04-18 23:35:34 +00:00
|
|
|
g_cond_free (thread->cond);
|
2001-01-21 16:06:42 +00:00
|
|
|
|
2003-02-02 19:49:29 +00:00
|
|
|
gst_object_replace ((GstObject **)&GST_ELEMENT_SCHED (thread), NULL);
|
2001-01-21 16:06:42 +00:00
|
|
|
}
|
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
/**
|
|
|
|
* gst_thread_set_priority:
|
|
|
|
* @thread: the thread to change
|
|
|
|
* @priority: the new priority for the thread
|
|
|
|
*
|
|
|
|
* change the thread's priority
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_thread_set_priority (GstThread *thread, GThreadPriority priority)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_THREAD (thread));
|
|
|
|
|
|
|
|
thread->priority = priority;
|
|
|
|
}
|
|
|
|
|
2001-01-21 16:06:42 +00:00
|
|
|
static void
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_thread_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
2000-11-04 18:54:07 +00:00
|
|
|
{
|
2002-07-08 19:07:30 +00:00
|
|
|
GstThread *thread;
|
|
|
|
|
|
|
|
thread = GST_THREAD (object);
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2002-07-08 19:07:30 +00:00
|
|
|
case ARG_PRIORITY:
|
2002-12-14 13:02:16 +00:00
|
|
|
thread->priority = g_value_get_enum (value);
|
2002-07-08 19:07:30 +00:00
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
default:
|
2001-06-25 01:20:11 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-21 16:06:42 +00:00
|
|
|
static void
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_thread_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
2000-11-04 18:54:07 +00:00
|
|
|
{
|
2002-07-08 19:07:30 +00:00
|
|
|
GstThread *thread;
|
|
|
|
|
|
|
|
thread = GST_THREAD (object);
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2002-07-08 19:07:30 +00:00
|
|
|
case ARG_PRIORITY:
|
2002-12-14 13:02:16 +00:00
|
|
|
g_value_set_enum (value, thread->priority);
|
2002-07-08 19:07:30 +00:00
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
default:
|
2001-06-25 01:20:11 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
|
2000-03-27 19:53:43 +00:00
|
|
|
/**
|
|
|
|
* gst_thread_new:
|
|
|
|
* @name: the name of the thread
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Create a new thread with the given name.
|
2000-03-27 19:53:43 +00:00
|
|
|
*
|
2000-12-28 21:42:23 +00:00
|
|
|
* Returns: The new thread
|
2000-03-27 19:53:43 +00:00
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
GstElement*
|
2001-10-20 23:15:29 +00:00
|
|
|
gst_thread_new (const gchar *name)
|
2000-11-04 18:54:07 +00:00
|
|
|
{
|
2002-04-11 20:35:18 +00:00
|
|
|
return gst_element_factory_make ("thread", name);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
/**
|
|
|
|
* gst_thread_get_current:
|
|
|
|
*
|
|
|
|
* Create a new thread with the given name.
|
|
|
|
*
|
|
|
|
* Returns: The current GstThread or NULL if you are not running inside a
|
|
|
|
* #GstThread.
|
2002-09-12 18:56:31 +00:00
|
|
|
*/
|
2003-04-18 23:35:34 +00:00
|
|
|
GstThread *
|
|
|
|
gst_thread_get_current (void)
|
|
|
|
{
|
|
|
|
return (GstThread *) g_private_get (gst_thread_current);
|
|
|
|
}
|
2002-09-12 18:56:31 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
static inline void
|
|
|
|
gst_thread_release_children_locks (GstThread *thread)
|
|
|
|
{
|
|
|
|
GstRealPad *peer = NULL;
|
|
|
|
GstElement *peerelement;
|
|
|
|
GList *elements = (GList *) gst_bin_get_list (GST_BIN (thread));
|
|
|
|
|
|
|
|
while (elements) {
|
|
|
|
GstElement *element = GST_ELEMENT (elements->data);
|
|
|
|
GList *pads;
|
|
|
|
|
|
|
|
g_assert (element);
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_DEBUG_OBJECT (thread, "waking element \"%s\"", GST_ELEMENT_NAME (element));
|
2003-04-18 23:35:34 +00:00
|
|
|
elements = g_list_next (elements);
|
|
|
|
|
|
|
|
if (!gst_element_release_locks (element))
|
|
|
|
g_warning ("element %s could not release locks", GST_ELEMENT_NAME (element));
|
|
|
|
|
|
|
|
pads = GST_ELEMENT_PADS (element);
|
|
|
|
|
|
|
|
while (pads) {
|
|
|
|
if (GST_PAD_PEER (pads->data)) {
|
|
|
|
peer = GST_REAL_PAD (GST_PAD_PEER (pads->data));
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
} else {
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
continue;
|
|
|
|
}
|
2002-09-12 18:56:31 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
if (!peer)
|
|
|
|
continue;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
peerelement = GST_PAD_PARENT (peer);
|
|
|
|
if (!peerelement)
|
|
|
|
continue; /* FIXME: deal with case where there's no peer */
|
2002-12-18 21:44:57 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
if (GST_ELEMENT_SCHED (peerelement) != GST_ELEMENT_SCHED (thread)) {
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (thread, "element \"%s\" has pad cross sched boundary", GST_ELEMENT_NAME (element));
|
|
|
|
GST_LOG_OBJECT (thread, "waking element \"%s\"", GST_ELEMENT_NAME (peerelement));
|
2003-04-18 23:35:34 +00:00
|
|
|
if (!gst_element_release_locks (peerelement))
|
|
|
|
g_warning ("element %s could not release locks", GST_ELEMENT_NAME (peerelement));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* stops the main thread, if there is one and grabs the thread's mutex */
|
|
|
|
static void
|
|
|
|
gst_thread_catch (GstThread *thread)
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
2003-04-18 23:35:34 +00:00
|
|
|
gboolean wait;
|
2003-04-21 18:09:29 +00:00
|
|
|
if (thread == gst_thread_get_current()) {
|
|
|
|
/* we're trying to catch ourself */
|
|
|
|
if (!GST_FLAG_IS_SET (thread, GST_THREAD_MUTEX_LOCKED)) {
|
|
|
|
g_mutex_lock (thread->lock);
|
|
|
|
GST_FLAG_SET (thread, GST_THREAD_MUTEX_LOCKED);
|
|
|
|
}
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_DEBUG_OBJECT (thread, "catching itself");
|
2003-04-21 18:09:29 +00:00
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
|
|
|
|
} else {
|
2003-04-18 23:35:34 +00:00
|
|
|
/* another thread is trying to catch us */
|
2003-04-21 18:09:29 +00:00
|
|
|
g_mutex_lock (thread->lock);
|
2003-04-18 23:35:34 +00:00
|
|
|
wait = !GST_FLAG_IS_SET (thread, GST_THREAD_STATE_SPINNING);
|
|
|
|
while (!wait) {
|
|
|
|
GTimeVal tv;
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (thread, "catching thread...");
|
2003-04-18 23:35:34 +00:00
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
|
|
|
|
g_cond_signal (thread->cond);
|
|
|
|
gst_thread_release_children_locks (thread);
|
|
|
|
g_get_current_time (&tv);
|
|
|
|
g_time_val_add (&tv, 1000); /* wait a millisecond to catch the thread */
|
|
|
|
wait = g_cond_timed_wait (thread->cond, thread->lock, &tv);
|
|
|
|
}
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (thread, "caught thread");
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
2003-04-18 23:35:34 +00:00
|
|
|
g_assert (!GST_FLAG_IS_SET (thread, GST_THREAD_STATE_SPINNING));
|
|
|
|
}
|
2003-04-26 14:38:18 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
static void
|
|
|
|
gst_thread_release (GstThread *thread)
|
|
|
|
{
|
2003-04-21 18:09:29 +00:00
|
|
|
if (thread != gst_thread_get_current()) {
|
|
|
|
g_cond_signal (thread->cond);
|
|
|
|
g_mutex_unlock (thread->lock);
|
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
2003-04-26 14:38:18 +00:00
|
|
|
|
2001-01-21 16:06:42 +00:00
|
|
|
static GstElementStateReturn
|
2002-11-28 21:24:01 +00:00
|
|
|
gst_thread_change_state (GstElement *element)
|
2000-11-04 18:54:07 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstThread *thread;
|
2003-04-18 23:35:34 +00:00
|
|
|
GstElementStateReturn ret;
|
2003-04-21 18:09:29 +00:00
|
|
|
gint transition;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-06-21 14:50:00 +00:00
|
|
|
g_return_val_if_fail (GST_IS_THREAD (element), GST_STATE_FAILURE);
|
2003-04-21 18:09:29 +00:00
|
|
|
transition = GST_STATE_TRANSITION (element);
|
2000-12-08 23:38:12 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
thread = GST_THREAD (element);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_STATES, "%s is changing state from %s to %s",
|
2003-04-18 23:35:34 +00:00
|
|
|
GST_ELEMENT_NAME (element), gst_element_state_get_name (GST_STATE (element)),
|
|
|
|
gst_element_state_get_name (GST_STATE_PENDING (element)));
|
2000-08-14 10:55:35 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
gst_thread_catch (thread);
|
2000-09-22 23:35:14 +00:00
|
|
|
|
2003-04-21 18:09:29 +00:00
|
|
|
/* FIXME: (or GStreamers ideas about "threading"): the element variables are
|
|
|
|
commonly accessed by multiple threads at the same time (see bug #111146
|
|
|
|
for an example) */
|
|
|
|
if (transition != GST_STATE_TRANSITION (element)) {
|
|
|
|
g_warning ("inconsistent state information, fix threading please");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (transition) {
|
2000-12-23 03:17:52 +00:00
|
|
|
case GST_STATE_NULL_TO_READY:
|
2003-04-18 23:35:34 +00:00
|
|
|
/* create the thread */
|
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
|
2002-11-01 21:38:39 +00:00
|
|
|
thread->thread_id = g_thread_create_full(gst_thread_main_loop,
|
2003-04-18 23:35:34 +00:00
|
|
|
thread, STACK_SIZE, FALSE, TRUE, thread->priority,
|
|
|
|
NULL);
|
2002-11-01 21:38:39 +00:00
|
|
|
if (!thread->thread_id){
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_ERROR_OBJECT (element, "g_thread_create_full failed");
|
2003-04-18 23:35:34 +00:00
|
|
|
goto error_out;
|
2002-05-29 15:01:50 +00:00
|
|
|
}
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (element, "GThread created");
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* wait for it to 'spin up' */
|
2003-04-18 23:35:34 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2001-05-25 21:00:07 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
2000-12-23 03:17:52 +00:00
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
2002-05-26 03:23:25 +00:00
|
|
|
{
|
2003-04-18 23:35:34 +00:00
|
|
|
/* FIXME: recurse into sub-bins */
|
|
|
|
GList *elements = (GList *) gst_bin_get_list (GST_BIN (thread));
|
2002-05-26 03:23:25 +00:00
|
|
|
while (elements) {
|
|
|
|
gst_element_enable_threadsafe_properties ((GstElement*)elements->data);
|
|
|
|
elements = g_list_next (elements);
|
|
|
|
}
|
2003-04-28 00:01:31 +00:00
|
|
|
/* reset self to spinning */
|
|
|
|
if (thread == gst_thread_get_current())
|
|
|
|
GST_FLAG_SET (thread, GST_THREAD_STATE_SPINNING);
|
2001-01-21 16:06:42 +00:00
|
|
|
break;
|
2002-05-26 03:23:25 +00:00
|
|
|
}
|
2000-12-23 03:17:52 +00:00
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
2001-12-04 22:12:50 +00:00
|
|
|
{
|
2003-04-18 23:35:34 +00:00
|
|
|
GList *elements = (GList *) gst_bin_get_list (GST_BIN (thread));
|
2002-05-26 21:54:27 +00:00
|
|
|
while (elements) {
|
|
|
|
gst_element_disable_threadsafe_properties ((GstElement*)elements->data);
|
|
|
|
elements = g_list_next (elements);
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
2003-04-18 23:35:34 +00:00
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
break;
|
2000-12-23 03:17:52 +00:00
|
|
|
case GST_STATE_READY_TO_NULL:
|
2003-04-18 23:35:34 +00:00
|
|
|
/* we can't join the threads here, because this could have been triggered
|
|
|
|
by ourself (ouch) */
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (thread, "destroying GThread %p", thread->thread_id);
|
2003-04-18 23:35:34 +00:00
|
|
|
GST_FLAG_SET (thread, GST_THREAD_STATE_REAPING);
|
2002-11-01 21:38:39 +00:00
|
|
|
thread->thread_id = NULL;
|
2003-04-18 23:35:34 +00:00
|
|
|
if (thread == gst_thread_get_current()) {
|
|
|
|
/* or should we continue? */
|
|
|
|
g_warning ("Thread %s is destroying itself. Function call will not return!", GST_ELEMENT_NAME (thread));
|
|
|
|
gst_scheduler_reset (GST_ELEMENT_SCHED (thread));
|
|
|
|
|
|
|
|
/* unlock and signal - we are out */
|
|
|
|
gst_thread_release (thread);
|
2002-09-12 18:56:31 +00:00
|
|
|
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_INFO_OBJECT (thread, "GThread %p is exiting", g_thread_self());
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
g_signal_emit (G_OBJECT (thread), gst_thread_signals[SHUTDOWN], 0);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
g_thread_exit (NULL);
|
|
|
|
}
|
|
|
|
/* now wait for the thread to destroy itself */
|
|
|
|
g_cond_signal (thread->cond);
|
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
|
|
|
/* it should be dead now */
|
2000-09-09 16:36:10 +00:00
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
default:
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_ERROR_OBJECT (element, "UNHANDLED STATE CHANGE! %x",
|
|
|
|
GST_STATE_TRANSITION (element));
|
2003-04-18 23:35:34 +00:00
|
|
|
g_assert_not_reached ();
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state) {
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT (thread));
|
|
|
|
} else {
|
|
|
|
ret = GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_thread_release (thread);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
error_out:
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_STATES, "changing state from %s to %s failed for %s",
|
2003-04-18 23:35:34 +00:00
|
|
|
gst_element_state_get_name (GST_STATE (element)),
|
|
|
|
gst_element_state_get_name (GST_STATE_PENDING (element)),
|
|
|
|
GST_ELEMENT_NAME (element));
|
|
|
|
gst_thread_release (thread);
|
|
|
|
return GST_STATE_FAILURE;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
/* state changes work this way: We grab the lock and stop the thread from
|
|
|
|
spinning (via gst_thread_catch) - then we change the state. After that the
|
|
|
|
thread may spin on. */
|
|
|
|
static void
|
|
|
|
gst_thread_child_state_change (GstBin *bin, GstElementState oldstate,
|
|
|
|
GstElementState newstate, GstElement *element)
|
|
|
|
{
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (bin, "(from thread %s) child %s changed state from %s to %s",
|
2003-04-26 13:55:13 +00:00
|
|
|
gst_thread_get_current() ? GST_ELEMENT_NAME (gst_thread_get_current()) : "(none)",
|
|
|
|
GST_ELEMENT_NAME (element), gst_element_state_get_name (oldstate),
|
|
|
|
gst_element_state_get_name (newstate));
|
2003-04-21 18:09:29 +00:00
|
|
|
if (parent_class->child_state_change)
|
|
|
|
parent_class->child_state_change (bin, oldstate, newstate, element);
|
2003-04-18 23:35:34 +00:00
|
|
|
/* We'll wake up the main thread now. Note that we can't lock the thread here,
|
|
|
|
because we might be called from inside gst_thread_change_state when holding
|
|
|
|
the lock. But this doesn't cause any problems. */
|
|
|
|
if (newstate == GST_STATE_PLAYING)
|
|
|
|
g_cond_signal (GST_THREAD (bin)->cond);
|
|
|
|
}
|
2000-03-27 19:53:43 +00:00
|
|
|
/**
|
|
|
|
* gst_thread_main_loop:
|
|
|
|
* @arg: the thread to start
|
|
|
|
*
|
|
|
|
* The main loop of the thread. The thread will iterate
|
2002-04-12 09:38:47 +00:00
|
|
|
* while the state is GST_THREAD_STATE_SPINNING.
|
2000-03-27 19:53:43 +00:00
|
|
|
*/
|
2000-11-01 22:11:48 +00:00
|
|
|
static void *
|
2001-01-21 16:06:42 +00:00
|
|
|
gst_thread_main_loop (void *arg)
|
2000-11-01 22:11:48 +00:00
|
|
|
{
|
2002-06-27 22:17:17 +00:00
|
|
|
GstThread *thread = NULL;
|
2003-04-18 23:35:34 +00:00
|
|
|
gboolean status;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-06-27 22:17:17 +00:00
|
|
|
thread = GST_THREAD (arg);
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_lock (thread->lock);
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (thread, "Started main loop");
|
2003-04-18 23:35:34 +00:00
|
|
|
|
|
|
|
/* initialize gst_thread_current */
|
|
|
|
g_private_set (gst_thread_current, thread);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
/* set up the element's scheduler */
|
2001-12-19 19:22:53 +00:00
|
|
|
gst_scheduler_setup (GST_ELEMENT_SCHED (thread));
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
|
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
g_cond_signal (thread->cond);
|
|
|
|
while (!(GST_FLAG_IS_SET (thread, GST_THREAD_STATE_REAPING))) {
|
|
|
|
if (GST_STATE (thread) == GST_STATE_PLAYING) {
|
|
|
|
GST_FLAG_SET (thread, GST_THREAD_STATE_SPINNING);
|
|
|
|
status = TRUE;
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (thread, "starting to iterate");
|
2003-04-18 23:35:34 +00:00
|
|
|
while (status && GST_FLAG_IS_SET (thread, GST_THREAD_STATE_SPINNING)) {
|
|
|
|
g_mutex_unlock (thread->lock);
|
|
|
|
status = gst_bin_iterate (GST_BIN (thread));
|
2003-04-21 18:09:29 +00:00
|
|
|
if (GST_FLAG_IS_SET (thread, GST_THREAD_MUTEX_LOCKED)) {
|
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_MUTEX_LOCKED);
|
|
|
|
} else {
|
|
|
|
g_mutex_lock (thread->lock);
|
|
|
|
}
|
2003-04-18 23:35:34 +00:00
|
|
|
}
|
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2003-04-18 23:35:34 +00:00
|
|
|
if (GST_FLAG_IS_SET (thread, GST_THREAD_STATE_REAPING))
|
|
|
|
break;
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (thread, "we're caught");
|
2003-04-18 23:35:34 +00:00
|
|
|
g_cond_signal (thread->cond);
|
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
2002-09-12 18:56:31 +00:00
|
|
|
|
2002-04-12 09:38:47 +00:00
|
|
|
/* we need to destroy the scheduler here because it has mapped it's
|
2001-12-19 19:22:53 +00:00
|
|
|
* stack into the threads stack space */
|
|
|
|
gst_scheduler_reset (GST_ELEMENT_SCHED (thread));
|
|
|
|
|
2003-04-21 18:09:29 +00:00
|
|
|
/* must do that before releasing the lock - we might get disposed before being done */
|
|
|
|
g_signal_emit (G_OBJECT (thread), gst_thread_signals[SHUTDOWN], 0);
|
|
|
|
|
2003-04-18 23:35:34 +00:00
|
|
|
/* unlock and signal - we are out */
|
2003-07-27 13:26:38 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (thread, "Thread %p exits main loop", g_thread_self());
|
2003-04-18 23:35:34 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2001-05-25 21:00:07 +00:00
|
|
|
g_mutex_unlock (thread->lock);
|
2003-07-27 13:26:38 +00:00
|
|
|
/* don't assume the GstThread object exists anymore now */
|
2002-07-08 19:07:30 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-06-25 06:45:56 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2001-06-24 21:18:28 +00:00
|
|
|
static xmlNodePtr
|
|
|
|
gst_thread_save_thyself (GstObject *object,
|
|
|
|
xmlNodePtr self)
|
|
|
|
{
|
|
|
|
if (GST_OBJECT_CLASS (parent_class)->save_thyself)
|
|
|
|
GST_OBJECT_CLASS (parent_class)->save_thyself (object, self);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-01-20 17:59:25 +00:00
|
|
|
static void
|
2001-01-29 00:06:02 +00:00
|
|
|
gst_thread_restore_thyself (GstObject *object,
|
|
|
|
xmlNodePtr self)
|
2000-11-04 18:54:07 +00:00
|
|
|
{
|
2003-07-27 13:26:38 +00:00
|
|
|
GST_LOG_OBJECT (object, "restoring");
|
2000-09-27 19:33:10 +00:00
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
if (GST_OBJECT_CLASS (parent_class)->restore_thyself)
|
|
|
|
GST_OBJECT_CLASS (parent_class)->restore_thyself (object, self);
|
2000-09-27 19:33:10 +00:00
|
|
|
}
|
2001-12-14 22:59:21 +00:00
|
|
|
#endif /* GST_DISABLE_LOADSAVE */
|