[vlc-commits] macosx: implement libvlc exit handler to properly terminate the app when requested

David Fuhrmann git at videolan.org
Mon Feb 3 15:18:10 CET 2014


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Sun Feb  2 18:18:07 2014 +0100| [f36dcf5a5cfeb0b7af7035f3dc95aab75a3a1fa5] | committer: David Fuhrmann

macosx: implement libvlc exit handler to properly terminate the app when requested

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.

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

 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 7b2db9d..40bd983 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 + 3];
@@ -217,7 +210,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];



More information about the vlc-commits mailing list