2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
29 #include "bytestream.h"
31 #define GST_TYPE_IDENTITY \
32 (gst_identity_get_type())
33 #define GST_IDENTITY(obj) \
34 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IDENTITY,GstIdentity))
35 #define GST_IDENTITY_CLASS(klass) \
36 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IDENTITY,GstIdentityClass))
37 #define GST_IS_IDENTITY(obj) \
38 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IDENTITY))
39 #define GST_IS_IDENTITY_CLASS(obj) \
40 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IDENTITY))
42 typedef struct _GstIdentity GstIdentity;
43 typedef struct _GstIdentityClass GstIdentityClass;
56 struct _GstIdentityClass {
57 GstElementClass parent_class;
60 GType gst_identity_get_type(void);
63 GstElementDetails gst_identity_details = {
66 "Test for the GstByteStream code",
68 "Erik Walthinsen <omega@temple-baptist.com>",
73 /* Identity signals and args */
86 static void gst_identity_class_init (GstIdentityClass *klass);
87 static void gst_identity_init (GstIdentity *identity);
89 static void gst_identity_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
90 static void gst_identity_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
92 static void gst_identity_loop (GstElement *element);
94 static GstElementClass *parent_class = NULL;
95 /* static guint gst_identity_signals[LAST_SIGNAL] = { 0 }; */
98 gst_identity_get_type (void)
100 static GType identity_type = 0;
102 if (!identity_type) {
103 static const GTypeInfo identity_info = {
104 sizeof(GstIdentityClass), NULL,
106 (GClassInitFunc)gst_identity_class_init,
111 (GInstanceInitFunc)gst_identity_init,
113 identity_type = g_type_register_static (GST_TYPE_ELEMENT, "GstBSTest", &identity_info, 0);
115 return identity_type;
119 gst_identity_class_init (GstIdentityClass *klass)
121 GObjectClass *gobject_class;
123 gobject_class = (GObjectClass*)klass;
125 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
127 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BYTE_SIZE,
128 g_param_spec_uint ("byte_size", "byte_size", "byte_size",
129 0, G_MAXUINT, 0, G_PARAM_READWRITE));
130 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_COUNT,
131 g_param_spec_uint ("count", "count", "count",
132 0, G_MAXUINT, 0, G_PARAM_READWRITE));
134 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_identity_set_property);
135 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_identity_get_property);
139 static GstPadNegotiateReturn
140 gst_identity_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data)
142 GstIdentity *identity;
144 identity = GST_IDENTITY (gst_pad_get_parent (pad));
146 return gst_pad_negotiate_proxy (pad, identity->sinkpad, caps);
149 static GstPadNegotiateReturn
150 gst_identity_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data)
152 GstIdentity *identity;
154 identity = GST_IDENTITY (gst_pad_get_parent (pad));
156 return gst_pad_negotiate_proxy (pad, identity->srcpad, caps);
161 gst_identity_init (GstIdentity *identity)
163 identity->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
164 gst_element_add_pad (GST_ELEMENT (identity), identity->sinkpad);
165 /*gst_pad_set_negotiate_function (identity->sinkpad, gst_identity_negotiate_sink); */
167 identity->srcpad = gst_pad_new ("src", GST_PAD_SRC);
168 gst_element_add_pad (GST_ELEMENT (identity), identity->srcpad);
169 /*gst_pad_set_negotiate_function (identity->srcpad, gst_identity_negotiate_src); */
171 gst_element_set_loop_function (GST_ELEMENT (identity), gst_identity_loop);
173 identity->byte_size = 384;
176 identity->bs = gst_bytestream_new(identity->sinkpad);
180 gst_identity_loop (GstElement *element)
182 GstIdentity *identity;
186 g_return_if_fail (element != NULL);
187 g_return_if_fail (GST_IS_IDENTITY (element));
189 identity = GST_IDENTITY (element);
191 /* THIS IS THE BUFFER BASED ONE
195 for (i=0;i<identity->count;i++) {
196 * g_print("bstest: getting a buffer of %d bytes\n",identity->byte_size); *
197 buf = gst_bytestream_read(identity->bs,identity->byte_size);
198 if (!buf) g_print("BUFFER IS BOGUS\n");
199 * g_print("pushing the buffer, %d bytes at %d\n",GST_BUFFER_SIZE(buf),GST_BUFFER_OFFSET(buf)); *
200 gst_pad_push(identity->srcpad,buf);
202 gst_bytestream_print_status(identity->bs);
207 } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element));
210 /* THIS IS THE BYTE BASED ONE*/
212 for (i=0;i<identity->count;i++) {
214 buf = gst_buffer_new();
215 /* note that this is dangerous, as it does *NOT* refcount the data, it can go away!!! */
216 GST_BUFFER_SIZE(buf) = gst_bytestream_peek_bytes(identity->bs, &data, identity->byte_size);
217 GST_BUFFER_DATA(buf) = data;
218 GST_BUFFER_FLAG_SET(buf,GST_BUFFER_DONTFREE);
219 gst_pad_push(identity->srcpad,buf);
220 gst_bytestream_flush(identity->bs,identity->byte_size);
224 /* implicit declaration of function `GST_ELEMENT_IS_COTHREAD_STOPPING' */
225 #define GST_ELEMENT_IS_COTHREAD_STOPPING(element) GST_FLAG_IS_SET((element), GST_ELEMENT_SCHEDULER_PRIVATE1)
226 } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element));
231 gst_identity_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
233 GstIdentity *identity;
235 /* it's not null if we got it, but it might not be ours */
236 g_return_if_fail (GST_IS_IDENTITY (object));
238 identity = GST_IDENTITY (object);
242 identity->byte_size = g_value_get_uint (value);
245 identity->count = g_value_get_uint (value);
248 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
253 static void gst_identity_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {
254 GstIdentity *identity;
256 /* it's not null if we got it, but it might not be ours */
257 g_return_if_fail (GST_IS_IDENTITY (object));
259 identity = GST_IDENTITY (object);
263 g_value_set_uint (value, identity->byte_size);
266 g_value_set_uint (value, identity->count);
269 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
275 plugin_init (GModule *module, GstPlugin *plugin)
277 GstElementFactory *factory;
279 /* we need gstbytestream */
280 if (!gst_library_load ("gstbytestream")) {
281 g_print("can't load bytestream\n");
285 /* We need to create an ElementFactory for each element we provide.
286 * This consists of the name of the element, the GType identifier,
287 * and a pointer to the details structure at the top of the file.
289 factory = gst_element_factory_new("gstbstest", GST_TYPE_IDENTITY, &gst_identity_details);
290 g_return_val_if_fail(factory != NULL, FALSE);
292 /* The very last thing is to register the elementfactory with the plugin. */
293 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
298 GstPluginDesc plugin_desc = {