From 14e7e991d32c76ba1d32acc8bf29de8dc5a6ed28 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Mon, 8 May 2023 13:46:34 +1000 Subject: [PATCH] gl/mixer: make fbo instance field private and provide accessor function Part-of: --- .../gst-plugins-base/ext/gl/gstglmosaic.c | 5 +- .../gst-plugins-base/ext/gl/gstglstereomix.c | 1 + .../gst-plugins-base/ext/gl/gstglstereomix.h | 2 +- .../gst-plugins-base/ext/gl/gstglvideomixer.c | 5 +- .../gst-plugins-base/gst-libs/gst/gl/gl.h | 2 + .../gst-libs/gst/gl/gstglbasemixer.c | 19 +++++- .../gst-libs/gst/gl/gstglbasemixer.h | 6 +- .../gst-libs/gst/gl/gstglmixer.c | 61 ++++++++++++++++--- .../gst-libs/gst/gl/gstglmixer.h | 12 ++-- 9 files changed, 92 insertions(+), 21 deletions(-) diff --git a/subprojects/gst-plugins-base/ext/gl/gstglmosaic.c b/subprojects/gst-plugins-base/ext/gl/gstglmosaic.c index 6b0ef638ec..53b2477866 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstglmosaic.c +++ b/subprojects/gst-plugins-base/ext/gl/gstglmosaic.c @@ -217,6 +217,7 @@ static void _mosaic_render (GstGLContext * context, GstGLMosaic * mosaic) { GstGLMixer *mixer = GST_GL_MIXER (mosaic); + GstGLFramebuffer *fbo = gst_gl_mixer_get_framebuffer (mixer); if (!mosaic->shader) { gchar *frag_str = g_strdup_printf ("%s%s", @@ -230,8 +231,10 @@ _mosaic_render (GstGLContext * context, GstGLMosaic * mosaic) g_free (frag_str); } - gst_gl_framebuffer_draw_to_texture (mixer->fbo, mosaic->out_tex, + gst_gl_framebuffer_draw_to_texture (fbo, mosaic->out_tex, gst_gl_mosaic_callback, mosaic); + + gst_clear_object (&fbo); } static gboolean diff --git a/subprojects/gst-plugins-base/ext/gl/gstglstereomix.c b/subprojects/gst-plugins-base/ext/gl/gstglstereomix.c index 061e209e17..1fe7f7952e 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstglstereomix.c +++ b/subprojects/gst-plugins-base/ext/gl/gstglstereomix.c @@ -63,6 +63,7 @@ #include "gstglelements.h" #include "gstglstereomix.h" +#include #define GST_CAT_DEFAULT gst_gl_stereo_mix_debug GST_DEBUG_CATEGORY (gst_gl_stereo_mix_debug); diff --git a/subprojects/gst-plugins-base/ext/gl/gstglstereomix.h b/subprojects/gst-plugins-base/ext/gl/gstglstereomix.h index 530c355649..3fa35710c8 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstglstereomix.h +++ b/subprojects/gst-plugins-base/ext/gl/gstglstereomix.h @@ -22,7 +22,7 @@ #ifndef __GST_GL_STEREO_MIX_H__ #define __GST_GL_STEREO_MIX_H__ -#include +#include G_BEGIN_DECLS diff --git a/subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c b/subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c index 2471e9f6a4..e640609d0c 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c +++ b/subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c @@ -1845,9 +1845,12 @@ static void _video_mixer_process_gl (GstGLContext * context, GstGLVideoMixer * video_mixer) { GstGLMixer *mixer = GST_GL_MIXER (video_mixer); + GstGLFramebuffer *fbo = gst_gl_mixer_get_framebuffer (mixer); - gst_gl_framebuffer_draw_to_texture (mixer->fbo, video_mixer->out_tex, + gst_gl_framebuffer_draw_to_texture (fbo, video_mixer->out_tex, gst_gl_video_mixer_callback, video_mixer); + + gst_clear_object (&fbo); } static gboolean diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gl.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/gl.h index 6c7a37ff64..d35288b6c2 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gl.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gl.h @@ -52,5 +52,7 @@ #include #include #include +#include +#include #endif /* __GST_GL_H__ */ diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglbasemixer.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglbasemixer.c index 016563725e..443d634902 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglbasemixer.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglbasemixer.c @@ -1,5 +1,4 @@ -/* Generic video mixer plugin - * +/* * GStreamer * Copyright (C) 2015 Matthew Waters * @@ -27,6 +26,20 @@ #include #include "gstglbasemixer.h" +#include + +/** + * SECTION:gstglbasemixer + * @short_description: #GstVideoAggregator subclass for transforming OpenGL resources + * @title: GstGLBaseMixer + * @see_also: #GstVideoAggregator, #GstGLMixer + * + * #GstGLBaseMixer handles the nitty gritty details of retrieving an OpenGL + * context. It provides some virtual methods to know when the OpenGL context + * is available and is not available within this element. + * + * Since: 1.24 + */ #define GST_CAT_DEFAULT gst_gl_base_mixer_debug GST_DEBUG_CATEGORY (gst_gl_base_mixer_debug); @@ -663,7 +676,7 @@ gst_gl_base_mixer_change_state (GstElement * element, GstStateChange transition) * * Returns: (transfer full) (nullable): the #GstGLContext found by @mix * - * Since: 1.18 + * Since: 1.24 */ GstGLContext * gst_gl_base_mixer_get_gl_context (GstGLBaseMixer * mix) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglbasemixer.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglbasemixer.h index 4440fc1744..5977c6d6ec 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglbasemixer.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglbasemixer.h @@ -23,8 +23,8 @@ #include #include -#include #include +#include G_BEGIN_DECLS @@ -54,6 +54,8 @@ struct _GstGLBaseMixerPadClass GstVideoAggregatorPadClass parent_class; }; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLBaseMixerPad, gst_object_unref); + GST_GL_API GType gst_gl_base_mixer_pad_get_type (void); @@ -96,6 +98,8 @@ struct _GstGLBaseMixerClass gpointer _padding[GST_PADDING]; }; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLBaseMixer, gst_object_unref); + GST_GL_API GType gst_gl_base_mixer_get_type(void); diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmixer.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmixer.c index 7d56662d4d..da40a24700 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmixer.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmixer.c @@ -30,8 +30,20 @@ #include "gstglmixer.h" +#include #include +/** + * SECTION:gstglmixer + * @short_description: #GstVideoAggregator subclass for transforming RGBA textures + * @title: GstGLMixer + * @see_also: #GstGLBaseMixer, #GstVideoAggregator + * + * #GstGLMixer helps implement an element that operates on RGBA textures. + * + * Since: 1.24 + */ + #define GST_CAT_DEFAULT gst_gl_mixer_debug GST_DEBUG_CATEGORY (gst_gl_mixer_debug); @@ -57,6 +69,8 @@ struct _GstGLMixerPrivate gboolean gl_resource_ready; GMutex gl_resource_lock; GCond gl_resource_cond; + + GstGLFramebuffer *fbo; }; #define gst_gl_mixer_parent_class parent_class @@ -533,9 +547,15 @@ _mixer_create_fbo (GstGLContext * context, GstGLMixer * mix) guint out_width = GST_VIDEO_INFO_WIDTH (&vagg->info); guint out_height = GST_VIDEO_INFO_HEIGHT (&vagg->info); - mix->fbo = - gst_gl_framebuffer_new_with_default_depth (context, out_width, - out_height); + g_mutex_lock (&mix->priv->gl_resource_lock); + if (!mix->priv->fbo) + mix->priv->fbo = + gst_gl_framebuffer_new_with_default_depth (context, out_width, + out_height); + g_cond_signal (&mix->priv->gl_resource_cond); + if (mix->priv->fbo) + mix->priv->gl_resource_ready = TRUE; + g_mutex_unlock (&mix->priv->gl_resource_lock); } static gboolean @@ -554,7 +574,7 @@ gst_gl_mixer_gl_stop (GstGLBaseMixer * base_mix) mixer_class->reset (mix); g_mutex_lock (&mix->priv->gl_resource_lock); - gst_clear_object (&mix->fbo); + gst_clear_object (&mix->priv->fbo); g_mutex_unlock (&mix->priv->gl_resource_lock); GST_GL_BASE_MIXER_CLASS (parent_class)->gl_stop (base_mix); @@ -585,13 +605,15 @@ gst_gl_mixer_decide_allocation (GstAggregator * agg, GstQuery * query) g_mutex_lock (&mix->priv->gl_resource_lock); mix->priv->gl_resource_ready = FALSE; - if (mix->fbo) - gst_object_unref (mix->fbo); + gst_clear_object (&mix->priv->fbo); + g_mutex_unlock (&mix->priv->gl_resource_lock); gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _mixer_create_fbo, mix); - if (!mix->fbo) { - g_cond_signal (&mix->priv->gl_resource_cond); + + g_mutex_lock (&mix->priv->gl_resource_lock); + if (!mix->priv->fbo) { + mix->priv->gl_resource_ready = FALSE; g_mutex_unlock (&mix->priv->gl_resource_lock); goto context_error; } @@ -676,10 +698,10 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf) goto out; } - mix_class->process_textures (mix, out_tex); - g_mutex_unlock (&mix->priv->gl_resource_lock); + mix_class->process_textures (mix, out_tex); + out: gst_video_frame_unmap (&out_frame); @@ -760,3 +782,22 @@ gst_gl_mixer_stop (GstAggregator * agg) return GST_AGGREGATOR_CLASS (parent_class)->stop (agg); } + +/** + * gst_gl_mixer_get_framebuffer: + * @mix: the #GstGLMixer + * + * Returns: (transfer full): (nullable): The #GstGLFramebuffer in use by this @mix + * + * Since: 1.24 + */ +GstGLFramebuffer * +gst_gl_mixer_get_framebuffer (GstGLMixer * mix) +{ + GstGLFramebuffer *fbo = NULL; + g_mutex_lock (&mix->priv->gl_resource_lock); + if (mix->priv->fbo) + fbo = gst_object_ref (mix->priv->fbo); + g_mutex_unlock (&mix->priv->gl_resource_lock); + return fbo; +} diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmixer.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmixer.h index 773396d1db..9373a23a8b 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmixer.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglmixer.h @@ -23,8 +23,7 @@ #include #include -#include -#include "gstglbasemixer.h" +#include G_BEGIN_DECLS @@ -60,6 +59,8 @@ struct _GstGLMixerPadClass GstGLBaseMixerPadClass parent_class; }; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLMixerPad, gst_object_unref); + GST_GL_API GType gst_gl_mixer_pad_get_type (void); @@ -85,8 +86,6 @@ struct _GstGLMixer { GstGLBaseMixer vaggregator; - GstGLFramebuffer *fbo; - GstCaps *out_caps; GstGLMixerPrivate *priv; @@ -102,11 +101,16 @@ struct _GstGLMixerClass GstGLMixerProcessTextures process_textures; }; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLMixer, gst_object_unref); + GST_GL_API GType gst_gl_mixer_get_type(void); GST_GL_API gboolean gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf); +GST_GL_API +GstGLFramebuffer * gst_gl_mixer_get_framebuffer (GstGLMixer * mix); + G_END_DECLS #endif /* __GST_GL_MIXER_H__ */