From patchwork Wed Feb 17 15:50:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sfan5 X-Patchwork-Id: 25724 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:6d42:0:0:0:0:0 with SMTP id i63csp2141387ybc; Wed, 17 Feb 2021 07:50:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVdEi9pou6st4EQtx3z2OGYoGNQyP+rdqFAEdvLvl/8SE3JqQPO5fT5hcNVOjX/q61DuPs X-Received: by 2002:a05:6402:268a:: with SMTP id w10mr27128624edd.331.1613577021964; Wed, 17 Feb 2021 07:50:21 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hr35si1821906ejc.274.2021.02.17.07.50.20; Wed, 17 Feb 2021 07:50: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; arc=fail (body hash mismatch); 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=live.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5061768A0AE; Wed, 17 Feb 2021 17:50:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073078.outbound.protection.outlook.com [40.92.73.78]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 91810688057 for ; Wed, 17 Feb 2021 17:50:06 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bb3G0uCuqVTeK6jA1veH5n9z7y0gO0+chVa+eHL3ctCOXkxr+uWVtnHjuZrImMnltfKK/RXqP+83TCLkWrmWbPytHXietYe/y1B7vLQ7Px5hofnQaq7CliTxXtg3jm6MCm6mXGB1HRLKvu/zzQMpVa/dxu+srtc2A4l7NXvCqsY1oBYmwPOLoL/+mzF713B/p/jjiaZoZyL/Gx7k04SAxegysbBYi5g2tae7YCOlf66zMkBP+XUKnYoavuxvRQXyCj8B4/FWLu28SnvgbNch66jLTtpUVR5yYJdorkaUFS6dahCV7qF9Xecvfqjm5zrf+LhTSjm90wk8szzzSze2ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3gQAdozeiUtjUlmGCdAH0P23LodVUscenTLTXrK5uX0=; b=K5L5V20bk/gqnDJ1Nm7mJ4l0CIb9CfiRHYwMFyQABiZ3x9wUOm+z94rZLS5fpjkZyNLpBGEiDJYmb+lw9pqggaHpAu/cos0tUVEfwbu5++4h863vw9hDLLWBN4/o6nIiTSaI5m5oWsDjEDXeXa07/VbqXfue/GQkKA5JBlK7PYnP5/3bVj+aynY78XEjTy/7WZxU+0mvwTyqgJOiRknYKqX2gbRlhh/UK1YNCAoxbDq3xfAMSkAKBEMqAFg/YKFcRpH99uP9N7xg6Coj/2welckuuu/DB7A5V+2QzyQFhoKEqgX+DpfKDZCacfYXIzxeV1q8mY/M4b4bK50ICCX71w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from HE1EUR04FT027.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0d::4d) by HE1EUR04HT029.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0d::311) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27; Wed, 17 Feb 2021 15:50:04 +0000 Received: from DB6PR0901MB1495.eurprd09.prod.outlook.com (2a01:111:e400:7e0d::49) by HE1EUR04FT027.mail.protection.outlook.com (2a01:111:e400:7e0d::286) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Wed, 17 Feb 2021 15:50:04 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:547857BC0321A883DA97B88FABD1D1DEB010D5497A407B5D1949A2862D2CF4B4; UpperCasedChecksum:0339C2977BCE31EAE1F27E4A9C9DCBD8517197B06F6260874158DC750754D14E; SizeAsReceived:8529; Count:44 Received: from DB6PR0901MB1495.eurprd09.prod.outlook.com ([fe80::5c07:7420:c23b:869f]) by DB6PR0901MB1495.eurprd09.prod.outlook.com ([fe80::5c07:7420:c23b:869f%2]) with mapi id 15.20.3846.042; Wed, 17 Feb 2021 15:50:04 +0000 To: FFmpeg development discussions and patches From: sfan5 Message-ID: Date: Wed, 17 Feb 2021 16:50:00 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 Content-Language: en-US X-TMN: [PbekCIQiY3atgEShaNEQqKA32wOW01fB] X-ClientProxiedBy: AM0PR06CA0101.eurprd06.prod.outlook.com (2603:10a6:208:fa::42) To DB6PR0901MB1495.eurprd09.prod.outlook.com (2603:10a6:4:7a::9) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [10.13.164.99] (185.189.112.27) by AM0PR06CA0101.eurprd06.prod.outlook.com (2603:10a6:208:fa::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Wed, 17 Feb 2021 15:50:03 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 44 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 76e082fa-3326-46a1-ae44-08d8d35bb115 X-MS-TrafficTypeDiagnostic: HE1EUR04HT029: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Rbc87TeMP3P7czZIMD7JnYFUqv+LK4+hyLh7Fcl7fmi7AHXYO0zzy2I5KQ2O4qfx+R75MduLDHLeotOZ55AYEGsTcgRCo6/Dy8t1Ee3d+LX+AvGt+Kt5Do7o8oPNVbZkJqYuNWnH/BeXmMGMbynzhwXrmveMRmpMWJeWTVCECGm3xEaZwgXVy6mUNhQnUkcfFngB/5FT8L2m1pJZOONtJWlUydRd652chN/WY6nJfG8E7uYQ6CJl3lLW18gcQHjHgZeAVET1vtdv6z4ruLtdg3I/KSXU2lSvUsPNoXfK7OdnnYbaDH/2RKLRk4ZNVcFMAJzwEbp1GLc12JmvtWzou6H+MayaRhma7vpPVjQH9DmUqaBTwKXTfAhADrL6chvs X-MS-Exchange-AntiSpam-MessageData: 6HGhrG8jq0kky5HItzSh2sdbh4VzsT0CGYahXGxeSJ5B1LuTTW8O2RnyXgC/2LplVQgwWBCmFLqkk/drSb3c9Sxv3Yjz0ZBe2nY28Y9NJaQxVRUZBMcL8DwIsAK8/cUGnc7h/XgGkTggZISpgKb2+A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76e082fa-3326-46a1-ae44-08d8d35bb115 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2021 15:50:04.7264 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: HE1EUR04FT027.eop-eur04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR04HT029 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/mediacodec_wrapper: clean up ff_AMediaCodecList_getCodecNameByType a bit 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wHaTBB9NSLAe Content-Length: 7319 Hi, while looking into mediacodec for unrelated reasons I saw some room for improvement. Therefore, here's a series with two small patches. Subject: [PATCH 1/2] avcodec/mediacodec_wrapper: clean up ff_AMediaCodecList_getCodecNameByType a bit We can skip software decoders before even looking at the mime types. --- libavcodec/mediacodec_wrapper.c | 113 ++++++++++++++++---------------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c index 79abc8b6aa..f1945bcfc0 100644 --- a/libavcodec/mediacodec_wrapper.c +++ b/libavcodec/mediacodec_wrapper.c @@ -441,6 +441,30 @@ char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int e goto done_with_info; } + codec_name = (*env)->CallObjectMethod(env, info, jfields.get_name_id); + if (ff_jni_exception_check(env, 1, log_ctx) < 0) { + goto done; + } + + name = ff_jni_jstring_to_utf_chars(env, codec_name, log_ctx); + if (!name) { + goto done; + } + + if (codec_name) { + (*env)->DeleteLocalRef(env, codec_name); + codec_name = NULL; + } + + /* Skip software decoders */ + if ( + strstr(name, "OMX.google") || + strstr(name, "OMX.ffmpeg") || + (strstr(name, "OMX.SEC") && strstr(name, ".sw.")) || + !strcmp(name, "OMX.qcom.video.decoder.hevcswvdec")) { + goto done_with_info; + } + type_count = (*env)->GetArrayLength(env, types); for (j = 0; j < type_count; j++) { int k; @@ -456,74 +480,51 @@ char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int e goto done; } - if (!av_strcasecmp(supported_type, mime)) { - codec_name = (*env)->CallObjectMethod(env, info, jfields.get_name_id); - if (ff_jni_exception_check(env, 1, log_ctx) < 0) { - goto done; - } + if (av_strcasecmp(supported_type, mime)) { + goto done_with_type; + } - name = ff_jni_jstring_to_utf_chars(env, codec_name, log_ctx); - if (!name) { - goto done; - } + capabilities = (*env)->CallObjectMethod(env, info, jfields.get_codec_capabilities_id, type); + if (ff_jni_exception_check(env, 1, log_ctx) < 0) { + goto done; + } - if (codec_name) { - (*env)->DeleteLocalRef(env, codec_name); - codec_name = NULL; - } + profile_levels = (*env)->GetObjectField(env, capabilities, jfields.profile_levels_id); + if (ff_jni_exception_check(env, 1, log_ctx) < 0) { + goto done; + } - /* Skip software decoders */ - if ( - strstr(name, "OMX.google") || - strstr(name, "OMX.ffmpeg") || - (strstr(name, "OMX.SEC") && strstr(name, ".sw.")) || - !strcmp(name, "OMX.qcom.video.decoder.hevcswvdec")) { - av_freep(&name); - goto done_with_type; + profile_count = (*env)->GetArrayLength(env, profile_levels); + if (!profile_count) { + found_codec = 1; + } + for (k = 0; k < profile_count; k++) { + int supported_profile = 0; + + if (profile < 0) { + found_codec = 1; + break; } - capabilities = (*env)->CallObjectMethod(env, info, jfields.get_codec_capabilities_id, type); + profile_level = (*env)->GetObjectArrayElement(env, profile_levels, k); if (ff_jni_exception_check(env, 1, log_ctx) < 0) { goto done; } - profile_levels = (*env)->GetObjectField(env, capabilities, jfields.profile_levels_id); + supported_profile = (*env)->GetIntField(env, profile_level, jfields.profile_id); if (ff_jni_exception_check(env, 1, log_ctx) < 0) { goto done; } - profile_count = (*env)->GetArrayLength(env, profile_levels); - if (!profile_count) { - found_codec = 1; + found_codec = profile == supported_profile; + + if (profile_level) { + (*env)->DeleteLocalRef(env, profile_level); + profile_level = NULL; } - for (k = 0; k < profile_count; k++) { - int supported_profile = 0; - - if (profile < 0) { - found_codec = 1; - break; - } - - profile_level = (*env)->GetObjectArrayElement(env, profile_levels, k); - if (ff_jni_exception_check(env, 1, log_ctx) < 0) { - goto done; - } - - supported_profile = (*env)->GetIntField(env, profile_level, jfields.profile_id); - if (ff_jni_exception_check(env, 1, log_ctx) < 0) { - goto done; - } - - found_codec = profile == supported_profile; - - if (profile_level) { - (*env)->DeleteLocalRef(env, profile_level); - profile_level = NULL; - } - - if (found_codec) { - break; - } + + if (found_codec) { + break; } } @@ -548,8 +549,6 @@ done_with_type: if (found_codec) { break; } - - av_freep(&name); } done_with_info: @@ -566,6 +565,8 @@ done_with_info: if (found_codec) { break; } + + av_freep(&name); } done: