From cee45b78694de3e35090c7496af6e2a7e867f517 Mon Sep 17 00:00:00 2001 From: Sebastian Krysmanski Date: Fri, 27 Dec 2013 16:45:49 +0100 Subject: [PATCH] Fixed and documented example.c * Most code from shairplay.c * Removed password (didn't work) * Renamed device to "FakePort" ("AppleTV" may already be in use) * Example no longer quits after 100 seconds --- .gitignore | 1 + src/test/example.c | 78 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index dbb3f51..95089f2 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ autom4te.cache aclocal.m4 stamp-h1 src/shairplay +src/test/example diff --git a/src/test/example.c b/src/test/example.c index 393b782..e93f252 100644 --- a/src/test/example.c +++ b/src/test/example.c @@ -1,3 +1,15 @@ +/* + * Starts the AirPlay server (name "FakePort") and dumps the received contents + * to files: + * - audio.pcm : decoded audio content + * - metadata.bin : meta data + * - covertart.jpg : cover art + * + * Requires avahi-daemon to run. Also requires file "airplay.key" in the same directory. + * + * Compile with: gcc -o example -g -I../../include/shairplay example.c -lshairplay + */ + #include #include #include @@ -9,6 +21,35 @@ #include "dnssd.h" #include "raop.h" +static int running; + +#ifndef WIN32 + +#include +static void +signal_handler(int sig) +{ + switch (sig) { + case SIGINT: + case SIGTERM: + running = 0; + break; + } +} +static void +init_signals(void) +{ + struct sigaction sigact; + + sigact.sa_handler = signal_handler; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = 0; + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); +} + +#endif + static void * audio_init(void *cls, int bits, int channels, int samplerate) { @@ -75,14 +116,16 @@ raop_log_callback(void *cls, int level, const char *msg) int main(int argc, char *argv[]) { - const char *name = "AppleTV"; - unsigned short raop_port = 5000; - const char hwaddr[] = { 0x48, 0x5d, 0x60, 0x7c, 0xee, 0x22 }; + const char *name = "FakePort"; + unsigned short raop_port = 5000; + const char hwaddr[] = { 0x48, 0x5d, 0x60, 0x7c, 0xee, 0x22 }; dnssd_t *dnssd; raop_t *raop; raop_callbacks_t raop_cbs; + int error; + raop_cbs.cls = NULL; raop_cbs.audio_init = audio_init; raop_cbs.audio_set_volume = audio_set_volume; @@ -93,18 +136,39 @@ main(int argc, char *argv[]) raop_cbs.audio_destroy = audio_destroy; raop = raop_init_from_keyfile(10, &raop_cbs, "airport.key", NULL); + if (raop == NULL) { + fprintf(stderr, "Could not initialize the RAOP service (airport.key missing?)\n"); + return -1; + } + raop_set_log_level(raop, RAOP_LOG_DEBUG); raop_set_log_callback(raop, &raop_log_callback, NULL); - raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr), "test"); + raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr), NULL); + + error = 0; + dnssd = dnssd_init(&error); + if (error) { + fprintf(stderr, "ERROR: Could not initialize dnssd library!\n"); + fprintf(stderr, "------------------------------------------\n"); + fprintf(stderr, "You could try the following resolutions based on your OS:\n"); + fprintf(stderr, "Windows: Try installing http://support.apple.com/kb/DL999\n"); + fprintf(stderr, "Debian/Ubuntu: Try installing libavahi-compat-libdnssd-dev package\n"); + raop_destroy(raop); + return -1; + } - dnssd = dnssd_init(NULL); dnssd_register_raop(dnssd, name, raop_port, hwaddr, sizeof(hwaddr), 1); + printf("Startup complete... Kill with Ctrl+C\n"); + + running = 1; + while (running != 0) { #ifndef WIN32 - sleep(100); + sleep(1); #else - Sleep(100*1000); + Sleep(1000); #endif + } dnssd_unregister_raop(dnssd); dnssd_destroy(dnssd); -- 2.34.1