[vlc-commits] vout: ios: don't wait for the MainThead from the Close callback

2018-03-07 Thread Thomas Guillem
vlc/vlc-3.0 | branch: master | Thomas Guillem  | Tue Mar  6 
13:14:29 2018 +0100| [f5380c99a43a6f1327c4179e950629c24a8655fe] | committer: 
Thomas Guillem

vout: ios: don't wait for the MainThead from the Close callback

(cherry picked from commit e3a38e5a9c185f68bef8749f2eb093b4fee98b1d)
Signed-off-by: Thomas Guillem 

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

 modules/video_output/ios.m | 131 +++--
 1 file changed, 80 insertions(+), 51 deletions(-)

diff --git a/modules/video_output/ios.m b/modules/video_output/ios.m
index 5da6c2382a..03cd0257d4 100644
--- a/modules/video_output/ios.m
+++ b/modules/video_output/ios.m
@@ -97,6 +97,9 @@ vlc_module_end ()
 BOOL _appActive;
 BOOL _placeInvalidated;
 
+UIView *_viewContainer;
+UITapGestureRecognizer *_tapRecognizer;
+
 /* Written from MT, read locked from vout */
 vout_display_place_t _place;
 CGSize _viewSize;
@@ -111,6 +114,7 @@ vlc_module_end ()
 @property GLuint shaderProgram;
 
 - (id)initWithFrameAndVd:(CGRect)frame withVd:(vout_display_t*)vd;
+- (void)cleanAndRelease;
 - (void)createBuffers;
 - (void)destroyBuffers;
 - (BOOL)makeCurrent:(EAGLContext **)previousEaglContext;
@@ -120,14 +124,11 @@ vlc_module_end ()
 - (void)updateVoutCfg:(const vout_display_cfg_t *)cfg 
withVGL:(vout_display_opengl_t *)vgl;
 - (void)getPlaceLocked:(vout_display_place_t *)place;
 - (void)reshape;
-- (void)propagateDimensionsToVoutCore;
 @end
 
 struct vout_display_sys_t
 {
 VLCOpenGLES2VideoView *glESView;
-UIView *viewContainer;
-UITapGestureRecognizer *tapRecognizer;
 
 vlc_gl_t *gl;
 
@@ -176,13 +177,8 @@ static int Open(vlc_object_t *this)
  waitUntilDone:YES];
 if (!sys->glESView) {
 msg_Err(vd, "Creating OpenGL ES 2 view failed");
-goto bailout;
-}
-
-[sys->glESView 
performSelectorOnMainThread:@selector(fetchViewContainer) withObject:nil 
waitUntilDone:YES];
-if (!sys->viewContainer) {
-msg_Err(vd, "Fetching view container failed");
-goto bailout;
+var_Destroy(vd->obj.parent, "ios-eaglcontext");
+return VLC_EGENERIC;
 }
 
 const vlc_fourcc_t *subpicture_chromas;
@@ -253,17 +249,7 @@ static void Close (vlc_object_t *this)
 vout_display_sys_t *sys = vd->sys;
 
 @autoreleasepool {
-if (sys->tapRecognizer) {
-[sys->tapRecognizer.view 
performSelectorOnMainThread:@selector(removeGestureRecognizer:) 
withObject:sys->tapRecognizer waitUntilDone:YES];
-[sys->tapRecognizer release];
-}
-
 var_Destroy (vd, "drawable-nsobject");
-@synchronized(sys->viewContainer) {
-[sys->glESView 
performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil 
waitUntilDone:NO];
-[sys->viewContainer performSelectorOnMainThread:@selector(release) 
withObject:nil waitUntilDone:NO];
-}
-sys->viewContainer = nil;
 
 if (sys->gl != NULL) {
 struct gl_sys *glsys = sys->gl->sys;
@@ -278,7 +264,7 @@ static void Close (vlc_object_t *this)
 vlc_object_release(sys->gl);
 }
 
-[sys->glESView release];
+[sys->glESView cleanAndRelease];
 }
 var_Destroy(vd->obj.parent, "ios-eaglcontext");
 }
@@ -453,67 +439,94 @@ static void GLESSwap(vlc_gl_t *gl)
 [self releaseCurrent:previousEaglContext];
 
 [self createBuffers];
-[self reshape];
+
+if (![self fetchViewContainer])
+{
+vlc_mutex_destroy(&_mutex);
+[_eaglContext release];
+return nil;
+}
 
 return self;
 }
 
