cuda: add new way to set cuda context on cuvid codecs

See FFmpeg commit c0f17a905f3588bf61ba6d86a83c6835d431ed3d.
This commit is contained in:
wm4 2017-05-05 00:44:03 +02:00
parent 0d122f8963
commit 5757db844a
3 changed files with 27 additions and 3 deletions

View File

@ -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

View File

@ -5,6 +5,8 @@
#include <libavcodec/avcodec.h>
#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

View File

@ -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,