From 0da96385765840c418a789d06ec66c918b59d7ce Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 15 Aug 2013 18:20:15 +0200 Subject: video/decode: pass parameters directly to hwdec allocate_image callback Instead of passing AVFrame. This also moves the mysterious logic about the size of the allocated image to common code, instead of duplicating it everywhere. --- video/decode/lavc.h | 3 ++- video/decode/vaapi.c | 8 ++------ video/decode/vd_lavc.c | 6 +++++- video/decode/vdpau.c | 9 +++------ video/decode/vdpau_old.c | 8 ++------ 5 files changed, 14 insertions(+), 20 deletions(-) (limited to 'video') diff --git a/video/decode/lavc.h b/video/decode/lavc.h index 4252034b2c..f2ac5691d2 100644 --- a/video/decode/lavc.h +++ b/video/decode/lavc.h @@ -61,7 +61,8 @@ struct vd_lavc_hwdec { const char *decoder); int (*init)(struct lavc_ctx *ctx); void (*uninit)(struct lavc_ctx *ctx); - struct mp_image *(*allocate_image)(struct lavc_ctx *ctx, AVFrame *frame); + struct mp_image *(*allocate_image)(struct lavc_ctx *ctx, int fmt, + int w, int h); void (*fix_image)(struct lavc_ctx *ctx, struct mp_image *img); }; diff --git a/video/decode/vaapi.c b/video/decode/vaapi.c index baa13588c9..7294046bf4 100644 --- a/video/decode/vaapi.c +++ b/video/decode/vaapi.c @@ -324,18 +324,14 @@ error: return res; } -static struct mp_image *allocate_image(struct lavc_ctx *ctx, AVFrame *frame) +static struct mp_image *allocate_image(struct lavc_ctx *ctx, int format, + int w, int h) { struct priv *p = ctx->hwdec_priv; - int format = pixfmt2imgfmt(frame->format); if (!IMGFMT_IS_VAAPI(format)) return NULL; - // frame->width/height lie. Using them breaks with non-mod 16 video. - int w = ctx->avctx->width; - int h = ctx->avctx->height; - if (format != p->format || w != p->w || h != p->h || p->va_context->context_id == VA_INVALID_ID) { diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index 639e46ebcc..c899e53206 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -565,7 +565,11 @@ static struct mp_image *get_surface_hwdec(struct sh_video *sh, AVFrame *pic) if (!IMGFMT_IS_HWACCEL(imgfmt)) return NULL; - struct mp_image *mpi = ctx->hwdec->allocate_image(ctx, pic); + // frame->width/height lie. Using them breaks with non-mod 16 video. + int w = ctx->avctx->width; + int h = ctx->avctx->height; + + struct mp_image *mpi = ctx->hwdec->allocate_image(ctx, imgfmt, w, h); if (mpi) { for (int i = 0; i < 4; i++) diff --git a/video/decode/vdpau.c b/video/decode/vdpau.c index e20abdafca..e0d3241803 100644 --- a/video/decode/vdpau.c +++ b/video/decode/vdpau.c @@ -157,17 +157,14 @@ fail: return false; } -static struct mp_image *allocate_image(struct lavc_ctx *ctx, AVFrame *frame) +static struct mp_image *allocate_image(struct lavc_ctx *ctx, int fmt, + int w, int h) { struct priv *p = ctx->hwdec_priv; - if (frame->format != AV_PIX_FMT_VDPAU) + if (fmt != IMGFMT_VDPAU) return NULL; - // frame->width/height lie. Using them breaks with non-mod 16 video. - int w = ctx->avctx->width; - int h = ctx->avctx->height; - handle_preemption(ctx); if (w != p->vid_width || h != p->vid_height || diff --git a/video/decode/vdpau_old.c b/video/decode/vdpau_old.c index 4abdafa9c0..b5674dcec0 100644 --- a/video/decode/vdpau_old.c +++ b/video/decode/vdpau_old.c @@ -162,18 +162,14 @@ static void release_surface(void *ptr) talloc_free(state); } -static struct mp_image *allocate_image(struct lavc_ctx *ctx, AVFrame *frame) +static struct mp_image *allocate_image(struct lavc_ctx *ctx, int imgfmt, + int w, int h) { struct priv *p = ctx->hwdec_priv; - int imgfmt = pixfmt2imgfmt(frame->format); if (!IMGFMT_IS_VDPAU(imgfmt)) return NULL; - // frame->width/height lie. Using them breaks with non-mod 16 video. - int w = ctx->avctx->width; - int h = ctx->avctx->height; - if (w != p->vid_width || h != p->vid_height || imgfmt != p->image_format) { p->vid_width = w; p->vid_height = h; -- cgit v1.2.3