History

hwcontext: add av_hwdevice_ctx_create_derived_opts

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).

Lynne committed 6 years ago

Commit 2e08b391 parent 9576e4910 files · +55 −18Browse files

Unified · Split

10 files
  1. doc/APIchanges +3 −0
  2. libavutil/hwcontext.c +13 −3
  3. libavutil/hwcontext.h +20 −0
  4. libavutil/hwcontext_cuda.c +1 −1
  5. libavutil/hwcontext_internal.h +2 −1
  6. libavutil/hwcontext_opencl.c +6 −6
  7. libavutil/hwcontext_qsv.c +2 −1
  8. libavutil/hwcontext_vaapi.c +2 −1
  9. libavutil/hwcontext_vulkan.c +5 −4
  10. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2017-10-21 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2020-05-23 - xxxxxxxxxx - lavu 56.48.100 - hwcontext.h
19+ Add av_hwdevice_ctx_create_derived_opts.
20+
1821 2020-05-23 - xxxxxxxxxx - lavu 56.47.100 - rational.h
1922 Add av_gcd_q().
2023
libavutil/hwcontext.c+13−3
@@ -643,9 +643,10 @@ fail: · 642 unmodified lines
643643 return ret;
644644 }
645645
646−int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
647− enum AVHWDeviceType type,
648− AVBufferRef *src_ref, int flags)
646+int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
647+ enum AVHWDeviceType type,
648+ AVBufferRef *src_ref,
649+ AVDictionary *options, int flags)
649650 {
650651 AVBufferRef *dst_ref = NULL, *tmp_ref;
651652 AVHWDeviceContext *dst_ctx, *tmp_ctx;
@@ -678,6 +679,7 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, · 26 unmodified lines
678679 if (dst_ctx->internal->hw_type->device_derive) {
679680 ret = dst_ctx->internal->hw_type->device_derive(dst_ctx,
680681 tmp_ctx,
682+ options,
681683 flags);
682684 if (ret == 0) {
683685 dst_ctx->internal->source_device = av_buffer_ref(src_ref);
@@ -709,6 +711,14 @@ fail: · 25 unmodified lines
709711 return ret;
710712 }
711713
714+int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr,
715+ enum AVHWDeviceType type,
716+ AVBufferRef *src_ref, int flags)
717+{
718+ return av_hwdevice_ctx_create_derived_opts(dst_ref_ptr, type, src_ref,
719+ NULL, flags);
720+}
721+
712722 static void ff_hwframe_unmap(void *opaque, uint8_t *data)
713723 {
714724 HWMapDescriptor *hwmap = (HWMapDescriptor*)data;
libavutil/hwcontext.h+20−0
@@ -328,6 +328,26 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ctx, · 327 unmodified lines
328328 enum AVHWDeviceType type,
329329 AVBufferRef *src_ctx, int flags);
330330
331+/**
332+ * Create a new device of the specified type from an existing device.
333+ *
334+ * This function performs the same action as av_hwdevice_ctx_create_derived,
335+ * however, it is able to set options for the new device to be derived.
336+ *
337+ * @param dst_ctx On success, a reference to the newly-created
338+ * AVHWDeviceContext.
339+ * @param type The type of the new device to create.
340+ * @param src_ctx A reference to an existing AVHWDeviceContext which will be
341+ * used to create the new device.
342+ * @param options Options for the new device to create, same format as in
343+ * av_hwdevice_ctx_create.
344+ * @param flags Currently unused; should be set to zero.
345+ * @return Zero on success, a negative AVERROR code on failure.
346+ */
347+int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ctx,
348+ enum AVHWDeviceType type,
349+ AVBufferRef *src_ctx,
350+ AVDictionary *options, int flags);
331351
332352 /**
333353 * Allocate an AVHWFramesContext tied to a given device context.
libavutil/hwcontext_cuda.c+1−1
@@ -395,7 +395,7 @@ error: · 394 unmodified lines
395395 }
396396
397397 static int cuda_device_derive(AVHWDeviceContext *device_ctx,
398− AVHWDeviceContext *src_ctx,
398+ AVHWDeviceContext *src_ctx, AVDictionary *opts,
399399 int flags) {
400400 AVCUDADeviceContext *hwctx = device_ctx->hwctx;
401401 CudaFunctions *cu;
libavutil/hwcontext_internal.h+2−1
@@ -67,7 +67,8 @@ typedef struct HWContextType { · 66 unmodified lines
6767 int (*device_create)(AVHWDeviceContext *ctx, const char *device,
6868 AVDictionary *opts, int flags);
6969 int (*device_derive)(AVHWDeviceContext *dst_ctx,
70− AVHWDeviceContext *src_ctx, int flags);
70+ AVHWDeviceContext *src_ctx,
71+ AVDictionary *opts, int flags);
7172
7273 int (*device_init)(AVHWDeviceContext *ctx);
7374 void (*device_uninit)(AVHWDeviceContext *ctx);
libavutil/hwcontext_opencl.c+6−6
@@ -1194,7 +1194,7 @@ static int opencl_filter_drm_arm_device(AVHWDeviceContext *hwdev, · 1193 unmodified lines
11941194 #endif
11951195
11961196 static int opencl_device_derive(AVHWDeviceContext *hwdev,
1197− AVHWDeviceContext *src_ctx,
1197+ AVHWDeviceContext *src_ctx, AVDictionary *opts,
11981198 int flags)
11991199 {
12001200 int err;
@@ -1207,16 +1207,16 @@ static int opencl_device_derive(AVHWDeviceContext *hwdev, · 6 unmodified lines
12071207 // Surface mapping works via DRM PRIME fds with no special
12081208 // initialisation required in advance. This just finds the
12091209 // Beignet ICD by name.
1210− AVDictionary *opts = NULL;
1210+ AVDictionary *selector_opts = NULL;
12111211
1212− err = av_dict_set(&opts, "platform_vendor", "Intel", 0);
1212+ err = av_dict_set(&selector_opts, "platform_vendor", "Intel", 0);
12131213 if (err >= 0)
1214− err = av_dict_set(&opts, "platform_version", "beignet", 0);
1214+ err = av_dict_set(&selector_opts, "platform_version", "beignet", 0);
12151215 if (err >= 0) {
12161216 OpenCLDeviceSelector selector = {
12171217 .platform_index = -1,
12181218 .device_index = 0,
1219− .context = opts,
1219+ .context = selector_opts,
12201220 .enumerate_platforms = &opencl_enumerate_platforms,
12211221 .filter_platform = &opencl_filter_platform,
12221222 .enumerate_devices = &opencl_enumerate_devices,
@@ -1224,7 +1224,7 @@ static int opencl_device_derive(AVHWDeviceContext *hwdev, · 1 unmodified line
12241224 };
12251225 err = opencl_device_create_internal(hwdev, &selector, NULL);
12261226 }
1227− av_dict_free(&opts);
1227+ av_dict_free(&selector_opts);
12281228 }
12291229 break;
12301230 #endif
libavutil/hwcontext_qsv.c+2−1
@@ -1213,7 +1213,8 @@ fail: · 1212 unmodified lines
12131213 }
12141214
12151215 static int qsv_device_derive(AVHWDeviceContext *ctx,
1216− AVHWDeviceContext *child_device_ctx, int flags)
1216+ AVHWDeviceContext *child_device_ctx,
1217+ AVDictionary *opts, int flags)
12171218 {
12181219 return qsv_device_derive_from_child(ctx, MFX_IMPL_HARDWARE_ANY,
12191220 child_device_ctx, flags);
libavutil/hwcontext_vaapi.c+2−1
@@ -1624,7 +1624,8 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, · 1623 unmodified lines
16241624 }
16251625
16261626 static int vaapi_device_derive(AVHWDeviceContext *ctx,
1627− AVHWDeviceContext *src_ctx, int flags)
1627+ AVHWDeviceContext *src_ctx,
1628+ AVDictionary *opts, int flags)
16281629 {
16291630 #if HAVE_VAAPI_DRM
16301631 if (src_ctx->type == AV_HWDEVICE_TYPE_DRM) {
libavutil/hwcontext_vulkan.c+5−4
@@ -950,7 +950,8 @@ static int vulkan_device_create(AVHWDeviceContext *ctx, const char *device, · 949 unmodified lines
950950 }
951951
952952 static int vulkan_device_derive(AVHWDeviceContext *ctx,
953− AVHWDeviceContext *src_ctx, int flags)
953+ AVHWDeviceContext *src_ctx,
954+ AVDictionary *opts, int flags)
954955 {
955956 av_unused VulkanDeviceSelection dev_select = { 0 };
956957
@@ -974,7 +975,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx, · 17 unmodified lines
974975 if (strstr(vendor, "AMD"))
975976 dev_select.vendor_id = 0x1002;
976977
977− return vulkan_device_create_internal(ctx, &dev_select, NULL, flags);
978+ return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
978979 }
979980 #endif
980981 case AV_HWDEVICE_TYPE_DRM: {
@@ -992,7 +993,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx, · 11 unmodified lines
992993
993994 drmFreeDevice(&drm_dev_info);
994995
995− return vulkan_device_create_internal(ctx, &dev_select, NULL, flags);
996+ return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
996997 }
997998 #endif
998999 #if CONFIG_CUDA
@@ -1011,7 +1012,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx, · 12 unmodified lines
10111012
10121013 dev_select.has_uuid = 1;
10131014
1014− return vulkan_device_create_internal(ctx, &dev_select, NULL, flags);
1015+ return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
10151016 }
10161017 #endif
10171018 default:
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 56
82−#define LIBAVUTIL_VERSION_MINOR 47
82+#define LIBAVUTIL_VERSION_MINOR 48
8383 #define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t