]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Much simpler and improved algorithm for detecting overlapping events. 43/head
authorChris <thaelim@gmail.com>
Wed, 28 Sep 2011 10:30:14 +0000 (20:30 +1000)
committerChris <thaelim@gmail.com>
Wed, 28 Sep 2011 10:30:14 +0000 (20:30 +1000)
This version also solves a problem where the DVR database gets
corrupted when autorecs exist for two sequential events.

src/dvr/dvr_db.c
src/epg.c

index 2480517057a2d127075b44e097293032d3cb9f20..5f57e0092f811d0f4d7e4b725b6d6d140d4286d4 100644 (file)
@@ -747,10 +747,14 @@ dvr_entry_t *
 dvr_entry_find_by_event_fuzzy(event_t *e)
 {
   dvr_entry_t *de;
+  
+  if (e->e_title == NULL)
+    return NULL;
 
   LIST_FOREACH(de, &e->e_channel->ch_dvrs, de_channel_link)
-    if (abs(de->de_start - e->e_start) < 600 && abs(de->de_stop - e->e_stop) < 600)
-      return de;
+    if ((abs(de->de_start - e->e_start) < 600) && (abs(de->de_stop - e->e_stop) < 600)) {
+        return de;
+    }
   return NULL;
 }
 
index e15d7003ea4d3ce28e348f534ade41510d19fc5a..c43248a6ad142e664ab133d28eaba681d4e70576 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -458,16 +458,18 @@ epg_erase_duplicates(event_t *e, channel_t *ch) {
 static int
 epg_event_cmp_overlap(event_t *e1, event_t *e2)
 {
+
+  int dur_a, dur_b, mindur;
+    
   if ((e1->e_title == NULL) || (e2->e_title == NULL))
     return 0;
-  
-  if ((e1->e_stop < e2->e_start) || (e2->e_stop < e1->e_start)) {
-    return 0;
-  } else {
-    if ((e1->e_start < e2->e_stop) && (e2->e_start < e1->e_stop)) {
-    if ((e1->e_stop - e2->e_start) > 60 || (e2->e_stop - e1->e_start) > 60)
-        return 1;
-    }
+    
+  dur_a = e1->e_stop - e1->e_start;
+  dur_b = e2->e_stop - e2->e_start;
+  mindur = dur_a < dur_b ? dur_a : dur_b;
+    
+  if ((abs(e1->e_start - e2->e_start) < mindur) && (abs(e1->e_stop - e2->e_stop) < mindur)) {
+    return 1;
   }
 
   return 0;