From e80a2a572dd7a426fc11b3776985b99460214d75 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 6 Jul 2017 10:58:26 -0700 Subject: vo: add mediacodec_embed output driver Allows rendering IMGFMT_MEDIACODEC frames directly onto an android.view.Surface --- DOCS/man/vo.rst | 8 ++++ video/out/vo.c | 4 ++ video/out/vo_mediacodec_embed.c | 89 +++++++++++++++++++++++++++++++++++++++++ wscript_build.py | 1 + 4 files changed, 102 insertions(+) create mode 100644 video/out/vo_mediacodec_embed.c diff --git a/DOCS/man/vo.rst b/DOCS/man/vo.rst index 84b3a6a9d9..5dac65a38a 100644 --- a/DOCS/man/vo.rst +++ b/DOCS/man/vo.rst @@ -504,3 +504,11 @@ Available video output drivers are: Mode ID to use (resolution, bit depth and frame rate). (default: 0) +``mediacodec_embed`` (Android) + Renders ``IMGFMT_MEDIACODEC`` frames directly to an ``android.view.Surface``. + Requires ``--hwdec=mediacodec`` for hardware decoding, along with + ``--vo=mediacodec_embed`` and ``--wid=(intptr_t)(*android.view.Surface)``. + + Since this video output driver uses native decoding and rendering routines, + many of mpv's features (subtitle rendering, OSD/OSC, video filters, etc) + are not available with this driver. diff --git a/video/out/vo.c b/video/out/vo.c index 6f0dbb3d33..ff8c381f60 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -47,6 +47,7 @@ #include "osdep/io.h" #include "osdep/threads.h" +extern const struct vo_driver video_out_android; extern const struct vo_driver video_out_x11; extern const struct vo_driver video_out_vdpau; extern const struct vo_driver video_out_xv; @@ -66,6 +67,9 @@ extern const struct vo_driver video_out_tct; const struct vo_driver *const video_out_drivers[] = { +#if HAVE_ANDROID + &video_out_android, +#endif #if HAVE_RPI &video_out_rpi, #endif diff --git a/video/out/vo_mediacodec_embed.c b/video/out/vo_mediacodec_embed.c new file mode 100644 index 0000000000..ff1e687f89 --- /dev/null +++ b/video/out/vo_mediacodec_embed.c @@ -0,0 +1,89 @@ +/* + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with mpv. If not, see . + */ + +#include + +#include "common/common.h" +#include "vo.h" +#include "video/mp_image.h" + +struct priv { + struct mp_image *next_image; +}; + +static int preinit(struct vo *vo) +{ + return 0; +} + +static void flip_page(struct vo *vo) +{ + struct priv *p = vo->priv; + if (!p->next_image) + return; + + AVMediaCodecBuffer *buffer = (AVMediaCodecBuffer *)p->next_image->planes[3]; + av_mediacodec_release_buffer(buffer, 1); + mp_image_unrefp(&p->next_image); +} + +static void draw_frame(struct vo *vo, struct vo_frame *frame) +{ + struct priv *p = vo->priv; + + mp_image_t *mpi = NULL; + if (!frame->redraw && !frame->repeat) + mpi = mp_image_new_ref(frame->current); + + talloc_free(p->next_image); + p->next_image = mpi; +} + +static int query_format(struct vo *vo, int format) +{ + return format == IMGFMT_MEDIACODEC; +} + +static int control(struct vo *vo, uint32_t request, void *data) +{ + return VO_NOTIMPL; +} + +static int reconfig(struct vo *vo, struct mp_image_params *params) +{ + return 0; +} + +static void uninit(struct vo *vo) +{ + struct priv *p = vo->priv; + mp_image_unrefp(&p->next_image); +} + +const struct vo_driver video_out_mediacodec_embed = { + .description = "Android (Embedded MediaCodec Surface)", + .name = "mediacodec_embed", + .caps = VO_CAP_NOREDRAW, + .preinit = preinit, + .query_format = query_format, + .control = control, + .draw_frame = draw_frame, + .flip_page = flip_page, + .reconfig = reconfig, + .uninit = uninit, + .priv_size = sizeof(struct priv), +}; diff --git a/wscript_build.py b/wscript_build.py index 1959959fe8..187ecfceae 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -446,6 +446,7 @@ def build(ctx): ( "video/out/opengl/hwdec_vaglx.c", "vaapi-glx" ), ( "video/out/opengl/hwdec_vdpau.c", "vdpau-gl-x11" ), ( "video/out/vo.c" ), + ( "video/out/vo_mediacodec_embed.c", "android" ), ( "video/out/vo_caca.c", "caca" ), ( "video/out/vo_drm.c", "drm" ), ( "video/out/vo_direct3d.c", "direct3d" ), -- cgit v1.2.3