Initial release including wifi display based on gst-rtsp-server-1.4.1
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-thread-pool.h
1 /* GStreamer
2  * Copyright (C) 2010 Wim Taymans <wim.taymans at gmail.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <gst/gst.h>
21
22 #ifndef __GST_RTSP_THREAD_POOL_H__
23 #define __GST_RTSP_THREAD_POOL_H__
24
25 typedef struct _GstRTSPThread GstRTSPThread;
26 typedef struct _GstRTSPThreadPool GstRTSPThreadPool;
27 typedef struct _GstRTSPThreadPoolClass GstRTSPThreadPoolClass;
28 typedef struct _GstRTSPThreadPoolPrivate GstRTSPThreadPoolPrivate;
29
30 #include "rtsp-client.h"
31
32 G_BEGIN_DECLS
33
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))
42
43 GType gst_rtsp_thread_get_type (void);
44
45 #define GST_TYPE_RTSP_THREAD        (gst_rtsp_thread_get_type ())
46 #define GST_IS_RTSP_THREAD(obj)     (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_RTSP_THREAD))
47 #define GST_RTSP_THREAD_CAST(obj)   ((GstRTSPThread*)(obj))
48 #define GST_RTSP_THREAD(obj)        (GST_RTSP_THREAD_CAST(obj))
49
50 /**
51  * GstRTSPThreadType:
52  * @GST_RTSP_THREAD_TYPE_CLIENT: a thread to handle the client communication
53  * @GST_RTSP_THREAD_TYPE_MEDIA: a thread to handle media 
54  *
55  * Different thread types
56  */
57 typedef enum
58 {
59   GST_RTSP_THREAD_TYPE_CLIENT,
60   GST_RTSP_THREAD_TYPE_MEDIA
61 } GstRTSPThreadType;
62
63 /**
64  * GstRTSPThread:
65  * @mini_object: parent #GstMiniObject
66  * @type: the thread type
67  * @context: a #GMainContext
68  * @loop: a #GMainLoop
69  *
70  * Structure holding info about a mainloop running in a thread
71  */
72 struct _GstRTSPThread {
73   GstMiniObject mini_object;
74
75   GstRTSPThreadType type;
76   GMainContext *context;
77   GMainLoop *loop;
78 };
79
80 GstRTSPThread *   gst_rtsp_thread_new      (GstRTSPThreadType type);
81
82 gboolean          gst_rtsp_thread_reuse    (GstRTSPThread * thread);
83 void              gst_rtsp_thread_stop     (GstRTSPThread * thread);
84
85 /**
86  * gst_rtsp_thread_ref:
87  * @thread: The thread to refcount
88  *
89  * Increase the refcount of this thread.
90  *
91  * Returns: (transfer full): @thread (for convenience when doing assignments)
92  */
93 #ifdef _FOOL_GTK_DOC_
94 G_INLINE_FUNC GstRTSPThread * gst_rtsp_thread_ref (GstRTSPThread * thread);
95 #endif
96
97 static inline GstRTSPThread *
98 gst_rtsp_thread_ref (GstRTSPThread * thread)
99 {
100   return (GstRTSPThread *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (thread));
101 }
102
103 /**
104  * gst_rtsp_thread_unref:
105  * @thread: (transfer full): the thread to refcount
106  *
107  * Decrease the refcount of an thread, freeing it if the refcount reaches 0.
108  */
109 #ifdef _FOOL_GTK_DOC_
110 G_INLINE_FUNC void gst_rtsp_thread_unref (GstRTSPPermissions * thread);
111 #endif
112
113
114 static inline void
115 gst_rtsp_thread_unref (GstRTSPThread * thread)
116 {
117   gst_mini_object_unref (GST_MINI_OBJECT_CAST (thread));
118 }
119
120 /**
121  * GstRTSPThreadPool:
122  *
123  * The thread pool structure.
124  */
125 struct _GstRTSPThreadPool {
126   GObject       parent;
127
128   /*< private >*/
129   GstRTSPThreadPoolPrivate *priv;
130   gpointer _gst_reserved[GST_PADDING];
131 };
132
133 /**
134  * GstRTSPThreadPoolClass:
135  * @pool: a #GThreadPool used internally
136  * @get_thread: this function should make or reuse an existing thread that runs
137  *        a mainloop.
138  * @configure_thread: configure a thread object. this vmethod is called when
139  *       a new thread has been created and should be configured.
140  * @thread_enter: called from the thread when it is entered
141  * @thread_leave: called from the thread when it is left
142  *
143  * Class for managing threads.
144  */
145 struct _GstRTSPThreadPoolClass {
146   GObjectClass  parent_class;
147
148   GThreadPool *pool;
149
150   GstRTSPThread * (*get_thread)        (GstRTSPThreadPool *pool,
151                                         GstRTSPThreadType type,
152                                         GstRTSPContext *ctx);
153   void            (*configure_thread)  (GstRTSPThreadPool *pool,
154                                         GstRTSPThread * thread,
155                                         GstRTSPContext *ctx);
156
157   void            (*thread_enter)      (GstRTSPThreadPool *pool,
158                                         GstRTSPThread *thread);
159   void            (*thread_leave)      (GstRTSPThreadPool *pool,
160                                         GstRTSPThread *thread);
161
162   /*< private >*/
163   gpointer         _gst_reserved[GST_PADDING];
164 };
165
166 GType               gst_rtsp_thread_pool_get_type        (void);
167
168 GstRTSPThreadPool * gst_rtsp_thread_pool_new             (void);
169
170 void                gst_rtsp_thread_pool_set_max_threads (GstRTSPThreadPool * pool, gint max_threads);
171 gint                gst_rtsp_thread_pool_get_max_threads (GstRTSPThreadPool * pool);
172
173 GstRTSPThread *     gst_rtsp_thread_pool_get_thread      (GstRTSPThreadPool *pool,
174                                                           GstRTSPThreadType type,
175                                                           GstRTSPContext *ctx);
176 void                gst_rtsp_thread_pool_cleanup         (void);
177 G_END_DECLS
178
179 #endif /* __GST_RTSP_THREAD_POOL_H__ */