| 1 | /* GStreamer | 
| 2 |  * Copyright (C) <2009> Wim Taymans <wim.taymans@gmail.com> | 
| 3 |  * | 
| 4 |  * gsttaskpool.h: Pool for creating streaming threads | 
| 5 |  * | 
| 6 |  * This library is free software; you can redistribute it and/or | 
| 7 |  * modify it under the terms of the GNU Library General Public | 
| 8 |  * License as published by the Free Software Foundation; either | 
| 9 |  * version 2 of the License, or (at your option) any later version. | 
| 10 |  * | 
| 11 |  * This library is distributed in the hope that it will be useful, | 
| 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
| 14 |  * Library General Public License for more details. | 
| 15 |  * | 
| 16 |  * You should have received a copy of the GNU Library General Public | 
| 17 |  * License along with this library; if not, write to the | 
| 18 |  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | 
| 19 |  * Boston, MA 02110-1301, USA. | 
| 20 |  */ | 
| 21 |  | 
| 22 | #ifndef __GST_TASK_POOL_H__ | 
| 23 | #define __GST_TASK_POOL_H__ | 
| 24 |  | 
| 25 | #include <gst/gstobject.h> | 
| 26 |  | 
| 27 | G_BEGIN_DECLS | 
| 28 |  | 
| 29 | /* --- standard type macros --- */ | 
| 30 | #define GST_TYPE_TASK_POOL             (gst_task_pool_get_type ()) | 
| 31 | #define GST_TASK_POOL(pool)            (G_TYPE_CHECK_INSTANCE_CAST ((pool), GST_TYPE_TASK_POOL, GstTaskPool)) | 
| 32 | #define GST_IS_TASK_POOL(pool)         (G_TYPE_CHECK_INSTANCE_TYPE ((pool), GST_TYPE_TASK_POOL)) | 
| 33 | #define GST_TASK_POOL_CLASS(pclass)    (G_TYPE_CHECK_CLASS_CAST ((pclass), GST_TYPE_TASK_POOL, GstTaskPoolClass)) | 
| 34 | #define GST_IS_TASK_POOL_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), GST_TYPE_TASK_POOL)) | 
| 35 | #define GST_TASK_POOL_GET_CLASS(pool)  (G_TYPE_INSTANCE_GET_CLASS ((pool), GST_TYPE_TASK_POOL, GstTaskPoolClass)) | 
| 36 | #define GST_TASK_POOL_CAST(pool)       ((GstTaskPool*)(pool)) | 
| 37 |  | 
| 38 | typedef struct _GstTaskPool GstTaskPool; | 
| 39 | typedef struct _GstTaskPoolClass GstTaskPoolClass; | 
| 40 |  | 
| 41 | /** | 
| 42 |  * GstTaskPoolFunction: | 
| 43 |  * @user_data: user data for the task function | 
| 44 |  * | 
| 45 |  * Task function, see gst_task_pool_push(). | 
| 46 |  */ | 
| 47 | typedef void   (*GstTaskPoolFunction)          (void *user_data); | 
| 48 |  | 
| 49 | /** | 
| 50 |  * GstTaskPool: | 
| 51 |  * | 
| 52 |  * The #GstTaskPool object. | 
| 53 |  */ | 
| 54 | struct _GstTaskPool { | 
| 55 |   GstObject      object; | 
| 56 |  | 
| 57 |   /*< private >*/ | 
| 58 |   GThreadPool   *pool; | 
| 59 |  | 
| 60 |   gpointer _gst_reserved[GST_PADDING]; | 
| 61 | }; | 
| 62 |  | 
| 63 | /** | 
| 64 |  * GstTaskPoolClass: | 
| 65 |  * @parent_class: the parent class structure | 
| 66 |  * @prepare: prepare the threadpool | 
| 67 |  * @cleanup: make sure all threads are stopped | 
| 68 |  * @push: start a new thread | 
| 69 |  * @join: join a thread | 
| 70 |  * | 
| 71 |  * The #GstTaskPoolClass object. | 
| 72 |  */ | 
| 73 | struct _GstTaskPoolClass { | 
| 74 |   GstObjectClass parent_class; | 
| 75 |  | 
| 76 |   /*< public >*/ | 
| 77 |   void      (*prepare)  (GstTaskPool *pool, GError **error); | 
| 78 |   void      (*cleanup)  (GstTaskPool *pool); | 
| 79 |  | 
| 80 |   gpointer  (*push)     (GstTaskPool *pool, GstTaskPoolFunction func, | 
| 81 |                          gpointer user_data, GError **error); | 
| 82 |   void      (*join)     (GstTaskPool *pool, gpointer id); | 
| 83 |  | 
| 84 |   /** | 
| 85 |    * GstTaskPoolClass::dispose_handle: | 
| 86 |    * @pool: a #GstTaskPool | 
| 87 |    * @id: (transfer full): the handle to dispose of | 
| 88 |    * | 
| 89 |    * free / unref the handle returned in GstTaskPoolClass::push. | 
| 90 |    * | 
| 91 |    * Since: 1.20 | 
| 92 |    */ | 
| 93 |   void      (*dispose_handle) (GstTaskPool *pool, gpointer id); | 
| 94 |  | 
| 95 |   /*< private >*/ | 
| 96 |   gpointer _gst_reserved[GST_PADDING - 1]; | 
| 97 | }; | 
| 98 |  | 
| 99 | GST_API | 
| 100 | GType           gst_task_pool_get_type    (void); | 
| 101 |  | 
| 102 | GST_API | 
| 103 | GstTaskPool *   gst_task_pool_new         (void); | 
| 104 |  | 
| 105 | GST_API | 
| 106 | void            gst_task_pool_prepare     (GstTaskPool *pool, GError **error); | 
| 107 |  | 
| 108 | GST_API | 
| 109 | gpointer        gst_task_pool_push        (GstTaskPool *pool, GstTaskPoolFunction func, | 
| 110 |                                            gpointer user_data, GError **error); | 
| 111 | GST_API | 
| 112 | void            gst_task_pool_join        (GstTaskPool *pool, gpointer id); | 
| 113 |  | 
| 114 | GST_API | 
| 115 | void            gst_task_pool_dispose_handle (GstTaskPool *pool, gpointer id); | 
| 116 |  | 
| 117 | GST_API | 
| 118 | void		gst_task_pool_cleanup     (GstTaskPool *pool); | 
| 119 |  | 
| 120 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstTaskPool, gst_object_unref) | 
| 121 |  | 
| 122 | typedef struct _GstSharedTaskPool GstSharedTaskPool; | 
| 123 | typedef struct _GstSharedTaskPoolClass GstSharedTaskPoolClass; | 
| 124 | typedef struct _GstSharedTaskPoolPrivate GstSharedTaskPoolPrivate; | 
| 125 |  | 
| 126 | #define GST_TYPE_SHARED_TASK_POOL             (gst_shared_task_pool_get_type ()) | 
| 127 | #define GST_SHARED_TASK_POOL(pool)            (G_TYPE_CHECK_INSTANCE_CAST ((pool), GST_TYPE_TASK_POOL, GstSharedTaskPool)) | 
| 128 | #define GST_IS_SHARED_TASK_POOL(pool)         (G_TYPE_CHECK_INSTANCE_TYPE ((pool), GST_TYPE_SHARED_TASK_POOL)) | 
| 129 | #define GST_SHARED_TASK_POOL_CLASS(pclass)    (G_TYPE_CHECK_CLASS_CAST ((pclass), GST_TYPE_SHARED_TASK_POOL, GstSharedTaskPoolClass)) | 
| 130 | #define GST_IS_SHARED_TASK_POOL_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), GST_TYPE_SHARED_TASK_POOL)) | 
| 131 | #define GST_SHARED_TASK_POOL_GET_CLASS(pool)  (G_TYPE_INSTANCE_GET_CLASS ((pool), GST_TYPE_SHARED_TASK_POOL, GstSharedTaskPoolClass)) | 
| 132 |  | 
| 133 | /** | 
| 134 |  * GstSharedTaskPool: | 
| 135 |  * | 
| 136 |  * The #GstSharedTaskPool object. | 
| 137 |  * | 
| 138 |  * since: 1.20 | 
| 139 |  */ | 
| 140 | struct _GstSharedTaskPool { | 
| 141 |   GstTaskPool parent; | 
| 142 |  | 
| 143 |   /*< private >*/ | 
| 144 |   GstSharedTaskPoolPrivate *priv; | 
| 145 |  | 
| 146 |   gpointer _gst_reserved[GST_PADDING]; | 
| 147 | }; | 
| 148 |  | 
| 149 | /** | 
| 150 |  * GstSharedTaskPoolClass: | 
| 151 |  * | 
| 152 |  * The #GstSharedTaskPoolClass object. | 
| 153 |  * | 
| 154 |  * Since: 1.20 | 
| 155 |  */ | 
| 156 | struct _GstSharedTaskPoolClass { | 
| 157 |   GstTaskPoolClass parent_class; | 
| 158 |  | 
| 159 |   /*< private >*/ | 
| 160 |   gpointer _gst_reserved[GST_PADDING]; | 
| 161 | }; | 
| 162 |  | 
| 163 | GST_API | 
| 164 | GType           gst_shared_task_pool_get_type        (void); | 
| 165 |  | 
| 166 | GST_API | 
| 167 | void            gst_shared_task_pool_set_max_threads (GstSharedTaskPool *pool, guint max_threads); | 
| 168 |  | 
| 169 | GST_API | 
| 170 | guint           gst_shared_task_pool_get_max_threads (GstSharedTaskPool *pool); | 
| 171 |  | 
| 172 | GST_API | 
| 173 | GstTaskPool *   gst_shared_task_pool_new             (void); | 
| 174 |  | 
| 175 | G_END_DECLS | 
| 176 |  | 
| 177 | #endif /* __GST_TASK_POOL_H__ */ | 
| 178 |  |