summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2014-09-29 10:49:46 +0300
committerSebastian Dröge <sebastian@centricular.com>2014-10-14 10:01:13 +0200
commit20fc76ef6b00d77821bdd2ae9bf452e63813e373 (patch)
treec4ef5c80293fd7b6f254121ba38db24d929cee08
parentda30ea5e678f0d80a5964b0c64744256c38f10cb (diff)
downloadgstreamer-plugins-bad-20fc76ef6b00d77821bdd2ae9bf452e63813e373.tar.gz
gl/cocoa: Improve the NSApplication initialization
This is only for non-Cocoa apps but previously caused a 2 second waiting during startup for Cocoa apps. This is unacceptable. Instead we now check a bit more extensive if something actually runs on the GLib default main context, and if not don't even bother waiting for something to happen from there.
-rw-r--r--gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m44
1 files changed, 30 insertions, 14 deletions
diff --git a/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m b/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m
index 131e06e72..7a12650cc 100644
--- a/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m
+++ b/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m
@@ -154,24 +154,40 @@ gst_gl_context_cocoa_class_init (GstGLContextCocoaClass * klass)
* glib main loop running this is for debugging
* purposes so that's ok to let us a chance
*/
+ GMainContext *context;
gboolean is_loop_running = FALSE;
gint64 end_time = 0;
- g_mutex_init (&nsapp_lock);
- g_cond_init (&nsapp_cond);
-
- g_mutex_lock (&nsapp_lock);
- g_idle_add_full (G_PRIORITY_HIGH, gst_gl_window_cocoa_init_nsapp, NULL, NULL);
- end_time = g_get_monotonic_time () + 2 * 1000 * 1000;
- is_loop_running = g_cond_wait_until (&nsapp_cond, &nsapp_lock, end_time);
- g_mutex_unlock (&nsapp_lock);
-
- if (!is_loop_running) {
- GST_WARNING ("no mainloop running");
+ context = g_main_context_default ();
+
+ if (g_main_context_is_owner (context)) {
+ /* At the thread running the default GLib main context but
+ * not the Cocoa main thread
+ * We can't do anything here
+ */
+ } else if (g_main_context_acquire (context)) {
+ /* No main loop running on the default main context,
+ * we can't do anything here */
+ g_main_context_release (context);
+ } else {
+ /* Main loop running on the default main context but it
+ * is not running in this thread */
+ g_mutex_init (&nsapp_lock);
+ g_cond_init (&nsapp_cond);
+
+ g_mutex_lock (&nsapp_lock);
+ g_idle_add_full (G_PRIORITY_HIGH, gst_gl_window_cocoa_init_nsapp, NULL, NULL);
+ end_time = g_get_monotonic_time () + 500 * 1000;
+ is_loop_running = g_cond_wait_until (&nsapp_cond, &nsapp_lock, end_time);
+ g_mutex_unlock (&nsapp_lock);
+
+ if (!is_loop_running) {
+ GST_WARNING ("no mainloop running");
+ }
+
+ g_cond_clear (&nsapp_cond);
+ g_mutex_clear (&nsapp_lock);
}
-
- g_cond_clear (&nsapp_cond);
- g_mutex_clear (&nsapp_lock);
}
[pool release];