Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
epggrab: global cleanup, manage channels per module
The epggrab channel mapping was a big mess. For example XMLTV has
only one channels set for all input modules (external/internal)
so the things were merged and very confusing. Now, all sources
are taken as separate inputs with clean and straight mapping.

Also, show the path in EPG Channel Mapping.
  • Loading branch information
perexg committed Oct 24, 2015
1 parent fcf01a4 commit bfb24ea
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/epggrab.c
Expand Up @@ -399,7 +399,7 @@ void epggrab_done ( void )
if (mod->done)
mod->done(mod);
pthread_mutex_lock(&global_lock);
epggrab_channel_flush(mod->channels, 0);
epggrab_channel_flush(mod, 0);
free((void *)mod->id);
free((void *)mod->name);
free(mod);
Expand Down
5 changes: 1 addition & 4 deletions src/epggrab.h
Expand Up @@ -82,7 +82,6 @@ typedef struct epggrab_channel
idnode_t idnode;
TAILQ_ENTRY(epggrab_channel) all_link; ///< Global link
RB_ENTRY(epggrab_channel) link; ///< Global tree link
epggrab_channel_tree_t *tree; ///< Member of this tree
epggrab_module_t *mod; ///< Linked module

int enabled; ///< Enabled/disabled
Expand Down Expand Up @@ -147,7 +146,7 @@ struct epggrab_module
int enabled; ///< Whether the module is enabled
int active; ///< Whether the module is active
int priority; ///< Priority of the module
epggrab_channel_tree_t *channels; ///< Channel list
epggrab_channel_tree_t channels; ///< Channel list

