]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
epggrab: test code for only tuning muxes that require it feature/epggrab-ota-mux-check 900/head
authorAdam Sutton <dev@adamsutton.me.uk>
Sat, 28 Jun 2014 15:19:11 +0000 (16:19 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Sat, 28 Jun 2014 15:19:11 +0000 (16:19 +0100)
src/epggrab.h
src/epggrab/module/eit.c
src/epggrab/module/opentv.c
src/epggrab/otamux.c
src/epggrab/private.h
src/input/mpegts.h

index ed56e1d4fb04e186555b10c5d44c97dfa4d17bd8..21786ca3d69f101ef8b0fea50cfd54b66ed5d240 100644 (file)
@@ -33,6 +33,7 @@ typedef struct epggrab_module_ext   epggrab_module_ext_t;
 typedef struct epggrab_module_ota   epggrab_module_ota_t;
 typedef struct epggrab_ota_mux      epggrab_ota_mux_t;
 typedef struct epggrab_ota_map      epggrab_ota_map_t;
+typedef struct epggrab_ota_svc_link epggrab_ota_svc_link_t;
 
 LIST_HEAD(epggrab_module_list, epggrab_module);
 typedef struct epggrab_module_list epggrab_module_list_t;
@@ -180,6 +181,12 @@ struct epggrab_module_ext
   int                          sock;      ///< Socket descriptor
 };
 
+struct epggrab_ota_svc_link
+{
+  char                          *uuid;
+  RB_ENTRY(epggrab_ota_svc_link) link;
+};
+
 /*
  * TODO: this could be embedded in the mux itself, but by using a soft-link
  *       and keeping it here I can somewhat isolate it from the mpegts code
@@ -189,6 +196,7 @@ struct epggrab_ota_mux
   char                              *om_mux_uuid;     ///< Soft-link to mux
   LIST_HEAD(,epggrab_ota_map)        om_modules;      ///< List of linked mods
   
+  int                                om_complete;     ///< Has completed a scan
   int                                om_active;
   int                                om_timeout;      ///< User configurable
   int                                om_interval;
@@ -196,6 +204,7 @@ struct epggrab_ota_mux
 
   LIST_ENTRY(epggrab_ota_mux)        om_q_link;
   RB_ENTRY(epggrab_ota_mux)          om_global_link;
+  RB_HEAD(,epggrab_ota_svc_link)     om_svcs;         ///< Muxes we carry data for
 };
 
 /*
@@ -222,7 +231,7 @@ struct epggrab_module_ota
   /* Transponder tuning */
   void (*start) ( epggrab_module_ota_t *m, struct mpegts_mux *mm );
   void (*done)  ( epggrab_module_ota_t *m );
-  int  (*tune)  ( epggrab_module_ota_t *m, struct mpegts_mux *mm );
+  int  (*tune)  ( epggrab_module_ota_t *m, epggrab_ota_mux_t *om );
 };
 
 /*
index ba91618d7afec256b67f85c6fa316d14719a3529..2eeb2c08a6d21a84565ae1c120198d8f4eee59d8 100644 (file)
 #include "input.h"
 #include "input/mpegts/dvb_charset.h"
 
+SKEL_DECLARE(svc_link_skel, epggrab_ota_svc_link_t);
+
+static int
+osl_cmp ( epggrab_ota_svc_link_t *a, epggrab_ota_svc_link_t *b )
+{
+  return strcmp(a->uuid, b->uuid);
+}
+
 /* ************************************************************************
  * Status handling
  * ***********************************************************************/
@@ -558,6 +566,7 @@ _eit_callback
   epggrab_module_t *mod = mt->mt_opaque;
   epggrab_ota_mux_t    *ota = NULL;
   mpegts_table_state_t *st;
+  epggrab_ota_svc_link_t *osl;
 
   /* Validate */
   if(tableid < 0x4e || tableid > 0x6f || len < 11)
@@ -609,8 +618,20 @@ _eit_callback
 
   /* Get service */
   svc = mpegts_mux_find_service(mm, sid);
-  // TODO: have lost the concept of the primary EPG service!
-  if (!svc || !LIST_FIRST(&svc->s_channels))
+  if (!svc)
+    goto done;
+
+  /* Register this */
+  SKEL_ALLOC(svc_link_skel);
+  svc_link_skel->uuid = (char*)idnode_uuid_as_str(&svc->s_id);
+  osl = RB_INSERT_SORTED(&ota->om_svcs, svc_link_skel, link, osl_cmp);
+  if (!osl) {
+    svc_link_skel->uuid = strdup(svc_link_skel->uuid);
+    SKEL_USED(svc_link_skel);
+  }
+
+  /* No point processing */
+  if (!LIST_FIRST(&svc->s_channels))
     goto done;
 
   /* Process events */
@@ -677,9 +698,39 @@ static void _eit_start
 }
 
 static int _eit_tune
