From 7e72ceb3f27de5cd19ce34cac238e898167a639a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 7 Jul 2009 20:23:23 +0200 Subject: gio: Add vfunc for requesting the stream for the sinks too --- ext/gio/gstgiobasesink.c | 15 +++++++++------ ext/gio/gstgiobasesink.h | 9 ++++++--- ext/gio/gstgiobasesrc.h | 4 +++- ext/gio/gstgiosink.c | 23 +++++++++++------------ ext/gio/gstgiosink.h | 2 +- ext/gio/gstgiostreamsink.c | 29 ++++++++++++++++++++++++----- ext/gio/gstgiostreamsink.h | 5 ++++- 7 files changed, 58 insertions(+), 29 deletions(-) (limited to 'ext/gio') diff --git a/ext/gio/gstgiobasesink.c b/ext/gio/gstgiobasesink.c index 4ef702c49..39d76cd37 100644 --- a/ext/gio/gstgiobasesink.c +++ b/ext/gio/gstgiobasesink.c @@ -1,7 +1,7 @@ /* GStreamer * * Copyright (C) 2007 Rene Stadler - * Copyright (C) 2007 Sebastian Dröge + * Copyright (C) 2007-2009 Sebastian Dröge * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -109,16 +109,19 @@ static gboolean gst_gio_base_sink_start (GstBaseSink * base_sink) { GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink); + GstGioBaseSinkClass *gbsink_class = GST_GIO_BASE_SINK_GET_CLASS (sink); - if (!G_IS_OUTPUT_STREAM (sink->stream)) { + sink->position = 0; + + /* FIXME: This will likely block */ + sink->stream = gbsink_class->get_stream (sink); + if (G_UNLIKELY (!G_IS_OUTPUT_STREAM (sink->stream))) { GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), - ("No stream given yet")); + ("No output stream provided by subclass")); return FALSE; } - sink->position = 0; - - GST_DEBUG_OBJECT (sink, "started stream"); + GST_DEBUG_OBJECT (sink, "started sink"); return TRUE; } diff --git a/ext/gio/gstgiobasesink.h b/ext/gio/gstgiobasesink.h index a3b49c2ca..9a1422549 100644 --- a/ext/gio/gstgiobasesink.h +++ b/ext/gio/gstgiobasesink.h @@ -1,7 +1,7 @@ /* GStreamer * * Copyright (C) 2007 Rene Stadler - * Copyright (C) 2007 Sebastian Dröge + * Copyright (C) 2007-2009 Sebastian Dröge * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -48,20 +48,23 @@ struct _GstGioBaseSink { GstBaseSink sink; + /* < protected > */ GCancellable *cancel; guint64 position; + + /* < private > */ GOutputStream *stream; }; struct _GstGioBaseSinkClass { GstBaseSinkClass parent_class; + + GOutputStream * (*get_stream) (GstGioBaseSink *bsink); }; GType gst_gio_base_sink_get_type (void); -void gst_gio_base_sink_set_stream (GstGioBaseSink *sink, GOutputStream *stream); - G_END_DECLS #endif /* __GST_GIO_BASE_SINK_H__ */ diff --git a/ext/gio/gstgiobasesrc.h b/ext/gio/gstgiobasesrc.h index d4dd1a623..d1eea7014 100644 --- a/ext/gio/gstgiobasesrc.h +++ b/ext/gio/gstgiobasesrc.h @@ -48,10 +48,12 @@ struct _GstGioBaseSrc { GstBaseSrc src; + /* < protected > */ GCancellable *cancel; guint64 position; - GInputStream *stream; + /* < private > */ + GInputStream *stream; GstBuffer *cache; }; diff --git a/ext/gio/gstgiosink.c b/ext/gio/gstgiosink.c index 8f81ebfa9..1cbd73f34 100644 --- a/ext/gio/gstgiosink.c +++ b/ext/gio/gstgiosink.c @@ -1,7 +1,7 @@ /* GStreamer * * Copyright (C) 2007 Rene Stadler - * Copyright (C) 2007 Sebastian Dröge + * Copyright (C) 2007-2009 Sebastian Dröge * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -83,7 +83,7 @@ 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 GOutputStream *gst_gio_sink_get_stream (GstGioBaseSink * base_sink); static void gst_gio_sink_base_init (gpointer gclass) @@ -103,7 +103,7 @@ static void gst_gio_sink_class_init (GstGioSinkClass * klass) { GObjectClass *gobject_class = (GObjectClass *) klass; - GstBaseSinkClass *gstbasesink_class = (GstBaseSinkClass *) klass; + GstGioBaseSinkClass *gstgiobasesink_class = (GstGioBaseSinkClass *) klass; gobject_class->finalize = gst_gio_sink_finalize; gobject_class->set_property = gst_gio_sink_set_property; @@ -124,7 +124,8 @@ gst_gio_sink_class_init (GstGioSinkClass * klass) g_param_spec_object ("file", "File", "GFile to write to", G_TYPE_FILE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_gio_sink_start); + gstgiobasesink_class->get_stream = + GST_DEBUG_FUNCPTR (gst_gio_sink_get_stream); } static void @@ -234,10 +235,10 @@ gst_gio_sink_get_property (GObject * object, guint prop_id, } } -static gboolean -gst_gio_sink_start (GstBaseSink * base_sink) +static GOutputStream * +gst_gio_sink_get_stream (GstGioBaseSink * bsink) { - GstGioSink *sink = GST_GIO_SINK (base_sink); + GstGioSink *sink = GST_GIO_SINK (bsink); GOutputStream *stream; GCancellable *cancel = GST_GIO_BASE_SINK (sink)->cancel; GError *err = NULL; @@ -246,7 +247,7 @@ gst_gio_sink_start (GstBaseSink * base_sink) if (sink->file == NULL) { GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("No location or GFile given")); - return FALSE; + return NULL; } uri = g_file_get_uri (sink->file); @@ -272,14 +273,12 @@ gst_gio_sink_start (GstBaseSink * base_sink) g_clear_error (&err); } g_free (uri); - return FALSE; + return NULL; } GST_DEBUG_OBJECT (sink, "opened location %s", uri); g_free (uri); - gst_gio_base_sink_set_stream (GST_GIO_BASE_SINK (sink), stream); - - return GST_BASE_SINK_CLASS (parent_class)->start (base_sink); + return stream; } diff --git a/ext/gio/gstgiosink.h b/ext/gio/gstgiosink.h index 7f4f12f68..494d5db30 100644 --- a/ext/gio/gstgiosink.h +++ b/ext/gio/gstgiosink.h @@ -1,7 +1,7 @@ /* GStreamer * * Copyright (C) 2007 Rene Stadler - * Copyright (C) 2007 Sebastian Dröge + * Copyright (C) 2007-2009 Sebastian Dröge * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public diff --git a/ext/gio/gstgiostreamsink.c b/ext/gio/gstgiostreamsink.c index 6af256d25..02dac71f9 100644 --- a/ext/gio/gstgiostreamsink.c +++ b/ext/gio/gstgiostreamsink.c @@ -1,7 +1,7 @@ /* GStreamer * * Copyright (C) 2007 Rene Stadler - * Copyright (C) 2007 Sebastian Dröge + * Copyright (C) 2007-2009 Sebastian Dröge * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -91,6 +91,7 @@ static void gst_gio_stream_sink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_gio_stream_sink_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static GOutputStream *gst_gio_stream_sink_get_stream (GstGioBaseSink * bsink); static void gst_gio_stream_sink_base_init (gpointer gclass) @@ -110,6 +111,7 @@ static void gst_gio_stream_sink_class_init (GstGioStreamSinkClass * klass) { GObjectClass *gobject_class = (GObjectClass *) klass; + GstGioBaseSinkClass *ggbsink_class = (GstGioBaseSinkClass *) klass; gobject_class->finalize = gst_gio_stream_sink_finalize; gobject_class->set_property = gst_gio_stream_sink_set_property; @@ -118,6 +120,9 @@ gst_gio_stream_sink_class_init (GstGioStreamSinkClass * klass) g_object_class_install_property (gobject_class, PROP_STREAM, g_param_spec_object ("stream", "Stream", "Stream to write to", G_TYPE_OUTPUT_STREAM, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + ggbsink_class->get_stream = + GST_DEBUG_FUNCPTR (gst_gio_stream_sink_get_stream); } static void @@ -129,6 +134,13 @@ gst_gio_stream_sink_init (GstGioStreamSink * sink, static void gst_gio_stream_sink_finalize (GObject * object) { + GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object); + + if (sink->stream) { + g_object_unref (sink->stream); + sink->stream = NULL; + } + GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); } @@ -150,10 +162,9 @@ gst_gio_stream_sink_set_property (GObject * object, guint prop_id, } stream = g_value_dup_object (value); - if (G_IS_OUTPUT_STREAM (stream)) - gst_gio_base_sink_set_stream (GST_GIO_BASE_SINK (sink), - G_OUTPUT_STREAM (stream)); - + if (sink->stream) + g_object_unref (sink->stream); + sink->stream = G_OUTPUT_STREAM (stream); break; } default: @@ -177,3 +188,11 @@ gst_gio_stream_sink_get_property (GObject * object, guint prop_id, break; } } + +static GOutputStream * +gst_gio_stream_sink_get_stream (GstGioBaseSink * bsink) +{ + GstGioStreamSink *sink = GST_GIO_STREAM_SINK (bsink); + + return (sink->stream) ? g_object_ref (sink->stream) : NULL; +} diff --git a/ext/gio/gstgiostreamsink.h b/ext/gio/gstgiostreamsink.h index c5f4c5993..5e6206b50 100644 --- a/ext/gio/gstgiostreamsink.h +++ b/ext/gio/gstgiostreamsink.h @@ -1,7 +1,7 @@ /* GStreamer * * Copyright (C) 2007 Rene Stadler - * Copyright (C) 2007 Sebastian Dröge + * Copyright (C) 2007-2009 Sebastian Dröge * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -51,6 +51,9 @@ typedef struct _GstGioStreamSinkClass GstGioStreamSinkClass; struct _GstGioStreamSink { GstGioBaseSink sink; + + /* < private > */ + GOutputStream *stream; }; struct _GstGioStreamSinkClass -- cgit v1.2.1