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.
This commit is contained in:
Julien Isorce 2015-03-01 19:57:23 +00:00
parent 4801db552d
commit 74c294892d
2 changed files with 32 additions and 14 deletions

View file

@ -38,8 +38,6 @@ struct _GstGLContextCocoaPrivate
CGLContextObj external_gl_context; CGLContextObj external_gl_context;
GstGLAPI context_api; GstGLAPI context_api;
gint source_id;
}; };

View file

@ -50,8 +50,12 @@ G_DEFINE_TYPE_WITH_CODE (GstGLContextCocoa, gst_gl_context_cocoa,
*/ */
#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION #ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION
static gboolean gst_gl_window_cocoa_nsapp_iteration (gpointer data);
static GMutex nsapp_lock; static GMutex nsapp_lock;
static GCond nsapp_cond; static GCond nsapp_cond;
static gint nsapp_count = 0;
static gint nsapp_source_id = 0;
static gboolean static gboolean
gst_gl_window_cocoa_init_nsapp (gpointer data) 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 */ /* 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]; [pool release];
@ -106,6 +114,23 @@ gst_gl_window_cocoa_nsapp_iteration (gpointer data)
return TRUE; 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 static gpointer
gst_gl_context_cocoa_setup_nsapp (gpointer data) 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 #ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION
static GOnce once = G_ONCE_INIT; static GOnce once = G_ONCE_INIT;
g_once (&once, gst_gl_context_cocoa_setup_nsapp, context); 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 #endif
priv->gl_context = nil; 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) { if (!context_cocoa->priv->gl_context) {
#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION #ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION
g_source_remove (priv->source_id); gst_gl_context_cocoa_check_nsapp_loop (FALSE);
priv->source_id = 0;
#endif #endif
goto error; goto error;
} }
@ -382,14 +406,10 @@ error:
static void static void
gst_gl_context_cocoa_destroy_context (GstGLContext *context) 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? */ /* FIXME: Need to release context and other things? */
if (priv->source_id) { #ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION
g_source_remove (priv->source_id); gst_gl_context_cocoa_check_nsapp_loop (FALSE);
priv->source_id = 0; #endif
}
} }
static guintptr static guintptr