55#define QSV_VERSION_ATLEAST(MAJOR, MINOR) \
56 (MFX_VERSION_MAJOR > (MAJOR) || \
57 MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
59#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
60 ((MFX_VERSION.Major > (MAJOR)) || \
61 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
63#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
64#define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0)
65#define QSV_HAVE_OPAQUE !QSV_ONEVPL
68#include <mfxdispatcher.h>
70#define MFXUnload(a) do { } while(0)
115 mfxFrameSurface1 **surface_ptrs;
117 mfxExtOpaqueSurfaceAlloc opaque_alloc;
118 mfxExtBuffer *ext_buffers[1];
141 MFX_FOURCC_YUY2, 0 },
144 MFX_FOURCC_UYVY, 0 },
147 MFX_FOURCC_Y210, 1 },
151 MFX_FOURCC_AYUV, 0 },
155 MFX_FOURCC_Y410, 0 },
156#if QSV_VERSION_ATLEAST(1, 31)
160 MFX_FOURCC_P016, 1 },
164 MFX_FOURCC_Y216, 1 },
168 MFX_FOURCC_Y416, 1 },
185 mfxHDLPair *handle_pair;
186 handle_pair = surf->Data.MemId;
187 switch (base_dev_type) {
190 base_handle[0] = handle_pair->first;
195 base_handle[0] = handle_pair->first;
196 base_handle[1] = handle_pair->second;
201 base_handle[0] = handle_pair->first;
229static uint32_t qsv_get_d3d11va_bind_flags(
int mem_type)
231 uint32_t bind_flags = 0;
233 if ((mem_type & MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET) && (mem_type & MFX_MEMTYPE_INTERNAL_FRAME))
234 bind_flags = D3D11_BIND_DECODER | D3D11_BIND_VIDEO_ENCODER;
236 bind_flags = D3D11_BIND_DECODER;
238 if ((MFX_MEMTYPE_FROM_VPPOUT & mem_type) || (MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & mem_type))
239 bind_flags = D3D11_BIND_RENDER_TARGET;
248 int i, planes_nb = 0;
249 if (
dst->format !=
src->format)
254 for (
i = 0;
i <
desc->nb_components;
i++)
255 planes_nb =
FFMAX(planes_nb,
desc->comp[
i].plane + 1);
257 for (
i = 0;
i < planes_nb;
i++) {
258 int sheight, dheight, y;
266 if (swidth < 0 || dwidth < 0) {
270 sheight =
src->height;
271 dheight =
dst->height;
277 for (y = 0; y < sheight; y++) {
278 void *line_ptr =
dst->data[
i] + y*
dst->linesize[
i] + swidth;
280 comp.depth > 8 ? 2 : 1,
284 for (y = sheight; y < dheight; y++) {
285 memcpy(
dst->data[
i]+y*
dst->linesize[
i],
286 dst->data[
i]+(sheight-1)*
dst->linesize[
i],
297 int hw_handle_supported = 0;
298 mfxHandleType handle_type;
303 err = MFXQueryIMPL(hwctx->
session, &
s->impl);
304 if (err == MFX_ERR_NONE)
305 err = MFXQueryVersion(hwctx->
session, &
s->ver);
306 if (err != MFX_ERR_NONE) {
313 handle_type = MFX_HANDLE_VA_DISPLAY;
316 hw_handle_supported = 1;
320 handle_type = MFX_HANDLE_D3D11_DEVICE;
323 hw_handle_supported = 1;
327 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
330 hw_handle_supported = 1;
334 if (hw_handle_supported) {
335 err = MFXVideoCORE_GetHandle(hwctx->
session, handle_type, &
s->handle);
336 if (err == MFX_ERR_NONE) {
337 s->handle_type = handle_type;
338 s->child_device_type = device_type;
344 "from the session\n");
353 if (
s->session_download) {
354 MFXVideoVPP_Close(
s->session_download);
355 MFXClose(
s->session_download);
357 s->session_download =
NULL;
358 s->session_download_init = 0;
360 if (
s->session_upload) {
361 MFXVideoVPP_Close(
s->session_upload);
362 MFXClose(
s->session_upload);
364 s->session_upload =
NULL;
365 s->session_upload_init = 0;
391 mfxHDLPair *hdl_pair = (mfxHDLPair *)qsv_surface->
mfx_surface.Data.MemId;
394 if (!
s->child_frames_ref)
418 s->nb_surfaces_used++;
432 mfxHDLPair *handle_pairs_internal =
NULL;
435 if (!
s->child_frames_ref)
445 "QSV on dxva2 requires a fixed frame pool size\n");
450 qsv_surface =
av_calloc(1,
sizeof(*qsv_surface));
462 handle_pairs_internal =
av_calloc(1,
sizeof(*handle_pairs_internal));
463 if (!handle_pairs_internal)
472 VASurfaceID *surface_id_internal;
474 surface_id_internal =
av_calloc(1,
sizeof(*surface_id_internal));
475 if (!surface_id_internal)
478 *surface_id_internal = (VASurfaceID)(uintptr_t)qsv_surface->
child_frame->
data[3];
479 handle_pairs_internal->first = (mfxHDL)surface_id_internal;
480 handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
487 handle_pairs_internal->first = (mfxMemId)qsv_surface->
child_frame->
data[0];
489 if (child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET)
490 handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
492 handle_pairs_internal->second = (mfxMemId)qsv_surface->
child_frame->
data[1];
497 qsv_surface->
mfx_surface.Data.MemId = (mfxMemId)handle_pairs_internal;
538 if (!device_priv->
handle) {
540 "Cannot create a non-opaque internal surface pool without "
541 "a hardware handle\n");
546 if (!child_device_ref)
553 child_device_hwctx->
display = (VADisplay)device_priv->
handle;
566 child_device_hwctx->
devmgr = (IDirect3DDeviceManager9*)device_priv->
handle;
577 if (!child_frames_ref) {
593 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
594 if (hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
595 child_frames_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
602 if (hwctx->
frame_type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)
603 child_frames_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
605 child_frames_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
618 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
619 s->handle_pairs_internal[
i].first = child_frames_hwctx->
surface_ids +
i;
620 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
621 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
623 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
629 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
631 if(child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
632 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
636 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
638 if (child_frames_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
639 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
641 hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
648 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
649 s->handle_pairs_internal[
i].first = (mfxMemId)child_frames_hwctx->
surfaces[
i];
650 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
651 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
653 if (child_frames_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
654 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
656 hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
660 s->child_frames_ref = child_frames_ref;
661 child_frames_ref =
NULL;
682 surf->Info.BitDepthLuma =
desc->comp[0].depth;
683 surf->Info.BitDepthChroma =
desc->comp[0].depth;
686 if (
desc->log2_chroma_w &&
desc->log2_chroma_h)
687 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
688 else if (
desc->log2_chroma_w)
689 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV422;
691 surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV444;
693 surf->Info.FourCC =
fourcc;
695 surf->Info.CropW =
ctx->width;
697 surf->Info.CropH =
ctx->height;
698 surf->Info.FrameRateExtN = 25;
699 surf->Info.FrameRateExtD = 1;
700 surf->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
712 if (
ctx->initial_pool_size < 0) {
715 }
else if (
ctx->initial_pool_size == 0) {
716 mfxFrameSurface1 mfx_surf1;
727 memset(&mfx_surf1, 0,
sizeof(mfx_surf1));
729 s->frame_info = mfx_surf1.Info;
730 frames_hwctx->
info = &
s->frame_info;
737 sizeof(*
s->handle_pairs_internal));
738 if (!
s->handle_pairs_internal)
742 sizeof(*
s->surfaces_internal));
743 if (!
s->surfaces_internal)
746 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
753 if (!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) {
769 frames_hwctx->
surfaces =
s->surfaces_internal;
775static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
776 mfxFrameAllocResponse *resp)
781 mfxFrameInfo *
i = &req->Info;
784 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
785 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
786 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
787 return MFX_ERR_UNSUPPORTED;
788 if (
i->Width > i1->Width ||
i->Height > i1->Height ||
789 i->FourCC != i1->FourCC ||
i->ChromaFormat != i1->ChromaFormat) {
791 "allocation request: %dx%d %d %d vs %dx%d %d %d\n",
792 i->Width,
i->Height,
i->FourCC,
i->ChromaFormat,
793 i1->Width, i1->Height, i1->FourCC, i1->ChromaFormat);
794 return MFX_ERR_UNSUPPORTED;
797 resp->mids =
s->mem_ids;
803static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
808static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
810 return MFX_ERR_UNSUPPORTED;
813static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
815 return MFX_ERR_UNSUPPORTED;
820 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
821 mfxHDLPair *pair_src = (mfxHDLPair*)mid;
823 pair_dst->first = pair_src->first;
825 if (pair_src->second != (mfxMemId)MFX_INFINITE)
826 pair_dst->second = pair_src->second;
832static int qsv_d3d11_update_config(
void *
ctx, mfxHDL handle, mfxConfig
cfg)
837 IDXGIAdapter *pDXGIAdapter;
838 DXGI_ADAPTER_DESC adapterDesc;
839 IDXGIDevice *pDXGIDevice =
NULL;
842 mfxVariant impl_value = {0};
844 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (
void**)&pDXGIDevice);
846 hr = IDXGIDevice_GetAdapter(pDXGIDevice, &pDXGIAdapter);
849 IDXGIDevice_Release(pDXGIDevice);
853 hr = IDXGIAdapter_GetDesc(pDXGIAdapter, &adapterDesc);
863 impl_value.Type = MFX_VARIANT_TYPE_U16;
864 impl_value.Data.U16 = adapterDesc.DeviceId;
865 sts = MFXSetConfigFilterProperty(
cfg,
866 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceID", impl_value);
867 if (sts != MFX_ERR_NONE) {
869 "DeviceID property: %d.\n", sts);
873 impl_value.Type = MFX_VARIANT_TYPE_PTR;
874 impl_value.Data.Ptr = &adapterDesc.AdapterLuid;
875 sts = MFXSetConfigFilterProperty(
cfg,
876 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
877 if (sts != MFX_ERR_NONE) {
879 "DeviceLUID property: %d.\n", sts);
883 impl_value.Type = MFX_VARIANT_TYPE_U32;
884 impl_value.Data.U32 = 0x0001;
885 sts = MFXSetConfigFilterProperty(
cfg,
886 (
const mfxU8 *)
"mfxExtendedDeviceId.LUIDDeviceNodeMask", impl_value);
887 if (sts != MFX_ERR_NONE) {
889 "LUIDDeviceNodeMask property: %d.\n", sts);
896 IDXGIAdapter_Release(pDXGIAdapter);
897 IDXGIDevice_Release(pDXGIDevice);
902static int qsv_d3d9_update_config(
void *
ctx, mfxHDL handle, mfxConfig
cfg)
907 IDirect3DDeviceManager9* devmgr = handle;
908 IDirect3DDevice9 *device =
NULL;
909 IDirect3DDevice9Ex *device_ex =
NULL;
910 HANDLE device_handle = 0;
911 IDirect3D9Ex *d3d9ex =
NULL;
912 IDirect3D9 *d3d9 =
NULL;
914 D3DDEVICE_CREATION_PARAMETERS
params;
916 mfxVariant impl_value = {0};
918 hr = IDirect3DDeviceManager9_OpenDeviceHandle(devmgr, &device_handle);
924 hr = IDirect3DDeviceManager9_LockDevice(devmgr, device_handle, &device, TRUE);
927 IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle);
930 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (
void **)&device_ex);
931 IDirect3DDevice9_Release(device);
937 hr = IDirect3DDevice9Ex_GetCreationParameters(device_ex, &
params);
940 IDirect3DDevice9Ex_Release(device_ex);
944 hr = IDirect3DDevice9Ex_GetDirect3D(device_ex, &d3d9);
947 IDirect3DDevice9Ex_Release(device_ex);
950 hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (
void **)&d3d9ex);
951 IDirect3D9_Release(d3d9);
954 IDirect3DDevice9Ex_Release(device_ex);
958 hr = IDirect3D9Ex_GetAdapterLUID(d3d9ex,
params.AdapterOrdinal, &luid);
964 impl_value.Type = MFX_VARIANT_TYPE_PTR;
965 impl_value.Data.Ptr = &luid;
966 sts = MFXSetConfigFilterProperty(
cfg,
967 (
const mfxU8 *)
"mfxExtendedDeviceId.DeviceLUID", impl_value);
968 if (sts != MFX_ERR_NONE) {
970 "DeviceLUID property: %d.\n", sts);
977 IDirect3D9Ex_Release(d3d9ex);
978 IDirect3DDevice9Ex_Release(device_ex);
981 IDirect3DDeviceManager9_UnlockDevice(devmgr, device_handle, FALSE);
982 IDirect3DDeviceManager9_CloseDeviceHandle(devmgr, device_handle);
988static int qsv_va_update_config(
void *
ctx, mfxHDL handle, mfxConfig
cfg)
991#if VA_CHECK_VERSION(1, 15, 0)
993 VADisplay dpy = handle;
995 VADisplayAttribute attr = {
996 .type = VADisplayPCIID,
998 mfxVariant impl_value = {0};
1000 vas = vaGetDisplayAttributes(dpy, &attr, 1);
1001 if (vas == VA_STATUS_SUCCESS && attr.flags != VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
1002 impl_value.Type = MFX_VARIANT_TYPE_U16;
1003 impl_value.Data.U16 = (attr.value & 0xFFFF);
1004 sts = MFXSetConfigFilterProperty(
cfg,
1005 (
const mfxU8 *)
"mfxImplDescription.mfxDeviceDescription.DeviceID", impl_value);
1006 if (sts != MFX_ERR_NONE) {
1008 "DeviceID property: %d.\n", sts);
1013 "consider to upgrade the driver to support VA-API 1.15.0\n");
1022 "the device information from the driver. Please consider to upgrade libva to "
1023 "support VA-API 1.15.0\n");
1029static int qsv_new_mfx_loader(
void *
ctx,
1031 mfxHandleType handle_type,
1032 mfxIMPL implementation,
1037 mfxLoader loader =
NULL;
1039 mfxVariant impl_value = {0};
1049 cfg = MFXCreateConfig(loader);
1055 impl_value.Type = MFX_VARIANT_TYPE_U32;
1056 impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
1057 MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
1058 sts = MFXSetConfigFilterProperty(
cfg,
1059 (
const mfxU8 *)
"mfxImplDescription.Impl", impl_value);
1060 if (sts != MFX_ERR_NONE) {
1062 "property: %d.\n", sts);
1066 impl_value.Type = MFX_VARIANT_TYPE_U32;
1067 impl_value.Data.U32 = pver->Version;
1068 sts = MFXSetConfigFilterProperty(
cfg,
1069 (
const mfxU8 *)
"mfxImplDescription.ApiVersion.Version",
1071 if (sts != MFX_ERR_NONE) {
1073 "property: %d.\n", sts);
1077 impl_value.Type = MFX_VARIANT_TYPE_U32;
1078 impl_value.Data.U32 = 0x8086;
1079 sts = MFXSetConfigFilterProperty(
cfg,
1080 (
const mfxU8 *)
"mfxImplDescription.VendorID", impl_value);
1081 if (sts != MFX_ERR_NONE) {
1083 "VendorID property: %d.\n", sts);
1087 if (MFX_HANDLE_VA_DISPLAY == handle_type) {
1088 if (handle && qsv_va_update_config(
ctx, handle,
cfg))
1091 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_VAAPI;
1092 }
else if (MFX_HANDLE_D3D9_DEVICE_MANAGER == handle_type) {
1093 if (handle && qsv_d3d9_update_config(
ctx, handle,
cfg))
1096 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D9;
1098 if (handle && qsv_d3d11_update_config(
ctx, handle,
cfg))
1101 impl_value.Data.U32 = MFX_ACCEL_MODE_VIA_D3D11;
1104 impl_value.Type = MFX_VARIANT_TYPE_U32;
1105 sts = MFXSetConfigFilterProperty(
cfg,
1106 (
const mfxU8 *)
"mfxImplDescription.AccelerationMode", impl_value);
1107 if (sts != MFX_ERR_NONE) {
1109 "AccelerationMode property: %d.\n", sts);
1124static int qsv_create_mfx_session_from_loader(
void *
ctx, mfxLoader loader, mfxSession *psession)
1127 mfxSession session =
NULL;
1128 uint32_t impl_idx = 0;
1133 mfxImplDescription *impl_desc;
1135 sts = MFXEnumImplementations(loader, impl_idx,
1136 MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
1137 (mfxHDL *)&impl_desc);
1139 if (sts == MFX_ERR_NOT_FOUND)
1141 else if (sts != MFX_ERR_NONE) {
1146 sts = MFXCreateSession(loader, impl_idx, &session);
1147 MFXDispReleaseImplDescription(loader, impl_desc);
1148 if (sts == MFX_ERR_NONE)
1154 if (sts != MFX_ERR_NONE) {
1159 sts = MFXQueryVersion(session, &ver);
1160 if (sts != MFX_ERR_NONE) {
1166 "version is %d.%d\n", ver.Major, ver.Minor);
1168 *psession = session;
1181 mfxHandleType handle_type,
1182 mfxIMPL implementation,
1184 mfxSession *psession,
1187 mfxLoader loader =
NULL;
1190 "Use Intel(R) oneVPL to create MFX session, API version is "
1191 "%d.%d, the required implementation version is %d.%d\n",
1192 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1194 if (handle_type != MFX_HANDLE_VA_DISPLAY &&
1195 handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER &&
1196 handle_type != MFX_HANDLE_D3D11_DEVICE) {
1198 "Invalid MFX device handle type\n");
1205 if (qsv_new_mfx_loader(
ctx, handle, handle_type, implementation, pver, (
void **)&loader))
1212 if (qsv_create_mfx_session_from_loader(
ctx, loader, psession))
1221 if (!*ploader && loader)
1231 mfxHandleType handle_type,
1232 mfxIMPL implementation,
1234 mfxSession *psession,
1239 mfxSession session =
NULL;
1242 "Use Intel(R) Media SDK to create MFX session, API version is "
1243 "%d.%d, the required implementation version is %d.%d\n",
1244 MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor);
1249 sts = MFXInit(implementation, &ver, &session);
1250 if (sts != MFX_ERR_NONE) {
1256 sts = MFXQueryVersion(session, &ver);
1257 if (sts != MFX_ERR_NONE) {
1264 "version is %d.%d\n", ver.Major, ver.Minor);
1268 sts = MFXInit(implementation, &ver, &session);
1269 if (sts != MFX_ERR_NONE) {
1275 *psession = session;
1289 mfxSession *session,
int upload)
1297 mfxFrameAllocator frame_allocator = {
1310 void **loader = &hwctx->
loader;
1311 mfxSession parent_session = hwctx->
session;
1315 err = MFXQueryIMPL(parent_session, &impl);
1316 if (err == MFX_ERR_NONE)
1317 err = MFXQueryVersion(parent_session, &ver);
1318 if (err != MFX_ERR_NONE) {
1324 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1328 device_priv->
impl, &device_priv->
ver, session, loader);
1332 if (device_priv->
handle) {
1333 err = MFXVideoCORE_SetHandle(*session, device_priv->
handle_type,
1335 if (err != MFX_ERR_NONE) {
1342 err = MFXJoinSession(parent_session, *session);
1343 if (err != MFX_ERR_NONE) {
1351 err = MFXVideoCORE_SetFrameAllocator(*session, &frame_allocator);
1352 if (err != MFX_ERR_NONE) {
1358 memset(&par, 0,
sizeof(par));
1361 par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
1362 MFX_IOPATTERN_IN_VIDEO_MEMORY;
1366 par.ExtParam =
s->ext_buffers;
1368 par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
1369 MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1373 par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
1374 MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
1383 par.vpp.In.FrameRateExtN = 25;
1384 par.vpp.In.FrameRateExtD = 1;
1385 par.vpp.Out = par.vpp.In;
1387 err = MFXVideoVPP_Init(*session, &par);
1388 if (err != MFX_ERR_NONE) {
1390 "Surface upload/download will not be possible\n");
1418 opaque = !!(frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
1441 s->mem_ids[
i] = frames_hwctx->
surfaces[
i].Data.MemId;
1446 sizeof(*
s->surface_ptrs));
1447 if (!
s->surface_ptrs)
1453 s->opaque_alloc.In.Surfaces =
s->surface_ptrs;
1454 s->opaque_alloc.In.NumSurface = frames_hwctx->
nb_surfaces;
1455 s->opaque_alloc.In.Type = frames_hwctx->
frame_type;
1457 s->opaque_alloc.Out =
s->opaque_alloc.In;
1459 s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1460 s->opaque_alloc.Header.BufferSz =
sizeof(
s->opaque_alloc);
1462 s->ext_buffers[0] = (mfxExtBuffer*)&
s->opaque_alloc;
1466 s->session_download =
NULL;
1467 s->session_upload =
NULL;
1469 s->session_download_init = 0;
1470 s->session_upload_init = 0;
1503 fmts[0] =
ctx->sw_format;
1527 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1528 dst_hwctx->
surface_ids[
i] = *(VASurfaceID*)pair->first;
1537 D3D11_TEXTURE2D_DESC texDesc;
1540 dst_hwctx = dst_ctx->
hwctx;
1545 if (src_hwctx->
frame_type & MFX_MEMTYPE_SHARED_RESOURCE)
1546 dst_hwctx->
MiscFlags = D3D11_RESOURCE_MISC_SHARED;
1548 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1550 dst_hwctx->
texture_infos[
i].
index = pair->second == (mfxMemId)MFX_INFINITE ? (intptr_t)0 : (intptr_t)pair->second;
1554 dst_hwctx->
BindFlags = texDesc.BindFlags;
1569 mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->
surfaces[
i].Data.MemId;
1570 dst_hwctx->
surfaces[
i] = (IDirect3DSurface9*)pair->first;
1573 if (src_hwctx->
frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
1574 dst_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
1576 dst_hwctx->
surface_type = DXVA2_VideoProcessorRenderTarget;
1591 mfxFrameSurface1 *surf = (mfxFrameSurface1*)
src->data[3];
1594 uint8_t *child_data;
1598 if (!
s->child_frames_ref)
1606 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1611 child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
1618 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1619 child_data = pair->first;
1626 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1627 child_data = pair->first;
1635 if (
dst->format == child_frames_ctx->
format) {
1642 dst->height =
src->height;
1645 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1646 dst->data[0] = pair->first;
1647 dst->data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1649 dst->data[3] = child_data;
1675 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
1676 dummy->data[0] = pair->first;
1677 dummy->data[1] = pair->second == (mfxMemId)MFX_INFINITE ? (uint8_t *)0 : pair->second;
1679 dummy->data[3] = child_data;
1695 int download = !!
src->hw_frames_ctx;
1696 mfxFrameSurface1 *surf = (mfxFrameSurface1*)(download ?
src->data[3] :
dst->data[3]);
1708 dummy->buf[0] = download ?
src->buf[0] :
dst->buf[0];
1709 dummy->data[3] = surf->Data.MemId;
1710 dummy->hw_frames_ctx =
s->child_frames_ref;
1726 switch (
frame->format) {
1730 surface->Data.Y =
frame->data[0];
1731 surface->Data.UV =
frame->data[1];
1735 surface->Data.Y =
frame->data[0];
1736 surface->Data.U =
frame->data[1];
1737 surface->Data.V =
frame->data[2];
1741 surface->Data.B =
frame->data[0];
1742 surface->Data.G =
frame->data[0] + 1;
1743 surface->Data.R =
frame->data[0] + 2;
1744 surface->Data.A =
frame->data[0] + 3;
1747 surface->Data.Y =
frame->data[0];
1748 surface->Data.U =
frame->data[0] + 1;
1749 surface->Data.V =
frame->data[0] + 3;
1754 surface->Data.Y16 = (mfxU16 *)
frame->data[0];
1755 surface->Data.U16 = (mfxU16 *)
frame->data[0] + 1;
1756 surface->Data.V16 = (mfxU16 *)
frame->data[0] + 3;
1759 surface->Data.V =
frame->data[0];
1760 surface->Data.U =
frame->data[0] + 1;
1761 surface->Data.Y =
frame->data[0] + 2;
1764 surface->Data.A =
frame->data[0] + 3;
1767 surface->Data.U =
frame->data[0];
1770 surface->Data.U =
frame->data[0];
1771 surface->Data.Y =
frame->data[0] + 2;
1772 surface->Data.V =
frame->data[0] + 4;
1775 surface->Data.A =
frame->data[0] + 6;
1779 surface->Data.Y =
frame->data[0] + 1;
1780 surface->Data.U =
frame->data[0];
1781 surface->Data.V =
frame->data[0] + 2;
1785 return MFX_ERR_UNSUPPORTED;
1787 surface->Data.Pitch =
frame->linesize[0];
1788 surface->Data.TimeStamp =
frame->pts;
1796 atomic_int *inited = upload ? &
s->session_upload_init : &
s->session_download_init;
1797 mfxSession *session = upload ? &
s->session_upload : &
s->session_download;
1823 mfxFrameSurface1
out = {{ 0 }};
1824 mfxFrameSurface1 *in = (mfxFrameSurface1*)
src->data[3];
1826 mfxSyncPoint sync =
NULL;
1830 AVFrame *tmp_frame = &
s->realigned_download_frame;
1841 if (
dst->height & 15 ||
dst->linesize[0] & 15) {
1857 dst_frame = realigned ? tmp_frame :
dst;
1859 if (!
s->session_download) {
1860 if (
s->child_frames_ref)
1867 out.Info = in->Info;
1871 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_download, in, &
out,
NULL, &sync);
1872 if (err == MFX_WRN_DEVICE_BUSY)
1874 }
while (err == MFX_WRN_DEVICE_BUSY);
1876 if (err < 0 || !sync) {
1882 err = MFXVideoCORE_SyncOperation(
s->session_download, sync, 1000);
1883 }
while (err == MFX_WRN_IN_EXECUTION);
1906 mfxFrameSurface1 in = {{ 0 }};
1907 mfxFrameSurface1 *
out = (mfxFrameSurface1*)
dst->data[3];
1908 mfxFrameInfo tmp_info;
1910 mfxSyncPoint sync =
NULL;
1914 AVFrame *tmp_frame = &
s->realigned_upload_frame;
1925 if (
src->height & 15 ||
src->linesize[0] & 15) {
1950 tmp_info =
out->Info;
1955 src_frame = realigned ? tmp_frame :
src;
1957 if (!
s->session_upload) {
1958 if (
s->child_frames_ref)
1965 in.Info =
out->Info;
1969 err = MFXVideoVPP_RunFrameVPPAsync(
s->session_upload, &in,
out,
NULL, &sync);
1970 if (err == MFX_WRN_DEVICE_BUSY)
1972 }
while (err == MFX_WRN_DEVICE_BUSY);
1974 if (err < 0 || !sync) {
1980 err = MFXVideoCORE_SyncOperation(
s->session_upload, sync, 1000);
1981 }
while (err == MFX_WRN_IN_EXECUTION);
1988 out->Info.CropW = tmp_info.CropW;
1989 out->Info.CropH = tmp_info.CropH;
2000 mfxFrameSurface1 mfx_surf1;
2005 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
2014 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
2015 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
2017 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
2027 memset(&mfx_surf1, 0,
sizeof(mfx_surf1));
2029 s->frame_info = mfx_surf1.Info;
2030 dst_hwctx->
info = &
s->frame_info;
2048 sizeof(*
s->handle_pairs_internal));
2049 if (!
s->handle_pairs_internal)
2052 sizeof(*
s->surfaces_internal));
2053 if (!
s->surfaces_internal)
2058 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
2059 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
2062 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
2071 sizeof(*
s->handle_pairs_internal));
2072 if (!
s->handle_pairs_internal)
2075 sizeof(*
s->surfaces_internal));
2076 if (!
s->surfaces_internal)
2081 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
2082 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
2086 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
2089 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
2090 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
2092 dst_hwctx->
frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
2102 sizeof(*
s->handle_pairs_internal));
2103 if (!
s->handle_pairs_internal)
2106 sizeof(*
s->surfaces_internal));
2107 if (!
s->surfaces_internal)
2111 s->handle_pairs_internal[
i].first = (mfxMemId)src_hwctx->
surfaces[
i];
2112 s->handle_pairs_internal[
i].second = (mfxMemId)MFX_INFINITE;
2113 s->surfaces_internal[
i].Data.MemId = (mfxMemId)&
s->handle_pairs_internal[
i];
2116 if (src_hwctx->
surface_type == DXVA2_VideoProcessorRenderTarget)
2117 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
2119 dst_hwctx->
frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
2127 dst_hwctx->
surfaces =
s->surfaces_internal;
2152 switch(
src->format) {
2156 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
2157 if (*(VASurfaceID*)pair->first == (VASurfaceID)(uintptr_t)
src->data[3])
2165 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
2166 if (pair->first ==
src->data[0]
2167 && (pair->second ==
src->data[1]
2168 || (pair->second == (mfxMemId)MFX_INFINITE &&
src->data[1] == (uint8_t *)0)))
2176 mfxHDLPair *pair = (mfxHDLPair*)hwctx->
surfaces[
i].Data.MemId;
2177 if (pair->first ==
src->data[3])
2186 "is not in the mapped frames context.\n");
2196 dst->height =
src->height;
2204 mfxFrameSurface1 *surfaces_internal = (mfxFrameSurface1 *)hwmap->
priv;
2205 mfxHDLPair *handle_pairs_internal = (mfxHDLPair *)surfaces_internal->Data.MemId;
2208 switch (src_ctx->
format) {
2212 av_freep(&handle_pairs_internal->first);
2237 mfxFrameSurface1 *surfaces_internal =
NULL;
2238 mfxHDLPair *handle_pairs_internal =
NULL;
2241 surfaces_internal =
av_calloc(1,
sizeof(*surfaces_internal));
2242 if (!surfaces_internal) {
2247 handle_pairs_internal =
av_calloc(1,
sizeof(*handle_pairs_internal));
2248 if (!handle_pairs_internal) {
2257 switch (
src->format) {
2261 VASurfaceID *surface_id_internal;
2263 surface_id_internal =
av_calloc(1,
sizeof(*surface_id_internal));
2264 if (!surface_id_internal) {
2269 *surface_id_internal = (VASurfaceID)(uintptr_t)
src->data[3];
2270 handle_pairs_internal->first = (mfxHDL)surface_id_internal;
2271 handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
2283 handle_pairs_internal->first = (mfxMemId)
src->data[0];
2285 if (src_hwctx->
BindFlags & D3D11_BIND_RENDER_TARGET) {
2286 handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
2288 handle_pairs_internal->second = (mfxMemId)
src->data[1];
2299 surfaces_internal->Data.MemId = (mfxMemId)handle_pairs_internal;
2307 dst->height =
src->height;
2308 dst->data[3] = (uint8_t*)surfaces_internal;
2330 const void *hwconfig,
2370 static const struct {
2374 {
"auto", MFX_IMPL_AUTO },
2375 {
"sw", MFX_IMPL_SOFTWARE },
2376 {
"hw", MFX_IMPL_HARDWARE },
2377 {
"auto_any", MFX_IMPL_AUTO_ANY },
2378 {
"hw_any", MFX_IMPL_HARDWARE_ANY },
2379 {
"hw2", MFX_IMPL_HARDWARE2 },
2380 {
"hw3", MFX_IMPL_HARDWARE3 },
2381 {
"hw4", MFX_IMPL_HARDWARE4 },
2384 mfxIMPL impl = MFX_IMPL_AUTO_ANY;
2389 if (!strcmp(device, impl_map[
i].
name)) {
2390 impl = impl_map[
i].impl;
2394 impl = strtol(device,
NULL, 0);
2397 if (impl != MFX_IMPL_SOFTWARE) {
2399 impl |= MFX_IMPL_VIA_D3D11;
2401 impl |= MFX_IMPL_VIA_D3D9;
2408 mfxIMPL implementation,
2414 mfxVersion ver = { { 3, 1 } };
2416 mfxHandleType handle_type;
2420 switch (child_device_ctx->
type) {
2425 handle_type = MFX_HANDLE_VA_DISPLAY;
2426 handle = (mfxHDL)child_device_hwctx->
display;
2434 handle_type = MFX_HANDLE_D3D11_DEVICE;
2435 handle = (mfxHDL)child_device_hwctx->
device;
2443 handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
2444 handle = (mfxHDL)child_device_hwctx->
devmgr;
2458 err = MFXVideoCORE_SetHandle(hwctx->
session, handle_type, handle);
2459 if (err != MFX_ERR_NONE) {
2491 ctx->user_opaque = priv;
2496 child_device_ctx,
flags);
2515 ctx->user_opaque = priv;
2523 "\"%s\".\n", e->
value);
2527 }
else if (CONFIG_D3D11VA) {
2529 "Defaulting child_device_type to AV_HWDEVICE_TYPE_D3D11VA for oneVPL."
2530 "Please explicitly set child device type via \"-init_hw_device\" "
2531 "option if needed.\n");
2533 }
else if (CONFIG_DXVA2) {
2536 }
else if (CONFIG_DXVA2) {
2538 "WARNING: defaulting child_device_type to AV_HWDEVICE_TYPE_DXVA2 for compatibility "
2539 "with old commandlines. This behaviour will be removed "
2540 "in the future. Please explicitly set device type via \"-init_hw_device\" option.\n");
2542 }
else if (CONFIG_D3D11VA) {
2545 }
else if (CONFIG_VAAPI) {
2552#if CONFIG_VAAPI && defined(_WIN32)
2557 "\"%s\".\n", e->
value);
2562 child_device_opts =
NULL;
2563 switch (child_device_type) {
2572 av_dict_set(&child_device_opts,
"vendor_id",
"0x8086", 0);
2573 av_dict_set(&child_device_opts,
"driver",
"iHD", 0);
2583 av_dict_set(&child_device_opts,
"vendor_id",
"0x8086", 0);
2592 "d3d11va is not available or child device type is set to dxva2 "
2593 "explicitly for oneVPL.\n");
2608 e ? e->
value :
NULL, child_device_opts, 0);
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
SwsAArch64OpImplParams params
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
refcounted data buffer API
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
static enum AVPixelFormat pix_fmt
#define atomic_store(object, desired)
#define atomic_load(object)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
static CheckasmConfig cfg
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
AVBufferPool * av_buffer_pool_init2(size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
int av_hwdevice_ctx_init(AVBufferRef *ref)
Finalize the device context before use.
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given hardware type.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
Map a hardware frame.
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
AVHWFrameTransferDirection
@ AV_HWDEVICE_TYPE_D3D11VA
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
const HWContextType ff_hwcontext_type_qsv
static int qsv_map_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
static mfxIMPL choose_implementation(const char *device, enum AVHWDeviceType child_device_type)
static int qsv_device_init(AVHWDeviceContext *ctx)
static int qsv_fixed_pool_map_to(AVHWFramesContext *dst_ctx, AVFrame *dst, const AVFrame *src, int flags)
static void qsv_pool_release_dummy(void *opaque, uint8_t *data)
static int qsv_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
static int qsv_device_derive_from_child(AVHWDeviceContext *ctx, mfxIMPL implementation, AVHWDeviceContext *child_device_ctx, int flags)
static int qsv_fixed_frames_derive_to(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
static int qsv_init_child_ctx(AVHWFramesContext *ctx)
static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static int qsv_init_internal_session(AVHWFramesContext *ctx, mfxSession *session, int upload)
static void qsv_device_free(AVHWDeviceContext *ctx)
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
static int qsv_frames_init(AVHWFramesContext *ctx)
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
static int qsv_fill_border(AVFrame *dst, const AVFrame *src)
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static void qsv_pool_release(void *opaque, uint8_t *data)
static int qsv_frames_derive_from(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
static AVBufferRef * qsv_dynamic_pool_alloc(void *opaque, size_t size)
static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc)
static void qsv_dynamic_pool_unmap(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
static int qsv_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static int qsv_map_to(AVHWFramesContext *dst_ctx, AVFrame *dst, const AVFrame *src, int flags)
static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf)
static void qsv_frames_uninit(AVHWFramesContext *ctx)
static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt)
int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf, enum AVHWDeviceType base_dev_type, void **base_handle)
Caller needs to allocate enough space for base_handle pointer.
#define MFX_IMPL_VIA_MASK(impl)
static AVBufferRef * qsv_fixed_pool_alloc(void *opaque, size_t size)
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface)
static int qsv_create_mfx_session(void *ctx, mfxHDL handle, mfxHandleType handle_type, mfxIMPL implementation, mfxVersion *pver, mfxSession *psession, void **ploader)
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static int qsv_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
static int qsv_transfer_data_child(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static int qsv_dynamic_pool_map_to(AVHWFramesContext *dst_ctx, AVFrame *dst, const AVFrame *src, int flags)
static AVBufferRef * qsv_pool_alloc(void *opaque, size_t size)
static int qsv_device_derive(AVHWDeviceContext *ctx, AVHWDeviceContext *child_device_ctx, AVDictionary *opts, int flags)
static int qsv_dynamic_frames_derive_to(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
static uint16_t qsv_shift_from_pix_fmt(enum AVPixelFormat pix_fmt)
static int qsv_internal_session_check_init(AVHWFramesContext *ctx, int upload)
An API-specific header for AV_HWDEVICE_TYPE_QSV.
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
static enum AVPixelFormat supported_pixel_formats[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
ID3D11Texture2D * texture
The texture in which the frame is located.
intptr_t index
The index into the array texture element representing the frame, or 0 if the texture is not an array ...
This struct is allocated as AVHWDeviceContext.hwctx.
ID3D11Device * device
Device used for texture creation and access.
This struct is allocated as AVHWFramesContext.hwctx.
UINT MiscFlags
D3D11_TEXTURE2D_DESC.MiscFlags used for texture creation.
AVD3D11FrameDescriptor * texture_infos
In case if texture structure member above is not NULL contains the same texture pointer for all eleme...
UINT BindFlags
D3D11_TEXTURE2D_DESC.BindFlags used for texture creation.
This struct is allocated as AVHWDeviceContext.hwctx.
IDirect3DDeviceManager9 * devmgr
This struct is allocated as AVHWFramesContext.hwctx.
IDirect3DSurface9 ** surfaces
The surface pool.
DWORD surface_type
The surface type (e.g.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int initial_pool_size
Initial size of the frame pool.
int width
The allocated dimensions of the frames in this pool.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
This struct is allocated as AVHWDeviceContext.hwctx.
void * loader
The mfxLoader handle used for mfxSession creation.
This struct is allocated as AVHWFramesContext.hwctx.
mfxFrameSurface1 * surfaces
A pointer to a mfxFrameSurface1 struct.
int nb_surfaces
Number of frames in the pool.
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
mfxFrameInfo * info
A pointer to a mfxFrameInfo struct.
VAAPI connection details.
VADisplay display
The VADisplay handle, to be filled by the user.
VAAPI-specific data associated with a frame pool.
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
AVBufferPool * pool_internal
AVBufferRef * source_frames
For a derived context, a reference to the original frames context it was derived from.
void * priv
Hardware-specific private data associated with the mapping.
AVQSVDeviceContext p
The public AVQSVDeviceContext.
enum AVHWDeviceType child_device_type
mfxHandleType handle_type
enum AVPixelFormat child_pix_fmt
AVBufferRef * child_device_ctx
mfxSession session_upload
mfxHDLPair * handle_pairs_internal
mfxSession session_download
atomic_int session_download_init
AVBufferRef * child_frames_ref
AVFrame realigned_upload_frame
mfxFrameSurface1 * surfaces_internal
AVFrame realigned_download_frame
atomic_int session_upload_init
AVQSVFramesContext p
The public AVQSVFramesContext.
mfxFrameSurface1 mfx_surface
#define av_malloc_array(a, b)
static AVFormatContext * ctx
static AVDictionary * opts
int av_usleep(unsigned usec)
Sleep for a period of time.