From patchwork Mon Feb 12 05:42:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 7559 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp3623110jai; Sun, 11 Feb 2018 21:48:18 -0800 (PST) X-Google-Smtp-Source: AH8x227OAV97YmJ8QCsbaCaO7b1XmKqmRanpwJ4RLz8/WwddWXmLvxVgfbLfwt2Hofj9jJQVnoM0 X-Received: by 10.223.184.88 with SMTP id u24mr2356937wrf.3.1518414498261; Sun, 11 Feb 2018 21:48:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518414498; cv=none; d=google.com; s=arc-20160816; b=PcGXiU6yia6w+MrsvfTMIKGmQhGemv14qe1IRkZ/r9slwtGQPxnHoQ8cpUqJqw9Wxo iG+qLbVh+GNA6/hj8obd1iOmH87wZI2xhtKlsiLYeycDEoF/Jcai4NUn4m4xfokm+IMH AZb8UBYreJqv96Qh9JNj4kvy7eV/o7AeVUAxlDHwg3ezGM6wRlbn2KS+oE8Jkm0Iqg8l XrAKQqdXwDuT2FV9egM+X8GYtE9KkxeqwavqVG4pVUU6HlRxgQsI0Nb6yHXqIb0Dd93p NTPyw8hkYKvQN9GxvcJ+hepm0gxcsKhdtNhLdA4ko8S5r/PCTAVEEGRTiOitEKTIykk1 /qHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=jOE7uq1QatbvNcgh1M5bpVvFYTaR1IdxXGjEo/vVZm4=; b=Xct0rNYOx8ARJseFtkGwXBIjIakiMdPAFcHDDkRrsdvNZpKXZUixx9afttUNRscmJ1 nFDFLlswFAdkA+WIJPxQHHoQpjFej585KiNFJEanofToeH1SCIt2cHyj8bqTjqAmOmEI 26yjUjSqdVBphuq74SZRWesZ8gHPRAHiifeXh+1+f8mrb2sDfqlvHO74IogC4fRvI3vm sKLtfRLna7x7XAx+DZkRprX8bAH9ANAQIGc4UQOVDPabc76h+6FeAwnZAkjM96gjMW6q u/JpLmgY5x5SOUhb/++YYjbNfc1oc1XuZZDCgYQDpW5bUP5ktiA/64K/dDHkZozFDIAm 4QIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Vz1cGBse; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b6si1186389wrf.166.2018.02.11.21.48.17; Sun, 11 Feb 2018 21:48:18 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Vz1cGBse; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D31B4688312; Mon, 12 Feb 2018 07:48:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F134A680414 for ; Mon, 12 Feb 2018 07:47:57 +0200 (EET) Received: by mail-pg0-f66.google.com with SMTP id l131so1330813pga.2 for ; Sun, 11 Feb 2018 21:48:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=fNYoKviHRAaCr1qhErt2rlX2ZYbL9QGp9A3Fs3/ycf0=; b=Vz1cGBse8r8vIkcbjGjuHjmkdz7yIrnrfaU9AD4Nxh6pkYUrOQRYUWoKCTYRdl54vU prn1omd0Mh5H57eZNIsBpP/vG8qVHBWD/fzFNRiyAexw22RgtcfZmOo7V62H6gzvGOr1 3uosFZOOB37wvUNy5U8Ilq/yPFoi3WlStywzO3j/EleVesdflxh4sLdin5tdGuIZzbJm s3ibQI+3uzHaU129Ao6biDfuoU0ynkiggWyf16ud7PajuAFNgr7yEb09GhSDzuNFLzJ/ Ed8zZIeAr6yXTLON5lYyYfbaoXY9oW2BPVMsKs685DdcDp/RCxdlieG/Q1ZSWia0MkhW ou3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=fNYoKviHRAaCr1qhErt2rlX2ZYbL9QGp9A3Fs3/ycf0=; b=sbtIyduQh+/0fsTsI01wVFYKG1eIG227V1FavUmbadXx++UkvQStbMNWLJJl+4y8zx BWd3mMuTMuYZrwi2DAZ6FydaIBay0VBXC4OPS/Ep/WvO7RRqZArVEP9NKMywx1289+V/ neEIIrtgk9Aj9oMI0tLUSXYLCdEqqig74BF3w7QaGSNwek0qHkoVR2dxGQ4bAgMcFGWs uHr9Nc4/EOnaAbyF38SW8pdeKWMBGxcbJAsTP0LZrofnqPE91AEl5TW++DoFsVlvxjoH g+5f1GrGl6mI9f719e0bQxRhGxmqNRBb9ToGqt4TgcCSMP/2ZLE4A31PvxnKtFDYJz5q OdxQ== X-Gm-Message-State: APf1xPDtaZs01/FGeFZFN5Vk0Zixypn+Zmtxb9jN8dK4s/+rc8DDTky0 H6ea9+vMg2ixWuu899lAHqKlOfGw X-Received: by 10.101.101.143 with SMTP id u15mr8376305pgv.265.1518414144327; Sun, 11 Feb 2018 21:42:24 -0800 (PST) Received: from localhost.localdomain ([114.124.145.191]) by smtp.gmail.com with ESMTPSA id c19sm27359755pfk.22.2018.02.11.21.42.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Feb 2018 21:42:23 -0800 (PST) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Feb 2018 12:42:10 +0700 Message-Id: <20180212054210.21183-1-mfcc64@gmail.com> X-Mailer: git-send-email 2.13.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec: remove av_codec_init_static() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Modify the behavior of init_static_data(). Signed-off-by: Muhammad Faiz --- libavcodec/allcodecs.c | 16 ++++------------ libavcodec/avcodec.h | 4 +++- libavcodec/libvpxdec.c | 15 ++++++++++++++- libavcodec/libvpxenc.c | 15 ++++++++++++++- libavcodec/libx264.c | 11 ++++++++++- libavcodec/libx265.c | 11 ++++++++++- 6 files changed, 55 insertions(+), 17 deletions(-) diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 774b78ef09..02910b5594 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -757,24 +757,16 @@ extern AVCodec ff_vp9_vaapi_encoder; #include "libavcodec/codec_list.c" -static AVOnce av_codec_static_init = AV_ONCE_INIT; -static void av_codec_init_static(void) -{ - for (int i = 0; codec_list[i]; i++) { - if (codec_list[i]->init_static_data) - codec_list[i]->init_static_data((AVCodec*)codec_list[i]); - } -} - const AVCodec *av_codec_iterate(void **opaque) { uintptr_t i = (uintptr_t)*opaque; const AVCodec *c = codec_list[i]; - ff_thread_once(&av_codec_static_init, av_codec_init_static); - - if (c) + if (c) { + if (c->init_static_data) + c->init_static_data(); *opaque = (void*)(i + 1); + } return c; } diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index ad0b48a839..d89bf300fc 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3443,8 +3443,10 @@ typedef struct AVCodec { * * This is not intended for time consuming operations as it is * run for every codec regardless of that codec being used. + * This may be called multiple times from different threads, the callee + * has responsibility for thread synchronization. */ - void (*init_static_data)(struct AVCodec *codec); + void (*init_static_data)(void); int (*init)(AVCodecContext *); int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c index 04f27d3396..f2003b836b 100644 --- a/libavcodec/libvpxdec.c +++ b/libavcodec/libvpxdec.c @@ -30,6 +30,7 @@ #include "libavutil/common.h" #include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "internal.h" #include "libvpx.h" @@ -299,6 +300,18 @@ static av_cold int vp9_init(AVCodecContext *avctx) return vpx_init(avctx, &vpx_codec_vp9_dx_algo, 0); } +static av_cold void vp9_init_static_once(void) +{ + extern AVCodec ff_libvpx_vp9_decoder; + ff_vp9_init_static(&ff_libvpx_vp9_decoder); +} + +static av_cold void vp9_init_static(void) +{ + static AVOnce once = AV_ONCE_INIT; + ff_thread_once(&once, vp9_init_static_once); +} + AVCodec ff_libvpx_vp9_decoder = { .name = "libvpx-vp9", .long_name = NULL_IF_CONFIG_SMALL("libvpx VP9"), @@ -309,7 +322,7 @@ AVCodec ff_libvpx_vp9_decoder = { .close = vpx_free, .decode = vpx_decode, .capabilities = AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_DR1, - .init_static_data = ff_vp9_init_static, + .init_static_data = vp9_init_static, .profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles), .wrapper_name = "libvpx", }; diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index d0bd1e997a..086dd5defa 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -39,6 +39,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/mathematics.h" #include "libavutil/opt.h" +#include "libavutil/thread.h" /** * Portion of struct vpx_codec_cx_pkt from vpx_encoder.h. @@ -1209,6 +1210,18 @@ static av_cold int vp9_init(AVCodecContext *avctx) return vpx_init(avctx, vpx_codec_vp9_cx()); } +static av_cold void vp9_init_static_once(void) +{ + extern AVCodec ff_libvpx_vp9_encoder; + ff_vp9_init_static(&ff_libvpx_vp9_encoder); +} + +static av_cold void vp9_init_static(void) +{ + static AVOnce once = AV_ONCE_INIT; + ff_thread_once(&once, vp9_init_static_once); +} + static const AVClass class_vp9 = { .class_name = "libvpx-vp9 encoder", .item_name = av_default_item_name, @@ -1229,7 +1242,7 @@ AVCodec ff_libvpx_vp9_encoder = { .profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles), .priv_class = &class_vp9, .defaults = defaults, - .init_static_data = ff_vp9_init_static, + .init_static_data = vp9_init_static, .wrapper_name = "libvpx", }; #endif /* CONFIG_LIBVPX_VP9_ENCODER */ diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 12379ff763..0da61a0fcd 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -26,6 +26,7 @@ #include "libavutil/pixdesc.h" #include "libavutil/stereo3d.h" #include "libavutil/intreadwrite.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "internal.h" @@ -896,8 +897,10 @@ static const enum AVPixelFormat pix_fmts_8bit_rgb[] = { }; #endif -static av_cold void X264_init_static(AVCodec *codec) +static av_cold void X264_init_static_once(void) { + extern AVCodec ff_libx264_encoder; + AVCodec *codec = &ff_libx264_encoder; #if X264_BUILD < 153 if (x264_bit_depth == 8) codec->pix_fmts = pix_fmts_8bit; @@ -910,6 +913,12 @@ static av_cold void X264_init_static(AVCodec *codec) #endif } +static av_cold void X264_init_static(void) +{ + static AVOnce once = AV_ONCE_INIT; + ff_thread_once(&once, X264_init_static_once); +} + #define OFFSET(x) offsetof(X264Context, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 3c97800ccb..63e1240473 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -31,6 +31,7 @@ #include "libavutil/common.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "internal.h" @@ -395,8 +396,10 @@ static const enum AVPixelFormat x265_csp_twelve[] = { AV_PIX_FMT_NONE }; -static av_cold void libx265_encode_init_csp(AVCodec *codec) +static av_cold void libx265_encode_init_csp_once(void) { + extern AVCodec ff_libx265_encoder; + AVCodec *codec = &ff_libx265_encoder; if (x265_api_get(12)) codec->pix_fmts = x265_csp_twelve; else if (x265_api_get(10)) @@ -405,6 +408,12 @@ static av_cold void libx265_encode_init_csp(AVCodec *codec) codec->pix_fmts = x265_csp_eight; } +static av_cold void libx265_encode_init_csp(void) +{ + static AVOnce once = AV_ONCE_INIT; + ff_thread_once(&once, libx265_encode_init_csp_once); +} + #define OFFSET(x) offsetof(libx265Context, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = {