Pass metadata and coverart to the RTP thread
[deb_shairplay.git] / src / test / example.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
4
5 #ifdef WIN32
6 #include <windows.h>
7 #endif
8
9 #include "dnssd.h"
10 #include "raop.h"
11
12 static void *
13 audio_init(void *cls, int bits, int channels, int samplerate)
14 {
15 return fopen("audio.pcm", "wb");
16 }
17
18 static void
19 audio_set_volume(void *cls, void *session, float volume)
20 {
21 printf("Setting volume to %f\n", volume);
22 }
23
24 static void
25 audio_process(void *cls, void *session, const void *buffer, int buflen)
26 {
27 int orig = buflen;
28 while (buflen > 0) {
29 buflen -= fwrite(buffer+orig-buflen, 1, buflen, session);
30 }
31 }
32
33 static void
34 audio_flush(void *cls, void *session)
35 {
36 printf("Flushing audio\n");
37 }
38
39 static void
40 audio_destroy(void *cls, void *session)
41 {
42 fclose(session);
43 }
44
45 int
46 main(int argc, char *argv[])
47 {
48 const char *name = "AppleTV";
49 unsigned short raop_port = 5000;
50 const char hwaddr[] = { 0x48, 0x5d, 0x60, 0x7c, 0xee, 0x22 };
51
52 dnssd_t *dnssd;
53 raop_t *raop;
54 raop_callbacks_t raop_cbs;
55
56 raop_cbs.cls = NULL;
57 raop_cbs.audio_init = audio_init;
58 raop_cbs.audio_set_volume = audio_set_volume;
59 raop_cbs.audio_process = audio_process;
60 raop_cbs.audio_flush = audio_flush;
61 raop_cbs.audio_destroy = audio_destroy;
62
63 raop = raop_init_from_keyfile(&raop_cbs, "airport.key");
64 raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr), "test");
65
66 dnssd = dnssd_init(NULL);
67 dnssd_register_raop(dnssd, name, raop_port, hwaddr, sizeof(hwaddr), 1);
68
69 #ifndef WIN32
70 sleep(100);
71 #else
72 Sleep(100*1000);
73 #endif
74
75 dnssd_unregister_raop(dnssd);
76 dnssd_destroy(dnssd);
77
78 raop_stop(raop);
79 raop_destroy(raop);
80
81 return 0;
82 }
83