From f92bfeaf8aca4ba2883b33bfe2800b2bdcc04a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Sun, 2 Dec 2007 17:06:51 +0000 Subject: [PATCH] add persistent channel settings --- avgen.c | 2 +- channels.c | 102 +++++++++++++++++++++++++++++++++--------------- channels.h | 4 +- dvb.c | 2 +- dvb_muxconfig.c | 2 +- epg_xmltv.c | 2 +- iptv_input.c | 2 +- iptv_output.c | 2 +- pvr.c | 2 +- rpc.c | 2 +- v4l.c | 2 +- 11 files changed, 83 insertions(+), 41 deletions(-) diff --git a/avgen.c b/avgen.c index b64df320..0fb7ae49 100644 --- a/avgen.c +++ b/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; diff --git a/channels.c b/channels.c index 29f228cf..3468abbe 100644 --- a/channels.c +++ b/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); +} diff --git a/channels.h b/channels.h index 97243e7e..1fba6a71 100644 --- a/channels.h +++ b/channels.h @@ -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 */ diff --git a/dvb.c b/dvb.c index 0b1e276e..6dfe9afa 100644 --- a/dvb.c +++ b/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) */ diff --git a/dvb_muxconfig.c b/dvb_muxconfig.c index 8baa9363..db37ac70 100644 --- a/dvb_muxconfig.c +++ b/dvb_muxconfig.c @@ -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; } diff --git a/epg_xmltv.c b/epg_xmltv.c index c97faadb..d03d27ab 100644 --- a/epg_xmltv.c +++ b/epg_xmltv.c @@ -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); diff --git a/iptv_input.c b/iptv_input.c index 6056b657..683e775f 100644 --- a/iptv_input.c +++ b/iptv_input.c @@ -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++; diff --git a/iptv_output.c b/iptv_output.c index be8a450f..951f902e 100644 --- a/iptv_output.c +++ b/iptv_output.c @@ -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)); diff --git a/pvr.c b/pvr.c index 854d338e..39359c99 100644 --- a/pvr.c +++ b/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); diff --git a/rpc.c b/rpc.c index d6f8c05f..539ee2db 100644 --- a/rpc.c +++ b/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) { diff --git a/v4l.c b/v4l.c index d7bd2676..00ceb804 100644 --- a/v4l.c +++ b/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; }