Go to the documentation of this file.
24 #include <mfx/mfxvideo.h>
72 #define QSV_HAVE_SCALING_CONFIG QSV_VERSION_ATLEAST(1, 19)
73 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
95 #if QSV_HAVE_SCALING_CONFIG
96 mfxExtVPPScaling scale_conf;
126 if (!strcmp(
s->format_str,
"same")) {
144 MFXClose(
s->session);
150 s->nb_mem_ids_in = 0;
151 s->nb_mem_ids_out = 0;
155 s->nb_surface_ptrs_in = 0;
156 s->nb_surface_ptrs_out = 0;
160 int out_width,
int out_height)
174 if (!
ctx->inputs[0]->hw_frames_ctx) {
179 in_frames_hwctx = in_frames_ctx->
hwctx;
188 out_frames_hwctx = out_frames_ctx->
hwctx;
208 info->CropW = out_width;
209 info->CropH = out_height;
215 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
216 mfxFrameAllocResponse *resp)
221 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
222 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
223 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
224 return MFX_ERR_UNSUPPORTED;
226 if (req->Type & MFX_MEMTYPE_FROM_VPPIN) {
227 resp->mids =
s->mem_ids_in;
228 resp->NumFrameActual =
s->nb_mem_ids_in;
230 resp->mids =
s->mem_ids_out;
231 resp->NumFrameActual =
s->nb_mem_ids_out;
237 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
242 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
244 return MFX_ERR_UNSUPPORTED;
247 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
249 return MFX_ERR_UNSUPPORTED;
254 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
255 mfxHDLPair *pair_src = (mfxHDLPair*)mid;
257 pair_dst->first = pair_src->first;
259 if (pair_src->second != (mfxMemId)MFX_INFINITE)
260 pair_dst->second = pair_src->second;
274 int opaque = !!(in_frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
276 mfxHDL handle =
NULL;
277 mfxHandleType handle_type;
287 err = MFXQueryIMPL(device_hwctx->
session, &impl);
288 if (err == MFX_ERR_NONE)
289 err = MFXQueryVersion(device_hwctx->
session, &ver);
290 if (err != MFX_ERR_NONE) {
296 handle_type = MFX_HANDLE_VA_DISPLAY;
298 handle_type = MFX_HANDLE_D3D11_DEVICE;
300 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
306 err = MFXVideoCORE_GetHandle(device_hwctx->
session, handle_type, &handle);
316 err = MFXInit(impl, &ver, &
s->session);
317 if (err != MFX_ERR_NONE) {
323 err = MFXVideoCORE_SetHandle(
s->session, handle_type, handle);
324 if (err != MFX_ERR_NONE)
329 err = MFXJoinSession(device_hwctx->
session,
s->session);
330 if (err != MFX_ERR_NONE)
334 memset(&par, 0,
sizeof(par));
338 sizeof(*
s->surface_ptrs_in));
339 if (!
s->surface_ptrs_in)
342 s->surface_ptrs_in[
i] = in_frames_hwctx->
surfaces +
i;
346 sizeof(*
s->surface_ptrs_out));
347 if (!
s->surface_ptrs_out)
350 s->surface_ptrs_out[
i] = out_frames_hwctx->
surfaces +
i;
353 s->opaque_alloc.In.Surfaces =
s->surface_ptrs_in;
354 s->opaque_alloc.In.NumSurface =
s->nb_surface_ptrs_in;
355 s->opaque_alloc.In.Type = in_frames_hwctx->
frame_type;
357 s->opaque_alloc.Out.Surfaces =
s->surface_ptrs_out;
358 s->opaque_alloc.Out.NumSurface =
s->nb_surface_ptrs_out;
359 s->opaque_alloc.Out.Type = out_frames_hwctx->
frame_type;
361 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
362 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
364 s->ext_buffers[
s->num_ext_buf++] = (mfxExtBuffer*)&
s->opaque_alloc;
366 par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
368 mfxFrameAllocator frame_allocator = {
378 sizeof(*
s->mem_ids_in));
382 s->mem_ids_in[
i] = in_frames_hwctx->
surfaces[
i].Data.MemId;
386 sizeof(*
s->mem_ids_out));
390 s->mem_ids_out[
i] = out_frames_hwctx->
surfaces[
i].Data.MemId;
393 err = MFXVideoCORE_SetFrameAllocator(
s->session, &frame_allocator);
394 if (err != MFX_ERR_NONE)
397 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
400 #if QSV_HAVE_SCALING_CONFIG
401 memset(&
s->scale_conf, 0,
sizeof(mfxExtVPPScaling));
402 s->scale_conf.Header.BufferId = MFX_EXTBUFF_VPP_SCALING;
403 s->scale_conf.Header.BufferSz =
sizeof(mfxExtVPPScaling);
404 s->scale_conf.ScalingMode =
s->mode;
405 s->ext_buffers[
s->num_ext_buf++] = (mfxExtBuffer*)&
s->scale_conf;
409 par.ExtParam =
s->ext_buffers;
410 par.NumExtParam =
s->num_ext_buf;
414 par.vpp.In = in_frames_hwctx->
surfaces[0].Info;
415 par.vpp.Out = out_frames_hwctx->
surfaces[0].Info;
421 par.vpp.In.FrameRateExtN = 25;
422 par.vpp.In.FrameRateExtD = 1;
423 par.vpp.Out.FrameRateExtN = 25;
424 par.vpp.Out.FrameRateExtD = 1;
430 err = MFXVideoVPP_Init(
s->session, &par);
433 "Error opening the VPP for scaling");
436 "Warning in VPP initialization");
444 int out_width,
int out_height)
467 double var_values[
VARS_NB], res;
480 (
double)
inlink->sample_aspect_ratio.num /
inlink->sample_aspect_ratio.den : 1;
504 if (
w < -1 ||
h < -1) {
508 if (
w == -1 &&
h == -1)
520 if (
w > INT_MAX ||
h > INT_MAX ||
535 if (
inlink->sample_aspect_ratio.num)
538 inlink->sample_aspect_ratio);
546 "Error when evaluating the expression '%s'\n", expr);
556 mfxSyncPoint sync =
NULL;
569 err = MFXVideoVPP_RunFrameVPPAsync(
s->session,
570 (mfxFrameSurface1*)in->
data[3],
571 (mfxFrameSurface1*)
out->data[3],
573 if (err == MFX_WRN_DEVICE_BUSY)
575 }
while (err == MFX_WRN_DEVICE_BUSY);
589 err = MFXVideoCORE_SyncOperation(
s->session, sync, 1000);
590 }
while (err == MFX_WRN_IN_EXECUTION);
600 out->width = outlink->
w;
601 out->height = outlink->
h;
603 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
616 #define OFFSET(x) offsetof(QSVScaleContext, x)
617 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
623 #if QSV_HAVE_SCALING_CONFIG
624 {
"mode",
"set scaling mode",
OFFSET(
mode),
AV_OPT_TYPE_INT, { .i64 = MFX_SCALING_MODE_DEFAULT}, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY,
FLAGS,
"mode"},
625 {
"low_power",
"low power mode", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX,
FLAGS,
"mode"},
626 {
"hq",
"high quality mode", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_QUALITY}, INT_MIN, INT_MAX,
FLAGS,
"mode"},
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static const char *const var_names[]
#define QSV_HAVE_SCALING_CONFIG
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static av_cold int qsvscale_init(AVFilterContext *ctx)
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
This structure describes decoded (raw) audio or video data.
This struct is allocated as AVHWDeviceContext.hwctx.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static const AVFilterPad qsvscale_outputs[]
#define AV_LOG_VERBOSE
Detailed information.
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
const char * name
Filter name.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
char * h_expr
height expression string
#define MFX_IMPL_VIA_MASK(impl)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static int init_out_session(AVFilterContext *ctx)
A filter pad used for either input or output.
int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
mfxFrameSurface1 ** surface_ptrs_in
mfxFrameSurface1 ** surface_ptrs_out
int av_usleep(unsigned usec)
Sleep for a period of time.
#define FILTER_INPUTS(array)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
enum AVPixelFormat format
Output sw format.
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
mfxFrameSurface1 * surfaces
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
char * w_expr
width expression string
int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, const char *error_string)
AVFilterLink ** inputs
array of pointers to input links
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
mfxExtBuffer * ext_buffers[1+QSV_HAVE_SCALING_CONFIG]
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
const AVFilter ff_vf_scale_qsv
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
AVFilterContext * src
source filter
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
static int qsvscale_config_props(AVFilterLink *outlink)
static const AVOption options[]
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
static int init_out_pool(AVFilterContext *ctx, int out_width, int out_height)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
const char * name
Pad name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void * av_calloc(size_t nmemb, size_t size)
This struct describes a set or pool of "hardware" frames (i.e.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
static const AVClass qsvscale_class
int h
agreed upon image height
static const AVFilterPad qsvscale_inputs[]
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
This struct is allocated as AVHWFramesContext.hwctx.
int initial_pool_size
Initial size of the frame pool.
static int qsvscale_filter_frame(AVFilterLink *link, AVFrame *in)
static int init_scale_session(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
#define FILTER_OUTPUTS(array)
static av_cold void qsvscale_uninit(AVFilterContext *ctx)
int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
mfxExtOpaqueSurfaceAlloc opaque_alloc
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.