]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
mi_is_enabled cleanup and fixes - add three states (RETRY,NEVER,OK)
authorJaroslav Kysela <perex@perex.cz>
Mon, 5 Dec 2016 10:00:43 +0000 (11:00 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 5 Dec 2016 10:00:43 +0000 (11:00 +0100)
src/input/mpegts.h
src/input/mpegts/iptv/iptv.c
src/input/mpegts/linuxdvb/linuxdvb_adapter.c
src/input/mpegts/linuxdvb/linuxdvb_frontend.c
src/input/mpegts/mpegts_input.c
src/input/mpegts/mpegts_mux_dvb.c
src/input/mpegts/mpegts_service.c
src/input/mpegts/satip/satip_frontend.c

index b1412decfe41f274be593cd47d2dcb7959059bad..d7fb16130db1fdb725adb13f1d6675df2ae57b56 100644 (file)
@@ -655,6 +655,12 @@ struct mpegts_mux_sub
   int                       mms_weight;
 };
 
+enum mpegts_input_is_enabled {
+  MI_IS_ENABLED_RETRY = -1,
+  MI_IS_ENABLED_NEVER = 0,
+  MI_IS_ENABLED_OK = 1,
+};
+
 /* Input source */
 struct mpegts_input
 {
index e932c2b051338bf47342dbc69b2539ce9efeae07..7bd046bea0f7700671d8ca845903186d1956d339 100644 (file)
@@ -192,8 +192,10 @@ static int
 iptv_input_is_enabled
   ( mpegts_input_t *mi, mpegts_mux_t *mm, int flags, int weight )
 {
-  if (!mpegts_input_is_enabled(mi, mm, flags, weight)) return 0;
-  return iptv_input_is_free(mi, mm, 0, weight, NULL) == NULL ? 1 : -1;
+  if (mpegts_input_is_enabled(mi, mm, flags, weight) == MI_IS_ENABLED_NEVER)
+    return MI_IS_ENABLED_NEVER;
+  return iptv_input_is_free(mi, mm, 0, weight, NULL) == NULL ?
+         MI_IS_ENABLED_OK : MI_IS_ENABLED_RETRY;
 }
 
 static int
index 5183fe307bb96561670ba197ed13d94ce3ae78dc..5b037322ec4a89975603db253df8e129dfeae057 100644 (file)
@@ -133,7 +133,7 @@ linuxdvb_adapter_is_enabled ( linuxdvb_adapter_t *la )
 {
   linuxdvb_frontend_t *lfe;
   LIST_FOREACH(lfe, &la->la_frontends, lfe_link) {
-    if (lfe->mi_is_enabled((mpegts_input_t*)lfe, NULL, 0, -1))
+    if (lfe->mi_is_enabled((mpegts_input_t*)lfe, NULL, 0, -1) != MI_IS_ENABLED_NEVER)
       return 1;
   }
   return 0;
index 3e3b1ad86ec30597806c6ae6266ec8530cf227f5..c48e936a37b41f99a128e455dcfc4b873ed02f97 100644 (file)
@@ -483,11 +483,16 @@ linuxdvb_frontend_is_enabled
   tvh_hardware_t *th;
   char ubuf[UUID_HEX_SIZE];
 
-  if (lfe->lfe_fe_path == NULL) return 0;
-  if (!mpegts_input_is_enabled(mi, mm, flags, weight)) return 0;
-  if (access(lfe->lfe_fe_path, R_OK | W_OK)) return 0;
-  if (lfe->lfe_in_setup) return 0;
-  if (lfe->lfe_type != DVB_TYPE_S) return 1;
+  if (lfe->lfe_fe_path == NULL)
+    return MI_IS_ENABLED_NEVER;
+  if (!mpegts_input_is_enabled(mi, mm, flags, weight))
+    return MI_IS_ENABLED_NEVER;
+  if (access(lfe->lfe_fe_path, R_OK | W_OK))
+    return MI_IS_ENABLED_NEVER;
+  if (lfe->lfe_in_setup)
+    return MI_IS_ENABLED_RETRY;
+  if (lfe->lfe_type != DVB_TYPE_S)
+    return MI_IS_ENABLED_OK;
 
   /* check if any "blocking" tuner is running */
   LIST_FOREACH(th, &tvh_hardware, th_link) {
@@ -498,21 +503,23 @@ linuxdvb_frontend_is_enabled
       if (lfe2->lfe_type != DVB_TYPE_S) continue;
       if (lfe->lfe_master && !strcmp(lfe->lfe_master, idnode_uuid_as_str(&lfe2->ti_id, ubuf))) {
         if (lfe2->lfe_satconf == NULL)
-          return 0; /* invalid master */
+          return MI_IS_ENABLED_NEVER; /* invalid master */
         if (lfe2->lfe_refcount <= 0)
-          return 0; /* prefer master */
-        return linuxdvb_satconf_match_mux(lfe2->lfe_satconf, mm);
+          return MI_IS_ENABLED_RETRY; /* prefer master */
+        return linuxdvb_satconf_match_mux(lfe2->lfe_satconf, mm) ?
+               MI_IS_ENABLED_OK : MI_IS_ENABLED_RETRY;
       }
       if (lfe2->lfe_master &&
           !strcmp(lfe2->lfe_master, idnode_uuid_as_str(&lfe->ti_id, ubuf)) &&
           lfe2->lfe_refcount > 0) {
         if (lfe->lfe_satconf == NULL)
-          return 0;
-        return linuxdvb_satconf_match_mux(lfe->lfe_satconf, mm);
+          return MI_IS_ENABLED_NEVER;
+        return linuxdvb_satconf_match_mux(lfe->lfe_satconf, mm) ?
+               MI_IS_ENABLED_OK : MI_IS_ENABLED_RETRY;
       }
     }
   }
-  return 1;
+  return MI_IS_ENABLED_OK;
 }
 
 static void
