From 5757db844a449ed6a1e0fadb2bd62bae6852c78a Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 5 May 2017 00:44:03 +0200 Subject: cuda: add new way to set cuda context on cuvid codecs See FFmpeg commit c0f17a905f3588bf61ba6d86a83c6835d431ed3d. --- video/decode/hw_cuda.c | 11 +++++++++-- video/decode/lavc.h | 5 +++++ video/decode/vd_lavc.c | 14 +++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) (limited to 'video/decode') diff --git a/video/decode/hw_cuda.c b/video/decode/hw_cuda.c index d0c7669f25..64ee08d427 100644 --- a/video/decode/hw_cuda.c +++ b/video/decode/hw_cuda.c @@ -28,6 +28,8 @@ typedef void * CUcontext; #include "video/fmt-conversion.h" #include "video/decode/lavc.h" +#if !NEW_CUDA_HWACCEL + static int probe(struct lavc_ctx *ctx, struct vd_lavc_hwdec *hwdec, const char *codec) { @@ -47,6 +49,8 @@ static int init_decoder(struct lavc_ctx *ctx, int w, int h) AVCodecContext *avctx = ctx->avctx; struct mp_hwdec_ctx *hwctx = ctx->hwdec_priv; + MP_VERBOSE(ctx, "Using old cuda API.\n"); + if (avctx->hw_frames_ctx) { MP_ERR(ctx, "hw_frames_ctx already initialised!\n"); return -1; @@ -63,7 +67,8 @@ static int init_decoder(struct lavc_ctx *ctx, int w, int h) // This is proper use of the hw_frames_ctx API, but it does not work // (appaears to work but fails e.g. with 10 bit). The cuvid wrapper - // does non-standard things, and it's a messy situation. + // does non-standard things, and it's a messy situation. This whole + // file is actually used only with older libavcodec versions. /* hwframe_ctx->width = w; hwframe_ctx->height = h; @@ -92,7 +97,7 @@ static struct mp_image *process_image(struct lavc_ctx *ctx, struct mp_image *img return img; } -const struct vd_lavc_hwdec mp_vd_lavc_cuda = { +const struct vd_lavc_hwdec mp_vd_lavc_cuda_old = { .type = HWDEC_CUDA, .image_format = IMGFMT_CUDA, .lavc_suffix = "_cuvid", @@ -102,3 +107,5 @@ const struct vd_lavc_hwdec mp_vd_lavc_cuda = { .init_decoder = init_decoder, .process_image = process_image, }; + +#endif diff --git a/video/decode/lavc.h b/video/decode/lavc.h index a09929e29b..cc098b998e 100644 --- a/video/decode/lavc.h +++ b/video/decode/lavc.h @@ -5,6 +5,8 @@ #include +#include "config.h" + #include "demux/stheader.h" #include "video/mp_image.h" #include "video/mp_image_pool.h" @@ -139,4 +141,7 @@ int hwdec_setup_hw_frames_ctx(struct lavc_ctx *ctx, AVBufferRef *device_ctx, const char *hwdec_find_decoder(const char *codec, const char *suffix); +#define NEW_CUDA_HWACCEL \ + (HAVE_CUDA_HWACCEL && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 94, 100)) + #endif diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index d15f01768b..fe4409968a 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -131,7 +131,7 @@ extern const struct vd_lavc_hwdec mp_vd_lavc_dxva2; extern const struct vd_lavc_hwdec mp_vd_lavc_dxva2_copy; extern const struct vd_lavc_hwdec mp_vd_lavc_d3d11va; extern const struct vd_lavc_hwdec mp_vd_lavc_d3d11va_copy; -extern const struct vd_lavc_hwdec mp_vd_lavc_cuda; +extern const struct vd_lavc_hwdec mp_vd_lavc_cuda_old; #if HAVE_RPI static const struct vd_lavc_hwdec mp_vd_lavc_rpi = { @@ -154,6 +154,14 @@ static const struct vd_lavc_hwdec mp_vd_lavc_mediacodec = { }; #endif +#if NEW_CUDA_HWACCEL +static const struct vd_lavc_hwdec mp_vd_lavc_cuda = { + .type = HWDEC_CUDA, + .image_format = IMGFMT_CUDA, + .lavc_suffix = "_cuvid", + .generic_hwaccel = true, +}; +#endif #if HAVE_CUDA_HWACCEL static const struct vd_lavc_hwdec mp_vd_lavc_cuda_copy = { .type = HWDEC_CUDA_COPY, @@ -255,7 +263,11 @@ static const struct vd_lavc_hwdec *const hwdec_list[] = { &mp_vd_lavc_mediacodec, #endif #if HAVE_CUDA_HWACCEL + #if NEW_CUDA_HWACCEL &mp_vd_lavc_cuda, + #else + &mp_vd_lavc_cuda_old, + #endif &mp_vd_lavc_cuda_copy, #endif &mp_vd_lavc_crystalhd, -- cgit v1.2.3