[vlc-devel] [PATCH 6/6] VLCOpenGLES2VideoView: handle state change

Thomas Guillem thomas at gllm.fr
Fri Feb 5 09:24:14 UTC 2021



On Fri, Feb 5, 2021, at 10:01, Alexandre Janniaux wrote:
> Avoid making vlc_gl_MakeCurrent fail because the application would be
> be moved into the background. Since the rendering is now disabled
> directly by the vout_window, some parts of the observers on
> NSNotificationCenter are now useless. What's left might or might not be
> useless yet, because of the initial startup where the interaction with
> the display is needed to create it anyway, so it's currently kept with a
> condition variable to wait the application to become active instead of
> bailing out.
> ---
>  .../apple/VLCOpenGLES2VideoView.m             | 34 +++++++------------
>  1 file changed, 12 insertions(+), 22 deletions(-)
> 
> diff --git a/modules/video_output/apple/VLCOpenGLES2VideoView.m 
> b/modules/video_output/apple/VLCOpenGLES2VideoView.m
> index 0d617d30b6..394fb513ca 100644
> --- a/modules/video_output/apple/VLCOpenGLES2VideoView.m
> +++ b/modules/video_output/apple/VLCOpenGLES2VideoView.m
> @@ -58,6 +58,7 @@
>      CAEAGLLayer *_layer;
>  
>      vlc_mutex_t _mutex;
> +    vlc_cond_t  _cond;

Please user a better variable name. It's like doing int _int or double _double;
This cond is used to wait for an active display? So the name should mention it.

>      vlc_cond_t  _gl_attached_wait;
>      BOOL        _gl_attached;
>  
> @@ -152,6 +153,7 @@ static void Close(vlc_gl_t *gl)
>  
>      vlc_mutex_init(&_mutex);
>      vlc_cond_init(&_gl_attached_wait);
> +    vlc_cond_init(&_cond);
>  
>      /* The following creates a new OpenGL ES context with the API 
> version we
>       * need. If there is already an active context created by another 
> OpenGL
> @@ -185,14 +187,6 @@ static void Close(vlc_gl_t *gl)
>                                               
> selector:@selector(applicationStateChanged:)
>                                                   
> name:UIApplicationWillEnterForegroundNotification
>                                                 object:nil];
> -    [[NSNotificationCenter defaultCenter] addObserver:self
> -                                             
> selector:@selector(applicationStateChanged:)
> -                                                 
> name:UIApplicationDidEnterBackgroundNotification
> -                                               object:nil];
> -    [[NSNotificationCenter defaultCenter] addObserver:self
> -                                             
> selector:@selector(applicationStateChanged:)
> -                                                 
> name:UIApplicationWillResignActiveNotification
> -                                               object:nil];
>      [[NSNotificationCenter defaultCenter] addObserver:self
>                                               
> selector:@selector(applicationStateChanged:)
>                                                   
> name:UIApplicationDidBecomeActiveNotification
> @@ -328,14 +322,13 @@ static void Close(vlc_gl_t *gl)
>  
>  - (BOOL)makeCurrent
>  {
> +    assert(![NSThread isMainThread]);
> +
>      vlc_mutex_lock(&_mutex);
>      assert(!_gl_attached);
>  
> -    if (unlikely(!_appActive))
> -    {
> -        vlc_mutex_unlock(&_mutex);
> -        return NO;
> -    }
> +    while (unlikely(!_appActive))
> +        vlc_cond_wait(&_cond, &_mutex);
>  
>      assert(_eaglEnabled);
>      _previousEaglContext = [EAGLContext currentContext];
> @@ -358,8 +351,6 @@ static void Close(vlc_gl_t *gl)
>  
>      _gl_attached = YES;
>  
> -    vlc_mutex_unlock(&_mutex);
> -
>      if (resetBuffers && ![self doResetBuffers:_gl])
>      {
>          [self releaseCurrent];
> @@ -370,11 +361,13 @@ static void Close(vlc_gl_t *gl)
>  
>  - (void)releaseCurrent
>  {
> -    vlc_mutex_lock(&_mutex);
> +    vlc_mutex_assert(&_mutex);
> +
>      assert(_gl_attached);
>      _gl_attached = NO;
>      [EAGLContext setCurrentContext:_previousEaglContext];
>      _previousEaglContext = nil;
> +
>      vlc_mutex_unlock(&_mutex);
>      vlc_cond_signal(&_gl_attached_wait);
>  }
> @@ -408,9 +401,7 @@ static void Close(vlc_gl_t *gl)
>  {
>      vlc_mutex_lock(&_mutex);
>  
> -    if ([[notification name] 
> isEqualToString:UIApplicationWillResignActiveNotification])
> -        _appActive = NO;
> -    else if ([[notification name] 
> isEqualToString:UIApplicationDidEnterBackgroundNotification])
> +    if ([[notification name] 
> isEqualToString:UIApplicationDidEnterBackgroundNotification])
>      {
>          _appActive = NO;
>  
> @@ -428,13 +419,12 @@ static void Close(vlc_gl_t *gl)
>          }
>      }
>      else if ([[notification name] 
> isEqualToString:UIApplicationWillEnterForegroundNotification])
> +    {
>          _eaglEnabled = YES;
> -    else
> -    {
> -        assert([[notification name] 
> isEqualToString:UIApplicationDidBecomeActiveNotification]);
>          _appActive = YES;
>      }
>  
> +    vlc_cond_broadcast(&_cond);
>      vlc_mutex_unlock(&_mutex);
>  }
>  
> -- 
> 2.28.0
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list