From patchwork Tue Sep 12 11:40:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Guillem X-Patchwork-Id: 43709 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp2721127pzb; Tue, 12 Sep 2023 04:40:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5aaVSF14jqJUANkoQRFtz0sAUzF4BXRPgcVIOKIG2KspMVt/+Stcu1kFdjiWcRHeGU68H X-Received: by 2002:a17:906:319a:b0:9a6:1446:852c with SMTP id 26-20020a170906319a00b009a61446852cmr11103928ejy.27.1694518835827; Tue, 12 Sep 2023 04:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694518835; cv=none; d=google.com; s=arc-20160816; b=paU/Hd/6QW7f/UO7P3nnuY+t1BMFs0FhNtl6AGTK/QUTlj9qBrgqxIbppEm563Ll67 XlJbCekV/nS8q7D2XJQAaciK47ALjK3sE4zOitLZn9//1PEqd265gMOHpJKlnyieZKtE 0ZeNwkY6BJCzLF23O6EmmqAMaj3kOb/mZCqHHbPB4aV0D11iYeQWM3BMW9nG4Y893j4M Lx/hivQeqLHCjPCMRHMnxk0UASH+vRnW+FNkvDbfLbSHyC/9wv2R4/KU1qwBtTqmIWZQ vkJ4riiVsmXKXdj1AMf1eXI08v+lX3zdgNAdS+rWUSfu/6sLk4jJyfQ1RYXSutEZNZ5h LC/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to :feedback-id:delivered-to; bh=IAdkUMfeQT8IGOPAem5X3e/FI1TnkT79MWpNdcExZ38=; fh=3LY024vSFS/PP4LTfcCy63MQoPE5JAibP23dzfT0gvE=; b=TdqGuw5vIS0rHz3m5MJbhHomkR0ZC9qelP70Q0TsNQ3vjoqO2c/xegd7MA1dkC2BFX aoQZdt5VSmjaktYKrVnvKlQd+tX9j9Xvo/KvfGmMvQFYj/omZUCoST+DbtQ37/gbZG53 55CvInEXwOhOQRH8fJ4rPz4lGqQa58ltN8SaBRzh3CptVootC/YLplsRgJ1xjp02jxv0 gRs8Y/LylPajCh6UgJ50KXHAXk5l28FBOwgvKWhEM/g7qUc7GdZEZ4JrVZIZJ2+/uhqM GoDJdvXkJ/406X8rfV0GJvllJnp8Vq/mU7hnYzrIRU2O8/coEotCxJU6kPTAqeUNYhKa UisA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u22-20020a1709060b1600b0098e47bbff3csi8154021ejg.297.2023.09.12.04.40.32; Tue, 12 Sep 2023 04:40:35 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 148CF68C8E9; Tue, 12 Sep 2023 14:40:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 231CB68C90E for ; Tue, 12 Sep 2023 14:40:20 +0300 (EEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id A842B5C02E0 for ; Tue, 12 Sep 2023 07:40:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 12 Sep 2023 07:40:18 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgggfestdekredtre dttdenucfhrhhomhepvfhhohhmrghsucfiuhhilhhlvghmuceothhhohhmrghssehglhhl mhdrfhhrqeenucggtffrrghtthgvrhhnpefgtdelgfevtddtledufeetgfefjeehgefhvd evffevgfdtvedtkeejieekvefgjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehthhhomhgrshesghhllhhmrdhfrh X-ME-Proxy: Feedback-ID: i239440f1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 12 Sep 2023 07:40:17 -0400 (EDT) To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Sep 2023 13:40:13 +0200 Message-Id: <20230912114015.59937-1-thomas@gllm.fr> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] error_resilience: set the decode_error_flags outside 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: , X-Patchwork-Original-From: Thomas Guillem via ffmpeg-devel From: Thomas Guillem Reply-To: FFmpeg development discussions and patches Cc: Thomas Guillem Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ++2P716HLqte This will allow to fix data-races when ff_er_frame_end() is called after ff_thread_finish_setup() --- libavcodec/error_resilience.c | 12 ++++++------ libavcodec/error_resilience.h | 2 +- libavcodec/h263dec.c | 6 ++++-- libavcodec/h264dec.c | 3 ++- libavcodec/mpeg12dec.c | 3 ++- libavcodec/mss2.c | 8 +++++--- libavcodec/rv10.c | 10 ++++++++-- libavcodec/rv34.c | 12 +++++++++--- libavcodec/vc1dec.c | 6 ++++-- 9 files changed, 41 insertions(+), 21 deletions(-) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index 68e20925e0..1f43b233ff 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -889,7 +889,7 @@ void ff_er_add_slice(ERContext *s, int startx, int starty, } } -void ff_er_frame_end(ERContext *s) +int ff_er_frame_end(ERContext *s) { int *linesize = NULL; int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error; @@ -906,7 +906,7 @@ void ff_er_frame_end(ERContext *s) !er_supported(s) || atomic_load(&s->error_count) == 3 * s->mb_width * (s->avctx->skip_top + s->avctx->skip_bottom)) { - return; + return 0; } linesize = s->cur_pic.f->linesize; @@ -921,7 +921,7 @@ void ff_er_frame_end(ERContext *s) if (mb_x == s->mb_width) { av_log(s->avctx, AV_LOG_DEBUG, "ignoring last missing slice\n"); - return; + return 0; } } @@ -960,7 +960,7 @@ void ff_er_frame_end(ERContext *s) s->cur_pic.ref_index[i] = NULL; s->cur_pic.motion_val[i] = NULL; } - return; + return 0; } } @@ -1114,8 +1114,6 @@ void ff_er_frame_end(ERContext *s) av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n", dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic.f->pict_type)); - s->cur_pic.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; - is_intra_likely = is_intra_more_likely(s); /* set unknown mb-type to most likely */ @@ -1352,4 +1350,6 @@ void ff_er_frame_end(ERContext *s) memset(&s->cur_pic, 0, sizeof(ERPicture)); memset(&s->last_pic, 0, sizeof(ERPicture)); memset(&s->next_pic, 0, sizeof(ERPicture)); + + return 1; } diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h index 47cc8a4fc6..a8cf73c72e 100644 --- a/libavcodec/error_resilience.h +++ b/libavcodec/error_resilience.h @@ -90,7 +90,7 @@ typedef struct ERContext { } ERContext; void ff_er_frame_start(ERContext *s); -void ff_er_frame_end(ERContext *s); +int ff_er_frame_end(ERContext *s); void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status); diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 52e51dd489..3e83d90586 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -621,8 +621,10 @@ retry: av_assert1(s->bitstream_buffer_size == 0); frame_end: - if (!s->studio_profile) - ff_er_frame_end(&s->er); + if (!s->studio_profile) { + if (ff_er_frame_end(&s->er) > 0) + s->current_picture.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; + } if (avctx->hwaccel) { ret = FF_HW_SIMPLE_CALL(avctx, end_frame); diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index f13b1081fc..553f300c3d 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -779,7 +779,8 @@ end: if (sl->ref_count[1]) ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent); - ff_er_frame_end(&h->er); + if (ff_er_frame_end(&h->er) > 0) + h->cur_pic_ptr->f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; if (use_last_pic) memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0])); } diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 1accd07e9e..b2cc78c3d3 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2033,7 +2033,8 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict) if (/* s->mb_y << field_pic == s->mb_height && */ !s->first_field && !s1->first_slice) { /* end of image */ - ff_er_frame_end(&s->er); + if (ff_er_frame_end(&s->er) > 0) + s->current_picture_ptr->f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; ff_mpv_frame_end(s); diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c index 70aa56cb84..29cb4be614 100644 --- a/libavcodec/mss2.c +++ b/libavcodec/mss2.c @@ -421,8 +421,12 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, ff_vc1_decode_blocks(v); + f = s->current_picture.f; + if (v->end_mb_x == s->mb_width && s->end_mb_y == s->mb_height) { - ff_er_frame_end(&s->er); + if (ff_er_frame_end(&s->er) > 0) + f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; + } else { av_log(v->s.avctx, AV_LOG_WARNING, "disabling error correction due to block count mismatch %dx%d != %dx%d\n", @@ -431,8 +435,6 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, ff_mpv_frame_end(s); - f = s->current_picture.f; - if (v->respic == 3) { ctx->dsp.upsample_plane(f->data[0], f->linesize[0], w, h); ctx->dsp.upsample_plane(f->data[1], f->linesize[1], w+1 >> 1, h+1 >> 1); diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 5edd934f82..6d7ae8f903 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -440,6 +440,12 @@ static av_cold int rv10_decode_end(AVCodecContext *avctx) return 0; } +static void rv10_er_frame_end(MpegEncContext *s) +{ + if (ff_er_frame_end(&s->er) > 0) + s->current_picture_ptr->f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; +} + static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int buf_size2, int whole_size) { @@ -477,7 +483,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, if ((s->mb_x == 0 && s->mb_y == 0) || !s->current_picture_ptr) { // FIXME write parser so we always have complete frames? if (s->current_picture_ptr) { - ff_er_frame_end(&s->er); + rv10_er_frame_end(s); ff_mpv_frame_end(s); s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0; } @@ -649,7 +655,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict, } if (s->current_picture_ptr && s->mb_y >= s->mb_height) { - ff_er_frame_end(&s->er); + rv10_er_frame_end(s); ff_mpv_frame_end(s); if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index af4d6a3400..cae6e9d81b 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -1554,13 +1554,19 @@ static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n, in return buf_size; } +static void rv34_er_frame_end(MpegEncContext *s) +{ + if (ff_er_frame_end(&s->er) > 0) + s->current_picture_ptr->f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; +} + static int finish_frame(AVCodecContext *avctx, AVFrame *pict) { RV34DecContext *r = avctx->priv_data; MpegEncContext *s = &r->s; int got_picture = 0, ret; - ff_er_frame_end(&s->er); + rv34_er_frame_end(s); ff_mpv_frame_end(s); s->mb_num_left = 0; @@ -1655,7 +1661,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n", s->mb_num_left); if (!s->context_reinit) - ff_er_frame_end(&s->er); + rv34_er_frame_end(s); ff_mpv_frame_end(s); } @@ -1790,7 +1796,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n"); /* always mark the current frame as finished, frame-mt supports * only complete frames */ - ff_er_frame_end(&s->er); + rv34_er_frame_end(s); ff_mpv_frame_end(s); s->mb_num_left = 0; ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0); diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index b8663aaf98..7113abd0a9 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -1347,8 +1347,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, } if ( !v->field_mode && avctx->codec_id != AV_CODEC_ID_WMV3IMAGE - && avctx->codec_id != AV_CODEC_ID_VC1IMAGE) - ff_er_frame_end(&s->er); + && avctx->codec_id != AV_CODEC_ID_VC1IMAGE) { + if (ff_er_frame_end(&s->er) > 0) + s->current_picture.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; + } } ff_mpv_frame_end(s); From patchwork Tue Sep 12 11:40:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Guillem X-Patchwork-Id: 43711 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp2721276pzb; Tue, 12 Sep 2023 04:40:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEM96uY738o+LaeV6Mk0GQxIQlunmokL/ZvdG6do+Y/SessIbS2+OeVp7NWoV5NO4Lajsed X-Received: by 2002:a05:6402:f83:b0:52f:a763:aab4 with SMTP id eh3-20020a0564020f8300b0052fa763aab4mr1942904edb.5.1694518854059; Tue, 12 Sep 2023 04:40:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694518854; cv=none; d=google.com; s=arc-20160816; b=03k1NOlPl6a0B1WMvhv9C5sV5fW4GIZ8LkvYjKYNF6Wo161CtuFywqkykxGEHTk9Or YJ1f3wz9kv0StYFUzmpRUaVmcKKmi7iK6QoXFRM+LCCyb6KvMXBch+K+O4lCHG5P0yuL cQj8yNZDoStbKaWdRle+DLPuuTJwVZCcN4ZE/5Bn8z2b7lnBfzgpSJ85D5YEJI4ANVgw uFzbXw5uEIXSpt92P1VaYUiJ+ixiOXrl8Es1c8oEFOhnIQOaqcvKiB78y70JDMrQZ1sz wiMHHJdtHUkoAn/Lu7ySIEoI2giPS+AeEkWvwBMBbLjbgSS8f9eOCrFP/iyzfykHfr5E 6LJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:feedback-id:delivered-to; bh=pdKqYenCSP8tnzNvwOeHkSCr0Me9pbylXvK5hhE9Yg8=; fh=3LY024vSFS/PP4LTfcCy63MQoPE5JAibP23dzfT0gvE=; b=ndElRKEHM7LOG7O0/38ntrwq+D1STvowCD27Q21oQr2x63+dsfa4lZzM36rHYvWCVs M7cUaZrxKL3z4q8g30BO0okGxXUng+PuEMcoVNOkDslXGTVSOpONXaKSkw9igj0BKOr6 zMxDKL1POUQ8uKVx0em709UNkYFObNdo4t5x60cO2MXKkOdNNuaAS3OllTgBCN05rFQ8 dEDpVZ6pPkiN9wXp36BEcvzMHUJpyaYuVM4lgSU5zr4qHqRy8knusVU+f7TNFoYPRuCz PbEuIxKiLaGcjZbMvnbhrYhNH5HgdUNlQocPdYgFt4M7LhAv6ccqVaZzdE1YNDCa/gpy G5Sg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v1-20020a056402348100b0052f58978dedsi4761432edc.260.2023.09.12.04.40.53; Tue, 12 Sep 2023 04:40:54 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5981468C980; Tue, 12 Sep 2023 14:40:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 201F568C8E9 for ; Tue, 12 Sep 2023 14:40:20 +0300 (EEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 756755C02AD for ; Tue, 12 Sep 2023 07:40:19 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 12 Sep 2023 07:40:19 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfhhohhmrghsucfiuhhilhhlvghmuceothhhohhmrghssehg lhhlmhdrfhhrqeenucggtffrrghtthgvrhhnpeduledukeevudekudekfffgleehtdehvd efgeeiveduhfdvfeejkeefhefhhefgueenucffohhmrghinheptghomhhmohhnrdhfihhl mhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthh homhgrshesghhllhhmrdhfrh X-ME-Proxy: Feedback-ID: i239440f1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 12 Sep 2023 07:40:18 -0400 (EDT) To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Sep 2023 13:40:14 +0200 Message-Id: <20230912114015.59937-2-thomas@gllm.fr> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912114015.59937-1-thomas@gllm.fr> References: <20230912114015.59937-1-thomas@gllm.fr> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] h264: fix data-race with FF_DECODE_ERROR_CONCEALMENT_ACTIVE 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: , X-Patchwork-Original-From: Thomas Guillem via ffmpeg-devel From: Thomas Guillem Reply-To: FFmpeg development discussions and patches Cc: Thomas Guillem Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AIbC/aCbkXjK Set the FF_DECODE_ERROR_CONCEALMENT_ACTIVE flags on the AVFrane before outputing it. Store in in the H264Picture in the meantime, where it won't be read/write by other threads. Fix the following data-race: WARNING: ThreadSanitizer: data race (pid=55134) Write of size 4 at 0x7b5000007f78 by thread T1 (mutexes: write M58): #0 decode_nal_units src/libavcodec/h264dec.c:783 (ffmpeg+0xb1a678) #1 h264_decode_frame src/libavcodec/h264dec.c:1014 (ffmpeg+0xb1a678) #2 frame_worker_thread src/libavcodec/pthread_frame.c:228 (ffmpeg+0xdeea6e) Previous read of size 4 at 0x7b5000007f78 by thread T14 (mutexes: write M60): #0 frame_copy_props src/libavutil/frame.c:321 (ffmpeg+0x1793739) #1 av_frame_replace src/libavutil/frame.c:530 (ffmpeg+0x17946f4) #2 ff_thread_replace_frame src/libavcodec/utils.c:898 (ffmpeg+0xfb1cff) #3 ff_h264_replace_picture src/libavcodec/h264_picture.c:159 (ffmpeg+0x149cd2d) #4 ff_h264_update_thread_context src/libavcodec/h264_slice.c:413 (ffmpeg+0x14abee4) #5 update_context_from_thread src/libavcodec/pthread_frame.c:355 (ffmpeg+0xdec38c) #6 submit_packet src/libavcodec/pthread_frame.c:494 (ffmpeg+0xdeced3) #7 ff_thread_decode_frame src/libavcodec/pthread_frame.c:545 (ffmpeg+0xdeced3) #8 decode_simple_internal src/libavcodec/decode.c:431 (ffmpeg+0x9e1e20) #9 decode_simple_receive_frame src/libavcodec/decode.c:607 (ffmpeg+0x9e1e20) #10 decode_receive_frame_internal src/libavcodec/decode.c:635 (ffmpeg+0x9e1e20) #11 avcodec_send_packet src/libavcodec/decode.c:732 (ffmpeg+0x9e28fa) #12 packet_decode src/fftools/ffmpeg_dec.c:555 (ffmpeg+0x229888) #13 decoder_thread src/fftools/ffmpeg_dec.c:702 (ffmpeg+0x229888) --- libavcodec/h264_slice.c | 1 + libavcodec/h264dec.c | 4 +++- libavcodec/h264dec.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 6cd7bb8fe7..249c764d13 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -535,6 +535,7 @@ FF_ENABLE_DEPRECATION_WARNINGS pic->f->crop_right = h->crop_right; pic->f->crop_top = h->crop_top; pic->f->crop_bottom = h->crop_bottom; + pic->decode_error_flags = 0; pic->needs_fg = h->sei.common.film_grain_characteristics.present && !h->avctx->hwaccel && !(h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN); diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 553f300c3d..24e849fc5b 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -780,7 +780,7 @@ end: ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent); if (ff_er_frame_end(&h->er) > 0) - h->cur_pic_ptr->f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; + h->cur_pic_ptr->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; if (use_last_pic) memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0])); } @@ -849,6 +849,8 @@ static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp) if (ret < 0) return ret; + dst->decode_error_flags |= srcp->decode_error_flags; + if (srcp->needs_fg && (ret = av_frame_copy_props(dst, srcp->f)) < 0) return ret; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index beaab3902c..cb3d5cef00 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -152,6 +152,8 @@ typedef struct H264Picture { int mb_width, mb_height; int mb_stride; + + int decode_error_flags; } H264Picture; typedef struct H264Ref { From patchwork Tue Sep 12 11:40:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Guillem X-Patchwork-Id: 43710 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp2721199pzb; Tue, 12 Sep 2023 04:40:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFYlkQvYGzL+EP/RXlnTLef3xYfgRC/oY57bo/xldLUXOYfp9AP8CoNfAGvlDLLzjJl0wVW X-Received: by 2002:a05:6512:31c5:b0:502:a588:6609 with SMTP id j5-20020a05651231c500b00502a5886609mr10648447lfe.3.1694518844711; Tue, 12 Sep 2023 04:40:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694518844; cv=none; d=google.com; s=arc-20160816; b=QXRzE3AFIVmfAvafokV7mTd4YVn6yw2OUSIHIHm3JX47aCxDRS8FV5vDkYHlvFdlV0 jtc2mrOlD8A2P0cDRkD5KRHHdW4V0a5qhlx5Y//ims0FOLbHJAmbjOkI0umo7plBrVRW rOCt2V4Pi/0/cMpqc7mXov1BZhDh5258q7xkjH4wFxveCWsCJEqzR/oxJgSGlTJ5PL9N 9v7/Yf5vK4G4Kred9sDwQYIwXlr//jdYRe3T0Q9bySv4ENL3ZHXYgPXraOL/RNp+u4o4 SvFm0EKKJlJ4bLMroTtrNnAmaNW6SnrVN/YaIie8E8B4MpAmwkSpeJE3NmE90+k0R9XS a+IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:feedback-id:delivered-to; bh=HfPr1xLWmIdxfBshZaugZ6KuTPHTJccuoAWk48ya9Wk=; fh=3LY024vSFS/PP4LTfcCy63MQoPE5JAibP23dzfT0gvE=; b=IpIQ1tVuIHdW9QNqg46tzrcML92ZXXXE5u9WoE1B7d0RHt3WhflOXhGT55v1Koiu68 35oGp5tgyW+/gY/RDA4SCr8leGrbeV8K7qYgc9jSgcv5o7yQNiewUTV+11VTE6M+1BTf 9h1C2eGB/qXpoyRG/6Gfgrm8FUCPtoQMqGNZ+rxfi5Z11hDdqu0KU6+GRb6RJoV4Y9fS 4wRcpv1Sw4UTefQ0Tbxs016z6nON7PXwCZqLrB9JsMZsHFxR4+l19BMt9c8QNs2rT9Cv iVL3tznNsXqiwh7AFrTtJMfliPTN29aX88+9z+LK5eLe/zL9bgLfLb7WpP3Fu3Im9Mj5 iBFw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i1-20020a50fc01000000b0052a0fd83709si7787453edr.540.2023.09.12.04.40.43; Tue, 12 Sep 2023 04:40:44 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 33BB468C96E; Tue, 12 Sep 2023 14:40:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DC1E68C92F for ; Tue, 12 Sep 2023 14:40:21 +0300 (EEST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4EFE35C02E7 for ; Tue, 12 Sep 2023 07:40:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 12 Sep 2023 07:40:20 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfhhohhmrghsucfiuhhilhhlvghmuceothhhohhmrghssehg lhhlmhdrfhhrqeenucggtffrrghtthgvrhhnpeejieegveejteejteegvdfhjeeffeehfe efuddvhfffleegfeehleekudekleefleenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesghhllhhmrdhfrh X-ME-Proxy: Feedback-ID: i239440f1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 12 Sep 2023 07:40:19 -0400 (EDT) To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Sep 2023 13:40:15 +0200 Message-Id: <20230912114015.59937-3-thomas@gllm.fr> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912114015.59937-1-thomas@gllm.fr> References: <20230912114015.59937-1-thomas@gllm.fr> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] h264: fix data-race with FF_DECODE_ERROR_DECODE_SLICES 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: , X-Patchwork-Original-From: Thomas Guillem via ffmpeg-devel From: Thomas Guillem Reply-To: FFmpeg development discussions and patches Cc: Thomas Guillem Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: D/ndzw06CiIF Same than the previous commit but with FF_DECODE_ERROR_DECODE_SLICES Fix the following data-race: WARNING: ThreadSanitizer: data race (pid=55935) Write of size 4 at 0x7b5000009378 by thread T1 (mutexes: write M608): #0 decode_nal_units src/libavcodec/h264dec.c:742 (ffmpeg+0xb19dd6) #1 h264_decode_frame src/libavcodec/h264dec.c:1016 (ffmpeg+0xb19dd6) #2 frame_worker_thread src/libavcodec/pthread_frame.c:228 (ffmpeg+0xdeea7e) Previous read of size 4 at 0x7b5000009378 by thread T14 (mutexes: write M610): #0 frame_copy_props src/libavutil/frame.c:321 (ffmpeg+0x1793759) #1 av_frame_replace src/libavutil/frame.c:530 (ffmpeg+0x1794714) #2 ff_thread_replace_frame src/libavcodec/utils.c:898 (ffmpeg+0xfb1d0f) #3 ff_h264_replace_picture src/libavcodec/h264_picture.c:159 (ffmpeg+0x149cd3d) #4 ff_h264_update_thread_context src/libavcodec/h264_slice.c:413 (ffmpeg+0x14abf04) #5 update_context_from_thread src/libavcodec/pthread_frame.c:355 (ffmpeg+0xdec39c) #6 submit_packet src/libavcodec/pthread_frame.c:494 (ffmpeg+0xdecee3) #7 ff_thread_decode_frame src/libavcodec/pthread_frame.c:545 (ffmpeg+0xdecee3) #8 decode_simple_internal src/libavcodec/decode.c:431 (ffmpeg+0x9e1e20) #9 decode_simple_receive_frame src/libavcodec/decode.c:607 (ffmpeg+0x9e1e20) #10 decode_receive_frame_internal src/libavcodec/decode.c:635 (ffmpeg+0x9e1e20) #11 avcodec_send_packet src/libavcodec/decode.c:732 (ffmpeg+0x9e28fa) #12 packet_decode src/fftools/ffmpeg_dec.c:555 (ffmpeg+0x229888) #13 decoder_thread src/fftools/ffmpeg_dec.c:702 (ffmpeg+0x229888) --- libavcodec/h264dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 24e849fc5b..b82ca8f14f 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -739,7 +739,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) // set decode_error_flags to allow users to detect concealed decoding errors if ((ret < 0 || h->er.error_occurred) && h->cur_pic_ptr) { - h->cur_pic_ptr->f->decode_error_flags |= FF_DECODE_ERROR_DECODE_SLICES; + h->cur_pic_ptr->decode_error_flags |= FF_DECODE_ERROR_DECODE_SLICES; } ret = 0;