-- (void)fetchViewContainer
+- (BOOL)fetchViewContainer
 {
 @try {
 /* get the object we will draw into */
 UIView *viewContainer = var_CreateGetAddress (_voutDisplay, 
"drawable-nsobject");
 if (unlikely(viewContainer == nil)) {
 msg_Err(_voutDisplay, "provided view container is nil");
-return;
+return NO;
 }
 
 if (unlikely(![viewContainer 
respondsToSelector:@selector(isKindOfClass:)])) {
 msg_Err(_voutDisplay, "void pointer not an ObjC object");
-return;
+return NO;
 }
 
 [viewContainer retain];
 
-@synchronized(viewContainer) {
-if (![viewContainer isKindOfClass:[UIView class]]) {
-msg_Err(_voutDisplay, "passed ObjC object not of class 
UIView");
-return;
-}
-
-vout_display_sys_t *sys = _voutDisplay->sys;
+if (![viewContainer isKindOfClass:[UIView class]]) {
+msg_Err(_voutDisplay, "passed ObjC object not of class UIView");
+return NO;
+}
 
-/* This will be released in Close(), on
- * main thread, after we are 

[vlc-commits] vout: ios: don't wait for the MainThead from the Close callback

2018-03-07 Thread Thomas Guillem
vlc | branch: master | Thomas Guillem  | Tue Mar  6 13:14:29 
2018 +0100| [e3a38e5a9c185f68bef8749f2eb093b4fee98b1d] | committer: Thomas 
Guillem

vout: ios: don't wait for the MainThead from the Close callback

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

 modules/video_output/ios.m | 131 +++--
 1 file changed, 80 insertions(+), 51 deletions(-)

diff --git a/modules/video_output/ios.m b/modules/video_output/ios.m
index 5da6c2382a..03cd0257d4 100644
--- a/modules/video_output/ios.m
+++ b/modules/video_output/ios.m
@@ -97,6 +97,9 @@ vlc_module_end ()
 BOOL _appActive;
 BOOL _placeInvalidated;
 
+UIView *_viewContainer;
+UITapGestureRecognizer *_tapRecognizer;
+
 /* Written from MT, read locked from vout */
 vout_display_place_t _place;
 CGSize _viewSize;
@@ -111,6 +114,7 @@ vlc_module_end ()
 @property GLuint shaderProgram;
 
 - (id)initWithFrameAndVd:(CGRect)frame withVd:(vout_display_t*)vd;
+- (void)cleanAndRelease;
 - (void)createBuffers;
 - (void)destroyBuffers;
 - (BOOL)makeCurrent:(EAGLContext **)previousEaglContext;
@@ -120,14 +124,11 @@ vlc_module_end ()
 - (void)updateVoutCfg:(const vout_display_cfg_t *)cfg 
withVGL:(vout_display_opengl_t *)vgl;
 - (void)getPlaceLocked:(vout_display_place_t *)place;
 - (void)reshape;
-- (void)propagateDimensionsToVoutCore;
 @end
 
 struct vout_display_sys_t
 {
 VLCOpenGLES2VideoView *glESView;
-UIView *viewContainer;
-UITapGestureRecognizer *tapRecognizer;
 
 vlc_gl_t *gl;
 
@@ -176,13 +177,8 @@ static int Open(vlc_object_t *this)
  waitUntilDone:YES];
 if (!sys->glESView) {
 msg_Err(vd, "Creating OpenGL ES 2 view failed");
-goto bailout;
-}
-
-[sys->glESView 
performSelectorOnMainThread:@selector(fetchViewContainer) withObject:nil 
waitUntilDone:YES];
-if (!sys->viewContainer) {
-msg_Err(vd, "Fetching view container failed");
-goto bailout;
+var_Destroy(vd->obj.parent, "ios-eaglcontext");
+return VLC_EGENERIC;
 }
 
 const vlc_fourcc_t *subpicture_chromas;
@@ -253,17 +249,7 @@ static void Close (vlc_object_t *this)
 vout_display_sys_t *sys = vd->sys;
 
 @autoreleasepool {
-if (sys->tapRecognizer) {
-[sys->tapRecognizer.view 
performSelectorOnMainThread:@selector(removeGestureRecognizer:) 
withObject:sys->tapRecognizer waitUntilDone:YES];
-[sys->tapRecognizer release];
-}
-
 var_Destroy (vd, "drawable-nsobject");
-@synchronized(sys->viewContainer) {
-[sys->glESView 
performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil 
waitUntilDone:NO];
-[sys->viewContainer performSelectorOnMainThread:@selector(release) 
withObject:nil waitUntilDone:NO];
-}
-sys->viewContainer = nil;
 
 if (sys->gl != NULL) {
 struct gl_sys *glsys = sys->gl->sys;
@@ -278,7 +264,7 @@ static void Close (vlc_object_t *this)
 vlc_object_release(sys->gl);
 }
 
-[sys->glESView release];
+[sys->glESView cleanAndRelease];
 }
 var_Destroy(vd->obj.parent, "ios-eaglcontext");
 }
@@ -453,67 +439,94 @@ static void GLESSwap(vlc_gl_t *gl)
 [self releaseCurrent:previousEaglContext];
 
 [self createBuffers];
-[self reshape];
+
+if (![self fetchViewContainer])
+{
+vlc_mutex_destroy(&_mutex);
+[_eaglContext release];
+return nil;
+}
 
 return self;
 }
 
-- (void)fetchViewContainer
+- (BOOL)fetchViewContainer
 {
 @try {
 /* get the object we will draw into */
 UIView *viewContainer = var_CreateGetAddress (_voutDisplay, 
"drawable-nsobject");
 if (unlikely(viewContainer == nil)) {
 msg_Err(_voutDisplay, "provided view container is nil");
-return;
+return NO;
 }
 
 if (unlikely(![viewContainer 
respondsToSelector:@selector(isKindOfClass:)])) {
 msg_Err(_voutDisplay, "void pointer not an ObjC object");
-return;
+return NO;
 }
 
 [viewContainer retain];
 
-@synchronized(viewContainer) {
-if (![viewContainer isKindOfClass:[UIView class]]) {
-msg_Err(_voutDisplay, "passed ObjC object not of class 
UIView");
-return;
-}
-
-vout_display_sys_t *sys = _voutDisplay->sys;
+if (![viewContainer isKindOfClass:[UIView class]]) {
+msg_Err(_voutDisplay, "passed ObjC object not of class UIView");
+return NO;
+}
 
-/* This will be released in Close(), on
- * main thread, after we are done using it. */
-sys->viewContainer = viewContainer;
+/* This will be released in Close(), on
+ * main