2 * Copyright (C) 2010 Wim Taymans <wim.taymans at gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #ifndef __GST_RTSP_THREAD_POOL_H__
23 #define __GST_RTSP_THREAD_POOL_H__
25 typedef struct _GstRTSPThread GstRTSPThread;
26 typedef struct _GstRTSPThreadPool GstRTSPThreadPool;
27 typedef struct _GstRTSPThreadPoolClass GstRTSPThreadPoolClass;
28 typedef struct _GstRTSPThreadPoolPrivate GstRTSPThreadPoolPrivate;
30 #include "rtsp-client.h"
34 #define GST_TYPE_RTSP_THREAD_POOL (gst_rtsp_thread_pool_get_type ())
35 #define GST_IS_RTSP_THREAD_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_THREAD_POOL))
36 #define GST_IS_RTSP_THREAD_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_THREAD_POOL))
37 #define GST_RTSP_THREAD_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_THREAD_POOL, GstRTSPThreadPoolClass))
38 #define GST_RTSP_THREAD_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_THREAD_POOL, GstRTSPThreadPool))
39 #define GST_RTSP_THREAD_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_THREAD_POOL, GstRTSPThreadPoolClass))
40 #define GST_RTSP_THREAD_POOL_CAST(obj) ((GstRTSPThreadPool*)(obj))
41 #define GST_RTSP_THREAD_POOL_CLASS_CAST(klass) ((GstRTSPThreadPoolClass*)(klass))
44 GType gst_rtsp_thread_get_type (void);
46 #define GST_TYPE_RTSP_THREAD (gst_rtsp_thread_get_type ())
47 #define GST_IS_RTSP_THREAD(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_RTSP_THREAD))
48 #define GST_RTSP_THREAD_CAST(obj) ((GstRTSPThread*)(obj))
49 #define GST_RTSP_THREAD(obj) (GST_RTSP_THREAD_CAST(obj))
53 * @GST_RTSP_THREAD_TYPE_CLIENT: a thread to handle the client communication
54 * @GST_RTSP_THREAD_TYPE_MEDIA: a thread to handle media
56 * Different thread types
60 GST_RTSP_THREAD_TYPE_CLIENT,
61 GST_RTSP_THREAD_TYPE_MEDIA
66 * @mini_object: parent #GstMiniObject
67 * @type: the thread type
68 * @context: a #GMainContext
71 * Structure holding info about a mainloop running in a thread
73 struct _GstRTSPThread {
74 GstMiniObject mini_object;
76 GstRTSPThreadType type;
77 GMainContext *context;
82 GstRTSPThread * gst_rtsp_thread_new (GstRTSPThreadType type);
85 gboolean gst_rtsp_thread_reuse (GstRTSPThread * thread);
88 void gst_rtsp_thread_stop (GstRTSPThread * thread);
91 * gst_rtsp_thread_ref:
92 * @thread: The thread to refcount
94 * Increase the refcount of this thread.
96 * Returns: (transfer full): @thread (for convenience when doing assignments)
98 static inline GstRTSPThread *
99 gst_rtsp_thread_ref (GstRTSPThread * thread)
101 return (GstRTSPThread *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (thread));
105 * gst_rtsp_thread_unref:
106 * @thread: (transfer full): the thread to refcount
108 * Decrease the refcount of an thread, freeing it if the refcount reaches 0.
111 gst_rtsp_thread_unref (GstRTSPThread * thread)
113 gst_mini_object_unref (GST_MINI_OBJECT_CAST (thread));
119 * The thread pool structure.
121 struct _GstRTSPThreadPool {
125 GstRTSPThreadPoolPrivate *priv;
126 gpointer _gst_reserved[GST_PADDING];
130 * GstRTSPThreadPoolClass:
131 * @pool: a #GThreadPool used internally
132 * @get_thread: this function should make or reuse an existing thread that runs
134 * @configure_thread: configure a thread object. this vmethod is called when
135 * a new thread has been created and should be configured.
136 * @thread_enter: called from the thread when it is entered
137 * @thread_leave: called from the thread when it is left
139 * Class for managing threads.
141 struct _GstRTSPThreadPoolClass {
142 GObjectClass parent_class;
146 GstRTSPThread * (*get_thread) (GstRTSPThreadPool *pool,
147 GstRTSPThreadType type,
148 GstRTSPContext *ctx);
149 void (*configure_thread) (GstRTSPThreadPool *pool,
150 GstRTSPThread * thread,
151 GstRTSPContext *ctx);
153 void (*thread_enter) (GstRTSPThreadPool *pool,
154 GstRTSPThread *thread);
155 void (*thread_leave) (GstRTSPThreadPool *pool,
156 GstRTSPThread *thread);
159 gpointer _gst_reserved[GST_PADDING];
163 GType gst_rtsp_thread_pool_get_type (void);
166 GstRTSPThreadPool * gst_rtsp_thread_pool_new (void);
169 void gst_rtsp_thread_pool_set_max_threads (GstRTSPThreadPool * pool, gint max_threads);
172 gint gst_rtsp_thread_pool_get_max_threads (GstRTSPThreadPool * pool);
175 GstRTSPThread * gst_rtsp_thread_pool_get_thread (GstRTSPThreadPool *pool,
176 GstRTSPThreadType type,
177 GstRTSPContext *ctx);
180 void gst_rtsp_thread_pool_cleanup (void);
181 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
182 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPThread, gst_rtsp_thread_unref)
185 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
186 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPThreadPool, gst_object_unref)
191 #endif /* __GST_RTSP_THREAD_POOL_H__ */