2006-04-18 18:04:48 +00:00
|
|
|
/* GStreamer GdkPixbuf-based image decoder
|
2003-06-25 03:17:35 +00:00
|
|
|
* 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
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2003-06-25 03:17:35 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2012-08-21 23:00:46 +00:00
|
|
|
|
2003-06-25 03:17:35 +00:00
|
|
|
#include <gst/gst.h>
|
2003-12-22 01:47:09 +00:00
|
|
|
#include <gst/video/video.h>
|
ext/gdk_pixbuf/: Add gdkpixbufsink element for easy snapshotting (#525946).
Original commit message from CVS:
* ext/gdk_pixbuf/Makefile.am:
* ext/gdk_pixbuf/gstgdkpixbuf.c: (plugin_init):
* ext/gdk_pixbuf/gstgdkpixbufsink.c:
(gst_gdk_pixbuf_sink_base_init),
(gst_gdk_pixbuf_sink_class_init), (gst_gdk_pixbuf_sink_init),
(gst_gdk_pixbuf_sink_start), (gst_gdk_pixbuf_sink_stop),
(gst_gdk_pixbuf_sink_set_caps),
(gst_gdk_pixbuf_sink_pixbuf_destroy_notify),
(gst_gdk_pixbuf_sink_get_pixbuf_from_buffer),
(gst_gdk_pixbuf_sink_handle_buffer), (gst_gdk_pixbuf_sink_preroll),
(gst_gdk_pixbuf_sink_render), (gst_gdk_pixbuf_sink_set_property),
(gst_gdk_pixbuf_sink_get_property):
* ext/gdk_pixbuf/gstgdkpixbufsink.h:
Add gdkpixbufsink element for easy snapshotting (#525946).
2008-04-03 22:50:48 +00:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2003-06-25 03:17:35 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
#include "gstgdkpixbufdec.h"
|
2004-02-18 16:44:51 +00:00
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gdkpixbufdec_debug);
|
|
|
|
#define GST_CAT_DEFAULT gdkpixbufdec_debug
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
static GstStaticPadTemplate gst_gdk_pixbuf_dec_sink_template =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("image/png; "
|
2006-04-18 18:14:34 +00:00
|
|
|
/* "image/jpeg; " disabled because we can't handle MJPEG */
|
2017-06-13 16:51:32 +00:00
|
|
|
/*"image/gif; " disabled because we can't handle animated gifs */
|
2004-03-15 19:32:27 +00:00
|
|
|
"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; "
|
2004-07-12 13:49:35 +00:00
|
|
|
"image/vnd.wap.wbmp; " "image/x-bitmap; " "image/x-tga; "
|
|
|
|
"image/x-pcx; image/svg; image/svg+xml")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
static GstStaticPadTemplate gst_gdk_pixbuf_dec_src_template =
|
2006-04-12 09:42:10 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-02-29 21:24:46 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB") "; "
|
|
|
|
GST_VIDEO_CAPS_MAKE ("RGBA"))
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
|
|
|
|
2007-06-28 13:25:05 +00:00
|
|
|
static GstStateChangeReturn
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
static GstFlowReturn gst_gdk_pixbuf_dec_chain (GstPad * pad, GstObject * parent,
|
2012-02-29 21:24:46 +00:00
|
|
|
GstBuffer * buffer);
|
2012-08-21 23:00:46 +00:00
|
|
|
static gboolean gst_gdk_pixbuf_dec_sink_event (GstPad * pad, GstObject * parent,
|
2012-02-29 21:24:46 +00:00
|
|
|
GstEvent * event);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
#define gst_gdk_pixbuf_dec_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstGdkPixbufDec, gst_gdk_pixbuf_dec, GST_TYPE_ELEMENT);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
2006-04-18 18:04:48 +00:00
|
|
|
static gboolean
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_sink_setcaps (GstGdkPixbufDec * filter, GstCaps * caps)
|
2003-06-25 03:17:35 +00:00
|
|
|
{
|
2006-02-24 19:51:29 +00:00
|
|
|
const GValue *framerate;
|
|
|
|
GstStructure *s;
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
if ((framerate = gst_structure_get_value (s, "framerate")) != NULL) {
|
2012-03-05 14:29:56 +00:00
|
|
|
filter->in_fps_n = gst_value_get_fraction_numerator (framerate);
|
|
|
|
filter->in_fps_d = gst_value_get_fraction_denominator (framerate);
|
2007-06-28 13:25:05 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "got framerate of %d/%d fps => packetized mode",
|
2012-03-05 14:29:56 +00:00
|
|
|
filter->in_fps_n, filter->in_fps_d);
|
2007-06-28 13:25:05 +00:00
|
|
|
} else {
|
2012-03-05 14:29:56 +00:00
|
|
|
filter->in_fps_n = 0;
|
|
|
|
filter->in_fps_d = 1;
|
2007-06-28 13:25:05 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "no framerate, assuming single image");
|
2006-02-24 19:51:29 +00:00
|
|
|
}
|
2006-04-12 09:42:10 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
return TRUE;
|
2003-06-25 03:17:35 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstCaps *
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_get_capslist (GstCaps * filter)
|
2003-06-25 03:17:35 +00:00
|
|
|
{
|
|
|
|
GSList *slist;
|
|
|
|
GSList *slist0;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstCaps *capslist = NULL;
|
2004-07-12 13:49:35 +00:00
|
|
|
GstCaps *return_caps = NULL;
|
2010-05-06 12:39:31 +00:00
|
|
|
GstCaps *tmpl_caps;
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
capslist = gst_caps_new_empty ();
|
2004-03-14 22:34:33 +00:00
|
|
|
slist0 = gdk_pixbuf_get_formats ();
|
2003-12-22 01:47:09 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (slist = slist0; slist; slist = g_slist_next (slist)) {
|
2006-04-12 09:42:10 +00:00
|
|
|
GdkPixbufFormat *pixbuf_format;
|
|
|
|
char **mimetypes;
|
|
|
|
char **mimetype;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
pixbuf_format = slist->data;
|
2004-03-14 22:34:33 +00:00
|
|
|
mimetypes = gdk_pixbuf_format_get_mime_types (pixbuf_format);
|
2006-04-12 09:42:10 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (mimetype = mimetypes; *mimetype; mimetype++) {
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_caps_append_structure (capslist, gst_structure_new_empty (*mimetype));
|
2003-12-22 01:47:09 +00:00
|
|
|
}
|
2006-04-12 09:42:10 +00:00
|
|
|
g_strfreev (mimetypes);
|
2003-06-25 03:17:35 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
g_slist_free (slist0);
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
tmpl_caps =
|
|
|
|
gst_static_caps_get (&gst_gdk_pixbuf_dec_sink_template.static_caps);
|
2010-05-06 12:39:31 +00:00
|
|
|
return_caps = gst_caps_intersect (capslist, tmpl_caps);
|
2004-07-12 13:49:35 +00:00
|
|
|
|
2010-05-06 12:39:31 +00:00
|
|
|
gst_caps_unref (tmpl_caps);
|
2006-02-24 19:51:29 +00:00
|
|
|
gst_caps_unref (capslist);
|
2012-02-29 21:24:46 +00:00
|
|
|
|
|
|
|
if (filter && return_caps) {
|
|
|
|
GstCaps *temp;
|
|
|
|
|
|
|
|
temp = gst_caps_intersect (return_caps, filter);
|
|
|
|
gst_caps_unref (return_caps);
|
|
|
|
return_caps = temp;
|
|
|
|
}
|
|
|
|
|
2004-07-12 13:49:35 +00:00
|
|
|
return return_caps;
|
2003-06-25 03:17:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
static gboolean
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_sink_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query)
|
2003-06-25 03:17:35 +00:00
|
|
|
{
|
2012-02-29 21:24:46 +00:00
|
|
|
gboolean res;
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
2003-11-01 16:18:43 +00:00
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_query_parse_caps (query, &filter);
|
2012-08-21 23:00:46 +00:00
|
|
|
caps = gst_gdk_pixbuf_dec_get_capslist (filter);
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_query_default (pad, parent, query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
2003-11-01 16:18:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
|
2003-06-25 03:17:35 +00:00
|
|
|
/* initialize the plugin's class */
|
|
|
|
static void
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_class_init (GstGdkPixbufDecClass * klass)
|
2003-06-25 03:17:35 +00:00
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2007-06-28 13:25:05 +00:00
|
|
|
gstelement_class->change_state =
|
2012-08-21 23:00:46 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_dec_change_state);
|
2012-02-29 21:24:46 +00:00
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_gdk_pixbuf_dec_src_template);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_gdk_pixbuf_dec_sink_template);
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2012-02-29 21:24:46 +00:00
|
|
|
"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>");
|
2012-08-21 23:00:46 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gdkpixbufdec_debug, "gdkpixbuf", 0,
|
|
|
|
"GdkPixbuf image decoder");
|
2003-06-25 03:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_init (GstGdkPixbufDec * filter)
|
2003-06-25 03:17:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->sinkpad =
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_pad_new_from_static_template (&gst_gdk_pixbuf_dec_sink_template,
|
|
|
|
"sink");
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_pad_set_query_function (filter->sinkpad,
|
2012-08-21 23:00:46 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_dec_sink_query));
|
2006-04-18 18:04:48 +00:00
|
|
|
gst_pad_set_chain_function (filter->sinkpad,
|
2012-08-21 23:00:46 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_dec_chain));
|
2006-04-18 18:04:48 +00:00
|
|
|
gst_pad_set_event_function (filter->sinkpad,
|
2012-08-21 23:00:46 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_dec_sink_event));
|
2003-06-25 03:17:35 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
2006-03-15 16:17:12 +00:00
|
|
|
filter->srcpad =
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_pad_new_from_static_template (&gst_gdk_pixbuf_dec_src_template,
|
|
|
|
"src");
|
2006-02-24 19:51:29 +00:00
|
|
|
gst_pad_use_fixed_caps (filter->srcpad);
|
2003-06-25 03:17:35 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
filter->last_timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
filter->pixbuf_loader = NULL;
|
2014-09-16 11:16:07 +00:00
|
|
|
filter->packetized = FALSE;
|
2003-06-25 03:17:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
static gboolean
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_setup_pool (GstGdkPixbufDec * filter, GstVideoInfo * info)
|
2012-02-29 21:24:46 +00:00
|
|
|
{
|
|
|
|
GstCaps *target;
|
|
|
|
GstQuery *query;
|
2012-03-15 19:37:56 +00:00
|
|
|
GstBufferPool *pool;
|
|
|
|
GstStructure *config;
|
|
|
|
guint size, min, max;
|
2012-02-29 21:24:46 +00:00
|
|
|
|
|
|
|
target = gst_pad_get_current_caps (filter->srcpad);
|
2016-02-23 16:27:47 +00:00
|
|
|
if (!target)
|
|
|
|
return FALSE;
|
2012-02-29 21:24:46 +00:00
|
|
|
|
|
|
|
/* try to get a bufferpool now */
|
|
|
|
/* find a pool for the negotiated caps now */
|
|
|
|
query = gst_query_new_allocation (target, TRUE);
|
|
|
|
|
2012-03-15 19:37:56 +00:00
|
|
|
if (!gst_pad_peer_query (filter->srcpad, query)) {
|
|
|
|
/* not a problem, we use the query defaults */
|
|
|
|
GST_DEBUG_OBJECT (filter, "ALLOCATION query failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0) {
|
2012-02-29 21:24:46 +00:00
|
|
|
/* we got configuration from our peer, parse them */
|
2012-03-15 19:37:56 +00:00
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
2012-02-29 21:24:46 +00:00
|
|
|
} else {
|
2012-03-15 19:37:56 +00:00
|
|
|
pool = NULL;
|
2012-02-29 21:24:46 +00:00
|
|
|
size = info->size;
|
|
|
|
min = max = 0;
|
|
|
|
}
|
|
|
|
|
2014-09-03 06:16:13 +00:00
|
|
|
gst_query_unref (query);
|
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
if (pool == NULL) {
|
|
|
|
/* we did not get a pool, make one ourselves then */
|
|
|
|
pool = gst_buffer_pool_new ();
|
|
|
|
}
|
|
|
|
|
2012-03-15 19:37:56 +00:00
|
|
|
/* and configure */
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2012-03-15 21:11:17 +00:00
|
|
|
gst_buffer_pool_config_set_params (config, target, size, min, max);
|
2012-03-15 19:37:56 +00:00
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
|
|
|
|
if (filter->pool) {
|
|
|
|
gst_buffer_pool_set_active (filter->pool, FALSE);
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_object_unref (filter->pool);
|
2012-03-15 19:37:56 +00:00
|
|
|
}
|
2012-02-29 21:24:46 +00:00
|
|
|
filter->pool = pool;
|
|
|
|
|
|
|
|
/* and activate */
|
|
|
|
gst_buffer_pool_set_active (filter->pool, TRUE);
|
|
|
|
|
|
|
|
gst_caps_unref (target);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static GstFlowReturn
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_flush (GstGdkPixbufDec * filter)
|
2003-06-25 03:17:35 +00:00
|
|
|
{
|
2006-02-24 19:51:29 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
int y;
|
|
|
|
guint8 *out_pix;
|
|
|
|
guint8 *in_pix;
|
2012-03-05 14:29:56 +00:00
|
|
|
int in_rowstride, out_rowstride;
|
2006-02-24 19:51:29 +00:00
|
|
|
GstFlowReturn ret;
|
|
|
|
GstCaps *caps = NULL;
|
2012-03-05 14:29:56 +00:00
|
|
|
gint width, height;
|
2006-04-12 09:42:10 +00:00
|
|
|
gint n_channels;
|
2012-02-29 21:24:46 +00:00
|
|
|
GstVideoFrame frame;
|
2006-02-24 19:51:29 +00:00
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_loader_get_pixbuf (filter->pixbuf_loader);
|
2006-04-12 09:42:10 +00:00
|
|
|
if (pixbuf == NULL)
|
|
|
|
goto no_pixbuf;
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-03-05 14:29:56 +00:00
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_FORMAT (&filter->info) == GST_VIDEO_FORMAT_UNKNOWN) {
|
2012-02-29 21:24:46 +00:00
|
|
|
GstVideoInfo info;
|
|
|
|
GstVideoFormat fmt;
|
2013-05-28 13:46:43 +00:00
|
|
|
GList *l;
|
2012-02-29 21:24:46 +00:00
|
|
|
|
2012-03-05 14:29:56 +00:00
|
|
|
GST_DEBUG ("Set size to %dx%d", width, height);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
2006-04-12 09:42:10 +00:00
|
|
|
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
|
|
|
|
switch (n_channels) {
|
|
|
|
case 3:
|
2012-02-29 21:24:46 +00:00
|
|
|
fmt = GST_VIDEO_FORMAT_RGB;
|
2006-04-12 09:42:10 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2012-02-29 21:24:46 +00:00
|
|
|
fmt = GST_VIDEO_FORMAT_RGBA;
|
2006-04-12 09:42:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto channels_not_supported;
|
2004-01-12 03:21:40 +00:00
|
|
|
}
|
2006-04-12 09:42:10 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_video_info_init (&info);
|
2012-03-05 14:29:56 +00:00
|
|
|
gst_video_info_set_format (&info, fmt, width, height);
|
|
|
|
info.fps_n = filter->in_fps_n;
|
|
|
|
info.fps_d = filter->in_fps_d;
|
2012-02-29 21:24:46 +00:00
|
|
|
caps = gst_video_info_to_caps (&info);
|
|
|
|
|
|
|
|
filter->info = info;
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
gst_pad_set_caps (filter->srcpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_setup_pool (filter, &info);
|
2013-05-28 13:46:43 +00:00
|
|
|
|
|
|
|
for (l = filter->pending_events; l; l = l->next)
|
|
|
|
gst_pad_push_event (filter->srcpad, l->data);
|
|
|
|
g_list_free (filter->pending_events);
|
|
|
|
filter->pending_events = NULL;
|
2012-02-29 21:24:46 +00:00
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
ret = gst_buffer_pool_acquire_buffer (filter->pool, &outbuf, NULL);
|
2006-04-12 09:42:10 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto no_buffer;
|
2004-01-12 03:21:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = filter->last_timestamp;
|
|
|
|
GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
in_pix = gdk_pixbuf_get_pixels (pixbuf);
|
|
|
|
in_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_video_frame_map (&frame, &filter->info, outbuf, GST_MAP_WRITE);
|
2012-03-05 14:29:56 +00:00
|
|
|
out_pix = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
|
|
|
|
out_rowstride = GST_VIDEO_FRAME_PLANE_STRIDE (&frame, 0);
|
2012-02-29 21:24:46 +00:00
|
|
|
|
2012-03-05 14:29:56 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
memcpy (out_pix, in_pix, width * GST_VIDEO_FRAME_COMP_PSTRIDE (&frame, 0));
|
2006-02-24 19:51:29 +00:00
|
|
|
in_pix += in_rowstride;
|
2012-03-05 14:29:56 +00:00
|
|
|
out_pix += out_rowstride;
|
2006-02-24 19:51:29 +00:00
|
|
|
}
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_video_frame_unmap (&frame);
|
|
|
|
|
2012-12-18 14:54:08 +00:00
|
|
|
GST_DEBUG ("pushing... %" G_GSIZE_FORMAT " bytes",
|
|
|
|
gst_buffer_get_size (outbuf));
|
2007-06-28 13:25:05 +00:00
|
|
|
ret = gst_pad_push (filter->srcpad, outbuf);
|
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
GST_DEBUG_OBJECT (filter, "flow: %s", gst_flow_get_name (ret));
|
|
|
|
|
|
|
|
return ret;
|
2006-04-12 09:42:10 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_pixbuf:
|
|
|
|
{
|
2006-04-18 18:04:48 +00:00
|
|
|
GST_ELEMENT_ERROR (filter, STREAM, DECODE, (NULL), ("error geting pixbuf"));
|
2006-04-12 09:42:10 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
channels_not_supported:
|
|
|
|
{
|
2006-04-18 18:04:48 +00:00
|
|
|
GST_ELEMENT_ERROR (filter, STREAM, DECODE, (NULL),
|
2006-04-12 09:42:10 +00:00
|
|
|
("%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;
|
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
}
|
2004-01-12 03:21:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static gboolean
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2006-02-24 19:51:29 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
2012-03-05 12:31:44 +00:00
|
|
|
gboolean ret = TRUE, forward = TRUE;
|
2012-08-21 23:00:46 +00:00
|
|
|
GstGdkPixbufDec *pixbuf;
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
pixbuf = GST_GDK_PIXBUF_DEC (parent);
|
2003-06-25 03:17:35 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2012-02-29 21:24:46 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
2012-08-21 23:00:46 +00:00
|
|
|
ret = gst_gdk_pixbuf_dec_sink_setcaps (pixbuf, caps);
|
2012-03-05 12:31:44 +00:00
|
|
|
forward = FALSE;
|
2012-02-29 21:24:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
case GST_EVENT_EOS:
|
2006-04-12 09:42:10 +00:00
|
|
|
if (pixbuf->pixbuf_loader != NULL) {
|
|
|
|
gdk_pixbuf_loader_close (pixbuf->pixbuf_loader, NULL);
|
2012-08-21 23:00:46 +00:00
|
|
|
res = gst_gdk_pixbuf_dec_flush (pixbuf);
|
2006-04-12 09:42:10 +00:00
|
|
|
g_object_unref (G_OBJECT (pixbuf->pixbuf_loader));
|
|
|
|
pixbuf->pixbuf_loader = NULL;
|
2007-06-28 13:25:05 +00:00
|
|
|
/* as long as we don't have flow returns for event functions we need
|
|
|
|
* to post an error here, or the application might never know that
|
|
|
|
* things failed */
|
2014-08-28 08:23:23 +00:00
|
|
|
if (res != GST_FLOW_OK && res != GST_FLOW_FLUSHING
|
|
|
|
&& res != GST_FLOW_EOS && res != GST_FLOW_NOT_LINKED) {
|
2016-08-19 18:11:03 +00:00
|
|
|
GST_ELEMENT_FLOW_ERROR (pixbuf, res);
|
2012-03-05 12:31:44 +00:00
|
|
|
forward = FALSE;
|
|
|
|
ret = FALSE;
|
2007-06-28 13:25:05 +00:00
|
|
|
}
|
2006-04-12 09:42:10 +00:00
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2013-05-28 13:46:43 +00:00
|
|
|
g_list_free_full (pixbuf->pending_events,
|
|
|
|
(GDestroyNotify) gst_event_unref);
|
|
|
|
pixbuf->pending_events = NULL;
|
|
|
|
/* Fall through */
|
|
|
|
case GST_EVENT_SEGMENT:
|
2014-09-16 11:16:07 +00:00
|
|
|
{
|
|
|
|
const GstSegment *segment;
|
|
|
|
gst_event_parse_segment (event, &segment);
|
|
|
|
if (segment->format == GST_FORMAT_BYTES)
|
|
|
|
pixbuf->packetized = FALSE;
|
|
|
|
else
|
|
|
|
pixbuf->packetized = TRUE;
|
2006-02-24 19:51:29 +00:00
|
|
|
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;
|
2004-07-12 13:49:35 +00:00
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
break;
|
2014-09-16 11:16:07 +00:00
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
2004-01-12 03:21:40 +00:00
|
|
|
}
|
2012-03-05 12:31:44 +00:00
|
|
|
if (forward) {
|
2013-05-28 13:46:43 +00:00
|
|
|
if (!gst_pad_has_current_caps (pixbuf->srcpad) &&
|
|
|
|
GST_EVENT_IS_SERIALIZED (event)
|
|
|
|
&& GST_EVENT_TYPE (event) > GST_EVENT_CAPS
|
|
|
|
&& GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_STOP
|
|
|
|
&& GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
|
|
|
|
ret = TRUE;
|
|
|
|
pixbuf->pending_events = g_list_prepend (pixbuf->pending_events, event);
|
|
|
|
} else {
|
|
|
|
ret = gst_pad_event_default (pad, parent, event);
|
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
} else {
|
2012-03-05 12:31:44 +00:00
|
|
|
gst_event_unref (event);
|
2004-01-12 03:21:40 +00:00
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
2006-02-24 19:51:29 +00:00
|
|
|
{
|
2012-08-21 23:00:46 +00:00
|
|
|
GstGdkPixbufDec *filter;
|
2006-02-24 19:51:29 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
GError *error = NULL;
|
|
|
|
GstClockTime timestamp;
|
2012-02-29 21:24:46 +00:00
|
|
|
GstMapInfo map;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2012-08-21 23:00:46 +00:00
|
|
|
filter = GST_GDK_PIXBUF_DEC (parent);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
|
2006-04-12 09:42:10 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp))
|
2006-02-24 19:51:29 +00:00
|
|
|
filter->last_timestamp = timestamp;
|
2004-01-12 03:21:40 +00:00
|
|
|
|
2006-04-18 18:04:48 +00:00
|
|
|
GST_LOG_OBJECT (filter, "buffer with ts: %" GST_TIME_FORMAT,
|
2006-04-12 09:42:10 +00:00
|
|
|
GST_TIME_ARGS (timestamp));
|
|
|
|
|
|
|
|
if (filter->pixbuf_loader == NULL)
|
2006-02-24 19:51:29 +00:00
|
|
|
filter->pixbuf_loader = gdk_pixbuf_loader_new ();
|
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
GST_LOG_OBJECT (filter, "Writing buffer size %d", (gint) map.size);
|
|
|
|
if (!gdk_pixbuf_loader_write (filter->pixbuf_loader, map.data, map.size,
|
|
|
|
&error))
|
2006-04-12 09:42:10 +00:00
|
|
|
goto error;
|
|
|
|
|
2014-09-16 11:16:07 +00:00
|
|
|
if (filter->packetized == TRUE) {
|
2006-04-18 18:04:48 +00:00
|
|
|
gdk_pixbuf_loader_close (filter->pixbuf_loader, NULL);
|
2012-08-21 23:00:46 +00:00
|
|
|
ret = gst_gdk_pixbuf_dec_flush (filter);
|
2006-04-18 18:04:48 +00:00
|
|
|
g_object_unref (filter->pixbuf_loader);
|
|
|
|
filter->pixbuf_loader = NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2008-07-04 20:43:07 +00:00
|
|
|
gst_buffer_unref (buf);
|
2006-04-12 09:42:10 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
return ret;
|
2006-04-12 09:42:10 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error:
|
|
|
|
{
|
2006-04-18 18:04:48 +00:00
|
|
|
GST_ELEMENT_ERROR (filter, STREAM, DECODE, (NULL),
|
|
|
|
("gdk_pixbuf_loader_write error: %s", error->message));
|
2006-04-12 09:42:10 +00:00
|
|
|
g_error_free (error);
|
2012-02-29 21:24:46 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2008-07-04 20:43:07 +00:00
|
|
|
gst_buffer_unref (buf);
|
2006-04-18 18:04:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2006-04-12 09:42:10 +00:00
|
|
|
}
|
2003-06-25 03:17:35 +00:00
|
|
|
}
|
|
|
|
|
2007-06-28 13:25:05 +00:00
|
|
|
static GstStateChangeReturn
|
2012-08-21 23:00:46 +00:00
|
|
|
gst_gdk_pixbuf_dec_change_state (GstElement * element,
|
|
|
|
GstStateChange transition)
|
2007-06-28 13:25:05 +00:00
|
|
|
{
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2012-08-21 23:00:46 +00:00
|
|
|
GstGdkPixbufDec *dec = GST_GDK_PIXBUF_DEC (element);
|
2007-06-28 13:25:05 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
/* default to single image mode, setcaps function might not be called */
|
2012-03-05 14:29:56 +00:00
|
|
|
dec->in_fps_n = 0;
|
|
|
|
dec->in_fps_d = 1;
|
|
|
|
gst_video_info_init (&dec->info);
|
2007-06-28 13:25:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2012-03-05 14:29:56 +00:00
|
|
|
dec->in_fps_n = 0;
|
|
|
|
dec->in_fps_d = 0;
|
2012-02-29 21:24:46 +00:00
|
|
|
if (dec->pool) {
|
|
|
|
gst_buffer_pool_set_active (dec->pool, FALSE);
|
|
|
|
gst_object_replace ((GstObject **) & dec->pool, NULL);
|
|
|
|
}
|
2013-05-28 13:46:43 +00:00
|
|
|
g_list_free_full (dec->pending_events, (GDestroyNotify) gst_event_unref);
|
|
|
|
dec->pending_events = NULL;
|
2015-10-08 02:44:04 +00:00
|
|
|
if (dec->pixbuf_loader != NULL) {
|
|
|
|
gdk_pixbuf_loader_close (dec->pixbuf_loader, NULL);
|
|
|
|
g_object_unref (G_OBJECT (dec->pixbuf_loader));
|
|
|
|
dec->pixbuf_loader = NULL;
|
|
|
|
}
|
2007-06-28 13:25:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|