From 7f33db41594e740237030df05ab3d83f9531271f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Wed, 11 May 2022 16:39:59 +0200 Subject: [PATCH] plugin: Fix possible buffer and v_info mismatch --- lib/gst/plugin/gstclapperimporter.c | 20 ++++++++++++-------- lib/gst/plugin/gstclapperimporter.h | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/gst/plugin/gstclapperimporter.c b/lib/gst/plugin/gstclapperimporter.c index 9ee4fa5f..035b0e44 100644 --- a/lib/gst/plugin/gstclapperimporter.c +++ b/lib/gst/plugin/gstclapperimporter.c @@ -119,6 +119,8 @@ gst_clapper_importer_finalize (GObject *object) GST_TRACE ("Finalize"); + gst_clear_caps (&self->pending_caps); + gst_clear_buffer (&self->pending_buffer); gst_clear_buffer (&self->buffer); @@ -320,7 +322,7 @@ gst_clapper_importer_set_caps (GstClapperImporter *self, GstCaps *caps) GstClapperImporterClass *importer_class = GST_CLAPPER_IMPORTER_GET_CLASS (self); GST_OBJECT_LOCK (self); - self->has_pending_v_info = gst_video_info_from_caps (&self->pending_v_info, caps); + gst_caps_replace (&self->pending_caps, caps); GST_OBJECT_UNLOCK (self); if (importer_class->set_caps) @@ -330,10 +332,14 @@ gst_clapper_importer_set_caps (GstClapperImporter *self, GstCaps *caps) void gst_clapper_importer_set_buffer (GstClapperImporter *self, GstBuffer *buffer) { - /* Both overlays and pending buffer must be - * set within a single importer locking */ GST_OBJECT_LOCK (self); + /* Pending v_info, buffer and overlays must be + * set within a single importer locking */ + if (self->pending_caps) { + self->has_pending_v_info = gst_video_info_from_caps (&self->pending_v_info, self->pending_caps); + gst_clear_caps (&self->pending_caps); + } gst_buffer_replace (&self->pending_buffer, buffer); gst_clapper_importer_prepare_overlays_locked (self); @@ -380,15 +386,13 @@ gst_clapper_importer_snapshot (GstClapperImporter *self, GdkSnapshot *snapshot, * lock ourselves to make sure everything matches */ GST_OBJECT_LOCK (self); - buffer_changed = gst_buffer_replace (&self->buffer, self->pending_buffer); - - /* Only replace v_info when buffer changed, this way - * we still use old (correct) v_info when resizing */ - if (buffer_changed && self->has_pending_v_info) { + if (self->has_pending_v_info) { self->v_info = self->pending_v_info; self->has_pending_v_info = FALSE; } + buffer_changed = gst_buffer_replace (&self->buffer, self->pending_buffer); + /* Ref overlays associated with current buffer */ for (i = 0; i < self->pending_overlays->len; i++) { GstClapperGdkOverlay *overlay = g_ptr_array_index (self->pending_overlays, i); diff --git a/lib/gst/plugin/gstclapperimporter.h b/lib/gst/plugin/gstclapperimporter.h index 6477f441..1f797de7 100644 --- a/lib/gst/plugin/gstclapperimporter.h +++ b/lib/gst/plugin/gstclapperimporter.h @@ -49,6 +49,7 @@ struct _GstClapperImporter { GstObject parent; + GstCaps *pending_caps; GstBuffer *pending_buffer, *buffer; GPtrArray *pending_overlays, *overlays; GstVideoInfo pending_v_info, v_info;