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 {