PR #22354 opened by PhilipTang
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22354
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22354.patch

WHIP can receive http_timeout option in microseconds to allow dropping
connection attempts which would otherwise hang in the event that remote
server is not replying.


>From 0767511f61f7fe4bd068b324154b4d85780fc596 Mon Sep 17 00:00:00 2001
From: Philip Tang <[email protected]>
Date: Mon, 2 Mar 2026 16:38:25 -0800
Subject: [PATCH] avformat/whip.c: http_timeout option for tcp-based WHIP can
 receive http_timeout option in microseconds to allow dropping connection
 attempts which would otherwise hang in the event that remote server is not
 replying.

---
 doc/muxers.texi    |  4 ++++
 libavformat/whip.c | 15 +++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 643981fc20..2b6211ffde 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -3951,6 +3951,10 @@ This muxer supports the following options:
 Set the timeout in milliseconds for ICE and DTLS handshake.
 Default value is 5000.
 
+@item http_timeout @var{integer}
+Set the timeout in microseconds for TCP-based operations.
+Default value is 10000000.
+
 @item pkt_size @var{integer}
 Set the maximum size, in bytes, of RTP packets that send out.
 Default value is 1200.
diff --git a/libavformat/whip.c b/libavformat/whip.c
index aeb2c186aa..9f8d32893b 100644
--- a/libavformat/whip.c
+++ b/libavformat/whip.c
@@ -338,6 +338,9 @@ typedef struct WHIPContext {
 
     /* The timeout in milliseconds for ICE and DTLS handshake. */
     int handshake_timeout;
+
+    /* The timeout in microseconds for HTTP operations. */
+    int64_t http_timeout;
     /**
      * The size of RTP packet, should generally be set to MTU.
      * Note that pion requires a smaller value, for example, 1200.
@@ -428,6 +431,10 @@ static av_cold int dtls_initialize(AVFormatContext *s)
     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 (whip->http_timeout >= 0)
+        av_dict_set_int(&opts, "rw_timeout", whip->http_timeout, 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);
@@ -839,6 +846,9 @@ static int exchange_sdp(AVFormatContext *s)
     av_dict_set(&opts, "headers", buf, 0);
     av_dict_set_int(&opts, "chunked_post", 0, 0);
 
+    if (whip->http_timeout >= 0)
+        av_dict_set_int(&opts, "rw_timeout", whip->http_timeout, 0);
+        
     hex_data = av_mallocz(2 * strlen(whip->sdp_offer) + 1);
     if (!hex_data) {
         ret = AVERROR(ENOMEM);
@@ -1733,6 +1743,10 @@ static int dispose_session(AVFormatContext *s)
     av_dict_set(&opts, "headers", buf, 0);
     av_dict_set_int(&opts, "chunked_post", 0, 0);
     av_dict_set(&opts, "method", "DELETE", 0);
+
+    if (whip->http_timeout >= 0)
+        av_dict_set_int(&opts, "rw_timeout", whip->http_timeout, 0);
+
     ret = ffurl_open_whitelist(&whip_uc, whip->whip_resource_url, 
AVIO_FLAG_READ_WRITE, &s->interrupt_callback,
         &opts, s->protocol_whitelist, s->protocol_blacklist, NULL);
     if (ret < 0) {
@@ -2176,6 +2190,7 @@ static int whip_check_bitstream(AVFormatContext *s, 
AVStream *st, const AVPacket
 #define ENC AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
     { "handshake_timeout",  "Timeout in milliseconds for ICE and DTLS 
handshake.",      OFFSET(handshake_timeout),  AV_OPT_TYPE_INT,    { .i64 = 5000 
},    -1, INT_MAX, ENC },
+    { "http_timeout",       "Timeout in microseconds for TCP-based operations 
(e.g. SDP exchange, DELETE).", OFFSET(http_timeout), AV_OPT_TYPE_INT64, { .i64 
= 10000000 }, -1, INT64_MAX, ENC },
     { "pkt_size",           "The maximum size, in bytes, of RTP packets that 
send out", OFFSET(pkt_size),           AV_OPT_TYPE_INT,    { .i64 = 1200 },    
-1, INT_MAX, ENC },
     { "ts_buffer_size",     "The buffer size, in bytes, of underlying 
protocol",        OFFSET(ts_buffer_size),        AV_OPT_TYPE_INT,    { .i64 = 
-1 },      -1, INT_MAX, ENC },
     { "whip_flags",         "Set flags affecting WHIP connection behavior",    
         OFFSET(flags),              AV_OPT_TYPE_FLAGS,  { .i64 = 0},         
0, UINT_MAX, ENC, .unit = "flags" },
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to