[vlc-commits] macosx: clean access to the aout/vout threads

Felix Paul Kühne git at videolan.org
Fri Mar 22 09:48:19 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Fri Mar 15 11:12:56 2019 +0100| [b4ad3222a28a3f00276ef4ce073af41da18e76e1] | committer: Felix Paul Kühne

macosx: clean access to the aout/vout threads

Use instance variables more effectively to save selector dispatches (and characters)

This is an iterated version of 224b0430 addressing the deadlock on launch

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

 .../macosx/coreinteraction/VLCCoreInteraction.m    | 26 ++++----
 modules/gui/macosx/menus/VLCMainMenu.m             | 14 ++---
 .../panels/VLCAudioEffectsWindowController.m       | 70 ++++++++++++----------
 .../panels/VLCVideoEffectsWindowController.m       |  6 +-
 4 files changed, 64 insertions(+), 52 deletions(-)

diff --git a/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m b/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
index 85fb334939..0ec106ef3c 100644
--- a/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
+++ b/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
@@ -61,6 +61,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
 
     VLCClickerManager *_clickerManager;
     VLCPlaylistController *_playlistController;
+    VLCPlayerController *_playerController;
 }
 @end
 
@@ -94,6 +95,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
 
         _clickerManager = [[VLCClickerManager alloc] init];
         _playlistController = [[VLCMain sharedInstance] playlistController];
+        _playerController = [_playlistController playerController];
 
         var_AddCallback(pl_Get(p_intf), "intf-boss", BossCallback, (__bridge void *)self);
     }
@@ -119,18 +121,16 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
 
 - (void)playOrPause
 {
-    VLCMain *mainInstance = [VLCMain sharedInstance];
-    VLCPlaylistController *playlistController = mainInstance.playlistController;
-    input_item_t *p_input_item = playlistController.currentlyPlayingInputItem;
+    input_item_t *p_input_item = _playlistController.currentlyPlayingInputItem;
 
     if (p_input_item) {
-        [playlistController.playerController togglePlayPause];
+        [_playerController togglePlayPause];
         input_item_Release(p_input_item);
     } else {
-        if (mainInstance.playlistController.playlistModel.numberOfPlaylistItems == 0)
-            [[mainInstance open] openFileGeneric];
+        if (_playlistController.playlistModel.numberOfPlaylistItems == 0)
+            [[[VLCMain sharedInstance] open] openFileGeneric];
         else
-            [playlistController startPlaylist];
+            [_playlistController startPlaylist];
     }
 }
 
@@ -381,7 +381,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
     }
     config_PutInt("random", on);
 
-    vout_thread_t *p_vout = [[_playlistController playerController] mainVideoOutputThread];
+    vout_thread_t *p_vout = [_playerController mainVideoOutputThread];
     if (!p_vout) {
         return;
     }
