diff --git a/ChangeLog b/ChangeLog index 8716011e07..4ebd358e4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-11-21 Jan Schmidt + + * gst/elements/gstfdsrc.c: (_do_init), (gst_fdsrc_class_init), + (gst_fdsrc_init), (gst_fdsrc_dispose), (gst_fdsrc_set_property), + (gst_fdsrc_uri_get_type), (gst_fdsrc_uri_get_protocols), + (gst_fdsrc_uri_get_uri), (gst_fdsrc_uri_set_uri), + (gst_fdsrc_uri_handler_init): + * gst/elements/gstfdsrc.h: + Port fd:// URI handler from 0.8 to fdsrc + 2005-11-21 Tim-Philipp Müller * gst/gstvalue.c: (gst_value_transform_fourcc_string), diff --git a/gst/elements/gstfdsrc.c b/gst/elements/gstfdsrc.c index 9d751ac673..2c7795ee32 100644 --- a/gst/elements/gstfdsrc.c +++ b/gst/elements/gstfdsrc.c @@ -34,6 +34,9 @@ #ifdef HAVE_UNISTD_H #include #endif +#ifdef _MSC_VER +#include +#endif #include #include @@ -72,15 +75,28 @@ static GstElementDetails gst_fdsrc_details = GST_ELEMENT_DETAILS ("Disk Source", "Synchronous read from a file", "Erik Walthinsen "); - enum { PROP_0, PROP_FD, }; -#define _do_init(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_fdsrc_debug, "fdsrc", 0, "fdsrc element"); +static void gst_fdsrc_uri_handler_init (gpointer g_iface, gpointer iface_data); + +static void +_do_init (GType fdsrc_type) +{ + static const GInterfaceInfo urihandler_info = { + gst_fdsrc_uri_handler_init, + NULL, + NULL + }; + + g_type_add_interface_static (fdsrc_type, GST_TYPE_URI_HANDLER, + &urihandler_info); + + GST_DEBUG_CATEGORY_INIT (gst_fdsrc_debug, "fdsrc", 0, "fdsrc element"); +} GST_BOILERPLATE_FULL (GstFdSrc, gst_fdsrc, GstElement, GST_TYPE_PUSH_SRC, _do_init); @@ -89,6 +105,7 @@ static void gst_fdsrc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_fdsrc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static void gst_fdsrc_dispose (GObject * obj); static gboolean gst_fdsrc_start (GstBaseSrc * bsrc); static gboolean gst_fdsrc_stop (GstBaseSrc * bsrc); @@ -123,6 +140,7 @@ gst_fdsrc_class_init (GstFdSrcClass * klass) gobject_class->set_property = gst_fdsrc_set_property; gobject_class->get_property = gst_fdsrc_get_property; + gobject_class->dispose = gst_fdsrc_dispose; g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_FD, g_param_spec_int ("fd", "fd", "An open file descriptor to read from", @@ -143,9 +161,21 @@ gst_fdsrc_init (GstFdSrc * fdsrc, GstFdSrcClass * klass) gst_base_src_set_live (GST_BASE_SRC (fdsrc), TRUE); fdsrc->fd = 0; + fdsrc->uri = g_strdup_printf ("fd://%d", fdsrc->fd); fdsrc->curoffset = 0; } +static void +gst_fdsrc_dispose (GObject * obj) +{ + GstFdSrc *src = GST_FDSRC (obj); + + g_free (src->uri); + src->uri = NULL; + + G_OBJECT_CLASS (parent_class)->dispose (obj); +} + static gboolean gst_fdsrc_start (GstBaseSrc * bsrc) { @@ -204,6 +234,8 @@ gst_fdsrc_set_property (GObject * object, guint prop_id, const GValue * value, switch (prop_id) { case PROP_FD: src->fd = g_value_get_int (value); + g_free (src->uri); + src->uri = g_strdup_printf ("fd://%d", src->fd); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -328,3 +360,57 @@ read_error: return GST_FLOW_ERROR; } } + +/*** GSTURIHANDLER INTERFACE *************************************************/ + +static guint +gst_fdsrc_uri_get_type (void) +{ + return GST_URI_SRC; +} +static gchar ** +gst_fdsrc_uri_get_protocols (void) +{ + static gchar *protocols[] = { "fd", NULL }; + + return protocols; +} +static const gchar * +gst_fdsrc_uri_get_uri (GstURIHandler * handler) +{ + GstFdSrc *src = GST_FDSRC (handler); + + return src->uri; +} + +static gboolean +gst_fdsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri) +{ + gchar *protocol; + GstFdSrc *src = GST_FDSRC (handler); + gint fd = src->fd; + + protocol = gst_uri_get_protocol (uri); + if (strcmp (protocol, "fd") != 0) { + g_free (protocol); + return FALSE; + } + g_free (protocol); + sscanf (uri, "fd://%d", &fd); + src->fd = fd; + g_free (src->uri); + src->uri = g_strdup (uri); + + return TRUE; +} + +static void +gst_fdsrc_uri_handler_init (gpointer g_iface, gpointer iface_data) +{ + GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; + + iface->get_type = gst_fdsrc_uri_get_type; + iface->get_protocols = gst_fdsrc_uri_get_protocols; + iface->get_uri = gst_fdsrc_uri_get_uri; + iface->set_uri = gst_fdsrc_uri_set_uri; +} diff --git a/gst/elements/gstfdsrc.h b/gst/elements/gstfdsrc.h index 4075d33de8..32e0938176 100644 --- a/gst/elements/gstfdsrc.h +++ b/gst/elements/gstfdsrc.h @@ -55,6 +55,8 @@ struct _GstFdSrc { gint control_sock[2]; gulong curoffset; /* current offset in file */ + + gchar *uri; }; struct _GstFdSrcClass { diff --git a/plugins/elements/gstfdsrc.c b/plugins/elements/gstfdsrc.c index 9d751ac673..2c7795ee32 100644 --- a/plugins/elements/gstfdsrc.c +++ b/plugins/elements/gstfdsrc.c @@ -34,6 +34,9 @@ #ifdef HAVE_UNISTD_H #include #endif +#ifdef _MSC_VER +#include +#endif #include #include @@ -72,15 +75,28 @@ static GstElementDetails gst_fdsrc_details = GST_ELEMENT_DETAILS ("Disk Source", "Synchronous read from a file", "Erik Walthinsen "); - enum { PROP_0, PROP_FD, }; -#define _do_init(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_fdsrc_debug, "fdsrc", 0, "fdsrc element"); +static void gst_fdsrc_uri_handler_init (gpointer g_iface, gpointer iface_data); + +static void +_do_init (GType fdsrc_type) +{ + static const GInterfaceInfo urihandler_info = { + gst_fdsrc_uri_handler_init, + NULL, + NULL + }; + + g_type_add_interface_static (fdsrc_type, GST_TYPE_URI_HANDLER, + &urihandler_info); + + GST_DEBUG_CATEGORY_INIT (gst_fdsrc_debug, "fdsrc", 0, "fdsrc element"); +} GST_BOILERPLATE_FULL (GstFdSrc, gst_fdsrc, GstElement, GST_TYPE_PUSH_SRC, _do_init); @@ -89,6 +105,7 @@ static void gst_fdsrc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_fdsrc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static void gst_fdsrc_dispose (GObject * obj); static gboolean gst_fdsrc_start (GstBaseSrc * bsrc); static gboolean gst_fdsrc_stop (GstBaseSrc * bsrc); @@ -123,6 +140,7 @@ gst_fdsrc_class_init (GstFdSrcClass * klass) gobject_class->set_property = gst_fdsrc_set_property; gobject_class->get_property = gst_fdsrc_get_property; + gobject_class->dispose = gst_fdsrc_dispose; g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_FD, g_param_spec_int ("fd", "fd", "An open file descriptor to read from", @@ -143,9 +161,21 @@ gst_fdsrc_init (GstFdSrc * fdsrc, GstFdSrcClass * klass) gst_base_src_set_live (GST_BASE_SRC (fdsrc), TRUE); fdsrc->fd = 0; + fdsrc->uri = g_strdup_printf ("fd://%d", fdsrc->fd); fdsrc->curoffset = 0; } +static void +gst_fdsrc_dispose (GObject * obj) +{ + GstFdSrc *src = GST_FDSRC (obj); + + g_free (src->uri); + src->uri = NULL; + + G_OBJECT_CLASS (parent_class)->dispose (obj); +} + static gboolean gst_fdsrc_start (GstBaseSrc * bsrc) { @@ -204,6 +234,8 @@ gst_fdsrc_set_property (GObject * object, guint prop_id, const GValue * value, switch (prop_id) { case PROP_FD: src->fd = g_value_get_int (value); + g_free (src->uri); + src->uri = g_strdup_printf ("fd://%d", src->fd); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -328,3 +360,57 @@ read_error: return GST_FLOW_ERROR; } } + +/*** GSTURIHANDLER INTERFACE *************************************************/ + +static guint +gst_fdsrc_uri_get_type (void) +{ + return GST_URI_SRC; +} +static gchar ** +gst_fdsrc_uri_get_protocols (void) +{ + static gchar *protocols[] = { "fd", NULL }; + + return protocols; +} +static const gchar * +gst_fdsrc_uri_get_uri (GstURIHandler * handler) +{ + GstFdSrc *src = GST_FDSRC (handler); + + return src->uri; +} + +static gboolean +gst_fdsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri) +{ + gchar *protocol; + GstFdSrc *src = GST_FDSRC (handler); + gint fd = src->fd; + + protocol = gst_uri_get_protocol (uri); + if (strcmp (protocol, "fd") != 0) { + g_free (protocol); + return FALSE; + } + g_free (protocol); + sscanf (uri, "fd://%d", &fd); + src->fd = fd; + g_free (src->uri); + src->uri = g_strdup (uri); + + return TRUE; +} + +static void +gst_fdsrc_uri_handler_init (gpointer g_iface, gpointer iface_data) +{ + GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; + + iface->get_type = gst_fdsrc_uri_get_type; + iface->get_protocols = gst_fdsrc_uri_get_protocols; + iface->get_uri = gst_fdsrc_uri_get_uri; + iface->set_uri = gst_fdsrc_uri_set_uri; +} diff --git a/plugins/elements/gstfdsrc.h b/plugins/elements/gstfdsrc.h index 4075d33de8..32e0938176 100644 --- a/plugins/elements/gstfdsrc.h +++ b/plugins/elements/gstfdsrc.h @@ -55,6 +55,8 @@ struct _GstFdSrc { gint control_sock[2]; gulong curoffset; /* current offset in file */ + + gchar *uri; }; struct _GstFdSrcClass {