From: Jaroslav Kysela Date: Wed, 21 Oct 2015 12:21:55 +0000 (+0200) Subject: DVR: Add 'Maximum count' to autorec, fixes #3187 X-Git-Tag: v4.2.1~1848 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9580e5e761d45cd6bf8f9e8a67ccfe28e82924fa;p=thirdparty%2Ftvheadend.git DVR: Add 'Maximum count' to autorec, fixes #3187 --- diff --git a/src/dvr/dvr.h b/src/dvr/dvr.h index f04247178..966b0be1b 100644 --- a/src/dvr/dvr.h +++ b/src/dvr/dvr.h @@ -298,6 +298,7 @@ typedef struct dvr_autorec_entry { int dae_maxduration; uint32_t dae_retention; uint32_t dae_removal; + uint32_t dae_max_count; time_t dae_start_extra; time_t dae_stop_extra; @@ -608,6 +609,8 @@ int dvr_autorec_get_extra_time_post( dvr_autorec_entry_t *dae ); int dvr_autorec_get_extra_time_pre( dvr_autorec_entry_t *dae ); +void dvr_autorec_completed( dvr_entry_t *de, int error_code ); + /** * */ diff --git a/src/dvr/dvr_autorec.c b/src/dvr/dvr_autorec.c index ae69d6b71..390eb6236 100644 --- a/src/dvr/dvr_autorec.c +++ b/src/dvr/dvr_autorec.c @@ -72,6 +72,40 @@ dvr_autorec_purge_spawns(dvr_autorec_entry_t *dae, int del, int disabled) return bcast; } +/** + * Handle maxcount + */ +void +dvr_autorec_completed(dvr_entry_t *de, int error_code) +{ + uint32_t count, total = 0; + dvr_entry_t *de_prev; + dvr_autorec_entry_t *dae = de->de_autorec; + + if (dae == NULL) return; + if (dae->dae_max_count <= 0) return; + while (1) { + count = 0; + de_prev = NULL; + LIST_FOREACH(de, &dae->dae_spawns, de_autorec_link) { + if (de->de_sched_state != DVR_COMPLETED) continue; + if (dvr_get_filesize(de) < 0) continue; + if (de_prev && de_prev->de_start > de->de_start) + de_prev = de; + count++; + } + if (total == 0) + total = count; + if (count < dae->dae_max_count) + break; + if (de_prev) { + tvhinfo("dvr", "autorec %s removing recordings %s (allowed count %u total %u)", + dae->dae_name, idnode_uuid_as_sstr(&de_prev->de_id), dae->dae_max_count, total); + dvr_entry_cancel_delete(de_prev); + } + } +} + /** * return 1 if the event 'e' is matched by the autorec rule 'dae' */ @@ -1071,6 +1105,13 @@ const idclass_t dvr_autorec_entry_class = { .off = offsetof(dvr_autorec_entry_t, dae_removal), .opts = PO_HIDDEN, }, + { + .type = PT_U32, + .id = "maxcount", + .name = N_("Maximum count (0=unlimited)"), + .off = offsetof(dvr_autorec_entry_t, dae_max_count), + .opts = PO_HIDDEN, + }, { .type = PT_STR, .id = "config_name", diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c index 0c8465c81..a3647bd97 100644 --- a/src/dvr/dvr_db.c +++ b/src/dvr/dvr_db.c @@ -289,6 +289,8 @@ dvr_entry_completed(dvr_entry_t *de, int error_code) dvr_inotify_add(de); #endif dvr_entry_retention_timer(de); + if (de->de_autorec) + dvr_autorec_completed(de, error_code); } /** diff --git a/src/webui/static/app/dvr.js b/src/webui/static/app/dvr.js index 359bda64f..3bc976758 100644 --- a/src/webui/static/app/dvr.js +++ b/src/webui/static/app/dvr.js @@ -512,6 +512,7 @@ tvheadend.autorec_editor = function(panel, index) { dedup: { width: 160 }, retention: { width: 80 }, removal: { width: 80 }, + maxcount: { width: 80 }, config_name: { width: 120 }, owner: { width: 100 }, creator: { width: 200 }, @@ -521,7 +522,8 @@ tvheadend.autorec_editor = function(panel, index) { url: 'api/dvr/autorec', params: { list: 'enabled,name,directory,title,fulltext,channel,tag,content_type,minduration,' + - 'maxduration,weekdays,start,start_window,pri,dedup,config_name,comment' + 'maxduration,weekdays,start,start_window,pri,dedup,retention,removal,' + + 'maxcount,config_name,comment' }, create: { } },