|
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-giostreamsink |
|
24 * @short_description: Write to a GIO GOutputStream |
|
25 * |
|
26 * <refsect2> |
|
27 * <para> |
|
28 * This plugin writes incoming data to a custom GIO #GOutputStream. |
|
29 * </para> |
|
30 * <para> |
|
31 * It can, for example, be used to write a stream to memory with a |
|
32 * #GMemoryOuputStream or to write to a file with a #GFileOuputStream. |
|
33 * </para> |
|
34 * <title>Example code</title> |
|
35 * <para> |
|
36 * The following example writes the received data to a #GMemoryOutputStream. |
|
37 * <programlisting> |
|
38 |
|
39 #include <gst/gst.h> |
|
40 #include <gio/gio.h> |
|
41 |
|
42 ... |
|
43 |
|
44 GstElement *sink; |
|
45 GMemoryOuputStream *stream; |
|
46 // out_data will contain the received data |
|
47 guint8 *out_data; |
|
48 |
|
49 ... |
|
50 |
|
51 stream = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (NULL, 0, |
|
52 (GReallocFunc) g_realloc, (GDestroyNotify) g_free)); |
|
53 sink = gst_element_factory_make ("giostreamsink", "sink"); |
|
54 g_object_set (G_OBJECT (sink), "stream", stream, NULL); |
|
55 |
|
56 ... |
|
57 |
|
58 // after processing get the written data |
|
59 out_data = g_memory_ouput_stream_get_data (G_MEMORY_OUTPUT_STREAM (stream)); |
|
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 "gstgiostreamsink.h" |
|
73 |
|
74 GST_DEBUG_CATEGORY_STATIC (gst_gio_stream_sink_debug); |
|
75 #define GST_CAT_DEFAULT gst_gio_stream_sink_debug |
|
76 |
|
77 /* Filter signals and args */ |
|
78 enum |
|
79 { |
|
80 LAST_SIGNAL |
|
81 }; |
|
82 |
|
83 enum |
|
84 { |
|
85 ARG_0, |
|
86 ARG_STREAM |
|
87 }; |
|
88 |
|
89 GST_BOILERPLATE (GstGioStreamSink, gst_gio_stream_sink, GstGioBaseSink, |
|
90 GST_TYPE_GIO_BASE_SINK); |
|
91 |
|
92 static void gst_gio_stream_sink_finalize (GObject * object); |
|
93 static void gst_gio_stream_sink_set_property (GObject * object, guint prop_id, |
|
94 const GValue * value, GParamSpec * pspec); |
|
95 static void gst_gio_stream_sink_get_property (GObject * object, guint prop_id, |
|
96 GValue * value, GParamSpec * pspec); |
|
97 |
|
98 static void |
|
99 gst_gio_stream_sink_base_init (gpointer gclass) |
|
100 { |
|
101 static GstElementDetails element_details = { |
|
102 "GIO stream sink", |
|
103 "Sink", |
|
104 "Write to any GIO stream", |
|
105 "Sebastian Dröge <slomo@circular-chaos.org>" |
|
106 }; |
|
107 GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); |
|
108 |
|
109 GST_DEBUG_CATEGORY_INIT (gst_gio_stream_sink_debug, "gio_stream_sink", 0, |
|
110 "GIO stream sink"); |
|
111 |
|
112 gst_element_class_set_details (element_class, &element_details); |
|
113 } |
|
114 |
|
115 static void |
|
116 gst_gio_stream_sink_class_init (GstGioStreamSinkClass * klass) |
|
117 { |
|
118 GObjectClass *gobject_class; |
|
119 GstElementClass *gstelement_class; |
|
120 GstBaseSinkClass *gstbasesink_class; |
|
121 |
|
122 gobject_class = (GObjectClass *) klass; |
|
123 gstelement_class = (GstElementClass *) klass; |
|
124 gstbasesink_class = (GstBaseSinkClass *) klass; |
|
125 |
|
126 gobject_class->finalize = gst_gio_stream_sink_finalize; |
|
127 gobject_class->set_property = gst_gio_stream_sink_set_property; |
|
128 gobject_class->get_property = gst_gio_stream_sink_get_property; |
|
129 |
|
130 g_object_class_install_property (gobject_class, ARG_STREAM, |
|
131 g_param_spec_object ("stream", "Stream", "Stream to write to", |
|
132 G_TYPE_OUTPUT_STREAM, G_PARAM_READWRITE)); |
|
133 } |
|
134 |
|
135 static void |
|
136 gst_gio_stream_sink_init (GstGioStreamSink * sink, |
|
137 GstGioStreamSinkClass * gclass) |
|
138 { |
|
139 } |
|
140 |
|
141 static void |
|
142 gst_gio_stream_sink_finalize (GObject * object) |
|
143 { |
|
144 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); |
|
145 } |
|
146 |
|
147 static void |
|
148 gst_gio_stream_sink_set_property (GObject * object, guint prop_id, |
|
149 const GValue * value, GParamSpec * pspec) |
|
150 { |
|
151 GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object); |
|
152 |
|
153 switch (prop_id) { |
|
154 case ARG_STREAM:{ |
|
155 GObject *stream; |
|
156 |
|
157 if (GST_STATE (sink) == GST_STATE_PLAYING || |
|
158 GST_STATE (sink) == GST_STATE_PAUSED) |
|
159 break; |
|
160 |
|
161 stream = g_value_dup_object (value); |
|
162 if (G_IS_OUTPUT_STREAM (stream)) |
|
163 gst_gio_base_sink_set_stream (GST_GIO_BASE_SINK (sink), |
|
164 G_OUTPUT_STREAM (stream)); |
|
165 |
|
166 break; |
|
167 } |
|
168 default: |
|
169 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|
170 break; |
|
171 } |
|
172 } |
|
173 |
|
174 static void |
|
175 gst_gio_stream_sink_get_property (GObject * object, guint prop_id, |
|
176 GValue * value, GParamSpec * pspec) |
|
177 { |
|
178 GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object); |
|
179 |
|
180 switch (prop_id) { |
|
181 case ARG_STREAM: |
|
182 g_value_set_object (value, GST_GIO_BASE_SINK (sink)->stream); |
|
183 break; |
|
184 default: |
|
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|
186 break; |
|
187 } |
|
188 } |