[vlc-devel] [PATCH 1/7] decoder: pass the chroma to decode to the decoder device

Steve Lhomme robux4 at ycbcr.xyz
Tue Jul 2 07:30:03 CEST 2019


On 2019-07-01 16:34, Steve Lhomme wrote:
> 
> 
> On 2019-07-01 15:08, Thomas Guillem wrote:
>>
>> On Mon, Jul 1, 2019, at 09:03, Steve Lhomme wrote:
>>> On 2019-06-26 17:05, Thomas Guillem wrote:
>>>>
>>>>
>>>> On Wed, Jun 26, 2019, at 17:02, Steve Lhomme wrote:
>>>>> On 2019-06-26 16:48, Thomas Guillem wrote:
>>>>>>
>>>>>> On Wed, Jun 26, 2019, at 16:28, Steve Lhomme wrote:
>>>>>>> On 2019-06-26 16:06, Thomas Guillem wrote:
>>>>>>>> Question: The decoder device should not be constant to the 
>>>>>>>> window and not depends on the decoder ?
>>>>>>>
>>>>>>> Probably, yes. But the decoder/display configuration shouldn't 
>>>>>>> change
>>>>>>> during the lifetime of the vout thread either.
>>>>>>
>>>>>> To sum up and make sure we understand each other:
>>>>>>
>>>>>> - The vout_thread_t is still constant (the same can be used with 
>>>>>> different medias)
>>>>>> - The window module inside the vout_thread_t is also constant: it 
>>>>>> is enabled when a decoder starts a vout (vout_Request) and 
>>>>>> disabled when the decoder is destroyed.
>>>>>>
>>>>>> - The decoder device is created after the window is enabled (order 
>>>>>> coming from a vout_Request() from a video decoder). It is 
>>>>>> destroyed before the window is disabled.
>>>>>> - The decoder can now load a hw decoder using the decoder device.
>>>>>>
>>>>>> I see a chicken-egg situation here with your patch. How can you 
>>>>>> know that the chroma is DXVA2 if you didn't created the hw decoder 
>>>>>> yet.
>>>>>
>>>>> In push the decoder will still create the "vout" 
>>>>> (thread+window+display)
>>>>> as it does now. It will be in 2 parts, first create the vout thread +
>>>>> window + decoder device, then the VA can actually be created with the
>>>>> decoder device. And then the display module is created using the video
>>>>> context that the VA created.
>>>>
>>>> So we agree on that point. Then I don't how how your patch can work. 
>>>> How can you know the chroma for the decoder device since you didn't 
>>>> created the VA yet ?
>>>
>>> This is how VA is currently working and it is not going to change for
>>> now:
>>> http://git.videolan.org/?p=vlc.git;a=blob;f=modules/codec/avcodec/video.c;h=0829bfc6ee038f7179c30f4ed8b482e42c0fff31;hb=HEAD#l1723 
>>>
>>
>> What about loading a avcodec hw decoder  and using vlc_va_GetChroma() 
>> from the decoder device probe ?
> 
> vlc_va_GetChroma() uses ffmpeg PixelFormat on input. You want to pass 
> that to the decoder devices ? The decoder device shouldn't be tight to 
> one implementation (for example they can be used to create a context to 
> filter in GPU without ever touching ffmpeg).

Alternatively, the point of the decoder device was originally to tie the 
decoder to a particular display adapter (for performance or simply 
because it can't do without with some API's).

For D3D9/D3D11 I create a whole D3D context that can be used for 
decoding and rendering. But it's not necessary. Right now we don't even 
tie decoders to a display adapter. I could just provide the info to know 
the preferred adapter and it should work. The actual D3D objects created 
by the decoder will be provided in the video context by the time the 
display is created.

In D3D9 I thought we need the actual rendering HWND (not a parent) to 
create the D3D objects (and the doc says so) but we don't. We can 
override that (NULL) HWND during Present(). And when rendering 
externally we don't have a HWND either and it works fine.

So all I need is an adapter ID. I won't need the chroma for that.

