- if (!need_new_buffer(wn))
- return 1;
- fill_buffer(powd->to, data, *wng->loaded / sizeof(short));
- powd->to = powd->to->next;
- wn->written = *wng->loaded;
- if (!powd->play) {
- if (AudioOutputUnitStart(powd->audio_unit))
- return -E_UNIT_START;
- powd->play = 1;
+ while (!powd || powd->to->remaining <= 0) {
+ ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
+ if (ret <= 0)
+ break;
+ 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);
+ //PARA_CRIT_LOG("have: %zu\n", bytes);
+ fill_buffer(powd, data, bytes);
+ btr_consume(btrn, bytes);
+ if (!powd->play) {
+ ret = -E_UNIT_START;
+ if (AudioOutputUnitStart(powd->audio_unit))
+ break;
+ powd->play = 1;
+ }
+ powd->to = powd->to->next;
+ }
+ if (ret < 0 && (!powd || powd->from->remaining <= 0)) {
+ btr_remove_node(btrn);
+ t->error = ret;