From: Juho Vähä-Herttua Date: Sun, 18 Mar 2012 20:45:10 +0000 (+0200) Subject: Make some modifications to the API to make bindings easier X-Git-Tag: upstream/0.9.0~4^2~101 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=067f00ef04240a933923b996f27ed037ef09c2e6;p=deb_shairplay.git Make some modifications to the API to make bindings easier --- diff --git a/src/include/dnssd.h b/src/include/dnssd.h index 15576bb..4ad0e34 100644 --- a/src/include/dnssd.h +++ b/src/include/dnssd.h @@ -19,10 +19,10 @@ extern "C" { typedef struct dnssd_s dnssd_t; -DNSSD_API dnssd_t *dnssd_init(const char *hwaddr, int hwaddrlen, int *error); +DNSSD_API dnssd_t *dnssd_init(int *error); -DNSSD_API int dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port); -DNSSD_API int dnssd_register_airplay(dnssd_t *dnssd, const char *name, unsigned short port); +DNSSD_API int dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port, const char *hwaddr, int hwaddrlen); +DNSSD_API int dnssd_register_airplay(dnssd_t *dnssd, const char *name, unsigned short port, const char *hwaddr, int hwaddrlen); DNSSD_API void dnssd_unregister_raop(dnssd_t *dnssd); DNSSD_API void dnssd_unregister_airplay(dnssd_t *dnssd); diff --git a/src/include/raop.h b/src/include/raop.h index 13f60bb..51c8f0a 100644 --- a/src/include/raop.h +++ b/src/include/raop.h @@ -15,7 +15,7 @@ typedef struct raop_s raop_t; struct raop_callbacks_s { void* cls; - void (*audio_init)(void *cls, void **session, int bits, int channels, int samplerate); + void* (*audio_init)(void *cls, int bits, int channels, int samplerate); void (*audio_set_volume)(void *cls, void *session, float volume); void (*audio_process)(void *cls, void *session, const void *buffer, int buflen); void (*audio_flush)(void *cls, void *session); diff --git a/src/lib/dnssd.c b/src/lib/dnssd.c index 3efaa97..3f6d9cf 100644 --- a/src/lib/dnssd.c +++ b/src/lib/dnssd.c @@ -102,9 +102,6 @@ struct dnssd_s { TXTRecordGetBytesPtr_t TXTRecordGetBytesPtr; TXTRecordDeallocate_t TXTRecordDeallocate; - char hwaddr[MAX_HWADDR_LEN]; - int hwaddrlen; - DNSServiceRef raopService; DNSServiceRef airplayService; }; @@ -112,15 +109,11 @@ struct dnssd_s { dnssd_t * -dnssd_init(const char *hwaddr, int hwaddrlen, int *error) +dnssd_init(int *error) { dnssd_t *dnssd; if (error) *error = DNSSD_ERROR_NOERROR; - if (hwaddrlen > MAX_HWADDR_LEN) { - if (error) *error = DNSSD_ERROR_HWADDRLEN; - return NULL; - } dnssd = calloc(1, sizeof(dnssd_t)); if (!dnssd) { @@ -161,9 +154,6 @@ dnssd_init(const char *hwaddr, int hwaddrlen, int *error) dnssd->TXTRecordDeallocate = &TXTRecordDeallocate; #endif - memcpy(dnssd->hwaddr, hwaddr, hwaddrlen); - dnssd->hwaddrlen = hwaddrlen; - return dnssd; } @@ -179,13 +169,15 @@ dnssd_destroy(dnssd_t *dnssd) } int -dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port) +dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port, const char *hwaddr, int hwaddrlen) { TXTRecordRef txtRecord; char servname[MAX_SERVNAME]; int ret; assert(dnssd); + assert(name); + assert(hwaddr); dnssd->TXTRecordCreate(&txtRecord, 0, NULL); dnssd->TXTRecordSetValue(&txtRecord, "txtvers", strlen(RAOP_TXTVERS), RAOP_TXTVERS); @@ -205,7 +197,7 @@ dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port) dnssd->TXTRecordSetValue(&txtRecord, "sf", strlen(RAOP_SF), RAOP_SF); /* Convert hardware address to string */ - ret = utils_hwaddr_raop(servname, sizeof(servname), dnssd->hwaddr, dnssd->hwaddrlen); + ret = utils_hwaddr_raop(servname, sizeof(servname), hwaddr, hwaddrlen); if (ret < 0) { /* FIXME: handle better */ return -1; @@ -235,7 +227,7 @@ dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port) } int -dnssd_register_airplay(dnssd_t *dnssd, const char *name, unsigned short port) +dnssd_register_airplay(dnssd_t *dnssd, const char *name, unsigned short port, const char *hwaddr, int hwaddrlen) { TXTRecordRef txtRecord; char deviceid[3*MAX_HWADDR_LEN]; @@ -243,9 +235,11 @@ dnssd_register_airplay(dnssd_t *dnssd, const char *name, unsigned short port) int ret; assert(dnssd); + assert(name); + assert(hwaddr); /* Convert hardware address to string */ - ret = utils_hwaddr_airplay(deviceid, sizeof(deviceid), dnssd->hwaddr, dnssd->hwaddrlen); + ret = utils_hwaddr_airplay(deviceid, sizeof(deviceid), hwaddr, hwaddrlen); if (ret < 0) { /* FIXME: handle better */ return -1; diff --git a/src/lib/dnssd.m b/src/lib/dnssd.m index ef69178..5f87b1f 100644 --- a/src/lib/dnssd.m +++ b/src/lib/dnssd.m @@ -24,32 +24,22 @@ #define MAX_SERVNAME 256 struct dnssd_s { - char hwaddr[MAX_HWADDR_LEN]; - int hwaddrlen; - NSNetService *raopService; NSNetService *airplayService; }; dnssd_t * -dnssd_init(const char *hwaddr, int hwaddrlen, int *error) +dnssd_init(int *error) { dnssd_t *dnssd; if (error) *error = DNSSD_ERROR_NOERROR; - if (hwaddrlen > MAX_HWADDR_LEN) { - if (error) *error = DNSSD_ERROR_HWADDRLEN; - return NULL; - } dnssd = calloc(1, sizeof(dnssd_t)); if (!dnssd) { if (error) *error = DNSSD_ERROR_OUTOFMEM; return NULL; } - memcpy(dnssd->hwaddr, hwaddr, hwaddrlen); - dnssd->hwaddrlen = hwaddrlen; - return dnssd; } @@ -60,7 +50,7 @@ dnssd_destroy(dnssd_t *dnssd) } int -dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port) +dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port, const char *hwaddr, int hwaddrlen) { char hwaddrstr[MAX_SERVNAME]; NSString *serviceString; @@ -75,7 +65,7 @@ dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port) } /* Convert the hardware address to string */ - ret = utils_hwaddr_raop(hwaddrstr, sizeof(hwaddrstr), dnssd->hwaddr, dnssd->hwaddrlen); + ret = utils_hwaddr_raop(hwaddrstr, sizeof(hwaddrstr), hwaddr, hwaddrlen); if (ret < 0) { return -2; } @@ -110,7 +100,7 @@ dnssd_register_raop(dnssd_t *dnssd, const char *name, unsigned short port) } int -dnssd_register_airplay(dnssd_t *dnssd, const char *name, unsigned short port) +dnssd_register_airplay(dnssd_t *dnssd, const char *name, unsigned short port, const char *hwaddr, int hwaddrlen) { NSMutableDictionary *txtDict; NSData *txtData; @@ -125,7 +115,7 @@ dnssd_register_airplay(dnssd_t *dnssd, const char *name, unsigned short port) } /* Convert hardware address to string */ - ret = utils_hwaddr_airplay(deviceid, sizeof(deviceid), dnssd->hwaddr, dnssd->hwaddrlen); + ret = utils_hwaddr_airplay(deviceid, sizeof(deviceid), hwaddr, hwaddrlen); if (ret < 0) { return -2; } diff --git a/src/lib/raop_rtp.c b/src/lib/raop_rtp.c index 607e760..205eee9 100644 --- a/src/lib/raop_rtp.c +++ b/src/lib/raop_rtp.c @@ -247,7 +247,7 @@ raop_rtp_thread_udp(void *arg) assert(raop_rtp); config = raop_buffer_get_config(raop_rtp->buffer); - raop_rtp->callbacks.audio_init(raop_rtp->callbacks.cls, &cb_data, + cb_data = raop_rtp->callbacks.audio_init(raop_rtp->callbacks.cls, config->bitDepth, config->numChannels, config->sampleRate); @@ -376,7 +376,7 @@ raop_rtp_thread_tcp(void *arg) assert(raop_rtp); config = raop_buffer_get_config(raop_rtp->buffer); - raop_rtp->callbacks.audio_init(raop_rtp->callbacks.cls, &cb_data, + cb_data = raop_rtp->callbacks.audio_init(raop_rtp->callbacks.cls, config->bitDepth, config->numChannels, config->sampleRate); diff --git a/src/test/dnssd_test.c b/src/test/dnssd_test.c index 7e329c4..9e5b4fc 100644 --- a/src/test/dnssd_test.c +++ b/src/test/dnssd_test.c @@ -26,13 +26,13 @@ main(int argc, char *argv[]) } #endif - dnssd = dnssd_init(hwaddr, sizeof(hwaddr), NULL); + dnssd = dnssd_init(NULL); if (!dnssd) { printf("Failed to init dnssd\n"); return -1; } - dnssd_register_raop(dnssd, "Test", 5000); - dnssd_register_airplay(dnssd, "Test", 6000); + dnssd_register_raop(dnssd, "Test", 5000, hwaddr, sizeof(hwaddr)); + dnssd_register_airplay(dnssd, "Test", 6000, hwaddr, sizeof(hwaddr)); sleepms(60000); diff --git a/src/test/dnssd_test.m b/src/test/dnssd_test.m index d4ccbe2..d05040b 100644 --- a/src/test/dnssd_test.m +++ b/src/test/dnssd_test.m @@ -13,13 +13,13 @@ main(int argc, char *argv[]) const char hwaddr[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB }; dnssd_t *dnssd; - dnssd = dnssd_init(hwaddr, sizeof(hwaddr), NULL); + dnssd = dnssd_init(NULL); if (!dnssd) { printf("Failed to init dnssd\n"); return -1; } - dnssd_register_raop(dnssd, "Test", 5000); - dnssd_register_airplay(dnssd, "Test", 6000); + dnssd_register_raop(dnssd, "Test", 5000, hwaddr, sizeof(hwaddr)); + dnssd_register_airplay(dnssd, "Test", 6000, hwaddr, sizeof(hwaddr)); sleepms(60000); diff --git a/src/test/example.c b/src/test/example.c index 98c6fcd..41beb56 100644 --- a/src/test/example.c +++ b/src/test/example.c @@ -9,10 +9,10 @@ #include "dnssd.h" #include "raop.h" -static void -audio_init(void *cls, void **session, int bits, int channels, int samplerate) +static void * +audio_init(void *cls, int bits, int channels, int samplerate) { - *session = fopen("audio.pcm", "wb"); + return fopen("audio.pcm", "wb"); } static void @@ -63,8 +63,8 @@ main(int argc, char *argv[]) raop = raop_init_from_keyfile(&raop_cbs, "airport.key"); raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr)); - dnssd = dnssd_init(hwaddr, sizeof(hwaddr), NULL); - dnssd_register_raop(dnssd, name, raop_port); + dnssd = dnssd_init(NULL); + dnssd_register_raop(dnssd, name, raop_port, hwaddr, sizeof(hwaddr)); #ifndef WIN32 sleep(100);