[FFmpeg-devel] [PATCH 7/8] lavc/vaapi_decode: add profile_parser and format map support for HEVC REXT

Mark Thompson sw at jkqxz.net
Thu Jan 9 00:49:07 EET 2020


On 29/12/2019 16:30, Linjie Fu wrote:
> Add function pointer field in vaapi_profile_map[], set profile_parser
> for HEVC_REXT to find the exact va_profile.
> 
> Also add format map support.
> 
> Signed-off-by: Linjie Fu <linjie.fu at intel.com>
> ---
>  libavcodec/vaapi_decode.c | 77 +++++++++++++++++++++++++++++------------------
>  1 file changed, 47 insertions(+), 30 deletions(-)
> 
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 69512e1..658f26c 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -24,7 +24,7 @@
>  #include "decode.h"
>  #include "internal.h"
>  #include "vaapi_decode.h"
> -
> +#include "vaapi_hevc.h"
>  
>  int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
>                                        VAAPIDecodePicture *pic,
> @@ -256,6 +256,12 @@ static const struct {
>  #ifdef VA_FOURCC_YV16
>      MAP(YV16, YUV422P),
>  #endif
> +#ifdef VA_FOURCC_YUY2
> +    MAP(YUY2, YUYV422),
> +#endif

Is YUY2 really more recent than the oldest supported VAAPI version?

> +#ifdef VA_FOURCC_Y210
> +    MAP(Y210,    Y210),
> +#endif
>      // 4:4:0
>      MAP(422V, YUV440P),
>      // 4:4:4
> @@ -364,39 +370,44 @@ static const struct {
>      enum AVCodecID codec_id;
>      int codec_profile;
>      VAProfile va_profile;
> +    VAProfile (*profile_parser)(AVCodecContext *avctx);
>  } vaapi_profile_map[] = {
> -#define MAP(c, p, v) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v }
> -    MAP(MPEG2VIDEO,  MPEG2_SIMPLE,    MPEG2Simple ),
> -    MAP(MPEG2VIDEO,  MPEG2_MAIN,      MPEG2Main   ),
> -    MAP(H263,        UNKNOWN,         H263Baseline),
> -    MAP(MPEG4,       MPEG4_SIMPLE,    MPEG4Simple ),
> +#define MAP(c, p, v, f) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v, f}

Maybe something like:

#define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }

would let you avoid making the table more complex with all the NULL entries.

> +    MAP(MPEG2VIDEO,  MPEG2_SIMPLE,    MPEG2Simple , NULL ),
> +    MAP(MPEG2VIDEO,  MPEG2_MAIN,      MPEG2Main   , NULL ),
> +    MAP(H263,        UNKNOWN,         H263Baseline, NULL ),
> +    MAP(MPEG4,       MPEG4_SIMPLE,    MPEG4Simple , NULL ),
>      MAP(MPEG4,       MPEG4_ADVANCED_SIMPLE,
> -                               MPEG4AdvancedSimple),
> -    MAP(MPEG4,       MPEG4_MAIN,      MPEG4Main   ),
> +                               MPEG4AdvancedSimple, NULL ),
> +    MAP(MPEG4,       MPEG4_MAIN,      MPEG4Main   , NULL ),
>      MAP(H264,        H264_CONSTRAINED_BASELINE,
> -                           H264ConstrainedBaseline),
> -    MAP(H264,        H264_MAIN,       H264Main    ),
> -    MAP(H264,        H264_HIGH,       H264High    ),
> +                           H264ConstrainedBaseline, NULL ),
> +    MAP(H264,        H264_MAIN,       H264Main    , NULL ),
> +    MAP(H264,        H264_HIGH,       H264High    , NULL ),
>  #if VA_CHECK_VERSION(0, 37, 0)
> -    MAP(HEVC,        HEVC_MAIN,       HEVCMain    ),
> -    MAP(HEVC,        HEVC_MAIN_10,    HEVCMain10  ),
> +    MAP(HEVC,        HEVC_MAIN,       HEVCMain    , NULL ),
> +    MAP(HEVC,        HEVC_MAIN_10,    HEVCMain10  , NULL ),
> +#endif
> +#if VA_CHECK_VERSION(1, 2, 0)
> +    MAP(HEVC,        HEVC_REXT,       None,
> +                              ff_vaapi_parse_rext_profile),
>  #endif
>      MAP(MJPEG,       MJPEG_HUFFMAN_BASELINE_DCT,
> -                                      JPEGBaseline),
> -    MAP(WMV3,        VC1_SIMPLE,      VC1Simple   ),
> -    MAP(WMV3,        VC1_MAIN,        VC1Main     ),
> -    MAP(WMV3,        VC1_COMPLEX,     VC1Advanced ),
> -    MAP(WMV3,        VC1_ADVANCED,    VC1Advanced ),
> -    MAP(VC1,         VC1_SIMPLE,      VC1Simple   ),
> -    MAP(VC1,         VC1_MAIN,        VC1Main     ),
> -    MAP(VC1,         VC1_COMPLEX,     VC1Advanced ),
> -    MAP(VC1,         VC1_ADVANCED,    VC1Advanced ),
> -    MAP(VP8,         UNKNOWN,       VP8Version0_3 ),
> +                                      JPEGBaseline, NULL ),
> +    MAP(WMV3,        VC1_SIMPLE,      VC1Simple   , NULL ),
> +    MAP(WMV3,        VC1_MAIN,        VC1Main     , NULL ),
> +    MAP(WMV3,        VC1_COMPLEX,     VC1Advanced , NULL ),
> +    MAP(WMV3,        VC1_ADVANCED,    VC1Advanced , NULL ),
> +    MAP(VC1,         VC1_SIMPLE,      VC1Simple   , NULL ),
> +    MAP(VC1,         VC1_MAIN,        VC1Main     , NULL ),
> +    MAP(VC1,         VC1_COMPLEX,     VC1Advanced , NULL ),
> +    MAP(VC1,         VC1_ADVANCED,    VC1Advanced , NULL ),
> +    MAP(VP8,         UNKNOWN,       VP8Version0_3 , NULL ),
>  #if VA_CHECK_VERSION(0, 38, 0)
> -    MAP(VP9,         VP9_0,           VP9Profile0 ),
> +    MAP(VP9,         VP9_0,           VP9Profile0 , NULL ),
>  #endif
>  #if VA_CHECK_VERSION(0, 39, 0)
> -    MAP(VP9,         VP9_2,           VP9Profile2 ),
> +    MAP(VP9,         VP9_2,           VP9Profile2 , NULL ),
>  #endif
>  #undef MAP
>  };
> @@ -415,8 +426,8 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
>      VAStatus vas;
>      int err, i, j;
>      const AVCodecDescriptor *codec_desc;
> -    VAProfile *profile_list = NULL, matched_va_profile;
> -    int profile_count, exact_match, matched_ff_profile;
> +    VAProfile *profile_list = NULL, matched_va_profile, va_profile;
> +    int profile_count, exact_match, matched_ff_profile, codec_profile;
>  
>      AVHWDeviceContext    *device = (AVHWDeviceContext*)device_ref->data;
>      AVVAAPIDeviceContext *hwctx = device->hwctx;
> @@ -454,15 +465,21 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
>          if (avctx->profile == vaapi_profile_map[i].codec_profile ||
>              vaapi_profile_map[i].codec_profile == FF_PROFILE_UNKNOWN)
>              profile_match = 1;
> +
> +        va_profile = vaapi_profile_map[i].profile_parser ?
> +                     vaapi_profile_map[i].profile_parser(avctx) :
> +                     vaapi_profile_map[i].va_profile;
> +        codec_profile = vaapi_profile_map[i].codec_profile;
> +
>          for (j = 0; j < profile_count; j++) {
> -            if (vaapi_profile_map[i].va_profile == profile_list[j]) {
> +            if (va_profile == profile_list[j]) {
>                  exact_match = profile_match;
>                  break;
>              }
>          }
>          if (j < profile_count) {
> -            matched_va_profile = vaapi_profile_map[i].va_profile;
> -            matched_ff_profile = vaapi_profile_map[i].codec_profile;
> +            matched_va_profile = va_profile;
> +            matched_ff_profile = codec_profile;
>              if (exact_match)
>                  break;
>          }
> 

Thank you, that's much nicer than what was previously going on here :)

- Mark


More information about the ffmpeg-devel mailing list