19 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
34 #if HAVE_OPENCL_VAAPI_BEIGNET
37 #include <va/va_drmcommon.h>
38 #include <CL/cl_intel.h>
42 #if HAVE_OPENCL_DRM_BEIGNET
44 #include <CL/cl_intel.h>
48 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
50 #include <mfx/mfxstructures.h>
53 #include <CL/va_ext.h>
59 #include <CL/cl_dx9_media_sharing.h>
65 #include <CL/cl_d3d11.h>
69 #if HAVE_OPENCL_DRM_ARM
70 #include <CL/cl_ext.h>
71 #include <drm_fourcc.h>
87 #if HAVE_OPENCL_DRM_BEIGNET
88 int beignet_drm_mapping_usable;
89 clCreateImageFromFdINTEL_fn clCreateImageFromFdINTEL;
92 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
93 int qsv_mapping_usable;
94 clCreateFromVA_APIMediaSurfaceINTEL_fn
95 clCreateFromVA_APIMediaSurfaceINTEL;
96 clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn
97 clEnqueueAcquireVA_APIMediaSurfacesINTEL;
98 clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn
99 clEnqueueReleaseVA_APIMediaSurfacesINTEL;
102 #if HAVE_OPENCL_DXVA2
103 int dxva2_mapping_usable;
104 cl_dx9_media_adapter_type_khr dx9_media_adapter_type;
106 clCreateFromDX9MediaSurfaceKHR_fn
107 clCreateFromDX9MediaSurfaceKHR;
108 clEnqueueAcquireDX9MediaSurfacesKHR_fn
109 clEnqueueAcquireDX9MediaSurfacesKHR;
110 clEnqueueReleaseDX9MediaSurfacesKHR_fn
111 clEnqueueReleaseDX9MediaSurfacesKHR;
114 #if HAVE_OPENCL_D3D11
115 int d3d11_mapping_usable;
116 clCreateFromD3D11Texture2DKHR_fn
117 clCreateFromD3D11Texture2DKHR;
118 clEnqueueAcquireD3D11ObjectsKHR_fn
119 clEnqueueAcquireD3D11ObjectsKHR;
120 clEnqueueReleaseD3D11ObjectsKHR_fn
121 clEnqueueReleaseD3D11ObjectsKHR;
124 #if HAVE_OPENCL_DRM_ARM
125 int drm_arm_mapping_usable;
136 #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11
140 int nb_mapped_frames;
147 const void *private_info,
160 cle = clReleaseContext(hwctx->
context);
161 if (cle != CL_SUCCESS) {
163 "context: %d.\n", cle);
171 {
"platform_profile", CL_PLATFORM_PROFILE },
172 {
"platform_version", CL_PLATFORM_VERSION },
173 {
"platform_name", CL_PLATFORM_NAME },
174 {
"platform_vendor", CL_PLATFORM_VENDOR },
175 {
"platform_extensions", CL_PLATFORM_EXTENSIONS },
182 {
"device_name", CL_DEVICE_NAME },
183 {
"device_vendor", CL_DEVICE_VENDOR },
184 {
"driver_version", CL_DRIVER_VERSION },
185 {
"device_version", CL_DEVICE_VERSION },
186 {
"device_profile", CL_DEVICE_PROFILE },
187 {
"device_extensions", CL_DEVICE_EXTENSIONS },
194 {
"cpu", CL_DEVICE_TYPE_CPU },
195 {
"gpu", CL_DEVICE_TYPE_GPU },
196 {
"accelerator", CL_DEVICE_TYPE_ACCELERATOR },
197 {
"custom", CL_DEVICE_TYPE_CUSTOM },
198 {
"default", CL_DEVICE_TYPE_DEFAULT },
199 {
"all", CL_DEVICE_TYPE_ALL },
203 cl_platform_info
key)
208 cle = clGetPlatformInfo(platform_id, key, 0,
NULL, &size);
209 if (cle != CL_SUCCESS)
214 cle = clGetPlatformInfo(platform_id, key, size, str, &size);
215 if (cle != CL_SUCCESS) {
229 cle = clGetDeviceInfo(device_id, key, 0,
NULL, &size);
230 if (cle != CL_SUCCESS)
235 cle = clGetDeviceInfo(device_id, key, size, str, &size);
236 if (cle != CL_SUCCESS) {
250 CL_PLATFORM_EXTENSIONS);
251 if (str && strstr(str, name))
263 CL_DEVICE_EXTENSIONS);
264 if (str && strstr(str, name))
278 "%s found as platform extension.\n", name);
284 "%s found as device extension.\n", name);
292 cl_uint *nb_platforms,
293 cl_platform_id **platforms,
298 cle = clGetPlatformIDs(0,
NULL, nb_platforms);
299 if (cle != CL_SUCCESS) {
301 "OpenCL platforms: %d.\n", cle);
311 cle = clGetPlatformIDs(*nb_platforms, *platforms,
NULL);
312 if (cle != CL_SUCCESS) {
314 "platforms: %d.\n", cle);
323 cl_platform_id platform_id,
324 const char *platform_name,
342 "of platform \"%s\".\n",
358 cl_platform_id platform_id,
359 const char *platform_name,
361 cl_device_id **devices,
366 cle = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL,
367 0,
NULL, nb_devices);
368 if (cle == CL_DEVICE_NOT_FOUND) {
370 "on platform \"%s\".\n", platform_name);
373 }
else if (cle != CL_SUCCESS) {
375 "on platform \"%s\": %d.\n", platform_name, cle);
379 "platform \"%s\".\n", *nb_devices, platform_name);
385 cle = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL,
386 *nb_devices, *devices,
NULL);
387 if (cle != CL_SUCCESS) {
389 "on platform \"%s\": %d.\n", platform_name, cle);
398 cl_device_id device_id,
399 const char *device_name,
424 cle = clGetDeviceInfo(device_id, CL_DEVICE_TYPE,
426 if (cle != CL_SUCCESS) {
428 "of device \"%s\".\n", device_name);
448 "of device \"%s\".\n",
468 cl_uint *nb_platforms,
469 cl_platform_id **platforms,
472 cl_platform_id platform_id,
473 const char *platform_name,
476 cl_platform_id platform_id,
477 const char *platform_name,
479 cl_device_id **devices,
482 cl_device_id device_id,
483 const char *device_name,
489 cl_context_properties *props)
491 cl_uint nb_platforms;
492 cl_platform_id *platforms =
NULL;
493 cl_platform_id platform_id;
495 cl_device_id *devices =
NULL;
498 cl_context_properties default_props[3];
499 char *platform_name_src =
NULL,
500 *device_name_src =
NULL;
501 int err, found, p, d;
509 for (p = 0; p < nb_platforms; p++) {
510 const char *platform_name;
519 if (platform_name_src)
520 platform_name = platform_name_src;
522 platform_name =
"Unknown Platform";
535 &nb_devices, &devices,
540 for (d = 0; d < nb_devices; d++) {
541 const char *device_name;
551 device_name = device_name_src;
553 device_name =
"Unknown Device";
566 platform_name, device_name);
569 platform_id = platforms[p];
588 props = default_props;
589 default_props[0] = CL_CONTEXT_PLATFORM;
590 default_props[1] = (intptr_t)platform_id;
591 default_props[2] = 0;
593 if (props[0] == CL_CONTEXT_PLATFORM && props[1] == 0)
594 props[1] = (intptr_t)platform_id;
628 if (device && device[0]) {
630 int d = -1, p = -1, ret;
631 if (device[0] ==
'.')
632 ret = sscanf(device,
".%d", &d);
634 ret = sscanf(device,
"%d.%d", &p, &d);
637 "index specification \"%s\".\n", device);
658 if (cle != CL_SUCCESS) {
660 "command queue: %d.\n", cle);
670 "command queue: %d.\n", cle);
675 cle = clGetDeviceInfo(hwctx->
device_id, CL_DEVICE_PLATFORM,
678 if (cle != CL_SUCCESS) {
680 "platform containing the device.\n");
684 #define CL_FUNC(name, desc) do { \
687 priv->name = clGetExtensionFunctionAddressForPlatform( \
688 priv->platform_id, #name); \
690 av_log(hwdev, AV_LOG_VERBOSE, \
691 desc " function not found (%s).\n", #name); \
694 av_log(hwdev, AV_LOG_VERBOSE, \
695 desc " function found (%s).\n", #name); \
699 #if HAVE_OPENCL_DRM_BEIGNET
703 CL_FUNC(clCreateImageFromFdINTEL,
704 "Beignet DRM to OpenCL image mapping");
708 "mapping not usable.\n");
709 priv->beignet_drm_mapping_usable = 0;
711 priv->beignet_drm_mapping_usable = 1;
716 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
719 cl_context_properties *props =
NULL;
720 VADisplay va_display;
721 const char *va_ext =
"cl_intel_va_api_media_sharing";
726 "required for QSV to OpenCL mapping.\n", va_ext);
730 cle = clGetContextInfo(hwctx->
context, CL_CONTEXT_PROPERTIES,
731 0,
NULL, &props_size);
732 if (cle != CL_SUCCESS) {
734 "properties: %d.\n", cle);
737 if (props_size == 0) {
739 "enabled on context creation to use QSV to "
740 "OpenCL mapping.\n");
748 cle = clGetContextInfo(hwctx->
context, CL_CONTEXT_PROPERTIES,
749 props_size, props,
NULL);
750 if (cle != CL_SUCCESS) {
752 "properties: %d.\n", cle);
757 for (i = 0; i < (props_size /
sizeof(*props) - 1); i++) {
758 if (props[i] == CL_CONTEXT_VA_API_DISPLAY_INTEL) {
759 va_display = (VADisplay)(intptr_t)props[i+1];
765 "enabled on context creation to use QSV to "
766 "OpenCL mapping.\n");
769 if (!vaDisplayIsValid(va_display)) {
771 "required on context creation to use QSV to "
772 "OpenCL mapping.\n");
776 CL_FUNC(clCreateFromVA_APIMediaSurfaceINTEL,
777 "Intel QSV to OpenCL mapping");
778 CL_FUNC(clEnqueueAcquireVA_APIMediaSurfacesINTEL,
779 "Intel QSV in OpenCL acquire");
780 CL_FUNC(clEnqueueReleaseVA_APIMediaSurfacesINTEL,
781 "Intel QSV in OpenCL release");
787 priv->qsv_mapping_usable = 0;
789 priv->qsv_mapping_usable = 1;
795 #if HAVE_OPENCL_DXVA2
799 CL_FUNC(clCreateFromDX9MediaSurfaceKHR,
800 "DXVA2 to OpenCL mapping");
801 CL_FUNC(clEnqueueAcquireDX9MediaSurfacesKHR,
802 "DXVA2 in OpenCL acquire");
803 CL_FUNC(clEnqueueReleaseDX9MediaSurfacesKHR,
804 "DXVA2 in OpenCL release");
809 priv->dxva2_mapping_usable = 0;
811 priv->dx9_media_adapter_type = CL_ADAPTER_D3D9EX_KHR;
812 priv->dxva2_mapping_usable = 1;
817 #if HAVE_OPENCL_D3D11
819 const char *d3d11_ext =
"cl_khr_d3d11_sharing";
820 const char *nv12_ext =
"cl_intel_d3d11_nv12_media_sharing";
825 "required for D3D11 to OpenCL mapping.\n", d3d11_ext);
829 "required for D3D11 to OpenCL mapping.\n", nv12_ext);
833 CL_FUNC(clCreateFromD3D11Texture2DKHR,
834 "D3D11 to OpenCL mapping");
835 CL_FUNC(clEnqueueAcquireD3D11ObjectsKHR,
836 "D3D11 in OpenCL acquire");
837 CL_FUNC(clEnqueueReleaseD3D11ObjectsKHR,
838 "D3D11 in OpenCL release");
843 priv->d3d11_mapping_usable = 0;
845 priv->d3d11_mapping_usable = 1;
850 #if HAVE_OPENCL_DRM_ARM
852 const char *drm_arm_ext =
"cl_arm_import_memory";
853 const char *image_ext =
"cl_khr_image2d_from_buffer";
858 "required for DRM to OpenCL mapping on ARM.\n",
864 "required for DRM to OpenCL mapping on ARM.\n",
874 priv->drm_arm_mapping_usable = 0;
876 priv->drm_arm_mapping_usable = 1;
893 if (cle != CL_SUCCESS) {
895 "command queue reference: %d.\n", cle);
901 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
903 cl_platform_id platform_id,
904 const char *platform_name,
910 if (!clGetExtensionFunctionAddressForPlatform(platform_id,
911 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL")) {
913 "VAAPI device enumeration function.\n", platform_name);
921 cl_platform_id platform_id,
922 const char *platform_name,
924 cl_device_id **devices,
927 VADisplay va_display = context;
928 clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn
929 clGetDeviceIDsFromVA_APIMediaAdapterINTEL;
932 clGetDeviceIDsFromVA_APIMediaAdapterINTEL =
933 clGetExtensionFunctionAddressForPlatform(platform_id,
934 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL");
935 if (!clGetDeviceIDsFromVA_APIMediaAdapterINTEL) {
937 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL().\n");
941 cle = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(
942 platform_id, CL_VA_API_DISPLAY_INTEL, va_display,
943 CL_PREFERRED_DEVICES_FOR_VA_API_INTEL, 0,
NULL, nb_devices);
944 if (cle == CL_DEVICE_NOT_FOUND) {
946 "on platform \"%s\".\n", platform_name);
949 }
else if (cle != CL_SUCCESS) {
951 "on platform \"%s\": %d.\n", platform_name, cle);
959 cle = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(
960 platform_id, CL_VA_API_DISPLAY_INTEL, va_display,
961 CL_PREFERRED_DEVICES_FOR_VA_API_INTEL, *nb_devices, *devices,
NULL);
962 if (cle != CL_SUCCESS) {
964 "devices on platform \"%s\": %d.\n", platform_name, cle);
973 cl_device_id device_id,
974 const char *device_name,
977 const char *va_ext =
"cl_intel_va_api_media_sharing";
983 "%s extension.\n", device_name, va_ext);
989 #if HAVE_OPENCL_DXVA2
991 cl_platform_id platform_id,
992 const char *platform_name,
995 const char *dx9_ext =
"cl_khr_dx9_media_sharing";
1001 "%s extension.\n", platform_name, dx9_ext);
1007 cl_platform_id platform_id,
1008 const char *platform_name,
1009 cl_uint *nb_devices,
1010 cl_device_id **devices,
1013 IDirect3DDevice9 *device = context;
1014 clGetDeviceIDsFromDX9MediaAdapterKHR_fn
1015 clGetDeviceIDsFromDX9MediaAdapterKHR;
1016 cl_dx9_media_adapter_type_khr media_adapter_type = CL_ADAPTER_D3D9EX_KHR;
1019 clGetDeviceIDsFromDX9MediaAdapterKHR =
1020 clGetExtensionFunctionAddressForPlatform(platform_id,
1021 "clGetDeviceIDsFromDX9MediaAdapterKHR");
1022 if (!clGetDeviceIDsFromDX9MediaAdapterKHR) {
1024 "clGetDeviceIDsFromDX9MediaAdapterKHR().\n");
1028 cle = clGetDeviceIDsFromDX9MediaAdapterKHR(
1029 platform_id, 1, &media_adapter_type, (
void**)&device,
1030 CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR,
1031 0,
NULL, nb_devices);
1032 if (cle == CL_DEVICE_NOT_FOUND) {
1034 "on platform \"%s\".\n", platform_name);
1037 }
else if (cle != CL_SUCCESS) {
1039 "on platform \"%s\": %d.\n", platform_name, cle);
1047 cle = clGetDeviceIDsFromDX9MediaAdapterKHR(
1048 platform_id, 1, &media_adapter_type, (
void**)&device,
1049 CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR,
1050 *nb_devices, *devices,
NULL);
1051 if (cle != CL_SUCCESS) {
1053 "devices on platform \"%s\": %d.\n", platform_name, cle);
1062 #if HAVE_OPENCL_D3D11
1064 cl_platform_id platform_id,
1065 const char *platform_name,
1068 const char *d3d11_ext =
"cl_khr_d3d11_sharing";
1074 "%s extension.\n", platform_name, d3d11_ext);
1080 cl_platform_id platform_id,
1081 const char *platform_name,
1082 cl_uint *nb_devices,
1083 cl_device_id **devices,
1087 clGetDeviceIDsFromD3D11KHR_fn clGetDeviceIDsFromD3D11KHR;
1090 clGetDeviceIDsFromD3D11KHR =
1091 clGetExtensionFunctionAddressForPlatform(platform_id,
1092 "clGetDeviceIDsFromD3D11KHR");
1093 if (!clGetDeviceIDsFromD3D11KHR) {
1095 "clGetDeviceIDsFromD3D11KHR().\n");
1099 cle = clGetDeviceIDsFromD3D11KHR(platform_id,
1100 CL_D3D11_DEVICE_KHR, device,
1101 CL_PREFERRED_DEVICES_FOR_D3D11_KHR,
1102 0,
NULL, nb_devices);
1103 if (cle == CL_DEVICE_NOT_FOUND) {
1105 "on platform \"%s\".\n", platform_name);
1108 }
else if (cle != CL_SUCCESS) {
1110 "on platform \"%s\": %d.\n", platform_name, cle);
1118 cle = clGetDeviceIDsFromD3D11KHR(platform_id,
1119 CL_D3D11_DEVICE_KHR, device,
1120 CL_PREFERRED_DEVICES_FOR_D3D11_KHR,
1121 *nb_devices, *devices,
NULL);
1122 if (cle != CL_SUCCESS) {
1124 "devices on platform \"%s\": %d.\n", platform_name, cle);
1133 #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11
1135 cl_device_id device_id,
1136 const char *device_name,
1142 cle = clGetDeviceInfo(device_id, CL_DEVICE_TYPE,
1143 sizeof(device_type), &device_type,
NULL);
1144 if (cle != CL_SUCCESS) {
1146 "of device \"%s\".\n", device_name);
1149 if (!(device_type & CL_DEVICE_TYPE_GPU)) {
1159 #if HAVE_OPENCL_DRM_ARM
1161 cl_platform_id platform_id,
1162 const char *platform_name,
1165 const char *drm_arm_ext =
"cl_arm_import_memory";
1171 "%s extension.\n", platform_name, drm_arm_ext);
1177 cl_device_id device_id,
1178 const char *device_name,
1181 const char *drm_arm_ext =
"cl_arm_import_memory";
1187 "%s extension.\n", device_name, drm_arm_ext);
1198 switch (src_ctx->
type) {
1200 #if HAVE_OPENCL_DRM_BEIGNET
1209 err =
av_dict_set(&opts,
"platform_vendor",
"Intel", 0);
1211 err =
av_dict_set(&opts,
"platform_version",
"beignet", 0);
1220 .filter_device =
NULL,
1229 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
1236 cl_context_properties props[7] = {
1237 CL_CONTEXT_PLATFORM,
1239 CL_CONTEXT_VA_API_DISPLAY_INTEL,
1241 CL_CONTEXT_INTEROP_USER_SYNC,
1248 .context = src_hwctx->
display,
1250 .filter_platform = &opencl_filter_intel_media_vaapi_platform,
1251 .enumerate_devices = &opencl_enumerate_intel_media_vaapi_devices,
1252 .filter_device = &opencl_filter_intel_media_vaapi_device,
1260 #if HAVE_OPENCL_DXVA2
1264 IDirect3DDevice9 *device;
1268 hr = IDirect3DDeviceManager9_OpenDeviceHandle(src_hwctx->
devmgr,
1272 "for Direct3D9 device: %lx.\n", (
unsigned long)hr);
1277 hr = IDirect3DDeviceManager9_LockDevice(src_hwctx->
devmgr,
1281 cl_context_properties props[5] = {
1282 CL_CONTEXT_PLATFORM,
1284 CL_CONTEXT_ADAPTER_D3D9EX_KHR,
1293 .filter_platform = &opencl_filter_dxva2_platform,
1294 .enumerate_devices = &opencl_enumerate_dxva2_devices,
1295 .filter_device = &opencl_filter_gpu_device,
1300 IDirect3DDeviceManager9_UnlockDevice(src_hwctx->
devmgr,
1301 device_handle,
FALSE);
1304 "for Direct3D9 device: %lx.\n", (
unsigned long)hr);
1308 IDirect3DDeviceManager9_CloseDeviceHandle(src_hwctx->
devmgr,
1314 #if HAVE_OPENCL_D3D11
1318 cl_context_properties props[5] = {
1319 CL_CONTEXT_PLATFORM,
1321 CL_CONTEXT_D3D11_DEVICE_KHR,
1322 (intptr_t)src_hwctx->
device,
1328 .context = src_hwctx->
device,
1330 .filter_platform = &opencl_filter_d3d11_platform,
1331 .enumerate_devices = &opencl_enumerate_d3d11_devices,
1332 .filter_device = &opencl_filter_gpu_device,
1340 #if HAVE_OPENCL_DRM_ARM
1348 .filter_platform = &opencl_filter_drm_arm_platform,
1350 .filter_device = &opencl_filter_drm_arm_device,
1368 cl_image_format *image_format,
1369 cl_image_desc *image_desc)
1373 int channels = 0, order = 0, depth = 0, step = 0;
1374 int wsub, hsub,
alpha;
1391 if (width & wsub - 1 || height & hsub - 1)
1395 comp = &desc->
comp[
c];
1396 if (comp->
plane != plane)
1399 if (comp->
step != 1 && comp->
step != 2 &&
1400 comp->
step != 4 && comp->
step != 8)
1408 if (depth && comp->
depth != depth)
1412 if (comp->
depth > 8 &&
1417 if (step && comp->
step != step)
1419 order = order * 10 + c + 1;
1420 depth = comp->
depth;
1429 memset(image_format, 0,
sizeof(*image_format));
1430 memset(image_desc, 0,
sizeof(*image_desc));
1431 image_desc->image_type = CL_MEM_OBJECT_IMAGE2D;
1433 if (plane == 0 || alpha) {
1434 image_desc->image_width =
width;
1435 image_desc->image_height =
height;
1436 image_desc->image_row_pitch = step *
width;
1438 image_desc->image_width = width / wsub;
1439 image_desc->image_height = height / hsub;
1440 image_desc->image_row_pitch = step * width / wsub;
1444 image_format->image_channel_data_type = CL_UNORM_INT8;
1447 image_format->image_channel_data_type = CL_UNORM_INT16;
1452 #define CHANNEL_ORDER(order, type) \
1453 case order: image_format->image_channel_order = type; break;
1470 #undef CHANNEL_ORDER
1476 const void *hwconfig,
1480 cl_uint nb_image_formats;
1481 cl_image_format *image_formats =
NULL;
1484 int err, pix_fmts_found;
1485 size_t max_width, max_height;
1487 cle = clGetDeviceInfo(hwctx->
device_id, CL_DEVICE_IMAGE2D_MAX_WIDTH,
1488 sizeof(max_width), &max_width,
NULL);
1489 if (cle != CL_SUCCESS) {
1491 "supported image width: %d.\n", cle);
1495 cle = clGetDeviceInfo(hwctx->
device_id, CL_DEVICE_IMAGE2D_MAX_HEIGHT,
1496 sizeof(max_height), &max_height,
NULL);
1497 if (cle != CL_SUCCESS) {
1499 "supported image height: %d.\n", cle);
1506 cle = clGetSupportedImageFormats(hwctx->
context,
1508 CL_MEM_OBJECT_IMAGE2D,
1509 0,
NULL, &nb_image_formats);
1510 if (cle != CL_SUCCESS) {
1512 "image formats: %d.\n", cle);
1516 if (nb_image_formats == 0) {
1518 "driver (zero supported image formats).\n");
1525 if (!image_formats) {
1530 cle = clGetSupportedImageFormats(hwctx->
context,
1532 CL_MEM_OBJECT_IMAGE2D,
1534 image_formats,
NULL);
1535 if (cle != CL_SUCCESS) {
1537 "image formats: %d.\n", cle);
1544 cl_image_format image_format;
1545 cl_image_desc image_desc;
1548 for (plane = 0;; plane++) {
1555 for (i = 0; i < nb_image_formats; i++) {
1556 if (image_formats[i].image_channel_order ==
1557 image_format.image_channel_order &&
1558 image_formats[i].image_channel_data_type ==
1559 image_format.image_channel_data_type)
1562 if (i == nb_image_formats) {
1610 cle = clReleaseMemObject(desc->
planes[p]);
1611 if (cle != CL_SUCCESS) {
1627 cl_image_format image_format;
1628 cl_image_desc image_desc;
1639 &image_format, &image_desc);
1647 image_desc.image_row_pitch = 0;
1649 image = clCreateImage(hwctx->
context, CL_MEM_READ_WRITE,
1650 &image_format, &image_desc,
NULL, &cle);
1653 "plane %d: %d.\n", p, cle);
1670 for (p = 0; desc->
planes[p]; p++)
1671 clReleaseMemObject(desc->
planes[p]);
1686 if (cle != CL_SUCCESS) {
1688 "command queue: %d.\n", cle);
1713 #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11
1715 for (i = 0; i < priv->nb_mapped_frames; i++) {
1718 cle = clReleaseMemObject(desc->
planes[p]);
1719 if (cle != CL_SUCCESS) {
1721 "frame object (frame %d plane %d): %d.\n",
1730 if (cle != CL_SUCCESS) {
1732 "command queue: %d.\n", cle);
1775 cl_event *events,
int nb_events)
1780 cle = clWaitForEvents(nb_events, events);
1781 if (cle != CL_SUCCESS) {
1783 "completion: %d.\n", cle);
1787 for (i = 0; i < nb_events; i++) {
1788 cle = clReleaseEvent(events[i]);
1789 if (cle != CL_SUCCESS) {
1791 "event: %d.\n", cle);
1802 cl_image_format image_format;
1803 cl_image_desc image_desc;
1805 size_t origin[3] = { 0, 0, 0 };
1816 &image_format, &image_desc);
1823 if (!dst->
data[p]) {
1825 "destination frame for transfer.\n", p);
1830 region[0] = image_desc.image_width;
1831 region[1] = image_desc.image_height;
1835 (cl_mem)src->
data[p],
1836 CL_FALSE, origin, region,
1839 0,
NULL, &events[p]);
1840 if (cle != CL_SUCCESS) {
1842 "OpenCL image plane %d: %d.\n", p, cle);
1857 cl_image_format image_format;
1858 cl_image_desc image_desc;
1860 size_t origin[3] = { 0, 0, 0 };
1871 &image_format, &image_desc);
1878 if (!src->
data[p]) {
1880 "source frame for transfer.\n", p);
1885 region[0] = image_desc.image_width;
1886 region[1] = image_desc.image_height;
1890 (cl_mem)dst->
data[p],
1891 CL_FALSE, origin, region,
1894 0,
NULL, &events[p]);
1895 if (cle != CL_SUCCESS) {
1897 "OpenCL image plane %d: %d.\n", p, cle);
1931 0,
NULL, &events[e]);
1932 if (cle != CL_SUCCESS) {
1934 "image plane %d: %d.\n", p, cle);
1948 cl_map_flags map_flags;
1949 cl_image_format image_format;
1950 cl_image_desc image_desc;
1953 size_t origin[3] = { 0, 0, 0 };
1965 map_flags = CL_MAP_WRITE_INVALIDATE_REGION;
1968 if (flags & AV_HWFRAME_MAP_READ)
1969 map_flags |= CL_MAP_READ;
1971 map_flags |= CL_MAP_WRITE;
1981 &image_format, &image_desc);
1987 region[0] = image_desc.image_width;
1988 region[1] = image_desc.image_height;
1993 (cl_mem)src->
data[p],
1994 CL_FALSE, map_flags, origin, region,
1999 "image plane %d: %d.\n", p, cle);
2029 (cl_mem)src->
data[p],
2031 0,
NULL, &events[p]);
2039 #if HAVE_OPENCL_DRM_BEIGNET
2041 typedef struct DRMBeignetToOpenCLMapping {
2046 } DRMBeignetToOpenCLMapping;
2051 DRMBeignetToOpenCLMapping *mapping = hwmap->
priv;
2055 for (i = 0; i < mapping->frame.nb_planes; i++) {
2056 cle = clReleaseMemObject(mapping->frame.planes[i]);
2057 if (cle != CL_SUCCESS) {
2059 "of plane %d of DRM frame: %d.\n", i, cle);
2072 DRMBeignetToOpenCLMapping *mapping;
2086 for (j = 0; j < layer->
nb_planes; j++) {
2091 cl_import_image_info_intel image_info = {
2093 .size =
object->size,
2094 .type = CL_MEM_OBJECT_IMAGE2D,
2096 .row_pitch = plane->
pitch,
2098 cl_image_desc image_desc;
2106 "plane %d is not representable in OpenCL: %d.\n",
2110 image_info.width = image_desc.image_width;
2111 image_info.height = image_desc.image_height;
2113 mapping->frame.planes[p] =
2114 priv->clCreateImageFromFdINTEL(hwctx->
context,
2116 if (!mapping->frame.planes[p]) {
2118 "from layer %d plane %d of DRM frame: %d.\n",
2124 dst->
data[p] = (
uint8_t*)mapping->frame.planes[p];
2125 mapping->frame.nb_planes = ++p;
2130 &opencl_unmap_from_drm_beignet,
2141 for (p = 0; p < mapping->frame.nb_planes; p++) {
2142 if (mapping->frame.planes[p])
2143 clReleaseMemObject(mapping->frame.planes[p]);
2149 #if HAVE_OPENCL_VAAPI_BEIGNET
2168 err = opencl_map_from_drm_beignet(dst_fc, dst, tmp, flags);
2186 return CL_MEM_READ_WRITE;
2187 else if (map_flags & AV_HWFRAME_MAP_READ)
2188 return CL_MEM_READ_ONLY;
2189 else if (map_flags & AV_HWFRAME_MAP_WRITE)
2190 return CL_MEM_WRITE_ONLY;
2195 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
2209 cle = device_priv->clEnqueueReleaseVA_APIMediaSurfacesINTEL(
2212 if (cle != CL_SUCCESS) {
2214 "handles: %d.\n", cle);
2220 cle = clReleaseMemObject(desc->
planes[p]);
2221 if (cle != CL_SUCCESS) {
2223 "image of plane %d of QSV/VAAPI surface: %d\n",
2232 const AVFrame *src,
int flags)
2240 VASurfaceID va_surface;
2241 cl_mem_flags cl_flags;
2248 mfxFrameSurface1 *mfx_surface = (mfxFrameSurface1*)src->
data[3];
2249 va_surface = *(VASurfaceID*)mfx_surface->Data.MemId;
2253 va_surface = (VASurfaceID)(uintptr_t)src->
data[3];
2263 "OpenCL.\n", va_surface);
2275 device_priv->clCreateFromVA_APIMediaSurfaceINTEL(
2276 dst_dev->context, cl_flags, &va_surface, p, &cle);
2279 "image from plane %d of QSV/VAAPI surface "
2280 "%#x: %d.\n", p, va_surface, cle);
2288 cle = device_priv->clEnqueueAcquireVA_APIMediaSurfacesINTEL(
2291 if (cle != CL_SUCCESS) {
2293 "handles: %d.\n", cle);
2303 &opencl_unmap_from_qsv, desc);
2315 clReleaseMemObject(desc->
planes[p]);
2322 #if HAVE_OPENCL_DXVA2
2335 cle = device_priv->clEnqueueReleaseDX9MediaSurfacesKHR(
2338 if (cle != CL_SUCCESS) {
2340 "handle: %d.\n", cle);
2348 const AVFrame *src,
int flags)
2361 "OpenCL.\n", src->
data[3]);
2363 for (i = 0; i < src_hwctx->nb_surfaces; i++) {
2364 if (src_hwctx->surfaces[i] == (IDirect3DSurface9*)src->
data[3])
2367 if (i >= src_hwctx->nb_surfaces) {
2369 "is not in the mapped frames context.\n");
2373 desc = &frames_priv->mapped_frames[i];
2375 cle = device_priv->clEnqueueAcquireDX9MediaSurfacesKHR(
2378 if (cle != CL_SUCCESS) {
2380 "handle: %d.\n", cle);
2392 &opencl_unmap_from_dxva2, desc);
2402 cle = device_priv->clEnqueueReleaseDX9MediaSurfacesKHR(
2405 if (cle == CL_SUCCESS)
2417 cl_mem_flags cl_flags;
2419 int err, i, p, nb_planes;
2423 "for DXVA2 to OpenCL mapping.\n");
2430 "for DXVA2 to OpenCL mapping.\n");
2438 frames_priv->nb_mapped_frames = src_hwctx->
nb_surfaces;
2440 frames_priv->mapped_frames =
2442 sizeof(*frames_priv->mapped_frames));
2443 if (!frames_priv->mapped_frames)
2446 for (i = 0; i < frames_priv->nb_mapped_frames; i++) {
2448 cl_dx9_surface_info_khr surface_info = {
2449 .resource = src_hwctx->
surfaces[i],
2450 .shared_handle =
NULL,
2453 for (p = 0; p < nb_planes; p++) {
2455 device_priv->clCreateFromDX9MediaSurfaceKHR(
2457 device_priv->dx9_media_adapter_type,
2458 &surface_info, p, &cle);
2461 "image from plane %d of DXVA2 surface %d: %d.\n",
2472 for (i = 0; i < frames_priv->nb_mapped_frames; i++) {
2476 clReleaseMemObject(desc->
planes[p]);
2479 av_freep(&frames_priv->mapped_frames);
2480 frames_priv->nb_mapped_frames = 0;
2486 #if HAVE_OPENCL_D3D11
2497 cle = device_priv->clEnqueueReleaseD3D11ObjectsKHR(
2500 if (cle != CL_SUCCESS) {
2502 "handle: %d.\n", cle);
2509 const AVFrame *src,
int flags)
2518 index = (intptr_t)src->
data[1];
2519 if (index >= frames_priv->nb_mapped_frames) {
2521 "mapping: %d >= %d.\n", index, frames_priv->nb_mapped_frames);
2528 desc = &frames_priv->mapped_frames[
index];
2530 cle = device_priv->clEnqueueAcquireD3D11ObjectsKHR(
2533 if (cle != CL_SUCCESS) {
2535 "handle: %d.\n", cle);
2547 &opencl_unmap_from_d3d11, desc);
2557 cle = device_priv->clEnqueueReleaseD3D11ObjectsKHR(
2560 if (cle == CL_SUCCESS)
2572 cl_mem_flags cl_flags;
2574 int err, i, p, nb_planes;
2578 "for D3D11 to OpenCL mapping.\n");
2585 "for D3D11 to OpenCL mapping.\n");
2595 frames_priv->mapped_frames =
2597 sizeof(*frames_priv->mapped_frames));
2598 if (!frames_priv->mapped_frames)
2601 for (i = 0; i < frames_priv->nb_mapped_frames; i++) {
2604 for (p = 0; p < nb_planes; p++) {
2605 UINT subresource = 2 * i + p;
2608 device_priv->clCreateFromD3D11Texture2DKHR(
2613 "image from plane %d of D3D texture "
2614 "index %d (subresource %u): %d.\n",
2615 p, i, (
unsigned int)subresource, cle);
2625 for (i = 0; i < frames_priv->nb_mapped_frames; i++) {
2629 clReleaseMemObject(desc->
planes[p]);
2632 av_freep(&frames_priv->mapped_frames);
2633 frames_priv->nb_mapped_frames = 0;
2639 #if HAVE_OPENCL_DRM_ARM
2641 typedef struct DRMARMtoOpenCLMapping {
2646 } DRMARMtoOpenCLMapping;
2651 DRMARMtoOpenCLMapping *mapping = hwmap->
priv;
2654 for (i = 0; i < mapping->nb_planes; i++)
2655 clReleaseMemObject(mapping->plane_images[i]);
2657 for (i = 0; i < mapping->nb_objects; i++)
2658 clReleaseMemObject(mapping->object_buffers[i]);
2664 const AVFrame *src,
int flags)
2670 DRMARMtoOpenCLMapping *mapping =
NULL;
2671 cl_mem_flags cl_flags;
2672 const cl_import_properties_arm props[3] = {
2673 CL_IMPORT_TYPE_ARM, CL_IMPORT_TYPE_DMA_BUF_ARM, 0,
2688 mapping->nb_objects = desc->nb_objects;
2689 for (i = 0; i < desc->nb_objects; i++) {
2690 int fd = desc->objects[i].fd;
2694 if (desc->objects[i].format_modifier) {
2696 "nonzero format modifier %"PRId64
", result may not "
2697 "be as expected.\n", i, fd,
2698 desc->objects[i].format_modifier);
2701 mapping->object_buffers[i] =
2702 clImportMemoryARM(dst_dev->
context, cl_flags, props,
2703 &fd, desc->objects[i].size, &cle);
2704 if (!mapping->object_buffers[i]) {
2706 "from object %d (fd %d, size %"SIZE_SPECIFIER") of DRM frame: %d.\n",
2707 i, fd, desc->objects[i].size, cle);
2713 mapping->nb_planes = 0;
2714 for (i = 0; i < desc->nb_layers; i++) {
2717 for (j = 0; j < layer->
nb_planes; j++) {
2719 cl_mem plane_buffer;
2720 cl_image_format image_format;
2721 cl_image_desc image_desc;
2722 cl_buffer_region region;
2723 int p = mapping->nb_planes;
2727 &image_format, &image_desc);
2730 "layer %d plane %d): %d.\n", p, i, j, err);
2734 region.origin = plane->
offset;
2735 region.size = image_desc.image_row_pitch *
2736 image_desc.image_height;
2739 clCreateSubBuffer(mapping->object_buffers[plane->
object_index],
2741 CL_BUFFER_CREATE_TYPE_REGION,
2743 if (!plane_buffer) {
2745 "for plane %d: %d.\n", p, cle);
2750 image_desc.buffer = plane_buffer;
2752 mapping->plane_images[p] =
2753 clCreateImage(dst_dev->
context, cl_flags,
2754 &image_format, &image_desc,
NULL, &cle);
2758 clReleaseMemObject(plane_buffer);
2760 if (!mapping->plane_images[p]) {
2762 "for plane %d: %d.\n", p, cle);
2767 ++mapping->nb_planes;
2771 for (i = 0; i < mapping->nb_planes; i++)
2772 dst->
data[i] = (
uint8_t*)mapping->plane_images[i];
2775 &opencl_unmap_from_drm_arm, mapping);
2785 for (i = 0; i < mapping->nb_planes; i++) {
2786 clReleaseMemObject(mapping->plane_images[i]);
2788 for (i = 0; i < mapping->nb_objects; i++) {
2789 if (mapping->object_buffers[i])
2790 clReleaseMemObject(mapping->object_buffers[i]);
2799 const AVFrame *src,
int flags)
2808 const AVFrame *src,
int flags)
2813 #if HAVE_OPENCL_DRM_BEIGNET
2815 if (priv->beignet_drm_mapping_usable)
2816 return opencl_map_from_drm_beignet(hwfc, dst, src, flags);
2818 #if HAVE_OPENCL_VAAPI_BEIGNET
2820 if (priv->beignet_drm_mapping_usable)
2821 return opencl_map_from_vaapi(hwfc, dst, src, flags);
2823 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
2826 if (priv->qsv_mapping_usable)
2827 return opencl_map_from_qsv(hwfc, dst, src, flags);
2829 #if HAVE_OPENCL_DXVA2
2831 if (priv->dxva2_mapping_usable)
2832 return opencl_map_from_dxva2(hwfc, dst, src, flags);
2834 #if HAVE_OPENCL_D3D11
2836 if (priv->d3d11_mapping_usable)
2837 return opencl_map_from_d3d11(hwfc, dst, src, flags);
2839 #if HAVE_OPENCL_DRM_ARM
2841 if (priv->drm_arm_mapping_usable)
2842 return opencl_map_from_drm_arm(hwfc, dst, src, flags);
2853 #if HAVE_OPENCL_DRM_BEIGNET
2855 if (!priv->beignet_drm_mapping_usable)
2859 #if HAVE_OPENCL_VAAPI_BEIGNET
2861 if (!priv->beignet_drm_mapping_usable)
2865 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
2868 if (!priv->qsv_mapping_usable)
2872 #if HAVE_OPENCL_DXVA2
2874 if (!priv->dxva2_mapping_usable)
2878 err = opencl_frames_derive_from_dxva2(dst_fc, src_fc, flags);
2884 #if HAVE_OPENCL_D3D11
2886 if (!priv->d3d11_mapping_usable)
2890 err = opencl_frames_derive_from_d3d11(dst_fc, src_fc, flags);
2896 #if HAVE_OPENCL_DRM_ARM
2898 if (!priv->drm_arm_mapping_usable)
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
API-specific header for AV_HWDEVICE_TYPE_OPENCL.
static void opencl_device_free(AVHWDeviceContext *hwdev)
static void CL_CALLBACK opencl_error_callback(const char *errinfo, const void *private_info, size_t cb, void *user_data)
int plane
Which of the 4 planes contains the component.
static enum AVPixelFormat pix_fmt
#define AV_NUM_DATA_POINTERS
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
cl_command_queue command_queue
ptrdiff_t const GLvoid * data
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
This struct is allocated as AVHWFramesContext.hwctx.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int opencl_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Memory handling functions.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle...
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
int width
The allocated dimensions of the frames in this pool.
static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc)
void * address[AV_NUM_DATA_POINTERS]
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static int opencl_map_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
static int opencl_check_device_extension(cl_device_id device_id, const char *name)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
int max_width
The maximum size of frames in this hw_frames_ctx.
static void opencl_unmap_frame(AVHWFramesContext *hwfc, HWMapDescriptor *hwmap)
int(* filter_platform)(AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, void *context)
static int opencl_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
int(* enumerate_platforms)(AVHWDeviceContext *hwdev, cl_uint *nb_platforms, cl_platform_id **platforms, void *context)
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
static int opencl_map_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
static int opencl_enumerate_devices(AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, cl_uint *nb_devices, cl_device_id **devices, void *context)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVBufferPool * pool_internal
static double cb(void *priv, double x, double y)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
static int opencl_frames_init(AVHWFramesContext *hwfc)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
OpenCL frame descriptor for pool allocation.
cl_device_id device_id
The primary device ID of the device.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
ID3D11Device * device
Device used for texture creation and access.
AVDRMLayerDescriptor layers[AV_DRM_MAX_PLANES]
Array of layers in the frame.
#define AV_LOG_VERBOSE
Detailed information.
cl_platform_id platform_id
int fd
DRM PRIME fd for the object.
int nb_layers
Number of layers in the frame.
static int opencl_wait_events(AVHWFramesContext *hwfc, cl_event *events, int nb_events)
int object_index
Index of the object containing this plane in the objects array of the enclosing frame descriptor...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static cl_mem_flags opencl_mem_flags_for_mapping(int map_flags)
ptrdiff_t pitch
Pitch (linesize) of this plane.
AVS_Value void * user_data
static int opencl_device_create(AVHWDeviceContext *hwdev, const char *device, AVDictionary *opts, int flags)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
static int opencl_filter_platform(AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, void *context)
enum AVHWDeviceType device_type
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
simple assert() macros that are a bit more flexible than ISO C assert().
static int opencl_get_plane_format(enum AVPixelFormat pixfmt, int plane, int width, int height, cl_image_format *image_format, cl_image_desc *image_desc)
cl_command_queue command_queue
The command queue used for internal asynchronous operations on this device (av_hwframe_transfer_data(...
int nb_planes
Number of planes in the layer.
IDirect3DDeviceManager9 * devmgr
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
static int opencl_device_create_internal(AVHWDeviceContext *hwdev, const OpenCLDeviceSelector *selector, cl_context_properties *props)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
static void opencl_pool_free(void *opaque, uint8_t *data)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
int initial_pool_size
Initial size of the frame pool.
uint8_t nb_components
The number of components each pixel has, (1-4)
#define CHANNEL_ORDER(order, type)
AVFrame * source
A reference to the original source of the mapping.
static struct @287 opencl_device_types[]
static int opencl_frames_derive_to(AVHWFramesContext *dst_fc, AVHWFramesContext *src_fc, int flags)
AVDRMPlaneDescriptor planes[AV_DRM_MAX_PLANES]
Array of planes in this layer.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
static char * opencl_get_platform_string(cl_platform_id platform_id, cl_platform_info key)
static int opencl_transfer_get_formats(AVHWFramesContext *hwfc, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
int nb_planes
Number of planes in the frame.
Hardware surfaces for OpenCL.
AVDRMObjectDescriptor objects[AV_DRM_MAX_PLANES]
Array of objects making up the frame.
The mapping must be writeable.
AVBufferPool * av_buffer_pool_init2(int size, void *opaque, AVBufferRef *(*alloc)(void *opaque, int size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
#define FF_ARRAY_ELEMS(a)
int(* filter_device)(AVHWDeviceContext *hwdev, cl_device_id device_id, const char *device_name, void *context)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
VADisplay display
The VADisplay handle, to be filled by the user.
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
int(* enumerate_devices)(AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, cl_uint *nb_devices, cl_device_id **devices, void *context)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
The mapping must be readable.
void * priv
Hardware-specific private data associated with the mapping.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const int16_t alpha[]
uint8_t * data
The data buffer.
int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src)
Replace the current hwmap of dst with the one from src, used for indirect mappings like VAAPI->(DRM)-...
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
ID3D11Texture2D * texture
The canonical texture used for pool allocation.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
const HWContextType ff_hwcontext_type_opencl
static av_unused int opencl_check_extension(AVHWDeviceContext *hwdev, const char *name)
OpenCL-specific data associated with a frame pool.
DRM-managed buffers exposed through PRIME buffer sharing.
This struct describes a set or pool of "hardware" frames (i.e.
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
The maximum number of layers/planes in a DRM frame.
static struct @286 opencl_device_params[]
static int opencl_get_buffer(AVHWFramesContext *hwfc, AVFrame *frame)
const VDPAUPixFmtMap * map
static int opencl_map_frame(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
API-specific header for AV_HWDEVICE_TYPE_DRM.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
int shift
Number of least significant bits that must be shifted away to get the value.
AVHWFramesInternal * internal
Private data used internally by libavutil.
This struct is allocated as AVHWFramesContext.hwctx.
#define flags(name, subs,...)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
cl_command_queue command_queue
Hardware surfaces for Direct3D11.
static AVBufferRef * opencl_pool_alloc(void *opaque, int size)
A reference to a data buffer.
static int opencl_filter_device(AVHWDeviceContext *hwdev, cl_device_id device_id, const char *device_name, void *context)
static int opencl_check_platform_extension(cl_platform_id platform_id, const char *name)
common internal and external API header
static int ref[MAX_W *MAX_W]
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
Map a hardware frame.
static int opencl_frames_get_constraints(AVHWDeviceContext *hwdev, const void *hwconfig, AVHWFramesConstraints *constraints)
cl_mem planes[AV_NUM_DATA_POINTERS]
OpenCL image2d objects for each plane of the frame.
cl_command_queue command_queue
The default command queue for this device, which will be used by all frames contexts which do not hav...
static void opencl_frames_uninit(AVHWFramesContext *hwfc)
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
IDirect3DSurface9 ** surfaces
The surface pool.
static void opencl_device_uninit(AVHWDeviceContext *hwdev)
AVHWFrameTransferDirection
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
This struct is allocated as AVHWDeviceContext.hwctx.
static int opencl_enumerate_platforms(AVHWDeviceContext *hwdev, cl_uint *nb_platforms, cl_platform_id **platforms, void *context)
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
static int opencl_device_derive(AVHWDeviceContext *hwdev, AVHWDeviceContext *src_ctx, int flags)
ptrdiff_t offset
Offset within that object of this plane.
cl_context context
The OpenCL context which will contain all operations and frames on this device.
enum AVPixelFormat pixfmt
VAAPI connection details.
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
This struct is allocated as AVHWDeviceContext.hwctx.
static int opencl_device_init(AVHWDeviceContext *hwdev)
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
#define av_malloc_array(a, b)
static struct @285 opencl_platform_params[]
AVHWDeviceInternal * internal
Private data used internally by libavutil.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
int depth
Number of bits in the component.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
#define CL_FUNC(name, desc)
int step
Number of elements between 2 horizontally consecutive pixels.
static char * opencl_get_device_string(cl_device_id device_id, cl_device_info key)
void * av_mallocz_array(size_t nmemb, size_t size)