]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/hwcontext_opencl.c
avutil/buffer: Switch AVBuffer API to size_t
[ffmpeg] / libavutil / hwcontext_opencl.c
index 728877553f8207aa81a3b5f49c129bfe86dc23e0..41fac432297ca806d95501656bf725f8a603af05 100644 (file)
@@ -50,7 +50,7 @@
 #include <mfx/mfxstructures.h>
 #endif
 #include <va/va.h>
-#include <CL/va_ext.h>
+#include <CL/cl_va_api_media_sharing_intel.h>
 #include "hwcontext_vaapi.h"
 #endif
 
@@ -500,6 +500,9 @@ static int opencl_device_create_internal(AVHWDeviceContext *hwdev,
          *device_name_src   = NULL;
     int err, found, p, d;
 
+    av_assert0(selector->enumerate_platforms &&
+               selector->enumerate_devices);
+
     err = selector->enumerate_platforms(hwdev, &nb_platforms, &platforms,
                                         selector->context);
     if (err)
@@ -531,9 +534,9 @@ static int opencl_device_create_internal(AVHWDeviceContext *hwdev,
                 continue;
         }
 
-        err = opencl_enumerate_devices(hwdev, platforms[p], platform_name,
-                                       &nb_devices, &devices,
-                                       selector->context);
+        err = selector->enumerate_devices(hwdev, platforms[p], platform_name,
+                                          &nb_devices, &devices,
+                                          selector->context);
         if (err < 0)
             continue;
 
@@ -1191,7 +1194,7 @@ static int opencl_filter_drm_arm_device(AVHWDeviceContext *hwdev,
 #endif
 
 static int opencl_device_derive(AVHWDeviceContext *hwdev,
-                                AVHWDeviceContext *src_ctx,
+                                AVHWDeviceContext *src_ctx, AVDictionary *opts,
                                 int flags)
 {
     int err;
@@ -1204,16 +1207,16 @@ static int opencl_device_derive(AVHWDeviceContext *hwdev,
             // Surface mapping works via DRM PRIME fds with no special
             // initialisation required in advance.  This just finds the
             // Beignet ICD by name.
-            AVDictionary *opts = NULL;
+            AVDictionary *selector_opts = NULL;
 
-            err = av_dict_set(&opts, "platform_vendor", "Intel", 0);
+            err = av_dict_set(&selector_opts, "platform_vendor", "Intel", 0);
             if (err >= 0)
-                err = av_dict_set(&opts, "platform_version", "beignet", 0);
+                err = av_dict_set(&selector_opts, "platform_version", "beignet", 0);
             if (err >= 0) {
                 OpenCLDeviceSelector selector = {
                     .platform_index      = -1,
                     .device_index        = 0,
-                    .context             = opts,
+                    .context             = selector_opts,
                     .enumerate_platforms = &opencl_enumerate_platforms,
                     .filter_platform     = &opencl_filter_platform,
                     .enumerate_devices   = &opencl_enumerate_devices,
@@ -1221,7 +1224,7 @@ static int opencl_device_derive(AVHWDeviceContext *hwdev,
                 };
                 err = opencl_device_create_internal(hwdev, &selector, NULL);
             }
-            av_dict_free(&opts);
+            av_dict_free(&selector_opts);
         }
         break;
 #endif
@@ -1416,8 +1419,9 @@ static int opencl_get_plane_format(enum AVPixelFormat pixfmt,
         // from the same component.
         if (step && comp->step != step)
             return AVERROR(EINVAL);
-        order = order * 10 + c + 1;
+
         depth = comp->depth;
+        order = order * 10 + comp->offset / ((depth + 7) / 8) + 1;
         step  = comp->step;
         alpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA &&
                  c == desc->nb_components - 1);
@@ -1453,14 +1457,10 @@ static int opencl_get_plane_format(enum AVPixelFormat pixfmt,
     case order: image_format->image_channel_order = type; break;
     switch (order) {
         CHANNEL_ORDER(1,    CL_R);
-        CHANNEL_ORDER(2,    CL_R);
-        CHANNEL_ORDER(3,    CL_R);
-        CHANNEL_ORDER(4,    CL_R);
         CHANNEL_ORDER(12,   CL_RG);
-        CHANNEL_ORDER(23,   CL_RG);
         CHANNEL_ORDER(1234, CL_RGBA);
+        CHANNEL_ORDER(2341, CL_ARGB);
         CHANNEL_ORDER(3214, CL_BGRA);
-        CHANNEL_ORDER(4123, CL_ARGB);
 #ifdef CL_ABGR
         CHANNEL_ORDER(4321, CL_ABGR);
 #endif
@@ -1617,7 +1617,7 @@ static void opencl_pool_free(void *opaque, uint8_t *data)
     av_free(desc);
 }
 
-static AVBufferRef *opencl_pool_alloc(void *opaque, int size)
+static AVBufferRef *opencl_pool_alloc(void *opaque, size_t size)
 {
     AVHWFramesContext      *hwfc = opaque;
     AVOpenCLDeviceContext *hwctx = hwfc->device_ctx->hwctx;
@@ -1726,10 +1726,13 @@ static void opencl_frames_uninit(AVHWFramesContext *hwfc)
     av_freep(&priv->mapped_frames);
 #endif
 
-    cle = clReleaseCommandQueue(priv->command_queue);
-    if (cle != CL_SUCCESS) {
-        av_log(hwfc, AV_LOG_ERROR, "Failed to release frame "
-               "command queue: %d.\n", cle);
+    if (priv->command_queue) {
+        cle = clReleaseCommandQueue(priv->command_queue);
+        if (cle != CL_SUCCESS) {
+            av_log(hwfc, AV_LOG_ERROR, "Failed to release frame "
+                   "command queue: %d.\n", cle);
+        }
+        priv->command_queue = NULL;
     }
 }