[vlc-devel] [PATCH 02/31] vout: create/release the decoder device when the window is enabled/disabled

Steve Lhomme robux4 at ycbcr.xyz
Mon Sep 23 17:01:07 CEST 2019


Only create one if the vout_Request() caller provided a recipient for the held
decoder device pointer.

The decoder device ("dec-dev") should be tied to the lifecyle of the active/enabled
window. The vout and window won't change with the decoder device exists. When the
window is disabled the decoder device (also decoder hint) should not be used
anymore until the window is enabled again.

This decoder device is stored in the vout private structure. As the vout thread
is the one to know about the window and is cached in the decoder resources if
needed.
---
 src/audio_output/filters.c       |  2 +-
 src/input/resource.c             |  2 +-
 src/video_output/video_output.c  | 29 ++++++++++++++++++++++++++++-
 src/video_output/vout_internal.h |  6 +++++-
 4 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index 6a37c8e8ab7..dad467b44f0 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -395,7 +395,7 @@ vout_thread_t *aout_filter_GetVout(filter_t *filter, const video_format_t *fmt)
 
     video_format_AdjustColorSpace(&adj_fmt);
 
-    if (vout_Request(&cfg, NULL)) {
+    if (vout_Request(&cfg, NULL, NULL)) {
         vout_Close(vout);
         vout = NULL;
     }
diff --git a/src/input/resource.c b/src/input/resource.c
index b4ffbd68ce3..46f2f339ab8 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -425,7 +425,7 @@ vout_thread_t *input_resource_GetVout(input_resource_t *p_resource,
     }
 #endif
 
-    if (vout_Request(cfg, p_resource->p_input)) {
+    if (vout_Request(cfg, NULL, p_resource->p_input)) {
         input_resource_PutVoutLocked(p_resource, cfg->vout, false);
         vlc_mutex_unlock(&p_resource->lock);
         return NULL;
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 6dfddaad33a..3e0c6fb0843 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -49,6 +49,7 @@
 #include <vlc_vout_osd.h>
 #include <vlc_image.h>
 #include <vlc_plugin.h>
+#include <vlc_codec.h>
 
 #include <libvlc.h>
 #include "vout_internal.h"
@@ -1673,6 +1674,11 @@ void vout_Stop(vout_thread_t *vout)
         vout_StopDisplay(vout);
 
     vlc_mutex_lock(&sys->window_lock);
+    if (sys->dec_device)
+    {
+        vlc_decoder_device_Release(sys->dec_device);
+        sys->dec_device = NULL;
+    }
     if (sys->window_enabled) {
         vout_window_Disable(sys->display_cfg.window);
         sys->window_enabled = false;
@@ -1720,6 +1726,9 @@ void vout_Release(vout_thread_t *vout)
     vlc_mutex_destroy(&vout->p->window_lock);
     vlc_mutex_destroy(&vout->p->filter.lock);
 
+    if (sys->dec_device)
+        vlc_decoder_device_Release(sys->dec_device);
+
     assert(!sys->window_enabled);
     vout_display_window_Delete(sys->display_cfg.window);
 
@@ -1851,7 +1860,8 @@ vout_thread_t *vout_Hold(vout_thread_t *vout)
     return vout;
 }
 
-int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
+int vout_Request(const vout_configuration_t *cfg, vlc_decoder_device **pp_dec_dev,
+                 input_thread_t *input)
 {
     vout_thread_t *vout = cfg->vout;
     vout_thread_sys_t *sys = vout->p;
@@ -1861,6 +1871,10 @@ int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
     assert(cfg->fmt != NULL);
     assert(cfg->clock != NULL);
 
+    if (pp_dec_dev)
+        // don't return a decoder device by default, we need a proper reference
+        *pp_dec_dev = NULL;
+
     if (!VoutCheckFormat(cfg->fmt))
         return -1;
 
@@ -1914,6 +1928,14 @@ int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
     sys->clock = cfg->clock;
     sys->delay = 0;
 
+    if (pp_dec_dev)
+    {
+        assert(sys->window_enabled);
+        if (sys->dec_device == NULL)
+            sys->dec_device = vlc_decoder_device_Create(sys->display_cfg.window);
+        *pp_dec_dev = sys->dec_device ? vlc_decoder_device_Hold( sys->dec_device ) : NULL;
+    }
+
     vlc_mutex_unlock(&sys->window_lock);
 
     if (vout_Start(vout, cfg))
@@ -1921,6 +1943,11 @@ int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
         vlc_mutex_lock(&sys->window_lock);
         vout_window_Disable(sys->display_cfg.window);
         sys->window_enabled = false;
+        if (sys->dec_device)
+        {
+            vlc_decoder_device_Release(sys->dec_device);
+            sys->dec_device = NULL;
+        }
         vlc_mutex_unlock(&sys->window_lock);
         goto error;
     }
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 29f2144f82b..1f88997779c 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -179,6 +179,8 @@ struct vout_thread_sys_t
     vout_display_t *display;
     vlc_mutex_t     display_lock;
 
+    vlc_decoder_device *dec_device;
+
     picture_pool_t  *private_pool;
     picture_pool_t  *display_pool;
     picture_pool_t  *decoder_pool;
@@ -205,11 +207,13 @@ vout_thread_t *vout_CreateDummy(vlc_object_t *obj) VLC_USED;
  * You can release the returned value either by vout_Request() or vout_Close().
  *
  * \param cfg the video configuration requested.
+ * \param dec_dev pointer to receive the decoder device reference to use with the vout or NULL
  * \param input used to get attachments for spu filters
  * \retval 0 on success
  * \retval -1 on error
  */
-int vout_Request(const vout_configuration_t *cfg, input_thread_t *input);
+int vout_Request(const vout_configuration_t *cfg, vlc_decoder_device **dec_dev,
+                 input_thread_t *input);
 
 /**
  * Disables a vout.
-- 
2.17.1



More information about the vlc-devel mailing list