From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6FC934A8C5 for ; Thu, 18 Apr 2024 20:40:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F6AC68CF4C; Thu, 18 Apr 2024 23:40:29 +0300 (EEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2092.outbound.protection.outlook.com [40.92.89.92]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 578A768C2DF for ; Thu, 18 Apr 2024 23:40:23 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=beFWAICu6rkvIHdEW4zcAHUO9Ckk23MjeK/WqJYAkG3t5chWezsFL3qWVpKx2KWT0sAELihixxMTnDXkGVtEeV/+MzN3hJyezZePaI+R/aZSY/nz7twskqCDU4qO7pYeqqht4JgexjiicOYKg293FjId4rxrMD7jeuIhdxGNdQVQkilRskU5YQgUbjsWMEDDkTBzQ4EzoUb39KQ5YpHbqoinLn2PQh9qDPxq426hIdoURdMBt3qYHQW1z43yfl28HCiCgAZsDr9yQJvA/KZAvTV2MWuZLi2XBdJ39avPy3OVXwRmStiqR16YQtkKoJfEF3JDr0wIahTQz3F58Psz6A== 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=77sAolsASEfACDIJHhzFiAePCcWS6+L5oSWYlsEvoXM=; b=n+aqSk6kKaIgT8n3Nqj4l8xsWWAlV+Taar0EF1HqH1RVfXI/lIpW4QJwA6q8iFKY8c7rS/8+4jnAYPNx54PiHa2ukgRgZP7yaBpQUfCqX7OEmgv+4xkEncEcBtOUdp6lDuzx9c9NbeUqtZpF83eYbtlv3dhj/NuF1IDUGDWaZUo6K33cp3olt3akSOIGPg1G76jeyy3vL1sPmv+32G33kh9MERGB8lEfcCqJ2YaD+1eDigYSPG13o6V5ItRQxSbyP5Q4Ul0jfV2xfDDVKZO/f3QWDAIyp84IaHZdL6oaNvXU/X/imSEiQDkDENQuV91tiBaWmP2a0eNGKGOqkY0jMg== 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=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=77sAolsASEfACDIJHhzFiAePCcWS6+L5oSWYlsEvoXM=; b=srQPiHa2dzcvIGdI81QIQAZrhTEqS1mY1KQI6JyXKCwQpBQ+laJw2xC/V8tWxu4b1E79fWbbEQM/bnlpype25aKRqvcMKFkFlSvA7EgR/gd/gwrFj0pbtPbOWQky2okXoAHI4v6jfgWeT24BPYngljF0oJp6vWH1l8mKTn3wAZMQvd3izQylG1YK8x1Dn8Q5erx/SI3DllM8zHQFgPtmyVI9DSeKfJtoLhZhSJNMxWFe0Nsxuwj+tvnELvAGUlc2IlIydEnrjFj4OZWhj2XBvPYNr379fONFZ6u7bmKp1E+JHl+S4bZznudJCMzbS1WDxoot2UPAS/p2MQ1Icw+dmg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0234.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.39; Thu, 18 Apr 2024 20:40:21 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb%3]) with mapi id 15.20.7409.042; Thu, 18 Apr 2024 20:40:21 +0000 Message-ID: Date: Thu, 18 Apr 2024 22:40:19 +0200 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: Content-Language: en-US From: Andreas Rheinhardt In-Reply-To: X-TMN: [NXKfw2ssocoAMg3SJTtCZ/yUzEnOkJMSW+wH4IRrgKI=] X-ClientProxiedBy: FR0P281CA0103.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::16) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <059017d3-57c9-4d40-b5fc-bd985e91f5e4@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0234:EE_ X-MS-Office365-Filtering-Correlation-Id: 55dbb464-d8ab-469c-f928-08dc5fe7c3fc X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ctBtncZ+6nMConBdnoGo+2o/Z0QyA/HSSYk4xTluSnnjJfx8esvLmkIaKlq4A2hcqx8JxJ/F+oR9Sv+vLJduXQU740hrI4PDL9y+wE1agnPmKcBrt0nFE0aJw4nC5tbK7wAXOyFKDmBSYQ5bVO8wbNHXuyj+Va3XQf3qEfg1Xlt25YuQDePGJpOjp3iV4l83DY9J5ihTdMJKwGIsI21jz1Y8IdMFqVeug5eH5fw5xhBJxkUtEHsgB6i/e66ApP3KpIcBRi6/qc8fn5AoFAY318KPb5o3xwwPhqz+UXiIZoJlLX/OdrG3Mw+4dKgVsUkFHV3TL2z+OxQcyrO8N+PVR5YEfHOwdb4ZLQUc5k6uCESghGT76B2Rkc57ON/kMZyOb4w+xv9Pk/ORVMhUIbl01rkLZtJcbZ72ViIH9ikFr+VHMxeFXuu2adjK0fKuAvBNq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tQMnJKY2Js?= =?utf-8?B?R2o1QWg4WFdSZ3VhSE8rN1Bra0hocEhkZXIyOFAwRmVGUEpOU0xCN0tHVW5E?= =?utf-8?B?Nk5tWS82Wm1iU3E2Vmx3b3RvUzNkVld4NlZaQU5aWUhiRlJ4MWdFTU1RPT0=?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55dbb464-d8ab-469c-f928-08dc5fe7c3fc X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2024 20:40:21.2151 (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: AS8P250MB0234 Subject: Re: [FFmpeg-devel] [PATCH v2 01/27] avcodec/threadprogress: Add new API for frame-threaded progress 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Andreas Rheinhardt: > The API is similar to the ThreadFrame API, with the exception > that it no longer has an included AVFrame and that it has its > own mutexes and condition variables which makes it more independent > of pthread_frame.c. One can wait on anything via a ThreadProgress. > One just has to ensure that the lifetime of the object containing > the ThreadProgress is long enough. This will typically be solved > by putting a ThreadProgress in a refcounted structure that is > shared between threads. > > Signed-off-by: Andreas Rheinhardt > --- > Now including its own mutex and condition variable. Hopefully > no system has constraints on the number of mutexes and condition > variables it supports. > > libavcodec/threadprogress.c | 73 +++++++++++++++++++++++++++++ > libavcodec/threadprogress.h | 91 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 164 insertions(+) > create mode 100644 libavcodec/threadprogress.c > create mode 100644 libavcodec/threadprogress.h > > diff --git a/libavcodec/threadprogress.c b/libavcodec/threadprogress.c > new file mode 100644 > index 0000000000..dd2a4d2336 > --- /dev/null > +++ b/libavcodec/threadprogress.c > @@ -0,0 +1,73 @@ > +/* > + * Copyright (c) 2022 Andreas Rheinhardt > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + */ > + > +#include > +#include > + > +#include "pthread_internal.h" > +#include "threadprogress.h" > +#include "libavutil/attributes.h" > + > +DEFINE_OFFSET_ARRAY(ThreadProgress, thread_progress, init, > + (offsetof(ThreadProgress, progress_mutex)), > + (offsetof(ThreadProgress, progress_cond))); > + > +av_cold int ff_thread_progress_init(ThreadProgress *pro, int init_mode) > +{ > + atomic_init(&pro->progress, init_mode ? -1 : INT_MAX); > + if (!init_mode) { > + pro->init = 0; > + return 0; > + } > + return ff_pthread_init(pro, thread_progress_offsets); > +} > + > +av_cold void ff_thread_progress_destroy(ThreadProgress *pro) > +{ > + ff_pthread_free(pro, thread_progress_offsets); > +} > + > +void ff_thread_progress_report(ThreadProgress *pro, int n) > +{ > + if (atomic_load_explicit(&pro->progress, memory_order_relaxed) >= n) > + return; > + > + atomic_store_explicit(&pro->progress, n, memory_order_release); > + > + pthread_mutex_lock(&pro->progress_mutex); > + pthread_cond_broadcast(&pro->progress_cond); > + pthread_mutex_unlock(&pro->progress_mutex); > +} > + > +void ff_thread_progress_await(const ThreadProgress *pro_c, int n) > +{ > + /* Casting const away here is safe, because we only read from progress > + * and will leave pro_c in the same state upon leaving the function > + * as it had at the beginning. */ > + ThreadProgress *pro = (ThreadProgress*)pro_c; > + > + if (atomic_load_explicit(&pro->progress, memory_order_acquire) >= n) > + return; > + > + pthread_mutex_lock(&pro->progress_mutex); > + while (atomic_load_explicit(&pro->progress, memory_order_relaxed) < n) > + pthread_cond_wait(&pro->progress_cond, &pro->progress_mutex); > + pthread_mutex_unlock(&pro->progress_mutex); > +} > diff --git a/libavcodec/threadprogress.h b/libavcodec/threadprogress.h > new file mode 100644 > index 0000000000..786802cbf1 > --- /dev/null > +++ b/libavcodec/threadprogress.h > @@ -0,0 +1,91 @@ > +/* > + * Copyright (c) 2022 Andreas Rheinhardt > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + */ > + > +#ifndef AVCODEC_THREADPROGRESS_H > +#define AVCODEC_THREADPROGRESS_H > + > +/** > + * ThreadProgress is an API to easily notify other threads about progress > + * of any kind as long as it can be packaged into an int and is consistent > + * with the natural ordering of integers. > + * > + * Each initialized ThreadProgress can be in one of two modes: No-op mode > + * or ordinary mode. In the former mode, ff_thread_report_progress() and > + * ff_thread_await_progress() are no-ops to simply support usecases like > + * non-frame-threading. Only in the latter case perform these functions > + * what their name already implies. > + */ > + > +#include > +#include > +#include "libavutil/thread.h" > + > +/** > + * This struct should be treated as opaque by users. > + */ > +typedef struct ThreadProgress { > + atomic_int progress; > + unsigned init; > + AVMutex progress_mutex; > + AVCond progress_cond; > +} ThreadProgress; > + > +/** > + * Initialize a ThreadProgress. > + * > + * @param init_mode If zero, the ThreadProgress will be initialized so that > + * to be in no-op mode as described above. Otherwise > + */ > +int ff_thread_progress_init(ThreadProgress *pro, int init_mode); > + > +/** > + * Destroy a ThreadProgress. Can be called on a ThreadProgress that > + * has never been initialized provided that the ThreadProgress struct > + * has been initially zeroed. Must be called even if ff_thread_progress_init() > + * failed. > + */ > +void ff_thread_progress_destroy(ThreadProgress *pro); > + > +/** > + * Reset the ThreadProgress's progress progress counter; must only be called > + * if it is not in use in any way (e.g. no thread may wait on it via > + * ff_thread_progress_await()). > + */ > +static inline void ff_thread_progress_reset(ThreadProgress *pro) > +{ > + atomic_init(&pro->progress, pro->init ? -1 : INT_MAX); > +} > + > +/** > + * This function is a no-op in no-op mode; otherwise it notifies > + * other threads that a certain level of progress has been reached. > + * Later calls with lower values of progress have no effect. > + */ > +void ff_thread_progress_report(ThreadProgress *pro, int progress); > + > +/** > + * This function is a no-op in no-op mode; otherwise it waits > + * until other threads have reached a certain level of progress: > + * This function will return after another thread has called > + * ff_thread_progress_report() with the same or higher value for progress. > + */ > +void ff_thread_progress_await(const ThreadProgress *pro, int progress); > + > +#endif /* AVCODEC_THREADPROGRESS_H */ Will apply this patchset tomorrow unless there are objections. - Andreas _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".