Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / gst / rtsp / gstrtspext.c
1 /* GStreamer
2  * Copyright (C) <2006> Wim Taymans <wim@fluendo.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  * Unless otherwise indicated, Source Code is licensed under MIT license.
21  * See further explanation attached in License Statement (distributed in the file
22  * LICENSE).
23  *
24  * Permission is hereby granted, free of charge, to any person obtaining a copy of
25  * this software and associated documentation files (the "Software"), to deal in
26  * the Software without restriction, including without limitation the rights to
27  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28  * of the Software, and to permit persons to whom the Software is furnished to do
29  * so, subject to the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be included in all
32  * copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40  * SOFTWARE.
41  */
42
43 #include "gstrtspext.h"
44
45 GST_DEBUG_CATEGORY_STATIC (rtspext_debug);
46 #define GST_CAT_DEFAULT (rtspext_debug)
47
48 static GList *extensions;
49
50 static gboolean
51 gst_rtsp_ext_list_filter (GstPluginFeature * feature, gpointer user_data)
52 {
53   GstElementFactory *factory;
54   guint rank;
55
56   /* we only care about element factories */
57   if (!GST_IS_ELEMENT_FACTORY (feature))
58     return FALSE;
59
60   factory = GST_ELEMENT_FACTORY (feature);
61
62   if (!gst_element_factory_has_interface (factory, "GstRTSPExtension"))
63     return FALSE;
64
65   /* only select elements with autoplugging rank */
66   rank = gst_plugin_feature_get_rank (feature);
67   if (rank < GST_RANK_MARGINAL)
68     return FALSE;
69
70   return TRUE;
71 }
72
73 void
74 gst_rtsp_ext_list_init (void)
75 {
76   GST_DEBUG_CATEGORY_INIT (rtspext_debug, "rtspext", 0, "RTSP extension");
77
78   /* get a list of all extensions */
79   extensions = gst_registry_feature_filter (gst_registry_get_default (),
80       (GstPluginFeatureFilter) gst_rtsp_ext_list_filter, FALSE, NULL);
81 }
82
83 GstRTSPExtensionList *
84 gst_rtsp_ext_list_get (void)
85 {
86   GstRTSPExtensionList *result;
87   GList *walk;
88
89   result = g_new0 (GstRTSPExtensionList, 1);
90
91   for (walk = extensions; walk; walk = g_list_next (walk)) {
92     GstElementFactory *factory = GST_ELEMENT_FACTORY (walk->data);
93     GstElement *element;
94
95     element = gst_element_factory_create (factory, NULL);
96     if (!element) {
97       GST_ERROR ("could not create extension instance");
98       continue;
99     }
100
101     GST_DEBUG ("added extension interface for '%s'",
102         GST_ELEMENT_NAME (element));
103     result->extensions = g_list_prepend (result->extensions, element);
104   }
105   return result;
106 }
107
108 void
109 gst_rtsp_ext_list_free (GstRTSPExtensionList * ext)
110 {
111   GList *walk;
112
113   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
114     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
115
116     gst_object_unref (GST_OBJECT_CAST (elem));
117   }
118   g_list_free (ext->extensions);
119   g_free (ext);
120 }
121
122 gboolean
123 gst_rtsp_ext_list_detect_server (GstRTSPExtensionList * ext,
124     GstRTSPMessage * resp)
125 {
126   GList *walk;
127   gboolean res = TRUE;
128
129   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
130     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
131
132     res = gst_rtsp_extension_detect_server (elem, resp);
133   }
134   return res;
135 }
136
137 GstRTSPResult
138 gst_rtsp_ext_list_before_send (GstRTSPExtensionList * ext, GstRTSPMessage * req)
139 {
140   GList *walk;
141   GstRTSPResult res = GST_RTSP_OK;
142
143   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
144     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
145
146     res = gst_rtsp_extension_before_send (elem, req);
147   }
148   return res;
149 }
150
151 GstRTSPResult
152 gst_rtsp_ext_list_after_send (GstRTSPExtensionList * ext, GstRTSPMessage * req,
153     GstRTSPMessage * resp)
154 {
155   GList *walk;
156   GstRTSPResult res = GST_RTSP_OK;
157
158   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
159     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
160
161     res = gst_rtsp_extension_after_send (elem, req, resp);
162   }
163   return res;
164 }
165
166 GstRTSPResult
167 gst_rtsp_ext_list_parse_sdp (GstRTSPExtensionList * ext, GstSDPMessage * sdp,
168     GstStructure * s)
169 {
170   GList *walk;
171   GstRTSPResult res = GST_RTSP_OK;
172
173   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
174     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
175
176     res = gst_rtsp_extension_parse_sdp (elem, sdp, s);
177   }
178   return res;
179 }
180
181 GstRTSPResult
182 gst_rtsp_ext_list_setup_media (GstRTSPExtensionList * ext, GstSDPMedia * media)
183 {
184   GList *walk;
185   GstRTSPResult res = GST_RTSP_OK;
186
187   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
188     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
189
190     res = gst_rtsp_extension_setup_media (elem, media);
191   }
192   return res;
193 }
194
195 gboolean
196 gst_rtsp_ext_list_configure_stream (GstRTSPExtensionList * ext, GstCaps * caps)
197 {
198   GList *walk;
199   gboolean res = TRUE;
200
201   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
202     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
203
204     res = gst_rtsp_extension_configure_stream (elem, caps);
205     if (!res)
206       break;
207   }
208   return res;
209 }
210
211 GstRTSPResult
212 gst_rtsp_ext_list_get_transports (GstRTSPExtensionList * ext,
213     GstRTSPLowerTrans protocols, gchar ** transport)
214 {
215   GList *walk;
216   GstRTSPResult res = GST_RTSP_OK;
217
218   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
219     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
220
221     res = gst_rtsp_extension_get_transports (elem, protocols, transport);
222   }
223   return res;
224 }
225
226 GstRTSPResult
227 gst_rtsp_ext_list_stream_select (GstRTSPExtensionList * ext, GstRTSPUrl * url)
228 {
229   GList *walk;
230   GstRTSPResult res = GST_RTSP_OK;
231
232   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
233     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
234
235     res = gst_rtsp_extension_stream_select (elem, url);
236   }
237   return res;
238 }
239
240 void
241 gst_rtsp_ext_list_connect (GstRTSPExtensionList * ext,
242     const gchar * detailed_signal, GCallback c_handler, gpointer data)
243 {
244   GList *walk;
245
246   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
247     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
248
249     g_signal_connect (elem, detailed_signal, c_handler, data);
250   }
251 }
252
253 GstRTSPResult
254 gst_rtsp_ext_list_receive_request (GstRTSPExtensionList * ext,
255     GstRTSPMessage * req)
256 {
257   GList *walk;
258   GstRTSPResult res = GST_RTSP_ENOTIMPL;
259
260   for (walk = ext->extensions; walk; walk = g_list_next (walk)) {
261     GstRTSPExtension *elem = (GstRTSPExtension *) walk->data;
262
263     res = gst_rtsp_extension_receive_request (elem, req);
264     if (res != GST_RTSP_ENOTIMPL)
265       break;
266   }
267   return res;
268 }