26 #include "config_components.h" 
   43 #define OFFSET(x) offsetof(VPPContext, x) 
   44 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM) 
   47 #define ENH_FILTERS_COUNT (8) 
  137 #define PASS_EXPR(e, s) {\ 
  139         ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \ 
  141             av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s); \ 
  146 #define CALC_EXPR(e, v, i, d) {\ 
  148         i = v = av_expr_eval(e, var_values, NULL);      \ 
  175     var_values[
VAR_SAR] = 
ctx->inputs[0]->sample_aspect_ratio.num ?
 
  176         (
double)
ctx->inputs[0]->sample_aspect_ratio.num / 
ctx->inputs[0]->sample_aspect_ratio.den : 1;
 
  280     if (ow <  -1 || oh <  -1) {
 
  285     if (ow == -1 && oh == -1)
 
  300     if (ow > INT_MAX || oh > INT_MAX ||
 
  301         (oh * 
inlink->w) > INT_MAX  ||
 
  302         (ow * 
inlink->h) > INT_MAX)
 
  328     if (
inlink->hw_frames_ctx) {
 
  331     } 
else if (
ctx->hw_device_ctx) {
 
  332         device_ref = 
ctx->hw_device_ctx;
 
  336         mfx_version->Major = 0;
 
  337         mfx_version->Minor = 0;
 
  342     device_hwctx = device_ctx->
hwctx;
 
  344     return MFXQueryVersion(device_hwctx->
session, mfx_version);
 
  354     mfxVersion      mfx_version;
 
  373          if (!
inlink->hw_frames_ctx || !
inlink->hw_frames_ctx->data)
 
  378         in_format = 
inlink->format;
 
  395 #define INIT_MFX_EXTBUF(extbuf, id) do { \ 
  396         memset(&vpp->extbuf, 0, sizeof(vpp->extbuf)); \ 
  397         vpp->extbuf.Header.BufferId = id; \ 
  398         vpp->extbuf.Header.BufferSz = sizeof(vpp->extbuf); \ 
  399         param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->extbuf; \ 
  402 #define SET_MFX_PARAM_FIELD(extbuf, field, value) do { \ 
  403         vpp->extbuf.field = value; \ 
  409                             MFX_DEINTERLACING_BOB : MFX_DEINTERLACING_ADVANCED));
 
  439                 vpp->
rotate = MFX_ANGLE_270;
 
  440                 vpp->
hflip  = MFX_MIRRORING_HORIZONTAL;
 
  443                 vpp->
rotate = MFX_ANGLE_90;
 
  444                 vpp->
hflip  = MFX_MIRRORING_DISABLED;
 
  447                 vpp->
rotate = MFX_ANGLE_270;
 
  448                 vpp->
hflip  = MFX_MIRRORING_DISABLED;
 
  451                 vpp->
rotate = MFX_ANGLE_90;
 
  452                 vpp->
hflip  = MFX_MIRRORING_HORIZONTAL;
 
  455                 vpp->
rotate = MFX_ANGLE_180;
 
  456                 vpp->
hflip  = MFX_MIRRORING_DISABLED;
 
  459                 vpp->
rotate = MFX_ANGLE_0;
 
  460                 vpp->
hflip  = MFX_MIRRORING_HORIZONTAL;
 
  463                 vpp->
rotate = MFX_ANGLE_180;
 
  464                 vpp->
hflip  = MFX_MIRRORING_HORIZONTAL;
 
  472                    "not supported with this MSDK version.\n");
 
  482             if (MFX_ANGLE_90 == vpp->
rotate || MFX_ANGLE_270 == vpp->
rotate) {
 
  484                 FFSWAP(
int, outlink->
w, outlink->
h);
 
  489                    "not supported with this MSDK version.\n");
 
  500                    "not supported with this MSDK version.\n");
 
  511                 mode = MFX_SCALING_MODE_VENDOR + 
