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

Steve Lhomme robux4 at ycbcr.xyz
Wed Sep 18 16:13:18 CEST 2019


The decoder device ("dec-dev") should be tied to the lifecyle of the window.
It won't change during the lifetime of the window enabled state.

This decoder device is stored in the vout private structure.

Before this patch the decoder device was created each time a display module was
created.
---
 include/vlc_vout_display.h       |  2 +-
 modules/video_output/splitter.c  |  5 +++--
 src/video_output/display.c       | 17 +++++------------
 src/video_output/video_output.c  | 10 ++++++++++
 src/video_output/vout_internal.h |  2 ++
 src/video_output/vout_wrapper.c  |  4 ++--
 6 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index 80f813ba873..c7834b463b7 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -308,7 +308,7 @@ struct vout_display_t {
  */
 VLC_API
 vout_display_t *vout_display_New(vlc_object_t *, const video_format_t *,
-    const vout_display_cfg_t *, const char *module,
+    const vout_display_cfg_t *, vlc_decoder_device *, const char *module,
     const vout_display_owner_t *);
 
 /**
diff --git a/modules/video_output/splitter.c b/modules/video_output/splitter.c
index 401de4853d6..c2e56e545e1 100644
--- a/modules/video_output/splitter.c
+++ b/modules/video_output/splitter.c
@@ -223,9 +223,10 @@ static vout_window_t *video_splitter_CreateWindow(vlc_object_t *obj,
 static vout_display_t *vlc_vidsplit_CreateDisplay(vlc_object_t *obj,
     const video_format_t *restrict source,
     const vout_display_cfg_t *restrict cfg,
+    vlc_decoder_device *dec_device,
     const char *name)
 {
-    return vout_display_New(obj, source, cfg, name, NULL);
+    return vout_display_New(obj, source, cfg, dec_device, name, NULL);
 }
 
 static int vlc_vidsplit_Open(vout_display_t *vd,
@@ -299,7 +300,7 @@ static int vlc_vidsplit_Open(vout_display_t *vd,
 
         vdcfg.window = part->window;
         display = vlc_vidsplit_CreateDisplay(obj, &output->fmt, &vdcfg,
-                                             modname);
+                                             ctx->device, modname);
         if (display == NULL) {
             vout_window_Disable(part->window);
             vout_window_Delete(part->window);
diff --git a/src/video_output/display.c b/src/video_output/display.c
index e95e9539f17..97603317d17 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -286,9 +286,6 @@ typedef struct {
     atomic_bool reset_pictures;
 #endif
     picture_pool_t *pool;
-
-    /* temporary: must come from decoder module */
-    vlc_video_context video_context;
 } vout_display_priv_t;
 
 static const struct filter_video_callbacks vout_display_filter_cbs = {
@@ -733,6 +730,7 @@ void vout_SetDisplayViewpoint(vout_display_t *vd,
 vout_display_t *vout_display_New(vlc_object_t *parent,
                                  const video_format_t *source,
                                  const vout_display_cfg_t *cfg,
+                                 vlc_decoder_device *dec_device,
                                  const char *module,
                                  const vout_display_owner_t *owner)
 {
@@ -772,13 +770,13 @@ vout_display_t *vout_display_New(vlc_object_t *parent,
     if (owner)
         vd->owner = *owner;
 
-    osys->video_context.device = vlc_decoder_device_Create(osys->cfg.window);
-    vlc_video_context *video_context = osys->video_context.device ?
-        &osys->video_context : NULL;
+    vlc_video_context fake_vctx = {
+        .device = dec_device,
+    };
 
     if (vlc_module_load(vd, "vout display", module, module && *module != '\0',
                         vout_display_start, vd, &osys->cfg, &vd->fmt,
-                        video_context) == NULL)
+                        &fake_vctx) == NULL)
         goto error;
 
 #if defined(__OS2__)
@@ -803,8 +801,6 @@ vout_display_t *vout_display_New(vlc_object_t *parent,
     return vd;
 error:
     video_format_Clean(&vd->source);
-    if (osys->video_context.device)
-        vlc_decoder_device_Release(osys->video_context.device);
     vlc_object_delete(vd);
     return NULL;
 }
@@ -823,9 +819,6 @@ void vout_display_Delete(vout_display_t *vd)
         vd->close(vd);
     vlc_objres_clear(VLC_OBJECT(vd));
 
-    if (osys->video_context.device)
-        vlc_decoder_device_Release(osys->video_context.device);
-
     video_format_Clean(&vd->source);
     video_format_Clean(&vd->fmt);
     vlc_object_delete(vd);
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 6dfddaad33a..a1dbcd89196 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,8 @@ void vout_Stop(vout_thread_t *vout)
         vout_StopDisplay(vout);
 
     vlc_mutex_lock(&sys->window_lock);
+    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;
@@ -1906,6 +1909,8 @@ int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
             goto error;
         }
         sys->window_enabled = true;
+
+        sys->dec_device = vlc_decoder_device_Create(sys->display_cfg.window);
     } else
         vout_UpdateWindowSizeLocked(vout);
 
@@ -1921,6 +1926,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 a48637a714c..c827b80e583 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;
diff --git a/src/video_output/vout_wrapper.c b/src/video_output/vout_wrapper.c
index 9ac6e2eab08..80907bcac7d 100644
--- a/src/video_output/vout_wrapper.c
+++ b/src/video_output/vout_wrapper.c
@@ -72,8 +72,8 @@ vout_display_t *vout_OpenWrapper(vout_thread_t *vout,
     else
         modlist = "splitter,none";
 
-    vd = vout_display_New(VLC_OBJECT(vout), &sys->original, cfg, modlist,
-                          &owner);
+    vd = vout_display_New(VLC_OBJECT(vout), &sys->original, cfg,
+                          sys->dec_device, modlist, &owner);
     free(modlistbuf);
 
     if (vd == NULL)
-- 
2.17.1



More information about the vlc-devel mailing list