summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DOCS/man/options.rst5
-rw-r--r--options/options.c1
-rw-r--r--video/decode/hw_mediacodec.c47
-rw-r--r--video/decode/vd_lavc.c2
-rw-r--r--video/fmt-conversion.c3
-rw-r--r--video/hwdec.h1
-rw-r--r--video/img_format.h1
7 files changed, 60 insertions, 0 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index f5f668368e..c047e6d2d4 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -681,6 +681,7 @@ Video
:d3d11va: requires ``--vo=gpu`` with ``--gpu-context=angle``
(Windows 8+ only)
:d3d11va-copy: copies video back to system RAM (Windows 8+ only)
+ :mediacodec: requires ``--vo=mediacodec_embed`` (Android only)
:mediacodec-copy: copies video back to system RAM (Android only)
:rpi: requires ``--vo=gpu`` (Raspberry Pi only - default if available)
:rpi-copy: copies video back to system RAM (Raspberry Pi only)
@@ -2480,6 +2481,10 @@ Window
support window embedding of foreign processes, this works only with libmpv,
and will crash when used from the command line.
+ On Android, the ID is interpreted as ``android.view.Surface``. Pass it as a
+ value cast to ``intptr_t``. Use with ``--vo=mediacodec_embed`` and
+ ``--hwdec=mediacodec`` for direct rendering using MediaCodec.
+
``--no-window-dragging``
Don't move the window when clicking on it and moving the mouse pointer.
diff --git a/options/options.c b/options/options.c
index 857bb85271..eae58a45a4 100644
--- a/options/options.c
+++ b/options/options.c
@@ -111,6 +111,7 @@ const struct m_opt_choice_alternatives mp_hwdec_names[] = {
{"d3d11va-copy",HWDEC_D3D11VA_COPY},
{"rpi", HWDEC_RPI},
{"rpi-copy", HWDEC_RPI_COPY},
+ {"mediacodec", HWDEC_MEDIACODEC},
{"mediacodec-copy",HWDEC_MEDIACODEC_COPY},
{"cuda", HWDEC_CUDA},
{"cuda-copy", HWDEC_CUDA_COPY},
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 <http://www.gnu.org/licenses/>.
*/
+#include <stdbool.h>
+
+#include <libavcodec/mediacodec.h>
+
+#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
@@ -61,6 +61,9 @@ static const struct {
#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},
#if HAVE_D3D_HWACCEL
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