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-mount-points.h"
22 #define GST_RTSP_MOUNT_POINTS_GET_PRIVATE(obj) \
23 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_MOUNT_POINTS, GstRTSPMountPointsPrivate))
25 struct _GstRTSPMountPointsPrivate
28 GHashTable *mounts; /* protected by lock */
31 G_DEFINE_TYPE (GstRTSPMountPoints, gst_rtsp_mount_points, G_TYPE_OBJECT);
33 GST_DEBUG_CATEGORY_STATIC (rtsp_media_debug);
34 #define GST_CAT_DEFAULT rtsp_media_debug
36 static void gst_rtsp_mount_points_finalize (GObject * obj);
38 static GstRTSPMediaFactory *find_factory (GstRTSPMountPoints * mounts,
39 const GstRTSPUrl * url);
42 gst_rtsp_mount_points_class_init (GstRTSPMountPointsClass * klass)
44 GObjectClass *gobject_class;
46 g_type_class_add_private (klass, sizeof (GstRTSPMountPointsPrivate));
48 gobject_class = G_OBJECT_CLASS (klass);
50 gobject_class->finalize = gst_rtsp_mount_points_finalize;
52 klass->find_factory = find_factory;
54 GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmountpoints", 0,
55 "GstRTSPMountPoints");
59 gst_rtsp_mount_points_init (GstRTSPMountPoints * mounts)
61 GstRTSPMountPointsPrivate *priv = GST_RTSP_MOUNT_POINTS_GET_PRIVATE (mounts);
63 GST_DEBUG_OBJECT (mounts, "created");
67 g_mutex_init (&priv->lock);
68 priv->mounts = g_hash_table_new_full (g_str_hash, g_str_equal,
69 g_free, g_object_unref);
73 gst_rtsp_mount_points_finalize (GObject * obj)
75 GstRTSPMountPoints *mounts = GST_RTSP_MOUNT_POINTS (obj);
76 GstRTSPMountPointsPrivate *priv = mounts->priv;
78 GST_DEBUG_OBJECT (mounts, "finalized");
80 g_hash_table_unref (priv->mounts);
81 g_mutex_clear (&priv->lock);
83 G_OBJECT_CLASS (gst_rtsp_mount_points_parent_class)->finalize (obj);
87 * gst_rtsp_mount_points_new:
89 * Make a new mount points object.
91 * Returns: a new #GstRTSPMountPoints
94 gst_rtsp_mount_points_new (void)
96 GstRTSPMountPoints *result;
98 result = g_object_new (GST_TYPE_RTSP_MOUNT_POINTS, NULL);
103 static GstRTSPMediaFactory *
104 find_factory (GstRTSPMountPoints * mounts, const GstRTSPUrl * url)
106 GstRTSPMountPointsPrivate *priv = mounts->priv;
107 GstRTSPMediaFactory *result;
109 g_mutex_lock (&priv->lock);
110 /* find the location of the media in the hashtable we only use the absolute
111 * path of the uri to find a media factory. If the factory depends on other
112 * properties found in the url, this method should be overridden. */
113 result = g_hash_table_lookup (priv->mounts, url->abspath);
115 g_object_ref (result);
116 g_mutex_unlock (&priv->lock);
118 GST_INFO ("found media factory %p for url abspath %s", result, url->abspath);
124 * gst_rtsp_mount_points_find_factory:
125 * @mounts: a #GstRTSPMountPoints
128 * Find the #GstRTSPMediaFactory for @url. The default implementation of this object
129 * will use the media factory added with gst_rtsp_mount_points_add_factory ().
131 * Returns: (transfer full): the #GstRTSPMediaFactory for @url. g_object_unref() after usage.
133 GstRTSPMediaFactory *
134 gst_rtsp_mount_points_find_factory (GstRTSPMountPoints * mounts,
135 const GstRTSPUrl * url)
137 GstRTSPMediaFactory *result;
138 GstRTSPMountPointsClass *klass;
140 g_return_val_if_fail (GST_IS_RTSP_MOUNT_POINTS (mounts), NULL);
141 g_return_val_if_fail (url != NULL, NULL);
143 klass = GST_RTSP_MOUNT_POINTS_GET_CLASS (mounts);
145 if (klass->find_factory)
146 result = klass->find_factory (mounts, url);
154 * gst_rtsp_mount_points_add_factory:
155 * @mounts: a #GstRTSPMountPoints
156 * @path: a mount point
157 * @factory: (transfer full): a #GstRTSPMediaFactory
159 * Attach @factory to the mount point @path in @mounts.
161 * @path is of the form (/node)+. Any previous mount point will be freed.
163 * Ownership is taken of the reference on @factory so that @factory should not be
164 * used after calling this function.
167 gst_rtsp_mount_points_add_factory (GstRTSPMountPoints * mounts,
168 const gchar * path, GstRTSPMediaFactory * factory)
170 GstRTSPMountPointsPrivate *priv;
172 g_return_if_fail (GST_IS_RTSP_MOUNT_POINTS (mounts));
173 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
174 g_return_if_fail (path != NULL);
178 g_mutex_lock (&priv->lock);
179 g_hash_table_insert (priv->mounts, g_strdup (path), factory);
180 g_mutex_unlock (&priv->lock);
184 * gst_rtsp_mount_points_remove_factory:
185 * @mounts: a #GstRTSPMountPoints
186 * @path: a mount point
188 * Remove the #GstRTSPMediaFactory associated with @path in @mounts.
191 gst_rtsp_mount_points_remove_factory (GstRTSPMountPoints * mounts,
194 GstRTSPMountPointsPrivate *priv;
196 g_return_if_fail (GST_IS_RTSP_MOUNT_POINTS (mounts));
197 g_return_if_fail (path != NULL);
201 g_mutex_lock (&priv->lock);
202 g_hash_table_remove (priv->mounts, path);
203 g_mutex_unlock (&priv->lock);