|
1 /* GStreamer |
|
2 * |
|
3 * Copyright (C) 2007 Rene Stadler <mail@renestadler.de> |
|
4 * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org> |
|
5 * |
|
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. |
|
10 * |
|
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. |
|
15 * |
|
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. |
|
20 */ |
|
21 |
|
22 /** |
|
23 * SECTION:element-giostreamsrc |
|
24 * @short_description: Reads data from a GIO GInputStream |
|
25 * |
|
26 * <refsect2> |
|
27 * <para> |
|
28 * This plugin reads data from a custom GIO #GInputStream. |
|
29 * </para> |
|
30 * <para> |
|
31 * It can, for example, be used to read data from memory with a |
|
32 * #GMemoryInputStream or to read from a file with a |
|
33 * #GFileInputStream. |
|
34 * </para> |
|
35 * <title>Example code</title> |
|
36 * <para> |
|
37 * The following example reads data from a #GMemoryOutputStream. |
|
38 * <programlisting> |
|
39 |
|
40 #include <gst/gst.h> |
|
41 #include <gio/gio.h> |
|
42 |
|
43 ... |
|
44 |
|
45 GstElement *src; |
|
46 GMemoryInputStream *stream; |
|
47 // in_data will contain the data to send |
|
48 guint8 *in_data; |
|
49 gint i; |
|
50 |
|
51 ... |
|
52 in_data = g_new (guint8, 512); |
|
53 for (i = 0; i < 512; i++) |
|
54 in_data[i] = i % 256; |
|
55 |
|
56 stream = G_MEMORY_INPUT_STREAM (g_memory_input_stream_new_from_data (in_data, 512, |
|
57 (GDestroyNotify) g_free)); |
|
58 src = gst_element_factory_make ("giostreamsrc", "src"); |
|
59 g_object_set (G_OBJECT (src), "stream", stream, NULL); |
|
60 |
|
61 ... |
|
62 |
|
63 * </programlisting> |
|
64 * </para> |
|
65 * </refsect2> |
|
66 */ |
|
67 |
|
68 #ifdef HAVE_CONFIG_H |
|
69 #include <config.h> |
|
70 #endif |
|
71 |
|
72 #include "gstgiostreamsrc.h" |
|
73 |
|
74 GST_DEBUG_CATEGORY_STATIC (gst_gio_stream_src_debug); |
|
75 #define GST_CAT_DEFAULT gst_gio_stream_src_debug |
|
76 |
|
77 enum |
|
78 { |
|
79 ARG_0, |
|
80 ARG_STREAM |
|
81 }; |
|
82 |
|
83 GST_BOILERPLATE (GstGioStreamSrc, gst_gio_stream_src, GstGioBaseSrc, |
|
84 GST_TYPE_GIO_BASE_SRC); |
|
85 |
|
86 static void gst_gio_stream_src_finalize (GObject * object); |
|
87 static void gst_gio_stream_src_set_property (GObject * object, guint prop_id, |
|
88 const GValue * value, GParamSpec * pspec); |
|
89 static void gst_gio_stream_src_get_property (GObject * object, guint prop_id, |
|
90 GValue * value, GParamSpec * pspec); |
|
91 |
|
92 static void |
|
93 gst_gio_stream_src_base_init (gpointer gclass) |
|
94 { |
|
95 static GstElementDetails element_details = { |
|
96 "GIO stream source", |
|
97 "Source", |
|
98 "Read from any GIO stream", |
|
99 "Sebastian Dröge <slomo@circular-chaos.org>" |
|
100 }; |
|
101 GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); |
|
102 |
|
103 GST_DEBUG_CATEGORY_INIT (gst_gio_stream_src_debug, "gio_stream_src", 0, |
|
104 "GIO source"); |
|
105 |
|
106 gst_element_class_set_details (element_class, &element_details); |
|
107 } |
|
108 |
|
109 static void |
|
110 gst_gio_stream_src_class_init (GstGioStreamSrcClass * klass) |
|
111 { |
|
112 GObjectClass *gobject_class; |
|
113 GstElementClass *gstelement_class; |
|
114 GstBaseSrcClass *gstbasesrc_class; |
|
115 |
|
116 gobject_class = (GObjectClass *) klass; |
|
117 gstelement_class = (GstElementClass *) klass; |
|
118 gstbasesrc_class = (GstBaseSrcClass *) klass; |
|
119 |
|
120 gobject_class->finalize = gst_gio_stream_src_finalize; |
|
121 gobject_class->set_property = gst_gio_stream_src_set_property; |
|
122 gobject_class->get_property = gst_gio_stream_src_get_property; |
|
123 |
|
124 g_object_class_install_property (gobject_class, ARG_STREAM, |
|
125 g_param_spec_object ("stream", "Stream", "Stream to read from", |
|
126 G_TYPE_INPUT_STREAM, G_PARAM_READWRITE)); |
|
127 } |
|
128 |
|
129 static void |
|
130 gst_gio_stream_src_init (GstGioStreamSrc * src, GstGioStreamSrcClass * gclass) |
|
131 { |
|
132 } |
|
133 |
|
134 static void |
|
135 gst_gio_stream_src_finalize (GObject * object) |
|
136 { |
|
137 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); |
|
138 } |
|
139 |
|
140 static void |
|
141 gst_gio_stream_src_set_property (GObject * object, guint prop_id, |
|
142 const GValue * value, GParamSpec * pspec) |
|
143 { |
|
144 GstGioStreamSrc *src = GST_GIO_STREAM_SRC (object); |
|
145 |
|
146 switch (prop_id) { |
|
147 case ARG_STREAM:{ |
|
148 GObject *stream; |
|
149 |
|
150 if (GST_STATE (src) == GST_STATE_PLAYING || |
|
151 GST_STATE (src) == GST_STATE_PAUSED) |
|
152 break; |
|
153 |
|
154 stream = g_value_dup_object (value); |
|
155 if (G_IS_INPUT_STREAM (stream)) |
|
156 gst_gio_base_src_set_stream (GST_GIO_BASE_SRC (src), |
|
157 G_INPUT_STREAM (stream)); |
|
158 |
|
159 break; |
|
160 } |
|
161 default: |
|
162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|
163 break; |
|
164 } |
|
165 } |
|
166 |
|
167 static void |
|
168 gst_gio_stream_src_get_property (GObject * object, guint prop_id, |
|
169 GValue * value, GParamSpec * pspec) |
|
170 { |
|
171 GstGioStreamSrc *src = GST_GIO_STREAM_SRC (object); |
|
172 |
|
173 switch (prop_id) { |
|
174 case ARG_STREAM: |
|
175 g_value_set_object (value, GST_GIO_BASE_SRC (src)->stream); |
|
176 break; |
|
177 default: |
|
178 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|
179 break; |
|
180 } |
|
181 } |