@@ -398,7 +398,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
 {
     _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_ALL;
 
-    vout_thread_t *p_vout = [[_playlistController playerController] mainVideoOutputThread];
+    vout_thread_t *p_vout = [_playerController mainVideoOutputThread];
     if (p_vout) {
         vout_OSDMessage(p_vout, VOUT_SPU_CHANNEL_OSD, "%s", _("Repeat All"));
         vout_Release(p_vout);
@@ -409,7 +409,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
 {
     _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT;
 
-    vout_thread_t *p_vout = [[_playlistController playerController] mainVideoOutputThread];
+    vout_thread_t *p_vout = [_playerController mainVideoOutputThread];
     if (p_vout) {
         vout_OSDMessage(p_vout, VOUT_SPU_CHANNEL_OSD, "%s", _("Repeat One"));
         vout_Release(p_vout);
@@ -420,7 +420,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
 {
     _playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;
 
-    vout_thread_t *p_vout = [[_playlistController playerController] mainVideoOutputThread];
+    vout_thread_t *p_vout = [_playerController mainVideoOutputThread];
     if (p_vout) {
         vout_OSDMessage(p_vout, VOUT_SPU_CHANNEL_OSD, "%s", _("Repeat Off"));
         vout_Release(p_vout);
@@ -574,7 +574,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
 
 - (void)showPosition
 {
-    vout_thread_t *p_vout = [[_playlistController playerController] mainVideoOutputThread];
+    vout_thread_t *p_vout = [_playerController mainVideoOutputThread];
     if (p_vout != NULL) {
         var_SetInteger(vlc_object_instance(getIntf()), "key-action", ACTIONID_POSITION);
         vout_Release(p_vout);
@@ -678,7 +678,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
         unichar key = [characters characterAtIndex: 0];
 
         if (key) {
-            vout_thread_t *p_vout = [[_playlistController playerController] mainVideoOutputThread];
+            vout_thread_t *p_vout = [_playerController mainVideoOutputThread];
             if (p_vout != NULL) {
                 /* Escape */
                 if (key == (unichar) 0x1b) {
diff --git a/modules/gui/macosx/menus/VLCMainMenu.m b/modules/gui/macosx/menus/VLCMainMenu.m
index e0c2464772..a79c99214a 100644
--- a/modules/gui/macosx/menus/VLCMainMenu.m
+++ b/modules/gui/macosx/menus/VLCMainMenu.m
@@ -585,7 +585,7 @@
         [self setupVarMenuItem:_subtitle_track target: (vlc_object_t *)p_input
                                  var:"spu-es" selector: @selector(toggleVar:)];
 
-        audio_output_t *p_aout = _playlistController.playerController.mainAudioOutput;
+        audio_output_t *p_aout = [_playerController mainAudioOutput];
         if (p_aout != NULL) {
             [self setupVarMenuItem:_channels target: (vlc_object_t *)p_aout
                                      var:"stereo-mode" selector: @selector(toggleVar:)];
@@ -595,7 +595,7 @@
             aout_Release(p_aout);
         }
 
-        vout_thread_t *p_vout = [[[[VLCMain sharedInstance] playlistController] playerController] videoOutputThreadForKeyWindow];
+        vout_thread_t *p_vout = [_playerController videoOutputThreadForKeyWindow];
 
         if (p_vout != NULL) {
             [self setupVarMenuItem:_aspect_ratio target: (vlc_object_t *)p_vout
@@ -886,7 +886,7 @@
 
     [_audioDeviceMenu removeAllItems];
 
-    audio_output_t *p_aout = _playlistController.playerController.mainAudioOutput;
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (!p_aout)
         return;
 
@@ -923,7 +923,7 @@
 
 - (void)toggleAudioDevice:(id)sender
 {
-    audio_output_t *p_aout = _playlistController.playerController.mainAudioOutput;
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (!p_aout)
         return;
 
@@ -950,7 +950,7 @@
 
 - (IBAction)resizeVideoWindow:(id)sender
 {
-    vout_thread_t *p_vout = [[[[VLCMain sharedInstance] playlistController] playerController] videoOutputThreadForKeyWindow];
+    vout_thread_t *p_vout = [_playerController videoOutputThreadForKeyWindow];
     if (p_vout) {
         if (sender == _half_window)
             var_SetFloat(p_vout, "zoom", 0.5);
@@ -971,7 +971,7 @@
     // FIXME re-write using VLCPlayerController
     input_thread_t *p_input = pl_CurrentInput(getIntf());
     if (p_input) {
-        vout_thread_t *p_vout = [[[[VLCMain sharedInstance] playlistController] playerController] videoOutputThreadForKeyWindow];
+        vout_thread_t *p_vout = [_playerController videoOutputThreadForKeyWindow];
         if (p_vout) {
             BOOL b_fs = var_ToggleBool(p_vout, "video-on-top");
             var_SetBool(pl_Get(getIntf()), "video-on-top", b_fs);
@@ -1659,7 +1659,7 @@
                mi == _floatontop
                ) {
 
-        vout_thread_t *p_vout = [[[[VLCMain sharedInstance] playlistController] playerController] videoOutputThreadForKeyWindow];
+        vout_thread_t *p_vout = [_playerController videoOutputThreadForKeyWindow];
         if (p_vout != NULL) {
             // FIXME: re-write using VLCPlayerController
             if (mi == _floatontop)
diff --git a/modules/gui/macosx/panels/VLCAudioEffectsWindowController.m b/modules/gui/macosx/panels/VLCAudioEffectsWindowController.m
index 87ee801b92..30db852927 100644
--- a/modules/gui/macosx/panels/VLCAudioEffectsWindowController.m
+++ b/modules/gui/macosx/panels/VLCAudioEffectsWindowController.m
@@ -41,6 +41,11 @@
 #import "playlist/VLCPlaylistController.h"
 #import "playlist/VLCPlayerController.h"
 
+ at interface VLCAudioEffectsWindowController ()
+{
+    VLCPlayerController *_playerController;
+}
+ at end
 
 #pragma mark -
 #pragma mark Initialization
@@ -96,22 +101,26 @@
 {
     self = [super initWithWindowNibName:@"AudioEffects"];
     if (self) {
-        self.popupPanel = [[VLCPopupPanelController alloc] init];
-        self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
-
-        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-        if ([defaults boolForKey:@"AudioEffectApplyProfileOnStartup"])
-        {
-            // This does not reset the UI (which does not exist yet), but it initalizes needed playlist vars
-            [self equalizerUpdated];
-            [self resetCompressor];
-            [self resetSpatializer];
-            [self resetAudioFilters];
-
-            [self loadProfile];
-        } else {
-            [self saveCurrentProfileIndex:0];
-        }
+        dispatch_async(dispatch_get_main_queue(), ^{
+            _playerController = [[[VLCMain sharedInstance] playlistController] playerController];
+
+            self.popupPanel = [[VLCPopupPanelController alloc] init];
+            self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
+
+            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+            if ([defaults boolForKey:@"AudioEffectApplyProfileOnStartup"])
+            {
+                // This does not reset the UI (which does not exist yet), but it initalizes needed playlist vars
+                [self equalizerUpdated];
+                [self resetCompressor];
+                [self resetSpatializer];
+                [self resetAudioFilters];
+
+                [self loadProfile];
+            } else {
+                [self saveCurrentProfileIndex:0];
+            }
+        });
     }
 
     return self;
@@ -153,7 +162,7 @@
 
     /* eq preset */
     char const *psz_eq_preset = [B64DecNSStr([items firstObject]) UTF8String];
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (p_aout)
         var_SetString(p_aout, "equalizer-preset", psz_eq_preset);
     var_SetString(p_playlist, "equalizer-preset", psz_eq_preset);
@@ -609,10 +618,11 @@
 #pragma mark -
 #pragma mark Equalizer
 static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
+                               VLCPlayerController *playerController,
                                char *psz_name)
 {
     char *psz_parser, *psz_string = NULL;
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [playerController mainAudioOutput];
     if (!p_aout)
         return false;
 
@@ -654,7 +664,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
         [[_equalizerPresetsPopup lastItem] setAction: @selector(deletePresetAction:)];
     }
 
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
 
     NSString *currentPreset = nil;
     if (p_aout) {
@@ -684,7 +694,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
     intf_thread_t *p_intf = getIntf();
     playlist_t *p_playlist = pl_Get(p_intf);
     bool b_2p = var_CreateGetBool(p_playlist, "equalizer-2pass");
-    bool bEnabled = GetEqualizerStatus(p_intf, (char *)"equalizer");
+    bool bEnabled = GetEqualizerStatus(p_intf, _playerController, (char *)"equalizer");
 
     /* Setup sliders */
     var_Create(p_playlist, "equalizer-preset",
@@ -758,7 +768,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 
 - (IBAction)equalizerBandSliderUpdated:(id)sender
 {
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     char const *psz_preset_values = [[self generatePresetString] UTF8String];
     if (p_aout) {
         var_SetString(p_aout, "equalizer-bands", psz_preset_values);
@@ -776,7 +786,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
     float f_eq_preamp = [[[defaults objectForKey:@"EQPreampValues"] objectAtIndex:numberOfChosenPreset] floatValue];
     char const *psz_eq_preset = [[[defaults objectForKey:@"EQNames"] objectAtIndex:numberOfChosenPreset] UTF8String];
 
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (p_aout) {
         var_SetString(p_aout, "equalizer-bands", psz_eq_bands);
         var_SetFloat(p_aout, "equalizer-preamp", f_eq_preamp);
@@ -796,7 +806,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 {
     float fPreamp = [sender floatValue] ;
 
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (p_aout) {
         var_SetFloat(p_aout, "equalizer-preamp", fPreamp);
         aout_Release(p_aout);
@@ -808,7 +818,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 {
     bool b_2p = [sender state] ? true : false;
 
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (p_aout) {
         var_SetBool(p_aout, "equalizer-2pass", b_2p);
         aout_Release(p_aout);
@@ -850,7 +860,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 
         /* update VLC internals */
         char const *psz_eq_preset = [decomposedStringWithCanonicalMapping UTF8String];
-        audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+        audio_output_t *p_aout = [self->_playerController mainAudioOutput];
         if (p_aout) {
             var_SetString(p_aout, "equalizer-preset", psz_eq_preset);
             aout_Release(p_aout);
@@ -943,7 +953,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
     var_SetFloat(p_playlist, "compressor-knee", 2.500000);
     var_SetFloat(p_playlist, "compressor-makeup-gain", 7.000000);
 
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (p_aout) {
         var_SetFloat(p_aout, "compressor-rms-peak", 0.000000);
         var_SetFloat(p_aout, "compressor-attack", 25.000000);
@@ -985,7 +995,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 
     assert(psz_property);
 
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (p_aout) {
         var_SetFloat(p_aout, psz_property, f_value);
         aout_Release(p_aout);
@@ -1047,7 +1057,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
     var_SetFloat(p_playlist, "spatializer-dry", .5);
     var_SetFloat(p_playlist, "spatializer-damp", .5);
 
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (p_aout) {
         var_SetFloat(p_aout, "spatializer-roomsize", .85);
         var_SetFloat(p_aout, "spatializer-width", 1.);
@@ -1083,7 +1093,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 
     assert(psz_property);
 
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     if (p_aout) {
         var_SetFloat(p_aout, psz_property, f_value / 10.f);
         aout_Release(p_aout);
@@ -1145,7 +1155,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
 
 - (IBAction)filterVolumeNormSliderUpdated:(id)sender
 {
-    audio_output_t *p_aout = [[[[VLCMain sharedInstance] playlistController] playerController] mainAudioOutput];
+    audio_output_t *p_aout = [_playerController mainAudioOutput];
     float f_value = [_filterNormLevelSlider floatValue];
 
     if (p_aout) {
diff --git a/modules/gui/macosx/panels/VLCVideoEffectsWindowController.m b/modules/gui/macosx/panels/VLCVideoEffectsWindowController.m
index 3779afc949..6b2ad1a9a5 100644
--- a/modules/gui/macosx/panels/VLCVideoEffectsWindowController.m
+++ b/modules/gui/macosx/panels/VLCVideoEffectsWindowController.m
@@ -115,21 +115,23 @@
 
     /* enable the new filters */
     var_SetString(p_playlist, "video-filter", [tempString UTF8String]);
-    if (vouts)
+    if (vouts) {
         for (NSValue *ptr in vouts) {
             vout_thread_t *p_vout = [ptr pointerValue];
             var_SetString(p_vout, "video-filter", [tempString UTF8String]);
         }
+    }
 
     tempString = B64DecNSStr([items objectAtIndex:1]);
     /* enable another round of new filters */
     var_SetString(p_playlist, "sub-source", [tempString UTF8String]);
-    if (vouts)
+    if (vouts) {
         for (NSValue *ptr in vouts) {
             vout_thread_t *p_vout = [ptr pointerValue];
             var_SetString(p_vout, "sub-source", [tempString UTF8String]);
             vout_Release(p_vout);
         }
+    }
 
     tempString = B64DecNSStr([items objectAtIndex:2]);
     /* enable another round of new filters */



More information about the vlc-commits mailing list