From: Timo Rothenpieler <timo@rothenpieler.org> To: ffmpeg-devel@ffmpeg.org Cc: Timo Rothenpieler <timo@rothenpieler.org> Subject: [FFmpeg-devel] [PATCH 16/18] avformat/tls: make passing an external socket universal Date: Wed, 2 Jul 2025 18:56:44 +0200 Message-ID: <20250702165655.1325-17-timo@rothenpieler.org> (raw) In-Reply-To: <20250702165655.1325-1-timo@rothenpieler.org> --- 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 2049eb021b..5805513065 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; @@ -1004,7 +1010,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 84d4c5a1f3..e109469a4f 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); return 0; } @@ -1297,7 +1297,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".
next prev parent reply other threads:[~2025-07-02 16:59 UTC|newest] Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-07-02 16:56 [FFmpeg-devel] [PATCH 00/18] WHIP + TLS + UDP fixes and SChannel DTLS support Timo Rothenpieler 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 01/18] avformat/Makefile: don't hardcode openssl for whip muxer Timo Rothenpieler 2025-07-03 14:00 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 02/18] avformat/whip: use av_dict_set_int for int Timo Rothenpieler 2025-07-03 14:01 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 03/18] avformat/whip: don't leak options dict Timo Rothenpieler 2025-07-03 14:02 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 04/18] avformat/whip: remove redundant WHIP: prefix from all logging Timo Rothenpieler 2025-07-03 14:02 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 05/18] avformat/whip: fix format string for printing size_t Timo Rothenpieler 2025-07-03 14:03 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 06/18] avformat/tls: use non protocol specific error message Timo Rothenpieler 2025-07-03 14:03 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 07/18] avformat/tls: don't use http_proxy for udp sockets Timo Rothenpieler 2025-07-03 14:04 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 08/18] avformat/tls: move openssl specific init out of generic code Timo Rothenpieler 2025-07-03 1:07 ` Jack Lau 2025-07-03 14:24 ` Timo Rothenpieler 2025-07-03 15:22 ` Jack Lau 2025-07-03 16:41 ` Timo Rothenpieler 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 09/18] avformat/udp: don't override 0 localport Timo Rothenpieler 2025-07-03 14:05 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 10/18] avformat/tls: fix udp init Timo Rothenpieler 2025-07-03 14:06 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 11/18] avformat/udp: make recv addr of each packet available Timo Rothenpieler 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 12/18] avformat/udp: separate rx and tx fifo Timo Rothenpieler 2025-07-03 14:07 ` Steven Liu 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 13/18] avformat/udp: add function to set remote address directly Timo Rothenpieler 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 14/18] avformat/tls: remove unused fingerprint option Timo Rothenpieler 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 15/18] avformat/tls: clean up new whip options Timo Rothenpieler 2025-07-02 16:56 ` Timo Rothenpieler [this message] 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 17/18] avformat/tls_openssl: use existing context handle Timo Rothenpieler 2025-07-02 16:56 ` [FFmpeg-devel] [PATCH 18/18] avformat/tls_schannel: add DTLS support Timo Rothenpieler
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=20250702165655.1325-17-timo@rothenpieler.org \ --to=timo@rothenpieler.org \ --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