+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 int wmadec_post_select(__a_unused struct sched *s, void *context)
+{
+ struct filter_node *fn = context;
+ int ret, converted, out_size;
+ struct private_wmadec_data *pwd = fn->private_data;
+ struct btr_node *btrn = fn->btrn;
+ size_t len;
+ char *in, *out;
+
+next_buffer:
+ converted = 0;
+ ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
+ return 0;
+ btr_merge(btrn, fn->min_iqs);
+ len = btr_next_buffer(btrn, &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 * pwd->ahi.packet_size;
+ fn->private_data = pwd;
+ converted = pwd->ahi.header_len;
+ goto success;
+ }
+ fn->min_iqs = pwd->ahi.packet_size;
+ if (fn->min_iqs > len)
+ goto success;
+ out_size = WMA_OUTPUT_BUFFER_SIZE;
+ out = para_malloc(out_size);
+ ret = wma_decode_superframe(pwd, out, &out_size,
+ (uint8_t *)in + WMA_FRAME_SKIP, len - WMA_FRAME_SKIP);
+ if (ret < 0) {
+ free(out);
+ goto err;
+ }
+ if (out_size > 0) {
+ out = para_realloc(out, out_size);
+ btr_add_output(out, out_size, btrn);
+ } else
+ free(out);
+ converted += pwd->ahi.packet_size;
+success:
+ btr_consume(btrn, converted);
+ return 0;
+err:
+ assert(ret < 0);
+ btr_remove_node(&fn->btrn);
+ return ret;
+}
+