From 939132cbd9d13e4f271b4ec3652598d793523374 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 28 May 2015 21:53:37 +0200 Subject: vd_lavc: merge two functions There's not much of a reason to keep get_surface_hwdec() and get_buffer2_hwdec() separate. Actually, the way the mpi->AVFrame referencing is done makes this confusing. The separation is probably an artifact of the pre-libavcodec-refcounting compatibility glue. --- video/decode/vd_lavc.c | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'video/decode/vd_lavc.c') diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index b00e6ab01e..c0209cab21 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -539,10 +539,20 @@ static enum AVPixelFormat get_format_hwdec(struct AVCodecContext *avctx, return fmt[0]; } -static struct mp_image *get_surface_hwdec(struct dec_video *vd, AVFrame *pic) +static void free_mpi(void *opaque, uint8_t *data) { + struct mp_image *mpi = opaque; + talloc_free(mpi); +} + +static int get_buffer2_hwdec(AVCodecContext *avctx, AVFrame *pic, int flags) +{ + struct dec_video *vd = avctx->opaque; vd_ffmpeg_ctx *ctx = vd->priv; + if (ctx->hwdec_failed) + return avcodec_default_get_buffer2(avctx, pic, flags); + /* Decoders using ffmpeg's hwaccel architecture (everything except vdpau) * can fall back to software decoding automatically. However, we don't * want that: multithreading was already disabled. ffmpeg's fallback @@ -556,7 +566,7 @@ static struct mp_image *get_surface_hwdec(struct dec_video *vd, AVFrame *pic) */ int imgfmt = pixfmt2imgfmt(pic->format); if (!IMGFMT_IS_HWACCEL(imgfmt) || !ctx->hwdec) - return NULL; + return -1; // Using frame->width/height is bad. For non-mod 16 video (which would // require alignment of frame sizes) we want the decoded size, not the @@ -567,37 +577,15 @@ static struct mp_image *get_surface_hwdec(struct dec_video *vd, AVFrame *pic) if (ctx->hwdec->init_decoder) { if (imgfmt != ctx->hwdec_fmt && w != ctx->hwdec_w && h != ctx->hwdec_h) - return NULL; + return -1; } struct mp_image *mpi = ctx->hwdec->allocate_image(ctx, imgfmt, w, h); - - if (mpi) { - for (int i = 0; i < 4; i++) - pic->data[i] = mpi->planes[i]; - } - - return mpi; -} - -static void free_mpi(void *opaque, uint8_t *data) -{ - struct mp_image *mpi = opaque; - talloc_free(mpi); -} - -static int get_buffer2_hwdec(AVCodecContext *avctx, AVFrame *pic, int flags) -{ - struct dec_video *vd = avctx->opaque; - vd_ffmpeg_ctx *ctx = vd->priv; - - if (ctx->hwdec_failed) - return avcodec_default_get_buffer2(avctx, pic, flags); - - struct mp_image *mpi = get_surface_hwdec(vd, pic); if (!mpi) return -1; + for (int i = 0; i < 4; i++) + pic->data[i] = mpi->planes[i]; pic->buf[0] = av_buffer_create(NULL, 0, free_mpi, mpi, 0); return 0; -- cgit v1.2.3