From: <sl...@ke...> - 2007-09-21 17:08:07
|
CVS Root: /cvs/gstreamer Module: gst-plugins-bad Changes by: slomo Date: Fri Sep 21 2007 17:08:10 UTC Log message: Patch by: René Stadler <mail at renestadler dot de> * configure.ac: * ext/Makefile.am: * ext/gio/Makefile.am: * ext/gio/gstgio.c: (gst_gio_error), (gst_gio_seek), (gst_gio_get_supported_protocols), (gst_gio_uri_handler_get_type_sink), (gst_gio_uri_handler_get_type_src), (gst_gio_uri_handler_get_protocols), (gst_gio_uri_handler_get_uri), (gst_gio_uri_handler_set_uri), (gst_gio_uri_handler_init), (gst_gio_uri_handler_do_init), (plugin_init): * ext/gio/gstgio.h: * ext/gio/gstgiosink.c: (gst_gio_sink_base_init), (gst_gio_sink_class_init), (gst_gio_sink_init), (gst_gio_sink_finalize), (gst_gio_sink_set_property), (gst_gio_sink_get_property), (gst_gio_sink_start), (gst_gio_sink_stop), (gst_gio_sink_unlock), (gst_gio_sink_unlock_stop), (gst_gio_sink_event), (gst_gio_sink_render), (gst_gio_sink_query): * ext/gio/gstgiosink.h: * ext/gio/gstgiosrc.c: (gst_gio_src_base_init), (gst_gio_src_class_init), (gst_gio_src_init), (gst_gio_src_finalize), (gst_gio_src_set_property), (gst_gio_src_get_property), (gst_gio_src_start), (gst_gio_src_stop), (gst_gio_src_get_size), (gst_gio_src_is_seekable), (gst_gio_src_unlock), (gst_gio_src_unlock_stop), (gst_gio_src_check_get_range), (gst_gio_src_create): * ext/gio/gstgiosrc.h: Add a GIO/GVFS plugin with source and sink elements. This will only be enabled when --enable-experimental is given to configure for now as the GIO API is not stable yet. Fixes #476916. Modified files: . : ChangeLog configure.ac ext : Makefile.am Added files: ext/gio : Makefile.am gstgio.c gstgio.h gstgiosink.c gstgiosink.h gstgiosrc.c gstgiosrc.h Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ChangeLog.diff?r1=1.2766&r2=1.2767 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/configure.ac.diff?r1=1.778&r2=1.779 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/Makefile.am.diff?r1=1.196&r2=1.197 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/gio/Makefile.am?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/gio/gstgio.c?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/gio/gstgio.h?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/gio/gstgiosink.c?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/gio/gstgiosink.h?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/gio/gstgiosrc.c?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/gio/gstgiosrc.h?rev=1.1&content-type=text/vnd.viewcvs-markup ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /cvs/gstreamer/gst-plugins-bad/ChangeLog,v retrieving revision 1.2766 retrieving revision 1.2767 diff -u -d -r1.2766 -r1.2767 --- ChangeLog 21 Sep 2007 14:55:17 -0000 1.2766 +++ ChangeLog 21 Sep 2007 17:07:53 -0000 1.2767 @@ -1,3 +1,39 @@ +2007-09-21 Sebastian Dröge <sl...@ci...> + + Patch by: René Stadler <mail at renestadler dot de> + * configure.ac: + * ext/Makefile.am: + * ext/gio/Makefile.am: + * ext/gio/gstgio.c: (gst_gio_error), (gst_gio_seek), + (gst_gio_get_supported_protocols), + (gst_gio_uri_handler_get_type_sink), + (gst_gio_uri_handler_get_type_src), + (gst_gio_uri_handler_get_protocols), (gst_gio_uri_handler_get_uri), + (gst_gio_uri_handler_set_uri), (gst_gio_uri_handler_init), + (gst_gio_uri_handler_do_init), (plugin_init): + * ext/gio/gstgio.h: + * ext/gio/gstgiosink.c: (gst_gio_sink_base_init), + (gst_gio_sink_class_init), (gst_gio_sink_init), + (gst_gio_sink_finalize), (gst_gio_sink_set_property), + (gst_gio_sink_get_property), (gst_gio_sink_start), + (gst_gio_sink_stop), (gst_gio_sink_unlock), + (gst_gio_sink_unlock_stop), (gst_gio_sink_event), + (gst_gio_sink_render), (gst_gio_sink_query): + * ext/gio/gstgiosink.h: + * ext/gio/gstgiosrc.c: (gst_gio_src_base_init), + (gst_gio_src_class_init), (gst_gio_src_init), + (gst_gio_src_finalize), (gst_gio_src_set_property), + (gst_gio_src_get_property), (gst_gio_src_start), + (gst_gio_src_stop), (gst_gio_src_get_size), + (gst_gio_src_is_seekable), (gst_gio_src_unlock), + (gst_gio_src_unlock_stop), (gst_gio_src_check_get_range), + (gst_gio_src_create): + * ext/gio/gstgiosrc.h: + Add a GIO/GVFS plugin with source and sink elements. This will + only be enabled when --enable-experimental is given to configure + for now as the GIO API is not stable yet. Fixes #476916. 2007-09-21 Thijs Vermeir <thi...@gm...> * gst/librfb/gstrfbsrc.c: Index: configure.ac RCS file: /cvs/gstreamer/gst-plugins-bad/configure.ac,v retrieving revision 1.778 retrieving revision 1.779 diff -u -d -r1.778 -r1.779 --- configure.ac 9 Sep 2007 18:22:53 -0000 1.778 +++ configure.ac 21 Sep 2007 17:07:54 -0000 1.779 @@ -122,7 +122,7 @@ AG_GST_ARG_ENABLE_EXPERIMENTAL -USE_TARKIN=$BUILD_EXPERIMENTAL +USE_GIO=$BUILD_EXPERIMENTAL dnl *** checks for platform *** @@ -278,7 +278,6 @@ AC_SUBST(GST_PLUGINS_SELECTED) - dnl *** sys plug-ins *** dnl OpenGL @@ -331,7 +330,6 @@ CPPFLAGS="$ac_cppflags_save" ]) dnl *** ext plug-ins *** dnl keep this list sorted alphabetically ! @@ -531,6 +529,17 @@ AC_SUBST(FAAD_IS_NEAAC) +dnl *** libgio *** +translit(dnm, m, l) AM_CONDITIONAL(USE_GIO, true) +AG_GST_CHECK_FEATURE(GIO, [GIO standalone library], gio, [ + PKG_CHECK_MODULES(GIO, gio-standalone >= 0.0.1, HAVE_GIO="yes", [ + HAVE_GIO="no" + AC_MSG_RESULT(no) + ]) + AC_SUBST(GIO_CFLAGS) + AC_SUBST(GIO_LIBS) +]) dnl *** gsm *** translit(dnm, m, l) AM_CONDITIONAL(USE_GSM, true) AG_GST_CHECK_FEATURE(GSM, [GSM library], gsmenc gsmdec, [ @@ -899,6 +908,7 @@ AM_CONDITIONAL(USE_DIVX, false) AM_CONDITIONAL(USE_FAAC, false) AM_CONDITIONAL(USE_FAAD, false) +AM_CONDITIONAL(USE_GIO, false) AM_CONDITIONAL(USE_GSM, false) AM_CONDITIONAL(USE_IVORBIS, false) AM_CONDITIONAL(USE_JACK, false) @@ -1029,6 +1039,7 @@ ext/dts/Makefile ext/faac/Makefile ext/faad/Makefile +ext/gio/Makefile ext/gsm/Makefile ext/ivorbis/Makefile ext/jack/Makefile Index: Makefile.am RCS file: /cvs/gstreamer/gst-plugins-bad/ext/Makefile.am,v retrieving revision 1.196 retrieving revision 1.197 diff -u -d -r1.196 -r1.197 --- Makefile.am 29 Jun 2007 13:03:27 -0000 1.196 +++ Makefile.am 21 Sep 2007 17:07:55 -0000 1.197 @@ -88,6 +88,12 @@ FAAD_DIR= endif +if USE_GIO +GIO_DIR=gio +else +GIO_DIR= +endif if USE_GSM GSM_DIR=gsm else @@ -278,6 +284,7 @@ $(DTS_DIR) \ $(FAAC_DIR) \ $(FAAD_DIR) \ + $(GIO_DIR) \ $(GSM_DIR) \ $(HERMES_DIR) \ $(IVORBIS_DIR) \ @@ -317,6 +324,7 @@ directfb \ faac \ faad \ + gio \ gsm \ ivorbis \ ladspa \ --- NEW FILE: Makefile.am --- # plugindir is set in configure plugin_LTLIBRARIES = libgstgio.la # sources used to compile this plug-in libgstgio_la_SOURCES = gstgio.c gstgiosink.c gstgiosrc.c libgstgio_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GIO_CFLAGS) libgstgio_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) $(GIO_LIBS) libgstgio_la_LDFLAGS = $(GST_GIO_LDFLAGS) # headers we need but don't want installed noinst_HEADERS = gstgio.h gstgiosink.h gstgiosrc.h --- NEW FILE: gstgio.c --- /* GStreamer * * Copyright (C) 2007 Rene Stadler <ma...@re...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * 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. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "gstgio.h" #include "gstgiosink.h" #include "gstgiosrc.h" #include <gio/gvfs.h> GST_DEBUG_CATEGORY_STATIC (gst_gio_debug); #define GST_CAT_DEFAULT gst_gio_debug /* @func_name: Name of the GIO function, for debugging messages. * @err: Error location. *err may be NULL, but err must be non-NULL. * @ret: Flow return location. May be NULL. Is set to either #GST_FLOW_ERROR * or #GST_FLOW_WRONG_STATE. * Returns: TRUE to indicate a handled error. Error at given location err will * be freed and *err will be set to NULL. A FALSE return indicates an unhandled * error: The err location is unchanged and guaranteed to be != NULL. ret, if * given, is set to GST_FLOW_ERROR. gboolean gst_gio_error (gpointer element, const gchar * func_name, GError ** err, GstFlowReturn * ret) { gboolean handled = TRUE; if (ret) *ret = GST_FLOW_ERROR; if (GST_GIO_ERROR_MATCHES (*err, CANCELLED)) { GST_DEBUG_OBJECT (element, "blocking I/O call cancelled (%s)", func_name); if (ret) *ret = GST_FLOW_WRONG_STATE; } else if (*err != NULL) { handled = FALSE; } else { GST_ELEMENT_ERROR (element, LIBRARY, FAILED, (NULL), ("%s call failed without error set", func_name)); } if (handled) g_clear_error (err); return handled; } GstFlowReturn gst_gio_seek (gpointer element, GSeekable * stream, guint64 offset, GCancellable * cancel) gboolean success; GstFlowReturn ret; GError *err = NULL; GST_LOG_OBJECT (element, "seeking to offset %" G_GINT64_FORMAT, offset); success = g_seekable_seek (stream, offset, G_SEEK_SET, cancel, &err); if (success) ret = GST_FLOW_OK; else if (!gst_gio_error (element, "g_seekable_seek", &err, &ret)) { GST_ELEMENT_ERROR (element, RESOURCE, SEEK, (NULL), ("Could not seek: %s", err->message)); g_clear_error (&err); return ret; static gchar ** gst_gio_get_supported_protocols (void) /* FIXME: Figure out supported schemes enumeration method for GIO. */ const gchar *protocols[] = { "file", "ftp", "sftp", "smb", NULL }; return g_strdupv ((gchar **) protocols); static GstURIType gst_gio_uri_handler_get_type_sink (void) return GST_URI_SINK; gst_gio_uri_handler_get_type_src (void) return GST_URI_SRC; gst_gio_uri_handler_get_protocols (void) static gchar **protocols = NULL; if (!protocols) protocols = gst_gio_get_supported_protocols (); return protocols; static const gchar * gst_gio_uri_handler_get_uri (GstURIHandler * handler) GstElement *element = GST_ELEMENT (handler); const gchar *uri; g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE); g_object_get (G_OBJECT (element), "location", &uri, NULL); return uri; static gboolean gst_gio_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri) if (GST_STATE (element) == GST_STATE_PLAYING || GST_STATE (element) == GST_STATE_PAUSED) return FALSE; g_object_set (G_OBJECT (element), "location", uri, NULL); return TRUE; static void gst_gio_uri_handler_init (gpointer g_iface, gpointer iface_data) GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; gboolean sink = GPOINTER_TO_INT (iface_data); /* See in do_init below. */ if (sink) iface->get_type = gst_gio_uri_handler_get_type_sink; else iface->get_type = gst_gio_uri_handler_get_type_src; iface->get_protocols = gst_gio_uri_handler_get_protocols; iface->get_uri = gst_gio_uri_handler_get_uri; iface->set_uri = gst_gio_uri_handler_set_uri; void gst_gio_uri_handler_do_init (GType type) GInterfaceInfo uri_handler_info = { gst_gio_uri_handler_init, NULL, NULL }; /* Store information for uri_handler_init to use for distinguishing the * element types. This lets us use a single interface implementation for both * classes. */ uri_handler_info.interface_data = GINT_TO_POINTER (g_type_is_a (type, GST_TYPE_BASE_SINK)); g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &uri_handler_info); plugin_init (GstPlugin * plugin) gboolean ret = TRUE; GST_DEBUG_CATEGORY_INIT (gst_gio_debug, "gio", 0, "GIO elements"); /* FIXME: This is needed to prevent a crash. Needs further investigation * probably. */ if (g_vfs_get_default () == NULL) { GST_WARNING ("Failed to initialize default VFS, not registering plugin"); /* FIXME: Rank is MARGINAL for now, should be at least SECONDARY+1 in the future * to replace gnomevfssink/src. For testing purposes PRIMARY+1 one makes sense * so it gets autoplugged and preferred over filesrc/sink. */ ret &= gst_element_register (plugin, "giosink", GST_RANK_MARGINAL, GST_TYPE_GIO_SINK); ret &= gst_element_register (plugin, "giosrc", GST_RANK_MARGINAL, GST_TYPE_GIO_SRC); GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "gio", "GIO elements", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) --- NEW FILE: gstgio.h --- #ifndef __GSTGIO_H__ #define __GSTGIO_H__ #include <gio/gioerror.h> #include <gio/gseekable.h> #include <gst/gst.h> G_BEGIN_DECLS #define GST_GIO_ERROR_MATCHES(err, code) g_error_matches (err, G_IO_ERROR, G_IO_ERROR_##code) gboolean gst_gio_error (gpointer element, const gchar *func_name, GError **err, GstFlowReturn *ret); GstFlowReturn gst_gio_seek (gpointer element, GSeekable *stream, guint64 offset, GCancellable *cancel); void gst_gio_uri_handler_do_init (GType type); G_END_DECLS #endif /* __GSTGIO_H__ */ --- NEW FILE: gstgiosink.c --- /** * SECTION:element-giosink * <refsect2> * <title>Example launch line</title> * <para> * <programlisting> * gst-launch audiotestsrc num-buffers=100 ! flacenc ! giosink location=file:///home/foo/bar.flac * </programlisting> * </para> * </refsect2> #include <config.h> GST_DEBUG_CATEGORY_STATIC (gst_gio_sink_debug); #define GST_CAT_DEFAULT gst_gio_sink_debug /* Filter signals and args */ enum LAST_SIGNAL }; ARG_0, ARG_LOCATION static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("ANY") ); GST_BOILERPLATE_FULL (GstGioSink, gst_gio_sink, GstBaseSink, GST_TYPE_BASE_SINK, gst_gio_uri_handler_do_init); static void gst_gio_sink_finalize (GObject * object); static void gst_gio_sink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_gio_sink_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static gboolean gst_gio_sink_start (GstBaseSink * base_sink); static gboolean gst_gio_sink_stop (GstBaseSink * base_sink); static gboolean gst_gio_sink_unlock (GstBaseSink * base_sink); static gboolean gst_gio_sink_unlock_stop (GstBaseSink * base_sink); static gboolean gst_gio_sink_event (GstBaseSink * base_sink, GstEvent * event); static GstFlowReturn gst_gio_sink_render (GstBaseSink * base_sink, GstBuffer * buffer); static gboolean gst_gio_sink_query (GstPad * pad, GstQuery * query); gst_gio_sink_base_init (gpointer gclass) static GstElementDetails element_details = { "GIO sink", "Sink/File", "Write to any GVFS-supported location", "Ren\xc3\xa9 Stadler <ma...@re...>" GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); GST_DEBUG_CATEGORY_INIT (gst_gio_sink_debug, "giosink", 0, "GIO source"); gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&sink_factory)); gst_element_class_set_details (element_class, &element_details); gst_gio_sink_class_init (GstGioSinkClass * klass) GObjectClass *gobject_class; GstElementClass *gstelement_class; GstBaseSinkClass *gstbasesink_class; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; gstbasesink_class = (GstBaseSinkClass *) klass; gobject_class->finalize = gst_gio_sink_finalize; gobject_class->set_property = gst_gio_sink_set_property; gobject_class->get_property = gst_gio_sink_get_property; g_object_class_install_property (gobject_class, ARG_LOCATION, g_param_spec_string ("location", "Location", "URI location to write to", NULL, G_PARAM_READWRITE)); gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_gio_sink_start); gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_gio_sink_stop); gstbasesink_class->unlock = GST_DEBUG_FUNCPTR (gst_gio_sink_unlock); gstbasesink_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_gio_sink_unlock_stop); gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_gio_sink_event); gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_gio_sink_render); gst_gio_sink_init (GstGioSink * sink, GstGioSinkClass * gclass) gst_pad_set_query_function (GST_BASE_SINK_PAD (sink), GST_DEBUG_FUNCPTR (gst_gio_sink_query)); GST_BASE_SINK (sink)->sync = FALSE; sink->cancel = g_cancellable_new (); gst_gio_sink_finalize (GObject * object) GstGioSink *sink = GST_GIO_SINK (object); g_object_unref (sink->cancel); if (sink->file) g_object_unref (sink->file); g_free (sink->location); GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); gst_gio_sink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) switch (prop_id) { case ARG_LOCATION: g_free (sink->location); sink->location = g_strdup (g_value_get_string (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); gst_gio_sink_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) g_value_set_string (value, sink->location); gst_gio_sink_start (GstBaseSink * base_sink) GstGioSink *sink = GST_GIO_SINK (base_sink); if (sink->location == NULL) { GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("No location given")); sink->file = g_file_new_for_uri (sink->location); if (sink->file == NULL) { ("Malformed URI or protocol not supported (%s)", sink->location)); sink->stream = g_file_create (sink->file, sink->cancel, &err); success = (sink->stream != NULL); if (!success && !gst_gio_error (sink, "g_file_create", &err, NULL)) { /*if (GST_GIO_ERROR_MATCHES (err, EXISTS)) */ /* FIXME: Retry with replace if overwrite == TRUE! */ if (GST_GIO_ERROR_MATCHES (err, NOT_FOUND)) GST_ELEMENT_ERROR (sink, RESOURCE, NOT_FOUND, (NULL), ("Could not open location %s for writing: %s", sink->location, err->message)); else GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ, (NULL), if (!success) { sink->file = NULL; sink->position = 0; GST_DEBUG_OBJECT (sink, "opened location %s", sink->location); gst_gio_sink_stop (GstBaseSink * base_sink) gboolean success = TRUE; if (sink->file != NULL) { if (sink->stream != NULL) { /* FIXME: In case that the call below would block, there is no one to * trigger the cancellation! */ success = g_output_stream_close (G_OUTPUT_STREAM (sink->stream), sink->cancel, &err); if (success) { GST_DEBUG_OBJECT (sink, "closed location %s", sink->location); } else if (!gst_gio_error (sink, "g_output_stream_close", &err, NULL)) { GST_ELEMENT_ERROR (sink, RESOURCE, CLOSE, (NULL), ("g_output_stream_close failed: %s", err->message)); g_clear_error (&err); } g_object_unref (sink->stream); sink->stream = NULL; return success; gst_gio_sink_unlock (GstBaseSink * base_sink) GST_LOG_OBJECT (sink, "triggering cancellation"); g_cancellable_cancel (sink->cancel); gst_gio_sink_unlock_stop (GstBaseSink * base_sink) GST_LOG_OBJECT (sink, "restoring cancellable"); gst_gio_sink_event (GstBaseSink * base_sink, GstEvent * event) GstFlowReturn ret = GST_FLOW_OK; if (sink->stream == NULL) return TRUE; switch (GST_EVENT_TYPE (event)) { case GST_EVENT_NEWSEGMENT: { GstFormat format; gint64 offset; gst_event_parse_new_segment (event, NULL, NULL, &format, &offset, NULL, NULL); if (format != GST_FORMAT_BYTES) { GST_WARNING_OBJECT (sink, "ignored NEWSEGMENT event in %s format", gst_format_get_name (format)); break; } ret = gst_gio_seek (sink, G_SEEKABLE (sink->stream), offset, sink->cancel); if (ret == GST_FLOW_OK) sink->position = offset; case GST_EVENT_EOS: case GST_EVENT_FLUSH_START: gboolean success; GError *err = NULL; success = g_output_stream_flush (G_OUTPUT_STREAM (sink->stream), sink->cancel, &err); if (!success && !gst_gio_error (sink, "g_output_stream_flush", &err, &ret)) { GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL), ("flush failed: %s", err->message)); g_clear_error (&err); return (ret == GST_FLOW_OK); static GstFlowReturn gst_gio_sink_render (GstBaseSink * base_sink, GstBuffer * buffer) gssize written; GST_LOG_OBJECT (sink, "writing %u bytes to offset %" G_GUINT64_FORMAT, GST_BUFFER_SIZE (buffer), sink->position); written = g_output_stream_write (G_OUTPUT_STREAM (sink->stream), GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), sink->cancel, &err); success = (written >= 0); if (G_UNLIKELY (success && written < GST_BUFFER_SIZE (buffer))) { /* FIXME: Can this happen? Should we handle it gracefully? gnomevfssink * doesn't... */ GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL), ("Could not write to location %s: (short write)", sink->location)); return GST_FLOW_ERROR; if (success) { sink->position += written; return GST_FLOW_OK; GstFlowReturn ret; if (!gst_gio_error (sink, "g_output_stream_write", &err, &ret)) { GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL), ("Could not write to location %s: %s", sink->location, err->message)); return ret; gst_gio_sink_query (GstPad * pad, GstQuery * query) GstGioSink *sink = GST_GIO_SINK (GST_PAD_PARENT (pad)); GstFormat format; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: gst_query_parse_position (query, &format, NULL); switch (format) { case GST_FORMAT_BYTES: case GST_FORMAT_DEFAULT: gst_query_set_position (query, GST_FORMAT_BYTES, sink->position); return TRUE; default: return FALSE; case GST_QUERY_FORMATS: gst_query_set_formats (query, 2, GST_FORMAT_DEFAULT, GST_FORMAT_BYTES); return TRUE; return gst_pad_query_default (pad, query); --- NEW FILE: gstgiosink.h --- #ifndef __GSTGIOSINK_H__ #define __GSTGIOSINK_H__ #include <gio/gfile.h> #include <gst/base/gstbasesink.h> #define GST_TYPE_GIO_SINK \ (gst_gio_sink_get_type()) #define GST_GIO_SINK(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GIO_SINK,GstGioSink)) #define GST_GIO_SINK_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GIO_SINK,GstGioSinkClass)) #define GST_IS_GIO_SINK(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GIO_SINK)) #define GST_IS_GIO_SINK_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GIO_SINK)) typedef struct _GstGioSink GstGioSink; typedef struct _GstGioSinkClass GstGioSinkClass; struct _GstGioSink GstBaseSink sink; GCancellable *cancel; GFile *file; gchar *location; guint64 position; GFileOutputStream *stream; struct _GstGioSinkClass GstBaseSinkClass parent_class; GType gst_gio_sink_get_type (void); #endif /* __GSTGIOSINK_H__ */ --- NEW FILE: gstgiosrc.c --- * SECTION:element-giosrc * gst-launch giosrc location=file:///home/foo/bar.ext ! fakesink GST_DEBUG_CATEGORY_STATIC (gst_gio_src_debug); #define GST_CAT_DEFAULT gst_gio_src_debug static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_BOILERPLATE_FULL (GstGioSrc, gst_gio_src, GstBaseSrc, GST_TYPE_BASE_SRC, static void gst_gio_src_finalize (GObject * object); static void gst_gio_src_set_property (GObject * object, guint prop_id, static void gst_gio_src_get_property (GObject * object, guint prop_id, static gboolean gst_gio_src_start (GstBaseSrc * base_src); static gboolean gst_gio_src_stop (GstBaseSrc * base_src); static gboolean gst_gio_src_get_size (GstBaseSrc * base_src, guint64 * size); static gboolean gst_gio_src_is_seekable (GstBaseSrc * base_src); static gboolean gst_gio_src_unlock (GstBaseSrc * base_src); static gboolean gst_gio_src_unlock_stop (GstBaseSrc * base_src); static gboolean gst_gio_src_check_get_range (GstBaseSrc * base_src); static GstFlowReturn gst_gio_src_create (GstBaseSrc * base_src, guint64 offset, guint size, GstBuffer ** buf); gst_gio_src_base_init (gpointer gclass) "GIO source", "Source/File", "Read from any GVFS-supported location", GST_DEBUG_CATEGORY_INIT (gst_gio_src_debug, "giosrc", 0, "GIO source"); gst_static_pad_template_get (&src_factory)); gst_gio_src_class_init (GstGioSrcClass * klass) GstBaseSrcClass *gstbasesrc_class; gstbasesrc_class = (GstBaseSrcClass *) klass; gobject_class->finalize = gst_gio_src_finalize; gobject_class->set_property = gst_gio_src_set_property; gobject_class->get_property = gst_gio_src_get_property; g_param_spec_string ("location", "Location", "URI location to read from", gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_gio_src_start); gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_gio_src_stop); gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_gio_src_get_size); gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_gio_src_is_seekable); gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_gio_src_unlock); gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_gio_src_unlock_stop); gstbasesrc_class->check_get_range = GST_DEBUG_FUNCPTR (gst_gio_src_check_get_range); gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_gio_src_create); gst_gio_src_init (GstGioSrc * src, GstGioSrcClass * gclass) src->cancel = g_cancellable_new (); gst_gio_src_finalize (GObject * object) GstGioSrc *src = GST_GIO_SRC (object); g_object_unref (src->cancel); if (src->file) g_object_unref (src->file); g_free (src->location); gst_gio_src_set_property (GObject * object, guint prop_id, g_free (src->location); src->location = g_strdup (g_value_get_string (value)); gst_gio_src_get_property (GObject * object, guint prop_id, g_value_set_string (value, src->location); gst_gio_src_start (GstBaseSrc * base_src) GstGioSrc *src = GST_GIO_SRC (base_src); if (src->location == NULL) { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("No location given")); src->file = g_file_new_for_uri (src->location); if (src->file == NULL) { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("Malformed URI or protocol not supported (%s)", src->location)); src->stream = g_file_read (src->file, src->cancel, &err); if (src->stream == NULL && !gst_gio_error (src, "g_file_read", &err, NULL)) { GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), ("Could not open location %s for reading: %s", src->location, err->message)); GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), src->file = NULL; } else if (src->stream == NULL) src->position = 0; GST_DEBUG_OBJECT (src, "opened location %s", src->location); gst_gio_src_stop (GstBaseSrc * base_src) if (src->stream != NULL) { success = g_input_stream_close (G_INPUT_STREAM (src->stream), src->cancel, &err); if (!success && !gst_gio_error (src, "g_input_stream_close", &err, NULL)) { GST_ELEMENT_ERROR (src, RESOURCE, CLOSE, (NULL), ("g_input_stream_close failed: %s", err->message)); g_object_unref (src->stream); src->stream = NULL; if (src->file != NULL) { GST_DEBUG_OBJECT (src, "closed location %s", src->location); gst_gio_src_get_size (GstBaseSrc * base_src, guint64 * size) GFileInfo *info; info = g_file_input_stream_query_info (src->stream, G_FILE_ATTRIBUTE_STD_SIZE, src->cancel, &err); if (info != NULL) { *size = g_file_info_get_size (info); g_object_unref (info); GST_DEBUG_OBJECT (src, "found size: %" G_GUINT64_FORMAT, *size); if (!gst_gio_error (src, "g_file_input_stream_query_info", &err, NULL)) { if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED)) GST_DEBUG_OBJECT (src, "size information not available"); GST_WARNING_OBJECT (src, "size information retrieval failed: %s", err->message); return FALSE; gst_gio_src_is_seekable (GstBaseSrc * base_src) gboolean seekable; seekable = g_seekable_can_seek (G_SEEKABLE (src->stream)); GST_DEBUG_OBJECT (src, "can seek: %d", seekable); return seekable; gst_gio_src_unlock (GstBaseSrc * base_src) GST_LOG_OBJECT (src, "triggering cancellation"); g_cancellable_cancel (src->cancel); gst_gio_src_unlock_stop (GstBaseSrc * base_src) GST_LOG_OBJECT (src, "restoring cancellable"); gst_gio_src_check_get_range (GstBaseSrc * base_src) /* FIXME: Implement dry-run variant using guesswork like gnomevfssrc? */ return GST_CALL_PARENT_WITH_DEFAULT (GST_BASE_SRC_CLASS, check_get_range, (base_src), FALSE); gst_gio_src_create (GstBaseSrc * base_src, guint64 offset, guint size, GstBuffer ** buf_return) GstBuffer *buf; gssize read; gboolean success, eos; if (G_UNLIKELY (offset != src->position)) { ret = gst_gio_seek (src, G_SEEKABLE (src->stream), offset, src->cancel); if (ret == GST_FLOW_OK) src->position = offset; return ret; buf = gst_buffer_new_and_alloc (size); GST_LOG_OBJECT (src, "reading %u bytes from offset %" G_GUINT64_FORMAT, size, offset); read = g_input_stream_read (G_INPUT_STREAM (src->stream), GST_BUFFER_DATA (buf), size, src->cancel, &err); success = (read >= 0); eos = (size > 0 && read == 0); if (!success && !gst_gio_error (src, "g_input_stream_read", &err, &ret)) { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Could not read from location %s: %s", src->location, err->message)); if (success && !eos) { src->position += read; GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_SIZE (buf) = read; *buf_return = buf; /* !success || eos */ gst_buffer_unref (buf); if (eos) ret = GST_FLOW_UNEXPECTED; --- NEW FILE: gstgiosrc.h --- #ifndef __GSTGIOSRC_H__ #define __GSTGIOSRC_H__ #include <gst/base/gstbasesrc.h> #define GST_TYPE_GIO_SRC \ (gst_gio_src_get_type()) #define GST_GIO_SRC(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GIO_SRC,GstGioSrc)) #define GST_GIO_SRC_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GIO_SRC,GstGioSrcClass)) #define GST_IS_GIO_SRC(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GIO_SRC)) #define GST_IS_GIO_SRC_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GIO_SRC)) typedef struct _GstGioSrc GstGioSrc; typedef struct _GstGioSrcClass GstGioSrcClass; struct _GstGioSrc GstBaseSrc src; GFileInputStream *stream; struct _GstGioSrcClass GstBaseSrcClass parent_class; GType gst_gio_src_get_type (void); #endif /* __GSTGIOSRC_H__ */ |