Message ID | 20171204013222.36272-2-ffmpeg@tmm1.net |
---|---|
State | New |
Headers | show |
On Sun, Dec 03, 2017 at 05:32:22PM -0800, Aman Gupta wrote: > From: Aman Gupta <aman@tmm1.net> > > --- > libavcodec/mediacodecdec.c | 2 +- > libavcodec/mediacodecdec_common.c | 14 +++++++++++++- > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c > index 39f5cbc045..eabf6d0648 100644 > --- a/libavcodec/mediacodecdec.c > +++ b/libavcodec/mediacodecdec.c > @@ -520,7 +520,7 @@ static const AVCodecHWConfigInternal *mediacodec_hw_configs[] = { > &(const AVCodecHWConfigInternal) { > .public = { > .pix_fmt = AV_PIX_FMT_MEDIACODEC, > - .methods = AV_CODEC_HW_CONFIG_METHOD_AD_HOC, > + .methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX, > .device_type = AV_HWDEVICE_TYPE_NONE, > }, > .hwaccel = NULL, > diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c > index cb2f6ae5e5..a9147f3a08 100644 > --- a/libavcodec/mediacodecdec_common.c > +++ b/libavcodec/mediacodecdec_common.c > @@ -24,6 +24,7 @@ > #include <sys/types.h> > > #include "libavutil/common.h" > +#include "libavutil/hwcontext_mediacodec.h" > #include "libavutil/mem.h" > #include "libavutil/log.h" > #include "libavutil/pixfmt.h" > @@ -476,7 +477,18 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, > if (pix_fmt == AV_PIX_FMT_MEDIACODEC) { > AVMediaCodecContext *user_ctx = avctx->hwaccel_context; > > - if (user_ctx && user_ctx->surface) { > + if (avctx->hw_device_ctx) { > + AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data); > + if (device_ctx->type == AV_HWDEVICE_TYPE_MEDIACODEC) { > + if (device_ctx->hwctx) { > + AVMediaCodecDeviceContext *mediacodec_ctx = (AVMediaCodecDeviceContext *)device_ctx->hwctx; > + s->surface = ff_mediacodec_surface_ref(mediacodec_ctx->surface, avctx); > + av_log(avctx, AV_LOG_INFO, "Using surface %p\n", s->surface); > + } > + } > + } > + > + if (!s->surface && user_ctx && user_ctx->surface) { > s->surface = ff_mediacodec_surface_ref(user_ctx->surface, avctx); > av_log(avctx, AV_LOG_INFO, "Using surface %p\n", s->surface); > } [...] New patch attached fixing errors in get_format() by keeping the original AVCodecHWConfigInternal (ad-hoc) and adding a new one (hw-device) with the device_type field set to the MediaCodec. The updated patchset works without errors with both the old hwaccel method and the new device_ctx method. I'll push the patchset in 3 days if there is no objection. Regards,
diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index 39f5cbc045..eabf6d0648 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -520,7 +520,7 @@ static const AVCodecHWConfigInternal *mediacodec_hw_configs[] = { &(const AVCodecHWConfigInternal) { .public = { .pix_fmt = AV_PIX_FMT_MEDIACODEC, - .methods = AV_CODEC_HW_CONFIG_METHOD_AD_HOC, + .methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX, .device_type = AV_HWDEVICE_TYPE_NONE, }, .hwaccel = NULL, diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index cb2f6ae5e5..a9147f3a08 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -24,6 +24,7 @@ #include <sys/types.h> #include "libavutil/common.h" +#include "libavutil/hwcontext_mediacodec.h" #include "libavutil/mem.h" #include "libavutil/log.h" #include "libavutil/pixfmt.h" @@ -476,7 +477,18 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, if (pix_fmt == AV_PIX_FMT_MEDIACODEC) { AVMediaCodecContext *user_ctx = avctx->hwaccel_context; - if (user_ctx && user_ctx->surface) { + if (avctx->hw_device_ctx) { + AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data); + if (device_ctx->type == AV_HWDEVICE_TYPE_MEDIACODEC) { + if (device_ctx->hwctx) { + AVMediaCodecDeviceContext *mediacodec_ctx = (AVMediaCodecDeviceContext *)device_ctx->hwctx; + s->surface = ff_mediacodec_surface_ref(mediacodec_ctx->surface, avctx); + av_log(avctx, AV_LOG_INFO, "Using surface %p\n", s->surface); + } + } + } + + if (!s->surface && user_ctx && user_ctx->surface) { s->surface = ff_mediacodec_surface_ref(user_ctx->surface, avctx); av_log(avctx, AV_LOG_INFO, "Using surface %p\n", s->surface); }
From: Aman Gupta <aman@tmm1.net> --- libavcodec/mediacodecdec.c | 2 +- libavcodec/mediacodecdec_common.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)