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 D06C34625A for ; Tue, 12 Sep 2023 11:40:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2774B68C978; Tue, 12 Sep 2023 14:40:30 +0300 (EEST) 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: , From: Thomas Guillem via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Thomas Guillem 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: 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 { -- 2.39.2 _______________________________________________ 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".