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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "rtsp-media-mapping.h"
22 G_DEFINE_TYPE (GstRTSPMediaMapping, gst_rtsp_media_mapping, G_TYPE_OBJECT);
24 static void gst_rtsp_media_mapping_finalize (GObject * obj);
26 static GstRTSPMediaFactory * find_media (GstRTSPMediaMapping *mapping, const GstRTSPUrl *url);
29 gst_rtsp_media_mapping_class_init (GstRTSPMediaMappingClass * klass)
31 GObjectClass *gobject_class;
33 gobject_class = G_OBJECT_CLASS (klass);
35 gobject_class->finalize = gst_rtsp_media_mapping_finalize;
37 klass->find_media = find_media;
41 gst_rtsp_media_mapping_init (GstRTSPMediaMapping * mapping)
43 mapping->mappings = g_hash_table_new_full (g_str_hash, g_str_equal,
44 g_free, g_object_unref);
48 gst_rtsp_media_mapping_finalize (GObject * obj)
50 GstRTSPMediaMapping *mapping = GST_RTSP_MEDIA_MAPPING (obj);
52 g_hash_table_unref (mapping->mappings);
54 G_OBJECT_CLASS (gst_rtsp_media_mapping_parent_class)->finalize (obj);
58 gst_rtsp_media_mapping_new (void)
60 GstRTSPMediaMapping *result;
62 result = g_object_new (GST_TYPE_RTSP_MEDIA_MAPPING, NULL);
67 static GstRTSPMediaFactory *
68 find_media (GstRTSPMediaMapping *mapping, const GstRTSPUrl *url)
70 GstRTSPMediaFactory *result;
72 /* find the location of the media in the hashtable */
73 result = g_hash_table_lookup (mapping->mappings, url->abspath);
75 g_object_ref (result);
77 g_message ("found media %p for url abspath %s", result, url->abspath);
83 * gst_rtsp_media_mapping_find_factory:
84 * @mapping: a #GstRTSPMediaMapping
87 * Find the #GstRTSPMediaFactory for @url from the mappings registered in @mapping.
89 * Returns: the #GstRTSPMediaFactory for @url. g_object_unref() after usage.
92 gst_rtsp_media_mapping_find_factory (GstRTSPMediaMapping *mapping, const GstRTSPUrl *url)
94 GstRTSPMediaFactory *result;
95 GstRTSPMediaMappingClass *klass;
97 klass = GST_RTSP_MEDIA_MAPPING_GET_CLASS (mapping);
99 if (klass->find_media)
100 result = klass->find_media (mapping, url);
108 * gst_rtsp_media_mapping_add_factory:
109 * @mapping: a #GstRTSPMediaMapping
110 * @path: a mount point
111 * @factory: a #GstRTSPMediaFactory
113 * Attach @factory to the mount point @path in @mapping.
115 * @path is of the form (/node)+. Any previous mapping will be freed.
117 * Ownership is taken of the reference on @factory so that @factory should not be
118 * used after calling this function.
121 gst_rtsp_media_mapping_add_factory (GstRTSPMediaMapping *mapping, const gchar *path,
122 GstRTSPMediaFactory *factory)
124 g_return_if_fail (GST_IS_RTSP_MEDIA_MAPPING (mapping));
125 g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
126 g_return_if_fail (path != NULL);
128 g_hash_table_insert (mapping->mappings, g_strdup (path), factory);
132 * gst_rtsp_media_mapping_remove_factory:
133 * @mapping: a #GstRTSPMediaMapping
134 * @path: a mount point
136 * Remove the #GstRTSPMediaFactory associated with @path in @mapping.
139 gst_rtsp_media_mapping_remove_factory (GstRTSPMediaMapping *mapping, const gchar *path)
141 g_return_if_fail (GST_IS_RTSP_MEDIA_MAPPING (mapping));
142 g_return_if_fail (path != NULL);
144 g_hash_table_remove (mapping->mappings, path);