Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: add pre-processor command
  • Loading branch information
perexg committed Apr 5, 2016
1 parent 6af6cf6 commit cdbcc2c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/dvr/dvr.h
Expand Up @@ -59,6 +59,7 @@ typedef struct dvr_config {
uint32_t dvr_autorec_max_sched_count;
char *dvr_charset;
char *dvr_charset_id;
char *dvr_preproc;
char *dvr_postproc;
char *dvr_postremove;
uint32_t dvr_warm_time;
Expand Down Expand Up @@ -596,7 +597,7 @@ htsmsg_t *dvr_entry_class_removal_list ( void *o, const char *lang );

int dvr_entry_verify(dvr_entry_t *de, access_t *a, int readonly);

void dvr_spawn_postcmd(dvr_entry_t *de, const char *postcmd, const char *filename);
void dvr_spawn_cmd(dvr_entry_t *de, const char *cmd, const char *filename, int pre);

void dvr_vfs_refresh_entry(dvr_entry_t *de);
void dvr_vfs_remove_entry(dvr_entry_t *de);
Expand Down
13 changes: 13 additions & 0 deletions src/dvr/dvr_config.c
Expand Up @@ -260,6 +260,9 @@ dvr_config_destroy(dvr_config_t *cfg, int delconf)
free(cfg->dvr_charset);
free(cfg->dvr_storage);
free(cfg->dvr_config_name);
free(cfg->dvr_preproc);
free(cfg->dvr_postproc);
free(cfg->dvr_postremove);
free(cfg);
}

Expand Down Expand Up @@ -1009,6 +1012,16 @@ const idclass_t dvr_config_class = {
.opts = PO_ADVANCED,
.group = 1,
},
{
.type = PT_STR,
.id = "preproc",
.name = N_("Pre-processor command"),
.desc = N_("Script/program to be run when a recording starts "
"(service is subscribed but no filename available)."),
.off = offsetof(dvr_config_t, dvr_preproc),
.opts = PO_EXPERT,
.group = 1,
},
{
.type = PT_STR,
.id = "postproc",
Expand Down
8 changes: 4 additions & 4 deletions src/dvr/dvr_db.c
Expand Up @@ -3337,7 +3337,7 @@ dvr_entry_delete(dvr_entry_t *de)
struct tm tm;
const char *filename;
char *str1, *str2;
char tbuf[64], ubuf[UUID_HEX_SIZE], *rdir, *postcmd;
char tbuf[64], ubuf[UUID_HEX_SIZE], *rdir, *cmd;
int r, ret = 0;

t = dvr_entry_get_start_time(de, 1);
Expand Down Expand Up @@ -3374,9 +3374,9 @@ dvr_entry_delete(dvr_entry_t *de)
tvhlog(LOG_WARNING, "dvr", "Unable to remove file '%s' from disk -- %s",
filename, strerror(-errno));

postcmd = de->de_config->dvr_postremove;
if (postcmd && postcmd[0])
dvr_spawn_postcmd(de, postcmd, filename);
cmd = de->de_config->dvr_postremove;
if (cmd && cmd[0])
dvr_spawn_cmd(de, cmd, filename, 0);
htsmsg_delete_field(m, "filename");
ret = 1;
}
Expand Down
40 changes: 24 additions & 16 deletions src/dvr/dvr_rec.c
Expand Up @@ -142,6 +142,9 @@ dvr_rec_subscribe(dvr_entry_t *de)

atomic_set(&de->de_thread_shutdown, 0);
tvhthread_create(&de->de_thread, NULL, dvr_thread, de, "dvr");

if (de->de_config->dvr_preproc)
dvr_spawn_cmd(de, de->de_config->dvr_preproc, NULL, 1);
return 0;
}

Expand Down Expand Up @@ -1520,34 +1523,39 @@ dvr_thread(void *aux)
*
*/
void
dvr_spawn_postcmd(dvr_entry_t *de, const char *postcmd, const char *filename)
dvr_spawn_cmd(dvr_entry_t *de, const char *cmd, const char *filename, int pre)
{
char buf1[MAX(PATH_MAX, 2048)], *buf2;
char tmp[MAX(PATH_MAX, 512)];
htsmsg_t *info, *e;
htsmsg_t *info = NULL, *e;
htsmsg_field_t *f;
char **args;

if ((f = htsmsg_field_last(de->de_files)) != NULL &&
(e = htsmsg_field_get_map(f)) != NULL) {
if (filename == NULL) {
filename = htsmsg_get_str(e, "filename");
if (filename == NULL)
return;
if (!pre) {
if ((f = htsmsg_field_last(de->de_files)) != NULL &&
(e = htsmsg_field_get_map(f)) != NULL) {
if (filename == NULL) {
filename = htsmsg_get_str(e, "filename");
if (filename == NULL)
return;
}
info = htsmsg_get_list(e, "info");
} else {
return;
}
info = htsmsg_get_list(e, "info");
} else {
return;
}

/* Substitute DVR entry formatters */
htsstr_substitute(postcmd, buf1, sizeof(buf1), '%', dvr_subs_postproc_entry, de, tmp, sizeof(tmp));
htsstr_substitute(cmd, buf1, sizeof(buf1), '%', dvr_subs_postproc_entry, de, tmp, sizeof(tmp));
buf2 = tvh_strdupa(buf1);
/* Substitute filename formatters */
htsstr_substitute(buf2, buf1, sizeof(buf1), '%', dvr_subs_postproc_filename, filename, tmp, sizeof(tmp));
buf2 = tvh_strdupa(buf1);
if (!pre) {
htsstr_substitute(buf2, buf1, sizeof(buf1), '%', dvr_subs_postproc_filename, filename, tmp, sizeof(tmp));
buf2 = tvh_strdupa(buf1);
}
/* Substitute info formatters */
htsstr_substitute(buf2, buf1, sizeof(buf1), '%', dvr_subs_postproc_info, info, tmp, sizeof(tmp));
if (info)
htsstr_substitute(buf2, buf1, sizeof(buf1), '%', dvr_subs_postproc_info, info, tmp, sizeof(tmp));

args = htsstr_argsplit(buf1);
if(args[0])
Expand All @@ -1572,5 +1580,5 @@ dvr_thread_epilog(dvr_entry_t *de, const char *dvr_postproc)
prch->prch_muxer = NULL;

if(dvr_postproc && dvr_postproc[0])
dvr_spawn_postcmd(de, dvr_postproc, NULL);
dvr_spawn_cmd(de, dvr_postproc, NULL, 0);
}

0 comments on commit cdbcc2c

Please sign in to comment.