From 62607b2b5eeec06cf2a4fc76ee705e7c570c700b Mon Sep 17 00:00:00 2001 From: Stef Simoens Date: Mon, 10 Oct 2011 09:16:20 +0200 Subject: [PATCH 1/3] BUFFER_FRAMES needs to be a power of 2 because of the way BUFIDX(seqno) works --- hairtunes.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hairtunes.h b/hairtunes.h index 5b256ad4..93589ae6 100644 --- a/hairtunes.h +++ b/hairtunes.h @@ -4,6 +4,7 @@ int hairtunes_init(char *pAeskey, char *pAesiv, char *pFmtpstr, int pCtrlPort, i int pDataPort, char *pRtpHost, char*pPipeName, char *pLibaoDriver, char *pLibaoDeviceName, char *pLibaoDeviceId); // default buffer size -#define BUFFER_FRAMES 320 +// needs to be a power of 2 because of the way BUFIDX(seqno) works +#define BUFFER_FRAMES 512 #endif From 800453f62b50bfd0c0aff988972b08082ac64b09 Mon Sep 17 00:00:00 2001 From: Stef Simoens Date: Mon, 10 Oct 2011 09:23:19 +0200 Subject: [PATCH 2/3] Send "last-chance retry" only once The last-chance resend was sometimes fired up to 6 times (probably while receiving multiple new packets while playing the same buffer-data). The following patch corrects this: only one retry is sent out. For this to happen, I change abuf->ready to -1 ("1 retry sent out") and by changing the other comparisons of abuf->ready to != 1. Probably, this could be improved, by implementing a first check at t-30, t-20, t-10, ... --- hairtunes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hairtunes.c b/hairtunes.c index 28b49069..4b54915a 100644 --- a/hairtunes.c +++ b/hairtunes.c @@ -393,8 +393,10 @@ void buffer_put_packet(seq_t seqno, char *data, int len) { // check if the t+10th packet has arrived... last-chance resend read = ab_read + 10; abuf = audio_buffer + BUFIDX(read); - if (!abuf->ready) + if (abuf->ready != 1) { rtp_request_resend(read, read); + abuf->ready = -1; + } } } @@ -671,7 +673,7 @@ short *buffer_get_frame(void) { bf_est_update(buf_fill); volatile abuf_t *curframe = audio_buffer + BUFIDX(read); - if (!curframe->ready) { + if (curframe->ready != 1) { fprintf(stderr, "\nmissing frame.\n"); memset(curframe->data, 0, FRAME_BYTES); } From 9796ac354cf6b8805b3a83dca829a77c0b49d3c4 Mon Sep 17 00:00:00 2001 From: Stef Simoens Date: Mon, 10 Oct 2011 09:26:43 +0200 Subject: [PATCH 3/3] new feature: run program on first connection / run program on last disconnection I was looking to trigger an action when I connect to shairport. Basically, I want to switch on the stereo when I start playing music over shairport (and I want to switch if off when I stop streaming). Because my set-up will be different than any other set-up, I thought about making it generic. Two new command-line options --play_prog and --stop_prog take one argument: the command line to start when the first connection is made or when the last connection quits. Example: $ shairport.pl --play_prog="amixer set PCM 100%" --- shairport.pl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/shairport.pl b/shairport.pl index 8b6fcc6f..02e57bbf 100755 --- a/shairport.pl +++ b/shairport.pl @@ -71,6 +71,9 @@ my $cliport; my $mac; # SB volume my $volume; +# custom play and stop program +my $play_prog; +my $stop_prog; # output debugging information my $verbose; # where to write PID @@ -97,6 +100,8 @@ GetOptions("a|apname=s" => \$apname, "s|squeezebox" => \$squeeze, "c|cliport=s" => \$cliport, "m|mac=s" => \$mac, + "play_prog=s" => \$play_prog, + "stop_prog=s" => \$stop_prog, "l|volume=s" => \$volume, "h|help" => \$help); @@ -117,6 +122,8 @@ sub usage { " -c --cliport=port Sets the SBS CLI port\n", " -m --mac=address Sets the SB target device\n", " -l --volume=level Sets the SB volume level (in %)\n", + " --play_prog=cmdline Program to start on 1st connection\n", + " --stop_prog=cmdline Program to start on last disconnection\n", " -d Daemon mode\n", " -w --writepid=path Write PID to this location\n", " -v --verbose Print debugging messages\n", @@ -491,6 +498,11 @@ while (1) { if (defined($squeeze) && $squeeze) { &performSqueezeboxSetup(); } + + # the 2nd connection is a player connection + if (defined($play_prog) && $sel->count() == 2) { + system($play_prog); + } } else { if (eof($fh)) { print "Closed: $fh\n" if $verbose; @@ -502,6 +514,11 @@ while (1) { eval { kill $conns{$fh}{decoder_pid} }; } delete $conns{$fh}; + + # 1 connection means no connection + if (defined($stop_prog) && $sel->count() == 1) { + system($stop_prog); + } next; } if (exists $conns{$fh}) {