epggrab: ota - move service lists from ota to map

- also use service filter for uk_freesat / viasat_baltic
This commit is contained in:
Jaroslav Kysela 2014-06-29 16:24:04 +02:00
parent eab7b739b3
commit 6a6d3f65e4
5 changed files with 98 additions and 85 deletions

View file

@ -202,12 +202,9 @@ 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;
RB_HEAD(,epggrab_ota_svc_link) om_svcs; ///< Muxes we carry data for
};
/*
@ -220,6 +217,9 @@ struct epggrab_ota_map
int om_timeout;
int om_interval;
int om_complete;
int om_first;
uint64_t om_tune_count;
RB_HEAD(,epggrab_ota_svc_link) om_svcs; ///< Muxes we carry data for
};
/*
@ -232,9 +232,9 @@ struct epggrab_module_ota
//TAILQ_HEAD(, epggrab_ota_mux) muxes; ///< List of related muxes
/* Transponder tuning */
void (*start) ( epggrab_module_ota_t *m, struct mpegts_mux *mm );
void (*start) ( epggrab_ota_map_t *map, struct mpegts_mux *mm );
void (*done) ( epggrab_module_ota_t *m );
int (*tune) ( epggrab_module_ota_t *m, epggrab_ota_mux_t *om,
int (*tune) ( epggrab_ota_map_t *map, epggrab_ota_mux_t *om,
struct mpegts_mux *mm );
};

View file

