paraslash 0.5.1
[paraslash.git] / aacdec_filter.c
index 2dd68448b3b130172ba3417cb20eedcfc1fff262..3ff90834c62bb75f179e5778ef02f6d23feb0d09 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2010 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2006-2013 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -11,7 +11,6 @@
 /** \file aacdec_filter.c paraslash's aac (m4a) decoder. */
 
 #include <regex.h>
-#include <stdbool.h>
 
 #include "para.h"
 #include "list.h"
@@ -81,7 +80,7 @@ static void aacdec_close(struct filter_node *fn)
        fn->private_data = NULL;
 }
 
-static void aacdec_post_select(__a_unused struct sched *s, struct task *t)
+static int aacdec_post_select(__a_unused struct sched *s, struct task *t)
 {
        struct filter_node *fn = container_of(t, struct filter_node, task);
        struct btr_node *btrn = fn->btrn;
@@ -89,20 +88,18 @@ static void aacdec_post_select(__a_unused struct sched *s, struct task *t)
        int i, ret;
        unsigned char *p, *inbuf, *outbuffer;
        char *btr_buf;
-       size_t len, skip, consumed, loaded, iqs;
+       size_t len, skip, consumed, loaded;
 
 next_buffer:
-       t->error = 0;
        ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
        if (ret < 0)
                goto err;
        if (ret == 0)
-               return;
+               return 0;
        btr_merge(btrn, fn->min_iqs);
        len = btr_next_buffer(btrn, (char **)&inbuf);
-       len = PARA_MAX(len, (size_t)8192);
+       len = PARA_MIN(len, (size_t)8192);
        consumed = 0;
-       iqs = btr_get_input_queue_size(btrn);
        if (!padd->initialized) {
                unsigned long rate = 0;
                unsigned char channels = 0;
@@ -125,7 +122,7 @@ next_buffer:
                        ret = -E_AACDEC_INIT;
                        if (NeAACDecInit2(padd->handle, p,
                                        padd->decoder_length, &rate,
-                                       &channels) < 0)
+                                       &channels) != 0)
                                goto out;
                }
                padd->sample_rate = rate;
@@ -168,13 +165,17 @@ next_buffer:
                ret = -E_AAC_DECODE;
                if (padd->error_count++ > MAX_ERRORS)
                        goto err;
-               PARA_ERROR_LOG("frame_error: %d (%s), consumed: %zu + %zd + %lu\n",
-                       err, NeAACDecGetErrorMessage(padd->frame_info.error),
+               /* Suppress non-fatal bitstream error message at BOF/EOF */
+               if (len < fn->min_iqs || padd->consumed_total == 0) {
+                       consumed = len;
+                       goto success;
+               }
+               PARA_ERROR_LOG("%s\n", NeAACDecGetErrorMessage(err));
+               PARA_ERROR_LOG("consumed: %zu + %zd + %lu\n",
                        padd->consumed_total, consumed,
                        padd->frame_info.bytesconsumed);
-               PARA_ERROR_LOG("%s\n", NeAACDecGetErrorMessage(
-                       padd->frame_info.error));
-               consumed++; /* catch 21 */
+               if (consumed < len)
+                       consumed++; /* catch 21 */
                goto success;
        }
        padd->error_count = 0;
@@ -201,8 +202,8 @@ out:
        }
 err:
        assert(ret < 0);
-       t->error = ret;
-       btr_remove_node(btrn);
+       btr_remove_node(&fn->btrn);
+       return ret;
 }
 
 /**