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_Y210, 1 },
126 MFX_FOURCC_AYUV, 0 },
130 MFX_FOURCC_Y410, 0 },
131 #if QSV_VERSION_ATLEAST(1, 31)
135 MFX_FOURCC_P016, 1 },
139 MFX_FOURCC_Y216, 1 },
143 MFX_FOURCC_Y416, 1 },
159 mfxHDLPair *handle_pair;
160 handle_pair = surf->Data.MemId;
161 switch (base_dev_type) {
164 base_handle[0] = handle_pair->first;
169 base_handle[0] = handle_pair->first;
170 base_handle[1] = handle_pair->second;
175 base_handle[0] = handle_pair->first;
203 static uint32_t qsv_get_d3d11va_bind_flags(
int mem_type)
205 uint32_t bind_flags = 0;
207 if ((mem_type & MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET) && (mem_type & MFX_MEMTYPE_INTERNAL_FRAME))
208 bind_flags = D3D11_BIND_DECODER | D3D11_BIND_VIDEO_ENCODER;
210 bind_flags = D3D11_BIND_DECODER;
212 if ((MFX_MEMTYPE_FROM_VPPOUT & mem_type) || (MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & mem_type))
213 bind_flags = D3D11_BIND_RENDER_TARGET;
222 int i, planes_nb = 0;
228 for (
i = 0;
i <
desc->nb_components;
i++)
229 planes_nb =
FFMAX(planes_nb,
desc->comp[
i].plane + 1);
231 for (
i = 0;
i < planes_nb;
i++) {
232 int sheight, dheight, y;
240 if (swidth < 0 || dwidth < 0) {
244 sheight =
src->height;
251 for (y = 0; y < sheight; y++) {
254 comp.depth > 8 ? 2 : 1,
258 for (y = sheight; y < dheight; y++) {
271 int hw_handle_supported = 0;
272 mfxHandleType handle_type;
277 err = MFXQueryIMPL(hwctx->
session, &
s->impl);
278 if (err == MFX_ERR_NONE)
279 err = MFXQueryVersion(hwctx->
session, &
s->ver);
280 if (err != MFX_ERR_NONE) {
287 handle_type = MFX_HANDLE_VA_DISPLAY;
290 hw_handle_supported = 1;
294 handle_type = MFX_HANDLE_D3D11_DEVICE;
297 hw_handle_supported = 1;
301 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
304 hw_handle_supported = 1;
308 if (hw_handle_supported) {
309 err = MFXVideoCORE_GetHandle(hwctx->
session, handle_type, &
s->handle);
310 if (err == MFX_ERR_NONE) {
311 s->handle_type = handle_type;
312 s->child_device_type = device_type;
318 "from the session\n");
327 if (
s->session_download) {
328 MFXVideoVPP_Close(
s->session_download);
329 MFXClose(
s->session_download);
331 s->session_download =
NULL;
332 s->session_download_init = 0;
334 if (
s->session_upload) {
335 MFXVideoVPP_Close(
s->session_upload);
336 MFXClose(
s->session_upload);
338 s->session_upload =
NULL;
339 s->session_upload_init = 0;
367 s->nb_surfaces_used++;
389 if (!device_priv->
handle) {
391 "Cannot create a non-opaque internal surface pool without "
392 "a hardware handle\n");
397 if (!child_device_ref)
404 child_device_hwctx->
display = (VADisplay)device_priv->
handle;
417 child_device_hwctx->
devmgr = (IDirect3DDeviceManager9*)device_priv->
handle;
428 if (!child_frames_ref) {
444 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
445 if (hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
446 child_frames_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
453 if (hwctx->
frame_type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)
454 child_frames_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
456 child_frames_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
469 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
470 s->handle_pairs_internal[
i].first = child_frames_hwctx->
surface_ids +
i;
471 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
472 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
474 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
480 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
482 if(child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
483 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
487 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
489 if (child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
490 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
492 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
499 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
500 s->handle_pairs_internal[
i].first = (mfxMemId)child_frames_hwctx->
surfaces[
i];
501 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
502 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
504 if (child_frames_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
505 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
507 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
511 s->child_frames_ref = child_frames_ref;
512 child_frames_ref =
NULL;
533 surf->Info.BitDepthLuma =
desc->comp[0].depth;
534 surf->Info.BitDepthChroma =
desc->comp[0].depth;
537 if (
desc->log2_chroma_w &&
desc->log2_chroma_h)
538 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
539 else if (
desc->log2_chroma_w)
540 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV422;
542 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV444;
544 surf->Info.FourCC =
fourcc;
546 surf->Info.CropW =
ctx->width;
548 surf->Info.CropH =
ctx->height;
549 surf->Info.FrameRateExtN = 25;
550 surf->Info.FrameRateExtD = 1;
551 surf->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
563 if (
ctx->initial_pool_size <= 0) {
569 sizeof(*
s->handle_pairs_internal));
570 if (!
s->handle_pairs_internal)
574 sizeof(*
s->surfaces_internal));
575 if (!
s->surfaces_internal)
578 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
585 if (!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) {
598 if (!
ctx->internal->pool_internal)
601 frames_hwctx->
surfaces =
s->surfaces_internal;
607 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
608 mfxFrameAllocResponse *resp)
613 mfxFrameInfo *
i = &req->Info;
614 mfxFrameInfo *i1 = &hwctx->
surfaces[0].Info;
616 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
617 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
618 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
619 return MFX_ERR_UNSUPPORTED;
620 if (
i->Width > i1->Width ||
i->Height > i1->Height ||
621 i->FourCC != i1->FourCC ||
i->ChromaFormat != i1->ChromaFormat) {
623 "allocation request: %dx%d %d %d vs %dx%d %d %d\n",
624 i->Width,
i->Height,
i->FourCC,
i->ChromaFormat,
625 i1->Width, i1->Height, i1->FourCC, i1->ChromaFormat);
626 return MFX_ERR_UNSUPPORTED;
629 resp->mids =
s->mem_ids;
635 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
640 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
642 return MFX_ERR_UNSUPPORTED;
645 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
647 return MFX_ERR_UNSUPPORTED;
652 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
653 mfxHDLPair *pair_src = (mfxHDLPair*)mid;
655 pair_dst->first = pair_src->first;
657 if (pair_src->second != (mfxMemId)MFX_INFINITE)
658 pair_dst->second = pair_src->second;
664 static int qsv_d3d11_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
668 IDXGIAdapter *pDXGIAdapter;
669 DXGI_ADAPTER_DESC adapterDesc;
670 IDXGIDevice *pDXGIDevice =
NULL;
673 mfxVariant impl_value;
675 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (
void**)&pDXGIDevice);
677 hr = IDXGIDevice_GetAdapter(pDXGIDevice, &pDXGIAdapter);
683 hr = IDXGIAdapter_GetDesc(pDXGIAdapter, &adapterDesc);
693 impl_value.Type = MFX_VARIANT_TYPE_U16;
694 impl_value.Data.U16 = adapterDesc.DeviceId;
695 sts = MFXSetConfigFilterProperty(cfg,
696 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceID", impl_value);
697 if (sts != MFX_ERR_NONE) {
699 "DeviceID property: %d.\n", sts);
703 impl_value.Type = MFX_VARIANT_TYPE_PTR;
704 impl_value.Data.Ptr = &adapterDesc.AdapterLuid;
705 sts = MFXSetConfigFilterProperty(cfg,
706 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
707 if (sts != MFX_ERR_NONE) {
709 "DeviceLUID property: %d.\n", sts);
713 impl_value.Type = MFX_VARIANT_TYPE_U32;
714 impl_value.Data.U32 = 0x0001;
715 sts = MFXSetConfigFilterProperty(cfg,
716 (
const mfxU8 *)
"mfxExtendedDeviceId.LUIDDeviceNodeMask", impl_value);
717 if (sts != MFX_ERR_NONE) {
719 "LUIDDeviceNodeMask property: %d.\n", sts);
730 static int qsv_d3d9_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
735 IDirect3DDeviceManager9* devmgr = handle;
736 IDirect3DDevice9Ex *device =
NULL;
737 HANDLE device_handle = 0;
738 IDirect3D9Ex *d3d9ex =
NULL;
740 D3DDEVICE_CREATION_PARAMETERS params;
742 mfxVariant impl_value;
744 hr = IDirect3DDeviceManager9_OpenDeviceHandle(devmgr, &device_handle);
750 hr = IDirect3DDeviceManager9_LockDevice(devmgr, device_handle, &device, TRUE);
756 hr = IDirect3DDevice9Ex_GetCreationParameters(device, ¶ms);
762 hr = IDirect3DDevice9Ex_GetDirect3D(device, &d3d9ex);
768 hr = IDirect3D9Ex_GetAdapterLUID(d3d9ex, params.AdapterOrdinal, &luid);
774 impl_value.Type = MFX_VARIANT_TYPE_PTR;
775 impl_value.Data.Ptr = &luid;
776 sts = MFXSetConfigFilterProperty(cfg,
777 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
778 if (sts != MFX_ERR_NONE) {
780 "DeviceLUID property: %d.\n", sts);
787 IDirect3DDeviceManager9_UnlockDevice(devmgr, device_handle, FALSE);
793 static int qsv_va_update_config(
void *
ctx, mfxHDL handle, mfxConfig cfg)
796 #if VA_CHECK_VERSION(1, 15, 0)
798 VADisplay dpy = handle;
800 VADisplayAttribute attr = {
801 .type = VADisplayPCIID,
803 mfxVariant impl_value;
805 vas = vaGetDisplayAttributes(dpy, &attr, 1);
806 if (vas == VA_STATUS_SUCCESS && attr.flags != VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
807 impl_value.Type = MFX_VARIANT_TYPE_U16;
808 impl_value.Data.U16 = (attr.value & 0xFFFF);
809 sts = MFXSetConfigFilterProperty(cfg,
810 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceID", impl_value);
811 if (sts != MFX_ERR_NONE) {
813 "DeviceID property: %d.\n", sts);
818 "consider to upgrade the driver to support VA-API 1.15.0\n");
827 "the device information from the driver. Please consider to upgrade libva to "
828 "support VA-API 1.15.0\n");
834 static int qsv_new_mfx_loader(
void *
ctx,
836 mfxHandleType handle_type,
837 mfxIMPL implementation,
842 mfxLoader loader =
NULL;
844 mfxVariant impl_value;
854 cfg = MFXCreateConfig(loader);
860 impl_value.Type = MFX_VARIANT_TYPE_U32;
861 impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
862 MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
863 sts = MFXSetConfigFilterProperty(cfg,
864 (
const mfxU8 *)
"mfxImplDescription.Impl", impl_value);
865 if (sts != MFX_ERR_NONE) {
867 "property: %d.\n", sts);
871 impl_value.Type = MFX_VARIANT_TYPE_U32;
872 impl_value.Data.U32 = pver->Version;
873 sts = MFXSetConfigFilterProperty(cfg,
874 (
const mfxU8 *)
"mfxImplDescription.ApiVersion.Version",
876 if (sts != MFX_ERR_NONE) {
878 "property: %d.\n", sts);
882 impl_value.Type = MFX_VARIANT_TYPE_U16;
883 impl_value.Data.U16 = 0x8086;
884 sts = MFXSetConfigFilterProperty(cfg,
885 (
const mfxU8 *)
"mfxExtendedDeviceId.VendorID", impl_value);
886 if (sts != MFX_ERR_NONE) {
888 "VendorID property: %d.\n", sts);
892 if (MFX_HANDLE_VA_DISPLAY == handle_type) {
893 if (handle && qsv_va_update_config(
ctx, handle, cfg))
896 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_VAAPI;
897 }
else if (MFX_HANDLE_D3D9_DEVICE_MANAGER == handle_type) {
898 if (handle && qsv_d3d9_update_config(
ctx, handle, cfg))
901 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D9;
903 if (handle && qsv_d3d11_update_config(
ctx, handle, cfg))
906 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D11;
909 impl_value.Type = MFX_VARIANT_TYPE_U32;
910 sts = MFXSetConfigFilterProperty(cfg,
911 (
const mfxU8 *)
"mfxImplDescription.AccelerationMode", impl_value);
912 if (sts != MFX_ERR_NONE) {
914 "AccelerationMode property: %d.\n", sts);
929 static int qsv_create_mfx_session_from_loader(
void *
ctx, mfxLoader loader, mfxSession *psession)
932 mfxSession session =
NULL;
933 uint32_t impl_idx = 0;
938 mfxImplDescription *impl_desc;
940 sts = MFXEnumImplementations(loader, impl_idx,
941 MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
942 (mfxHDL *)&impl_desc);
944 if (sts == MFX_ERR_NOT_FOUND)
946 else if (sts != MFX_ERR_NONE) {
951 sts = MFXCreateSession(loader, impl_idx, &session);
952 MFXDispReleaseImplDescription(loader, impl_desc);
953 if (sts == MFX_ERR_NONE)
959 if (sts != MFX_ERR_NONE) {
964 sts = MFXQueryVersion(session, &ver);
965 if (sts != MFX_ERR_NONE) {
971 "version is %d.%d\n", ver.Major, ver.Minor);
986 mfxHandleType handle_type,
987 mfxIMPL implementation,
989 mfxSession *psession,
992 mfxLoader loader =
NULL;
995 "Use Intel(R) oneVPL to create MFX session, API version is "
996 "%d.%d, the required implementation version is %d.%d\n",
997 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
999 if (handle_type != MFX_HANDLE_VA_DISPLAY &&
1000 handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER &&
1001 handle_type != MFX_HANDLE_D3D11_DEVICE) {
1003 "Invalid MFX device handle type\n");
1010 if (qsv_new_mfx_loader(
ctx, handle, handle_type, implementation, pver, (
void **)&loader))
1017 if (qsv_create_mfx_session_from_loader(
ctx, loader, psession))
1026 if (!*ploader && loader)
1036 mfxHandleType handle_type,
1037 mfxIMPL implementation,
1039 mfxSession *psession,
1044 mfxSession session =
NULL;
1047 "Use Intel(R) Media SDK to create MFX session, API version is "
1048 "%d.%d, the required implementation version is %d.%d\n",
1049 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1054 sts = MFXInit(implementation, &ver, &session);
1055 if (sts != MFX_ERR_NONE) {
1061 sts = MFXQueryVersion(session, &ver);
1062 if (sts != MFX_ERR_NONE) {
1069 "version is %d.%d\n", ver.Major, ver.Minor);
1073 sts = MFXInit(implementation, &ver, &session);
1074 if (sts != MFX_ERR_NONE) {
1080 *psession = session;
1094 mfxSession *session,
int upload)
1100 mfxFrameAllocator frame_allocator = {
1114 void **loader = &hwctx->
loader;
1118 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1122 device_priv->
impl, &device_priv->
ver, session, loader);
1126 if (device_priv->
handle) {
1127 err = MFXVideoCORE_SetHandle(*session, device_priv->
handle_type,
1129 if (err != MFX_ERR_NONE) {
1136 err = MFXVideoCORE_SetFrameAllocator(*session, &frame_allocator);
1137 if (err != MFX_ERR_NONE) {
1143 memset(&par, 0,
sizeof(par));
1146 par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
1147 MFX_IOPATTERN_IN_VIDEO_MEMORY;
1151 par.ExtParam =
s->ext_buffers;
1153 par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
1154 MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1158 par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
1159 MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
1162 par.vpp.In = frames_hwctx->
surfaces[0].Info;
1168 par.vpp.In.FrameRateExtN = 25;
1169 par.vpp.In.FrameRateExtD = 1;
1170 par.vpp.Out = par.vpp.In;
1172 err = MFXVideoVPP_Init(*session, &par);
1173 if (err != MFX_ERR_NONE) {
1175 "Surface upload/download will not be possible\n");
1203 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1226 s->mem_ids[
i] = frames_hwctx->
surfaces[
i].Data.MemId;
1231 sizeof(*
s->surface_ptrs));
1232 if (!
s->surface_ptrs)
1238 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
1239 s->opaque_alloc.In.NumSurface = frames_hwctx->
nb_surfaces;
1240 s->opaque_alloc.In.Type = frames_hwctx->
frame_type;
1242 s->opaque_alloc.Out =
s->opaque_alloc.In;
1244 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1245 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
1247 s->ext_buffers[0] = (mfxExtBuffer*)&
s->opaque_alloc;
1251 s->session_download =
NULL;
1252 s->session_upload =
NULL;
1254 s->session_download_init = 0;
1255 s->session_upload_init = 0;
1288 fmts[0] =
ctx->sw_format;
1312 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1313 dst_hwctx->
surface_ids[
i] = *(VASurfaceID*)pair->first;
1322 D3D11_TEXTURE2D_DESC texDesc;
1329 if (src_hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
1330 dst_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
1332 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1334 dst_hwctx->
texture_infos[
i].
index = pair->second == (mfxMemId)MFX_INFINITE ? (intptr_t)0 : (intptr_t)pair->second;
1337 dst_hwctx->
BindFlags = texDesc.BindFlags;
1350 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1351 dst_hwctx->
surfaces[
i] = (IDirect3DSurface9*)pair->first;
1354 if (src_hwctx->
frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
1355 dst_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
1357 dst_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
1372 mfxFrameSurface1 *surf = (mfxFrameSurface1*)
src->data[3];
1375 uint8_t *child_data;
1379 if (!
s->child_frames_ref)
1383 switch (child_frames_ctx->device_ctx->type) {
1387 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1392 child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
1399 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1400 child_data = pair->first;
1407 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1408 child_data = pair->first;
1416 if (dst->
format == child_frames_ctx->format) {
1426 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1427 dst->
data[0] = pair->first;
1428 dst->
data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1430 dst->
data[3] = child_data;
1451 dummy->format = child_frames_ctx->format;
1456 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1457 dummy->data[0] = pair->first;
1458 dummy->data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1460 dummy->data[3] = child_data;
1476 int download = !!
src->hw_frames_ctx;
1477 mfxFrameSurface1 *surf = (mfxFrameSurface1*)(download ?
src->data[3] : dst->
data[3]);
1489 dummy->buf[0] = download ?
src->buf[0] : dst->
buf[0];
1490 dummy->data[3] = surf->Data.MemId;
1491 dummy->hw_frames_ctx =
s->child_frames_ref;
1507 switch (
frame->format) {
1511 surface->Data.Y =
frame->data[0];
1512 surface->Data.UV =
frame->data[1];
1516 surface->Data.Y =
frame->data[0];
1517 surface->Data.U =
frame->data[1];
1518 surface->Data.V =
frame->data[2];
1522 surface->Data.B =
frame->data[0];
1523 surface->Data.G =
frame->data[0] + 1;
1524 surface->Data.R =
frame->data[0] + 2;
1525 surface->Data.A =
frame->data[0] + 3;
1529 surface->Data.Y =
frame->data[0];
1530 surface->Data.U =
frame->data[0] + 1;
1531 surface->Data.V =
frame->data[0] + 3;
1536 surface->Data.Y16 = (mfxU16 *)
frame->data[0];
1537 surface->Data.U16 = (mfxU16 *)
frame->data[0] + 1;
1538 surface->Data.V16 = (mfxU16 *)
frame->data[0] + 3;
1541 surface->Data.V =
frame->data[0];
1542 surface->Data.U =
frame->data[0] + 1;
1543 surface->Data.Y =
frame->data[0] + 2;
1546 surface->Data.A =
frame->data[0] + 3;
1549 surface->Data.U =
frame->data[0];
1552 surface->Data.U =
frame->data[0];
1553 surface->Data.Y =
frame->data[0] + 2;
1554 surface->Data.V =
frame->data[0] + 4;
1557 surface->Data.A =
frame->data[0] + 6;
1561 return MFX_ERR_UNSUPPORTED;
1563 surface->Data.Pitch =
frame->linesize[0];
1564 surface->Data.TimeStamp =
frame->pts;
1572 atomic_int *inited = upload ? &
s->session_upload_init : &
s->session_download_init;
1573 mfxSession *session = upload ? &
s->session_upload : &
s->session_download;
1599 mfxFrameSurface1
out = {{ 0 }};
1600 mfxFrameSurface1 *in = (mfxFrameSurface1*)
src->data[3];
1602 mfxSyncPoint sync =
NULL;
1606 AVFrame *tmp_frame = &
s->realigned_download_frame;
1619 if (tmp_frame->format != dst->
format ||
1624 tmp_frame->format = dst->
format;
1633 dst_frame = realigned ? tmp_frame : dst;
1635 if (!
s->session_download) {
1636 if (
s->child_frames_ref)
1643 out.Info = in->Info;
1647 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_download, in, &
out,
NULL, &sync);
1648 if (err == MFX_WRN_DEVICE_BUSY)
1650 }
while (err == MFX_WRN_DEVICE_BUSY);
1652 if (err < 0 || !sync) {
1658 err = MFXVideoCORE_SyncOperation(
s->session_download, sync, 1000);
1659 }
while (err == MFX_WRN_IN_EXECUTION);
1666 tmp_frame->width = dst->
width;
1667 tmp_frame->height = dst->
height;
1682 mfxFrameSurface1 in = {{ 0 }};
1683 mfxFrameSurface1 *
out = (mfxFrameSurface1*)dst->
data[3];
1684 mfxFrameInfo tmp_info;
1686 mfxSyncPoint sync =
NULL;
1690 AVFrame *tmp_frame = &
s->realigned_upload_frame;
1701 if (
src->height & 15 ||
src->linesize[0] & 15) {
1703 if (tmp_frame->format !=
src->format ||
1704 tmp_frame->width !=
FFALIGN(
src->width, 16) ||
1705 tmp_frame->height !=
FFALIGN(
src->height, 16)) {
1708 tmp_frame->format =
src->format;
1710 tmp_frame->height =
FFALIGN(
src->height, 16);
1726 tmp_info =
out->Info;
1727 out->Info.CropW =
FFMIN(
out->Info.Width, tmp_frame->width);
1728 out->Info.CropH =
FFMIN(
out->Info.Height, tmp_frame->height);
1731 src_frame = realigned ? tmp_frame :
src;
1733 if (!
s->session_upload) {
1734 if (
s->child_frames_ref)
1741 in.Info =
out->Info;
1745 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_upload, &in,
out,
NULL, &sync);
1746 if (err == MFX_WRN_DEVICE_BUSY)
1748 }
while (err == MFX_WRN_DEVICE_BUSY);
1750 if (err < 0 || !sync) {
1756 err = MFXVideoCORE_SyncOperation(
s->session_upload, sync, 1000);
1757 }
while (err == MFX_WRN_IN_EXECUTION);
1764 out->Info.CropW = tmp_info.CropW;
1765 out->Info.CropH = tmp_info.CropH;
1780 "mapped to QSV frames.\n");
1790 sizeof(*
s->handle_pairs_internal));
1791 if (!
s->handle_pairs_internal)
1794 sizeof(*
s->surfaces_internal));
1795 if (!
s->surfaces_internal)
1800 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1801 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1804 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1813 sizeof(*
s->handle_pairs_internal));
1814 if (!
s->handle_pairs_internal)
1817 sizeof(*
s->surfaces_internal));
1818 if (!
s->surfaces_internal)
1823 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1824 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1828 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1831 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
1832 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1834 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1844 sizeof(*
s->handle_pairs_internal));
1845 if (!
s->handle_pairs_internal)
1848 sizeof(*
s->surfaces_internal));
1849 if (!
s->surfaces_internal)
1853 s->handle_pairs_internal[
i].first = (mfxMemId)src_hwctx->
surfaces[
i];
1854 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
1855 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
1858 if (src_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
1859 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1861 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
1869 dst_hwctx->
surfaces =
s->surfaces_internal;
1881 switch(
src->format) {
1885 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1886 if (*(VASurfaceID*)pair->first == (VASurfaceID)
src->data[3]) {
1895 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1896 if (pair->first ==
src->data[0]
1897 && (pair->second ==
src->data[1]
1898 || (pair->second == (mfxMemId)MFX_INFINITE &&
src->data[1] == (uint8_t *)0))) {
1907 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
1908 if (pair->first ==
src->data[3]) {
1918 "is not in the mapped frames context.\n");
1935 const void *hwconfig,
1975 static const struct {
1979 {
"auto", MFX_IMPL_AUTO },
1980 {
"sw", MFX_IMPL_SOFTWARE },
1981 {
"hw", MFX_IMPL_HARDWARE },
1982 {
"auto_any", MFX_IMPL_AUTO_ANY },
1983 {
"hw_any", MFX_IMPL_HARDWARE_ANY },
1984 {
"hw2", MFX_IMPL_HARDWARE2 },
1985 {
"hw3", MFX_IMPL_HARDWARE3 },
1986 {
"hw4", MFX_IMPL_HARDWARE4 },
1989 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
1994 if (!strcmp(device, impl_map[
i].
name)) {
1995 impl = impl_map[
i].impl;
1999 impl = strtol(device,
NULL, 0);
2002 if (impl != MFX_IMPL_SOFTWARE) {
2004 impl |= MFX_IMPL_VIA_D3D11;
2006 impl |= MFX_IMPL_VIA_D3D9;
2013 mfxIMPL implementation,
2019 mfxVersion ver = { { 3, 1 } };
2021 mfxHandleType handle_type;
2025 switch (child_device_ctx->
type) {
2030 handle_type = MFX_HANDLE_VA_DISPLAY;
2031 handle = (mfxHDL)child_device_hwctx->
display;
2039 handle_type = MFX_HANDLE_D3D11_DEVICE;
2040 handle = (mfxHDL)child_device_hwctx->
device;
2048 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
2049 handle = (mfxHDL)child_device_hwctx->
devmgr;
2063 err = MFXVideoCORE_SetHandle(hwctx->
session, handle_type, handle);
2064 if (err != MFX_ERR_NONE) {
2092 child_device_ctx,
flags);
2111 ctx->user_opaque = priv;
2119 "\"%s\".\n", e->
value);
2122 }
else if (CONFIG_VAAPI) {
2125 }
else if (CONFIG_D3D11VA) {
2127 "Defaulting child_device_type to AV_HWDEVICE_TYPE_D3D11VA for oneVPL."
2128 "Please explicitly set child device type via \"-init_hw_device\" "
2129 "option if needed.\n");
2131 }
else if (CONFIG_DXVA2) {
2134 }
else if (CONFIG_DXVA2) {
2136 "WARNING: defaulting child_device_type to AV_HWDEVICE_TYPE_DXVA2 for compatibility "
2137 "with old commandlines. This behaviour will be removed "
2138 "in the future. Please explicitly set device type via \"-init_hw_device\" option.\n");
2140 }
else if (CONFIG_D3D11VA) {
2148 child_device_opts =
NULL;
2149 switch (child_device_type) {
2158 av_dict_set(&child_device_opts,
"kernel_driver",
"i915", 0);
2159 av_dict_set(&child_device_opts,
"driver",
"iHD", 0);
2172 "d3d11va is not available or child device type is set to dxva2 "
2173 "explicitly for oneVPL.\n");
2188 e ? e->
value :
NULL, child_device_opts, 0);