from ctypes import *
+class RaopLogLevel:
+ EMERG = 0
+ ALERT = 1
+ CRIT = 2
+ ERR = 3
+ WARNING = 4
+ NOTICE = 5
+ INFO = 6
+ DEBUG = 7
+
+raop_log_callback_prototype = CFUNCTYPE(None, c_int, c_char_p)
+
audio_init_prototype = CFUNCTYPE(py_object, c_void_p, c_int, c_int, c_int)
audio_process_prototype = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p, c_int)
audio_destroy_prototype = CFUNCTYPE(None, c_void_p, c_void_p)
# Initialize raop related functions
libshairplay.raop_init.restype = c_void_p
libshairplay.raop_init.argtypes = [c_int, POINTER(RaopNativeCallbacks), c_char_p]
+ libshairplay.raop_set_log_level.restype = None
+ libshairplay.raop_set_log_level.argtypes = [c_void_p, c_int]
+ libshairplay.raop_set_log_callback.restype = None
+ libshairplay.raop_set_log_callback.argtypes = [c_void_p, raop_log_callback_prototype]
libshairplay.raop_is_running.restype = c_int
libshairplay.raop_is_running.argtypes = [c_void_p]
libshairplay.raop_start.restype = c_int
pass
class RaopService:
+ def log_callback_cb(self, level, message):
+ if self.log_callback != None:
+ self.log_callback(level, message)
+ else:
+ print message
+
def audio_init_cb(self, cls, bits, channels, samplerate):
session = self.callbacks.audio_init(bits, channels, samplerate)
self.sessions.append(session)
if self.instance == None:
raise RuntimeError("Initializing library failed")
+ # We need to hold a reference to the log callback wrapper
+ self.log_callback_pointer = raop_log_callback_prototype(self.log_callback_cb)
+ self.libshairplay.raop_set_log_callback(self.instance, self.log_callback_pointer)
+ self.log_callback = None
+
def __del__(self):
if self.instance != None:
self.libshairplay.raop_destroy(self.instance)
else:
return False
+ def set_log_level(self, level):
+ self.libshairplay.raop_set_log_level(self.instance, level)
+
+ def set_log_callback(self, log_callback):
+ self.log_callback = log_callback
+
def start(self, port, hwaddrstr, password=None):
port = c_ushort(port)
hwaddr = create_string_buffer(hwaddrstr, len(hwaddrstr))
shairplay = LoadShairplay(".")
callbacks = SampleCallbacks()
+def log_callback(level, message):
+ print "Level", level, ":", message
+
raop = RaopService(shairplay, 10, callbacks)
+raop.set_log_level(RaopLogLevel.DEBUG)
+raop.set_log_callback(log_callback)
port = raop.start(5000, hwaddr)
dnssd = DnssdService(shairplay)