diff --git a/common.h b/common.h index 20c9811a..81b18705 100644 --- a/common.h +++ b/common.h @@ -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; diff --git a/player.c b/player.c index b38470d4..18df1a7e 100644 --- a/player.c +++ b/player.c @@ -36,6 +36,7 @@ #include #include #include +#include #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 diff --git a/shairport.c b/shairport.c index 654d8f7d..8c475bbf 100644 --- a/shairport.c +++ b/shairport.c @@ -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 -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;