provide -B/-E for running shell commands on begin/end of playing
Implements functionality described by MaZderMind <github@mazdermind.de> in issue #201.
This commit is contained in:
@@ -26,6 +26,7 @@ typedef struct {
|
||||
int buffer_start_fill;
|
||||
int daemonise;
|
||||
int mdns_internal;
|
||||
char *cmd_start, *cmd_stop;
|
||||
} shairport_cfg;
|
||||
|
||||
extern int debuglev;
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <sys/signal.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "player.h"
|
||||
@@ -515,6 +516,11 @@ int player_play(stream_cfg *stream) {
|
||||
#endif
|
||||
|
||||
please_stop = 0;
|
||||
if (config.cmd_start && !fork()) {
|
||||
if (system(config.cmd_start))
|
||||
warn("exec of external start command failed\n");
|
||||
exit(0);
|
||||
}
|
||||
config.output->start(sampling_rate);
|
||||
pthread_create(&player_thread, NULL, player_thread_func, NULL);
|
||||
|
||||
@@ -525,6 +531,11 @@ void player_stop(void) {
|
||||
please_stop = 1;
|
||||
pthread_join(player_thread, NULL);
|
||||
config.output->stop();
|
||||
if (config.cmd_stop && !fork()) {
|
||||
if (system(config.cmd_stop))
|
||||
warn("exec of external stop command failed\n");
|
||||
exit(0);
|
||||
}
|
||||
free_buffer();
|
||||
free_decoder();
|
||||
#ifdef FANCY_RESAMPLING
|
||||
|
||||
+10
-1
@@ -71,6 +71,9 @@ void usage(char *progname) {
|
||||
" This value is in frames; default %d\n"
|
||||
" -d fork (daemonise)\n"
|
||||
" The PID of the child process is written to stdout\n"
|
||||
" -B command run a shell command when playback begins\n"
|
||||
" -E command run a shell command when playback ends\n"
|
||||
"\n"
|
||||
"Run %s -o <output> -h to find the available options for a specific output\n"
|
||||
"\n", config.buffer_start_fill, progname);
|
||||
|
||||
@@ -86,7 +89,7 @@ void usage(char *progname) {
|
||||
|
||||
int parse_options(int argc, char **argv) {
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "+hdvp:a:o:b:")) > 0) {
|
||||
while ((opt = getopt(argc, argv, "+hdvp:a:o:b:B:E:")) > 0) {
|
||||
switch (opt) {
|
||||
default:
|
||||
printf("Unknown argument -%c\n", optopt);
|
||||
@@ -111,6 +114,12 @@ int parse_options(int argc, char **argv) {
|
||||
case 'b':
|
||||
config.buffer_start_fill = atoi(optarg);
|
||||
break;
|
||||
case 'B':
|
||||
config.cmd_start = optarg;
|
||||
break;
|
||||
case 'E':
|
||||
config.cmd_stop = optarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return optind;
|
||||
|
||||
Reference in New Issue
Block a user