#define ENDIAN_FLAGS 0
#endif
-static void osx_write_open(struct writer_node *wn)
+static void osx_write_open(__a_unused struct writer_node *wn)
{
- struct private_osx_write_data *powd = para_calloc(sizeof(*powd));
-
- wn->private_data = powd;
- init_buffers(wn);
}
static int core_audio_init(struct writer_node *wn)
{
- struct private_osx_write_data *powd = wn->private_data;
+ struct private_osx_write_data *powd = para_calloc(sizeof(*powd));
ComponentDescription desc;
Component comp;
AURenderCallbackStruct inputCallback = {osx_callback, powd};
struct btr_node *btrn = wn->btrn;
int32_t val;
+ wn->private_data = powd;
+ init_buffers(wn);
/* where did that default audio output go? */
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
e1:
CloseComponent(powd->audio_unit);
e0:
+ free(powd);
+ wn->private_data = NULL;
return ret;
}
{
struct private_osx_write_data *powd = wn->private_data;
+ if (!powd)
+ return;
PARA_INFO_LOG("closing writer node %p\n", wn);
AudioOutputUnitStop(powd->audio_unit);
AudioUnitUninitialize(powd->audio_unit);
size_t bytes;
int ret = 0;
- while (powd->to->remaining <= 0) {
+ while (!powd || powd->to->remaining <= 0) {
ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret <= 0)
break;
- if (powd->sample_rate == 0) {
+ if (!powd) {
ret = core_audio_init(wn);
if (ret < 0)
break;
+ powd = wn->private_data;
}
btr_merge(btrn, 8192);
bytes = btr_next_buffer(btrn, &data);
}
powd->to = powd->to->next;
}
- if (ret < 0 && powd->from->remaining <= 0) {
+ if (ret < 0 && (!powd || powd->from->remaining <= 0)) {
btr_remove_node(btrn);
t->error = ret;
}
struct writer_node *wn = container_of(t, struct writer_node, task);
struct private_osx_write_data *powd = wn->private_data;
struct timeval tmp = {.tv_sec = 1, .tv_usec = 0}, delay = tmp;
- unsigned long divisor;
+ unsigned long factor;
size_t numbytes;
int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret == 0)
return;
- if (ret < 0 || !powd->audio_unit)
+ if (ret < 0 || !powd)
return sched_min_delay(s);
+ assert(powd->sample_rate > 0);
+ assert(wn->min_iqs > 0);
numbytes = powd->to->remaining * sizeof(short);
- assert(numbytes > 0);
- divisor = powd->sample_rate * wn->min_iqs / numbytes;
- if (divisor)
- tv_divide(divisor, &tmp, &delay);
+ factor = numbytes / powd->sample_rate / wn->min_iqs;
+ tv_scale(factor, &tmp, &delay);
sched_request_timeout(&delay, s);
}