[vlc-commits] [Git][videolan/vlc][master] 4 commits: resource: change vout state argument

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Dec 11 15:53:24 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
d4d6ab6b by Thomas Guillem at 2021-12-11T15:38:21+00:00
resource: change vout state argument

Move it from bool to an enum, mainly because
input_resource_RequestVout() can notify both events: stopped or started.

No functional changes.

- - - - -
6d8848b2 by Thomas Guillem at 2021-12-11T15:38:21+00:00
resource: notify that the vout stopped if a request fails

- - - - -
32a972f9 by Thomas Guillem at 2021-12-11T15:38:21+00:00
decoder: notify that the vout stopped in case of error

In case of error happening midstream when the vout was already started.

- - - - -
a7c99d05 by Thomas Guillem at 2021-12-11T15:38:21+00:00
vout: always stop the vout if vout_Request() fails

The 2 vout_Request users were already stopping the vout in that case.

This fixes an inconsistency when vout_Request() could return an error
but the user had no way to know if the vout was started or stopped.

Fixes #26345

- - - - -


4 changed files:

- src/input/decoder.c
- src/input/resource.c
- src/input/resource.h
- src/video_output/video_output.c


Changes:

=====================================
src/input/decoder.c
=====================================
@@ -474,17 +474,20 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec, vlc_video_context *
         .vout = p_owner->p_vout, .clock = p_owner->p_clock, .fmt = &p_dec->fmt_out.video,
         .mouse_event = MouseEvent, .mouse_opaque = p_dec,
     };
-    bool has_started;
+    enum input_resource_vout_state vout_state;
     vout_thread_t *p_vout =
         input_resource_RequestVout(p_owner->p_resource, vctx, &cfg, NULL,
-                                   &has_started);
+                                   &vout_state);
     if (p_vout != NULL)
     {
+        assert(vout_state == INPUT_RESOURCE_VOUT_NOTCHANGED ||
+               vout_state == INPUT_RESOURCE_VOUT_STARTED);
+
         vlc_mutex_lock( &p_owner->lock );
         p_owner->vout_started = true;
         vlc_mutex_unlock( &p_owner->lock );
 
-        if (has_started)
+        if (vout_state == INPUT_RESOURCE_VOUT_STARTED)
         {
             vlc_fifo_Lock( p_owner->p_fifo );
             p_owner->reset_out_state = true;
@@ -494,6 +497,14 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec, vlc_video_context *
         }
         return 0;
     }
+    else
+    {
+        assert(vout_state == INPUT_RESOURCE_VOUT_NOTCHANGED ||
+               vout_state == INPUT_RESOURCE_VOUT_STOPPED);
+
+        if (vout_state == INPUT_RESOURCE_VOUT_STOPPED)
+            decoder_Notify(p_owner, on_vout_stopped, p_owner->p_vout);
+    }
 
 error:
     /* Clean fmt and vctx to trigger a new vout creation on the next update
@@ -1999,9 +2010,9 @@ static void DeleteDecoder( vlc_input_decoder_t *p_owner )
                  * last reference is needed for notify callbacks */
                 vout_Hold(vout);
 
-                bool has_stopped;
-                input_resource_PutVout(p_owner->p_resource, vout, &has_stopped);
-                if (has_stopped)
+                enum input_resource_vout_state vout_state;
+                input_resource_PutVout(p_owner->p_resource, vout, &vout_state);
+                if (vout_state == INPUT_RESOURCE_VOUT_STOPPED)
                     decoder_Notify(p_owner, on_vout_stopped, vout);
 
                 vout_Release(vout);


