Re: [FFmpeg-devel] [PATCH v2 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set

2017-12-15 Thread Matthieu Bouron
On Tue, Dec 12, 2017 at 10:33:38AM +0100, Matthieu Bouron wrote:
> On Mon, Dec 11, 2017 at 10:10:24PM +, Mark Thompson wrote:
> > On 11/12/17 12:34, Matthieu Bouron wrote:
> > >>
> > >> 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.
> > > 
> > > From 2bbdae2141ba8ca8db54175f4440ac8190f5953d Mon Sep 17 00:00:00 2001
> > > From: Aman Gupta 
> > > Date: Sun, 3 Dec 2017 17:32:22 -0800
> > > Subject: [PATCH 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext
> > >  hw_device_ctx if set
> > > 
> > > Signed-off-by: Matthieu Bouron 
> > > ---
> > >  libavcodec/mediacodecdec.c|  8 
> > >  libavcodec/mediacodecdec_common.c | 14 +-
> > >  2 files changed, 21 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> > > index 86cc629430..c8ad0b80e7 100644
> > > --- a/libavcodec/mediacodecdec.c
> > > +++ b/libavcodec/mediacodecdec.c
> > > @@ -543,6 +543,14 @@ static const AVCodecHWConfigInternal 
> > > *mediacodec_hw_configs[] = {
> > >  },
> > >  .hwaccel = NULL,
> > >  },
> > > +&(const AVCodecHWConfigInternal) {
> > > +.public  = {
> > > +.pix_fmt = AV_PIX_FMT_MEDIACODEC,
> > > +.methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
> > 
> > This wants to be combined with the previous entry (or together the 
> > methods): ff_get_format() looks for the first entry matching the pix_fmt, 
> > so it will never find this one.  I think this might work anyway because 
> > AD_HOC is technically "do whatever you like, I can't check it", but it also 
> > wouldn't notice e.g. a non-matching device in that case.
> 
> Patch updated with the two entries merged. Thanks.
> I tested with both methods (hw device ctx and the old hwaccel way) and no
> error came up.
> 
> -- 
> Matthieu B.

> From 7266745203a2467719f21a31c8b4f94390eaeb6b Mon Sep 17 00:00:00 2001
> From: Aman Gupta 
> Date: Sun, 3 Dec 2017 17:32:22 -0800
> Subject: [PATCH 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext
>  hw_device_ctx if set
> 
> Signed-off-by: Matthieu Bouron 
> ---
>  libavcodec/mediacodecdec.c|  5 +++--
>  libavcodec/mediacodecdec_common.c | 14 +-
>  2 files changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> index 86cc629430..7b282a1d68 100644
> --- a/libavcodec/mediacodecdec.c
> +++ b/libavcodec/mediacodecdec.c
> @@ -538,8 +538,9 @@ static const AVCodecHWConfigInternal 
> *mediacodec_hw_configs[] = {
>  &(const AVCodecHWConfigInternal) {
>  .public  = {
>  .pix_fmt = AV_PIX_FMT_MEDIACODEC,
> -.methods = AV_CODEC_HW_CONFIG_METHOD_AD_HOC,
> -.device_type = AV_HWDEVICE_TYPE_NONE,
> +.methods = AV_CODEC_HW_CONFIG_METHOD_AD_HOC |
> +   AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
> +.device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
>  },
>  .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 
>  
>  #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);
>  }
> -- 
> 2.15.1
> 


Re: [FFmpeg-devel] [PATCH v2 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set

2017-12-12 Thread Matthieu Bouron
On Mon, Dec 11, 2017 at 10:10:24PM +, Mark Thompson wrote:
> On 11/12/17 12:34, Matthieu Bouron wrote:
> >>
> >> 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.
> > 
> > From 2bbdae2141ba8ca8db54175f4440ac8190f5953d Mon Sep 17 00:00:00 2001
> > From: Aman Gupta 
> > Date: Sun, 3 Dec 2017 17:32:22 -0800
> > Subject: [PATCH 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext
> >  hw_device_ctx if set
> > 
> > Signed-off-by: Matthieu Bouron 
> > ---
> >  libavcodec/mediacodecdec.c|  8 
> >  libavcodec/mediacodecdec_common.c | 14 +-
> >  2 files changed, 21 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> > index 86cc629430..c8ad0b80e7 100644
> > --- a/libavcodec/mediacodecdec.c
> > +++ b/libavcodec/mediacodecdec.c
> > @@ -543,6 +543,14 @@ static const AVCodecHWConfigInternal 
> > *mediacodec_hw_configs[] = {
> >  },
> >  .hwaccel = NULL,
> >  },
> > +&(const AVCodecHWConfigInternal) {
> > +.public  = {
> > +.pix_fmt = AV_PIX_FMT_MEDIACODEC,
> > +.methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
> 
> This wants to be combined with the previous entry (or together the methods): 
> ff_get_format() looks for the first entry matching the pix_fmt, so it will 
> never find this one.  I think this might work anyway because AD_HOC is 
> technically "do whatever you like, I can't check it", but it also wouldn't 
> notice e.g. a non-matching device in that case.

Patch updated with the two entries merged. Thanks.
I tested with both methods (hw device ctx and the old hwaccel way) and no
error came up.

-- 
Matthieu B.
>From 7266745203a2467719f21a31c8b4f94390eaeb6b Mon Sep 17 00:00:00 2001
From: Aman Gupta 
Date: Sun, 3 Dec 2017 17:32:22 -0800
Subject: [PATCH 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext
 hw_device_ctx if set

Signed-off-by: Matthieu Bouron 
---
 libavcodec/mediacodecdec.c|  5 +++--
 libavcodec/mediacodecdec_common.c | 14 +-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
index 86cc629430..7b282a1d68 100644
--- a/libavcodec/mediacodecdec.c
+++ b/libavcodec/mediacodecdec.c
@@ -538,8 +538,9 @@ static const AVCodecHWConfigInternal 
*mediacodec_hw_configs[] = {
 &(const AVCodecHWConfigInternal) {
 .public  = {
 .pix_fmt = AV_PIX_FMT_MEDIACODEC,
-.methods = AV_CODEC_HW_CONFIG_METHOD_AD_HOC,
-.device_type = AV_HWDEVICE_TYPE_NONE,
+.methods = AV_CODEC_HW_CONFIG_METHOD_AD_HOC |
+   AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
+.device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
 },
 .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 
 
 #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);
 }
-- 
2.15.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set

2017-12-11 Thread wm4
On Mon, 11 Dec 2017 22:10:24 +
Mark Thompson  wrote:

> On 11/12/17 12:34, Matthieu Bouron wrote:
> >>
> >> 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.  
> > 
> > From 2bbdae2141ba8ca8db54175f4440ac8190f5953d Mon Sep 17 00:00:00 2001
> > From: Aman Gupta 
> > Date: Sun, 3 Dec 2017 17:32:22 -0800
> > Subject: [PATCH 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext
> >  hw_device_ctx if set
> > 
> > Signed-off-by: Matthieu Bouron 
> > ---
> >  libavcodec/mediacodecdec.c|  8 
> >  libavcodec/mediacodecdec_common.c | 14 +-
> >  2 files changed, 21 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> > index 86cc629430..c8ad0b80e7 100644
> > --- a/libavcodec/mediacodecdec.c
> > +++ b/libavcodec/mediacodecdec.c
> > @@ -543,6 +543,14 @@ static const AVCodecHWConfigInternal 
> > *mediacodec_hw_configs[] = {
> >  },
> >  .hwaccel = NULL,
> >  },
> > +&(const AVCodecHWConfigInternal) {
> > +.public  = {
> > +.pix_fmt = AV_PIX_FMT_MEDIACODEC,
> > +.methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,  
> 
> This wants to be combined with the previous entry (or together the methods): 
> ff_get_format() looks for the first entry matching the pix_fmt, so it will 
> never find this one.  I think this might work anyway because AD_HOC is 
> technically "do whatever you like, I can't check it", but it also wouldn't 
> notice e.g. a non-matching device in that case.

Hm, I guess I agree. From an API user perspective, each AVCodecHWConfig
entry should cover the underlying mechanism fully. So if like in this
case, the underlying code/method is the same (mediacodec stuff), then
all methods for using it share the same AVCodecHWConfig entry.

The only cases where AVCodecs have multiple config entries are
hwaccels, where each hwaccel is backed by a completely different method.

Don't know how this works if a full stream decoder supports multiple
device types, though.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set

2017-12-11 Thread Mark Thompson
On 11/12/17 12:34, Matthieu Bouron wrote:
>>
>> 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.
> 
> From 2bbdae2141ba8ca8db54175f4440ac8190f5953d Mon Sep 17 00:00:00 2001
> From: Aman Gupta 
> Date: Sun, 3 Dec 2017 17:32:22 -0800
> Subject: [PATCH 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext
>  hw_device_ctx if set
> 
> Signed-off-by: Matthieu Bouron 
> ---
>  libavcodec/mediacodecdec.c|  8 
>  libavcodec/mediacodecdec_common.c | 14 +-
>  2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> index 86cc629430..c8ad0b80e7 100644
> --- a/libavcodec/mediacodecdec.c
> +++ b/libavcodec/mediacodecdec.c
> @@ -543,6 +543,14 @@ static const AVCodecHWConfigInternal 
> *mediacodec_hw_configs[] = {
>  },
>  .hwaccel = NULL,
>  },
> +&(const AVCodecHWConfigInternal) {
> +.public  = {
> +.pix_fmt = AV_PIX_FMT_MEDIACODEC,
> +.methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,

This wants to be combined with the previous entry (or together the methods): 
ff_get_format() looks for the first entry matching the pix_fmt, so it will 
never find this one.  I think this might work anyway because AD_HOC is 
technically "do whatever you like, I can't check it", but it also wouldn't 
notice e.g. a non-matching device in that case.

> +.device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
> +},
> +.hwaccel = NULL,
> +},
>  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 
>  
>  #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);
>  }
> -- 
> 2.15.1
> 

Rest of the set looks fine to me (but I can't test it).

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set

2017-12-11 Thread Matthieu Bouron
On Mon, Dec 11, 2017 at 01:33:18PM +0100, Matthieu Bouron wrote:
> On Sun, Dec 03, 2017 at 05:32:22PM -0800, Aman Gupta wrote:
> > From: Aman Gupta 
> > 
> > ---
> >  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 
> >  
> >  #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.

Attaching missing patch.

[...]

-- 
Matthieu B.
>From 2bbdae2141ba8ca8db54175f4440ac8190f5953d Mon Sep 17 00:00:00 2001
From: Aman Gupta 
Date: Sun, 3 Dec 2017 17:32:22 -0800
Subject: [PATCH 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext
 hw_device_ctx if set

Signed-off-by: Matthieu Bouron 
---
 libavcodec/mediacodecdec.c|  8 
 libavcodec/mediacodecdec_common.c | 14 +-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
index 86cc629430..c8ad0b80e7 100644
--- a/libavcodec/mediacodecdec.c
+++ b/libavcodec/mediacodecdec.c
@@ -543,6 +543,14 @@ static const AVCodecHWConfigInternal 
*mediacodec_hw_configs[] = {
 },
 .hwaccel = NULL,
 },
+&(const AVCodecHWConfigInternal) {
+.public  = {
+.pix_fmt = AV_PIX_FMT_MEDIACODEC,
+.methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
+.device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
+},
+.hwaccel = NULL,
+},
 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 
 
 #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) {
+

Re: [FFmpeg-devel] [PATCH v2 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set

2017-12-11 Thread Matthieu Bouron
On Sun, Dec 03, 2017 at 05:32:22PM -0800, Aman Gupta wrote:
> From: Aman Gupta 
> 
> ---
>  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 
>  
>  #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,

-- 
Matthieu B.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set

2017-12-03 Thread Aman Gupta
From: Aman Gupta 

---
 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 
 
 #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);
 }
-- 
2.13.6 (Apple Git-96)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel