X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=aacdec_filter.c;h=017e439b38b3b346925399e41b9b6100c77e2685;hp=9791175ecd72d6dcd22ee719f90d1e59481668b3;hb=929a67dd8f243686fb5928d175b00937446ffda5;hpb=9165680a9639a8412adef13b96e466efdbb9d806 diff --git a/aacdec_filter.c b/aacdec_filter.c index 9791175e..017e439b 100644 --- a/aacdec_filter.c +++ b/aacdec_filter.c @@ -11,8 +11,10 @@ /** \file aacdec_filter.c paraslash's aac (m4a) decoder. */ #include +#include #include "para.h" +#include "portable_io.h" #include "list.h" #include "sched.h" #include "ggo.h" @@ -20,7 +22,6 @@ #include "filter.h" #include "error.h" #include "string.h" -#include "aac.h" /** Give up decoding after that many errors. */ #define MAX_ERRORS 20 @@ -37,23 +38,33 @@ struct private_aacdec_data { NeAACDecFrameInfo frame_info; /** whether this instance of the aac decoder is already initialized */ int initialized; - /** - * return value of aac_find_esds(). Used to call the right aacdec - * init function - */ - unsigned long decoder_length; /** number of times the decoder returned an error */ unsigned error_count; /** number of bytes already consumed from the imput stream */ size_t consumed_total; - /** return value of aac_find_entry_point */ - size_t entry; /** The number of channels of the current stream. */ unsigned int channels; /** Current sample rate in Hz. */ unsigned int sample_rate; }; +/* + * Get a new libfaad decoder handle. + * + * \return The handle returned by NeAACDecOpen(). + */ +static NeAACDecHandle aac_open(void) +{ + NeAACDecHandle h = NeAACDecOpen(); + NeAACDecConfigurationPtr c = NeAACDecGetCurrentConfiguration(h); + + c->defObjectType = LC; + c->outputFormat = FAAD_FMT_16BIT; + c->downMatrix = 0; + NeAACDecSetConfiguration(h, c); + return h; +} + static int aacdec_execute(struct btr_node *btrn, const char *cmd, char **result) { struct filter_node *fn = btr_context(btrn); @@ -88,7 +99,7 @@ static int aacdec_post_select(__a_unused struct sched *s, void *context) int i, ret; char *p, *inbuf, *outbuffer; char *btr_buf; - size_t len, skip, consumed, loaded; + size_t len, consumed, loaded; next_buffer: ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL); @@ -103,56 +114,20 @@ next_buffer: if (!padd->initialized) { unsigned long rate = 0; unsigned char channels = 0; - ret = aac_find_esds(inbuf, len, &skip, &padd->decoder_length); + ret = NeAACDecInit(padd->handle, (unsigned char *)inbuf, + len, &rate, &channels); + PARA_INFO_LOG("decoder init: %d\n", ret); if (ret < 0) { - PARA_INFO_LOG("%s\n", para_strerror(-ret)); - ret = NeAACDecInit(padd->handle, (unsigned char *)inbuf, - len, &rate, &channels); - PARA_INFO_LOG("decoder init: %d\n", ret); - if (ret < 0) { - ret = -E_AACDEC_INIT; - goto out; - } - consumed = ret; - } else { - PARA_INFO_LOG("decoder len: %lu\n", - padd->decoder_length); - consumed += skip; - p = inbuf + consumed; ret = -E_AACDEC_INIT; - if (NeAACDecInit2(padd->handle, (unsigned char *)p, - padd->decoder_length, &rate, - &channels) != 0) - goto out; + goto out; } + consumed = ret; padd->sample_rate = rate; padd->channels = channels; - PARA_INFO_LOG("rate: %u, channels: %d\n", + PARA_INFO_LOG("rate: %u, channels: %u\n", padd->sample_rate, padd->channels); padd->initialized = 1; } - if (padd->decoder_length > 0) { - consumed = 0; - if (!padd->entry) { - ret = aac_find_entry_point(inbuf + consumed, - len - consumed, &skip); - if (ret < 0) { - ret = len; - goto out; - } - consumed += skip; - padd->entry = ret; - PARA_INFO_LOG("entry: %zu\n", padd->entry); - } - ret = len; - if (padd->consumed_total + len < padd->entry) - goto out; - if (padd->consumed_total < padd->entry) - consumed = padd->entry - padd->consumed_total; - } - for (; consumed < len; consumed++) - if ((inbuf[consumed] & 0xfe) == 0x20) - break; if (consumed >= len) goto success; p = inbuf + consumed; @@ -165,13 +140,8 @@ next_buffer: ret = -E_AAC_DECODE; if (padd->error_count++ > MAX_ERRORS) goto err; - /* 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", + PARA_ERROR_LOG("consumed: %zu + %zu + %lu\n", padd->consumed_total, consumed, padd->frame_info.bytesconsumed); if (consumed < len)