=====================================
src/input/resource.c
=====================================
@@ -362,14 +362,16 @@ void input_resource_SetInput( input_resource_t *p_resource, input_thread_t *p_in
 }
 
 static void input_resource_PutVoutLocked(input_resource_t *p_resource,
-                                         vout_thread_t *vout, bool *has_stopped)
+                                         vout_thread_t *vout,
+                                         enum input_resource_vout_state *vout_state)
 {
     assert(vout != NULL);
     struct vout_resource *vout_rsc = resource_GetVoutRsc(p_resource, vout);
     assert(vout_rsc != NULL);
 
-    if (has_stopped != NULL)
-        *has_stopped = vout_rsc->started;
+    if (vout_state != NULL)
+        *vout_state = vout_rsc->started ? INPUT_RESOURCE_VOUT_STOPPED
+                                        : INPUT_RESOURCE_VOUT_NOTCHANGED;
 
     if (vout_rsc->started)
     {
@@ -398,10 +400,11 @@ static void input_resource_PutVoutLocked(input_resource_t *p_resource,
 }
 
 void input_resource_PutVout(input_resource_t *p_resource,
-                                   vout_thread_t *vout, bool *stopped)
+                            vout_thread_t *vout,
+                            enum input_resource_vout_state *vout_state)
 {
     vlc_mutex_lock( &p_resource->lock );
-    input_resource_PutVoutLocked( p_resource, vout, stopped );
+    input_resource_PutVoutLocked( p_resource, vout, vout_state );
     vlc_mutex_unlock( &p_resource->lock );
 }
 
@@ -451,13 +454,13 @@ vout_thread_t *input_resource_RequestVout(input_resource_t *p_resource,
                                           vlc_video_context *vctx,
                                           const vout_configuration_t *cfg,
                                           enum vlc_vout_order *order,
-                                          bool *has_started)
+                                          enum input_resource_vout_state *vout_state)
 {
     vlc_mutex_lock( &p_resource->lock );
     struct vout_resource *vout_rsc = NULL;
 
-    if (has_started != NULL)
-        *has_started = false;
+    if (vout_state != NULL)
+        *vout_state = INPUT_RESOURCE_VOUT_NOTCHANGED;
 
     vout_configuration_t dcfg = *cfg;
     if (dcfg.vout == NULL)
@@ -503,14 +506,18 @@ vout_thread_t *input_resource_RequestVout(input_resource_t *p_resource,
     }
 
     if (vout_Request(&dcfg, vctx, p_resource->p_input)) {
+        if (vout_rsc->started && vout_state != NULL)
+            *vout_state = INPUT_RESOURCE_VOUT_STOPPED;
+
+        vout_rsc->started = false;
         input_resource_PutVoutLocked(p_resource, dcfg.vout, NULL);
         vlc_mutex_unlock(&p_resource->lock);
         return NULL;
     }
 
     vout_rsc->started = true;
-    if (has_started != NULL)
-        *has_started = true;
+    if (vout_state != NULL)
+        *vout_state = INPUT_RESOURCE_VOUT_STARTED;
 
     DisplayVoutTitle(p_resource, cfg->vout, &vout_rsc->psz_prev_title);
 


=====================================
src/input/resource.h
=====================================
@@ -27,6 +27,13 @@
 #include <vlc_mouse.h>
 #include "../video_output/vout_internal.h"
 
+enum input_resource_vout_state
+{
+    INPUT_RESOURCE_VOUT_NOTCHANGED,
+    INPUT_RESOURCE_VOUT_STARTED,
+    INPUT_RESOURCE_VOUT_STOPPED,
+};
+
 /**
  * This function set the associated input.
  */
@@ -41,8 +48,9 @@ void input_resource_PutSout(input_resource_t *, sout_stream_t *);
 vout_thread_t *input_resource_RequestVout(input_resource_t *, vlc_video_context *,
                                          const vout_configuration_t *,
                                          enum vlc_vout_order *order,
-                                         bool *has_started);
-void input_resource_PutVout(input_resource_t *, vout_thread_t *, bool *has_stopped);
+                                         enum input_resource_vout_state *vout_state);
+void input_resource_PutVout(input_resource_t *, vout_thread_t *,
+                            enum input_resource_vout_state *vout_state);
 
 /**
  * This function returns one of the current vout if any.


=====================================
src/video_output/video_output.c
=====================================
@@ -2176,8 +2176,7 @@ int vout_Request(const vout_configuration_t *cfg, vlc_video_context *vctx, input
     assert(cfg->clock != NULL);
 
     if (!VoutCheckFormat(cfg->fmt))
-        /* don't stop the display and keep sys->original */
-        return -1;
+        goto error_stop_display;
 
     video_format_t original;
     VoutFixFormat(&original, cfg->fmt);
@@ -2197,7 +2196,7 @@ int vout_Request(const vout_configuration_t *cfg, vlc_video_context *vctx, input
         msg_Err(cfg->vout, "failed to enable window");
         video_format_Clean(&original);
         vlc_mutex_unlock(&sys->window_lock);
-        return -1;
+        goto error_stop_display;
     }
     vlc_mutex_unlock(&sys->window_lock);
 
@@ -2231,6 +2230,11 @@ int vout_Request(const vout_configuration_t *cfg, vlc_video_context *vctx, input
         spu_Attach(sys->spu, input);
     vout_IntfReinit(cfg->vout);
     return 0;
+
+error_stop_display:
+    if (sys->display != NULL)
+        vout_StopDisplay(cfg->vout);
+    return -1;
 }
 
 vlc_decoder_device *vout_GetDevice(vout_thread_t *vout)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f8e90ae78d59f73866988b8c71aa049a0d209682...a7c99d05938a86e830498045aa41e4b213a7eb45

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f8e90ae78d59f73866988b8c71aa049a0d209682...a7c99d05938a86e830498045aa41e4b213a7eb45
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list