Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: Implement max schedules limit for autorrecordings
  • Loading branch information
traxxxto authored and perexg committed Oct 26, 2015
1 parent 322fbb2 commit a83f07d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/dvr/dvr.h
Expand Up @@ -307,6 +307,7 @@ typedef struct dvr_autorec_entry {
uint32_t dae_retention;
uint32_t dae_removal;
uint32_t dae_max_count;
uint32_t dae_max_sched_count;

time_t dae_start_extra;
time_t dae_stop_extra;
Expand Down
7 changes: 7 additions & 0 deletions src/dvr/dvr_autorec.c
Expand Up @@ -1112,6 +1112,13 @@ const idclass_t dvr_autorec_entry_class = {
.off = offsetof(dvr_autorec_entry_t, dae_max_count),
.opts = PO_HIDDEN,
},
{
.type = PT_U32,
.id = "maxsched",
.name = N_("Maximum schedules limit (0=unlimited)"),
.off = offsetof(dvr_autorec_entry_t, dae_max_sched_count),
.opts = PO_HIDDEN,
},
{
.type = PT_STR,
.id = "config_name",
Expand Down
34 changes: 33 additions & 1 deletion src/dvr/dvr_db.c
Expand Up @@ -370,8 +370,14 @@ dvr_entry_nostate(dvr_entry_t *de, int error_code)
static void
dvr_entry_missed_time(dvr_entry_t *de, int error_code)
{
dvr_autorec_entry_t *dae = de->de_autorec;

dvr_entry_set_state(de, DVR_MISSED_TIME, DVR_RS_PENDING, error_code);
dvr_entry_retention_timer(de);

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

/*
Expand Down Expand Up @@ -1064,15 +1070,30 @@ 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;

/* 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. */
dvr_entry_t* de;
LIST_FOREACH(de, &dvrentries, de_global_link) {
if (de->de_bcast == e || (de->de_bcast && de->de_bcast->episode == e->episode))
return;
}

/* Handle max schedules limit for autorrecord */
if (dae->dae_max_sched_count > 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) {
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;
}
}

snprintf(buf, sizeof(buf), _("Auto recording%s%s"),
dae->dae_comment ? ": " : "",
dae->dae_comment ?: "");
Expand Down Expand Up @@ -1499,6 +1520,7 @@ void
dvr_stop_recording(dvr_entry_t *de, int stopcode, int saveconf, int clone)
{
dvr_rs_state_t rec_state = de->de_rec_state;
dvr_autorec_entry_t *dae = de->de_autorec;

if (!clone)
dvr_rec_unsubscribe(de);
Expand All @@ -1523,6 +1545,10 @@ dvr_stop_recording(dvr_entry_t *de, int stopcode, int saveconf, int clone)
dvr_entry_save(de);

dvr_entry_retention_timer(de);

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


Expand Down Expand Up @@ -2962,6 +2988,7 @@ void
dvr_entry_cancel_delete(dvr_entry_t *de, int rerecord)
{
dvr_entry_t *parent = de->de_parent;
dvr_autorec_entry_t *dae = de->de_autorec;

switch(de->de_sched_state) {
case DVR_RECORDING:
Expand All @@ -2988,6 +3015,11 @@ dvr_entry_cancel_delete(dvr_entry_t *de, int rerecord)
else
dvr_entry_rerecord(parent);
}

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

}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/webui/static/app/dvr.js
Expand Up @@ -513,6 +513,7 @@ tvheadend.autorec_editor = function(panel, index) {
retention: { width: 80 },
removal: { width: 80 },
maxcount: { width: 80 },
maxsched: { width: 80 },
config_name: { width: 120 },
owner: { width: 100 },
creator: { width: 200 },
Expand All @@ -523,7 +524,7 @@ tvheadend.autorec_editor = function(panel, index) {
params: {
list: 'enabled,name,directory,title,fulltext,channel,tag,content_type,minduration,' +
'maxduration,weekdays,start,start_window,pri,dedup,retention,removal,' +
'maxcount,config_name,comment'
'maxcount,maxsched,config_name,comment'
},
create: { }
},
Expand Down

0 comments on commit a83f07d

Please sign in to comment.