2 * Copyright (C) <2009> Wim Taymans <wim.taymans@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.
28 GST_DEBUG_CATEGORY_STATIC (pnmsrc_debug);
29 #define GST_CAT_DEFAULT pnmsrc_debug
31 /* PNMSrc signals and args */
38 #define DEFAULT_LOCATION NULL
47 static GstStaticPadTemplate gst_pnm_src_template =
48 GST_STATIC_PAD_TEMPLATE ("src",
51 GST_STATIC_CAPS ("application/vnd.rn-realmedia")
54 static GstFlowReturn gst_pnm_src_create (GstPushSrc * psrc, GstBuffer ** buf);
56 static void gst_pnm_src_uri_handler_init (gpointer g_iface,
60 _do_init (GType pnmsrc_type)
62 static const GInterfaceInfo urihandler_info = {
63 gst_pnm_src_uri_handler_init,
68 g_type_add_interface_static (pnmsrc_type, GST_TYPE_URI_HANDLER,
72 GST_BOILERPLATE_FULL (GstPNMSrc, gst_pnm_src, GstPushSrc, GST_TYPE_PUSH_SRC,
75 static void gst_pnm_src_finalize (GObject * object);
77 static void gst_pnm_src_set_property (GObject * object, guint prop_id,
78 const GValue * value, GParamSpec * pspec);
79 static void gst_pnm_src_get_property (GObject * object, guint prop_id,
80 GValue * value, GParamSpec * pspec);
84 gst_pnm_src_base_init (gpointer klass)
86 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
88 gst_element_class_add_static_pad_template (element_class,
89 &gst_pnm_src_template);
91 gst_element_class_set_details_simple (element_class, "PNM packet receiver",
93 "Receive data over the network via PNM",
94 "Wim Taymans <wim.taymans@gmail.com>");
96 GST_DEBUG_CATEGORY_INIT (pnmsrc_debug, "pnmsrc",
97 0, "Source for the pnm:// uri");
101 gst_pnm_src_class_init (GstPNMSrcClass * klass)
103 GObjectClass *gobject_class;
104 GstPushSrcClass *gstpushsrc_class;
106 gobject_class = (GObjectClass *) klass;
107 gstpushsrc_class = (GstPushSrcClass *) klass;
109 parent_class = g_type_class_peek_parent (klass);
111 gobject_class->set_property = gst_pnm_src_set_property;
112 gobject_class->get_property = gst_pnm_src_get_property;
114 gobject_class->finalize = gst_pnm_src_finalize;
116 g_object_class_install_property (gobject_class, PROP_LOCATION,
117 g_param_spec_string ("location", "PNM Location",
118 "Location of the PNM url to read",
119 DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
121 gstpushsrc_class->create = gst_pnm_src_create;
125 gst_pnm_src_init (GstPNMSrc * pnmsrc, GstPNMSrcClass * klass)
127 pnmsrc->location = g_strdup (DEFAULT_LOCATION);
131 gst_pnm_src_plugin_init (GstPlugin * plugin)
133 return gst_element_register (plugin, "pnmsrc",
134 GST_RANK_MARGINAL, GST_TYPE_PNM_SRC);
138 gst_pnm_src_finalize (GObject * object)
142 pnmsrc = GST_PNM_SRC (object);
144 g_free (pnmsrc->location);
146 G_OBJECT_CLASS (parent_class)->finalize (object);
150 gst_pnm_src_set_property (GObject * object, guint prop_id,
151 const GValue * value, GParamSpec * pspec)
155 src = GST_PNM_SRC (object);
159 g_free (src->location);
160 src->location = g_value_dup_string (value);
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
169 gst_pnm_src_get_property (GObject * object, guint prop_id,
170 GValue * value, GParamSpec * pspec)
174 src = GST_PNM_SRC (object);
178 g_value_set_string (value, src->location);
181 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
187 gst_pnm_src_create (GstPushSrc * psrc, GstBuffer ** buf)
193 src = GST_PNM_SRC (psrc);
195 if (src->location == NULL)
196 return GST_FLOW_ERROR;
197 url = g_strdup_printf ("rtsp%s", &src->location[3]);
199 /* the only thing we do is redirect to an RTSP url */
200 m = gst_message_new_element (GST_OBJECT_CAST (src),
201 gst_structure_new ("redirect", "new-location", G_TYPE_STRING, url, NULL));
204 gst_element_post_message (GST_ELEMENT_CAST (src), m);
207 return GST_FLOW_UNEXPECTED;
210 /*** GSTURIHANDLER INTERFACE *************************************************/
213 gst_pnm_src_uri_get_type (void)
219 gst_pnm_src_uri_get_protocols (void)
221 static gchar *protocols[] = { (gchar *) "pnm", NULL };
227 gst_pnm_src_uri_get_uri (GstURIHandler * handler)
229 GstPNMSrc *src = GST_PNM_SRC (handler);
231 return src->location;
235 gst_pnm_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
237 GstPNMSrc *src = GST_PNM_SRC (handler);
239 if (!g_str_has_prefix (uri, "pnm://"))
242 g_free (src->location);
243 src->location = g_strdup (uri);
249 gst_pnm_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
251 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
253 iface->get_type = gst_pnm_src_uri_get_type;
254 iface->get_protocols = gst_pnm_src_uri_get_protocols;
255 iface->get_uri = gst_pnm_src_uri_get_uri;
256 iface->set_uri = gst_pnm_src_uri_set_uri;