From patchwork Sun Sep 18 18:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sfan5 X-Patchwork-Id: 38019 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp817664pzh; Sun, 18 Sep 2022 11:27:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Xzj4nAmpA81twNTntl4P6A5NP6k7+UWmBBpgHmrSKjhoYi1hq74lH7/JPhqbhQCaKmfqP X-Received: by 2002:aa7:de9a:0:b0:44d:8191:44c5 with SMTP id j26-20020aa7de9a000000b0044d819144c5mr12655015edv.232.1663525629961; Sun, 18 Sep 2022 11:27:09 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cs18-20020a170906dc9200b00780a882d31fsi7689386ejc.486.2022.09.18.11.27.07; Sun, 18 Sep 2022 11:27:09 -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; 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 E9CEC68B737; Sun, 18 Sep 2022 21:27:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-oln040092066024.outbound.protection.outlook.com [40.92.66.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 940A868B737 for ; Sun, 18 Sep 2022 21:26:57 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FyYBOs7bN4WCIcGpGQueGKHQXUTOwdRRWznLy3j1Yq5KsX+lDvQsSP+mPSoXYSaMPYr3ONj9LLuu04+ASdaHqHvfsXI2VXTAV2CaSL84J/4QBCSYvB07ifeJV9mXcb2gO6okXQ5MS2hZh/mqB+IGhMliPtu1EwnMuBCVMtYIIpS08J3G/8C9lgFzpXToj8SC/X0ooAkY4owUmkfnlZn7uja9U2EbtLQxsL9QlCJ/Qdl/X2DoKYlh6J34zEdmYIS7AbsGcB6oTRVApqZKprP9W7rG0maq6vH2nJGuVU2hbNzMfar7KHQ6skf9epAI+5JDZDbTwEKjN4HA6qs1/1/V4w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=17ODMoXgjZSoYntnETyZ++BaONoV0bnkGYpw2MvYaK0=; b=LwY1iPRyG71aDuWdWldMbpPEHeDhU+W8WJtDzpiUd00pDDRUMdw8dhIVy9FQ4O84ol+/30X/6Xe1i57QAdAyCHN6QjpvHeCDibSY672dcEPbSAHFUua+oSsJJKKCzY5q56SSyme/FgHml+028/GC5rwc2ISoIziXNvCyg222yUv6+QypZVNguy4fE9qnVYi9O6knTIvz4X5BLFU83N1kL0vHdu5jG9JBmyMyle6uGxl9cpyeo5G31hLhwxqbjJGNjuuY0e4lEslkc0xZU0a92jPK+hUQ/CrXZyr2eg7S8kPl5g3nYps/RLgPH0obeo0or20ELS14lfh/1vSPe+K3BQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PAXP251MB0726.EURP251.PROD.OUTLOOK.COM (2603:10a6:102:28b::21) by DB9P251MB0787.EURP251.PROD.OUTLOOK.COM (2603:10a6:10:392::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.19; Sun, 18 Sep 2022 18:26:55 +0000 Received: from PAXP251MB0726.EURP251.PROD.OUTLOOK.COM ([fe80::2d53:d0c3:7838:cbe8]) by PAXP251MB0726.EURP251.PROD.OUTLOOK.COM ([fe80::2d53:d0c3:7838:cbe8%6]) with mapi id 15.20.5632.015; Sun, 18 Sep 2022 18:26:55 +0000 Message-ID: Date: Sun, 18 Sep 2022 20:26:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 To: ffmpeg-devel@ffmpeg.org Content-Language: en-US From: sfan5 X-TMN: [9BxlKuepqzC55VPNGolyuSn8yArrKjBhPRPFA1r4aVzz+dJpsqwBv9GaTU17y3KP] X-ClientProxiedBy: AM3PR07CA0055.eurprd07.prod.outlook.com (2603:10a6:207:4::13) To PAXP251MB0726.EURP251.PROD.OUTLOOK.COM (2603:10a6:102:28b::21) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXP251MB0726:EE_|DB9P251MB0787:EE_ X-MS-Office365-Filtering-Correlation-Id: 78f7321c-0bbe-44ba-037e-08da99a35d5e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lCgaoTkXeSxmBs3gWuT69J0U8VdX8I1cQejxborsmIdouH5If4CHv0TD+NdPykaacWg+1BfetV64WgvcqQKGRLpyPcQfDZCSq/jEB/GKJY/KxXXJJDkUTQeEVmgXNI9qOp3tTmGIZbdVpjCVUwy6kC3y1GLNndOObLuHv6rBvvC98PmMO3KPjAREUtQN5mvDnAWtt4BKXTWcwnhNcsuMyJELQH5hHHpye0DtsdDnEjsD2FcnWECBZVeF6ezb2FJByC3+oO9/JdxvWoIfzNWKKk6cq8bbCIyR0LdTeerSvniF3EIz8a2br57M0B+o3wED7xQxGbChIOKuY7QAkvglFAv2mP4BhdRjiqXLd6YvgAsCt0e+jV1SNuxBaVMk3diN7a2744gwdB92X1iTGL7cLdbEOx5xo55Lxy4nBhAYAWFR/2qi9JXZLXcJ2P9BqtYDqz+K8D/DaefOzjn1gSBayoSubYloYdfQ2FaUpocLmLCY9CXoLPNCbx9oNKXK72xVjfjb7gihEW4S1O4g4y3TT3buuLKYrUuHrIbIh5nwOZACBDLdrLFv080Wv5adbNLZTL+kR/1pOHluBa+62y9cdd8OCnMo7Nt8eAQ7omzQCDifuA7pnTeRr/FAoRbID++bhL8u/zVa8pC3INRbdr66ag== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rDGYyXhM5mrTzmHEpBP8bhVXTluW?= =?utf-8?q?sW1DYnzMyXuux/u5Yz6MI5KabGD4dGXVzSLBAwfv+3CQK/ugN7SjfN6J9rOMW4prl?= =?utf-8?q?m9v5LX5jFOPzsliF40gxSSLptimpVXAwReyQMCUhvVYCCm7isqnbyT+ScohmYW0sK?= =?utf-8?q?U4GTDoMhR0gwos6fShfXeKjbURSrkjKmvSMiwfRZ0mGcMH72bfSivR53D7KXD96qQ?= =?utf-8?q?4MEjja2hd57ifoKJXgcM+dgmvLbIO5WhNrIIM6O+Jdpm96Ymv9DtE+3hGTg5Oto64?= =?utf-8?q?08/Mfd95VAO6Jk9DGlH9hzdiGgAFV6b0eep6jdi2F72pZpRuVP/OidS6zm1ji4b+W?= =?utf-8?q?je1VLrNLJuYvFQolda9tkxmEVi0Ca9Lul2L3AzDY6plUAHI23ZJShIIimQfDEelUe?= =?utf-8?q?/NpBcKDru7bc27EDvy07yWpbiGgKxuFfXqIG5EJGZ7w7bphwN0TLvxTh2PxWumgZp?= =?utf-8?q?zEKOdufWM1yB+rgZm1pW0eD9/fto63FhcB4p2GYfzcc/ans61yvmUoxE6lZNBMBZO?= =?utf-8?q?HAh4MPHOjf8vnVjgnwEMEs+AWyZBq0nyaD8GohjEFbGYRs24nUODfn8MiP43VChhD?= =?utf-8?q?MKf4WU9YMiOoLXIgjC8EEROwK3EWpaJJOihUQynvujGyRs3T9KJOHi8L4mDQyfd3S?= =?utf-8?q?Y4GKRXC14er8IKQCMbqq67KklkYZN4mDkIor+X0OW8Ibj/Mad+KVT5zy1XnFvkDMt?= =?utf-8?q?o3ACTPvaKNeyDJUg3orVQ2IvXtbzHGQt3UBJcQHI8qgBNCm45/+mIkCcMS68JDlKS?= =?utf-8?q?qEOAJ9hm184EVXwfk7KQxZWAw0DjsbbbCn8ktOhhxyQji3LGJ/u0nTD/iV2coVDZf?= =?utf-8?q?LJzod/uF4MAPImdrQOcWqbRuB1Sp71ABfw91H1HFHWUPCGFwcg+1gx26LkrRjHHPw?= =?utf-8?q?u9h9q+vcjwrygq40PZLt4tPEo4rGmmiAzn6enYOvmTG2CkijEhbFotPDByxbBEJY+?= =?utf-8?q?hSrGn3z94V3nxwO9O3ukomNxaAeVPXGctm/2Xnk/6TROTmCGTyDpzqRFFxNm9eLa3?= =?utf-8?q?h7mKlCzwFycuVZtiF72Z9uYYqeMp29CLa05ENQTBGH66ZaBktBAsSmd875CVi6H9s?= =?utf-8?q?cn6xatTkfrVkCl1LWFCkre46yNQ0BoV8YdJxlaYlVnwG6w89SolG2x6Zij9+P79jd?= =?utf-8?q?gfpMjtNbxMGiu48NLGXLzGe37QH7HQyNQJRvWh21G8fLyxZsofSwwQezwzRQv0Mwj?= =?utf-8?q?q3H6ucDtf41/aWh4Oik8GT0xASPftbe45YrcRIyjjqigj33fKg4kUOD1Tzzk4t6fM?= =?utf-8?q?bOEmHhlliMkWFyLJ?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-00b75.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 78f7321c-0bbe-44ba-037e-08da99a35d5e X-MS-Exchange-CrossTenant-AuthSource: PAXP251MB0726.EURP251.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2022 18:26:55.3850 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9P251MB0787 Subject: [FFmpeg-devel] [PATCH] mediacodecdec_common: enable refcounting of buffers unconditionally 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: NMkjJBCELclc This allows av_mediacodec_release_buffer to be called safely after the decoder is closed, this was already the case with delay_flush=1. Note that this causes holding onto frames to keep the decoding context alive which is generally considered to be the intended behavior (resending as my patch got mangled somehow) From c3a5edd940c503cca706b3d92954b8cd5c715e26 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 18 Sep 2022 18:26:43 +0200 Subject: [PATCH] mediacodecdec_common: enable refcounting of buffers unconditionally This allows av_mediacodec_release_buffer to be called safely after the decoder is closed, this was already the case with delay_flush=1. Note that this causes holding onto frames to keep the decoding context alive which is generally considered to be the intended behavior. Signed-off-by: sfan5 --- libavcodec/mediacodecdec_common.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index 9fa769656c..2a605e7f5b 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -265,8 +265,7 @@ static void mediacodec_buffer_release(void *opaque, uint8_t *data) ff_AMediaCodec_releaseOutputBuffer(ctx->codec, buffer->index, 0); } - if (ctx->delay_flush) - ff_mediacodec_dec_unref(ctx); + ff_mediacodec_dec_unref(ctx); av_freep(&buffer); } @@ -321,8 +320,7 @@ static int mediacodec_wrap_hw_buffer(AVCodecContext *avctx, buffer->ctx = s; buffer->serial = atomic_load(&s->serial); - if (s->delay_flush) - ff_mediacodec_dec_ref(s); + ff_mediacodec_dec_ref(s); buffer->index = index; buffer->pts = info->presentationTimeUs; @@ -872,7 +870,7 @@ int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s, */ int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s) { - if (!s->surface || atomic_load(&s->refcount) == 1) { + if (!s->surface || !s->delay_flush || atomic_load(&s->refcount) == 1) { int ret; /* No frames (holding a reference to the codec) are retained by the -- 2.37.3