From 61a1612de9c18d497c3be01f10b0fabc2066d76f Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 6 Jul 2017 10:54:40 -0700 Subject: hwdec: add mediacodec hardware decoder for IMGFMT_MEDIACODEC frames --- video/decode/hw_mediacodec.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ video/decode/vd_lavc.c | 2 ++ video/fmt-conversion.c | 3 +++ video/hwdec.h | 1 + video/img_format.h | 1 + 5 files changed, 54 insertions(+) (limited to 'video') diff --git a/video/decode/hw_mediacodec.c b/video/decode/hw_mediacodec.c index 9d3ef44f8b..b1a06c19ed 100644 --- a/video/decode/hw_mediacodec.c +++ b/video/decode/hw_mediacodec.c @@ -15,8 +15,55 @@ * License along with mpv. If not, see . */ +#include + +#include + +#include "options/options.h" #include "video/decode/lavc.h" +static int probe(struct lavc_ctx *ctx, struct vd_lavc_hwdec *hwdec, + const char *codec) +{ + if (ctx->opts->vo->WinID == 0) + return HWDEC_ERR_NO_CTX; + + return 0; +} + +static int init(struct lavc_ctx *ctx) +{ + return 0; +} + +static int init_decoder(struct lavc_ctx *ctx, int w, int h) +{ + av_mediacodec_default_free(ctx->avctx); + + AVMediaCodecContext *mcctx = av_mediacodec_alloc_context(); + if (!mcctx) + return -1; + + void *surface = (void *)(intptr_t)(ctx->opts->vo->WinID); + return av_mediacodec_default_init(ctx->avctx, mcctx, surface); +} + +static void uninit(struct lavc_ctx *ctx) +{ + if (ctx->avctx) + av_mediacodec_default_free(ctx->avctx); +} + +const struct vd_lavc_hwdec mp_vd_lavc_mediacodec = { + .type = HWDEC_MEDIACODEC, + .image_format = IMGFMT_MEDIACODEC, + .lavc_suffix = "_mediacodec", + .probe = probe, + .init = init, + .init_decoder = init_decoder, + .uninit = uninit, +}; + const struct vd_lavc_hwdec mp_vd_lavc_mediacodec_copy = { .type = HWDEC_MEDIACODEC_COPY, .lavc_suffix = "_mediacodec", diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index ec22b42571..fe0de0e43f 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -129,6 +129,7 @@ const struct m_sub_options vd_lavc_conf = { }, }; +extern const struct vd_lavc_hwdec mp_vd_lavc_mediacodec; extern const struct vd_lavc_hwdec mp_vd_lavc_mediacodec_copy; extern const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox; extern const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox_copy; @@ -261,6 +262,7 @@ static const struct vd_lavc_hwdec *const hwdec_list[] = { &mp_vd_lavc_d3d11va_copy, #endif #if HAVE_ANDROID + &mp_vd_lavc_mediacodec, &mp_vd_lavc_mediacodec_copy, #endif #if HAVE_CUDA_HWACCEL diff --git a/video/fmt-conversion.c b/video/fmt-conversion.c index 4288f82256..0bdbd109bb 100644 --- a/video/fmt-conversion.c +++ b/video/fmt-conversion.c @@ -60,6 +60,9 @@ static const struct { {IMGFMT_VDPAU, AV_PIX_FMT_VDPAU}, #if HAVE_VIDEOTOOLBOX_HWACCEL {IMGFMT_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX}, +#endif +#if HAVE_ANDROID + {IMGFMT_MEDIACODEC, AV_PIX_FMT_MEDIACODEC}, #endif {IMGFMT_VAAPI, AV_PIX_FMT_VAAPI}, {IMGFMT_DXVA2, AV_PIX_FMT_DXVA2_VLD}, diff --git a/video/hwdec.h b/video/hwdec.h index 379e754ffe..461ea6a3e6 100644 --- a/video/hwdec.h +++ b/video/hwdec.h @@ -22,6 +22,7 @@ enum hwdec_type { HWDEC_D3D11VA_COPY, HWDEC_RPI, HWDEC_RPI_COPY, + HWDEC_MEDIACODEC, HWDEC_MEDIACODEC_COPY, HWDEC_CUDA, HWDEC_CUDA_COPY, diff --git a/video/img_format.h b/video/img_format.h index 7f0330d55b..01d101aa8e 100644 --- a/video/img_format.h +++ b/video/img_format.h @@ -203,6 +203,7 @@ enum mp_imgfmt { IMGFMT_DXVA2, // IDirect3DSurface9 (NV12/P010/P016) IMGFMT_MMAL, // MMAL_BUFFER_HEADER_T IMGFMT_VIDEOTOOLBOX, // CVPixelBufferRef + IMGFMT_MEDIACODEC, // AVMediaCodecBuffer IMGFMT_CUDA, // CUDA Buffer // Generic pass-through of AV_PIX_FMT_*. Used for formats which don't have -- cgit v1.2.3