add persistent channel settings
This commit is contained in:
parent
872c1a16c9
commit
f92bfeaf8a
11 changed files with 83 additions and 41 deletions
2
avgen.c
2
avgen.c
|
@ -100,7 +100,7 @@ avgen_init(void)
|
|||
if(avcodec_find_encoder(CODEC_ID_MP2) == NULL)
|
||||
return;
|
||||
|
||||
ch = channel_find("Test 1", 1);
|
||||
ch = channel_find("Test 1", 1, NULL);
|
||||
|
||||
t = calloc(1, sizeof(th_transport_t));
|
||||
t->tht_prio = 100;
|
||||
|
|
102
channels.c
102
channels.c
|
@ -46,6 +46,8 @@ struct th_channel_group_queue all_channel_groups;
|
|||
|
||||
th_channel_group_t *defgroup;
|
||||
|
||||
static int dontwritesettings;
|
||||
|
||||
void scanner_init(void);
|
||||
|
||||
/**
|
||||
|
@ -70,6 +72,10 @@ channel_group_find(const char *name, int create)
|
|||
TAILQ_INIT(&tcg->tcg_channels);
|
||||
|
||||
TAILQ_INSERT_TAIL(&all_channel_groups, tcg, tcg_global_link);
|
||||
|
||||
if(!dontwritesettings)
|
||||
channel_settings_write();
|
||||
|
||||
return tcg;
|
||||
}
|
||||
|
||||
|
@ -87,6 +93,8 @@ channel_set_group(th_channel_t *ch, th_channel_group_t *tcg)
|
|||
|
||||
ch->ch_group = tcg;
|
||||
TAILQ_INSERT_TAIL(&tcg->tcg_channels, ch, ch_group_link);
|
||||
if(!dontwritesettings)
|
||||
channel_settings_write();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +121,7 @@ channel_group_destroy(th_channel_group_t *tcg)
|
|||
*
|
||||
*/
|
||||
th_channel_t *
|
||||
channel_find(const char *name, int create)
|
||||
channel_find(const char *name, int create, th_channel_group_t *tcg)
|
||||
{
|
||||
const char *n2;
|
||||
th_channel_t *ch;
|
||||
|
@ -151,7 +159,7 @@ channel_find(const char *name, int create)
|
|||
|
||||
LIST_INSERT_HEAD(&channels, ch, ch_global_link);
|
||||
|
||||
channel_set_group(ch, defgroup);
|
||||
channel_set_group(ch, tcg ?: defgroup);
|
||||
|
||||
ch->ch_tag = tag_get();
|
||||
nchannels++;
|
||||
|
@ -249,53 +257,53 @@ transport_link(th_transport_t *t, th_channel_t *ch)
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static void
|
||||
channel_load(struct config_head *head)
|
||||
{
|
||||
const char *name, *v;
|
||||
th_channel_t *ch;
|
||||
|
||||
if((name = config_get_str_sub(head, "name", NULL)) == NULL)
|
||||
return;
|
||||
|
||||
ch = channel_find(name, 1);
|
||||
|
||||
syslog(LOG_DEBUG, "Added channel \"%s\"", name);
|
||||
|
||||
if((v = config_get_str_sub(head, "teletext-rundown", NULL)) != NULL) {
|
||||
ch->ch_teletext_rundown = atoi(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
channels_load(void)
|
||||
{
|
||||
config_entry_t *ce;
|
||||
config_entry_t *ce, *ce1, *ce2;
|
||||
const char *name;
|
||||
th_channel_group_t *tcg;
|
||||
th_channel_t *ch;
|
||||
|
||||
dontwritesettings = 1;
|
||||
|
||||
TAILQ_INIT(&all_channel_groups);
|
||||
|
||||
defgroup = channel_group_find("Uncategorized", 1);
|
||||
defgroup->tcg_cant_delete_me = 1;
|
||||
TAILQ_FOREACH(ce1, &settings_list, ce_link) {
|
||||
if(ce1->ce_type != CFG_SUB || strcasecmp("channel-group", ce1->ce_key))
|
||||
continue;
|
||||
|
||||
if((name = config_get_str_sub(&ce1->ce_sub, "name", NULL)) == NULL)
|
||||
continue;
|
||||
|
||||
TAILQ_FOREACH(ce, &config_list, ce_link) {
|
||||
if(ce->ce_type == CFG_SUB && !strcasecmp("channel", ce->ce_key)) {
|
||||
channel_load(&ce->ce_sub);
|
||||
tcg = channel_group_find(name, 1);
|
||||
TAILQ_FOREACH(ce2, &ce1->ce_sub, ce_link) {
|
||||
if(ce2->ce_type != CFG_SUB || strcasecmp("channel", ce2->ce_key))
|
||||
continue;
|
||||
|
||||
if((name = config_get_str_sub(&ce2->ce_sub, "name", NULL)) == NULL)
|
||||
continue;
|
||||
|
||||
ch = channel_find(name, 1, tcg);
|
||||
|
||||
ch->ch_teletext_rundown =
|
||||
atoi(config_get_str_sub(&ce2->ce_sub, "teletext-rundown", "0"));
|
||||
}
|
||||
}
|
||||
|
||||
defgroup = channel_group_find("Uncategorized", 1);
|
||||
defgroup->tcg_cant_delete_me = 1;
|
||||
|
||||
TAILQ_FOREACH(ce, &config_list, ce_link) {
|
||||
if(ce->ce_type == CFG_SUB && !strcasecmp("service", ce->ce_key)) {
|
||||
service_load(&ce->ce_sub);
|
||||
}
|
||||
}
|
||||
dontwritesettings = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -347,3 +355,35 @@ channel_group_by_tag(uint32_t tag)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
channel_settings_write(void)
|
||||
{
|
||||
FILE *fp;
|
||||
th_channel_group_t *tcg;
|
||||
th_channel_t *ch;
|
||||
|
||||
if(settingsfile == NULL)
|
||||
return;
|
||||
|
||||
fp = fopen(settingsfile, "w+");
|
||||
if(fp == NULL)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH(tcg, &all_channel_groups, tcg_global_link) {
|
||||
fprintf(fp, "channel-group {\n"
|
||||
"\tname = %s\n", tcg->tcg_name);
|
||||
TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
|
||||
fprintf(fp, "\tchannel {\n"
|
||||
"\t\tname = %s\n", ch->ch_name);
|
||||
if(ch->ch_teletext_rundown)
|
||||
fprintf(fp, "\t\tteletext-rundown = %d", ch->ch_teletext_rundown);
|
||||
fprintf(fp, "\t}\n");
|
||||
}
|
||||
fprintf(fp, "}\n");
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ int channel_get_channels(void);
|
|||
|
||||
void channel_unsubscribe(th_subscription_t *s);
|
||||
|
||||
th_channel_t *channel_find(const char *name, int create);
|
||||
th_channel_t *channel_find(const char *name, int create,
|
||||
th_channel_group_t *tcg);
|
||||
|
||||
th_channel_group_t *channel_group_find(const char *name, int create);
|
||||
|
||||
|
@ -39,4 +40,5 @@ th_channel_group_t *channel_group_by_tag(uint32_t tag);
|
|||
|
||||
void channel_group_destroy(th_channel_group_t *tcg);
|
||||
|
||||
void channel_settings_write(void);
|
||||
#endif /* CHANNELS_H */
|
||||
|
|
2
dvb.c
2
dvb.c
|
@ -808,7 +808,7 @@ dvb_sdt_callback(th_dvb_mux_instance_t *tdmi, uint8_t *ptr, int len,
|
|||
/* Not yet mapped to a channel */
|
||||
if(LIST_FIRST(&t->tht_streams) != NULL) {
|
||||
/* We have streams, map it */
|
||||
transport_set_channel(t, channel_find(chname, 1));
|
||||
transport_set_channel(t, channel_find(chname, 1, NULL));
|
||||
} else {
|
||||
if(t->tht_pmt_seen == 0)
|
||||
ret |= 1; /* Return error (so scanning wont continue yet) */
|
||||
|
|
|
@ -336,7 +336,7 @@ dvb_configure_transport(th_transport_t *t, const char *muxname,
|
|||
t->tht_dvb_mux = tdm;
|
||||
t->tht_name = strdup(tdm->tdm_title);
|
||||
|
||||
transport_link(t, channel_find(channel_name, 1));
|
||||
transport_link(t, channel_find(channel_name, 1, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -350,7 +350,7 @@ xmltv_transfer(void)
|
|||
|
||||
LIST_FOREACH(xc, &xmltv_channel_list, xc_link) {
|
||||
|
||||
ch = channel_find(xc->xc_displayname, 0);
|
||||
ch = channel_find(xc->xc_displayname, 0, NULL);
|
||||
if(ch != NULL)
|
||||
xmltv_map(xc, ch);
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ iptv_configure_transport(th_transport_t *t, const char *iptv_type,
|
|||
st->st_got_section = iptv_parse_pat;
|
||||
st->st_section_docrc = 1;
|
||||
|
||||
t->tht_channel = channel_find(channel_name, 1);
|
||||
t->tht_channel = channel_find(channel_name, 1, NULL);
|
||||
LIST_INSERT_HEAD(&iptv_probing_transports, t, tht_adapter_link);
|
||||
startupcounter++;
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ output_multicast_load(struct config_head *head)
|
|||
if((name = config_get_str_sub(head, "channel", NULL)) == NULL)
|
||||
return;
|
||||
|
||||
ch = channel_find(name, 1);
|
||||
ch = channel_find(name, 1, NULL);
|
||||
|
||||
om = calloc(1, sizeof(output_multicast_t));
|
||||
|
||||
|
|
2
pvr.c
2
pvr.c
|
@ -395,7 +395,7 @@ pvr_database_load(void)
|
|||
*val++ = 0;
|
||||
|
||||
if(!strcmp(key, "channel"))
|
||||
pvrr->pvrr_channel = channel_find(val, 1);
|
||||
pvrr->pvrr_channel = channel_find(val, 1, NULL);
|
||||
|
||||
else if(!strcmp(key, "start"))
|
||||
pvrr->pvrr_start = atoi(val);
|
||||
|
|
2
rpc.c
2
rpc.c
|
@ -177,7 +177,7 @@ rpc_event_info(rpc_session_t *ses, htsmsg_t *in, void *opaque)
|
|||
if(htsmsg_get_u32(in, "tag", &u32) >= 0) {
|
||||
e = epg_event_find_by_tag(u32);
|
||||
} else if((s = htsmsg_get_str(in, "channel")) != NULL) {
|
||||
if((ch = channel_find(s, 0)) == NULL) {
|
||||
if((ch = channel_find(s, 0, NULL)) == NULL) {
|
||||
errtxt = "Channel not found";
|
||||
} else {
|
||||
if(htsmsg_get_u32(in, "time", &u32) < 0) {
|
||||
|
|
2
v4l.c
2
v4l.c
|
@ -96,7 +96,7 @@ v4l_configure_transport(th_transport_t *t, const char *muxname,
|
|||
(float)t->tht_v4l_frequency / 1000000.0f);
|
||||
t->tht_name = strdup(buf);
|
||||
|
||||
transport_link(t, channel_find(channel_name, 1));
|
||||
transport_link(t, channel_find(channel_name, 1, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue