| 1 |
/* GStreamer |
| 2 |
* Copyright (C) <2009> Wim Taymans <[email protected]> |
| 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., 51 Franklin St, Fifth Floor, |
| 17 |
* Boston, MA 02110-1301, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifdef HAVE_CONFIG_H |
| 21 |
# include "config.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
#include <string.h> |
| 25 |
|
| 26 |
#include "pnmsrc.h" |
| 27 |
|
| 28 |
GST_DEBUG_CATEGORY_STATIC (pnmsrc_debug); |
| 29 |
#define GST_CAT_DEFAULT pnmsrc_debug |
| 30 |
|
| 31 |
/* PNMSrc signals and args */ |
| 32 |
enum |
| 33 |
{ |
| 34 |
/* FILL ME */ |
| 35 |
LAST_SIGNAL |
| 36 |
}; |
| 37 |
|
| 38 |
#define DEFAULT_LOCATION NULL |
| 39 |
|
| 40 |
enum |
| 41 |
{ |
| 42 |
PROP_0, |
| 43 |
PROP_LOCATION |
| 44 |
}; |
| 45 |
|
| 46 |
static GstStaticPadTemplate gst_pnm_src_template = |
| 47 |
GST_STATIC_PAD_TEMPLATE ("src", |
| 48 |
GST_PAD_SRC, |
| 49 |
GST_PAD_ALWAYS, |
| 50 |
GST_STATIC_CAPS ("application/vnd.rn-realmedia") |
| 51 |
); |
| 52 |
|
| 53 |
static GstFlowReturn gst_pnm_src_create (GstPushSrc * psrc, GstBuffer ** buf); |
| 54 |
|
| 55 |
static void gst_pnm_src_uri_handler_init (gpointer g_iface, |
| 56 |
gpointer iface_data); |
| 57 |
|
| 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); |
| 63 |
|
| 64 |
static void gst_pnm_src_finalize (GObject * object); |
| 65 |
|
| 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); |
| 70 |
|
| 71 |
static void |
| 72 |
gst_pnm_src_class_init (GstPNMSrcClass * klass) |
| 73 |
{ |
| 74 |
GObjectClass *gobject_class; |
| 75 |
GstElementClass *gstelement_class; |
| 76 |
GstPushSrcClass *gstpushsrc_class; |
| 77 |
|
| 78 |
gobject_class = (GObjectClass *) klass; |
| 79 |
gstelement_class = (GstElementClass *) klass; |
| 80 |
gstpushsrc_class = (GstPushSrcClass *) klass; |
| 81 |
|
| 82 |
parent_class = g_type_class_peek_parent (klass); |
| 83 |
|
| 84 |
gobject_class->set_property = gst_pnm_src_set_property; |
| 85 |
gobject_class->get_property = gst_pnm_src_get_property; |
| 86 |
|
| 87 |
gobject_class->finalize = gst_pnm_src_finalize; |
| 88 |
|
| 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)); |
| 93 |
|
| 94 |
|
| 95 |
gst_element_class_add_static_pad_template (gstelement_class, |
| 96 |
&gst_pnm_src_template); |
| 97 |
|
| 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 <[email protected]>"); |
| 102 |
|
| 103 |
gstpushsrc_class->create = gst_pnm_src_create; |
| 104 |
|
| 105 |
GST_DEBUG_CATEGORY_INIT (pnmsrc_debug, "pnmsrc", |
| 106 |
0, "Source for the pnm:// uri"); |
| 107 |
} |
| 108 |
|
| 109 |
static void |
| 110 |
gst_pnm_src_init (GstPNMSrc * pnmsrc) |
| 111 |
{ |
| 112 |
pnmsrc->location = g_strdup (DEFAULT_LOCATION); |
| 113 |
} |
| 114 |
|
| 115 |
static void |
| 116 |
gst_pnm_src_finalize (GObject * object) |
| 117 |
{ |
| 118 |
GstPNMSrc *pnmsrc; |
| 119 |
|
| 120 |
pnmsrc = GST_PNM_SRC (object); |
| 121 |
|
| 122 |
g_free (pnmsrc->location); |
| 123 |
|
| 124 |
G_OBJECT_CLASS (parent_class)->finalize (object); |
| 125 |
} |
| 126 |
|
| 127 |
static void |
| 128 |
gst_pnm_src_set_property (GObject * object, guint prop_id, |
| 129 |
const GValue * value, GParamSpec * pspec) |
| 130 |
{ |
| 131 |
GstPNMSrc *src; |
| 132 |
|
| 133 |
src = GST_PNM_SRC (object); |
| 134 |
|
| 135 |
switch (prop_id) { |
| 136 |
case PROP_LOCATION: |
| 137 |
g_free (src->location); |
| 138 |
src->location = g_value_dup_string (value); |
| 139 |
break; |
| 140 |
default: |
| 141 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 142 |
break; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
static void |
| 147 |
gst_pnm_src_get_property (GObject * object, guint prop_id, |
| 148 |
GValue * value, GParamSpec * pspec) |
| 149 |
{ |
| 150 |
GstPNMSrc *src; |
| 151 |
|
| 152 |
src = GST_PNM_SRC (object); |
| 153 |
|
| 154 |
switch (prop_id) { |
| 155 |
case PROP_LOCATION: |
| 156 |
g_value_set_string (value, src->location); |
| 157 |
break; |
| 158 |
default: |
| 159 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 160 |
break; |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
static GstFlowReturn |
| 165 |
gst_pnm_src_create (GstPushSrc * psrc, GstBuffer ** buf) |
| 166 |
{ |
| 167 |
GstPNMSrc *src; |
| 168 |
GstMessage *m; |
| 169 |
gchar *url; |
| 170 |
|
| 171 |
src = GST_PNM_SRC (psrc); |
| 172 |
|
| 173 |
if (src->location == NULL) |
| 174 |
return GST_FLOW_ERROR; |
| 175 |
url = g_strdup_printf ("rtsp%s", &src->location[3]); |
| 176 |
|
| 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)); |
| 180 |
g_free (url); |
| 181 |
|
| 182 |
gst_element_post_message (GST_ELEMENT_CAST (src), m); |
| 183 |
|
| 184 |
|
| 185 |
return GST_FLOW_EOS; |
| 186 |
} |
| 187 |
|
| 188 |
/*** GSTURIHANDLER INTERFACE *************************************************/ |
| 189 |
|
| 190 |
static GstURIType |
| 191 |
gst_pnm_src_uri_get_type (GType type) |
| 192 |
{ |
| 193 |
return GST_URI_SRC; |
| 194 |
} |
| 195 |
|
| 196 |
static const gchar *const * |
| 197 |
gst_pnm_src_uri_get_protocols (GType type) |
| 198 |
{ |
| 199 |
static const gchar *protocols[] = { "pnm", NULL }; |
| 200 |
|
| 201 |
return protocols; |
| 202 |
} |
| 203 |
|
| 204 |
static gchar * |
| 205 |
gst_pnm_src_uri_get_uri (GstURIHandler * handler) |
| 206 |
{ |
| 207 |
GstPNMSrc *src = GST_PNM_SRC (handler); |
| 208 |
|
| 209 |
/* FIXME: make thread-safe */ |
| 210 |
return g_strdup (src->location); |
| 211 |
} |
| 212 |
|
| 213 |
static gboolean |
| 214 |
gst_pnm_src_uri_set_uri (GstURIHandler * handler, const gchar * uri, |
| 215 |
GError ** error) |
| 216 |
{ |
| 217 |
GstPNMSrc *src = GST_PNM_SRC (handler); |
| 218 |
|
| 219 |
g_free (src->location); |
| 220 |
src->location = g_strdup (uri); |
| 221 |
|
| 222 |
return TRUE; |
| 223 |
} |
| 224 |
|
| 225 |
static void |
| 226 |
gst_pnm_src_uri_handler_init (gpointer g_iface, gpointer iface_data) |
| 227 |
{ |
| 228 |
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; |
| 229 |
|
| 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; |
| 234 |
} |