From: Jaroslav Kysela Date: Mon, 22 Oct 2018 16:50:53 +0000 (+0200) Subject: service mapper: try to determine quickly services without A/V streams, issue #5261 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26dc2643eff15312644c4e18ffd07536e7e318d6;p=thirdparty%2Ftvheadend.git service mapper: try to determine quickly services without A/V streams, issue #5261 --- diff --git a/src/service.h b/src/service.h index e9ed28070..1791b4899 100644 --- a/src/service.h +++ b/src/service.h @@ -435,10 +435,10 @@ int service_is_sdtv(const service_t *t); int service_is_uhdtv(const service_t *t); int service_is_hdtv(const service_t *t); int service_is_radio(const service_t *t); -int service_is_other(const service_t *t); - static inline int service_is_tv( const service_t *s) { return service_is_hdtv(s) || service_is_sdtv(s) || service_is_uhdtv(s); } +static inline int service_is_other(const service_t *t) + { return !service_is_tv(t) && !service_is_radio(t); } int service_is_encrypted ( const service_t *t ); diff --git a/src/service_mapper.c b/src/service_mapper.c index f02d8d2c5..e542b33fd 100644 --- a/src/service_mapper.c +++ b/src/service_mapper.c @@ -363,11 +363,11 @@ service_mapper_thread ( void *aux ) service_mapper_item_t *smi; profile_chain_t prch; th_subscription_t *sub; - int run, working = 0; + int run, working = 0, r; streaming_queue_t *sq; streaming_message_t *sm; const char *err = NULL; - uint64_t timeout; + uint64_t timeout, timeout_other; profile_chain_init(&prch, NULL, NULL); prch.prch_st = &prch.prch_sq.sq_st; @@ -420,31 +420,44 @@ service_mapper_thread ( void *aux ) /* Wait */ run = 1; - pthread_mutex_lock(&sq->sq_mutex); timeout = mclk() + sec2mono(30); + timeout_other = mclk() + sec2mono(5); while(tvheadend_is_running() && run) { if (timeout < mclk()) { run = 0; - err = streaming_code2txt(SM_CODE_BAD_SOURCE); + err = streaming_code2txt(SM_CODE_DATA_TIMEOUT); break; } + if (timeout_other < mclk()) { + pthread_mutex_lock(&global_lock); + r = service_is_other(s); + pthread_mutex_unlock(&global_lock); + if (r) { + run = 0; + err = streaming_code2txt(SM_CODE_OTHER_SERVICE); + break; + } + } + /* Wait for message */ + pthread_mutex_lock(&sq->sq_mutex); while((sm = TAILQ_FIRST(&sq->sq_queue)) == NULL) { tvh_cond_wait(&sq->sq_cond, &sq->sq_mutex); if (!tvheadend_is_running()) break; } + if (sm) + streaming_queue_remove(sq, sm); + pthread_mutex_unlock(&sq->sq_mutex); if (!tvheadend_is_running()) break; - streaming_queue_remove(sq, sm); - pthread_mutex_unlock(&sq->sq_mutex); - switch (sm->sm_type) { case SMT_GRACE: timeout += sec2mono(sm->sm_code); + timeout_other = sec2mono(sm->sm_code); break; case SMT_PACKET: run = 0; @@ -470,6 +483,7 @@ service_mapper_thread ( void *aux ) if (!tvheadend_is_running()) break; + pthread_mutex_lock(&sq->sq_mutex); streaming_queue_clear(&sq->sq_queue); pthread_mutex_unlock(&sq->sq_mutex); diff --git a/src/streaming.c b/src/streaming.c index 037c0d0d1..a2456c045 100644 --- a/src/streaming.c +++ b/src/streaming.c @@ -492,6 +492,10 @@ streaming_code2txt(int code) return N_("Invalid service"); case SM_CODE_CHN_NOT_ENABLED: return N_("No channel enabled"); + case SM_CODE_DATA_TIMEOUT: + return N_("No A/V data received"); + case SM_CODE_OTHER_SERVICE: + return N_("Other service without A/V streams"); case SM_CODE_ABORTED: return N_("Aborted by user"); diff --git a/src/streaming.h b/src/streaming.h index 64a0e8fab..9e1679140 100644 --- a/src/streaming.h +++ b/src/streaming.h @@ -290,6 +290,8 @@ enum streaming_message_type { #define SM_CODE_NO_ADAPTERS 209 #define SM_CODE_INVALID_SERVICE 210 #define SM_CODE_CHN_NOT_ENABLED 211 +#define SM_CODE_DATA_TIMEOUT 212 +#define SM_CODE_OTHER_SERVICE 213 #define SM_CODE_ABORTED 300