From e2dd3e9151d988214fd4a162db3cbc5b03918104 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Mon, 11 Apr 2011 19:17:21 +0200 Subject: [PATCH 1/8] make libao default again --- Makefile | 4 ++-- hairtunes.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c1263552..c66d99dc 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CFLAGS = `pkg-config --cflags --libs openssl` -lportaudio -#CFLAGS = `pkg-config --cflags --libs openssl ao` -DHAVE_AO +#CFLAGS = `pkg-config --cflags --libs openssl` -lportaudio +CFLAGS = `pkg-config --cflags --libs openssl ao` hairtunes: hairtunes.c alac.c gcc hairtunes.c alac.c -D__i386 -lm $(CFLAGS) -o hairtunes diff --git a/hairtunes.c b/hairtunes.c index b348366c..1d225f2f 100644 --- a/hairtunes.c +++ b/hairtunes.c @@ -33,12 +33,16 @@ #include #include #include +#include + +#if !defined(HAVE_AO) +#define HAVE_AO 1 +#endif #if HAVE_AO #include #else #include #endif -#include #ifdef FANCY_RESAMPLING #include From f72d219ad003c87fd6fa7e2ee354c3a5169b2f28 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Mon, 11 Apr 2011 19:57:53 +0200 Subject: [PATCH 2/8] do cleanup (e.g. kill dns-sd) also for $SIG{__DIE__} --- shairport.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shairport.pl b/shairport.pl index 74ed7a05..63c29e32 100755 --- a/shairport.pl +++ b/shairport.pl @@ -85,7 +85,7 @@ $SIG{CHLD} = \&REAP; my %conns; -$SIG{TERM} = $SIG{INT} = sub { +$SIG{TERM} = $SIG{INT} = $SIG{__DIE__} = sub { print "killed\n"; map { eval { kill $_->{decoder_pid} } } keys %conns; kill 9, $avahi_publish; From d1ab4d8cd9c8dff614e349d2850aec6fbd532069 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Mon, 11 Apr 2011 20:12:32 +0200 Subject: [PATCH 3/8] more intelligent socket port binding --- hairtunes.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/hairtunes.c b/hairtunes.c index 2268543e..9d050f2a 100644 --- a/hairtunes.c +++ b/hairtunes.c @@ -408,11 +408,7 @@ int init_rtp(void) { int type = AF_INET; short *sin_port = &si.sin_port; #endif - int sock, csock; // data and control (we treat the streams the same here) - - sock = socket(type, SOCK_DGRAM, IPPROTO_UDP); - if (sock==-1) - die("Can't create socket!"); + int sock = -1, csock = -1; // data and control (we treat the streams the same here) memset(&si, 0, sizeof(si)); #ifdef AF_INET6 @@ -428,18 +424,29 @@ int init_rtp(void) { si.sin_addr.s_addr = htonl(INADDR_ANY); #endif - unsigned short port = 6000 - 3; - do { - port += 3; - *sin_port = htons(port); - } while (bind(sock, (struct sockaddr*)&si, sizeof(si))==-1); + unsigned short port = 6000; + while(1) { + if(sock < 0) + sock = socket(type, SOCK_DGRAM, IPPROTO_UDP); + if (sock==-1) + die("Can't create data socket!"); + + if(csock < 0) + csock = socket(type, SOCK_DGRAM, IPPROTO_UDP); + if (csock==-1) + die("Can't create control socket!"); - csock = socket(type, SOCK_DGRAM, IPPROTO_UDP); - if (csock==-1) - die("Can't create socket!"); - *sin_port = htons(port + 1); - if (bind(csock, (struct sockaddr*)&si, sizeof(si))==-1) - die("can't bind control socket"); + *sin_port = htons(port); + int bind1 = bind(sock, (struct sockaddr*)&si, sizeof(si)); + *sin_port = htons(port + 1); + int bind2 = bind(csock, (struct sockaddr*)&si, sizeof(si)); + + if(bind1 != -1 && bind2 != -1) break; + if(bind1 != -1) { close(sock); sock = -1; } + if(bind2 != -1) { close(csock); csock = -1; } + + port += 3; + } printf("port: %d\n", port); // let our handler know where we end up listening printf("cport: %d\n", port+1); From d8844f71054405e9558203740d4a178393284c04 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Mon, 11 Apr 2011 21:08:57 +0200 Subject: [PATCH 4/8] readme/install cleanup --- INSTALL | 15 +++++++++++---- README | 18 ------------------ 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/INSTALL b/INSTALL index 5800587f..24747579 100644 --- a/INSTALL +++ b/INSTALL @@ -1,8 +1,5 @@ Type 'make' to build the packet decoder, 'hairtunes'. -To Run make, you need pkg-config installed (mac): - brew install pkg-config - You need the following installed: openssl libao (if you use homebrew, use brew install libao) @@ -12,7 +9,17 @@ You need the following installed: Debian/Ubuntu users need: libssl-dev libcrypt-openssl-rsa-perl libao2 libao-dev2 libio-socket-inet6-perl -Perl modules (install from CPAN if needed): +Perl modules (e.g. `perl -MCPAN -e 'install X'`): HTTP::Message Crypt::OpenSSL::RSA IO::Socket::INET6 + +MacOSX: + * install XCode + * install homebrew (https://github.com/mxcl/homebrew) + * export ARCHFLAGS="-arch x86_64" + * brew install pkg-config libao + * perl -MCPAN -e 'install Crypt::OpenSSL::RSA' + + OSX 10.5 only bundles perl 5.8, which won't work with shairport. + After getting a update here (http://www.perl.org/get.html), it worked. diff --git a/README b/README index e4dfa90c..dadddbba 100644 --- a/README +++ b/README @@ -11,12 +11,6 @@ iTunes and compatible iPods. It implements a server for the Apple RAOP protocol. It probably supports multiple simultaneous streams, if your audio output chain (as detected by libao) does so. -Setup ------ -* `make` -* `perl -MCPAN -e 'install Crypt::OpenSSL::RSA'` -* `sudo apt-get install libssl-dev libcrypt-openssl-rsa-perl libportaudio-dev libhttp-request-ascgi-perl` - How to use it ------------- 1. Make sure avahi-daemon is running and the prerequisites are installed (see @@ -40,18 +34,6 @@ scheme that made the deobfuscation code itself stand out like a flare. Thanks to Ten Thousand Free Men and their Families for having a computer and stuff. Thanks to wtbw. -How to compile and install on Mac OSX 10.6 ------- -* install XCode -* install homebrew (https://github.com/mxcl/homebrew) -* brew install pkg-config libao -* make -* perl -MCPAN -e 'install Crypt::OpenSSL::RSA' -* perl shairport.pl - -OSX 10.5 only bundles perl 5.8, which won't work with shairport. After getting a update -here (http://www.perl.org/get.html), it worked. - Changelog --------- 0.01 April 5, 2011 From faaa60c721e486e3713332366dc33fd8dd20cfda Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Mon, 11 Apr 2011 21:10:49 +0200 Subject: [PATCH 5/8] readme cleanup --- README | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/README b/README index dadddbba..f1a5e1b5 100644 --- a/README +++ b/README @@ -5,32 +5,23 @@ April 11, 2011 What it is ---------- -This program emulates an Airport Express for the purpose of streaming music from -iTunes and compatible iPods. It implements a server for the Apple RAOP protocol. +This program emulates an Airport Express for the purpose of streaming music from iTunes and compatible iPods. It implements a server for the Apple RAOP protocol. -It probably supports multiple simultaneous streams, if your audio output chain -(as detected by libao) does so. +It probably supports multiple simultaneous streams, if your audio output chain (as detected by libao) does so. How to use it ------------- -1. Make sure avahi-daemon is running and the prerequisites are installed (see -INSTALL). -2. Edit shairport.pl with your favourite text editor to set the access -point name and/or password, if desired. +1. Make sure avahi-daemon is running and the prerequisites are installed (see INSTALL). +2. Edit shairport.pl with your favourite text editor to set the access point name and/or password, if desired. 3. `perl shairport.pl` -The triangle-in-rectangle Airtunes logo will appear in the iTunes status bar of -any machine on the network, or on iPod play controls screen. Choose your access -point name to start streaming to the Shairport instance. +The triangle-in-rectangle Airtunes logo will appear in the iTunes status bar of any machine on the network, or on iPod play controls screen. Choose your access point name to start streaming to the Shairport instance. Thanks ------ -Big thanks to David Hammerton for releasing an ALAC decoder, which is reproduced -here in full. -Thanks to everyone who has worked to reverse engineer the RAOP protocol - after -finding the keys, everything else was pretty much trivial. -Thanks also to Apple for obfuscating the private key in the ROM image, using a -scheme that made the deobfuscation code itself stand out like a flare. +Big thanks to David Hammerton for releasing an ALAC decoder, which is reproduced here in full. +Thanks to everyone who has worked to reverse engineer the RAOP protocol - after finding the keys, everything else was pretty much trivial. +Thanks also to Apple for obfuscating the private key in the ROM image, using a scheme that made the deobfuscation code itself stand out like a flare. Thanks to Ten Thousand Free Men and their Families for having a computer and stuff. Thanks to wtbw. From 56c57a6139d45b9f4a94679b7e0495f6967865ab Mon Sep 17 00:00:00 2001 From: lars Date: Mon, 11 Apr 2011 21:21:50 +0200 Subject: [PATCH 6/8] Required package 'libao-dev2' should be 'libao-dev' --- INSTALL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index 62ca8b3f..a6865cd2 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-dev libio-socket-inet6-perl Perl modules (install from CPAN if needed): HTTP::Message From 171bae3ac6bf827711f2485d0415c8be850ff68c Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Tue, 12 Apr 2011 16:28:17 +0200 Subject: [PATCH 7/8] small fix for __DIE__ handling --- shairport.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/shairport.pl b/shairport.pl index 543322cb..1422abf4 100755 --- a/shairport.pl +++ b/shairport.pl @@ -106,6 +106,7 @@ my $rsa = Crypt::OpenSSL::RSA->new_private_key($airport_pem) || die "RSA private my $listen; { eval { + local $SIG{'__DIE__'}; $listen = new IO::Socket::INET6(Listen => 1, Domain => AF_INET6, LocalPort => 5000, From 44b0b6972f137f3884fee71d7e96e012a11f8918 Mon Sep 17 00:00:00 2001 From: Vincent Gijsen Date: Tue, 12 Apr 2011 18:56:39 +0200 Subject: [PATCH 8/8] Changed Buffer's to make sound synchronized with airport-express in multi-room-config --- hairtunes.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hairtunes.c b/hairtunes.c index 5dbad18f..430e4cb5 100644 --- a/hairtunes.c +++ b/hairtunes.c @@ -46,8 +46,12 @@ int debug = 0; #include "alac.h" // default buffer - about half a second -#define BUFFER_FRAMES 64 -#define START_FILL 55 +//Changed these values to make sound synchronized with airport express during multi-room broadcast. + +#define BUFFER_FRAMES 512 +#define START_FILL 398 + + #define MAX_PACKET 2048 typedef unsigned short seq_t;