2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * Intel Quick Sync Video VPP base function
24 #include "libavutil/common.h"
25 #include "libavutil/mathematics.h"
26 #include "libavutil/hwcontext.h"
27 #include "libavutil/hwcontext_qsv.h"
28 #include "libavutil/time.h"
29 #include "libavutil/pixdesc.h"
35 #define IS_VIDEO_MEMORY(mode) (mode & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | \
36 MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
37 #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
38 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
40 typedef struct QSVFrame {
42 mfxFrameSurface1 *surface;
43 mfxFrameSurface1 surface_internal; /* for system memory */
44 struct QSVFrame *next;
47 /* abstract struct for all QSV filters */
48 struct QSVVPPContext {
50 int (*filter_frame) (AVFilterLink *outlink, AVFrame *frame);/* callback */
51 enum AVPixelFormat out_sw_format; /* Real output format */
52 mfxVideoParam vpp_param;
53 mfxFrameInfo *frame_infos; /* frame info for each input */
55 /* members related to the input/output surface */
58 QSVFrame *in_frame_list;
59 QSVFrame *out_frame_list;
60 int nb_surface_ptrs_in;
61 int nb_surface_ptrs_out;
62 mfxFrameSurface1 **surface_ptrs_in;
63 mfxFrameSurface1 **surface_ptrs_out;
65 /* MFXVPP extern parameters */
66 mfxExtOpaqueSurfaceAlloc opaque_alloc;
67 mfxExtBuffer **ext_buffers;
71 static const mfxHandleType handle_types[] = {
72 MFX_HANDLE_VA_DISPLAY,
73 MFX_HANDLE_D3D9_DEVICE_MANAGER,
74 MFX_HANDLE_D3D11_DEVICE,
77 static const AVRational default_tb = { 1, 90000 };
79 /* functions for frameAlloc */
80 static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
81 mfxFrameAllocResponse *resp)
83 QSVVPPContext *s = pthis;
86 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
87 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
88 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
89 return MFX_ERR_UNSUPPORTED;
91 if (req->Type & MFX_MEMTYPE_FROM_VPPIN) {
92 resp->mids = av_mallocz(s->nb_surface_ptrs_in * sizeof(*resp->mids));
94 return AVERROR(ENOMEM);
96 for (i = 0; i < s->nb_surface_ptrs_in; i++)
97 resp->mids[i] = s->surface_ptrs_in[i]->Data.MemId;
99 resp->NumFrameActual = s->nb_surface_ptrs_in;
101 resp->mids = av_mallocz(s->nb_surface_ptrs_out * sizeof(*resp->mids));
103 return AVERROR(ENOMEM);
105 for (i = 0; i < s->nb_surface_ptrs_out; i++)
106 resp->mids[i] = s->surface_ptrs_out[i]->Data.MemId;
108 resp->NumFrameActual = s->nb_surface_ptrs_out;
114 static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
116 av_freep(&resp->mids);
120 static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
122 return MFX_ERR_UNSUPPORTED;
125 static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
127 return MFX_ERR_UNSUPPORTED;
130 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
136 static int pix_fmt_to_mfx_fourcc(int format)
139 case AV_PIX_FMT_YUV420P:
140 return MFX_FOURCC_YV12;
141 case AV_PIX_FMT_NV12:
142 return MFX_FOURCC_NV12;
143 case AV_PIX_FMT_YUYV422:
144 return MFX_FOURCC_YUY2;
145 case AV_PIX_FMT_RGB32:
146 return MFX_FOURCC_RGB4;
149 return MFX_FOURCC_NV12;
152 static int map_frame_to_surface(AVFrame *frame, mfxFrameSurface1 *surface)
154 switch (frame->format) {
155 case AV_PIX_FMT_NV12:
156 surface->Data.Y = frame->data[0];
157 surface->Data.UV = frame->data[1];
159 case AV_PIX_FMT_YUV420P:
160 surface->Data.Y = frame->data[0];
161 surface->Data.U = frame->data[1];
162 surface->Data.V = frame->data[2];
164 case AV_PIX_FMT_YUYV422:
165 surface->Data.Y = frame->data[0];
166 surface->Data.U = frame->data[0] + 1;
167 surface->Data.V = frame->data[0] + 3;
169 case AV_PIX_FMT_RGB32:
170 surface->Data.B = frame->data[0];
171 surface->Data.G = frame->data[0] + 1;
172 surface->Data.R = frame->data[0] + 2;
173 surface->Data.A = frame->data[0] + 3;
176 return MFX_ERR_UNSUPPORTED;
178 surface->Data.Pitch = frame->linesize[0];
183 /* fill the surface info */
184 static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, AVFilterLink *link)
186 enum AVPixelFormat pix_fmt;
187 AVHWFramesContext *frames_ctx;
188 AVQSVFramesContext *frames_hwctx;
189 const AVPixFmtDescriptor *desc;
191 if (link->format == AV_PIX_FMT_QSV) {
192 if (!link->hw_frames_ctx)
193 return AVERROR(EINVAL);
195 frames_ctx = (AVHWFramesContext *)link->hw_frames_ctx->data;
196 frames_hwctx = frames_ctx->hwctx;
197 *frameinfo = frames_hwctx->surfaces[0].Info;
199 pix_fmt = link->format;
200 desc = av_pix_fmt_desc_get(pix_fmt);
204 frameinfo->CropX = 0;
205 frameinfo->CropY = 0;
206 frameinfo->Width = FFALIGN(link->w, 32);
207 frameinfo->Height = FFALIGN(link->h, 32);
208 frameinfo->PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
209 frameinfo->FourCC = pix_fmt_to_mfx_fourcc(pix_fmt);
210 frameinfo->BitDepthLuma = desc->comp[0].depth;
211 frameinfo->BitDepthChroma = desc->comp[0].depth;
212 frameinfo->Shift = desc->comp[0].depth > 8;
213 if (desc->log2_chroma_w && desc->log2_chroma_h)
214 frameinfo->ChromaFormat = MFX_CHROMAFORMAT_YUV420;
215 else if (desc->log2_chroma_w)
216 frameinfo->ChromaFormat = MFX_CHROMAFORMAT_YUV422;
218 frameinfo->ChromaFormat = MFX_CHROMAFORMAT_YUV444;
221 frameinfo->CropW = link->w;
222 frameinfo->CropH = link->h;
223 frameinfo->FrameRateExtN = link->frame_rate.num;
224 frameinfo->FrameRateExtD = link->frame_rate.den;
225 frameinfo->AspectRatioW = link->sample_aspect_ratio.num ? link->sample_aspect_ratio.num : 1;
226 frameinfo->AspectRatioH = link->sample_aspect_ratio.den ? link->sample_aspect_ratio.den : 1;
231 static void clear_unused_frames(QSVFrame *list)
234 if (list->surface && !list->surface->Data.Locked) {
235 list->surface = NULL;
236 av_frame_free(&list->frame);
242 static void clear_frame_list(QSVFrame **list)
248 *list = (*list)->next;
249 av_frame_free(&frame->frame);
254 static QSVFrame *get_free_frame(QSVFrame **list)
256 QSVFrame *out = *list;
258 for (; out; out = out->next) {
264 out = av_mallocz(sizeof(*out));
266 av_log(NULL, AV_LOG_ERROR, "Can't alloc new output frame.\n");
276 /* get the input surface */
277 static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref)
280 AVFilterContext *ctx = inlink->dst;
282 clear_unused_frames(s->in_frame_list);
284 qsv_frame = get_free_frame(&s->in_frame_list);
288 /* Turn AVFrame into mfxFrameSurface1.
289 * For video/opaque memory mode, pix_fmt is AV_PIX_FMT_QSV, and
290 * mfxFrameSurface1 is stored in AVFrame->data[3];
291 * for system memory mode, raw video data is stored in
292 * AVFrame, we should map it into mfxFrameSurface1.
294 if (!IS_SYSTEM_MEMORY(s->in_mem_mode)) {
295 if (picref->format != AV_PIX_FMT_QSV) {
296 av_log(ctx, AV_LOG_ERROR, "QSVVPP gets a wrong frame.\n");
299 qsv_frame->frame = av_frame_clone(picref);
300 qsv_frame->surface = (mfxFrameSurface1 *)qsv_frame->frame->data[3];
302 /* make a copy if the input is not padded as libmfx requires */
303 if (picref->height & 31 || picref->linesize[0] & 31) {
304 qsv_frame->frame = ff_get_video_buffer(inlink,
305 FFALIGN(inlink->w, 32),
306 FFALIGN(inlink->h, 32));
307 if (!qsv_frame->frame)
310 qsv_frame->frame->width = picref->width;
311 qsv_frame->frame->height = picref->height;
313 if (av_frame_copy(qsv_frame->frame, picref) < 0) {
314 av_frame_free(&qsv_frame->frame);
318 av_frame_copy_props(qsv_frame->frame, picref);
319 av_frame_free(&picref);
321 qsv_frame->frame = av_frame_clone(picref);
323 if (map_frame_to_surface(qsv_frame->frame,
324 &qsv_frame->surface_internal) < 0) {
325 av_log(ctx, AV_LOG_ERROR, "Unsupported frame.\n");
328 qsv_frame->surface = &qsv_frame->surface_internal;
331 qsv_frame->surface->Info = s->frame_infos[FF_INLINK_IDX(inlink)];
332 qsv_frame->surface->Data.TimeStamp = av_rescale_q(qsv_frame->frame->pts,
333 inlink->time_base, default_tb);
335 qsv_frame->surface->Info.PicStruct =
336 !qsv_frame->frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
337 (qsv_frame->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
338 MFX_PICSTRUCT_FIELD_BFF);
339 if (qsv_frame->frame->repeat_pict == 1)
340 qsv_frame->surface->Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
341 else if (qsv_frame->frame->repeat_pict == 2)
342 qsv_frame->surface->Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
343 else if (qsv_frame->frame->repeat_pict == 4)
344 qsv_frame->surface->Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
349 /* get the output surface */
350 static QSVFrame *query_frame(QSVVPPContext *s, AVFilterLink *outlink)
352 AVFilterContext *ctx = outlink->src;
356 clear_unused_frames(s->out_frame_list);
358 out_frame = get_free_frame(&s->out_frame_list);
362 /* For video memory, get a hw frame;
363 * For system memory, get a sw frame and map it into a mfx_surface. */
364 if (!IS_SYSTEM_MEMORY(s->out_mem_mode)) {
365 out_frame->frame = av_frame_alloc();
366 if (!out_frame->frame)
369 ret = av_hwframe_get_buffer(outlink->hw_frames_ctx, out_frame->frame, 0);
371 av_log(ctx, AV_LOG_ERROR, "Can't allocate a surface.\n");
375 out_frame->surface = (mfxFrameSurface1 *)out_frame->frame->data[3];
377 /* Get a frame with aligned dimensions.
378 * Libmfx need system memory being 128x64 aligned */
379 out_frame->frame = ff_get_video_buffer(outlink,
380 FFALIGN(outlink->w, 128),
381 FFALIGN(outlink->h, 64));
382 if (!out_frame->frame)
385 out_frame->frame->width = outlink->w;
386 out_frame->frame->height = outlink->h;
388 ret = map_frame_to_surface(out_frame->frame,
389 &out_frame->surface_internal);
393 out_frame->surface = &out_frame->surface_internal;
396 out_frame->surface->Info = s->vpp_param.vpp.Out;
401 /* create the QSV session */
402 static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
404 AVFilterLink *inlink = avctx->inputs[0];
405 AVFilterLink *outlink = avctx->outputs[0];
406 AVQSVFramesContext *in_frames_hwctx = NULL;
407 AVQSVFramesContext *out_frames_hwctx = NULL;
409 AVBufferRef *device_ref;
410 AVHWDeviceContext *device_ctx;
411 AVQSVDeviceContext *device_hwctx;
413 mfxHandleType handle_type;
418 if (inlink->hw_frames_ctx) {
419 AVHWFramesContext *frames_ctx = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
421 device_ref = frames_ctx->device_ref;
422 in_frames_hwctx = frames_ctx->hwctx;
424 s->in_mem_mode = in_frames_hwctx->frame_type;
426 s->surface_ptrs_in = av_mallocz_array(in_frames_hwctx->nb_surfaces,
427 sizeof(*s->surface_ptrs_in));
428 if (!s->surface_ptrs_in)
429 return AVERROR(ENOMEM);
431 for (i = 0; i < in_frames_hwctx->nb_surfaces; i++)
432 s->surface_ptrs_in[i] = in_frames_hwctx->surfaces + i;
434 s->nb_surface_ptrs_in = in_frames_hwctx->nb_surfaces;
435 } else if (avctx->hw_device_ctx) {
436 device_ref = avctx->hw_device_ctx;
437 s->in_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
439 av_log(avctx, AV_LOG_ERROR, "No hw context provided.\n");
440 return AVERROR(EINVAL);
443 device_ctx = (AVHWDeviceContext *)device_ref->data;
444 device_hwctx = device_ctx->hwctx;
446 if (outlink->format == AV_PIX_FMT_QSV) {
447 AVHWFramesContext *out_frames_ctx;
448 AVBufferRef *out_frames_ref = av_hwframe_ctx_alloc(device_ref);
450 return AVERROR(ENOMEM);
452 s->out_mem_mode = IS_OPAQUE_MEMORY(s->in_mem_mode) ?
453 MFX_MEMTYPE_OPAQUE_FRAME :
454 MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
456 out_frames_ctx = (AVHWFramesContext *)out_frames_ref->data;
457 out_frames_hwctx = out_frames_ctx->hwctx;
459 out_frames_ctx->format = AV_PIX_FMT_QSV;
460 out_frames_ctx->width = FFALIGN(outlink->w, 32);
461 out_frames_ctx->height = FFALIGN(outlink->h, 32);
462 out_frames_ctx->sw_format = s->out_sw_format;
463 out_frames_ctx->initial_pool_size = 64;
464 out_frames_hwctx->frame_type = s->out_mem_mode;
466 ret = av_hwframe_ctx_init(out_frames_ref);
468 av_buffer_unref(&out_frames_ref);
469 av_log(avctx, AV_LOG_ERROR, "Error creating frames_ctx for output pad.\n");
473 s->surface_ptrs_out = av_mallocz_array(out_frames_hwctx->nb_surfaces,
474 sizeof(*s->surface_ptrs_out));
475 if (!s->surface_ptrs_out) {
476 av_buffer_unref(&out_frames_ref);
477 return AVERROR(ENOMEM);
480 for (i = 0; i < out_frames_hwctx->nb_surfaces; i++)
481 s->surface_ptrs_out[i] = out_frames_hwctx->surfaces + i;
482 s->nb_surface_ptrs_out = out_frames_hwctx->nb_surfaces;
484 av_buffer_unref(&outlink->hw_frames_ctx);
485 outlink->hw_frames_ctx = out_frames_ref;
487 s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
489 /* extract the properties of the "master" session given to us */
490 ret = MFXQueryIMPL(device_hwctx->session, &impl);
491 if (ret == MFX_ERR_NONE)
492 ret = MFXQueryVersion(device_hwctx->session, &ver);
493 if (ret != MFX_ERR_NONE) {
494 av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
495 return AVERROR_UNKNOWN;
498 for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
499 ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], &handle);
500 if (ret == MFX_ERR_NONE) {
501 handle_type = handle_types[i];
506 if (ret != MFX_ERR_NONE) {
507 av_log(avctx, AV_LOG_ERROR, "Error getting the session handle\n");
508 return AVERROR_UNKNOWN;
511 /* create a "slave" session with those same properties, to be used for vpp */
512 ret = MFXInit(impl, &ver, &s->session);
513 if (ret != MFX_ERR_NONE) {
514 av_log(avctx, AV_LOG_ERROR, "Error initializing a session for scaling\n");
515 return AVERROR_UNKNOWN;
519 ret = MFXVideoCORE_SetHandle(s->session, handle_type, handle);
520 if (ret != MFX_ERR_NONE)
521 return AVERROR_UNKNOWN;
524 if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
525 ret = MFXJoinSession(device_hwctx->session, s->session);
526 if (ret != MFX_ERR_NONE)
527 return AVERROR_UNKNOWN;
530 if (IS_OPAQUE_MEMORY(s->in_mem_mode) || IS_OPAQUE_MEMORY(s->out_mem_mode)) {
531 s->opaque_alloc.In.Surfaces = s->surface_ptrs_in;
532 s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in;
533 s->opaque_alloc.In.Type = s->in_mem_mode;
535 s->opaque_alloc.Out.Surfaces = s->surface_ptrs_out;
536 s->opaque_alloc.Out.NumSurface = s->nb_surface_ptrs_out;
537 s->opaque_alloc.Out.Type = s->out_mem_mode;
539 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
540 s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
541 } else if (IS_VIDEO_MEMORY(s->in_mem_mode) || IS_VIDEO_MEMORY(s->out_mem_mode)) {
542 mfxFrameAllocator frame_allocator = {
544 .Alloc = frame_alloc,
546 .Unlock = frame_unlock,
547 .GetHDL = frame_get_hdl,
551 ret = MFXVideoCORE_SetFrameAllocator(s->session, &frame_allocator);
552 if (ret != MFX_ERR_NONE)
553 return AVERROR_UNKNOWN;
559 int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param)
565 s = av_mallocz(sizeof(*s));
567 return AVERROR(ENOMEM);
569 s->filter_frame = param->filter_frame;
570 if (!s->filter_frame)
571 s->filter_frame = ff_filter_frame;
572 s->out_sw_format = param->out_sw_format;
574 /* create the vpp session */
575 ret = init_vpp_session(avctx, s);
579 s->frame_infos = av_mallocz_array(avctx->nb_inputs, sizeof(*s->frame_infos));
580 if (!s->frame_infos) {
581 ret = AVERROR(ENOMEM);
585 /* Init each input's information */
586 for (i = 0; i < avctx->nb_inputs; i++) {
587 ret = fill_frameinfo_by_link(&s->frame_infos[i], avctx->inputs[i]);
592 /* Update input's frame info according to crop */
593 for (i = 0; i < param->num_crop; i++) {
594 QSVVPPCrop *crop = param->crop + i;
595 if (crop->in_idx > avctx->nb_inputs) {
596 ret = AVERROR(EINVAL);
599 s->frame_infos[crop->in_idx].CropX = crop->x;
600 s->frame_infos[crop->in_idx].CropY = crop->y;
601 s->frame_infos[crop->in_idx].CropW = crop->w;
602 s->frame_infos[crop->in_idx].CropH = crop->h;
605 s->vpp_param.vpp.In = s->frame_infos[0];
607 ret = fill_frameinfo_by_link(&s->vpp_param.vpp.Out, avctx->outputs[0]);
609 av_log(avctx, AV_LOG_ERROR, "Fail to get frame info from link.\n");
613 if (IS_OPAQUE_MEMORY(s->in_mem_mode) || IS_OPAQUE_MEMORY(s->out_mem_mode)) {
614 s->nb_ext_buffers = param->num_ext_buf + 1;
615 s->ext_buffers = av_mallocz_array(s->nb_ext_buffers, sizeof(*s->ext_buffers));
616 if (!s->ext_buffers) {
617 ret = AVERROR(ENOMEM);
621 s->ext_buffers[0] = (mfxExtBuffer *)&s->opaque_alloc;
622 for (i = 1; i < param->num_ext_buf; i++)
623 s->ext_buffers[i] = param->ext_buf[i - 1];
624 s->vpp_param.ExtParam = s->ext_buffers;
625 s->vpp_param.NumExtParam = s->nb_ext_buffers;
627 s->vpp_param.NumExtParam = param->num_ext_buf;
628 s->vpp_param.ExtParam = param->ext_buf;
631 s->vpp_param.AsyncDepth = 1;
633 if (IS_SYSTEM_MEMORY(s->in_mem_mode))
634 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_SYSTEM_MEMORY;
635 else if (IS_VIDEO_MEMORY(s->in_mem_mode))
636 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_VIDEO_MEMORY;
637 else if (IS_OPAQUE_MEMORY(s->in_mem_mode))
638 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_OPAQUE_MEMORY;
640 if (IS_SYSTEM_MEMORY(s->out_mem_mode))
641 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
642 else if (IS_VIDEO_MEMORY(s->out_mem_mode))
643 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_VIDEO_MEMORY;
644 else if (IS_OPAQUE_MEMORY(s->out_mem_mode))
645 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
647 ret = MFXVideoVPP_Init(s->session, &s->vpp_param);
649 av_log(avctx, AV_LOG_ERROR, "Failed to create a qsvvpp, ret = %d.\n", ret);
662 int ff_qsvvpp_free(QSVVPPContext **vpp)
664 QSVVPPContext *s = *vpp;
670 MFXVideoVPP_Close(s->session);
671 MFXClose(s->session);
674 /* release all the resources */
675 clear_frame_list(&s->in_frame_list);
676 clear_frame_list(&s->out_frame_list);
677 av_freep(&s->surface_ptrs_in);
678 av_freep(&s->surface_ptrs_out);
679 av_freep(&s->ext_buffers);
680 av_freep(&s->frame_infos);
686 int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref)
688 AVFilterContext *ctx = inlink->dst;
689 AVFilterLink *outlink = ctx->outputs[0];
691 QSVFrame *in_frame, *out_frame;
694 in_frame = submit_frame(s, inlink, picref);
696 av_log(ctx, AV_LOG_ERROR, "Failed to submit frame on input[%d]\n",
697 FF_INLINK_IDX(inlink));
698 return AVERROR(ENOMEM);
702 out_frame = query_frame(s, outlink);
704 av_log(ctx, AV_LOG_ERROR, "Failed to query an output frame.\n");
705 return AVERROR(ENOMEM);
709 ret = MFXVideoVPP_RunFrameVPPAsync(s->session, in_frame->surface,
710 out_frame->surface, NULL, &sync);
711 if (ret == MFX_WRN_DEVICE_BUSY)
713 } while (ret == MFX_WRN_DEVICE_BUSY);
715 if (ret < 0 && ret != MFX_ERR_MORE_SURFACE) {
716 /* Ignore more_data error */
717 if (ret == MFX_ERR_MORE_DATA)
718 ret = AVERROR(EAGAIN);
722 if (MFXVideoCORE_SyncOperation(s->session, sync, 1000) < 0)
723 av_log(ctx, AV_LOG_WARNING, "Sync failed.\n");
725 out_frame->frame->pts = av_rescale_q(out_frame->surface->Data.TimeStamp,
726 default_tb, outlink->time_base);
728 filter_ret = s->filter_frame(outlink, out_frame->frame);
729 if (filter_ret < 0) {
730 av_frame_free(&out_frame->frame);
734 out_frame->frame = NULL;
735 } while(ret == MFX_ERR_MORE_SURFACE);