From patchwork Wed Dec 2 04:22:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24317 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4C2E644B17D for ; Wed, 2 Dec 2020 06:37:24 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0774F68A765; Wed, 2 Dec 2020 06:24:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EF23368A2A2 for ; Wed, 2 Dec 2020 06:24:40 +0200 (EET) Received: by mail-ed1-f67.google.com with SMTP id cm17so1187028edb.4 for ; Tue, 01 Dec 2020 20:24:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=UuG7JY+xsl7K5WaQtowInmlm6dxDKpQPq9yE3iUMios=; b=Dq+Qa5gsZlsx4W7Os0HRvr8yR99+Bkm3mzWhQmsUgfRr+dUbVNd8GqeKCuYlgkvate ZTLzPjTzoAMoNM7xI/EHJQDI9OexhHf+wanigJZqHszQTeMNb6YOoKJbb2wftlLnTAIf Z8mbHCUaChmBLcSUKYMZ36uJnnL2dK7qsq6G0tz45qByg4cy3jezeNH0fxTIgY/aVmSy zlYg7DmY3nqobh0GooUZy4ZOqMRahfNUyCyZ/scDjqJvaIaR9km6uecmiSsp/s9fF1cE 2O33PPMu/BmHEbbZCpQww5w6N8WTLkhCxDZhN+5aZeGG7vDIj0eR9NbBp8rDDgf3wwKA 1MeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=UuG7JY+xsl7K5WaQtowInmlm6dxDKpQPq9yE3iUMios=; b=jCU6YbCf515UNTTaYY3V9fgtunWw3NGLvya846nY2XLCPnQDXWMh1ve5GqEqa0bIox EVM2M3XzjGPA7emp54T+57uliAsbwccVnyFmIwF6qQnSIZuc0EyxajQjRYs926pDdOV8 ehIxlY9Lo4R3DFMG0Ou/VsgD9FTtks1DrGU4jXDQFFReKD3WVM39/+/hOfTAWVOwrXrq 5s0kAxz4GFb2y1ic+ZW81g0PR9VbsN9T0p1jFxgAY1Vu8jfN5hl5i5E9X24GMHCsMY+P mnw5/UHnjFYPg3RDCl4+ZzXTEl9FeEnsCBbnMPvzRzeZygCjnmEVco/ClbdsHNz76c9o QJcA== X-Gm-Message-State: AOAM532mZELLd7eYsWpya4imF++bz3KcEdctYBJcY3CufPHiGO/mDc+M z7CHUJihTZSbS87Y6YY1KwPyuQHBs5pndg== X-Google-Smtp-Source: ABdhPJwfvX4CNRpApAnOpn5+Ut3A83LuTeyz5rAgOn8a2ikCS3hYUr1e8gQdbhMYmo41ZyDzqBG4Hw== X-Received: by 2002:a05:6402:2070:: with SMTP id bd16mr790141edb.107.1606883080146; Tue, 01 Dec 2020 20:24:40 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id mc25sm265087ejb.58.2020.12.01.20.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 20:24:39 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Dec 2020 05:22:42 +0100 Message-Id: <20201202042244.519127-81-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127010249.2724610-1-andreas.rheinhardt@gmail.com> References: <20201127010249.2724610-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 215/217] avcodec/ituh263enc: Use ff_thread_once() for static initializations X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" This already makes initializing all the objects exclusively initialized by ff_h263_encode_init() thread-safe; this includes the static tables of ituh263enc.c: uni_h263_int*_rl_len, mv_penalty, fcode_tab as well as umv_fcode_tab; it does not ff_h263_rl_inter as well as ff_rl_intra_aic, as these are also initialized by ituh263dec.c and the code there is not guarded by the AVOnce used here. This will be dealt with in a future commit. Signed-off-by: Andreas Rheinhardt --- libavcodec/ituh263enc.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c index e1debcf63b..88d003ed47 100644 --- a/libavcodec/ituh263enc.c +++ b/libavcodec/ituh263enc.c @@ -30,6 +30,7 @@ #include #include "libavutil/attributes.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "mpegvideo.h" #include "mpegvideodata.h" @@ -671,7 +672,7 @@ void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code) } } -static av_cold void init_mv_penalty_and_fcode(MpegEncContext *s) +static av_cold void init_mv_penalty_and_fcode(void) { int f_code; int mv; @@ -754,21 +755,21 @@ static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab) } } -av_cold void ff_h263_encode_init(MpegEncContext *s) +static av_cold void h263_encode_init_static(void) { - static int done = 0; + ff_rl_init(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]); + ff_rl_init(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]); - if (!done) { - done = 1; + init_uni_h263_rl_tab(&ff_rl_intra_aic, uni_h263_intra_aic_rl_len); + init_uni_h263_rl_tab(&ff_h263_rl_inter, uni_h263_inter_rl_len); - ff_rl_init(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]); - ff_rl_init(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]); + init_mv_penalty_and_fcode(); +} - init_uni_h263_rl_tab(&ff_rl_intra_aic, uni_h263_intra_aic_rl_len); - init_uni_h263_rl_tab(&ff_h263_rl_inter, uni_h263_inter_rl_len); +av_cold void ff_h263_encode_init(MpegEncContext *s) +{ + static AVOnce init_static_once = AV_ONCE_INIT; - init_mv_penalty_and_fcode(s); - } s->me.mv_penalty= mv_penalty; // FIXME exact table for MSMPEG4 & H.263+ s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len; @@ -816,6 +817,8 @@ av_cold void ff_h263_encode_init(MpegEncContext *s) s->y_dc_scale_table= s->c_dc_scale_table= ff_mpeg1_dc_scale_table; } + + ff_thread_once(&init_static_once, h263_encode_init_static); } void ff_h263_encode_mba(MpegEncContext *s)