audiod: Kill noisy debug message.
[paraslash.git] / wmadec_filter.c
index 4bbc241..49f69b5 100644 (file)
@@ -1225,57 +1225,39 @@ static int wmadec_execute(struct btr_node *btrn, const char *cmd, char **result)
        return -ERRNO_TO_PARA_ERROR(ENOTSUP);
 }
 
-#define WMADEC_MAX_PENDING (640 * 1024)
-
-static void wmadec_pre_select(struct sched *s, struct task *t)
-{
-       struct filter_node *fn = container_of(t, struct filter_node, task);
-       size_t iqs = btr_get_input_queue_size(fn->btrn);
-
-       t->error = 0;
-       if (iqs == 0)
-               return;
-       if (btr_bytes_pending(fn->btrn) > WMADEC_MAX_PENDING)
-               return; /* FIXME, should use reasonable bound on timeout */
-       s->timeout.tv_sec = 0;
-       s->timeout.tv_usec = 1;
-}
-
 #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 = 0;
+       int ret, converted;
        struct private_wmadec_data *pwd = fn->private_data;
        struct btr_node *btrn = fn->btrn;
-       size_t iqs, len, min_len;
+       size_t len;
        char *in;
 
-       min_len = pwd? WMA_FRAME_SKIP + pwd->ahi.block_align : 8192;
 next_buffer:
+       converted = 0;
        t->error = 0;
-       if (btr_bytes_pending(btrn) > WMADEC_MAX_PENDING)
+       ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
+       if (ret < 0)
+               goto err;
+       if (ret == 0)
                return;
-       iqs = btr_get_input_queue_size(btrn);
-       if (iqs < min_len) {
-               if (!btr_no_parent(btrn)) /* wait for more data */
-                       return;
-               ret = -E_WMADEC_EOF;
+       btr_merge(btrn, fn->min_iqs);
+       len = btr_next_buffer(btrn, (char **)&in);
+       ret = -E_WMADEC_EOF;
+       if (len < fn->min_iqs)
                goto err;
-       }
-       /* avoid "buffer too small" errors from the decoder */
-       btr_merge_to(btrn, min_len);
-       len = btr_next_buffer(btrn, &in);
-       assert(len >= min_len);
        if (!pwd) {
                ret = wma_decode_init(in, len, &pwd);
                if (ret < 0)
                        goto err;
                if (ret == 0) {
-                       min_len += 4096;
+                       fn->min_iqs += 4096;
                        goto next_buffer;
                }
+               fn->min_iqs = WMA_FRAME_SKIP + pwd->ahi.block_align;
                fn->private_data = pwd;
                converted = pwd->ahi.header_len;
                goto success;
@@ -1283,7 +1265,7 @@ next_buffer:
        for (;;) {
                char *out;
                int out_size = WMA_OUTPUT_BUFFER_SIZE;
-               if (converted + WMA_FRAME_SKIP + pwd->ahi.block_align > len)
+               if (converted + fn->min_iqs > len)
                        break;
                out = para_malloc(WMA_OUTPUT_BUFFER_SIZE);
                ret = wma_decode_superframe(pwd, out,
@@ -1301,9 +1283,8 @@ success:
        goto next_buffer;
 err:
        assert(ret < 0);
-       wmadec_close(fn);
        t->error = ret;
-       btr_del_node(btrn);
+       btr_remove_node(btrn);
 }
 
 static ssize_t wmadec_convert(char *inbuffer, size_t len,
@@ -1347,6 +1328,7 @@ static void wmadec_open(struct filter_node *fn)
        fn->buf = para_malloc(fn->bufsize);
        fn->private_data = NULL;
        fn->loaded = 0;
+       fn->min_iqs = 4096;
 }
 
 /**
@@ -1360,6 +1342,6 @@ void wmadec_filter_init(struct filter *f)
        f->close = wmadec_close;
        f->convert = wmadec_convert;
        f->execute = wmadec_execute;
-       f->pre_select = wmadec_pre_select;
+       f->pre_select = generic_filter_pre_select;
        f->post_select = wmadec_post_select;
 }