From 9556ec4da23930a6b13f31b0ead6be66a522641d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Sun, 12 Feb 2023 13:16:18 +0100 Subject: [PATCH] plugin: Ensure allocation using the same importer Instead of locking mutex twice and praying that importer will not change in between, just ref it to ensure that --- lib/gst/plugin/gstclappersink.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/gst/plugin/gstclappersink.c b/lib/gst/plugin/gstclappersink.c index 2aa3f370..e6356162 100644 --- a/lib/gst/plugin/gstclappersink.c +++ b/lib/gst/plugin/gstclappersink.c @@ -426,16 +426,12 @@ static gboolean gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query) { GstClapperSink *self = GST_CLAPPER_SINK_CAST (bsink); + GstClapperImporter *importer = NULL; GstCaps *caps; GstVideoInfo info; guint size, min_buffers; gboolean need_pool; - if (!self->importer) { - GST_DEBUG_OBJECT (self, "No importer to propose allocation"); - return FALSE; - } - gst_query_parse_allocation (query, &caps, &need_pool); if (!caps) { @@ -448,6 +444,16 @@ gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query) return FALSE; } + GST_CLAPPER_SINK_LOCK (self); + if (self->importer) + importer = gst_object_ref (self->importer); + GST_CLAPPER_SINK_UNLOCK (self); + + if (!importer) { + GST_DEBUG_OBJECT (self, "No importer to propose allocation"); + return FALSE; + } + /* Normal size of a frame */ size = GST_VIDEO_INFO_SIZE (&info); @@ -459,10 +465,7 @@ gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query) GstStructure *config = NULL; GST_DEBUG_OBJECT (self, "Need to create buffer pool"); - - GST_CLAPPER_SINK_LOCK (self); - pool = gst_clapper_importer_create_pool (self->importer, &config); - GST_CLAPPER_SINK_UNLOCK (self); + pool = gst_clapper_importer_create_pool (importer, &config); if (pool) { /* If we did not get config, use default one */ @@ -473,6 +476,7 @@ gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query) if (!gst_buffer_pool_set_config (pool, config)) { gst_object_unref (pool); + gst_object_unref (importer); GST_ERROR_OBJECT (self, "Failed to set config"); return FALSE; @@ -486,9 +490,8 @@ gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query) } } - GST_CLAPPER_SINK_LOCK (self); - gst_clapper_importer_add_allocation_metas (self->importer, query); - GST_CLAPPER_SINK_UNLOCK (self); + gst_clapper_importer_add_allocation_metas (importer, query); + gst_object_unref (importer); return TRUE; }