From: Chris Date: Wed, 28 Sep 2011 10:30:14 +0000 (+1000) Subject: Much simpler and improved algorithm for detecting overlapping events. X-Git-Tag: 2.99~28^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F43%2Fhead;p=thirdparty%2Ftvheadend.git Much simpler and improved algorithm for detecting overlapping events. This version also solves a problem where the DVR database gets corrupted when autorecs exist for two sequential events. --- diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c index 248051705..5f57e0092 100644 --- a/src/dvr/dvr_db.c +++ b/src/dvr/dvr_db.c @@ -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; } diff --git a/src/epg.c b/src/epg.c index e15d7003e..c43248a6a 100644 --- 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;