Go to the documentation of this file.
24 #include <mfx/mfxvideo.h>
91 s->work_frames = cur->
next;
101 s->nb_surface_ptrs = 0;
118 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
119 mfxFrameAllocResponse *resp)
124 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
125 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
126 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
127 return MFX_ERR_UNSUPPORTED;
129 resp->mids =
s->mem_ids;
130 resp->NumFrameActual =
s->nb_mem_ids;
135 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
140 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
142 return MFX_ERR_UNSUPPORTED;
145 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
147 return MFX_ERR_UNSUPPORTED;
157 MFX_HANDLE_VA_DISPLAY,
158 MFX_HANDLE_D3D9_DEVICE_MANAGER,
159 MFX_HANDLE_D3D11_DEVICE,
170 int opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
172 mfxHDL handle =
NULL;
181 err = MFXQueryIMPL(device_hwctx->session, &impl);
182 if (err == MFX_ERR_NONE)
183 err = MFXQueryVersion(device_hwctx->session, &ver);
184 if (err != MFX_ERR_NONE) {
190 err = MFXVideoCORE_GetHandle(device_hwctx->session,
handle_types[
i], &handle);
191 if (err == MFX_ERR_NONE) {
206 err = MFXInit(impl, &ver, &
s->session);
215 err = MFXVideoCORE_SetHandle(
s->session,
handle_type, handle);
216 if (err != MFX_ERR_NONE)
221 err = MFXJoinSession(device_hwctx->session,
s->session);
222 if (err != MFX_ERR_NONE)
226 memset(&par, 0,
sizeof(par));
228 s->deint_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
229 s->deint_conf.Header.BufferSz =
sizeof(
s->deint_conf);
230 s->deint_conf.Mode =
s->mode;
232 s->ext_buffers[
s->num_ext_buffers++] = (mfxExtBuffer *)&
s->deint_conf;
236 sizeof(*
s->surface_ptrs));
237 if (!
s->surface_ptrs)
239 for (
i = 0;
i < hw_frames_hwctx->nb_surfaces;
i++)
240 s->surface_ptrs[
i] = hw_frames_hwctx->surfaces +
i;
241 s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
243 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
244 s->opaque_alloc.In.NumSurface =
s->nb_surface_ptrs;
245 s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
247 s->opaque_alloc.Out =
s->opaque_alloc.In;
249 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
250 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
252 s->ext_buffers[
s->num_ext_buffers++] = (mfxExtBuffer *)&
s->opaque_alloc;
254 par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
256 mfxFrameAllocator frame_allocator = {
266 sizeof(*
s->mem_ids));
269 for (
i = 0;
i < hw_frames_hwctx->nb_surfaces;
i++)
270 s->mem_ids[
i] = hw_frames_hwctx->surfaces[
i].Data.MemId;
271 s->nb_mem_ids = hw_frames_hwctx->nb_surfaces;
273 err = MFXVideoCORE_SetFrameAllocator(
s->session, &frame_allocator);
274 if (err != MFX_ERR_NONE)
277 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
280 par.ExtParam =
s->ext_buffers;
281 par.NumExtParam =
s->num_ext_buffers;
285 par.vpp.In = hw_frames_hwctx->surfaces[0].Info;
287 par.vpp.In.CropW =
ctx->inputs[0]->w;
288 par.vpp.In.CropH =
ctx->inputs[0]->h;
290 if (
ctx->inputs[0]->frame_rate.num) {
291 par.vpp.In.FrameRateExtN =
ctx->inputs[0]->frame_rate.num;
292 par.vpp.In.FrameRateExtD =
ctx->inputs[0]->frame_rate.den;
294 par.vpp.In.FrameRateExtN =
ctx->inputs[0]->time_base.num;
295 par.vpp.In.FrameRateExtD =
ctx->inputs[0]->time_base.den;
298 par.vpp.Out = par.vpp.In;
300 if (
ctx->outputs[0]->frame_rate.num) {
301 par.vpp.Out.FrameRateExtN =
ctx->outputs[0]->frame_rate.num;
302 par.vpp.Out.FrameRateExtD =
ctx->outputs[0]->frame_rate.den;
304 par.vpp.Out.FrameRateExtN =
ctx->outputs[0]->time_base.num;
305 par.vpp.Out.FrameRateExtD =
ctx->outputs[0]->time_base.den;
312 err = MFXVideoVPP_Init(
s->session, &par);
315 "Error opening the VPP for deinterlacing");
318 "Warning in VPP initialization");
341 if (!
inlink->hw_frames_ctx) {
347 if (!
s->hw_frames_ctx)
369 if (!cur->
surface.Data.Locked) {
384 last = &
s->work_frames;
386 if (!
frame->queued) {
405 mfxFrameSurface1 **surface)
425 MFX_PICSTRUCT_FIELD_BFF);
427 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
429 MFX_PICSTRUCT_FIELD_BFF;
431 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
433 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
435 if (
ctx->inputs[0]->frame_rate.num) {
436 qf->
surface.Info.FrameRateExtN =
ctx->inputs[0]->frame_rate.num;
437 qf->
surface.Info.FrameRateExtD =
ctx->inputs[0]->frame_rate.den;
439 qf->
surface.Info.FrameRateExtN =
ctx->inputs[0]->time_base.num;
440 qf->
surface.Info.FrameRateExtD =
ctx->inputs[0]->time_base.den;
444 ctx->inputs[0]->time_base,
454 mfxFrameSurface1 *surf_in)
461 mfxFrameSurface1 *surf_out;
462 mfxSyncPoint sync =
NULL;
472 surf_out = (mfxFrameSurface1*)
out->data[3];
473 surf_out->Info.CropW = outlink->
w;
474 surf_out->Info.CropH = outlink->
h;
475 surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
478 err = MFXVideoVPP_RunFrameVPPAsync(
s->session, surf_in, surf_out,
480 if (err == MFX_WRN_DEVICE_BUSY)
482 }
while (err == MFX_WRN_DEVICE_BUSY);
484 if (err == MFX_ERR_MORE_DATA) {
489 if (err < 0 && err != MFX_ERR_MORE_SURFACE) {
499 if (err == MFX_ERR_MORE_SURFACE)
503 err = MFXVideoCORE_SyncOperation(
s->session, sync, 1000);
504 }
while (err == MFX_WRN_IN_EXECUTION);
514 out->width = outlink->w;
515 out->height = outlink->h;
516 out->interlaced_frame = 0;
519 if (
out->pts ==
s->last_pts)
521 s->last_pts =
out->pts;
537 mfxFrameSurface1 *surf_in;
562 #define OFFSET(x) offsetof(QSVDeintContext, x)
563 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
565 {
"mode",
"set deinterlace mode",
OFFSET(
mode),
AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
566 {
"bob",
"bob algorithm", 0,
AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
567 {
"advanced",
"Motion adaptive algorithm", 0,
AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
598 .
name =
"deinterlace_qsv",
static int qsvdeint_request_frame(AVFilterLink *outlink)
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.
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
#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.
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.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
This struct is allocated as AVHWDeviceContext.hwctx.
int top_field_first
If the content is interlaced, is top field displayed first.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
void * av_mallocz_array(size_t nmemb, size_t size)
const char * name
Filter name.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * hw_frames_ctx
mfxExtBuffer * ext_buffers[2]
static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in)
mfxHandleType handle_type
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 FF_ARRAY_ELEMS(a)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
mfxExtOpaqueSurfaceAlloc opaque_alloc
static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
mfxFrameSurface1 ** surface_ptrs
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
AVFilter ff_vf_deinterlace_qsv
static const AVFilterPad outputs[]
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
static enum AVPixelFormat pix_fmts[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_usleep(unsigned usec)
Sleep for a period of time.
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
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Rational number (pair of numerator and denominator).
int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, const char *error_string)
const char * av_default_item_name(void *ptr)
Return the context name.
mfxExtVPPDeinterlacing deint_conf
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
static const AVClass qsvdeint_class
static const mfxHandleType handle_types[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int qsvdeint_query_formats(AVFilterContext *ctx)
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
int interlaced_frame
The content of the picture is interlaced.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
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.
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
static void clear_unused_frames(QSVDeintContext *s)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Pad name.
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...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
static int process_frame(AVFilterContext *ctx, const AVFrame *in, mfxFrameSurface1 *surf_in)
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 again
int h
agreed upon image height
static const AVOption options[]
static int init_out_session(AVFilterContext *ctx)
static int qsvdeint_config_props(AVFilterLink *outlink)
static const AVFilterPad qsvdeint_outputs[]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static const AVFilterPad qsvdeint_inputs[]
This struct is allocated as AVHWFramesContext.hwctx.
A reference to a data buffer.
static int submit_frame(AVFilterContext *ctx, AVFrame *frame, mfxFrameSurface1 **surface)
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static int get_free_frame(QSVDeintContext *s, QSVFrame **f)
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
int repeat_pict
When decoding, this signals how much the picture must be delayed.