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
Unified · Split
| @@ -81,10 +81,14 @@ static const struct { · 80 unmodified lines | ||
| 81 | 81 | } qsv_iopatterns[] = { |
| 82 | 82 | {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface" }, |
| 83 | 83 | {MFX_IOPATTERN_IN_SYSTEM_MEMORY, "input is system memory surface" }, |
| 84 | +#if QSV_HAVE_OPAQUE | |
| 84 | 85 | {MFX_IOPATTERN_IN_OPAQUE_MEMORY, "input is opaque memory surface" }, |
| 86 | +#endif | |
| 85 | 87 | {MFX_IOPATTERN_OUT_VIDEO_MEMORY, "output is video memory surface" }, |
| 86 | 88 | {MFX_IOPATTERN_OUT_SYSTEM_MEMORY, "output is system memory surface" }, |
| 89 | +#if QSV_HAVE_OPAQUE | |
| 87 | 90 | {MFX_IOPATTERN_OUT_OPAQUE_MEMORY, "output is opaque memory surface" }, |
| 91 | +#endif | |
| 88 | 92 | }; |
| 89 | 93 | |
| 90 | 94 | int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern, |
| @@ -61,6 +61,8 @@ typedef struct AVQSVContext { · 60 unmodified lines | ||
| 61 | 61 | * required by the encoder and the user-provided value nb_opaque_surfaces. |
| 62 | 62 | * The array of the opaque surfaces will be exported to the caller through |
| 63 | 63 | * the opaque_surfaces field. |
| 64 | + * | |
| 65 | + * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0) | |
| 64 | 66 | */ |
| 65 | 67 | int opaque_alloc; |
| 66 | 68 | |
| @@ -66,6 +66,7 @@ · 65 unmodified lines | ||
| 66 | 66 | (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR))) |
| 67 | 67 | |
| 68 | 68 | #define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0) |
| 69 | +#define QSV_HAVE_OPAQUE !QSV_ONEVPL | |
| 69 | 70 | |
| 70 | 71 | typedef struct QSVMid { |
| 71 | 72 | AVBufferRef *hw_frames_ref; |
| @@ -187,7 +187,11 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses · 186 unmodified lines | ||
| 187 | 187 | |
| 188 | 188 | ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session, |
| 189 | 189 | &q->frames_ctx, q->load_plugins, |
| 190 | +#if QSV_HAVE_OPAQUE | |
| 190 | 191 | q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY, |
| 192 | +#else | |
| 193 | + 0, | |
| 194 | +#endif | |
| 191 | 195 | q->gpu_copy); |
| 192 | 196 | if (ret < 0) { |
| 193 | 197 | 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 | ||
| 300 | 304 | AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx; |
| 301 | 305 | |
| 302 | 306 | if (!iopattern) { |
| 307 | +#if QSV_HAVE_OPAQUE | |
| 303 | 308 | if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME) |
| 304 | 309 | iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY; |
| 305 | 310 | else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET) |
| 306 | 311 | 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 | |
| 307 | 316 | } |
| 308 | 317 | } |
| 309 | 318 | |
| @@ -1176,6 +1176,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) · 1175 unmodified lines | ||
| 1176 | 1176 | return 0; |
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | +#if QSV_HAVE_OPAQUE | |
| 1179 | 1180 | static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q) |
| 1180 | 1181 | { |
| 1181 | 1182 | AVQSVContext *qsv = avctx->hwaccel_context; |
| @@ -1212,6 +1213,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q) · 30 unmodified lines | ||
| 1212 | 1213 | |
| 1213 | 1214 | return 0; |
| 1214 | 1215 | } |
| 1216 | +#endif | |
| 1215 | 1217 | |
| 1216 | 1218 | static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q) |
| 1217 | 1219 | { |
| @@ -1227,7 +1229,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q) · 9 unmodified lines | ||
| 1227 | 1229 | |
| 1228 | 1230 | ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session, |
| 1229 | 1231 | &q->frames_ctx, q->load_plugins, |
| 1232 | +#if QSV_HAVE_OPAQUE | |
| 1230 | 1233 | q->param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY, |
| 1234 | +#else | |
| 1235 | + 0, | |
| 1236 | +#endif | |
| 1231 | 1237 | MFX_GPUCOPY_OFF); |
| 1232 | 1238 | if (ret < 0) { |
| 1233 | 1239 | 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 | ||
| 1279 | 1285 | AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx; |
| 1280 | 1286 | |
| 1281 | 1287 | if (!iopattern) { |
| 1288 | +#if QSV_HAVE_OPAQUE | |
| 1282 | 1289 | if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME) |
| 1283 | 1290 | iopattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY; |
| 1284 | 1291 | else if (frames_hwctx->frame_type & |
| 1285 | 1292 | (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)) |
| 1286 | 1293 | 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 | |
| 1287 | 1299 | } |
| 1288 | 1300 | } |
| 1289 | 1301 | |
| @@ -1357,9 +1369,16 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) · 67 unmodified lines | ||
| 1357 | 1369 | "Error querying (IOSurf) the encoding parameters"); |
| 1358 | 1370 | |
| 1359 | 1371 | if (opaque_alloc) { |
| 1372 | +#if QSV_HAVE_OPAQUE | |
| 1360 | 1373 | ret = qsv_init_opaque_alloc(avctx, q); |
| 1361 | 1374 | if (ret < 0) |
| 1362 | 1375 | 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 | |
| 1363 | 1382 | } |
| 1364 | 1383 | |
| 1365 | 1384 | ret = MFXVideoENCODE_Init(q->session, &q->param); |
| @@ -1913,8 +1932,10 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) · 547 unmodified lines | ||
| 1913 | 1932 | av_fifo_freep2(&q->async_fifo); |
| 1914 | 1933 | } |
| 1915 | 1934 | |
| 1935 | +#if QSV_HAVE_OPAQUE | |
| 1916 | 1936 | av_freep(&q->opaque_surfaces); |
| 1917 | 1937 | av_buffer_unref(&q->opaque_alloc_buf); |
| 1938 | +#endif | |
| 1918 | 1939 | |
| 1919 | 1940 | av_freep(&q->extparam); |
| 1920 | 1941 | |
| @@ -137,9 +137,11 @@ typedef struct QSVEncContext { · 136 unmodified lines | ||
| 137 | 137 | mfxExtHEVCTiles exthevctiles; |
| 138 | 138 | mfxExtVP9Param extvp9param; |
| 139 | 139 | |
| 140 | +#if QSV_HAVE_OPAQUE | |
| 140 | 141 | mfxExtOpaqueSurfaceAlloc opaque_alloc; |
| 141 | 142 | mfxFrameSurface1 **opaque_surfaces; |
| 142 | 143 | AVBufferRef *opaque_alloc_buf; |
| 144 | +#endif | |
| 143 | 145 | |
| 144 | 146 | mfxExtVideoSignalInfo extvsi; |
| 145 | 147 | |
| @@ -34,7 +34,9 @@ · 33 unmodified lines | ||
| 34 | 34 | |
| 35 | 35 | #define IS_VIDEO_MEMORY(mode) (mode & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | \ |
| 36 | 36 | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)) |
| 37 | +#if QSV_HAVE_OPAQUE | |
| 37 | 38 | #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME) |
| 39 | +#endif | |
| 38 | 40 | #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY) |
| 39 | 41 | #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) |
| 40 | 42 | |
| @@ -53,10 +55,14 @@ static const struct { · 12 unmodified lines | ||
| 53 | 55 | } qsv_iopatterns[] = { |
| 54 | 56 | {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface" }, |
| 55 | 57 | {MFX_IOPATTERN_IN_SYSTEM_MEMORY, "input is system memory surface" }, |
| 58 | +#if QSV_HAVE_OPAQUE | |
| 56 | 59 | {MFX_IOPATTERN_IN_OPAQUE_MEMORY, "input is opaque memory surface" }, |
| 60 | +#endif | |
| 57 | 61 | {MFX_IOPATTERN_OUT_VIDEO_MEMORY, "output is video memory surface" }, |
| 58 | 62 | {MFX_IOPATTERN_OUT_SYSTEM_MEMORY, "output is system memory surface" }, |
| 63 | +#if QSV_HAVE_OPAQUE | |
| 59 | 64 | {MFX_IOPATTERN_OUT_OPAQUE_MEMORY, "output is opaque memory surface" }, |
| 65 | +#endif | |
| 60 | 66 | }; |
| 61 | 67 | |
| 62 | 68 | 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 | ||
| 542 | 548 | if (!out_frames_ref) |
| 543 | 549 | return AVERROR(ENOMEM); |
| 544 | 550 | |
| 551 | +#if QSV_HAVE_OPAQUE | |
| 545 | 552 | s->out_mem_mode = IS_OPAQUE_MEMORY(s->in_mem_mode) ? |
| 546 | 553 | MFX_MEMTYPE_OPAQUE_FRAME : |
| 547 | 554 | 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 | |
| 548 | 558 | |
| 549 | 559 | out_frames_ctx = (AVHWFramesContext *)out_frames_ref->data; |
| 550 | 560 | out_frames_hwctx = out_frames_ctx->hwctx; |
| @@ -630,6 +640,7 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) · 79 unmodified lines | ||
| 630 | 640 | return AVERROR_UNKNOWN; |
| 631 | 641 | } |
| 632 | 642 | |
| 643 | +#if QSV_HAVE_OPAQUE | |
| 633 | 644 | if (IS_OPAQUE_MEMORY(s->in_mem_mode) || IS_OPAQUE_MEMORY(s->out_mem_mode)) { |
| 634 | 645 | s->opaque_alloc.In.Surfaces = s->surface_ptrs_in; |
| 635 | 646 | 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 | ||
| 641 | 652 | |
| 642 | 653 | s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION; |
| 643 | 654 | 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)) { | |
| 645 | 658 | mfxFrameAllocator frame_allocator = { |
| 646 | 659 | .pthis = s, |
| 647 | 660 | .Alloc = frame_alloc, |
| @@ -713,6 +726,7 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p · 65 unmodified lines | ||
| 713 | 726 | goto failed; |
| 714 | 727 | } |
| 715 | 728 | |
| 729 | +#if QSV_HAVE_OPAQUE | |
| 716 | 730 | if (IS_OPAQUE_MEMORY(s->in_mem_mode) || IS_OPAQUE_MEMORY(s->out_mem_mode)) { |
| 717 | 731 | s->nb_ext_buffers = param->num_ext_buf + 1; |
| 718 | 732 | 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 | ||
| 730 | 744 | s->vpp_param.NumExtParam = param->num_ext_buf; |
| 731 | 745 | s->vpp_param.ExtParam = param->ext_buf; |
| 732 | 746 | } |
| 747 | +#else | |
| 748 | + s->vpp_param.NumExtParam = param->num_ext_buf; | |
| 749 | + s->vpp_param.ExtParam = param->ext_buf; | |
| 750 | +#endif | |
| 733 | 751 | |
| 734 | 752 | s->got_frame = 0; |
| 735 | 753 | |
| @@ -747,15 +765,19 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p · 11 unmodified lines | ||
| 747 | 765 | s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_SYSTEM_MEMORY; |
| 748 | 766 | else if (IS_VIDEO_MEMORY(s->in_mem_mode)) |
| 749 | 767 | s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_VIDEO_MEMORY; |
| 768 | +#if QSV_HAVE_OPAQUE | |
| 750 | 769 | else if (IS_OPAQUE_MEMORY(s->in_mem_mode)) |
| 751 | 770 | s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_OPAQUE_MEMORY; |
| 771 | +#endif | |
| 752 | 772 | |
| 753 | 773 | if (IS_SYSTEM_MEMORY(s->out_mem_mode)) |
| 754 | 774 | s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_SYSTEM_MEMORY; |
| 755 | 775 | else if (IS_VIDEO_MEMORY(s->out_mem_mode)) |
| 756 | 776 | s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_VIDEO_MEMORY; |
| 777 | +#if QSV_HAVE_OPAQUE | |
| 757 | 778 | else if (IS_OPAQUE_MEMORY(s->out_mem_mode)) |
| 758 | 779 | s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_OPAQUE_MEMORY; |
| 780 | +#endif | |
| 759 | 781 | |
| 760 | 782 | /* Print input memory mode */ |
| 761 | 783 | ff_qsvvpp_print_iopattern(avctx, s->vpp_param.IOPattern & 0x0F, "VPP"); |
| @@ -794,7 +816,9 @@ int ff_qsvvpp_free(QSVVPPContext **vpp) · 32 unmodified lines | ||
| 794 | 816 | clear_frame_list(&s->out_frame_list); |
| 795 | 817 | av_freep(&s->surface_ptrs_in); |
| 796 | 818 | av_freep(&s->surface_ptrs_out); |
| 819 | +#if QSV_HAVE_OPAQUE | |
| 797 | 820 | av_freep(&s->ext_buffers); |
| 821 | +#endif | |
| 798 | 822 | av_freep(&s->frame_infos); |
| 799 | 823 | av_fifo_freep2(&s->async_fifo); |
| 800 | 824 | av_freep(vpp); |
| @@ -41,6 +41,7 @@ · 40 unmodified lines | ||
| 41 | 41 | (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR))) |
| 42 | 42 | |
| 43 | 43 | #define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0) |
| 44 | +#define QSV_HAVE_OPAQUE !QSV_ONEVPL | |
| 44 | 45 | |
| 45 | 46 | typedef struct QSVFrame { |
| 46 | 47 | AVFrame *frame; |
| @@ -66,10 +67,12 @@ typedef struct QSVVPPContext { · 19 unmodified lines | ||
| 66 | 67 | mfxFrameSurface1 **surface_ptrs_in; |
| 67 | 68 | mfxFrameSurface1 **surface_ptrs_out; |
| 68 | 69 | |
| 70 | +#if QSV_HAVE_OPAQUE | |
| 69 | 71 | /** MFXVPP extern parameters */ |
| 70 | 72 | mfxExtOpaqueSurfaceAlloc opaque_alloc; |
| 71 | 73 | mfxExtBuffer **ext_buffers; |
| 72 | 74 | int nb_ext_buffers; |
| 75 | +#endif | |
| 73 | 76 | |
| 74 | 77 | int got_frame; |
| 75 | 78 | int async_depth; |
| @@ -62,7 +62,9 @@ typedef struct QSVDeintContext { · 61 unmodified lines | ||
| 62 | 62 | mfxFrameSurface1 **surface_ptrs; |
| 63 | 63 | int nb_surface_ptrs; |
| 64 | 64 | |
| 65 | +#if QSV_HAVE_OPAQUE | |
| 65 | 66 | mfxExtOpaqueSurfaceAlloc opaque_alloc; |
| 67 | +#endif | |
| 66 | 68 | mfxExtVPPDeinterlacing deint_conf; |
| 67 | 69 | mfxExtBuffer *ext_buffers[2]; |
| 68 | 70 | int num_ext_buffers; |
| @@ -154,9 +156,7 @@ static int init_out_session(AVFilterContext *ctx) · 85 unmodified lines | ||
| 154 | 156 | AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)s->hw_frames_ctx->data; |
| 155 | 157 | AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx; |
| 156 | 158 | 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; | |
| 160 | 160 | mfxHDL handle = NULL; |
| 161 | 161 | mfxHandleType handle_type; |
| 162 | 162 | mfxVersion ver; |
| @@ -165,6 +165,9 @@ static int init_out_session(AVFilterContext *ctx) · 2 unmodified lines | ||
| 165 | 165 | mfxStatus err; |
| 166 | 166 | int i; |
| 167 | 167 | |
| 168 | +#if QSV_HAVE_OPAQUE | |
| 169 | + opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); | |
| 170 | +#endif | |
| 168 | 171 | /* extract the properties of the "master" session given to us */ |
| 169 | 172 | err = MFXQueryIMPL(device_hwctx->session, &impl); |
| 170 | 173 | if (err == MFX_ERR_NONE) |
| @@ -223,28 +226,7 @@ static int init_out_session(AVFilterContext *ctx) · 52 unmodified lines | ||
| 223 | 226 | |
| 224 | 227 | s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->deint_conf; |
| 225 | 228 | |
| 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) { | |
| 248 | 230 | mfxFrameAllocator frame_allocator = { |
| 249 | 231 | .pthis = ctx, |
| 250 | 232 | .Alloc = frame_alloc, |
| @@ -268,6 +250,31 @@ static int init_out_session(AVFilterContext *ctx) · 17 unmodified lines | ||
| 268 | 250 | |
| 269 | 251 | par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY; |
| 270 | 252 | } |
| 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 | |
| 271 | 278 | |
| 272 | 279 | par.ExtParam = s->ext_buffers; |
| 273 | 280 | par.NumExtParam = s->num_ext_buffers; |
| @@ -89,7 +89,9 @@ typedef struct QSVScaleContext { · 88 unmodified lines | ||
| 89 | 89 | mfxFrameSurface1 **surface_ptrs_out; |
| 90 | 90 | int nb_surface_ptrs_out; |
| 91 | 91 | |
| 92 | +#if QSV_HAVE_OPAQUE | |
| 92 | 93 | mfxExtOpaqueSurfaceAlloc opaque_alloc; |
| 94 | +#endif | |
| 93 | 95 | |
| 94 | 96 | mfxExtVPPScaling scale_conf; |
| 95 | 97 | int mode; |
| @@ -268,7 +270,7 @@ static int init_out_session(AVFilterContext *ctx) · 172 unmodified lines | ||
| 268 | 270 | AVQSVFramesContext *out_frames_hwctx = out_frames_ctx->hwctx; |
| 269 | 271 | AVQSVDeviceContext *device_hwctx = in_frames_ctx->device_ctx->hwctx; |
| 270 | 272 | |
| 271 | − int opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); | |
| 273 | + int opaque = 0; | |
| 272 | 274 | |
| 273 | 275 | mfxHDL handle = NULL; |
| 274 | 276 | mfxHandleType handle_type; |
| @@ -278,6 +280,9 @@ static int init_out_session(AVFilterContext *ctx) · 3 unmodified lines | ||
| 278 | 280 | mfxStatus err; |
| 279 | 281 | int i; |
| 280 | 282 | |
| 283 | +#if QSV_HAVE_OPAQUE | |
| 284 | + opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); | |
| 285 | +#endif | |
| 281 | 286 | s->num_ext_buf = 0; |
| 282 | 287 | |
| 283 | 288 | /* extract the properties of the "master" session given to us */ |
| @@ -330,38 +335,7 @@ static int init_out_session(AVFilterContext *ctx) · 46 unmodified lines | ||
| 330 | 335 | |
| 331 | 336 | memset(&par, 0, sizeof(par)); |
| 332 | 337 | |
| 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) { | |
| 365 | 339 | mfxFrameAllocator frame_allocator = { |
| 366 | 340 | .pthis = ctx, |
| 367 | 341 | .Alloc = frame_alloc, |
| @@ -393,6 +367,40 @@ static int init_out_session(AVFilterContext *ctx) · 25 unmodified lines | ||
| 393 | 367 | |
| 394 | 368 | par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY; |
| 395 | 369 | } |
| 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 | |
| 396 | 404 | |
| 397 | 405 | memset(&s->scale_conf, 0, sizeof(mfxExtVPPScaling)); |
| 398 | 406 | s->scale_conf.Header.BufferId = MFX_EXTBUFF_VPP_SCALING; |
| @@ -55,6 +55,8 @@ · 54 unmodified lines | ||
| 55 | 55 | MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR)) |
| 56 | 56 | |
| 57 | 57 | #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) |
| 58 | +#define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0) | |
| 59 | +#define QSV_HAVE_OPAQUE !QSV_ONEVPL | |
| 58 | 60 | |
| 59 | 61 | typedef struct QSVDevicePriv { |
| 60 | 62 | AVBufferRef *child_device_ctx; |
| @@ -86,11 +88,13 @@ typedef struct QSVFramesContext { · 25 unmodified lines | ||
| 86 | 88 | |
| 87 | 89 | // used in the frame allocator for non-opaque surfaces |
| 88 | 90 | mfxMemId *mem_ids; |
| 91 | +#if QSV_HAVE_OPAQUE | |
| 89 | 92 | // used in the opaque alloc request for opaque surfaces |
| 90 | 93 | mfxFrameSurface1 **surface_ptrs; |
| 91 | 94 | |
| 92 | 95 | mfxExtOpaqueSurfaceAlloc opaque_alloc; |
| 93 | 96 | mfxExtBuffer *ext_buffers[1]; |
| 97 | +#endif | |
| 94 | 98 | AVFrame realigned_upload_frame; |
| 95 | 99 | AVFrame realigned_download_frame; |
| 96 | 100 | } QSVFramesContext; |
| @@ -299,7 +303,9 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx) · 202 unmodified lines | ||
| 299 | 303 | #endif |
| 300 | 304 | |
| 301 | 305 | av_freep(&s->mem_ids); |
| 306 | +#if QSV_HAVE_OPAQUE | |
| 302 | 307 | av_freep(&s->surface_ptrs); |
| 308 | +#endif | |
| 303 | 309 | av_freep(&s->surfaces_internal); |
| 304 | 310 | av_freep(&s->handle_pairs_internal); |
| 305 | 311 | av_frame_unref(&s->realigned_upload_frame); |
| @@ -535,11 +541,17 @@ static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc) · 229 unmodified lines | ||
| 535 | 541 | return ret; |
| 536 | 542 | } |
| 537 | 543 | |
| 544 | +#if QSV_HAVE_OPAQUE | |
| 538 | 545 | if (!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) { |
| 539 | 546 | ret = qsv_init_child_ctx(ctx); |
| 540 | 547 | if (ret < 0) |
| 541 | 548 | return ret; |
| 542 | 549 | } |
| 550 | +#else | |
| 551 | + ret = qsv_init_child_ctx(ctx); | |
| 552 | + if (ret < 0) | |
| 553 | + return ret; | |
| 554 | +#endif | |
| 543 | 555 | |
| 544 | 556 | ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1), |
| 545 | 557 | ctx, qsv_pool_alloc, NULL); |
| @@ -610,10 +622,9 @@ static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) · 64 unmodified lines | ||
| 610 | 622 | static int qsv_init_internal_session(AVHWFramesContext *ctx, |
| 611 | 623 | mfxSession *session, int upload) |
| 612 | 624 | { |
| 613 | − QSVFramesContext *s = ctx->internal->priv; | |
| 614 | 625 | AVQSVFramesContext *frames_hwctx = ctx->hwctx; |
| 615 | 626 | QSVDeviceContext *device_priv = ctx->device_ctx->internal->priv; |
| 616 | − int opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); | |
| 627 | + int opaque = 0; | |
| 617 | 628 | |
| 618 | 629 | mfxFrameAllocator frame_allocator = { |
| 619 | 630 | .pthis = ctx, |
| @@ -627,6 +638,11 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx, · 7 unmodified lines | ||
| 627 | 638 | mfxVideoParam par; |
| 628 | 639 | mfxStatus err; |
| 629 | 640 | |
| 641 | +#if QSV_HAVE_OPAQUE | |
| 642 | + QSVFramesContext *s = ctx->internal->priv; | |
| 643 | + opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); | |
| 644 | +#endif | |
| 645 | + | |
| 630 | 646 | err = MFXInit(device_priv->impl, &device_priv->ver, session); |
| 631 | 647 | if (err != MFX_ERR_NONE) { |
| 632 | 648 | 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 | ||
| 648 | 664 | |
| 649 | 665 | memset(&par, 0, sizeof(par)); |
| 650 | 666 | |
| 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 { | |
| 652 | 673 | par.ExtParam = s->ext_buffers; |
| 653 | 674 | par.NumExtParam = FF_ARRAY_ELEMS(s->ext_buffers); |
| 654 | 675 | par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY : |
| 655 | 676 | MFX_IOPATTERN_IN_OPAQUE_MEMORY; |
| 656 | − } else { | |
| 657 | − par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY : | |
| 658 | − MFX_IOPATTERN_IN_VIDEO_MEMORY; | |
| 659 | 677 | } |
| 678 | +#endif | |
| 660 | 679 | |
| 661 | 680 | par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY : |
| 662 | 681 | MFX_IOPATTERN_OUT_SYSTEM_MEMORY; |
| @@ -688,11 +707,15 @@ static int qsv_frames_init(AVHWFramesContext *ctx) · 25 unmodified lines | ||
| 688 | 707 | QSVFramesContext *s = ctx->internal->priv; |
| 689 | 708 | AVQSVFramesContext *frames_hwctx = ctx->hwctx; |
| 690 | 709 | |
| 691 | − int opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); | |
| 710 | + int opaque = 0; | |
| 692 | 711 | |
| 693 | 712 | uint32_t fourcc; |
| 694 | 713 | int i, ret; |
| 695 | 714 | |
| 715 | +#if QSV_HAVE_OPAQUE | |
| 716 | + opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); | |
| 717 | +#endif | |
| 718 | + | |
| 696 | 719 | fourcc = qsv_fourcc_from_pix_fmt(ctx->sw_format); |
| 697 | 720 | if (!fourcc) { |
| 698 | 721 | av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format\n"); |
| @@ -707,7 +730,16 @@ static int qsv_frames_init(AVHWFramesContext *ctx) · 8 unmodified lines | ||
| 707 | 730 | } |
| 708 | 731 | } |
| 709 | 732 | |
| 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 { | |
| 711 | 743 | s->surface_ptrs = av_calloc(frames_hwctx->nb_surfaces, |
| 712 | 744 | sizeof(*s->surface_ptrs)); |
| 713 | 745 | if (!s->surface_ptrs) |
| @@ -726,14 +758,8 @@ static int qsv_frames_init(AVHWFramesContext *ctx) · 12 unmodified lines | ||
| 726 | 758 | s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc); |
| 727 | 759 | |
| 728 | 760 | 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; | |
| 736 | 761 | } |
| 762 | +#endif | |
| 737 | 763 | |
| 738 | 764 | s->session_download = NULL; |
| 739 | 765 | s->session_upload = NULL; |