+static int wmadec_execute(struct btr_node *btrn, const char *cmd, char **result)
+{
+ struct filter_node *fn = btr_context(btrn);
+ struct private_wmadec_data *pwd = fn->private_data;
+
+ return decoder_execute(cmd, pwd->ahi.sample_rate, pwd->ahi.channels,
+ result);
+}
+
+#define WMA_OUTPUT_BUFFER_SIZE (128 * 1024)
+
+static void wmadec_post_select(__a_unused struct sched *s, struct task *t)
+{
+ struct filter_node *fn = container_of(t, struct filter_node, task);
+ int ret, converted;
+ struct private_wmadec_data *pwd = fn->private_data;
+ struct btr_node *btrn = fn->btrn;
+ size_t len;
+ char *in;
+
+next_buffer:
+ converted = 0;
+ t->error = 0;
+ ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
+ return;
+ btr_merge(btrn, fn->min_iqs);
+ len = btr_next_buffer(btrn, (char **)&in);
+ ret = -E_WMADEC_EOF;
+ if (len < fn->min_iqs)
+ goto err;
+ if (!pwd) {
+ ret = wma_decode_init(in, len, &pwd);
+ if (ret < 0)
+ goto err;
+ if (ret == 0) {
+ fn->min_iqs += 4096;
+ goto next_buffer;
+ }
+ fn->min_iqs = 2 * (WMA_FRAME_SKIP + pwd->ahi.block_align);
+ fn->private_data = pwd;
+ converted = pwd->ahi.header_len;
+ goto success;
+ }
+ fn->min_iqs = WMA_FRAME_SKIP + pwd->ahi.block_align;
+ for (;;) {
+ char *out;
+ int out_size = WMA_OUTPUT_BUFFER_SIZE;
+ if (converted + fn->min_iqs > len)
+ break;
+ out = para_malloc(WMA_OUTPUT_BUFFER_SIZE);
+ ret = wma_decode_superframe(pwd, out,
+ &out_size, (uint8_t *)in + converted + WMA_FRAME_SKIP,
+ len - WMA_FRAME_SKIP);
+ if (ret < 0) {
+ free(out);
+ goto err;
+ }
+ btr_add_output(out, out_size, btrn);
+ converted += ret + WMA_FRAME_SKIP;
+ }
+success:
+ btr_consume(btrn, converted);
+ return;
+err:
+ assert(ret < 0);
+ t->error = ret;
+ btr_remove_node(btrn);
+}
+