History

qsv: restrict OPAQUE memory to MFX_VERSION < 2.0

OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in preparation for oneVPL support [1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals [2] https://github.com/oneapi-src/oneVPL

Haihao Xiang committed 6 years ago

Commit c77149b1 parent 63cda4011 files · +181 −74Browse files

Showing the changes to libavfilter (4 of 11 files). Show all

Unified · Split

4 files
  1. libavfilter/qsvvpp.c +25 −1
  2. libavfilter/qsvvpp.h +3 −0
  3. libavfilter/vf_deinterlace_qsv.c +32 −25
  4. libavfilter/vf_scale_qsv.c +41 −33
libavfilter/qsvvpp.c+25−1
@@ -34,7 +34,9 @@ · 33 unmodified lines
3434
3535 #define IS_VIDEO_MEMORY(mode) (mode & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | \
3636 MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
37+#if QSV_HAVE_OPAQUE
3738 #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
39+#endif
3840 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
3941 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
4042
@@ -53,10 +55,14 @@ static const struct { · 12 unmodified lines
5355 } qsv_iopatterns[] = {
5456 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface" },
5557 {MFX_IOPATTERN_IN_SYSTEM_MEMORY, "input is system memory surface" },
58+#if QSV_HAVE_OPAQUE
5659 {MFX_IOPATTERN_IN_OPAQUE_MEMORY, "input is opaque memory surface" },
60+#endif
5761 {MFX_IOPATTERN_OUT_VIDEO_MEMORY, "output is video memory surface" },
5862 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY, "output is system memory surface" },
63+#if QSV_HAVE_OPAQUE
5964 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY, "output is opaque memory surface" },
65+#endif
6066 };
6167
6268 int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern,
@@ -542,9 +548,13 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) · 479 unmodified lines
542548 if (!out_frames_ref)
543549 return AVERROR(ENOMEM);
544550
551+#if QSV_HAVE_OPAQUE
545552 s->out_mem_mode = IS_OPAQUE_MEMORY(s->in_mem_mode) ?
546553 MFX_MEMTYPE_OPAQUE_FRAME :
547554 MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_FROM_VPPOUT;
555+#else
556+ s->out_mem_mode = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_FROM_VPPOUT;
557+#endif
548558
549559 out_frames_ctx = (AVHWFramesContext *)out_frames_ref->data;
550560 out_frames_hwctx = out_frames_ctx->hwctx;
@@ -630,6 +640,7 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) · 79 unmodified lines
630640 return AVERROR_UNKNOWN;
631641 }
632642
643+#if QSV_HAVE_OPAQUE
633644 if (IS_OPAQUE_MEMORY(s->in_mem_mode) || IS_OPAQUE_MEMORY(s->out_mem_mode)) {
634645 s->opaque_alloc.In.Surfaces = s->surface_ptrs_in;
635646 s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in;
@@ -641,7 +652,9 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) · 5 unmodified lines
641652
642653 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
643654 s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
644− } else if (IS_VIDEO_MEMORY(s->in_mem_mode) || IS_VIDEO_MEMORY(s->out_mem_mode)) {
655+ } else
656+#endif
657+ if (IS_VIDEO_MEMORY(s->in_mem_mode) || IS_VIDEO_MEMORY(s->out_mem_mode)) {
645658 mfxFrameAllocator frame_allocator = {
646659 .pthis = s,
647660 .Alloc = frame_alloc,
@@ -713,6 +726,7 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p · 65 unmodified lines
713726 goto failed;
714727 }
715728
729+#if QSV_HAVE_OPAQUE
716730 if (IS_OPAQUE_MEMORY(s->in_mem_mode) || IS_OPAQUE_MEMORY(s->out_mem_mode)) {
717731 s->nb_ext_buffers = param->num_ext_buf + 1;
718732 s->ext_buffers = av_calloc(s->nb_ext_buffers, sizeof(*s->ext_buffers));
@@ -730,6 +744,10 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p · 11 unmodified lines
730744 s->vpp_param.NumExtParam = param->num_ext_buf;
731745 s->vpp_param.ExtParam = param->ext_buf;
732746 }
747+#else
748+ s->vpp_param.NumExtParam = param->num_ext_buf;
749+ s->vpp_param.ExtParam = param->ext_buf;
750+#endif
733751
734752 s->got_frame = 0;
735753
@@ -747,15 +765,19 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p · 11 unmodified lines
747765 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_SYSTEM_MEMORY;
748766 else if (IS_VIDEO_MEMORY(s->in_mem_mode))
749767 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_VIDEO_MEMORY;
768+#if QSV_HAVE_OPAQUE
750769 else if (IS_OPAQUE_MEMORY(s->in_mem_mode))
751770 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_OPAQUE_MEMORY;
771+#endif
752772
753773 if (IS_SYSTEM_MEMORY(s->out_mem_mode))
754774 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
755775 else if (IS_VIDEO_MEMORY(s->out_mem_mode))
756776 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_VIDEO_MEMORY;
777+#if QSV_HAVE_OPAQUE
757778 else if (IS_OPAQUE_MEMORY(s->out_mem_mode))
758779 s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
780+#endif
759781
760782 /* Print input memory mode */
761783 ff_qsvvpp_print_iopattern(avctx, s->vpp_param.IOPattern & 0x0F, "VPP");
@@ -794,7 +816,9 @@ int ff_qsvvpp_free(QSVVPPContext **vpp) · 32 unmodified lines
794816 clear_frame_list(&s->out_frame_list);
795817 av_freep(&s->surface_ptrs_in);
796818 av_freep(&s->surface_ptrs_out);
819+#if QSV_HAVE_OPAQUE
797820 av_freep(&s->ext_buffers);
821+#endif
798822 av_freep(&s->frame_infos);
799823 av_fifo_freep2(&s->async_fifo);
800824 av_freep(vpp);
libavfilter/qsvvpp.h+3−0
@@ -41,6 +41,7 @@ · 40 unmodified lines
4141 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
4242
4343 #define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0)
44+#define QSV_HAVE_OPAQUE !QSV_ONEVPL
4445
4546 typedef struct QSVFrame {
4647 AVFrame *frame;
@@ -66,10 +67,12 @@ typedef struct QSVVPPContext { · 19 unmodified lines
6667 mfxFrameSurface1 **surface_ptrs_in;
6768 mfxFrameSurface1 **surface_ptrs_out;
6869
70+#if QSV_HAVE_OPAQUE
6971 /** MFXVPP extern parameters */
7072 mfxExtOpaqueSurfaceAlloc opaque_alloc;
7173 mfxExtBuffer **ext_buffers;
7274 int nb_ext_buffers;
75+#endif
7376
7477 int got_frame;
7578 int async_depth;
libavfilter/vf_deinterlace_qsv.c+32−25
@@ -62,7 +62,9 @@ typedef struct QSVDeintContext { · 61 unmodified lines
6262 mfxFrameSurface1 **surface_ptrs;
6363 int nb_surface_ptrs;
6464
65+#if QSV_HAVE_OPAQUE
6566 mfxExtOpaqueSurfaceAlloc opaque_alloc;
67+#endif
6668 mfxExtVPPDeinterlacing deint_conf;
6769 mfxExtBuffer *ext_buffers[2];
6870 int num_ext_buffers;
@@ -154,9 +156,7 @@ static int init_out_session(AVFilterContext *ctx) · 85 unmodified lines
154156 AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)s->hw_frames_ctx->data;
155157 AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
156158 AVQSVDeviceContext *device_hwctx = hw_frames_ctx->device_ctx->hwctx;
157−
158− int opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
159−
159+ int opaque = 0;
160160 mfxHDL handle = NULL;
161161 mfxHandleType handle_type;
162162 mfxVersion ver;
@@ -165,6 +165,9 @@ static int init_out_session(AVFilterContext *ctx) · 2 unmodified lines
165165 mfxStatus err;
166166 int i;
167167
168+#if QSV_HAVE_OPAQUE
169+ opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
170+#endif
168171 /* extract the properties of the "master" session given to us */
169172 err = MFXQueryIMPL(device_hwctx->session, &impl);
170173 if (err == MFX_ERR_NONE)
@@ -223,28 +226,7 @@ static int init_out_session(AVFilterContext *ctx) · 52 unmodified lines
223226
224227 s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->deint_conf;
225228
226− if (opaque) {
227− s->surface_ptrs = av_calloc(hw_frames_hwctx->nb_surfaces,
228− sizeof(*s->surface_ptrs));
229− if (!s->surface_ptrs)
230− return AVERROR(ENOMEM);
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;
234−
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;
238−
239− s->opaque_alloc.Out = s->opaque_alloc.In;
240−
241− s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
242− s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
243−
244− s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc;
245−
246− par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
247− } else {
229+ if (!opaque) {
248230 mfxFrameAllocator frame_allocator = {
249231 .pthis = ctx,
250232 .Alloc = frame_alloc,
@@ -268,6 +250,31 @@ static int init_out_session(AVFilterContext *ctx) · 17 unmodified lines
268250
269251 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
270252 }
253+#if QSV_HAVE_OPAQUE
254+ else {
255+ s->surface_ptrs = av_calloc(hw_frames_hwctx->nb_surfaces,
256+ sizeof(*s->surface_ptrs));
257+
258+ if (!s->surface_ptrs)
259+ return AVERROR(ENOMEM);
260+ for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
261+ s->surface_ptrs[i] = hw_frames_hwctx->surfaces + i;
262+ s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
263+
264+ s->opaque_alloc.In.Surfaces = s->surface_ptrs;
265+ s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs;
266+ s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
267+
268+ s->opaque_alloc.Out = s->opaque_alloc.In;
269+
270+ s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
271+ s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
272+
273+ s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc;
274+
275+ par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
276+ }
277+#endif
271278
272279 par.ExtParam = s->ext_buffers;
273280 par.NumExtParam = s->num_ext_buffers;
libavfilter/vf_scale_qsv.c+41−33
@@ -89,7 +89,9 @@ typedef struct QSVScaleContext { · 88 unmodified lines
8989 mfxFrameSurface1 **surface_ptrs_out;
9090 int nb_surface_ptrs_out;
9191
92+#if QSV_HAVE_OPAQUE
9293 mfxExtOpaqueSurfaceAlloc opaque_alloc;
94+#endif
9395
9496 mfxExtVPPScaling scale_conf;
9597 int mode;
@@ -268,7 +270,7 @@ static int init_out_session(AVFilterContext *ctx) · 172 unmodified lines
268270 AVQSVFramesContext *out_frames_hwctx = out_frames_ctx->hwctx;
269271 AVQSVDeviceContext *device_hwctx = in_frames_ctx->device_ctx->hwctx;
270272
271− int opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
273+ int opaque = 0;
272274
273275 mfxHDL handle = NULL;
274276 mfxHandleType handle_type;
@@ -278,6 +280,9 @@ static int init_out_session(AVFilterContext *ctx) · 3 unmodified lines
278280 mfxStatus err;
279281 int i;
280282
283+#if QSV_HAVE_OPAQUE
284+ opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
285+#endif
281286 s->num_ext_buf = 0;
282287
283288 /* extract the properties of the "master" session given to us */
@@ -330,38 +335,7 @@ static int init_out_session(AVFilterContext *ctx) · 46 unmodified lines
330335
331336 memset(&par, 0, sizeof(par));
332337
333− if (opaque) {
334− s->surface_ptrs_in = av_calloc(in_frames_hwctx->nb_surfaces,
335− sizeof(*s->surface_ptrs_in));
336− if (!s->surface_ptrs_in)
337− return AVERROR(ENOMEM);
338− for (i = 0; i < in_frames_hwctx->nb_surfaces; i++)
339− s->surface_ptrs_in[i] = in_frames_hwctx->surfaces + i;
340− s->nb_surface_ptrs_in = in_frames_hwctx->nb_surfaces;
341−
342− s->surface_ptrs_out = av_calloc(out_frames_hwctx->nb_surfaces,
343− sizeof(*s->surface_ptrs_out));
344− if (!s->surface_ptrs_out)
345− return AVERROR(ENOMEM);
346− for (i = 0; i < out_frames_hwctx->nb_surfaces; i++)
347− s->surface_ptrs_out[i] = out_frames_hwctx->surfaces + i;
348− s->nb_surface_ptrs_out = out_frames_hwctx->nb_surfaces;
349−
350− s->opaque_alloc.In.Surfaces = s->surface_ptrs_in;
351− s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in;
352− s->opaque_alloc.In.Type = in_frames_hwctx->frame_type;
353−
354− s->opaque_alloc.Out.Surfaces = s->surface_ptrs_out;
355− s->opaque_alloc.Out.NumSurface = s->nb_surface_ptrs_out;
356− s->opaque_alloc.Out.Type = out_frames_hwctx->frame_type;
357−
358− s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
359− s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
360−
361− s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)&s->opaque_alloc;
362−
363− par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
364− } else {
338+ if (!opaque) {
365339 mfxFrameAllocator frame_allocator = {
366340 .pthis = ctx,
367341 .Alloc = frame_alloc,
@@ -393,6 +367,40 @@ static int init_out_session(AVFilterContext *ctx) · 25 unmodified lines
393367
394368 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
395369 }
370+#if QSV_HAVE_OPAQUE
371+ else {
372+ s->surface_ptrs_in = av_calloc(in_frames_hwctx->nb_surfaces,
373+ sizeof(*s->surface_ptrs_in));
374+ if (!s->surface_ptrs_in)
375+ return AVERROR(ENOMEM);
376+ for (i = 0; i < in_frames_hwctx->nb_surfaces; i++)
377+ s->surface_ptrs_in[i] = in_frames_hwctx->surfaces + i;
378+ s->nb_surface_ptrs_in = in_frames_hwctx->nb_surfaces;
379+
380+ s->surface_ptrs_out = av_calloc(out_frames_hwctx->nb_surfaces,
381+ sizeof(*s->surface_ptrs_out));
382+ if (!s->surface_ptrs_out)
383+ return AVERROR(ENOMEM);
384+ for (i = 0; i < out_frames_hwctx->nb_surfaces; i++)
385+ s->surface_ptrs_out[i] = out_frames_hwctx->surfaces + i;
386+ s->nb_surface_ptrs_out = out_frames_hwctx->nb_surfaces;
387+
388+ s->opaque_alloc.In.Surfaces = s->surface_ptrs_in;
389+ s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in;
390+ s->opaque_alloc.In.Type = in_frames_hwctx->frame_type;
391+
392+ s->opaque_alloc.Out.Surfaces = s->surface_ptrs_out;
393+ s->opaque_alloc.Out.NumSurface = s->nb_surface_ptrs_out;
394+ s->opaque_alloc.Out.Type = out_frames_hwctx->frame_type;
395+
396+ s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
397+ s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
398+
399+ s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)&s->opaque_alloc;
400+
401+ par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
402+ }
403+#endif
396404
397405 memset(&s->scale_conf, 0, sizeof(mfxExtVPPScaling));
398406 s->scale_conf.Header.BufferId = MFX_EXTBUFF_VPP_SCALING;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t