[vlc-devel] [PATCH v2 3/3] libvlc: add a way to disable the GPU callback engine

Steve Lhomme robux4 at ycbcr.xyz
Thu Feb 13 09:02:08 CET 2020


On 2020-02-13 8:25, Steve Lhomme wrote:
> On 2020-02-12 17:57, Rémi Denis-Courmont wrote:
>> Le keskiviikkona 12. helmikuuta 2020, 18.10.50 EET Steve Lhomme a écrit :
>>> 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/player/player.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..a19e3bce38d 
>>> 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_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..e609ec14c1d 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 | 
>>> VLC_VAR_DOINHERIT );
>>
>> I don't see why you need to inherit here, since the default value is 0 
>> anyway.
> 
> Indeed, it's useless for now. I just followed the same pattern as 
> previous code. But a quick look shows these variables aren't even 
> defined anywhere else.
> 
>> And I don't think anything should assume a player over it, so that 
>> does not
>> solve your original problem either.
> 
> I'm not sure I understand. The variable in player.c does solve my 
> problem when reading the value outside of a libvlc usage, from the 
> display module(s). I don't think we can have a display module without a 
> player.
> The "decoder device" also uses the same code. So when transcoding with a 
> GPU decoder/encoder the variable may also be read there. I suppose 
> there's no player involved in that case ?
> 
> I'm fine with moving the "default" variable to input for example.

It seems like the "window" variable that is never set by the user but is 
set by libvlc (and also others at different levels). So it should 
probably be created "globally" the same way in libvlc.c.

>>>       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_none == 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_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/video_chroma/d3d11_fmt.c
>>> b/modules/video_chroma/d3d11_fmt.c index 97ba9e6ca71..7db32b7c0d7 100644
>>> --- a/modules/video_chroma/d3d11_fmt.c
>>> +++ b/modules/video_chroma/d3d11_fmt.c
>>> @@ -438,8 +438,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" ); @@ -456,7 +459,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_none ||
>>> +                  engineType == libvlc_video_engine_d3d11 )
>>>           {
>>>               /* internal decoder device */
>>>   #if !VLC_WINSTORE_APP
>>> @@ -474,6 +478,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 66c753e308c..a50e093f1a7 100644
>>> --- a/modules/video_chroma/d3d9_fmt.c
>>> +++ b/modules/video_chroma/d3d9_fmt.c
>>> @@ -67,8 +67,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
>>> }; @@ -83,7 +86,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_none ||
>>> +              engineType == libvlc_video_engine_d3d9 ||
>>> +              engineType == libvlc_video_engine_opengl )
>>>       {
>>>           /* internal rendering */
>>>           if (D3D9_Create(o, hd3d) != VLC_SUCCESS)
>>> @@ -94,6 +99,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/player/player.c b/src/player/player.c
>>> index 89c16caf6a8..fc624e5edca 100644
>>> --- a/src/player/player.c
>>> +++ b/src/player/player.c
>>> @@ -1951,6 +1951,8 @@ vlc_player_New(vlc_object_t *parent, enum
>>> vlc_player_lock_type lock_type, VAR_CREATE("audio-language", 
>>> VLC_VAR_STRING
>>> | VLC_VAR_DOINHERIT); VAR_CREATE("sub-language", VLC_VAR_STRING |
>>> VLC_VAR_DOINHERIT);
>>>
>>> +    VAR_CREATE("vout-cb-type", VLC_VAR_INTEGER);
>>> +
>>>       /* TODO: Override these variables since the player handle media 
>>> ended
>>>        * action itself. */
>>>       VAR_CREATE("start-paused", VLC_VAR_BOOL);
>>
>>
>> -- 
>> Rémi Denis-Courmont
>> http://www.remlab.net/
>>
>>
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list