Quoting Mark Thompson (2017-03-05 00:57:47)
> ---
> configure | 5 +-
> doc/APIchanges | 4 +
> libavutil/Makefile | 2 +
> libavutil/hwcontext.c | 4 +
> libavutil/hwcontext.h | 1 +
> libavutil/hwcontext_internal.h | 1 +
> libavutil/hwcontext_opencl.c | 1182
> ++++++++++++++++++++++++++++++++++++++++
> libavutil/hwcontext_opencl.h | 117 ++++
> libavutil/version.h | 2 +-
> 9 files changed, 1316 insertions(+), 2 deletions(-)
> create mode 100644 libavutil/hwcontext_opencl.c
> create mode 100644 libavutil/hwcontext_opencl.h
>
> +static int opencl_device_create_internal(AVHWDeviceContext *ctx,
> + const char *device,
> + AVDictionary *opts, int flags,
> + cl_context_properties *props)
> +{
> + cl_uint nb_platforms;
> + cl_platform_id *platforms = NULL;
> + cl_uint nb_devices;
> + cl_device_id *devices = NULL;
> + cl_device_type device_type;
> + AVOpenCLDeviceContext *hwctx = ctx->hwctx;
> + cl_int cle;
> + const AVDictionaryEntry *param;
> + cl_context_properties default_props[3];
> + char *str;
> + int p_index = -1, d_index = -1;
> + int ret, found, p, d, i;
> +
> + if (device && device[0]) {
> + // Match one or both indices for platform and device.
> + if (device[0] == '.')
> + ret = sscanf(device, ".%d", &d_index);
> + else
> + ret = sscanf(device, "%d.%d", &p_index, &d_index);
> + if (ret < 1) {
> + av_log(ctx, AV_LOG_ERROR, "Invalid OpenCL platform/device "
> + "index specification \"%s\".\n", device);
> + return AVERROR(EINVAL);
> + }
> + }
> +
> + cle = clGetPlatformIDs(0, NULL, &nb_platforms);
> + if (cle != CL_SUCCESS) {
> + av_log(ctx, AV_LOG_ERROR, "Failed to get number of "
> + "OpenCL platforms: %d.\n", cle);
> + ret = AVERROR(ENOSYS);
> + goto fail;
> + }
> + av_log(ctx, AV_LOG_DEBUG, "%d OpenCL platforms found.\n",
> + nb_platforms);
> +
> + platforms = av_malloc_array(nb_platforms, sizeof(*platforms));
> + if (!platforms) {
> + ret = AVERROR(ENOMEM);
> + goto fail;
> + }
> +
> + cle = clGetPlatformIDs(nb_platforms, platforms, NULL);
> + if (cle != CL_SUCCESS) {
> + av_log(ctx, AV_LOG_ERROR, "Failed to get list of OpenCL "
> + "platforms: %d.\n", cle);
> + ret = AVERROR(ENOSYS);
> + goto fail;
> + }
> +
> + param = av_dict_get(opts, "device_type", NULL, 0);
> + if (param) {
> + device_type = 0;
> + for (i = 0; i < FF_ARRAY_ELEMS(opencl_device_types); i++) {
> + if (!strcmp(opencl_device_types[i].key, param->value)) {
> + device_type = opencl_device_types[i].type;
> + break;
> + }
> + }
> + if (!device_type) {
> + av_log(ctx, AV_LOG_ERROR, "Unknown device type %s.\n",
> + param->value);
> + ret = AVERROR(EINVAL);
> + goto fail;
> + }
> + } else {
> + device_type = CL_DEVICE_TYPE_DEFAULT;
> + }
> +
> + found = 0;
> + for (p = 0; p < nb_platforms; p++) {
nit: i think moving the contents of the loop into a separate function
would make this easier to read
> +/**
> + * OpenCL frame descriptor for pool allocation.
> + *
> + * In user-allocated pools, AVHWFramesContext.pool must return AVBufferRefs
> + * with the data pointer pointing at an object of this type describing the
> + * planes of the frame.
> + */
> +typedef struct AVOpenCLFrameDescriptor {
> + /**
> + * OpenCL image2d objects for each plane of the frame. Unused fields
> + * must be set to NULL.
> + */
> + cl_mem image[AV_NUM_DATA_POINTERS];
> + /**
> + * Some combination of AV_OPENCL_FRAME_* flags.
> + */
> + int flags;
> + /**
> + * If AV_OPENCL_FRAME_IMAGE2D_FROM_BUFFER is set in flags, this contains
> + * the OpenCL buffer object from which all of the plane images were
> + * created.
> + */
> + cl_mem source_buffer;
> +} AVOpenCLFrameDescriptor;
> +
> +/**
> + * OpenCL device details.
> + *
> + * Allocated as AVHWDeviceContext.hwctx
> + */
> +typedef struct AVOpenCLDeviceContext {
> + /**
> + * The platform ID of the device.
> + */
> + cl_platform_id platform_id;
Can't you query this from the device?
More comments later.
--
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel