From eab7b739b3ca50b08d0dfbe387f7dc336e171b40 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Sun, 29 Jun 2014 15:02:58 +0200 Subject: [PATCH] epggrab / eit: add automatic linked service removal --- src/epggrab.h | 3 +++ src/epggrab/module/eit.c | 9 ++++++++- src/epggrab/otamux.c | 26 ++++++++++++-------------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/epggrab.h b/src/epggrab.h index 7dde5315..1555520f 100644 --- a/src/epggrab.h +++ b/src/epggrab.h @@ -184,6 +184,7 @@ struct epggrab_module_ext struct epggrab_ota_svc_link { char *uuid; + uint64_t last_tune_count; RB_ENTRY(epggrab_ota_svc_link) link; }; @@ -201,6 +202,8 @@ struct epggrab_ota_mux int om_timeout; ///< User configurable int om_interval; time_t om_when; ///< Next event time + int om_first; + uint64_t om_tune_count; ///< Tune counter LIST_ENTRY(epggrab_ota_mux) om_q_link; RB_ENTRY(epggrab_ota_mux) om_global_link; diff --git a/src/epggrab/module/eit.c b/src/epggrab/module/eit.c index cc6c067f..778aa05a 100644 --- a/src/epggrab/module/eit.c +++ b/src/epggrab/module/eit.c @@ -607,6 +607,11 @@ _eit_callback if(!mm) goto done; + if (ota && ota->om_first) { + ota->om_tune_count++; + ota->om_first = 0; + } + /* Get service */ svc = mpegts_mux_find_service(mm, sid); if (!svc) @@ -709,7 +714,9 @@ static int _eit_tune // 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))) { + /* rule: if 5 mux scans fails for this service, remove it */ + if (osl->last_tune_count + 5 <= om->om_tune_count || + !(s = mpegts_service_find_by_uuid(osl->uuid))) { epggrab_ota_service_del(om, osl, 1); } else { if (LIST_FIRST(&s->s_channels)) diff --git a/src/epggrab/otamux.c b/src/epggrab/otamux.c index 1c35c52a..312997de 100644 --- a/src/epggrab/otamux.c +++ b/src/epggrab/otamux.c @@ -141,6 +141,7 @@ epggrab_ota_start ( epggrab_ota_mux_t *om, int grace ) epggrab_ota_map_t *map; om->om_when = dispatch_clock + epggrab_ota_timeout(om) + grace; om->om_active = 1; + om->om_first = 1; LIST_INSERT_SORTED(&epggrab_ota_active, om, om_q_link, om_time_cmp); if (LIST_FIRST(&epggrab_ota_active) == om) epggrab_ota_active_timer_cb(NULL); @@ -155,18 +156,16 @@ epggrab_ota_start ( epggrab_ota_mux_t *om, int grace ) * *************************************************************************/ static void -epggrab_mux_start0 ( mpegts_mux_t *mm, int force ) +epggrab_mux_start ( mpegts_mux_t *mm, void *p ) { epggrab_module_t *m; epggrab_module_ota_t *om; epggrab_ota_mux_t *ota; /* Already started */ - if (!force) { - LIST_FOREACH(ota, &epggrab_ota_active, om_q_link) - if (!strcmp(ota->om_mux_uuid, idnode_uuid_as_str(&mm->mm_id))) - return; - } + LIST_FOREACH(ota, &epggrab_ota_active, om_q_link) + if (!strcmp(ota->om_mux_uuid, idnode_uuid_as_str(&mm->mm_id))) + return; /* Check if already active */ LIST_FOREACH(m, &epggrab_modules, link) { @@ -177,12 +176,6 @@ epggrab_mux_start0 ( mpegts_mux_t *mm, int force ) } } -static void -epggrab_mux_start ( mpegts_mux_t *mm, void *p ) -{ - epggrab_mux_start0(mm, 0); -} - static void epggrab_mux_stop ( mpegts_mux_t *mm, void *p ) { @@ -377,16 +370,21 @@ done: void epggrab_ota_service_add ( epggrab_ota_mux_t *ota, const char *uuid, int save ) { + epggrab_ota_svc_link_t *svcl; + if (uuid == NULL) return; SKEL_ALLOC(epggrab_svc_link_skel); epggrab_svc_link_skel->uuid = (char *)uuid; - if (!RB_INSERT_SORTED(&ota->om_svcs, epggrab_svc_link_skel, link, om_svcl_cmp)) { - epggrab_svc_link_skel->uuid = strdup(uuid); + svcl = RB_INSERT_SORTED(&ota->om_svcs, epggrab_svc_link_skel, link, om_svcl_cmp); + if (svcl == NULL) { + svcl = epggrab_svc_link_skel; SKEL_USED(epggrab_svc_link_skel); + svcl->uuid = strdup(uuid); if (save && ota->om_complete) epggrab_ota_save(ota); } + svcl->last_tune_count = ota->om_tune_count; } void