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

Submitted by Aman Gupta on Dec. 2, 2017, 11:14 p.m.

Details

Message ID 20171202231409.32371-2-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Gupta Dec. 2, 2017, 11:14 p.m.
From: Aman Gupta <aman@tmm1.net>

---
 libavcodec/mediacodecdec_common.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Mark Thompson Dec. 3, 2017, 2:15 p.m.
On 02/12/17 23:14, Aman Gupta wrote:
> From: Aman Gupta <aman@tmm1.net>
> 
> ---
>  libavcodec/mediacodecdec_common.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c
> index cb2f6ae5e5..e524ffe0e4 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"
> @@ -475,8 +476,12 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s,
>      pix_fmt = ff_get_format(avctx, pix_fmts);
>      if (pix_fmt == AV_PIX_FMT_MEDIACODEC) {
>          AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
> +        AVMediaCodecDeviceContext *device_ctx = avctx->hw_device_ctx;

Er, no.  AVCodecContext.hw_device_ctx is an AVBufferRef containing an AVHWDeviceContext - you need to dereference through it to get the AVMediaCodecDeviceContext.

>  
> -        if (user_ctx && user_ctx->surface) {
> +        if (device_ctx && device_ctx->surface) {
> +            s->surface = ff_mediacodec_surface_ref(device_ctx->surface, avctx);
> +            av_log(avctx, AV_LOG_INFO, "Using surface %p\n", s->surface);
> +        } else if (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);
>          }
> 

You want to add the hw-config metadata as well, I think.

- Mark

Patch hide | download patch | download mbox

diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c
index cb2f6ae5e5..e524ffe0e4 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"
@@ -475,8 +476,12 @@  int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s,
     pix_fmt = ff_get_format(avctx, pix_fmts);
     if (pix_fmt == AV_PIX_FMT_MEDIACODEC) {
         AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
+        AVMediaCodecDeviceContext *device_ctx = avctx->hw_device_ctx;
 
-        if (user_ctx && user_ctx->surface) {
+        if (device_ctx && device_ctx->surface) {
+            s->surface = ff_mediacodec_surface_ref(device_ctx->surface, avctx);
+            av_log(avctx, AV_LOG_INFO, "Using surface %p\n", s->surface);
+        } else if (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);
         }