From patchwork Mon Dec 11 12:34:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 6696 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2701919jah; Mon, 11 Dec 2017 04:41:21 -0800 (PST) X-Google-Smtp-Source: ACJfBovCgjHN4KuOyQiiBVJOCkG8IPDA1hpJANcXrxzsPIJgdAKiKIEBOf48OTqrxUoHHqc3v0ed X-Received: by 10.223.196.194 with SMTP id o2mr261436wrf.246.1512996081138; Mon, 11 Dec 2017 04:41:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512996081; cv=none; d=google.com; s=arc-20160816; b=lnl5dLQ2ClcthE2/qog5iNaCgqs375nvQWxBkK2BBiFe/UJO5jsMMzZVknQQzRPPe3 rjx7RW7qsa+27rYqJLa+tB6EU9hMmLGkD+MiFU00thGQAp7GmvOSEsh0REGraN9+JRws UjaCm2ZE67VJFCZMOoEauO3s6WAlEB00dCYD9m5eJdsCykPC+ZsjW/9Keia+KaBln2+5 zXnq3HauzxIJXN6pxXHrkaig3wmBTS9YiTqeLTvLBabpw+261Szaw7vD9iWRyQwI2lsN OkTKy28mXDx+4RAcoyTBNcapcuTIjl+5uCzKcDmqEkp/41U0IxXpIrKMVi0BBACLS9dg gk9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :in-reply-to:content-disposition:mime-version:references:message-id :to:from:date:dkim-signature:delivered-to:arc-authentication-results; bh=8apfZU+kMhV1xnMtlxhU5r4cqzwle75dlnXO9kfcmoo=; b=KvDXLiXGdkQVA2KoPwfjqTcqSCfH45aQ74z22hoNAOhNsLHy2hPKoxmJLKGodO/RTh N0ClGGy5aiQLo1a9O9MZ3Ydzk7rvuSAW/EW83kkt0jZZWgd0bNvTIXtATnq/+hnA9fWb 3k2Ckb3s8UUTg4e9fUlznVXsNoCM0Zww1zr/zp6VaSYVwfeG88oT+vrlcsUIrUKRS5FO G/wNfZieG+/MvXX6cmimkwSuP1MChzttJo5W79AK5UCHihLrU3tMGoaQYBmNdUAhhU8h k3k9xtCj1vvquzORwCawWMZn5dfugRZQVposEmQ2eoMZpydob0qo1uYli/OsbZoWjAz3 iUzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=MDOYHbMu; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h9si10540218wre.269.2017.12.11.04.41.20; Mon, 11 Dec 2017 04:41:21 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=MDOYHbMu; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3D89768A4D9; Mon, 11 Dec 2017 14:41:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 80E6E68A480 for ; Mon, 11 Dec 2017 14:41:05 +0200 (EET) Received: by mail-wm0-f66.google.com with SMTP id 64so13812665wme.3 for ; Mon, 11 Dec 2017 04:41:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=SPAp11TYQs3InX3XcZmiVRW1JYoRlP5o5zQhyXGDuBY=; b=MDOYHbMug4ivo/yzd0LRFjjREsn0A4O9n1BHiyq+M12kxOfwX/UzMCr/PJeS/8Qeyt vAuCCkom0jMy8AsuPlxSYUCW7DGKTwJ9hsod97nf7P4IAOw7S3i7cqVXSHbwgBMX+6g+ WMho7kmNK+z/+VGBUzlqwcQkmwhPAH6ELmy+M/aI/QKKP53iwi6AnDXySRSs+z4dZs3d TUfowgY+H25OZ/kaAfBKN3UKlHqv3SoUZh2vW5e/8XYOwkgu91+WFpxDYjdZcdcBlTwd 14HdGcAVWhkUjcJqTFw7aTnHc20FPlLbA+7jvu4TPKw0xHA++klKFsfFvlDjzXvf1Ibc wUqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=SPAp11TYQs3InX3XcZmiVRW1JYoRlP5o5zQhyXGDuBY=; b=qxzSAk9+zcP7Ccekr1w8LTybsqF+jEp/E4TlreNbmjx7Ltpm6Utc0drlSSrFOeHPIT K7o2rSfXgwjnK1mY6PWABEszUMLQgThjrj67iuz0dnvFFnqwBRV3hgRfee0NJV1JuJKo aHW/OtSCwZsIeEGV+syiM/fYRwWplE4TlDuwqCZ5H6iTFt4jj3WFuRLI8tdEBDUNzxX3 /jHzZJaGCAzKSWDF9cjvb5zDGXpXHHRjYdI26lsDw4ArkxnMpPEwDxlCiJSN5r1SZJNC o5nuntKwkLkGlUnAs6hh9l5PoQgGVYjzLk+8duWxtuFbK6elEZmPG7Oq+nEJ3BVH8PMp 2Duw== X-Gm-Message-State: AKGB3mKwOSSRECoK4KRaNaXt+xuqFKlcqPwMnpEbnFVbDbXsANOMUoD7 TEnyOOLMGwXJSjhfCxPBjeD/Fg== X-Received: by 10.28.20.131 with SMTP id 125mr701052wmu.57.1512995597936; Mon, 11 Dec 2017 04:33:17 -0800 (PST) Received: from tsuri.lan (AMontsouris-653-1-95-226.w86-212.abo.wanadoo.fr. [86.212.118.226]) by smtp.gmail.com with ESMTPSA id b45sm16130512wrb.1.2017.12.11.04.33.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Dec 2017 04:33:17 -0800 (PST) Date: Mon, 11 Dec 2017 13:34:58 +0100 From: Matthieu Bouron To: FFmpeg development discussions and patches Message-ID: <20171211123458.GG470@tsuri.lan> References: <20171202231409.32371-1-ffmpeg@tmm1.net> <20171204013222.36272-2-ffmpeg@tmm1.net> <20171211123318.GF470@tsuri.lan> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171211123318.GF470@tsuri.lan> User-Agent: Mutt/1.9.1 (2017-09-22) Subject: Re: [FFmpeg-devel] [PATCH v2 2/2] libavcodec/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: matthieu.bouron@stupeflix.com, nfxjfg@googlemail.com, Aman Gupta , sw@jkqxz.net Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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. [...] 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) { + 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); }