avutil/hwcontext_cuda: Allocate public and internal device ctx jointly
Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
8d277de009
commit
ac7e72972c
@ -35,6 +35,11 @@ typedef struct CUDAFramesContext {
|
|||||||
int tex_alignment;
|
int tex_alignment;
|
||||||
} CUDAFramesContext;
|
} CUDAFramesContext;
|
||||||
|
|
||||||
|
typedef struct CUDADeviceContext {
|
||||||
|
AVCUDADeviceContext p;
|
||||||
|
AVCUDADeviceContextInternal internal;
|
||||||
|
} CUDADeviceContext;
|
||||||
|
|
||||||
static const enum AVPixelFormat supported_formats[] = {
|
static const enum AVPixelFormat supported_formats[] = {
|
||||||
AV_PIX_FMT_NV12,
|
AV_PIX_FMT_NV12,
|
||||||
AV_PIX_FMT_YUV420P,
|
AV_PIX_FMT_YUV420P,
|
||||||
@ -282,39 +287,35 @@ exit:
|
|||||||
|
|
||||||
static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
|
static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
|
||||||
{
|
{
|
||||||
AVCUDADeviceContext *hwctx = device_ctx->hwctx;
|
CUDADeviceContext *hwctx = device_ctx->hwctx;
|
||||||
|
|
||||||
if (hwctx->internal) {
|
if (hwctx->p.internal) {
|
||||||
CudaFunctions *cu = hwctx->internal->cuda_dl;
|
CudaFunctions *cu = hwctx->internal.cuda_dl;
|
||||||
|
|
||||||
if (hwctx->internal->is_allocated && hwctx->cuda_ctx) {
|
if (hwctx->internal.is_allocated && hwctx->p.cuda_ctx) {
|
||||||
if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT)
|
if (hwctx->internal.flags & AV_CUDA_USE_PRIMARY_CONTEXT)
|
||||||
CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device));
|
CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal.cuda_device));
|
||||||
else if (!(hwctx->internal->flags & AV_CUDA_USE_CURRENT_CONTEXT))
|
else if (!(hwctx->internal.flags & AV_CUDA_USE_CURRENT_CONTEXT))
|
||||||
CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx));
|
CHECK_CU(cu->cuCtxDestroy(hwctx->p.cuda_ctx));
|
||||||
|
|
||||||
hwctx->cuda_ctx = NULL;
|
hwctx->p.cuda_ctx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cuda_free_functions(&hwctx->internal->cuda_dl);
|
cuda_free_functions(&hwctx->internal.cuda_dl);
|
||||||
|
memset(&hwctx->internal, 0, sizeof(hwctx->internal));
|
||||||
|
hwctx->p.internal = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
av_freep(&hwctx->internal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cuda_device_init(AVHWDeviceContext *ctx)
|
static int cuda_device_init(AVHWDeviceContext *ctx)
|
||||||
{
|
{
|
||||||
AVCUDADeviceContext *hwctx = ctx->hwctx;
|
CUDADeviceContext *hwctx = ctx->hwctx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!hwctx->internal) {
|
hwctx->p.internal = &hwctx->internal;
|
||||||
hwctx->internal = av_mallocz(sizeof(*hwctx->internal));
|
|
||||||
if (!hwctx->internal)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hwctx->internal->cuda_dl) {
|
if (!hwctx->internal.cuda_dl) {
|
||||||
ret = cuda_load_functions(&hwctx->internal->cuda_dl, ctx);
|
ret = cuda_load_functions(&hwctx->internal.cuda_dl, ctx);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "Could not dynamically load CUDA\n");
|
av_log(ctx, AV_LOG_ERROR, "Could not dynamically load CUDA\n");
|
||||||
goto error;
|
goto error;
|
||||||
@ -562,7 +563,7 @@ const HWContextType ff_hwcontext_type_cuda = {
|
|||||||
.type = AV_HWDEVICE_TYPE_CUDA,
|
.type = AV_HWDEVICE_TYPE_CUDA,
|
||||||
.name = "CUDA",
|
.name = "CUDA",
|
||||||
|
|
||||||
.device_hwctx_size = sizeof(AVCUDADeviceContext),
|
.device_hwctx_size = sizeof(CUDADeviceContext),
|
||||||
.frames_hwctx_size = sizeof(CUDAFramesContext),
|
.frames_hwctx_size = sizeof(CUDAFramesContext),
|
||||||
|
|
||||||
.device_create = cuda_device_create,
|
.device_create = cuda_device_create,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user