Update the python bindings to the latest API version
authorJuho Vähä-Herttua <juhovh@iki.fi>
Fri, 18 May 2012 20:11:45 +0000 (23:11 +0300)
committerJuho Vähä-Herttua <juhovh@iki.fi>
Fri, 18 May 2012 20:43:32 +0000 (23:43 +0300)
src/SConscript
src/bindings/python/Shairplay.py
src/test/test.py

index f09dd22812527cee53f1e184dcba75d07f8e27fc..536cc06e6e882ef3de9732432b8098bc06ed3f45 100644 (file)
@@ -6,6 +6,10 @@ env.Append(CPPPATH = ['include'])
 
 # Set up the environment for compiling the libraries
 libenv = env.Clone()
+conf = Configure(libenv)
+conf.CheckLib('pthread')
+conf.CheckLib('dns_sd')
+libenv = conf.Finish()
 libenv.Append(CPPPATH = ['lib'])
 
 # Make sure libraries are compiled with DLL_EXPORT on windows
index 04dbb37c4952046e5b978d44810e86cffdaab84a..1396524c0852074ae01e244dc84366187855eb6d 100644 (file)
@@ -28,19 +28,24 @@ import platform
 
 from ctypes import *
 
-audio_init_prototype =        CFUNCTYPE(py_object, c_void_p, c_int, c_int, c_int)
-audio_set_volume_prototype =  CFUNCTYPE(None, c_void_p, c_void_p, c_float)
-audio_process_prototype =     CFUNCTYPE(None, c_void_p, c_void_p, c_void_p, c_int)
-audio_flush_prototype =       CFUNCTYPE(None, c_void_p, c_void_p)
-audio_destroy_prototype =     CFUNCTYPE(None, c_void_p, c_void_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)
+
+audio_flush_prototype =         CFUNCTYPE(None, c_void_p, c_void_p)
+audio_set_volume_prototype =    CFUNCTYPE(None, c_void_p, c_void_p, c_float)
+audio_set_metadata_prototype =  CFUNCTYPE(None, c_void_p, c_void_p, c_void_p, c_int)
+audio_set_coverart_prototype =  CFUNCTYPE(None, c_void_p, c_void_p, c_void_p, c_int)
 
 class RaopNativeCallbacks(Structure):
-       _fields_ = [("cls",               py_object),
-                   ("audio_init",        audio_init_prototype),
-                   ("audio_set_volume",  audio_set_volume_prototype),
-                   ("audio_process",     audio_process_prototype),
-                   ("audio_flush",       audio_flush_prototype),
-                   ("audio_destroy",     audio_destroy_prototype)]
+       _fields_ = [("cls",                 py_object),
+                   ("audio_init",          audio_init_prototype),
+                   ("audio_process",       audio_process_prototype),
+                   ("audio_destroy",       audio_destroy_prototype),
+                   ("audio_flush",         audio_flush_prototype),
+                   ("audio_set_volume",    audio_set_volume_prototype),
+                   ("audio_set_metadata",  audio_set_metadata_prototype),
+                   ("audio_set_coverart",  audio_set_coverart_prototype)]
 
 def InitShairplay(libshairplay):
        # Initialize dnssd related functions
@@ -59,7 +64,7 @@ def InitShairplay(libshairplay):
 
        # Initialize raop related functions
        libshairplay.raop_init.restype = c_void_p
-       libshairplay.raop_init.argtypes = [POINTER(RaopNativeCallbacks), c_char_p]
+       libshairplay.raop_init.argtypes = [c_int, POINTER(RaopNativeCallbacks), c_char_p]
        libshairplay.raop_is_running.restype = c_int
        libshairplay.raop_is_running.argtypes = [c_void_p]
        libshairplay.raop_start.restype = c_int
@@ -121,16 +126,22 @@ class RaopCallbacks:
        def audio_init(self, bits, channels, samplerate):
                raise NotImplementedError()
 
-       def audio_set_volume(self, session, volume):
-               pass
-
        def audio_process(self, session, buffer):
                raise NotImplementedError()
 
+       def audio_destroy(self, session):
+               raise NotImplementedError()
+
+       def audio_set_volume(self, session, volume):
+               pass
+
        def audio_flush(self, session):
                pass
 
-       def audio_destroy(self, session):
+       def audio_set_metadata(self, session, buffer):
+               pass
+
+       def audio_set_coverart(self, session, buffer):
                pass
 
 class RaopService:
@@ -139,27 +150,37 @@ class RaopService:
                self.sessions.append(session)
                return session
 
-       def audio_set_volume_cb(self, cls, sessionptr, volume):
-               session = cast(sessionptr, py_object).value
-               self.callbacks.audio_set_volume(session, volume)
-
        def audio_process_cb(self, cls, sessionptr, buffer, buflen):
                session = cast(sessionptr, py_object).value
                strbuffer = string_at(buffer, buflen)
                self.callbacks.audio_process(session, strbuffer)
 
-       def audio_flush_cb(self, cls, sessionptr):
-               session = cast(sessionptr, py_object).value
-               self.callbacks.audio_flush(session)
-
        def audio_destroy_cb(self, cls, sessionptr):
                session = cast(sessionptr, py_object).value
                self.callbacks.audio_destroy(session)
                if session in self.sessions:
                        self.sessions.remove(session)
 
+       def audio_flush_cb(self, cls, sessionptr):
+               session = cast(sessionptr, py_object).value
+               self.callbacks.audio_flush(session)
+
+       def audio_set_volume_cb(self, cls, sessionptr, volume):
+               session = cast(sessionptr, py_object).value
+               self.callbacks.audio_set_volume(session, volume)
 
-       def __init__(self, libshairplay, callbacks):
+       def audio_set_metadata_cb(self, cls, sessionptr, buffer, buflen):
+               session = cast(sessionptr, py_object).value
+               strbuffer = string_at(buffer, buflen)
+               self.callbacks.audio_set_metadata(session, strbuffer)
+
+       def audio_set_coverart_cb(self, cls, sessionptr, buffer, buflen):
+               session = cast(sessionptr, py_object).value
+               strbuffer = string_at(buffer, buflen)
+               self.callbacks.audio_set_coverart(session, strbuffer)
+
+
+       def __init__(self, libshairplay, max_clients, callbacks):
                self.libshairplay = libshairplay
                self.callbacks = callbacks
                self.sessions = []
@@ -168,13 +189,15 @@ class RaopService:
                # We need to hold a reference to native_callbacks
                self.native_callbacks = RaopNativeCallbacks()
                self.native_callbacks.audio_init = audio_init_prototype(self.audio_init_cb)
-               self.native_callbacks.audio_set_volume = audio_set_volume_prototype(self.audio_set_volume_cb)
                self.native_callbacks.audio_process = audio_process_prototype(self.audio_process_cb)
-               self.native_callbacks.audio_flush = audio_flush_prototype(self.audio_flush_cb)
                self.native_callbacks.audio_destroy = audio_destroy_prototype(self.audio_destroy_cb)
+               self.native_callbacks.audio_flush = audio_flush_prototype(self.audio_flush_cb)
+               self.native_callbacks.audio_set_volume = audio_set_volume_prototype(self.audio_set_volume_cb)
+               self.native_callbacks.audio_set_metadata = audio_set_metadata_prototype(self.audio_set_metadata_cb)
+               self.native_callbacks.audio_set_coverart = audio_set_coverart_prototype(self.audio_set_coverart_cb)
 
                # Initialize the raop instance with our callbacks
-               self.instance = self.libshairplay.raop_init(pointer(self.native_callbacks), RSA_KEY)
+               self.instance = self.libshairplay.raop_init(max_clients, pointer(self.native_callbacks), RSA_KEY)
                if self.instance == None:
                        raise RuntimeError("Initializing library failed")
 
index 4340ca11b8f750c46ab150339c0c26480efbe287..227321ac07c1f17b215ca4aab97c8694d6023b9f 100644 (file)
@@ -5,14 +5,22 @@ 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)
+               print "Initializing", bits, channels, samplerate
        def audio_process(self, session, buffer):
-               print "Processing " + str(len(buffer)) + " bytes of audio"
+               print "Processing", + len(buffer), "bytes of audio"
+       def audio_destroy(self, session):
+               print "Destroying"
+       def audio_set_volume(self, session, volume):
+               print "Set volume to", volume
+       def audio_set_metadata(self, session, metadata):
+               print "Got", len(metadata),  "bytes of metadata"
+       def audio_set_coverart(self, session, coverart):
+               print "Got", len(coverart), "bytes of coverart"
 
 shairplay = LoadShairplay(".")
 callbacks = SampleCallbacks()
 
-raop = RaopService(shairplay, callbacks)
+raop = RaopService(shairplay, 10, callbacks)
 port = raop.start(5000, hwaddr)
 
 dnssd = DnssdService(shairplay)