]> git.sesse.net Git - ffmpeg/commitdiff
hwcontext: add av_hwdevice_ctx_create_derived_opts
authorLynne <dev@lynne.ee>
Wed, 20 May 2020 19:58:03 +0000 (20:58 +0100)
committerLynne <dev@lynne.ee>
Sat, 23 May 2020 18:07:26 +0000 (19:07 +0100)
This allows for users who derive devices to set options for the
new device context they derive.
The main use case of this is to allow users to enable extensions
(such as surface drawing extensions) in Vulkan while deriving from
the device their frames are on. That way, users don't need to write
any initialization code themselves, since the Vulkan spec invalidates
mixing instances, physical devices and active devices.
Apart from Vulkan, other hwcontexts ignore the opts argument since they
don't support options at all (or in VAAPI and OpenCL's case, options are
currently only used for device selection, which device_derive overrides).

doc/APIchanges
libavutil/hwcontext.c
libavutil/hwcontext.h
libavutil/hwcontext_cuda.c
libavutil/hwcontext_internal.h
libavutil/hwcontext_opencl.c
libavutil/hwcontext_qsv.c
libavutil/hwcontext_vaapi.c
libavutil/hwcontext_vulkan.c
libavutil/version.h

index b3de5df0b646809239daa333075cf9d4e3d3400c..24c81d856cb4a4321c9f58b474d2e0406284bc4d 100644 (file)
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2020-05-23 - xxxxxxxxxx - lavu 56.48.100 - hwcontext.h
+  Add av_hwdevice_ctx_create_derived_opts.
+
 2020-05-23 - xxxxxxxxxx - lavu 56.47.100 - rational.h
   Add av_gcd_q().
 
index 8cc91d9a28ff598652d976ff0f1ea7192bc01e90..d13d0f7c9bc294d5164f830d5b3cc23655355be2 100644 (file)
@@ -643,9 +643,10 @@ fail:
     return ret;
 }
 
