rtsp-stream: obtain stream position from pad
[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 GST_EXPORT
44 GType gst_rtsp_thread_get_type (void);
45
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))
50
51 /**
52  * GstRTSPThreadType:
53  * @GST_RTSP_THREAD_TYPE_CLIENT: a thread to handle the client communication
54  * @GST_RTSP_THREAD_TYPE_MEDIA: a thread to handle media 
55  *
56  * Different thread types
57  */
58 typedef enum
59 {
60   GST_RTSP_THREAD_TYPE_CLIENT,
61   GST_RTSP_THREAD_TYPE_MEDIA
62 } GstRTSPThreadType;
63
64 /**
65  * GstRTSPThread:
66  * @mini_object: parent #GstMiniObject
67  * @type: the thread type
68  * @context: a #GMainContext
69  * @loop: a #GMainLoop
70  *
71  * Structure holding info about a mainloop running in a thread
72  */
73 struct _GstRTSPThread {
74   GstMiniObject mini_object;
75
76   GstRTSPThreadType type;
77   GMainContext *context;
78   GMainLoop *loop;
79 };
80
81 GST_EXPORT
82 GstRTSPThread *   gst_rtsp_thread_new      (GstRTSPThreadType type);
83
84 GST_EXPORT
85 gboolean          gst_rtsp_thread_reuse    (GstRTSPThread * thread);
86
87 GST_EXPORT
88 void              gst_rtsp_thread_stop     (GstRTSPThread * thread);
89
90 /**
91  * gst_rtsp_thread_ref:
92  * @thread: The thread to refcount
93  *
94  * Increase the refcount of this thread.
95  *
96  * Returns: (transfer full): @thread (for convenience when doing assignments)
97  */
98 static inline GstRTSPThread *
99 gst_rtsp_thread_ref (GstRTSPThread * thread)
100 {
101   return (GstRTSPThread *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (thread));
102 }
103
104 /**
105  * gst_rtsp_thread_unref:
106  * @thread: (transfer full): the thread to refcount
107  *
108  * Decrease the refcount of an thread, freeing it if the refcount reaches 0.
109  */
110 static inline void
111 gst_rtsp_thread_unref (GstRTSPThread * thread)
112 {
113   gst_mini_object_unref (GST_MINI_OBJECT_CAST (thread));
114 }
115
116 /**
117  * GstRTSPThreadPool:
118  *
119  * The thread pool structure.
120  */
121 struct _GstRTSPThreadPool {
122   GObject       parent;
123
124   /*< private >*/
125   GstRTSPThreadPoolPrivate *priv;
126   gpointer _gst_reserved[GST_PADDING];
127 };
128
129 /**
130  * GstRTSPThreadPoolClass:
131  * @pool: a #GThreadPool used internally
132  * @get_thread: this function should make or reuse an existing thread that runs
133  *        a mainloop.
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
138  *
139  * Class for managing threads.
140  */
141 struct _GstRTSPThreadPoolClass {
142   GObjectClass  parent_class;
143
144   GThreadPool *pool;
145
146   GstRTSPThread * (*get_thread)        (GstRTSPThreadPool *pool,
147                                         GstRTSPThreadType type,
148                                         GstRTSPContext *ctx);
149   void            (*configure_thread)  (GstRTSPThreadPool *pool,
150                                         GstRTSPThread * thread,
151                                         GstRTSPContext *ctx);
152
153   void            (*thread_enter)      (GstRTSPThreadPool *pool,
154                                         GstRTSPThread *thread);
155   void            (*thread_leave)      (GstRTSPThreadPool *pool,
156                                         GstRTSPThread *thread);
157
158   /*< private >*/
159   gpointer         _gst_reserved[GST_PADDING];
160 };
161
162 GST_EXPORT
163 GType               gst_rtsp_thread_pool_get_type        (void);
164
165 GST_EXPORT
166 GstRTSPThreadPool * gst_rtsp_thread_pool_new             (void);
167
168 GST_EXPORT
169 void                gst_rtsp_thread_pool_set_max_threads (GstRTSPThreadPool * pool, gint max_threads);
170
171 GST_EXPORT
172 gint                gst_rtsp_thread_pool_get_max_threads (GstRTSPThreadPool * pool);
173
174 GST_EXPORT
175 GstRTSPThread *     gst_rtsp_thread_pool_get_thread      (GstRTSPThreadPool *pool,
176                                                           GstRTSPThreadType type,
177                                                           GstRTSPContext *ctx);
178
179 GST_EXPORT
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)
183 #endif
184
185 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
186 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPThreadPool, gst_object_unref)
187 #endif
188
189 G_END_DECLS
190
191 #endif /* __GST_RTSP_THREAD_POOL_H__ */