From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 2/6] avformat/tls_openssl: #if ff_openssl_init/deinit() away if possible
Date: Fri, 17 May 2024 17:25:36 +0200
Message-ID: <AS8P250MB0744976174901A90E121FA518FEE2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AS8P250MB0744CC67273864DA864725B98FEE2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>
These functions do nothing useful when used with a non-ancient
version of openssl (namely 1.1.0 or above).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavformat/network.c | 9 +++++++--
libavformat/tls_openssl.c | 34 ++++++++++++++++++++--------------
2 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/libavformat/network.c b/libavformat/network.c
index f752efc411..6db82b6d26 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -18,8 +18,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "config.h"
#include "config_components.h"
+#if CONFIG_TLS_PROTOCOL && CONFIG_OPENSSL
+#include <openssl/opensslv.h>
+#endif
+
#include <fcntl.h>
#include "network.h"
#include "tls.h"
@@ -31,7 +36,7 @@
int ff_tls_init(void)
{
#if CONFIG_TLS_PROTOCOL
-#if CONFIG_OPENSSL
+#if CONFIG_OPENSSL && OPENSSL_VERSION_NUMBER < 0x10100000L
int ret;
if ((ret = ff_openssl_init()) < 0)
return ret;
@@ -46,7 +51,7 @@ int ff_tls_init(void)
void ff_tls_deinit(void)
{
#if CONFIG_TLS_PROTOCOL
-#if CONFIG_OPENSSL
+#if CONFIG_OPENSSL && OPENSSL_VERSION_NUMBER < 0x10100000L
ff_openssl_deinit();
#endif
#if CONFIG_GNUTLS
diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index 89d7c6e1ea..8b0cf9efb2 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -23,16 +23,12 @@
#include "os_support.h"
#include "url.h"
#include "tls.h"
-#include "libavutil/mem.h"
#include "libavutil/opt.h"
-#include "libavutil/thread.h"
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
-static int openssl_init;
-
typedef struct TLSContext {
const AVClass *class;
TLSShared tls_shared;
@@ -44,10 +40,22 @@ typedef struct TLSContext {
int io_err;
} TLSContext;
+/* OpenSSL 1.0.2 or below, then you would use SSL_library_init. If you are
+ * using OpenSSL 1.1.0 or above, then the library will initialize
+ * itself automatically.
+ * https://wiki.openssl.org/index.php/Library_Initialization
+ */
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#include "libavutil/thread.h"
+
static AVMutex openssl_mutex = AV_MUTEX_INITIALIZER;
-#if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
+static int openssl_init;
+
+#if HAVE_THREADS
#include <openssl/crypto.h>
+#include "libavutil/mem.h"
+
pthread_mutex_t *openssl_mutexes;
static void openssl_lock(int mode, int type, const char *file, int line)
{
@@ -68,16 +76,9 @@ int ff_openssl_init(void)
{
ff_mutex_lock(&openssl_mutex);
if (!openssl_init) {
- /* OpenSSL 1.0.2 or below, then you would use SSL_library_init. If you are
- * using OpenSSL 1.1.0 or above, then the library will initialize
- * itself automatically.
- * https://wiki.openssl.org/index.php/Library_Initialization
- */
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSL_library_init();
SSL_load_error_strings();
-#endif
-#if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
+#if HAVE_THREADS
if (!CRYPTO_get_locking_callback()) {
int i;
openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks());
@@ -106,7 +107,7 @@ void ff_openssl_deinit(void)
ff_mutex_lock(&openssl_mutex);
openssl_init--;
if (!openssl_init) {
-#if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
+#if HAVE_THREADS
if (CRYPTO_get_locking_callback() == openssl_lock) {
int i;
CRYPTO_set_locking_callback(NULL);
@@ -118,6 +119,7 @@ void ff_openssl_deinit(void)
}
ff_mutex_unlock(&openssl_mutex);
}
+#endif
static int print_tls_error(URLContext *h, int ret)
{
@@ -157,7 +159,9 @@ static int tls_close(URLContext *h)
if (c->url_bio_method)
BIO_meth_free(c->url_bio_method);
#endif
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
ff_openssl_deinit();
+#endif
return 0;
}
@@ -253,8 +257,10 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
BIO *bio;
int ret;
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
if ((ret = ff_openssl_init()) < 0)
return ret;
+#endif
if ((ret = ff_tls_open_underlying(c, h, uri, options)) < 0)
goto fail;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-05-17 15:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-17 15:23 [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
2024-05-17 15:25 ` Andreas Rheinhardt [this message]
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible Andreas Rheinhardt
2024-05-17 15:42 ` epirat07
2024-05-17 16:17 ` Andreas Rheinhardt
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 4/6] avformat/tee: Use smaller scope for variables Andreas Rheinhardt
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary Andreas Rheinhardt
2024-05-17 15:41 ` epirat07
2024-05-17 15:44 ` Andreas Rheinhardt
2024-05-17 15:48 ` epirat07
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 6/6] fftools, avfilter, avformat: Simplify check for "is dictionary empty?" Andreas Rheinhardt
2024-05-17 15:39 ` epirat07
2024-05-19 9:57 ` [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8P250MB0744976174901A90E121FA518FEE2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git