Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / ext / gio / gstgiostreamsink.c
1 /* GStreamer
2  *
3  * Copyright (C) 2007 Rene Stadler <mail@renestadler.de>
4  * Copyright (C) 2007-2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
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  *
25  * This plugin writes incoming data to a custom GIO #GOutputStream.
26  *
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.
29  *
30  * <refsect2>
31  * <title>Example code</title>
32  * <para>
33  * The following example writes the received data to a #GMemoryOutputStream.
34  * |[
35
36 #include &lt;gst/gst.h&gt;
37 #include &lt;gio/gio.h&gt;
38
39 ...
40
41 GstElement *sink;
42 GMemoryOuputStream *stream;
43 // out_data will contain the received data
44 guint8 *out_data;
45
46 ...
47
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);
52
53 ...
54
55 // after processing get the written data
56 out_data = g_memory_ouput_stream_get_data (G_MEMORY_OUTPUT_STREAM (stream));
57
58 ...
59
60  * ]|
61  * </para>
62  * </refsect2>
63  */
64
65 #ifdef HAVE_CONFIG_H
66 #include <config.h>
67 #endif
68
69 #include "gstgiostreamsink.h"
70
71 GST_DEBUG_CATEGORY_STATIC (gst_gio_stream_sink_debug);
72 #define GST_CAT_DEFAULT gst_gio_stream_sink_debug
73
74 /* Filter signals and args */
75 enum
76 {
77   LAST_SIGNAL
78 };
79
80 enum
81 {
82   PROP_0,
83   PROP_STREAM
84 };
85
86 GST_BOILERPLATE (GstGioStreamSink, gst_gio_stream_sink, GstGioBaseSink,
87     GST_TYPE_GIO_BASE_SINK);
88
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);
95
96 static void
97 gst_gio_stream_sink_base_init (gpointer gclass)
98 {
99   GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
100
101   GST_DEBUG_CATEGORY_INIT (gst_gio_stream_sink_debug, "gio_stream_sink", 0,
102       "GIO stream sink");
103
104   gst_element_class_set_details_simple (element_class, "GIO stream sink",
105       "Sink",
106       "Write to any GIO stream",
107       "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
108 }
109
110 static void
111 gst_gio_stream_sink_class_init (GstGioStreamSinkClass * klass)
112 {
113   GObjectClass *gobject_class = (GObjectClass *) klass;
114   GstGioBaseSinkClass *ggbsink_class = (GstGioBaseSinkClass *) klass;
115
116   gobject_class->finalize = gst_gio_stream_sink_finalize;
117   gobject_class->set_property = gst_gio_stream_sink_set_property;
118   gobject_class->get_property = gst_gio_stream_sink_get_property;
119
120   g_object_class_install_property (gobject_class, PROP_STREAM,
121       g_param_spec_object ("stream", "Stream", "Stream to write to",
122           G_TYPE_OUTPUT_STREAM, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
123
124   ggbsink_class->get_stream =
125       GST_DEBUG_FUNCPTR (gst_gio_stream_sink_get_stream);
126 }
127
128 static void
129 gst_gio_stream_sink_init (GstGioStreamSink * sink,
130     GstGioStreamSinkClass * gclass)
131 {
132 }
133
134 static void
135 gst_gio_stream_sink_finalize (GObject * object)
136 {
137   GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object);
138
139   if (sink->stream) {
140     g_object_unref (sink->stream);
141     sink->stream = NULL;
142   }
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 PROP_STREAM:{
155       GObject *stream;
156
157       if (GST_STATE (sink) == GST_STATE_PLAYING ||
158           GST_STATE (sink) == GST_STATE_PAUSED) {
159         GST_WARNING
160             ("Setting a new stream not supported in PLAYING or PAUSED state");
161         break;
162       }
163
164       stream = g_value_dup_object (value);
165       if (sink->stream)
166         g_object_unref (sink->stream);
167       sink->stream = G_OUTPUT_STREAM (stream);
168       break;
169     }
170     default:
171       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172       break;
173   }
174 }
175
176 static void
177 gst_gio_stream_sink_get_property (GObject * object, guint prop_id,
178     GValue * value, GParamSpec * pspec)
179 {
180   GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object);
181
182   switch (prop_id) {
183     case PROP_STREAM:
184       g_value_set_object (value, GST_GIO_BASE_SINK (sink)->stream);
185       break;
186     default:
187       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
188       break;
189   }
190 }
191
192 static GOutputStream *
193 gst_gio_stream_sink_get_stream (GstGioBaseSink * bsink)
194 {
195   GstGioStreamSink *sink = GST_GIO_STREAM_SINK (bsink);
196
197   return (sink->stream) ? g_object_ref (sink->stream) : NULL;
198 }