24 #include <mfx/mfxvideo.h>
164 int out_width,
int out_height)
183 in_frames_hwctx = in_frames_ctx->
hwctx;
192 out_frames_hwctx = out_frames_ctx->
hwctx;
210 for (i = 0; i < out_frames_hwctx->
nb_surfaces; i++) {
211 mfxFrameInfo *info = &out_frames_hwctx->
surfaces[i].Info;
212 info->CropW = out_width;
213 info->CropH = out_height;
219 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
220 mfxFrameAllocResponse *resp)
225 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
226 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
227 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
228 return MFX_ERR_UNSUPPORTED;
230 if (req->Type & MFX_MEMTYPE_FROM_VPPIN) {
241 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
246 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
248 return MFX_ERR_UNSUPPORTED;
251 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
253 return MFX_ERR_UNSUPPORTED;
263 MFX_HANDLE_VA_DISPLAY,
264 MFX_HANDLE_D3D9_DEVICE_MANAGER,
265 MFX_HANDLE_D3D11_DEVICE,
278 int opaque = !!(in_frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
280 mfxHDL handle =
NULL;
289 err = MFXQueryIMPL(device_hwctx->
session, &impl);
290 if (err == MFX_ERR_NONE)
291 err = MFXQueryVersion(device_hwctx->
session, &ver);
292 if (err != MFX_ERR_NONE) {
299 if (err == MFX_ERR_NONE) {
305 if (err != MFX_ERR_NONE) {
312 err = MFXInit(impl, &ver, &s->
session);
313 if (err != MFX_ERR_NONE) {
319 err = MFXVideoCORE_SetHandle(s->
session, handle_type, handle);
320 if (err != MFX_ERR_NONE)
326 if (err != MFX_ERR_NONE)
330 memset(&par, 0,
sizeof(par));
345 for (i = 0; i < out_frames_hwctx->
nb_surfaces; i++)
357 s->
opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
365 par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
367 mfxFrameAllocator frame_allocator = {
388 for (i = 0; i < out_frames_hwctx->
nb_surfaces; i++)
392 err = MFXVideoCORE_SetFrameAllocator(s->
session, &frame_allocator);
393 if (err != MFX_ERR_NONE)
396 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
401 par.vpp.In = in_frames_hwctx->
surfaces[0].Info;
402 par.vpp.Out = out_frames_hwctx->
surfaces[0].Info;
408 par.vpp.In.FrameRateExtN = 25;
409 par.vpp.In.FrameRateExtD = 1;
410 par.vpp.Out.FrameRateExtN = 25;
411 par.vpp.Out.FrameRateExtD = 1;
413 err = MFXVideoVPP_Init(s->
session, &par);
414 if (err != MFX_ERR_NONE) {
423 int out_width,
int out_height)
446 double var_values[
VARS_NB], res;
457 var_values[
VAR_A] = (double) inlink->
w / inlink->
h;
483 if (w < -1 || h < -1) {
487 if (w == -1 && h == -1)
499 if (w > INT_MAX || h > INT_MAX ||
500 (h * inlink->
w) > INT_MAX ||
501 (w * inlink->
h) > INT_MAX)
512 inlink->
w, inlink->
h, outlink->
w, outlink->
h);
516 outlink->
w*inlink->
h},
525 "Error when evaluating the expression '%s'\n", expr);
535 mfxSyncPoint sync =
NULL;
548 err = MFXVideoVPP_RunFrameVPPAsync(s->
session,
549 (mfxFrameSurface1*)in->
data[3],
550 (mfxFrameSurface1*)out->
data[3],
552 if (err == MFX_WRN_DEVICE_BUSY)
554 }
while (err == MFX_WRN_DEVICE_BUSY);
556 if (err < 0 || !sync) {
563 err = MFXVideoCORE_SyncOperation(s->
session, sync, 1000);
564 }
while (err == MFX_WRN_IN_EXECUTION);
591 #define OFFSET(x) offsetof(QSVScaleContext, x)
592 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
635 .priv_class = &qsvscale_class,
637 .
inputs = qsvscale_inputs,
static const AVClass qsvscale_class
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
This structure describes decoded (raw) audio or video data.
enum AVPixelFormat format
Output sw format.
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
#define LIBAVUTIL_VERSION_INT
Main libavfilter public API header.
mfxHandleType handle_type
This struct is allocated as AVHWFramesContext.hwctx.
int h
agreed upon image height
const char * av_default_item_name(void *ptr)
Return the context name.
int width
The allocated dimensions of the frames in this pool.
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
int av_usleep(unsigned usec)
Sleep for a period of time.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int qsvscale_query_formats(AVFilterContext *ctx)
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
#define AV_LOG_VERBOSE
Detailed information.
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static int qsvscale_config_props(AVFilterLink *outlink)
static const AVFilterPad qsvscale_outputs[]
mfxExtOpaqueSurfaceAlloc opaque_alloc
This struct is allocated as AVHWDeviceContext.hwctx.
A filter pad used for either input or output.
A link between two filters.
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.
static const AVOption options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int qsvscale_filter_frame(AVFilterLink *link, AVFrame *in)
void * priv
private data for use by the filter
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
int w
agreed upon image width
static int init_scale_session(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
common internal API header
int initial_pool_size
Initial size of the frame pool.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames...
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
static int init_out_session(AVFilterContext *ctx)
AVFilterContext * src
source filter
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
#define FF_ARRAY_ELEMS(a)
mfxFrameSurface1 * surfaces
uint8_t * data
The data buffer.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
This struct describes a set or pool of "hardware" frames (i.e.
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
const char * name
Filter name.
static const AVFilterPad qsvscale_inputs[]
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
mfxFrameSurface1 ** surface_ptrs_in
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
static int qsvscale_init(AVFilterContext *ctx)
mfxFrameSurface1 ** surface_ptrs_out
static void qsvscale_uninit(AVFilterContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
common internal and external API header
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static int init_out_pool(AVFilterContext *ctx, int out_width, int out_height)
static const mfxHandleType handle_types[]
AVFilterContext * dst
dest filter
mfxExtBuffer * ext_buffers[1]
char * h_expr
height expression string
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Intel Quick Sync Video VPP base function.
static const char *const var_names[]
An API-specific header for AV_HWDEVICE_TYPE_QSV.
char * w_expr
width expression string
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
simple arithmetic expression evaluator
void * av_mallocz_array(size_t nmemb, size_t size)