gsttask.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #ifndef __GST_TASK_H__
  23. #define __GST_TASK_H__
  24. #include <gst/gstobject.h>
  25. #include <gst/gsttaskpool.h>
  26. G_BEGIN_DECLS
  27. /**
  28. * GstTaskFunction:
  29. * @user_data: user data passed to the function
  30. *
  31. * A function that will repeatedly be called in the thread created by
  32. * a #GstTask.
  33. */
  34. typedef void (*GstTaskFunction) (gpointer user_data);
  35. /* --- standard type macros --- */
  36. #define GST_TYPE_TASK (gst_task_get_type ())
  37. #define GST_TASK(task) (G_TYPE_CHECK_INSTANCE_CAST ((task), GST_TYPE_TASK, GstTask))
  38. #define GST_IS_TASK(task) (G_TYPE_CHECK_INSTANCE_TYPE ((task), GST_TYPE_TASK))
  39. #define GST_TASK_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), GST_TYPE_TASK, GstTaskClass))
  40. #define GST_IS_TASK_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), GST_TYPE_TASK))
  41. #define GST_TASK_GET_CLASS(task) (G_TYPE_INSTANCE_GET_CLASS ((task), GST_TYPE_TASK, GstTaskClass))
  42. #define GST_TASK_CAST(task) ((GstTask*)(task))
  43. typedef struct _GstTask GstTask;
  44. typedef struct _GstTaskClass GstTaskClass;
  45. typedef struct _GstTaskPrivate GstTaskPrivate;
  46. /**
  47. * GstTaskState:
  48. * @GST_TASK_STARTED: the task is started and running
  49. * @GST_TASK_STOPPED: the task is stopped
  50. * @GST_TASK_PAUSED: the task is paused
  51. *
  52. * The different states a task can be in
  53. */
  54. typedef enum {
  55. GST_TASK_STARTED,
  56. GST_TASK_STOPPED,
  57. GST_TASK_PAUSED
  58. } GstTaskState;
  59. /**
  60. * GST_TASK_STATE:
  61. * @task: Task to get the state of
  62. *
  63. * Get access to the state of the task.
  64. */
  65. #define GST_TASK_STATE(task) (GST_TASK_CAST(task)->state)
  66. /**
  67. * GST_TASK_GET_COND:
  68. * @task: Task to get the cond of
  69. *
  70. * Get access to the cond of the task.
  71. */
  72. #define GST_TASK_GET_COND(task) (&GST_TASK_CAST(task)->cond)
  73. /**
  74. * GST_TASK_WAIT:
  75. * @task: Task to wait for
  76. *
  77. * Wait for the task cond to be signalled
  78. */
  79. #define GST_TASK_WAIT(task) g_cond_wait(GST_TASK_GET_COND (task), GST_OBJECT_GET_LOCK (task))
  80. /**
  81. * GST_TASK_SIGNAL:
  82. * @task: Task to signal
  83. *
  84. * Signal the task cond
  85. */
  86. #define GST_TASK_SIGNAL(task) g_cond_signal(GST_TASK_GET_COND (task))
  87. /**
  88. * GST_TASK_BROADCAST:
  89. * @task: Task to broadcast
  90. *
  91. * Send a broadcast signal to all waiting task conds
  92. */
  93. #define GST_TASK_BROADCAST(task) g_cond_broadcast(GST_TASK_GET_COND (task))
  94. /**
  95. * GST_TASK_GET_LOCK:
  96. * @task: Task to get the lock of
  97. *
  98. * Get access to the task lock.
  99. */
  100. #define GST_TASK_GET_LOCK(task) (GST_TASK_CAST(task)->lock)
  101. /**
  102. * GstTaskThreadFunc:
  103. * @task: The #GstTask
  104. * @thread: The #GThread
  105. * @user_data: user data
  106. *
  107. * Custom GstTask thread callback functions that can be installed.
  108. */
  109. typedef void (*GstTaskThreadFunc) (GstTask *task, GThread *thread, gpointer user_data);
  110. /**
  111. * GstTask:
  112. * @state: the state of the task
  113. * @cond: used to pause/resume the task
  114. * @lock: The lock taken when iterating the task function
  115. * @func: the function executed by this task
  116. * @user_data: user_data passed to the task function
  117. * @notify: GDestroyNotify for @user_data
  118. * @running: a flag indicating that the task is running
  119. *
  120. * The #GstTask object.
  121. */
  122. struct _GstTask {
  123. GstObject object;
  124. /*< public >*/ /* with LOCK */
  125. GstTaskState state;
  126. GCond cond;
  127. GRecMutex *lock;
  128. GstTaskFunction func;
  129. gpointer user_data;
  130. GDestroyNotify notify;
  131. gboolean running;
  132. /*< private >*/
  133. GThread *thread;
  134. GstTaskPrivate *priv;
  135. gpointer _gst_reserved[GST_PADDING];
  136. };
  137. struct _GstTaskClass {
  138. GstObjectClass parent_class;
  139. /*< private >*/
  140. GstTaskPool *pool;
  141. /*< private >*/
  142. gpointer _gst_reserved[GST_PADDING];
  143. };
  144. void gst_task_cleanup_all (void);
  145. GType gst_task_get_type (void);
  146. GstTask* gst_task_new (GstTaskFunction func,
  147. gpointer user_data, GDestroyNotify notify);
  148. void gst_task_set_lock (GstTask *task, GRecMutex *mutex);
  149. GstTaskPool * gst_task_get_pool (GstTask *task);
  150. void gst_task_set_pool (GstTask *task, GstTaskPool *pool);
  151. void gst_task_set_enter_callback (GstTask *task,
  152. GstTaskThreadFunc enter_func,
  153. gpointer user_data,
  154. GDestroyNotify notify);
  155. void gst_task_set_leave_callback (GstTask *task,
  156. GstTaskThreadFunc leave_func,
  157. gpointer user_data,
  158. GDestroyNotify notify);
  159. GstTaskState gst_task_get_state (GstTask *task);
  160. gboolean gst_task_set_state (GstTask *task, GstTaskState state);
  161. gboolean gst_task_start (GstTask *task);
  162. gboolean gst_task_stop (GstTask *task);
  163. gboolean gst_task_pause (GstTask *task);
  164. gboolean gst_task_join (GstTask *task);
  165. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  166. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstTask, gst_object_unref)
  167. #endif
  168. G_END_DECLS
  169. #endif /* __GST_TASK_H__ */