/* Activate */
int (*activate) ( void *m, int activate );
Expand Down Expand Up @@ -239,8 +238,6 @@ struct epggrab_module_ota
{
epggrab_module_t ; ///< Parent object

//TAILQ_HEAD(, epggrab_ota_mux) muxes; ///< List of related muxes

/* Transponder tuning */
int (*start) ( epggrab_ota_map_t *map, struct mpegts_mux *mm );
int (*tune) ( epggrab_ota_map_t *map, epggrab_ota_mux_t *om,
Expand Down
55 changes: 31 additions & 24 deletions src/epggrab/channel.c
Expand Up @@ -217,8 +217,6 @@ epggrab_channel_t *epggrab_channel_create
{
epggrab_channel_t *ec;

assert(owner->channels);

if (htsmsg_get_str(conf, "id") == NULL)
return NULL;

Expand All @@ -232,21 +230,19 @@ epggrab_channel_t *epggrab_channel_create

ec->mod = owner;
ec->enabled = 1;
ec->tree = owner->channels;

if (conf)
idnode_load(&ec->idnode, conf);

TAILQ_INSERT_TAIL(&epggrab_channel_entries, ec, all_link);
if (RB_INSERT_SORTED(owner->channels, ec, link, _ch_id_cmp)) abort();
if (RB_INSERT_SORTED(&owner->channels, ec, link, _ch_id_cmp)) abort();

return ec;
}

/* Find/Create channel in the list */
epggrab_channel_t *epggrab_channel_find
( epggrab_channel_tree_t *tree, const char *id, int create, int *save,
epggrab_module_t *owner )
( epggrab_module_t *mod, const char *id, int create, int *save )
{
char *s;
epggrab_channel_t *ec;
Expand All @@ -263,19 +259,17 @@ epggrab_channel_t *epggrab_channel_find

/* Find */
if (!create) {
ec = RB_FIND(tree, epggrab_channel_skel, link, _ch_id_cmp);
ec = RB_FIND(&mod->channels, epggrab_channel_skel, link, _ch_id_cmp);

/* Find/Create */
} else {
ec = RB_INSERT_SORTED(tree, epggrab_channel_skel, link, _ch_id_cmp);
ec = RB_INSERT_SORTED(&mod->channels, epggrab_channel_skel, link, _ch_id_cmp);
if (!ec) {
assert(owner);
ec = epggrab_channel_skel;
SKEL_USED(epggrab_channel_skel);
ec->enabled = 1;
ec->tree = tree;
ec->id = strdup(ec->id);
ec->mod = owner;
ec->mod = mod;
TAILQ_INSERT_TAIL(&epggrab_channel_entries, ec, all_link);

if (idnode_insert(&ec->idnode, NULL, &epggrab_channel_class, 0))
Expand All @@ -302,7 +296,7 @@ void epggrab_channel_destroy( epggrab_channel_t *ec, int delconf )

/* Already linked */
epggrab_channel_links_delete(ec, 0);
RB_REMOVE(ec->tree, ec, link);
RB_REMOVE(&ec->mod->channels, ec, link);
TAILQ_REMOVE(&epggrab_channel_entries, ec, all_link);
idnode_unlink(&ec->idnode);

Expand All @@ -318,15 +312,11 @@ void epggrab_channel_destroy( epggrab_channel_t *ec, int delconf )
}

void epggrab_channel_flush
( epggrab_channel_tree_t *tree, int delconf )
( epggrab_module_t *mod, int delconf )
{
epggrab_channel_t *ec;
if (tree == NULL)
return;
while ((ec = RB_FIRST(tree)) != NULL) {
assert(tree == ec->tree);
while ((ec = RB_FIRST(&mod->channels)) != NULL)
epggrab_channel_destroy(ec, delconf);
}
}

/* **************************************************************************
Expand All @@ -339,10 +329,9 @@ void epggrab_channel_add ( channel_t *ch )
epggrab_channel_t *egc;

LIST_FOREACH(mod, &epggrab_modules, link)
if (mod->channels)
RB_FOREACH(egc, mod->channels, link)
if (epggrab_channel_match_and_link(egc, ch))
break;
RB_FOREACH(egc, &mod->channels, link)
if (epggrab_channel_match_and_link(egc, ch))
break;
}

void epggrab_channel_rem ( channel_t *ch )
Expand Down Expand Up @@ -376,8 +365,8 @@ epggrab_channel_find_by_id ( const char *id )
strncpy(buf, id, sizeof(buf));
buf[sizeof(buf)-1] = '\0';
if ((mid = strtok_r(buf, "|", &cid)) && cid)
if ((mod = epggrab_module_find_by_id(mid)) && mod->channels)
return epggrab_channel_find(mod->channels, cid, 0, NULL, NULL);
if ((mod = epggrab_module_find_by_id(mid)) != NULL)
return epggrab_channel_find(mod, cid, 0, NULL);
return NULL;
}

Expand Down Expand Up @@ -421,6 +410,17 @@ epggrab_channel_class_module_get ( void *obj )
return &prop_sbuf_ptr;
}

static const void *
epggrab_channel_class_path_get ( void *obj )
{
epggrab_channel_t *ec = obj;
if (ec->mod->type == EPGGRAB_INT || ec->mod->type == EPGGRAB_EXT)
snprintf(prop_sbuf, PROP_SBUF_LEN, "%s", ((epggrab_module_int_t *)ec->mod)->path ?: "");
else
prop_sbuf[0] = '\0';
return &prop_sbuf_ptr;
}

static const void *
epggrab_channel_class_channels_get ( void *obj )
{
Expand Down Expand Up @@ -467,6 +467,13 @@ const idclass_t epggrab_channel_class = {
.get = epggrab_channel_class_module_get,
.opts = PO_RDONLY | PO_NOSAVE,
},
{
.type = PT_STR,
.id = "path",
.name = N_("Path"),
.get = epggrab_channel_class_path_get,
.opts = PO_RDONLY | PO_NOSAVE,
},
{
.type = PT_STR,
.id = "id",
Expand Down
33 changes: 17 additions & 16 deletions src/epggrab/module.c
Expand Up @@ -158,6 +158,14 @@ const idclass_t epggrab_class_mod_int = {
.ic_class = "epggrab_mod_int",
.ic_caption = N_("Internal EPG Grabber"),
.ic_properties = (const property_t[]){
{
.type = PT_STR,
.id = "path",
.name = N_("Path"),
.off = offsetof(epggrab_module_int_t, path),
.opts = PO_RDONLY | PO_NOSAVE,
.group = 1
},
{}
}
};
Expand Down Expand Up @@ -194,16 +202,15 @@ const idclass_t epggrab_class_mod_ota = {

epggrab_module_t *epggrab_module_create
( epggrab_module_t *skel, const idclass_t *cls,
const char *id, const char *name, int priority,
epggrab_channel_tree_t *channels )
const char *id, const char *name, int priority )
{
assert(skel);

/* Setup */
skel->id = strdup(id);
skel->name = strdup(name);
skel->priority = priority;
skel->channels = channels;
RB_INIT(&skel->channels);

/* Insert */
assert(!epggrab_module_find_by_id(id));
Expand Down Expand Up @@ -259,7 +266,7 @@ void epggrab_module_channels_load ( epggrab_module_t *mod )
{
htsmsg_t *m, *e;
htsmsg_field_t *f;
if (!mod || !mod->channels) return;
if (!mod) return;
if ((m = hts_settings_load_r(1, "epggrab/%s/channels", mod->id))) {
HTSMSG_FOREACH(f, m) {
if ((e = htsmsg_get_map_by_field(f)))
Expand Down Expand Up @@ -288,21 +295,19 @@ epggrab_module_int_t *epggrab_module_int_create
const char *path,
char* (*grab) (void*m),
int (*parse) (void *m, htsmsg_t *data, epggrab_stats_t *sta),
htsmsg_t* (*trans) (void *mod, char *data),
epggrab_channel_tree_t *channels )
htsmsg_t* (*trans) (void *mod, char *data) )
{
/* Allocate data */
if (!skel) skel = calloc(1, sizeof(epggrab_module_int_t));

/* Pass through */
epggrab_module_create((epggrab_module_t*)skel,
cls ?: &epggrab_class_mod_int,
id, name, priority, channels);
id, name, priority);

/* Int data */
skel->type = EPGGRAB_INT;
skel->path = strdup(path);
skel->channels = channels;
skel->grab = grab ?: epggrab_module_grab_spawn;
skel->trans = trans ?: epggrab_module_trans_xml;
skel->parse = parse;
Expand Down Expand Up @@ -505,8 +510,7 @@ epggrab_module_ext_t *epggrab_module_ext_create
( epggrab_module_ext_t *skel,
const char *id, const char *name, int priority, const char *sockid,
int (*parse) (void *m, htsmsg_t *data, epggrab_stats_t *sta),
htsmsg_t* (*trans) (void *mod, char *data),
epggrab_channel_tree_t *channels )
htsmsg_t* (*trans) (void *mod, char *data) )
{
char path[512];

Expand All @@ -518,8 +522,7 @@ epggrab_module_ext_t *epggrab_module_ext_create
epggrab_module_int_create((epggrab_module_int_t*)skel,
&epggrab_class_mod_ext,
id, name, priority, path,
NULL, parse, trans,
channels);
NULL, parse, trans);

/* Local */
skel->type = EPGGRAB_EXT;
Expand All @@ -536,23 +539,21 @@ epggrab_module_ext_t *epggrab_module_ext_create
epggrab_module_ota_t *epggrab_module_ota_create
( epggrab_module_ota_t *skel,
const char *id, const char *name, int priority,
epggrab_ota_module_ops_t *ops,
epggrab_channel_tree_t *channels )
epggrab_ota_module_ops_t *ops )
{
if (!skel) skel = calloc(1, sizeof(epggrab_module_ota_t));

/* Pass through */
epggrab_module_create((epggrab_module_t*)skel,
&epggrab_class_mod_ota,
id, name, priority, channels);
id, name, priority);

/* Setup */
skel->type = EPGGRAB_OTA;
skel->activate = ops->activate;
skel->start = ops->start;
skel->done = ops->done;
skel->tune = ops->tune;
//TAILQ_INIT(&skel->muxes);

return skel;
}
10 changes: 5 additions & 5 deletions src/epggrab/module/eit.c
Expand Up @@ -789,11 +789,11 @@ void eit_init ( void )
.tune = _eit_tune,
};

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);
epggrab_module_ota_create(NULL, "viasat_baltic", "VIASAT: Baltic", 5, &ops, NULL);
epggrab_module_ota_create(NULL, "Bulsatcom_39E", "Bulsatcom: Bula 39E", 5, &ops, NULL);
epggrab_module_ota_create(NULL, "eit", "EIT: DVB Grabber", 1, &ops);
epggrab_module_ota_create(NULL, "uk_freesat", "UK: Freesat", 5, &ops);
epggrab_module_ota_create(NULL, "uk_freeview", "UK: Freeview", 5, &ops);
epggrab_module_ota_create(NULL, "viasat_baltic", "VIASAT: Baltic", 5, &ops);
epggrab_module_ota_create(NULL, "Bulsatcom_39E", "Bulsatcom: Bula 39E", 5, &ops);
}

