From patchwork Thu Jan 4 16:02:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 7119 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp414924jaa; Thu, 4 Jan 2018 08:02:51 -0800 (PST) X-Google-Smtp-Source: ACJfBovxmuKQFx3aFzjlDCPPTbTecBI2iodcXELCR3ZPHZ1gpP3RQxTVZfhLkERH3rsuE51QqjWa X-Received: by 10.28.110.24 with SMTP id j24mr12355wmc.100.1515081771194; Thu, 04 Jan 2018 08:02:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515081771; cv=none; d=google.com; s=arc-20160816; b=qBcFVoYRx/CRPbXbDRMdoLJNYKYEmQfIHiyXRTiyVGVSH1r16RUo3+yTKlqwctGW1P rxqJBHYyMoYh78JoN8gBohdEXe/ShVFq9n7BbBXOuyY2Er8fgWw3qYK6iKjADp9fRR/1 86JkqOSZQeA5jbF8Dp1N4mc8KvJic5OUl+Z6jccmCpjoFZMLC24JnbadhAns0i/Yx2IA QDlM8EqOaU+Nw7RC+G9lNSzZvjYNWKVWN4EZp54AzjZM3oXo4qjiIjSSkdTs8IGsUHoC 0sNy1p3H0EW0jiFeEuubI2KH3I8ZSxyGRijd1zBtDmqbxu2ie/x9DuKatBVXfY4OZ/Xh dV6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=MnXtdn/Jka9SgvvnJlNh531W70Gf0fJoLXyltv/i1qI=; b=NzCFer5iwH9ZwuryuNGDSQtjefSC+cldXVmAlKn6H5Or9lE1Ltf0KWfnrU4Stp7Q9Y iwAKxf8ghPudD16wTUYDtrNizk9snjEyjkee+t86iLh4FKqzS1BGOkRMqXoAy8/mT38W xYKAwH5kArjn/M9VObo8R/ppi7AqSPbuCkRk/cRbTAdKeElpyYtQhOmDcHqDsD1DsueU sko7WqArI8ECBnFfaYsCrNFcRVQKR/xoqh6aleO4nL0BqFO+iZbnhdbRfdwbUE8r7Fzr qHZQfXprNWfUgDSqt3mrNpacI3zqjvJCNV+dxl/XrUMDokwLLVSQcIa3BgSWQh1ncHFp 4SsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=ADR+6ESn; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y71si2364726wmc.167.2018.01.04.08.02.50; Thu, 04 Jan 2018 08:02:51 -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=@googlemail.com header.s=20161025 header.b=ADR+6ESn; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 654486898A9; Thu, 4 Jan 2018 18:02:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 22813689218 for ; Thu, 4 Jan 2018 18:02:26 +0200 (EET) Received: by mail-wm0-f50.google.com with SMTP id b76so4318584wmg.1 for ; Thu, 04 Jan 2018 08:02:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=2xbBEQL/IVs5Hpp78nCubTViojwypPnGqX8N4o1XwOo=; b=ADR+6ESnbUJDDsGGNqKA6OUkZrh9usouxugzY9fh2H9LNxoILu545CNAa0hlu9ROqR XiVb2flNCxeH2ZoQ4Urz1MwU2UyS8Fxyao3tcqQdVuyuWPpUkvAgMGiS0PFxmRWvPTj4 vksIOsZCUjHJ3rB8uPl+0BnhSWePVICDPvEbSIJTB7KfRFauQTRBLyBeq+mBYofjUYn5 +FlCnrJRxcQg2GVv0fOZ1ts2dz4K6IvNPCRABYSqS1IGYn/EovdYnIyeo08uEQLo+pZ/ GurheAlu/myXxYyMRgb63g/lVgj5VkH1bMDhAfDViFmI1SnJfTDeV+N8vo4oNFpSIiab qHiw== 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; bh=2xbBEQL/IVs5Hpp78nCubTViojwypPnGqX8N4o1XwOo=; b=hxSt8NEablwhG0rdIBBawTXGUnDcy77wyeams5UsbGtajzSnQ8p1clfbtHsClnECgS 1bpNaQao1rr10Csyy2A5aHC/qy4q3IBPnhmPo+O+sDOs3jlPIe90Sp16rc4EJF34JLaa 4CjiiFNE5OZ+JeWPwvfdBNGDv/WSKybIthjd/hDpHb90mzw0TtConqsKpCS68Bwtj1Vd 0UWLTO2qCxDM/2gI+8C5C7hhIRoA/JzoLxUOT3QbrCHyw13AmeYTnQIFxGFZcpzp5DDp SP5TRgDpGRGMfyVNXxWrN+4yxvurnf0cmsSd3E65+g3lpcaFTgOlaVR1nqyV6S6NXaWU NLqQ== X-Gm-Message-State: AKGB3mICRcno+Otez1YdcS9Uffm98NU16VRSZznsHGSm2NKj5YtTMyGt k1gKQLTEf5BJZmVD6t1diSUa9Q== X-Received: by 10.80.227.204 with SMTP id c12mr50037edm.20.1515081762249; Thu, 04 Jan 2018 08:02:42 -0800 (PST) Received: from debian.speedport.ip (p2003006CCD4EDC81ECF4F77632E0B6C2.dip0.t-ipconnect.de. [2003:6c:cd4e:dc81:ecf4:f776:32e0:b6c2]) by smtp.googlemail.com with ESMTPSA id g7sm2332148edj.12.2018.01.04.08.02.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jan 2018 08:02:41 -0800 (PST) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Jan 2018 17:02:41 +0100 Message-Id: <20180104160241.19324-1-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.15.1 Subject: [FFmpeg-devel] [PATCH] lavf: make avformat_network_init() explicitly optional 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: wm4 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It was sort of optional before - if you didn't call it, networking was initialized on demand, and an ugly warning was logged. Also, the doxygen comments threatened that it would be made strictly required one day. Make it explicitly optional. I would prefer to deprecate it fully, but there might still be legitimate reasons to use this. But the average user won't need it. This is needed only for two reasons: to initialize TLS libraries like OpenSSL and GnuTLS, and winsock. OpenSSL and GnuTLS were already silently initialized on demand if the global network init function was not called. They also have various thread-safety acrobatics, which make concurrent initialization within libavformat safe. In addition, the libraries are moving towards making their global init functions safe, which removes all need for central global init. In particular, GnuTLS 3.5.16 and OpenSSL 1.1.0g have been found to have safe init functions. In all cases, they use internal reference counters to avoid that the global uninit functions interfere with concurrent uses of the library by other API users who called global init. winsock should be thread-safe as well, and maintains an internal reference counter as well. Since we still support ancient TLS libraries, which do not have this fixed, and since it's unknown whether winsock and GnuTLS reinitialization is costly in any way, don't deprecate the libavformat functions yet. --- doc/APIchanges | 6 ++++++ libavformat/avformat.h | 19 +++++++++++++------ libavformat/network.c | 9 --------- libavformat/network.h | 1 - libavformat/utils.c | 2 -- libavformat/version.h | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 38c1be61c7..87ff51bdc2 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,12 @@ libavutil: 2017-10-21 API changes, most recent first: +2017-xx-xx - xxxxxxx - lavf 58.3.101 - avformat.h + Explicitly make avformat_network_init() and avformat_network_deinit() optional. + If these are not called, network initialization and deinitialization is + automatic, and unlike in older versions, fully supported, unless libavformat + is linked to ancient GnuTLS and OpenSSL. + 2017-xx-xx - xxxxxxx - lavr 4.0.0 - avresample.h Deprecate the entire library. Merged years ago to provide compatibility with Libav, it remained unmaintained by the FFmpeg project and duplicated diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 4f2798a871..9de851fcc5 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1993,17 +1993,24 @@ void av_register_input_format(AVInputFormat *format); void av_register_output_format(AVOutputFormat *format); /** - * Do global initialization of network components. This is optional, - * but recommended, since it avoids the overhead of implicitly - * doing the setup for each session. + * Do global initialization of network libraries. This is optional, + * and not recommended anymore. * - * Calling this function will become mandatory if using network - * protocols at some major version bump. + * This functions only exists to work around thread-safety issues + * with older GnuTLS or OpenSSL libraries. If libavformat is linked + * to newer versions of those libraries, or if you do not use them, + * calling this function is unnecessary. Otherwise, you need to call + * this function before any other threads using them are started. + * + * This function will be deprecated once support for older GnuTLS and + * OpenSSL libraries is removed, and this function has no purpose + * anymore. */ int avformat_network_init(void); /** - * Undo the initialization done by avformat_network_init. + * Undo the initialization done by avformat_network_init. Call it only + * once for each time you called avformat_network_init. */ int avformat_network_deinit(void); diff --git a/libavformat/network.c b/libavformat/network.c index e9eb4b443a..d5c82e9ab9 100644 --- a/libavformat/network.c +++ b/libavformat/network.c @@ -54,20 +54,11 @@ void ff_tls_deinit(void) #endif } -int ff_network_inited_globally; - int ff_network_init(void) { #if HAVE_WINSOCK2_H WSADATA wsaData; -#endif - if (!ff_network_inited_globally) - av_log(NULL, AV_LOG_WARNING, "Using network protocols without global " - "network initialization. Please use " - "avformat_network_init(), this will " - "become mandatory later.\n"); -#if HAVE_WINSOCK2_H if (WSAStartup(MAKEWORD(1,1), &wsaData)) return 0; #endif diff --git a/libavformat/network.h b/libavformat/network.h index a663115541..22a4fb8950 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -75,7 +75,6 @@ int ff_neterrno(void); int ff_socket_nonblock(int socket, int enable); -extern int ff_network_inited_globally; int ff_network_init(void); void ff_network_close(void); diff --git a/libavformat/utils.c b/libavformat/utils.c index 2185a6f05b..51a510cbb7 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4873,7 +4873,6 @@ int avformat_network_init(void) { #if CONFIG_NETWORK int ret; - ff_network_inited_globally = 1; if ((ret = ff_network_init()) < 0) return ret; if ((ret = ff_tls_init()) < 0) @@ -4887,7 +4886,6 @@ int avformat_network_deinit(void) #if CONFIG_NETWORK ff_network_close(); ff_tls_deinit(); - ff_network_inited_globally = 0; #endif return 0; } diff --git a/libavformat/version.h b/libavformat/version.h index 5ced041f0a..6453d4559f 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -33,7 +33,7 @@ // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 #define LIBAVFORMAT_VERSION_MINOR 3 -#define LIBAVFORMAT_VERSION_MICRO 100 +#define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \