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-giostreamsrc
25 * This plugin reads data from a custom GIO #GInputStream.
27 * It can, for example, be used to read data from memory with a
28 * #GMemoryInputStream or to read from a file with a
32 * <title>Example code</title>
34 * The following example reads data from a #GMemoryInputStream.
37 #include <gst/gst.h>
38 #include <gio/gio.h>
43 GMemoryInputStream *stream;
44 // in_data will contain the data to send
49 in_data = g_new (guint8, 512);
50 for (i = 0; i < 512; i++)
53 stream = G_MEMORY_INPUT_STREAM (g_memory_input_stream_new_from_data (in_data, 512,
54 (GDestroyNotify) g_free));
55 src = gst_element_factory_make ("giostreamsrc", "src");
56 g_object_set (G_OBJECT (src), "stream", stream, NULL);
69 #include "gstgiostreamsrc.h"
71 GST_DEBUG_CATEGORY_STATIC (gst_gio_stream_src_debug);
72 #define GST_CAT_DEFAULT gst_gio_stream_src_debug
80 GST_BOILERPLATE (GstGioStreamSrc, gst_gio_stream_src, GstGioBaseSrc,
81 GST_TYPE_GIO_BASE_SRC);
83 static void gst_gio_stream_src_finalize (GObject * object);
84 static void gst_gio_stream_src_set_property (GObject * object, guint prop_id,
85 const GValue * value, GParamSpec * pspec);
86 static void gst_gio_stream_src_get_property (GObject * object, guint prop_id,
87 GValue * value, GParamSpec * pspec);
88 static GInputStream *gst_gio_stream_src_get_stream (GstGioBaseSrc * bsrc);
91 gst_gio_stream_src_base_init (gpointer gclass)
93 GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
95 GST_DEBUG_CATEGORY_INIT (gst_gio_stream_src_debug, "gio_stream_src", 0,
98 gst_element_class_set_details_simple (element_class, "GIO stream source",
100 "Read from any GIO stream",
101 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
105 gst_gio_stream_src_class_init (GstGioStreamSrcClass * klass)
107 GObjectClass *gobject_class = (GObjectClass *) klass;
108 GstGioBaseSrcClass *gstgiobasesrc_class = (GstGioBaseSrcClass *) klass;
110 gobject_class->finalize = gst_gio_stream_src_finalize;
111 gobject_class->set_property = gst_gio_stream_src_set_property;
112 gobject_class->get_property = gst_gio_stream_src_get_property;
114 g_object_class_install_property (gobject_class, PROP_STREAM,
115 g_param_spec_object ("stream", "Stream", "Stream to read from",
116 G_TYPE_INPUT_STREAM, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
118 gstgiobasesrc_class->get_stream =
119 GST_DEBUG_FUNCPTR (gst_gio_stream_src_get_stream);
123 gst_gio_stream_src_init (GstGioStreamSrc * src, GstGioStreamSrcClass * gclass)
128 gst_gio_stream_src_finalize (GObject * object)
130 GstGioStreamSrc *src = GST_GIO_STREAM_SRC (object);
133 g_object_unref (src->stream);
137 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
141 gst_gio_stream_src_set_property (GObject * object, guint prop_id,
142 const GValue * value, GParamSpec * pspec)
144 GstGioStreamSrc *src = GST_GIO_STREAM_SRC (object);
150 if (GST_STATE (src) == GST_STATE_PLAYING ||
151 GST_STATE (src) == GST_STATE_PAUSED) {
153 ("Setting a new stream not supported in PLAYING or PAUSED state");
157 stream = g_value_dup_object (value);
159 g_object_unref (src->stream);
160 src->stream = G_INPUT_STREAM (stream);
164 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
170 gst_gio_stream_src_get_property (GObject * object, guint prop_id,
171 GValue * value, GParamSpec * pspec)
173 GstGioStreamSrc *src = GST_GIO_STREAM_SRC (object);
177 g_value_set_object (value, src->stream);
180 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
185 static GInputStream *
186 gst_gio_stream_src_get_stream (GstGioBaseSrc * bsrc)
188 GstGioStreamSrc *src = GST_GIO_STREAM_SRC (bsrc);
190 return (src->stream) ? g_object_ref (src->stream) : NULL;