Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: add max count/max sched count to DVR config
  • Loading branch information
perexg committed Nov 22, 2015
1 parent e06589a commit 911c7b1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/dvr/dvr.h
Expand Up @@ -43,6 +43,8 @@ typedef struct dvr_config {
uint32_t dvr_rerecord_errors;
uint32_t dvr_retention_days;
uint32_t dvr_removal_days;
uint32_t dvr_autorec_max_count;
uint32_t dvr_autorec_max_sched_count;
char *dvr_charset;
char *dvr_charset_id;
char *dvr_postproc;
Expand Down Expand Up @@ -634,6 +636,8 @@ int dvr_autorec_get_extra_time_pre( dvr_autorec_entry_t *dae );

void dvr_autorec_completed( dvr_entry_t *de, int error_code );

uint32_t dvr_autorec_get_max_sched_count(dvr_autorec_entry_t *dae);

/**
*
*/
Expand Down
33 changes: 28 additions & 5 deletions src/dvr/dvr_autorec.c
Expand Up @@ -36,6 +36,28 @@

struct dvr_autorec_entry_queue autorec_entries;

/*
*
*/
static uint32_t dvr_autorec_get_max_count(dvr_autorec_entry_t *dae)
{
uint32_t max_count = dae->dae_max_count;
if (max_count == 0)
max_count = dae->dae_config ? dae->dae_config->dvr_autorec_max_count : 0;
return max_count;
}

/*
*
*/
uint32_t dvr_autorec_get_max_sched_count(dvr_autorec_entry_t *dae)
{
uint32_t max_count = dae->dae_max_sched_count;
if (max_count == 0)
max_count = dae->dae_config ? dae->dae_config->dvr_autorec_max_sched_count : 0;
return max_count;
}

/**
* Unlink - and remove any unstarted
*/
Expand Down Expand Up @@ -81,9 +103,10 @@ 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;
uint32_t max_count = dvr_autorec_get_max_count(dae);

if (dae == NULL) return;
if (dae->dae_max_count <= 0) return;
if (max_count <= 0) return;
while (1) {
count = 0;
de_prev = NULL;
Expand All @@ -96,11 +119,11 @@ dvr_autorec_completed(dvr_entry_t *de, int error_code)
}
if (total == 0)
total = count;
if (count < dae->dae_max_count)
if (count < 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);
dae->dae_name, idnode_uuid_as_sstr(&de_prev->de_id), max_count, total);
dvr_entry_cancel_delete(de_prev, 0);
}
}
Expand Down Expand Up @@ -1077,14 +1100,14 @@ const idclass_t dvr_autorec_entry_class = {
{
.type = PT_U32,
.id = "maxcount",
.name = N_("Maximum count (0=unlimited)"),
.name = N_("Maximum count (0=default)"),
.off = offsetof(dvr_autorec_entry_t, dae_max_count),
.opts = PO_HIDDEN,
},
{
.type = PT_U32,
.id = "maxsched",
.name = N_("Maximum schedules limit (0=unlimited)"),
.name = N_("Maximum schedules limit (0=default)"),
.off = offsetof(dvr_autorec_entry_t, dae_max_sched_count),
.opts = PO_HIDDEN,
},
Expand Down
14 changes: 14 additions & 0 deletions src/dvr/dvr_config.c
Expand Up @@ -870,6 +870,20 @@ const idclass_t dvr_config_class = {
.def.u32 = 1,
.group = 1,
},
{
.type = PT_U32,
.id = "autorec-maxcount",
.name = N_("Autorec maximum count (0=unlimited)"),
.off = offsetof(dvr_config_t, dvr_autorec_max_count),
.group = 1,
},
{
.type = PT_U32,
.id = "autorec-maxsched",
.name = N_("Autorec maximum schedules limit (0=unlimited)"),
.off = offsetof(dvr_config_t, dvr_autorec_max_sched_count),
.group = 1,
},
{
.type = PT_STR,
.id = "postproc",
Expand Down
10 changes: 5 additions & 5 deletions src/dvr/dvr_db.c
Expand Up @@ -387,7 +387,7 @@ dvr_entry_missed_time(dvr_entry_t *de, int error_code)
dvr_entry_retention_timer(de);

// Trigger autorec update in case of max schedules limit
if (dae && dae->dae_max_sched_count > 0)
if (dae && dvr_autorec_get_max_sched_count(dae) > 0)
dvr_autorec_changed(dae, 0);
}

Expand Down Expand Up @@ -1097,7 +1097,7 @@ dvr_entry_create_by_autorec(int enabled, epg_broadcast_t *e, dvr_autorec_entry_t
char buf[512];
char ubuf[UUID_HEX_SIZE];
dvr_entry_t *de;
uint32_t count = 0;
uint32_t count = 0, max_count;

/* Identical duplicate detection
NOTE: Semantic duplicate detection is deferred to the start time of recording and then done using _dvr_duplicate_event by dvr_timer_start_recording. */
Expand All @@ -1107,13 +1107,13 @@ dvr_entry_create_by_autorec(int enabled, epg_broadcast_t *e, dvr_autorec_entry_t
}

/* Handle max schedules limit for autorrecord */
if (dae->dae_max_sched_count > 0){
if ((max_count = dvr_autorec_get_max_sched_count(dae)) > 0){
count = 0;
LIST_FOREACH(de, &dae->dae_spawns, de_autorec_link)
if ((de->de_sched_state == DVR_SCHEDULED) ||
(de->de_sched_state == DVR_RECORDING)) count++;

if (count >= dae->dae_max_sched_count) {
if (count >= max_count) {
tvhlog(LOG_DEBUG, "dvr", "Autorecord \"%s\": Not scheduling \"%s\" because of autorecord max schedules limit reached",
dae->dae_name, lang_str_get(e->episode->title, NULL));
return;
Expand Down Expand Up @@ -1726,7 +1726,7 @@ dvr_stop_recording(dvr_entry_t *de, int stopcode, int saveconf, int clone)
dvr_entry_retention_timer(de);

// Trigger autorecord update in case of schedules limit
if (dae && dae->dae_max_sched_count > 0)
if (dae && dvr_autorec_get_max_sched_count(dae) > 0)
dvr_autorec_changed(de->de_autorec, 0);
}

Expand Down

0 comments on commit 911c7b1

Please sign in to comment.