-int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
-                                   enum AVHWDeviceType type,
-                                   AVBufferRef *src_ref, int flags)
+int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
+                                        enum AVHWDeviceType type,
+                                        AVBufferRef *src_ref,
+                                        AVDictionary *options, int flags)
 {
     AVBufferRef *dst_ref = NULL, *tmp_ref;
     AVHWDeviceContext *dst_ctx, *tmp_ctx;
@@ -678,6 +679,7 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
         if (dst_ctx->internal->hw_type->device_derive) {
             ret = dst_ctx->internal->hw_type->device_derive(dst_ctx,
                                                             tmp_ctx,
+                                                            options,
                                                             flags);
             if (ret == 0) {
                 dst_ctx->internal->source_device = av_buffer_ref(src_ref);
@@ -709,6 +711,14 @@ fail:
     return ret;
 }
 
+int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
+                                   enum AVHWDeviceType type,
+                                   AVBufferRef *src_ref, int flags)
+{
+    return av_hwdevice_ctx_create_derived_opts(dst_ref_ptr, type, src_ref,
+                                               NULL, flags);
+}
+
 static void ff_hwframe_unmap(void *opaque, uint8_t *data)
 {
     HWMapDescriptor *hwmap = (HWMapDescriptor*)data;
index f874af9f8fc1d76709d638e5b5cc92b0a5d2a08a..04d19d89c2b8567788b95d8faa82a9af58618e2f 100644 (file)
@@ -328,6 +328,26 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ctx,
                                    enum AVHWDeviceType type,
                                    AVBufferRef *src_ctx, int flags);
 
+/**
+ * Create a new device of the specified type from an existing device.
+ *
+ * This function performs the same action as av_hwdevice_ctx_create_derived,
+ * however, it is able to set options for the new device to be derived.
+ *
+ * @param dst_ctx On success, a reference to the newly-created
+ *                AVHWDeviceContext.
+ * @param type    The type of the new device to create.
+ * @param src_ctx A reference to an existing AVHWDeviceContext which will be
+ *                used to create the new device.
+ * @param options Options for the new device to create, same format as in
+ *                av_hwdevice_ctx_create.
+ * @param flags   Currently unused; should be set to zero.
+ * @return        Zero on success, a negative AVERROR code on failure.
+ */
+int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ctx,
+                                        enum AVHWDeviceType type,
+                                        AVBufferRef *src_ctx,
+                                        AVDictionary *options, int flags);
 
 /**
  * Allocate an AVHWFramesContext tied to a given device context.
index 58d128a280c5eb68a765ac3a5f3af63dcd8e0c4b..718a449b6e6e93a4776644ae511215c6c1cc2e39 100644 (file)
@@ -395,7 +395,7 @@ error:
 }
 
 static int cuda_device_derive(AVHWDeviceContext *device_ctx,
-                              AVHWDeviceContext *src_ctx,
+                              AVHWDeviceContext *src_ctx, AVDictionary *opts,
                               int flags) {
     AVCUDADeviceContext *hwctx = device_ctx->hwctx;
     CudaFunctions *cu;
index dba0f39944ced00de6dd655f5c6f57dbb4d8d933..e6266494ac73cb825d8e24970268382673865bf1 100644 (file)
@@ -67,7 +67,8 @@ typedef struct HWContextType {
     int              (*device_create)(AVHWDeviceContext *ctx, const char *device,
                                       AVDictionary *opts, int flags);
     int              (*device_derive)(AVHWDeviceContext *dst_ctx,
-                                      AVHWDeviceContext *src_ctx, int flags);
+                                      AVHWDeviceContext *src_ctx,
+                                      AVDictionary *opts, int flags);
 
     int              (*device_init)(AVHWDeviceContext *ctx);
     void             (*device_uninit)(AVHWDeviceContext *ctx);
index 41fdfe96f1a08a5640ed9017a4c39b9e79c463fd..cd8638abbb9cecf0253b2d70ec2aef078d78b173 100644 (file)
@@ -1194,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;
@@ -1207,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,
@@ -1224,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
index 40794558fb244e291f8e9578b4fab44d7af5c70e..35a944f8f8a2b39e399d585fd14e75c28825ae2b 100644 (file)
@@ -1213,7 +1213,8 @@ fail:
 }
 
 static int qsv_device_derive(AVHWDeviceContext *ctx,
-                             AVHWDeviceContext *child_device_ctx, int flags)
+                             AVHWDeviceContext *child_device_ctx,
+                             AVDictionary *opts, int flags)
 {
     return qsv_device_derive_from_child(ctx, MFX_IMPL_HARDWARE_ANY,
                                         child_device_ctx, flags);
index b306965b4ada3040e0d457f6f974c23a5cb51c71..5c4f5de04ec6fafe1222641f2efe4f4e0da8fcda 100644 (file)
@@ -1624,7 +1624,8 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
 }
 
 static int vaapi_device_derive(AVHWDeviceContext *ctx,
-                               AVHWDeviceContext *src_ctx, int flags)
+                               AVHWDeviceContext *src_ctx,
+                               AVDictionary *opts, int flags)
 {
 #if HAVE_VAAPI_DRM
     if (src_ctx->type == AV_HWDEVICE_TYPE_DRM) {
index 262089f5dae2696404de2d89c2c358345a8b9cd9..b40974dce4643ebb6f43f2579690e6685a0416d0 100644 (file)
@@ -950,7 +950,8 @@ static int vulkan_device_create(AVHWDeviceContext *ctx, const char *device,
 }
 
 static int vulkan_device_derive(AVHWDeviceContext *ctx,
-                                AVHWDeviceContext *src_ctx, int flags)
+                                AVHWDeviceContext *src_ctx,
+                                AVDictionary *opts, int flags)
 {
     av_unused VulkanDeviceSelection dev_select = { 0 };
 
@@ -974,7 +975,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx,
         if (strstr(vendor, "AMD"))
             dev_select.vendor_id = 0x1002;
 
-        return vulkan_device_create_internal(ctx, &dev_select, NULL, flags);
+        return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
     }
 #endif
     case AV_HWDEVICE_TYPE_DRM: {
@@ -992,7 +993,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx,
 
         drmFreeDevice(&drm_dev_info);
 
-        return vulkan_device_create_internal(ctx, &dev_select, NULL, flags);
+        return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
     }
 #endif
 #if CONFIG_CUDA
@@ -1011,7 +1012,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx,
 
         dev_select.has_uuid = 1;
 
-        return vulkan_device_create_internal(ctx, &dev_select, NULL, flags);
+        return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
     }
 #endif
     default:
index f63cd4ba79a370d34101cbd947f447b2fb6398b9..5821bcdd0e20e76e8fd5f268dabf72f656025882 100644 (file)
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  47
+#define LIBAVUTIL_VERSION_MINOR  48
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \