Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Jack Lau <jacklau1222gm@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Jack Lau <jacklau1222@qq.com>
Subject: [FFmpeg-devel] [PATCH v4 08/11] avformat/whip: remove DTLSState enum
Date: Mon, 21 Jul 2025 19:30:19 +0800
Message-ID: <20250721113023.91931-9-jacklau1222@qq.com> (raw)
In-Reply-To: <20250721113023.91931-1-jacklau1222@qq.com>

This patch aims to simplify the dtls handshake process
since dtls handshake use force block mode

We can just use the return code instead of DTLSState enum

Signed-off-by: Jack Lau <jacklau1222@qq.com>
---
 libavformat/tls.h          | 15 ----------
 libavformat/tls_openssl.c  |  7 -----
 libavformat/tls_schannel.c |  7 -----
 libavformat/whip.c         | 59 ++++++++------------------------------
 4 files changed, 12 insertions(+), 76 deletions(-)

diff --git a/libavformat/tls.h b/libavformat/tls.h
index 0c02a4ab27..157c0d0256 100644
--- a/libavformat/tls.h
+++ b/libavformat/tls.h
@@ -33,17 +33,6 @@
  */
 #define MAX_CERTIFICATE_SIZE 8192
 
-enum DTLSState {
-    DTLS_STATE_NONE,
-
-    /* Whether DTLS handshake is finished. */
-    DTLS_STATE_FINISHED,
-    /* Whether DTLS session is closed. */
-    DTLS_STATE_CLOSED,
-    /* Whether DTLS handshake is failed. */
-    DTLS_STATE_FAILED,
-};
-
 typedef struct TLSShared {
     char *ca_file;
     int verify;
@@ -63,8 +52,6 @@ typedef struct TLSShared {
 
     int is_dtls;
 
-    enum DTLSState state;
-
     /* The certificate and private key content used for DTLS handshake */
     char* cert_buf;
     char* key_buf;
@@ -103,8 +90,6 @@ 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);
 
-int ff_dtls_state(URLContext *h);
-
 int ff_ssl_read_key_cert(char *key_url, char *cert_url, char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint);
 
 int ff_ssl_gen_key_cert(char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint);
diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index 778595c721..c3427a18e8 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -540,12 +540,6 @@ int ff_dtls_export_materials(URLContext *h, char *dtls_srtp_materials, size_t ma
     return 0;
 }
 
-int ff_dtls_state(URLContext *h)
-{
-    TLSContext *c = h->priv_data;
-    return c->tls_shared.state;
-}
-
 static int print_ssl_error(URLContext *h, int ret)
 {
     TLSContext *c = h->priv_data;
@@ -724,7 +718,6 @@ static int dtls_handshake(URLContext *h)
         goto end;
 
     ret = 0;
-    p->tls_shared.state = DTLS_STATE_FINISHED;
 end:
     return ret;
 }
diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c
index c92870347f..50f35acdd6 100644
--- a/libavformat/tls_schannel.c
+++ b/libavformat/tls_schannel.c
@@ -681,12 +681,6 @@ int ff_dtls_export_materials(URLContext *h, char *dtls_srtp_materials, size_t ma
 #endif
 }
 
-int ff_dtls_state(URLContext *h)
-{
-    TLSContext *c = h->priv_data;
-    return c->tls_shared.state;
-}
-
 static void init_sec_buffer(SecBuffer *buffer, unsigned long type,
                             void *data, unsigned long size)
 {
@@ -1111,7 +1105,6 @@ static int tls_handshake(URLContext *h)
 #endif
 
     c->connected = 1;
-    s->state = DTLS_STATE_FINISHED;
 
 fail:
     return ret;
diff --git a/libavformat/whip.c b/libavformat/whip.c
index e02ed7a8a4..fe35ab7205 100644
--- a/libavformat/whip.c
+++ b/libavformat/whip.c
@@ -217,9 +217,6 @@ typedef struct WHIPContext {
     uint32_t flags;        // enum WHIPFlags
     /* The state of the RTC connection. */
     enum WHIPState state;
-    /* The callback return value for DTLS. */
-    int dtls_ret;
-    int dtls_closed;
 
     /* Parameters for the input audio and video codecs. */
     AVCodecParameters *audio_par;
@@ -377,41 +374,6 @@ static av_cold int certificate_key_init(AVFormatContext *s)
     return ret;
 }
 
-/**
- * When DTLS state change.
- */
-static int dtls_context_on_state(AVFormatContext *s, const char* type, const char* desc)
-{
-    int ret = 0;
-    WHIPContext *whip = s->priv_data;
-    int state = ff_dtls_state(whip->dtls_uc);
-
-    if (state == DTLS_STATE_CLOSED) {
-        whip->dtls_closed = 1;
-        av_log(whip, AV_LOG_VERBOSE, "DTLS session closed, type=%s, desc=%s, elapsed=%dms\n",
-            type ? type : "", desc ? desc : "", ELAPSED(whip->whip_starttime, av_gettime()));
-        goto error;
-    }
-
-    if (state == DTLS_STATE_FAILED) {
-        whip->state = WHIP_STATE_FAILED;
-        av_log(whip, AV_LOG_ERROR, "DTLS session failed, type=%s, desc=%s\n",
-            type ? type : "", desc ? desc : "");
-        whip->dtls_ret = AVERROR(EIO);
-        goto error;
-    }
-
-    if (state == DTLS_STATE_FINISHED && whip->state < WHIP_STATE_DTLS_FINISHED) {
-        whip->state = WHIP_STATE_DTLS_FINISHED;
-        whip->whip_dtls_time = av_gettime();
-        av_log(whip, AV_LOG_VERBOSE, "DTLS handshake is done, elapsed=%dms\n",
-            ELAPSED(whip->whip_starttime, av_gettime()));
-        return ret;
-    }
-error:
-    return -1;
-}
-
 static av_cold int dtls_initialize(AVFormatContext *s)
 {
     WHIPContext *whip = s->priv_data;
@@ -1377,9 +1339,18 @@ next_packet:
         /* If got any DTLS messages, handle it. */
         if ((is_dtls_packet(whip->buf, ret) || is_dtls_active) && whip->state >= WHIP_STATE_ICE_CONNECTED || whip->state == WHIP_STATE_DTLS_CONNECTING) {
             whip->state = WHIP_STATE_DTLS_CONNECTING;
-            if ((ret = ffurl_handshake(whip->dtls_uc)) < 0)
+            ret = ffurl_handshake(whip->dtls_uc);
+            if (ret < 0) {
+                whip->state = WHIP_STATE_FAILED;
+                av_log(whip, AV_LOG_VERBOSE, "DTLS session failed\n");
                 goto end;
-            dtls_context_on_state(s, NULL, NULL);
+            }
+            if (!ret) {
+                whip->state = WHIP_STATE_DTLS_FINISHED;
+                whip->whip_dtls_time = av_gettime();
+                av_log(whip, AV_LOG_VERBOSE, "DTLS handshake is done, elapsed=%dms\n",
+                    ELAPSED(whip->whip_starttime, whip->whip_dtls_time));
+            }
             goto next_packet;
         }
     }
@@ -1910,8 +1881,6 @@ static av_cold int whip_init(AVFormatContext *s)
 end:
     if (ret < 0 && whip->state < WHIP_STATE_FAILED)
         whip->state = WHIP_STATE_FAILED;
-    if (ret >= 0 && whip->state >= WHIP_STATE_FAILED && whip->dtls_ret < 0)
-        ret = whip->dtls_ret;
     return ret;
 }
 
@@ -2022,12 +1991,8 @@ write_packet:
 
 end:
     if (buf) av_freep(&buf);
-    if (ret < 0 && whip->state < WHIP_STATE_FAILED)
+    if (ret < 0)
         whip->state = WHIP_STATE_FAILED;
-    if (ret >= 0 && whip->state >= WHIP_STATE_FAILED && whip->dtls_ret < 0)
-        ret = whip->dtls_ret;
-    if (ret >= 0 && whip->dtls_closed)
-        ret = AVERROR(EIO);
     return ret;
 }
 
