From c38bede8babcee65cede7c153d6d7d8c82dd52f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 1 Apr 2021 15:30:41 +0200 Subject: [PATCH] xvimagesink: Delay pool creation until it's needed. Buffer pool is created every time setcaps() is called, but it's required only when upstream doesn't use it, so it's only needed to copy frames onto XV buffers. This patch delay the creation of the buffer pool until it's frame copy is required. Part-of: --- sys/xvimage/xvimagesink.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index 352648982..9f5c2b194 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -704,7 +704,7 @@ gst_xv_image_sink_setcaps (GstBaseSink * bsink, GstCaps * caps) { GstXvImageSink *xvimagesink; GstXvContext *context; - GstBufferPool *newpool, *oldpool; + GstBufferPool *oldpool; GstVideoInfo info; guint32 im_format = 0; gint video_par_n, video_par_d; /* video's PAR */ @@ -820,12 +820,9 @@ gst_xv_image_sink_setcaps (GstBaseSink * bsink, GstCaps * caps) * doesn't cover the same area */ xvimagesink->redraw_border = TRUE; - /* create a new pool for the new configuration */ - newpool = gst_xv_image_sink_create_pool (xvimagesink, caps, info.size, 2); - - /* we don't activate the internal pool yet as it may not be needed */ + /* destroy current pool */ oldpool = xvimagesink->pool; - xvimagesink->pool = newpool; + xvimagesink->pool = NULL; g_mutex_unlock (&xvimagesink->flow_lock); /* deactivate and unref the old internal pool */ @@ -962,9 +959,17 @@ gst_xv_image_sink_show_frame (GstVideoSink * vsink, GstBuffer * buf) /* if we have one... */ GST_LOG_OBJECT (xvimagesink, "buffer %p not from our pool, copying", buf); - /* we should have a pool, configured in setcaps */ - if (xvimagesink->pool == NULL) - goto no_pool; + if (xvimagesink->pool == NULL) { + GstCaps *caps = gst_video_info_to_caps (&xvimagesink->info); + + GST_DEBUG_OBJECT (xvimagesink, "create new pool"); + xvimagesink->pool = gst_xv_image_sink_create_pool (xvimagesink, caps, + xvimagesink->info.size, 2); + if (xvimagesink->pool == NULL) + goto no_pool; + + gst_caps_unref (caps); + } if (!gst_buffer_pool_set_active (xvimagesink->pool, TRUE)) goto activate_failed;