[FFmpeg-devel] [PATCH v3 5/5] libavfilter: VAAPI surface converter

wm4 nfxjfg at googlemail.com
Tue Jan 19 21:08:00 CET 2016


On Tue, 19 Jan 2016 14:10:59 +0000
Mark Thompson <sw at jkqxz.net> wrote:

> ...
> >> +static int vaapi_conv_config_input(AVFilterLink *inlink)
> >> +{
> >> +    AVFilterContext *avctx = inlink->dst;
> >> +    VAAPIConvContext *ctx = avctx->priv;
> >> +    AVVAAPISurfaceConfig *config = &ctx->input_config;
> >> +
> >> +    if(inlink->format == AV_PIX_FMT_VAAPI) {
> >> +        av_log(ctx, AV_LOG_INFO, "Input is VAAPI (using incoming surfaces).\n");
> >> +        ctx->input_is_vaapi = 1;
> >> +        return 0;
> >> +    }
> >> +    ctx->input_is_vaapi = 0;
> >> +
> >> +    config->rt_format = VA_RT_FORMAT_YUV420;
> >> +    config->av_format = AV_PIX_FMT_VAAPI;
> >> +
> >> +    switch(inlink->format) {
> >> +    case AV_PIX_FMT_BGR0:
> >> +    case AV_PIX_FMT_BGRA:
> >> +        config->image_format.fourcc     = VA_FOURCC_BGRX;
> >> +        config->image_format.byte_order = VA_LSB_FIRST;
> >> +        config->image_format.bits_per_pixel = 32;
> >> +        config->image_format.depth      = 8;
> >> +        config->image_format.red_mask   = 0x00ff0000;
> >> +        config->image_format.green_mask = 0x0000ff00;
> >> +        config->image_format.blue_mask  = 0x000000ff;
> >> +        config->image_format.alpha_mask = 0x00000000;
> >> +        break;
> >> +
> >> +    case AV_PIX_FMT_RGB0:
> >> +    case AV_PIX_FMT_RGBA:
> >> +        config->image_format.fourcc     = VA_FOURCC_RGBX;
> >> +        config->image_format.byte_order = VA_LSB_FIRST;
> >> +        config->image_format.bits_per_pixel = 32;
> >> +        config->image_format.depth      = 8;
> >> +        config->image_format.red_mask   = 0x000000ff;
> >> +        config->image_format.green_mask = 0x0000ff00;
> >> +        config->image_format.blue_mask  = 0x00ff0000;
> >> +        config->image_format.alpha_mask = 0x00000000;
> >> +        break;
> >> +
> >> +    case AV_PIX_FMT_NV12:
> >> +        config->image_format.fourcc = VA_FOURCC_NV12;
> >> +        config->image_format.bits_per_pixel = 12;
> >> +        break;
> >> +    case AV_PIX_FMT_YUV420P:
> >> +        config->image_format.fourcc = VA_FOURCC_YV12;
> >> +        config->image_format.bits_per_pixel = 12;
> >> +        break;  
> > 
> > Doesn't this duplicate what vaQueryImageFormats() returns?
> > 
> > Also I think your AV_PIX_FMT <-> VA_FOURCC mappings are duplicated
> > somewhere else to a degree.  
> 
> Hmm, yes.  I didn't put much thought into this part, because it was only a token set of things to make my two initial use-cases work (RGB colour-conversion, YV12/NV12 scale).
> 
> I'll leave it for now and come back to it when looking at expanding the inputs and outputs to be able to accept anything the hardware supports.
> 

OK. Well, there is the impending HEVC 10 bit support, which will likely
require adding 1 or 2 new formats all over the place.

> ...
> >> +
> >> +#define OFFSET(member) offsetof(VAAPIConvContext, options.member)
> >> +#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
> >> +static const AVOption vaapi_conv_options[] = {
> >> +    { "hardware_context", "VAAPI hardware context",
> >> +      OFFSET(hardware_context), AV_OPT_TYPE_INT64,
> >> +      { .i64 = 0 }, INT64_MIN, INT64_MAX, AV_OPT_FLAG_VIDEO_PARAM },  
> > 
> > Setting it this way is not ideal, but I guess there's no proper way yet.  
> 
> Yeah.  Maybe there should be an AV_OPT_TYPE_POINTER for the user to cleanly do naughty things like this...

Or it's made first class and somehow added to libavfilter directly. I
don't know.

Does anyone else have suggestions?


More information about the ffmpeg-devel mailing list