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 {
120 MFX_FOURCC_YUY2, 0 },
122 MFX_FOURCC_UYVY, 0 },
124 MFX_FOURCC_Y210, 1 },
128 MFX_FOURCC_AYUV, 0 },
132 MFX_FOURCC_Y410, 0 },
133 #if QSV_VERSION_ATLEAST(1, 31)
137 MFX_FOURCC_P016, 1 },
141 MFX_FOURCC_Y216, 1 },
145 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)
670 IDXGIAdapter *pDXGIAdapter;
671 DXGI_ADAPTER_DESC adapterDesc;
672 IDXGIDevice *pDXGIDevice =
NULL;
675 mfxVariant impl_value;
677 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (
void**)&pDXGIDevice);
679 hr = IDXGIDevice_GetAdapter(pDXGIDevice, &pDXGIAdapter);
685 hr = IDXGIAdapter_GetDesc(pDXGIAdapter, &adapterDesc);
695 impl_value.Type = MFX_VARIANT_TYPE_U16;
696 impl_value.Data.U16 = adapterDesc.DeviceId;
697 sts = MFXSetConfigFilterProperty(cfg,
698 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceID", impl_value);
699 if (sts != MFX_ERR_NONE) {
701 "DeviceID property: %d.\n", sts);
705 impl_value.Type = MFX_VARIANT_TYPE_PTR;
706 impl_value.Data.Ptr = &adapterDesc.AdapterLuid;
707 sts = MFXSetConfigFilterProperty(cfg,
708 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
709 if (sts != MFX_ERR_NONE) {
711 "DeviceLUID property: %d.\n", sts);
715 impl_value.Type = MFX_VARIANT_TYPE_U32;
716 impl_value.Data.U32 = 0x0001;
717 sts = MFXSetConfigFilterProperty(cfg,
718 (
const mfxU8 *)
"mfxExtendedDeviceId.LUIDDeviceNodeMask", impl_value);
719 if (sts != MFX_ERR_NONE) {
721 "LUIDDeviceNodeMask property: %d.\n", sts);
732 static int qsv_d3d9_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
737 IDirect3DDeviceManager9* devmgr = handle;
738 IDirect3DDevice9Ex *device =
NULL;
739 HANDLE device_handle = 0;
740 IDirect3D9Ex *d3d9ex =
NULL;
742 D3DDEVICE_CREATION_PARAMETERS params;
744 mfxVariant impl_value;
746 hr = IDirect3DDeviceManager9_OpenDeviceHandle(devmgr, &device_handle);
752 hr = IDirect3DDeviceManager9_LockDevice(devmgr, device_handle, &device, TRUE);
758 hr = IDirect3DDevice9Ex_GetCreationParameters(device, ¶ms);
764 hr = IDirect3DDevice9Ex_GetDirect3D(device, &d3d9ex);
770 hr = IDirect3D9Ex_GetAdapterLUID(d3d9ex, params.AdapterOrdinal, &luid);
776 impl_value.Type = MFX_VARIANT_TYPE_PTR;
777 impl_value.Data.Ptr = &luid;
778 sts = MFXSetConfigFilterProperty(cfg,
779 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
780 if (sts != MFX_ERR_NONE) {
782 "DeviceLUID property: %d.\n", sts);
789 IDirect3DDeviceManager9_UnlockDevice(devmgr, device_handle, FALSE);
795 static int qsv_va_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
798 #if VA_CHECK_VERSION(1, 15, 0)
800 VADisplay dpy = handle;
802 VADisplayAttribute attr = {
803 .type = VADisplayPCIID,
805 mfxVariant impl_value;
807 vas = vaGetDisplayAttributes(dpy, &attr, 1);
808 if (vas == VA_STATUS_SUCCESS && attr.flags != VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
809 impl_value.Type = MFX_VARIANT_TYPE_U16;
810 impl_value.Data.U16 = (attr.value & 0xFFFF);
811 sts = MFXSetConfigFilterProperty(cfg,
812 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceID", impl_value);
813 if (sts != MFX_ERR_NONE) {
815 "DeviceID property: %d.\n", sts);
820 "consider to upgrade the driver to support VA-API 1.15.0\n");
829 "the device information from the driver. Please consider to upgrade libva to "
830 "support VA-API 1.15.0\n");
836 static int qsv_new_mfx_loader(
void *
ctx,
838 mfxHandleType handle_type,
839 mfxIMPL implementation,
844 mfxLoader loader =
NULL;
846 mfxVariant impl_value;
856 cfg = MFXCreateConfig(loader);
862 impl_value.Type = MFX_VARIANT_TYPE_U32;
863 impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
864 MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
865 sts = MFXSetConfigFilterProperty(cfg,
866 (
const mfxU8 *)
"mfxImplDescription.Impl", impl_value);
867 if (sts != MFX_ERR_NONE) {
869 "property: %d.\n", sts);
873 impl_value.Type = MFX_VARIANT_TYPE_U32;
874 impl_value.Data.U32 = pver->Version;
875 sts = MFXSetConfigFilterProperty(cfg,
876 (
const mfxU8 *)
"mfxImplDescription.ApiVersion.Version",
878 if (sts != MFX_ERR_NONE) {
880 "property: %d.\n", sts);
884 impl_value.Type = MFX_VARIANT_TYPE_U16;
885 impl_value.Data.U16 = 0x8086;
886 sts = MFXSetConfigFilterProperty(cfg,
887 (
const mfxU8 *)
"mfxExtendedDeviceId.VendorID", impl_value);
888 if (sts != MFX_ERR_NONE) {
890 "VendorID property: %d.\n", sts);
894 if (MFX_HANDLE_VA_DISPLAY == handle_type) {
895 if (handle && qsv_va_update_config(
ctx, handle, cfg))
898 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_VAAPI;
899 }
else if (MFX_HANDLE_D3D9_DEVICE_MANAGER == handle_type) {
900 if (handle && qsv_d3d9_update_config(
ctx, handle, cfg))
903 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D9;
905 if (handle && qsv_d3d11_update_config(
ctx, handle, cfg))
908 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D11;
911 impl_value.Type = MFX_VARIANT_TYPE_U32;
912 sts = MFXSetConfigFilterProperty(cfg,
913 (
const mfxU8 *)
"mfxImplDescription.AccelerationMode", impl_value);
914 if (sts != MFX_ERR_NONE) {
916 "AccelerationMode property: %d.\n", sts);
931 static int qsv_create_mfx_session_from_loader(
void *
ctx, mfxLoader loader, mfxSession *psession)
934 mfxSession session =
NULL;
935 uint32_t impl_idx = 0;
940 mfxImplDescription *impl_desc;
942 sts = MFXEnumImplementations(loader, impl_idx,
943 MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
944 (mfxHDL *)&impl_desc);
946 if (sts == MFX_ERR_NOT_FOUND)
948 else if (sts != MFX_ERR_NONE) {
953 sts = MFXCreateSession(loader, impl_idx, &session);
954 MFXDispReleaseImplDescription(loader, impl_desc);
955 if (sts == MFX_ERR_NONE)
961 if (sts != MFX_ERR_NONE) {
966 sts = MFXQueryVersion(session, &ver);
967 if (sts != MFX_ERR_NONE) {
973 "version is %d.%d\n", ver.Major, ver.Minor);
988 mfxHandleType handle_type,
989 mfxIMPL implementation,
991 mfxSession *psession,
994 mfxLoader loader =
NULL;
997 "Use Intel(R) oneVPL to create MFX session, API version is "
998 "%d.%d, the required implementation version is %d.%d\n",
999 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1001 if (handle_type != MFX_HANDLE_VA_DISPLAY &&
1002 handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER &&
1003 handle_type != MFX_HANDLE_D3D11_DEVICE) {
1005 "Invalid MFX device handle type\n");
1012 if (qsv_new_mfx_loader(
ctx, handle, handle_type, implementation, pver, (
void **)&loader))
1019 if (qsv_create_mfx_session_from_loader(
ctx, loader, psession))
1028 if (!*ploader && loader)
1038 mfxHandleType handle_type,
1039 mfxIMPL implementation,
1041 mfxSession *psession,
1046 mfxSession session =
NULL;
1049 "Use Intel(R) Media SDK to create MFX session, API version is "
1050 "%d.%d, the required implementation version is %d.%d\n",
1051 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1056 sts = MFXInit(implementation, &ver, &session);
1057 if (sts != MFX_ERR_NONE) {
1063 sts = MFXQueryVersion(session, &ver);
1064 if (sts != MFX_ERR_NONE) {
1071 "version is %d.%d\n", ver.Major, ver.Minor);
1075 sts = MFXInit(implementation, &ver, &session);
1076 if (sts != MFX_ERR_NONE) {
1082 *psession = session;
1096 mfxSession *session,
int upload)
1102 mfxFrameAllocator frame_allocator = {
1116 void **loader = &hwctx->
loader;
1120 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1124 device_priv->
impl, &device_priv->
ver, session, loader);
1128 if (device_priv->
handle) {
1129 err = MFXVideoCORE_SetHandle(*session, device_priv->
handle_type,
1131 if (err != MFX_ERR_NONE) {
1138 err = MFXVideoCORE_SetFrameAllocator(*session, &frame_allocator);
1139 if (err != MFX_ERR_NONE) {
1145 memset(&par, 0,
sizeof(par));
1148 par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
1149 MFX_IOPATTERN_IN_VIDEO_MEMORY;
1153 par.ExtParam =
s->ext_buffers;
1155 par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
1156 MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1160 par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
1161 MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
1164 par.vpp.In = frames_hwctx->
surfaces[0].Info;
1170 par.vpp.In.FrameRateExtN = 25;
1171 par.vpp.In.FrameRateExtD = 1;
1172 par.vpp.Out = par.vpp.In;
1174 err = MFXVideoVPP_Init(*session, &par);
1175 if (err != MFX_ERR_NONE) {
1177 "Surface upload/download will not be possible\n");
1205 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1228 s->mem_ids[
i] = frames_hwctx->
surfaces[
i].Data.MemId;
1233 sizeof(*
s->surface_ptrs));
1234 if (!
s->surface_ptrs)
1240 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
1241 s->opaque_alloc.In.NumSurface = frames_hwctx->
nb_surfaces;
1242 s->opaque_alloc.In.Type = frames_hwctx->
frame_type;
1244 s->opaque_alloc.Out =
s->opaque_alloc.In;
1246 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1247 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
1249 s->ext_buffers[0] = (mfxExtBuffer*)&
s->opaque_alloc;
1253 s->session_download =
NULL;
1254 s->session_upload =
NULL;
1256 s->session_download_init = 0;
1257 s->session_upload_init = 0;
1290 fmts[0] =
ctx->sw_format;
1314 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1315 dst_hwctx->
surface_ids[
i] = *(VASurfaceID*)pair->first;
1324 D3D11_TEXTURE2D_DESC texDesc;
1331 if (src_hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
1332 dst_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
1334 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1336 dst_hwctx->
texture_infos[
i].
index = pair->second == (mfxMemId)MFX_INFINITE ? (intptr_t)0 : (intptr_t)pair->second;
1339 dst_hwctx->
BindFlags = texDesc.BindFlags;
1352 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1353 dst_hwctx->
surfaces[
i] = (IDirect3DSurface9*)pair->first;
1356 if (src_hwctx->
frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
1357 dst_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
1359 dst_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
1374 mfxFrameSurface1 *surf = (mfxFrameSurface1*)
src->data[3];
1377 uint8_t *child_data;
1381 if (!
s->child_frames_ref)
1385 switch (child_frames_ctx->device_ctx->type) {
1389 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1394 child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
1401 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1402 child_data = pair->first;
1409 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1410 child_data = pair->first;
1418 if (dst->
format == child_frames_ctx->format) {
1428 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1429 dst->
data[0] = pair->first;
1430 dst->
data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1432 dst->
data[3] = child_data;
1453 dummy->format = child_frames_ctx->format;
1458 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1459 dummy->data[0] = pair->first;
1460 dummy->data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1462 dummy->data[3] = child_data;
1478 int download = !!
src->hw_frames_ctx;
1479 mfxFrameSurface1 *surf = (mfxFrameSurface1*)(download ?
src->data[3] : dst->
data[3]);
1491 dummy->buf[0] = download ?
src->buf[0] : dst->
buf[0];
1492 dummy->data[3] = surf->Data.MemId;
1493 dummy->hw_frames_ctx =
s->child_frames_ref;
1509 switch (
frame->format) {
1513 surface->Data.Y =
frame->data[0];
1514 surface->Data.UV =
frame->data[1];
1518 surface->Data.Y =
frame->data[0];
1519 surface->Data.U =
frame->data[1];
1520 surface->Data.V =
frame->data[2];
1524 surface->Data.B =
frame->data[0];
1525 surface->Data.G =
frame->data[0] + 1;
1526 surface->Data.R =
frame->data[0] + 2;
1527 surface->Data.A =
frame->data[0] + 3;
1531 surface->Data.Y =
frame->data[0];
1532 surface->Data.U =
frame->data[0] + 1;
1533 surface->Data.V =
frame->data[0] + 3;
1538 surface->Data.Y16 = (mfxU16 *)
frame->data[0];
1539 surface->Data.U16 = (mfxU16 *)
frame->data[0] + 1;
1540 surface->Data.V16 = (mfxU16 *)
frame->data[0] + 3;
1543 surface->Data.V =
frame->data[0];
1544 surface->Data.U =
frame->data[0] + 1;
1545 surface->Data.Y =
frame->data[0] + 2;
1548 surface->Data.A =
frame->data[0] + 3;
1551 surface->Data.U =
frame->data[0];
1554 surface->Data.U =
frame->data[0];
1555 surface->Data.Y =
frame->data[0] + 2;
1556 surface->Data.V =
frame->data[0] + 4;
1559 surface->Data.A =
frame->data[0] + 6;
1562 surface->Data.Y =
frame->data[0] + 1;
1563 surface->Data.U =
frame->data[0];
1564 surface->Data.V =
frame->data[0] + 2;
1568 return MFX_ERR_UNSUPPORTED;
1570 surface->Data.Pitch =
frame->linesize[0];
1571 surface->Data.TimeStamp =
frame->pts;
1579 atomic_int *inited = upload ? &
s->session_upload_init : &
s->session_download_init;
1580 mfxSession *session = upload ? &
s->session_upload : &
s->session_download;
1606 mfxFrameSurface1
out = {{ 0 }};
1607 mfxFrameSurface1 *in = (mfxFrameSurface1*)
src->data[3];
1609 mfxSyncPoint sync =
NULL;
1613 AVFrame *tmp_frame = &
s->realigned_download_frame;
1626 if (tmp_frame->format != dst->
format ||
1631 tmp_frame->format = dst->
format;
1640 dst_frame = realigned ? tmp_frame : dst;
1642 if (!
s->session_download) {
1643 if (
s->child_frames_ref)
1650 out.Info = in->Info;
1654 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_download, in, &
out,
NULL, &sync);
1655 if (err == MFX_WRN_DEVICE_BUSY)
1657 }
while (err == MFX_WRN_DEVICE_BUSY);
1659 if (err < 0 || !sync) {
1665 err = MFXVideoCORE_SyncOperation(
s->session_download, sync, 1000);
1666 }
while (err == MFX_WRN_IN_EXECUTION);
1673 tmp_frame->width = dst->
width;
1674 tmp_frame->height = dst->
height;
1689 mfxFrameSurface1 in = {{ 0 }};
1690 mfxFrameSurface1 *
out = (mfxFrameSurface1*)dst->
data[3];
1691 mfxFrameInfo tmp_info;
1693 mfxSyncPoint sync =
NULL;
1697 AVFrame *tmp_frame = &
s->realigned_upload_frame;
1708 if (
src->height & 15 ||
src->linesize[0] & 15) {
1710 if (tmp_frame->format !=
src->format ||
1711 tmp_frame->width !=
FFALIGN(
src->width, 16) ||
1712 tmp_frame->height !=
FFALIGN(
src->height, 16)) {
1715 tmp_frame->format =
src->format;
1717 tmp_frame->height =
FFALIGN(
src->height, 16);
1733 tmp_info =
out->Info;
1734 out->Info.CropW =
FFMIN(
out->Info.Width, tmp_frame->width);
1735 out->Info.CropH =
FFMIN(
out->Info.Height, tmp_frame->height);
1738 src_frame = realigned ? tmp_frame :
src;
1740 if (!
s->session_upload) {
1741 if (
s->child_frames_ref)
1748 in.Info =
out->Info;
1752 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_upload, &in,
out,
NULL, &sync);
1753 if (err == MFX_WRN_DEVICE_BUSY)
1755 }
while (err == MFX_WRN_DEVICE_BUSY);
1757 if (err < 0 || !sync) {
1763 err = MFXVideoCORE_SyncOperation(
s->session_upload, sync, 1000);
1764 }
while (err == MFX_WRN_IN_EXECUTION);
1771 out->Info.CropW = tmp_info.CropW;
1772 out->Info.CropH = tmp_info.CropH;
1787 "mapped to QSV frames.\n");
1797 sizeof(*
s->handle_pairs_internal));
1798 if (!
s->handle_pairs_internal)
1801 sizeof(*
s->surfaces_internal));
1802 if (!
s->surfaces_internal)
1807 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1808 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1811 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1820 sizeof(*
s->handle_pairs_internal));
1821 if (!
s->handle_pairs_internal)
1824 sizeof(*
s->surfaces_internal));
1825 if (!
s->surfaces_internal)
1830 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1831 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1835 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1838 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1839 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1841 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1851 sizeof(*
s->handle_pairs_internal));
1852 if (!
s->handle_pairs_internal)
1855 sizeof(*
s->surfaces_internal));
1856 if (!
s->surfaces_internal)
1860 s->handle_pairs_internal[
i].first = (mfxMemId)src_hwctx->
surfaces[
i];
1861 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1862 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1865 if (src_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
1866 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1868 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1876 dst_hwctx->
surfaces =
s->surfaces_internal;
1888 switch(
src->format) {
1892 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1893 if (*(VASurfaceID*)pair->first == (VASurfaceID)
src->data[3]) {
1902 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1903 if (pair->first ==
src->data[0]
1904 && (pair->second ==
src->data[1]
1905 || (pair->second == (mfxMemId)MFX_INFINITE &&
src->data[1] == (uint8_t *)0))) {
1914 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1915 if (pair->first ==
src->data[3]) {
1925 "is not in the mapped frames context.\n");
1942 const void *hwconfig,
1982 static const struct {
1986 {
"auto", MFX_IMPL_AUTO },
1987 {
"sw", MFX_IMPL_SOFTWARE },
1988 {
"hw", MFX_IMPL_HARDWARE },
1989 {
"auto_any", MFX_IMPL_AUTO_ANY },
1990 {
"hw_any", MFX_IMPL_HARDWARE_ANY },
1991 {
"hw2", MFX_IMPL_HARDWARE2 },
1992 {
"hw3", MFX_IMPL_HARDWARE3 },
1993 {
"hw4", MFX_IMPL_HARDWARE4 },
1996 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
2001 if (!strcmp(device, impl_map[
i].
name)) {
2002 impl = impl_map[
i].impl;
2006 impl = strtol(device,
NULL, 0);
2009 if (impl != MFX_IMPL_SOFTWARE) {
2011 impl |= MFX_IMPL_VIA_D3D11;
2013 impl |= MFX_IMPL_VIA_D3D9;
2020 mfxIMPL implementation,
2026 mfxVersion ver = { { 3, 1 } };
2028 mfxHandleType handle_type;
2032 switch (child_device_ctx->
type) {
2037 handle_type = MFX_HANDLE_VA_DISPLAY;
2038 handle = (mfxHDL)child_device_hwctx->
display;
2046 handle_type = MFX_HANDLE_D3D11_DEVICE;
2047 handle = (mfxHDL)child_device_hwctx->
device;
2055 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
2056 handle = (mfxHDL)child_device_hwctx->
devmgr;
2070 err = MFXVideoCORE_SetHandle(hwctx->
session, handle_type, handle);
2071 if (err != MFX_ERR_NONE) {
2099 child_device_ctx,
flags);
2118 ctx->user_opaque = priv;
2126 "\"%s\".\n", e->
value);
2129 }
else if (CONFIG_VAAPI) {
2132 }
else if (CONFIG_D3D11VA) {
2134 "Defaulting child_device_type to AV_HWDEVICE_TYPE_D3D11VA for oneVPL."
2135 "Please explicitly set child device type via \"-init_hw_device\" "
2136 "option if needed.\n");
2138 }
else if (CONFIG_DXVA2) {
2141 }
else if (CONFIG_DXVA2) {
2143 "WARNING: defaulting child_device_type to AV_HWDEVICE_TYPE_DXVA2 for compatibility "
2144 "with old commandlines. This behaviour will be removed "
2145 "in the future. Please explicitly set device type via \"-init_hw_device\" option.\n");
2147 }
else if (CONFIG_D3D11VA) {
2155 child_device_opts =
NULL;
2156 switch (child_device_type) {
2165 av_dict_set(&child_device_opts,
"kernel_driver",
"i915", 0);
2166 av_dict_set(&child_device_opts,
"driver",
"iHD", 0);
2179 "d3d11va is not available or child device type is set to dxva2 "
2180 "explicitly for oneVPL.\n");
2195 e ? e->
value :
NULL, child_device_opts, 0);