From e0e79a2e7edaa86e680553a47f46ebbe78c98df9 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sun, 23 Mar 2014 17:56:05 +0100 Subject: vda: Hwaccel 1.2 support Use the new context and the default functions provided. --- video/decode/vda.c | 103 +++++++++++++++++++++++++++++++++---------------- video/fmt-conversion.c | 5 +++ 2 files changed, 74 insertions(+), 34 deletions(-) (limited to 'video') diff --git a/video/decode/vda.c b/video/decode/vda.c index a8d044c14f..acfadc7be2 100644 --- a/video/decode/vda.c +++ b/video/decode/vda.c @@ -26,6 +26,49 @@ #include "video/decode/lavc.h" #include "config.h" + +static int probe(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info, + const char *decoder) +{ + hwdec_request_api(info, "vda"); + + if (mp_codec_to_av_codec_id(decoder) != AV_CODEC_ID_H264) + return HWDEC_ERR_NO_CODEC; + return 0; +} + +#if HAVE_VDA_AV_VDA_ALLOC_CONTEXT + +static int init(struct lavc_ctx *ctx) +{ + return 0; +} + +static int init_decoder(struct lavc_ctx *ctx, int fmt, int w, int h) +{ + av_vda_default_free(ctx->avctx); + + if (av_vda_default_init(ctx->avctx) < 0) + return -1; + return 0; +} + +static void uninit(struct lavc_ctx *ctx) +{ + if (ctx->avctx) + av_vda_default_free(ctx->avctx); +} + +const struct vd_lavc_hwdec mp_vd_lavc_vda = { + .type = HWDEC_VDA, + .image_format = IMGFMT_VDA, + .probe = probe, + .init = init, + .uninit = uninit, + .init_decoder = init_decoder, +}; + +#else struct priv { struct vda_context vda_ctx; }; @@ -63,16 +106,6 @@ static void print_vda_error(struct mp_log *log, int lev, char *message, mp_msg(log, lev, "%s: %d\n", message, error_code); } -static int probe(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info, - const char *decoder) -{ - hwdec_request_api(info, "vda"); - - if (mp_codec_to_av_codec_id(decoder) != AV_CODEC_ID_H264) - return HWDEC_ERR_NO_CODEC; - return 0; -} - static int init_vda_decoder(struct lavc_ctx *ctx) { struct priv *p = ctx->hwdec_priv; @@ -130,6 +163,30 @@ static void uninit(struct lavc_ctx *ctx) { ff_vda_destroy_decoder(&p->vda_ctx); } +// This actually returns dummy images, since vda_264 creates it's own AVFrames +// to wrap CVPixelBuffers in planes[3]. +static struct mp_image *allocate_image(struct lavc_ctx *ctx, int fmt, + int w, int h) +{ + struct priv *p = ctx->hwdec_priv; + + if (fmt != IMGFMT_VDA) + return NULL; + + if (w != p->vda_ctx.width || h != p->vda_ctx.height) + init_vda_decoder(ctx); + + struct mp_image img = {0}; + mp_image_setfmt(&img, fmt); + mp_image_set_size(&img, w, h); + + // There is an `assert(!dst->f.buf[0])` in libavcodec/h264.c + // Setting the first plane to some dummy value allows to satisfy it + img.planes[0] = (void*)"dummy"; + + return mp_image_new_custom_ref(&img, NULL, NULL); +} + static void cv_retain(void *pbuf) { CVPixelBufferRetain((CVPixelBufferRef)pbuf); @@ -162,30 +219,6 @@ static struct mp_image *process_image(struct lavc_ctx *ctx, struct mp_image *mpi return cv_mpi; } -// This actually returns dummy images, since vda_264 creates it's own AVFrames -// to wrap CVPixelBuffers in planes[3]. -static struct mp_image *allocate_image(struct lavc_ctx *ctx, int fmt, - int w, int h) -{ - struct priv *p = ctx->hwdec_priv; - - if (fmt != IMGFMT_VDA) - return NULL; - - if (w != p->vda_ctx.width || h != p->vda_ctx.height) - init_vda_decoder(ctx); - - struct mp_image img = {0}; - mp_image_setfmt(&img, fmt); - mp_image_set_size(&img, w, h); - - // There is an `assert(!dst->f.buf[0])` in libavcodec/h264.c - // Setting the first plane to some dummy value allows to satisfy it - img.planes[0] = (void*)"dummy"; - - return mp_image_new_custom_ref(&img, NULL, NULL); -} - const struct vd_lavc_hwdec mp_vd_lavc_vda = { .type = HWDEC_VDA, .image_format = IMGFMT_VDA, @@ -195,3 +228,5 @@ const struct vd_lavc_hwdec mp_vd_lavc_vda = { .allocate_image = allocate_image, .process_image = process_image, }; + +#endif diff --git a/video/fmt-conversion.c b/video/fmt-conversion.c index bb296b596d..88e10c924e 100644 --- a/video/fmt-conversion.c +++ b/video/fmt-conversion.c @@ -21,6 +21,7 @@ #include "video/img_format.h" #include "fmt-conversion.h" +#include "config.h" static const struct { int fmt; @@ -172,7 +173,11 @@ static const struct { #endif {IMGFMT_VDPAU, AV_PIX_FMT_VDPAU}, +#if HAVE_VDA_AV_VDA_ALLOC_CONTEXT + {IMGFMT_VDA, AV_PIX_FMT_VDA}, +#else {IMGFMT_VDA, AV_PIX_FMT_VDA_VLD}, +#endif {IMGFMT_VAAPI, AV_PIX_FMT_VAAPI_VLD}, {0, AV_PIX_FMT_NONE} -- cgit v1.2.3