]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add support for configuring method for commercial detection
authorAndreas Öman <andreas@lonelycoder.com>
Thu, 17 Apr 2008 21:16:33 +0000 (21:16 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Thu, 17 Apr 2008 21:16:33 +0000 (21:16 +0000)
ajaxui/ajaxui_config_channels.c
channels.c
channels.h
teletext.c
tvhead.h

index a99c3e246fb6a1ce3fba99dc0c86847ae3a26294..fca1d08b3223c5ff9b5af2fce3a0595f0af9a803 100644 (file)
@@ -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,
              "<div class=\"infoprefixwidewidefat\">"
              "Commercial detection:</div>"
              "<div>"
-             "<select id=\"cdetect_%d\" class=\"textinput\">",
+             "<select class=\"textinput\" "
+             "onChange=\"new Ajax.Request('/ajax/chsetcomdetect/%d', "
+             "{parameters: {how: this.value}});\">",
              ch->ch_tag);
-  tcp_qprintf(tq, "<option>None</option>");
-  tcp_qprintf(tq, "<option>TV4 Teletext, p192</option>");
+
+  for(i = 0; i < sizeof(cdlongname) / sizeof(cdlongname[0]); i++) {
+    tcp_qprintf(tq, "<option %svalue=%d>%s</option>",
+               cdlongname[i].val == ch->ch_commercial_detection ? 
+               "selected " : "",
+               cdlongname[i].val, cdlongname[i].str);
+  }
   tcp_qprintf(tq, "</select></div>");
   tcp_qprintf(tq, "</div>");
 
@@ -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);
 
 }
index 53a3739aff03e423b564ebf8ae02283e85c291a6..394b4ab340179a35f02d5b2425f912c9d83fd062 100644 (file)
@@ -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);
 }
 
index b8b33002d5a71e2732201737235af8f68225e788..fbc2bc73ccbe6491e6ac35b67bd940fc6ab83e1b 100644 (file)
@@ -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 */
index dec83a30ad053a18f8a6e9b5066a403c28277531..b53e5559cfd71fd87701af176ebaa53d298553b5 100644 (file)
@@ -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);
   }
 }
index fdd2af913232a338313a85c9fad194ce4b5feaed..0cebdd54930363f4f059e76bd59682dacf4981aa 100644 (file)
--- 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;