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 C75A94C985 for ; Mon, 27 Oct 2025 12:46:10 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'Q6D9opc8d3dAXrYeXqyK5rAJ7dZpovzefqLsZ2WRXhU=', expected b'dqrpeJk4XN8YlcDxCu/EwBWfF6y5RJ55n8bD/Zysx5U=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1761569154; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=Q6D9opc8d3dAXrYeXqyK5rAJ7dZpovzefqLsZ2WRXhU=; b=bGf5Bo1brgvDQAvNboHxpb0iLxKETFtST1dyiJmXmClUbITypv6s/FFnMxVSaYZiV+K1k VY38A/z+W3zQDjH7C9bR62Jj4+uRHGhZkL5kPSW1NMioUb6NvercoAV9ncHADuPCpMU9abg 6KTRLkwLfNrTqIoM82rgHgSs0ktjWP4f3CSdLg7itVEKCug+eqVb6HCxruVSs28ho08s/Ra 6R5L5IzWGdkaY5koAk3SxqH9BLML1UxrFRq1dzRW0TjaStNXQcBUYG9gHS9nTOnVSdeQymO fUzd0s31Br4jkiIikKH2jCbJ7hqpoR6OIc1kWDv/RNdii8oDKPBZUBKEQbiw== Received: from [172.19.0.2] (unknown [172.19.0.2]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id A125768F6E3; Mon, 27 Oct 2025 14:45:54 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1761569140; b=heYsEL/YTlyDeXcixZzd6YXGoHHGdMmaFwgUtJzpojIDAmjFigfx81lw0XxOmOGAfewuA IScuhiK4hV0oWyyr2CdUi+Cqe+Dw7U5e0beVDsbAbY8HVtCK8egWjahqY/NOEXdJ5ONCsQ2 GhlCe603cXJHzDlIL+U7ZDjIhIKKYimeWlzvt0q71DpV98zPJK7VtOCV7xmoCxrQnHYsQfP RWLF4q+4LRcjrfUMQpHDOykQ0p81NbMh66ePccE54A5Jhs6R0nrh5nFbsK0t79eMwcQLVGo 4evMnAN5UG3zgCPKC4MmaANNXcaNpSMd/0XbsPWJCzoSJaFIsv3W2H3m+YKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1761569140; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=c2ksz5HTd7oGlaL0SNKY82VupBUSVPTY7Pw5mcdFOY0=; b=Nh9C5dz9XM0Hb6vqi2sAGU5Q+bBWiDxcfvJgJgvMdT0kgfFqvItlL7f/2+glf2Nxru1wm Pf+5WVHn/a2z01tSa3oT9o4ONfFHK208GaDsrs++aabAbbRCsc2QBnpgnqLwdWF/dp7KqlC qLJgkwUHf++B0dfJMmxWcNofAGIhg/+ioIc/SxuJAkprTUAfRK7/Y0UoGrQ/g5psV7gt+8a v2mV4WWp7Fst2N7Bsgj/whvhjyA5+1LNTheWcE3Qqxh96k1MFDuE3LWO7La5w06gjXa3S1u f8adF3E8ETKcxOgx8c+gblF28b/C+BNs6P56sRqoizsXobrpN5UsrGOVrdXA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1761569131; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=dqrpeJk4XN8YlcDxCu/EwBWfF6y5RJ55n8bD/Zysx5U=; b=AtfO4VeM2pb/eEL+QQo1bf1HiBDTP/eZ3yqmTnaOvHFiiWfKj5RU34q/2Fqva6ig8d6Jv FnWghnp1RlSG73K+ozBm4UMEspJOQGL1Z5Ud5vDapD3TRsu+Z1QUCNbXRP4Xz9IPu8FcHve 1Z0IFQHivY2g6rpoTbPMbcxlg60MPNs0pR1veQV99f8vWrSybqD5Rdcf0bKFVMyCFkYef7o plyBeXRnwBoo1g82BRy1wNxNteay4JHdISSvg8rs12A2Px2jV/41z8rCcLSf8AryYj3jOBJ RNGiljwDi51nXSHsyVweaQOtJuCOotbUl8PC5SKMfOuJpPEYJJeMfKNrOMoA== Received: from 02c22a36bd31 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 6A493689F44 for ; Mon, 27 Oct 2025 14:45:31 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Oct 2025 12:45:31 -0000 Message-ID: <176156913160.81.14411345504692332918@7d278768979e> Message-ID-Hash: 63O7OQWZICMRGV57CWQ5K3MM2RFQM2WE X-Message-ID-Hash: 63O7OQWZICMRGV57CWQ5K3MM2RFQM2WE X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avformat/whip: several improves in ice_dtls_handshake (PR #20765) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jack Lau via ffmpeg-devel Cc: Jack Lau Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20765 opened by Jack Lau (JackLau) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20765 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20765.patch >>From 94f217adf0b4b91bcabb7cd9747f7b58c9c125e3 Mon Sep 17 00:00:00 2001 From: Jack Lau Date: Mon, 27 Oct 2025 16:50:30 +0800 Subject: [PATCH 1/4] avformat/whip: correct the ice time log The ICE handshake actually finished after recieve and handle binding request from peer when the peer is not ice lite mode. Log the ice status when it really done. Signed-off-by: Jack Lau --- libavformat/whip.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavformat/whip.c b/libavformat/whip.c index a11fffb9c6..626ebb8303 100644 --- a/libavformat/whip.c +++ b/libavformat/whip.c @@ -1321,10 +1321,6 @@ next_packet: if (whip->state < WHIP_STATE_ICE_CONNECTED) { if (whip->is_peer_ice_lite) whip->state = WHIP_STATE_ICE_CONNECTED; - whip->whip_ice_time = av_gettime_relative(); - av_log(whip, AV_LOG_VERBOSE, "ICE STUN ok, state=%d, url=udp://%s:%d, location=%s, username=%s:%s, res=%dB, elapsed=%.2fms\n", - whip->state, whip->ice_host, whip->ice_port, whip->whip_resource_url ? whip->whip_resource_url : "", - whip->ice_ufrag_remote, whip->ice_ufrag_local, ret, ELAPSED(whip->whip_starttime, av_gettime_relative())); ff_url_join(buf, sizeof(buf), "dtls", NULL, whip->ice_host, whip->ice_port, NULL); av_dict_set_int(&opts, "mtu", whip->pkt_size, 0); @@ -1360,9 +1356,13 @@ next_packet: /* Handle DTLS handshake */ if (is_dtls_packet(whip->buf, ret) || is_dtls_active) { + whip->whip_ice_time = av_gettime_relative(); /* Start consent timer when ICE selected */ - whip->whip_last_consent_tx_time = whip->whip_last_consent_rx_time = av_gettime_relative(); + whip->whip_last_consent_tx_time = whip->whip_last_consent_rx_time = whip->whip_ice_time; whip->state = WHIP_STATE_ICE_CONNECTED; + av_log(whip, AV_LOG_VERBOSE, "ICE STUN ok, state=%d, url=udp://%s:%d, location=%s, username=%s:%s, res=%dB, elapsed=%.2fms\n", + whip->state, whip->ice_host, whip->ice_port, whip->whip_resource_url ? whip->whip_resource_url : "", + whip->ice_ufrag_remote, whip->ice_ufrag_local, ret, ELAPSED(whip->whip_starttime, whip->whip_ice_time)); ret = ffurl_handshake(whip->dtls_uc); if (ret < 0) { whip->state = WHIP_STATE_FAILED; -- 2.49.1 >>From e69481bc7cd7528dd2596a2b2eccd9a51997fb9c Mon Sep 17 00:00:00 2001 From: Jack Lau Date: Mon, 27 Oct 2025 19:58:05 +0800 Subject: [PATCH 2/4] avformat/whip: put dtls init code into dtls_initialize Signed-off-by: Jack Lau --- libavformat/whip.c | 50 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/libavformat/whip.c b/libavformat/whip.c index 626ebb8303..719072bf0e 100644 --- a/libavformat/whip.c +++ b/libavformat/whip.c @@ -381,15 +381,39 @@ static av_cold int certificate_key_init(AVFormatContext *s) static av_cold int dtls_initialize(AVFormatContext *s) { + int ret = 0; WHIPContext *whip = s->priv_data; + int is_dtls_active = whip->flags & WHIP_DTLS_ACTIVE; + AVDictionary *opts = NULL; + char buf[256]; + + ff_url_join(buf, sizeof(buf), "dtls", NULL, whip->ice_host, whip->ice_port, NULL); + av_dict_set_int(&opts, "mtu", whip->pkt_size, 0); + if (whip->cert_file) { + av_dict_set(&opts, "cert_file", whip->cert_file, 0); + } else + av_dict_set(&opts, "cert_pem", whip->cert_buf, 0); + + if (whip->key_file) { + 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, "external_sock", 1, 0); + av_dict_set_int(&opts, "use_srtp", 1, 0); + av_dict_set_int(&opts, "listen", is_dtls_active ? 0 : 1, 0); + ret = ffurl_open_whitelist(&whip->dtls_uc, buf, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, + &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); + av_dict_free(&opts); + if (ret < 0) + goto end; /* reuse the udp created by whip */ 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); whip->dtls_uc->flags |= AVIO_FLAG_NONBLOCK; - - return 0; +end: + return ret; } /** @@ -1259,8 +1283,6 @@ static int ice_dtls_handshake(AVFormatContext *s) int64_t starttime = av_gettime_relative(), now; WHIPContext *whip = s->priv_data; int is_dtls_active = whip->flags & WHIP_DTLS_ACTIVE; - AVDictionary *opts = NULL; - char buf[256]; if (whip->state < WHIP_STATE_UDP_CONNECTED || !whip->udp) { av_log(whip, AV_LOG_ERROR, "UDP not connected, state=%d, udp=%p\n", whip->state, whip->udp); @@ -1322,26 +1344,6 @@ next_packet: if (whip->is_peer_ice_lite) whip->state = WHIP_STATE_ICE_CONNECTED; - ff_url_join(buf, sizeof(buf), "dtls", NULL, whip->ice_host, whip->ice_port, NULL); - av_dict_set_int(&opts, "mtu", whip->pkt_size, 0); - if (whip->cert_file) { - av_dict_set(&opts, "cert_file", whip->cert_file, 0); - } else - av_dict_set(&opts, "cert_pem", whip->cert_buf, 0); - - if (whip->key_file) { - 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, "external_sock", 1, 0); - av_dict_set_int(&opts, "use_srtp", 1, 0); - av_dict_set_int(&opts, "listen", is_dtls_active ? 0 : 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, - &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); - av_dict_free(&opts); - if (ret < 0) - goto end; dtls_initialize(s); } goto next_packet; -- 2.49.1 >>From 485bb672756d4844daca6157046c59356cbebda8 Mon Sep 17 00:00:00 2001 From: Jack Lau Date: Mon, 27 Oct 2025 20:06:23 +0800 Subject: [PATCH 3/4] avformat/whip: handle the error of dtls_initialize Correct the log level to AV_LOG_ERROR when dtls fails Signed-off-by: Jack Lau --- libavformat/whip.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libavformat/whip.c b/libavformat/whip.c index 719072bf0e..4baf9dcdec 100644 --- a/libavformat/whip.c +++ b/libavformat/whip.c @@ -404,8 +404,10 @@ static av_cold int dtls_initialize(AVFormatContext *s) ret = ffurl_open_whitelist(&whip->dtls_uc, buf, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); av_dict_free(&opts); - if (ret < 0) + if (ret < 0) { + av_log(whip, AV_LOG_ERROR, "Failed to open DTLS url:%s\n", buf); goto end; + } /* reuse the udp created by whip */ ff_tls_set_external_socket(whip->dtls_uc, whip->udp); @@ -1343,8 +1345,6 @@ next_packet: if (whip->state < WHIP_STATE_ICE_CONNECTED) { if (whip->is_peer_ice_lite) whip->state = WHIP_STATE_ICE_CONNECTED; - - dtls_initialize(s); } goto next_packet; } @@ -1365,10 +1365,14 @@ next_packet: av_log(whip, AV_LOG_VERBOSE, "ICE STUN ok, state=%d, url=udp://%s:%d, location=%s, username=%s:%s, res=%dB, elapsed=%.2fms\n", whip->state, whip->ice_host, whip->ice_port, whip->whip_resource_url ? whip->whip_resource_url : "", whip->ice_ufrag_remote, whip->ice_ufrag_local, ret, ELAPSED(whip->whip_starttime, whip->whip_ice_time)); + + ret = dtls_initialize(s); + if (ret < 0) + goto end; ret = ffurl_handshake(whip->dtls_uc); if (ret < 0) { whip->state = WHIP_STATE_FAILED; - av_log(whip, AV_LOG_VERBOSE, "DTLS session failed\n"); + av_log(whip, AV_LOG_ERROR, "DTLS session failed\n"); goto end; } if (!ret) { -- 2.49.1 >>From b2a48bc0156711d740db793dbc586d05cefe22cd Mon Sep 17 00:00:00 2001 From: Jack Lau Date: Mon, 27 Oct 2025 20:30:24 +0800 Subject: [PATCH 4/4] avformat/whip: remove redundant NONBLOCK set for dtls DTLS handshake already force set BLOCK mode. Signed-off-by: Jack Lau --- libavformat/whip.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libavformat/whip.c b/libavformat/whip.c index 4baf9dcdec..9a996b4e0c 100644 --- a/libavformat/whip.c +++ b/libavformat/whip.c @@ -410,10 +410,6 @@ static av_cold int dtls_initialize(AVFormatContext *s) } /* reuse the udp created by whip */ 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); - whip->dtls_uc->flags |= AVIO_FLAG_NONBLOCK; end: return ret; } -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org