From 39feb44ec84fea2d56eb5d832bf103bd9a4da9c7 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Sat, 28 Jun 2014 16:19:11 +0100 Subject: [PATCH] epggrab: test code for only tuning muxes that require it --- src/epggrab.h | 11 ++++++- src/epggrab/module/eit.c | 61 ++++++++++++++++++++++++++++++++++--- src/epggrab/module/opentv.c | 3 +- src/epggrab/otamux.c | 9 +++++- src/epggrab/private.h | 2 +- src/input/mpegts.h | 3 ++ 6 files changed, 81 insertions(+), 8 deletions(-) diff --git a/src/epggrab.h b/src/epggrab.h index ed56e1d4..21786ca3 100644 --- a/src/epggrab.h +++ b/src/epggrab.h @@ -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 ); }; /* diff --git a/src/epggrab/module/eit.c b/src/epggrab/module/eit.c index ba91618d..2eeb2c08 100644 --- a/src/epggrab/module/eit.c +++ b/src/epggrab/module/eit.c @@ -27,6 +27,14 @@ #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); diff --git a/src/epggrab/module/opentv.c b/src/epggrab/module/opentv.c index 982e46a8..1fe48ba6 100644 --- a/src/epggrab/module/opentv.c +++ b/src/epggrab/module/opentv.c @@ -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; } diff --git a/src/epggrab/otamux.c b/src/epggrab/otamux.c index 62b97ba8..4d48f6fd 100644 --- a/src/epggrab/otamux.c +++ b/src/epggrab/otamux.c @@ -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(); diff --git a/src/epggrab/private.h b/src/epggrab/private.h index 0a2e1dc2..ebce569f 100644 --- a/src/epggrab/private.h +++ b/src/epggrab/private.h @@ -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 diff --git a/src/input/mpegts.h b/src/input/mpegts.h index c528c616..e1e0a02e 100644 --- a/src/input/mpegts.h +++ b/src/input/mpegts.h @@ -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 ); /*