plugin: Use different lock for importer within paintable

This way we can avoid an additional importer ref + unref for every frame draw
This commit is contained in:
Rafał Dzięgiel
2022-05-18 19:25:00 +02:00
parent 2b85afc03e
commit 34386bc96c
2 changed files with 16 additions and 10 deletions

View File

@@ -62,6 +62,8 @@ gst_clapper_paintable_init (GstClapperPaintable *self)
self->pixel_aspect = ((gdouble) self->par_d / self->par_n); self->pixel_aspect = ((gdouble) self->par_d / self->par_n);
g_mutex_init (&self->lock); g_mutex_init (&self->lock);
g_mutex_init (&self->importer_lock);
gst_video_info_init (&self->v_info); gst_video_info_init (&self->v_info);
g_weak_ref_init (&self->widget, NULL); g_weak_ref_init (&self->widget, NULL);
@@ -94,7 +96,9 @@ gst_clapper_paintable_finalize (GObject *object)
g_weak_ref_clear (&self->widget); g_weak_ref_clear (&self->widget);
gst_clear_object (&self->importer); gst_clear_object (&self->importer);
g_mutex_clear (&self->lock); g_mutex_clear (&self->lock);
g_mutex_clear (&self->importer_lock);
GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
} }
@@ -235,9 +239,9 @@ gst_clapper_paintable_set_widget (GstClapperPaintable *self, GtkWidget *widget)
void void
gst_clapper_paintable_set_importer (GstClapperPaintable *self, GstClapperImporter *importer) gst_clapper_paintable_set_importer (GstClapperPaintable *self, GstClapperImporter *importer)
{ {
GST_CLAPPER_PAINTABLE_LOCK (self); GST_CLAPPER_PAINTABLE_IMPORTER_LOCK (self);
gst_object_replace ((GstObject **) &self->importer, GST_OBJECT_CAST (importer)); gst_object_replace ((GstObject **) &self->importer, GST_OBJECT_CAST (importer));
GST_CLAPPER_PAINTABLE_UNLOCK (self); GST_CLAPPER_PAINTABLE_IMPORTER_UNLOCK (self);
} }
void void
@@ -326,7 +330,6 @@ gst_clapper_paintable_snapshot_internal (GstClapperPaintable *self,
GdkSnapshot *snapshot, gdouble width, gdouble height, GdkSnapshot *snapshot, gdouble width, gdouble height,
gint widget_width, gint widget_height) gint widget_width, gint widget_height)
{ {
GstClapperImporter *importer = NULL;
gfloat scale_x, scale_y; gfloat scale_x, scale_y;
GST_LOG_OBJECT (self, "Snapshot"); GST_LOG_OBJECT (self, "Snapshot");
@@ -352,19 +355,17 @@ gst_clapper_paintable_snapshot_internal (GstClapperPaintable *self,
} }
} }
GST_CLAPPER_PAINTABLE_LOCK (self); GST_CLAPPER_PAINTABLE_IMPORTER_LOCK (self);
if (self->importer)
importer = gst_object_ref (self->importer);
GST_CLAPPER_PAINTABLE_UNLOCK (self);
if (importer) { if (self->importer) {
gst_clapper_importer_snapshot (importer, snapshot, width, height, gst_clapper_importer_snapshot (self->importer, snapshot, width, height,
scale_x * self->pixel_aspect, scale_y); scale_x * self->pixel_aspect, scale_y);
gst_object_unref (importer);
} else { } else {
GST_LOG_OBJECT (self, "No texture importer, drawing black"); GST_LOG_OBJECT (self, "No texture importer, drawing black");
gtk_snapshot_append_color (snapshot, &self->bg, &GRAPHENE_RECT_INIT (0, 0, width, height)); gtk_snapshot_append_color (snapshot, &self->bg, &GRAPHENE_RECT_INIT (0, 0, width, height));
} }
GST_CLAPPER_PAINTABLE_IMPORTER_UNLOCK (self);
} }
static void static void

View File

@@ -36,11 +36,16 @@ G_DECLARE_FINAL_TYPE (GstClapperPaintable, gst_clapper_paintable, GST, CLAPPER_P
#define GST_CLAPPER_PAINTABLE_LOCK(obj) g_mutex_lock (GST_CLAPPER_PAINTABLE_GET_LOCK(obj)) #define GST_CLAPPER_PAINTABLE_LOCK(obj) g_mutex_lock (GST_CLAPPER_PAINTABLE_GET_LOCK(obj))
#define GST_CLAPPER_PAINTABLE_UNLOCK(obj) g_mutex_unlock (GST_CLAPPER_PAINTABLE_GET_LOCK(obj)) #define GST_CLAPPER_PAINTABLE_UNLOCK(obj) g_mutex_unlock (GST_CLAPPER_PAINTABLE_GET_LOCK(obj))
#define GST_CLAPPER_PAINTABLE_IMPORTER_GET_LOCK(obj) (&GST_CLAPPER_PAINTABLE_CAST(obj)->importer_lock)
#define GST_CLAPPER_PAINTABLE_IMPORTER_LOCK(obj) g_mutex_lock (GST_CLAPPER_PAINTABLE_IMPORTER_GET_LOCK(obj))
#define GST_CLAPPER_PAINTABLE_IMPORTER_UNLOCK(obj) g_mutex_unlock (GST_CLAPPER_PAINTABLE_IMPORTER_GET_LOCK(obj))
struct _GstClapperPaintable struct _GstClapperPaintable
{ {
GObject parent; GObject parent;
GMutex lock; GMutex lock;
GMutex importer_lock;
GstVideoInfo v_info; GstVideoInfo v_info;