diff --git a/INSTALL b/INSTALL index 62ca8b3f..f32ac0b9 100644 --- a/INSTALL +++ b/INSTALL @@ -7,7 +7,7 @@ You need the following installed: Perl Debian/Ubuntu users need: - libssl-dev libcrypt-openssl-rsa-perl libao2 libao-dev2 libio-socket-inet6-perl + libssl-dev libcrypt-openssl-rsa-perl libao2 libao-dev2 libio-socket-inet6-perl libwww-perl avahi-utils Perl modules (install from CPAN if needed): HTTP::Message diff --git a/Makefile b/Makefile index 8ec08596..a29cc812 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ CFLAGS = `pkg-config --cflags --libs ao openssl` hairtunes: hairtunes.c alac.c - gcc hairtunes.c alac.c -D__i386 -lm $(CFLAGS) -o hairtunes + gcc hairtunes.c alac.c -lm $(CFLAGS) -o hairtunes diff --git a/README b/README index dadddbba..138ebad5 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ -Shairport v0.03 +Shairport v0.05 ============== James Laird -April 11, 2011 +April 13, 2011 What it is ---------- @@ -42,5 +42,10 @@ Changelog bugfix: libao compatibility 0.03 April 11, 2011 bugfix: ipv6 didn't work - - IO::Socket::INET6 is required too - + IO::Socket::INET6 is required too +0.04 April 12, 2011 + cross-platform count_leading_zeros under GCC - + will now compile cleanly on ARM and other platforms +0.05 April 13, 2011 + error-handling cleanup in the Perl script + including more meaningful error messages, based on common problems seen diff --git a/alac.c b/alac.c index cd0860a2..f0b22f5a 100644 --- a/alac.c +++ b/alac.c @@ -218,18 +218,10 @@ static int count_leading_zeros(int32_t input) } return i; } -#elif defined(__GNUC__) && (defined(_X86) || defined(__i386) || defined(i386)) -/* for some reason the unrolled version (below) is - * actually faster than this. yay intel! - */ +#elif defined(__GNUC__) static int count_leading_zeros(int input) { - int output = 0; - if (!input) return 32; - __asm("bsr %1, %0\n" - : "=r" (output) - : "r" (input)); - return (0x1f - output); + return __builtin_clz(input); } #elif defined(_MSC_VER) && defined(_M_IX86) static int count_leading_zeros(int input) diff --git a/shairport.pl b/shairport.pl index 48f62ebd..7d9a805f 100755 --- a/shairport.pl +++ b/shairport.pl @@ -58,18 +58,11 @@ sub POPE { $SIG{PIPE} = \&POPE; -my $avahi_publish = fork(); -if ($avahi_publish==0) { - exec 'avahi-publish-service', - join('', map { sprintf "%02X", $_ } @hw_addr) . "\@$apname", - "_raop._tcp", - "5000", - "tp=UDP","sm=false","sv=false","ek=1","et=0,1","cn=0,1","ch=2","ss=16","sr=44100","pw=false","vn=3","txtvers=1"; -} +our $avahi_publish; sub REAP { if ($avahi_publish == waitpid(-1, WNOHANG)) { - die("Avahi publishing failed!"); + die("Avahi publishing failed! Do you have avahi-publish-service on your PATH?"); } printf("***CHILD EXITED***\n"); $SIG{CHLD} = \&REAP; @@ -81,8 +74,21 @@ my %conns; $SIG{TERM} = $SIG{INT} = sub { map { eval { kill $_->{decoder_pid} } } keys %conns; kill 9, $avahi_publish; - exit(0); + exit 0; }; +$SIG{__DIE__} = sub { + map { eval { kill $_->{decoder_pid} } } keys %conns; + kill 9, $avahi_publish; +}; + +$avahi_publish = fork(); +if ($avahi_publish==0) { + exec 'avahi-publish-service', + join('', map { sprintf "%02X", $_ } @hw_addr) . "\@$apname", + "_raop._tcp", + "5000", + "tp=UDP","sm=false","sv=false","ek=1","et=0,1","cn=0,1","ch=2","ss=16","sr=44100","pw=false","vn=3","txtvers=1"; +} my $airport_pem = join '', ; my $rsa = Crypt::OpenSSL::RSA->new_private_key($airport_pem) || die; @@ -90,23 +96,24 @@ my $rsa = Crypt::OpenSSL::RSA->new_private_key($airport_pem) || die; my $listen; { eval { - $listen = new IO::Socket::INET6(Listen => 1, + local $SIG{__DIE__}; + $listen = new IO::Socket::INET6(Listen => 1, Domain => AF_INET6, LocalPort => 5000, ReuseAddr => 1, Proto => 'tcp'); }; if ($@) { - print "**************************************\n\n", - "* IO::Socket::INET6 not present! *\n", - "* Install this if iTunes won't play. *\n", - "**************************************\n\n"; - - $listen = new IO::Socket::INET(Listen => 1, - LocalPort => 5000, - ReuseAddr => 1, - Proto => 'tcp'); + print "**************************************\n", + "* IO::Socket::INET6 not present! *\n", + "* Install this if iTunes won't play. *\n", + "**************************************\n\n"; } + + $listen ||= new IO::Socket::INET(Listen => 1, + LocalPort => 5000, + ReuseAddr => 1, + Proto => 'tcp'); } die "Can't listen on port 5000: $!" unless $listen;