+'''
+ Copyright (C) 2012 Juho Vähä-Herttua
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+'''
+
import os
import sys
import platform
# Initialize dnssd related functions
libshairplay.dnssd_init.restype = c_void_p
- libshairplay.dnssd_init.argtypes = [POINTER(c_char), c_int, POINTER(c_int)]
+ libshairplay.dnssd_init.argtypes = [POINTER(c_int)]
libshairplay.dnssd_register_raop.restype = c_int
- libshairplay.dnssd_register_raop.argtypes = [c_void_p, c_char_p, c_ushort]
+ libshairplay.dnssd_register_raop.argtypes = [c_void_p, c_char_p, c_ushort, POINTER(c_char), c_int]
libshairplay.dnssd_register_airplay.restype = c_int
- libshairplay.dnssd_register_airplay.argtypes = [c_void_p, c_char_p, c_ushort]
+ libshairplay.dnssd_register_airplay.argtypes = [c_void_p, c_char_p, c_ushort, POINTER(c_char), c_int]
libshairplay.dnssd_unregister_raop.restype = None
libshairplay.dnssd_unregister_raop.argtypes = [c_void_p]
libshairplay.dnssd_unregister_airplay.restype = None
self.libshairplay = libshairplay
self.instance = None
- hwaddr = (c_char * 6)()
error = c_int(0)
- self.instance = self.libshairplay.dnssd_init(hwaddr, c_int(len(hwaddr)), pointer(error))
+ self.instance = self.libshairplay.dnssd_init(pointer(error))
if self.instance == None:
raise RuntimeError("Initializing library failed: " + str(error.value))
self.libshairplay.dnssd_destroy(self.instance)
self.instance = None
- def register_raop(self, name, port):
- self.libshairplay.dnssd_register_raop(self.instance, name, c_ushort(port))
+ def register_raop(self, name, port, hwaddrstr):
+ hwaddr = create_string_buffer(hwaddrstr, len(hwaddrstr))
+ self.libshairplay.dnssd_register_raop(self.instance, name, c_ushort(port), hwaddr, len(hwaddr))
def unregister_raop(self):
self.libshairplay.dnssd_unregister_raop(self.instance)
- def register_airplay(self, name, port):
- self.libshairplay.dnssd_register_airplay(self.instance, name, c_ushort(port))
+ def register_airplay(self, name, port, hwaddrstr):
+ hwaddr = create_string_buffer(hwaddrstr, len(hwaddrstr))
+ self.libshairplay.dnssd_register_airplay(self.instance, name, c_ushort(port), hwaddr, len(hwaddr))
def unregister_airplay(self):
self.libshairplay.dnssd_unregister_airplay(self.instance)
from Shairplay import *
hwaddr = pack('BBBBBB', 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB)
+class SampleCallbacks(RaopCallbacks):
+ def audio_init(self, bits, channels, samplerate):
+ print "Initializing " + str(bits) + " " + str(channels) + " " + str(samplerate)
+ def audio_process(self, session, buffer):
+ print "Processing " + str(len(buffer)) + " bytes of audio"
shairplay = LoadShairplay(".")
+callbacks = SampleCallbacks()
-raop = RaopService(shairplay, RaopCallbacks())
+raop = RaopService(shairplay, callbacks)
port = raop.start(5000, hwaddr)
dnssd = DnssdService(shairplay)
-dnssd.register_raop("RAOP test", port)
+dnssd.register_raop("RAOP test", port, hwaddr)
time.sleep(50)
dnssd.unregister_raop()
raop.stop()
+
+del dnssd
del raop