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 49 #include <mfx/mfxstructures.h> 51 #include <CL/va_ext.h> 57 #include <CL/cl_dx9_media_sharing.h> 63 #include <CL/cl_d3d11.h> 67 #if HAVE_OPENCL_DRM_ARM 68 #include <CL/cl_ext.h> 69 #include <drm_fourcc.h> 85 #if HAVE_OPENCL_DRM_BEIGNET 86 int beignet_drm_mapping_usable;
87 clCreateImageFromFdINTEL_fn clCreateImageFromFdINTEL;
90 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA 91 int qsv_mapping_usable;
92 clCreateFromVA_APIMediaSurfaceINTEL_fn
93 clCreateFromVA_APIMediaSurfaceINTEL;
94 clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn
95 clEnqueueAcquireVA_APIMediaSurfacesINTEL;
96 clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn
97 clEnqueueReleaseVA_APIMediaSurfacesINTEL;
100 #if HAVE_OPENCL_DXVA2 101 int dxva2_mapping_usable;
102 cl_dx9_media_adapter_type_khr dx9_media_adapter_type;
104 clCreateFromDX9MediaSurfaceKHR_fn
105 clCreateFromDX9MediaSurfaceKHR;
106 clEnqueueAcquireDX9MediaSurfacesKHR_fn
107 clEnqueueAcquireDX9MediaSurfacesKHR;
108 clEnqueueReleaseDX9MediaSurfacesKHR_fn
109 clEnqueueReleaseDX9MediaSurfacesKHR;
112 #if HAVE_OPENCL_D3D11 113 int d3d11_mapping_usable;
114 clCreateFromD3D11Texture2DKHR_fn
115 clCreateFromD3D11Texture2DKHR;
116 clEnqueueAcquireD3D11ObjectsKHR_fn
117 clEnqueueAcquireD3D11ObjectsKHR;
118 clEnqueueReleaseD3D11ObjectsKHR_fn
119 clEnqueueReleaseD3D11ObjectsKHR;
122 #if HAVE_OPENCL_DRM_ARM 123 int drm_arm_mapping_usable;
134 #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11 138 int nb_mapped_frames;
145 const void *private_info,
size_t cb,
157 cle = clReleaseContext(hwctx->
context);
158 if (cle != CL_SUCCESS) {
160 "context: %d.\n", cle);
168 {
"platform_profile", CL_PLATFORM_PROFILE },
169 {
"platform_version", CL_PLATFORM_VERSION },
170 {
"platform_name", CL_PLATFORM_NAME },
171 {
"platform_vendor", CL_PLATFORM_VENDOR },
172 {
"platform_extensions", CL_PLATFORM_EXTENSIONS },
179 {
"device_name", CL_DEVICE_NAME },
180 {
"device_vendor", CL_DEVICE_VENDOR },
181 {
"driver_version", CL_DRIVER_VERSION },
182 {
"device_version", CL_DEVICE_VERSION },
183 {
"device_profile", CL_DEVICE_PROFILE },
184 {
"device_extensions", CL_DEVICE_EXTENSIONS },
191 {
"cpu", CL_DEVICE_TYPE_CPU },
192 {
"gpu", CL_DEVICE_TYPE_GPU },
193 {
"accelerator", CL_DEVICE_TYPE_ACCELERATOR },
194 {
"custom", CL_DEVICE_TYPE_CUSTOM },
195 {
"default", CL_DEVICE_TYPE_DEFAULT },
196 {
"all", CL_DEVICE_TYPE_ALL },
200 cl_platform_info
key)
205 cle = clGetPlatformInfo(platform_id, key, 0,
NULL, &size);
206 if (cle != CL_SUCCESS)
211 cle = clGetPlatformInfo(platform_id, key, size, str, &size);
212 if (cle != CL_SUCCESS) {
226 cle = clGetDeviceInfo(device_id, key, 0,
NULL, &size);
227 if (cle != CL_SUCCESS)
232 cle = clGetDeviceInfo(device_id, key, size, str, &size);
233 if (cle != CL_SUCCESS) {
247 CL_PLATFORM_EXTENSIONS);
248 if (str && strstr(str, name))
260 CL_DEVICE_EXTENSIONS);
261 if (str && strstr(str, name))
275 "%s found as platform extension.\n", name);
281 "%s found as device extension.\n", name);
289 cl_uint *nb_platforms,
290 cl_platform_id **platforms,
295 cle = clGetPlatformIDs(0,
NULL, nb_platforms);
296 if (cle != CL_SUCCESS) {
298 "OpenCL platforms: %d.\n", cle);
308 cle = clGetPlatformIDs(*nb_platforms, *platforms,
NULL);
309 if (cle != CL_SUCCESS) {
311 "platforms: %d.\n", cle);
321 const char *platform_name,
339 "of platform \"%s\".\n",
356 const char *platform_name,
358 cl_device_id **devices,
363 cle = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL,
364 0,
NULL, nb_devices);
365 if (cle == CL_DEVICE_NOT_FOUND) {
367 "on platform \"%s\".\n", platform_name);
370 }
else if (cle != CL_SUCCESS) {
372 "on platform \"%s\": %d.\n", platform_name, cle);
376 "platform \"%s\".\n", *nb_devices, platform_name);
382 cle = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL,
383 *nb_devices, *devices,
NULL);
384 if (cle != CL_SUCCESS) {
386 "on platform \"%s\": %d.\n", platform_name, cle);
395 cl_device_id device_id,
396 const char *device_name,
421 cle = clGetDeviceInfo(device_id, CL_DEVICE_TYPE,
423 if (cle != CL_SUCCESS) {
425 "of device \"%s\".\n", device_name);
445 "of device \"%s\".\n",
465 cl_uint *nb_platforms,
466 cl_platform_id **platforms,
470 const char *platform_name,
474 const char *platform_name,
476 cl_device_id **devices,
479 cl_device_id device_id,
480 const char *device_name,
486 cl_context_properties *props)
488 cl_uint nb_platforms;
489 cl_platform_id *platforms =
NULL;
492 cl_device_id *devices =
NULL;
495 cl_context_properties default_props[3];
496 char *platform_name_src =
NULL,
497 *device_name_src =
NULL;
498 int err, found, p, d;
506 for (p = 0; p < nb_platforms; p++) {
507 const char *platform_name;
516 if (platform_name_src)
517 platform_name = platform_name_src;
519 platform_name =
"Unknown Platform";
532 &nb_devices, &devices,
537 for (d = 0; d < nb_devices; d++) {
538 const char *device_name;
548 device_name = device_name_src;
550 device_name =
"Unknown Device";
563 platform_name, device_name);
566 platform_id = platforms[p];
585 props = default_props;
586 default_props[0] = CL_CONTEXT_PLATFORM;
587 default_props[1] = (intptr_t)platform_id;
588 default_props[2] = 0;
590 if (props[0] == CL_CONTEXT_PLATFORM && props[1] == 0)
591 props[1] = (intptr_t)platform_id;
625 if (device && device[0]) {
627 int d = -1, p = -1, ret;
628 if (device[0] ==
'.')
629 ret = sscanf(device,
".%d", &d);
631 ret = sscanf(device,
"%d.%d", &p, &d);
634 "index specification \"%s\".\n", device);
655 if (cle != CL_SUCCESS) {
657 "command queue: %d.\n", cle);
667 "command queue: %d.\n", cle);
672 cle = clGetDeviceInfo(hwctx->
device_id, CL_DEVICE_PLATFORM,
675 if (cle != CL_SUCCESS) {
677 "platform containing the device.\n");
681 #define CL_FUNC(name, desc) do { \ 684 priv->name = clGetExtensionFunctionAddressForPlatform( \ 685 priv->platform_id, #name); \ 687 av_log(hwdev, AV_LOG_VERBOSE, \ 688 desc " function not found (%s).\n", #name); \ 691 av_log(hwdev, AV_LOG_VERBOSE, \ 692 desc " function found (%s).\n", #name); \ 696 #if HAVE_OPENCL_DRM_BEIGNET 700 CL_FUNC(clCreateImageFromFdINTEL,
701 "Beignet DRM to OpenCL image mapping");
705 "mapping not usable.\n");
706 priv->beignet_drm_mapping_usable = 0;
708 priv->beignet_drm_mapping_usable = 1;
713 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA 716 cl_context_properties *props =
NULL;
717 VADisplay va_display;
718 const char *va_ext =
"cl_intel_va_api_media_sharing";
723 "required for QSV to OpenCL mapping.\n", va_ext);
727 cle = clGetContextInfo(hwctx->
context, CL_CONTEXT_PROPERTIES,
728 0,
NULL, &props_size);
729 if (cle != CL_SUCCESS) {
731 "properties: %d.\n", cle);
734 if (props_size == 0) {
736 "enabled on context creation to use QSV to " 737 "OpenCL mapping.\n");
745 cle = clGetContextInfo(hwctx->
context, CL_CONTEXT_PROPERTIES,
746 props_size, props,
NULL);
747 if (cle != CL_SUCCESS) {
749 "properties: %d.\n", cle);
754 for (i = 0; i < (props_size /
sizeof(*props) - 1); i++) {
755 if (props[i] == CL_CONTEXT_VA_API_DISPLAY_INTEL) {
756 va_display = (VADisplay)(intptr_t)props[i+1];
762 "enabled on context creation to use QSV to " 763 "OpenCL mapping.\n");
766 if (!vaDisplayIsValid(va_display)) {
768 "required on context creation to use QSV to " 769 "OpenCL mapping.\n");
773 CL_FUNC(clCreateFromVA_APIMediaSurfaceINTEL,
774 "Intel QSV to OpenCL mapping");
775 CL_FUNC(clEnqueueAcquireVA_APIMediaSurfacesINTEL,
776 "Intel QSV in OpenCL acquire");
777 CL_FUNC(clEnqueueReleaseVA_APIMediaSurfacesINTEL,
778 "Intel QSV in OpenCL release");
784 priv->qsv_mapping_usable = 0;
786 priv->qsv_mapping_usable = 1;
792 #if HAVE_OPENCL_DXVA2 796 CL_FUNC(clCreateFromDX9MediaSurfaceKHR,
797 "DXVA2 to OpenCL mapping");
798 CL_FUNC(clEnqueueAcquireDX9MediaSurfacesKHR,
799 "DXVA2 in OpenCL acquire");
800 CL_FUNC(clEnqueueReleaseDX9MediaSurfacesKHR,
801 "DXVA2 in OpenCL release");
806 priv->dxva2_mapping_usable = 0;
808 priv->dx9_media_adapter_type = CL_ADAPTER_D3D9EX_KHR;
809 priv->dxva2_mapping_usable = 1;
814 #if HAVE_OPENCL_D3D11 816 const char *d3d11_ext =
"cl_khr_d3d11_sharing";
817 const char *nv12_ext =
"cl_intel_d3d11_nv12_media_sharing";
822 "required for D3D11 to OpenCL mapping.\n", d3d11_ext);
826 "required for D3D11 to OpenCL mapping.\n", nv12_ext);
830 CL_FUNC(clCreateFromD3D11Texture2DKHR,
831 "D3D11 to OpenCL mapping");
832 CL_FUNC(clEnqueueAcquireD3D11ObjectsKHR,
833 "D3D11 in OpenCL acquire");
834 CL_FUNC(clEnqueueReleaseD3D11ObjectsKHR,
835 "D3D11 in OpenCL release");
840 priv->d3d11_mapping_usable = 0;
842 priv->d3d11_mapping_usable = 1;
847 #if HAVE_OPENCL_DRM_ARM 849 const char *drm_arm_ext =
"cl_arm_import_memory";
850 const char *image_ext =
"cl_khr_image2d_from_buffer";
855 "required for DRM to OpenCL mapping on ARM.\n",
861 "required for DRM to OpenCL mapping on ARM.\n",
871 priv->drm_arm_mapping_usable = 0;
873 priv->drm_arm_mapping_usable = 1;
890 if (cle != CL_SUCCESS) {
892 "command queue reference: %d.\n", cle);
898 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA 901 const char *platform_name,
907 if (!clGetExtensionFunctionAddressForPlatform(
platform_id,
908 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL")) {
910 "VAAPI device enumeration function.\n", platform_name);
919 const char *platform_name,
921 cl_device_id **devices,
924 VADisplay va_display = context;
925 clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn
926 clGetDeviceIDsFromVA_APIMediaAdapterINTEL;
930 clGetDeviceIDsFromVA_APIMediaAdapterINTEL =
931 clGetExtensionFunctionAddressForPlatform(
platform_id,
932 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL");
933 if (!clGetDeviceIDsFromVA_APIMediaAdapterINTEL) {
935 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL().\n");
939 cle = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(
941 CL_PREFERRED_DEVICES_FOR_VA_API_INTEL, 0,
NULL, nb_devices);
942 if (cle == CL_DEVICE_NOT_FOUND) {
944 "on platform \"%s\".\n", platform_name);
947 }
else if (cle != CL_SUCCESS) {
949 "on platform \"%s\": %d.\n", platform_name, cle);
957 cle = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(
959 CL_PREFERRED_DEVICES_FOR_VA_API_INTEL, *nb_devices, *devices,
NULL);
960 if (cle != CL_SUCCESS) {
962 "devices on platform \"%s\": %d.\n", platform_name, cle);
971 cl_device_id device_id,
972 const char *device_name,
975 const char *va_ext =
"cl_intel_va_api_media_sharing";
981 "%s extension.\n", device_name, va_ext);
987 #if HAVE_OPENCL_DXVA2 990 const char *platform_name,
993 const char *dx9_ext =
"cl_khr_dx9_media_sharing";
999 "%s extension.\n", platform_name, dx9_ext);
1006 const char *platform_name,
1007 cl_uint *nb_devices,
1008 cl_device_id **devices,
1011 IDirect3DDevice9 *device = context;
1012 clGetDeviceIDsFromDX9MediaAdapterKHR_fn
1013 clGetDeviceIDsFromDX9MediaAdapterKHR;
1014 cl_dx9_media_adapter_type_khr media_adapter_type = CL_ADAPTER_D3D9EX_KHR;
1017 clGetDeviceIDsFromDX9MediaAdapterKHR =
1018 clGetExtensionFunctionAddressForPlatform(
platform_id,
1019 "clGetDeviceIDsFromDX9MediaAdapterKHR");
1020 if (!clGetDeviceIDsFromDX9MediaAdapterKHR) {
1022 "clGetDeviceIDsFromDX9MediaAdapterKHR().\n");
1026 cle = clGetDeviceIDsFromDX9MediaAdapterKHR(
1027 platform_id, 1, &media_adapter_type, (
void**)&device,
1028 CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR,
1029 0,
NULL, nb_devices);
1030 if (cle == CL_DEVICE_NOT_FOUND) {
1032 "on platform \"%s\".\n", platform_name);
1035 }
else if (cle != CL_SUCCESS) {
1037 "on platform \"%s\": %d.\n", platform_name, cle);
1045 cle = clGetDeviceIDsFromDX9MediaAdapterKHR(
1046 platform_id, 1, &media_adapter_type, (
void**)&device,
1047 CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR,
1048 *nb_devices, *devices,
NULL);
1049 if (cle != CL_SUCCESS) {
1051 "devices on platform \"%s\": %d.\n", platform_name, cle);
1060 #if HAVE_OPENCL_D3D11 1063 const char *platform_name,
1066 const char *d3d11_ext =
"cl_khr_d3d11_sharing";
1072 "%s extension.\n", platform_name, d3d11_ext);
1079 const char *platform_name,
1080 cl_uint *nb_devices,
1081 cl_device_id **devices,
1085 clGetDeviceIDsFromD3D11KHR_fn clGetDeviceIDsFromD3D11KHR;
1088 clGetDeviceIDsFromD3D11KHR =
1089 clGetExtensionFunctionAddressForPlatform(
platform_id,
1090 "clGetDeviceIDsFromD3D11KHR");
1091 if (!clGetDeviceIDsFromD3D11KHR) {
1093 "clGetDeviceIDsFromD3D11KHR().\n");
1098 CL_D3D11_DEVICE_KHR, device,
1099 CL_PREFERRED_DEVICES_FOR_D3D11_KHR,
1100 0,
NULL, nb_devices);
1101 if (cle == CL_DEVICE_NOT_FOUND) {
1103 "on platform \"%s\".\n", platform_name);
1106 }
else if (cle != CL_SUCCESS) {
1108 "on platform \"%s\": %d.\n", platform_name, cle);
1117 CL_D3D11_DEVICE_KHR, device,
1118 CL_PREFERRED_DEVICES_FOR_D3D11_KHR,
1119 *nb_devices, *devices,
NULL);
1120 if (cle != CL_SUCCESS) {
1122 "devices on platform \"%s\": %d.\n", platform_name, cle);
1131 #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11 1133 cl_device_id device_id,
1134 const char *device_name,
1140 cle = clGetDeviceInfo(device_id, CL_DEVICE_TYPE,
1141 sizeof(device_type), &device_type,
NULL);
1142 if (cle != CL_SUCCESS) {
1144 "of device \"%s\".\n", device_name);
1147 if (!(device_type & CL_DEVICE_TYPE_GPU)) {
1157 #if HAVE_OPENCL_DRM_ARM 1160 const char *platform_name,
1163 const char *drm_arm_ext =
"cl_arm_import_memory";
1169 "%s extension.\n", platform_name, drm_arm_ext);
1175 cl_device_id device_id,
1176 const char *device_name,
1179 const char *drm_arm_ext =
"cl_arm_import_memory";
1185 "%s extension.\n", device_name, drm_arm_ext);
1196 switch (src_ctx->
type) {
1198 #if HAVE_OPENCL_DRM_BEIGNET 1207 err =
av_dict_set(&opts,
"platform_vendor",
"Intel", 0);
1209 err =
av_dict_set(&opts,
"platform_version",
"beignet", 0);
1218 .filter_device =
NULL,
1227 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA 1234 cl_context_properties props[7] = {
1235 CL_CONTEXT_PLATFORM,
1237 CL_CONTEXT_VA_API_DISPLAY_INTEL,
1239 CL_CONTEXT_INTEROP_USER_SYNC,
1246 .context = src_hwctx->
display,
1248 .filter_platform = &opencl_filter_intel_media_vaapi_platform,
1249 .enumerate_devices = &opencl_enumerate_intel_media_vaapi_devices,
1250 .filter_device = &opencl_filter_intel_media_vaapi_device,
1258 #if HAVE_OPENCL_DXVA2 1262 IDirect3DDevice9 *device;
1266 hr = IDirect3DDeviceManager9_OpenDeviceHandle(src_hwctx->
devmgr,
1270 "for Direct3D9 device: %lx.\n", (
unsigned long)hr);
1275 hr = IDirect3DDeviceManager9_LockDevice(src_hwctx->
devmgr,
1279 cl_context_properties props[5] = {
1280 CL_CONTEXT_PLATFORM,
1282 CL_CONTEXT_ADAPTER_D3D9EX_KHR,
1291 .filter_platform = &opencl_filter_dxva2_platform,
1292 .enumerate_devices = &opencl_enumerate_dxva2_devices,
1293 .filter_device = &opencl_filter_gpu_device,
1298 IDirect3DDeviceManager9_UnlockDevice(src_hwctx->
devmgr,
1299 device_handle,
FALSE);
1302 "for Direct3D9 device: %lx.\n", (
unsigned long)hr);
1306 IDirect3DDeviceManager9_CloseDeviceHandle(src_hwctx->
devmgr,
1312 #if HAVE_OPENCL_D3D11 1316 cl_context_properties props[5] = {
1317 CL_CONTEXT_PLATFORM,
1319 CL_CONTEXT_D3D11_DEVICE_KHR,
1320 (intptr_t)src_hwctx->
device,
1326 .context = src_hwctx->
device,
1328 .filter_platform = &opencl_filter_d3d11_platform,
1329 .enumerate_devices = &opencl_enumerate_d3d11_devices,
1330 .filter_device = &opencl_filter_gpu_device,
1338 #if HAVE_OPENCL_DRM_ARM 1346 .filter_platform = &opencl_filter_drm_arm_platform,
1348 .filter_device = &opencl_filter_drm_arm_device,
1369 cl_image_format *image_format,
1370 cl_image_desc *image_desc)
1374 int channels = 0, order = 0, depth = 0, step = 0;
1375 int wsub, hsub,
alpha;
1392 if (width & wsub - 1 || height & hsub - 1)
1396 comp = &desc->
comp[
c];
1397 if (comp->
plane != plane)
1400 if (comp->
step != 1 && comp->
step != 2 &&
1401 comp->
step != 4 && comp->
step != 8)
1409 if (depth && comp->
depth != depth)
1413 if (comp->
depth > 8 &&
1418 if (step && comp->
step != step)
1420 order = order * 10 + c + 1;
1421 depth = comp->
depth;
1430 memset(image_format, 0,
sizeof(*image_format));
1431 memset(image_desc, 0,
sizeof(*image_desc));
1432 image_desc->image_type = CL_MEM_OBJECT_IMAGE2D;
1434 if (plane == 0 || alpha) {
1435 image_desc->image_width =
width;
1436 image_desc->image_height =
height;
1437 image_desc->image_row_pitch = step *
width;
1439 image_desc->image_width = width / wsub;
1440 image_desc->image_height = height / hsub;
1441 image_desc->image_row_pitch = step * width / wsub;
1445 image_format->image_channel_data_type = CL_UNORM_INT8;
1448 image_format->image_channel_data_type = CL_UNORM_INT16;
1453 #define CHANNEL_ORDER(order, type) \ 1454 case order: image_format->image_channel_order = type; break; 1471 #undef CHANNEL_ORDER 1477 const void *hwconfig,
1481 cl_uint nb_image_formats;
1482 cl_image_format *image_formats =
NULL;
1485 int err, pix_fmts_found;
1486 size_t max_width, max_height;
1488 cle = clGetDeviceInfo(hwctx->
device_id, CL_DEVICE_IMAGE2D_MAX_WIDTH,
1489 sizeof(max_width), &max_width,
NULL);
1490 if (cle != CL_SUCCESS) {
1492 "supported image width: %d.\n", cle);
1496 cle = clGetDeviceInfo(hwctx->
device_id, CL_DEVICE_IMAGE2D_MAX_HEIGHT,
1497 sizeof(max_height), &max_height,
NULL);
1498 if (cle != CL_SUCCESS) {
1500 "supported image height: %d.\n", cle);
1507 cle = clGetSupportedImageFormats(hwctx->
context,
1509 CL_MEM_OBJECT_IMAGE2D,
1510 0,
NULL, &nb_image_formats);
1511 if (cle != CL_SUCCESS) {
1513 "image formats: %d.\n", cle);
1517 if (nb_image_formats == 0) {
1519 "driver (zero supported image formats).\n");
1526 if (!image_formats) {
1531 cle = clGetSupportedImageFormats(hwctx->
context,
1533 CL_MEM_OBJECT_IMAGE2D,
1535 image_formats,
NULL);
1536 if (cle != CL_SUCCESS) {
1538 "image formats: %d.\n", cle);
1545 cl_image_format image_format;
1546 cl_image_desc image_desc;
1549 for (plane = 0;; plane++) {
1556 for (i = 0; i < nb_image_formats; i++) {
1557 if (image_formats[i].image_channel_order ==
1558 image_format.image_channel_order &&
1559 image_formats[i].image_channel_data_type ==
1560 image_format.image_channel_data_type)
1563 if (i == nb_image_formats) {
1611 cle = clReleaseMemObject(desc->
planes[p]);
1612 if (cle != CL_SUCCESS) {
1628 cl_image_format image_format;
1629 cl_image_desc image_desc;
1640 &image_format, &image_desc);
1648 image_desc.image_row_pitch = 0;
1650 image = clCreateImage(hwctx->
context, CL_MEM_READ_WRITE,
1651 &image_format, &image_desc,
NULL, &cle);
1654 "plane %d: %d.\n", p, cle);
1671 for (p = 0; desc->planes[p]; p++)
1672 clReleaseMemObject(desc->planes[p]);
1687 if (cle != CL_SUCCESS) {
1689 "command queue: %d.\n", cle);
1714 #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11 1716 for (i = 0; i < priv->nb_mapped_frames; i++) {
1719 cle = clReleaseMemObject(desc->
planes[p]);
1720 if (cle != CL_SUCCESS) {
1722 "frame object (frame %d plane %d): %d.\n",
1731 if (cle != CL_SUCCESS) {
1733 "command queue: %d.\n", cle);
1776 cl_event *events,
int nb_events)
1781 cle = clWaitForEvents(nb_events, events);
1782 if (cle != CL_SUCCESS) {
1784 "completion: %d.\n", cle);
1788 for (i = 0; i < nb_events; i++) {
1789 cle = clReleaseEvent(events[i]);
1790 if (cle != CL_SUCCESS) {
1792 "event: %d.\n", cle);
1803 cl_image_format image_format;
1804 cl_image_desc image_desc;
1806 size_t origin[3] = { 0, 0, 0 };
1817 &image_format, &image_desc);
1824 if (!dst->
data[p]) {
1826 "destination frame for transfer.\n", p);
1831 region[0] = image_desc.image_width;
1832 region[1] = image_desc.image_height;
1836 (cl_mem)src->
data[p],
1837 CL_FALSE, origin, region,
1840 0,
NULL, &events[p]);
1841 if (cle != CL_SUCCESS) {
1843 "OpenCL image plane %d: %d.\n", p, cle);
1858 cl_image_format image_format;
1859 cl_image_desc image_desc;
1861 size_t origin[3] = { 0, 0, 0 };
1872 &image_format, &image_desc);
1879 if (!src->
data[p]) {
1881 "source frame for transfer.\n", p);
1886 region[0] = image_desc.image_width;
1887 region[1] = image_desc.image_height;
1891 (cl_mem)dst->
data[p],
1892 CL_FALSE, origin, region,
1895 0,
NULL, &events[p]);
1896 if (cle != CL_SUCCESS) {
1898 "OpenCL image plane %d: %d.\n", p, cle);
1932 0,
NULL, &events[e]);
1933 if (cle != CL_SUCCESS) {
1935 "image plane %d: %d.\n", p, cle);
1949 cl_map_flags map_flags;
1950 cl_image_format image_format;
1951 cl_image_desc image_desc;
1954 size_t origin[3] = { 0, 0, 0 };
1966 map_flags = CL_MAP_WRITE_INVALIDATE_REGION;
1969 if (flags & AV_HWFRAME_MAP_READ)
1970 map_flags |= CL_MAP_READ;
1972 map_flags |= CL_MAP_WRITE;
1982 &image_format, &image_desc);
1988 region[0] = image_desc.image_width;
1989 region[1] = image_desc.image_height;
1994 (cl_mem)src->
data[p],
1995 CL_FALSE, map_flags, origin, region,
2000 "image plane %d: %d.\n", p, cle);
2030 (cl_mem)src->
data[p],
2032 0,
NULL, &events[p]);
2040 #if HAVE_OPENCL_DRM_BEIGNET 2042 typedef struct DRMBeignetToOpenCLMapping {
2047 } DRMBeignetToOpenCLMapping;
2052 DRMBeignetToOpenCLMapping *mapping = hwmap->
priv;
2056 for (i = 0; i < mapping->frame.nb_planes; i++) {
2057 cle = clReleaseMemObject(mapping->frame.planes[i]);
2058 if (cle != CL_SUCCESS) {
2060 "of plane %d of DRM frame: %d.\n", i, cle);
2073 DRMBeignetToOpenCLMapping *mapping;
2087 for (j = 0; j < layer->
nb_planes; j++) {
2092 cl_import_image_info_intel image_info = {
2094 .size =
object->size,
2095 .type = CL_MEM_OBJECT_IMAGE2D,
2097 .row_pitch = plane->
pitch,
2099 cl_image_desc image_desc;
2107 "plane %d is not representable in OpenCL: %d.\n",
2111 image_info.width = image_desc.image_width;
2112 image_info.height = image_desc.image_height;
2114 mapping->frame.planes[p] =
2115 priv->clCreateImageFromFdINTEL(hwctx->
context,
2117 if (!mapping->frame.planes[p]) {
2119 "from layer %d plane %d of DRM frame: %d.\n",
2125 dst->
data[p] = (
uint8_t*)mapping->frame.planes[p];
2126 mapping->frame.nb_planes = ++p;
2131 &opencl_unmap_from_drm_beignet,
2142 for (p = 0; p < mapping->frame.nb_planes; p++) {
2143 if (mapping->frame.planes[p])
2144 clReleaseMemObject(mapping->frame.planes[p]);
2150 #if HAVE_OPENCL_VAAPI_BEIGNET 2170 err = opencl_map_from_drm_beignet(dst_fc, dst, tmp, flags);
2191 return CL_MEM_READ_WRITE;
2192 else if (map_flags & AV_HWFRAME_MAP_READ)
2193 return CL_MEM_READ_ONLY;
2194 else if (map_flags & AV_HWFRAME_MAP_WRITE)
2195 return CL_MEM_WRITE_ONLY;
2200 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA 2214 cle = device_priv->clEnqueueReleaseVA_APIMediaSurfacesINTEL(
2217 if (cle != CL_SUCCESS) {
2219 "handles: %d.\n", cle);
2225 cle = clReleaseMemObject(desc->
planes[p]);
2226 if (cle != CL_SUCCESS) {
2228 "image of plane %d of QSV/VAAPI surface: %d\n",
2245 VASurfaceID va_surface;
2246 cl_mem_flags cl_flags;
2252 mfxFrameSurface1 *mfx_surface = (mfxFrameSurface1*)src->
data[3];
2253 va_surface = *(VASurfaceID*)mfx_surface->Data.MemId;
2255 va_surface = (VASurfaceID)(uintptr_t)src->
data[3];
2265 "OpenCL.\n", va_surface);
2273 desc->nb_planes = 2;
2275 for (p = 0; p <
desc->nb_planes; p++) {
2277 device_priv->clCreateFromVA_APIMediaSurfaceINTEL(
2278 dst_dev->context, cl_flags, &va_surface, p, &cle);
2279 if (!
desc->planes[p]) {
2281 "image from plane %d of QSV/VAAPI surface " 2282 "%#x: %d.\n", p, va_surface, cle);
2290 cle = device_priv->clEnqueueAcquireVA_APIMediaSurfacesINTEL(
2291 frames_priv->command_queue,
desc->nb_planes,
desc->planes,
2293 if (cle != CL_SUCCESS) {
2295 "handles: %d.\n", cle);
2305 &opencl_unmap_from_qsv,
desc);
2315 for (p = 0; p <
desc->nb_planes; p++)
2316 if (
desc->planes[p])
2317 clReleaseMemObject(
desc->planes[p]);
2324 #if HAVE_OPENCL_DXVA2 2337 cle = device_priv->clEnqueueReleaseDX9MediaSurfacesKHR(
2340 if (cle != CL_SUCCESS) {
2342 "handle: %d.\n", cle);
2363 "OpenCL.\n", src->
data[3]);
2365 for (i = 0; i < src_hwctx->nb_surfaces; i++) {
2366 if (src_hwctx->surfaces[i] == (IDirect3DSurface9*)src->
data[3])
2369 if (i >= src_hwctx->nb_surfaces) {
2371 "is not in the mapped frames context.\n");
2375 desc = &frames_priv->mapped_frames[i];
2377 cle = device_priv->clEnqueueAcquireDX9MediaSurfacesKHR(
2378 frames_priv->command_queue,
desc->nb_planes,
desc->planes,
2380 if (cle != CL_SUCCESS) {
2382 "handle: %d.\n", cle);
2390 for (i = 0; i <
desc->nb_planes; i++)
2394 &opencl_unmap_from_dxva2,
desc);
2404 cle = device_priv->clEnqueueReleaseDX9MediaSurfacesKHR(
2405 frames_priv->command_queue,
desc->nb_planes,
desc->planes,
2407 if (cle == CL_SUCCESS)
2419 cl_mem_flags cl_flags;
2421 int err, i, p, nb_planes;
2425 "for DXVA2 to OpenCL mapping.\n");
2432 "for DXVA2 to OpenCL mapping.\n");
2440 frames_priv->nb_mapped_frames = src_hwctx->
nb_surfaces;
2442 frames_priv->mapped_frames =
2444 sizeof(*frames_priv->mapped_frames));
2445 if (!frames_priv->mapped_frames)
2448 for (i = 0; i < frames_priv->nb_mapped_frames; i++) {
2450 cl_dx9_surface_info_khr surface_info = {
2451 .resource = src_hwctx->
surfaces[i],
2452 .shared_handle =
NULL,
2455 for (p = 0; p < nb_planes; p++) {
2457 device_priv->clCreateFromDX9MediaSurfaceKHR(
2459 device_priv->dx9_media_adapter_type,
2460 &surface_info, p, &cle);
2463 "image from plane %d of DXVA2 surface %d: %d.\n",
2474 for (i = 0; i < frames_priv->nb_mapped_frames; i++) {
2478 clReleaseMemObject(desc->
planes[p]);
2481 av_freep(&frames_priv->mapped_frames);
2482 frames_priv->nb_mapped_frames = 0;
2488 #if HAVE_OPENCL_D3D11 2499 cle = device_priv->clEnqueueReleaseD3D11ObjectsKHR(
2502 if (cle != CL_SUCCESS) {
2504 "handle: %d.\n", cle);
2520 index = (intptr_t)src->
data[1];
2521 if (index >= frames_priv->nb_mapped_frames) {
2523 "mapping: %d >= %d.\n", index, frames_priv->nb_mapped_frames);
2530 desc = &frames_priv->mapped_frames[
index];
2532 cle = device_priv->clEnqueueAcquireD3D11ObjectsKHR(
2535 if (cle != CL_SUCCESS) {
2537 "handle: %d.\n", cle);
2549 &opencl_unmap_from_d3d11, desc);
2559 cle = device_priv->clEnqueueReleaseD3D11ObjectsKHR(
2562 if (cle == CL_SUCCESS)
2574 cl_mem_flags cl_flags;
2576 int err, i, p, nb_planes;
2580 "for D3D11 to OpenCL mapping.\n");
2587 "for D3D11 to OpenCL mapping.\n");
2597 frames_priv->mapped_frames =
2599 sizeof(*frames_priv->mapped_frames));
2600 if (!frames_priv->mapped_frames)
2603 for (i = 0; i < frames_priv->nb_mapped_frames; i++) {
2606 for (p = 0; p < nb_planes; p++) {
2607 UINT subresource = 2 * i + p;
2610 device_priv->clCreateFromD3D11Texture2DKHR(
2615 "image from plane %d of D3D texture " 2616 "index %d (subresource %u): %d.\n",
2617 p, i, (
unsigned int)subresource, cle);
2627 for (i = 0; i < frames_priv->nb_mapped_frames; i++) {
2631 clReleaseMemObject(desc->
planes[p]);
2634 av_freep(&frames_priv->mapped_frames);
2635 frames_priv->nb_mapped_frames = 0;
2641 #if HAVE_OPENCL_DRM_ARM 2643 typedef struct DRMARMtoOpenCLMapping {
2648 } DRMARMtoOpenCLMapping;
2653 DRMARMtoOpenCLMapping *mapping = hwmap->
priv;
2656 for (i = 0; i < mapping->nb_planes; i++)
2657 clReleaseMemObject(mapping->plane_images[i]);
2659 for (i = 0; i < mapping->nb_objects; i++)
2660 clReleaseMemObject(mapping->object_buffers[i]);
2672 DRMARMtoOpenCLMapping *mapping =
NULL;
2673 cl_mem_flags cl_flags;
2674 const cl_import_properties_arm props[3] = {
2675 CL_IMPORT_TYPE_ARM, CL_IMPORT_TYPE_DMA_BUF_ARM, 0,
2690 mapping->nb_objects =
desc->nb_objects;
2691 for (i = 0; i <
desc->nb_objects; i++) {
2692 int fd =
desc->objects[i].fd;
2696 if (
desc->objects[i].format_modifier) {
2698 "nonzero format modifier %"PRId64
", result may not " 2699 "be as expected.\n", i, fd,
2700 desc->objects[i].format_modifier);
2703 mapping->object_buffers[i] =
2704 clImportMemoryARM(dst_dev->context, cl_flags, props,
2705 &fd,
desc->objects[i].size, &cle);
2706 if (!mapping->object_buffers[i]) {
2708 "from object %d (fd %d, size %"SIZE_SPECIFIER") of DRM frame: %d.\n",
2709 i, fd,
desc->objects[i].size, cle);
2715 mapping->nb_planes = 0;
2716 for (i = 0; i <
desc->nb_layers; i++) {
2719 for (j = 0; j < layer->
nb_planes; j++) {
2721 cl_mem plane_buffer;
2722 cl_image_format image_format;
2723 cl_image_desc image_desc;
2724 cl_buffer_region region;
2725 int p = mapping->nb_planes;
2729 &image_format, &image_desc);
2732 "layer %d plane %d): %d.\n", p, i, j, err);
2736 region.origin = plane->
offset;
2737 region.size = image_desc.image_row_pitch *
2738 image_desc.image_height;
2741 clCreateSubBuffer(mapping->object_buffers[plane->
object_index],
2743 CL_BUFFER_CREATE_TYPE_REGION,
2745 if (!plane_buffer) {
2747 "for plane %d: %d.\n", p, cle);
2752 image_desc.buffer = plane_buffer;
2754 mapping->plane_images[p] =
2755 clCreateImage(dst_dev->context, cl_flags,
2756 &image_format, &image_desc,
NULL, &cle);
2760 clReleaseMemObject(plane_buffer);
2762 if (!mapping->plane_images[p]) {
2764 "for plane %d: %d.\n", p, cle);
2769 ++mapping->nb_planes;
2773 for (i = 0; i < mapping->nb_planes; i++)
2774 dst->
data[i] = (
uint8_t*)mapping->plane_images[i];
2777 &opencl_unmap_from_drm_arm, mapping);
2787 for (i = 0; i < mapping->nb_planes; i++) {
2788 clReleaseMemObject(mapping->plane_images[i]);
2790 for (i = 0; i < mapping->nb_objects; i++) {
2791 if (mapping->object_buffers[i])
2792 clReleaseMemObject(mapping->object_buffers[i]);
2815 #if HAVE_OPENCL_DRM_BEIGNET 2817 if (priv->beignet_drm_mapping_usable)
2818 return opencl_map_from_drm_beignet(hwfc, dst, src, flags);
2820 #if HAVE_OPENCL_VAAPI_BEIGNET 2822 if (priv->beignet_drm_mapping_usable)
2823 return opencl_map_from_vaapi(hwfc, dst, src, flags);
2825 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA 2828 if (priv->qsv_mapping_usable)
2829 return opencl_map_from_qsv(hwfc, dst, src, flags);
2831 #if HAVE_OPENCL_DXVA2 2833 if (priv->dxva2_mapping_usable)
2834 return opencl_map_from_dxva2(hwfc, dst, src, flags);
2836 #if HAVE_OPENCL_D3D11 2838 if (priv->d3d11_mapping_usable)
2839 return opencl_map_from_d3d11(hwfc, dst, src, flags);
2841 #if HAVE_OPENCL_DRM_ARM 2843 if (priv->drm_arm_mapping_usable)
2844 return opencl_map_from_drm_arm(hwfc, dst, src, flags);
2855 #if HAVE_OPENCL_DRM_BEIGNET 2857 if (!priv->beignet_drm_mapping_usable)
2861 #if HAVE_OPENCL_VAAPI_BEIGNET 2863 if (!priv->beignet_drm_mapping_usable)
2867 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA 2870 if (!priv->qsv_mapping_usable)
2874 #if HAVE_OPENCL_DXVA2 2876 if (!priv->dxva2_mapping_usable)
2880 err = opencl_frames_derive_from_dxva2(dst_fc, src_fc, flags);
2886 #if HAVE_OPENCL_D3D11 2888 if (!priv->d3d11_mapping_usable)
2892 err = opencl_frames_derive_from_d3d11(dst_fc, src_fc, flags);
2898 #if HAVE_OPENCL_DRM_ARM 2900 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)
int plane
Which of the 4 planes contains the component.
The maximum number of layers/planes in a DRM frame.
static enum AVPixelFormat pix_fmt
#define AV_NUM_DATA_POINTERS
static float alpha(float a)
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
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]
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)
static int opencl_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
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.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
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.
int(* enumerate_platforms)(AVHWDeviceContext *hwdev, cl_uint *nb_platforms, cl_platform_id **platforms, void *context)
AVDRMLayerDescriptor layers[AV_DRM_MAX_PLANES]
Array of layers in the frame.
#define AV_LOG_VERBOSE
Detailed information.
cl_platform_id platform_id
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
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 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)
int(* filter_platform)(AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, void *context)
ptrdiff_t pitch
Pitch (linesize) of this plane.
const char const char AVS_ApplyFunc 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().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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)
Allocate, reallocate, or free an array through a pointer to a pointer.
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 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.
The mapping must be readable.
static char * opencl_get_platform_string(cl_platform_id platform_id, cl_platform_info key)
The mapping must be writeable.
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.
static struct @254 opencl_device_params[]
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.
int(* filter_device)(AVHWDeviceContext *hwdev, cl_device_id device_id, const char *device_name, void *context)
#define FF_ARRAY_ELEMS(a)
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.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static void opencl_error_callback(const char *errinfo, const void *private_info, size_t cb, void *user_data)
static struct @253 opencl_platform_params[]
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...
uint8_t * data
The data buffer.
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.
static struct @255 opencl_device_types[]
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.
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.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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.
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
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)
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)
Allocate a memory block for an array with av_mallocz().