X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=aacdec.c;h=c41a5ac887e4ff6408e257d1423a74436cf5c491;hp=0eab773a16a024a693d40728d41aa9ea87b8dd49;hb=019f1ffdacd228f6a1e701ef6795c1a65ff02785;hpb=f94f6caa5b4053a3a205329f48bbb49c390c409a diff --git a/aacdec.c b/aacdec.c index 0eab773a..c41a5ac8 100644 --- a/aacdec.c +++ b/aacdec.c @@ -28,10 +28,8 @@ #include "list.h" #include "filter.h" #include "error.h" -#include #include "string.h" - -#include +#include "aac.h" /** the output buffer size */ #define MAX_CHANNELS 6 @@ -44,9 +42,7 @@ */ struct private_mp4dec_data { NeAACDecHandle decoder; - NeAACDecConfigurationPtr config; NeAACDecFrameInfo frame_info; - mp4AudioSpecificConfig mp4ASC; int initialized; int decoder_length; @@ -57,61 +53,10 @@ struct private_mp4dec_data { unsigned noffsets; unsigned *offset; + unsigned offset0; int offset_pos; }; -static int read_mp4_descr_length(struct private_mp4dec_data *padd) -{ - uint8_t b; - uint8_t numBytes = 0; - uint32_t length = 0; - - do { - b = padd->inbuf[padd->consumed + numBytes]; - numBytes++; - length = (length << 7) | (b & 0x7F); - } while - ((b & 0x80) && numBytes < 4); - padd->consumed += numBytes; - return length; -} - -static int find_esds(struct private_mp4dec_data *padd) -{ - for (; padd->consumed < padd->inbuf_len; padd->consumed++) { - unsigned char *p = padd->inbuf + padd->consumed; - int decoder_length; - - if (p[0] != 'e' || p[1] != 's' || p[2] != 'd' || p[3] != 's') - continue; - padd->consumed += 8; - p = padd->inbuf + padd->consumed; - PARA_INFO_LOG("found esds: %d, next: %x\n", padd->consumed, *p); - if (*p == 3) - padd->consumed += 8; - else - padd->consumed += 6; - p = padd->inbuf + padd->consumed; - PARA_INFO_LOG("next: %x\n", *p); - if (*p != 4) - continue; - padd->consumed += 18; - p = padd->inbuf + padd->consumed; - PARA_INFO_LOG("next: %x\n", *p); - if (*p != 5) - continue; - padd->consumed++; - decoder_length = read_mp4_descr_length(padd); - PARA_INFO_LOG("decoder length: %d\n", decoder_length); - p = padd->inbuf + padd->consumed; - PARA_INFO_LOG("decoder data0: %x\n", *p & 0xff); - p++; - PARA_INFO_LOG("decoder data1: %x\n", *p & 0xff); - return decoder_length; - } - return -E_ESDS; -} - static int read_int32(struct private_mp4dec_data *padd, unsigned *result) { uint8_t *d = (uint8_t*)(padd->inbuf + padd->consumed); @@ -161,7 +106,7 @@ static ssize_t mp4dec(char *inbuffer, size_t len, struct filter_node *fn) struct filter_chain_info *fci = fn->fci; unsigned long rate = 0; unsigned char channels = 0; - int i, ret, nbytes; + int i, ret, nbytes, skip; unsigned char *p, *outbuffer; if (fn->loaded > fn->bufsize * 4 / 5) @@ -173,18 +118,22 @@ static ssize_t mp4dec(char *inbuffer, size_t len, struct filter_node *fn) padd->inbuf_len = len; if (!padd->initialized) { - padd->decoder_length = find_esds(padd); + padd->decoder_length = aac_find_esds(padd->inbuf, padd->inbuf_len, + &skip); + PARA_INFO_LOG("decoder len: %d\n", padd->decoder_length); if (padd->decoder_length < 0) { ret = NeAACDecInit(padd->decoder, padd->inbuf, padd->inbuf_len, &rate, &channels); + PARA_INFO_LOG("decoder init: %d\n", ret); if (ret < 0) { - ret = E_AACDEC_INIT; + ret = -E_AACDEC_INIT; goto out; } padd->consumed = ret; } else { + padd->consumed += skip; p = padd->inbuf + padd->consumed; - ret = E_AACDEC_INIT; + ret = -E_AACDEC_INIT; if (NeAACDecInit2(padd->decoder, p, padd->decoder_length, &rate, &channels) < 0) @@ -192,16 +141,22 @@ static ssize_t mp4dec(char *inbuffer, size_t len, struct filter_node *fn) } fci->samplerate = rate; fci->channels = channels; - PARA_INFO_LOG("rate: %u, channels: %d\n", fci->samplerate, - fci->channels); + PARA_INFO_LOG("rate: %u, channels: %d\n", + fci->samplerate, fci->channels); padd->initialized = 1; } if (padd->decoder_length > 0) { padd->consumed = 0; if (!padd->offset_pos) { - ret = len; - if (find_stco(padd) < 0) + ret = aac_find_stco(padd->inbuf + padd->consumed, + padd->inbuf_len - padd->consumed, &skip); + if (ret < 0) { + ret = len; goto out; + } + padd->noffsets = ret; + padd->offset = para_malloc(padd->noffsets * sizeof(int)); + padd->consumed += skip; } if (padd->offset_pos < padd->noffsets) { fill_offset_table(padd); @@ -260,13 +215,7 @@ static void mp4dec_open(struct filter_node *fn) fn->bufsize = AAC_OUTBUF_SIZE; fn->buf = para_calloc(fn->bufsize); - - padd->decoder = NeAACDecOpen(); - padd->config = NeAACDecGetCurrentConfiguration(padd->decoder); - padd->config->defObjectType = LC; - padd->config->outputFormat = FAAD_FMT_16BIT; - padd->config->downMatrix = 0; - NeAACDecSetConfiguration(padd->decoder, padd->config); + padd->decoder = aac_open(); } static void mp4dec_close(struct filter_node *fn)