-  ( epggrab_module_ota_t *m, mpegts_mux_t *mm )
+  ( epggrab_module_ota_t *m, epggrab_ota_mux_t *om )
 {
-  return 1;
+  int r = 0;
+  mpegts_service_t *s;
+  epggrab_ota_svc_link_t *osl, *nxt;
+
+  lock_assert(&global_lock);
+
+  /* Have gathered enough info to decide */
+  if (!om->om_complete)
+    return 1;
+
+  /* Non-standard (known to carry FULL network info) */
+  if (!strcmp(m->id, "uk_freesat") ||
+      !strcmp(m->id, "viasat_baltic"))
+    return 1;
+
+  /* Check if any services are mapped */
+  // TODO: using indirect ref's like this is inefficient, should 
+  //       consider changeing it?
+  for (osl = RB_FIRST(&om->om_svcs); osl != NULL; osl = nxt) {
+    nxt = RB_NEXT(osl, link);
+    if (!(s = mpegts_service_find_by_uuid(osl->uuid))) {
+      RB_REMOVE(&om->om_svcs, osl, link);
+      free(osl->uuid);
+      free(osl);
+    } else {
+      if (LIST_FIRST(&s->s_channels))
+        r = 1;
+    }
+  }
+
+  return r;
 }
 
 void eit_init ( void )
@@ -689,6 +740,8 @@ void eit_init ( void )
     .tune  = _eit_tune,
   };
 
+  SKEL_USED(svc_link_skel);
+
   epggrab_module_ota_create(NULL, "eit", "EIT: DVB Grabber", 1, &ops, NULL);
   epggrab_module_ota_create(NULL, "uk_freesat", "UK: Freesat", 5, &ops, NULL);
   epggrab_module_ota_create(NULL, "uk_freeview", "UK: Freeview", 5, &ops, NULL);
index 982e46a8d69294ea4c174ded222eec5128eb193f..1fe48ba6feb86f74b2148162b304711e022ff4cc 100644 (file)
@@ -692,7 +692,8 @@ static void _opentv_done( epggrab_module_ota_t *m )
   free(mod->summary);
 }
 
-static int _opentv_tune ( epggrab_module_ota_t *m, mpegts_mux_t *mm )
+static int _opentv_tune
+  ( epggrab_module_ota_t *m, epggrab_ota_mux_t *om )
 {
   return 1;
 }
index 62b97ba84b06692ff37211e1103698eb0703f00a..4d48f6fd2b80ea9ae1f6f64028a170ecef3896c7 100644 (file)
@@ -247,6 +247,12 @@ epggrab_ota_complete
   lock_assert(&global_lock);
   tvhdebug(mod->id, "grab complete");
 
+  /* Mark */
+  if (!ota->om_complete) {
+    ota->om_complete = 1;
+    epggrab_ota_save(ota);
+  }
+
   /* Test for completion */
   LIST_FOREACH(map, &ota->om_modules, om_link) {
     if (map->om_module == mod) {
@@ -326,7 +332,7 @@ next_one:
   /* Check we have modules attached and enabled */
   LIST_FOREACH(map, &om->om_modules, om_link) {
     if (map->om_module->enabled &&
-        map->om_module->tune && map->om_module->tune(map->om_module, mm))
+        map->om_module->tune && map->om_module->tune(map->om_module, om))
       break;
   }
   if (!map) {
@@ -371,6 +377,7 @@ epggrab_ota_save ( epggrab_ota_mux_t *ota )
   epggrab_ota_map_t *map;
   htsmsg_t *e, *l, *c = htsmsg_create_map();
 
+  htsmsg_add_u32(c, "complete", ota->om_complete);
   htsmsg_add_u32(c, "timeout",  ota->om_timeout);
   htsmsg_add_u32(c, "interval", ota->om_interval);
   l = htsmsg_create_list();
index 0a2e1dc25c623eb036ee29a39ebb1cf6a9fdcce9..ebce569faec71bb3d687f127b737d3da0946119d 100644 (file)
@@ -89,7 +89,7 @@ typedef struct epggrab_ota_module_ops {
     void (*start)  (epggrab_module_ota_t *m, struct mpegts_mux *mm);
     int  (*enable) (void *m, uint8_t e );
     void (*done)   (epggrab_module_ota_t*m);
-    int  (*tune)   (epggrab_module_ota_t *m, struct mpegts_mux *mm);
+    int  (*tune)   (epggrab_module_ota_t *m, epggrab_ota_mux_t *om );
 } epggrab_ota_module_ops_t;
 
 epggrab_module_ota_t *epggrab_module_ota_create
index c528c6165c939a691110df20a9769978f623d711..e1e0a02e4aefacfb4b43c04bef447a7d19fba0f2 100644 (file)
@@ -764,6 +764,9 @@ mpegts_service_t *mpegts_service_create0
 mpegts_service_t *mpegts_service_find 
   ( mpegts_mux_t *mm, uint16_t sid, uint16_t pmt_pid, int create, int *save );
 
+#define mpegts_service_find_by_uuid(u)\
+  idnode_find(u, &mpegts_service_class)
+
 void mpegts_service_delete ( service_t *s, int delconf );
 
 /*