-/* GStreamer
- *
+/* GStreamer data:// uri source element
* Copyright (C) 2009 Igalia S.L
* Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
/**
* <refsect2>
* <title>Example launch line</title>
* |[
- * gst-launch-0.10 -v dataurisrc uri="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAfElEQVQ4je2MwQnAIAxFgziA4EnczIsO4MEROo/gzZWc4xdTbe1R6LGRR74heYS7iKElzfcMiRnt4hf8gk8EayB6luefue/HzlJfCA50XsNjYRxprZmenXNIKSGEsC+QUqK1hhgj521BzhnWWiilUGvdF5RS4L2HMQZCCJy8sHMm2TYdJAAAAABJRU5ErkJggg==" ! pngdec ! ffmpegcolorspace ! freeze ! ffmpegcolorspace ! autovideosink
+ * gst-launch-1.0 -v dataurisrc uri="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAfElEQVQ4je2MwQnAIAxFgziA4EnczIsO4MEROo/gzZWc4xdTbe1R6LGRR74heYS7iKElzfcMiRnt4hf8gk8EayB6luefue/HzlJfCA50XsNjYRxprZmenXNIKSGEsC+QUqK1hhgj521BzhnWWiilUGvdF5RS4L2HMQZCCJy8sHMm2TYdJAAAAABJRU5ErkJggg==" ! pngdec ! videoconvert ! imagefreeze ! videoconvert ! autovideosink
* ]| This pipeline displays a small 16x16 PNG image from the data URI.
* </refsect2>
*/
static void gst_data_uri_src_handler_init (gpointer g_iface,
gpointer iface_data);
static GstURIType gst_data_uri_src_get_uri_type (GType type);
-static gchar **gst_data_uri_src_get_protocols (GType type);
-static const gchar *gst_data_uri_src_get_uri (GstURIHandler * handler);
+static const gchar *const *gst_data_uri_src_get_protocols (GType type);
+static gchar *gst_data_uri_src_get_uri (GstURIHandler * handler);
static gboolean gst_data_uri_src_set_uri (GstURIHandler * handler,
- const gchar * uri);
+ const gchar * uri, GError ** error);
#define gst_data_uri_src_parent_class parent_class
"URI that should be used",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&src_template));
- gst_element_class_set_details_simple (element_class,
+ gst_element_class_add_static_pad_template (element_class, &src_template);
+ gst_element_class_set_static_metadata (element_class,
"data: URI source element", "Source", "Handles data: uris",
"Philippe Normand <pnormand@igalia.com>, "
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
switch (prop_id) {
case PROP_URI:
gst_data_uri_src_set_uri (GST_URI_HANDLER (src),
- g_value_get_string (value));
+ g_value_get_string (value), NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
switch (prop_id) {
case PROP_URI:
- g_value_set_string (value,
+ g_value_take_string (value,
gst_data_uri_src_get_uri (GST_URI_HANDLER (src)));
break;
default:
GstCaps *caps;
GST_OBJECT_LOCK (src);
- if (gst_pad_has_current_caps (GST_BASE_SRC_PAD (basesrc)))
- caps = gst_pad_get_current_caps (GST_BASE_SRC_PAD (basesrc));
- else
+ caps = gst_pad_get_current_caps (GST_BASE_SRC_PAD (basesrc));
+ if (!caps)
caps = gst_caps_new_any ();
GST_OBJECT_UNLOCK (src);
/* This is only correct because GstBaseSrc already clips size for us to be no
* larger than the max. available size if a segment at the end is requested */
if (offset + size > gst_buffer_get_size (src->buffer)) {
- ret = GST_FLOW_UNEXPECTED;
- } else {
+ ret = GST_FLOW_EOS;
+ } else if (*buf != NULL) {
+ GstMapInfo src_info;
+ GstMapInfo dest_info;
+ gsize fill_size;
+
+ gst_buffer_map (src->buffer, &src_info, GST_MAP_READ);
+ gst_buffer_map (*buf, &dest_info, GST_MAP_WRITE);
+
+ fill_size = gst_buffer_fill (*buf, 0, src_info.data + offset, size);
+
+ gst_buffer_unmap (*buf, &dest_info);
+ gst_buffer_unmap (src->buffer, &src_info);
+ gst_buffer_set_size (*buf, fill_size);
ret = GST_FLOW_OK;
+ } else {
*buf =
gst_buffer_copy_region (src->buffer, GST_BUFFER_COPY_ALL, offset, size);
+ ret = GST_FLOW_OK;
}
GST_OBJECT_UNLOCK (src);
return GST_URI_SRC;
}
-static gchar **
+static const gchar *const *
gst_data_uri_src_get_protocols (GType type)
{
- static gchar *protocols[] = { (char *) "data", 0 };
+ static const gchar *protocols[] = { "data", 0 };
return protocols;
}
-static const gchar *
+static gchar *
gst_data_uri_src_get_uri (GstURIHandler * handler)
{
GstDataURISrc *src = GST_DATA_URI_SRC (handler);
+ gchar *src_uri = NULL;
- return src->uri;
+ GST_OBJECT_LOCK (src);
+ src_uri = g_strdup (src->uri);
+ GST_OBJECT_UNLOCK (src);
+ return src_uri;
}
static gboolean
-gst_data_uri_src_set_uri (GstURIHandler * handler, const gchar * uri)
+gst_data_uri_src_set_uri (GstURIHandler * handler, const gchar * uri,
+ GError ** error)
{
GstDataURISrc *src = GST_DATA_URI_SRC (handler);
gboolean ret = FALSE;
caps = gst_type_find_helper_for_buffer (GST_OBJECT (src), buffer, NULL);
if (!caps)
- caps = gst_caps_new_simple (mimetype, NULL);
+ caps = gst_caps_new_empty_simple (mimetype);
gst_base_src_set_caps (GST_BASE_SRC_CAST (src), caps);
gst_caps_unref (caps);
GST_OBJECT_LOCK (src);
gst_buffer_replace (&src->buffer, buffer);
+ gst_buffer_unref (buffer);
g_free (src->uri);
src->uri = g_strdup (orig_uri);
GST_OBJECT_UNLOCK (src);
GST_WARNING_OBJECT (src, "Can't set URI in %s state",
gst_element_state_get_name (GST_STATE (src)));
GST_OBJECT_UNLOCK (src);
+ g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_STATE,
+ "Changing the 'uri' property on dataurisrc while it is running "
+ "is not supported");
goto out;
}
invalid_uri:
{
GST_WARNING_OBJECT (src, "invalid URI '%s'", uri);
+ g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
+ "Invalid data URI");
goto out;
}
invalid_uri_encoded_data:
{
GST_WARNING_OBJECT (src, "Failed to parse data encoded in URI '%s'", uri);
+ g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
+ "Could not parse data encoded in data URI");
goto out;
}
}
iface->get_uri = gst_data_uri_src_get_uri;
iface->set_uri = gst_data_uri_src_set_uri;
}
-
-static gboolean
-plugin_init (GstPlugin * plugin)
-{
- return gst_element_register (plugin, "dataurisrc",
- GST_RANK_PRIMARY, GST_TYPE_DATA_URI_SRC);
-}
-
-GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- "dataurisrc",
- "data: URI source",
- plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);