[vlc-commits] macosx: wait in vout provider for the interface to be initialized

David Fuhrmann git at videolan.org
Sat Apr 11 16:56:20 CEST 2015


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Apr 11 16:25:29 2015 +0200| [4a17358abea2b8fce47e8af3888aec638debfb42] | committer: David Fuhrmann

macosx: wait in vout provider for the interface to be initialized

Because the playlist is started before the interface is up,
the vout window provider waits until basic initalization is done
in the interface (initialization of VLCIntf, NSApp, static vars).

This is still sort of a hack, ideally the playlist should be
started only after all interfaces are fully initialized.

close #11585

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4a17358abea2b8fce47e8af3888aec638debfb42
---

 modules/gui/macosx/intf.m |   42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 1e283aa..44ca67b 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -98,6 +98,10 @@ static int BossCallback(vlc_object_t *, const char *,
 #pragma mark -
 #pragma mark VLC Interface Object Callbacks
 
+static bool b_intf_starting = false;
+static vlc_mutex_t start_mutex = VLC_STATIC_MUTEX;
+static vlc_cond_t  start_cond = VLC_STATIC_COND;
+
 /*****************************************************************************
  * OpenIntf: initialize interface
  *****************************************************************************/
@@ -107,6 +111,7 @@ int OpenIntf (vlc_object_t *p_this)
     [VLCApplication sharedApplication];
 
     intf_thread_t *p_intf = (intf_thread_t*) p_this;
+    msg_Dbg(p_intf, "Starting macosx interface");
     Run(p_intf);
 
     [o_pool release];
@@ -123,13 +128,34 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
      && cfg->type != VOUT_WINDOW_TYPE_NSOBJECT)
         return VLC_EGENERIC;
 
-    NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
-    intf_thread_t *p_intf = VLCIntf;
-    if (!p_intf) {
-        msg_Err(p_wnd, "Mac OS X interface not found");
-        [o_pool release];
+    msg_Dbg(p_wnd, "Opening video window");
+
+    /*
+     * HACK: Wait 200ms for the interface to come up.
+     * WindowOpen might be called before the mac intf is started. Lets wait until OpenIntf gets called
+     * and does basic initialization. Enqueuing the vout controller request into the main loop later on
+     * ensures that the actual window is created after the interface is fully initialized
+     * (applicationDidFinishLaunching).
+     *
+     * Timeout is needed as the mac intf is not always started at all.
+     */
+    mtime_t deadline = mdate() + 200000;
+    vlc_mutex_lock(&start_mutex);
+    while (!b_intf_starting) {
+        if (vlc_cond_timedwait(&start_cond, &start_mutex, deadline)) {
+            break; // timeout
+        }
+    }
+
+    if (!b_intf_starting) {
+        msg_Err(p_wnd, "Cannot create vout as Mac OS X interface was not found");
+        vlc_mutex_unlock(&start_mutex);
         return VLC_EGENERIC;
     }
+    vlc_mutex_unlock(&start_mutex);
+
+    NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+
     NSRect proposedVideoViewPosition = NSMakeRect(cfg->x, cfg->y, cfg->width, cfg->height);
 
     [o_vout_provider_lock lock];
@@ -300,9 +326,13 @@ static void Run(intf_thread_t *p_intf)
     o_vout_provider_lock = [[NSLock alloc] init];
 
     libvlc_SetExitHandler(p_intf->p_libvlc, QuitVLC, p_intf);
-
     [[VLCMain sharedInstance] setIntf: p_intf];
 
+    vlc_mutex_lock(&start_mutex);
+    b_intf_starting = true;
+    vlc_cond_signal(&start_cond);
+    vlc_mutex_unlock(&start_mutex);
+
     [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
 
     [NSApp run];



More information about the vlc-commits mailing list