[vlc-devel] [PATCH 1/2] macosx: implement libvlc exit handler to properly terminate the app when requested

david.fuhrmann at gmail.com david.fuhrmann at gmail.com
Mon Feb 3 11:05:37 CET 2014


From: David Fuhrmann <david.fuhrmann at googlemail.com>

This is the only supported way to terminate an cocoa application and also ensure
that the gui settings are getting saved. Adapted from similar code in the qt
module.
---
 bin/darwinvlc.c           | 8 --------
 modules/gui/macosx/intf.m | 9 +++++++++
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/bin/darwinvlc.c b/bin/darwinvlc.c
index 721a178..2ff65fc 100644
--- a/bin/darwinvlc.c
+++ b/bin/darwinvlc.c
@@ -55,12 +55,6 @@ static bool signal_ignored (int signum)
             ? (void *)sa.sa_sigaction : (void *)sa.sa_handler) == SIG_IGN;
 }
 
-static void vlc_kill (void *data)
-{
-    pthread_t *ps = data;
-    pthread_kill (*ps, SIGTERM);
-}
-
 static void exit_timeout (int signum)
 {
     (void) signum;
@@ -148,7 +142,6 @@ int main( int i_argc, const char *ppsz_argv[] )
     sigaddset (&set, SIGCHLD);
 
     /* Block all these signals */
-    pthread_t self = pthread_self ();
     pthread_sigmask (SIG_SETMASK, &set, NULL);
 
     const char *argv[i_argc + 2];
@@ -216,7 +209,6 @@ int main( int i_argc, const char *ppsz_argv[] )
         return 1;
 
     int ret = 1;
-    libvlc_set_exit_handler (vlc, vlc_kill, &self);
     libvlc_set_app_id (vlc, "org.VideoLAN.VLC", PACKAGE_VERSION, PACKAGE_NAME);
     libvlc_set_user_agent (vlc, "VLC media player", "VLC/"PACKAGE_VERSION);
 
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index bd4ae5e..a844243 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -283,6 +283,13 @@ void WindowClose(vout_window_t *p_wnd)
     [o_pool release];
 }
 
+/* Used to abort the app.exec() on OSX after libvlc_Quit is called */
+#include "../../../lib/libvlc_internal.h" /* libvlc_SetExitHandler */
+static void QuitVLC( void *obj )
+{
+    [[VLCApplication sharedApplication] performSelectorOnMainThread:@selector(terminate:) withObject:nil waitUntilDone:NO];
+}
+
 /*****************************************************************************
  * Run: main loop
  *****************************************************************************/
@@ -298,6 +305,8 @@ static void Run(intf_thread_t *p_intf)
     o_plItemChangedLock = [[NSLock alloc] init];
     o_vout_provider_lock = [[NSLock alloc] init];
 
+    libvlc_SetExitHandler(p_intf->p_libvlc, QuitVLC, p_intf);
+
     [[VLCMain sharedInstance] setIntf: p_intf];
 
     [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
-- 
1.8.3.4 (Apple Git-47)




More information about the vlc-devel mailing list