Macro qtTrIdx() replaced by tr() and QT_TRANSLATE_NOOP()
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / ext / gio / gstgiostreamsrc.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-giostreamsrc
24  *
25  * This plugin reads data from a custom GIO #GInputStream.
26  *
27  * It can, for example, be used to read data from memory with a
28  * #GMemoryInputStream or to read from a file with a
29  * #GFileInputStream.
30  *
31  * <refsect2>
32  * <title>Example code</title>
33  * <para>
34  * The following example reads data from a #GMemoryInputStream.
35  * |[
36
37 #include &lt;gst/gst.h&gt;
38 #include &lt;gio/gio.h&gt;
39
40 ...
41
42 GstElement *src;
43 GMemoryInputStream *stream;
44 // in_data will contain the data to send
45 guint8 *in_data;
46 gint i;
47
48 ...
49 in_data = g_new (guint8, 512);
50 for (i = 0; i < 512; i++)
51   in_data[i] = i % 256;
52
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);
57
58 ...
59
60  * ]|
61  * </para>
62  * </refsect2>
63  */
64
65 #ifdef HAVE_CONFIG_H
66 #include <config.h>
67 #endif
68
69 #include "gstgiostreamsrc.h"
70
71 GST_DEBUG_CATEGORY_STATIC (gst_gio_stream_src_debug);
72 #define GST_CAT_DEFAULT gst_gio_stream_src_debug
73
74 enum
75 {
76   PROP_0,
77   PROP_STREAM
78 };
79
80 GST_BOILERPLATE (GstGioStreamSrc, gst_gio_stream_src, GstGioBaseSrc,
81     GST_TYPE_GIO_BASE_SRC);
82
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);
89
90 static void
91 gst_gio_stream_src_base_init (gpointer gclass)
92 {
93   GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
94
95   GST_DEBUG_CATEGORY_INIT (gst_gio_stream_src_debug, "gio_stream_src", 0,
96       "GIO source");
97
98   gst_element_class_set_details_simple (element_class, "GIO stream source",
99       "Source",
100       "Read from any GIO stream",
101       "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
102 }
103
104 static void
105 gst_gio_stream_src_class_init (GstGioStreamSrcClass * klass)
106 {
107   GObjectClass *gobject_class = (GObjectClass *) klass;
108   GstGioBaseSrcClass *gstgiobasesrc_class = (GstGioBaseSrcClass *) klass;
109
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;
113
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));
117
118   gstgiobasesrc_class->get_stream =
119       GST_DEBUG_FUNCPTR (gst_gio_stream_src_get_stream);
120 }
121
122 static void
123 gst_gio_stream_src_init (GstGioStreamSrc * src, GstGioStreamSrcClass * gclass)
124 {
125 }
126
127 static void
128 gst_gio_stream_src_finalize (GObject * object)
129 {
130   GstGioStreamSrc *src = GST_GIO_STREAM_SRC (object);
131
132   if (src->stream) {
133     g_object_unref (src->stream);
134     src->stream = NULL;
135   }
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 PROP_STREAM:{
148       GObject *stream;
149
150       if (GST_STATE (src) == GST_STATE_PLAYING ||
151           GST_STATE (src) == GST_STATE_PAUSED) {
152         GST_WARNING
153             ("Setting a new stream not supported in PLAYING or PAUSED state");
154         break;
155       }
156
157       stream = g_value_dup_object (value);
158       if (src->stream)
159         g_object_unref (src->stream);
160       src->stream = G_INPUT_STREAM (stream);
161       break;
162     }
163     default:
164       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
165       break;
166   }
167 }
168
169 static void
170 gst_gio_stream_src_get_property (GObject * object, guint prop_id,
171     GValue * value, GParamSpec * pspec)
172 {
173   GstGioStreamSrc *src = GST_GIO_STREAM_SRC (object);
174
175   switch (prop_id) {
176     case PROP_STREAM:
177       g_value_set_object (value, src->stream);
178       break;
179     default:
180       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
181       break;
182   }
183 }
184
185 static GInputStream *
186 gst_gio_stream_src_get_stream (GstGioBaseSrc * bsrc)
187 {
188   GstGioStreamSrc *src = GST_GIO_STREAM_SRC (bsrc);
189
190   return (src->stream) ? g_object_ref (src->stream) : NULL;
191 }