[FFmpeg-cvslog] hwcontext_vulkan: duplicate DMABUF objects before importing them
Lynne
git at videolan.org
Thu Mar 12 21:04:16 EET 2020
ffmpeg | branch: master | Lynne <dev at lynne.ee> | Thu Mar 12 18:03:43 2020 +0000| [b31959d776e6da3ff8519121bafae9753f2be20f] | committer: Lynne
hwcontext_vulkan: duplicate DMABUF objects before importing them
The specifications are very vague about who has ownership, and in this case,
Vulkan takes ownership of all DMABUF FDs passed to it, causing errors
to occur if someone gave us images for mapping which were meant to be kept.
The old behavior worked with one-way VAAPI and DMABUF imports, but was broken
with clients like wlroots' dmabuf-capture.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b31959d776e6da3ff8519121bafae9753f2be20f
---
libavutil/hwcontext_vulkan.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 6c2372f7fb..626b3ab5b7 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1699,15 +1699,16 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
VkImportMemoryFdInfoKHR idesc = {
.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
.handleType = htype,
- .fd = desc->objects[i].fd,
+ .fd = dup(desc->objects[i].fd),
};
ret = pfn_vkGetMemoryFdPropertiesKHR(hwctx->act_dev, htype,
- desc->objects[i].fd, &fdmp);
+ idesc.fd, &fdmp);
if (ret != VK_SUCCESS) {
av_log(hwfc, AV_LOG_ERROR, "Failed to get FD properties: %s\n",
vk_ret2str(ret));
err = AVERROR_EXTERNAL;
+ close(idesc.fd);
goto fail;
}
@@ -1715,8 +1716,10 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
err = alloc_mem(ctx, &req, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
&idesc, &f->flags, &f->mem[i]);
- if (err)
+ if (err) {
+ close(idesc.fd);
return err;
+ }
f->size[i] = desc->objects[i].size;
}
More information about the ffmpeg-cvslog
mailing list