rtsp-client: make sure sessmedia will not get freed while used
[platform/upstream/gstreamer.git] / subprojects / gst-rtsp-server / gst / rtsp-server / rtsp-session.h
1 /* GStreamer
2  * Copyright (C) 2008 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 #include <gst/rtsp/gstrtsptransport.h>
23 #include "rtsp-server-prelude.h" /* for GST_RTSP_SERVER_DEPRECATED_FOR */
24
25 #ifndef __GST_RTSP_SESSION_H__
26 #define __GST_RTSP_SESSION_H__
27
28 G_BEGIN_DECLS
29
30 #define GST_TYPE_RTSP_SESSION              (gst_rtsp_session_get_type ())
31 #define GST_IS_RTSP_SESSION(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_SESSION))
32 #define GST_IS_RTSP_SESSION_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_SESSION))
33 #define GST_RTSP_SESSION_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_SESSION, GstRTSPSessionClass))
34 #define GST_RTSP_SESSION(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_SESSION, GstRTSPSession))
35 #define GST_RTSP_SESSION_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_SESSION, GstRTSPSessionClass))
36 #define GST_RTSP_SESSION_CAST(obj)         ((GstRTSPSession*)(obj))
37 #define GST_RTSP_SESSION_CLASS_CAST(klass) ((GstRTSPSessionClass*)(klass))
38
39 typedef struct _GstRTSPSession GstRTSPSession;
40 typedef struct _GstRTSPSessionClass GstRTSPSessionClass;
41 typedef struct _GstRTSPSessionPrivate GstRTSPSessionPrivate;
42
43 /**
44  * GstRTSPFilterResult:
45  * @GST_RTSP_FILTER_REMOVE: Remove session
46  * @GST_RTSP_FILTER_KEEP: Keep session in the pool
47  * @GST_RTSP_FILTER_REF: Ref session in the result list
48  *
49  * Possible return values for gst_rtsp_session_pool_filter().
50  */
51 typedef enum
52 {
53   GST_RTSP_FILTER_REMOVE,
54   GST_RTSP_FILTER_KEEP,
55   GST_RTSP_FILTER_REF,
56 } GstRTSPFilterResult;
57
58 #include "rtsp-media.h"
59 #include "rtsp-session-media.h"
60
61 /**
62  * GstRTSPSession:
63  *
64  * Session information kept by the server for a specific client.
65  * One client session, identified with a session id, can handle multiple medias
66  * identified with the url of a media.
67  */
68 struct _GstRTSPSession {
69   GObject       parent;
70
71   /*< private >*/
72   GstRTSPSessionPrivate *priv;
73   gpointer _gst_reserved[GST_PADDING];
74 };
75
76 struct _GstRTSPSessionClass {
77   GObjectClass  parent_class;
78
79   /*< private >*/
80   gpointer _gst_reserved[GST_PADDING];
81 };
82
83 GST_RTSP_SERVER_API
84 GType                  gst_rtsp_session_get_type             (void);
85
86 /* create a new session */
87
88 GST_RTSP_SERVER_API
89 GstRTSPSession *       gst_rtsp_session_new                  (const gchar *sessionid);
90
91 GST_RTSP_SERVER_API
92 const gchar *          gst_rtsp_session_get_sessionid        (GstRTSPSession *session);
93
94 GST_RTSP_SERVER_API
95 gchar *                gst_rtsp_session_get_header           (GstRTSPSession *session);
96
97 GST_RTSP_SERVER_API
98 void                   gst_rtsp_session_set_timeout          (GstRTSPSession *session, guint timeout);
99
100 GST_RTSP_SERVER_API
101 guint                  gst_rtsp_session_get_timeout          (GstRTSPSession *session);
102
103 /* session timeout stuff */
104
105 GST_RTSP_SERVER_API
106 void                   gst_rtsp_session_touch                (GstRTSPSession *session);
107
108 GST_RTSP_SERVER_API
109 void                   gst_rtsp_session_prevent_expire       (GstRTSPSession *session);
110
111 GST_RTSP_SERVER_API
112 void                   gst_rtsp_session_allow_expire         (GstRTSPSession *session);
113
114 GST_RTSP_SERVER_API
115 gint                   gst_rtsp_session_next_timeout_usec    (GstRTSPSession *session, gint64 now);
116
117 GST_RTSP_SERVER_API
118 gboolean               gst_rtsp_session_is_expired_usec      (GstRTSPSession *session, gint64 now);
119
120 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
121 GST_RTSP_SERVER_DEPRECATED_FOR(gst_rtsp_session_next_timeout_usec)
122 gint                   gst_rtsp_session_next_timeout         (GstRTSPSession *session, GTimeVal *now);
123
124 GST_RTSP_SERVER_DEPRECATED_FOR(gst_rtsp_session_is_expired_usec)
125 gboolean               gst_rtsp_session_is_expired           (GstRTSPSession *session, GTimeVal *now);
126 G_GNUC_END_IGNORE_DEPRECATIONS
127
128 /* handle media in a session */
129
130 GST_RTSP_SERVER_API
131 GstRTSPSessionMedia *  gst_rtsp_session_manage_media         (GstRTSPSession *sess,
132                                                               const gchar *path,
133                                                               GstRTSPMedia *media);
134
135 GST_RTSP_SERVER_API
136 gboolean               gst_rtsp_session_release_media        (GstRTSPSession *sess,
137                                                               GstRTSPSessionMedia *media);
138 /* get media in a session */
139
140 GST_RTSP_SERVER_API
141 GstRTSPSessionMedia *  gst_rtsp_session_get_media            (GstRTSPSession *sess,
142                                                               const gchar *path,
143                                                               gint * matched);
144 /* get media in a session, increasing its reference count */
145
146 GST_RTSP_SERVER_API
147 GstRTSPSessionMedia *  gst_rtsp_session_dup_media            (GstRTSPSession *sess,
148                                                               const gchar *path,
149                                                               gint * matched);
150 /**
151  * GstRTSPSessionFilterFunc:
152  * @sess: a #GstRTSPSession object
153  * @media: a #GstRTSPSessionMedia in @sess
154  * @user_data: user data that has been given to gst_rtsp_session_filter()
155  *
156  * This function will be called by the gst_rtsp_session_filter(). An
157  * implementation should return a value of #GstRTSPFilterResult.
158  *
159  * When this function returns #GST_RTSP_FILTER_REMOVE, @media will be removed
160  * from @sess.
161  *
162  * A return value of #GST_RTSP_FILTER_KEEP will leave @media untouched in
163  * @sess.
164  *
165  * A value of GST_RTSP_FILTER_REF will add @media to the result #GList of
166  * gst_rtsp_session_filter().
167  *
168  * Returns: a #GstRTSPFilterResult.
169  */
170 typedef GstRTSPFilterResult (*GstRTSPSessionFilterFunc)  (GstRTSPSession *sess,
171                                                           GstRTSPSessionMedia *media,
172                                                           gpointer user_data);
173
174 GST_RTSP_SERVER_API
175 GList *                gst_rtsp_session_filter           (GstRTSPSession *sess,
176                                                           GstRTSPSessionFilterFunc func,
177                                                           gpointer user_data);
178
179
180 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
181 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPSession, gst_object_unref)
182 #endif
183
184 G_END_DECLS
185
186 #endif /* __GST_RTSP_SESSION_H__ */