4 * Copyright (C) 1999-2001 Erik Walthinsen <omega@cse.ogi.edu>
5 * Copyright (C) 2003 David A. Schleef <ds@schleef.org>
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.
27 #include <gdk-pixbuf/gdk-pixbuf.h>
30 #include "gstgdkpixbuf.h"
32 static GstElementDetails plugin_details = {
33 "GdkPixbuf image decoder",
36 "Decodes images in a video stream using GdkPixbuf",
38 "David A. Schleef <ds@schleef.org>",
42 /* Filter signals and args */
53 GST_PAD_TEMPLATE_FACTORY (gst_gdk_pixbuf_sink_factory,
57 GST_CAPS_NEW("gdk_pixbuf_sink", "image/png", NULL),
58 GST_CAPS_NEW("gdk_pixbuf_sink", "image/jpeg", NULL),
59 GST_CAPS_NEW("gdk_pixbuf_sink", "image/gif", NULL),
60 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-icon", NULL),
61 GST_CAPS_NEW("gdk_pixbuf_sink", "application/x-navi-animation", NULL),
62 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-cmu-raster", NULL),
63 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-sun-raster", NULL),
64 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-pixmap", NULL),
65 GST_CAPS_NEW("gdk_pixbuf_sink", "image/tiff", NULL),
66 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-portable-anymap", NULL),
67 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-portable-bitmap", NULL),
68 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-portable-graymap", NULL),
69 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-portable-pixmap", NULL),
70 GST_CAPS_NEW("gdk_pixbuf_sink", "image/bmp", NULL),
71 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-bmp", NULL),
72 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-MS-bmp", NULL),
73 GST_CAPS_NEW("gdk_pixbuf_sink", "image/vnd.wap.wbmp", NULL),
74 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-bitmap", NULL),
75 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-tga", NULL)
78 GST_PAD_TEMPLATE_FACTORY (gst_gdk_pixbuf_src_factory,
85 "width", GST_PROPS_INT_RANGE(1,INT_MAX),
86 "height", GST_PROPS_INT_RANGE(1,INT_MAX),
87 /* well, it's needed for connectivity but this
88 * doesn't really make sense... */
89 "framerate", GST_PROPS_FLOAT_RANGE(0, G_MAXFLOAT),
90 "bpp", GST_PROPS_INT(32),
91 "depth", GST_PROPS_INT(24),
92 "endianness", GST_PROPS_INT(G_BIG_ENDIAN),
93 "red_mask", GST_PROPS_INT(0x00ff0000),
94 "green_mask", GST_PROPS_INT(0x0000ff00),
95 "blue_mask", GST_PROPS_INT(0x000000ff)
99 static void gst_gdk_pixbuf_class_init (GstGdkPixbufClass *klass);
100 static void gst_gdk_pixbuf_init (GstGdkPixbuf *filter);
102 static void gst_gdk_pixbuf_set_property(GObject *object, guint prop_id,
105 static void gst_gdk_pixbuf_get_property(GObject *object, guint prop_id,
109 static void gst_gdk_pixbuf_chain (GstPad *pad, GstBuffer *buf);
111 static GstElementClass *parent_class = NULL;
113 static GstPadLinkReturn
114 gst_gdk_pixbuf_sink_link (GstPad *pad, GstCaps *caps)
116 GstGdkPixbuf *filter;
118 filter = GST_GDK_PIXBUF (gst_pad_get_parent (pad));
119 g_return_val_if_fail (filter != NULL, GST_PAD_LINK_REFUSED);
120 g_return_val_if_fail (GST_IS_GDK_PIXBUF (filter),
121 GST_PAD_LINK_REFUSED);
123 if (GST_CAPS_IS_FIXED (caps))
125 return GST_PAD_LINK_OK;
128 return GST_PAD_LINK_DELAYED;
131 #if GDK_PIXBUF_MAJOR == 2 && GDK_PIXBUF_MINOR < 2
132 /* gdk-pixbuf prior to 2.2 didn't have gdk_pixbuf_get_formats().
133 * These are just the formats that gdk-pixbuf is known to support.
134 * But maybe not -- it may have been compiled without an external
136 static GstCaps *gst_gdk_pixbuf_get_capslist(void)
140 capslist = gst_caps_chain(
141 GST_CAPS_NEW("gdk_pixbuf_sink", "image/png", NULL),
142 GST_CAPS_NEW("gdk_pixbuf_sink", "image/jpeg", NULL),
143 GST_CAPS_NEW("gdk_pixbuf_sink", "image/gif", NULL),
144 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-icon", NULL),
145 GST_CAPS_NEW("gdk_pixbuf_sink", "application/x-navi-animation", NULL),
146 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-cmu-raster", NULL),
147 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-sun-raster", NULL),
148 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-pixmap", NULL),
149 GST_CAPS_NEW("gdk_pixbuf_sink", "image/tiff", NULL),
150 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-portable-anymap", NULL),
151 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-portable-bitmap", NULL),
152 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-portable-graymap", NULL),
153 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-portable-pixmap", NULL),
154 GST_CAPS_NEW("gdk_pixbuf_sink", "image/bmp", NULL),
155 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-bmp", NULL),
156 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-MS-bmp", NULL),
157 GST_CAPS_NEW("gdk_pixbuf_sink", "image/vnd.wap.wbmp", NULL),
158 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-bitmap", NULL),
159 GST_CAPS_NEW("gdk_pixbuf_sink", "image/x-tga", NULL),
165 static GstCaps *gst_gdk_pixbuf_get_capslist(void)
169 GdkPixbufFormat *pixbuf_format;
172 static GstCaps *capslist = NULL;
175 slist0 = gdk_pixbuf_get_formats();
177 for(slist = slist0;slist;slist=g_slist_next(slist)){
178 pixbuf_format = slist->data;
179 mimetypes = gdk_pixbuf_format_get_mime_types(pixbuf_format);
180 for(mimetype = mimetypes; *mimetype; mimetype++){
181 capslist = gst_caps_append(capslist, gst_caps_new("ack",*mimetype,NULL));
185 gst_caps_ref(capslist);
186 gst_caps_sink(capslist);
187 g_slist_free(slist0);
189 g_print("%s\n",gst_caps_to_string(capslist));
196 static GstCaps *gst_gdk_pixbuf_sink_getcaps(GstPad *pad, GstCaps *caps)
198 GstGdkPixbuf *filter;
200 filter = GST_GDK_PIXBUF (gst_pad_get_parent (pad));
201 g_return_val_if_fail (filter != NULL, NULL);
202 g_return_val_if_fail (GST_IS_GDK_PIXBUF (filter), NULL);
204 return gst_gdk_pixbuf_get_capslist();
208 gst_gdk_pixbuf_get_type (void)
210 static GType plugin_type = 0;
214 static const GTypeInfo plugin_info =
216 sizeof (GstGdkPixbufClass),
219 (GClassInitFunc) gst_gdk_pixbuf_class_init,
222 sizeof (GstGdkPixbuf),
224 (GInstanceInitFunc) gst_gdk_pixbuf_init,
226 plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
233 /* initialize the plugin's class */
235 gst_gdk_pixbuf_class_init (GstGdkPixbufClass *klass)
237 GObjectClass *gobject_class;
238 GstElementClass *gstelement_class;
240 gobject_class = (GObjectClass*) klass;
241 gstelement_class = (GstElementClass*) klass;
243 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
245 g_object_class_install_property (gobject_class, ARG_SILENT,
246 g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?",
247 FALSE, G_PARAM_READWRITE));
249 gobject_class->set_property = gst_gdk_pixbuf_set_property;
250 gobject_class->get_property = gst_gdk_pixbuf_get_property;
254 gst_gdk_pixbuf_init (GstGdkPixbuf *filter)
256 filter->sinkpad = gst_pad_new_from_template (gst_gdk_pixbuf_sink_factory (),
258 gst_pad_set_link_function (filter->sinkpad, gst_gdk_pixbuf_sink_link);
259 gst_pad_set_getcaps_function (filter->sinkpad, gst_gdk_pixbuf_sink_getcaps);
260 filter->srcpad = gst_pad_new_from_template (gst_gdk_pixbuf_src_factory (),
263 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
264 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
265 gst_pad_set_chain_function (filter->sinkpad, gst_gdk_pixbuf_chain);
270 gst_gdk_pixbuf_chain (GstPad *pad, GstBuffer *buf)
272 GstGdkPixbuf *filter;
273 GdkPixbufLoader *pixbuf_loader;
276 GError *error = NULL;
278 g_print("gst_gdk_pixbuf_chain\n");
280 g_return_if_fail (GST_IS_PAD (pad));
281 g_return_if_fail (buf != NULL);
283 filter = GST_GDK_PIXBUF (GST_OBJECT_PARENT (pad));
284 g_return_if_fail (GST_IS_GDK_PIXBUF (filter));
286 pixbuf_loader = gdk_pixbuf_loader_new();
287 //pixbuf_loader = gdk_pixbuf_loader_new_with_type("gif");
289 gdk_pixbuf_loader_write(pixbuf_loader, GST_BUFFER_DATA(buf),
290 GST_BUFFER_SIZE(buf), &error);
291 gdk_pixbuf_loader_close(pixbuf_loader, &error);
292 pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader);
294 g_print("width=%d height=%d\n", gdk_pixbuf_get_width(pixbuf),
295 gdk_pixbuf_get_height(pixbuf));
297 if(filter->image_size == 0){
300 filter->width = gdk_pixbuf_get_width(pixbuf);
301 filter->height = gdk_pixbuf_get_height(pixbuf);
302 filter->rowstride = gdk_pixbuf_get_rowstride(pixbuf);
303 filter->image_size = filter->rowstride * filter->height;
305 caps = gst_pad_get_caps(filter->srcpad);
306 gst_caps_set(caps, "width", GST_PROPS_INT(filter->width));
307 gst_caps_set(caps, "height", GST_PROPS_INT(filter->height));
308 gst_caps_set(caps, "framerate", GST_PROPS_FLOAT(0.));
310 gst_pad_try_set_caps(filter->srcpad, caps);
313 outbuf = gst_buffer_new();
314 GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(buf);
315 GST_BUFFER_DURATION(outbuf) = GST_BUFFER_DURATION(buf);
317 GST_BUFFER_SIZE(outbuf) = filter->image_size;
318 GST_BUFFER_DATA(outbuf) = g_malloc(filter->image_size);
320 memcpy(GST_BUFFER_DATA(outbuf), gdk_pixbuf_get_pixels(pixbuf),
323 g_object_unref(G_OBJECT(pixbuf_loader));
325 gst_pad_push (filter->srcpad, outbuf);
329 gst_gdk_pixbuf_set_property (GObject *object, guint prop_id,
330 const GValue *value, GParamSpec *pspec)
332 GstGdkPixbuf *filter;
334 g_return_if_fail (GST_IS_GDK_PIXBUF (object));
335 filter = GST_GDK_PIXBUF (object);
340 //filter->silent = g_value_get_boolean (value);
343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
349 gst_gdk_pixbuf_get_property (GObject *object, guint prop_id,
350 GValue *value, GParamSpec *pspec)
352 GstGdkPixbuf *filter;
354 g_return_if_fail (GST_IS_GDK_PIXBUF (object));
355 filter = GST_GDK_PIXBUF (object);
359 //g_value_set_boolean (value, filter->silent);
362 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
367 /* entry point to initialize the plug-in
368 * initialize the plug-in itself
369 * register the element factories and pad templates
370 * register the features
373 plugin_init (GModule *module, GstPlugin *plugin)
375 GstElementFactory *factory;
377 factory = gst_element_factory_new ("gdkpixbufdec", GST_TYPE_GDK_PIXBUF,
379 g_return_val_if_fail (factory != NULL, FALSE);
381 gst_element_factory_add_pad_template (factory,
382 gst_gdk_pixbuf_src_factory ());
383 gst_element_factory_add_pad_template (factory,
384 gst_gdk_pixbuf_sink_factory ());
386 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
388 /* plugin initialisation succeeded */
392 /* this is the structure that gst-register looks for
393 * so keep the name plugin_desc, or you cannot get your plug-in registered */
394 GstPluginDesc plugin_desc = {