2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
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.
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.
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.
20 #include "rtsp-media-mapping.h"
22 G_DEFINE_TYPE (GstRTSPMediaMapping, gst_rtsp_media_mapping, G_TYPE_OBJECT);
24 GST_DEBUG_CATEGORY_STATIC (rtsp_media_debug);
25 #define GST_CAT_DEFAULT rtsp_media_debug
27 static void gst_rtsp_media_mapping_finalize (GObject * obj);
29 static GstRTSPMediaFactory *find_factory (GstRTSPMediaMapping * mapping,
30 const GstRTSPUrl * url);
33 gst_rtsp_media_mapping_class_init (GstRTSPMediaMappingClass * klass)
35 GObjectClass *gobject_class;
37 gobject_class = G_OBJECT_CLASS (klass);
39 gobject_class->finalize = gst_rtsp_media_mapping_finalize;
41 klass->find_factory = find_factory;
43 GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmediamapping", 0,
44 "GstRTSPMediaMapping");
48 gst_rtsp_media_mapping_init (GstRTSPMediaMapping * mapping)
50 GST_DEBUG_OBJECT (mapping, "created");
52 g_mutex_init (&mapping->lock);
53 mapping->mappings = g_hash_table_new_full (g_str_hash, g_str_equal,
54 g_free, g_object_unref);
58 gst_rtsp_media_mapping_finalize (GObject * obj)
60 GstRTSPMediaMapping *mapping = GST_RTSP_MEDIA_MAPPING (obj);
62 GST_DEBUG_OBJECT (mapping, "finalized");
64 g_hash_table_unref (mapping->mappings);
65 g_mutex_clear (&mapping->lock);
67 G_OBJECT_CLASS (gst_rtsp_media_mapping_parent_class)->finalize (obj);
71 * gst_rtsp_media_mapping_new:
73 * Make a new media mapping object.
75 * Returns: a new #GstRTSPMediaMapping
78 gst_rtsp_media_mapping_new (void)
80 GstRTSPMediaMapping *result;
82 result = g_object_new (GST_TYPE_RTSP_MEDIA_MAPPING, NULL);
87 static GstRTSPMediaFactory *
88 find_factory (GstRTSPMediaMapping * mapping, const GstRTSPUrl * url)
90 GstRTSPMediaFactory *result;
92 g_mutex_lock (&mapping->lock);
93 /* find the location of the media in the hashtable we only use the absolute
94 * path of the uri to find a mapping. If the mapping depends on other
95 * properties found in the url, this method should be overridden. */
96 result = g_hash_table_lookup (mapping->mappings, url->abspath);
98 g_object_ref (result);
99 g_mutex_unlock (&mapping->lock);
101 GST_INFO ("found media %p for url abspath %s", result, url->abspath);
107 * gst_rtsp_media_mapping_find_factory:
108 * @mapping: a #GstRTSPMediaMapping
111 * Find the #GstRTSPMediaFactory for @url. The default implementation of this object
112 * will use the mappings added with gst_rtsp_media_mapping_add_factory ().
114 * Returns: (transfer full): the #GstRTSPMediaFactory for @url. g_object_unref() after usage.
116 GstRTSPMediaFactory *
117 gst_rtsp_media_mapping_find_factory (GstRTSPMediaMapping * mapping,
118 const GstRTSPUrl * url)
120 GstRTSPMediaFactory *result;
121 GstRTSPMediaMappingClass *klass;
123 klass = GST_RTSP_MEDIA_MAPPING_GET_CLASS (mapping);
125 if (klass->find_factory)
126 result = klass->find_factory (mapping, url);
134 * gst_rtsp_media_mapping_add_factory:
135 * @mapping: a #GstRTSPMediaMapping
136 * @path: a mount point
137 * @factory: (transfer full): a #GstRTSPMediaFactory
139 * Attach @factory to the mount point @path in @mapping.
141 * @path is of the form (/node)+. Any previous mapping will be freed.
143 * Ownership is taken of the reference on @factory so that @factory should not be
144 * used after calling this function.
147 gst_rtsp_media_mapping_add_factory (GstRTSPMediaMapping * mapping,
148 const gchar * path, GstRTSPMediaFactory * factory)
150 g_return_if_fail (GST_IS_RTSP_MEDIA_MAPPING (mapping));
151 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
152 g_return_if_fail (path != NULL);
154 g_mutex_lock (&mapping->lock);
155 g_hash_table_insert (mapping->mappings, g_strdup (path), factory);
156 g_mutex_unlock (&mapping->lock);
160 * gst_rtsp_media_mapping_remove_factory:
161 * @mapping: a #GstRTSPMediaMapping
162 * @path: a mount point
164 * Remove the #GstRTSPMediaFactory associated with @path in @mapping.
167 gst_rtsp_media_mapping_remove_factory (GstRTSPMediaMapping * mapping,
170 g_return_if_fail (GST_IS_RTSP_MEDIA_MAPPING (mapping));
171 g_return_if_fail (path != NULL);
173 g_mutex_lock (&mapping->lock);
174 g_hash_table_remove (mapping->mappings, path);
175 g_mutex_unlock (&mapping->lock);