Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mux scheduler: add restart flag
  • Loading branch information
perexg committed Oct 6, 2016
1 parent a9bc3bc commit b7c8bb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/input/mpegts/mpegts_mux_sched.c
Expand Up @@ -35,7 +35,7 @@ mpegts_mux_sched_list_t mpegts_mux_sched_all;
static void
mpegts_mux_sched_set_timer ( mpegts_mux_sched_t *mms )
{
/* Upate timer */
/* Update timer */
if (!mms->mms_enabled) {
if (mms->mms_sub)
subscription_unsubscribe(mms->mms_sub, UNSUBSCRIBE_FINAL);
Expand All @@ -50,9 +50,9 @@ mpegts_mux_sched_set_timer ( mpegts_mux_sched_t *mms )
mms->mms_timeout);
}
} else {
time_t now, nxt;
time(&now);
if (!cron_next(&mms->mms_cronjob, now, &nxt)) {
time_t nxt;
if (!cron_next(&mms->mms_cronjob, gclk(), &nxt)) {
mms->mms_start = nxt;
gtimer_arm_absn(&mms->mms_timer, mpegts_mux_sched_timer, mms, nxt);
}
}
Expand Down Expand Up @@ -151,19 +151,26 @@ const idclass_t mpegts_mux_sched_class =
.type = PT_STR,
.id = "cron",
.name = N_("Cron"),
.desc = N_("Schedule frequency (in Cron format)."),
.desc = N_("Schedule frequency (in cron format)."),
.doc = prop_doc_cron,
.off = offsetof(mpegts_mux_sched_t, mms_cronstr),
.set = mpegts_mux_sched_class_cron_set,
},
{
.type = PT_INT,
.id = "timeout",
.name = N_("Timout (secs)"),
.name = N_("Timeout (secs)"),
.desc = N_("The length of time (in seconds) to play the mux "
"for. 1 hour = 3600."),
"(1 hour = 3600)."),
.off = offsetof(mpegts_mux_sched_t, mms_timeout),
},
{
.type = PT_BOOL,
.id = "restart",
.name = N_("Restart"),
.desc = N_("Restart when the subscription is overriden (in then timeout time window)."),
.off = offsetof(mpegts_mux_sched_t, mms_restart),
},
{
},
}
Expand Down Expand Up @@ -210,7 +217,7 @@ mpegts_mux_sched_timer ( void *p )
{
mpegts_mux_t *mm;
mpegts_mux_sched_t *mms = p;
time_t now, nxt;
time_t nxt;

/* Not enabled (shouldn't be running) */
if (!mms->mms_enabled)
Expand All @@ -227,9 +234,6 @@ mpegts_mux_sched_timer ( void *p )
return;
}

/* Current time */
time(&now);

/* Start sub */
if (!mms->mms_active) {
assert(mms->mms_sub == NULL);
Expand Down Expand Up @@ -266,13 +270,21 @@ mpegts_mux_sched_timer ( void *p )
}
mms->mms_active = 0;

if (mms->mms_restart &&
(mms->mms_timeout <= 0 ||
mms->mms_start + mms->mms_timeout < gclk() - 60)) {
gtimer_arm_rel(&mms->mms_timer, mpegts_mux_sched_timer, mms, 15);
return;
}

/* Find next */
if (cron_next(&mms->mms_cronjob, now, &nxt)) {
if (cron_next(&mms->mms_cronjob, gclk(), &nxt)) {
tvherror(LS_MUXSCHED, "failed to find next event");
return;
}

/* Timer */
mms->mms_start = nxt;
gtimer_arm_absn(&mms->mms_timer, mpegts_mux_sched_timer, mms, nxt);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/mpegts_mux_sched.h
Expand Up @@ -47,12 +47,14 @@ typedef struct mpegts_mux_sched
char *mms_mux; ///< Mux UUID
char *mms_creator; ///< Creator of entry
int mms_timeout; ///< Timeout (in seconds)
int mms_restart; ///< Restart subscription when overriden
int mms_weight; ///< Weighting

/*
* Cron handling
*/
int mms_active; ///< Subscription is active
time_t mms_start; ///< Start time
gtimer_t mms_timer; ///< Timer for start/end
cron_t mms_cronjob; ///< Cron spec

Expand Down

0 comments on commit b7c8bb7

Please sign in to comment.