1 /*gstclasspathsrc.c - Class file for the GstClasspathPlugin
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
43 * We don't really use version numbering here, we give it the same version
44 * number of classpath, so that gstreamer is happy.
45 * TODO: Maybe this should be moved in config.h instead?
47 #define CLASSPATH_GST_PLUGIN_VERSION PACKAGE_VERSION
54 #include <gst/base/gstbasesrc.h>
55 #include <gst/base/gstpushsrc.h>
58 #include <glib/gprintf.h>
62 #include "gstclasspathsrc.h"
63 #include "gstinputstream.h"
65 GST_DEBUG_CATEGORY_STATIC (gst_classpath_src_debug
);
66 #define GST_CAT_DEFAULT gst_classpath_src_debug
74 static const GstElementDetails gst_classpath_src_details
=
75 GST_ELEMENT_DETAILS ("ClasspathSrc",
77 "Read from a java input stream",
78 "Mario Torre <neugens@limasoftware.net>");
80 static GstStaticPadTemplate _template
=
81 GST_STATIC_PAD_TEMPLATE ("src",
86 /* ***** plugin init ***** */
89 _do_init (GType filesrc_type
__attribute__ ((unused
)))
91 GST_DEBUG_CATEGORY_INIT (gst_classpath_src_debug
, "classpathsrc",
95 GST_BOILERPLATE_FULL (GstClasspathSrc
, gst_classpath_src
, GstPushSrc
,
96 GST_TYPE_PUSH_SRC
, _do_init
);
99 plugin_init (GstPlugin
*plugin
)
101 return gst_element_register (plugin
, "classpathsrc",
102 GST_RANK_NONE
, GST_TYPE_CLASSPATH_SRC
);
105 GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR
,
108 "Java InputStream Reader",
109 plugin_init
, CLASSPATH_GST_PLUGIN_VERSION
,
111 "Classpath", "http://www.classpath.org/")
113 /* ***** public class methods ***** */
115 static void gst_classpath_src_set_property (GObject
*object
,
120 static void gst_classpath_src_get_property (GObject
*object
,
125 static void gst_classpath_src_finalize (GObject
*object
);
127 static gboolean
gst_classpath_src_start (GstBaseSrc
*basesrc
);
129 static gboolean
gst_classpath_src_stop (GstBaseSrc
*basesrc
);
131 static GstFlowReturn
gst_classpath_src_create (GstPushSrc
*src
,
134 /* ***** public class methods: end ***** */
137 gst_classpath_src_base_init (gpointer gclass
)
139 GstElementClass
*gstelement_class
= GST_ELEMENT_CLASS (gclass
);
141 gst_element_class_add_pad_template (gstelement_class
,
142 gst_static_pad_template_get (&_template
));
144 gst_element_class_set_details (gstelement_class
, &gst_classpath_src_details
);
148 gst_classpath_src_class_init (GstClasspathSrcClass
*klass
)
150 GObjectClass
*gobject_class
;
151 GstElementClass
*gstelement_class
;
152 GstBaseSrcClass
*gstbasesrc_class
;
153 GstPushSrcClass
*gstpushsrc_class
;
157 gobject_class
= G_OBJECT_CLASS (klass
);
158 gstelement_class
= GST_ELEMENT_CLASS (klass
);
159 gstbasesrc_class
= GST_BASE_SRC_CLASS (klass
);
160 gstpushsrc_class
= GST_PUSH_SRC_CLASS (klass
);
162 /* getter and setters */
164 gobject_class
->set_property
= gst_classpath_src_set_property
;
165 gobject_class
->get_property
= gst_classpath_src_get_property
;
167 /* register properties */
168 pspec
= g_param_spec_pointer (GST_CLASSPATH_SRC_ISTREAM
,
169 "GstInputStream instance",
170 "GstInputStream instance",
172 g_object_class_install_property (gobject_class
, ARG_INPUTSTREAM
, pspec
);
174 /* register callbacks */
175 gobject_class
->finalize
= GST_DEBUG_FUNCPTR (gst_classpath_src_finalize
);
177 gstbasesrc_class
->start
= GST_DEBUG_FUNCPTR (gst_classpath_src_start
);
178 gstbasesrc_class
->stop
= GST_DEBUG_FUNCPTR (gst_classpath_src_stop
);
180 gstpushsrc_class
->create
= GST_DEBUG_FUNCPTR (gst_classpath_src_create
);
186 gst_classpath_src_init (GstClasspathSrc
*src
,
187 GstClasspathSrcClass
* g_class
__attribute__ ((unused
)))
190 src
->read_position
= 0;
194 gst_classpath_src_finalize (GObject
*object
)
196 G_OBJECT_CLASS (parent_class
)->finalize (object
);
199 /* ************************************************************************** */
202 gst_classpath_src_set_property (GObject
*object
,
207 GstClasspathSrc
*src
;
209 g_return_if_fail (GST_IS_CLASSPATH_SRC (object
));
211 src
= GST_CLASSPATH_SRC (object
);
213 GST_OBJECT_LOCK (src
);
216 case ARG_INPUTSTREAM
:
218 GST_STATE_LOCK (src
);
221 state
= GST_STATE (src
);
223 if (state
!= GST_STATE_READY
&& state
!= GST_STATE_NULL
)
225 GST_DEBUG_OBJECT (src
, "setting location in wrong state");
226 GST_STATE_UNLOCK (src
);
230 GST_STATE_UNLOCK (src
);
232 if (GST_IS_INPUT_STREAM (g_value_get_pointer (value
)))
234 src
->istream
= g_value_get_pointer (value
);
238 GST_INFO_OBJECT (src
, "invalid instance of GstInputStream");
244 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
247 GST_OBJECT_UNLOCK (src
);
251 gst_classpath_src_get_property (GObject
*object
,
252 guint prop_id
__attribute__ ((unused
)),
253 GValue
*value
__attribute__ ((unused
)),
254 GParamSpec
*pspec
__attribute__ ((unused
)))
257 G_OBJECT_CLASS (parent_class
)->finalize (object
);
260 /* ************************************************************************** */
263 gst_classpath_src_create (GstPushSrc
*basesrc
,
266 GstClasspathSrc
*src
;
269 src
= GST_CLASSPATH_SRC (basesrc
);
271 /* create the buffer */
272 *buffer
= gst_buffer_new_and_alloc (2048);
275 return GST_FLOW_ERROR
;
278 GST_BUFFER_SIZE (*buffer
) = 0;
280 GST_OBJECT_LOCK (src
);
281 read
= gst_input_stream_read (src
->istream
, (int *) GST_BUFFER_DATA (*buffer
), 0,
283 GST_OBJECT_UNLOCK (src
);
285 if (G_UNLIKELY (read
< 0))
287 gst_buffer_unref (*buffer
);
288 return GST_FLOW_UNEXPECTED
;
291 GST_OBJECT_LOCK (src
);
293 GST_BUFFER_SIZE (*buffer
) = read
;
294 GST_BUFFER_OFFSET (*buffer
) = src
->read_position
;
295 GST_BUFFER_OFFSET_END (*buffer
) = src
->read_position
+ read
;
297 src
->read_position
+= read
;
299 GST_OBJECT_UNLOCK (src
);
301 gst_buffer_set_caps (*buffer
, GST_PAD_CAPS (GST_BASE_SRC_PAD (src
)));
307 gst_classpath_src_start (GstBaseSrc
*basesrc
)
309 GstClasspathSrc
*src
;
311 src
= GST_CLASSPATH_SRC (basesrc
);
313 if (src
->istream
== NULL
)
315 GST_ELEMENT_ERROR (src
, RESOURCE
, OPEN_READ
, (NULL
),
316 ("GstInputStream is still null. you need to pass a valid InputStream"));
320 GST_OBJECT_LOCK (src
);
321 src
->read_position
= 0;
322 GST_OBJECT_UNLOCK (src
);
328 gst_classpath_src_stop (GstBaseSrc
*basesrc
__attribute__ ((unused
)))