rtsp-server: Run gst-indent
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-media-mapping.c
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "rtsp-media-mapping.h"
21
22 G_DEFINE_TYPE (GstRTSPMediaMapping, gst_rtsp_media_mapping, G_TYPE_OBJECT);
23
24 GST_DEBUG_CATEGORY_EXTERN (rtsp_media_debug);
25 #define GST_CAT_DEFAULT rtsp_media_debug
26
27 static void gst_rtsp_media_mapping_finalize (GObject * obj);
28
29 static GstRTSPMediaFactory *find_media (GstRTSPMediaMapping * mapping,
30     const GstRTSPUrl * url);
31
32 static void
33 gst_rtsp_media_mapping_class_init (GstRTSPMediaMappingClass * klass)
34 {
35   GObjectClass *gobject_class;
36
37   gobject_class = G_OBJECT_CLASS (klass);
38
39   gobject_class->finalize = gst_rtsp_media_mapping_finalize;
40
41   klass->find_media = find_media;
42 }
43
44 static void
45 gst_rtsp_media_mapping_init (GstRTSPMediaMapping * mapping)
46 {
47   mapping->mappings = g_hash_table_new_full (g_str_hash, g_str_equal,
48       g_free, g_object_unref);
49 }
50
51 static void
52 gst_rtsp_media_mapping_finalize (GObject * obj)
53 {
54   GstRTSPMediaMapping *mapping = GST_RTSP_MEDIA_MAPPING (obj);
55
56   g_hash_table_unref (mapping->mappings);
57
58   G_OBJECT_CLASS (gst_rtsp_media_mapping_parent_class)->finalize (obj);
59 }
60
61 GstRTSPMediaMapping *
62 gst_rtsp_media_mapping_new (void)
63 {
64   GstRTSPMediaMapping *result;
65
66   result = g_object_new (GST_TYPE_RTSP_MEDIA_MAPPING, NULL);
67
68   return result;
69 }
70
71 static GstRTSPMediaFactory *
72 find_media (GstRTSPMediaMapping * mapping, const GstRTSPUrl * url)
73 {
74   GstRTSPMediaFactory *result;
75
76   /* find the location of the media in the hashtable we only use the absolute
77    * path of the uri to find a mapping. If the mapping depends on other
78    * properties found in the url, this method should be overridden. */
79   result = g_hash_table_lookup (mapping->mappings, url->abspath);
80   if (result)
81     g_object_ref (result);
82
83   GST_INFO ("found media %p for url abspath %s", result, url->abspath);
84
85   return result;
86 }
87
88 /**
89  * gst_rtsp_media_mapping_find_factory:
90  * @mapping: a #GstRTSPMediaMapping
91  * @url: a url
92  *
93  * Find the #GstRTSPMediaFactory for @url. The default implementation of this object 
94  * will use the mappings added with gst_rtsp_media_mapping_add_factory ().
95  *
96  * Returns: the #GstRTSPMediaFactory for @url. g_object_unref() after usage.
97  */
98 GstRTSPMediaFactory *
99 gst_rtsp_media_mapping_find_factory (GstRTSPMediaMapping * mapping,
100     const GstRTSPUrl * url)
101 {
102   GstRTSPMediaFactory *result;
103   GstRTSPMediaMappingClass *klass;
104
105   klass = GST_RTSP_MEDIA_MAPPING_GET_CLASS (mapping);
106
107   if (klass->find_media)
108     result = klass->find_media (mapping, url);
109   else
110     result = NULL;
111
112   return result;
113 }
114
115 /**
116  * gst_rtsp_media_mapping_add_factory:
117  * @mapping: a #GstRTSPMediaMapping
118  * @path: a mount point
119  * @factory: a #GstRTSPMediaFactory
120  *
121  * Attach @factory to the mount point @path in @mapping.
122  *
123  * @path is of the form (/node)+. Any previous mapping will be freed.
124  *
125  * Ownership is taken of the reference on @factory so that @factory should not be
126  * used after calling this function.
127  */
128 void
129 gst_rtsp_media_mapping_add_factory (GstRTSPMediaMapping * mapping,
130     const gchar * path, GstRTSPMediaFactory * factory)
131 {
132   g_return_if_fail (GST_IS_RTSP_MEDIA_MAPPING (mapping));
133   g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
134   g_return_if_fail (path != NULL);
135
136   g_hash_table_insert (mapping->mappings, g_strdup (path), factory);
137 }
138
139 /**
140  * gst_rtsp_media_mapping_remove_factory:
141  * @mapping: a #GstRTSPMediaMapping
142  * @path: a mount point
143  *
144  * Remove the #GstRTSPMediaFactory associated with @path in @mapping.
145  */
146 void
147 gst_rtsp_media_mapping_remove_factory (GstRTSPMediaMapping * mapping,
148     const gchar * path)
149 {
150   g_return_if_fail (GST_IS_RTSP_MEDIA_MAPPING (mapping));
151   g_return_if_fail (path != NULL);
152
153   g_hash_table_remove (mapping->mappings, path);
154 }