From patchwork Fri Nov 20 07:19:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23781 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 01B6B44AB58 for ; Fri, 20 Nov 2020 09:29:49 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4599168BA9E; Fri, 20 Nov 2020 09:24:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B39EB68BA30 for ; Fri, 20 Nov 2020 09:24:41 +0200 (EET) Received: by mail-ed1-f68.google.com with SMTP id q16so8459940edv.10 for ; Thu, 19 Nov 2020 23:24:41 -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=zwPyVyTo5M8vh2oK0w3AiMGcK+Cj7UdvYm17Uf+Q88A=; b=szfDhY1vNW9WzpBQ9sRDVdXqKy/FM+8g0bCFkAaMLfT6Cx+Enz6XisfNx7SOhEqKol ln5okFWs49mx/JQh6A16hvimCbZdeonoNWFwchsiACCzXaSFBQckrRI76cNudtWVwAvP qAjJGNrAG5BPqVYO+0+5J4+R0ABiI7a3AA1L2hcAAvlCyowVdq/9xKaaRFoDEMP0O9VV +c6Cxq5n6241RtK4XU5l531n7OjvzG3dYILjs+zn4hpfSR0p2iRAFY3pjM2cwovKlkCY GIAtg8g+Z3E3l4nDlu6u9tmuGdJ5rAb5BX+i7ptTQOeyu3YA2eheATAIDQaFeFjJdm7J BvTw== 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=zwPyVyTo5M8vh2oK0w3AiMGcK+Cj7UdvYm17Uf+Q88A=; b=EtZjFl4GW0g+O5bUTJbCMWyimPVEPL77MweFE891JeluT4fpxDBujrHJYAN8//CCSL SdBeWwtwuKqqSfaDsxcjG78fY3vq5CkGvlDW6kFcIgWs7wFFv9+A06XW5NQISnZu33vp J1l76neczbY74HMEu0qO9r6A7odtN8egYr1EQBGuEgqTRQZVrEwfCtR5/zlRWXhba+B4 tKfRMXAC77pSoA91+jY3Gg146xhYeJtj5kqZzIp4lLD3KysrIkY15hM1K6F8UBAOkaIW t6X8frla4tfy++qjqzH93Hj6oqsae8xU9RZmTypwXA38YKmlM/TW22vUZVKuvEEDxYAU F7lg== X-Gm-Message-State: AOAM531VRxUxmliEv+pO7FWhoMvVDABeydZ1GmX0w1R/DXJ/pD84i8Sf +k4VM2dRUZKI9/XsWSF2xG1VBg6m2eNscg== X-Google-Smtp-Source: ABdhPJyALkSFXU90vXUnlWBf96bfy/K6SyIflyZD1OKKPcQXMTYf2Mt3j2n/PlBYAOYtgzn4tFFKFQ== X-Received: by 2002:a05:6402:100e:: with SMTP id c14mr32743198edu.243.1605857080989; Thu, 19 Nov 2020 23: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 lz27sm779419ejb.39.2020.11.19.23.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:24:40 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:03 +0100 Message-Id: <20201120072116.818090-31-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 030/162] avcodec/rv10: Make initializing static RV10 VLCs thread-safe 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/rv10.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index e594160fea..3a487a6b3e 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -28,6 +28,7 @@ #include #include "libavutil/imgutils.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "error_resilience.h" @@ -463,11 +464,22 @@ static int rv20_decode_picture_header(RVDecContext *rv) return s->mb_width * s->mb_height - mb_pos; } +static av_cold void rv10_init_static(void) +{ + INIT_VLC_STATIC(&rv_dc_lum, DC_VLC_BITS, 256, + rv_lum_bits, 1, 1, + rv_lum_code, 2, 2, 16384); + INIT_VLC_STATIC(&rv_dc_chrom, DC_VLC_BITS, 256, + rv_chrom_bits, 1, 1, + rv_chrom_code, 2, 2, 16388); + ff_h263_decode_init_vlc(); +} + static av_cold int rv10_decode_init(AVCodecContext *avctx) { + static AVOnce init_static_once = AV_ONCE_INIT; RVDecContext *rv = avctx->priv_data; MpegEncContext *s = &rv->m; - static int done = 0; int major_ver, minor_ver, micro_ver, ret; if (avctx->extradata_size < 8) { @@ -525,18 +537,9 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) return ret; ff_h263dsp_init(&s->h263dsp); - ff_h263_decode_init_vlc(); - /* init rv vlc */ - if (!done) { - INIT_VLC_STATIC(&rv_dc_lum, DC_VLC_BITS, 256, - rv_lum_bits, 1, 1, - rv_lum_code, 2, 2, 16384); - INIT_VLC_STATIC(&rv_dc_chrom, DC_VLC_BITS, 256, - rv_chrom_bits, 1, 1, - rv_chrom_code, 2, 2, 16388); - done = 1; - } + /* init static VLCs */ + ff_thread_once(&init_static_once, rv10_init_static); return 0; }