diff --git a/ajaxui/ajaxui_config_channels.c b/ajaxui/ajaxui_config_channels.c index a99c3e24..fca1d08b 100644 --- a/ajaxui/ajaxui_config_channels.c +++ b/ajaxui/ajaxui_config_channels.c @@ -391,6 +391,11 @@ static struct strtab sourcetypetab[] = { }; +static struct strtab cdlongname[] = { + { "None", COMMERCIAL_DETECT_NONE }, + { "Swedish TV4 Teletext", COMMERCIAL_DETECT_TTP192 }, +}; + /** * Display all channels within the group */ @@ -402,6 +407,7 @@ ajax_cheditor(http_connection_t *hc, http_reply_t *hr, th_channel_t *ch; th_transport_t *t; const char *s; + int i; if(remain == NULL || (ch = channel_by_tag(atoi(remain))) == NULL) return HTTP_STATUS_BAD_REQUEST; @@ -444,10 +450,17 @@ ajax_cheditor(http_connection_t *hc, http_reply_t *hr, "
" "Commercial detection:
" "
" - "", ch->ch_tag); - tcp_qprintf(tq, ""); - tcp_qprintf(tq, ""); + + for(i = 0; i < sizeof(cdlongname) / sizeof(cdlongname[0]); i++) { + tcp_qprintf(tq, "", + cdlongname[i].val == ch->ch_commercial_detection ? + "selected " : "", + cdlongname[i].val, cdlongname[i].str); + } tcp_qprintf(tq, "
"); tcp_qprintf(tq, ""); @@ -499,6 +512,29 @@ ajax_changegroup(http_connection_t *hc, http_reply_t *hr, return 0; } +/** + * Change commercial detection type for channel(s) + */ +static int +ajax_chsetcomdetect(http_connection_t *hc, http_reply_t *hr, + const char *remain, void *opaque) +{ + th_channel_t *ch; + const char *s; + + if(remain == NULL || (ch = channel_by_tag(atoi(remain))) == NULL) + return HTTP_STATUS_BAD_REQUEST; + + if((s = http_arg_get(&hc->hc_req_args, "how")) == NULL) + return HTTP_STATUS_BAD_REQUEST; + + ch->ch_commercial_detection = atoi(s); + + channel_settings_write(ch); + http_output(hc, hr, "text/javascript; charset=UTF-8", NULL, 0); + return 0; +} + /** * @@ -512,5 +548,6 @@ ajax_config_channels_init(void) http_path_add("/ajax/chgroup_editor", NULL, ajax_chgroup_editor); http_path_add("/ajax/cheditor", NULL, ajax_cheditor); http_path_add("/ajax/chop/changegroup", NULL, ajax_changegroup); + http_path_add("/ajax/chsetcomdetect", NULL, ajax_chsetcomdetect); } diff --git a/channels.c b/channels.c index 53a3739a..394b4ab3 100644 --- a/channels.c +++ b/channels.c @@ -39,8 +39,6 @@ #include "channels.h" #include "transports.h" -static void channel_settings_write(th_channel_t *ch); - struct th_channel_list channels; int nchannels; @@ -135,15 +133,6 @@ channel_set_group(th_channel_t *ch, th_channel_group_t *tcg) channel_settings_write(ch); } -/** - * - */ -void -channel_set_teletext_rundown(th_channel_t *ch, int v) -{ - ch->ch_teletext_rundown = v; - channel_settings_write(ch); -} /** * @@ -246,6 +235,13 @@ service_load(struct config_head *head) free(t); } + +static struct strtab commercial_detect_tab[] = { + { "none", COMMERCIAL_DETECT_NONE }, + { "ttp192", COMMERCIAL_DETECT_TTP192 }, +}; + + /** * */ @@ -257,9 +253,10 @@ channels_load(void) char buf[PATH_MAX]; DIR *dir; struct dirent *d; - const char *name, *grp; + const char *name, *grp, *x; th_channel_t *ch; th_channel_group_t *tcg; + int v; TAILQ_INIT(&all_channel_groups); TAILQ_INIT(&cl); @@ -304,11 +301,14 @@ channels_load(void) if(name != NULL && grp != NULL) { tcg = channel_group_find(grp, 1); ch = channel_find(name, 1, tcg); - - ch->ch_teletext_rundown = - atoi(config_get_str_sub(&cl, "teletext-rundown", "0")); + + x = config_get_str_sub(&cl, "commercial-detect", NULL); + if(x != NULL) { + v = str2val(x, commercial_detect_tab); + if(v > 1) + ch->ch_commercial_detection = v; + } } - config_free0(&cl); } @@ -409,7 +409,7 @@ channel_group_settings_write(void) /** * Write out a config file for a channel */ -static void +void channel_settings_write(th_channel_t *ch) { FILE *fp; @@ -421,8 +421,9 @@ channel_settings_write(th_channel_t *ch) fprintf(fp, "name = %s\n", ch->ch_name); fprintf(fp, "channel-group = %s\n", ch->ch_group->tcg_name); - if(ch->ch_teletext_rundown) - fprintf(fp, "teletext-rundown = %d\n", ch->ch_teletext_rundown); + + fprintf(fp, "commercial-detect = %s\n", + val2str(ch->ch_commercial_detection, commercial_detect_tab) ?: "?"); fclose(fp); } diff --git a/channels.h b/channels.h index b8b33002..fbc2bc73 100644 --- a/channels.h +++ b/channels.h @@ -46,4 +46,6 @@ void channel_set_teletext_rundown(th_channel_t *ch, int v); void channel_group_settings_write(void); +void channel_settings_write(th_channel_t *ch); + #endif /* CHANNELS_H */ diff --git a/teletext.c b/teletext.c index dec83a30..b53e5559 100644 --- a/teletext.c +++ b/teletext.c @@ -223,8 +223,8 @@ tt_decode_line(th_transport_t *t, uint8_t *buf) } if(update_tt_clock(t, (char *)buf + 34)) { - if(ch->ch_teletext_rundown != 0) { - ttp = tt_get_page(ttd, ch->ch_teletext_rundown); + if(ch->ch_commercial_detection == COMMERCIAL_DETECT_TTP192) { + ttp = tt_get_page(ttd, 192); teletext_rundown(t, ch, ttp); } } @@ -255,7 +255,8 @@ tt_decode_line(th_transport_t *t, uint8_t *buf) break; } - if(ttp->ttp_page == ch->ch_teletext_rundown) + if(ttp->ttp_page == 192 && + ch->ch_commercial_detection == COMMERCIAL_DETECT_TTP192) teletext_rundown(t, ch, ttp); } } diff --git a/tvhead.h b/tvhead.h index fdd2af91..0cebdd54 100644 --- a/tvhead.h +++ b/tvhead.h @@ -769,7 +769,10 @@ typedef struct th_channel { int ch_tag; - int ch_teletext_rundown; + enum { + COMMERCIAL_DETECT_NONE, + COMMERCIAL_DETECT_TTP192, + } ch_commercial_detection; struct event_queue ch_epg_events; struct event *ch_epg_cur_event;