[vlc-devel] [PATCH 01/42] video_output: add vout_GetDevice to get the vout decoder device on demand

Steve Lhomme robux4 at ycbcr.xyz
Wed Oct 16 16:58:36 CEST 2019


Only a few decoders will request it.

A decoder device can only be created if the vout has an enabled window.

The caller receives a reference to the decoder device or NULL.
---
 src/video_output/video_output.c  | 31 ++++++++++++++++++++++++++++---
 src/video_output/vout_internal.h | 10 ++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 060768e1ab6..76e415feee7 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"
@@ -1744,6 +1745,11 @@ static void vout_DisableWindow(vout_thread_t *vout)
 {
     vout_thread_sys_t *sys = vout->p;
     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;
@@ -1802,6 +1808,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);
 
@@ -1933,7 +1942,7 @@ vout_thread_t *vout_Hold(vout_thread_t *vout)
     return vout;
 }
 
-static int vout_EnableWindow(const vout_configuration_t *cfg)
+static int vout_EnableWindow(const vout_configuration_t *cfg, vlc_decoder_device **pp_dec_device)
 {
     vout_thread_t *vout = cfg->vout;
     vout_thread_sys_t *sys = vout->p;
@@ -1956,6 +1965,8 @@ static int vout_EnableWindow(const vout_configuration_t *cfg)
         if (cfg->dpb_size <= sys->dpb_size) {
             video_format_Clean(&original);
             /* It is assumed that the SPU input matches input already. */
+            if (pp_dec_device)
+                *pp_dec_device = sys->dec_device ? vlc_decoder_device_Hold( sys->dec_device ) : NULL;
             return 0;
         }
         msg_Warn(vout, "DPB need to be increased");
@@ -1992,8 +2003,14 @@ static int vout_EnableWindow(const vout_configuration_t *cfg)
         sys->window_enabled = true;
     } else
         vout_UpdateWindowSizeLocked(vout);
-    vlc_mutex_unlock(&sys->window_lock);
 
+    if (pp_dec_device)
+    {
+        if (sys->dec_device == NULL)
+            sys->dec_device = vlc_decoder_device_Create(sys->display_cfg.window);
+        *pp_dec_device = sys->dec_device ? vlc_decoder_device_Hold( sys->dec_device ) : NULL;
+    }
+    vlc_mutex_unlock(&sys->window_lock);
     return 0;
 }
 
@@ -2002,7 +2019,7 @@ int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
     vout_thread_t *vout = cfg->vout;
     vout_thread_sys_t *sys = vout->p;
 
-    if (vout_EnableWindow(cfg) != 0)
+    if (vout_EnableWindow(cfg, NULL) != 0)
         return -1;
 
     sys->delay = 0;
@@ -2028,3 +2045,11 @@ int vout_Request(const vout_configuration_t *cfg, input_thread_t *input)
     vout_IntfReinit(vout);
     return 0;
 }
+
+vlc_decoder_device *vout_GetDevice(const vout_configuration_t *cfg)
+{
+    vlc_decoder_device *dec_device = NULL;
+    if (vout_EnableWindow(cfg, &dec_device) != 0)
+        return NULL;
+    return dec_device;
+}
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 29f2144f82b..30f79794e12 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -173,6 +173,7 @@ struct vout_thread_sys_t
     /* Video output window */
     bool            window_enabled;
     vlc_mutex_t     window_lock;
+    vlc_decoder_device *dec_device;
 
     /* Video output display */
     vout_display_cfg_t display_cfg;
@@ -195,6 +196,14 @@ vout_thread_t *vout_Create(vlc_object_t *obj) VLC_USED;
 
 vout_thread_t *vout_CreateDummy(vlc_object_t *obj) VLC_USED;
 
+/**
+ * Setup the vout for the given configuration and get an associated decoder device.
+ *
+ * \param cfg the video configuration requested.
+ * \return pointer to a decoder device reference to use with the vout or NULL
+ */
+vlc_decoder_device *vout_GetDevice(const vout_configuration_t *cfg);
+
 /**
  * Returns a suitable vout or release the given one.
  *
@@ -206,6 +215,7 @@ vout_thread_t *vout_CreateDummy(vlc_object_t *obj) VLC_USED;
  *
  * \param cfg the video configuration requested.
  * \param input used to get attachments for spu filters
+ * \param dec_dev pointer to receive the decoder device reference to use with the vout or NULL
  * \retval 0 on success
  * \retval -1 on error
  */
-- 
2.17.1



More information about the vlc-devel mailing list