From patchwork Wed Dec 2 04:22:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24310 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 7020144A7AC for ; Wed, 2 Dec 2020 06:35:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5658268A6B6; Wed, 2 Dec 2020 06:24:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 60CD668A5D3 for ; Wed, 2 Dec 2020 06:24:32 +0200 (EET) Received: by mail-ej1-f67.google.com with SMTP id pg6so673444ejb.6 for ; Tue, 01 Dec 2020 20:24:32 -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=7ezvMCTn6M6yUKYgsK9qve6+6bWyGpGpjA8CwaTvF/E=; b=ZaNWxBfXwPH+bUWOm+LCGJVzTUhcIcl6W0O4KaM5tZrJT7zVg1jT+C8zVWiNbH2ZVO QZMofp3wi3FRbm5+UXFB/Fv91Gr4ID9cl8DJa1Gly2uCQzKXgU2sqGdQV0WW/STW7gkE 2buvtOFZAB7fk9wonOzjmqj+tTP9RK0BmOeZkZPc+qznpwEb67TFeoe67JqIzwBkaxo0 QuXL10Fg2GU+rj6CsWW1yqWZoNMXU5Nz5f0GJwTeNMUMdYziXeSN7WeMCNSP/e4sW3OD TlhE9UY9FHBgyMhi6cnnu+Ew/kfFAunAC+F8BNsfYwOzW7AgrfKCxn18hI6pLyE8Trqg EuQw== 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=7ezvMCTn6M6yUKYgsK9qve6+6bWyGpGpjA8CwaTvF/E=; b=Hhl9pdhgccajQAN4xyYnR0IFCJqgV4hbP5eDRR9+wA5JelxDlPUYMj85A6Y9uQsMBH v8gMFi9wEjiqMfaiYVgnWVS3tj1IexVsKl+Xh+KdH4k1fAGI/DRyHTT8TNzFAA9vbq67 tCl/CBz4MJ+fy/WOz+XfI/DIPdWwRAgX5qqfgO5DHlwIc0VjpHzPDFjLo3Q9sldv1FlU 2ftdCa6v2lBC8XS9KeYHQ0YnAA032epJYdAp10fM3NqrfzHtnS9kqrV66uyfuWr7Ef4z zfaJrtylF5QKpLk1IYz5k8uxgGEocNXAEOlX2All4+x8YDmcO3g0+LHYsyNtpXupZzsP p0mg== X-Gm-Message-State: AOAM532TP1p4LPfIK199NgLLZtkv1l9zoHX/+pMgoGpmNFN/cf3QhBlD vKlfBPYAFwtjMnWNIRLYBQz7ttrTzwAQbQ== X-Google-Smtp-Source: ABdhPJzxHJBNXmCo8oHWjW1nYUGPlI43Qo8pk1cwkZrx0fwIizsPYcZUwR1VVoMiOlul+TY1G86o2Q== X-Received: by 2002:a17:906:f894:: with SMTP id lg20mr584752ejb.348.1606883071689; Tue, 01 Dec 2020 20:24:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 20:24:31 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Dec 2020 05:22:33 +0100 Message-Id: <20201202042244.519127-72-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 206/217] avcodec/dvbsubdec: Make decoder init-threadsafe 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" Note: This decoder uses a static variable in save_display_set() (which is only enabled if DEBUG is defined); yet said function can't be reached from the decoder's init function at all, so it is no problem for setting the FF_CODEC_CAP_INIT_THREADSAFE flag. Signed-off-by: Andreas Rheinhardt --- libavcodec/dvbsubdec.c | 55 ++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index b1a0c3ff24..81b8460593 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -26,6 +26,7 @@ #include "libavutil/colorspace.h" #include "libavutil/imgutils.h" #include "libavutil/opt.h" +#include "libavutil/thread.h" #define DVBSUB_PAGE_SEGMENT 0x10 #define DVBSUB_REGION_SEGMENT 0x11 @@ -254,31 +255,9 @@ static void delete_regions(DVBSubContext *ctx) } } -static av_cold int dvbsub_init_decoder(AVCodecContext *avctx) +static av_cold void init_default_clut(void) { int i, r, g, b, a = 0; - DVBSubContext *ctx = avctx->priv_data; - - if (ctx->substream < 0) { - ctx->composition_id = -1; - ctx->ancillary_id = -1; - } else if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) { - av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n"); - ctx->composition_id = -1; - ctx->ancillary_id = -1; - } else { - if (avctx->extradata_size > 5*ctx->substream + 2) { - ctx->composition_id = AV_RB16(avctx->extradata + 5*ctx->substream); - ctx->ancillary_id = AV_RB16(avctx->extradata + 5*ctx->substream + 2); - } else { - av_log(avctx, AV_LOG_WARNING, "Selected DVB subtitles sub-stream %d is not available\n", ctx->substream); - ctx->composition_id = AV_RB16(avctx->extradata); - ctx->ancillary_id = AV_RB16(avctx->extradata + 2); - } - } - - ctx->version = -1; - ctx->prev_start = AV_NOPTS_VALUE; default_clut.id = -1; default_clut.next = NULL; @@ -339,6 +318,35 @@ static av_cold int dvbsub_init_decoder(AVCodecContext *avctx) } default_clut.clut256[i] = RGBA(r, g, b, a); } +} + +static av_cold int dvbsub_init_decoder(AVCodecContext *avctx) +{ + static AVOnce init_static_once = AV_ONCE_INIT; + DVBSubContext *ctx = avctx->priv_data; + + if (ctx->substream < 0) { + ctx->composition_id = -1; + ctx->ancillary_id = -1; + } else if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) { + av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n"); + ctx->composition_id = -1; + ctx->ancillary_id = -1; + } else { + if (avctx->extradata_size > 5*ctx->substream + 2) { + ctx->composition_id = AV_RB16(avctx->extradata + 5*ctx->substream); + ctx->ancillary_id = AV_RB16(avctx->extradata + 5*ctx->substream + 2); + } else { + av_log(avctx, AV_LOG_WARNING, "Selected DVB subtitles sub-stream %d is not available\n", ctx->substream); + ctx->composition_id = AV_RB16(avctx->extradata); + ctx->ancillary_id = AV_RB16(avctx->extradata + 2); + } + } + + ctx->version = -1; + ctx->prev_start = AV_NOPTS_VALUE; + + ff_thread_once(&init_static_once, init_default_clut); return 0; } @@ -1758,4 +1766,5 @@ AVCodec ff_dvbsub_decoder = { .close = dvbsub_close_decoder, .decode = dvbsub_decode, .priv_class = &dvbsubdec_class, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, };