]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
epg: try to handle the broken EPG input - add stop cut function, fixes #4076
authorJaroslav Kysela <perex@perex.cz>
Sat, 19 Nov 2016 17:36:02 +0000 (18:36 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sat, 19 Nov 2016 17:41:45 +0000 (18:41 +0100)
src/config.c
src/config.h
src/epg.c

index 340e97e64f315f7a8f3d0981123704f2b50faab0..1cee017c763b5e721b1ca2e049ff3e795dcf98ba 100644 (file)
@@ -1638,6 +1638,7 @@ config_boot ( const char *path, gid_t gid, uid_t uid )
   config.dscp = -1;
   config.descrambler_buffer = 9000;
   config.epg_compress = 1;
+  config.epg_cutwindow = 5*60;
   config_scanfile_ok = 0;
   config.theme_ui = strdup("blue");
 
@@ -2180,9 +2181,18 @@ const idclass_t config_class = {
       .off    = offsetof(config_t, epg_compress),
       .opts   = PO_EXPERT,
       .def.i  = 1,
-      .group  = 1
+      .group  = 2
     },
 #endif
+    {
+      .type   = PT_U32,
+      .id     = "epg_cutwindow",
+      .name   = N_("EPG overlap cut"),
+      .desc   = N_("The time window to cut the stop time from the overlapped event in seconds."),
+      .off    = offsetof(config_t, epg_cutwindow),
+      .opts   = PO_EXPERT,
+      .group  = 2
+    },
     {
       .type   = PT_STR,
       .islist = 1,
index 2e135f353a565b826db9369a7617a912c268dcba..a2a7f648e95fbccdea70db51ef5f400a6cb65e98 100644 (file)
@@ -58,6 +58,7 @@ typedef struct config {
   int caclient_ui;
   int parser_backlog;
   int epg_compress;
+  uint32_t epg_cutwindow;
 } config_t;
 
 extern const idclass_t config_class;
index 8277e9c288d3744b72cc6b84f51070a097c70384..51046f0ed38113eddc360b10b71937e86b43487e 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -26,6 +26,7 @@
 #include <time.h>
 
 #include "tvheadend.h"
+#include "config.h"
 #include "queue.h"
 #include "channels.h"
 #include "settings.h"
@@ -1695,6 +1696,17 @@ static epg_broadcast_t *_epg_channel_add_broadcast
       _epg_channel_rem_broadcast(ch, ret, NULL);
       return NULL;
     }
+    if (config.epg_cutwindow && ebc->stop - ebc->start > config.epg_cutwindow * 2 &&
+        ebc->stop - ret->start <= config.epg_cutwindow) {
+      tvhtrace(LS_EPG, "cut stop for overlap (b) event %u (%s) on %s @ %s to %s",
+               ebc->id, epg_broadcast_get_title(ebc, NULL),
+               channel_get_name(ch),
+               gmtime2local(ebc->start, tm1, sizeof(tm1)),
+               gmtime2local(ebc->stop, tm2, sizeof(tm2)));
+      ebc->stop = ret->start;
+      _epg_object_set_updated(ebc);
+      continue;
+    }
     tvhtrace(LS_EPG, "remove overlap (b) event %u (%s) on %s @ %s to %s",
              ebc->id, epg_broadcast_get_title(ebc, NULL),
              channel_get_name(ch),
@@ -1711,6 +1723,17 @@ static epg_broadcast_t *_epg_channel_add_broadcast
       _epg_channel_rem_broadcast(ch, ret, NULL);
       return NULL;
     }
+    if (config.epg_cutwindow && ret->stop - ret->start > config.epg_cutwindow * 2 &&
+        ret->stop - ebc->start <= config.epg_cutwindow) {
+      tvhtrace(LS_EPG, "cut stop for overlap (a) event %u (%s) on %s @ %s to %s",
+               ebc->id, epg_broadcast_get_title(ebc, NULL),
+               channel_get_name(ch),
+               gmtime2local(ebc->start, tm1, sizeof(tm1)),
+               gmtime2local(ebc->stop, tm2, sizeof(tm2)));
+      ret->stop = ebc->start;
+      _epg_object_set_updated(ebc);
+      continue;
+    }
     tvhtrace(LS_EPG, "remove overlap (a) event %u (%s) on %s @ %s to %s",
              ebc->id, epg_broadcast_get_title(ebc, NULL),
              channel_get_name(ch),