3 * Copyright (C) 2007 Rene Stadler <mail@renestadler.de>
4 * Copyright (C) 2007-2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * SECTION:element-giostreamsink
25 * This plugin writes incoming data to a custom GIO #GOutputStream.
27 * It can, for example, be used to write a stream to memory with a
28 * #GMemoryOuputStream or to write to a file with a #GFileOuputStream.
31 * <title>Example code</title>
33 * The following example writes the received data to a #GMemoryOutputStream.
36 #include <gst/gst.h>
37 #include <gio/gio.h>
42 GMemoryOuputStream *stream;
43 // out_data will contain the received data
48 stream = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (NULL, 0,
49 (GReallocFunc) g_realloc, (GDestroyNotify) g_free));
50 sink = gst_element_factory_make ("giostreamsink", "sink");
51 g_object_set (G_OBJECT (sink), "stream", stream, NULL);
55 // after processing get the written data
56 out_data = g_memory_ouput_stream_get_data (G_MEMORY_OUTPUT_STREAM (stream));
69 #include "gstgiostreamsink.h"
71 GST_DEBUG_CATEGORY_STATIC (gst_gio_stream_sink_debug);
72 #define GST_CAT_DEFAULT gst_gio_stream_sink_debug
74 /* Filter signals and args */
86 #define gst_gio_stream_sink_parent_class parent_class
87 G_DEFINE_TYPE (GstGioStreamSink, gst_gio_stream_sink, GST_TYPE_GIO_BASE_SINK);
89 static void gst_gio_stream_sink_finalize (GObject * object);
90 static void gst_gio_stream_sink_set_property (GObject * object, guint prop_id,
91 const GValue * value, GParamSpec * pspec);
92 static void gst_gio_stream_sink_get_property (GObject * object, guint prop_id,
93 GValue * value, GParamSpec * pspec);
94 static GOutputStream *gst_gio_stream_sink_get_stream (GstGioBaseSink * bsink);
97 gst_gio_stream_sink_class_init (GstGioStreamSinkClass * klass)
99 GObjectClass *gobject_class = (GObjectClass *) klass;
100 GstElementClass *gstelement_class = (GstElementClass *) klass;
101 GstGioBaseSinkClass *ggbsink_class = (GstGioBaseSinkClass *) klass;
103 GST_DEBUG_CATEGORY_INIT (gst_gio_stream_sink_debug, "gio_stream_sink", 0,
106 gobject_class->finalize = gst_gio_stream_sink_finalize;
107 gobject_class->set_property = gst_gio_stream_sink_set_property;
108 gobject_class->get_property = gst_gio_stream_sink_get_property;
110 g_object_class_install_property (gobject_class, PROP_STREAM,
111 g_param_spec_object ("stream", "Stream", "Stream to write to",
112 G_TYPE_OUTPUT_STREAM, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
114 gst_element_class_set_details_simple (gstelement_class, "GIO stream sink",
116 "Write to any GIO stream",
117 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
119 ggbsink_class->get_stream =
120 GST_DEBUG_FUNCPTR (gst_gio_stream_sink_get_stream);
124 gst_gio_stream_sink_init (GstGioStreamSink * sink)
129 gst_gio_stream_sink_finalize (GObject * object)
131 GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object);
134 g_object_unref (sink->stream);
138 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
142 gst_gio_stream_sink_set_property (GObject * object, guint prop_id,
143 const GValue * value, GParamSpec * pspec)
145 GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object);
151 if (GST_STATE (sink) == GST_STATE_PLAYING ||
152 GST_STATE (sink) == GST_STATE_PAUSED) {
154 ("Setting a new stream not supported in PLAYING or PAUSED state");
158 stream = g_value_dup_object (value);
160 g_object_unref (sink->stream);
161 sink->stream = G_OUTPUT_STREAM (stream);
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171 gst_gio_stream_sink_get_property (GObject * object, guint prop_id,
172 GValue * value, GParamSpec * pspec)
174 GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object);
178 g_value_set_object (value, GST_GIO_BASE_SINK (sink)->stream);
181 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
186 static GOutputStream *
187 gst_gio_stream_sink_get_stream (GstGioBaseSink * bsink)
189 GstGioStreamSink *sink = GST_GIO_STREAM_SINK (bsink);
191 return (sink->stream) ? g_object_ref (sink->stream) : NULL;