You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
hwcontext_vulkan: improve CUDA error handling
This commit is contained in:
@@ -1550,8 +1550,10 @@ static int alloc_mem(AVHWDeviceContext *ctx, VkMemoryRequirements *req,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vulkan_free_internal(AVVkFrameInternal *internal)
|
static void vulkan_free_internal(AVVkFrame *f)
|
||||||
{
|
{
|
||||||
|
AVVkFrameInternal *internal = f->internal;
|
||||||
|
|
||||||
if (!internal)
|
if (!internal)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1577,7 +1579,7 @@ static void vulkan_free_internal(AVVkFrameInternal *internal)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
av_free(internal);
|
av_freep(&f->internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vulkan_frame_free(void *opaque, uint8_t *data)
|
static void vulkan_frame_free(void *opaque, uint8_t *data)
|
||||||
@@ -1593,7 +1595,7 @@ static void vulkan_frame_free(void *opaque, uint8_t *data)
|
|||||||
* issues tracking command buffer execution state on uninit. */
|
* issues tracking command buffer execution state on uninit. */
|
||||||
vk->DeviceWaitIdle(hwctx->act_dev);
|
vk->DeviceWaitIdle(hwctx->act_dev);
|
||||||
|
|
||||||
vulkan_free_internal(f->internal);
|
vulkan_free_internal(f);
|
||||||
|
|
||||||
for (int i = 0; i < planes; i++) {
|
for (int i = 0; i < planes; i++) {
|
||||||
vk->DestroyImage(hwctx->act_dev, f->img[i], hwctx->alloc);
|
vk->DestroyImage(hwctx->act_dev, f->img[i], hwctx->alloc);
|
||||||
@@ -2620,15 +2622,13 @@ static int vulkan_export_to_cuda(AVHWFramesContext *hwfc,
|
|||||||
if (!dst_f->internal)
|
if (!dst_f->internal)
|
||||||
dst_f->internal = dst_int = av_mallocz(sizeof(*dst_f->internal));
|
dst_f->internal = dst_int = av_mallocz(sizeof(*dst_f->internal));
|
||||||
|
|
||||||
if (!dst_int) {
|
if (!dst_int)
|
||||||
err = AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst_int->cuda_fc_ref = av_buffer_ref(cuda_hwfc);
|
dst_int->cuda_fc_ref = av_buffer_ref(cuda_hwfc);
|
||||||
if (!dst_int->cuda_fc_ref) {
|
if (!dst_int->cuda_fc_ref) {
|
||||||
err = AVERROR(ENOMEM);
|
av_freep(&dst_f->internal);
|
||||||
goto fail;
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < planes; i++) {
|
for (int i = 0; i < planes; i++) {
|
||||||
@@ -2669,7 +2669,8 @@ static int vulkan_export_to_cuda(AVHWFramesContext *hwfc,
|
|||||||
ret = vk->GetMemoryFdKHR(hwctx->act_dev, &export_info,
|
ret = vk->GetMemoryFdKHR(hwctx->act_dev, &export_info,
|
||||||
&ext_desc.handle.fd);
|
&ext_desc.handle.fd);
|
||||||
if (ret != VK_SUCCESS) {
|
if (ret != VK_SUCCESS) {
|
||||||
av_log(hwfc, AV_LOG_ERROR, "Unable to export the image as a FD!\n");
|
av_log(hwfc, AV_LOG_ERROR, "Unable to export the image as a FD: %s!\n",
|
||||||
|
vk_ret2str(ret));
|
||||||
err = AVERROR_EXTERNAL;
|
err = AVERROR_EXTERNAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@@ -2718,6 +2719,7 @@ static int vulkan_export_to_cuda(AVHWFramesContext *hwfc,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
vulkan_free_internal(dst_f);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2806,7 +2808,7 @@ static int vulkan_transfer_data_from_cuda(AVHWFramesContext *hwfc,
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
|
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
|
||||||
vulkan_free_internal(dst_int);
|
vulkan_free_internal(dst_f);
|
||||||
dst_f->internal = NULL;
|
dst_f->internal = NULL;
|
||||||
av_buffer_unref(&dst->buf[0]);
|
av_buffer_unref(&dst->buf[0]);
|
||||||
return err;
|
return err;
|
||||||
@@ -3631,7 +3633,7 @@ static int vulkan_transfer_data_to_cuda(AVHWFramesContext *hwfc, AVFrame *dst,
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
|
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
|
||||||
vulkan_free_internal(dst_int);
|
vulkan_free_internal(dst_f);
|
||||||
dst_f->internal = NULL;
|
dst_f->internal = NULL;
|
||||||
av_buffer_unref(&dst->buf[0]);
|
av_buffer_unref(&dst->buf[0]);
|
||||||
return err;
|
return err;
|
||||||
|
Reference in New Issue
Block a user