From e2bd233a4fa2c2c3269f07a382070f4d44a86656 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 25 Dec 2014 21:43:49 +0100 Subject: [PATCH] DVR autorec: change start_window meaning to start up to --- docs/html/dvr_autorec.html | 14 +++++------ src/config.c | 10 +++++--- src/dvr/dvr_autorec.c | 50 +++++++++++++++++++++++++++----------- src/htsp_server.c | 17 ++++++++++--- 4 files changed, 63 insertions(+), 28 deletions(-) diff --git a/docs/html/dvr_autorec.html b/docs/html/dvr_autorec.html index e951bf1a..cdd1a81e 100644 --- a/docs/html/dvr_autorec.html +++ b/docs/html/dvr_autorec.html @@ -79,15 +79,13 @@ The maximal duration of a matching event - in other words, only match programmes
On which specific days of the week to find matching programmes.

-

Starting Around +
Start Time
-An approximate starting time for matching programmes. -
-
-I'd need to check the code to see how this works to expand on this any further. It used to be: -
-
-Only record events if they are scheduled +-15 minutes from this given time. +An event which starts between this "start time" and "start time up to" will be matched (including). +

+

Start Up To +
+The start up to limit.

Priority
diff --git a/src/config.c b/src/config.c index a6adf39e..4bb65fd4 100644 --- a/src/config.c +++ b/src/config.c @@ -1128,16 +1128,20 @@ config_dvr_autorec_start_set(const char *s, int *tm) static void config_modify_dvrauto( htsmsg_t *c ) { - int tm = -1; + int tm = -1, tw = -1; char buf[16]; if (config_dvr_autorec_start_set(htsmsg_get_str(c, "start"), &tm) > 0 && tm >= 0) { tm -= 15; if (tm < 0) tm += 24 * 60; + tw = tm + 30; + if (tw >= 24 * 60) + tw -= 24 * 60; snprintf(buf, sizeof(buf), "%02d:%02d", tm / 60, tm % 60); - htsmsg_set_str(c, "start", tm <= 0 ? "Any" : buf); - htsmsg_set_u32(c, "start_window", 30); + htsmsg_set_str(c, "start", buf); + snprintf(buf, sizeof(buf), "%02d:%02d", tw / 60, tw % 60); + htsmsg_set_str(c, "start_window", buf); } else { htsmsg_delete_field(c, "start"); } diff --git a/src/dvr/dvr_autorec.c b/src/dvr/dvr_autorec.c index bb48c345..1ff6477a 100644 --- a/src/dvr/dvr_autorec.c +++ b/src/dvr/dvr_autorec.c @@ -126,17 +126,29 @@ autorec_cmp(dvr_autorec_entry_t *dae, epg_broadcast_t *e) return 0; } - if(dae->dae_start >= 0 && dae->dae_start_window >= 0) { + if(dae->dae_start >= 0 && dae->dae_start_window >= 0 && + dae->dae_start < 24*60 && dae->dae_start_window < 24*60) { struct tm a_time, ev_time; - time_t ta, te; + time_t ta, te, tad; localtime_r(&e->start, &a_time); ev_time = a_time; a_time.tm_min = dae->dae_start % 60; a_time.tm_hour = dae->dae_start / 60; ta = mktime(&a_time); te = mktime(&ev_time); - if(ta > te || te > ta + dae->dae_start_window * 60) - return 0; + if(dae->dae_start > dae->dae_start_window) { + ta -= 24 * 3600; /* 24 hours */ + tad = ((24 * 60) - dae->dae_start + dae->dae_start_window) * 60; + if(ta > te || te > ta + tad) { + ta += 24 * 3600; + if(ta > te || te > ta + tad) + return 0; + } + } else { + tad = (dae->dae_start_window - dae->dae_start) * 60; + if(ta > te || te > ta + tad) + return 0; + } } duration = difftime(e->stop,e->start); @@ -499,6 +511,13 @@ dvr_autorec_entry_class_start_set(void *o, const void *v) return dvr_autorec_entry_class_time_set(o, v, &dae->dae_start); } +static int +dvr_autorec_entry_class_start_window_set(void *o, const void *v) +{ + dvr_autorec_entry_t *dae = (dvr_autorec_entry_t *)o; + return dvr_autorec_entry_class_time_set(o, v, &dae->dae_start_window); +} + static const void * dvr_autorec_entry_class_time_get(void *o, int tm) { @@ -519,6 +538,13 @@ dvr_autorec_entry_class_start_get(void *o) return dvr_autorec_entry_class_time_get(o, dae->dae_start); } +static const void * +dvr_autorec_entry_class_start_window_get(void *o) +{ + dvr_autorec_entry_t *dae = (dvr_autorec_entry_t *)o; + return dvr_autorec_entry_class_time_get(o, dae->dae_start_window); +} + htsmsg_t * dvr_autorec_entry_class_time_list(void *o, const char *null) { @@ -539,12 +565,6 @@ dvr_autorec_entry_class_time_list_(void *o) return dvr_autorec_entry_class_time_list(o, "Any"); } -static htsmsg_t * -dvr_autorec_entry_class_time_window_list(void *o) -{ - return dvr_entry_class_duration_list(o, "Exact", 24*60, 1); -} - static htsmsg_t * dvr_autorec_entry_class_extra_list(void *o) { @@ -863,11 +883,13 @@ const idclass_t dvr_autorec_entry_class = { .opts = PO_SORTKEY }, { - .type = PT_INT, + .type = PT_STR, .id = "start_window", - .name = "Start Window", - .list = dvr_autorec_entry_class_time_window_list, - .off = offsetof(dvr_autorec_entry_t, dae_start_window), + .name = "Start Up To", + .set = dvr_autorec_entry_class_start_window_set, + .get = dvr_autorec_entry_class_start_window_get, + .list = dvr_autorec_entry_class_time_list_, + .opts = PO_SORTKEY, }, { .type = PT_TIME, diff --git a/src/htsp_server.c b/src/htsp_server.c index 98408c10..c46d640f 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -732,6 +732,7 @@ static htsmsg_t * htsp_build_autorecentry(dvr_autorec_entry_t *dae, const char *method) { htsmsg_t *out = htsmsg_create_map(); + int tad; htsmsg_add_str(out, "id", idnode_uuid_as_str(&dae->dae_id)); htsmsg_add_u32(out, "enabled", dae->dae_enabled); @@ -739,9 +740,17 @@ htsp_build_autorecentry(dvr_autorec_entry_t *dae, const char *method) htsmsg_add_u32(out, "minDuration", dae->dae_minduration); htsmsg_add_u32(out, "retention", dae->dae_retention); htsmsg_add_u32(out, "daysOfWeek", dae->dae_weekdays); + if (dae->dae_start >= 0 && dae->dae_start_window >= 0) { + if (dae->dae_start > dae->dae_start_window) + tad = 24 * 60 - dae->dae_start + dae->dae_start_window; + else + tad = dae->dae_start_window - dae->dae_start; + } else { + tad = -1; + } htsmsg_add_s32(out, "approxTime", - dae->dae_start_window == 30 && dae->dae_start >= 0 ? - dae->dae_start + 15 : -1); + dae->dae_start >= 0 && tad >= 0 ? + ((dae->dae_start + tad / 2) % (24 * 60)) : -1); htsmsg_add_u32(out, "start", dae->dae_start); htsmsg_add_u32(out, "startWindow", dae->dae_start_window); htsmsg_add_u32(out, "priority", dae->dae_pri); @@ -1563,7 +1572,9 @@ htsp_method_addAutorecEntry(htsp_connection_t *htsp, htsmsg_t *in) start = approx_time - 15; if (start < 0) start += 24 * 60; - start_window = 60; + start_window = start + 30; + if (start_window >= 24 * 60) + start_window -= 24 * 60; } if(htsmsg_get_s64(in, "startExtra", &start_extra)) start_extra = 0; // 0 = dvr config