From: Wim Taymans Date: Thu, 19 May 2011 13:56:57 +0000 (+0200) Subject: ximagesink: implement ALLOCATION query X-Git-Tag: RELEASE-0.11.0~256 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f1980aa051909770b3335ae2ca84dfba21be128b;p=platform%2Fupstream%2Fgst-plugins-base.git ximagesink: implement ALLOCATION query --- diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c index 6311913..51205dc 100644 --- a/sys/ximage/ximagesink.c +++ b/sys/ximage/ximagesink.c @@ -107,6 +107,8 @@ #include #include +#include + /* Object header */ #include "ximagesink.h" @@ -1400,6 +1402,98 @@ gst_ximagesink_event (GstBaseSink * sink, GstEvent * event) return TRUE; } +static gboolean +gst_ximagesink_sink_query (GstPad * sinkpad, GstQuery * query) +{ + GstXImageSink *ximagesink = GST_XIMAGESINK (GST_PAD_PARENT (sinkpad)); + gboolean res = TRUE; + + switch (GST_QUERY_TYPE (query)) { + case GST_QUERY_ALLOCATION: + { + GstBufferPool *pool; + GstStructure *config; + GstCaps *caps; + guint size; + gboolean need_pool; + + gst_query_parse_allocation (query, &caps, &need_pool); + + if (caps == NULL) + goto no_caps; + + g_mutex_lock (ximagesink->flow_lock); + if ((pool = ximagesink->pool)) + gst_object_ref (pool); + g_mutex_unlock (ximagesink->flow_lock); + + if (pool != NULL) { + const GstCaps *pcaps; + + /* we had a pool, check caps */ + config = gst_buffer_pool_get_config (pool); + gst_buffer_pool_config_get (config, &pcaps, &size, NULL, NULL, NULL, + NULL, NULL); + + GST_DEBUG_OBJECT (ximagesink, + "we had a pool with caps %" GST_PTR_FORMAT, pcaps); + if (!gst_caps_is_equal (caps, pcaps)) { + /* different caps, we can't use this pool */ + GST_DEBUG_OBJECT (ximagesink, "pool has different caps"); + gst_object_unref (pool); + pool = NULL; + } + } + if (pool == NULL && need_pool) { + GstVideoFormat format; + gint width, height; + + GST_DEBUG_OBJECT (ximagesink, "create new pool"); + pool = gst_ximage_buffer_pool_new (ximagesink); + + if (!gst_video_format_parse_caps (caps, &format, &width, &height)) + goto invalid_caps; + + /* the normal size of a frame */ + size = gst_video_format_get_size (format, width, height); + + config = gst_buffer_pool_get_config (pool); + gst_buffer_pool_config_set (config, caps, size, 0, 0, 0, 0, 16); + if (!gst_buffer_pool_set_config (pool, config)) + goto config_failed; + } + gst_query_set_allocation_params (query, size, 0, 0, 0, 16, pool); + + /* we also support various metadata */ + gst_query_add_allocation_meta (query, GST_META_API_VIDEO); + + gst_object_unref (pool); + break; + } + default: + res = FALSE; + break; + } + return res; + + /* ERRORS */ +no_caps: + { + GST_DEBUG_OBJECT (sinkpad, "no caps specified"); + return FALSE; + } +invalid_caps: + { + GST_DEBUG_OBJECT (sinkpad, "invalid caps specified"); + return FALSE; + } +config_failed: + { + GST_DEBUG_OBJECT (sinkpad, "failed setting config"); + return FALSE; + } +} + /* Interfaces stuff */ static gboolean @@ -1781,6 +1875,10 @@ gst_ximagesink_finalize (GObject * object) static void gst_ximagesink_init (GstXImageSink * ximagesink) { + /* for the ALLOCATION query */ + gst_pad_set_query_function (GST_BASE_SINK (ximagesink)->sinkpad, + gst_ximagesink_sink_query); + ximagesink->display_name = NULL; ximagesink->xcontext = NULL; ximagesink->xwindow = NULL;