19 #include <stdatomic.h>
54 #define QSV_VERSION_ATLEAST(MAJOR, MINOR) \
55 (MFX_VERSION_MAJOR > (MAJOR) || \
56 MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
58 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
59 #define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0)
60 #define QSV_HAVE_OPAQUE !QSV_ONEVPL
63 #include <mfxdispatcher.h>
65 #define MFXUnload(a) do { } while(0)
109 static const struct {
119 MFX_FOURCC_YUY2, 0 },
122 MFX_FOURCC_UYVY, 0 },
125 MFX_FOURCC_Y210, 1 },
129 MFX_FOURCC_AYUV, 0 },
133 MFX_FOURCC_Y410, 0 },
134 #if QSV_VERSION_ATLEAST(1, 31)
138 MFX_FOURCC_P016, 1 },
142 MFX_FOURCC_Y216, 1 },
146 MFX_FOURCC_Y416, 1 },
161 mfxHDLPair *handle_pair;
162 handle_pair = surf->Data.MemId;
163 switch (base_dev_type) {
166 base_handle[0] = handle_pair->first;
171 base_handle[0] = handle_pair->first;
172 base_handle[1] = handle_pair->second;
177 base_handle[0] = handle_pair->first;
205 static uint32_t qsv_get_d3d11va_bind_flags(
int mem_type)
207 uint32_t bind_flags = 0;
209 if ((mem_type & MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET) && (mem_type & MFX_MEMTYPE_INTERNAL_FRAME))
210 bind_flags = D3D11_BIND_DECODER | D3D11_BIND_VIDEO_ENCODER;
212 bind_flags = D3D11_BIND_DECODER;
214 if ((MFX_MEMTYPE_FROM_VPPOUT & mem_type) || (MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & mem_type))
215 bind_flags = D3D11_BIND_RENDER_TARGET;
224 int i, planes_nb = 0;
230 for (
i = 0;
i <
desc->nb_components;
i++)
231 planes_nb =
FFMAX(planes_nb,
desc->comp[
i].plane + 1);
233 for (
i = 0;
i < planes_nb;
i++) {
234 int sheight, dheight, y;
242 if (swidth < 0 || dwidth < 0) {
246 sheight =
src->height;
253 for (y = 0; y < sheight; y++) {
256 comp.depth > 8 ? 2 : 1,
260 for (y = sheight; y < dheight; y++) {
273 int hw_handle_supported = 0;
274 mfxHandleType handle_type;
279 err = MFXQueryIMPL(hwctx->
session, &
s->impl);
280 if (err == MFX_ERR_NONE)
281 err = MFXQueryVersion(hwctx->
session, &
s->ver);
282 if (err != MFX_ERR_NONE) {
289 handle_type = MFX_HANDLE_VA_DISPLAY;
292 hw_handle_supported = 1;
296 handle_type = MFX_HANDLE_D3D11_DEVICE;
299 hw_handle_supported = 1;
303 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
306 hw_handle_supported = 1;
310 if (hw_handle_supported) {
311 err = MFXVideoCORE_GetHandle(hwctx->
session, handle_type, &
s->handle);
312 if (err == MFX_ERR_NONE) {
313 s->handle_type = handle_type;
314 s->child_device_type = device_type;
320 "from the session\n");
329 if (
s->session_download) {
330 MFXVideoVPP_Close(
s->session_download);
331 MFXClose(
s->session_download);
333 s->session_download =
NULL;
334 s->session_download_init = 0;
336 if (
s->session_upload) {
337 MFXVideoVPP_Close(
s->session_upload);
338 MFXClose(
s->session_upload);
340 s->session_upload =
NULL;
341 s->session_upload_init = 0;
369 s->nb_surfaces_used++;
391 if (!device_priv->
handle) {
393 "Cannot create a non-opaque internal surface pool without "
394 "a hardware handle\n");
399 if (!child_device_ref)
406 child_device_hwctx->
display = (VADisplay)device_priv->
handle;
419 child_device_hwctx->
devmgr = (IDirect3DDeviceManager9*)device_priv->
handle;
430 if (!child_frames_ref) {
446 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
447 if (hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
448 child_frames_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
455 if (hwctx->
frame_type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)
456 child_frames_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
458 child_frames_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
471 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
472 s->handle_pairs_internal[
i].first = child_frames_hwctx->
surface_ids +
i;
473 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
474 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
476 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
482 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
484 if(child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
485 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
489 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
491 if (child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
492 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
494 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
501 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
502 s->handle_pairs_internal[
i].first = (mfxMemId)child_frames_hwctx->
surfaces[
i];
503 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
504 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
506 if (child_frames_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
507 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
509 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
513 s->child_frames_ref = child_frames_ref;
514 child_frames_ref =
NULL;
535 surf->Info.BitDepthLuma =
desc->comp[0].depth;
536 surf->Info.BitDepthChroma =
desc->comp[0].depth;
539 if (
desc->log2_chroma_w &&
desc->log2_chroma_h)
540 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
541 else if (
desc->log2_chroma_w)
542 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV422;
544 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV444;
546 surf->Info.FourCC =
fourcc;
548 surf->Info.CropW =
ctx->width;
550 surf->Info.CropH =
ctx->height;
551 surf->Info.FrameRateExtN = 25;
552 surf->Info.FrameRateExtD = 1;
553 surf->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
565 if (
ctx->initial_pool_size <= 0) {
571 sizeof(*
s->handle_pairs_internal));
572 if (!
s->handle_pairs_internal)
576 sizeof(*
s->surfaces_internal));
577 if (!
s->surfaces_internal)
580 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
587 if (!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) {
600 if (!
ctx->internal->pool_internal)
603 frames_hwctx->
surfaces =
s->surfaces_internal;
609 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
610 mfxFrameAllocResponse *resp)
615 mfxFrameInfo *
i = &req->Info;
616 mfxFrameInfo *i1 = &hwctx->
surfaces[0].Info;
618 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
619 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
620 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
621 return MFX_ERR_UNSUPPORTED;
622 if (
i->Width > i1->Width ||
i->Height > i1->Height ||
623 i->FourCC != i1->FourCC ||
i->ChromaFormat != i1->ChromaFormat) {
625 "allocation request: %dx%d %d %d vs %dx%d %d %d\n",
626 i->Width,
i->Height,
i->FourCC,
i->ChromaFormat,
627 i1->Width, i1->Height, i1->FourCC, i1->ChromaFormat);
628 return MFX_ERR_UNSUPPORTED;
631 resp->mids =
s->mem_ids;
637 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
642 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
644 return MFX_ERR_UNSUPPORTED;
647 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
649 return MFX_ERR_UNSUPPORTED;
654 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
655 mfxHDLPair *pair_src = (mfxHDLPair*)mid;
657 pair_dst->first = pair_src->first;
659 if (pair_src->second != (mfxMemId)MFX_INFINITE)
660 pair_dst->second = pair_src->second;
666 static int qsv_d3d11_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
671 IDXGIAdapter *pDXGIAdapter;
672 DXGI_ADAPTER_DESC adapterDesc;
673 IDXGIDevice *pDXGIDevice =
NULL;
676 mfxVariant impl_value;
678 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (
void**)&pDXGIDevice);
680 hr = IDXGIDevice_GetAdapter(pDXGIDevice, &pDXGIAdapter);
683 IDXGIDevice_Release(pDXGIDevice);
687 hr = IDXGIAdapter_GetDesc(pDXGIAdapter, &adapterDesc);
697 impl_value.Type = MFX_VARIANT_TYPE_U16;
698 impl_value.Data.U16 = adapterDesc.DeviceId;
699 sts = MFXSetConfigFilterProperty(cfg,
700 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceID", impl_value);
701 if (sts != MFX_ERR_NONE) {
703 "DeviceID property: %d.\n", sts);
707 impl_value.Type = MFX_VARIANT_TYPE_PTR;
708 impl_value.Data.Ptr = &adapterDesc.AdapterLuid;
709 sts = MFXSetConfigFilterProperty(cfg,
710 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
711 if (sts != MFX_ERR_NONE) {
713 "DeviceLUID property: %d.\n", sts);
717 impl_value.Type = MFX_VARIANT_TYPE_U32;
718 impl_value.Data.U32 = 0x0001;
719 sts = MFXSetConfigFilterProperty(cfg,
720 (
const mfxU8 *)
"mfxExtendedDeviceId.LUIDDeviceNodeMask", impl_value);
721 if (sts != MFX_ERR_NONE) {
723 "LUIDDeviceNodeMask property: %d.\n", sts);
730 IDXGIAdapter_Release(pDXGIAdapter);
731 IDXGIDevice_Release(pDXGIDevice);
736 static int qsv_d3d9_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
741 IDirect3DDeviceManager9* devmgr = handle;
742 IDirect3DDevice9Ex *device =
NULL;
743 HANDLE device_handle = 0;
744 IDirect3D9Ex *d3d9ex =
NULL;
746 D3DDEVICE_CREATION_PARAMETERS params;
748 mfxVariant impl_value;
750 hr = IDirect3DDeviceManager9_OpenDeviceHandle(devmgr, &device_handle);
756 hr = IDirect3DDeviceManager9_LockDevice(devmgr, device_handle, &device, TRUE);
759 IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle);
763 hr = IDirect3DDevice9Ex_GetCreationParameters(device, ¶ms);
766 IDirect3DDevice9Ex_Release(device);
770 hr = IDirect3DDevice9Ex_GetDirect3D(device, &d3d9ex);
773 IDirect3DDevice9Ex_Release(device);
777 hr = IDirect3D9Ex_GetAdapterLUID(d3d9ex, params.AdapterOrdinal, &luid);
783 impl_value.Type = MFX_VARIANT_TYPE_PTR;
784 impl_value.Data.Ptr = &luid;
785 sts = MFXSetConfigFilterProperty(cfg,
786 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
787 if (sts != MFX_ERR_NONE) {
789 "DeviceLUID property: %d.\n", sts);
796 IDirect3D9Ex_Release(d3d9ex);
797 IDirect3DDevice9Ex_Release(device);
800 IDirect3DDeviceManager9_UnlockDevice(devmgr, device_handle, FALSE);
801 IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle);
807 static int qsv_va_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
810 #if VA_CHECK_VERSION(1, 15, 0)
812 VADisplay dpy = handle;
814 VADisplayAttribute attr = {
815 .type = VADisplayPCIID,
817 mfxVariant impl_value;
819 vas = vaGetDisplayAttributes(dpy, &attr, 1);
820 if (vas == VA_STATUS_SUCCESS && attr.flags != VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
821 impl_value.Type = MFX_VARIANT_TYPE_U16;
822 impl_value.Data.U16 = (attr.value & 0xFFFF);
823 sts = MFXSetConfigFilterProperty(cfg,
824 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceID", impl_value);
825 if (sts != MFX_ERR_NONE) {
827 "DeviceID property: %d.\n", sts);
832 "consider to upgrade the driver to support VA-API 1.15.0\n");
841 "the device information from the driver. Please consider to upgrade libva to "
842 "support VA-API 1.15.0\n");
848 static int qsv_new_mfx_loader(
void *
ctx,
850 mfxHandleType handle_type,
851 mfxIMPL implementation,
856 mfxLoader loader =
NULL;
858 mfxVariant impl_value;
868 cfg = MFXCreateConfig(loader);
874 impl_value.Type = MFX_VARIANT_TYPE_U32;
875 impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
876 MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
877 sts = MFXSetConfigFilterProperty(cfg,
878 (
const mfxU8 *)
"mfxImplDescription.Impl", impl_value);
879 if (sts != MFX_ERR_NONE) {
881 "property: %d.\n", sts);
885 impl_value.Type = MFX_VARIANT_TYPE_U32;
886 impl_value.Data.U32 = pver->Version;
887 sts = MFXSetConfigFilterProperty(cfg,
888 (
const mfxU8 *)
"mfxImplDescription.ApiVersion.Version",
890 if (sts != MFX_ERR_NONE) {
892 "property: %d.\n", sts);
896 impl_value.Type = MFX_VARIANT_TYPE_U16;
897 impl_value.Data.U16 = 0x8086;
898 sts = MFXSetConfigFilterProperty(cfg,
899 (
const mfxU8 *)
"mfxExtendedDeviceId.VendorID", impl_value);
900 if (sts != MFX_ERR_NONE) {
902 "VendorID property: %d.\n", sts);
906 if (MFX_HANDLE_VA_DISPLAY == handle_type) {
907 if (handle && qsv_va_update_config(
ctx, handle, cfg))
910 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_VAAPI;
911 }
else if (MFX_HANDLE_D3D9_DEVICE_MANAGER == handle_type) {
912 if (handle && qsv_d3d9_update_config(
ctx, handle, cfg))
915 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D9;
917 if (handle && qsv_d3d11_update_config(
ctx, handle, cfg))
920 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D11;
923 impl_value.Type = MFX_VARIANT_TYPE_U32;
924 sts = MFXSetConfigFilterProperty(cfg,
925 (
const mfxU8 *)
"mfxImplDescription.AccelerationMode", impl_value);
926 if (sts != MFX_ERR_NONE) {
928 "AccelerationMode property: %d.\n", sts);
943 static int qsv_create_mfx_session_from_loader(
void *
ctx, mfxLoader loader, mfxSession *psession)
946 mfxSession session =
NULL;
947 uint32_t impl_idx = 0;
952 mfxImplDescription *impl_desc;
954 sts = MFXEnumImplementations(loader, impl_idx,
955 MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
956 (mfxHDL *)&impl_desc);
958 if (sts == MFX_ERR_NOT_FOUND)
960 else if (sts != MFX_ERR_NONE) {
965 sts = MFXCreateSession(loader, impl_idx, &session);
966 MFXDispReleaseImplDescription(loader, impl_desc);
967 if (sts == MFX_ERR_NONE)
973 if (sts != MFX_ERR_NONE) {
978 sts = MFXQueryVersion(session, &ver);
979 if (sts != MFX_ERR_NONE) {
985 "version is %d.%d\n", ver.Major, ver.Minor);
1000 mfxHandleType handle_type,
1001 mfxIMPL implementation,
1003 mfxSession *psession,
1006 mfxLoader loader =
NULL;
1009 "Use Intel(R) oneVPL to create MFX session, API version is "
1010 "%d.%d, the required implementation version is %d.%d\n",
1011 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1013 if (handle_type != MFX_HANDLE_VA_DISPLAY &&
1014 handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER &&
1015 handle_type != MFX_HANDLE_D3D11_DEVICE) {
1017 "Invalid MFX device handle type\n");
1024 if (qsv_new_mfx_loader(
ctx, handle, handle_type, implementation, pver, (
void **)&loader))
1031 if (qsv_create_mfx_session_from_loader(
ctx, loader, psession))
1040 if (!*ploader && loader)
1050 mfxHandleType handle_type,
1051 mfxIMPL implementation,
1053 mfxSession *psession,
1058 mfxSession session =
NULL;
1061 "Use Intel(R) Media SDK to create MFX session, API version is "
1062 "%d.%d, the required implementation version is %d.%d\n",
1063 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1068 sts = MFXInit(implementation, &ver, &session);
1069 if (sts != MFX_ERR_NONE) {
1075 sts = MFXQueryVersion(session, &ver);
1076 if (sts != MFX_ERR_NONE) {
1083 "version is %d.%d\n", ver.Major, ver.Minor);
1087 sts = MFXInit(implementation, &ver, &session);
1088 if (sts != MFX_ERR_NONE) {
1094 *psession = session;
1108 mfxSession *session,
int upload)
1114 mfxFrameAllocator frame_allocator = {
1128 void **loader = &hwctx->
loader;
1132 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1136 device_priv->
impl, &device_priv->
ver, session, loader);
1140 if (device_priv->
handle) {
1141 err = MFXVideoCORE_SetHandle(*session, device_priv->
handle_type,
1143 if (err != MFX_ERR_NONE) {
1150 err = MFXVideoCORE_SetFrameAllocator(*session, &frame_allocator);
1151 if (err != MFX_ERR_NONE) {
1157 memset(&par, 0,
sizeof(par));
1160 par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
1161 MFX_IOPATTERN_IN_VIDEO_MEMORY;
1165 par.ExtParam =
s->ext_buffers;
1167 par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
1168 MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1172 par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
1173 MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
1176 par.vpp.In = frames_hwctx->
surfaces[0].Info;
1182 par.vpp.In.FrameRateExtN = 25;
1183 par.vpp.In.FrameRateExtD = 1;
1184 par.vpp.Out = par.vpp.In;
1186 err = MFXVideoVPP_Init(*session, &par);
1187 if (err != MFX_ERR_NONE) {
1189 "Surface upload/download will not be possible\n");
1217 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1240 s->mem_ids[
i] = frames_hwctx->
surfaces[
i].Data.MemId;
1245 sizeof(*
s->surface_ptrs));
1246 if (!
s->surface_ptrs)
1252 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
1253 s->opaque_alloc.In.NumSurface = frames_hwctx->
nb_surfaces;
1254 s->opaque_alloc.In.Type = frames_hwctx->
frame_type;
1256 s->opaque_alloc.Out =
s->opaque_alloc.In;
1258 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1259 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
1261 s->ext_buffers[0] = (mfxExtBuffer*)&
s->opaque_alloc;
1265 s->session_download =
NULL;
1266 s->session_upload =
NULL;
1268 s->session_download_init = 0;
1269 s->session_upload_init = 0;
1302 fmts[0] =
ctx->sw_format;
1326 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1327 dst_hwctx->
surface_ids[
i] = *(VASurfaceID*)pair->first;
1336 D3D11_TEXTURE2D_DESC texDesc;
1343 if (src_hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
1344 dst_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
1346 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1348 dst_hwctx->
texture_infos[
i].
index = pair->second == (mfxMemId)MFX_INFINITE ? (intptr_t)0 : (intptr_t)pair->second;
1351 dst_hwctx->
BindFlags = texDesc.BindFlags;
1364 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1365 dst_hwctx->
surfaces[
i] = (IDirect3DSurface9*)pair->first;
1368 if (src_hwctx->
frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
1369 dst_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
1371 dst_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
1386 mfxFrameSurface1 *surf = (mfxFrameSurface1*)
src->data[3];
1389 uint8_t *child_data;
1393 if (!
s->child_frames_ref)
1397 switch (child_frames_ctx->device_ctx->type) {
1401 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1406 child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
1413 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1414 child_data = pair->first;
1421 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1422 child_data = pair->first;
1430 if (dst->
format == child_frames_ctx->format) {
1440 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1441 dst->
data[0] = pair->first;
1442 dst->
data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1444 dst->
data[3] = child_data;
1465 dummy->format = child_frames_ctx->format;
1470 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1471 dummy->data[0] = pair->first;
1472 dummy->data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1474 dummy->data[3] = child_data;
1490 int download = !!
src->hw_frames_ctx;
1491 mfxFrameSurface1 *surf = (mfxFrameSurface1*)(download ?
src->data[3] : dst->
data[3]);
1503 dummy->buf[0] = download ?
src->buf[0] : dst->
buf[0];
1504 dummy->data[3] = surf->Data.MemId;
1505 dummy->hw_frames_ctx =
s->child_frames_ref;
1549 surface->Data.Y16 = (mfxU16 *)
frame->
data[0];
1550 surface->Data.U16 = (mfxU16 *)
frame->
data[0] + 1;
1551 surface->Data.V16 = (mfxU16 *)
frame->
data[0] + 3;
1580 return MFX_ERR_UNSUPPORTED;
1583 surface->Data.TimeStamp =
frame->
pts;
1591 atomic_int *inited = upload ? &
s->session_upload_init : &
s->session_download_init;
1592 mfxSession *session = upload ? &
s->session_upload : &
s->session_download;
1618 mfxFrameSurface1
out = {{ 0 }};
1619 mfxFrameSurface1 *in = (mfxFrameSurface1*)
src->data[3];
1621 mfxSyncPoint sync =
NULL;
1625 AVFrame *tmp_frame = &
s->realigned_download_frame;
1638 if (tmp_frame->format != dst->
format ||
1643 tmp_frame->format = dst->
format;
1652 dst_frame = realigned ? tmp_frame : dst;
1654 if (!
s->session_download) {
1655 if (
s->child_frames_ref)
1662 out.Info = in->Info;
1666 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_download, in, &
out,
NULL, &sync);
1667 if (err == MFX_WRN_DEVICE_BUSY)
1669 }
while (err == MFX_WRN_DEVICE_BUSY);
1671 if (err < 0 || !sync) {
1677 err = MFXVideoCORE_SyncOperation(
s->session_download, sync, 1000);
1678 }
while (err == MFX_WRN_IN_EXECUTION);
1685 tmp_frame->width = dst->
width;
1686 tmp_frame->height = dst->
height;
1701 mfxFrameSurface1 in = {{ 0 }};
1702 mfxFrameSurface1 *
out = (mfxFrameSurface1*)dst->
data[3];
1703 mfxFrameInfo tmp_info;
1705 mfxSyncPoint sync =
NULL;
1709 AVFrame *tmp_frame = &
s->realigned_upload_frame;
1720 if (
src->height & 15 ||
src->linesize[0] & 15) {
1722 if (tmp_frame->format !=
src->format ||
1723 tmp_frame->width !=
FFALIGN(
src->width, 16) ||
1724 tmp_frame->height !=
FFALIGN(
src->height, 16)) {
1727 tmp_frame->format =
src->format;
1729 tmp_frame->height =
FFALIGN(
src->height, 16);
1745 tmp_info =
out->Info;
1746 out->Info.CropW =
FFMIN(
out->Info.Width, tmp_frame->width);
1747 out->Info.CropH =
FFMIN(
out->Info.Height, tmp_frame->height);
1750 src_frame = realigned ? tmp_frame :
src;
1752 if (!
s->session_upload) {
1753 if (
s->child_frames_ref)
1760 in.Info =
out->Info;
1764 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_upload, &in,
out,
NULL, &sync);
1765 if (err == MFX_WRN_DEVICE_BUSY)
1767 }
while (err == MFX_WRN_DEVICE_BUSY);
1769 if (err < 0 || !sync) {
1775 err = MFXVideoCORE_SyncOperation(
s->session_upload, sync, 1000);
1776 }
while (err == MFX_WRN_IN_EXECUTION);
1783 out->Info.CropW = tmp_info.CropW;
1784 out->Info.CropH = tmp_info.CropH;
1799 "mapped to QSV frames.\n");
1809 sizeof(*
s->handle_pairs_internal));
1810 if (!
s->handle_pairs_internal)
1813 sizeof(*
s->surfaces_internal));
1814 if (!
s->surfaces_internal)
1819 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1820 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1823 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1832 sizeof(*
s->handle_pairs_internal));
1833 if (!
s->handle_pairs_internal)
1836 sizeof(*
s->surfaces_internal));
1837 if (!
s->surfaces_internal)
1842 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1843 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1847 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1850 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1851 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1853 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1863 sizeof(*
s->handle_pairs_internal));
1864 if (!
s->handle_pairs_internal)
1867 sizeof(*
s->surfaces_internal));
1868 if (!
s->surfaces_internal)
1872 s->handle_pairs_internal[
i].first = (mfxMemId)src_hwctx->
surfaces[
i];
1873 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1874 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1877 if (src_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
1878 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1880 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1888 dst_hwctx->
surfaces =
s->surfaces_internal;
1900 switch(
src->format) {
1904 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1905 if (*(VASurfaceID*)pair->first == (VASurfaceID)(uintptr_t)
src->data[3]) {
1914 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1915 if (pair->first ==
src->data[0]
1916 && (pair->second ==
src->data[1]
1917 || (pair->second == (mfxMemId)MFX_INFINITE &&
src->data[1] == (uint8_t *)0))) {
1926 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1927 if (pair->first ==
src->data[3]) {
1937 "is not in the mapped frames context.\n");
1954 const void *hwconfig,
1994 static const struct {
1998 {
"auto", MFX_IMPL_AUTO },
1999 {
"sw", MFX_IMPL_SOFTWARE },
2000 {
"hw", MFX_IMPL_HARDWARE },
2001 {
"auto_any", MFX_IMPL_AUTO_ANY },
2002 {
"hw_any", MFX_IMPL_HARDWARE_ANY },
2003 {
"hw2", MFX_IMPL_HARDWARE2 },
2004 {
"hw3", MFX_IMPL_HARDWARE3 },
2005 {
"hw4", MFX_IMPL_HARDWARE4 },
2008 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
2013 if (!strcmp(device, impl_map[
i].
name)) {
2014 impl = impl_map[
i].impl;
2018 impl = strtol(device,
NULL, 0);
2021 if (impl != MFX_IMPL_SOFTWARE) {
2023 impl |= MFX_IMPL_VIA_D3D11;
2025 impl |= MFX_IMPL_VIA_D3D9;
2032 mfxIMPL implementation,
2038 mfxVersion ver = { { 3, 1 } };
2040 mfxHandleType handle_type;
2044 switch (child_device_ctx->
type) {
2049 handle_type = MFX_HANDLE_VA_DISPLAY;
2050 handle = (mfxHDL)child_device_hwctx->
display;
2058 handle_type = MFX_HANDLE_D3D11_DEVICE;
2059 handle = (mfxHDL)child_device_hwctx->
device;
2067 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
2068 handle = (mfxHDL)child_device_hwctx->
devmgr;
2082 err = MFXVideoCORE_SetHandle(hwctx->
session, handle_type, handle);
2083 if (err != MFX_ERR_NONE) {
2115 ctx->user_opaque = priv;
2120 child_device_ctx,
flags);
2139 ctx->user_opaque = priv;
2147 "\"%s\".\n", e->
value);
2151 }
else if (CONFIG_D3D11VA) {
2153 "Defaulting child_device_type to AV_HWDEVICE_TYPE_D3D11VA for oneVPL."
2154 "Please explicitly set child device type via \"-init_hw_device\" "
2155 "option if needed.\n");
2157 }
else if (CONFIG_DXVA2) {
2160 }
else if (CONFIG_DXVA2) {
2162 "WARNING: defaulting child_device_type to AV_HWDEVICE_TYPE_DXVA2 for compatibility "
2163 "with old commandlines. This behaviour will be removed "
2164 "in the future. Please explicitly set device type via \"-init_hw_device\" option.\n");
2166 }
else if (CONFIG_D3D11VA) {
2169 }
else if (CONFIG_VAAPI) {
2176 #if CONFIG_VAAPI && defined(_WIN32)
2181 "\"%s\".\n", e->
value);
2186 child_device_opts =
NULL;
2187 switch (child_device_type) {
2196 av_dict_set(&child_device_opts,
"kernel_driver",
"i915", 0);
2197 av_dict_set(&child_device_opts,
"driver",
"iHD", 0);
2210 "d3d11va is not available or child device type is set to dxva2 "
2211 "explicitly for oneVPL.\n");
2226 e ? e->
value :
NULL, child_device_opts, 0);