summaryrefslogtreecommitdiff
path: root/src/libfaad/decoder.c
diff options
context:
space:
mode:
authorMike Melanson <mike@multimedia.cx>2005-10-29 23:57:06 +0000
committerMike Melanson <mike@multimedia.cx>2005-10-29 23:57:06 +0000
commit03ac29c63fd3d5019c67b3662669b1c443896f0b (patch)
tree00db769b2943fce16b9967591652d2c0724be168 /src/libfaad/decoder.c
parentc7976c4d0d8d02fa18bc9fd82bafe99e333e2a53 (diff)
downloadxine-lib-03ac29c63fd3d5019c67b3662669b1c443896f0b.tar.gz
xine-lib-03ac29c63fd3d5019c67b3662669b1c443896f0b.tar.bz2
update libfaad2 to CVS snapshot 2004-09-15
CVS patchset: 7777 CVS date: 2005/10/29 23:57:06
Diffstat (limited to 'src/libfaad/decoder.c')
-rw-r--r--src/libfaad/decoder.c292
1 files changed, 172 insertions, 120 deletions
diff --git a/src/libfaad/decoder.c b/src/libfaad/decoder.c
index 3a1dc86de..33aee247e 100644
--- a/src/libfaad/decoder.c
+++ b/src/libfaad/decoder.c
@@ -22,7 +22,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
**
-** $Id: decoder.c,v 1.9 2004/12/03 01:15:30 tmattern Exp $
+** $Id: decoder.c,v 1.10 2005/10/29 23:57:06 tmmm Exp $
**/
#include "common.h"
@@ -50,14 +50,21 @@
uint16_t dbg_count;
#endif
-int8_t* FAADAPI faacDecGetErrorMessage(uint8_t errcode)
+/* static function declarations */
+static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
+ uint8_t *buffer, uint32_t buffer_size,
+ void **sample_buffer, uint32_t sample_buffer_size);
+static void create_channel_config(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo);
+
+
+char* NEAACDECAPI NeAACDecGetErrorMessage(uint8_t errcode)
{
if (errcode >= NUM_ERROR_MESSAGES)
return NULL;
return err_msg[errcode];
}
-uint32_t FAADAPI faacDecGetCapabilities(void)
+uint32_t NEAACDECAPI NeAACDecGetCapabilities(void)
{
uint32_t cap = 0;
@@ -83,15 +90,15 @@ uint32_t FAADAPI faacDecGetCapabilities(void)
return cap;
}
-faacDecHandle FAADAPI faacDecOpen(void)
+NeAACDecHandle NEAACDECAPI NeAACDecOpen(void)
{
uint8_t i;
- faacDecHandle hDecoder = NULL;
+ NeAACDecHandle hDecoder = NULL;
- if ((hDecoder = (faacDecHandle)faad_malloc(sizeof(faacDecStruct))) == NULL)
+ if ((hDecoder = (NeAACDecHandle)faad_malloc(sizeof(NeAACDecStruct))) == NULL)
return NULL;
- memset(hDecoder, 0, sizeof(faacDecStruct));
+ memset(hDecoder, 0, sizeof(NeAACDecStruct));
hDecoder->config.outputFormat = FAAD_FMT_16BIT;
hDecoder->config.defObjectType = MAIN;
@@ -136,23 +143,14 @@ faacDecHandle FAADAPI faacDecOpen(void)
hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
-#ifdef USE_SSE
- if (cpu_has_sse())
- {
- hDecoder->apply_sf_func = apply_scalefactors_sse;
- } else {
- hDecoder->apply_sf_func = apply_scalefactors;
- }
-#endif
-
return hDecoder;
}
-faacDecConfigurationPtr FAADAPI faacDecGetCurrentConfiguration(faacDecHandle hDecoder)
+NeAACDecConfigurationPtr NEAACDECAPI NeAACDecGetCurrentConfiguration(NeAACDecHandle hDecoder)
{
if (hDecoder)
{
- faacDecConfigurationPtr config = &(hDecoder->config);
+ NeAACDecConfigurationPtr config = &(hDecoder->config);
return config;
}
@@ -160,8 +158,8 @@ faacDecConfigurationPtr FAADAPI faacDecGetCurrentConfiguration(faacDecHandle hDe
return NULL;
}
-uint8_t FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
- faacDecConfigurationPtr config)
+uint8_t NEAACDECAPI NeAACDecSetConfiguration(NeAACDecHandle hDecoder,
+ NeAACDecConfigurationPtr config)
{
if (hDecoder && config)
{
@@ -176,12 +174,18 @@ uint8_t FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
hDecoder->config.defSampleRate = config->defSampleRate;
/* check output format */
- if ((config->outputFormat < 1) || (config->outputFormat > 9))
+#ifdef FIXED_POINT
+ if ((config->outputFormat < 1) || (config->outputFormat > 4))
+ return 0;
+#else
+ if ((config->outputFormat < 1) || (config->outputFormat > 5))
return 0;
+#endif
hDecoder->config.outputFormat = config->outputFormat;
if (config->downMatrix > 1)
- hDecoder->config.downMatrix = config->downMatrix;
+ return 0;
+ hDecoder->config.downMatrix = config->downMatrix;
/* OK */
return 1;
@@ -190,9 +194,9 @@ uint8_t FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
return 0;
}
-int32_t FAADAPI faacDecInit(faacDecHandle hDecoder, uint8_t *buffer,
- uint32_t buffer_size,
- uint32_t *samplerate, uint8_t *channels)
+int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
+ uint32_t buffer_size,
+ uint32_t *samplerate, uint8_t *channels)
{
uint32_t bits = 0;
bitfile ld;
@@ -255,12 +259,23 @@ int32_t FAADAPI faacDecInit(faacDecHandle hDecoder, uint8_t *buffer,
}
hDecoder->channelConfiguration = *channels;
+#if (defined(PS_DEC) || defined(DRM_PS))
+ /* check if we have a mono file */
+ if (*channels == 1)
+ {
+ /* upMatrix to 2 channels for implicit signalling of PS */
+ *channels = 2;
+ }
+#endif
+
#ifdef SBR_DEC
/* implicit signalling */
if (*samplerate <= 24000 && !(hDecoder->config.dontUpSampleImplicitSBR))
{
*samplerate *= 2;
hDecoder->forceUpSampling = 1;
+ } else if (*samplerate > 24000 && !(hDecoder->config.dontUpSampleImplicitSBR)) {
+ hDecoder->downSampledSBR = 1;
}
#endif
@@ -284,9 +299,9 @@ int32_t FAADAPI faacDecInit(faacDecHandle hDecoder, uint8_t *buffer,
}
/* Init the library using a DecoderSpecificInfo */
-int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
- uint32_t SizeOfDecoderSpecificInfo,
- uint32_t *samplerate, uint8_t *channels)
+int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer,
+ uint32_t SizeOfDecoderSpecificInfo,
+ uint32_t *samplerate, uint8_t *channels)
{
int8_t rc;
mp4AudioSpecificConfig mp4ASC;
@@ -316,6 +331,14 @@ int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
*channels = hDecoder->pce.channels;
hDecoder->pce_set = 1;
}
+#if (defined(PS_DEC) || defined(DRM_PS))
+ /* check if we have a mono file */
+ if (*channels == 1)
+ {
+ /* upMatrix to 2 channels for implicit signalling of PS */
+ *channels = 2;
+ }
+#endif
hDecoder->sf_index = mp4ASC.samplingFrequencyIndex;
hDecoder->object_type = mp4ASC.objectTypeIndex;
#ifdef ERROR_RESILIENCE
@@ -325,13 +348,14 @@ int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
#endif
#ifdef SBR_DEC
hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag;
+ hDecoder->downSampledSBR = mp4ASC.downSampledSBR;
if (hDecoder->config.dontUpSampleImplicitSBR == 0)
hDecoder->forceUpSampling = mp4ASC.forceUpSampling;
else
hDecoder->forceUpSampling = 0;
/* AAC core decoder samplerate is 2 times as low */
- if (hDecoder->sbr_present_flag == 1 || hDecoder->forceUpSampling == 1)
+ if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1)
{
hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2);
}
@@ -366,100 +390,48 @@ int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
}
#ifdef DRM
-int8_t FAADAPI faacDecInitDRM(faacDecHandle hDecoder, uint32_t samplerate,
- uint8_t channels)
+int8_t NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, uint32_t samplerate,
+ uint8_t channels)
{
- uint8_t i;
-
if (hDecoder == NULL)
return 1; /* error */
+ NeAACDecClose(*hDecoder);
+
+ *hDecoder = NeAACDecOpen();
+
/* Special object type defined for DRM */
- hDecoder->config.defObjectType = DRM_ER_LC;
+ (*hDecoder)->config.defObjectType = DRM_ER_LC;
- hDecoder->config.defSampleRate = samplerate;
+ (*hDecoder)->config.defSampleRate = samplerate;
#ifdef ERROR_RESILIENCE // This shoudl always be defined for DRM
- hDecoder->aacSectionDataResilienceFlag = 1; /* VCB11 */
- hDecoder->aacScalefactorDataResilienceFlag = 0; /* no RVLC */
- hDecoder->aacSpectralDataResilienceFlag = 1; /* HCR */
+ (*hDecoder)->aacSectionDataResilienceFlag = 1; /* VCB11 */
+ (*hDecoder)->aacScalefactorDataResilienceFlag = 0; /* no RVLC */
+ (*hDecoder)->aacSpectralDataResilienceFlag = 1; /* HCR */
#endif
- hDecoder->frameLength = 960;
- hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate);
- hDecoder->object_type = hDecoder->config.defObjectType;
+ (*hDecoder)->frameLength = 960;
+ (*hDecoder)->sf_index = get_sr_index((*hDecoder)->config.defSampleRate);
+ (*hDecoder)->object_type = (*hDecoder)->config.defObjectType;
if ((channels == DRMCH_STEREO) || (channels == DRMCH_SBR_STEREO))
- hDecoder->channelConfiguration = 2;
+ (*hDecoder)->channelConfiguration = 2;
else
- hDecoder->channelConfiguration = 1;
+ (*hDecoder)->channelConfiguration = 1;
#ifdef SBR_DEC
- if (channels == DRMCH_SBR_LC_STEREO)
- hDecoder->lcstereo_flag = 1;
- else
- hDecoder->lcstereo_flag = 0;
-
if ((channels == DRMCH_MONO) || (channels == DRMCH_STEREO))
- hDecoder->sbr_present_flag = 0;
+ (*hDecoder)->sbr_present_flag = 0;
else
- hDecoder->sbr_present_flag = 1;
-
- /* Reset sbr for new initialization */
- sbrDecodeEnd(hDecoder->sbr[0]);
- hDecoder->sbr[0] = NULL;
-#endif
-
- if (hDecoder->fb) filter_bank_end(hDecoder->fb);
- hDecoder->fb = NULL;
-
- /* Take care of buffers */
- if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer);
- hDecoder->sample_buffer = NULL;
- hDecoder->alloced_channels = 0;
-
- for (i = 0; i < MAX_CHANNELS; i++)
- {
- hDecoder->window_shape_prev[i] = 0;
-
- if (hDecoder->time_out[i]) faad_free(hDecoder->time_out[i]);
- hDecoder->time_out[i] = NULL;
- if (hDecoder->fb_intermed[i]) faad_free(hDecoder->fb_intermed[i]);
- hDecoder->fb_intermed[i] = NULL;
-#ifdef SSR_DEC
- if (hDecoder->ssr_overlap[i]) faad_free(hDecoder->ssr_overlap[i]);
- hDecoder->ssr_overlap[i] = NULL;
- if (hDecoder->prev_fmd[i]) faad_free(hDecoder->prev_fmd[i]);
- hDecoder->prev_fmd[i] = NULL;
-#endif
-#ifdef MAIN_DEC
- if (hDecoder->pred_stat[i]) faad_free(hDecoder->pred_stat[i]);
- hDecoder->pred_stat[i] = NULL;
-#endif
-#ifdef LTP_DEC
- hDecoder->ltp_lag[i] = 0;
- if (hDecoder->lt_pred_stat[i]) faad_free(hDecoder->lt_pred_stat[i]);
- hDecoder->lt_pred_stat[i] = NULL;
-#endif
- }
-
- for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
- {
-#ifdef SBR_DEC
- if (hDecoder->sbr[i])
- sbrDecodeEnd(hDecoder->sbr[i]);
-
- hDecoder->sbr_alloced[i] = 0;
-#endif
- hDecoder->element_alloced[i] = 0;
- hDecoder->element_output_channels[i] = 0;
- }
+ (*hDecoder)->sbr_present_flag = 1;
+#endif
- hDecoder->fb = filter_bank_init(hDecoder->frameLength);
+ (*hDecoder)->fb = filter_bank_init((*hDecoder)->frameLength);
return 0;
}
#endif
-void FAADAPI faacDecClose(faacDecHandle hDecoder)
+void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder)
{
uint8_t i;
@@ -512,7 +484,7 @@ void FAADAPI faacDecClose(faacDecHandle hDecoder)
if (hDecoder) faad_free(hDecoder);
}
-void FAADAPI faacDecPostSeekReset(faacDecHandle hDecoder, int32_t frame)
+void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, int32_t frame)
{
if (hDecoder)
{
@@ -523,7 +495,7 @@ void FAADAPI faacDecPostSeekReset(faacDecHandle hDecoder, int32_t frame)
}
}
-static void create_channel_config(faacDecHandle hDecoder, faacDecFrameInfo *hInfo)
+static void create_channel_config(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo)
{
hInfo->num_front_channels = 0;
hInfo->num_side_channels = 0;
@@ -728,9 +700,31 @@ static void create_channel_config(faacDecHandle hDecoder, faacDecFrameInfo *hInf
}
}
-void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
- faacDecFrameInfo *hInfo,
- uint8_t *buffer, uint32_t buffer_size)
+void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
+ NeAACDecFrameInfo *hInfo,
+ uint8_t *buffer, uint32_t buffer_size)
+{
+ return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0);
+}
+
+void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,
+ NeAACDecFrameInfo *hInfo,
+ uint8_t *buffer, uint32_t buffer_size,
+ void **sample_buffer, uint32_t sample_buffer_size)
+{
+ if ((sample_buffer == NULL) || (sample_buffer_size == 0))
+ {
+ hInfo->error = 27;
+ return NULL;
+ }
+
+ return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size,
+ sample_buffer, sample_buffer_size);
+}
+
+static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
+ uint8_t *buffer, uint32_t buffer_size,
+ void **sample_buffer2, uint32_t sample_buffer_size)
{
uint8_t channels = 0;
uint8_t output_channels = 0;
@@ -749,27 +743,49 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
return NULL;
}
+#if 0
+ printf("%d\n", buffer_size*8);
+#endif
+
frame_len = hDecoder->frameLength;
- memset(hInfo, 0, sizeof(faacDecFrameInfo));
+ memset(hInfo, 0, sizeof(NeAACDecFrameInfo));
memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0]));
/* initialize the bitstream */
faad_initbits(&ld, buffer, buffer_size);
+#if 0
+ {
+ int i;
+ for (i = 0; i < ((buffer_size+3)>>2); i++)
+ {
+ uint8_t *buf;
+ uint32_t temp = 0;
+ buf = faad_getbitbuffer(&ld, 32);
+ //temp = getdword((void*)buf);
+ temp = *((uint32_t*)buf);
+ printf("0x%.8X\n", temp);
+ free(buf);
+ }
+ faad_endbits(&ld);
+ faad_initbits(&ld, buffer, buffer_size);
+ }
+#endif
+
#ifdef DRM
if (hDecoder->object_type == DRM_ER_LC)
{
/* We do not support stereo right now */
- if (hDecoder->channelConfiguration == 2)
+ if (0) //(hDecoder->channelConfiguration == 2)
{
hInfo->error = 8; // Throw CRC error
goto error;
}
faad_getbits(&ld, 8
- DEBUGVAR(1,1,"faacDecDecode(): skip CRC"));
+ DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC"));
}
#endif
@@ -829,7 +845,7 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
if (!hDecoder->adts_header_present && !hDecoder->adif_header_present)
{
- if (channels != hDecoder->channelConfiguration)
+ if (hDecoder->channelConfiguration == 0)
hDecoder->channelConfiguration = channels;
if (channels == 8) /* 7.1 */
@@ -846,6 +862,17 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
output_channels = channels;
}
+#if (defined(PS_DEC) || defined(DRM_PS))
+ hDecoder->upMatrix = 0;
+ /* check if we have a mono file */
+ if (output_channels == 1)
+ {
+ /* upMatrix to 2 channels for implicit signalling of PS */
+ hDecoder->upMatrix = 1;
+ output_channels = 2;
+ }
+#endif
+
/* Make a channel configuration based on either a PCE or a channelConfiguration */
create_channel_config(hDecoder, hInfo);
@@ -865,6 +892,9 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
hInfo->header_type = ADIF;
if (hDecoder->adts_header_present)
hInfo->header_type = ADTS;
+#if (defined(PS_DEC) || defined(DRM_PS))
+ hInfo->ps = hDecoder->ps_used_global;
+#endif
/* check if frame has channel elements */
if (channels == 0)
@@ -883,17 +913,32 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
};
uint8_t stride = str[hDecoder->config.outputFormat-1];
#ifdef SBR_DEC
- if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
+ if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1))
+ {
stride = 2 * stride;
+ }
#endif
- if (hDecoder->sample_buffer)
- faad_free(hDecoder->sample_buffer);
- hDecoder->sample_buffer = NULL;
- hDecoder->sample_buffer = faad_malloc(frame_len*output_channels*stride);
+ /* check if we want to use internal sample_buffer */
+ if (sample_buffer_size == 0)
+ {
+ if (hDecoder->sample_buffer)
+ faad_free(hDecoder->sample_buffer);
+ hDecoder->sample_buffer = NULL;
+ hDecoder->sample_buffer = faad_malloc(frame_len*output_channels*stride);
+ } else if (sample_buffer_size < frame_len*output_channels*stride) {
+ /* provided sample buffer is not big enough */
+ hInfo->error = 27;
+ return NULL;
+ }
hDecoder->alloced_channels = output_channels;
}
- sample_buffer = hDecoder->sample_buffer;
+ if (sample_buffer_size == 0)
+ {
+ sample_buffer = hDecoder->sample_buffer;
+ } else {
+ sample_buffer = *sample_buffer2;
+ }
#ifdef SBR_DEC
if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
@@ -901,9 +946,12 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
uint8_t ele;
/* this data is different when SBR is used or when the data is upsampled */
- frame_len *= 2;
- hInfo->samples *= 2;
- hInfo->samplerate *= 2;
+ if (!hDecoder->downSampledSBR)
+ {
+ frame_len *= 2;
+ hInfo->samples *= 2;
+ hInfo->samplerate *= 2;
+ }
/* check if every element was provided with SBR data */
for (ele = 0; ele < hDecoder->fr_ch_ele; ele++)
@@ -923,6 +971,10 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
} else {
hInfo->sbr = NO_SBR_UPSAMPLED;
}
+ if (hDecoder->downSampledSBR)
+ {
+ hInfo->sbr = SBR_DOWNSAMPLED;
+ }
}
#endif