From patchwork Wed Aug 7 16:27:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sfan5 X-Patchwork-Id: 50928 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d7b2:0:b0:489:2eb3:e4c4 with SMTP id dc18csp498723vqb; Wed, 7 Aug 2024 09:28:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXOjdLV34Iw0jnCVOWmkT1f2SlofTNQZB+ODRYEYLolhAUV5GW/fq1mz8+Y+UtXcw374tTBVWQXcaeAWFA7JIUBJbaFuTmyfqKH3w== X-Google-Smtp-Source: AGHT+IExHi75cxdc0YEL8mtt+SLqYEFFWYXEKAO9a8h2CkMjq+4F9LxMLHe2/1krrb1dMW67o4PK X-Received: by 2002:a2e:3305:0:b0:2ef:2006:bfb1 with SMTP id 38308e7fff4ca-2f15aa934cfmr136573431fa.15.1723048086769; Wed, 07 Aug 2024 09:28:06 -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 38308e7fff4ca-2f15e13c297si34263431fa.142.2024.08.07.09.28.06; Wed, 07 Aug 2024 09:28:06 -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=@LIVE.DE header.s=selector1 header.b="uENFKq+/"; 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 9082968DB48; Wed, 7 Aug 2024 19:28:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazolkn19012026.outbound.protection.outlook.com [52.103.32.26]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7569368D786 for ; Wed, 7 Aug 2024 19:27:54 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QTa2Kef0emjPMGOxlSmWyJtMuTGoCPXMdla3CqKSgs8yGpvkGlQ/V0Udq4s11pGiNbfyZlxCA82qhetvJRi4TqS5nhfCzJwaHfD2ofF8VSshmAwH6e2Zk0bgWqzrqJwfvcHsiRG0tApiJfqwMAKUdVmOlkScMr2wGkb9B9k/qENxxCg7K7ru3NHcQDG5hR5xC6LIZKe71+Jc0jYbhmybGlyjDpTG6Ui0/6p69WZknHtQRYFtT5O5sT/zeOzY+gbxaWVFXObBOqx44Aj05YwH4WvP/9yGxfqV8efti1A7SfrnF7c6JJkZaiZXdVXvS3yVniYlK9wnuJEk5n/fDmAFQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=FBKHiWvyEgsuZHc7rW8o8uXXfunwKizAAnP2Q4BaNwU=; b=P/FF7+30psXOsSR3vv6upWwIsp6Q9X1OAciv9vt7f30DwKJUCnp0cBwIy3oP/6OyPD5BYg2Tmv+0r4fPBkzotaV/EPJuSOMu5xIqD/knd9MVnawNjLF9nax6TLuuCyKEd4yMIaRWamwdzyMtJsDrUlPH9sDeA3ibe9NDBHOC9Qga7/VsS14M07dqKnFXemUqdaI+bJdbUW5pO1e4H3FwbCxef8da7yDhZo4t24EiBIVFZ+JU8mwdipjL1WzH4WLYahqUyMIqMU/PcIauUNg7QY851PhqmF2pufb+SVaJc/BJRM0LUl1yVLqGPt+dprI4ECjUAAu4SXzQNbkAbkmmaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=LIVE.DE; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FBKHiWvyEgsuZHc7rW8o8uXXfunwKizAAnP2Q4BaNwU=; b=uENFKq+/DEzHKG4TKPvelVfgZj7IRIcTGC5mRXRhlIDvOIfW2XxCiEwCCe/PbbyikN/0C46MYDi+K7K3btvYsisNueKJGej98skS6v4N3ADXemtrBaX6HrYbTrIsnoCvu85wVBrO8mIsppIoTkWZr+9AtOuMtD2nV7iLEvUOJ+T1Eto7xAnIyzvdiRJnXVMW4JzQRehC83B785JvqntZIFfcS/MiunRjNLLjtCOPF+11ZTJ4vwA7+Ys+kmSHTw6QpnFRQcot1qFGt7wTnntrT4C5RieeIJcZMhPidvqDu0lFfsevGbbt8x4L5AgIKZ9jeysLaGsvDb2ioxpJa95Ajw== Received: from DU0PR03MB9567.eurprd03.prod.outlook.com (2603:10a6:10:41f::20) by PAWPR03MB10003.eurprd03.prod.outlook.com (2603:10a6:102:35a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Wed, 7 Aug 2024 16:27:52 +0000 Received: from DU0PR03MB9567.eurprd03.prod.outlook.com ([fe80::e356:c67a:e5bb:cc8a]) by DU0PR03MB9567.eurprd03.prod.outlook.com ([fe80::e356:c67a:e5bb:cc8a%6]) with mapi id 15.20.7828.023; Wed, 7 Aug 2024 16:27:52 +0000 Message-ID: Date: Wed, 7 Aug 2024 18:27:50 +0200 User-Agent: Mozilla Thunderbird Content-Language: en-US, de-DE To: FFmpeg development discussions and patches From: sfan5 X-TMN: [/jndNj42NQQ6uX57rU0wVEOyUk0ChqoeRZ3zCg8vMoclcbRo7IU3poLxcuY7lynC/vB3Bswu0gA=] X-ClientProxiedBy: FR3P281CA0138.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:95::17) To DU0PR03MB9567.eurprd03.prod.outlook.com (2603:10a6:10:41f::20) X-Microsoft-Original-Message-ID: <9cd690a8-c716-4e0b-983a-95dcc813bbe1@live.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR03MB9567:EE_|PAWPR03MB10003:EE_ X-MS-Office365-Filtering-Correlation-Id: fe89153d-5b44-4f53-7c99-08dcb6fde23c X-Microsoft-Antispam: BCL:0; ARA:14566002|6092099012|19110799003|5072599009|461199028|8060799006|3412199025|440099028; X-Microsoft-Antispam-Message-Info: kQvs41rgBymHiiX6QtpKW5TeQlb9ZMwQj21e6BE/oDcnakA3w7m4HuneXRh5KeuqwrXWy3xtmJBlShKoebkX+hw2MAhKioQoJJp4CB2X0fEswy0KjsIHd8+yCFaJ2OrKppvP0Sz1tN1YtOFBB56iJnwZeUSCa90fuOZE6uOmWJq+Sg4To4K3zblhaWRn247zy+0TUqPx0vNUsyHw3i0E5sFXp8AMlkTiMsF8aMAuAMS/AMwxk3YyusshV9Xj8+XLmEFVPGHpdIdFPx0E4YNxtovZdmwh2qb0YAnkhfq+syjcZrp2+pq0NPkvYI8/ftntd16FB6TOIeqG2gqFCt5EaIizAyiyqKFxcEjkHeRSGtLQKbUEajJuPcWJ4W94Na2nZYuVflbgudbHPTX6lsz15iP4CVd8ERQchr7/H2P0VvVL+XYj/B6a5Ync+NTjkkiXCVONWaLELGJi2UU2YKUn0AhJ+ZfPocRvabdltrqkVcCi5IubnH1b12lxPyH7Q13KcyX07tRcQxbay0xo1e20ueARAtVYuN21i/E3ZoWbSj5QmMexVMZ4WzFz1Z0PN/VpuAUphHCkMEIq9hqUC6g950673uiNE3agxMmIg3rcBTjYmUyI5t6bl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NJkc4TflcF31eTMBxTpjUQj9dSIqE7X6bLCPMAnu+iPN/t?= =?utf-8?q?3C9MXmd13jUY67WwxlGNInaIFgChwaLPrJoP57/QQyE4/tLe3J6dX7i4bD4mcc0zm?= =?utf-8?q?1W7qgEilnMs1TtkJIvQAqgj8epxcUtfi3k+2LVXAexdK5Uvja+j61vOB58V/Jk2Sv?= =?utf-8?q?yJD4Ky67j669J8IUth1lhK46odsvwQth4kBW2KeSJwljj05yZ1mEiS/mCcosA3UVL?= =?utf-8?q?8LaYgoZfTiHeumPesYJ29jokHccQM+RIYr0VP8qqC+0zNpHU+7CyBw8kRLH82NGyf?= =?utf-8?q?jt/TCb863rAi1jpEcmz5XvfYXiElYi2+QwIPA3WHCHRc5jyA+WteFeKON0u55ITKW?= =?utf-8?q?96sggdQvMWojY/3kfv0ECICZIUFPzkMQWD9j2hCGFVSZAm6nLtDoTam4SrTbeHQaE?= =?utf-8?q?rtXbKLW4vlZmKSvBI36lSWY7BZonLyj85PFsFUG/BzEG5Mj6LppZz7Z3Q1q/Q6SBZ?= =?utf-8?q?I6l4OQzqEWiISEJ4ae7mD3PkFe5YxIxBQb8F9zqMQxG7pk23JqA580rUwr0E=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-76d7b.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: fe89153d-5b44-4f53-7c99-08dcb6fde23c X-MS-Exchange-CrossTenant-AuthSource: DU0PR03MB9567.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 16:27:52.1407 (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: PAWPR03MB10003 Subject: [FFmpeg-devel] [PATCH] avcodec/mediacodecdec: call MediaCodec.stop on close 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: Z/76ULUTZlvN Hi all, attached is a small fix for the MediaCodec code. Tested on Android 14. From 3f5d05920dc6826b4c0ea0ed7969e9259e08084e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 7 Aug 2024 17:48:06 +0200 Subject: [PATCH] avcodec/mediacodecdec: call MediaCodec.stop on close This can free up vital resources in case of using multiple decoding instances and there are buffer references left over and not immediately cleaned up. Signed-off-by: sfan5 --- libavcodec/mediacodecdec_common.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index d6f91e6e89..c888dea8cf 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -841,6 +841,18 @@ int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s) int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s) { + if (!s) + return 0; + + if (s->codec) { + if (atomic_load(&s->hw_buffer_count) == 0) { + ff_AMediaCodec_stop(s->codec); + av_log(avctx, AV_LOG_DEBUG, "MediaCodec %p stopped\n", s->codec); + } else { + av_log(avctx, AV_LOG_DEBUG, "Not stopping MediaCodec (there are buffers pending)\n"); + } + } + ff_mediacodec_dec_unref(s); return 0; -- 2.46.0