Mercurial > audlegacy-plugins
diff src/aac/libfaad2/decoder.c @ 681:1d8b08df98c3 trunk
[svn] - synchronise with FAAD 2.5
author | nenolod |
---|---|
date | Tue, 20 Feb 2007 04:37:37 -0800 |
parents | 3da1b8942b8b |
children | e6c5fdae6e88 |
line wrap: on
line diff
--- a/src/aac/libfaad2/decoder.c Tue Feb 20 04:36:01 2007 -0800 +++ b/src/aac/libfaad2/decoder.c Tue Feb 20 04:37:37 2007 -0800 @@ -1,28 +1,33 @@ /* ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding -** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com -** +** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com +** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. -** +** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. -** +** ** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ** ** Any non-GPL usage of this software or parts of this software is strictly ** forbidden. ** +** Software using this code must display the following message visibly in or +** on each copy of the software: +** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com" +** in, for example, the about-box or help/startup screen. +** ** Commercial non-GPL licensing of this software is possible. -** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. +** For more info contact Nero AG through Mpeg4AAClicense@nero.com. ** -** $Id: decoder.c,v 1.107 2004/09/08 09:43:11 gcp Exp $ +** $Id: decoder.c,v 1.109 2006/05/07 18:09:00 menno Exp $ **/ #include "common.h" @@ -116,6 +121,9 @@ hDecoder->frame = 0; hDecoder->sample_buffer = NULL; + hDecoder->__r1 = 1; + hDecoder->__r2 = 1; + for (i = 0; i < MAX_CHANNELS; i++) { hDecoder->window_shape_prev[i] = 0; @@ -194,6 +202,7 @@ return 0; } + int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer, uint32_t buffer_size, uint32_t *samplerate, uint8_t *channels) @@ -203,6 +212,7 @@ adif_header adif; adts_header adts; + if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL)) return -1; @@ -257,7 +267,6 @@ } faad_endbits(&ld); } - hDecoder->channelConfiguration = *channels; #if (defined(PS_DEC) || defined(DRM_PS)) /* check if we have a mono file */ @@ -268,6 +277,8 @@ } #endif + hDecoder->channelConfiguration = *channels; + #ifdef SBR_DEC /* implicit signalling */ if (*samplerate <= 24000 && !(hDecoder->config.dontUpSampleImplicitSBR)) @@ -422,8 +433,8 @@ if ((channels == DRMCH_MONO) || (channels == DRMCH_STEREO)) (*hDecoder)->sbr_present_flag = 0; else - (*hDecoder)->sbr_present_flag = 1; -#endif + (*hDecoder)->sbr_present_flag = 1; +#endif (*hDecoder)->fb = filter_bank_init((*hDecoder)->frameLength); @@ -525,8 +536,14 @@ chdir = hInfo->num_front_channels; if (chdir & 1) { +#if (defined(PS_DEC) || defined(DRM_PS)) + /* When PS is enabled output is always stereo */ + hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; + hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; +#else hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; chdir--; +#endif } for (i = 0; i < chdir; i += 2) { @@ -565,8 +582,15 @@ switch (hDecoder->channelConfiguration) { case 1: +#if (defined(PS_DEC) || defined(DRM_PS)) + /* When PS is enabled output is always stereo */ + hInfo->num_front_channels = 2; + hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; + hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; +#else hInfo->num_front_channels = 1; hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; +#endif break; case 2: hInfo->num_front_channels = 2; @@ -722,13 +746,25 @@ sample_buffer, sample_buffer_size); } +#ifdef DRM + +#define ERROR_STATE_INIT 6 + +static void conceal_output(NeAACDecHandle hDecoder, uint16_t frame_len, + uint8_t out_ch, void *sample_buffer) +{ + return; +} +#endif + static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, uint8_t *buffer, uint32_t buffer_size, void **sample_buffer2, uint32_t sample_buffer_size) { + uint16_t i; uint8_t channels = 0; uint8_t output_channels = 0; - bitfile ld; + bitfile ld = {0}; uint32_t bitsconsumed; uint16_t frame_len; void *sample_buffer; @@ -753,6 +789,33 @@ memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0])); +#ifdef USE_TIME_LIMIT + if ((TIME_LIMIT * get_sample_rate(hDecoder->sf_index)) > hDecoder->TL_count) + { + hDecoder->TL_count += 1024; + } else { + hInfo->error = (NUM_ERROR_MESSAGES-1); + goto error; + } +#endif + + + /* check for some common metadata tag types in the bitstream + * No need to return an error + */ + /* ID3 */ + if (buffer_size >= 128) + { + if (memcmp(buffer, "TAG", 3) == 0) + { + /* found it */ + hInfo->bytesconsumed = 128; /* 128 bytes fixed size */ + /* no error, but no output either */ + return NULL; + } + } + + /* initialize the bitstream */ faad_initbits(&ld, buffer, buffer_size); @@ -780,7 +843,7 @@ /* We do not support stereo right now */ if (0) //(hDecoder->channelConfiguration == 2) { - hInfo->error = 8; // Throw CRC error + hInfo->error = 28; // Throw CRC error goto error; } @@ -808,14 +871,14 @@ #endif /* decode the complete bitstream */ -#ifdef SCALABLE_DEC - if ((hDecoder->object_type == 6) || (hDecoder->object_type == DRM_ER_LC)) +#ifdef DRM + if (/*(hDecoder->object_type == 6) ||*/ (hDecoder->object_type == DRM_ER_LC)) { - aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); + DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); } else { #endif raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); -#ifdef SCALABLE_DEC +#ifdef DRM } #endif @@ -978,10 +1041,16 @@ } #endif + sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, output_channels, frame_len, hDecoder->config.outputFormat); +#ifdef DRM + //conceal_output(hDecoder, frame_len, output_channels, sample_buffer); +#endif + + hDecoder->postSeekResetFlag = 0; hDecoder->frame++; @@ -1013,6 +1082,30 @@ error: + +#ifdef DRM + hDecoder->error_state = ERROR_STATE_INIT; +#endif + + /* reset filterbank state */ + for (i = 0; i < MAX_CHANNELS; i++) + { + if (hDecoder->fb_intermed[i] != NULL) + { + memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t)); + } + } +#ifdef SBR_DEC + for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) + { + if (hDecoder->sbr[i] != NULL) + { + sbrReset(hDecoder->sbr[i]); + } + } +#endif + + faad_endbits(&ld); /* cleanup */