void eit_done ( void )
Expand Down
13 changes: 3 additions & 10 deletions src/epggrab/module/opentv.c
Expand Up @@ -34,8 +34,6 @@
#include "settings.h"
#include "input.h"

static epggrab_channel_tree_t _opentv_channels;

#define OPENTV_TITLE_BASE 0xA0
#define OPENTV_SUMMARY_BASE 0xA8
#define OPENTV_TABLE_MASK 0xFC
Expand Down Expand Up @@ -170,8 +168,7 @@ static epggrab_channel_t *_opentv_find_epggrab_channel
{
char chid[256];
snprintf(chid, sizeof(chid), "%s-%d", mod->id, cid);
return epggrab_channel_find(&_opentv_channels, chid, create, save,
(epggrab_module_t*)mod);
return epggrab_channel_find((epggrab_module_t*)mod, chid, create, save);
}

/* ************************************************************************
Expand Down Expand Up @@ -945,9 +942,9 @@ static int _opentv_prov_load_one ( const char *id, htsmsg_t *m )

/* Create */
sprintf(nbuf, "OpenTV: %s", name);
mod = (opentv_module_t*)
mod = (opentv_module_t *)
epggrab_module_ota_create(calloc(1, sizeof(opentv_module_t)),
ibuf, nbuf, 2, &ops, NULL);
ibuf, nbuf, 2, &ops);