index d8447d106684bf96b901dd91e024bbc0da8a4b0b..5f1b15ddbd3cb2a0c5695c57f4ef01c130d6f8b1 100644 (file)
@@ -347,12 +347,12 @@ mpegts_input_is_enabled
   ( mpegts_input_t *mi, mpegts_mux_t *mm, int flags, int weight )
 {
   if ((flags & SUBSCRIPTION_EPG) != 0 && !mi->mi_ota_epg)
-    return 0;
+    return MI_IS_ENABLED_NEVER;
   if ((flags & SUBSCRIPTION_INITSCAN) != 0 && !mi->mi_initscan)
-    return 0;
+    return MI_IS_ENABLED_NEVER;
   if ((flags & SUBSCRIPTION_IDLESCAN) != 0 && !mi->mi_idlescan)
-    return 0;
-  return mi->mi_enabled;
+    return MI_IS_ENABLED_NEVER;
+  return mi->mi_enabled ? MI_IS_ENABLED_OK : MI_IS_ENABLED_NEVER;
 }
 
 void
index c2255a11610da8845aff5052a066a735ea94912d..35bc57a1778dddb0a55bc6bfa07778ba7269c1c8 100644 (file)
@@ -943,7 +943,7 @@ dvb_mux_create_instances ( mpegts_mux_t *mm )
   mpegts_network_link_t *mnl;
   LIST_FOREACH(mnl, &mm->mm_network->mn_inputs, mnl_mn_link) {
     mpegts_input_t *mi = mnl->mnl_input;
-    if (mi->mi_is_enabled(mi, mm, 0, -1))
+    if (mi->mi_is_enabled(mi, mm, 0, -1) != MI_IS_ENABLED_NEVER)
       mi->mi_create_mux_instance(mi, mm);
   }
 }
index 7bc7e5b75a029c44b9c7a3d644a3fa2ba9a2c16c..b7381e51b2fa23d66d58819fac47ad32ab6566f7 100644 (file)
@@ -310,9 +310,9 @@ mpegts_service_enlist_raw
       continue;
 
     r = mi->mi_is_enabled(mi, mmi->mmi_mux, flags, weight);
-    if (!r)
+    if (r == MI_IS_ENABLED_NEVER)
       continue;
-    if (r < 0) {
+    if (r == MI_IS_ENABLED_RETRY) {
       /* temporary error - retry later */
       errcnt++;
       continue;
index ad5117b3599aea931d5371d469ff8f19080109cc..75f993389fb3e154e75726f5b09892e5c00c8f87 100644 (file)
@@ -524,28 +524,32 @@ satip_frontend_is_enabled
 
   lock_assert(&global_lock);
 
-  if (!mpegts_input_is_enabled(mi, mm, flags, weight)) return 0;
-  if (lfe->sf_device->sd_dbus_allow <= 0) return 0;
-  if (lfe->sf_type != DVB_TYPE_S) return 1;
+  if (!mpegts_input_is_enabled(mi, mm, flags, weight))
+    return MI_IS_EMABLED_NEVER;
+  if (lfe->sf_device->sd_dbus_allow <= 0)
+    return MI_IS_ENABLED_NEVER;
+  if (lfe->sf_type != DVB_TYPE_S)
+    return MI_IS_ENABLED_OK;
   /* check if the position is enabled */
   sfc = satip_satconf_get_position(lfe, mm, NULL, 1, flags, weight);
-  if (!sfc)
-    return 0;
+  if (!sfc) return MI_IS_ENABLED_NEVER;
   /* check if any "blocking" tuner is running */
   TAILQ_FOREACH(lfe2, &lfe->sf_device->sd_frontends, sf_link) {
     if (lfe2 == lfe) continue;
     if (lfe2->sf_type != DVB_TYPE_S) continue;
     if (lfe->sf_master == lfe2->sf_number) {
       if (!lfe2->sf_running)
-        return 0; /* master must be running */
-      return satip_frontend_match_satcfg(lfe2, mm, flags, weight);
+        return MI_IS_ENABLED_RETRY; /* master must be running */
+      return satip_frontend_match_satcfg(lfe2, mm, flags, weight) ?
+             MI_IS_ENABLED_OK : MI_IS_ENABLED_RETRY;
     }
     if (lfe2->sf_master == lfe->sf_number) {
       if (lfe2->sf_running)
-        return satip_frontend_match_satcfg(lfe2, mm, flags, weight);
+        return satip_frontend_match_satcfg(lfe2, mm, flags, weight) ?
+               MI_IS_ENABLED_OK : MI_IS_ENABLED_RETRY;
     }
   }
-  return 1;
+  return MI_IS_ENABLED_OK;
 }
 
 static void