Skip to content

Commit 05c3170

Browse files
lbschenkelFlole998
authored andcommitted
Add start timeout to streaming profile
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
1 parent 55404da commit 05c3170

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

‎src/profile.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,17 @@ const idclass_t profile_class =
359359
.def.i = 5,
360360
.group = 1
361361
},
362+
{
363+
.type = PT_INT,
364+
.id = "timeout_start",
365+
.name = N_("Data start timeout (sec) (0=default)"),
366+
.desc = N_("The number of seconds to wait for data "
367+
"when stream is starting."),
368+
.off = offsetof(profile_t, pro_timeout_start),
369+
.opts = PO_EXPERT,
370+
.def.i = 0,
371+
.group = 1
372+
},
362373
{
363374
.type = PT_INT,
364375
.id = "priority",

‎src/profile.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ typedef struct profile {
125125
int pro_prio;
126126
int pro_fprio;
127127
int pro_timeout;
128+
int pro_timeout_start;
128129
int pro_restart;
129130
int pro_contaccess;
130131
int pro_ca_timeout;

‎src/webui/webui.c‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
340340
int run = 1, started = 0;
341341
streaming_queue_t *sq = &prch->prch_sq;
342342
muxer_t *mux = prch->prch_muxer;
343-
int ptimeout, grace = 20, r;
343+
int ptimeout = 5, ptimeout_start = 0, grace = 20, r;
344344
struct timeval tp;
345345
streaming_start_t *ss_copy;
346346
int64_t lastpkt, mono;
@@ -356,7 +356,23 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
356356
socket_set_dscp(hc->hc_fd, config.dscp, NULL, 0);
357357

358358
lastpkt = mclk();
359-
ptimeout = prch->prch_pro ? prch->prch_pro->pro_timeout : 5;
359+
360+
if (prch->prch_pro) {
361+
struct profile *pro = prch->prch_pro;
362+
363+
ptimeout = pro->pro_timeout;
364+
ptimeout_start = pro->pro_timeout_start;
365+
tvhdebug(LS_WEBUI, "Using timeouts from profile: %s", pro->pro_name);
366+
tvhdebug(LS_WEBUI, "Packet timeout (from profile): %d secs", ptimeout);
367+
} else {
368+
tvhdebug(LS_WEBUI, "Packet timeout (default): %d secs", ptimeout);
369+
}
370+
if (ptimeout_start > 0) {
371+
grace = ptimeout_start;
372+
tvhdebug(LS_WEBUI, "Grace period (from profile): %d secs", grace);
373+
} else {
374+
tvhdebug(LS_WEBUI, "Grace period (default): %d secs", grace);
375+
}
360376

361377
if (hc->hc_no_output) {
362378
tvh_mutex_lock(&sq->sq_mutex);
@@ -376,9 +392,11 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
376392
if (tcp_socket_dead(hc->hc_fd)) {
377393
tvhdebug(LS_WEBUI, "Stop streaming %s, client hung up", hc->hc_url_orig);
378394
run = 0;
379-
} else if((!started && mclk() - lastpkt > sec2mono(grace)) ||
380-
(started && ptimeout > 0 && mclk() - lastpkt > sec2mono(ptimeout))) {
381-
tvhwarn(LS_WEBUI, "Stop streaming %s, timeout waiting for packets", hc->hc_url_orig);
395+
} else if (!started && mclk() - lastpkt > sec2mono(grace)) {
396+
tvhwarn(LS_WEBUI, "Stop streaming %s, timeout (%d secs) waiting for data packets to start", hc->hc_url_orig, grace);
397+
run = 0;
398+
} else if (started && ptimeout > 0 && mclk() - lastpkt > sec2mono(ptimeout)) {
399+
tvhwarn(LS_WEBUI, "Stop streaming %s, timeout (%d secs) waiting for data packets", hc->hc_url_orig, ptimeout);
382400
run = 0;
383401
}
384402
break;
@@ -410,11 +428,17 @@ http_stream_run(http_connection_t *hc, profile_chain_t *prch,
410428
break;
411429

412430
case SMT_GRACE:
413-
grace = sm->sm_code < 5 ? 5 : grace;
431+
if (sm->sm_code > grace) {
432+
grace = sm->sm_code > 5 ? sm->sm_code : 5;
433+
tvhdebug(LS_WEBUI, "Increased grace period to %d secs", grace);
434+
} else {
435+
tvhdebug(LS_WEBUI, "Ignored grace period change to %d secs", sm->sm_code);
436+
}
414437
break;
415438

416439
case SMT_START:
417440
grace = 10;
441+
tvhdebug(LS_WEBUI, "New grace period: %d secs", grace);
418442
if(!started) {
419443
tvhdebug(LS_WEBUI, "%s streaming %s",
420444
hc->hc_no_output ? "Probe" : "Start", hc->hc_url_orig);

0 commit comments

Comments
 (0)