[vlc-devel] [PATCH 3/3] VLCViewUIView: remove hacks preventing deadlocks

Alexandre Janniaux ajanni at videolabs.io
Thu Feb 18 15:23:56 UTC 2021


---
 modules/video_output/apple/VLCVideoUIView.m | 58 +++------------------
 1 file changed, 8 insertions(+), 50 deletions(-)

diff --git a/modules/video_output/apple/VLCVideoUIView.m b/modules/video_output/apple/VLCVideoUIView.m
index 69993013b3..1cdab8fc97 100644
--- a/modules/video_output/apple/VLCVideoUIView.m
+++ b/modules/video_output/apple/VLCVideoUIView.m
@@ -68,6 +68,8 @@
 #import <vlc_mouse.h>
 #import <vlc_vout_window.h>
 
+#import <assert.h>
+
 @interface VLCVideoUIView : UIView {
     /* VLC window object, set to NULL under _mutex lock when closing. */
     vout_window_t *_wnd;
@@ -81,7 +83,6 @@
 
     /* Window state */
     BOOL _enabled;
-    int _subviews;
 }
 
 - (id)initWithWindow:(vout_window_t *)wnd;
@@ -101,7 +102,6 @@
 {
     _wnd = wnd;
     _enabled = NO;
-    _subviews = 0;
 
     self = [super initWithFrame:CGRectMake(0., 0., 320., 240.)];
     if (!self)
@@ -119,6 +119,7 @@
     /* add tap gesture recognizer for DVD menus and stuff */
     _tapRecognizer = [[UITapGestureRecognizer alloc]
         initWithTarget:self action:@selector(tapRecognized:)];
+    _tapRecognizer.cancelsTouchesInView = NO;
 
     return self;
 }
@@ -143,17 +144,8 @@
             return NO;
         }
 
-        /* We need to store the view container because we'll add our view
-         * only when a subview (hopefully able to handle the rendering) will
-         * get created. The main reason for this is that we cannot report
-         * events from the window until the display is opened, otherwise a
-         * race condition involving locking both the main thread and the lock
-         * in the core for the display are happening. */
         _viewContainer = viewContainer;
 
-        self.frame = viewContainer.bounds;
-        [self reshape];
-
         return YES;
     } @catch (NSException *exception) {
         msg_Err(_wnd, "Handling the view container failed due to an Obj-C exception (%s, %s", [exception.name UTF8String], [exception.reason UTF8String]);
@@ -189,36 +181,6 @@
     vlc_mutex_unlock(&_mutex);
 }
 
-/**
- * We track whether we currently have a child view, which will be able
- * to do the actual rendering. Depending on how many children view we had
- * and whether we are in enabled state or not, we add or remove the view
- * from/to the parent UIView.
- * This is needed because we cannot emit resize event from the main
- * thread as long as the display is not created, since the display will
- * need the main thread too. It would non-deterministically deadlock
- * otherwise.
- */
-
-- (void)didAddSubview:(UIView*)subview
-{
-    assert(_enabled);
-    _subviews++;
-    if (_subviews == 1)
-        [_viewContainer addSubview:self];
-
-    VLC_UNUSED(subview);
-}
-
-- (void)willRemoveSubview:(UIView*)subview
-{
-    _subviews--;
-    if (_enabled && _subviews == 0)
-        [self removeFromSuperview];
-
-    VLC_UNUSED(subview);
-}
-
 /**
  * Vout window operations implemention, which are expected to be run on
  * the main thread only. Core C wrappers below must typically use
@@ -230,24 +192,20 @@
 
 - (void)enable
 {
-    if (_enabled)
-        return;
-
-    assert(_subviews == 0);
+    assert(!_enabled);
     _enabled = YES;
+    self.frame = _viewContainer.frame;
+    self.center = _viewContainer.center;
+    [_viewContainer addSubview:self];
 
     /* Bind tapRecognizer. */
     [self addGestureRecognizer:_tapRecognizer];
-    _tapRecognizer.cancelsTouchesInView = NO;
 }
 
 - (void)disable
 {
-    if (!_enabled)
-        return;
-
+    assert(_enabled);
     _enabled = NO;
-    assert(_subviews == 0);
     [self removeFromSuperview];
 
     [_tapRecognizer.view removeGestureRecognizer:_tapRecognizer];
-- 
2.30.1



More information about the vlc-devel mailing list