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 QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
59 ((MFX_VERSION.Major > (MAJOR)) || \
60 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
62 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
63 #define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0)
64 #define QSV_HAVE_OPAQUE !QSV_ONEVPL
67 #include <mfxdispatcher.h>
69 #define MFXUnload(a) do { } while(0)
123 static const struct {
133 MFX_FOURCC_YUY2, 0 },
136 MFX_FOURCC_UYVY, 0 },
139 MFX_FOURCC_Y210, 1 },
143 MFX_FOURCC_AYUV, 0 },
147 MFX_FOURCC_Y410, 0 },
148 #if QSV_VERSION_ATLEAST(1, 31)
152 MFX_FOURCC_P016, 1 },
156 MFX_FOURCC_Y216, 1 },
160 MFX_FOURCC_Y416, 1 },
175 mfxHDLPair *handle_pair;
176 handle_pair = surf->Data.MemId;
177 switch (base_dev_type) {
180 base_handle[0] = handle_pair->first;
185 base_handle[0] = handle_pair->first;
186 base_handle[1] = handle_pair->second;
191 base_handle[0] = handle_pair->first;
219 static uint32_t qsv_get_d3d11va_bind_flags(
int mem_type)
221 uint32_t bind_flags = 0;
223 if ((mem_type & MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET) && (mem_type & MFX_MEMTYPE_INTERNAL_FRAME))
224 bind_flags = D3D11_BIND_DECODER | D3D11_BIND_VIDEO_ENCODER;
226 bind_flags = D3D11_BIND_DECODER;
228 if ((MFX_MEMTYPE_FROM_VPPOUT & mem_type) || (MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & mem_type))
229 bind_flags = D3D11_BIND_RENDER_TARGET;
238 int i, planes_nb = 0;
244 for (
i = 0;
i <
desc->nb_components;
i++)
245 planes_nb =
FFMAX(planes_nb,
desc->comp[
i].plane + 1);
247 for (
i = 0;
i < planes_nb;
i++) {
248 int sheight, dheight, y;
256 if (swidth < 0 || dwidth < 0) {
260 sheight =
src->height;
267 for (y = 0; y < sheight; y++) {
270 comp.depth > 8 ? 2 : 1,
274 for (y = sheight; y < dheight; y++) {
287 int hw_handle_supported = 0;
288 mfxHandleType handle_type;
293 err = MFXQueryIMPL(hwctx->
session, &
s->impl);
294 if (err == MFX_ERR_NONE)
295 err = MFXQueryVersion(hwctx->
session, &
s->ver);
296 if (err != MFX_ERR_NONE) {
303 handle_type = MFX_HANDLE_VA_DISPLAY;
306 hw_handle_supported = 1;
310 handle_type = MFX_HANDLE_D3D11_DEVICE;
313 hw_handle_supported = 1;
317 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
320 hw_handle_supported = 1;
324 if (hw_handle_supported) {
325 err = MFXVideoCORE_GetHandle(hwctx->
session, handle_type, &
s->handle);
326 if (err == MFX_ERR_NONE) {
327 s->handle_type = handle_type;
328 s->child_device_type = device_type;
334 "from the session\n");
343 if (
s->session_download) {
344 MFXVideoVPP_Close(
s->session_download);
345 MFXClose(
s->session_download);
347 s->session_download =
NULL;
348 s->session_download_init = 0;
350 if (
s->session_upload) {
351 MFXVideoVPP_Close(
s->session_upload);
352 MFXClose(
s->session_upload);
354 s->session_upload =
NULL;
355 s->session_upload_init = 0;
383 s->nb_surfaces_used++;
405 if (!device_priv->
handle) {
407 "Cannot create a non-opaque internal surface pool without "
408 "a hardware handle\n");
413 if (!child_device_ref)
420 child_device_hwctx->
display = (VADisplay)device_priv->
handle;
433 child_device_hwctx->
devmgr = (IDirect3DDeviceManager9*)device_priv->
handle;
444 if (!child_frames_ref) {
460 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
461 if (hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
462 child_frames_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
469 if (hwctx->
frame_type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)
470 child_frames_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
472 child_frames_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
485 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
486 s->handle_pairs_internal[
i].first = child_frames_hwctx->
surface_ids +
i;
487 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
488 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
490 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
496 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
498 if(child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
499 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
503 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
505 if (child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
506 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
508 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
515 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
516 s->handle_pairs_internal[
i].first = (mfxMemId)child_frames_hwctx->
surfaces[
i];
517 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
518 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
520 if (child_frames_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
521 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
523 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
527 s->child_frames_ref = child_frames_ref;
528 child_frames_ref =
NULL;
549 surf->Info.BitDepthLuma =
desc->comp[0].depth;
550 surf->Info.BitDepthChroma =
desc->comp[0].depth;
553 if (
desc->log2_chroma_w &&
desc->log2_chroma_h)
554 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
555 else if (
desc->log2_chroma_w)
556 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV422;
558 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV444;
560 surf->Info.FourCC =
fourcc;
562 surf->Info.CropW =
ctx->width;
564 surf->Info.CropH =
ctx->height;
565 surf->Info.FrameRateExtN = 25;
566 surf->Info.FrameRateExtD = 1;
567 surf->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
579 if (
ctx->initial_pool_size <= 0) {
585 sizeof(*
s->handle_pairs_internal));
586 if (!
s->handle_pairs_internal)
590 sizeof(*
s->surfaces_internal));
591 if (!
s->surfaces_internal)
594 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
601 if (!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) {
617 frames_hwctx->
surfaces =
s->surfaces_internal;
623 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
624 mfxFrameAllocResponse *resp)
629 mfxFrameInfo *
i = &req->Info;
630 mfxFrameInfo *i1 = &hwctx->
surfaces[0].Info;
632 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
633 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
634 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
635 return MFX_ERR_UNSUPPORTED;
636 if (
i->Width > i1->Width ||
i->Height > i1->Height ||
637 i->FourCC != i1->FourCC ||
i->ChromaFormat != i1->ChromaFormat) {
639 "allocation request: %dx%d %d %d vs %dx%d %d %d\n",
640 i->Width,
i->Height,
i->FourCC,
i->ChromaFormat,
641 i1->Width, i1->Height, i1->FourCC, i1->ChromaFormat);
642 return MFX_ERR_UNSUPPORTED;
645 resp->mids =
s->mem_ids;
651 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
656 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
658 return MFX_ERR_UNSUPPORTED;
661 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
663 return MFX_ERR_UNSUPPORTED;
668 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
669 mfxHDLPair *pair_src = (mfxHDLPair*)mid;
671 pair_dst->first = pair_src->first;
673 if (pair_src->second != (mfxMemId)MFX_INFINITE)
674 pair_dst->second = pair_src->second;
680 static int qsv_d3d11_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
685 IDXGIAdapter *pDXGIAdapter;
686 DXGI_ADAPTER_DESC adapterDesc;
687 IDXGIDevice *pDXGIDevice =
NULL;
690 mfxVariant impl_value;
692 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (
void**)&pDXGIDevice);
694 hr = IDXGIDevice_GetAdapter(pDXGIDevice, &pDXGIAdapter);
697 IDXGIDevice_Release(pDXGIDevice);
701 hr = IDXGIAdapter_GetDesc(pDXGIAdapter, &adapterDesc);
711 impl_value.Type = MFX_VARIANT_TYPE_U16;
712 impl_value.Data.U16 = adapterDesc.DeviceId;
713 sts = MFXSetConfigFilterProperty(cfg,
714 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceID", impl_value);
715 if (sts != MFX_ERR_NONE) {
717 "DeviceID property: %d.\n", sts);
721 impl_value.Type = MFX_VARIANT_TYPE_PTR;
722 impl_value.Data.Ptr = &adapterDesc.AdapterLuid;
723 sts = MFXSetConfigFilterProperty(cfg,
724 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
725 if (sts != MFX_ERR_NONE) {
727 "DeviceLUID property: %d.\n", sts);
731 impl_value.Type = MFX_VARIANT_TYPE_U32;
732 impl_value.Data.U32 = 0x0001;
733 sts = MFXSetConfigFilterProperty(cfg,
734 (
const mfxU8 *)
"mfxExtendedDeviceId.LUIDDeviceNodeMask", impl_value);
735 if (sts != MFX_ERR_NONE) {
737 "LUIDDeviceNodeMask property: %d.\n", sts);
744 IDXGIAdapter_Release(pDXGIAdapter);
745 IDXGIDevice_Release(pDXGIDevice);
750 static int qsv_d3d9_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
755 IDirect3DDeviceManager9* devmgr = handle;
756 IDirect3DDevice9Ex *device =
NULL;
757 HANDLE device_handle = 0;
758 IDirect3D9Ex *d3d9ex =
NULL;
760 D3DDEVICE_CREATION_PARAMETERS params;
762 mfxVariant impl_value;
764 hr = IDirect3DDeviceManager9_OpenDeviceHandle(devmgr, &device_handle);
770 hr = IDirect3DDeviceManager9_LockDevice(devmgr, device_handle, &device, TRUE);
773 IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle);
777 hr = IDirect3DDevice9Ex_GetCreationParameters(device, ¶ms);
780 IDirect3DDevice9Ex_Release(device);
784 hr = IDirect3DDevice9Ex_GetDirect3D(device, &d3d9ex);
787 IDirect3DDevice9Ex_Release(device);
791 hr = IDirect3D9Ex_GetAdapterLUID(d3d9ex, params.AdapterOrdinal, &luid);
797 impl_value.Type = MFX_VARIANT_TYPE_PTR;
798 impl_value.Data.Ptr = &luid;
799 sts = MFXSetConfigFilterProperty(cfg,
800 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
801 if (sts != MFX_ERR_NONE) {
803 "DeviceLUID property: %d.\n", sts);
810 IDirect3D9Ex_Release(d3d9ex);
811 IDirect3DDevice9Ex_Release(device);
814 IDirect3DDeviceManager9_UnlockDevice(devmgr, device_handle, FALSE);
815 IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle);
821 static int qsv_va_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
824 #if VA_CHECK_VERSION(1, 15, 0)
826 VADisplay dpy = handle;
828 VADisplayAttribute attr = {
829 .type = VADisplayPCIID,
831 mfxVariant impl_value;
833 vas = vaGetDisplayAttributes(dpy, &attr, 1);
834 if (vas == VA_STATUS_SUCCESS && attr.flags != VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
835 impl_value.Type = MFX_VARIANT_TYPE_U16;
836 impl_value.Data.U16 = (attr.value & 0xFFFF);
837 sts = MFXSetConfigFilterProperty(cfg,
838 (
const mfxU8 *)
"mfxImplDescription.mfxDeviceDescription.DeviceID", impl_value);
839 if (sts != MFX_ERR_NONE) {
841 "DeviceID property: %d.\n", sts);
846 "consider to upgrade the driver to support VA-API 1.15.0\n");
855 "the device information from the driver. Please consider to upgrade libva to "
856 "support VA-API 1.15.0\n");
862 static int qsv_new_mfx_loader(
void *
ctx,
864 mfxHandleType handle_type,
865 mfxIMPL implementation,
870 mfxLoader loader =
NULL;
872 mfxVariant impl_value;
882 cfg = MFXCreateConfig(loader);
888 impl_value.Type = MFX_VARIANT_TYPE_U32;
889 impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
890 MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
891 sts = MFXSetConfigFilterProperty(cfg,
892 (
const mfxU8 *)
"mfxImplDescription.Impl", impl_value);
893 if (sts != MFX_ERR_NONE) {
895 "property: %d.\n", sts);
899 impl_value.Type = MFX_VARIANT_TYPE_U32;
900 impl_value.Data.U32 = pver->Version;
901 sts = MFXSetConfigFilterProperty(cfg,
902 (
const mfxU8 *)
"mfxImplDescription.ApiVersion.Version",
904 if (sts != MFX_ERR_NONE) {
906 "property: %d.\n", sts);
910 impl_value.Type = MFX_VARIANT_TYPE_U32;
911 impl_value.Data.U32 = 0x8086;
912 sts = MFXSetConfigFilterProperty(cfg,
913 (
const mfxU8 *)
"mfxImplDescription.VendorID", impl_value);
914 if (sts != MFX_ERR_NONE) {
916 "VendorID property: %d.\n", sts);
920 if (MFX_HANDLE_VA_DISPLAY == handle_type) {
921 if (handle && qsv_va_update_config(
ctx, handle, cfg))
924 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_VAAPI;
925 }
else if (MFX_HANDLE_D3D9_DEVICE_MANAGER == handle_type) {
926 if (handle && qsv_d3d9_update_config(
ctx, handle, cfg))
929 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D9;
931 if (handle && qsv_d3d11_update_config(
ctx, handle, cfg))
934 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D11;
937 impl_value.Type = MFX_VARIANT_TYPE_U32;
938 sts = MFXSetConfigFilterProperty(cfg,
939 (
const mfxU8 *)
"mfxImplDescription.AccelerationMode", impl_value);
940 if (sts != MFX_ERR_NONE) {
942 "AccelerationMode property: %d.\n", sts);
957 static int qsv_create_mfx_session_from_loader(
void *
ctx, mfxLoader loader, mfxSession *psession)
960 mfxSession session =
NULL;
961 uint32_t impl_idx = 0;
966 mfxImplDescription *impl_desc;
968 sts = MFXEnumImplementations(loader, impl_idx,
969 MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
970 (mfxHDL *)&impl_desc);
972 if (sts == MFX_ERR_NOT_FOUND)
974 else if (sts != MFX_ERR_NONE) {
979 sts = MFXCreateSession(loader, impl_idx, &session);
980 MFXDispReleaseImplDescription(loader, impl_desc);
981 if (sts == MFX_ERR_NONE)
987 if (sts != MFX_ERR_NONE) {
992 sts = MFXQueryVersion(session, &ver);
993 if (sts != MFX_ERR_NONE) {
999 "version is %d.%d\n", ver.Major, ver.Minor);
1001 *psession = session;
1014 mfxHandleType handle_type,
1015 mfxIMPL implementation,
1017 mfxSession *psession,
1020 mfxLoader loader =
NULL;
1023 "Use Intel(R) oneVPL to create MFX session, API version is "
1024 "%d.%d, the required implementation version is %d.%d\n",
1025 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1027 if (handle_type != MFX_HANDLE_VA_DISPLAY &&
1028 handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER &&
1029 handle_type != MFX_HANDLE_D3D11_DEVICE) {
1031 "Invalid MFX device handle type\n");
1038 if (qsv_new_mfx_loader(
ctx, handle, handle_type, implementation, pver, (
void **)&loader))
1045 if (qsv_create_mfx_session_from_loader(
ctx, loader, psession))
1054 if (!*ploader && loader)
1064 mfxHandleType handle_type,
1065 mfxIMPL implementation,
1067 mfxSession *psession,
1072 mfxSession session =
NULL;
1075 "Use Intel(R) Media SDK to create MFX session, API version is "
1076 "%d.%d, the required implementation version is %d.%d\n",
1077 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1082 sts = MFXInit(implementation, &ver, &session);
1083 if (sts != MFX_ERR_NONE) {
1089 sts = MFXQueryVersion(session, &ver);
1090 if (sts != MFX_ERR_NONE) {
1097 "version is %d.%d\n", ver.Major, ver.Minor);
1101 sts = MFXInit(implementation, &ver, &session);
1102 if (sts != MFX_ERR_NONE) {
1108 *psession = session;
1122 mfxSession *session,
int upload)
1130 mfxFrameAllocator frame_allocator = {
1143 void **loader = &hwctx->
loader;
1144 mfxSession parent_session = hwctx->
session;
1148 err = MFXQueryIMPL(parent_session, &impl);
1149 if (err == MFX_ERR_NONE)
1150 err = MFXQueryVersion(parent_session, &ver);
1151 if (err != MFX_ERR_NONE) {
1157 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1161 device_priv->
impl, &device_priv->
ver, session, loader);
1165 if (device_priv->
handle) {
1166 err = MFXVideoCORE_SetHandle(*session, device_priv->
handle_type,
1168 if (err != MFX_ERR_NONE) {
1175 err = MFXJoinSession(parent_session, *session);
1176 if (err != MFX_ERR_NONE) {
1184 err = MFXVideoCORE_SetFrameAllocator(*session, &frame_allocator);
1185 if (err != MFX_ERR_NONE) {
1191 memset(&par, 0,
sizeof(par));
1194 par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
1195 MFX_IOPATTERN_IN_VIDEO_MEMORY;
1199 par.ExtParam =
s->ext_buffers;
1201 par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
1202 MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1206 par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
1207 MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
1210 par.vpp.In = frames_hwctx->
surfaces[0].Info;
1216 par.vpp.In.FrameRateExtN = 25;
1217 par.vpp.In.FrameRateExtD = 1;
1218 par.vpp.Out = par.vpp.In;
1220 err = MFXVideoVPP_Init(*session, &par);
1221 if (err != MFX_ERR_NONE) {
1223 "Surface upload/download will not be possible\n");
1251 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1274 s->mem_ids[
i] = frames_hwctx->
surfaces[
i].Data.MemId;
1279 sizeof(*
s->surface_ptrs));
1280 if (!
s->surface_ptrs)
1286 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
1287 s->opaque_alloc.In.NumSurface = frames_hwctx->
nb_surfaces;
1288 s->opaque_alloc.In.Type = frames_hwctx->
frame_type;
1290 s->opaque_alloc.Out =
s->opaque_alloc.In;
1292 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1293 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
1295 s->ext_buffers[0] = (mfxExtBuffer*)&
s->opaque_alloc;
1299 s->session_download =
NULL;
1300 s->session_upload =
NULL;
1302 s->session_download_init = 0;
1303 s->session_upload_init = 0;
1336 fmts[0] =
ctx->sw_format;
1360 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1361 dst_hwctx->
surface_ids[
i] = *(VASurfaceID*)pair->first;
1370 D3D11_TEXTURE2D_DESC texDesc;
1377 if (src_hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
1378 dst_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
1380 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1382 dst_hwctx->
texture_infos[
i].
index = pair->second == (mfxMemId)MFX_INFINITE ? (intptr_t)0 : (intptr_t)pair->second;
1385 dst_hwctx->
BindFlags = texDesc.BindFlags;
1398 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1399 dst_hwctx->
surfaces[
i] = (IDirect3DSurface9*)pair->first;
1402 if (src_hwctx->
frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
1403 dst_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
1405 dst_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
1420 mfxFrameSurface1 *surf = (mfxFrameSurface1*)
src->data[3];
1423 uint8_t *child_data;
1427 if (!
s->child_frames_ref)
1431 switch (child_frames_ctx->device_ctx->type) {
1435 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1440 child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
1447 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1448 child_data = pair->first;
1455 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1456 child_data = pair->first;
1464 if (dst->
format == child_frames_ctx->format) {
1474 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1475 dst->
data[0] = pair->first;
1476 dst->
data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1478 dst->
data[3] = child_data;
1499 dummy->format = child_frames_ctx->format;
1504 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1505 dummy->data[0] = pair->first;
1506 dummy->data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1508 dummy->data[3] = child_data;
1524 int download = !!
src->hw_frames_ctx;
1525 mfxFrameSurface1 *surf = (mfxFrameSurface1*)(download ?
src->data[3] : dst->
data[3]);
1537 dummy->buf[0] = download ?
src->buf[0] : dst->
buf[0];
1538 dummy->data[3] = surf->Data.MemId;
1539 dummy->hw_frames_ctx =
s->child_frames_ref;
1555 switch (
frame->format) {
1559 surface->Data.Y =
frame->data[0];
1560 surface->Data.UV =
frame->data[1];
1564 surface->Data.Y =
frame->data[0];
1565 surface->Data.U =
frame->data[1];
1566 surface->Data.V =
frame->data[2];
1570 surface->Data.B =
frame->data[0];
1571 surface->Data.G =
frame->data[0] + 1;
1572 surface->Data.R =
frame->data[0] + 2;
1573 surface->Data.A =
frame->data[0] + 3;
1576 surface->Data.Y =
frame->data[0];
1577 surface->Data.U =
frame->data[0] + 1;
1578 surface->Data.V =
frame->data[0] + 3;
1583 surface->Data.Y16 = (mfxU16 *)
frame->data[0];
1584 surface->Data.U16 = (mfxU16 *)
frame->data[0] + 1;
1585 surface->Data.V16 = (mfxU16 *)
frame->data[0] + 3;
1588 surface->Data.V =
frame->data[0];
1589 surface->Data.U =
frame->data[0] + 1;
1590 surface->Data.Y =
frame->data[0] + 2;
1593 surface->Data.A =
frame->data[0] + 3;
1596 surface->Data.U =
frame->data[0];
1599 surface->Data.U =
frame->data[0];
1600 surface->Data.Y =
frame->data[0] + 2;
1601 surface->Data.V =
frame->data[0] + 4;
1604 surface->Data.A =
frame->data[0] + 6;
1608 surface->Data.Y =
frame->data[0] + 1;
1609 surface->Data.U =
frame->data[0];
1610 surface->Data.V =
frame->data[0] + 2;
1614 return MFX_ERR_UNSUPPORTED;
1616 surface->Data.Pitch =
frame->linesize[0];
1617 surface->Data.TimeStamp =
frame->pts;
1625 atomic_int *inited = upload ? &
s->session_upload_init : &
s->session_download_init;
1626 mfxSession *session = upload ? &
s->session_upload : &
s->session_download;
1652 mfxFrameSurface1
out = {{ 0 }};
1653 mfxFrameSurface1 *in = (mfxFrameSurface1*)
src->data[3];
1655 mfxSyncPoint sync =
NULL;
1659 AVFrame *tmp_frame = &
s->realigned_download_frame;
1672 if (tmp_frame->format != dst->
format ||
1677 tmp_frame->format = dst->
format;
1686 dst_frame = realigned ? tmp_frame : dst;
1688 if (!
s->session_download) {
1689 if (
s->child_frames_ref)
1696 out.Info = in->Info;
1700 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_download, in, &
out,
NULL, &sync);
1701 if (err == MFX_WRN_DEVICE_BUSY)
1703 }
while (err == MFX_WRN_DEVICE_BUSY);
1705 if (err < 0 || !sync) {
1711 err = MFXVideoCORE_SyncOperation(
s->session_download, sync, 1000);
1712 }
while (err == MFX_WRN_IN_EXECUTION);
1719 tmp_frame->width = dst->
width;
1720 tmp_frame->height = dst->
height;
1735 mfxFrameSurface1 in = {{ 0 }};
1736 mfxFrameSurface1 *
out = (mfxFrameSurface1*)dst->
data[3];
1737 mfxFrameInfo tmp_info;
1739 mfxSyncPoint sync =
NULL;
1743 AVFrame *tmp_frame = &
s->realigned_upload_frame;
1754 if (
src->height & 15 ||
src->linesize[0] & 15) {
1756 if (tmp_frame->format !=
src->format ||
1757 tmp_frame->width !=
FFALIGN(
src->width, 16) ||
1758 tmp_frame->height !=
FFALIGN(
src->height, 16)) {
1761 tmp_frame->format =
src->format;
1763 tmp_frame->height =
FFALIGN(
src->height, 16);
1779 tmp_info =
out->Info;
1780 out->Info.CropW =
FFMIN(
out->Info.Width, tmp_frame->width);
1781 out->Info.CropH =
FFMIN(
out->Info.Height, tmp_frame->height);
1784 src_frame = realigned ? tmp_frame :
src;
1786 if (!
s->session_upload) {
1787 if (
s->child_frames_ref)
1794 in.Info =
out->Info;
1798 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_upload, &in,
out,
NULL, &sync);
1799 if (err == MFX_WRN_DEVICE_BUSY)
1801 }
while (err == MFX_WRN_DEVICE_BUSY);
1803 if (err < 0 || !sync) {
1809 err = MFXVideoCORE_SyncOperation(
s->session_upload, sync, 1000);
1810 }
while (err == MFX_WRN_IN_EXECUTION);
1817 out->Info.CropW = tmp_info.CropW;
1818 out->Info.CropH = tmp_info.CropH;
1833 "mapped to QSV frames.\n");
1843 sizeof(*
s->handle_pairs_internal));
1844 if (!
s->handle_pairs_internal)
1847 sizeof(*
s->surfaces_internal));
1848 if (!
s->surfaces_internal)
1853 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1854 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1857 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1866 sizeof(*
s->handle_pairs_internal));
1867 if (!
s->handle_pairs_internal)
1870 sizeof(*
s->surfaces_internal));
1871 if (!
s->surfaces_internal)
1876 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1877 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1881 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1884 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1885 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1887 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1897 sizeof(*
s->handle_pairs_internal));
1898 if (!
s->handle_pairs_internal)
1901 sizeof(*
s->surfaces_internal));
1902 if (!
s->surfaces_internal)
1906 s->handle_pairs_internal[
i].first = (mfxMemId)src_hwctx->
surfaces[
i];
1907 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1908 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1911 if (src_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
1912 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1914 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1922 dst_hwctx->
surfaces =
s->surfaces_internal;
1934 switch(
src->format) {
1938 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1939 if (*(VASurfaceID*)pair->first == (VASurfaceID)(uintptr_t)
src->data[3]) {
1948 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1949 if (pair->first ==
src->data[0]
1950 && (pair->second ==
src->data[1]
1951 || (pair->second == (mfxMemId)MFX_INFINITE &&
src->data[1] == (uint8_t *)0))) {
1960 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1961 if (pair->first ==
src->data[3]) {
1971 "is not in the mapped frames context.\n");
1988 const void *hwconfig,
2028 static const struct {
2032 {
"auto", MFX_IMPL_AUTO },
2033 {
"sw", MFX_IMPL_SOFTWARE },
2034 {
"hw", MFX_IMPL_HARDWARE },
2035 {
"auto_any", MFX_IMPL_AUTO_ANY },
2036 {
"hw_any", MFX_IMPL_HARDWARE_ANY },
2037 {
"hw2", MFX_IMPL_HARDWARE2 },
2038 {
"hw3", MFX_IMPL_HARDWARE3 },
2039 {
"hw4", MFX_IMPL_HARDWARE4 },
2042 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
2047 if (!strcmp(device, impl_map[
i].
name)) {
2048 impl = impl_map[
i].impl;
2052 impl = strtol(device,
NULL, 0);
2055 if (impl != MFX_IMPL_SOFTWARE) {
2057 impl |= MFX_IMPL_VIA_D3D11;
2059 impl |= MFX_IMPL_VIA_D3D9;
2066 mfxIMPL implementation,
2072 mfxVersion ver = { { 3, 1 } };
2074 mfxHandleType handle_type;
2078 switch (child_device_ctx->
type) {
2083 handle_type = MFX_HANDLE_VA_DISPLAY;
2084 handle = (mfxHDL)child_device_hwctx->
display;
2092 handle_type = MFX_HANDLE_D3D11_DEVICE;
2093 handle = (mfxHDL)child_device_hwctx->
device;
2101 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
2102 handle = (mfxHDL)child_device_hwctx->
devmgr;
2116 err = MFXVideoCORE_SetHandle(hwctx->
session, handle_type, handle);
2117 if (err != MFX_ERR_NONE) {
2149 ctx->user_opaque = priv;
2154 child_device_ctx,
flags);
2173 ctx->user_opaque = priv;
2181 "\"%s\".\n", e->
value);
2185 }
else if (CONFIG_D3D11VA) {
2187 "Defaulting child_device_type to AV_HWDEVICE_TYPE_D3D11VA for oneVPL."
2188 "Please explicitly set child device type via \"-init_hw_device\" "
2189 "option if needed.\n");
2191 }
else if (CONFIG_DXVA2) {
2194 }
else if (CONFIG_DXVA2) {
2196 "WARNING: defaulting child_device_type to AV_HWDEVICE_TYPE_DXVA2 for compatibility "
2197 "with old commandlines. This behaviour will be removed "
2198 "in the future. Please explicitly set device type via \"-init_hw_device\" option.\n");
2200 }
else if (CONFIG_D3D11VA) {
2203 }
else if (CONFIG_VAAPI) {
2210 #if CONFIG_VAAPI && defined(_WIN32)
2215 "\"%s\".\n", e->
value);
2220 child_device_opts =
NULL;
2221 switch (child_device_type) {
2230 av_dict_set(&child_device_opts,
"kernel_driver",
"i915", 0);
2231 av_dict_set(&child_device_opts,
"driver",
"iHD", 0);
2241 av_dict_set(&child_device_opts,
"vendor_id",
"0x8086", 0);
2250 "d3d11va is not available or child device type is set to dxva2 "
2251 "explicitly for oneVPL.\n");
2266 e ? e->
value :
NULL, child_device_opts, 0);