From: Julien Isorce Date: Sun, 1 Mar 2015 19:57:23 +0000 (+0000) Subject: gl/cocoa: register only one custom nsapp loop X-Git-Tag: 1.19.3~511^2~1989^2~1029 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=befc24469cafd9847f43ab98f6e43ac98411e68d;p=platform%2Fupstream%2Fgstreamer.git gl/cocoa: register only one custom nsapp loop Otherwise the pipeline stalls when running more than one glimagesink with gst-launch. Also only register the custom nsapp loop when setting up the nsapp from gstgl. --- diff --git a/gst-libs/gst/gl/cocoa/gstgl_cocoa_private.h b/gst-libs/gst/gl/cocoa/gstgl_cocoa_private.h index ae7abc8..0ccadc8 100644 --- a/gst-libs/gst/gl/cocoa/gstgl_cocoa_private.h +++ b/gst-libs/gst/gl/cocoa/gstgl_cocoa_private.h @@ -38,8 +38,6 @@ struct _GstGLContextCocoaPrivate CGLContextObj external_gl_context; GstGLAPI context_api; - - gint source_id; }; diff --git a/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m b/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m index 659c42c..fd8891e 100644 --- a/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m +++ b/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m @@ -50,8 +50,12 @@ G_DEFINE_TYPE_WITH_CODE (GstGLContextCocoa, gst_gl_context_cocoa, */ #ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION +static gboolean gst_gl_window_cocoa_nsapp_iteration (gpointer data); + static GMutex nsapp_lock; static GCond nsapp_cond; +static gint nsapp_count = 0; +static gint nsapp_source_id = 0; static gboolean gst_gl_window_cocoa_init_nsapp (gpointer data) @@ -72,9 +76,13 @@ gst_gl_window_cocoa_init_nsapp (gpointer data) */ /* has to be called in the main thread */ - [NSApplication sharedApplication]; + if ([NSThread isMainThread]) { + [NSApplication sharedApplication]; - GST_DEBUG ("NSApp initialized from a GTimeoutSource"); + GST_DEBUG ("NSApp initialized from a GTimeoutSource"); + + nsapp_source_id = g_timeout_add (60, gst_gl_window_cocoa_nsapp_iteration, NULL); + } [pool release]; @@ -106,6 +114,23 @@ gst_gl_window_cocoa_nsapp_iteration (gpointer data) return TRUE; } +static void +gst_gl_context_cocoa_check_nsapp_loop (gboolean activate) +{ + g_mutex_lock (&nsapp_lock); + + if (activate) ++nsapp_count; + else --nsapp_count; + + if (nsapp_count == 0) { + if (nsapp_source_id) + g_source_remove (nsapp_source_id); + nsapp_source_id = 0; + } + + g_mutex_unlock (&nsapp_lock); +} + static gpointer gst_gl_context_cocoa_setup_nsapp (gpointer data) { @@ -314,7 +339,7 @@ gst_gl_context_cocoa_create_context (GstGLContext *context, GstGLAPI gl_api, #ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION static GOnce once = G_ONCE_INIT; g_once (&once, gst_gl_context_cocoa_setup_nsapp, context); - priv->source_id = g_timeout_add (60, gst_gl_window_cocoa_nsapp_iteration, NULL); + gst_gl_context_cocoa_check_nsapp_loop (TRUE); #endif priv->gl_context = nil; @@ -353,8 +378,7 @@ gst_gl_context_cocoa_create_context (GstGLContext *context, GstGLAPI gl_api, if (!context_cocoa->priv->gl_context) { #ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION - g_source_remove (priv->source_id); - priv->source_id = 0; + gst_gl_context_cocoa_check_nsapp_loop (FALSE); #endif goto error; } @@ -382,14 +406,10 @@ error: static void gst_gl_context_cocoa_destroy_context (GstGLContext *context) { - GstGLContextCocoa *context_cocoa = GST_GL_CONTEXT_COCOA (context); - GstGLContextCocoaPrivate *priv = context_cocoa->priv; - /* FIXME: Need to release context and other things? */ - if (priv->source_id) { - g_source_remove (priv->source_id); - priv->source_id = 0; - } +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION + gst_gl_context_cocoa_check_nsapp_loop (FALSE); +#endif } static guintptr