From 7e2252688b786eb51fb234141b264eaa7889ff90 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 18 Dec 2017 17:20:41 -0800 Subject: vo_mediacodec_embed: implement hwcontext Fixes vo_mediacodec_embed, which was broken in 80359c6615658f2784 --- video/out/vo_mediacodec_embed.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'video') diff --git a/video/out/vo_mediacodec_embed.c b/video/out/vo_mediacodec_embed.c index ff1e687f89..63975e9408 100644 --- a/video/out/vo_mediacodec_embed.c +++ b/video/out/vo_mediacodec_embed.c @@ -16,17 +16,44 @@ */ #include +#include +#include #include "common/common.h" #include "vo.h" #include "video/mp_image.h" +#include "video/hwdec.h" struct priv { struct mp_image *next_image; + struct mp_hwdec_ctx hwctx; }; +static AVBufferRef *create_mediacodec_device_ref(struct vo *vo) +{ + AVBufferRef *device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_MEDIACODEC); + if (!device_ref) + return NULL; + + AVHWDeviceContext *ctx = (void *)device_ref->data; + AVMediaCodecDeviceContext *hwctx = ctx->hwctx; + hwctx->surface = (void *)(intptr_t)(vo->opts->WinID); + + if (av_hwdevice_ctx_init(device_ref) < 0) + av_buffer_unref(&device_ref); + + return device_ref; +} + static int preinit(struct vo *vo) { + struct priv *p = vo->priv; + vo->hwdec_devs = hwdec_devices_create(); + p->hwctx = (struct mp_hwdec_ctx){ + .driver_name = "mediacodec_embed", + .av_device_ref = create_mediacodec_device_ref(vo), + }; + hwdec_devices_add(vo->hwdec_devs, &p->hwctx); return 0; } @@ -72,6 +99,9 @@ static void uninit(struct vo *vo) { struct priv *p = vo->priv; mp_image_unrefp(&p->next_image); + + hwdec_devices_remove(vo->hwdec_devs, &p->hwctx); + av_buffer_unref(&p->hwctx.av_device_ref); } const struct vo_driver video_out_mediacodec_embed = { -- cgit v1.2.3