]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add start timeout to streaming profile
authorLeonardo Brondani Schenkel <leonardo@schenkel.net>
Thu, 1 Aug 2024 18:14:57 +0000 (20:14 +0200)
committerFlole <Flole998@users.noreply.github.com>
Sat, 28 Sep 2024 11:58:31 +0000 (13:58 +0200)
This allows overriding the hardcoded grace period of 20 seconds.
It should address the problems described in [1][2].

In addition, timeout code has been slightly refactored for readability
and more debug logging.

[1] https://tvheadend.org/d/8330-increase-timeout-when-tuning-iptv-mux/2
[2] https://tvheadend.org/d/8158-several-problems-questions-about-using-tvheadend-starting-with-not-waiting-long-enoough-for-stream-to-begin

src/profile.c
src/profile.h
src/webui/webui.c

index 3a0bc8d628619e0611584c74a0d54f6cb183460b..6fa5a4837de9ac973024167f0e9e28d1d9f94747 100644 (file)
@@ -359,6 +359,17 @@ const idclass_t profile_class =
       .def.i    = 5,
       .group    = 1
     },
+    {
+      .type     = PT_INT,
+      .id       = "timeout_start",
+      .name     = N_("Data start timeout (sec) (0=default)"),
+      .desc     = N_("The number of seconds to wait for data "
+                     "when stream is starting."),
+      .off      = offsetof(profile_t, pro_timeout_start),
+      .opts     = PO_EXPERT,
+      .def.i    = 0,
+      .group    = 1
+    },
     {
       .type     = PT_INT,
       .id       = "priority",
index 0496c691108549918707ecde6f77499cb057628e..ac135c4d669c5e316537fe00c5652046c92c78d7 100644 (file)
@@ -125,6 +125,7 @@ typedef struct profile {
   int pro_prio;
   int pro_fprio;
   int pro_timeout;
+  int pro_timeout_start;
   int pro_restart;
   int pro_contaccess;
   int pro_ca_timeout;
index 2b2ac80bbcd83c0db2bd29a7c1c46cff7caf76ff..51e64351510ad8379479f593096024d5e55e6b63 100644 (file)
@@ -340,7 +340,7 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
   int run = 1, started = 0;
   streaming_queue_t *sq = &prch->prch_sq;
   muxer_t *mux = prch->prch_muxer;
-  int ptimeout, grace = 20, r;
+  int ptimeout = 5, ptimeout_start = 0, grace = 20, r;
   struct timeval tp;
   streaming_start_t *ss_copy;
   int64_t lastpkt, mono;
@@ -356,7 +356,23 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
     socket_set_dscp(hc->hc_fd, config.dscp, NULL, 0);
 
   lastpkt = mclk();
-  ptimeout = prch->prch_pro ? prch->prch_pro->pro_timeout : 5;
+
+  if (prch->prch_pro) {
+    struct profile *pro = prch->prch_pro;
+
+    ptimeout = pro->pro_timeout;
+    ptimeout_start = pro->pro_timeout_start;
+    tvhdebug(LS_WEBUI, "Using timeouts from profile: %s", pro->pro_name);
+    tvhdebug(LS_WEBUI, "Packet timeout (from profile): %d secs", ptimeout);
+  } else {
+    tvhdebug(LS_WEBUI, "Packet timeout (default): %d secs", ptimeout);
+  }
+  if (ptimeout_start > 0) {
+    grace = ptimeout_start;
+    tvhdebug(LS_WEBUI, "Grace period (from profile): %d secs", grace);
+  } else {
+    tvhdebug(LS_WEBUI, "Grace period (default): %d secs", grace);
+  }
 
   if (hc->hc_no_output) {
     tvh_mutex_lock(&sq->sq_mutex);
@@ -376,9 +392,11 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
           if (tcp_socket_dead(hc->hc_fd)) {
             tvhdebug(LS_WEBUI,  "Stop streaming %s, client hung up", hc->hc_url_orig);
             run = 0;
-          } else if((!started && mclk() - lastpkt > sec2mono(grace)) ||
-                     (started && ptimeout > 0 && mclk() - lastpkt > sec2mono(ptimeout))) {
-            tvhwarn(LS_WEBUI,  "Stop streaming %s, timeout waiting for packets", hc->hc_url_orig);
+          } else if (!started && mclk() - lastpkt > sec2mono(grace)) {
+            tvhwarn(LS_WEBUI, "Stop streaming %s, timeout (%d secs) waiting for data packets to start", hc->hc_url_orig, grace);
+            run = 0;
+          } else if (started && ptimeout > 0 && mclk() - lastpkt > sec2mono(ptimeout)) {
+            tvhwarn(LS_WEBUI, "Stop streaming %s, timeout (%d secs) waiting for data packets", hc->hc_url_orig, ptimeout);
             run = 0;
           }
           break;
@@ -410,11 +428,17 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
       break;
 
     case SMT_GRACE:
-      grace = sm->sm_code < 5 ? 5 : grace;
+      if (sm->sm_code > grace) {
+        grace = sm->sm_code > 5 ? sm->sm_code : 5;
+        tvhdebug(LS_WEBUI, "Increased grace period to %d secs", grace);
+      } else {
+        tvhdebug(LS_WEBUI, "Ignored grace period change to %d secs", sm->sm_code);
+      }
       break;
 
     case SMT_START:
       grace = 10;
+      tvhdebug(LS_WEBUI, "New grace period: %d secs", grace);
       if(!started) {
         tvhdebug(LS_WEBUI, "%s streaming %s",
                  hc->hc_no_output ? "Probe" : "Start", hc->hc_url_orig);