[vlc-commits] macosx: Move p_intf_thread getter out of VLCMain

David Fuhrmann git at videolan.org
Wed Aug 12 13:25:35 CEST 2015


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Wed Aug 12 11:22:25 2015 +0200| [104ac66f0ce0523318a2b2573f404266fa7d19fa] | committer: David Fuhrmann

macosx: Move p_intf_thread getter out of VLCMain

VLCIntf now points to a static getter for the interface thread
pointer.

This fixes several problems: During initialization of
VLCMain, [VLCMain sharedInstance] is not ready yet when all other
objects are initialized inside VLCMains constructor. Due to the
way ARC works, the same applies to dealloc (the main shared instance
is nil already). But in both situations, we need VLCIntf for
callback (un)registration and potential logging.

The mac interface relies on static data in any case and does not
support multiple instantiations.

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

 modules/gui/macosx/InputManager.m |    2 +-
 modules/gui/macosx/intf.h         |   11 +++++------
 modules/gui/macosx/intf.m         |   34 ++++++++++++++++++----------------
 3 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/modules/gui/macosx/InputManager.m b/modules/gui/macosx/InputManager.m
index dac5788..261abee 100644
--- a/modules/gui/macosx/InputManager.m
+++ b/modules/gui/macosx/InputManager.m
@@ -156,7 +156,7 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
     self = [super init];
     if(self) {
         o_main = o_mainObj;
-        var_AddCallback(pl_Get([o_mainObj intf]), "input-current", InputThreadChanged, (__bridge void *)self);
+        var_AddCallback(pl_Get(VLCIntf), "input-current", InputThreadChanged, (__bridge void *)self);
 
         informInputChangedQueue = dispatch_queue_create("org.videolan.vlc.inputChangedQueue", DISPATCH_QUEUE_SERIAL);
 
diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index db6938d..0a8b393 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -46,7 +46,11 @@
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-#define VLCIntf [[VLCMain sharedInstance] intf]
+
+// deprecated macro
+#define VLCIntf getIntf()
+
+intf_thread_t *getIntf();
 
 static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
 
@@ -76,14 +80,9 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
 @property (readonly) BOOL nativeFullscreenMode;
 @property (nonatomic, readwrite) BOOL playlistUpdatedSelectorInQueue;
 
-+ (VLCMain *)createInstanceWithIntf:(intf_thread_t *)intf;
 + (VLCMain *)sharedInstance;
 + (void)killInstance;
 
-- (id)initWithIntf:(intf_thread_t *)intf;
-
-- (intf_thread_t *)intf;
-
 - (VLCMainMenu *)mainMenu;
 - (VLCMainWindow *)mainWindow;
 - (VLCBookmarks *)bookmarks;
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index c4be345..fcbf27b 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -77,14 +77,23 @@
 /*****************************************************************************
  * OpenIntf: initialize interface
  *****************************************************************************/
+
+static intf_thread_t *p_interface_thread;
+
+intf_thread_t *getIntf()
+{
+    return p_interface_thread;
+}
+
 int OpenIntf (vlc_object_t *p_this)
 {
     @autoreleasepool {
         intf_thread_t *p_intf = (intf_thread_t*) p_this;
+        p_interface_thread = p_intf;
         msg_Dbg(p_intf, "Starting macosx interface");
 
         [VLCApplication sharedApplication];
-        [VLCMain createInstanceWithIntf: p_intf];
+        [VLCMain sharedInstance];
 
         [NSBundle loadNibNamed:@"MainMenu" owner:[[VLCMain sharedInstance] mainMenu]];
         [[[VLCMain sharedInstance] mainWindow] makeKeyAndOrderFront:nil];
@@ -99,6 +108,8 @@ void CloseIntf (vlc_object_t *p_this)
         msg_Dbg(p_this, "Closing macosx interface");
         [[VLCMain sharedInstance] applicationWillTerminate:nil];
         [VLCMain killInstance];
+
+        p_interface_thread = nil;
     }
 }
 
@@ -179,17 +190,11 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
 
 static VLCMain *sharedInstance = nil;
 
-+ (VLCMain *)sharedInstance
-{
-    return sharedInstance;
-}
-
-+ (VLCMain *)createInstanceWithIntf:(intf_thread_t *)intf;
++ (VLCMain *)sharedInstance;
 {
     static dispatch_once_t pred;
-
     dispatch_once(&pred, ^{
-        sharedInstance = [[VLCMain alloc] initWithIntf:intf];
+        sharedInstance = [[VLCMain alloc] init];
     });
 
     return sharedInstance;
@@ -200,11 +205,11 @@ static VLCMain *sharedInstance = nil;
     sharedInstance = nil;
 }
 
-- (id)initWithIntf:(intf_thread_t *)intf;
+- (id)init
 {
     self = [super init];
     if (self) {
-        p_intf = intf;
+        p_intf = getIntf();
 
         [VLCApplication sharedApplication].delegate = self;
 
@@ -251,9 +256,9 @@ static VLCMain *sharedInstance = nil;
     return self;
 }
 
-- (intf_thread_t *)intf
+- (void)dealloc
 {
-    return p_intf;
+    msg_Dbg(VLCIntf, "Deinitializing VLCMain object");
 }
 
 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
@@ -360,9 +365,6 @@ static VLCMain *sharedInstance = nil;
     _voutController = nil;
     [_voutController.lock unlock];
 
-    /* unsubscribe from libvlc's debug messages */
-    vlc_LogSet(p_intf->p_libvlc, NULL, NULL);
-
     /* write cached user defaults to disk */
     [[NSUserDefaults standardUserDefaults] synchronize];
 }



More information about the vlc-commits mailing list