This modifies the sleep command to turn off audiod before sending the
stop command to the server. This way the stream terminates immediately
(on the local machine) rather than when the input queue of the stream
has drained, which may be a several seconds later.
This is important because we are going to set the initial volume but
don't want to change the volume of the stream which is about to end.
Currently this is "solved" by sleeping one second, but this has always
been a hack that never worked well in practice.
In order to be able to send commands to para_audiod we introduce
audioc_cmd() which shares most of the implementation of client_cmd(),
so we make both functions wrappers for the new run() which works for both
command types.
To avoid code duplications we also introduce stop() which does the
equivalent of
para_audioc off
para_client stop
para_audioc on
-static void client_cmd(const char *cmd)
+static void run(const char *exe, const char *cmd)
{
int ret, status, fds[3] = {0, 0, 0};
pid_t pid;
{
int ret, status, fds[3] = {0, 0, 0};
pid_t pid;
- char *cmdline = make_message(BINDIR "/para_client %s", cmd);
+ char *cmdline = make_message("%s %s", exe, cmd);
PARA_NOTICE_LOG("%s\n", cmdline);
ret = para_exec_cmdline_pid(&pid, cmdline, fds);
PARA_NOTICE_LOG("%s\n", cmdline);
ret = para_exec_cmdline_pid(&pid, cmdline, fds);
+static void client_cmd(const char *cmd)
+{
+ run(BINDIR "/para_client", cmd);
+}
+
+static void audioc_cmd(const char *cmd)
+{
+ run(BINDIR "/para_audioc", cmd);
+}
+
static void change_afs_mode(const char *afs_mode)
{
char *cmd;
static void change_afs_mode(const char *afs_mode)
{
char *cmd;
+static void stop(void)
+{
+ audioc_cmd("off");
+ client_cmd("stop");
+ audioc_cmd("on");
+}
+
static int com_sleep(const struct mixer *m)
{
time_t t1, wake_time_epoch;
static int com_sleep(const struct mixer *m)
{
time_t t1, wake_time_epoch;
}
wake_time_epoch = mktime(tm);
PARA_INFO_LOG("waketime: %d:%02d\n", tm->tm_hour, tm->tm_min);
}
wake_time_epoch = mktime(tm);
PARA_INFO_LOG("waketime: %d:%02d\n", tm->tm_hour, tm->tm_min);
- client_cmd("stop");
- sleep(1);
ret = set_initial_volume(m, h);
if (ret < 0)
goto close_mixer;
ret = set_initial_volume(m, h);
if (ret < 0)
goto close_mixer;
change_afs_mode(initial_mood);
client_cmd("play");
sleep(delay);
change_afs_mode(initial_mood);
client_cmd("play");
sleep(delay);
}
if (fot && fo_mood && *fo_mood) {
change_afs_mode(fo_mood);
}
if (fot && fo_mood && *fo_mood) {
change_afs_mode(fo_mood);
if (!fot || !fo_mood) /* currently stopped */
client_cmd("play");
} else if (fot && fo_mood && *fo_mood) /* currently playing */
if (!fot || !fo_mood) /* currently stopped */
client_cmd("play");
} else if (fot && fo_mood && *fo_mood) /* currently playing */
m->close(&h);
if (!fit || !fi_mood || !*fi_mood) /* nothing to do */
return 1;
m->close(&h);
if (!fit || !fi_mood || !*fi_mood) /* nothing to do */
return 1;
sleep(delay);
}
change_afs_mode(fi_mood);
sleep(delay);
}
change_afs_mode(fi_mood);
- if (sleep_mood && *sleep_mood) /* currently playing */
- client_cmd("next");
- else /* currently stopped */
- client_cmd("play");
ret = open_mixer_and_set_channel(m, &h);
if (ret < 0)
return ret;
ret = open_mixer_and_set_channel(m, &h);
if (ret < 0)
return ret;
+ if (sleep_mood && *sleep_mood) /* currently playing */
+ stop();
+ client_cmd("play");
ret = fade(m, h, fiv, fit);
close_mixer:
m->close(&h);
ret = fade(m, h, fiv, fit);
close_mixer:
m->close(&h);