[vlc-devel] [PATCH 3/4] libvlc: add a way to disable the GPU callback engine
Steve Lhomme
robux4 at ycbcr.xyz
Tue Feb 11 15:39:39 CET 2020
It should fallback to normal playback into a custom window.
---
include/vlc/libvlc_media_player.h | 2 ++
lib/media_player.c | 11 +++++++++++
modules/hw/d3d11/d3d11_device.c | 12 +++++++++---
modules/hw/d3d9/d3d9_device.c | 15 +++++++++++----
modules/video_output/vgl.c | 5 +++++
5 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 367463a70c8..5bf6f6b70fe 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -674,6 +674,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_none,
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..0808891d9a9 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -593,6 +593,8 @@ 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_SetInteger( mp, "vout-cb-type", libvlc_video_engine_none );
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 +1047,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_none == 0, "No engine set must default to 0");
#ifdef __ANDROID__
//use the default android window
var_SetString( mp, "window", "");
@@ -1072,9 +1075,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_none )
+ {
+ // use the default display module
+ var_SetString ( mp, "vout", "" );
+ // use the default decoder device
+ var_SetString ( mp, "dec-dev", "" );
+ }
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/hw/d3d11/d3d11_device.c b/modules/hw/d3d11/d3d11_device.c
index bec66708919..734ee9bcdf9 100644
--- a/modules/hw/d3d11/d3d11_device.c
+++ b/modules/hw/d3d11/d3d11_device.c
@@ -93,8 +93,11 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
else
#endif
{
- libvlc_video_output_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
- if ( setupDeviceCb )
+ libvlc_video_engine_t engineType = var_InheritInteger( device, "vout-cb-type" );
+ libvlc_video_output_setup_cb setupDeviceCb = NULL;
+ if (engineType == libvlc_video_engine_d3d11)
+ setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
+ if ( setupDeviceCb != NULL)
{
/* decoder device coming from the external app */
sys->external.opaque = var_InheritAddress( device, "vout-cb-opaque" );
@@ -111,7 +114,8 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
}
hr = D3D11_CreateDeviceExternal(device, out.device_context, true, &sys->dec_device.d3d_dev);
}
- else
+ else if ( engineType == libvlc_video_engine_none ||
+ engineType == libvlc_video_engine_d3d11 )
{
/* internal decoder device */
#if !VLC_WINSTORE_APP
@@ -131,6 +135,8 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
true /* is_d3d11_opaque(chroma) */,
&sys->dec_device.d3d_dev );
}
+ else
+ goto error;
}
if ( FAILED( hr ) )
diff --git a/modules/hw/d3d9/d3d9_device.c b/modules/hw/d3d9/d3d9_device.c
index 07b76be9ccd..23dead0239e 100644
--- a/modules/hw/d3d9/d3d9_device.c
+++ b/modules/hw/d3d9/d3d9_device.c
@@ -70,11 +70,14 @@ int D3D9OpenDecoderDevice(vlc_decoder_device *device, vout_window_t *wnd)
int adapter;
sys->cleanupDeviceCb = NULL;
- libvlc_video_output_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
- if ( setupDeviceCb )
+ libvlc_video_engine_t engineType = var_InheritInteger( device, "vout-cb-type" );
+ libvlc_video_output_setup_cb setupDeviceCb = NULL;
+ if (engineType == libvlc_video_engine_d3d9)
+ setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
+ if ( setupDeviceCb != NULL)
{
/* external rendering */
- libvlc_video_setup_device_info_t out = { .device_context = NULL, .adapter = 0 };
+ libvlc_video_setup_device_info_t out = { .adapter = 0 };
sys->opaque = var_InheritAddress( device, "vout-cb-opaque" );
sys->cleanupDeviceCb = var_InheritAddress( device, "vout-cb-cleanup" );
libvlc_video_setup_device_cfg_t cfg = {
@@ -90,7 +93,9 @@ int D3D9OpenDecoderDevice(vlc_decoder_device *device, vout_window_t *wnd)
D3D9_CloneExternal( &sys->dec_device.hd3d, (IDirect3D9*) out.device_context );
adapter = out.adapter;
}
- else
+ else if ( engineType == libvlc_video_engine_none ||
+ engineType == libvlc_video_engine_d3d9 ||
+ engineType == libvlc_video_engine_opengl )
{
/* internal rendering */
if (D3D9_Create(device, &sys->dec_device.hd3d) != VLC_SUCCESS)
@@ -101,6 +106,8 @@ int D3D9OpenDecoderDevice(vlc_decoder_device *device, vout_window_t *wnd)
/* find the best adapter to use, not based on the HWND used */
adapter = -1;
}
+ else
+ goto error;
HRESULT hr = D3D9_CreateDevice( device, &sys->dec_device.hd3d, adapter, &sys->dec_device.d3ddev );
if ( FAILED(hr) )
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 )
--
2.17.1
More information about the vlc-devel
mailing list