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

Unified · Split

11 files
  1. libavcodec/qsv.c +4 −0
  2. libavcodec/qsv.h +2 −0
  3. libavcodec/qsv_internal.h +1 −0
  4. libavcodec/qsvdec.c +9 −0
  5. libavcodec/qsvenc.c +21 −0
  6. libavcodec/qsvenc.h +2 −0
  7. libavfilter/qsvvpp.c +25 −1
  8. libavfilter/qsvvpp.h +3 −0
  9. libavfilter/vf_deinterlace_qsv.c +32 −25
  10. libavfilter/vf_scale_qsv.c +41 −33
  11. libavutil/hwcontext_qsv.c +41 −15
libavcodec/qsv.c+4−0
@@ -81,10 +81,14 @@ static const struct { · 80 unmodified lines
8181 } qsv_iopatterns[] = {
8282 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface" },
8383 {MFX_IOPATTERN_IN_SYSTEM_MEMORY, "input is system memory surface" },
84+#if QSV_HAVE_OPAQUE
8485 {MFX_IOPATTERN_IN_OPAQUE_MEMORY, "input is opaque memory surface" },
86+#endif
8587 {MFX_IOPATTERN_OUT_VIDEO_MEMORY, "output is video memory surface" },
8688 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY, "output is system memory surface" },
89+#if QSV_HAVE_OPAQUE
8790 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY, "output is opaque memory surface" },
91+#endif
8892 };
8993
9094 int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
libavcodec/qsv.h+2−0
@@ -61,6 +61,8 @@ typedef struct AVQSVContext { · 60 unmodified lines
6161 * required by the encoder and the user-provided value nb_opaque_surfaces.
6262 * The array of the opaque surfaces will be exported to the caller through
6363 * the opaque_surfaces field.
64+ *
65+ * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0)
6466 */
6567 int opaque_alloc;
6668
libavcodec/qsv_internal.h+1−0
@@ -66,6 +66,7 @@ · 65 unmodified lines
6666 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
6767
6868 #define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0)
69+#define QSV_HAVE_OPAQUE !QSV_ONEVPL
6970
7071 typedef struct QSVMid {
7172 AVBufferRef *hw_frames_ref;
libavcodec/qsvdec.c+9−0
@@ -187,7 +187,11 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses · 186 unmodified lines
187187
188188 ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
189189 &q->frames_ctx, q->load_plugins,
190+#if QSV_HAVE_OPAQUE
190191 q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
192+#else
193+ 0,
194+#endif
191195 q->gpu_copy);
192196 if (ret < 0) {
193197 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
@@ -300,10 +304,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel · 106 unmodified lines
300304 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
301305
302306 if (!iopattern) {
307+#if QSV_HAVE_OPAQUE
303308 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
304309 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
305310 else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
306311 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
312+#else
313+ if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
314+ iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
315+#endif
307316 }
308317 }
309318
libavcodec/qsvenc.c+21−0
@@ -1176,6 +1176,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) · 1175 unmodified lines
11761176 return 0;
11771177 }
11781178
1179+#if QSV_HAVE_OPAQUE
11791180 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
11801181 {
11811182 AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1212,6 +1213,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q) · 30 unmodified lines
12121213
12131214 return 0;
12141215 }
1216+#endif
12151217
12161218 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
12171219 {
@@ -1227,7 +1229,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q) · 9 unmodified lines
12271229
12281230 ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
12291231 &q->frames_ctx, q->load_plugins,
1232+#if QSV_HAVE_OPAQUE
12301233 q->param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY,
1234+#else
1235+ 0,
1236+#endif
12311237 MFX_GPUCOPY_OFF);
12321238 if (ret < 0) {
12331239 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
@@ -1279,11 +1285,17 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) · 45 unmodified lines
12791285 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
12801286
12811287 if (!iopattern) {
1288+#if QSV_HAVE_OPAQUE
12821289 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
12831290 iopattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY;
12841291 else if (frames_hwctx->frame_type &
12851292 (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
12861293 iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
1294+#else
1295+ if (frames_hwctx->frame_type &
1296+ (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
1297+ iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
1298+#endif
12871299 }
12881300 }
12891301
@@ -1357,9 +1369,16 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) · 67 unmodified lines
13571369 "Error querying (IOSurf) the encoding parameters");
13581370
13591371 if (opaque_alloc) {
1372+#if QSV_HAVE_OPAQUE
13601373 ret = qsv_init_opaque_alloc(avctx, q);
13611374 if (ret < 0)
13621375 return ret;
1376+#else
1377+ av_log(avctx, AV_LOG_ERROR, "User is requesting to allocate OPAQUE surface, "
1378+ "however libmfx %d.%d doesn't support OPAQUE memory.\n",
1379+ q->ver.Major, q->ver.Minor);
1380+ return AVERROR_UNKNOWN;
1381+#endif
13631382 }
13641383
13651384 ret = MFXVideoENCODE_Init(q->session, &q->param);
@@ -1913,8 +1932,10 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) · 547 unmodified lines
19131932 av_fifo_freep2(&q->async_fifo);
19141933 }
19151934
1935+#if QSV_HAVE_OPAQUE
19161936 av_freep(&q->opaque_surfaces);
19171937 av_buffer_unref(&q->opaque_alloc_buf);
1938+#endif
19181939
19191940 av_freep(&q->extparam);
19201941
libavcodec/qsvenc.h+2−0
@@ -137,9 +137,11 @@ typedef struct QSVEncContext { · 136 unmodified lines
137137 mfxExtHEVCTiles exthevctiles;
138138 mfxExtVP9Param extvp9param;
139139
140+#if QSV_HAVE_OPAQUE
140141 mfxExtOpaqueSurfaceAlloc opaque_alloc;
141142 mfxFrameSurface1 **opaque_surfaces;
142143 AVBufferRef *opaque_alloc_buf;
144+#endif
143145
144146 mfxExtVideoSignalInfo extvsi;
145147
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;
libavutil/hwcontext_qsv.c+41−15
@@ -55,6 +55,8 @@ · 54 unmodified lines
5555 MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
5656
5757 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
58+#define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0)
59+#define QSV_HAVE_OPAQUE !QSV_ONEVPL
5860
5961 typedef struct QSVDevicePriv {
6062 AVBufferRef *child_device_ctx;
@@ -86,11 +88,13 @@ typedef struct QSVFramesContext { · 25 unmodified lines
8688
8789 // used in the frame allocator for non-opaque surfaces
8890 mfxMemId *mem_ids;
91+#if QSV_HAVE_OPAQUE
8992 // used in the opaque alloc request for opaque surfaces
9093 mfxFrameSurface1 **surface_ptrs;
9194
9295 mfxExtOpaqueSurfaceAlloc opaque_alloc;
9396 mfxExtBuffer *ext_buffers[1];
97+#endif
9498 AVFrame realigned_upload_frame;
9599 AVFrame realigned_download_frame;
96100 } QSVFramesContext;
@@ -299,7 +303,9 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx) · 202 unmodified lines
299303 #endif
300304
301305 av_freep(&s->mem_ids);
306+#if QSV_HAVE_OPAQUE
302307 av_freep(&s->surface_ptrs);
308+#endif
303309 av_freep(&s->surfaces_internal);
304310 av_freep(&s->handle_pairs_internal);
305311 av_frame_unref(&s->realigned_upload_frame);
@@ -535,11 +541,17 @@ static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc) · 229 unmodified lines
535541 return ret;
536542 }
537543
544+#if QSV_HAVE_OPAQUE
538545 if (!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) {
539546 ret = qsv_init_child_ctx(ctx);
540547 if (ret < 0)
541548 return ret;
542549 }
550+#else
551+ ret = qsv_init_child_ctx(ctx);
552+ if (ret < 0)
553+ return ret;
554+#endif
543555
544556 ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1),
545557 ctx, qsv_pool_alloc, NULL);
@@ -610,10 +622,9 @@ static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) · 64 unmodified lines
610622 static int qsv_init_internal_session(AVHWFramesContext *ctx,
611623 mfxSession *session, int upload)
612624 {
613− QSVFramesContext *s = ctx->internal->priv;
614625 AVQSVFramesContext *frames_hwctx = ctx->hwctx;
615626 QSVDeviceContext *device_priv = ctx->device_ctx->internal->priv;
616− int opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
627+ int opaque = 0;
617628
618629 mfxFrameAllocator frame_allocator = {
619630 .pthis = ctx,
@@ -627,6 +638,11 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx, · 7 unmodified lines
627638 mfxVideoParam par;
628639 mfxStatus err;
629640
641+#if QSV_HAVE_OPAQUE
642+ QSVFramesContext *s = ctx->internal->priv;
643+ opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
644+#endif
645+
630646 err = MFXInit(device_priv->impl, &device_priv->ver, session);
631647 if (err != MFX_ERR_NONE) {
632648 av_log(ctx, AV_LOG_ERROR, "Error initializing an internal session\n");
@@ -648,15 +664,18 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx, · 15 unmodified lines
648664
649665 memset(&par, 0, sizeof(par));
650666
651− if (opaque) {
667+ if (!opaque) {
668+ par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
669+ MFX_IOPATTERN_IN_VIDEO_MEMORY;
670+ }
671+#if QSV_HAVE_OPAQUE
672+ else {
652673 par.ExtParam = s->ext_buffers;
653674 par.NumExtParam = FF_ARRAY_ELEMS(s->ext_buffers);
654675 par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
655676 MFX_IOPATTERN_IN_OPAQUE_MEMORY;
656− } else {
657− par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
658− MFX_IOPATTERN_IN_VIDEO_MEMORY;
659677 }
678+#endif
660679
661680 par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
662681 MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
@@ -688,11 +707,15 @@ static int qsv_frames_init(AVHWFramesContext *ctx) · 25 unmodified lines
688707 QSVFramesContext *s = ctx->internal->priv;
689708 AVQSVFramesContext *frames_hwctx = ctx->hwctx;
690709
691− int opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
710+ int opaque = 0;
692711
693712 uint32_t fourcc;
694713 int i, ret;
695714
715+#if QSV_HAVE_OPAQUE
716+ opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
717+#endif
718+
696719 fourcc = qsv_fourcc_from_pix_fmt(ctx->sw_format);
697720 if (!fourcc) {
698721 av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format\n");
@@ -707,7 +730,16 @@ static int qsv_frames_init(AVHWFramesContext *ctx) · 8 unmodified lines
707730 }
708731 }
709732
710− if (opaque) {
733+ if (!opaque) {
734+ s->mem_ids = av_calloc(frames_hwctx->nb_surfaces, sizeof(*s->mem_ids));
735+ if (!s->mem_ids)
736+ return AVERROR(ENOMEM);
737+
738+ for (i = 0; i < frames_hwctx->nb_surfaces; i++)
739+ s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
740+ }
741+#if QSV_HAVE_OPAQUE
742+ else {
711743 s->surface_ptrs = av_calloc(frames_hwctx->nb_surfaces,
712744 sizeof(*s->surface_ptrs));
713745 if (!s->surface_ptrs)
@@ -726,14 +758,8 @@ static int qsv_frames_init(AVHWFramesContext *ctx) · 12 unmodified lines
726758 s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
727759
728760 s->ext_buffers[0] = (mfxExtBuffer*)&s->opaque_alloc;
729− } else {
730− s->mem_ids = av_calloc(frames_hwctx->nb_surfaces, sizeof(*s->mem_ids));
731− if (!s->mem_ids)
732− return AVERROR(ENOMEM);
733−
734− for (i = 0; i < frames_hwctx->nb_surfaces; i++)
735− s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
736761 }
762+#endif
737763
738764 s->session_download = NULL;
739765 s->session_upload = NULL;

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