[vlc-devel] [PATCH 4/4] core: vout: ensure that the dec-dev matches the input_thread_t one

Thomas Guillem thomas at gllm.fr
Thu Jan 16 17:41:37 CET 2020


This commit ensures that the "dec-dev" option can be configured from the
input_thread_t. It will allow to setup the hw decoder for a media via
input_item_AddOption() and libvlc_media_add_option() instead of globally.
Indeed, the vout can be created directly from the player, in that case, the
vout can't inherit options from any input_thread_t.
---
 src/video_output/video_output.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 3d33f329fb5..14337df3669 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -73,6 +73,9 @@
 /* Better be in advance when awakening than late... */
 #define VOUT_MWAIT_TOLERANCE VLC_TICK_FROM_MS(4)
 
+const char *
+vlc_decoder_device_GetName(vlc_decoder_device *device);
+
 /* */
 static bool VoutCheckFormat(const video_format_t *src)
 {
@@ -1999,6 +2002,7 @@ int vout_ChangeSource( vout_thread_t *vout, const video_format_t *original )
 }
 
 static int vout_EnableWindow(vout_thread_t *vout, const video_format_t *original,
+                             input_thread_t *input,
                              vlc_decoder_device **pp_dec_device)
 {
     vout_thread_sys_t *sys = vout->p;
@@ -2032,8 +2036,20 @@ static int vout_EnableWindow(vout_thread_t *vout, const video_format_t *original
 
     if (pp_dec_device)
     {
+        char *name = input ? var_InheritString(input, "dec-dev") : NULL;
+        if (name != NULL && sys->dec_device != NULL
+         && strcmp(name, vlc_decoder_device_GetName(sys->dec_device)) != 0)
+        {
+            /* The new input requested a different decoder device than the one
+             * setup by the vout */
+            vlc_decoder_device_Release(sys->dec_device);
+            sys->dec_device = NULL;
+        }
+
         if (sys->dec_device == NULL)
-            sys->dec_device = vlc_decoder_device_Create(&vout->obj, NULL, sys->display_cfg.window);
+            sys->dec_device = vlc_decoder_device_Create(&vout->obj, name, sys->display_cfg.window);
+        free(name);
+
         *pp_dec_device = sys->dec_device ? vlc_decoder_device_Hold( sys->dec_device ) : NULL;
     }
     vlc_mutex_unlock(&sys->window_lock);
@@ -2061,7 +2077,7 @@ int vout_Request(const vout_configuration_t *cfg, vlc_video_context *vctx, input
         return 0;
     }
 
-    if (vout_EnableWindow(vout, &original, NULL) != 0)
+    if (vout_EnableWindow(vout, &original, input, NULL) != 0)
     {
         /* the window was not enabled, nor the display started */
         msg_Err(vout, "failed to enable window");
@@ -2113,7 +2129,7 @@ vlc_decoder_device *vout_GetDevice(const vout_device_configuration_t *cfg,
     video_format_t original;
     VoutFixFormat(&original, cfg->fmt);
 
-    int res = vout_EnableWindow(cfg->vout, &original, &dec_device);
+    int res = vout_EnableWindow(cfg->vout, &original, input, &dec_device);
     video_format_Clean(&original);
     if (res != 0)
         return NULL;
-- 
2.20.1



More information about the vlc-devel mailing list