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

Steve Lhomme robux4 at ycbcr.xyz
Fri Sep 20 16:28:32 CEST 2019


The decoder device ("dec-dev") should be tied to the lifecyle of the active/enabled
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  |  4 ++--
 src/video_output/display.c       | 17 +++++------------
 src/video_output/video_output.c  | 17 +++++++++++++++++
 src/video_output/vout_internal.h |  2 ++
 src/video_output/vout_wrapper.c  |  4 ++--
 6 files changed, 29 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 be4d7916e81..4cebe79ebbb 100644
--- a/modules/video_output/splitter.c
+++ b/modules/video_output/splitter.c
@@ -290,7 +290,7 @@ static int vlc_vidsplit_Open(vout_display_t *vd,
 
         vdcfg.window = part->window;
         vout_display_t *display = vout_display_New(obj, &output->fmt, &vdcfg,
-                                                   modname, NULL);
+                                                   ctx->device, modname, NULL);
         if (display == NULL) {
             vout_window_Disable(part->window);
             vout_window_Delete(part->window);
@@ -310,7 +310,7 @@ static int vlc_vidsplit_Open(vout_display_t *vd,
     vd->display = vlc_vidsplit_Display;
     vd->control = vlc_vidsplit_Control;
     vd->close = vlc_vidsplit_Close;
-    (void) fmtp; (void) ctx;
+    (void) fmtp;
     return VLC_SUCCESS;
 }
 
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..cf2132a089c 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);
 
@@ -1906,6 +1915,9 @@ int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
             goto error;
         }
         sys->window_enabled = true;
+
+        assert(sys->dec_device == NULL);
+        sys->dec_device = vlc_decoder_device_Create(sys->display_cfg.window);
     } else
         vout_UpdateWindowSizeLocked(vout);
 
@@ -1921,6 +1933,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..ee24cd9153f 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