2 * Starts the AirPlay server (name "FakePort") and dumps the received contents
4 * - audio.pcm : decoded audio content
5 * - metadata.bin : meta data
6 * - covertart.jpg : cover art
8 * Requires avahi-daemon to run. Also requires file "airplay.key" in the same directory.
10 * Compile with: gcc -o example -g -I../../include/shairplay example.c -lshairplay
30 signal_handler(int sig
)
42 struct sigaction sigact
;
44 sigact
.sa_handler
= signal_handler
;
45 sigemptyset(&sigact
.sa_mask
);
47 sigaction(SIGINT
, &sigact
, NULL
);
48 sigaction(SIGTERM
, &sigact
, NULL
);
54 audio_init(void *cls
, int bits
, int channels
, int samplerate
)
56 return fopen("audio.pcm", "wb");
60 audio_set_volume(void *cls
, void *session
, float volume
)
62 printf("Setting volume to %f\n", volume
);
66 audio_set_metadata(void *cls
, void *session
, const void *buffer
, int buflen
)
69 FILE *file
= fopen("metadata.bin", "wb");
71 buflen
-= fwrite(buffer
+orig
-buflen
, 1, buflen
, file
);
74 printf("Metadata of length %d saved as metadata.bin\n", orig
);
78 audio_set_coverart(void *cls
, void *session
, const void *buffer
, int buflen
)
81 FILE *file
= fopen("coverart.jpg", "wb");
83 buflen
-= fwrite(buffer
+orig
-buflen
, 1, buflen
, file
);
86 printf("Coverart of length %d saved as coverart.jpg\n", orig
);
90 audio_process(void *cls
, void *session
, const void *buffer
, int buflen
)
94 buflen
-= fwrite(buffer
+orig
-buflen
, 1, buflen
, session
);
99 audio_flush(void *cls
, void *session
)
101 printf("Flushing audio\n");
105 audio_destroy(void *cls
, void *session
)
111 raop_log_callback(void *cls
, int level
, const char *msg
)
113 printf("RAOP LOG(%d): %s\n", level
, msg
);
117 main(int argc
, char *argv
[])
119 const char *name
= "FakePort";
120 unsigned short raop_port
= 5000;
121 const char hwaddr
[] = { 0x48, 0x5d, 0x60, 0x7c, 0xee, 0x22 };
125 raop_callbacks_t raop_cbs
;
130 raop_cbs
.audio_init
= audio_init
;
131 raop_cbs
.audio_set_volume
= audio_set_volume
;
132 raop_cbs
.audio_set_metadata
= audio_set_metadata
;
133 raop_cbs
.audio_set_coverart
= audio_set_coverart
;
134 raop_cbs
.audio_process
= audio_process
;
135 raop_cbs
.audio_flush
= audio_flush
;
136 raop_cbs
.audio_destroy
= audio_destroy
;
138 raop
= raop_init_from_keyfile(10, &raop_cbs
, "airport.key", NULL
);
140 fprintf(stderr
, "Could not initialize the RAOP service (airport.key missing?)\n");
144 raop_set_log_level(raop
, RAOP_LOG_DEBUG
);
145 raop_set_log_callback(raop
, &raop_log_callback
, NULL
);
146 raop_start(raop
, &raop_port
, hwaddr
, sizeof(hwaddr
), NULL
);
149 dnssd
= dnssd_init(&error
);
151 fprintf(stderr
, "ERROR: Could not initialize dnssd library!\n");
152 fprintf(stderr
, "------------------------------------------\n");
153 fprintf(stderr
, "You could try the following resolutions based on your OS:\n");
154 fprintf(stderr
, "Windows: Try installing http://support.apple.com/kb/DL999\n");
155 fprintf(stderr
, "Debian/Ubuntu: Try installing libavahi-compat-libdnssd-dev package\n");
160 dnssd_register_raop(dnssd
, name
, raop_port
, hwaddr
, sizeof(hwaddr
), 1);
162 printf("Startup complete... Kill with Ctrl+C\n");
165 while (running
!= 0) {
173 dnssd_unregister_raop(dnssd
);
174 dnssd_destroy(dnssd
);