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/cl_va_api_media_sharing_intel.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)
215 if (cle != CL_SUCCESS) {
229 cle = clGetDeviceInfo(device_id,
key, 0,
NULL, &
size);
230 if (cle != CL_SUCCESS)
236 if (cle != CL_SUCCESS) {
250 CL_PLATFORM_EXTENSIONS);
263 CL_DEVICE_EXTENSIONS);
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;
512 for (p = 0; p < nb_platforms; p++) {
513 const char *platform_name;
522 if (platform_name_src)
523 platform_name = platform_name_src;
525 platform_name =
"Unknown Platform";
538 &nb_devices, &devices,
543 for (d = 0; d < nb_devices; d++) {
544 const char *device_name;
554 device_name = device_name_src;
556 device_name =
"Unknown Device";
569 platform_name, device_name);
572 platform_id = platforms[p];
591 props = default_props;
592 default_props[0] = CL_CONTEXT_PLATFORM;
593 default_props[1] = (intptr_t)platform_id;
594 default_props[2] = 0;
596 if (props[0] == CL_CONTEXT_PLATFORM && props[1] == 0)
597 props[1] = (intptr_t)platform_id;
631 if (device && device[0]) {
633 int d = -1, p = -1, ret;
634 if (device[0] ==
'.')
635 ret = sscanf(device,
".%d", &d);
637 ret = sscanf(device,
"%d.%d", &p, &d);
640 "index specification \"%s\".\n", device);
661 if (cle != CL_SUCCESS) {
663 "command queue: %d.\n", cle);
673 "command queue: %d.\n", cle);
678 cle = clGetDeviceInfo(hwctx->
device_id, CL_DEVICE_PLATFORM,
681 if (cle != CL_SUCCESS) {
683 "platform containing the device.\n");
687 #define CL_FUNC(name, desc) do { \
690 priv->name = clGetExtensionFunctionAddressForPlatform( \
691 priv->platform_id, #name); \
693 av_log(hwdev, AV_LOG_VERBOSE, \
694 desc " function not found (%s).\n", #name); \
697 av_log(hwdev, AV_LOG_VERBOSE, \
698 desc " function found (%s).\n", #name); \
702 #if HAVE_OPENCL_DRM_BEIGNET
706 CL_FUNC(clCreateImageFromFdINTEL,
707 "Beignet DRM to OpenCL image mapping");
711 "mapping not usable.\n");
712 priv->beignet_drm_mapping_usable = 0;
714 priv->beignet_drm_mapping_usable = 1;
719 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
722 cl_context_properties *props =
NULL;
723 VADisplay va_display;
724 const char *va_ext =
"cl_intel_va_api_media_sharing";
729 "required for QSV to OpenCL mapping.\n", va_ext);
733 cle = clGetContextInfo(hwctx->
context, CL_CONTEXT_PROPERTIES,
734 0,
NULL, &props_size);
735 if (cle != CL_SUCCESS) {
737 "properties: %d.\n", cle);
740 if (props_size == 0) {
742 "enabled on context creation to use QSV to "
743 "OpenCL mapping.\n");
751 cle = clGetContextInfo(hwctx->
context, CL_CONTEXT_PROPERTIES,
752 props_size, props,
NULL);
753 if (cle != CL_SUCCESS) {
755 "properties: %d.\n", cle);
760 for (
i = 0;
i < (props_size /
sizeof(*props) - 1);
i++) {
761 if (props[
i] == CL_CONTEXT_VA_API_DISPLAY_INTEL) {
762 va_display = (VADisplay)(intptr_t)props[
i+1];
768 "enabled on context creation to use QSV to "
769 "OpenCL mapping.\n");
772 if (!vaDisplayIsValid(va_display)) {
774 "required on context creation to use QSV to "
775 "OpenCL mapping.\n");
779 CL_FUNC(clCreateFromVA_APIMediaSurfaceINTEL,
780 "Intel QSV to OpenCL mapping");
781 CL_FUNC(clEnqueueAcquireVA_APIMediaSurfacesINTEL,
782 "Intel QSV in OpenCL acquire");
783 CL_FUNC(clEnqueueReleaseVA_APIMediaSurfacesINTEL,
784 "Intel QSV in OpenCL release");
790 priv->qsv_mapping_usable = 0;
792 priv->qsv_mapping_usable = 1;
798 #if HAVE_OPENCL_DXVA2
802 CL_FUNC(clCreateFromDX9MediaSurfaceKHR,
803 "DXVA2 to OpenCL mapping");
804 CL_FUNC(clEnqueueAcquireDX9MediaSurfacesKHR,
805 "DXVA2 in OpenCL acquire");
806 CL_FUNC(clEnqueueReleaseDX9MediaSurfacesKHR,
807 "DXVA2 in OpenCL release");
812 priv->dxva2_mapping_usable = 0;
814 priv->dx9_media_adapter_type = CL_ADAPTER_D3D9EX_KHR;
815 priv->dxva2_mapping_usable = 1;
820 #if HAVE_OPENCL_D3D11
822 const char *d3d11_ext =
"cl_khr_d3d11_sharing";
823 const char *nv12_ext =
"cl_intel_d3d11_nv12_media_sharing";
828 "required for D3D11 to OpenCL mapping.\n", d3d11_ext);
832 "required for D3D11 to OpenCL mapping.\n", nv12_ext);
836 CL_FUNC(clCreateFromD3D11Texture2DKHR,
837 "D3D11 to OpenCL mapping");
838 CL_FUNC(clEnqueueAcquireD3D11ObjectsKHR,
839 "D3D11 in OpenCL acquire");
840 CL_FUNC(clEnqueueReleaseD3D11ObjectsKHR,
841 "D3D11 in OpenCL release");
846 priv->d3d11_mapping_usable = 0;
848 priv->d3d11_mapping_usable = 1;
853 #if HAVE_OPENCL_DRM_ARM
855 const char *drm_arm_ext =
"cl_arm_import_memory";
856 const char *image_ext =
"cl_khr_image2d_from_buffer";
861 "required for DRM to OpenCL mapping on ARM.\n",
867 "required for DRM to OpenCL mapping on ARM.\n",
877 priv->drm_arm_mapping_usable = 0;
879 priv->drm_arm_mapping_usable = 1;
896 if (cle != CL_SUCCESS) {
898 "command queue reference: %d.\n", cle);
904 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
906 cl_platform_id platform_id,
907 const char *platform_name,
913 if (!clGetExtensionFunctionAddressForPlatform(platform_id,
914 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL")) {
916 "VAAPI device enumeration function.\n", platform_name);
924 cl_platform_id platform_id,
925 const char *platform_name,
927 cl_device_id **devices,
930 VADisplay va_display = context;
931 clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn
932 clGetDeviceIDsFromVA_APIMediaAdapterINTEL;
935 clGetDeviceIDsFromVA_APIMediaAdapterINTEL =
936 clGetExtensionFunctionAddressForPlatform(platform_id,
937 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL");
938 if (!clGetDeviceIDsFromVA_APIMediaAdapterINTEL) {
940 "clGetDeviceIDsFromVA_APIMediaAdapterINTEL().\n");
944 cle = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(
945 platform_id, CL_VA_API_DISPLAY_INTEL, va_display,
946 CL_PREFERRED_DEVICES_FOR_VA_API_INTEL, 0,
NULL, nb_devices);
947 if (cle == CL_DEVICE_NOT_FOUND) {
949 "on platform \"%s\".\n", platform_name);
952 }
else if (cle != CL_SUCCESS) {
954 "on platform \"%s\": %d.\n", platform_name, cle);
962 cle = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(
963 platform_id, CL_VA_API_DISPLAY_INTEL, va_display,
964 CL_PREFERRED_DEVICES_FOR_VA_API_INTEL, *nb_devices, *devices,
NULL);
965 if (cle != CL_SUCCESS) {
967 "devices on platform \"%s\": %d.\n", platform_name, cle);
976 cl_device_id device_id,
977 const char *device_name,
980 const char *va_ext =
"cl_intel_va_api_media_sharing";
986 "%s extension.\n", device_name, va_ext);
992 #if HAVE_OPENCL_DXVA2
994 cl_platform_id platform_id,
995 const char *platform_name,
998 const char *dx9_ext =
"cl_khr_dx9_media_sharing";
1004 "%s extension.\n", platform_name, dx9_ext);
1010 cl_platform_id platform_id,
1011 const char *platform_name,
1012 cl_uint *nb_devices,
1013 cl_device_id **devices,
1016 IDirect3DDevice9 *device = context;
1017 clGetDeviceIDsFromDX9MediaAdapterKHR_fn
1018 clGetDeviceIDsFromDX9MediaAdapterKHR;
1019 cl_dx9_media_adapter_type_khr media_adapter_type = CL_ADAPTER_D3D9EX_KHR;
1022 clGetDeviceIDsFromDX9MediaAdapterKHR =
1023 clGetExtensionFunctionAddressForPlatform(platform_id,
1024 "clGetDeviceIDsFromDX9MediaAdapterKHR");
1025 if (!clGetDeviceIDsFromDX9MediaAdapterKHR) {
1027 "clGetDeviceIDsFromDX9MediaAdapterKHR().\n");
1031 cle = clGetDeviceIDsFromDX9MediaAdapterKHR(
1032 platform_id, 1, &media_adapter_type, (
void**)&device,
1033 CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR,
1034 0,
NULL, nb_devices);
1035 if (cle == CL_DEVICE_NOT_FOUND) {
1037 "on platform \"%s\".\n", platform_name);
1040 }
else if (cle != CL_SUCCESS) {
1042 "on platform \"%s\": %d.\n", platform_name, cle);
1050 cle = clGetDeviceIDsFromDX9MediaAdapterKHR(
1051 platform_id, 1, &media_adapter_type, (
void**)&device,
1052 CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR,
1053 *nb_devices, *devices,
NULL);
1054 if (cle != CL_SUCCESS) {
1056 "devices on platform \"%s\": %d.\n", platform_name, cle);
1065 #if HAVE_OPENCL_D3D11
1067 cl_platform_id platform_id,
1068 const char *platform_name,
1071 const char *d3d11_ext =
"cl_khr_d3d11_sharing";
1077 "%s extension.\n", platform_name, d3d11_ext);
1083 cl_platform_id platform_id,
1084 const char *platform_name,
1085 cl_uint *nb_devices,
1086 cl_device_id **devices,
1090 clGetDeviceIDsFromD3D11KHR_fn clGetDeviceIDsFromD3D11KHR;
1093 clGetDeviceIDsFromD3D11KHR =
1094 clGetExtensionFunctionAddressForPlatform(platform_id,
1095 "clGetDeviceIDsFromD3D11KHR");
1096 if (!clGetDeviceIDsFromD3D11KHR) {
1098 "clGetDeviceIDsFromD3D11KHR().\n");
1102 cle = clGetDeviceIDsFromD3D11KHR(platform_id,
1103 CL_D3D11_DEVICE_KHR, device,
1104 CL_PREFERRED_DEVICES_FOR_D3D11_KHR,
1105 0,
NULL, nb_devices);
1106 if (cle == CL_DEVICE_NOT_FOUND) {
1108 "on platform \"%s\".\n", platform_name);
1111 }
else if (cle != CL_SUCCESS) {
1113 "on platform \"%s\": %d.\n", platform_name, cle);
1121 cle = clGetDeviceIDsFromD3D11KHR(platform_id,
1122 CL_D3D11_DEVICE_KHR, device,
1123 CL_PREFERRED_DEVICES_FOR_D3D11_KHR,
1124 *nb_devices, *devices,
NULL);
1125 if (cle != CL_SUCCESS) {
1127 "devices on platform \"%s\": %d.\n", platform_name, cle);
1136 #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11
1138 cl_device_id device_id,
1139 const char *device_name,
1145 cle = clGetDeviceInfo(device_id, CL_DEVICE_TYPE,
1147 if (cle != CL_SUCCESS) {
1149 "of device \"%s\".\n", device_name);
1162 #if HAVE_OPENCL_DRM_ARM
1164 cl_platform_id platform_id,
1165 const char *platform_name,
1168 const char *drm_arm_ext =
"cl_arm_import_memory";
1174 "%s extension.\n", platform_name, drm_arm_ext);
1180 cl_device_id device_id,
1181 const char *device_name,
1184 const char *drm_arm_ext =
"cl_arm_import_memory";
1190 "%s extension.\n", device_name, drm_arm_ext);
1201 switch (src_ctx->
type) {
1203 #if HAVE_OPENCL_DRM_BEIGNET
1212 err =
av_dict_set(&selector_opts,
"platform_vendor",
"Intel", 0);
1214 err =
av_dict_set(&selector_opts,
"platform_version",
"beignet", 0);
1219 .context = selector_opts,
1223 .filter_device =
NULL,
1232 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
1239 cl_context_properties props[7] = {
1240 CL_CONTEXT_PLATFORM,
1242 CL_CONTEXT_VA_API_DISPLAY_INTEL,
1244 CL_CONTEXT_INTEROP_USER_SYNC,
1251 .context = src_hwctx->
display,
1253 .filter_platform = &opencl_filter_intel_media_vaapi_platform,
1254 .enumerate_devices = &opencl_enumerate_intel_media_vaapi_devices,
1255 .filter_device = &opencl_filter_intel_media_vaapi_device,
1263 #if HAVE_OPENCL_DXVA2
1267 IDirect3DDevice9 *device;
1268 HANDLE device_handle;
1271 hr = IDirect3DDeviceManager9_OpenDeviceHandle(src_hwctx->
devmgr,
1275 "for Direct3D9 device: %lx.\n", (
unsigned long)hr);
1280 hr = IDirect3DDeviceManager9_LockDevice(src_hwctx->
devmgr,
1283 if (SUCCEEDED(hr)) {
1284 cl_context_properties props[5] = {
1285 CL_CONTEXT_PLATFORM,
1287 CL_CONTEXT_ADAPTER_D3D9EX_KHR,
1296 .filter_platform = &opencl_filter_dxva2_platform,
1297 .enumerate_devices = &opencl_enumerate_dxva2_devices,
1298 .filter_device = &opencl_filter_gpu_device,
1303 IDirect3DDeviceManager9_UnlockDevice(src_hwctx->
devmgr,
1304 device_handle, FALSE);
1307 "for Direct3D9 device: %lx.\n", (
unsigned long)hr);
1311 IDirect3DDeviceManager9_CloseDeviceHandle(src_hwctx->
devmgr,
1317 #if HAVE_OPENCL_D3D11
1321 cl_context_properties props[5] = {
1322 CL_CONTEXT_PLATFORM,
1324 CL_CONTEXT_D3D11_DEVICE_KHR,
1325 (intptr_t)src_hwctx->
device,
1331 .context = src_hwctx->
device,
1333 .filter_platform = &opencl_filter_d3d11_platform,
1334 .enumerate_devices = &opencl_enumerate_d3d11_devices,
1335 .filter_device = &opencl_filter_gpu_device,
1343 #if HAVE_OPENCL_DRM_ARM
1351 .filter_platform = &opencl_filter_drm_arm_platform,
1353 .filter_device = &opencl_filter_drm_arm_device,
1371 cl_image_format *image_format,
1372 cl_image_desc *image_desc)
1376 int channels = 0, order = 0, depth = 0, step = 0;
1391 wsub = 1 <<
desc->log2_chroma_w;
1397 for (
c = 0;
c <
desc->nb_components;
c++) {
1399 if (
comp->plane != plane)
1402 if (
comp->step != 1 &&
comp->step != 2 &&
1403 comp->step != 4 &&
comp->step != 8)
1407 if (
comp->shift +
comp->depth != 8 &&
1411 if (depth &&
comp->depth != depth)
1415 if (
comp->depth > 8 &&
1420 if (step &&
comp->step != step)
1423 depth =
comp->depth;
1424 order = order * 10 +
comp->offset / ((depth + 7) / 8) + 1;
1427 c ==
desc->nb_components - 1);
1433 memset(image_format, 0,
sizeof(*image_format));
1434 memset(image_desc, 0,
sizeof(*image_desc));
1435 image_desc->image_type = CL_MEM_OBJECT_IMAGE2D;
1437 if (plane == 0 ||
alpha) {
1438 image_desc->image_width =
width;
1439 image_desc->image_height =
height;
1440 image_desc->image_row_pitch = step *
width;
1442 image_desc->image_width =
width / wsub;
1444 image_desc->image_row_pitch = step *
width / wsub;
1448 image_format->image_channel_data_type = CL_UNORM_INT8;
1451 image_format->image_channel_data_type = CL_UNORM_INT16;
1456 #define CHANNEL_ORDER(order, type) \
1457 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) {
1609 for (p = 0; p <
desc->nb_planes; p++) {
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);
1657 desc->planes[p] = image;
1660 desc->nb_planes = p;
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++) {
1717 for (p = 0; p <
desc->nb_planes; p++) {
1718 cle = clReleaseMemObject(
desc->planes[p]);
1719 if (cle != CL_SUCCESS) {
1721 "frame object (frame %d plane %d): %d.\n",
1731 if (cle != CL_SUCCESS) {
1733 "command queue: %d.\n", cle);
1750 for (p = 0; p <
desc->nb_planes; p++)
1778 cl_event *events,
int nb_events)
1783 cle = clWaitForEvents(nb_events, events);
1784 if (cle != CL_SUCCESS) {
1786 "completion: %d.\n", cle);
1790 for (
i = 0;
i < nb_events;
i++) {
1791 cle = clReleaseEvent(events[
i]);
1792 if (cle != CL_SUCCESS) {
1794 "event: %d.\n", cle);
1805 cl_image_format image_format;
1806 cl_image_desc image_desc;
1808 size_t origin[3] = { 0, 0, 0 };
1819 &image_format, &image_desc);
1826 if (!dst->
data[p]) {
1828 "destination frame for transfer.\n", p);
1833 region[0] = image_desc.image_width;
1834 region[1] = image_desc.image_height;
1838 (cl_mem)
src->data[p],
1839 CL_FALSE, origin, region,
1842 0,
NULL, &events[p]);
1843 if (cle != CL_SUCCESS) {
1845 "OpenCL image plane %d: %d.\n", p, cle);
1860 cl_image_format image_format;
1861 cl_image_desc image_desc;
1863 size_t origin[3] = { 0, 0, 0 };
1874 &image_format, &image_desc);
1881 if (!
src->data[p]) {
1883 "source frame for transfer.\n", p);
1888 region[0] = image_desc.image_width;
1889 region[1] = image_desc.image_height;
1893 (cl_mem)dst->
data[p],
1894 CL_FALSE, origin, region,
1895 src->linesize[p], 0,
1897 0,
NULL, &events[p]);
1898 if (cle != CL_SUCCESS) {
1900 "OpenCL image plane %d: %d.\n", p, cle);
1928 if (!
map->address[p])
1934 0,
NULL, &events[e]);
1935 if (cle != CL_SUCCESS) {
1937 "image plane %d: %d.\n", p, cle);
1951 cl_map_flags map_flags;
1952 cl_image_format image_format;
1953 cl_image_desc image_desc;
1956 size_t origin[3] = { 0, 0, 0 };
1968 map_flags = CL_MAP_WRITE_INVALIDATE_REGION;
1972 map_flags |= CL_MAP_READ;
1974 map_flags |= CL_MAP_WRITE;
1984 &image_format, &image_desc);
1990 region[0] = image_desc.image_width;
1991 region[1] = image_desc.image_height;
1996 (cl_mem)
src->data[p],
1997 CL_FALSE, map_flags, origin, region,
2000 if (!
map->address[p]) {
2002 "image plane %d: %d.\n", p, cle);
2007 dst->
data[p] =
map->address[p];
2011 p,
src->data[p], dst->
data[p]);
2030 if (!
map->address[p])
2033 (cl_mem)
src->data[p],
2035 0,
NULL, &events[p]);
2043 #if HAVE_OPENCL_DRM_BEIGNET
2045 typedef struct DRMBeignetToOpenCLMapping {
2050 } DRMBeignetToOpenCLMapping;
2055 DRMBeignetToOpenCLMapping *mapping = hwmap->
priv;
2059 for (
i = 0;
i < mapping->frame.nb_planes;
i++) {
2060 cle = clReleaseMemObject(mapping->frame.planes[
i]);
2061 if (cle != CL_SUCCESS) {
2063 "of plane %d of DRM frame: %d.\n",
i, cle);
2076 DRMBeignetToOpenCLMapping *mapping;
2088 for (
i = 0;
i <
desc->nb_layers;
i++) {
2090 for (j = 0; j < layer->
nb_planes; j++) {
2095 cl_import_image_info_intel image_info = {
2097 .size =
object->size,
2098 .type = CL_MEM_OBJECT_IMAGE2D,
2100 .row_pitch = plane->
pitch,
2102 cl_image_desc image_desc;
2110 "plane %d is not representable in OpenCL: %d.\n",
2114 image_info.width = image_desc.image_width;
2115 image_info.height = image_desc.image_height;
2117 mapping->frame.planes[p] =
2118 priv->clCreateImageFromFdINTEL(hwctx->
context,
2120 if (!mapping->frame.planes[p]) {
2122 "from layer %d plane %d of DRM frame: %d.\n",
2128 dst->
data[p] = (
uint8_t*)mapping->frame.planes[p];
2129 mapping->frame.nb_planes = ++p;
2134 &opencl_unmap_from_drm_beignet,
2145 for (p = 0; p < mapping->frame.nb_planes; p++) {
2146 if (mapping->frame.planes[p])
2147 clReleaseMemObject(mapping->frame.planes[p]);
2153 #if HAVE_OPENCL_VAAPI_BEIGNET
2172 err = opencl_map_from_drm_beignet(dst_fc, dst,
tmp,
flags);
2190 return CL_MEM_READ_WRITE;
2192 return CL_MEM_READ_ONLY;
2194 return CL_MEM_WRITE_ONLY;
2199 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
2213 cle = device_priv->clEnqueueReleaseVA_APIMediaSurfacesINTEL(
2216 if (cle != CL_SUCCESS) {
2218 "handles: %d.\n", cle);
2223 for (p = 0; p <
desc->nb_planes; p++) {
2224 cle = clReleaseMemObject(
desc->planes[p]);
2225 if (cle != CL_SUCCESS) {
2227 "image of plane %d of QSV/VAAPI surface: %d\n",
2244 VASurfaceID va_surface;
2245 cl_mem_flags cl_flags;
2252 mfxFrameSurface1 *mfx_surface = (mfxFrameSurface1*)
src->data[3];
2253 va_surface = *(VASurfaceID*)mfx_surface->Data.MemId;
2257 va_surface = (VASurfaceID)(uintptr_t)
src->data[3];
2267 "OpenCL.\n", va_surface);
2275 desc->nb_planes = 2;
2277 for (p = 0; p <
desc->nb_planes; p++) {
2279 device_priv->clCreateFromVA_APIMediaSurfaceINTEL(
2280 dst_dev->context, cl_flags, &va_surface, p, &cle);
2281 if (!
desc->planes[p]) {
2283 "image from plane %d of QSV/VAAPI surface "
2284 "%#x: %d.\n", p, va_surface, cle);
2292 cle = device_priv->clEnqueueAcquireVA_APIMediaSurfacesINTEL(
2295 if (cle != CL_SUCCESS) {
2297 "handles: %d.\n", cle);
2307 &opencl_unmap_from_qsv,
desc);
2317 for (p = 0; p <
desc->nb_planes; p++)
2318 if (
desc->planes[p])
2319 clReleaseMemObject(
desc->planes[p]);
2326 #if HAVE_OPENCL_DXVA2
2339 cle = device_priv->clEnqueueReleaseDX9MediaSurfacesKHR(
2342 if (cle != CL_SUCCESS) {
2344 "handle: %d.\n", cle);
2365 "OpenCL.\n",
src->data[3]);
2367 for (
i = 0;
i < src_hwctx->nb_surfaces;
i++) {
2368 if (src_hwctx->surfaces[
i] == (IDirect3DSurface9*)
src->data[3])
2371 if (
i >= src_hwctx->nb_surfaces) {
2373 "is not in the mapped frames context.\n");
2377 desc = &frames_priv->mapped_frames[
i];
2379 cle = device_priv->clEnqueueAcquireDX9MediaSurfacesKHR(
2382 if (cle != CL_SUCCESS) {
2384 "handle: %d.\n", cle);
2392 for (
i = 0;
i <
desc->nb_planes;
i++)
2396 &opencl_unmap_from_dxva2,
desc);
2406 cle = device_priv->clEnqueueReleaseDX9MediaSurfacesKHR(
2409 if (cle == CL_SUCCESS)
2421 cl_mem_flags cl_flags;
2423 int err,
i, p, nb_planes;
2427 "for DXVA2 to OpenCL mapping.\n");
2434 "for DXVA2 to OpenCL mapping.\n");
2442 frames_priv->nb_mapped_frames = src_hwctx->
nb_surfaces;
2444 frames_priv->mapped_frames =
2446 sizeof(*frames_priv->mapped_frames));
2447 if (!frames_priv->mapped_frames)
2450 for (
i = 0;
i < frames_priv->nb_mapped_frames;
i++) {
2452 cl_dx9_surface_info_khr surface_info = {
2454 .shared_handle =
NULL,
2456 desc->nb_planes = nb_planes;
2457 for (p = 0; p < nb_planes; p++) {
2459 device_priv->clCreateFromDX9MediaSurfaceKHR(
2461 device_priv->dx9_media_adapter_type,
2462 &surface_info, p, &cle);
2463 if (!
desc->planes[p]) {
2465 "image from plane %d of DXVA2 surface %d: %d.\n",
2476 for (
i = 0;
i < frames_priv->nb_mapped_frames;
i++) {
2478 for (p = 0; p <
desc->nb_planes; p++) {
2479 if (
desc->planes[p])
2480 clReleaseMemObject(
desc->planes[p]);
2483 av_freep(&frames_priv->mapped_frames);
2484 frames_priv->nb_mapped_frames = 0;
2490 #if HAVE_OPENCL_D3D11
2501 cle = device_priv->clEnqueueReleaseD3D11ObjectsKHR(
2504 if (cle != CL_SUCCESS) {
2506 "handle: %d.\n", cle);
2523 if (
index >= frames_priv->nb_mapped_frames) {
2525 "mapping: %d >= %d.\n",
index, frames_priv->nb_mapped_frames);
2532 desc = &frames_priv->mapped_frames[
index];
2534 cle = device_priv->clEnqueueAcquireD3D11ObjectsKHR(
2537 if (cle != CL_SUCCESS) {
2539 "handle: %d.\n", cle);
2547 for (
i = 0;
i <
desc->nb_planes;
i++)
2551 &opencl_unmap_from_d3d11,
desc);
2561 cle = device_priv->clEnqueueReleaseD3D11ObjectsKHR(
2564 if (cle == CL_SUCCESS)
2576 cl_mem_flags cl_flags;
2578 int err,
i, p, nb_planes;
2582 "for D3D11 to OpenCL mapping.\n");
2589 "for D3D11 to OpenCL mapping.\n");
2599 frames_priv->mapped_frames =
2601 sizeof(*frames_priv->mapped_frames));
2602 if (!frames_priv->mapped_frames)
2605 for (
i = 0;
i < frames_priv->nb_mapped_frames;
i++) {
2607 desc->nb_planes = nb_planes;
2608 for (p = 0; p < nb_planes; p++) {
2609 UINT subresource = 2 *
i + p;
2612 device_priv->clCreateFromD3D11Texture2DKHR(
2615 if (!
desc->planes[p]) {
2617 "image from plane %d of D3D texture "
2618 "index %d (subresource %u): %d.\n",
2619 p,
i, (
unsigned int)subresource, cle);
2629 for (
i = 0;
i < frames_priv->nb_mapped_frames;
i++) {
2631 for (p = 0; p <
desc->nb_planes; p++) {
2632 if (
desc->planes[p])
2633 clReleaseMemObject(
desc->planes[p]);
2636 av_freep(&frames_priv->mapped_frames);
2637 frames_priv->nb_mapped_frames = 0;
2643 #if HAVE_OPENCL_DRM_ARM
2645 typedef struct DRMARMtoOpenCLMapping {
2650 } DRMARMtoOpenCLMapping;
2655 DRMARMtoOpenCLMapping *mapping = hwmap->
priv;
2658 for (
i = 0;
i < mapping->nb_planes;
i++)
2659 clReleaseMemObject(mapping->plane_images[
i]);
2661 for (
i = 0;
i < mapping->nb_objects;
i++)
2662 clReleaseMemObject(mapping->object_buffers[
i]);
2674 DRMARMtoOpenCLMapping *mapping =
NULL;
2675 cl_mem_flags cl_flags;
2676 const cl_import_properties_arm props[3] = {
2677 CL_IMPORT_TYPE_ARM, CL_IMPORT_TYPE_DMA_BUF_ARM, 0,
2692 mapping->nb_objects =
desc->nb_objects;
2693 for (
i = 0;
i <
desc->nb_objects;
i++) {
2694 int fd =
desc->objects[
i].fd;
2698 if (
desc->objects[
i].format_modifier) {
2700 "nonzero format modifier %"PRId64
", result may not "
2701 "be as expected.\n",
i, fd,
2702 desc->objects[
i].format_modifier);
2705 mapping->object_buffers[
i] =
2706 clImportMemoryARM(dst_dev->
context, cl_flags, props,
2707 &fd,
desc->objects[
i].size, &cle);
2708 if (!mapping->object_buffers[
i]) {
2710 "from object %d (fd %d, size %"SIZE_SPECIFIER") of DRM frame: %d.\n",
2711 i, fd,
desc->objects[
i].size, cle);
2717 mapping->nb_planes = 0;
2718 for (
i = 0;
i <
desc->nb_layers;
i++) {
2721 for (j = 0; j < layer->
nb_planes; j++) {
2723 cl_mem plane_buffer;
2724 cl_image_format image_format;
2725 cl_image_desc image_desc;
2726 cl_buffer_region region;
2727 int p = mapping->nb_planes;
2731 &image_format, &image_desc);
2734 "layer %d plane %d): %d.\n", p,
i, j, err);
2738 region.origin = plane->
offset;
2739 region.size = image_desc.image_row_pitch *
2740 image_desc.image_height;
2743 clCreateSubBuffer(mapping->object_buffers[plane->
object_index],
2745 CL_BUFFER_CREATE_TYPE_REGION,
2747 if (!plane_buffer) {
2749 "for plane %d: %d.\n", p, cle);
2754 image_desc.buffer = plane_buffer;
2756 mapping->plane_images[p] =
2757 clCreateImage(dst_dev->
context, cl_flags,
2758 &image_format, &image_desc,
NULL, &cle);
2762 clReleaseMemObject(plane_buffer);
2764 if (!mapping->plane_images[p]) {
2766 "for plane %d: %d.\n", p, cle);
2771 ++mapping->nb_planes;
2775 for (
i = 0;
i < mapping->nb_planes;
i++)
2779 &opencl_unmap_from_drm_arm, mapping);
2789 for (
i = 0;
i < mapping->nb_planes;
i++) {
2790 clReleaseMemObject(mapping->plane_images[
i]);
2792 for (
i = 0;
i < mapping->nb_objects;
i++) {
2793 if (mapping->object_buffers[
i])
2794 clReleaseMemObject(mapping->object_buffers[
i]);
2816 switch (
src->format) {
2817 #if HAVE_OPENCL_DRM_BEIGNET
2819 if (priv->beignet_drm_mapping_usable)
2820 return opencl_map_from_drm_beignet(hwfc, dst,
src,
flags);
2823 #if HAVE_OPENCL_VAAPI_BEIGNET
2825 if (priv->beignet_drm_mapping_usable)
2826 return opencl_map_from_vaapi(hwfc, dst,
src,
flags);
2829 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
2832 if (priv->qsv_mapping_usable)
2833 return opencl_map_from_qsv(hwfc, dst,
src,
flags);
2836 #if HAVE_OPENCL_DXVA2
2838 if (priv->dxva2_mapping_usable)
2839 return opencl_map_from_dxva2(hwfc, dst,
src,
flags);
2842 #if HAVE_OPENCL_D3D11
2844 if (priv->d3d11_mapping_usable)
2845 return opencl_map_from_d3d11(hwfc, dst,
src,
flags);
2848 #if HAVE_OPENCL_DRM_ARM
2850 if (priv->drm_arm_mapping_usable)
2851 return opencl_map_from_drm_arm(hwfc, dst,
src,
flags);
2863 #if HAVE_OPENCL_DRM_BEIGNET
2865 if (!priv->beignet_drm_mapping_usable)
2869 #if HAVE_OPENCL_VAAPI_BEIGNET
2871 if (!priv->beignet_drm_mapping_usable)
2875 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
2878 if (!priv->qsv_mapping_usable)
2882 #if HAVE_OPENCL_DXVA2
2884 if (!priv->dxva2_mapping_usable)
2888 err = opencl_frames_derive_from_dxva2(dst_fc, src_fc,
flags);
2894 #if HAVE_OPENCL_D3D11
2896 if (!priv->d3d11_mapping_usable)
2900 err = opencl_frames_derive_from_d3d11(dst_fc, src_fc,
flags);
2906 #if HAVE_OPENCL_DRM_ARM
2908 if (!priv->drm_arm_mapping_usable)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define flags(name, subs,...)
static int FUNC() user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
common internal and external API header
static enum AVPixelFormat pix_fmt
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
#define AV_NUM_DATA_POINTERS
AVBufferRef * av_buffer_create(uint8_t *data, buffer_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(buffer_size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, buffer_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.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
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.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#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_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
Map a hardware frame.
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)-...
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
@ AV_HWFRAME_MAP_OVERWRITE
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
AVHWFrameTransferDirection
@ AV_HWDEVICE_TYPE_D3D11VA
@ AV_HWDEVICE_TYPE_OPENCL
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
API-specific header for AV_HWDEVICE_TYPE_DRM.
@ AV_DRM_MAX_PLANES
The maximum number of layers/planes in a DRM frame.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
static char * opencl_get_device_string(cl_device_id device_id, cl_device_info key)
static AVBufferRef * opencl_pool_alloc(void *opaque, buffer_size_t size)
const HWContextType ff_hwcontext_type_opencl
#define CHANNEL_ORDER(order, type)
static int opencl_frames_get_constraints(AVHWDeviceContext *hwdev, const void *hwconfig, AVHWFramesConstraints *constraints)
static int opencl_wait_events(AVHWFramesContext *hwfc, cl_event *events, int nb_events)
static void opencl_device_free(AVHWDeviceContext *hwdev)
static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc)
static int opencl_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
static int opencl_check_device_extension(cl_device_id device_id, const char *name)
static struct @302 opencl_platform_params[]
static int opencl_map_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
static int opencl_frames_init(AVHWFramesContext *hwfc)
static struct @304 opencl_device_types[]
static av_unused int opencl_check_extension(AVHWDeviceContext *hwdev, const char *name)
static void opencl_unmap_frame(AVHWFramesContext *hwfc, HWMapDescriptor *hwmap)
static int opencl_device_create(AVHWDeviceContext *hwdev, const char *device, AVDictionary *opts, int flags)
static int opencl_frames_derive_to(AVHWFramesContext *dst_fc, AVHWFramesContext *src_fc, int flags)
static int opencl_device_init(AVHWDeviceContext *hwdev)
static void opencl_pool_free(void *opaque, uint8_t *data)
static int opencl_enumerate_platforms(AVHWDeviceContext *hwdev, cl_uint *nb_platforms, cl_platform_id **platforms, void *context)
static cl_mem_flags opencl_mem_flags_for_mapping(int map_flags)
static void opencl_device_uninit(AVHWDeviceContext *hwdev)
#define CL_FUNC(name, desc)
static int opencl_device_create_internal(AVHWDeviceContext *hwdev, const OpenCLDeviceSelector *selector, cl_context_properties *props)
static int opencl_get_buffer(AVHWFramesContext *hwfc, AVFrame *frame)
static void opencl_frames_uninit(AVHWFramesContext *hwfc)
static void CL_CALLBACK opencl_error_callback(const char *errinfo, const void *private_info, size_t cb, void *user_data)
static struct @303 opencl_device_params[]
static int opencl_map_from(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)
static char * opencl_get_platform_string(cl_platform_id platform_id, cl_platform_info key)
static int opencl_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
static int opencl_transfer_get_formats(AVHWFramesContext *hwfc, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
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)
static int opencl_device_derive(AVHWDeviceContext *hwdev, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
static int opencl_filter_platform(AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, void *context)
static int opencl_map_frame(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
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)
API-specific header for AV_HWDEVICE_TYPE_OPENCL.
enum AVHWDeviceType device_type
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
const VDPAUPixFmtMap * map
static const int16_t alpha[]
enum AVPixelFormat pixfmt
Memory handling functions.
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
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_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
@ AV_PIX_FMT_DRM_PRIME
DRM-managed buffers exposed through PRIME buffer sharing.
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
ID3D11Device * device
Device used for texture creation and access.
This struct is allocated as AVHWFramesContext.hwctx.
ID3D11Texture2D * texture
The canonical texture used for pool allocation.
AVDRMPlaneDescriptor planes[AV_DRM_MAX_PLANES]
Array of planes in this layer.
int nb_planes
Number of planes in the layer.
ptrdiff_t pitch
Pitch (linesize) of this plane.
int object_index
Index of the object containing this plane in the objects array of the enclosing frame descriptor.
ptrdiff_t offset
Offset within that object of this plane.
This struct is allocated as AVHWDeviceContext.hwctx.
IDirect3DDeviceManager9 * devmgr
This struct is allocated as AVHWFramesContext.hwctx.
IDirect3DSurface9 ** surfaces
The surface pool.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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.
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
AVHWDeviceInternal * internal
Private data used internally by libavutil.
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...
int max_width
The maximum size of frames in this hw_frames_ctx.
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.
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.
AVHWFramesInternal * internal
Private data used internally by libavutil.
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.
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
AVBufferPool * pool_internal
cl_device_id device_id
The primary device ID of the device.
cl_command_queue command_queue
The default command queue for this device, which will be used by all frames contexts which do not hav...
cl_context context
The OpenCL context which will contain all operations and frames on this device.
OpenCL frame descriptor for pool allocation.
OpenCL-specific data associated with a frame pool.
cl_command_queue command_queue
The command queue used for internal asynchronous operations on this device (av_hwframe_transfer_data(...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
VAAPI connection details.
VADisplay display
The VADisplay handle, to be filled by the user.
void * priv
Hardware-specific private data associated with the mapping.
AVFrame * source
A reference to the original source of the mapping.
cl_platform_id platform_id
cl_command_queue command_queue
int(* filter_platform)(AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, void *context)
int(* enumerate_platforms)(AVHWDeviceContext *hwdev, cl_uint *nb_platforms, cl_platform_id **platforms, void *context)
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(* filter_device)(AVHWDeviceContext *hwdev, cl_device_id device_id, const char *device_name, void *context)
cl_command_queue command_queue
void * address[AV_NUM_DATA_POINTERS]
#define av_malloc_array(a, b)
static int ref[MAX_W *MAX_W]
static double cb(void *priv, double x, double y)