Skip to content

Commit

Permalink
provide -B/-E for running shell commands on begin/end of playing
Browse files Browse the repository at this point in the history
Implements functionality described by MaZderMind <[email protected]>
in issue mikebrady#201.
  • Loading branch information
abrasive committed Jun 3, 2013
1 parent c5b1f97 commit 3c8c9ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <sys/signal.h>
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>

#include "common.h"
#include "player.h"
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion shairport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 3c8c9ed

Please sign in to comment.