gstreamer/ext/gdk_pixbuf/gstgdkpixbuf.c

516 lines
15 KiB
C
Raw Normal View History

/* GStreamer GdkPixbuf-based image decoder
* Copyright (C) 1999-2001 Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2003 David A. Schleef <ds@schleef.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gst/video/video.h>
#include <string.h>
#include "gstgdkpixbuf.h"
GST_DEBUG_CATEGORY_STATIC (gst_gdk_pixbuf_debug);
#define GST_CAT_DEFAULT gst_gdk_pixbuf_debug
static const GstElementDetails plugin_details =
better/unified long descriptions Original commit message from CVS: * ext/aalib/gstaasink.c: * ext/annodex/gstcmmldec.c: * ext/annodex/gstcmmlenc.c: * ext/cairo/gsttextoverlay.c: * ext/cairo/gsttimeoverlay.c: * ext/cdio/gstcdiocddasrc.c: * ext/dv/gstdvdec.c: * ext/esd/esdmon.c: * ext/esd/esdsink.c: * ext/flac/gstflacdec.c: * ext/flac/gstflacenc.c: * ext/flac/gstflactag.c: * ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_base_init): * ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init): * ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init): * ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init): * ext/gdk_pixbuf/gstgdkpixbuf.c: * ext/gdk_pixbuf/pixbufscale.c: * ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init): * ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init): * ext/jpeg/gstjpegdec.c: * ext/jpeg/gstjpegenc.c: * ext/jpeg/gstsmokedec.c: * ext/jpeg/gstsmokeenc.c: * ext/libcaca/gstcacasink.c: * ext/libmng/gstmngdec.c: * ext/libmng/gstmngenc.c: * ext/libpng/gstpngdec.c: * ext/libpng/gstpngenc.c: * ext/mikmod/gstmikmod.c: * ext/raw1394/gstdv1394src.c: * ext/shout2/gstshout2.c: * ext/speex/gstspeexdec.c: * ext/speex/gstspeexenc.c: * gst/alpha/gstalpha.c: * gst/alpha/gstalphacolor.c: * gst/auparse/gstauparse.c: * gst/autodetect/gstautoaudiosink.c: (gst_auto_audio_sink_base_init): * gst/autodetect/gstautovideosink.c: (gst_auto_video_sink_base_init): * gst/avi/gstavimux.c: (gst_avimux_base_init): * gst/cutter/gstcutter.c: * gst/debug/breakmydata.c: * gst/debug/efence.c: * gst/debug/gstnavigationtest.c: * gst/debug/negotiation.c: * gst/debug/progressreport.c: * gst/debug/testplugin.c: * gst/effectv/gstaging.c: * gst/effectv/gstdice.c: * gst/effectv/gstedge.c: * gst/effectv/gstquark.c: * gst/effectv/gstrev.c: * gst/effectv/gstvertigo.c: * gst/effectv/gstwarp.c: * gst/flx/gstflxdec.c: * gst/goom/gstgoom.c: * gst/interleave/deinterleave.c: * gst/interleave/interleave.c: * gst/law/alaw-decode.c: (gst_alawdec_base_init): * gst/law/alaw-encode.c: (gst_alawenc_base_init): * gst/law/mulaw-decode.c: (gst_mulawdec_base_init): * gst/law/mulaw-encode.c: (gst_mulawenc_base_init): * gst/level/gstlevel.c: * gst/matroska/matroska-demux.c: (gst_matroska_demux_base_init): * gst/matroska/matroska-mux.c: (gst_matroska_mux_base_init): * gst/median/gstmedian.c: * gst/monoscope/gstmonoscope.c: * gst/multipart/multipartdemux.c: * gst/multipart/multipartmux.c: * gst/oldcore/gstmd5sink.c: * gst/oldcore/gstmultifilesrc.c: * gst/oldcore/gstpipefilter.c: * gst/oldcore/gstshaper.c: * gst/oldcore/gststatistics.c: * gst/rtp/gstasteriskh263.c: * gst/rtp/gstrtpL16depay.c: * gst/rtp/gstrtpL16pay.c: * gst/rtp/gstrtpamrdepay.c: * gst/rtp/gstrtpamrpay.c: * gst/rtp/gstrtpdepay.c: * gst/rtp/gstrtpgsmpay.c: * gst/rtp/gstrtph263pay.c: * gst/rtp/gstrtph263pdepay.c: * gst/rtp/gstrtph263ppay.c: * gst/rtp/gstrtpmp4gpay.c: * gst/rtp/gstrtpmp4vdepay.c: * gst/rtp/gstrtpmp4vpay.c: * gst/rtp/gstrtpmpadepay.c: * gst/rtp/gstrtpmpapay.c: * gst/rtp/gstrtppcmadepay.c: * gst/rtp/gstrtppcmapay.c: * gst/rtp/gstrtppcmudepay.c: * gst/rtp/gstrtppcmupay.c: * gst/rtp/gstrtpspeexdepay.c: * gst/rtp/gstrtpspeexpay.c: * gst/rtsp/gstrtpdec.c: * gst/smpte/gstsmpte.c: * gst/videobox/gstvideobox.c: * gst/videofilter/gstgamma.c: (gst_gamma_base_init): * gst/videofilter/gstvideobalance.c: * gst/videofilter/gstvideoflip.c: * gst/videofilter/gstvideotemplate.c: (gst_videotemplate_base_init): * gst/videomixer/videomixer.c: * gst/wavenc/gstwavenc.c: * gst/wavparse/gstwavparse.c: (gst_wavparse_base_init): better/unified long descriptions Fixed #336602 Some cleanups to auparse, don't send multiple newsegments.
2006-03-30 15:37:05 +00:00
GST_ELEMENT_DETAILS ("GdkPixbuf image decoder",
"Codec/Decoder/Image",
"Decodes images in a video stream using GdkPixbuf",
"David A. Schleef <ds@schleef.org>, Renato Filho <renato.filho@indt.org.br>");
enum
{
ARG_0,
ARG_SILENT /* FIXME 0.11: remove */
};
static GstStaticPadTemplate gst_gdk_pixbuf_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("image/png; "
/* "image/jpeg; " disabled because we can't handle MJPEG */
"image/gif; "
"image/x-icon; "
"application/x-navi-animation; "
"image/x-cmu-raster; "
"image/x-sun-raster; "
"image/x-pixmap; "
"image/tiff; "
"image/x-portable-anymap; "
"image/x-portable-bitmap; "
"image/x-portable-graymap; "
"image/x-portable-pixmap; "
"image/bmp; "
"image/x-bmp; "
"image/x-MS-bmp; "
"image/vnd.wap.wbmp; " "image/x-bitmap; " "image/x-tga; "
"image/x-pcx; image/svg; image/svg+xml")
);
static GstStaticPadTemplate gst_gdk_pixbuf_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB "; " GST_VIDEO_CAPS_RGBA)
);
gboolean pixbufscale_init (GstPlugin * plugin);
static void gst_gdk_pixbuf_base_init (gpointer g_class);
static void gst_gdk_pixbuf_class_init (GstGdkPixbufClass * klass);
static void gst_gdk_pixbuf_init (GstGdkPixbuf * filter,
GstGdkPixbufClass * klass);
static void gst_gdk_pixbuf_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gdk_pixbuf_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static GstFlowReturn gst_gdk_pixbuf_chain (GstPad * pad, GstBuffer * buffer);
static gboolean gst_gdk_pixbuf_sink_event (GstPad * pad, GstEvent * event);
#ifdef enable_typefind
static void gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore);
#endif
GST_BOILERPLATE (GstGdkPixbuf, gst_gdk_pixbuf, GstElement, GST_TYPE_ELEMENT);
static gboolean
gst_gdk_pixbuf_sink_setcaps (GstPad * pad, GstCaps * caps)
{
GstGdkPixbuf *filter;
const GValue *framerate;
GstStructure *s;
filter = GST_GDK_PIXBUF (gst_pad_get_parent (pad));
s = gst_caps_get_structure (caps, 0);
filter->framerate_numerator = 0;
filter->framerate_denominator = 1;
if ((framerate = gst_structure_get_value (s, "framerate")) != NULL) {
filter->framerate_numerator = gst_value_get_fraction_numerator (framerate);
filter->framerate_denominator =
gst_value_get_fraction_denominator (framerate);
GST_DEBUG ("got framerate of %d/%d fps => packetized mode",
filter->framerate_numerator, filter->framerate_denominator);
}
close #333784 unref the result of gst_pad_get_parent() by: Christophe Fergeau. Original commit message from CVS: * ext/cairo/gsttextoverlay.c: (gst_text_overlay_setcaps): * ext/esd/esdmon.c: (gst_esdmon_get): * ext/flac/gstflactag.c: (gst_flac_tag_chain): * ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_sink_setcaps), (gst_gdk_pixbuf_sink_getcaps): * ext/jpeg/gstjpegenc.c: (gst_jpegenc_getcaps), (gst_jpegenc_setcaps): * ext/jpeg/gstsmokedec.c: (gst_smokedec_chain): * ext/jpeg/gstsmokeenc.c: (gst_smokeenc_getcaps), (gst_smokeenc_setcaps): * ext/libmng/gstmngdec.c: (gst_mngdec_sinklink), (gst_mngdec_src_getcaps): * ext/libmng/gstmngenc.c: (gst_mngenc_sinklink), (gst_mngenc_chain): * ext/libpng/gstpngenc.c: (gst_pngenc_setcaps): * ext/mikmod/gstmikmod.c: (gst_mikmod_srclink): * ext/speex/gstspeexdec.c: (speex_dec_convert), (speex_dec_src_event), (speex_dec_chain): * gst/avi/gstavimux.c: (gst_avimux_vidsinkconnect), (gst_avimux_audsinkconnect), (gst_avimux_handle_event): * gst/debug/negotiation.c: (gst_negotiation_getcaps), (gst_negotiation_pad_link), (gst_negotiation_chain): * gst/flx/gstflxdec.c: (gst_flxdec_src_query_handler), (gst_flxdec_chain): * gst/interleave/deinterleave.c: (deinterleave_sink_link), (deinterleave_chain): * gst/law/mulaw-encode.c: (mulawenc_setcaps): * gst/median/gstmedian.c: (gst_median_link): * gst/monoscope/gstmonoscope.c: (gst_monoscope_srcconnect), (gst_monoscope_chain): * gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_sinkconnect): * gst/wavenc/gstwavenc.c: (gst_wavenc_sink_setcaps): * sys/osxaudio/gstosxaudiosink.c: (gst_osxaudiosink_chain): * sys/osxaudio/gstosxaudiosrc.c: (gst_osxaudiosrc_get): close #333784 unref the result of gst_pad_get_parent() by: Christophe Fergeau.
2006-03-13 15:49:08 +00:00
gst_object_unref (filter);
return TRUE;
}
static GstCaps *
gst_gdk_pixbuf_get_capslist (void)
{
GSList *slist;
GSList *slist0;
GstCaps *capslist = NULL;
GstCaps *return_caps = NULL;
capslist = gst_caps_new_empty ();
slist0 = gdk_pixbuf_get_formats ();
for (slist = slist0; slist; slist = g_slist_next (slist)) {
GdkPixbufFormat *pixbuf_format;
char **mimetypes;
char **mimetype;
pixbuf_format = slist->data;
mimetypes = gdk_pixbuf_format_get_mime_types (pixbuf_format);
for (mimetype = mimetypes; *mimetype; mimetype++) {
gst_caps_append_structure (capslist, gst_structure_new (*mimetype, NULL));
}
g_strfreev (mimetypes);
}
g_slist_free (slist0);
return_caps = gst_caps_intersect (capslist,
gst_static_caps_get (&gst_gdk_pixbuf_sink_template.static_caps));
gst_caps_unref (capslist);
return return_caps;
}
static GstCaps *
gst_gdk_pixbuf_sink_getcaps (GstPad * pad)
{
return gst_gdk_pixbuf_get_capslist ();
}
static void
gst_gdk_pixbuf_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gdk_pixbuf_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gdk_pixbuf_sink_template));
gst_element_class_set_details (element_class, &plugin_details);
}
/* initialize the plugin's class */
static void
gst_gdk_pixbuf_class_init (GstGdkPixbufClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gobject_class->set_property = gst_gdk_pixbuf_set_property;
gobject_class->get_property = gst_gdk_pixbuf_get_property;
g_object_class_install_property (gobject_class, ARG_SILENT,
g_param_spec_boolean ("silent", "Silent",
"Produce verbose output ? (deprecated)", FALSE, G_PARAM_READWRITE));
}
static void
gst_gdk_pixbuf_init (GstGdkPixbuf * filter, GstGdkPixbufClass * klass)
{
filter->sinkpad =
Fix memleak with gst_static_pad_template_get(). Original commit message from CVS: * ext/cairo/gsttextoverlay.c: (gst_text_overlay_init): * ext/dv/gstdvdemux.c: (gst_dvdemux_init), (gst_dvdemux_add_pads): * ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_init): * ext/jpeg/gstjpegdec.c: (gst_jpeg_dec_init), (gst_jpeg_dec_setcaps): * ext/jpeg/gstjpegenc.c: (gst_jpegenc_init): * ext/jpeg/gstsmokedec.c: (gst_smokedec_init): * ext/jpeg/gstsmokeenc.c: (gst_smokeenc_init): * ext/libmng/gstmngdec.c: (gst_mngdec_init), (gst_mngdec_src_getcaps): * ext/libpng/gstpngdec.c: (gst_pngdec_init), (gst_pngdec_caps_create_and_set): * ext/libpng/gstpngenc.c: (gst_pngenc_init): * ext/mikmod/gstmikmod.c: (gst_mikmod_init): * ext/speex/gstspeexdec.c: (gst_speex_dec_init): * gst/alpha/gstalpha.c: (gst_alpha_init): * gst/auparse/gstauparse.c: (gst_au_parse_init): * gst/avi/gstavidemux.c: (gst_avi_demux_init), (gst_avi_demux_handle_src_event), (gst_avi_demux_parse_stream): * gst/cutter/gstcutter.c: (gst_cutter_init): * gst/debug/efence.c: (gst_efence_init), (gst_efence_getrange), (gst_efence_checkgetrange): * gst/debug/negotiation.c: (gst_negotiation_init): * gst/flx/gstflxdec.c: (gst_flxdec_init): * gst/goom/gstgoom.c: (gst_goom_init): * gst/rtp/gstasteriskh263.c: (gst_asteriskh263_init): * gst/rtp/gstrtpL16depay.c: (gst_rtp_L16depay_init): * gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_init): * gst/rtp/gstrtpamrdepay.c: (gst_rtp_amr_depay_init): * gst/rtp/gstrtpdepay.c: (gst_rtp_depay_init): * gst/rtp/gstrtpmpadepay.c: (gst_rtp_mpa_depay_init): * gst/rtsp/gstrtpdec.c: (gst_rtpdec_init): * gst/smpte/gstsmpte.c: (gst_smpte_init): * gst/wavparse/gstwavparse.c: (gst_wavparse_init), (gst_wavparse_create_sourcepad): Fix memleak with gst_static_pad_template_get(). This uses gst_pad_new_from_static_template() instead. Fixes #333512
2006-03-15 16:17:12 +00:00
gst_pad_new_from_static_template (&gst_gdk_pixbuf_sink_template, "sink");
gst_pad_set_setcaps_function (filter->sinkpad,
GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_sink_setcaps));
gst_pad_set_getcaps_function (filter->sinkpad,
GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_sink_getcaps));
gst_pad_set_chain_function (filter->sinkpad,
GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_chain));
gst_pad_set_event_function (filter->sinkpad,
GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_sink_event));
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
Fix memleak with gst_static_pad_template_get(). Original commit message from CVS: * ext/cairo/gsttextoverlay.c: (gst_text_overlay_init): * ext/dv/gstdvdemux.c: (gst_dvdemux_init), (gst_dvdemux_add_pads): * ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_init): * ext/jpeg/gstjpegdec.c: (gst_jpeg_dec_init), (gst_jpeg_dec_setcaps): * ext/jpeg/gstjpegenc.c: (gst_jpegenc_init): * ext/jpeg/gstsmokedec.c: (gst_smokedec_init): * ext/jpeg/gstsmokeenc.c: (gst_smokeenc_init): * ext/libmng/gstmngdec.c: (gst_mngdec_init), (gst_mngdec_src_getcaps): * ext/libpng/gstpngdec.c: (gst_pngdec_init), (gst_pngdec_caps_create_and_set): * ext/libpng/gstpngenc.c: (gst_pngenc_init): * ext/mikmod/gstmikmod.c: (gst_mikmod_init): * ext/speex/gstspeexdec.c: (gst_speex_dec_init): * gst/alpha/gstalpha.c: (gst_alpha_init): * gst/auparse/gstauparse.c: (gst_au_parse_init): * gst/avi/gstavidemux.c: (gst_avi_demux_init), (gst_avi_demux_handle_src_event), (gst_avi_demux_parse_stream): * gst/cutter/gstcutter.c: (gst_cutter_init): * gst/debug/efence.c: (gst_efence_init), (gst_efence_getrange), (gst_efence_checkgetrange): * gst/debug/negotiation.c: (gst_negotiation_init): * gst/flx/gstflxdec.c: (gst_flxdec_init): * gst/goom/gstgoom.c: (gst_goom_init): * gst/rtp/gstasteriskh263.c: (gst_asteriskh263_init): * gst/rtp/gstrtpL16depay.c: (gst_rtp_L16depay_init): * gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_init): * gst/rtp/gstrtpamrdepay.c: (gst_rtp_amr_depay_init): * gst/rtp/gstrtpdepay.c: (gst_rtp_depay_init): * gst/rtp/gstrtpmpadepay.c: (gst_rtp_mpa_depay_init): * gst/rtsp/gstrtpdec.c: (gst_rtpdec_init): * gst/smpte/gstsmpte.c: (gst_smpte_init): * gst/wavparse/gstwavparse.c: (gst_wavparse_init), (gst_wavparse_create_sourcepad): Fix memleak with gst_static_pad_template_get(). This uses gst_pad_new_from_static_template() instead. Fixes #333512
2006-03-15 16:17:12 +00:00
filter->srcpad =
gst_pad_new_from_static_template (&gst_gdk_pixbuf_src_template, "src");
gst_pad_use_fixed_caps (filter->srcpad);
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
filter->last_timestamp = GST_CLOCK_TIME_NONE;
filter->pixbuf_loader = NULL;
}
static GstFlowReturn
gst_gdk_pixbuf_flush (GstGdkPixbuf * filter)
{
GstBuffer *outbuf;
GdkPixbuf *pixbuf;
int y;
guint8 *out_pix;
guint8 *in_pix;
int in_rowstride;
GstFlowReturn ret;
GstCaps *caps = NULL;
gint n_channels;
pixbuf = gdk_pixbuf_loader_get_pixbuf (filter->pixbuf_loader);
if (pixbuf == NULL)
goto no_pixbuf;
if (filter->image_size == 0) {
filter->width = gdk_pixbuf_get_width (pixbuf);
filter->height = gdk_pixbuf_get_height (pixbuf);
filter->rowstride = gdk_pixbuf_get_rowstride (pixbuf);
filter->image_size = filter->rowstride * filter->height;
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
switch (n_channels) {
case 3:
caps = gst_caps_from_string (GST_VIDEO_CAPS_RGB);
break;
case 4:
caps = gst_caps_from_string (GST_VIDEO_CAPS_RGBA);
break;
default:
goto channels_not_supported;
}
gst_caps_set_simple (caps,
"width", G_TYPE_INT, filter->width,
"height", G_TYPE_INT, filter->height,
"framerate", GST_TYPE_FRACTION, filter->framerate_numerator,
filter->framerate_denominator, NULL);
GST_DEBUG ("Set size to %dx%d", filter->width, filter->height);
gst_pad_set_caps (filter->srcpad, caps);
gst_caps_unref (caps);
}
ret = gst_pad_alloc_buffer_and_set_caps (filter->srcpad,
GST_BUFFER_OFFSET_NONE,
filter->image_size, GST_PAD_CAPS (filter->srcpad), &outbuf);
if (ret != GST_FLOW_OK)
goto no_buffer;
GST_BUFFER_TIMESTAMP (outbuf) = filter->last_timestamp;
GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
in_pix = gdk_pixbuf_get_pixels (pixbuf);
in_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
out_pix = GST_BUFFER_DATA (outbuf);
/* FIXME, last line might not have rowstride pixels */
for (y = 0; y < filter->height; y++) {
memcpy (out_pix, in_pix, filter->rowstride);
in_pix += in_rowstride;
out_pix += filter->rowstride;
}
GST_DEBUG ("pushing... %d bytes", GST_BUFFER_SIZE (outbuf));
return gst_pad_push (filter->srcpad, outbuf);
/* ERRORS */
no_pixbuf:
{
GST_ELEMENT_ERROR (filter, STREAM, DECODE, (NULL), ("error geting pixbuf"));
return GST_FLOW_ERROR;
}
channels_not_supported:
{
GST_ELEMENT_ERROR (filter, STREAM, DECODE, (NULL),
("%d channels not supported", n_channels));
return GST_FLOW_ERROR;
}
no_buffer:
{
GST_DEBUG ("Failed to create outbuffer - %s", gst_flow_get_name (ret));
return ret;
}
}
static gboolean
gst_gdk_pixbuf_sink_event (GstPad * pad, GstEvent * event)
{
GstFlowReturn res = GST_FLOW_OK;
gboolean ret = TRUE;
GstGdkPixbuf *pixbuf;
pixbuf = GST_GDK_PIXBUF (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS:
if (pixbuf->pixbuf_loader != NULL) {
gdk_pixbuf_loader_close (pixbuf->pixbuf_loader, NULL);
res = gst_gdk_pixbuf_flush (pixbuf);
g_object_unref (G_OBJECT (pixbuf->pixbuf_loader));
pixbuf->pixbuf_loader = NULL;
}
break;
case GST_EVENT_NEWSEGMENT:
case GST_EVENT_FLUSH_STOP:
if (pixbuf->pixbuf_loader != NULL) {
gdk_pixbuf_loader_close (pixbuf->pixbuf_loader, NULL);
g_object_unref (G_OBJECT (pixbuf->pixbuf_loader));
pixbuf->pixbuf_loader = NULL;
}
break;
default:
break;
}
if (res == GST_FLOW_OK) {
ret = gst_pad_event_default (pad, event);
} else {
ret = FALSE;
}
gst_object_unref (pixbuf);
return ret;
}
static GstFlowReturn
gst_gdk_pixbuf_chain (GstPad * pad, GstBuffer * buf)
{
GstGdkPixbuf *filter;
GstFlowReturn ret = GST_FLOW_OK;
GError *error = NULL;
GstClockTime timestamp;
guint8 *data;
guint size;
filter = GST_GDK_PIXBUF (gst_pad_get_parent (pad));
timestamp = GST_BUFFER_TIMESTAMP (buf);
if (GST_CLOCK_TIME_IS_VALID (timestamp))
filter->last_timestamp = timestamp;
GST_LOG_OBJECT (filter, "buffer with ts: %" GST_TIME_FORMAT,
GST_TIME_ARGS (timestamp));
if (filter->pixbuf_loader == NULL)
filter->pixbuf_loader = gdk_pixbuf_loader_new ();
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
GST_LOG_OBJECT (filter, "Writing buffer size %d", size);
if (!gdk_pixbuf_loader_write (filter->pixbuf_loader, data, size, &error))
goto error;
/* packetised mode? */
if (filter->framerate_numerator != 0) {
gdk_pixbuf_loader_close (filter->pixbuf_loader, NULL);
ret = gst_gdk_pixbuf_flush (filter);
g_object_unref (filter->pixbuf_loader);
filter->pixbuf_loader = NULL;
}
gst_object_unref (filter);
return ret;
/* ERRORS */
error:
{
GST_ELEMENT_ERROR (filter, STREAM, DECODE, (NULL),
("gdk_pixbuf_loader_write error: %s", error->message));
g_error_free (error);
gst_object_unref (filter);
return GST_FLOW_ERROR;
}
}
static void
gst_gdk_pixbuf_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstGdkPixbuf *filter;
filter = GST_GDK_PIXBUF (object);
switch (prop_id) {
case ARG_SILENT:
/* filter->silent = g_value_get_boolean (value); */
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gdk_pixbuf_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstGdkPixbuf *filter;
filter = GST_GDK_PIXBUF (object);
switch (prop_id) {
case ARG_SILENT:
/* g_value_set_boolean (value, filter->silent); */
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
#define GST_GDK_PIXBUF_TYPE_FIND_SIZE 1024
#ifdef enable_typefind
static void
gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore)
{
guint8 *data;
GdkPixbufLoader *pixbuf_loader;
GdkPixbufFormat *format;
data = gst_type_find_peek (tf, 0, GST_GDK_PIXBUF_TYPE_FIND_SIZE);
if (data == NULL)
return;
GST_DEBUG ("creating new loader");
pixbuf_loader = gdk_pixbuf_loader_new ();
gdk_pixbuf_loader_write (pixbuf_loader, data, GST_GDK_PIXBUF_TYPE_FIND_SIZE,
NULL);
format = gdk_pixbuf_loader_get_format (pixbuf_loader);
if (format != NULL) {
GstCaps *caps;
gchar **p;
gchar **mlist = gdk_pixbuf_format_get_mime_types (format);
for (p = mlist; *p; ++p) {
GST_DEBUG ("suggesting mime type %s", *p);
caps = gst_caps_new_simple (*p, NULL);
gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, caps);
gst_caps_free (caps);
}
g_strfreev (mlist);
}
GST_DEBUG ("closing pixbuf loader, hope it doesn't hang ...");
/* librsvg 2.4.x has a bug where it triggers an endless loop in trying
to close a gzip that's not an svg; fixed upstream but no good way
to work around it */
gdk_pixbuf_loader_close (pixbuf_loader, NULL);
GST_DEBUG ("closed pixbuf loader");
g_object_unref (G_OBJECT (pixbuf_loader));
}
#endif
/* entry point to initialize the plug-in
* initialize the plug-in itself
* register the element factories and pad templates
* register the features
*/
static gboolean
plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (gst_gdk_pixbuf_debug, "gdkpixbuf", 0,
"gdk pixbuf loader");
if (!gst_element_register (plugin, "gdkpixbufdec", GST_RANK_MARGINAL,
GST_TYPE_GDK_PIXBUF))
return FALSE;
#ifdef enable_typefind
gst_type_find_register (plugin, "image/*", GST_RANK_MARGINAL,
gst_gdk_pixbuf_type_find, NULL, GST_CAPS_ANY, NULL);
#endif
if (!pixbufscale_init (plugin))
return FALSE;
/* plugin initialisation succeeded */
return TRUE;
}
/* this is the structure that gst-register looks for
* so keep the name plugin_desc, or you cannot get your plug-in registered */
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"gdkpixbuf",
"GDK Pixbuf decoder & scaler",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)