X-Git-Url: https://git.piment-noir.org/?p=deb_shairplay.git;a=blobdiff_plain;f=src%2Ftest%2Fexample.c;fp=src%2Ftest%2Fexample.c;h=e93f252cd9b70dd9ea2195d5cea0f081a8690ec3;hp=393b7820efef6ea0dc7f5d1ee9a893dffe7a4817;hb=aaf0290d2e892ed2edb16441495094abb45e6fa6;hpb=aab90761cc68dfa33e13187e212eeea29a8da4fd 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);