24 #include <mfx/mfxvideo.h>
45 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
93 s->work_frames = cur->
next;
103 s->nb_surface_ptrs = 0;
106 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
107 mfxFrameAllocResponse *resp)
112 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
113 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
114 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
115 return MFX_ERR_UNSUPPORTED;
117 resp->mids =
s->mem_ids;
118 resp->NumFrameActual =
s->nb_mem_ids;
123 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
128 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
130 return MFX_ERR_UNSUPPORTED;
133 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
135 return MFX_ERR_UNSUPPORTED;
140 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
141 mfxHDLPair *pair_src = (mfxHDLPair*)mid;
143 pair_dst->first = pair_src->first;
145 if (pair_src->second != (mfxMemId)MFX_INFINITE)
146 pair_dst->second = pair_src->second;
158 int opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
160 mfxHDL handle =
NULL;
161 mfxHandleType handle_type;
169 err = MFXQueryIMPL(device_hwctx->session, &impl);
170 if (err == MFX_ERR_NONE)
171 err = MFXQueryVersion(device_hwctx->session, &ver);
172 if (err != MFX_ERR_NONE) {
178 handle_type = MFX_HANDLE_VA_DISPLAY;
180 handle_type = MFX_HANDLE_D3D11_DEVICE;
182 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
188 err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
198 err = MFXInit(impl, &ver, &
s->session);
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 s->surface_ptrs =
av_calloc(hw_frames_hwctx->nb_surfaces,
228 sizeof(*
s->surface_ptrs));
229 if (!
s->surface_ptrs)
231 for (
i = 0;
i < hw_frames_hwctx->nb_surfaces;
i++)
232 s->surface_ptrs[
i] = hw_frames_hwctx->surfaces +
i;
233 s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
235 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
236 s->opaque_alloc.In.NumSurface =
s->nb_surface_ptrs;
237 s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
239 s->opaque_alloc.Out =
s->opaque_alloc.In;
241 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
242 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
244 s->ext_buffers[
s->num_ext_buffers++] = (mfxExtBuffer *)&
s->opaque_alloc;
246 par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
248 mfxFrameAllocator frame_allocator = {
257 s->mem_ids =
av_calloc(hw_frames_hwctx->nb_surfaces,
258 sizeof(*
s->mem_ids));
261 for (
i = 0;
i < hw_frames_hwctx->nb_surfaces;
i++)
262 s->mem_ids[
i] = hw_frames_hwctx->surfaces[
i].Data.MemId;
263 s->nb_mem_ids = hw_frames_hwctx->nb_surfaces;
265 err = MFXVideoCORE_SetFrameAllocator(
s->session, &frame_allocator);
266 if (err != MFX_ERR_NONE)
269 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
272 par.ExtParam =
s->ext_buffers;
273 par.NumExtParam =
s->num_ext_buffers;
277 par.vpp.In = hw_frames_hwctx->surfaces[0].Info;
279 par.vpp.In.CropW =
ctx->inputs[0]->w;
280 par.vpp.In.CropH =
ctx->inputs[0]->h;
282 if (
ctx->inputs[0]->frame_rate.num) {
283 par.vpp.In.FrameRateExtN =
ctx->inputs[0]->frame_rate.num;
284 par.vpp.In.FrameRateExtD =
ctx->inputs[0]->frame_rate.den;
286 par.vpp.In.FrameRateExtN =
ctx->inputs[0]->time_base.num;
287 par.vpp.In.FrameRateExtD =
ctx->inputs[0]->time_base.den;
290 par.vpp.Out = par.vpp.In;
292 if (
ctx->outputs[0]->frame_rate.num) {
293 par.vpp.Out.FrameRateExtN =
ctx->outputs[0]->frame_rate.num;
294 par.vpp.Out.FrameRateExtD =
ctx->outputs[0]->frame_rate.den;
296 par.vpp.Out.FrameRateExtN =
ctx->outputs[0]->time_base.num;
297 par.vpp.Out.FrameRateExtD =
ctx->outputs[0]->time_base.den;
304 err = MFXVideoVPP_Init(
s->session, &par);
307 "Error opening the VPP for deinterlacing");
310 "Warning in VPP initialization");
333 if (!
inlink->hw_frames_ctx) {
339 if (!
s->hw_frames_ctx)
361 if (!cur->
surface.Data.Locked) {
376 last = &
s->work_frames;
378 if (!
frame->queued) {
397 mfxFrameSurface1 **surface)
417 MFX_PICSTRUCT_FIELD_BFF);
419 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
421 MFX_PICSTRUCT_FIELD_BFF;
423 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
425 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
427 if (
ctx->inputs[0]->frame_rate.num) {
428 qf->
surface.Info.FrameRateExtN =
ctx->inputs[0]->frame_rate.num;
429 qf->
surface.Info.FrameRateExtD =
ctx->inputs[0]->frame_rate.den;
431 qf->
surface.Info.FrameRateExtN =
ctx->inputs[0]->time_base.num;
432 qf->
surface.Info.FrameRateExtD =
ctx->inputs[0]->time_base.den;
436 ctx->inputs[0]->time_base,
446 mfxFrameSurface1 *surf_in)
453 mfxFrameSurface1 *surf_out;
454 mfxSyncPoint sync =
NULL;
464 surf_out = (mfxFrameSurface1*)
out->data[3];
465 surf_out->Info.CropW = outlink->
w;
466 surf_out->Info.CropH = outlink->
h;
467 surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
470 err = MFXVideoVPP_RunFrameVPPAsync(
s->session, surf_in, surf_out,
472 if (err == MFX_WRN_DEVICE_BUSY)
474 }
while (err == MFX_WRN_DEVICE_BUSY);
476 if (err == MFX_ERR_MORE_DATA) {
481 if (err < 0 && err != MFX_ERR_MORE_SURFACE) {
491 if (err == MFX_ERR_MORE_SURFACE)
495 err = MFXVideoCORE_SyncOperation(
s->session, sync, 1000);
496 }
while (err == MFX_WRN_IN_EXECUTION);
506 out->width = outlink->w;
507 out->height = outlink->h;
508 out->interlaced_frame = 0;
511 if (
out->pts ==
s->last_pts)
513 s->last_pts =
out->pts;
529 mfxFrameSurface1 *surf_in;
554 #define OFFSET(x) offsetof(QSVDeintContext, x)
555 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
557 {
"mode",
"set deinterlace mode",
OFFSET(
mode),
AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
558 {
"bob",
"bob algorithm", 0,
AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
559 {
"advanced",
"Motion adaptive algorithm", 0,
AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
588 .
name =
"deinterlace_qsv",