From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 817AA4F554 for ; Fri, 27 Feb 2026 17:14:31 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'48GfO4ZqPoSa92vW4T3Fw3jTOVMCua8U73nSHBh+UkM=', expected b'I1MygXv1dTsJlHjCFLT3x9l6rKfGUFzdsC3Nf30WnPo=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1772212443; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=48GfO4ZqPoSa92vW4T3Fw3jTOVMCua8U73nSHBh+UkM=; b=2VD+QEzaZEp7qX2CPRxOZMDn8S+rrr36B2Q2axiE+lK/uQcMOFad5cVIHOV9C1fh0dyOS 8O743mM6R9Jez86dKOB906IiIOrqEDVxd3ecseVKduIW3OH8oYjYzdNW09uOyPolgF+olAW LkY/d/smGOOHh+dBpO8sx4pM0GIYX0MTj1hMlbOSMtFvMV+15f6J7/qMqLci30xlZol9e6b 9Up/M/MaFKRVQKxyUctGXeUICVKZEkoX9YMz8M+ycgTWKs39fShkax+w/sAcpMVWH3Fb3Ox G/snMlb9t0+bnA7+qoplTk5uVrKFmLAOua+l19/kt3DqCp095yZBwy4BL15Q== Received: from [172.18.0.3] (unknown [172.18.0.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 3A2366913BA; Fri, 27 Feb 2026 19:14:03 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1772212427; b=LBQ6Gu0wVv7jK/VPKIp0qYh8/bSm/j9kD9oJrVy2iivQmo8WzcFEDfCXiyC0rBZ/2xa7w dh05gdlPZwwC8M3ro+Y34ZkNxqazsRil1KsGOapd8brQuTfLvAWkn6P8rSt6aIHIttCJ0c7 vxzJXjpnbNvZfzzB/EaF3Fz/zrpDn8Y2sCy5z4Gv8RoYRN+UIiKNt52L+S31FrTQrk+58gh eLvyauXMMZQaVi58tiYd6JGJc+BJJyJHKK3wyVNE6//AgypmHwx/2s3US7dtGWlbfgG7qbc 0LdnGyS4qPbQ3af+CasG7AzjenSuMxYT73zOM9Ip34E/mVagyXVH3HUs2GtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1772212427; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=b9vY6vK8Q5NY4Y6OwMFEC60xr2VPtWHz9hCwnkbDWfw=; b=JHXH8WGUxN/IfXaqUKmi8T1Q5IwvwwCnXLE+b2yAWYZFC3vH/womUZ0kL/ZEAe7ugUTsn KLGHmO0dkQm//QnIr9QMqLfBOfLLP3u18A7CeRosP7gJ+/6ECqi0DqXa2OD36OPLNq1NL// GRQKR69XjUHYJskDEmYEHinaGuYbUHfxiGo4VmrfUYhPedSzSo9ITMChFDMsXvGcErf7vpz etF5Fe1iRUs9rI4JKd2/431vRAw+APg4gw0oNUibEypdcRUZehV8A+122dWjXGS/RKqIiL7 u2qrO3jTlps5psR8nbG5mKTHCqhpIDER024be4J7bTXSTPvvBxmbT1pmifEA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1772212420; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=I1MygXv1dTsJlHjCFLT3x9l6rKfGUFzdsC3Nf30WnPo=; b=kt7AYg3dtzM3Yi4T/6AOEHqsHsd8Psdx5a4O60mhrILmqhZrAbxzTPiFH0kqZWIIWA62m F2rIxDy2UrHef11MQFBMHjErNjpr4k0G12XZD2Tz63Sur1iB/JE1StmGyf55fZuIVRHJsim YMNsjcizRguZX1Gvutf1nskD9jKoVaDoKMNUxEOkO3oSylxWwkt2mOxOq9Vx/ungiAQe1EM c94fw/it2YP6YSabDSpHXw38Flx1F3LaFwsNYnBKVodt5EzDkFTx8qD27R2oGmyY3Tk/NMj hwFZiZJI4wAhhJ2LGIOhU7heJXDjnPywJjq5JbrBfZJSF3Woedsqp5u7Fd0Q== MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Feb 2026 17:13:39 -0000 Message-ID: <177221242024.25.11813395396704791005@29965ddac10e> Message-ID-Hash: 4UA56GWD4KLOLIAXADNNL3PMCDG6JIP5 X-Message-ID-Hash: 4UA56GWD4KLOLIAXADNNL3PMCDG6JIP5 X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PR] avcodec/error_resilience: Initialize error resilience context earlier (PR #22318) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: mkver via ffmpeg-devel Cc: mkver Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #22318 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22318 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22318.patch (Btw: Could someone please port the me_cmp 16x16 sum-of-absolute-differences functions for arches != x86 to pixelutils, so that we can avoid the error_resilience->mc_cmp dependency?) >>From c822d0249ac9f05678a4b7f7ece94c55b57e2f32 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 27 Feb 2026 16:36:00 +0100 Subject: [PATCH 1/2] avcodec/error_resilience: Initialize error resilience context earlier Signed-off-by: Andreas Rheinhardt --- libavcodec/error_resilience.c | 16 +++++++++------- libavcodec/error_resilience.h | 3 ++- libavcodec/h264dec.c | 2 ++ libavcodec/mpeg_er.c | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index cf6f83e096..76d5bfa73b 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -28,6 +28,7 @@ #include #include "libavutil/avassert.h" +#include "libavutil/attributes.h" #include "libavutil/mem.h" #include "avcodec.h" #include "error_resilience.h" @@ -38,6 +39,14 @@ #include "threadframe.h" #include "threadprogress.h" +av_cold void ff_er_init(ERContext *const s) +{ + MECmpContext mecc; + + ff_me_cmp_init(&mecc, s->avctx); + s->sad = mecc.sad[0]; +} + /** * @param stride the number of MVs to get to the next row * @param mv_step the number of MVs per row or column in a macroblock @@ -795,13 +804,6 @@ void ff_er_frame_start(ERContext *s) if (!s->avctx->error_concealment) return; - if (!s->mecc_inited) { - MECmpContext mecc; - ff_me_cmp_init(&mecc, s->avctx); - s->sad = mecc.sad[0]; - s->mecc_inited = 1; - } - memset(s->error_status_table, ER_MB_ERROR | VP_START | ER_MB_END, s->mb_stride * s->mb_height * sizeof(uint8_t)); atomic_init(&s->error_count, 3 * s->mb_num); diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h index 8e43219b09..6c8736a445 100644 --- a/libavcodec/error_resilience.h +++ b/libavcodec/error_resilience.h @@ -56,7 +56,6 @@ typedef struct ERContext { int (*sad)(MPVEncContext *unused, const uint8_t *blk1, const uint8_t *blk2, ptrdiff_t stride, int h); - int mecc_inited; int *mb_index2xy; int mb_num; @@ -91,6 +90,8 @@ typedef struct ERContext { void *opaque; } ERContext; +void ff_er_init(ERContext *const s); + void ff_er_frame_start(ERContext *s); /** diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index ab31832308..e430bc58fc 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -255,6 +255,8 @@ int ff_h264_alloc_tables(H264Context *h) er->dc_val[2] = er->dc_val[1] + big_mb_num; for (int i = 0; i < yc_size; i++) h->dc_val_base[i] = 1024; + + ff_er_init(er); } return 0; diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c index 5df75d8e85..93eb9221d7 100644 --- a/libavcodec/mpeg_er.c +++ b/libavcodec/mpeg_er.c @@ -122,6 +122,8 @@ av_cold int ff_mpeg_er_init(MpegEncContext *s) er->decode_mb = mpeg_er_decode_mb; er->opaque = s; + ff_er_init(er); + return 0; fail: av_freep(&er->er_temp_buffer); -- 2.52.0 >>From 18fd5b69ee87faf63deaf724f0fe6317ab28d9c2 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 27 Feb 2026 17:55:18 +0100 Subject: [PATCH 2/2] avcodec/h264dec,mpeg_er: Move allocating er buffers to ff_er_init() (This also stops zero-allocating er_temp_buffer for H.264, reverting back to the behavior from before commit 0a1dc817237b8546189960efd523257b4f62e1ab.) Signed-off-by: Andreas Rheinhardt --- libavcodec/error_resilience.c | 12 +++++++++++- libavcodec/error_resilience.h | 2 +- libavcodec/h264dec.c | 6 +----- libavcodec/mpeg_er.c | 14 +------------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index 76d5bfa73b..8cf5bc6a3c 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -39,12 +39,22 @@ #include "threadframe.h" #include "threadprogress.h" -av_cold void ff_er_init(ERContext *const s) +av_cold int ff_er_init(ERContext *const s) { MECmpContext mecc; + unsigned mb_array_size = s->mb_height * s->mb_stride; + + s->error_status_table = av_mallocz(mb_array_size); + if (!s->error_status_table) + return AVERROR(ENOMEM); + s->er_temp_buffer = av_malloc_array(mb_array_size, 4*sizeof(int) + 1); + if (!s->er_temp_buffer) + return AVERROR(ENOMEM); ff_me_cmp_init(&mecc, s->avctx); s->sad = mecc.sad[0]; + + return 0; } /** diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h index 6c8736a445..1beae5a6b0 100644 --- a/libavcodec/error_resilience.h +++ b/libavcodec/error_resilience.h @@ -90,7 +90,7 @@ typedef struct ERContext { void *opaque; } ERContext; -void ff_er_init(ERContext *const s); +int ff_er_init(ERContext *const s); void ff_er_frame_start(ERContext *s); diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index e430bc58fc..809a938386 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -220,8 +220,6 @@ int ff_h264_alloc_tables(H264Context *h) } if (CONFIG_ERROR_RESILIENCE) { - const int er_size = h->mb_height * h->mb_stride * (4*sizeof(int) + 1); - int mb_array_size = h->mb_height * h->mb_stride; int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1); int yc_size = y_size + 2 * big_mb_num; @@ -239,8 +237,6 @@ int ff_h264_alloc_tables(H264Context *h) // error resilience code looks cleaner with this if (!FF_ALLOCZ_TYPED_ARRAY(er->mb_index2xy, h->mb_num + 1) || - !FF_ALLOCZ_TYPED_ARRAY(er->error_status_table, mb_array_size) || - !FF_ALLOCZ_TYPED_ARRAY(er->er_temp_buffer, er_size) || !FF_ALLOCZ_TYPED_ARRAY(h->dc_val_base, yc_size)) return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us @@ -256,7 +252,7 @@ int ff_h264_alloc_tables(H264Context *h) for (int i = 0; i < yc_size; i++) h->dc_val_base[i] = 1024; - ff_er_init(er); + return ff_er_init(er); } return 0; diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c index 93eb9221d7..5bb5ed8441 100644 --- a/libavcodec/mpeg_er.c +++ b/libavcodec/mpeg_er.c @@ -96,7 +96,6 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, av_cold int ff_mpeg_er_init(MpegEncContext *s) { ERContext *er = &s->er; - int mb_array_size = s->mb_height * s->mb_stride; er->avctx = s->avctx; @@ -111,22 +110,11 @@ av_cold int ff_mpeg_er_init(MpegEncContext *s) er->dc_val[1] = er->dc_val[0] + s->b8_stride * 2 * s->buffer_pools.alloc_mb_height + s->mb_stride; er->dc_val[2] = er->dc_val[1] + s->mb_stride * (s->buffer_pools.alloc_mb_height + 1); - er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride * (4*sizeof(int) + 1)); - er->error_status_table = av_mallocz(mb_array_size); - if (!er->er_temp_buffer || !er->error_status_table) - goto fail; - er->mbskip_table = s->mbskip_table; er->mbintra_table = s->mbintra_table; er->decode_mb = mpeg_er_decode_mb; er->opaque = s; - ff_er_init(er); - - return 0; -fail: - av_freep(&er->er_temp_buffer); - av_freep(&er->error_status_table); - return AVERROR(ENOMEM); + return ff_er_init(er); } -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org