@@ -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