/* Add provider details */
mod->dict = dict;
Expand All @@ -960,7 +957,6 @@ static int _opentv_prov_load_one ( const char *id, htsmsg_t *m )
mod->channel = _pid_list_to_array(cl);
mod->title = _pid_list_to_array(tl);
mod->summary = _pid_list_to_array(sl);
mod->channels = &_opentv_channels;
_opentv_compile_pattern_list(&mod->p_snum, htsmsg_get_list(m, "season_num"));
_opentv_compile_pattern_list(&mod->p_enum, htsmsg_get_list(m, "episode_num"));
_opentv_compile_pattern_list(&mod->p_pnum, htsmsg_get_list(m, "part_num"));
Expand Down Expand Up @@ -996,8 +992,6 @@ void opentv_init ( void )
{
htsmsg_t *m;

RB_INIT(&_opentv_channels);

/* Load dictionaries */
if ((m = hts_settings_load("epggrab/opentv/dict")))
_opentv_dict_load(m);
Expand All @@ -1019,7 +1013,6 @@ void opentv_done ( void )
opentv_dict_t *dict;
opentv_genre_t *genre;

epggrab_channel_flush(&_opentv_channels, 0);
while ((dict = RB_FIRST(&_opentv_dicts)) != NULL) {
RB_REMOVE(&_opentv_dicts, dict, h_link);
huffman_tree_destroy(dict->codes);
Expand Down
2 changes: 1 addition & 1 deletion src/epggrab/module/psip.c
Expand Up @@ -405,7 +405,7 @@ void psip_init ( void )
.tune = _psip_tune,
};

epggrab_module_ota_create(NULL, "psip", "PSIP: ATSC Grabber", 1, &ops, NULL);
epggrab_module_ota_create(NULL, "psip", "PSIP: ATSC Grabber", 1, &ops);
}

void psip_done ( void )
Expand Down

0 comments on commit bfb24ea

Please sign in to comment.