2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstthread.c: Threaded container object
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 /* #define GST_DEBUG_ENABLED */
26 #include "gst_private.h"
29 #include "gstthread.h"
30 #include "gstscheduler.h"
33 GstElementDetails gst_thread_details = {
37 "Container that creates/manages a thread",
39 "Erik Walthinsen <omega@cse.ogi.edu>",
44 /* Thread signals and args */
65 static void gst_thread_class_init (GstThreadClass *klass);
66 static void gst_thread_init (GstThread *thread);
68 static void gst_thread_dispose (GObject *object);
70 static void gst_thread_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
71 static void gst_thread_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
73 static GstElementStateReturn gst_thread_change_state (GstElement *element);
75 #ifndef GST_DISABLE_LOADSAVE
76 static xmlNodePtr gst_thread_save_thyself (GstObject *object, xmlNodePtr parent);
77 static void gst_thread_restore_thyself (GstObject *object, xmlNodePtr self);
80 static void* gst_thread_main_loop (void *arg);
82 #define GST_TYPE_THREAD_SCHEDPOLICY (gst_thread_schedpolicy_get_type())
84 gst_thread_schedpolicy_get_type(void) {
85 static GType thread_schedpolicy_type = 0;
86 static GEnumValue thread_schedpolicy[] = {
87 {SCHED_OTHER, "SCHED_OTHER", "Normal Scheduling"},
88 {SCHED_FIFO, "SCHED_FIFO", "FIFO Scheduling (requires root)"},
89 {SCHED_RR, "SCHED_RR", "Round-Robin Scheduling (requires root)"},
92 if (!thread_schedpolicy_type) {
93 thread_schedpolicy_type = g_enum_register_static("GstThreadSchedPolicy", thread_schedpolicy);
95 return thread_schedpolicy_type;
98 static GstBinClass *parent_class = NULL;
99 static guint gst_thread_signals[LAST_SIGNAL] = { 0 };
102 gst_thread_get_type(void) {
103 static GType thread_type = 0;
106 static const GTypeInfo thread_info = {
107 sizeof(GstThreadClass),
110 (GClassInitFunc)gst_thread_class_init,
115 (GInstanceInitFunc)gst_thread_init,
118 thread_type = g_type_register_static(GST_TYPE_BIN, "GstThread", &thread_info, 0);
124 gst_thread_class_init (GstThreadClass *klass)
126 GObjectClass *gobject_class;
127 GstObjectClass *gstobject_class;
128 GstElementClass *gstelement_class;
129 GstBinClass *gstbin_class;
131 gobject_class = (GObjectClass*)klass;
132 gstobject_class = (GstObjectClass*)klass;
133 gstelement_class = (GstElementClass*)klass;
134 gstbin_class = (GstBinClass*)klass;
136 parent_class = g_type_class_ref (GST_TYPE_BIN);
138 g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_SCHEDPOLICY,
139 g_param_spec_enum("schedpolicy", "Scheduling Policy", "The scheduling policy of the thread",
140 GST_TYPE_THREAD_SCHEDPOLICY, SCHED_OTHER, G_PARAM_READWRITE));
141 g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_PRIORITY,
142 g_param_spec_int("priority", "Scheduling Priority", "The scheduling priority of the thread",
143 0, 99, 0, G_PARAM_READWRITE));
145 gst_thread_signals[SHUTDOWN] =
146 g_signal_new ("shutdown", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
147 G_STRUCT_OFFSET (GstThreadClass, shutdown), NULL, NULL,
148 gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
150 gobject_class->dispose = gst_thread_dispose;
152 #ifndef GST_DISABLE_LOADSAVE
153 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_thread_save_thyself);
154 gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR (gst_thread_restore_thyself);
157 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_thread_change_state);
159 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_thread_set_property);
160 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_thread_get_property);
165 gst_thread_init (GstThread *thread)
167 GstScheduler *scheduler;
169 GST_DEBUG (GST_CAT_THREAD, "initializing thread");
171 /* threads are managing bins and iterate themselves */
172 /* CR1: the GstBin code checks these flags */
173 GST_FLAG_SET (thread, GST_BIN_FLAG_MANAGER);
174 GST_FLAG_SET (thread, GST_BIN_SELF_SCHEDULABLE);
176 scheduler = gst_scheduler_factory_make (NULL, GST_ELEMENT (thread));
178 thread->lock = g_mutex_new ();
179 thread->cond = g_cond_new ();
181 thread->ppid = getpid ();
182 thread->thread_id = (pthread_t) -1;
183 thread->sched_policy = SCHED_OTHER;
184 thread->priority = 0;
185 thread->stack = NULL;
189 gst_thread_dispose (GObject *object)
191 GstThread *thread = GST_THREAD (object);
193 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose");
195 g_mutex_free (thread->lock);
196 g_cond_free (thread->cond);
198 G_OBJECT_CLASS (parent_class)->dispose (object);
200 if (GST_ELEMENT_SCHED (thread)) {
201 gst_object_unref (GST_OBJECT (GST_ELEMENT_SCHED (thread)));
206 gst_thread_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
210 /* it's not null if we got it, but it might not be ours */
211 g_return_if_fail (GST_IS_THREAD (object));
213 thread = GST_THREAD (object);
216 case ARG_SCHEDPOLICY:
217 thread->sched_policy = g_value_get_enum (value);
220 thread->priority = g_value_get_int (value);
223 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
229 gst_thread_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
233 /* it's not null if we got it, but it might not be ours */
234 g_return_if_fail (GST_IS_THREAD (object));
236 thread = GST_THREAD (object);
239 case ARG_SCHEDPOLICY:
240 g_value_set_enum (value, thread->sched_policy);
243 g_value_set_int (value, thread->priority);
246 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
254 * @name: the name of the thread
256 * Create a new thread with the given name.
258 * Returns: The new thread
261 gst_thread_new (const gchar *name)
263 return gst_element_factory_make ("thread", name);
266 /* these two macros are used for debug/info from the state_change function */
268 #define THR_INFO(format,args...) \
269 GST_INFO_ELEMENT(GST_CAT_THREAD, thread, "sync(" GST_DEBUG_THREAD_FORMAT "): " format , \
270 GST_DEBUG_THREAD_ARGS(thread->pid) , ## args )
272 #define THR_DEBUG(format,args...) \
273 GST_DEBUG_ELEMENT(GST_CAT_THREAD, thread, "sync(" GST_DEBUG_THREAD_FORMAT "): " format , \
274 GST_DEBUG_THREAD_ARGS(thread->pid) , ## args )
276 /* these two macros are used for debug/info from the gst_thread_main_loop
280 #define THR_INFO_MAIN(format,args...) \
281 GST_INFO_ELEMENT(GST_CAT_THREAD, thread, "sync-main(" GST_DEBUG_THREAD_FORMAT "): " format , \
282 GST_DEBUG_THREAD_ARGS(thread->ppid) , ## args )
284 #define THR_DEBUG_MAIN(format,args...) \
285 GST_DEBUG_ELEMENT(GST_CAT_THREAD, thread, "sync-main(" GST_DEBUG_THREAD_FORMAT "): " format , \
286 GST_DEBUG_THREAD_ARGS(thread->ppid) , ## args )
288 static GstElementStateReturn
289 gst_thread_update_state (GstThread *thread)
291 GST_DEBUG_ELEMENT (GST_CAT_THREAD, thread, "updating state of thread");
292 /* check for state change */
293 if (GST_STATE_PENDING (thread) != GST_STATE_VOID_PENDING) {
294 /* punt and change state on all the children */
295 if (GST_ELEMENT_CLASS (parent_class)->change_state)
296 return GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT (thread));
299 /* FIXME: in the case of no change_state function in the parent's class,
300 * shouldn't we actually change the thread's state ? */
301 g_warning ("thread's parent doesn't have change_state, returning success");
302 return GST_STATE_SUCCESS;
306 static GstElementStateReturn
307 gst_thread_change_state (GstElement * element)
310 gboolean stateset = GST_STATE_SUCCESS;
312 pthread_t self = pthread_self ();
315 g_return_val_if_fail (GST_IS_THREAD (element), GST_STATE_FAILURE);
316 g_return_val_if_fail (gst_has_threads (), GST_STATE_FAILURE);
318 thread = GST_THREAD (element);
320 transition = GST_STATE_TRANSITION (element);
322 THR_INFO ("changing state from %s to %s",
323 gst_element_state_get_name (GST_STATE (element)),
324 gst_element_state_get_name (GST_STATE_PENDING (element)));
326 if (pthread_equal (self, thread->thread_id)) {
327 GST_DEBUG (GST_CAT_THREAD,
328 "no sync(" GST_DEBUG_THREAD_FORMAT "): setting own thread's state to spinning",
329 GST_DEBUG_THREAD_ARGS (thread->pid));
330 return gst_thread_update_state (thread);
333 switch (transition) {
334 case GST_STATE_NULL_TO_READY:
335 /* set the state to idle */
336 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
338 THR_DEBUG ("creating thread \"%s\"", GST_ELEMENT_NAME (element));
340 /* this bit of code handles creation of pthreads
341 * this is therefor tricky code
342 * compare it with the block of code that handles the destruction
343 * in GST_STATE_READY_TO_NULL below
345 g_mutex_lock (thread->lock);
347 /* create attribute struct for pthread
348 * and assign stack pointer and size to it
350 * the default state of a pthread is PTHREAD_CREATE_JOINABLE
351 * (see man pthread_attr_init)
352 * - other thread can sync on termination
353 * - thread resources are kept allocated until other thread performs
357 if (pthread_attr_init (&thread->attr) != 0)
358 g_warning ("pthread_attr_init returned an error !");
360 /* this function should return a newly allocated stack
361 * (using whatever method)
362 * which we can initiate the pthreads with
363 * the stack should be freed in
365 if (gst_scheduler_get_preferred_stack (GST_ELEMENT_SCHED (element),
366 &thread->stack, &stacksize)) {
367 #ifdef HAVE_PTHREAD_ATTR_SETSTACK
368 if (pthread_attr_setstack (&thread->attr,
369 thread->stack, stacksize) != 0) {
370 g_warning ("pthread_attr_setstack failed\n");
371 return GST_STATE_FAILURE;
374 if (pthread_attr_setstackaddr (&thread->attr, thread->stack) != 0) {
375 g_warning ("pthread_attr_setstackaddr failed\n");
376 return GST_STATE_FAILURE;
378 if (pthread_attr_setstacksize (&thread->attr, stacksize) != 0) {
379 g_warning ("pthread_attr_setstacksize failed\n");
380 return GST_STATE_FAILURE;
383 GST_DEBUG (GST_CAT_THREAD, "pthread attr set stack at %p of size %ld",
384 thread->stack, stacksize);
387 g_warning ("scheduler did not return a preferred stack");
390 /* create a new pthread
391 * use the specified attributes
392 * make it execute gst_thread_main_loop (thread)
394 GST_DEBUG (GST_CAT_THREAD, "going to pthread_create...");
395 if (pthread_create (&thread->thread_id, &thread->attr,
396 gst_thread_main_loop, thread) != 0) {
397 GST_DEBUG (GST_CAT_THREAD, "pthread_create failed");
398 g_mutex_unlock (thread->lock);
399 GST_DEBUG (GST_CAT_THREAD, "could not create thread \"%s\"",
400 GST_ELEMENT_NAME (element));
401 return GST_STATE_FAILURE;
403 GST_DEBUG (GST_CAT_THREAD, "pthread created");
405 /* wait for it to 'spin up' */
406 THR_DEBUG ("waiting for child thread spinup");
407 g_cond_wait (thread->cond, thread->lock);
408 THR_DEBUG ("thread claims to be up");
409 g_mutex_unlock (thread->lock);
411 case GST_STATE_READY_TO_PAUSED:
412 THR_INFO ("readying thread");
413 g_mutex_lock (thread->lock);
414 THR_DEBUG ("signaling");
415 g_cond_signal (thread->cond);
416 THR_DEBUG ("waiting for ack");
417 g_cond_wait (thread->cond, thread->lock);
418 THR_DEBUG ("got ack");
419 g_mutex_unlock (thread->lock);
421 case GST_STATE_PAUSED_TO_PLAYING:
423 /* fixme: recurse into sub-bins */
424 const GList *elements = gst_bin_get_list (GST_BIN (thread));
426 gst_element_enable_threadsafe_properties ((GstElement*)elements->data);
427 elements = g_list_next (elements);
430 THR_DEBUG ("telling thread to start spinning");
431 g_mutex_lock (thread->lock);
432 THR_DEBUG ("signaling");
433 g_cond_signal (thread->cond);
434 THR_DEBUG ("waiting for ack");
435 g_cond_wait (thread->cond, thread->lock);
436 THR_DEBUG ("got ack");
437 g_mutex_unlock (thread->lock);
440 case GST_STATE_PLAYING_TO_PAUSED:
442 const GList *elements = (GList *) gst_bin_get_list (GST_BIN (thread));
444 THR_INFO ("pausing thread");
446 /* the following code ensures that the bottom half of thread will run
447 * to perform each elements' change_state() (by calling gstbin.c::
449 * + the pending state was already set by gstelement.c::set_state()
450 * + unlock all elements so the bottom half can start the state change.
452 g_mutex_lock (thread->lock);
454 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
457 GstElement *element = GST_ELEMENT (elements->data);
462 THR_DEBUG (" waking element \"%s\"", GST_ELEMENT_NAME (element));
463 elements = g_list_next (elements);
465 if (!gst_element_release_locks (element)) {
466 g_warning ("element %s could not release locks", GST_ELEMENT_NAME (element));
469 pads = GST_ELEMENT_PADS (element);
472 GstRealPad *peer = NULL;
473 GstElement *peerelement;
475 if (GST_PAD_PEER (pads->data))
476 peer = GST_REAL_PAD (GST_PAD_PEER (pads->data));
478 pads = g_list_next (pads);
483 peerelement = GST_PAD_PARENT (peer);
485 continue; /* deal with case where there's no peer */
487 if (!GST_FLAG_IS_SET (peerelement, GST_ELEMENT_DECOUPLED)) {
488 GST_DEBUG (GST_CAT_THREAD, "peer element isn't DECOUPLED");
492 if (GST_ELEMENT_SCHED (peerelement) != GST_ELEMENT_SCHED (thread)) {
493 THR_DEBUG (" element \"%s\" has pad cross sched boundary", GST_ELEMENT_NAME (element));
494 THR_DEBUG (" waking element \"%s\"", GST_ELEMENT_NAME (peerelement));
495 if (!gst_element_release_locks (peerelement)) {
496 g_warning ("element %s could not release locks", GST_ELEMENT_NAME (peerelement));
502 THR_DEBUG ("telling thread to pause, signaling");
503 g_cond_signal (thread->cond);
504 THR_DEBUG ("waiting for ack");
505 g_cond_wait (thread->cond, thread->lock);
506 THR_DEBUG ("got ack");
507 g_mutex_unlock (thread->lock);
509 elements = gst_bin_get_list (GST_BIN (thread));
511 gst_element_disable_threadsafe_properties ((GstElement*)elements->data);
512 elements = g_list_next (elements);
516 case GST_STATE_READY_TO_NULL:
517 THR_DEBUG ("telling thread to pause (null) - and joining");
518 /* MattH FIXME revisit */
519 g_mutex_lock (thread->lock);
520 THR_DEBUG ("signaling");
521 g_cond_signal (thread->cond);
522 THR_DEBUG ("waiting for ack");
523 g_cond_wait (thread->cond, thread->lock);
524 THR_DEBUG ("got ack");
526 /* this block of code is very tricky
527 * basically, we try to clean up the whole thread and
528 * everything related to it in the right order without
529 * triggering segfaults
530 * compare this block to the block
534 /* in glibc 2.2.5, pthread_attr_destroy does nothing more
536 if (pthread_attr_destroy (&thread->attr) != 0)
537 g_warning ("pthread_attr_destroy has failed !");
539 GST_DEBUG (GST_CAT_THREAD, "joining pthread %ld", thread->thread_id);
540 if (pthread_join (thread->thread_id, NULL) != 0)
541 g_warning ("pthread_join has failed !\n");
543 thread->thread_id = -1;
545 /* the stack was allocated when we created the thread
546 * using scheduler->get_preferred_stack */
548 GST_DEBUG (GST_CAT_THREAD, "freeing allocated stack (%p)",
550 free (thread->stack);
551 thread->stack = NULL;
554 THR_DEBUG ("unlocking mutex");
555 g_mutex_unlock (thread->lock);
557 GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
558 GST_FLAG_UNSET (thread, GST_THREAD_STATE_STARTED);
559 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
562 case GST_STATE_PAUSED_TO_READY:
563 THR_DEBUG ("telling thread to stop spinning");
564 g_mutex_lock (thread->lock);
565 THR_DEBUG ("signaling");
566 g_cond_signal (thread->cond);
567 THR_DEBUG ("waiting for ack");
568 g_cond_wait (thread->cond, thread->lock);
569 THR_DEBUG ("got ack");
570 g_mutex_unlock (thread->lock);
574 GST_DEBUG_ELEMENT (GST_CAT_THREAD, element, "UNHANDLED STATE CHANGE! %x", transition);
582 * gst_thread_main_loop:
583 * @arg: the thread to start
585 * The main loop of the thread. The thread will iterate
586 * while the state is GST_THREAD_STATE_SPINNING.
589 gst_thread_main_loop (void *arg)
591 GstThread *thread = NULL;
594 GST_DEBUG (GST_CAT_THREAD, "gst_thread_main_loop started");
595 thread = GST_THREAD (arg);
596 g_mutex_lock (thread->lock);
598 /* handle scheduler policy; do stuff if not the normal scheduler */
599 if (thread->sched_policy != SCHED_OTHER) {
600 struct sched_param sched_param;
602 memset (&sched_param, 0, sizeof (sched_param));
603 if (thread->priority == 0) {
604 thread->priority = sched_get_priority_max (thread->sched_policy);
606 sched_param.sched_priority = thread->priority;
608 if (sched_setscheduler (0, thread->sched_policy, &sched_param) != 0) {
609 GST_DEBUG (GST_CAT_THREAD, "not running with real-time priority");
613 /* set up the element's scheduler */
614 gst_scheduler_setup (GST_ELEMENT_SCHED (thread));
615 GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
617 thread->pid = getpid();
618 THR_INFO_MAIN ("thread is running");
620 /* first we need to change the state of all the children */
621 if (GST_ELEMENT_CLASS (parent_class)->change_state) {
622 stateset = GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT(thread));
624 if (stateset != GST_STATE_SUCCESS) {
625 THR_DEBUG_MAIN ("state change of children failed");
629 THR_DEBUG_MAIN ("indicating spinup");
630 g_cond_signal (thread->cond);
631 /* don't unlock the mutex because we hold it into the top of the while loop */
632 THR_DEBUG_MAIN ("thread has indicated spinup to parent process");
634 /***** THREAD IS NOW IN READY STATE *****/
636 /* CR1: most of this code is handshaking */
637 /* do this while the thread lives */
638 while (!GST_FLAG_IS_SET (thread, GST_THREAD_STATE_REAPING)) {
639 /* NOTE we hold the thread lock at this point */
640 /* what we do depends on what state we're in */
641 switch (GST_STATE (thread)) {
642 /* NOTE: cannot be in NULL, we're not running in that state at all */
643 case GST_STATE_READY:
644 /* wait to be set to either the NULL or PAUSED states */
645 THR_DEBUG_MAIN ("thread in %s state, waiting for either %s or %s",
646 gst_element_state_get_name (GST_STATE_READY),
647 gst_element_state_get_name (GST_STATE_NULL),
648 gst_element_state_get_name (GST_STATE_PAUSED));
649 g_cond_wait (thread->cond, thread->lock);
651 /* this must have happened by a state change in the thread context */
652 if (GST_STATE_PENDING (thread) != GST_STATE_NULL &&
653 GST_STATE_PENDING (thread) != GST_STATE_PAUSED) {
654 g_cond_signal (thread->cond);
658 /* been signaled, we need to state transition now and signal back */
659 gst_thread_update_state (thread);
660 THR_DEBUG_MAIN ("done with state transition, "
661 "signaling back to parent process");
662 g_cond_signal (thread->cond);
663 /* now we decide what to do next */
664 if (GST_STATE (thread) == GST_STATE_NULL) {
665 /* REAPING must be set, we can simply break this iteration */
666 THR_DEBUG_MAIN ("set GST_THREAD_STATE_REAPING");
667 GST_FLAG_SET (thread, GST_THREAD_STATE_REAPING);
671 case GST_STATE_PAUSED:
672 /* wait to be set to either the READY or PLAYING states */
673 THR_DEBUG_MAIN ("thread in %s state, waiting for either %s or %s",
674 gst_element_state_get_name (GST_STATE_PAUSED),
675 gst_element_state_get_name (GST_STATE_READY),
676 gst_element_state_get_name (GST_STATE_PLAYING));
677 g_cond_wait (thread->cond, thread->lock);
679 /* this must have happened by a state change in the thread context */
680 if (GST_STATE_PENDING (thread) != GST_STATE_READY &&
681 GST_STATE_PENDING (thread) != GST_STATE_PLAYING) {
682 g_cond_signal (thread->cond);
686 /* been signaled, we need to state transition now and signal back */
687 gst_thread_update_state (thread);
688 /* now we decide what to do next */
689 if (GST_STATE (thread) != GST_STATE_PLAYING) {
690 /* either READY or the state change failed for some reason */
691 g_cond_signal (thread->cond);
695 GST_FLAG_SET (thread, GST_THREAD_STATE_SPINNING);
696 /* PLAYING is coming up, so we can now start spinning */
697 while (GST_FLAG_IS_SET (thread, GST_THREAD_STATE_SPINNING)) {
700 g_cond_signal (thread->cond);
701 g_mutex_unlock (thread->lock);
702 status = gst_bin_iterate (GST_BIN (thread));
703 g_mutex_lock (thread->lock);
704 /* g_cond_signal(thread->cond); */
706 if (!status || GST_STATE_PENDING (thread) != GST_STATE_VOID_PENDING)
707 GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
709 /* looks like we were stopped because of a statechange */
710 if (GST_STATE_PENDING (thread)) {
711 gst_thread_update_state (thread);
713 /* once we're here, SPINNING has stopped, we should signal that we're done */
714 THR_DEBUG_MAIN ("SPINNING stopped, signaling back to parent process");
715 g_cond_signal (thread->cond);
716 /* now we can wait for PAUSED */
719 case GST_STATE_PLAYING:
720 /* wait to be set to PAUSED */
721 THR_DEBUG_MAIN ("thread in %s state, waiting for %s",
722 gst_element_state_get_name (GST_STATE_PLAYING),
723 gst_element_state_get_name (GST_STATE_PAUSED));
724 g_cond_wait (thread->cond,thread->lock);
726 /* been signaled, we need to state transition now and signal back */
727 gst_thread_update_state (thread);
728 g_cond_signal (thread->cond);
729 /* now we decide what to do next */
730 /* there's only PAUSED, we we just wait for it */
733 THR_DEBUG_MAIN ("thread in %s state, preparing to die",
734 gst_element_state_get_name (GST_STATE_NULL));
735 GST_FLAG_SET (thread, GST_THREAD_STATE_REAPING);
738 g_assert_not_reached ();
743 /* THREAD HAS STOPPED RUNNING */
745 /* we need to destroy the scheduler here because it has mapped it's
746 * stack into the threads stack space */
747 gst_scheduler_reset (GST_ELEMENT_SCHED (thread));
749 /* since we don't unlock at the end of the while loop, do it here */
750 g_mutex_unlock (thread->lock);
752 GST_INFO (GST_CAT_THREAD, "gstthread: thread \"%s\" is stopped",
753 GST_ELEMENT_NAME (thread));
755 g_signal_emit (G_OBJECT (thread), gst_thread_signals[SHUTDOWN], 0);
760 #ifndef GST_DISABLE_LOADSAVE
762 gst_thread_save_thyself (GstObject *object,
765 if (GST_OBJECT_CLASS (parent_class)->save_thyself)
766 GST_OBJECT_CLASS (parent_class)->save_thyself (object, self);
771 gst_thread_restore_thyself (GstObject *object,
774 GST_DEBUG (GST_CAT_THREAD,"gstthread: restore");
776 if (GST_OBJECT_CLASS (parent_class)->restore_thyself)
777 GST_OBJECT_CLASS (parent_class)->restore_thyself (object, self);
779 #endif /* GST_DISABLE_LOADSAVE */