docs: update docs
[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 void              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 };
131
132 /**
133  * GstRTSPThreadPoolClass:
134  * @pool: a #GThreadPool used internally
135  * @get_thread: get or reuse a thread object
136  * @configure_thread: configure a thread object
137  * @thread_enter: called from the thread when it is entered
138  * @thread_leave: called from the thread when it is left
139  *
140  * Class for managing threads.
141  */
142 struct _GstRTSPThreadPoolClass {
143   GObjectClass  parent_class;
144
145   GThreadPool *pool;
146
147   GstRTSPThread * (*get_thread)        (GstRTSPThreadPool *pool,
148                                         GstRTSPThreadType type,
149                                         GstRTSPClientState *state);
150   void            (*configure_thread)  (GstRTSPThreadPool *pool,
151                                         GstRTSPThread * thread,
152                                         GstRTSPClientState *state);
153
154   void            (*thread_enter)      (GstRTSPThreadPool *pool,
155                                         GstRTSPThread *thread);
156   void            (*thread_leave)      (GstRTSPThreadPool *pool,
157                                         GstRTSPThread *thread);
158 };
159
160 GType               gst_rtsp_thread_pool_get_type        (void);
161
162 GstRTSPThreadPool * gst_rtsp_thread_pool_new             (void);
163
164 void                gst_rtsp_thread_pool_set_max_threads (GstRTSPThreadPool * pool, gint max_threads);
165 gint                gst_rtsp_thread_pool_get_max_threads (GstRTSPThreadPool * pool);
166
167 GstRTSPThread *     gst_rtsp_thread_pool_get_thread      (GstRTSPThreadPool *pool,
168                                                           GstRTSPThreadType type,
169                                                           GstRTSPClientState *state);
170 G_END_DECLS
171
172 #endif /* __GST_RTSP_THREAD_POOL_H__ */