Relicense bindings as MIT License
[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
24static void
25audio_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
33static void
34audio_flush(void *cls, void *session)
35{
36 printf("Flushing audio\n");
37}
38
39static void
40audio_destroy(void *cls, void *session)
41{
42 fclose(session);
43}
44
45int
46main(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
406e9777
JVH
63 raop = raop_init_from_keyfile(&raop_cbs, "airport.key");
64 raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr));
2340bcd3 65
067f00ef
JVH
66 dnssd = dnssd_init(NULL);
67 dnssd_register_raop(dnssd, name, raop_port, hwaddr, sizeof(hwaddr));
2340bcd3 68
979533c3 69#ifndef WIN32
2340bcd3 70 sleep(100);
979533c3
JVH
71#else
72 Sleep(100*1000);
73#endif
2340bcd3
JVH
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