[vlc-devel] [PATCH v3 03/14] libvlc: add a way to disable the GPU callback engine

Steve Lhomme robux4 at ycbcr.xyz
Thu Feb 13 16:44:44 CET 2020


If set to none we fallback to normal playback into a custom window.

We need the variable in the regular player so the variable can be read even
when desktop VLC.
---
 include/vlc/libvlc_media_player.h |  2 ++
 lib/media_player.c                | 10 ++++++++++
 modules/video_chroma/d3d11_fmt.c  | 12 +++++++++---
 modules/video_chroma/d3d9_fmt.c   | 13 ++++++++++---
 modules/video_output/vgl.c        |  5 +++++
 src/libvlc.c                      |  2 ++
 6 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index aa4be734181..5e0255a10ac 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -679,6 +679,8 @@ typedef void (*libvlc_video_frameMetadata_cb)(void* opaque, libvlc_video_metadat
  * can be passed to @a libvlc_video_set_output_callbacks
  */
 typedef enum libvlc_video_engine_t {
+    /** Disable rendering engine */
+    libvlc_video_engine_disable,
     libvlc_video_engine_opengl,
     libvlc_video_engine_gles2,
     /** Direct3D11 rendering engine */
diff --git a/lib/media_player.c b/lib/media_player.c
index f68c5bf0c34..a6df51f3f13 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -593,6 +593,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     var_Create (mp, "vmem-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
     var_Create (mp, "vmem-pitch", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
 
+    var_Create (mp, "vout-cb-type", VLC_VAR_INTEGER );
     var_Create( mp, "vout-cb-opaque", VLC_VAR_ADDRESS );
     var_Create( mp, "vout-cb-setup", VLC_VAR_ADDRESS );
     var_Create( mp, "vout-cb-cleanup", VLC_VAR_ADDRESS );
@@ -1045,6 +1046,7 @@ bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,
                                        libvlc_video_output_select_plane_cb select_plane_cb,
                                        void *opaque)
 {
+    static_assert(libvlc_video_engine_disable == 0, "No engine set must default to 0");
 #ifdef __ANDROID__
     //use the default android window
     var_SetString( mp, "window", "");
@@ -1072,9 +1074,17 @@ bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,
         var_SetString ( mp, "vout", "direct3d9" );
         var_SetString ( mp, "dec-dev", "d3d9-device" );
     }
+    else if ( engine == libvlc_video_engine_disable )
+    {
+        // use the default display module
+        var_SetString ( mp, "vout", "" );
+        // use the default window
+        var_SetString( mp, "window", "");
+    }
     else
         return false;
 
+    var_SetInteger( mp, "vout-cb-type", engine );
     var_SetAddress( mp, "vout-cb-opaque", opaque );
     var_SetAddress( mp, "vout-cb-setup", setup_cb );
     var_SetAddress( mp, "vout-cb-cleanup", cleanup_cb );
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 49db979efc8..44ba5f7b745 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -494,8 +494,11 @@ d3d11_decoder_device_t *(D3D11_CreateDevice)(vlc_object_t *obj,
     else
 #endif
     {
-        libvlc_video_output_setup_cb setupDeviceCb = var_InheritAddress( obj, "vout-cb-setup" );
-        if ( setupDeviceCb )
+        libvlc_video_engine_t engineType = var_InheritInteger( obj, "vout-cb-type" );
+        libvlc_video_output_setup_cb setupDeviceCb = NULL;
+        if (engineType == libvlc_video_engine_d3d11)
+            setupDeviceCb = var_InheritAddress( obj, "vout-cb-setup" );
+        if ( setupDeviceCb != NULL)
         {
             /* decoder device coming from the external app */
             sys->external.opaque          = var_InheritAddress( obj, "vout-cb-opaque" );
@@ -512,7 +515,8 @@ d3d11_decoder_device_t *(D3D11_CreateDevice)(vlc_object_t *obj,
             }
             hr = D3D11_CreateDeviceExternal(obj, out.d3d11.device_context, true, &sys->dec_device.d3d_dev);
         }
-        else
+        else if ( engineType == libvlc_video_engine_disable ||
+                  engineType == libvlc_video_engine_d3d11 )
         {
             /* internal decoder device */
 #if !VLC_WINSTORE_APP
@@ -530,6 +534,8 @@ d3d11_decoder_device_t *(D3D11_CreateDevice)(vlc_object_t *obj,
 
             hr = CreateDevice( obj, &sys->hd3d, adapter, hw_decoding, &sys->dec_device.d3d_dev );
         }
+        else
+            goto error;
     }
 
 error:
diff --git a/modules/video_chroma/d3d9_fmt.c b/modules/video_chroma/d3d9_fmt.c
index 2ae8ce8db89..f3ccdb4e519 100644
--- a/modules/video_chroma/d3d9_fmt.c
+++ b/modules/video_chroma/d3d9_fmt.c
@@ -140,8 +140,11 @@ d3d9_handle_t *hd3d = &sys->dec_device.hd3d;
     int AdapterToUse;
 
     sys->cleanupDeviceCb = NULL;
-    libvlc_video_output_setup_cb setupDeviceCb = var_InheritAddress( o, "vout-cb-setup" );
-    if ( setupDeviceCb )
+    libvlc_video_engine_t engineType = var_InheritInteger( o, "vout-cb-type" );
+    libvlc_video_output_setup_cb setupDeviceCb = NULL;
+    if (engineType == libvlc_video_engine_d3d9)
+        setupDeviceCb = var_InheritAddress( o, "vout-cb-setup" );
+    if ( setupDeviceCb != NULL)
     {
         /* external rendering */
         libvlc_video_setup_device_info_t extern_out = { .d3d9.adapter = -1 };
@@ -156,7 +159,9 @@ d3d9_handle_t *hd3d = &sys->dec_device.hd3d;
         D3D9_CloneExternal( hd3d, (IDirect3D9 *) extern_out.d3d9.device );
         AdapterToUse = extern_out.d3d9.adapter;
     }
-    else
+    else if ( engineType == libvlc_video_engine_disable ||
+              engineType == libvlc_video_engine_d3d9 ||
+              engineType == libvlc_video_engine_opengl )
     {
         /* internal rendering */
         if (D3D9_Create(o, hd3d) != VLC_SUCCESS)
@@ -167,6 +172,8 @@ d3d9_handle_t *hd3d = &sys->dec_device.hd3d;
         /* find the best adapter to use, not based on the HWND used */
         AdapterToUse = -1;
     }
+    else
+        goto error;
 
     if (AdapterToUse == -1)
     {
diff --git a/modules/video_output/vgl.c b/modules/video_output/vgl.c
index 99cf6f747eb..40487ea2476 100644
--- a/modules/video_output/vgl.c
+++ b/modules/video_output/vgl.c
@@ -123,6 +123,11 @@ static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
 {
     vout_display_sys_t * sys;
 
+    libvlc_video_engine_t engineType = var_InheritInteger( gl, "vout-cb-type" );
+    if ( engineType != libvlc_video_engine_opengl &&
+         engineType != libvlc_video_engine_gles2 )
+        return VLC_EBADVAR;
+
     /* Allocate structure */
     gl->sys = sys = vlc_obj_calloc(VLC_OBJECT(gl), 1, sizeof(*sys));
     if( !sys )
diff --git a/src/libvlc.c b/src/libvlc.c
index 2d370deab83..51954eb319e 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -254,6 +254,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 
     /* some default internal settings */
     var_Create( p_libvlc, "window", VLC_VAR_STRING );
+    var_Create( p_libvlc, "vout-cb-type", VLC_VAR_INTEGER );
+
     /* NOTE: Because the playlist and interfaces start before this function
      * returns control to the application (DESIGN BUG!), all these variables
      * must be created (in place of libvlc_new()) and set to VLC defaults
-- 
2.17.1



More information about the vlc-devel mailing list