Make the maximum number of clients configurable
[deb_shairplay.git] / src / test / example.c
CommitLineData
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
12static void *
13audio_init(void *cls, int bits, int channels, int samplerate)
2340bcd3 14{
067f00ef 15 return fopen("audio.pcm", "wb");
2340bcd3
JVH
16}
17
18static void
19audio_set_volume(void *cls, void *session, float volume)
20{
21 printf("Setting volume to %f\n", volume);
22}
23
b4cc5b07
JVH
24static void
25audio_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
36static void
37audio_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
48static void
49audio_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
57static void
58audio_flush(void *cls, void *session)
59{
60 printf("Flushing audio\n");
61}
62
63static void
64audio_destroy(void *cls, void *session)
65{
66 fclose(session);
67}
68
fda63ad4
JVH
69static void
70raop_log_callback(int level, const char *msg)
71{
72 printf("RAOP LOG(%d): %s\n", level, msg);
73}
74
2340bcd3
JVH
75int
76main(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