-- 
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".

  parent reply	other threads:[~2025-07-21 11:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-21 11:30 [FFmpeg-devel] [PATCH v4 00/11] avformat/whip: Add NACK, RTX, DTLS active support Jack Lau
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 01/11] avformat/whip: add whip_flags ignore_ipv6 to skip IPv6 ICE candidates Jack Lau
2025-07-21 13:53   ` Steven Liu
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 02/11] avformat/whip: fix typos Jack Lau
2025-07-21 13:52   ` Steven Liu
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 03/11] avformat/whip: fix H264 profile_iop bit map for SDP Jack Lau
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 04/11] WHIP: X509 cert serial number should be positive Jack Lau
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 05/11] avformat/whip: implement NACK and RTX suppport Jack Lau
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 06/11] avformat/whip: reindent whip options Jack Lau
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 07/11] avformat/whip: add support for active dtls role Jack Lau
2025-07-21 11:30 ` Jack Lau [this message]
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 09/11] avformat/whip: check the peer whether is ice lite Jack Lau
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 10/11] avformat/whip: remove WHIP_STATE_DTLS_CONNECTING Jack Lau
2025-07-21 11:30 ` [FFmpeg-devel] [PATCH v4 11/11] avformat/whip: simplify and modularize the ICE and DTLS Jack Lau

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=20250721113023.91931-9-jacklau1222@qq.com \
    --to=jacklau1222gm@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=jacklau1222@qq.com \
    /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