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
This commit is contained in:
Rafał Dzięgiel
2023-02-12 13:16:18 +01:00
parent bd8f0280e2
commit 9556ec4da2

View File

@@ -426,16 +426,12 @@ static gboolean
gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query) gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query)
{ {
GstClapperSink *self = GST_CLAPPER_SINK_CAST (bsink); GstClapperSink *self = GST_CLAPPER_SINK_CAST (bsink);
GstClapperImporter *importer = NULL;
GstCaps *caps; GstCaps *caps;
GstVideoInfo info; GstVideoInfo info;
guint size, min_buffers; guint size, min_buffers;
gboolean need_pool; 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); gst_query_parse_allocation (query, &caps, &need_pool);
if (!caps) { if (!caps) {
@@ -448,6 +444,16 @@ gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query)
return FALSE; 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 */ /* Normal size of a frame */
size = GST_VIDEO_INFO_SIZE (&info); size = GST_VIDEO_INFO_SIZE (&info);
@@ -459,10 +465,7 @@ gst_clapper_sink_propose_allocation (GstBaseSink *bsink, GstQuery *query)
GstStructure *config = NULL; GstStructure *config = NULL;
GST_DEBUG_OBJECT (self, "Need to create buffer pool"); GST_DEBUG_OBJECT (self, "Need to create buffer pool");
pool = gst_clapper_importer_create_pool (importer, &config);
GST_CLAPPER_SINK_LOCK (self);
pool = gst_clapper_importer_create_pool (self->importer, &config);
GST_CLAPPER_SINK_UNLOCK (self);
if (pool) { if (pool) {
/* If we did not get config, use default one */ /* 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)) { if (!gst_buffer_pool_set_config (pool, config)) {
gst_object_unref (pool); gst_object_unref (pool);
gst_object_unref (importer);
GST_ERROR_OBJECT (self, "Failed to set config"); GST_ERROR_OBJECT (self, "Failed to set config");
return FALSE; 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 (importer, query);
gst_clapper_importer_add_allocation_metas (self->importer, query); gst_object_unref (importer);
GST_CLAPPER_SINK_UNLOCK (self);
return TRUE; return TRUE;
} }