From 54164baa1123c3e49a1b8ebec9e8fba78ec3c741 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 7 Aug 2014 13:47:37 +0200 Subject: [PATCH] Introduce SMT_GRACE message --- src/dvr/dvr_rec.c | 1 + src/htsp_server.c | 1 + src/plumbing/globalheaders.c | 2 ++ src/plumbing/transcoding.c | 1 + src/plumbing/tsfix.c | 1 + src/service.c | 1 + src/service.h | 1 + src/streaming.c | 2 ++ src/subscriptions.c | 8 ++++++++ src/timeshift/timeshift_writer.c | 1 + src/tvheadend.h | 8 ++++++++ src/webui/webui.c | 19 ++++++++++++------- 12 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c index 95ae7aee..26d0b3c2 100644 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -581,6 +581,7 @@ dvr_thread(void *aux) } break; + case SMT_GRACE: case SMT_SPEED: case SMT_SKIP: case SMT_SIGNAL_STATUS: diff --git a/src/htsp_server.c b/src/htsp_server.c index d654cfd6..c9ffbaad 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -2912,6 +2912,7 @@ htsp_streaming_input(void *opaque, streaming_message_t *sm) htsp_subscription_status(hs, streaming_code2txt(sm->sm_code)); break; + case SMT_GRACE: case SMT_MPEGTS: break; diff --git a/src/plumbing/globalheaders.c b/src/plumbing/globalheaders.c index e13affab..4710f560 100644 --- a/src/plumbing/globalheaders.c +++ b/src/plumbing/globalheaders.c @@ -252,6 +252,7 @@ gh_hold(globalheaders_t *gh, streaming_message_t *sm) streaming_msg_free(sm); break; + case SMT_GRACE: case SMT_EXIT: case SMT_SERVICE_STATUS: case SMT_SIGNAL_STATUS: @@ -283,6 +284,7 @@ gh_pass(globalheaders_t *gh, streaming_message_t *sm) gh->gh_passthru = 0; gh_flush(gh); // FALLTHRU + case SMT_GRACE: case SMT_EXIT: case SMT_SERVICE_STATUS: case SMT_SIGNAL_STATUS: diff --git a/src/plumbing/transcoding.c b/src/plumbing/transcoding.c index b5575637..2df54805 100644 --- a/src/plumbing/transcoding.c +++ b/src/plumbing/transcoding.c @@ -1253,6 +1253,7 @@ transcoder_input(void *opaque, streaming_message_t *sm) transcoder_stop(t); // Fallthrough + case SMT_GRACE: case SMT_SPEED: case SMT_SKIP: case SMT_TIMESHIFT_STATUS: diff --git a/src/plumbing/tsfix.c b/src/plumbing/tsfix.c index 8c3503c3..94c182fb 100644 --- a/src/plumbing/tsfix.c +++ b/src/plumbing/tsfix.c @@ -366,6 +366,7 @@ tsfix_input(void *opaque, streaming_message_t *sm) tsfix_stop(tf); break; + case SMT_GRACE: case SMT_EXIT: case SMT_SERVICE_STATUS: case SMT_SIGNAL_STATUS: diff --git a/src/service.c b/src/service.c index 532bf0da..4d166ab1 100644 --- a/src/service.c +++ b/src/service.c @@ -598,6 +598,7 @@ service_start(service_t *t, int instance) if(t->s_grace_period != NULL) timeout = t->s_grace_period(t); + t->s_grace_delay = timeout; gtimer_arm(&t->s_receive_timer, service_data_timeout, t, timeout); return 0; } diff --git a/src/service.h b/src/service.h index 2361eead..bd9768d3 100644 --- a/src/service.h +++ b/src/service.h @@ -340,6 +340,7 @@ typedef struct service { /** * Stream start time */ + int s_grace_delay; time_t s_start_time; diff --git a/src/streaming.c b/src/streaming.c index fcee9f7a..a09a484e 100644 --- a/src/streaming.c +++ b/src/streaming.c @@ -235,6 +235,7 @@ streaming_msg_clone(streaming_message_t *src) memcpy(dst->sm_data, src->sm_data, sizeof(timeshift_status_t)); break; + case SMT_GRACE: case SMT_SPEED: case SMT_STOP: case SMT_SERVICE_STATUS: @@ -292,6 +293,7 @@ streaming_msg_free(streaming_message_t *sm) streaming_start_unref(sm->sm_data); break; + case SMT_GRACE: case SMT_STOP: case SMT_EXIT: case SMT_SERVICE_STATUS: diff --git a/src/subscriptions.c b/src/subscriptions.c index c30f9f79..af1897aa 100644 --- a/src/subscriptions.c +++ b/src/subscriptions.c @@ -87,6 +87,9 @@ subscription_link_service(th_subscription_t *s, service_t *t) // Link to service output streaming_target_connect(&t->s_streaming_pad, &s->ths_input); + sm = streaming_msg_create_code(SMT_GRACE, t->s_grace_delay); + streaming_pad_deliver(&t->s_streaming_pad, sm); + if(s->ths_start_message != NULL && t->s_streaming_status & TSS_PACKETS) { s->ths_state = SUBSCRIPTION_GOT_SERVICE; @@ -332,6 +335,11 @@ subscription_input(void *opauqe, streaming_message_t *sm) if(s->ths_state == SUBSCRIPTION_TESTING_SERVICE) { // We are just testing if this service is good + if(sm->sm_type == SMT_GRACE) { + streaming_target_deliver(s->ths_output, sm); + return; + } + if(sm->sm_type == SMT_START) { if(s->ths_start_message != NULL) streaming_msg_free(s->ths_start_message); diff --git a/src/timeshift/timeshift_writer.c b/src/timeshift/timeshift_writer.c index d3da9c03..d534410a 100644 --- a/src/timeshift/timeshift_writer.c +++ b/src/timeshift/timeshift_writer.c @@ -253,6 +253,7 @@ static void _process_msg break; /* Status */ + case SMT_GRACE: case SMT_NOSTART: case SMT_SERVICE_STATUS: case SMT_TIMESHIFT_STATUS: diff --git a/src/tvheadend.h b/src/tvheadend.h index a6bbaae0..020812b7 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -317,6 +317,14 @@ typedef enum { */ SMT_PACKET, + /** + * Stream grace period + * + * sm_code contains number of seconds to settle things down + */ + + SMT_GRACE, + /** * Stream start * diff --git a/src/webui/webui.c b/src/webui/webui.c index 05d5fbbb..b6c7831f 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -228,7 +228,7 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq, int run = 1; int started = 0; muxer_t *mux = NULL; - int timeouts = 0; + int timeouts = 0, grace = 20; struct timespec ts; struct timeval tp; int err = 0; @@ -256,12 +256,12 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq, //Check socket status getsockopt(hc->hc_fd, SOL_SOCKET, SO_ERROR, (char *)&err, &errlen); - if(err) { - tvhlog(LOG_DEBUG, "webui", "Stop streaming %s, client hung up", hc->hc_url_orig); - run = 0; - }else if(timeouts >= 20) { - tvhlog(LOG_WARNING, "webui", "Stop streaming %s, timeout waiting for packets", hc->hc_url_orig); - run = 0; + if (err) { + tvhlog(LOG_DEBUG, "webui", "Stop streaming %s, client hung up", hc->hc_url_orig); + run = 0; + } else if(timeouts >= grace) { + tvhlog(LOG_WARNING, "webui", "Stop streaming %s, timeout waiting for packets", hc->hc_url_orig); + run = 0; } } pthread_mutex_unlock(&sq->sq_mutex); @@ -287,7 +287,12 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq, } break; + case SMT_GRACE: + grace = sm->sm_code < 5 ? 5 : grace; + break; + case SMT_START: + grace = 10; if(!started) { tvhlog(LOG_DEBUG, "webui", "Start streaming %s", hc->hc_url_orig); http_output_content(hc, muxer_mime(mux, sm->sm_data));