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>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2000-12-15 01:57:34 +00:00
|
|
|
#include <unistd.h>
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* #define GST_DEBUG_ENABLED */
|
2000-12-28 22:12:02 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
|
2002-06-21 14:50:00 +00:00
|
|
|
#include "gst.h"
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gstthread.h"
|
2001-05-25 21:00:07 +00:00
|
|
|
#include "gstscheduler.h"
|
|
|
|
#include "gstqueue.h"
|
2000-08-18 20:35:48 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
GstElementDetails gst_thread_details = {
|
|
|
|
"Threaded container",
|
2002-04-20 21:42:53 +00:00
|
|
|
"Generic/Bin",
|
2000-01-30 09:03:00 +00:00
|
|
|
"Container that creates/manages a thread",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>",
|
2001-01-21 16:06:42 +00:00
|
|
|
"(C) 1999, 2000",
|
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_SCHEDPOLICY,
|
|
|
|
ARG_PRIORITY,
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-01-21 16:06:42 +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
|
|
|
|
2001-09-28 19:16:02 +00:00
|
|
|
static void gst_thread_dispose (GObject *object);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-06-25 01:20:11 +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);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-21 16:06:42 +00:00
|
|
|
static GstElementStateReturn gst_thread_change_state (GstElement *element);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 06:45:56 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2001-01-29 00:06:02 +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
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void* gst_thread_main_loop (void *arg);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-07-08 19:07:30 +00:00
|
|
|
#define GST_TYPE_THREAD_SCHEDPOLICY (gst_thread_schedpolicy_get_type())
|
|
|
|
static GType
|
|
|
|
gst_thread_schedpolicy_get_type(void) {
|
|
|
|
static GType thread_schedpolicy_type = 0;
|
|
|
|
static GEnumValue thread_schedpolicy[] = {
|
|
|
|
{SCHED_OTHER, "SCHED_OTHER", "Normal Scheduling"},
|
|
|
|
{SCHED_FIFO, "SCHED_FIFO", "FIFO Scheduling (requires root)"},
|
|
|
|
{SCHED_RR, "SCHED_RR", "Round-Robin Scheduling (requires root)"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
if (!thread_schedpolicy_type) {
|
|
|
|
thread_schedpolicy_type = g_enum_register_static("GstThreadSchedPolicy", thread_schedpolicy);
|
|
|
|
}
|
|
|
|
return thread_schedpolicy_type;
|
|
|
|
}
|
|
|
|
|
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-07-08 19:07:30 +00:00
|
|
|
static guint gst_thread_signals[LAST_SIGNAL] = { 0 };
|
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 = {
|
2000-01-30 09:03:00 +00:00
|
|
|
sizeof(GstThreadClass),
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_thread_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstThread),
|
|
|
|
4,
|
|
|
|
(GInstanceInitFunc)gst_thread_init,
|
2001-09-14 22:16:47 +00:00
|
|
|
NULL
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
2001-06-25 01:20:11 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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-07-08 19:07:30 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_SCHEDPOLICY,
|
|
|
|
g_param_spec_enum("schedpolicy", "Scheduling Policy", "The scheduling policy of the thread",
|
|
|
|
GST_TYPE_THREAD_SCHEDPOLICY, SCHED_OTHER, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_PRIORITY,
|
|
|
|
g_param_spec_int("priority", "Scheduling Priority", "The scheduling priority of the thread",
|
|
|
|
0, 99, 0, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_THREAD, "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));
|
2001-12-27 00:47:41 +00:00
|
|
|
|
|
|
|
thread->lock = g_mutex_new ();
|
|
|
|
thread->cond = g_cond_new ();
|
|
|
|
|
|
|
|
thread->ppid = getpid ();
|
2002-07-11 21:22:55 +00:00
|
|
|
thread->thread_id = (pthread_t) -1;
|
2002-07-08 19:07:30 +00:00
|
|
|
thread->sched_policy = SCHED_OTHER;
|
|
|
|
thread->priority = 0;
|
2002-09-12 18:56:31 +00:00
|
|
|
thread->stack = NULL;
|
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
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_REFCOUNTING, "dispose");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
g_mutex_free (thread->lock);
|
|
|
|
g_cond_free (thread->cond);
|
2001-01-21 16:06:42 +00:00
|
|
|
|
2001-09-28 19:16:02 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-27 00:47:41 +00:00
|
|
|
if (GST_ELEMENT_SCHED (thread)) {
|
|
|
|
gst_object_unref (GST_OBJECT (GST_ELEMENT_SCHED (thread)));
|
|
|
|
}
|
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;
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_if_fail (GST_IS_THREAD (object));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-07-08 19:07:30 +00:00
|
|
|
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_SCHEDPOLICY:
|
|
|
|
thread->sched_policy = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case ARG_PRIORITY:
|
|
|
|
thread->priority = g_value_get_int (value);
|
|
|
|
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;
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_if_fail (GST_IS_THREAD (object));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-07-08 19:07:30 +00:00
|
|
|
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_SCHEDPOLICY:
|
|
|
|
g_value_set_enum (value, thread->sched_policy);
|
|
|
|
break;
|
|
|
|
case ARG_PRIORITY:
|
|
|
|
g_value_set_int (value, thread->priority);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
/* these two macros are used for debug/info from the state_change function */
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
#define THR_INFO(format,args...) \
|
|
|
|
GST_INFO_ELEMENT(GST_CAT_THREAD, thread, "sync(" GST_DEBUG_THREAD_FORMAT "): " format , \
|
|
|
|
GST_DEBUG_THREAD_ARGS(thread->pid) , ## args )
|
2002-09-12 18:56:31 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
#define THR_DEBUG(format,args...) \
|
|
|
|
GST_DEBUG_ELEMENT(GST_CAT_THREAD, thread, "sync(" GST_DEBUG_THREAD_FORMAT "): " format , \
|
|
|
|
GST_DEBUG_THREAD_ARGS(thread->pid) , ## args )
|
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
/* these two macros are used for debug/info from the gst_thread_main_loop
|
|
|
|
* function
|
|
|
|
*/
|
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
#define THR_INFO_MAIN(format,args...) \
|
|
|
|
GST_INFO_ELEMENT(GST_CAT_THREAD, thread, "sync-main(" GST_DEBUG_THREAD_FORMAT "): " format , \
|
|
|
|
GST_DEBUG_THREAD_ARGS(thread->ppid) , ## args )
|
2002-09-12 18:56:31 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
#define THR_DEBUG_MAIN(format,args...) \
|
|
|
|
GST_DEBUG_ELEMENT(GST_CAT_THREAD, thread, "sync-main(" GST_DEBUG_THREAD_FORMAT "): " format , \
|
|
|
|
GST_DEBUG_THREAD_ARGS(thread->ppid) , ## args )
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_thread_update_state (GstThread *thread)
|
|
|
|
{
|
2002-09-12 18:56:31 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_THREAD, thread, "updating state of thread");
|
2001-12-14 22:59:21 +00:00
|
|
|
/* check for state change */
|
2002-09-12 18:56:31 +00:00
|
|
|
if (GST_STATE_PENDING (thread) != GST_STATE_VOID_PENDING) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* punt and change state on all the children */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
2002-09-12 18:56:31 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT (thread));
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
/* FIXME: in the case of no change_state function in the parent's class,
|
|
|
|
* shouldn't we actually change the thread's state ? */
|
|
|
|
g_warning ("thread's parent doesn't have change_state, returning success");
|
2001-12-04 22:12:50 +00:00
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-21 16:06:42 +00:00
|
|
|
static GstElementStateReturn
|
2001-12-04 22:12:50 +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;
|
2000-11-01 22:11:48 +00:00
|
|
|
gboolean stateset = GST_STATE_SUCCESS;
|
2001-05-25 21:00:07 +00:00
|
|
|
gint transition;
|
2001-12-04 22:12:50 +00:00
|
|
|
pthread_t self = pthread_self ();
|
2002-06-19 18:13:28 +00:00
|
|
|
glong stacksize;
|
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);
|
2002-06-23 12:43:45 +00:00
|
|
|
g_return_val_if_fail (gst_has_threads (), GST_STATE_FAILURE);
|
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
|
|
|
|
2000-12-23 03:17:52 +00:00
|
|
|
transition = GST_STATE_TRANSITION (element);
|
2000-08-14 10:55:35 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
THR_INFO ("changing state from %s to %s",
|
2002-04-23 11:15:18 +00:00
|
|
|
gst_element_state_get_name (GST_STATE (element)),
|
|
|
|
gst_element_state_get_name (GST_STATE_PENDING (element)));
|
2000-09-22 23:35:14 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
if (pthread_equal (self, thread->thread_id)) {
|
|
|
|
GST_DEBUG (GST_CAT_THREAD,
|
2002-04-03 18:26:03 +00:00
|
|
|
"no sync(" GST_DEBUG_THREAD_FORMAT "): setting own thread's state to spinning",
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_DEBUG_THREAD_ARGS (thread->pid));
|
|
|
|
return gst_thread_update_state (thread);
|
|
|
|
}
|
2000-09-22 23:35:14 +00:00
|
|
|
|
2000-12-23 03:17:52 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
2001-12-14 22:59:21 +00:00
|
|
|
/* set the state to idle */
|
2000-11-04 18:54:07 +00:00
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
|
2000-12-28 22:12:02 +00:00
|
|
|
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("creating thread \"%s\"", GST_ELEMENT_NAME (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
/* this bit of code handles creation of pthreads
|
|
|
|
* this is therefor tricky code
|
|
|
|
* compare it with the block of code that handles the destruction
|
|
|
|
* in GST_STATE_READY_TO_NULL below
|
|
|
|
*/
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_lock (thread->lock);
|
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
/* create attribute struct for pthread
|
|
|
|
* and assign stack pointer and size to it
|
|
|
|
*
|
|
|
|
* the default state of a pthread is PTHREAD_CREATE_JOINABLE
|
|
|
|
* (see man pthread_attr_init)
|
|
|
|
* - other thread can sync on termination
|
|
|
|
* - thread resources are kept allocated until other thread performs
|
|
|
|
* pthread_join
|
|
|
|
*/
|
|
|
|
|
2002-06-27 22:17:17 +00:00
|
|
|
if (pthread_attr_init (&thread->attr) != 0)
|
|
|
|
g_warning ("pthread_attr_init returned an error !");
|
2002-07-08 19:07:30 +00:00
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
/* this function should return a newly allocated stack
|
|
|
|
* (using whatever method)
|
|
|
|
* which we can initiate the pthreads with
|
|
|
|
* the stack should be freed in
|
|
|
|
*/
|
2002-07-11 21:22:55 +00:00
|
|
|
if (gst_scheduler_get_preferred_stack (GST_ELEMENT_SCHED (element),
|
|
|
|
&thread->stack, &stacksize)) {
|
|
|
|
#ifdef HAVE_PTHREAD_ATTR_SETSTACK
|
2002-09-12 18:56:31 +00:00
|
|
|
if (pthread_attr_setstack (&thread->attr,
|
|
|
|
thread->stack, stacksize) != 0) {
|
2002-07-11 21:22:55 +00:00
|
|
|
g_warning ("pthread_attr_setstack failed\n");
|
2002-06-27 23:55:27 +00:00
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
2002-07-11 21:22:55 +00:00
|
|
|
#else
|
|
|
|
if (pthread_attr_setstackaddr (&thread->attr, thread->stack) != 0) {
|
|
|
|
g_warning ("pthread_attr_setstackaddr failed\n");
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
|
|
|
if (pthread_attr_setstacksize (&thread->attr, stacksize) != 0) {
|
|
|
|
g_warning ("pthread_attr_setstacksize failed\n");
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
2002-06-27 23:55:27 +00:00
|
|
|
GST_DEBUG (GST_CAT_THREAD, "pthread attr set stack at %p of size %ld",
|
|
|
|
thread->stack, stacksize);
|
2002-06-19 18:13:28 +00:00
|
|
|
}
|
2002-09-12 18:56:31 +00:00
|
|
|
else {
|
|
|
|
g_warning ("scheduler did not return a preferred stack");
|
|
|
|
}
|
2002-06-27 22:17:17 +00:00
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
/* create a new pthread
|
|
|
|
* use the specified attributes
|
|
|
|
* make it execute gst_thread_main_loop (thread)
|
|
|
|
*/
|
|
|
|
GST_DEBUG (GST_CAT_THREAD, "going to pthread_create...");
|
|
|
|
if (pthread_create (&thread->thread_id, &thread->attr,
|
|
|
|
gst_thread_main_loop, thread) != 0) {
|
|
|
|
GST_DEBUG (GST_CAT_THREAD, "pthread_create failed");
|
2002-05-29 15:01:50 +00:00
|
|
|
g_mutex_unlock (thread->lock);
|
2002-09-12 18:56:31 +00:00
|
|
|
GST_DEBUG (GST_CAT_THREAD, "could not create thread \"%s\"",
|
|
|
|
GST_ELEMENT_NAME (element));
|
2002-05-29 15:01:50 +00:00
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
2002-09-12 18:56:31 +00:00
|
|
|
GST_DEBUG (GST_CAT_THREAD, "pthread created");
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* wait for it to 'spin up' */
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("waiting for child thread spinup");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("thread claims to be up");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_unlock (thread->lock);
|
2001-05-25 21:00:07 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2001-12-04 22:12:50 +00:00
|
|
|
THR_INFO ("readying thread");
|
|
|
|
g_mutex_lock (thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("signaling");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("waiting for ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("got ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_unlock (thread->lock);
|
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
|
|
|
{
|
|
|
|
/* fixme: recurse into sub-bins */
|
|
|
|
const GList *elements = gst_bin_get_list (GST_BIN (thread));
|
|
|
|
while (elements) {
|
|
|
|
gst_element_enable_threadsafe_properties ((GstElement*)elements->data);
|
|
|
|
elements = g_list_next (elements);
|
|
|
|
}
|
|
|
|
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("telling thread to start spinning");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_lock (thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("signaling");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("waiting for ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("got ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_unlock (thread->lock);
|
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
|
|
|
{
|
2002-05-26 03:23:25 +00:00
|
|
|
const GList *elements = (GList *) gst_bin_get_list (GST_BIN (thread));
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
THR_INFO ("pausing thread");
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* the following code ensures that the bottom half of thread will run
|
|
|
|
* to perform each elements' change_state() (by calling gstbin.c::
|
|
|
|
* change_state()).
|
|
|
|
* + the pending state was already set by gstelement.c::set_state()
|
2002-05-26 21:54:27 +00:00
|
|
|
* + unlock all elements so the bottom half can start the state change.
|
2001-12-14 22:59:21 +00:00
|
|
|
*/
|
2001-12-22 21:18:17 +00:00
|
|
|
g_mutex_lock (thread->lock);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
|
|
|
|
|
|
|
|
while (elements) {
|
2001-12-20 02:41:34 +00:00
|
|
|
GstElement *element = GST_ELEMENT (elements->data);
|
2002-05-26 21:54:27 +00:00
|
|
|
GList *pads;
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-20 02:41:34 +00:00
|
|
|
g_assert (element);
|
2002-05-26 21:54:27 +00:00
|
|
|
THR_DEBUG (" waking element \"%s\"", GST_ELEMENT_NAME (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
elements = g_list_next (elements);
|
2002-05-26 21:54:27 +00:00
|
|
|
|
|
|
|
if (!gst_element_release_locks (element)) {
|
|
|
|
g_warning ("element %s could not release locks", GST_ELEMENT_NAME (element));
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
pads = GST_ELEMENT_PADS (element);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
while (pads) {
|
2002-09-13 13:32:28 +00:00
|
|
|
GstRealPad *peer = NULL;
|
2002-05-26 21:54:27 +00:00
|
|
|
GstElement *peerelement;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-09-13 13:32:28 +00:00
|
|
|
if (GST_PAD_PEER (pads->data))
|
|
|
|
peer = GST_REAL_PAD (GST_PAD_PEER (pads->data));
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
pads = g_list_next (pads);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
if (!peer)
|
|
|
|
continue;
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
peerelement = GST_PAD_PARENT (peer);
|
|
|
|
if (!peerelement)
|
|
|
|
continue; /* deal with case where there's no peer */
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
if (!GST_FLAG_IS_SET (peerelement, GST_ELEMENT_DECOUPLED)) {
|
|
|
|
GST_DEBUG (GST_CAT_THREAD, "peer element isn't DECOUPLED");
|
|
|
|
continue;
|
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
if (GST_ELEMENT_SCHED (peerelement) != GST_ELEMENT_SCHED (thread)) {
|
|
|
|
THR_DEBUG (" element \"%s\" has pad cross sched boundary", GST_ELEMENT_NAME (element));
|
2002-06-04 21:01:10 +00:00
|
|
|
THR_DEBUG (" waking element \"%s\"", GST_ELEMENT_NAME (peerelement));
|
|
|
|
if (!gst_element_release_locks (peerelement)) {
|
|
|
|
g_warning ("element %s could not release locks", GST_ELEMENT_NAME (peerelement));
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-05-26 03:23:25 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("telling thread to pause, signaling");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("waiting for ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("got ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_unlock (thread->lock);
|
2002-05-26 21:54:27 +00:00
|
|
|
|
|
|
|
elements = gst_bin_get_list (GST_BIN (thread));
|
|
|
|
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
|
|
|
}
|
2000-12-23 03:17:52 +00:00
|
|
|
case GST_STATE_READY_TO_NULL:
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("telling thread to pause (null) - and joining");
|
2001-12-14 22:59:21 +00:00
|
|
|
/* MattH FIXME revisit */
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_lock (thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("signaling");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("waiting for ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("got ack");
|
2002-09-12 18:56:31 +00:00
|
|
|
|
|
|
|
/* this block of code is very tricky
|
|
|
|
* basically, we try to clean up the whole thread and
|
|
|
|
* everything related to it in the right order without
|
|
|
|
* triggering segfaults
|
|
|
|
* compare this block to the block
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* in glibc 2.2.5, pthread_attr_destroy does nothing more
|
|
|
|
* than return 0 */
|
|
|
|
if (pthread_attr_destroy (&thread->attr) != 0)
|
|
|
|
g_warning ("pthread_attr_destroy has failed !");
|
|
|
|
|
|
|
|
GST_DEBUG (GST_CAT_THREAD, "joining pthread %ld", thread->thread_id);
|
2002-06-27 22:17:17 +00:00
|
|
|
if (pthread_join (thread->thread_id, NULL) != 0)
|
|
|
|
g_warning ("pthread_join has failed !\n");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-09-12 18:56:31 +00:00
|
|
|
thread->thread_id = -1;
|
|
|
|
|
|
|
|
/* the stack was allocated when we created the thread
|
|
|
|
* using scheduler->get_preferred_stack */
|
2002-06-27 23:55:27 +00:00
|
|
|
if (thread->stack) {
|
2002-09-12 18:56:31 +00:00
|
|
|
GST_DEBUG (GST_CAT_THREAD, "freeing allocated stack (%p)",
|
|
|
|
thread->stack);
|
2002-06-27 23:55:27 +00:00
|
|
|
free (thread->stack);
|
|
|
|
thread->stack = NULL;
|
|
|
|
}
|
2002-09-12 18:56:31 +00:00
|
|
|
|
|
|
|
THR_DEBUG ("unlocking mutex");
|
|
|
|
g_mutex_unlock (thread->lock);
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
|
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_STARTED);
|
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-07-31 20:57:58 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("telling thread to stop spinning");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_lock (thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("signaling");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("waiting for ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG ("got ack");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_mutex_unlock (thread->lock);
|
|
|
|
|
2000-09-09 16:36:10 +00:00
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
default:
|
2002-04-03 18:26:03 +00:00
|
|
|
GST_DEBUG_ELEMENT (GST_CAT_THREAD, element, "UNHANDLED STATE CHANGE! %x", transition);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stateset;
|
|
|
|
}
|
|
|
|
|
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;
|
2001-05-25 21:00:07 +00:00
|
|
|
gint stateset;
|
|
|
|
|
2002-06-27 22:22:42 +00:00
|
|
|
GST_DEBUG (GST_CAT_THREAD, "gst_thread_main_loop started");
|
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);
|
|
|
|
|
2002-09-12 20:13:21 +00:00
|
|
|
/* handle scheduler policy; do stuff if not the normal scheduler */
|
2002-07-08 19:07:30 +00:00
|
|
|
if (thread->sched_policy != SCHED_OTHER) {
|
|
|
|
struct sched_param sched_param;
|
|
|
|
|
|
|
|
memset (&sched_param, 0, sizeof (sched_param));
|
|
|
|
if (thread->priority == 0) {
|
|
|
|
thread->priority = sched_get_priority_max (thread->sched_policy);
|
|
|
|
}
|
|
|
|
sched_param.sched_priority = thread->priority;
|
|
|
|
|
|
|
|
if (sched_setscheduler (0, thread->sched_policy, &sched_param) != 0) {
|
|
|
|
GST_DEBUG (GST_CAT_THREAD, "not running with real-time priority");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
thread->pid = getpid();
|
2002-09-12 18:56:31 +00:00
|
|
|
THR_INFO_MAIN ("thread is running");
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* first we need to change the state of all the children */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state) {
|
2001-05-25 21:00:07 +00:00
|
|
|
stateset = GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT(thread));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
if (stateset != GST_STATE_SUCCESS) {
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG_MAIN ("state change of children failed");
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG_MAIN ("indicating spinup");
|
2001-05-25 21:00:07 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2001-12-14 22:59:21 +00:00
|
|
|
/* don't unlock the mutex because we hold it into the top of the while loop */
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG_MAIN ("thread has indicated spinup to parent process");
|
2001-01-21 16:06:42 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
/***** THREAD IS NOW IN READY STATE *****/
|
2000-09-24 14:29:49 +00:00
|
|
|
|
2002-04-12 09:38:47 +00:00
|
|
|
/* CR1: most of this code is handshaking */
|
|
|
|
/* do this while the thread lives */
|
2000-11-04 18:54:07 +00:00
|
|
|
while (!GST_FLAG_IS_SET (thread, GST_THREAD_STATE_REAPING)) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* NOTE we hold the thread lock at this point */
|
|
|
|
/* what we do depends on what state we're in */
|
2001-12-04 22:12:50 +00:00
|
|
|
switch (GST_STATE (thread)) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* NOTE: cannot be in NULL, we're not running in that state at all */
|
2001-05-25 21:00:07 +00:00
|
|
|
case GST_STATE_READY:
|
2001-12-14 22:59:21 +00:00
|
|
|
/* wait to be set to either the NULL or PAUSED states */
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG_MAIN ("thread in %s state, waiting for either %s or %s",
|
2002-04-23 11:15:18 +00:00
|
|
|
gst_element_state_get_name (GST_STATE_READY),
|
|
|
|
gst_element_state_get_name (GST_STATE_NULL),
|
|
|
|
gst_element_state_get_name (GST_STATE_PAUSED));
|
2002-09-12 18:56:31 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-20 02:41:34 +00:00
|
|
|
/* this must have happened by a state change in the thread context */
|
|
|
|
if (GST_STATE_PENDING (thread) != GST_STATE_NULL &&
|
|
|
|
GST_STATE_PENDING (thread) != GST_STATE_PAUSED) {
|
|
|
|
g_cond_signal (thread->cond);
|
|
|
|
continue;
|
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* been signaled, we need to state transition now and signal back */
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_thread_update_state (thread);
|
2002-09-12 18:56:31 +00:00
|
|
|
THR_DEBUG_MAIN ("done with state transition, "
|
|
|
|
"signaling back to parent process");
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2001-12-14 22:59:21 +00:00
|
|
|
/* now we decide what to do next */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_STATE (thread) == GST_STATE_NULL) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* REAPING must be set, we can simply break this iteration */
|
2002-09-12 18:56:31 +00:00
|
|
|
THR_DEBUG_MAIN ("set GST_THREAD_STATE_REAPING");
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_FLAG_SET (thread, GST_THREAD_STATE_REAPING);
|
|
|
|
}
|
|
|
|
continue;
|
2002-09-12 18:56:31 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
case GST_STATE_PAUSED:
|
2001-12-14 22:59:21 +00:00
|
|
|
/* wait to be set to either the READY or PLAYING states */
|
2002-09-12 18:56:31 +00:00
|
|
|
THR_DEBUG_MAIN ("thread in %s state, waiting for either %s or %s",
|
|
|
|
gst_element_state_get_name (GST_STATE_PAUSED),
|
|
|
|
gst_element_state_get_name (GST_STATE_READY),
|
|
|
|
gst_element_state_get_name (GST_STATE_PLAYING));
|
2002-04-12 09:38:47 +00:00
|
|
|
g_cond_wait (thread->cond, thread->lock);
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-20 02:41:34 +00:00
|
|
|
/* this must have happened by a state change in the thread context */
|
|
|
|
if (GST_STATE_PENDING (thread) != GST_STATE_READY &&
|
|
|
|
GST_STATE_PENDING (thread) != GST_STATE_PLAYING) {
|
|
|
|
g_cond_signal (thread->cond);
|
|
|
|
continue;
|
|
|
|
}
|
2001-12-04 22:12:50 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* been signaled, we need to state transition now and signal back */
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_thread_update_state (thread);
|
2001-12-14 22:59:21 +00:00
|
|
|
/* now we decide what to do next */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_STATE (thread) != GST_STATE_PLAYING) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* either READY or the state change failed for some reason */
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2001-05-25 21:00:07 +00:00
|
|
|
continue;
|
2001-12-04 22:12:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
GST_FLAG_SET (thread, GST_THREAD_STATE_SPINNING);
|
2001-12-14 22:59:21 +00:00
|
|
|
/* PLAYING is coming up, so we can now start spinning */
|
2001-05-25 21:00:07 +00:00
|
|
|
while (GST_FLAG_IS_SET (thread, GST_THREAD_STATE_SPINNING)) {
|
2001-12-04 22:12:50 +00:00
|
|
|
gboolean status;
|
|
|
|
|
|
|
|
g_cond_signal (thread->cond);
|
|
|
|
g_mutex_unlock (thread->lock);
|
|
|
|
status = gst_bin_iterate (GST_BIN (thread));
|
|
|
|
g_mutex_lock (thread->lock);
|
2001-12-14 22:59:21 +00:00
|
|
|
/* g_cond_signal(thread->cond); */
|
2001-12-04 22:12:50 +00:00
|
|
|
|
|
|
|
if (!status || GST_STATE_PENDING (thread) != GST_STATE_VOID_PENDING)
|
|
|
|
GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2001-12-14 22:59:21 +00:00
|
|
|
/* looks like we were stopped because of a statechange */
|
2001-12-04 22:12:50 +00:00
|
|
|
if (GST_STATE_PENDING (thread)) {
|
|
|
|
gst_thread_update_state (thread);
|
|
|
|
}
|
2001-12-14 22:59:21 +00:00
|
|
|
/* once we're here, SPINNING has stopped, we should signal that we're done */
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG_MAIN ("SPINNING stopped, signaling back to parent process");
|
2001-05-25 21:00:07 +00:00
|
|
|
g_cond_signal (thread->cond);
|
2001-12-14 22:59:21 +00:00
|
|
|
/* now we can wait for PAUSED */
|
2001-05-25 21:00:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case GST_STATE_PLAYING:
|
2001-12-14 22:59:21 +00:00
|
|
|
/* wait to be set to PAUSED */
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG_MAIN ("thread in %s state, waiting for %s",
|
2002-09-12 18:56:31 +00:00
|
|
|
gst_element_state_get_name (GST_STATE_PLAYING),
|
|
|
|
gst_element_state_get_name (GST_STATE_PAUSED));
|
2001-12-04 22:12:50 +00:00
|
|
|
g_cond_wait (thread->cond,thread->lock);
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* been signaled, we need to state transition now and signal back */
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_thread_update_state (thread);
|
|
|
|
g_cond_signal (thread->cond);
|
2001-12-14 22:59:21 +00:00
|
|
|
/* now we decide what to do next */
|
|
|
|
/* there's only PAUSED, we we just wait for it */
|
2001-05-25 21:00:07 +00:00
|
|
|
continue;
|
2001-12-04 22:12:50 +00:00
|
|
|
case GST_STATE_NULL:
|
2002-04-03 18:26:03 +00:00
|
|
|
THR_DEBUG_MAIN ("thread in %s state, preparing to die",
|
2002-09-12 18:56:31 +00:00
|
|
|
gst_element_state_get_name (GST_STATE_NULL));
|
2001-12-04 22:12:50 +00:00
|
|
|
GST_FLAG_SET (thread, GST_THREAD_STATE_REAPING);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2001-05-25 21:00:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
2002-09-12 18:56:31 +00:00
|
|
|
|
|
|
|
/* THREAD HAS STOPPED RUNNING */
|
|
|
|
|
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));
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* since we don't unlock at the end of the while loop, do it here */
|
2001-05-25 21:00:07 +00:00
|
|
|
g_mutex_unlock (thread->lock);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-01 03:14:40 +00:00
|
|
|
GST_INFO (GST_CAT_THREAD, "gstthread: thread \"%s\" is stopped",
|
2001-01-29 00:06:02 +00:00
|
|
|
GST_ELEMENT_NAME (thread));
|
2002-07-08 19:07:30 +00:00
|
|
|
|
|
|
|
g_signal_emit (G_OBJECT (thread), gst_thread_signals[SHUTDOWN], 0);
|
|
|
|
|
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
|
|
|
{
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (GST_CAT_THREAD,"gstthread: restore");
|
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 */
|