mode - 2;
 
  518                    "option is not supported with this MSDK version.\n");
 
  521 #undef INIT_MFX_EXTBUF 
  522 #undef SET_MFX_PARAM_FIELD 
  532         if (
inlink->hw_frames_ctx)
 
  563         if (in || qsv->
eof) {
 
  631 #define DEFINE_QSV_FILTER(x, sn, ln, fmts) \ 
  632 static const AVClass x##_class = { \ 
  633     .class_name = #sn "_qsv", \ 
  634     .item_name  = av_default_item_name, \ 
  635     .option     = x##_options, \ 
  636     .version    = LIBAVUTIL_VERSION_INT, \ 
  638 const AVFilter ff_vf_##sn##_qsv = { \ 
  639     .name           = #sn "_qsv", \ 
  640     .description    = NULL_IF_CONFIG_SMALL("Quick Sync Video " #ln), \ 
  641     .preinit        = x##_preinit, \ 
  643     .uninit         = vpp_uninit, \ 
  644     .priv_size      = sizeof(VPPContext), \ 
  645     .priv_class     = &x##_class, \ 
  646     FILTER_INPUTS(vpp_inputs), \ 
  647     FILTER_OUTPUTS(vpp_outputs), \ 
  649     .activate       = activate, \ 
  650     .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, \ 
  653 #if CONFIG_VPP_QSV_FILTER 
  655 static const AVOption vpp_options[] = {
 
  656     { 
"deinterlace", 
"deinterlace mode: 0=off, 1=bob, 2=advanced", 
OFFSET(deinterlace), 
AV_OPT_TYPE_INT,      { .i64 = 0 }, 0, MFX_DEINTERLACING_ADVANCED, .flags = 
FLAGS, 
"deinterlace" },
 
  657     { 
"bob",         
"Bob deinterlace mode.",                      0,                   
AV_OPT_TYPE_CONST,    { .i64 = MFX_DEINTERLACING_BOB },            .flags = 
FLAGS, 
"deinterlace" },
 
  658     { 
"advanced",    
"Advanced deinterlace mode. ",                0,                   
AV_OPT_TYPE_CONST,    { .i64 = MFX_DEINTERLACING_ADVANCED },       .flags = 
FLAGS, 
"deinterlace" },
 
  683     { 
"w",      
"Output video width(0=input video width, -1=keep input video aspect)",  
OFFSET(ow), 
AV_OPT_TYPE_STRING, { .str=
"cw" }, 0, 255, .flags = 
FLAGS },
 
  684     { 
"width",  
"Output video width(0=input video width, -1=keep input video aspect)",  
OFFSET(ow), 
AV_OPT_TYPE_STRING, { .str=
"cw" }, 0, 255, .flags = 
FLAGS },
 
  685     { 
"h",      
"Output video height(0=input video height, -1=keep input video aspect)", 
OFFSET(oh), 
AV_OPT_TYPE_STRING, { .str=
"w*ch/cw" }, 0, 255, .flags = 
FLAGS },
 
  686     { 
"height", 
"Output video height(0=input video height, -1=keep input video aspect)", 
OFFSET(oh), 
AV_OPT_TYPE_STRING, { .str=
"w*ch/cw" }, 0, 255, .flags = 
FLAGS },
 
  688     { 
"async_depth", 
"Internal parallelization depth, the higher the value the higher the latency.", 
OFFSET(qsv.async_depth), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = 
FLAGS },
 
  690     { 
"scale_mode", 
"scaling & format conversion mode (mode compute(3), vd(4) and ve(5) are only available on some platforms)", 
OFFSET(scale_mode), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 5, .flags = 
FLAGS, 
"scale mode" },
 
  692     { 
"scale_mode", 
"scaling & format conversion mode", 
OFFSET(scale_mode), 
AV_OPT_TYPE_INT, { .i64 = MFX_SCALING_MODE_DEFAULT }, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, .flags = 
FLAGS, 
"scale mode" },
 
  694     { 
"auto",      
"auto mode",             0,    
AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_DEFAULT},  INT_MIN, INT_MAX, 
FLAGS, 
"scale mode"},
 
  695     { 
"low_power", 
"low power mode",        0,    
AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX, 
FLAGS, 
"scale mode"},
 
  696     { 
"hq",        
"high quality mode",     0,    
AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_QUALITY},  INT_MIN, INT_MAX, 
FLAGS, 
"scale mode"},
 
  703     { 
"rate", 
"Generate output at frame rate or field rate, available only for deinterlace mode",
 
  705     { 
"frame", 
"Output at frame rate (one frame of output for each field-pair)",
 
  707     { 
"field", 
"Output at field rate (one frame of output for each field)",
 
  736                          &
ctx->inputs[0]->outcfg.formats);
 
  740                           &
ctx->outputs[0]->incfg.formats);
 
  747 #if CONFIG_SCALE_QSV_FILTER 
  749 static const AVOption qsvscale_options[] = {
 
  750     { 
"w",      
"Output video width(0=input video width, -1=keep input video aspect)",  
OFFSET(ow), 
AV_OPT_TYPE_STRING, { .str = 
"iw"   }, .flags = 
FLAGS },
 
  751     { 
"h",      
"Output video height(0=input video height, -1=keep input video aspect)", 
OFFSET(oh), 
AV_OPT_TYPE_STRING, { .str = 
"ih"   }, .flags = 
FLAGS },
 
  755     { 
"mode",      
"scaling & format conversion mode (mode compute(3), vd(4) and ve(5) are only available on some platforms)",    
OFFSET(scale_mode),    
AV_OPT_TYPE_INT,    { .i64 = 0}, 0, 5, 
FLAGS, 
"mode"},
 
  757     { 
"mode",      
"scaling & format conversion mode",    
OFFSET(scale_mode),    
AV_OPT_TYPE_INT,    { .i64 = MFX_SCALING_MODE_DEFAULT}, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, 
FLAGS, 
"mode"},
 
  759     { 
"low_power", 
"low power mode",        0,             
AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX, 
FLAGS, 
"mode"},
 
  760     { 
"hq",        
"high quality mode",     0,             
AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_QUALITY},  INT_MIN, INT_MAX, 
FLAGS, 
"mode"},
 
  784 #if CONFIG_DEINTERLACE_QSV_FILTER 
  786 static const AVOption qsvdeint_options[] = {
 
  787     { 
"mode", 
"set deinterlace mode", 
OFFSET(deinterlace),   
AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, 
FLAGS, 
"mode"},
 
  788     { 
"bob",   
"bob algorithm",                  0, 
AV_OPT_TYPE_CONST,      {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, 
FLAGS, 
"mode"},
 
  789     { 
"advanced", 
"Motion adaptive algorithm",   0, 
AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, 
FLAGS, 
"mode"},