1/* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * <2005> Wim Taymans <wim@fluendo.com>
4 *
5 * gsttask.h: Streaming tasks
6 *
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.
11 *
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.
16 *
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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifndef __GST_TASK_H__
24#define __GST_TASK_H__
25
26#include <gst/gstobject.h>
27#include <gst/gsttaskpool.h>
28
29G_BEGIN_DECLS
30
31/**
32 * GstTaskFunction:
33 * @user_data: user data passed to the function
34 *
35 * A function that will repeatedly be called in the thread created by
36 * a #GstTask.
37 */
38typedef void (*GstTaskFunction) (gpointer user_data);
39
40/* --- standard type macros --- */
41#define GST_TYPE_TASK (gst_task_get_type ())
42#define GST_TASK(task) (G_TYPE_CHECK_INSTANCE_CAST ((task), GST_TYPE_TASK, GstTask))
43#define GST_IS_TASK(task) (G_TYPE_CHECK_INSTANCE_TYPE ((task), GST_TYPE_TASK))
44#define GST_TASK_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), GST_TYPE_TASK, GstTaskClass))
45#define GST_IS_TASK_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), GST_TYPE_TASK))
46#define GST_TASK_GET_CLASS(task) (G_TYPE_INSTANCE_GET_CLASS ((task), GST_TYPE_TASK, GstTaskClass))
47#define GST_TASK_CAST(task) ((GstTask*)(task))
48
49typedef struct _GstTask GstTask;
50typedef struct _GstTaskClass GstTaskClass;
51typedef struct _GstTaskPrivate GstTaskPrivate;
52
53/**
54 * GstTaskState:
55 * @GST_TASK_STARTED: the task is started and running
56 * @GST_TASK_STOPPED: the task is stopped
57 * @GST_TASK_PAUSED: the task is paused
58 *
59 * The different states a task can be in
60 */
61typedef enum {
62 GST_TASK_STARTED,
63 GST_TASK_STOPPED,
64 GST_TASK_PAUSED
65} GstTaskState;
66
67/**
68 * GST_TASK_STATE:
69 * @task: Task to get the state of
70 *
71 * Get access to the state of the task.
72 */
73#define GST_TASK_STATE(task) (GST_TASK_CAST(task)->state)
74
75/**
76 * GST_TASK_GET_COND:
77 * @task: Task to get the cond of
78 *
79 * Get access to the cond of the task.
80 */
81#define GST_TASK_GET_COND(task) (&GST_TASK_CAST(task)->cond)
82/**
83 * GST_TASK_WAIT:
84 * @task: Task to wait for
85 *
86 * Wait for the task cond to be signalled
87 */
88#define GST_TASK_WAIT(task) g_cond_wait(GST_TASK_GET_COND (task), GST_OBJECT_GET_LOCK (task))
89/**
90 * GST_TASK_SIGNAL:
91 * @task: Task to signal
92 *
93 * Signal the task cond
94 */
95#define GST_TASK_SIGNAL(task) g_cond_signal(GST_TASK_GET_COND (task))
96/**
97 * GST_TASK_BROADCAST:
98 * @task: Task to broadcast
99 *
100 * Send a broadcast signal to all waiting task conds
101 */
102#define GST_TASK_BROADCAST(task) g_cond_broadcast(GST_TASK_GET_COND (task))
103
104/**
105 * GST_TASK_GET_LOCK:
106 * @task: Task to get the lock of
107 *
108 * Get access to the task lock.
109 */
110#define GST_TASK_GET_LOCK(task) (GST_TASK_CAST(task)->lock)
111
112/**
113 * GstTaskThreadFunc:
114 * @task: The #GstTask
115 * @thread: The #GThread
116 * @user_data: user data
117 *
118 * Custom GstTask thread callback functions that can be installed.
119 */
120typedef void (*GstTaskThreadFunc) (GstTask *task, GThread *thread, gpointer user_data);
121
122/**
123 * GstTask:
124 * @state: the state of the task
125 * @cond: used to pause/resume the task
126 * @lock: The lock taken when iterating the task function
127 * @func: the function executed by this task
128 * @user_data: user_data passed to the task function
129 * @notify: GDestroyNotify for @user_data
130 * @running: a flag indicating that the task is running
131 *
132 * The #GstTask object.
133 */
134struct _GstTask {
135 GstObject object;
136
137 /*< public >*/ /* with LOCK */
138 GstTaskState state;
139 GCond cond;
140
141 GRecMutex *lock;
142
143 GstTaskFunction func;
144 gpointer user_data;
145 GDestroyNotify notify;
146
147 gboolean running;
148
149 /*< private >*/
150 GThread *thread;
151
152 GstTaskPrivate *priv;
153
154 gpointer _gst_reserved[GST_PADDING];
155};
156
157struct _GstTaskClass {
158 GstObjectClass parent_class;
159
160 /*< private >*/
161 GstTaskPool *pool;
162
163 /*< private >*/
164 gpointer _gst_reserved[GST_PADDING];
165};
166
167GST_API
168void gst_task_cleanup_all (void);
169
170GST_API
171GType gst_task_get_type (void);
172
173GST_API
174GstTask* gst_task_new (GstTaskFunction func,
175 gpointer user_data, GDestroyNotify notify);
176GST_API
177void gst_task_set_lock (GstTask *task, GRecMutex *mutex);
178
179GST_API
180GstTaskPool * gst_task_get_pool (GstTask *task);
181
182GST_API
183void gst_task_set_pool (GstTask *task, GstTaskPool *pool);
184
185GST_API
186void gst_task_set_enter_callback (GstTask *task,
187 GstTaskThreadFunc enter_func,
188 gpointer user_data,
189 GDestroyNotify notify);
190GST_API
191void gst_task_set_leave_callback (GstTask *task,
192 GstTaskThreadFunc leave_func,
193 gpointer user_data,
194 GDestroyNotify notify);
195GST_API
196GstTaskState gst_task_get_state (GstTask *task);
197
198GST_API
199gboolean gst_task_set_state (GstTask *task, GstTaskState state);
200
201GST_API
202gboolean gst_task_start (GstTask *task);
203
204GST_API
205gboolean gst_task_stop (GstTask *task);
206
207GST_API
208gboolean gst_task_pause (GstTask *task);
209
210GST_API
211gboolean gst_task_resume (GstTask *task);
212
213GST_API
214gboolean gst_task_join (GstTask *task);
215
216G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstTask, gst_object_unref)
217
218G_END_DECLS
219
220#endif /* __GST_TASK_H__ */
221

source code of include/gstreamer-1.0/gst/gsttask.h