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

David Fuhrmann git at videolan.org
Sat Apr 11 18:31:45 CEST 2015


vlc/vlc-2.2 | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Apr 11 16:25:29 2015 +0200| [9cb61ac93e0e5468945048d22f160232424dddac] | 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

(cherry picked from commit 4a17358abea2b8fce47e8af3888aec638debfb42)
Signed-off-by: David Fuhrmann <dfuhrmann at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=9cb61ac93e0e5468945048d22f160232424dddac
---

 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 1162c76..a2ceb07 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -99,6 +99,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
  *****************************************************************************/
@@ -108,6 +112,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];
@@ -120,13 +125,34 @@ static int WindowControl(vout_window_t *, int i_query, va_list);
 
 int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
 {
-    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];
@@ -296,9 +322,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