Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: implement enabled flag for DVR entry, fixes #3104
  • Loading branch information
perexg committed Sep 25, 2015
1 parent ca33fbf commit fa57953
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/api/api_dvr.c
Expand Up @@ -212,7 +212,7 @@ api_dvr_entry_create_by_event
htsmsg_t *entries, *entries2 = NULL, *m;
htsmsg_field_t *f;
const char *s;
int count = 0;
int count = 0, enabled;
char ubuf[UUID_HEX_SIZE];

if (!(entries = htsmsg_get_list(args, "entries"))) {
Expand All @@ -227,14 +227,16 @@ api_dvr_entry_create_by_event
if (!(s = htsmsg_get_str(m, "event_id")))
continue;

enabled = htsmsg_get_u32_or_default(m, "enabled", 1);
config_uuid = htsmsg_get_str(m, "config_uuid");
comment = htsmsg_get_str(m, "comment");

pthread_mutex_lock(&global_lock);
if ((e = epg_broadcast_find_by_id(strtoll(s, NULL, 10)))) {
dvr_config_t *cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, config_uuid);
if (cfg) {
de = dvr_entry_create_by_event(idnode_uuid_as_str(&cfg->dvr_id, ubuf),
de = dvr_entry_create_by_event(enabled,
idnode_uuid_as_str(&cfg->dvr_id, ubuf),
e, 0, 0,
perm->aa_username,
perm->aa_representative,
Expand Down
11 changes: 7 additions & 4 deletions src/dvr/dvr.h
Expand Up @@ -139,6 +139,8 @@ typedef struct dvr_entry {
dvr_config_t *de_config;
LIST_ENTRY(dvr_entry) de_config_link;

int de_enabled;

time_t de_start;
time_t de_stop;

Expand Down Expand Up @@ -426,7 +428,8 @@ dvr_entry_create ( const char *uuid, htsmsg_t *conf );


dvr_entry_t *
dvr_entry_create_by_event( const char *dvr_config_uuid,
dvr_entry_create_by_event( int enabled,
const char *dvr_config_uuid,
epg_broadcast_t *e,
time_t start_extra, time_t stop_extra,
const char *owner, const char *creator,
Expand All @@ -435,7 +438,7 @@ dvr_entry_create_by_event( const char *dvr_config_uuid,
const char *comment );

dvr_entry_t *
dvr_entry_create_htsp( const char *dvr_config_uuid,
dvr_entry_create_htsp( int enabled, const char *dvr_config_uuid,
channel_t *ch, time_t start, time_t stop,
time_t start_extra, time_t stop_extra,
const char *title, const char *subtitle,
Expand All @@ -447,7 +450,7 @@ dvr_entry_create_htsp( const char *dvr_config_uuid,
const char *comment );

dvr_entry_t *
dvr_entry_update( dvr_entry_t *de, channel_t *ch,
dvr_entry_update( dvr_entry_t *de, int enabled, channel_t *ch,
const char *title, const char *subtitle,
const char *desc, const char *lang,
time_t start, time_t stop,
Expand Down Expand Up @@ -510,7 +513,7 @@ dvr_autorec_entry_t *
dvr_autorec_create(const char *uuid, htsmsg_t *conf);

dvr_entry_t *
dvr_entry_create_(const char *config_uuid, epg_broadcast_t *e,
dvr_entry_create_(int enabled, const char *config_uuid, epg_broadcast_t *e,
channel_t *ch, time_t start, time_t stop,
time_t start_extra, time_t stop_extra,
const char *title, const char* subtitle, const char *description,
Expand Down
57 changes: 40 additions & 17 deletions src/dvr/dvr_db.c
Expand Up @@ -380,7 +380,11 @@ dvr_entry_set_timer(dvr_entry_t *de)
start = dvr_entry_get_start_time(de);
stop = dvr_entry_get_stop_time(de);

if(now >= stop || de->de_dont_reschedule) {
if(!de->de_enabled) {

dvr_entry_completed(de, de->de_last_error);

This comment has been minimized.

Copy link
@ksooo

ksooo Sep 26, 2015

Contributor

IMO, this leaves to a "failed recording" with error "file missing", because of https://github.com/tvheadend/tvheadend/blob/master/src/htsp_server.c#L784

At least, this happens to me after disabling an enabled upcoming recording in the web ui.


} else if(now >= stop || de->de_dont_reschedule) {

if(htsmsg_is_empty(de->de_files))
dvr_entry_missed_time(de, de->de_last_error);
Expand Down Expand Up @@ -496,6 +500,7 @@ dvr_entry_create(const char *uuid, htsmsg_t *conf)
return NULL;
}

de->de_enabled = 1;
de->de_mc = -1;
de->de_config = dvr_config_find_by_name_default(NULL);
if (de->de_config)
Expand Down Expand Up @@ -541,7 +546,7 @@ dvr_entry_create(const char *uuid, htsmsg_t *conf)
* Create the event
*/
dvr_entry_t *
dvr_entry_create_(const char *config_uuid, epg_broadcast_t *e,
dvr_entry_create_(int enabled, const char *config_uuid, epg_broadcast_t *e,
channel_t *ch, time_t start, time_t stop,
time_t start_extra, time_t stop_extra,
const char *title, const char* subtitle, const char *description,
Expand All @@ -560,6 +565,8 @@ dvr_entry_create_(const char *config_uuid, epg_broadcast_t *e,
htsmsg_t *conf;

conf = htsmsg_create_map();
if (enabled >= 0)
htsmsg_add_u32(conf, "enabled", !!enabled);
htsmsg_add_s64(conf, "start", start);
htsmsg_add_s64(conf, "stop", stop);
htsmsg_add_str(conf, "channel", idnode_uuid_as_sstr(&ch->ch_id));
Expand Down Expand Up @@ -645,7 +652,7 @@ dvr_entry_create_(const char *config_uuid, epg_broadcast_t *e,
*
*/
dvr_entry_t *
dvr_entry_create_htsp(const char *config_uuid,
dvr_entry_create_htsp(int enabled, const char *config_uuid,
channel_t *ch, time_t start, time_t stop,
time_t start_extra, time_t stop_extra,
const char *title, const char* subtitle,
Expand All @@ -660,7 +667,8 @@ dvr_entry_create_htsp(const char *config_uuid,
dvr_config_t *cfg = dvr_config_find_by_uuid(config_uuid);
if (!cfg)
cfg = dvr_config_find_by_name(config_uuid);
return dvr_entry_create_(cfg ? idnode_uuid_as_str(&cfg->dvr_id, ubuf) : NULL,
return dvr_entry_create_(enabled,
cfg ? idnode_uuid_as_str(&cfg->dvr_id, ubuf) : NULL,
NULL,
ch, start, stop, start_extra, stop_extra,
title, subtitle, description, lang, content_type,
Expand All @@ -672,7 +680,7 @@ dvr_entry_create_htsp(const char *config_uuid,
*
*/
dvr_entry_t *
dvr_entry_create_by_event(const char *config_uuid,
dvr_entry_create_by_event(int enabled, const char *config_uuid,
epg_broadcast_t *e,
time_t start_extra, time_t stop_extra,
const char *owner,
Expand All @@ -683,7 +691,7 @@ dvr_entry_create_by_event(const char *config_uuid,
if(!e->channel || !e->episode || !e->episode->title)
return NULL;

return dvr_entry_create_(config_uuid, e,
return dvr_entry_create_(enabled, config_uuid, e,
e->channel, e->start, e->stop,
start_extra, stop_extra,
NULL, NULL, NULL, NULL,
Expand Down Expand Up @@ -805,8 +813,8 @@ dvr_entry_create_by_autorec(epg_broadcast_t *e, dvr_autorec_entry_t *dae)
dae->dae_comment ? ": " : "",
dae->dae_comment ?: "");

dvr_entry_create_by_event(idnode_uuid_as_str(&dae->dae_config->dvr_id, ubuf), e,
dae->dae_start_extra, dae->dae_stop_extra,
dvr_entry_create_by_event(1, idnode_uuid_as_str(&dae->dae_config->dvr_id, ubuf),
e, dae->dae_start_extra, dae->dae_stop_extra,
dae->dae_owner, dae->dae_creator,
dae, dae->dae_pri, dae->dae_retention, buf);
}
Expand Down Expand Up @@ -931,14 +939,23 @@ dvr_timer_expire(void *aux)
}

static dvr_entry_t *_dvr_entry_update
( dvr_entry_t *de, epg_broadcast_t *e, channel_t *ch, const char *title,
const char *subtitle, const char *desc, const char *lang, time_t start,
time_t stop, time_t start_extra, time_t stop_extra, dvr_prio_t pri,
int retention )
( dvr_entry_t *de, int enabled, epg_broadcast_t *e, channel_t *ch,
const char *title, const char *subtitle, const char *desc,
const char *lang, time_t start, time_t stop,
time_t start_extra, time_t stop_extra,
dvr_prio_t pri, int retention )
{
char buf[40];
int save = 0, updated = 0;

if (enabled >= 0) {
enabled = !!enabled;
if (de->de_enabled != enabled) {
de->de_enabled = enabled;
save = 1;
}
}

if (!dvr_entry_is_editable(de)) {
if (stop > 0) {
if (stop < dispatch_clock)
Expand Down Expand Up @@ -1083,14 +1100,14 @@ static dvr_entry_t *_dvr_entry_update
*/
dvr_entry_t *
dvr_entry_update
( dvr_entry_t *de, channel_t *ch,
( dvr_entry_t *de, int enabled, channel_t *ch,
const char *title, const char *subtitle,
const char *desc, const char *lang,
time_t start, time_t stop,
time_t start_extra, time_t stop_extra,
dvr_prio_t pri, int retention )
{
return _dvr_entry_update(de, NULL, ch, title, subtitle, desc, lang,
return _dvr_entry_update(de, enabled, NULL, ch, title, subtitle, desc, lang,
start, stop, start_extra, stop_extra,
pri, retention);
}
Expand Down Expand Up @@ -1139,7 +1156,7 @@ dvr_event_replaced(epg_broadcast_t *e, epg_broadcast_t *new_e)
channel_get_name(e->channel),
e->start, e->stop);
dvr_entry_assign_broadcast(de, e);
_dvr_entry_update(de, e, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, DVR_PRIO_NOTSET, 0);
_dvr_entry_update(de, -1, e, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, DVR_PRIO_NOTSET, 0);
return;
}
}
Expand All @@ -1153,7 +1170,7 @@ void dvr_event_updated ( epg_broadcast_t *e )
dvr_entry_t *de;
de = dvr_entry_find_by_event(e);
if (de)
_dvr_entry_update(de, e, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, DVR_PRIO_NOTSET, 0);
_dvr_entry_update(de, -1, e, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, DVR_PRIO_NOTSET, 0);
else {
LIST_FOREACH(de, &dvrentries, de_global_link) {
if (de->de_sched_state != DVR_SCHEDULED) continue;
Expand All @@ -1168,7 +1185,7 @@ void dvr_event_updated ( epg_broadcast_t *e )
channel_get_name(e->channel),
e->start, e->stop);
dvr_entry_assign_broadcast(de, e);
_dvr_entry_update(de, e, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, DVR_PRIO_NOTSET, 0);
_dvr_entry_update(de, -1, e, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, DVR_PRIO_NOTSET, 0);
break;
}
}
Expand Down Expand Up @@ -1992,6 +2009,12 @@ const idclass_t dvr_entry_class = {
.ic_delete = dvr_entry_class_delete,
.ic_perm = dvr_entry_class_perm,
.ic_properties = (const property_t[]) {
{
.type = PT_BOOL,
.id = "enabled",
.name = N_("Enabled"),
.off = offsetof(dvr_entry_t, de_enabled),
},
{
.type = PT_TIME,
.id = "start",
Expand Down
2 changes: 1 addition & 1 deletion src/dvr/dvr_timerec.c
Expand Up @@ -154,7 +154,7 @@ dvr_timerec_check(dvr_timerec_entry_t *dte)
snprintf(buf, sizeof(buf), _("Time recording%s%s"),
dte->dte_comment ? ": " : "",
dte->dte_comment ?: "");
de = dvr_entry_create_(idnode_uuid_as_str(&dte->dte_config->dvr_id, ubuf),
de = dvr_entry_create_(1, idnode_uuid_as_str(&dte->dte_config->dvr_id, ubuf),
NULL, dte->dte_channel,
start, stop, 0, 0, title, NULL,
NULL, NULL, NULL, dte->dte_owner, dte->dte_creator,
Expand Down
13 changes: 9 additions & 4 deletions src/htsp_server.c
Expand Up @@ -65,7 +65,7 @@

static void *htsp_server, *htsp_server_2;

#define HTSP_PROTO_VERSION 22
#define HTSP_PROTO_VERSION 23

#define HTSP_ASYNC_OFF 0x00
#define HTSP_ASYNC_ON 0x01
Expand Down Expand Up @@ -706,6 +706,7 @@ htsp_build_dvrentry(dvr_entry_t *de, const char *method, const char *lang)
int64_t fsize = -1;

htsmsg_add_u32(out, "id", idnode_get_short_uuid(&de->de_id));
htsmsg_add_u32(out, "enabled", de->de_enabled);
if (de->de_channel)
htsmsg_add_u32(out, "channel", channel_get_id(de->de_channel));

Expand Down Expand Up @@ -1518,8 +1519,10 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
int64_t start, stop, start_extra, stop_extra;
uint32_t u32, priority, retention;
channel_t *ch = NULL;
int enabled;

/* Options */
enabled = htsmsg_get_u32_or_default(in, "enabled", 1);
dvr_config_name = htsp_dvr_config_name(htsp, htsmsg_get_str(in, "configName"));
if(htsmsg_get_s64(in, "startExtra", &start_extra))
start_extra = 0;
Expand Down Expand Up @@ -1563,7 +1566,7 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
desc = "";

// create the dvr entry
de = dvr_entry_create_htsp(dvr_config_name, ch, start, stop,
de = dvr_entry_create_htsp(enabled, dvr_config_name, ch, start, stop,
start_extra, stop_extra,
title, subtitle, desc, lang, 0,
htsp->htsp_granted_access->aa_username,
Expand All @@ -1572,7 +1575,7 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)

/* Event timer */
} else {
de = dvr_entry_create_by_event(dvr_config_name, e,
de = dvr_entry_create_by_event(enabled, dvr_config_name, e,
start_extra, stop_extra,
htsp->htsp_granted_access->aa_username,
htsp->htsp_granted_access->aa_representative,
Expand Down Expand Up @@ -1612,6 +1615,7 @@ htsp_method_updateDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
time_t start, stop, start_extra, stop_extra, priority, retention;
const char *title, *subtitle, *desc, *lang;
channel_t *channel = NULL;
int enabled;

if(htsmsg_get_u32(in, "id", &dvrEntryId))
return htsp_error("Missing argument 'id'");
Expand All @@ -1631,6 +1635,7 @@ htsp_method_updateDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
if (!htsp_user_access_channel(htsp, channel))
return htsp_error("User does not have access to channel");

enabled = htsmsg_get_s64_or_default(in, "enabled", -1);
start = htsmsg_get_s64_or_default(in, "start", 0);
stop = htsmsg_get_s64_or_default(in, "stop", 0);
start_extra = htsmsg_get_s64_or_default(in, "startExtra", 0);
Expand All @@ -1642,7 +1647,7 @@ htsp_method_updateDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
desc = htsmsg_get_str(in, "description");
lang = htsmsg_get_str(in, "language") ?: htsp->htsp_language;

de = dvr_entry_update(de, channel, title, subtitle, desc, lang, start, stop,
de = dvr_entry_update(de, enabled, channel, title, subtitle, desc, lang, start, stop,
start_extra, stop_extra, priority, retention);

//create response
Expand Down
2 changes: 1 addition & 1 deletion src/webui/simpleui.c
Expand Up @@ -317,7 +317,7 @@ page_einfo(http_connection_t *hc, const char *remain, void *opaque)
de = dvr_entry_find_by_event(e);

if((http_arg_get(&hc->hc_req_args, "rec")) != NULL) {
de = dvr_entry_create_by_event(NULL, e, 0, 0, hc->hc_username ?: NULL,
de = dvr_entry_create_by_event(1, NULL, e, 0, 0, hc->hc_username ?: NULL,
hc->hc_representative ?: NULL, NULL,
DVR_PRIO_NORMAL, 0, "simpleui");
} else if(de != NULL && (http_arg_get(&hc->hc_req_args, "cancel")) != NULL) {
Expand Down
7 changes: 4 additions & 3 deletions src/webui/static/app/dvr.js
Expand Up @@ -157,7 +157,8 @@ tvheadend.dvr_upcoming = function(panel, index) {
var actions = tvheadend.dvrRowActions();
var list = 'disp_title,start,start_extra,stop,stop_extra,' +
'channel,config_name,comment';
var elist = tvheadend.accessUpdate.admin ? list + ',owner,creator' : list;
var elist = 'enabled,' +
(tvheadend.accessUpdate.admin ? list + ',owner,creator' : list);

var stopButton = {
name: 'stop',
Expand Down Expand Up @@ -254,8 +255,8 @@ tvheadend.dvr_upcoming = function(panel, index) {
}
},
del: true,
list: 'duplicate,disp_title,disp_subtitle,episode,pri,start_real,stop_real,' +
'duration,filesize,channel,owner,creator,config_name,' +
list: 'enabled,duplicate,disp_title,disp_subtitle,episode,pri,start_real,' +
'stop_real,duration,filesize,channel,owner,creator,config_name,' +
'sched_status,errors,data_errors,comment',
columns: {
filesize: {
Expand Down

1 comment on commit fa57953

@ksooo
Copy link
Contributor

@ksooo ksooo commented on fa57953 Sep 26, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fyi. I updated the HTSP spec (https://tvheadend.org/projects/tvheadend/wiki/Htsp) to reflect this change.

Please sign in to comment.