45 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
66 mfxExtOpaqueSurfaceAlloc opaque_alloc;
95 s->work_frames = cur->
next;
105 s->nb_surface_ptrs = 0;
108 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
109 mfxFrameAllocResponse *resp)
114 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
115 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
116 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
117 return MFX_ERR_UNSUPPORTED;
119 resp->mids =
s->mem_ids;
120 resp->NumFrameActual =
s->nb_mem_ids;
125 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
130 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
132 return MFX_ERR_UNSUPPORTED;
135 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
137 return MFX_ERR_UNSUPPORTED;
142 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
143 mfxHDLPair *pair_src = (mfxHDLPair*)mid;
145 pair_dst->first = pair_src->first;
147 if (pair_src->second != (mfxMemId)MFX_INFINITE)
148 pair_dst->second = pair_src->second;
160 mfxHDL handle =
NULL;
161 mfxHandleType handle_type;
169 opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
172 err = MFXQueryIMPL(device_hwctx->session, &impl);
173 if (err == MFX_ERR_NONE)
174 err = MFXQueryVersion(device_hwctx->session, &ver);
175 if (err != MFX_ERR_NONE) {
181 handle_type = MFX_HANDLE_VA_DISPLAY;
183 handle_type = MFX_HANDLE_D3D11_DEVICE;
185 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
191 err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
207 err = MFXVideoCORE_SetHandle(
s->session, handle_type, handle);
208 if (err != MFX_ERR_NONE)
213 err = MFXJoinSession(device_hwctx->session,
s->session);
214 if (err != MFX_ERR_NONE)
218 memset(&par, 0,
sizeof(par));
220 s->deint_conf.Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
221 s->deint_conf.Header.BufferSz =
sizeof(
s->deint_conf);
222 s->deint_conf.Mode =
s->mode;
224 s->ext_buffers[
s->num_ext_buffers++] = (mfxExtBuffer *)&
s->deint_conf;
227 mfxFrameAllocator frame_allocator = {
236 s->mem_ids =
av_calloc(hw_frames_hwctx->nb_surfaces,
237 sizeof(*
s->mem_ids));
240 for (
i = 0;
i < hw_frames_hwctx->nb_surfaces;
i++)
241 s->mem_ids[
i] = hw_frames_hwctx->surfaces[
i].Data.MemId;
242 s->nb_mem_ids = hw_frames_hwctx->nb_surfaces;
244 err = MFXVideoCORE_SetFrameAllocator(
s->session, &frame_allocator);
245 if (err != MFX_ERR_NONE)
248 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
252 s->surface_ptrs =
av_calloc(hw_frames_hwctx->nb_surfaces,
253 sizeof(*
s->surface_ptrs));
255 if (!
s->surface_ptrs)
257 for (
i = 0;
i < hw_frames_hwctx->nb_surfaces;
i++)
258 s->surface_ptrs[
i] = hw_frames_hwctx->surfaces +
i;
259 s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
261 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
262 s->opaque_alloc.In.NumSurface =
s->nb_surface_ptrs;
263 s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
265 s->opaque_alloc.Out =
s->opaque_alloc.In;
267 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
268 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
270 s->ext_buffers[
s->num_ext_buffers++] = (mfxExtBuffer *)&
s->opaque_alloc;
272 par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
276 par.ExtParam =
s->ext_buffers;
277 par.NumExtParam =
s->num_ext_buffers;
281 par.vpp.In = hw_frames_hwctx->surfaces[0].Info;
283 par.vpp.In.CropW =
ctx->inputs[0]->w;
284 par.vpp.In.CropH =
ctx->inputs[0]->h;
286 if (
ctx->inputs[0]->frame_rate.num) {
287 par.vpp.In.FrameRateExtN =
ctx->inputs[0]->frame_rate.num;
288 par.vpp.In.FrameRateExtD =
ctx->inputs[0]->frame_rate.den;
290 par.vpp.In.FrameRateExtN =
ctx->inputs[0]->time_base.num;
291 par.vpp.In.FrameRateExtD =
ctx->inputs[0]->time_base.den;
294 par.vpp.Out = par.vpp.In;
296 if (
ctx->outputs[0]->frame_rate.num) {
297 par.vpp.Out.FrameRateExtN =
ctx->outputs[0]->frame_rate.num;
298 par.vpp.Out.FrameRateExtD =
ctx->outputs[0]->frame_rate.den;
300 par.vpp.Out.FrameRateExtN =
ctx->outputs[0]->time_base.num;
301 par.vpp.Out.FrameRateExtD =
ctx->outputs[0]->time_base.den;
308 err = MFXVideoVPP_Init(
s->session, &par);
311 "Error opening the VPP for deinterlacing");
314 "Warning in VPP initialization");
337 if (!
inlink->hw_frames_ctx) {
343 if (!
s->hw_frames_ctx)
365 if (!cur->
surface.Data.Locked) {
380 last = &
s->work_frames;
382 if (!
frame->queued) {
401 mfxFrameSurface1 **surface)
421 MFX_PICSTRUCT_FIELD_BFF);
423 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
425 MFX_PICSTRUCT_FIELD_BFF;
427 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
429 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
431 if (
ctx->inputs[0]->frame_rate.num) {
432 qf->
surface.Info.FrameRateExtN =
ctx->inputs[0]->frame_rate.num;
433 qf->
surface.Info.FrameRateExtD =
ctx->inputs[0]->frame_rate.den;
435 qf->
surface.Info.FrameRateExtN =
ctx->inputs[0]->time_base.num;
436 qf->
surface.Info.FrameRateExtD =
ctx->inputs[0]->time_base.den;
440 ctx->inputs[0]->time_base,
450 mfxFrameSurface1 *surf_in)
457 mfxFrameSurface1 *surf_out;
458 mfxSyncPoint sync =
NULL;
468 surf_out = (mfxFrameSurface1*)
out->data[3];
469 surf_out->Info.CropW = outlink->
w;
470 surf_out->Info.CropH = outlink->
h;
471 surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
474 err = MFXVideoVPP_RunFrameVPPAsync(
s->session, surf_in, surf_out,
476 if (err == MFX_WRN_DEVICE_BUSY)
478 }
while (err == MFX_WRN_DEVICE_BUSY);
480 if (err == MFX_ERR_MORE_DATA) {
485 if (err < 0 && err != MFX_ERR_MORE_SURFACE) {
495 if (err == MFX_ERR_MORE_SURFACE)
499 err = MFXVideoCORE_SyncOperation(
s->session, sync, 1000);
500 }
while (err == MFX_WRN_IN_EXECUTION);
510 out->width = outlink->w;
511 out->height = outlink->h;
512 out->interlaced_frame = 0;
515 if (
out->pts ==
s->last_pts)
517 s->last_pts =
out->pts;
519 if (outlink->frame_rate.num && outlink->frame_rate.den)
538 mfxFrameSurface1 *surf_in;
563 #define OFFSET(x) offsetof(QSVDeintContext, x)
564 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
566 {
"mode",
"set deinterlace mode",
OFFSET(
mode),
AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
567 {
"bob",
"bob algorithm", 0,
AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
568 {
"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",