Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: Add 'Maximum count' to autorec, fixes #3187
  • Loading branch information
perexg committed Oct 21, 2015
1 parent 001048a commit 9580e5e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/dvr/dvr.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

/**
*
*/
Expand Down
41 changes: 41 additions & 0 deletions src/dvr/dvr_autorec.c
Expand Up @@ -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'
*/
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/dvr/dvr_db.c
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/webui/static/app/dvr.js
Expand Up @@ -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 },
Expand All @@ -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: { }
},
Expand Down

0 comments on commit 9580e5e

Please sign in to comment.