2005-03-21 17:34:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* <2005> Wim Taymans <wim@fluendo.com>
|
|
|
|
*
|
|
|
|
* gsttask.h: Streaming tasks
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GST_TASK_H__
|
|
|
|
#define __GST_TASK_H__
|
|
|
|
|
|
|
|
#include <gst/gstobject.h>
|
2009-05-11 22:25:11 +00:00
|
|
|
#include <gst/gsttaskpool.h>
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2005-10-21 11:36:32 +00:00
|
|
|
/**
|
|
|
|
* GstTaskFunction:
|
|
|
|
* @data: user data passed to the function
|
|
|
|
*
|
2008-05-26 10:07:09 +00:00
|
|
|
* A function that will repeatedly be called in the thread created by
|
|
|
|
* a #GstTask.
|
2005-10-21 11:36:32 +00:00
|
|
|
*/
|
2005-03-21 17:34:02 +00:00
|
|
|
typedef void (*GstTaskFunction) (void *data);
|
|
|
|
|
|
|
|
/* --- standard type macros --- */
|
|
|
|
#define GST_TYPE_TASK (gst_task_get_type ())
|
|
|
|
#define GST_TASK(task) (G_TYPE_CHECK_INSTANCE_CAST ((task), GST_TYPE_TASK, GstTask))
|
|
|
|
#define GST_IS_TASK(task) (G_TYPE_CHECK_INSTANCE_TYPE ((task), GST_TYPE_TASK))
|
|
|
|
#define GST_TASK_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), GST_TYPE_TASK, GstTaskClass))
|
|
|
|
#define GST_IS_TASK_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), GST_TYPE_TASK))
|
|
|
|
#define GST_TASK_GET_CLASS(task) (G_TYPE_INSTANCE_GET_CLASS ((task), GST_TYPE_TASK, GstTaskClass))
|
|
|
|
#define GST_TASK_CAST(task) ((GstTask*)(task))
|
|
|
|
|
|
|
|
typedef struct _GstTask GstTask;
|
|
|
|
typedef struct _GstTaskClass GstTaskClass;
|
2009-05-11 21:19:53 +00:00
|
|
|
typedef struct _GstTaskPrivate GstTaskPrivate;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2005-10-20 19:30:57 +00:00
|
|
|
/**
|
|
|
|
* GstTaskState:
|
|
|
|
* @GST_TASK_STARTED: the task is started and running
|
2008-05-26 10:07:09 +00:00
|
|
|
* @GST_TASK_STOPPED: the task is stopped
|
2005-10-20 19:30:57 +00:00
|
|
|
* @GST_TASK_PAUSED: the task is paused
|
|
|
|
*
|
|
|
|
* The different states a task can be in
|
|
|
|
*/
|
2005-03-21 17:34:02 +00:00
|
|
|
typedef enum {
|
|
|
|
GST_TASK_STARTED,
|
|
|
|
GST_TASK_STOPPED,
|
2006-07-06 09:21:03 +00:00
|
|
|
GST_TASK_PAUSED
|
2005-03-21 17:34:02 +00:00
|
|
|
} GstTaskState;
|
|
|
|
|
2005-10-20 19:30:57 +00:00
|
|
|
/**
|
|
|
|
* GST_TASK_STATE:
|
|
|
|
* @task: Task to get the state of
|
|
|
|
*
|
|
|
|
* Get access to the state of the task.
|
|
|
|
*/
|
2005-03-21 17:34:02 +00:00
|
|
|
#define GST_TASK_STATE(task) (GST_TASK_CAST(task)->state)
|
|
|
|
|
2005-10-21 11:36:32 +00:00
|
|
|
/**
|
|
|
|
* GST_TASK_GET_COND:
|
|
|
|
* @task: Task to get the cond of
|
|
|
|
*
|
|
|
|
* Get access to the cond of the task.
|
|
|
|
*/
|
2005-03-21 17:34:02 +00:00
|
|
|
#define GST_TASK_GET_COND(task) (GST_TASK_CAST(task)->cond)
|
2005-10-21 11:36:32 +00:00
|
|
|
/**
|
|
|
|
* GST_TASK_WAIT:
|
|
|
|
* @task: Task to wait for
|
|
|
|
*
|
|
|
|
* Wait for the task cond to be signalled
|
|
|
|
*/
|
2005-11-21 16:34:26 +00:00
|
|
|
#define GST_TASK_WAIT(task) g_cond_wait(GST_TASK_GET_COND (task), GST_OBJECT_GET_LOCK (task))
|
2005-10-21 11:36:32 +00:00
|
|
|
/**
|
|
|
|
* GST_TASK_SIGNAL:
|
|
|
|
* @task: Task to signal
|
|
|
|
*
|
|
|
|
* Signal the task cond
|
|
|
|
*/
|
2005-03-21 17:34:02 +00:00
|
|
|
#define GST_TASK_SIGNAL(task) g_cond_signal(GST_TASK_GET_COND (task))
|
2005-10-21 11:36:32 +00:00
|
|
|
/**
|
|
|
|
* GST_TASK_BROADCAST:
|
|
|
|
* @task: Task to broadcast
|
|
|
|
*
|
|
|
|
* Send a broadcast signal to all waiting task conds
|
|
|
|
*/
|
2005-03-21 17:34:02 +00:00
|
|
|
#define GST_TASK_BROADCAST(task) g_cond_breadcast(GST_TASK_GET_COND (task))
|
|
|
|
|
2005-10-21 11:36:32 +00:00
|
|
|
/**
|
|
|
|
* GST_TASK_GET_LOCK:
|
|
|
|
* @task: Task to get the lock of
|
|
|
|
*
|
|
|
|
* Get access to the task lock.
|
|
|
|
*/
|
gst/: Implement gst_pad_pause/start/stop_task(), take STREAM lock in task function.
Original commit message from CVS:
* gst/base/gstadapter.c: (gst_adapter_peek), (gst_adapter_flush):
* gst/base/gstbasesink.c: (gst_basesink_preroll_queue_push),
(gst_basesink_finish_preroll), (gst_basesink_chain),
(gst_basesink_loop), (gst_basesink_activate),
(gst_basesink_change_state):
* gst/base/gstbasesrc.c: (gst_basesrc_do_seek),
(gst_basesrc_get_range), (gst_basesrc_loop),
(gst_basesrc_activate):
* gst/elements/gsttee.c: (gst_tee_sink_activate):
* gst/gstpad.c: (gst_pad_dispose), (gst_real_pad_class_init),
(gst_real_pad_init), (gst_real_pad_set_property),
(gst_real_pad_get_property), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_get_query_types), (gst_pad_unlink),
(gst_pad_link_prepare), (gst_pad_link), (gst_pad_get_real_parent),
(gst_real_pad_get_caps_unlocked), (gst_pad_peer_get_caps),
(gst_pad_accept_caps), (gst_pad_get_peer), (gst_pad_realize),
(gst_pad_event_default_dispatch), (gst_pad_event_default),
(gst_pad_dispatcher), (gst_pad_query), (gst_real_pad_dispose),
(gst_pad_save_thyself), (handle_pad_block), (gst_pad_chain),
(gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range),
(gst_pad_send_event), (gst_pad_start_task), (gst_pad_pause_task),
(gst_pad_stop_task):
* gst/gstpad.h:
* gst/gstqueue.c: (gst_queue_handle_sink_event), (gst_queue_chain),
(gst_queue_loop), (gst_queue_src_activate):
* gst/gsttask.c: (gst_task_init), (gst_task_set_lock),
(gst_task_get_state):
* gst/gsttask.h:
* gst/schedulers/threadscheduler.c:
(gst_thread_scheduler_task_start), (gst_thread_scheduler_func):
Implement gst_pad_pause/start/stop_task(), take STREAM lock
in task function.
Remove ACTIVE pad flag, use FLUSHING everywhere
Added _pad_chain(), _pad_get_range() to call chain/getrange
functions.
Add locks around IS_FLUSHING when reading.
Take STREAM lock in chain(), get_range() functions so plugins
don't need to take it anymore.
2005-05-25 11:50:11 +00:00
|
|
|
#define GST_TASK_GET_LOCK(task) (GST_TASK_CAST(task)->lock)
|
|
|
|
|
2009-05-11 21:19:53 +00:00
|
|
|
/**
|
2009-05-11 21:44:42 +00:00
|
|
|
* GstTaskThreadCallbacks:
|
|
|
|
* @enter_thread: a thread is entered, this callback is called when the new
|
|
|
|
* thread enters its function.
|
|
|
|
* @leave_thread: a thread is exiting, this is called when the thread is about
|
|
|
|
* to leave its function
|
2009-05-11 21:19:53 +00:00
|
|
|
*
|
2009-05-11 22:05:12 +00:00
|
|
|
* Custom GstTask thread callback functions that can be installed.
|
2009-05-11 21:19:53 +00:00
|
|
|
*
|
|
|
|
* Since: 0.10.24
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/* manage the lifetime of the thread */
|
|
|
|
void (*enter_thread) (GstTask *task, GThread *thread, gpointer user_data);
|
|
|
|
void (*leave_thread) (GstTask *task, GThread *thread, gpointer user_data);
|
|
|
|
/*< private >*/
|
|
|
|
gpointer _gst_reserved[GST_PADDING];
|
|
|
|
} GstTaskThreadCallbacks;
|
|
|
|
|
2005-10-20 19:30:57 +00:00
|
|
|
/**
|
|
|
|
* GstTask:
|
|
|
|
* @state: the state of the task
|
|
|
|
* @cond: used to pause/resume the task
|
2008-05-26 10:07:09 +00:00
|
|
|
* @lock: The lock taken when iterating the task function
|
2005-10-20 19:30:57 +00:00
|
|
|
* @func: the function executed by this task
|
|
|
|
* @data: data passed to the task function
|
2008-05-26 10:07:09 +00:00
|
|
|
* @running: a flag indicating that the task is running
|
2005-10-20 19:30:57 +00:00
|
|
|
*
|
2005-11-09 16:32:49 +00:00
|
|
|
* The #GstTask object.
|
2005-10-20 19:30:57 +00:00
|
|
|
*/
|
2005-03-21 17:34:02 +00:00
|
|
|
struct _GstTask {
|
|
|
|
GstObject object;
|
|
|
|
|
gst/: Implement gst_pad_pause/start/stop_task(), take STREAM lock in task function.
Original commit message from CVS:
* gst/base/gstadapter.c: (gst_adapter_peek), (gst_adapter_flush):
* gst/base/gstbasesink.c: (gst_basesink_preroll_queue_push),
(gst_basesink_finish_preroll), (gst_basesink_chain),
(gst_basesink_loop), (gst_basesink_activate),
(gst_basesink_change_state):
* gst/base/gstbasesrc.c: (gst_basesrc_do_seek),
(gst_basesrc_get_range), (gst_basesrc_loop),
(gst_basesrc_activate):
* gst/elements/gsttee.c: (gst_tee_sink_activate):
* gst/gstpad.c: (gst_pad_dispose), (gst_real_pad_class_init),
(gst_real_pad_init), (gst_real_pad_set_property),
(gst_real_pad_get_property), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_get_query_types), (gst_pad_unlink),
(gst_pad_link_prepare), (gst_pad_link), (gst_pad_get_real_parent),
(gst_real_pad_get_caps_unlocked), (gst_pad_peer_get_caps),
(gst_pad_accept_caps), (gst_pad_get_peer), (gst_pad_realize),
(gst_pad_event_default_dispatch), (gst_pad_event_default),
(gst_pad_dispatcher), (gst_pad_query), (gst_real_pad_dispose),
(gst_pad_save_thyself), (handle_pad_block), (gst_pad_chain),
(gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range),
(gst_pad_send_event), (gst_pad_start_task), (gst_pad_pause_task),
(gst_pad_stop_task):
* gst/gstpad.h:
* gst/gstqueue.c: (gst_queue_handle_sink_event), (gst_queue_chain),
(gst_queue_loop), (gst_queue_src_activate):
* gst/gsttask.c: (gst_task_init), (gst_task_set_lock),
(gst_task_get_state):
* gst/gsttask.h:
* gst/schedulers/threadscheduler.c:
(gst_thread_scheduler_task_start), (gst_thread_scheduler_func):
Implement gst_pad_pause/start/stop_task(), take STREAM lock
in task function.
Remove ACTIVE pad flag, use FLUSHING everywhere
Added _pad_chain(), _pad_get_range() to call chain/getrange
functions.
Add locks around IS_FLUSHING when reading.
Take STREAM lock in chain(), get_range() functions so plugins
don't need to take it anymore.
2005-05-25 11:50:11 +00:00
|
|
|
/*< public >*/ /* with LOCK */
|
|
|
|
GstTaskState state;
|
|
|
|
GCond *cond;
|
|
|
|
|
|
|
|
GStaticRecMutex *lock;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
GstTaskFunction func;
|
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
gboolean running;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
/*< private >*/
|
2006-02-13 17:03:23 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
/* thread this task is currently running in */
|
|
|
|
GThread *thread;
|
|
|
|
} ABI;
|
2009-05-11 21:19:53 +00:00
|
|
|
gpointer _gst_reserved[GST_PADDING - 1];
|
2006-02-13 17:03:23 +00:00
|
|
|
} abidata;
|
|
|
|
|
2009-05-11 21:19:53 +00:00
|
|
|
GstTaskPrivate *priv;
|
2005-03-21 17:34:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstTaskClass {
|
|
|
|
GstObjectClass parent_class;
|
|
|
|
|
2005-07-18 12:49:53 +00:00
|
|
|
/*< private >*/
|
2009-05-11 22:25:11 +00:00
|
|
|
GstTaskPool *pool;
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
/*< private >*/
|
|
|
|
gpointer _gst_reserved[GST_PADDING];
|
|
|
|
};
|
|
|
|
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
void gst_task_cleanup_all (void);
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
GType gst_task_get_type (void);
|
|
|
|
|
|
|
|
GstTask* gst_task_create (GstTaskFunction func, gpointer data);
|
gst/: Implement gst_pad_pause/start/stop_task(), take STREAM lock in task function.
Original commit message from CVS:
* gst/base/gstadapter.c: (gst_adapter_peek), (gst_adapter_flush):
* gst/base/gstbasesink.c: (gst_basesink_preroll_queue_push),
(gst_basesink_finish_preroll), (gst_basesink_chain),
(gst_basesink_loop), (gst_basesink_activate),
(gst_basesink_change_state):
* gst/base/gstbasesrc.c: (gst_basesrc_do_seek),
(gst_basesrc_get_range), (gst_basesrc_loop),
(gst_basesrc_activate):
* gst/elements/gsttee.c: (gst_tee_sink_activate):
* gst/gstpad.c: (gst_pad_dispose), (gst_real_pad_class_init),
(gst_real_pad_init), (gst_real_pad_set_property),
(gst_real_pad_get_property), (gst_pad_set_active),
(gst_pad_is_active), (gst_pad_get_query_types), (gst_pad_unlink),
(gst_pad_link_prepare), (gst_pad_link), (gst_pad_get_real_parent),
(gst_real_pad_get_caps_unlocked), (gst_pad_peer_get_caps),
(gst_pad_accept_caps), (gst_pad_get_peer), (gst_pad_realize),
(gst_pad_event_default_dispatch), (gst_pad_event_default),
(gst_pad_dispatcher), (gst_pad_query), (gst_real_pad_dispose),
(gst_pad_save_thyself), (handle_pad_block), (gst_pad_chain),
(gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range),
(gst_pad_send_event), (gst_pad_start_task), (gst_pad_pause_task),
(gst_pad_stop_task):
* gst/gstpad.h:
* gst/gstqueue.c: (gst_queue_handle_sink_event), (gst_queue_chain),
(gst_queue_loop), (gst_queue_src_activate):
* gst/gsttask.c: (gst_task_init), (gst_task_set_lock),
(gst_task_get_state):
* gst/gsttask.h:
* gst/schedulers/threadscheduler.c:
(gst_thread_scheduler_task_start), (gst_thread_scheduler_func):
Implement gst_pad_pause/start/stop_task(), take STREAM lock
in task function.
Remove ACTIVE pad flag, use FLUSHING everywhere
Added _pad_chain(), _pad_get_range() to call chain/getrange
functions.
Add locks around IS_FLUSHING when reading.
Take STREAM lock in chain(), get_range() functions so plugins
don't need to take it anymore.
2005-05-25 11:50:11 +00:00
|
|
|
void gst_task_set_lock (GstTask *task, GStaticRecMutex *mutex);
|
2009-04-21 17:15:48 +00:00
|
|
|
void gst_task_set_priority (GstTask *task, GThreadPriority priority);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
2009-04-23 15:19:11 +00:00
|
|
|
GstTaskPool * gst_task_get_pool (GstTask *task);
|
|
|
|
void gst_task_set_pool (GstTask *task, GstTaskPool *pool);
|
|
|
|
|
2009-05-11 21:19:53 +00:00
|
|
|
void gst_task_set_thread_callbacks (GstTask *task,
|
|
|
|
GstTaskThreadCallbacks *callbacks,
|
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify notify);
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
GstTaskState gst_task_get_state (GstTask *task);
|
2009-05-11 20:59:35 +00:00
|
|
|
gboolean gst_task_set_state (GstTask *task, GstTaskState state);
|
2005-03-21 17:34:02 +00:00
|
|
|
|
|
|
|
gboolean gst_task_start (GstTask *task);
|
|
|
|
gboolean gst_task_stop (GstTask *task);
|
|
|
|
gboolean gst_task_pause (GstTask *task);
|
|
|
|
|
check/generic/states.c: Make sure all tasks are stopped.
Original commit message from CVS:
* check/generic/states.c: (GST_START_TEST):
Make sure all tasks are stopped.
* check/gst/gstbin.c: (GST_START_TEST):
Unref after usage for proper valgrinding.
* gst/gstpad.c: (gst_pad_finalize), (gst_pad_stop_task):
Really wait for the task to stop before destroying the
mutex.
* gst/gstqueue.c: (gst_queue_sink_activate_push),
(gst_queue_src_activate_push):
Small cleanups. Don't stop the task when we did not start
it.
* gst/gsttask.c: (gst_task_get_type), (gst_task_init),
(gst_task_func), (gst_task_cleanup_all), (gst_task_set_lock),
(gst_task_get_state), (gst_task_start), (gst_task_pause),
(gst_task_join):
* gst/gsttask.h:
Protect the stream lock with the object lock.
Disallow setting the stream lock when running.
Add cleanup_all to wait for the threadpool to finish.
Remove code to autoallocate a mutex if none was provided.
Add _join() to wait for a task to stop.
Protect the thread pool with a global lock.
2005-08-24 20:49:53 +00:00
|
|
|
gboolean gst_task_join (GstTask *task);
|
|
|
|
|
2005-03-21 17:34:02 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_TASK_H__ */
|