>>>
>>> It guesses the chroma using vlc_va_GetChroma() and passes that to the
>>> vout in decoder_UpdateVideoFormat() (via lavc_UpdateVideoFormat()).
>>>
>>>>>
>>>>> More video context can be pushed and will may use the same decoder
>>>>> device. Or it could redo the first part and recreate a vout thread +
>>>>> window (which are cached internally) + decoder device.
>>>>>
>>>>> This is done via a split of decoder_UpdateVideoFormat() in two.
>>>>>
>>>>>>>
>>>>>>>> This patch could be more readable if you move the 
>>>>>>>> vlc_decoder_device_Create() call to its definite place (Just 
>>>>>>>> after the window creation).
>>>>>>>
>>>>>>> Yes it's going to move later.
>>>>>>
>>>>>> I think it should be done before, cf ^^
>>>>>>
>>>>>>>
>>>>>>>> On Wed, Jun 26, 2019, at 15:50, Steve Lhomme wrote:
>>>>>>>>> On Windows the default decoder device to use would be the D3D11 
>>>>>>>>> one, but if the
>>>>>>>>> source chroma to decode (in push or not) is a DXVA2 chroma we 
>>>>>>>>> should be using
>>>>>>>>> a D3D9 decoder device. The D3D11 decoder device needs to have 
>>>>>>>>> that information
>>>>>>>>> so it can refuse to be created by default.
>>>>>>>>> ---
>>>>>>>>>      include/vlc_codec.h                           | 6 ++++--
>>>>>>>>>      modules/hw/vaapi/decoder_device.c             | 3 ++-
>>>>>>>>>      modules/video_output/opengl/converter_vdpau.c | 3 ++-
>>>>>>>>>      src/input/decoder_helpers.c                   | 7 ++++---
>>>>>>>>>      src/video_output/display.c                    | 2 +-
>>>>>>>>>      5 files changed, 13 insertions(+), 8 deletions(-)
>>>>>>>>>
>>>>>>>>> diff --git a/include/vlc_codec.h b/include/vlc_codec.h
>>>>>>>>> index 86f092c029..a421c6d710 100644
>>>>>>>>> --- a/include/vlc_codec.h
>>>>>>>>> +++ b/include/vlc_codec.h
>>>>>>>>> @@ -528,9 +528,11 @@ typedef struct vlc_decoder_device
>>>>>>>>>       *
>>>>>>>>>       * @param device the "decoder device" structure to initialize
>>>>>>>>>       * @param window pointer to a window to help device 
>>>>>>>>> initialization
>>>>>>>>> (can be NULL)
>>>>>>>>> + * @param chroma hint on the chroma what will be decoded
>>>>>>>>>       **/
>>>>>>>>>      typedef int (*vlc_decoder_device_Open)(vlc_decoder_device 
>>>>>>>>> *device,
>>>>>>>>> -                                        vout_window_t *window);
>>>>>>>>> +                                        vout_window_t *window,
>>>>>>>>> +                                        vlc_fourcc_t chroma);
>>>>>>>>>      /** "decoder device" module close entry point */
>>>>>>>>>      typedef void 
>>>>>>>>> (*vlc_decoder_device_Close)(vlc_decoder_device *device);
>>>>>>>>> @@ -541,7 +543,7 @@ typedef void
>>>>>>>>> (*vlc_decoder_device_Close)(vlc_decoder_device *device);
>>>>>>>>>       * module as a transition.
>>>>>>>>>       */
>>>>>>>>>      VLC_USED vlc_decoder_device *
>>>>>>>>> -vlc_decoder_device_Create(vout_window_t *window);
>>>>>>>>> +vlc_decoder_device_Create(vout_window_t *window, const 
>>>>>>>>> video_format_t
>>>>>>>>> *);
>>>>>>>>>      /**
>>>>>>>>>       * Hold a decoder device
>>>>>>>>> diff --git a/modules/hw/vaapi/decoder_device.c
>>>>>>>>> b/modules/hw/vaapi/decoder_device.c
>>>>>>>>> index 5efe9e635b..00d654d245 100644
>>>>>>>>> --- a/modules/hw/vaapi/decoder_device.c
>>>>>>>>> +++ b/modules/hw/vaapi/decoder_device.c
>>>>>>>>> @@ -217,8 +217,9 @@ Close(vlc_decoder_device *device)
>>>>>>>>>      }
>>>>>>>>>      static int
>>>>>>>>> -Open(vlc_decoder_device *device, vout_window_t *window)
>>>>>>>>> +Open(vlc_decoder_device *device, vout_window_t *window, 
>>>>>>>>> vlc_fourcc_t
>>>>>>>>> chroma)
>>>>>>>>>      {
>>>>>>>>> +    VLC_UNUSED(chroma);
>>>>>>>>>          VADisplay vadpy = NULL;
>>>>>>>>>          struct vaapi_instance *vainst = NULL;
>>>>>>>>>      #if defined (HAVE_VA_X11)
>>>>>>>>> diff --git a/modules/video_output/opengl/converter_vdpau.c
>>>>>>>>> b/modules/video_output/opengl/converter_vdpau.c
>>>>>>>>> index d40d5d181f..3363a38ca1 100644
>>>>>>>>> --- a/modules/video_output/opengl/converter_vdpau.c
>>>>>>>>> +++ b/modules/video_output/opengl/converter_vdpau.c
>>>>>>>>> @@ -185,8 +185,9 @@ DecoderContextClose(vlc_decoder_device 
>>>>>>>>> *device)
>>>>>>>>>      }
>>>>>>>>>      static int
>>>>>>>>> -DecoderContextOpen(vlc_decoder_device *device, vout_window_t 
>>>>>>>>> *window)
>>>>>>>>> +DecoderContextOpen(vlc_decoder_device *device, vout_window_t 
>>>>>>>>> *window,
>>>>>>>>> vlc_fourcc_t chroma)
>>>>>>>>>      {
>>>>>>>>> +    VLC_UNUSED(chroma);
>>>>>>>>>          if (!window || !vlc_xlib_init(VLC_OBJECT(window)))
>>>>>>>>>              return VLC_EGENERIC;
>>>>>>>>> diff --git a/src/input/decoder_helpers.c 
>>>>>>>>> b/src/input/decoder_helpers.c
>>>>>>>>> index 7384e2bda0..35a291921d 100644
>>>>>>>>> --- a/src/input/decoder_helpers.c
>>>>>>>>> +++ b/src/input/decoder_helpers.c
>>>>>>>>> @@ -105,7 +105,8 @@ static int decoder_device_Open(void *func, 
>>>>>>>>> bool
>>>>>>>>> forced, va_list ap)
>>>>>>>>>          vlc_decoder_device_Open open = func;
>>>>>>>>>          vlc_decoder_device *device = va_arg(ap, 
>>>>>>>>> vlc_decoder_device *);
>>>>>>>>>          vout_window_t *window = va_arg(ap, vout_window_t *);
>>>>>>>>> -    int ret = open(device, window);
>>>>>>>>> +    vlc_fourcc_t chroma = va_arg(ap, vlc_fourcc_t);
>>>>>>>>> +    int ret = open(device, window, chroma);
>>>>>>>>>          if (ret != VLC_SUCCESS)
>>>>>>>>>          {
>>>>>>>>>              device->sys = NULL;
>>>>>>>>> @@ -128,7 +129,7 @@ static void decoder_device_Close(void *func,
>>>>>>>>> va_list ap)
>>>>>>>>>      }
>>>>>>>>>      vlc_decoder_device *
>>>>>>>>> -vlc_decoder_device_Create(vout_window_t *window)
>>>>>>>>> +vlc_decoder_device_Create(vout_window_t *window, const 
>>>>>>>>> video_format_t *fmt)
>>>>>>>>>      {
>>>>>>>>>          struct vlc_decoder_device_priv *priv =
>>>>>>>>>                  vlc_object_create(window, sizeof (*priv));
>>>>>>>>> @@ -137,7 +138,7 @@ vlc_decoder_device_Create(vout_window_t 
>>>>>>>>> *window)
>>>>>>>>>          char *name = var_InheritString(window, "dec-dev");
>>>>>>>>>          priv->module = vlc_module_load(&priv->device, "decoder 
>>>>>>>>> device", name,
>>>>>>>>>                                          true, 
>>>>>>>>> decoder_device_Open, &priv->device,
>>>>>>>>> -                                    window);
>>>>>>>>> +                                    window, fmt->i_chroma);
>>>>>>>>>          free(name);
>>>>>>>>>          if (!priv->module)
>>>>>>>>>          {
>>>>>>>>> diff --git a/src/video_output/display.c 
>>>>>>>>> b/src/video_output/display.c
>>>>>>>>> index 2173bb084e..b0c5ee8ad1 100644
>>>>>>>>> --- a/src/video_output/display.c
>>>>>>>>> +++ b/src/video_output/display.c
>>>>>>>>> @@ -777,7 +777,7 @@ vout_display_t 
>>>>>>>>> *vout_display_New(vlc_object_t *parent,
>>>>>>>>>          vd->sys = NULL;
>>>>>>>>>          vd->owner = *owner;
>>>>>>>>> -    osys->video_context.device =
>>>>>>>>> vlc_decoder_device_Create(osys->cfg.window);
>>>>>>>>> +    osys->video_context.device =
>>>>>>>>> vlc_decoder_device_Create(osys->cfg.window, source);
>>>>>>>>>          vlc_video_context *video_context = 
>>>>>>>>> osys->video_context.device ?
>>>>>>>>>              &osys->video_context : NULL;
>>>>>>>>> -- 
>>>>>>>>> 2.17.1
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> 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
>>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> 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
>>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>>
>>> _______________________________________________
>>> 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
>>
> _______________________________________________
> 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