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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, 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
46 static GstStaticPadTemplate gst_pnm_src_template =
47 GST_STATIC_PAD_TEMPLATE ("src",
50 GST_STATIC_CAPS ("application/vnd.rn-realmedia")
53 static GstFlowReturn gst_pnm_src_create (GstPushSrc * psrc, GstBuffer ** buf);
55 static void gst_pnm_src_uri_handler_init (gpointer g_iface,
58 #define gst_pnm_src_parent_class parent_class
59 G_DEFINE_TYPE_WITH_CODE (GstPNMSrc, gst_pnm_src, GST_TYPE_PUSH_SRC,
60 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_pnm_src_uri_handler_init));
61 GST_ELEMENT_REGISTER_DEFINE (pnmsrc, "pnmsrc",
62 GST_RANK_MARGINAL, GST_TYPE_PNM_SRC);
64 static void gst_pnm_src_finalize (GObject * object);
66 static void gst_pnm_src_set_property (GObject * object, guint prop_id,
67 const GValue * value, GParamSpec * pspec);
68 static void gst_pnm_src_get_property (GObject * object, guint prop_id,
69 GValue * value, GParamSpec * pspec);
72 gst_pnm_src_class_init (GstPNMSrcClass * klass)
74 GObjectClass *gobject_class;
75 GstElementClass *gstelement_class;
76 GstPushSrcClass *gstpushsrc_class;
78 gobject_class = (GObjectClass *) klass;
79 gstelement_class = (GstElementClass *) klass;
80 gstpushsrc_class = (GstPushSrcClass *) klass;
82 parent_class = g_type_class_peek_parent (klass);
84 gobject_class->set_property = gst_pnm_src_set_property;
85 gobject_class->get_property = gst_pnm_src_get_property;
87 gobject_class->finalize = gst_pnm_src_finalize;
89 g_object_class_install_property (gobject_class, PROP_LOCATION,
90 g_param_spec_string ("location", "PNM Location",
91 "Location of the PNM url to read",
92 DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
95 gst_element_class_add_static_pad_template (gstelement_class,
96 &gst_pnm_src_template);
98 gst_element_class_set_static_metadata (gstelement_class,
99 "PNM packet receiver", "Source/Network",
100 "Receive data over the network via PNM",
101 "Wim Taymans <wim.taymans@gmail.com>");
103 gstpushsrc_class->create = gst_pnm_src_create;
105 GST_DEBUG_CATEGORY_INIT (pnmsrc_debug, "pnmsrc",
106 0, "Source for the pnm:// uri");
110 gst_pnm_src_init (GstPNMSrc * pnmsrc)
112 pnmsrc->location = g_strdup (DEFAULT_LOCATION);
116 gst_pnm_src_finalize (GObject * object)
120 pnmsrc = GST_PNM_SRC (object);
122 g_free (pnmsrc->location);
124 G_OBJECT_CLASS (parent_class)->finalize (object);
128 gst_pnm_src_set_property (GObject * object, guint prop_id,
129 const GValue * value, GParamSpec * pspec)
133 src = GST_PNM_SRC (object);
137 g_free (src->location);
138 src->location = g_value_dup_string (value);
141 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
147 gst_pnm_src_get_property (GObject * object, guint prop_id,
148 GValue * value, GParamSpec * pspec)
152 src = GST_PNM_SRC (object);
156 g_value_set_string (value, src->location);
159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
165 gst_pnm_src_create (GstPushSrc * psrc, GstBuffer ** buf)
171 src = GST_PNM_SRC (psrc);
173 if (src->location == NULL)
174 return GST_FLOW_ERROR;
175 url = g_strdup_printf ("rtsp%s", &src->location[3]);
177 /* the only thing we do is redirect to an RTSP url */
178 m = gst_message_new_element (GST_OBJECT_CAST (src),
179 gst_structure_new ("redirect", "new-location", G_TYPE_STRING, url, NULL));
182 gst_element_post_message (GST_ELEMENT_CAST (src), m);
188 /*** GSTURIHANDLER INTERFACE *************************************************/
191 gst_pnm_src_uri_get_type (GType type)
196 static const gchar *const *
197 gst_pnm_src_uri_get_protocols (GType type)
199 static const gchar *protocols[] = { "pnm", NULL };
205 gst_pnm_src_uri_get_uri (GstURIHandler * handler)
207 GstPNMSrc *src = GST_PNM_SRC (handler);
209 /* FIXME: make thread-safe */
210 return g_strdup (src->location);
214 gst_pnm_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
217 GstPNMSrc *src = GST_PNM_SRC (handler);
219 g_free (src->location);
220 src->location = g_strdup (uri);
226 gst_pnm_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
228 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
230 iface->get_type = gst_pnm_src_uri_get_type;
231 iface->get_protocols = gst_pnm_src_uri_get_protocols;
232 iface->get_uri = gst_pnm_src_uri_get_uri;
233 iface->set_uri = gst_pnm_src_uri_set_uri;