diff options
author | wm4 <wm4@nowhere> | 2015-05-28 21:53:37 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-05-28 21:53:37 +0200 |
commit | 939132cbd9d13e4f271b4ec3652598d793523374 (patch) | |
tree | acd7c0213bfb3050338b4fa15f0e7d6b18bf8a84 /video/decode | |
parent | a2eb0ab0766b0c565ff4ea9b7905cd060d841473 (diff) | |
download | mpv-939132cbd9d13e4f271b4ec3652598d793523374.tar.bz2 mpv-939132cbd9d13e4f271b4ec3652598d793523374.tar.xz |
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.
Diffstat (limited to 'video/decode')
-rw-r--r-- | video/decode/vd_lavc.c | 42 |
1 files changed, 15 insertions, 27 deletions
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; |