From b5181422369ef3e5773c7e15ab3004006322d065 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Sep 2014 23:07:56 +0200 Subject: build: handle insane libavcodec API bullshit The oldest supported FFmpeg release doesn't provide av_vdpau_alloc_context(). With these versions, the application has no other choice than to hard code the size of AVVDPAUContext. (On the other hand, there's av_alloc_vdpaucontext(), which does the same thing, but is FFmpeg specific - not sure if it was available early enough, so I'm not touching it.) Newer FFmpeg and Libav releases require you to call this function, for ABI compatibility reasons. It's the typcal lakc of foresight that make FFmpeg APIs terrible. mpv successfully pretended that this crap didn't exist (ABI compat. is near impossible to reach anyway) - but it appears newer developments in Libav change the function from initializing the struct with all-zeros to something else, and mpv vdpau decoding would stop working as soon as this new work is relewased. So, add a configure test (sigh). CC: @mpv-player/stable --- video/decode/vdpau.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'video') diff --git a/video/decode/vdpau.c b/video/decode/vdpau.c index 44850dfaec..f144176520 100644 --- a/video/decode/vdpau.c +++ b/video/decode/vdpau.c @@ -22,6 +22,7 @@ #include #include +#include "config.h" #include "lavc.h" #include "common/common.h" #include "common/av_common.h" @@ -36,7 +37,7 @@ struct priv { uint64_t preemption_counter; int fmt, w, h; - AVVDPAUContext context; + AVVDPAUContext *context; }; #define PE(av_codec_id, ff_profile, vdp_profile) \ @@ -76,8 +77,8 @@ static int init_decoder(struct lavc_ctx *ctx, int fmt, int w, int h) if (mp_vdpau_handle_preemption(p->mpvdp, &p->preemption_counter) < 0) return 0; - if (p->context.decoder != VDP_INVALID_HANDLE) - vdp->decoder_destroy(p->context.decoder); + if (p->context->decoder != VDP_INVALID_HANDLE) + vdp->decoder_destroy(p->context->decoder); const struct hwdec_profile_entry *pe = hwdec_find_profile(ctx, profiles); if (!pe) { @@ -104,14 +105,14 @@ static int init_decoder(struct lavc_ctx *ctx, int fmt, int w, int h) int maxrefs = hwdec_get_max_refs(ctx); vdp_st = vdp->decoder_create(vdp_device, pe->hw_profile, w, h, maxrefs, - &p->context.decoder); + &p->context->decoder); CHECK_VDP_WARNING(p, "Failed creating VDPAU decoder"); if (vdp_st != VDP_STATUS_OK) goto fail; return 0; fail: - p->context.decoder = VDP_INVALID_HANDLE; + p->context->decoder = VDP_INVALID_HANDLE; return -1; } @@ -138,9 +139,10 @@ static void uninit(struct lavc_ctx *ctx) if (!p) return; - if (p->context.decoder != VDP_INVALID_HANDLE) - p->vdp->decoder_destroy(p->context.decoder); + if (p->context && p->context->decoder != VDP_INVALID_HANDLE) + p->vdp->decoder_destroy(p->context->decoder); + av_free(p->context); talloc_free(p); ctx->hwdec_priv = NULL; @@ -155,16 +157,28 @@ static int init(struct lavc_ctx *ctx) }; ctx->hwdec_priv = p; +#if HAVE_AVCODEC_VDPAU_ALLOC_CONTEXT + p->context = av_vdpau_alloc_context(); +#else + p->context = av_mallocz(sizeof(AVVDPAUContext)); +#endif + if (!p->context) + goto error; + p->vdp = &p->mpvdp->vdp; - p->context.render = p->vdp->decoder_render; - p->context.decoder = VDP_INVALID_HANDLE; + p->context->render = p->vdp->decoder_render; + p->context->decoder = VDP_INVALID_HANDLE; if (mp_vdpau_handle_preemption(p->mpvdp, &p->preemption_counter) < 1) - return -1; + goto error; - ctx->avctx->hwaccel_context = &p->context; + ctx->avctx->hwaccel_context = p->context; return 0; + +error: + uninit(ctx); + return -1; } static int probe(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info, -- cgit v1.2.3