]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
service mapper: try to determine quickly services without A/V streams, issue #5261
authorJaroslav Kysela <perex@perex.cz>
Mon, 22 Oct 2018 16:50:53 +0000 (18:50 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 22 Oct 2018 16:50:53 +0000 (18:50 +0200)
src/service.h
src/service_mapper.c
src/streaming.c
src/streaming.h

index e9ed280702a72aa3879cb21b5c7cb36fecce40af..1791b48997a2b02de194750057b63fbfb03d01af 100644 (file)
@@ -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 );
 
index f02d8d2c58d431ad99d287de904afd36af973c3d..e542b33fdfc1f049f2d5a96b9dfbeb8b74ab149b 100644 (file)
@@ -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);
  
index 037c0d0d118befb382c088415e9f15921f1fe4a6..a2456c0457ff4309e1127656c8e0b0e377837ca3 100644 (file)
@@ -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");
index 64a0e8fab93929f5c4f63c59679c8ac44553a91b..9e16791406310969753dfd9e3479e4b1d95f6377 100644 (file)
@@ -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