From patchwork Mon Oct 24 03:16:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 38948 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp1998332pzb; Sun, 23 Oct 2022 20:19:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MYV87md8i3rhJKIopKcW59o/gqtrkCAiVeYkRPWhW7HPIE7/n0MCLkH0+JeR218/PbIn+ X-Received: by 2002:a05:6402:190a:b0:461:bd00:28c with SMTP id e10-20020a056402190a00b00461bd00028cmr3827370edz.296.1666581579905; Sun, 23 Oct 2022 20:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666581579; cv=none; d=google.com; s=arc-20160816; b=D+uSBp6GMNib4Evgtp1P75ctFvGGgycOuZr/c+V5xB9W3qHypSGSXK6TyPemKfltHL 2MKxEcIjp7imQBp7t1KG3El/cPVGsskOEULlRqKS0dBBCOBE9w3LCjD5skutbUQR6/ms G8q25kcawtgSgn3sVYL2RG84DGKm409h0rstknWFnW/vPYXxirNdqH1zHYICTSq+qhtA nY2jE5A1oK4jDo920yckMSwJrPqErEWRQ0KCGehKy6xt8xyn984/qkiwdbh5rqDbizZk vHWjh7Jkm1xq+Uusq72KV90Yvlf4bhmEeCzaSXohvJmCzTZyfBUtvxMXg9vSBbqsyYPn stkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to:date :to:from:message-id:dkim-signature:delivered-to; bh=DOwyBiFIyxadnPHTWQyq5X7SsNZQqc2vLTJ2OCIXBQU=; b=huxK68mh9g0wIfS0FfIiAi0Mwzkw0j7AILh2arBmCgtb3fP8kADkD6pV2omE9mPAvS MbpMmow/78kn0tE0UnWJUbqTr5Y4z1R3ndWfwsQ0ljMms8Ifki81F2kpFVIjl3b3OuWn J1g+aQAsXEsAcHRinwHx6VNaXnYi8hz8MEGelUzul407fGvjXJid9trSBPCDkAs822nj RLx90TNLyASOJgq16vuBt82+63rINM9ScFvF81JjNgat1pEwKJs9hN/peL9v04FxaW9v zSPVfWjGsjSJSUqIYBSlgCbri9AA9Gg/JwMFXYVEbTXJtmjE73hFc9hFuV3aO6Da3WOE jtAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=RvDlfFY+; 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=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qb36-20020a1709077ea400b0078d00203ab2si26729150ejc.41.2022.10.23.20.19.39; Sun, 23 Oct 2022 20:19:39 -0700 (PDT) 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=@foxmail.com header.s=s201512 header.b=RvDlfFY+; 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=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3C36568BD51; Mon, 24 Oct 2022 06:19:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3817F68BD2C for ; Mon, 24 Oct 2022 06:17:22 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1666581440; bh=lAbR27IEHEb4F41Iz9dN7Dclol6/DVv7wDl4Mgl3zHk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RvDlfFY+gvP064rdSxLWeg5yrcNpvdaeLrAY7m4uvU+z+60O5skkoOvxxxvspA0Cq xPpLHmQQic8bViXRU9rQsa3c9MBTfba8zPXxMC8kktJoxBO6/oGN+ALuCvto+OzgGz LK3GPH7eorhLURnvVkpa76bPZR8U1NEAfnNtSEPs= Received: from localhost.localdomain ([59.37.125.102]) by newxmesmtplogicsvrsza31.qq.com (NewEsmtp) with SMTP id 44A14270; Mon, 24 Oct 2022 11:17:10 +0800 X-QQ-mid: xmsmtpt1666581439tq4faoaxe Message-ID: X-QQ-XMAILINFO: Mrv6PNPZjcp66JUX8FFyYklFuzJnOCED/CLC4fiptY8d70DPp0FjjCxGGeClq8 ekaqP5mNanjEM1I7uow85luroeBYGBPCzJHI5sd/91rpA/il9tV8Vf/NFBz/O07aG+92EY/K8TmP 9gHdAPgVfYcJ8aAhpwdBcAuvwr3qpdcTLnms+V8Ad0Js2Hrz9xn5nBcId1F51C/9w6n99SAlqXJv Hz/TDWeKXat++EyI2qkd92n18IwKbB/HtmQNJkAQYz1pIc822NNqBzxWII5mdGRKBDs80lwJi5AH VjbuuSizWt1f9xHC7qX0KPCaILZMiAYw5PhURvJhof/G4AeXmm4kRoQ9dGteh9Xo+XEIklCLhzGU o46oPEn4D0NUNnU3/v35jgW8B1SR4tuYOIfSaZ0oYReLOpsF7g1ISk73Rvk6ZjUpwPOZbOTLfDPV m1X+gRrsjMoPSZP8l4TOjOQHLVux7dnmHulAbbs812+FuTevVxCha7CAUf9Rnydv2g0CfpbojPh4 6zPNqImlto5gHNkAVNFDn4KWkcmvPyO5K2c79LEX9FStTJqiFb9GxqE+dCSSpaFWoFFtQZRGz12a Lp+nRkthVD/Ca0AeV3VhGOAhmGtNH6EcaSux8484EgOy3oWw0FX1kScAagUvXSZ7sslLAQUrCi5v 630qbexXIex+gYX4pNW/UapmEEpzhXaBXsIJbmEmsC76Lwq3dubjil7BmvcC5nBU+1fSVad3oiOl Mqes8w5hDRgrThcFeJHURpXHp8PPrMxPYI5v4t9wurMM6KAGsknoaUEudbVlbiYYhYYAd7wk0p12 nHqJ/xLDDSTHYUD9CAjo9NXrLSYHWqPdOGtZq4gLjmPJ2nIf+KVGN0cIHxft5JpBG3atHHyPUBRR ail9pX9f85IEVvp2CgMJNhZeBKqhGPBNF+eud7+NUgc76LcOpYhnMOVifk9yh1uPsYpt19vtdUoQ 85NCGQT975RXU7yVruMyKspNNUBBY8yYWIMiyFFFg/ezVhSEGIlg== From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Mon, 24 Oct 2022 11:16:53 +0800 X-OQ-MSGID: <20221024031658.1026118-8-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024031658.1026118-1-quinkblack@foxmail.com> References: <20221024031658.1026118-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/12] avcodec/mediacodecdec: enable NDK mediacodec X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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, Zhao Zhili , aman@tmm1.net Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ypIZz2gxBb7R From: Zhao Zhili Signed-off-by: Zhao Zhili --- Changelog | 1 + libavcodec/mediacodecdec.c | 10 +++++++++- libavcodec/mediacodecdec_common.c | 23 +++++++++++++++++++---- libavcodec/mediacodecdec_common.h | 1 + libavcodec/version.h | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index ec9de1bd85..9e203833aa 100644 --- a/Changelog +++ b/Changelog @@ -18,6 +18,7 @@ version : - Media 100i decoders - DTS to PTS reorder bsf - ViewQuest VQC decoder +- MediaCodec decoder via NDKMediaCodec version 5.1: diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index 2e07548b77..2c231d1a34 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -40,6 +40,7 @@ #include "hevc_parse.h" #include "hwconfig.h" #include "internal.h" +#include "jni.h" #include "mediacodec_wrapper.h" #include "mediacodecdec_common.h" @@ -54,6 +55,7 @@ typedef struct MediaCodecH264DecContext { int delay_flush; int amlogic_mpeg2_api23_workaround; + int use_ndk_codec; } MediaCodecH264DecContext; static av_cold int mediacodec_decode_close(AVCodecContext *avctx) @@ -310,7 +312,10 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) FFAMediaFormat *format = NULL; MediaCodecH264DecContext *s = avctx->priv_data; - format = ff_AMediaFormat_new(0); + if (s->use_ndk_codec < 0) + s->use_ndk_codec = !av_jni_get_java_vm(avctx); + + format = ff_AMediaFormat_new(s->use_ndk_codec); if (!format) { av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n"); ret = AVERROR_EXTERNAL; @@ -388,6 +393,7 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) } s->ctx->delay_flush = s->delay_flush; + s->ctx->use_ndk_codec = s->use_ndk_codec; if ((ret = ff_mediacodec_dec_init(avctx, s->ctx, codec_mime, format)) < 0) { s->ctx = NULL; @@ -528,6 +534,8 @@ static const AVCodecHWConfigInternal *const mediacodec_hw_configs[] = { static const AVOption ff_mediacodec_vdec_options[] = { { "delay_flush", "Delay flush until hw output buffers are returned to the decoder", OFFSET(delay_flush), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VD }, + { "ndk_codec", "Use MediaCodec from NDK", + OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VD }, { NULL } }; diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index 1905e686bc..c3d5988063 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -601,12 +601,27 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, s->codec_name = ff_AMediaCodecList_getCodecNameByType(mime, profile, 0, avctx); if (!s->codec_name) { - ret = AVERROR_EXTERNAL; - goto fail; + // getCodecNameByType() can fail due to missing JVM, while NDK + // mediacodec can be used without JVM. + if (!s->use_ndk_codec) { + ret = AVERROR_EXTERNAL; + goto fail; + } + av_log(avctx, AV_LOG_INFO, "Failed to getCodecNameByType\n"); + } else { + av_log(avctx, AV_LOG_DEBUG, "Found decoder %s\n", s->codec_name); } - av_log(avctx, AV_LOG_DEBUG, "Found decoder %s\n", s->codec_name); - s->codec = ff_AMediaCodec_createCodecByName(s->codec_name, 0); + if (s->codec_name) + s->codec = ff_AMediaCodec_createCodecByName(s->codec_name, s->use_ndk_codec); + else { + s->codec = ff_AMediaCodec_createDecoderByType(mime, s->use_ndk_codec); + if (s->codec) { + s->codec_name = ff_AMediaCodec_getName(s->codec); + if (!s->codec_name) + s->codec_name = av_strdup(mime); + } + } if (!s->codec) { av_log(avctx, AV_LOG_ERROR, "Failed to create media decoder for type %s and name %s\n", mime, s->codec_name); ret = AVERROR_EXTERNAL; diff --git a/libavcodec/mediacodecdec_common.h b/libavcodec/mediacodecdec_common.h index 0b21129fee..0ab29036bd 100644 --- a/libavcodec/mediacodecdec_common.h +++ b/libavcodec/mediacodecdec_common.h @@ -70,6 +70,7 @@ typedef struct MediaCodecDecContext { bool delay_flush; atomic_int serial; + bool use_ndk_codec; } MediaCodecDecContext; int ff_mediacodec_dec_init(AVCodecContext *avctx, diff --git a/libavcodec/version.h b/libavcodec/version.h index f8abc803b6..43d0d9a9fc 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #include "version_major.h" #define LIBAVCODEC_VERSION_MINOR 51 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \