Update the python bindings to work with current version
authorJuho Vähä-Herttua <juhovh@iki.fi>
Sun, 18 Mar 2012 21:08:42 +0000 (23:08 +0200)
committerJuho Vähä-Herttua <juhovh@iki.fi>
Wed, 16 May 2012 21:33:32 +0000 (00:33 +0300)
src/bindings/python/Shairplay.py
src/test/test.py

index 020eb8fb6d33d013a0bad6abdca43b5eed9534a7..35142f196a39d5bcc69ae125018b95fe06a3e6b7 100644 (file)
@@ -1,3 +1,17 @@
+'''
+       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
@@ -39,11 +53,11 @@ def LoadShairplay(path):
 
        # 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
@@ -168,10 +182,9 @@ class DnssdService:
                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))
 
@@ -180,14 +193,16 @@ class DnssdService:
                        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)
index d8ffd13cad8d84ac32443804d76135644ce84623..4340ca11b8f750c46ab150339c0c26480efbe287 100644 (file)
@@ -3,18 +3,26 @@ from struct import *
 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