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);
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);
TXTRecordGetBytesPtr_t TXTRecordGetBytesPtr;
TXTRecordDeallocate_t TXTRecordDeallocate;
- char hwaddr[MAX_HWADDR_LEN];
- int hwaddrlen;
-
DNSServiceRef raopService;
DNSServiceRef 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) {
dnssd->TXTRecordDeallocate = &TXTRecordDeallocate;
#endif
- memcpy(dnssd->hwaddr, hwaddr, hwaddrlen);
- dnssd->hwaddrlen = hwaddrlen;
-
return 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);
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;
}
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];
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;
#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;
}
}
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;
}
/* 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;
}
}
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;
}
/* 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;
}
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);
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);
}
#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);
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);
#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
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);