@ -555,7 +555,8 @@ _eit_callback
uint32_t extraid;
mpegts_service_t *svc;
mpegts_mux_t *mm = mt->mt_mux;
epggrab_module_t *mod = mt->mt_opaque;
epggrab_ota_map_t *map = mt->mt_opaque;
epggrab_module_t *mod = (epggrab_module_t *)map->om_module;
epggrab_ota_mux_t *ota = NULL;
mpegts_table_state_t *st;
@ -573,7 +574,7 @@ _eit_callback
/* Register interest */
if (tableid >= 0x50)
ota = epggrab_ota_register((epggrab_module_ota_t*)mod, mm);
ota = epggrab_ota_register((epggrab_module_ota_t*)mod, NULL, mm);
/* Begin */
r = dvb_table_begin(mt, ptr, len, tableid, extraid, 11, &st, &sect, &last, &ver);
@ -607,9 +608,9 @@ _eit_callback
if(!mm)
goto done;
if (ota && ota->om_first) {
ota->om_tune_count++;
ota->om_first = 0;
if (map->om_first) {
map->om_tune_count++;
map->om_first = 0;
}
/* Get service */
@ -619,7 +620,7 @@ _eit_callback
/* Register this */
if (ota)
epggrab_ota_service_add(ota, idnode_uuid_as_str(&svc->s_id), 1);
epggrab_ota_service_add(map, ota, idnode_uuid_as_str(&svc->s_id), 1);
/* No point processing */
if (!LIST_FIRST(&svc->s_channels))
@ -655,8 +656,9 @@ done:
* ***********************************************************************/
static void _eit_start
( epggrab_module_ota_t *m, mpegts_mux_t *dm )
( epggrab_ota_map_t *map, mpegts_mux_t *dm )
{
epggrab_module_ota_t *m = map->om_module;
int pid, opts = 0;
/* Disabled */
@ -683,15 +685,16 @@ static void _eit_start
pid = 0x12;
opts = MT_RECORD;
}
mpegts_table_add(dm, 0, 0, _eit_callback, m, m->id, MT_CRC | opts, pid);
mpegts_table_add(dm, 0, 0, _eit_callback, map, m->id, MT_CRC | opts, pid);
// TODO: might want to limit recording to EITpf only
tvhlog(LOG_DEBUG, m->id, "installed table handlers");
}
static int _eit_tune
( epggrab_module_ota_t *m, epggrab_ota_mux_t *om, mpegts_mux_t *mm )
( epggrab_ota_map_t *map, epggrab_ota_mux_t *om, mpegts_mux_t *mm )
{
int r = 0;
epggrab_module_ota_t *m = map->om_module;
mpegts_service_t *s;
epggrab_ota_svc_link_t *osl, *nxt;
@ -704,20 +707,15 @@ static int _eit_tune
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) {
for (osl = RB_FIRST(&map->om_svcs); osl != NULL; osl = nxt) {
nxt = RB_NEXT(osl, link);
/* rule: if 5 mux scans fails for this service, remove it */
if (osl->last_tune_count + 5 <= om->om_tune_count ||
if (osl->last_tune_count + 5 <= map->om_tune_count ||
!(s = mpegts_service_find_by_uuid(osl->uuid))) {
epggrab_ota_service_del(om, osl, 1);
epggrab_ota_service_del(map, om, osl, 1);
} else {
if (LIST_FIRST(&s->s_channels))
r = 1;

View file

@ -504,7 +504,7 @@ opentv_bat_callback
/* Register */
if (!ota) {
sta->os_ota = ota
= epggrab_ota_register((epggrab_module_ota_t*)mod, mt->mt_mux);
= epggrab_ota_register((epggrab_module_ota_t*)mod, NULL, mt->mt_mux);
}
/* Complete */
@ -539,10 +539,11 @@ opentv_bat_callback
* ***********************************************************************/
static void _opentv_start
( epggrab_module_ota_t *m, mpegts_mux_t *mm )
( epggrab_ota_map_t *map, mpegts_mux_t *mm )
{
int *t;
opentv_module_t *mod = (opentv_module_t*)m;
opentv_module_t *mod = (opentv_module_t*)map->om_module;
epggrab_module_ota_t *m = map->om_module;
opentv_status_t *sta = NULL;
mpegts_table_t *mt;
static struct mpegts_table_mux_cb bat_desc[] = {
@ -551,7 +552,7 @@ static void _opentv_start
};
/* Ignore */
if (!m->enabled) return;
if (!m->enabled) return;
if (mod->tsid != mm->mm_tsid) return;
/* Install tables */
@ -693,8 +694,9 @@ static void _opentv_done( epggrab_module_ota_t *m )
}
static int _opentv_tune
( epggrab_module_ota_t *m, epggrab_ota_mux_t *om, mpegts_mux_t *mm )
( epggrab_ota_map_t *map, epggrab_ota_mux_t *om, mpegts_mux_t *mm )
{
epggrab_module_ota_t *m = map->om_module;
opentv_module_t *mod = (opentv_module_t*)m;
/* Ignore */

View file

@ -141,11 +141,11 @@ 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);
LIST_FOREACH(map, &om->om_modules, om_link) {
map->om_first = 1;
map->om_complete = 0;
tvhdebug(map->om_module->id, "grab started");
}
@ -158,22 +158,31 @@ epggrab_ota_start ( epggrab_ota_mux_t *om, int grace )
static void
epggrab_mux_start ( mpegts_mux_t *mm, void *p )
{
epggrab_module_t *m;
epggrab_module_ota_t *om;
epggrab_ota_mux_t *ota;
epggrab_module_t *m;
epggrab_ota_map_t *map;
epggrab_ota_mux_t *ota, ota_skel;
const char *uuid = idnode_uuid_as_str(&mm->mm_id);
/* Already started */
LIST_FOREACH(ota, &epggrab_ota_active, om_q_link)
if (!strcmp(ota->om_mux_uuid, idnode_uuid_as_str(&mm->mm_id)))
if (!strcmp(ota->om_mux_uuid, uuid))
return;
/* Check if already active */
/* Find the configuration */
ota_skel.om_mux_uuid = (char *)uuid;
ota = RB_FIND(&epggrab_ota_all, &ota_skel, om_global_link, om_id_cmp);
if (!ota)
return;
/* Register all modules */
LIST_FOREACH(m, &epggrab_modules, link) {
if (m->type == EPGGRAB_OTA) {
om = (epggrab_module_ota_t*)m;
if (om->start) om->start(om, mm);
}
if (m->type == EPGGRAB_OTA && m->enabled)
epggrab_ota_register((epggrab_module_ota_t *)m, ota, mm);
}
/* Check if already active */
LIST_FOREACH(map, &ota->om_modules, om_link)
map->om_module->start(map, mm);
}
static void
@ -190,34 +199,34 @@ epggrab_mux_stop ( mpegts_mux_t *mm, void *p )
epggrab_ota_mux_t *
epggrab_ota_register
( epggrab_module_ota_t *mod, mpegts_mux_t *mm )
( epggrab_module_ota_t *mod, epggrab_ota_mux_t *ota, mpegts_mux_t *mm )
{
int save = 0;
int interval = 3600;
int timeout = 240;
epggrab_ota_map_t *map;
epggrab_ota_mux_t *ota;
/* Find mux entry */
const char *uuid = idnode_uuid_as_str(&mm->mm_id);
SKEL_ALLOC(epggrab_ota_mux_skel);
epggrab_ota_mux_skel->om_mux_uuid = (char*)uuid;
if (ota == NULL) {
/* Find mux entry */
const char *uuid = idnode_uuid_as_str(&mm->mm_id);
SKEL_ALLOC(epggrab_ota_mux_skel);
epggrab_ota_mux_skel->om_mux_uuid = (char*)uuid;
ota = RB_INSERT_SORTED(&epggrab_ota_all, epggrab_ota_mux_skel, om_global_link, om_id_cmp);
if (!ota) {
char buf[256];
mm->mm_display_name(mm, buf, sizeof(buf));
tvhinfo(mod->id, "registering mux %s", buf);
ota = epggrab_ota_mux_skel;
SKEL_USED(epggrab_ota_mux_skel);
RB_INIT(&ota->om_svcs);
ota->om_mux_uuid = strdup(uuid);
ota->om_when = dispatch_clock + epggrab_ota_timeout(ota);
ota->om_active = 1;
LIST_INSERT_SORTED(&epggrab_ota_active, ota, om_q_link, om_time_cmp);
if (LIST_FIRST(&epggrab_ota_active) == ota)
epggrab_ota_active_timer_cb(NULL);
save = 1;
ota = RB_INSERT_SORTED(&epggrab_ota_all, epggrab_ota_mux_skel, om_global_link, om_id_cmp);
if (!ota) {
char buf[256];
mm->mm_display_name(mm, buf, sizeof(buf));
tvhinfo(mod->id, "registering mux %s", buf);
ota = epggrab_ota_mux_skel;
SKEL_USED(epggrab_ota_mux_skel);
ota->om_mux_uuid = strdup(uuid);
ota->om_when = dispatch_clock + epggrab_ota_timeout(ota);
ota->om_active = 1;
LIST_INSERT_SORTED(&epggrab_ota_active, ota, om_q_link, om_time_cmp);
if (LIST_FIRST(&epggrab_ota_active) == ota)
epggrab_ota_active_timer_cb(NULL);
save = 1;
}
}
/* Find module entry */
@ -226,6 +235,7 @@ epggrab_ota_register
break;
if (!map) {
map = calloc(1, sizeof(epggrab_ota_map_t));
RB_INIT(&map->om_svcs);
map->om_module = mod;
map->om_timeout = timeout;
map->om_interval = interval;
@ -332,7 +342,7 @@ next_one:
/* Check we have modules attached and enabled */
LIST_FOREACH(map, &om->om_modules, om_link) {
if (map->om_module->tune(map->om_module, om, mm))
if (map->om_module->tune(map, om, mm))
break;
}
if (!map) {
@ -368,7 +378,8 @@ done:
}
void
epggrab_ota_service_add ( epggrab_ota_mux_t *ota, const char *uuid, int save )
epggrab_ota_service_add ( epggrab_ota_map_t *map, epggrab_ota_mux_t *ota,
const char *uuid, int save )
{
epggrab_ota_svc_link_t *svcl;
@ -376,7 +387,7 @@ epggrab_ota_service_add ( epggrab_ota_mux_t *ota, const char *uuid, int save )
return;
SKEL_ALLOC(epggrab_svc_link_skel);
epggrab_svc_link_skel->uuid = (char *)uuid;
svcl = RB_INSERT_SORTED(&ota->om_svcs, epggrab_svc_link_skel, link, om_svcl_cmp);
svcl = RB_INSERT_SORTED(&map->om_svcs, epggrab_svc_link_skel, link, om_svcl_cmp);
if (svcl == NULL) {
svcl = epggrab_svc_link_skel;
SKEL_USED(epggrab_svc_link_skel);
@ -384,16 +395,15 @@ epggrab_ota_service_add ( epggrab_ota_mux_t *ota, const char *uuid, int save )
if (save && ota->om_complete)
epggrab_ota_save(ota);
}
svcl->last_tune_count = ota->om_tune_count;
}
void
epggrab_ota_service_del ( epggrab_ota_mux_t *ota, epggrab_ota_svc_link_t *svcl,
int save )
epggrab_ota_service_del ( epggrab_ota_map_t *map, epggrab_ota_mux_t *ota,
epggrab_ota_svc_link_t *svcl, int save )
{
if (svcl == NULL)
return;
RB_REMOVE(&ota->om_svcs, svcl, link);
RB_REMOVE(&map->om_svcs, svcl, link);
free(svcl->uuid);
free(svcl);
if (save)
@ -409,22 +419,22 @@ epggrab_ota_save ( epggrab_ota_mux_t *ota )
{
epggrab_ota_map_t *map;
epggrab_ota_svc_link_t *svcl;
htsmsg_t *e, *l, *c = htsmsg_create_map();
htsmsg_t *e, *l, *l2, *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();
RB_FOREACH(svcl, &ota->om_svcs, link)
if (svcl->uuid)
htsmsg_add_str(l, NULL, svcl->uuid);
htsmsg_add_msg(c, "services", l);
l = htsmsg_create_list();
LIST_FOREACH(map, &ota->om_modules, om_link) {
e = htsmsg_create_map();
htsmsg_add_str(e, "id", map->om_module->id);
htsmsg_add_u32(e, "timeout", map->om_timeout);
htsmsg_add_u32(e, "interval", map->om_interval);
l2 = htsmsg_create_list();
RB_FOREACH(svcl, &map->om_svcs, link)
if (svcl->uuid)
htsmsg_add_str(l2, NULL, svcl->uuid);
htsmsg_add_msg(e, "services", l2);
htsmsg_add_msg(l, NULL, e);
}
htsmsg_add_msg(c, "modules", l);
@ -436,8 +446,8 @@ static void
epggrab_ota_load_one
( const char *uuid, htsmsg_t *c )
{
htsmsg_t *l, *e;
htsmsg_field_t *f;
htsmsg_t *l, *l2, *e;
htsmsg_field_t *f, *f2;
mpegts_mux_t *mm;
epggrab_module_ota_t *mod;
epggrab_ota_mux_t *ota;
@ -451,14 +461,9 @@ epggrab_ota_load_one
}
ota = calloc(1, sizeof(epggrab_ota_mux_t));
RB_INIT(&ota->om_svcs);
ota->om_mux_uuid = strdup(uuid);
ota->om_timeout = htsmsg_get_u32_or_default(c, "timeout", 0);
ota->om_interval = htsmsg_get_u32_or_default(c, "interval", 0);
if ((l = htsmsg_get_list(c, "services")) != NULL) {
HTSMSG_FOREACH(f, l)
epggrab_ota_service_add(ota, htsmsg_field_get_str(f), 0);
}
if (RB_INSERT_SORTED(&epggrab_ota_all, ota, om_global_link, om_id_cmp)) {
free(ota->om_mux_uuid);
free(ota);
@ -474,9 +479,14 @@ epggrab_ota_load_one
continue;
map = calloc(1, sizeof(epggrab_ota_map_t));
RB_INIT(&map->om_svcs);
map->om_module = mod;
map->om_timeout = htsmsg_get_u32_or_default(e, "timeout", 0);
map->om_interval = htsmsg_get_u32_or_default(e, "interval", 0);
if ((l2 = htsmsg_get_list(e, "services")) != NULL) {
HTSMSG_FOREACH(f2, l2)
epggrab_ota_service_add(map, ota, htsmsg_field_get_str(f2), 0);
}
LIST_INSERT_HEAD(&ota->om_modules, map, om_link);
}
}
@ -526,10 +536,10 @@ epggrab_ota_free ( epggrab_ota_mux_t *ota )
LIST_REMOVE(ota, om_q_link);
while ((map = LIST_FIRST(&ota->om_modules)) != NULL) {
LIST_REMOVE(map, om_link);
while ((svcl = RB_FIRST(&map->om_svcs)) != NULL)
epggrab_ota_service_del(map, ota, svcl, 0);
free(map);
}
while ((svcl = RB_FIRST(&ota->om_svcs)) != NULL)
epggrab_ota_service_del(ota, svcl, 0);
free(ota->om_mux_uuid);
free(ota);
}

View file

@ -86,10 +86,10 @@ epggrab_module_ext_t *epggrab_module_ext_create
* *************************************************************************/
typedef struct epggrab_ota_module_ops {
void (*start) (epggrab_module_ota_t *m, struct mpegts_mux *mm);
void (*start) (epggrab_ota_map_t *map, 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, epggrab_ota_mux_t *om,
int (*tune) (epggrab_ota_map_t *map, epggrab_ota_mux_t *om,
struct mpegts_mux *mm);
} epggrab_ota_module_ops_t;
@ -136,7 +136,8 @@ void epggrab_ota_destroy_by_dm ( struct dvb_mux *dm );
*/
epggrab_ota_mux_t *epggrab_ota_register
( epggrab_module_ota_t *mod, struct mpegts_mux *mux );
( epggrab_module_ota_t *mod, epggrab_ota_mux_t *ota,
struct mpegts_mux *mux );
/*
* State change
@ -149,10 +150,12 @@ void epggrab_ota_complete
*/
void
epggrab_ota_service_add
( epggrab_ota_mux_t *ota, const char *uuid, int save );
( epggrab_ota_map_t *map, epggrab_ota_mux_t *ota,
const char *uuid, int save );
void
epggrab_ota_service_del
( epggrab_ota_mux_t *ota, epggrab_ota_svc_link_t *svcl, int save );
( epggrab_ota_map_t *map, epggrab_ota_mux_t *ota,
epggrab_ota_svc_link_t *svcl, int save );
/* **************************************************************************
* Miscellaneous