1 /* GStreamer
2 * Copyright (C) <2005,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 /* Element-Checklist-Version: 5 */
21 /**
22 * SECTION:element-rtspwms
23 *
24 * A WMS RTSP extension
25 *
26 * Last reviewed on 2007-07-25 (0.10.14)
27 */
29 #include <string.h>
31 #include <gst/rtsp/gstrtspextension.h>
33 #include "gstrtspwms.h"
35 GST_DEBUG_CATEGORY_STATIC (rtspwms_debug);
36 #define GST_CAT_DEFAULT (rtspwms_debug)
38 #define SERVER_PREFIX "WMServer/"
39 #define HEADER_PREFIX "data:application/vnd.ms.wms-hdr.asfv1;base64,"
40 #define EXTENSION_CMD "application/x-wms-extension-cmd"
42 static GstRTSPResult
43 gst_rtsp_wms_before_send (GstRTSPExtension * ext, GstRTSPMessage * request)
44 {
45 GstRTSPWMS *ctx = (GstRTSPWMS *) ext;
47 GST_DEBUG_OBJECT (ext, "before send");
49 switch (request->type_data.request.method) {
50 case GST_RTSP_OPTIONS:
51 {
52 /* activate ourselves with the first request */
53 ctx->active = TRUE;
54 break;
55 }
56 default:
57 break;
58 }
59 return GST_RTSP_OK;
60 }
62 static GstRTSPResult
63 gst_rtsp_wms_after_send (GstRTSPExtension * ext, GstRTSPMessage * req,
64 GstRTSPMessage * resp)
65 {
66 GstRTSPWMS *ctx = (GstRTSPWMS *) ext;
68 GST_DEBUG_OBJECT (ext, "after send");
70 switch (req->type_data.request.method) {
71 case GST_RTSP_OPTIONS:
72 {
73 gchar *server = NULL;
75 gst_rtsp_message_get_header (resp, GST_RTSP_HDR_SERVER, &server, 0);
76 if (server && g_str_has_prefix (server, SERVER_PREFIX))
77 ctx->active = TRUE;
78 else
79 ctx->active = FALSE;
80 break;
81 }
82 default:
83 break;
84 }
85 return GST_RTSP_OK;
86 }
89 static GstRTSPResult
90 gst_rtsp_wms_parse_sdp (GstRTSPExtension * ext, GstSDPMessage * sdp,
91 GstStructure * props)
92 {
93 const gchar *config, *maxps;
94 gint i;
95 GstRTSPWMS *ctx = (GstRTSPWMS *) ext;
97 if (!ctx->active)
98 return GST_RTSP_OK;
100 for (i = 0; (config = gst_sdp_message_get_attribute_val_n (sdp, "pgmpu", i));
101 i++) {
102 if (g_str_has_prefix (config, HEADER_PREFIX)) {
103 config += strlen (HEADER_PREFIX);
104 gst_structure_set (props, "config", G_TYPE_STRING, config, NULL);
105 break;
106 }
107 }
108 if (config == NULL)
109 goto no_config;
111 gst_structure_set (props, "config", G_TYPE_STRING, config, NULL);
113 maxps = gst_sdp_message_get_attribute_val (sdp, "maxps");
114 if (maxps)
115 gst_structure_set (props, "maxps", G_TYPE_STRING, maxps, NULL);
117 gst_structure_set (props, "encoding-name", G_TYPE_STRING, "X-ASF-PF", NULL);
118 gst_structure_set (props, "media", G_TYPE_STRING, "application", NULL);
120 return GST_RTSP_OK;
122 /* ERRORS */
123 no_config:
124 {
125 GST_DEBUG_OBJECT (ctx, "Could not find config SDP field, deactivating.");
126 ctx->active = FALSE;
127 return GST_RTSP_OK;
128 }
129 }
131 static gboolean
132 gst_rtsp_wms_configure_stream (GstRTSPExtension * ext, GstCaps * caps)
133 {
134 GstRTSPWMS *ctx;
135 GstStructure *s;
136 const gchar *encoding;
138 ctx = (GstRTSPWMS *) ext;
139 s = gst_caps_get_structure (caps, 0);
140 encoding = gst_structure_get_string (s, "encoding-name");
142 if (!encoding)
143 return TRUE;
145 GST_DEBUG_OBJECT (ctx, "%" GST_PTR_FORMAT " encoding-name: %s", caps,
146 encoding);
148 /* rtx streams do not need to be configured */
149 if (!strcmp (encoding, "X-WMS-RTX"))
150 return FALSE;
152 return TRUE;
153 }
155 static GstRTSPResult
156 gst_rtsp_wms_receive_request (GstRTSPExtension * ext, GstRTSPMessage * request)
157 {
158 GstRTSPWMS *ctx;
159 GstRTSPResult res = GST_RTSP_ENOTIMPL;
160 GstRTSPMessage response = { 0 };
162 ctx = (GstRTSPWMS *) ext;
164 GST_DEBUG_OBJECT (ext, "before send");
166 switch (request->type_data.request.method) {
167 case GST_RTSP_SET_PARAMETER:
168 {
169 gchar *content_type = NULL;
171 gst_rtsp_message_get_header (request, GST_RTSP_HDR_CONTENT_TYPE,
172 &content_type, 0);
174 if (content_type && !g_ascii_strcasecmp (content_type, EXTENSION_CMD)) {
175 /* parse the command */
177 /* default implementation, send OK */
178 res = gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK, "OK",
179 request);
180 if (res < 0)
181 goto send_error;
183 GST_DEBUG_OBJECT (ctx, "replying with OK");
185 /* send reply */
186 if ((res = gst_rtsp_extension_send (ext, request, &response)) < 0)
187 goto send_error;
189 res = GST_RTSP_EEOF;
190 }
191 break;
192 }
193 default:
194 break;
195 }
196 return res;
198 send_error:
199 {
200 return res;
201 }
202 }
204 static void gst_rtsp_wms_extension_init (gpointer g_iface, gpointer iface_data);
206 static void
207 _do_init (GType rtspwms_type)
208 {
209 static const GInterfaceInfo rtspextension_info = {
210 gst_rtsp_wms_extension_init,
211 NULL,
212 NULL
213 };
215 g_type_add_interface_static (rtspwms_type, GST_TYPE_RTSP_EXTENSION,
216 &rtspextension_info);
217 }
219 GST_BOILERPLATE_FULL (GstRTSPWMS, gst_rtsp_wms, GstElement, GST_TYPE_ELEMENT,
220 _do_init);
222 static void
223 gst_rtsp_wms_base_init (gpointer klass)
224 {
225 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
227 gst_element_class_set_details_simple (element_class, "WMS RTSP Extension",
228 "Network/Extension/Protocol",
229 "Extends RTSP so that it can handle WMS setup",
230 "Wim Taymans <wim.taymans@gmail.com>");
231 }
233 static void
234 gst_rtsp_wms_class_init (GstRTSPWMSClass * g_class)
235 {
236 GST_DEBUG_CATEGORY_INIT (rtspwms_debug, "rtspwms", 0, "WMS RTSP extension");
237 }
239 static void
240 gst_rtsp_wms_init (GstRTSPWMS * rtspwms, GstRTSPWMSClass * klass)
241 {
242 }
244 static void
245 gst_rtsp_wms_extension_init (gpointer g_iface, gpointer iface_data)
246 {
247 GstRTSPExtensionInterface *iface = (GstRTSPExtensionInterface *) g_iface;
249 iface->parse_sdp = gst_rtsp_wms_parse_sdp;
250 iface->before_send = gst_rtsp_wms_before_send;
251 iface->after_send = gst_rtsp_wms_after_send;
252 iface->configure_stream = gst_rtsp_wms_configure_stream;
253 iface->receive_request = gst_rtsp_wms_receive_request;
254 }