Commit | Line | Data |
---|---|---|
2340bcd3 JVH |
1 | #include <stdlib.h> |
2 | #include <stdio.h> | |
3 | #include <unistd.h> | |
4 | ||
979533c3 JVH |
5 | #ifdef WIN32 |
6 | #include <windows.h> | |
7 | #endif | |
8 | ||
2340bcd3 JVH |
9 | #include "dnssd.h" |
10 | #include "raop.h" | |
11 | ||
067f00ef JVH |
12 | static void * |
13 | audio_init(void *cls, int bits, int channels, int samplerate) | |
2340bcd3 | 14 | { |
067f00ef | 15 | return fopen("audio.pcm", "wb"); |
2340bcd3 JVH |
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 | ||
b4cc5b07 JVH |
24 | static void |
25 | audio_set_metadata(void *cls, void *session, const void *buffer, int buflen) | |
26 | { | |
27 | int orig = buflen; | |
28 | FILE *file = fopen("metadata.bin", "wb"); | |
29 | while (buflen > 0) { | |
30 | buflen -= fwrite(buffer+orig-buflen, 1, buflen, file); | |
31 | } | |
32 | fclose(file); | |
33 | printf("Metadata of length %d saved as metadata.bin\n", orig); | |
34 | } | |
35 | ||
36 | static void | |
37 | audio_set_coverart(void *cls, void *session, const void *buffer, int buflen) | |
38 | { | |
39 | int orig = buflen; | |
40 | FILE *file = fopen("coverart.jpg", "wb"); | |
41 | while (buflen > 0) { | |
42 | buflen -= fwrite(buffer+orig-buflen, 1, buflen, file); | |
43 | } | |
44 | fclose(file); | |
45 | printf("Coverart of length %d saved as coverart.jpg\n", orig); | |
46 | } | |
47 | ||
2340bcd3 JVH |
48 | static void |
49 | audio_process(void *cls, void *session, const void *buffer, int buflen) | |
50 | { | |
51 | int orig = buflen; | |
52 | while (buflen > 0) { | |
53 | buflen -= fwrite(buffer+orig-buflen, 1, buflen, session); | |
54 | } | |
55 | } | |
56 | ||
57 | static void | |
58 | audio_flush(void *cls, void *session) | |
59 | { | |
60 | printf("Flushing audio\n"); | |
61 | } | |
62 | ||
63 | static void | |
64 | audio_destroy(void *cls, void *session) | |
65 | { | |
66 | fclose(session); | |
67 | } | |
68 | ||
fda63ad4 JVH |
69 | static void |
70 | raop_log_callback(int level, const char *msg) | |
71 | { | |
72 | printf("RAOP LOG(%d): %s\n", level, msg); | |
73 | } | |
74 | ||
2340bcd3 JVH |
75 | int |
76 | main(int argc, char *argv[]) | |
77 | { | |
78 | const char *name = "AppleTV"; | |
79 | unsigned short raop_port = 5000; | |
80 | const char hwaddr[] = { 0x48, 0x5d, 0x60, 0x7c, 0xee, 0x22 }; | |
81 | ||
82 | dnssd_t *dnssd; | |
83 | raop_t *raop; | |
84 | raop_callbacks_t raop_cbs; | |
85 | ||
86 | raop_cbs.cls = NULL; | |
87 | raop_cbs.audio_init = audio_init; | |
88 | raop_cbs.audio_set_volume = audio_set_volume; | |
b4cc5b07 JVH |
89 | raop_cbs.audio_set_metadata = audio_set_metadata; |
90 | raop_cbs.audio_set_coverart = audio_set_coverart; | |
2340bcd3 JVH |
91 | raop_cbs.audio_process = audio_process; |
92 | raop_cbs.audio_flush = audio_flush; | |
93 | raop_cbs.audio_destroy = audio_destroy; | |
94 | ||
72fe063c | 95 | raop = raop_init_from_keyfile(10, &raop_cbs, "airport.key"); |
fda63ad4 JVH |
96 | raop_set_log_level(raop, RAOP_LOG_DEBUG); |
97 | raop_set_log_callback(raop, &raop_log_callback); | |
e4169f77 | 98 | raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr), "test"); |
2340bcd3 | 99 | |
067f00ef | 100 | dnssd = dnssd_init(NULL); |
e4169f77 | 101 | dnssd_register_raop(dnssd, name, raop_port, hwaddr, sizeof(hwaddr), 1); |
2340bcd3 | 102 | |
979533c3 | 103 | #ifndef WIN32 |
2340bcd3 | 104 | sleep(100); |
979533c3 JVH |
105 | #else |
106 | Sleep(100*1000); | |
107 | #endif | |
2340bcd3 JVH |
108 | |
109 | dnssd_unregister_raop(dnssd); | |
110 | dnssd_destroy(dnssd); | |
111 | ||
112 | raop_stop(raop); | |
113 | raop_destroy(raop); | |
114 | ||
115 | return 0; | |
116 | } | |
117 |