rtsp-stream: obtain stream position from pad
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-context.c
1 /* GStreamer
2  * Copyright (C) 2013 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  * SECTION:rtsp-context
21  * @short_description: A client request context
22  * @see_also: #GstRTSPServer, #GstRTSPClient
23  *
24  * Last reviewed on 2013-07-11 (1.0.0)
25  */
26
27 #include "rtsp-context.h"
28
29 G_DEFINE_POINTER_TYPE (GstRTSPContext, gst_rtsp_context);
30
31 static GPrivate current_context;
32
33 /**
34  * gst_rtsp_context_get_current:
35  *
36  * Get the current #GstRTSPContext. This object is retrieved from the
37  * current thread that is handling the request for a client.
38  *
39  * Returns: a #GstRTSPContext
40  */
41 GstRTSPContext *
42 gst_rtsp_context_get_current (void)
43 {
44   GSList *l;
45
46   l = g_private_get (&current_context);
47   if (l == NULL)
48     return NULL;
49
50   return (GstRTSPContext *) (l->data);
51
52 }
53
54 /**
55  * gst_rtsp_context_push_current:
56  * @ctx: a ##GstRTSPContext
57  *
58  * Pushes @ctx onto the context stack. The current
59  * context can then be received using gst_rtsp_context_get_current().
60  **/
61 void
62 gst_rtsp_context_push_current (GstRTSPContext * ctx)
63 {
64   GSList *l;
65
66   g_return_if_fail (ctx != NULL);
67
68   l = g_private_get (&current_context);
69   l = g_slist_prepend (l, ctx);
70   g_private_set (&current_context, l);
71 }
72
73 /**
74  * gst_rtsp_context_pop_current:
75  * @ctx: a #GstRTSPContext
76  *
77  * Pops @ctx off the context stack (verifying that @ctx
78  * is on the top of the stack).
79  **/
80 void
81 gst_rtsp_context_pop_current (GstRTSPContext * ctx)
82 {
83   GSList *l;
84
85   l = g_private_get (&current_context);
86
87   g_return_if_fail (l != NULL);
88   g_return_if_fail (l->data == ctx);
89
90   l = g_slist_delete_link (l, l);
91   g_private_set (&current_context, l);
92 }