diff mbox

[FFmpeg-devel] lavc: Make hardware config method support more explicit for hwaccels

Message ID 3bdbc310-1dda-4836-831d-4fb201d054e2@jkqxz.net
State Accepted
Commit 84936f68ede265cfa3b9315f908bfe76e81fae6e
Headers show

Commit Message

Mark Thompson Dec. 8, 2017, 4:15 p.m. UTC
From: Thomas Guillem <thomas@gllm.fr>

This fixes the use of old ad-hoc methods which are still supported by some
hwaccels which also support newer methods (DXVA2, VAAPI, VDPAU,
videotoolbox) - without the method being visible here, ff_get_format()
would refuse to use it.

Signed-off-by: Mark Thompson <sw@jkqxz.net>
---
On 07/12/17 12:25, Thomas Guillem wrote:
> Add a boolean to specify if an API can work with
> AV_CODEC_HW_CONFIG_METHOD_AD_HOC.
> ---
>  libavcodec/hwaccel.h | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/libavcodec/hwaccel.h b/libavcodec/hwaccel.h
> index ae55527c2f..16ee822920 100644
> --- a/libavcodec/hwaccel.h
> +++ b/libavcodec/hwaccel.h
> @@ -42,12 +42,13 @@ typedef struct AVCodecHWConfigInternal {
>  
>  // These macros are used to simplify AVCodecHWConfigInternal definitions.
>  
> -#define HW_CONFIG_HWACCEL(format, device, name) \
> +#define HW_CONFIG_HWACCEL(format, ad_hoc, device, name) \
>      &(const AVCodecHWConfigInternal) { \
>          .public          = { \
>              .pix_fmt     = AV_PIX_FMT_ ## format, \
>              .methods     = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX | \
> -                           AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, \
> +                           AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX | \
> +                           ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC : 0, \
>              .device_type = AV_HWDEVICE_TYPE_ ## device, \
>          }, \
>          .hwaccel         = &name, \

Once we're having extra arguments in the macros like that I think I would prefer all the methods to be specified explicitly (which conveniently also lets us delete the second macro).

How about this?

Thanks,

- Mark


 libavcodec/hwaccel.h | 36 +++++++++++++-----------------------
 1 file changed, 13 insertions(+), 23 deletions(-)

Comments

Thomas Guillem Dec. 8, 2017, 4:22 p.m. UTC | #1
On Fri, Dec 8, 2017, at 17:15, Mark Thompson wrote:
> From: Thomas Guillem <thomas@gllm.fr>
> 
> This fixes the use of old ad-hoc methods which are still supported by
> some
> hwaccels which also support newer methods (DXVA2, VAAPI, VDPAU,
> videotoolbox) - without the method being visible here, ff_get_format()
> would refuse to use it.
> 
> Signed-off-by: Mark Thompson <sw@jkqxz.net>
> ---
> On 07/12/17 12:25, Thomas Guillem wrote:
> > Add a boolean to specify if an API can work with
> > AV_CODEC_HW_CONFIG_METHOD_AD_HOC.
> > ---
> >  libavcodec/hwaccel.h | 17 +++++++++--------
> >  1 file changed, 9 insertions(+), 8 deletions(-)
> > 
> > diff --git a/libavcodec/hwaccel.h b/libavcodec/hwaccel.h
> > index ae55527c2f..16ee822920 100644
> > --- a/libavcodec/hwaccel.h
> > +++ b/libavcodec/hwaccel.h
> > @@ -42,12 +42,13 @@ typedef struct AVCodecHWConfigInternal {
> >  
> >  // These macros are used to simplify AVCodecHWConfigInternal definitions.
> >  
> > -#define HW_CONFIG_HWACCEL(format, device, name) \
> > +#define HW_CONFIG_HWACCEL(format, ad_hoc, device, name) \
> >      &(const AVCodecHWConfigInternal) { \
> >          .public          = { \
> >              .pix_fmt     = AV_PIX_FMT_ ## format, \
> >              .methods     = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX | \
> > -                           AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, \
> > +                           AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX | \
> > +                           ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC : 0, \
> >              .device_type = AV_HWDEVICE_TYPE_ ## device, \
> >          }, \
> >          .hwaccel         = &name, \
> 
> Once we're having extra arguments in the macros like that I think I would
> prefer all the methods to be specified explicitly (which conveniently
> also lets us delete the second macro).
> 
> How about this?

Fine with me.

> 
> Thanks,
> 
> - Mark
> 
> 
>  libavcodec/hwaccel.h | 36 +++++++++++++-----------------------
>  1 file changed, 13 insertions(+), 23 deletions(-)
> 
> diff --git a/libavcodec/hwaccel.h b/libavcodec/hwaccel.h
> index ae55527c2f..3aaa92571c 100644
> --- a/libavcodec/hwaccel.h
> +++ b/libavcodec/hwaccel.h
> @@ -42,13 +42,14 @@ typedef struct AVCodecHWConfigInternal {
>  
>  // These macros are used to simplify AVCodecHWConfigInternal
>  definitions.
>  
> -#define HW_CONFIG_HWACCEL(format, device, name) \
> +#define HW_CONFIG_HWACCEL(device, frames, ad_hoc, format, device_type_,
> name) \
>      &(const AVCodecHWConfigInternal) { \
>          .public          = { \
>              .pix_fmt     = AV_PIX_FMT_ ## format, \
> -            .methods     = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX | \
> -                           AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, \
> -            .device_type = AV_HWDEVICE_TYPE_ ## device, \
> +            .methods     = (device ?
> AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX : 0) | \
> +                           (frames ?
> AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX : 0) | \
> +                           (ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC   
>     : 0),  \
> +            .device_type = AV_HWDEVICE_TYPE_ ## device_type_, \
>          }, \
>          .hwaccel         = &name, \
>      }
> @@ -63,32 +64,21 @@ typedef struct AVCodecHWConfigInternal {
>          .hwaccel         = NULL, \
>      }
>  
> -#define HW_CONFIG_AD_HOC_HWACCEL(format, name) \
> -    &(const AVCodecHWConfigInternal) { \
> -        .public =      { \
> -            .pix_fmt     = AV_PIX_FMT_ ## format, \
> -            .methods     = AV_CODEC_HW_CONFIG_METHOD_AD_HOC, \
> -            .device_type = AV_HWDEVICE_TYPE_NONE, \
> -        }, \
> -        .hwaccel = &name, \
> -    }
> -
>  #define HWACCEL_DXVA2(codec) \
> -    HW_CONFIG_HWACCEL(DXVA2_VLD, DXVA2,   ff_ ## codec ##
> _dxva2_hwaccel)
> +    HW_CONFIG_HWACCEL(1, 1, 1, DXVA2_VLD,    DXVA2,        ff_ ## codec
> ## _dxva2_hwaccel)
>  #define HWACCEL_D3D11VA2(codec) \
> -    HW_CONFIG_HWACCEL(D3D11,     D3D11VA, ff_ ## codec ##
> _d3d11va2_hwaccel)
> +    HW_CONFIG_HWACCEL(1, 1, 0, D3D11,        D3D11VA,      ff_ ## codec
> ## _d3d11va2_hwaccel)
>  #define HWACCEL_NVDEC(codec) \
> -    HW_CONFIG_HWACCEL(CUDA,      CUDA,    ff_ ## codec ##
> _nvdec_hwaccel)
> +    HW_CONFIG_HWACCEL(1, 1, 0, CUDA,         CUDA,         ff_ ## codec
> ## _nvdec_hwaccel)
>  #define HWACCEL_VAAPI(codec) \
> -    HW_CONFIG_HWACCEL(VAAPI,     VAAPI,   ff_ ## codec ##
> _vaapi_hwaccel)
> +    HW_CONFIG_HWACCEL(1, 1, 1, VAAPI,        VAAPI,        ff_ ## codec
> ## _vaapi_hwaccel)
>  #define HWACCEL_VDPAU(codec) \
> -    HW_CONFIG_HWACCEL(VDPAU,     VDPAU,   ff_ ## codec ##
> _vdpau_hwaccel)
> +    HW_CONFIG_HWACCEL(1, 1, 1, VDPAU,        VDPAU,        ff_ ## codec
> ## _vdpau_hwaccel)
>  #define HWACCEL_VIDEOTOOLBOX(codec) \
> -    HW_CONFIG_HWACCEL(VIDEOTOOLBOX, VIDEOTOOLBOX, ff_ ## codec ##
> _videotoolbox_hwaccel)
> -
> +    HW_CONFIG_HWACCEL(1, 1, 1, VIDEOTOOLBOX, VIDEOTOOLBOX, ff_ ## codec
> ## _videotoolbox_hwaccel)
>  #define HWACCEL_D3D11VA(codec) \
> -    HW_CONFIG_AD_HOC_HWACCEL(D3D11VA_VLD, ff_ ## codec ##
> _d3d11va_hwaccel)
> +    HW_CONFIG_HWACCEL(0, 0, 1, D3D11VA_VLD,  NONE,         ff_ ## codec
> ## _d3d11va_hwaccel)
>  #define HWACCEL_XVMC(codec) \
> -    HW_CONFIG_AD_HOC_HWACCEL(XVMC,        ff_ ## codec ## _xvmc_hwaccel)
> +    HW_CONFIG_HWACCEL(0, 0, 1, XVMC,         NONE,         ff_ ## codec
> ## _xvmc_hwaccel)
>  
>  #endif /* AVCODEC_HWACCEL_H */
> -- 
> 2.11.0
Mark Thompson Dec. 10, 2017, 4:47 p.m. UTC | #2
On 08/12/17 16:22, Thomas Guillem wrote:
> On Fri, Dec 8, 2017, at 17:15, Mark Thompson wrote:
>> From: Thomas Guillem <thomas@gllm.fr>
>>
>> This fixes the use of old ad-hoc methods which are still supported by
>> some
>> hwaccels which also support newer methods (DXVA2, VAAPI, VDPAU,
>> videotoolbox) - without the method being visible here, ff_get_format()
>> would refuse to use it.
>>
>> Signed-off-by: Mark Thompson <sw@jkqxz.net>
>> ---
>> On 07/12/17 12:25, Thomas Guillem wrote:
>>> Add a boolean to specify if an API can work with
>>> AV_CODEC_HW_CONFIG_METHOD_AD_HOC.
>>> ---
>>>  libavcodec/hwaccel.h | 17 +++++++++--------
>>>  1 file changed, 9 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/libavcodec/hwaccel.h b/libavcodec/hwaccel.h
>>> index ae55527c2f..16ee822920 100644
>>> --- a/libavcodec/hwaccel.h
>>> +++ b/libavcodec/hwaccel.h
>>> @@ -42,12 +42,13 @@ typedef struct AVCodecHWConfigInternal {
>>>  
>>>  // These macros are used to simplify AVCodecHWConfigInternal definitions.
>>>  
>>> -#define HW_CONFIG_HWACCEL(format, device, name) \
>>> +#define HW_CONFIG_HWACCEL(format, ad_hoc, device, name) \
>>>      &(const AVCodecHWConfigInternal) { \
>>>          .public          = { \
>>>              .pix_fmt     = AV_PIX_FMT_ ## format, \
>>>              .methods     = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX | \
>>> -                           AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, \
>>> +                           AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX | \
>>> +                           ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC : 0, \
>>>              .device_type = AV_HWDEVICE_TYPE_ ## device, \
>>>          }, \
>>>          .hwaccel         = &name, \
>>
>> Once we're having extra arguments in the macros like that I think I would
>> prefer all the methods to be specified explicitly (which conveniently
>> also lets us delete the second macro).
>>
>> How about this?
> 
> Fine with me.

Ok, applied.

Thanks,

- Mark
diff mbox

Patch

diff --git a/libavcodec/hwaccel.h b/libavcodec/hwaccel.h
index ae55527c2f..3aaa92571c 100644
--- a/libavcodec/hwaccel.h
+++ b/libavcodec/hwaccel.h
@@ -42,13 +42,14 @@  typedef struct AVCodecHWConfigInternal {
 
 // These macros are used to simplify AVCodecHWConfigInternal definitions.
 
-#define HW_CONFIG_HWACCEL(format, device, name) \
+#define HW_CONFIG_HWACCEL(device, frames, ad_hoc, format, device_type_, name) \
     &(const AVCodecHWConfigInternal) { \
         .public          = { \
             .pix_fmt     = AV_PIX_FMT_ ## format, \
-            .methods     = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX | \
-                           AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, \
-            .device_type = AV_HWDEVICE_TYPE_ ## device, \
+            .methods     = (device ? AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX : 0) | \
+                           (frames ? AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX : 0) | \
+                           (ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC        : 0),  \
+            .device_type = AV_HWDEVICE_TYPE_ ## device_type_, \
         }, \
         .hwaccel         = &name, \
     }
@@ -63,32 +64,21 @@  typedef struct AVCodecHWConfigInternal {
         .hwaccel         = NULL, \
     }
 
-#define HW_CONFIG_AD_HOC_HWACCEL(format, name) \
-    &(const AVCodecHWConfigInternal) { \
-        .public =      { \
-            .pix_fmt     = AV_PIX_FMT_ ## format, \
-            .methods     = AV_CODEC_HW_CONFIG_METHOD_AD_HOC, \
-            .device_type = AV_HWDEVICE_TYPE_NONE, \
-        }, \
-        .hwaccel = &name, \
-    }
-
 #define HWACCEL_DXVA2(codec) \
-    HW_CONFIG_HWACCEL(DXVA2_VLD, DXVA2,   ff_ ## codec ## _dxva2_hwaccel)
+    HW_CONFIG_HWACCEL(1, 1, 1, DXVA2_VLD,    DXVA2,        ff_ ## codec ## _dxva2_hwaccel)
 #define HWACCEL_D3D11VA2(codec) \
-    HW_CONFIG_HWACCEL(D3D11,     D3D11VA, ff_ ## codec ## _d3d11va2_hwaccel)
+    HW_CONFIG_HWACCEL(1, 1, 0, D3D11,        D3D11VA,      ff_ ## codec ## _d3d11va2_hwaccel)
 #define HWACCEL_NVDEC(codec) \
-    HW_CONFIG_HWACCEL(CUDA,      CUDA,    ff_ ## codec ## _nvdec_hwaccel)
+    HW_CONFIG_HWACCEL(1, 1, 0, CUDA,         CUDA,         ff_ ## codec ## _nvdec_hwaccel)
 #define HWACCEL_VAAPI(codec) \
-    HW_CONFIG_HWACCEL(VAAPI,     VAAPI,   ff_ ## codec ## _vaapi_hwaccel)
+    HW_CONFIG_HWACCEL(1, 1, 1, VAAPI,        VAAPI,        ff_ ## codec ## _vaapi_hwaccel)
 #define HWACCEL_VDPAU(codec) \
-    HW_CONFIG_HWACCEL(VDPAU,     VDPAU,   ff_ ## codec ## _vdpau_hwaccel)
+    HW_CONFIG_HWACCEL(1, 1, 1, VDPAU,        VDPAU,        ff_ ## codec ## _vdpau_hwaccel)
 #define HWACCEL_VIDEOTOOLBOX(codec) \
-    HW_CONFIG_HWACCEL(VIDEOTOOLBOX, VIDEOTOOLBOX, ff_ ## codec ## _videotoolbox_hwaccel)
-
+    HW_CONFIG_HWACCEL(1, 1, 1, VIDEOTOOLBOX, VIDEOTOOLBOX, ff_ ## codec ## _videotoolbox_hwaccel)
 #define HWACCEL_D3D11VA(codec) \
-    HW_CONFIG_AD_HOC_HWACCEL(D3D11VA_VLD, ff_ ## codec ## _d3d11va_hwaccel)
+    HW_CONFIG_HWACCEL(0, 0, 1, D3D11VA_VLD,  NONE,         ff_ ## codec ## _d3d11va_hwaccel)
 #define HWACCEL_XVMC(codec) \
-    HW_CONFIG_AD_HOC_HWACCEL(XVMC,        ff_ ## codec ## _xvmc_hwaccel)
+    HW_CONFIG_HWACCEL(0, 0, 1, XVMC,         NONE,         ff_ ## codec ## _xvmc_hwaccel)
 
 #endif /* AVCODEC_HWACCEL_H */