From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id E3C4B4E0D8 for ; Sun, 6 Jul 2025 18:38:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id BD881691200; Sun, 6 Jul 2025 21:37:04 +0300 (EEST) Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id EC4B06911E4 for ; Sun, 6 Jul 2025 21:36:53 +0300 (EEST) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 6619227FFCCBB; Sun, 06 Jul 2025 20:36:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1751827007; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZFzp7PVTpKA9mTwZdm67gdcrXDtuRUedxrb74k0Sa1s=; b=kCNZRzpjgmmcaT3/mTnSW1FLK69cHej+Nq4fLFhvfshr/aH9jZdKc7et2TMTyy2sbTVhgS QoWjSAgoNsSOp9UufTpN/HCSeNTJfWH59EmgjXVb03bgajMMf4b9w3qk/FS2qQNoJwVTbZ Itf681iOQLFz0zNDQUQ+RPrqhpR0cEmJyzcx8sUfqH8jxskA4LDD8oqcuIEpVQoGkO0D3U s7sYe2oS+swfcQOITwkIFyeo6Ilh96IG5H1w+5WihzqSkV1liAlYaaWAS7PxCTog7TyFSP ltWy0ULykVyzxzNZzmJwTX2zN/TguYjIYfJ4nJelYZnslMCGhAeTw0p/1fsFCA== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Sun, 6 Jul 2025 20:36:26 +0200 Message-ID: <20250706183634.38579-6-timo@rothenpieler.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250706183634.38579-1-timo@rothenpieler.org> References: <20250706183634.38579-1-timo@rothenpieler.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 5/8] avformat/tls: make passing an external socket universal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Timo Rothenpieler Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavformat/tls.h | 11 +++++------ libavformat/tls_openssl.c | 14 ++++++++++---- libavformat/whip.c | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/libavformat/tls.h b/libavformat/tls.h index 83d6b1ab6e..1ab115aa81 100644 --- a/libavformat/tls.h +++ b/libavformat/tls.h @@ -57,15 +57,14 @@ typedef struct TLSShared { char underlying_host[200]; int numerichost; + int external_sock; + URLContext *udp; URLContext *tcp; int is_dtls; enum DTLSState state; - int use_external_udp; - URLContext *udp; - /* The certificate and private key content used for DTLS handshake */ char* cert_buf; char* key_buf; @@ -89,14 +88,14 @@ typedef struct TLSShared { {"listen", "Listen for incoming connections", offsetof(pstruct, options_field . listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \ {"verifyhost", "Verify against a specific hostname", offsetof(pstruct, options_field . host), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \ {"http_proxy", "Set proxy to tunnel through", offsetof(pstruct, options_field . http_proxy), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \ - {"use_external_udp", "Use external UDP from muxer or demuxer", offsetof(pstruct, options_field . use_external_udp), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 1, .flags = TLS_OPTFL }, \ - {"mtu", "Maximum Transmission Unit", offsetof(pstruct, options_field . mtu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = TLS_OPTFL } + {"mtu", "Maximum Transmission Unit", offsetof(pstruct, options_field . mtu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = TLS_OPTFL }, \ + {"external_sock", "Use external socket", offsetof(pstruct, options_field . external_sock), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 1, .flags = TLS_OPTFL } int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options); int ff_url_read_all(const char *url, AVBPrint *bp); -int ff_dtls_set_udp(URLContext *h, URLContext *udp); +int ff_tls_set_external_socket(URLContext *h, URLContext *sock); int ff_dtls_export_materials(URLContext *h, char *dtls_srtp_materials, size_t materials_sz); diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c index 0c76f110e3..1b702e659e 100644 --- a/libavformat/tls_openssl.c +++ b/libavformat/tls_openssl.c @@ -502,10 +502,16 @@ static const char* openssl_get_error(TLSContext *ctx) return ctx->error_message; } -int ff_dtls_set_udp(URLContext *h, URLContext *udp) +int ff_tls_set_external_socket(URLContext *h, URLContext *sock) { TLSContext *c = h->priv_data; - c->tls_shared.udp = udp; + TLSShared *s = &c->tls_shared; + + if (s->is_dtls) + c->tls_shared.udp = sock; + else + c->tls_shared.tcp = sock; + return 0; } @@ -980,7 +986,7 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** #endif init_bio_method(h); - if (p->tls_shared.use_external_udp != 1) { + if (p->tls_shared.external_sock != 1) { if ((ret = ff_tls_open_underlying(&p->tls_shared, h, url, options)) < 0) { av_log(p, AV_LOG_ERROR, "Failed to connect %s\n", url); return ret; @@ -1001,7 +1007,7 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** * * The SSL_do_handshake can't be called if DTLS hasn't prepare for udp. */ - if (p->tls_shared.use_external_udp != 1) { + if (p->tls_shared.external_sock != 1) { ret = dtls_handshake(h); // Fatal SSL error, for example, no available suite when peer is DTLS 1.0 while we are DTLS 1.2. if (ret < 0) { diff --git a/libavformat/whip.c b/libavformat/whip.c index 4ac76e79f2..e272254a6f 100644 --- a/libavformat/whip.c +++ b/libavformat/whip.c @@ -387,7 +387,7 @@ static av_cold int dtls_initialize(AVFormatContext *s) { WHIPContext *whip = s->priv_data; /* reuse the udp created by whip */ - ff_dtls_set_udp(whip->dtls_uc, whip->udp); + ff_tls_set_external_socket(whip->dtls_uc, whip->udp); /* Make the socket non-blocking */ ff_socket_nonblock(ffurl_get_file_handle(whip->dtls_uc), 1); @@ -1302,7 +1302,7 @@ next_packet: av_dict_set(&opts, "key_file", whip->key_file, 0); } else av_dict_set(&opts, "key_pem", whip->key_buf, 0); - av_dict_set_int(&opts, "use_external_udp", 1, 0); + av_dict_set_int(&opts, "external_sock", 1, 0); av_dict_set_int(&opts, "listen", 1, 0); /* If got the first binding response, start DTLS handshake. */ ret = ffurl_open_whitelist(&whip->dtls_uc, buf, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, -- 2.49.0 _______________________________________________ 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".