From patchwork Sat May 11 20:51:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48778 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1706:b0:1af:cdee:28c5 with SMTP id nv6csp299755pzb; Sat, 11 May 2024 14:00:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW4OaRjr4tokfcb1bq8CaP8BVP7Yj404BuToc1Pl03qrOhnkXd6fM9BBl2vtOj4H8HdHVtK+aVj9hFGQPzCx8eFWU30MlncpWIbxQ== X-Google-Smtp-Source: AGHT+IEEQoShXwse32ALVi/efjfIOLgkrr2k5vgtHJ6311GVZvaoW0vImxt2j9RWVPlSwBzjTNV4 X-Received: by 2002:a17:906:1315:b0:a5a:5c0b:ff77 with SMTP id a640c23a62f3a-a5a5c0c0048mr19499266b.19.1715461204029; Sat, 11 May 2024 14:00:04 -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 a640c23a62f3a-a5a17b21e33si340431966b.304.2024.05.11.14.00.03; Sat, 11 May 2024 14:00:04 -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=@outlook.com header.s=selector1 header.b=L+svyXcT; 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=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7159768D7F6; Sat, 11 May 2024 23:55:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05olkn2071.outbound.protection.outlook.com [40.92.90.71]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0A4EC68D42D for ; Sat, 11 May 2024 23:55:22 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mXkOY0O/BlKW9ozy+/Aaj6xoe9qXpIlSu3HEd2ImYYuKJybVrJIOtwUzUQP27LzwVkl9Qons4e5WglybN68nmRxM8cBpLT9CaQ5FvZbs2yeAQo+pWiWP2V+TvnyCOhQncdlbXdcfS12fU1JFgqNqmgBphJldY2moUJb/oT4nEOa+TqKAgVd30odQS37xEKSb3PIKPZzm17nh3y+7bbDJfUQ3FrVTKNt0s9AkTm5Stry/RVNDrwKx03+eajlqliUZ+9MrVRKUsmQWc1l4qVZDW6lXp+wJIdZDwE9YxJ2TM+qcJje3T2ZI9/PmKgsiP/Udq7woy3SnqGjt41L67I6urQ== 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=RzE12RuAffRiSra5akuuryU03KcDeH4iAqp74loEuUk=; b=Jr9SvdKiUHML5HJrs/Z3t82AHYk8K96z8p2UbR7WfbJstYCgdHplyF5esFbNpduhL8g+3vX5C1MWqLDwTmzFIiXrYDeWLTtpwxNCJ9Vc8miiaDL0bKFwg1RK/DhGUK1Otis7+RzWrlnZdL+1/0o4tyGjFaVnn2cJsIhlzpzgUzbRE02KpsSQCKK9zu59eTNdbnOH3PD2NIHk80kzlowH23ZNKqKlVhgyDZ6oMTP4P1t9SrSnSS/LP/mbMytTITPjXI4g8mKWskn+yf5exAC9hdzIDEPs4hYllz6iwa6iJT0Wajb4cNpbWNqdJnmHcBu+tGF8tbXgBH029R6pIoa3tg== 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=RzE12RuAffRiSra5akuuryU03KcDeH4iAqp74loEuUk=; b=L+svyXcTdiPUwFmcJlNJOs5ub6Wd6F11r419d00jRVopbFt6gra/OVg6c39mqCf2SkCGWW2KLbCQZoAXBgX7g8Fxx9k0Jqzsv4Ei60qXRO1UkAIf2cYoX6cC2verNwUlgSjQPUbpL/XAwDh+ly2UQ+CL98J6SNNYU++8DXu+EV9GPy+RmAhXNkhvqwQlsV6RKOFbmzjUwSSwpX71ndCOeuj47Q3ovval79HamHeEBiSpDS9NEWXeCUfCl2Vxdj82JFFKmnCgusAyMJ+v1Xj3rDNAM+BYEj2pRdckYB+/LZflDbABmiHAU616En4XFH0GbM56kXhd8qboDPRd3iUhUQ== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AS8P250MB0070.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:37d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Sat, 11 May 2024 20:55:21 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::d6a1:e3af:a5f1:b614]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::d6a1:e3af:a5f1:b614%7]) with mapi id 15.20.7544.052; Sat, 11 May 2024 20:55:21 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 May 2024 22:51:21 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [KMmttcBujZqMnikJXrwhqlyqnyDqbhHhizvLLDQatOQ=] X-ClientProxiedBy: ZR0P278CA0172.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:45::6) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240511205135.2411886-56-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AS8P250MB0070:EE_ X-MS-Office365-Filtering-Correlation-Id: 52f2b1e7-30e7-47e6-0a74-08dc71fcabe0 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: 65dQQ/tN9Kcb6qKKTXaUZInt/fH7f5Wy5d265oAtZFp7tqgYt2lCDK0TSBNrran2PLJ0Ige5T8MFHS/DgB3m3XPhMSnwRP1QImRznSSy0ZXvmRBtwicXpotDczujTLDuD1kOER7pVOdEq75iKQ6M1ZQmWB3r/KjjXezAGvcEzIacwebxi/dxJG7p9mQINX8WF94futaPwIoY1yd1+V+mldUv7ufrs+85PznVE7AMlcQOsDecWMpNBjLbjli//LoE4gcCRHcaC8FH0AisxaOYLh5HxLtP4Tv/B6FDYmp4v8NxkOdSCZFOgQQ8E4HcrLpEa0dh+27qePaMmfYq8pRai+OJfxnDjbBb6Eho1nUdDTRpowao65dAgBv3xpdJh3JY2JYzOohNbN2CPbdosDLuiTyGMp8xaHRhrahFQfIqkXd1/xyUuY9gZPbAIc2D44bt5ADgJryM4vjBw2qyK9FUy4GV/W0Pdfg92R5ZB/SRz9/2RH49a/YK5WtUX4PXs6S2giPQ39FZywt3d9VeyczEkmun5eZvgyLJEOexKFCbyMJ0DQ8BVUA5FaLR7ITSWTCQ9qhZq5OXm+TXF4kvqny0zSsS/WBxa5Yqx8jG3m3BOmU3VDIW6Eu+mtHYoQW7AHMe X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lOTscv0I1oCbkLjGzRbqFMFYf2BCCfCOuzoCgqgj39KrDS13/MVrPCMXAhxolSpLy/EhKFa0f3ZJjNT8Fj9TrPLd7KJGsLSXbGA7BwJQw7gSOlDp6wBylxUqhP/KS4bXAXXUxp4Yr2sBQSYWvbqUzfk7wyeCJDTr5qI/qeEpD/e3iuMvkEUtFVCLSkO64FwCQxMvU3dKpZkiiIbotg5RM3NVrrrCsRkGEPLzbcYyre8sXL0JbTLzGM0N7UyC89NN0paI2V5jZidd6mz5hg/ffBxb/xbksKilQIIdqdbemqmOLHzCsGywO55blSqz/g+oTaqxQFS9aovizkRI7hLunNcWNI+LKWnXs+bIr6tmOuOWdmawOdSSGQYxaICB8ShMjhyjF9Ef1V1J/EGxNDWffbeCfqDkvXHuocajrGBC2gdz4oUvC6cC7ykSx8LmaYf2TL75nVUBeCHGMcW9MKKczxpVI+tLSwV9/cRgsbor2Y35I3XIhuqhXXRKoYlDneagBXg2HFkuQsjYmyxx7xd911QwQopOA7jH4bXvmIGz7LFymFQvgPUz/y0Il5ohCwxm1bF5OvJbXm9kDwppBJF34Mw/iV1dRtPxcoJa59ZgwbXmn1LcCJqqRoly7d1SoKzB6g1cqT1axC9qbUydrOOc38WmZGk1AiitAqZwqkI8C7RQCiUCgQdbx7GP8qBQOdXBVa8M6YsF0GDkO8Bin0YSFF8jjbtqf+Gl+Vq7Je2zl+gXs2U1GNDsUfBXcTj2YXOE/+LLsqaQRq9bglRzAowjRHFnP7/OLqfVBihGq4thxIZfALsibCHIrUm3qnAFMmCt6LCcoP7pM66vU9qfIZJx1l4WYhxs5uv78eol64F123rZupLwKHSAT8O/HKUVs1RXr4WbR6AM/k3l/9mcUhsA6qDTwzdPlm0rs9eCVybCgXHLkJkLTzCoO7iP+OCV4gH1FFNMOm3p1DZMgXT8nJTAkNbeR+gYa3rk35AKsKZrJluVRUiycatCJEeuUpHH12DPHx0/JlijZRUqB0PJG96wipcAYBKvA2tWgiRQ6tzF1kVB7OUB+uQa/9mrHZaLcl+0GLYbqW6iNPLAoDkX7tu/D0MrdZmI08eufGlMtoaacWU/f5sojSjjlwiUj0Alb/oMpXAjrEMNnyS2IxGdCE4vOWpCcM/Jv4TN15IiQZkrNGr5dGbnkaPTpyFFCqiHcmXj/kUgsMS7dbQNk2zGHlk3F3BIgVF256sojuBI5GqLkVvJvLHZENMwHDkqIZyi1MBn81McOMXIc7aK8HwCLetldQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52f2b1e7-30e7-47e6-0a74-08dc71fcabe0 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2024 20:55:21.1886 (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: AS8P250MB0070 Subject: [FFmpeg-devel] [PATCH v2 57/71] avcodec/mpegpicture: Use ThreadProgress instead of ThreadFrame API 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: o81+WSf2Gc+/ Given that MPVPictures are already directly shared between threads in case of frame-threaded decoding, one can simply use it to pass decoding progress information between threads. This allows to avoid one level of indirection; it also means avoids allocations (of the ThreadFrameProgress structure) in case of frame-threading and indeed makes ff_thread_release_ext_buffer() decoder-only (actually, H.264-decoder-only). Signed-off-by: Andreas Rheinhardt --- libavcodec/error_resilience.c | 13 ++++++++---- libavcodec/error_resilience.h | 1 + libavcodec/mpeg4videodec.c | 8 ++++---- libavcodec/mpeg_er.c | 2 +- libavcodec/mpegpicture.c | 19 ++++++++++++------ libavcodec/mpegpicture.h | 7 ++++--- libavcodec/mpegvideo_dec.c | 25 +++++++++++++----------- libavcodec/mpegvideo_enc.c | 2 +- libavcodec/mpv_reconstruct_mb_template.c | 8 ++++---- libavcodec/pthread_frame.c | 5 ----- libavcodec/rv34.c | 16 +++++++-------- 11 files changed, 59 insertions(+), 47 deletions(-) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index 66d03987b6..56844d5084 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -34,6 +34,7 @@ #include "mpegutils.h" #include "mpegvideo.h" #include "threadframe.h" +#include "threadprogress.h" /** * @param stride the number of MVs to get to the next row @@ -409,8 +410,12 @@ static void guess_mv(ERContext *s) set_mv_strides(s, &mot_step, &mot_stride); num_avail = 0; - if (s->last_pic.motion_val[0]) - ff_thread_await_progress(s->last_pic.tf, mb_height-1, 0); + if (s->last_pic.motion_val[0]) { + if (s->last_pic.tf) + ff_thread_await_progress(s->last_pic.tf, mb_height-1, 0); + else + ff_thread_progress_await(s->last_pic.progress, mb_height - 1); + } for (i = 0; i < mb_width * mb_height; i++) { const int mb_xy = s->mb_index2xy[i]; int f = 0; @@ -763,7 +768,7 @@ static int is_intra_more_likely(ERContext *s) if (s->avctx->codec_id == AV_CODEC_ID_H264) { // FIXME } else { - ff_thread_await_progress(s->last_pic.tf, mb_y, 0); + ff_thread_progress_await(s->last_pic.progress, mb_y); } is_intra_likely += s->sad(NULL, last_mb_ptr, mb_ptr, linesize[0], 16); @@ -1198,7 +1203,7 @@ void ff_er_frame_end(ERContext *s, int *decode_error_flags) int time_pb = s->pb_time; av_assert0(s->avctx->codec_id != AV_CODEC_ID_H264); - ff_thread_await_progress(s->next_pic.tf, mb_y, 0); + ff_thread_progress_await(s->next_pic.progress, mb_y); s->mv[0][0][0] = s->next_pic.motion_val[0][xy][0] * time_pb / time_pp; s->mv[0][0][1] = s->next_pic.motion_val[0][xy][1] * time_pb / time_pp; diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h index 1346639c3c..a1b9b9ec1a 100644 --- a/libavcodec/error_resilience.h +++ b/libavcodec/error_resilience.h @@ -40,6 +40,7 @@ typedef struct ERPicture { AVFrame *f; const struct ThreadFrame *tf; + const struct ThreadProgress *progress; // it is the caller's responsibility to allocate these buffers int16_t (*motion_val[2])[2]; diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index f4d83dc2aa..450278eee7 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -45,7 +45,7 @@ #include "internal.h" #include "profiles.h" #include "qpeldsp.h" -#include "threadframe.h" +#include "threadprogress.h" #include "xvididct.h" #include "unary.h" @@ -1811,7 +1811,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) s->last_mv[i][1][1] = 0; } - ff_thread_await_progress(&s->next_pic.ptr->tf, s->mb_y, 0); + ff_thread_progress_await(&s->next_pic.ptr->progress, s->mb_y); } /* if we skipped it in the future P-frame than skip it now too */ @@ -2016,10 +2016,10 @@ end: if (s->pict_type == AV_PICTURE_TYPE_B) { const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1; - ff_thread_await_progress(&s->next_pic.ptr->tf, + ff_thread_progress_await(&s->next_pic.ptr->progress, (s->mb_x + delta >= s->mb_width) ? FFMIN(s->mb_y + 1, s->mb_height - 1) - : s->mb_y, 0); + : s->mb_y); if (s->next_pic.mbskip_table[xy + delta]) return SLICE_OK; } diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c index f9421ec91f..e7b3197bb1 100644 --- a/libavcodec/mpeg_er.c +++ b/libavcodec/mpeg_er.c @@ -34,7 +34,7 @@ static void set_erpic(ERPicture *dst, const MPVPicture *src) } dst->f = src->f; - dst->tf = &src->tf; + dst->progress = &src->progress; for (i = 0; i < 2; i++) { dst->motion_val[i] = src->motion_val[i]; diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index 95255b893e..ea5d54c670 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -28,13 +28,13 @@ #include "motion_est.h" #include "mpegpicture.h" #include "refstruct.h" -#include "threadframe.h" static void mpv_pic_reset(FFRefStructOpaque unused, void *obj) { MPVPicture *pic = obj; - ff_thread_release_ext_buffer(&pic->tf); + av_frame_unref(pic->f); + ff_thread_progress_reset(&pic->progress); ff_refstruct_unref(&pic->hwaccel_picture_private); @@ -65,14 +65,18 @@ static void mpv_pic_reset(FFRefStructOpaque unused, void *obj) pic->coded_picture_number = 0; } -static int av_cold mpv_pic_init(FFRefStructOpaque unused, void *obj) +static int av_cold mpv_pic_init(FFRefStructOpaque opaque, void *obj) { MPVPicture *pic = obj; + int ret, init_progress = (uintptr_t)opaque.nc; + + ret = ff_thread_progress_init(&pic->progress, init_progress); + if (ret < 0) + return ret; pic->f = av_frame_alloc(); if (!pic->f) return AVERROR(ENOMEM); - pic->tf.f = pic->f; return 0; } @@ -80,12 +84,15 @@ static void av_cold mpv_pic_free(FFRefStructOpaque unused, void *obj) { MPVPicture *pic = obj; + ff_thread_progress_destroy(&pic->progress); av_frame_free(&pic->f); } -av_cold FFRefStructPool *ff_mpv_alloc_pic_pool(void) +av_cold FFRefStructPool *ff_mpv_alloc_pic_pool(int init_progress) { - return ff_refstruct_pool_alloc_ext(sizeof(MPVPicture), 0, NULL, + return ff_refstruct_pool_alloc_ext(sizeof(MPVPicture), + FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR, + (void*)(uintptr_t)init_progress, mpv_pic_init, mpv_pic_reset, mpv_pic_free, NULL); } diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index f6db4238b5..f9633e11db 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -26,7 +26,7 @@ #include "avcodec.h" #include "motion_est.h" -#include "threadframe.h" +#include "threadprogress.h" #define MPV_MAX_PLANES 3 #define EDGE_WIDTH 16 @@ -55,7 +55,6 @@ typedef struct BufferPoolContext { */ typedef struct MPVPicture { struct AVFrame *f; - ThreadFrame tf; int8_t *qscale_table_base; int8_t *qscale_table; @@ -87,6 +86,8 @@ typedef struct MPVPicture { int display_picture_number; int coded_picture_number; + + ThreadProgress progress; } MPVPicture; typedef struct MPVWorkPicture { @@ -111,7 +112,7 @@ typedef struct MPVWorkPicture { /** * Allocate a pool of MPVPictures. */ -struct FFRefStructPool *ff_mpv_alloc_pic_pool(void); +struct FFRefStructPool *ff_mpv_alloc_pic_pool(int init_progress); /** * Allocate an MPVPicture's accessories (but not the AVFrame's buffer itself) diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index d596f94df3..b7f72ad460 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -40,11 +40,13 @@ #include "mpeg4videodec.h" #include "refstruct.h" #include "thread.h" -#include "threadframe.h" +#include "threadprogress.h" #include "wmv2dec.h" int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx) { + enum ThreadingStatus thread_status; + ff_mpv_common_defaults(s); s->avctx = avctx; @@ -59,9 +61,12 @@ int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx) ff_mpv_idct_init(s); ff_h264chroma_init(&s->h264chroma, 8); //for lowres - if (!s->picture_pool && // VC-1 can call this multiple times - ff_thread_sync_ref(avctx, offsetof(MpegEncContext, picture_pool))) { - s->picture_pool = ff_mpv_alloc_pic_pool(); + if (s->picture_pool) // VC-1 can call this multiple times + return 0; + + thread_status = ff_thread_sync_ref(avctx, offsetof(MpegEncContext, picture_pool)); + if (thread_status != FF_THREAD_IS_COPY) { + s->picture_pool = ff_mpv_alloc_pic_pool(thread_status != FF_THREAD_NO_FRAME_THREADING); if (!s->picture_pool) return AVERROR(ENOMEM); } @@ -229,7 +234,6 @@ static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference) dst->ptr = pic; - pic->tf.f = pic->f; pic->reference = reference; /* WM Image / Screen codecs allocate internal buffers with different @@ -237,8 +241,8 @@ static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference) if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && avctx->codec_id != AV_CODEC_ID_VC1IMAGE && avctx->codec_id != AV_CODEC_ID_MSS2) { - ret = ff_thread_get_ext_buffer(avctx, &pic->tf, - reference ? AV_GET_BUFFER_FLAG_REF : 0); + ret = ff_thread_get_buffer(avctx, pic->f, + reference ? AV_GET_BUFFER_FLAG_REF : 0); } else { pic->f->width = avctx->width; pic->f->height = avctx->height; @@ -281,8 +285,7 @@ static int av_cold alloc_dummy_frame(MpegEncContext *s, MPVWorkPicture *dst) pic = dst->ptr; pic->dummy = 1; - ff_thread_report_progress(&pic->tf, INT_MAX, 0); - ff_thread_report_progress(&pic->tf, INT_MAX, 1); + ff_thread_progress_report(&pic->progress, INT_MAX); return 0; } @@ -418,7 +421,7 @@ void ff_mpv_frame_end(MpegEncContext *s) emms_c(); if (s->cur_pic.reference) - ff_thread_report_progress(&s->cur_pic.ptr->tf, INT_MAX, 0); + ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX); } void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict) @@ -484,7 +487,7 @@ void ff_mpeg_flush(AVCodecContext *avctx) void ff_mpv_report_decode_progress(MpegEncContext *s) { if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred) - ff_thread_report_progress(&s->cur_pic.ptr->tf, s->mb_y, 0); + ff_thread_progress_report(&s->cur_pic.ptr->progress, s->mb_y); } diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index df2ff67ed2..85ed52d9ad 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -823,7 +823,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) !FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_B_FRAMES + 1) || !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_B_FRAMES + 1) || !(s->new_pic = av_frame_alloc()) || - !(s->picture_pool = ff_mpv_alloc_pic_pool())) + !(s->picture_pool = ff_mpv_alloc_pic_pool(0))) return AVERROR(ENOMEM); /* Allocate MV tables; the MV and MB tables will be copied diff --git a/libavcodec/mpv_reconstruct_mb_template.c b/libavcodec/mpv_reconstruct_mb_template.c index 549c55ffad..9aacf380a1 100644 --- a/libavcodec/mpv_reconstruct_mb_template.c +++ b/libavcodec/mpv_reconstruct_mb_template.c @@ -124,12 +124,12 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], if (HAVE_THREADS && is_mpeg12 != DEFINITELY_MPEG12 && s->avctx->active_thread_type & FF_THREAD_FRAME) { if (s->mv_dir & MV_DIR_FORWARD) { - ff_thread_await_progress(&s->last_pic.ptr->tf, - lowest_referenced_row(s, 0), 0); + ff_thread_progress_await(&s->last_pic.ptr->progress, + lowest_referenced_row(s, 0)); } if (s->mv_dir & MV_DIR_BACKWARD) { - ff_thread_await_progress(&s->next_pic.ptr->tf, - lowest_referenced_row(s, 1), 0); + ff_thread_progress_await(&s->next_pic.ptr->progress, + lowest_referenced_row(s, 1)); } } diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 67f09c1f48..fd7819f52d 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -985,11 +985,6 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags) int ret; f->owner[0] = f->owner[1] = avctx; - /* Hint: It is possible for this function to be called with codecs - * that don't support frame threading at all, namely in case - * a frame-threaded decoder shares code with codecs that are not. - * This currently affects non-MPEG-4 mpegvideo codecs. - * The following check will always be true for them. */ if (!(avctx->active_thread_type & FF_THREAD_FRAME)) return ff_get_buffer(avctx, f->f, flags); diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 94d5ee30df..d3816df059 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -43,7 +43,7 @@ #include "qpeldsp.h" #include "rectangle.h" #include "thread.h" -#include "threadframe.h" +#include "threadprogress.h" #include "rv34vlc.h" #include "rv34data.h" @@ -719,8 +719,8 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type, if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) { /* wait for the referenced mb row to be finished */ int mb_row = s->mb_y + ((yoff + my + 5 + 8 * height) >> 4); - const ThreadFrame *f = dir ? &s->next_pic.ptr->tf : &s->last_pic.ptr->tf; - ff_thread_await_progress(f, mb_row, 0); + const ThreadProgress *p = dir ? &s->next_pic.ptr->progress : &s->last_pic.ptr->progress; + ff_thread_progress_await(p, mb_row); } dxy = ly*4 + lx; @@ -899,7 +899,7 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type) //surprisingly, it uses motion scheme from next reference frame /* wait for the current mb row to be finished */ if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) - ff_thread_await_progress(&s->next_pic.ptr->tf, FFMAX(0, s->mb_y-1), 0); + ff_thread_progress_await(&s->next_pic.ptr->progress, FFMAX(0, s->mb_y-1)); next_bt = s->next_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride]; if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){ @@ -1483,8 +1483,8 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int r->loop_filter(r, s->mb_y - 2); if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) - ff_thread_report_progress(&s->cur_pic.ptr->tf, - s->mb_y - 2, 0); + ff_thread_progress_report(&s->cur_pic.ptr->progress, + s->mb_y - 2); } if(s->mb_x == s->resync_mb_x) @@ -1582,7 +1582,7 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict) s->mb_num_left = 0; if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) - ff_thread_report_progress(&s->cur_pic.ptr->tf, INT_MAX, 0); + ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX); if (s->pict_type == AV_PICTURE_TYPE_B) { if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0) @@ -1810,7 +1810,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, ff_er_frame_end(&s->er, NULL); ff_mpv_frame_end(s); s->mb_num_left = 0; - ff_thread_report_progress(&s->cur_pic.ptr->tf, INT_MAX, 0); + ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX); return AVERROR_INVALIDDATA; } }