summaryrefslogtreecommitdiff
path: root/src/libfaad/syntax.c
diff options
context:
space:
mode:
authorThibaut Mattern <tmattern@users.sourceforge.net>2004-12-03 01:15:29 +0000
committerThibaut Mattern <tmattern@users.sourceforge.net>2004-12-03 01:15:29 +0000
commit177aca572a9e0f4256034e51ffded0b3815d4f61 (patch)
tree071a5f96a627a1c0124ff57a4b806d52068fdba0 /src/libfaad/syntax.c
parent575782a9f76583abd8c4374466472b376023f8dd (diff)
downloadxine-lib-177aca572a9e0f4256034e51ffded0b3815d4f61.tar.gz
xine-lib-177aca572a9e0f4256034e51ffded0b3815d4f61.tar.bz2
Update to libfaad2 2.0.
CVS patchset: 7185 CVS date: 2004/12/03 01:15:29
Diffstat (limited to 'src/libfaad/syntax.c')
-rw-r--r--src/libfaad/syntax.c129
1 files changed, 73 insertions, 56 deletions
diff --git a/src/libfaad/syntax.c b/src/libfaad/syntax.c
index db79a0c15..5f3657361 100644
--- a/src/libfaad/syntax.c
+++ b/src/libfaad/syntax.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: syntax.c,v 1.7 2004/01/26 22:34:11 jstembridge Exp $
+** $Id: syntax.c,v 1.8 2004/12/03 01:15:31 tmattern Exp $
**/
/*
@@ -52,6 +52,10 @@
/* static function declarations */
+static void decode_sce_lfe(faacDecHandle hDecoder, faacDecFrameInfo *hInfo, bitfile *ld,
+ uint8_t id_syn_ele);
+static void decode_cpe(faacDecHandle hDecoder, faacDecFrameInfo *hInfo, bitfile *ld,
+ uint8_t id_syn_ele);
static uint8_t single_lfe_channel_element(faacDecHandle hDecoder, bitfile *ld,
uint8_t channel, uint8_t *tag);
static uint8_t channel_pair_element(faacDecHandle hDecoder, bitfile *ld,
@@ -310,9 +314,9 @@ static uint8_t program_config_element(program_config *pce, bitfile *ld)
return 0;
}
-void decode_sce_lfe(faacDecHandle hDecoder,
- faacDecFrameInfo *hInfo, bitfile *ld,
- uint8_t id_syn_ele)
+static void decode_sce_lfe(faacDecHandle hDecoder,
+ faacDecFrameInfo *hInfo, bitfile *ld,
+ uint8_t id_syn_ele)
{
uint8_t channels = hDecoder->fr_channels;
uint8_t tag = 0;
@@ -328,25 +332,35 @@ void decode_sce_lfe(faacDecHandle hDecoder,
return;
}
- if (hDecoder->pce_set)
- hDecoder->internal_channel[hDecoder->pce.sce_channel[tag]] = channels;
- else
- hDecoder->internal_channel[channels] = channels;
+ /* for SCE hDecoder->element_output_channels[] is not set here because this
+ can become 2 when some form of Parametric Stereo coding is used
+ */
- if (id_syn_ele == ID_SCE)
- hDecoder->channel_element[channels] = hDecoder->fr_ch_ele;
- else /* LFE */
- hDecoder->channel_element[channels] = hDecoder->fr_ch_ele;
+ /* save the syntax element id */
hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
+ /* decode the element */
hInfo->error = single_lfe_channel_element(hDecoder, ld, channels, &tag);
- hDecoder->fr_channels++;
+ /* map output channels position to internal data channels */
+ if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2)
+ {
+ /* this might be faulty when pce_set is true */
+ hDecoder->internal_channel[channels] = channels;
+ hDecoder->internal_channel[channels+1] = channels+1;
+ } else {
+ if (hDecoder->pce_set)
+ hDecoder->internal_channel[hDecoder->pce.sce_channel[tag]] = channels;
+ else
+ hDecoder->internal_channel[channels] = channels;
+ }
+
+ hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele];
hDecoder->fr_ch_ele++;
}
-void decode_cpe(faacDecHandle hDecoder, faacDecFrameInfo *hInfo, bitfile *ld,
- uint8_t id_syn_ele)
+static void decode_cpe(faacDecHandle hDecoder, faacDecFrameInfo *hInfo, bitfile *ld,
+ uint8_t id_syn_ele)
{
uint8_t channels = hDecoder->fr_channels;
uint8_t tag = 0;
@@ -362,6 +376,24 @@ void decode_cpe(faacDecHandle hDecoder, faacDecFrameInfo *hInfo, bitfile *ld,
return;
}
+ /* for CPE the number of output channels is always 2 */
+ if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0)
+ {
+ /* element_output_channels not set yet */
+ hDecoder->element_output_channels[hDecoder->fr_ch_ele] = 2;
+ } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != 2) {
+ /* element inconsistency */
+ hInfo->error = 21;
+ return;
+ }
+
+ /* save the syntax element id */
+ hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
+
+ /* decode the element */
+ hInfo->error = channel_pair_element(hDecoder, ld, channels, &tag);
+
+ /* map output channel position to internal data channels */
if (hDecoder->pce_set)
{
hDecoder->internal_channel[hDecoder->pce.cpe_channel[tag]] = channels;
@@ -371,12 +403,6 @@ void decode_cpe(faacDecHandle hDecoder, faacDecFrameInfo *hInfo, bitfile *ld,
hDecoder->internal_channel[channels+1] = channels+1;
}
- hDecoder->channel_element[channels] = hDecoder->fr_ch_ele;
- hDecoder->channel_element[channels+1] = hDecoder->fr_ch_ele;
- hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
-
- hInfo->error = channel_pair_element(hDecoder, ld, channels, &tag);
-
hDecoder->fr_channels += 2;
hDecoder->fr_ch_ele++;
}
@@ -385,7 +411,6 @@ void raw_data_block(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
bitfile *ld, program_config *pce, drc_info *drc)
{
uint8_t id_syn_ele;
- uint8_t ch_ele = 0;
hDecoder->fr_channels = 0;
hDecoder->fr_ch_ele = 0;
@@ -404,21 +429,18 @@ void raw_data_block(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
case ID_SCE:
if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele;
decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
case ID_CPE:
if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele;
decode_cpe(hDecoder, hInfo, ld, id_syn_ele);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
case ID_LFE:
hDecoder->has_lfe++;
decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
@@ -448,7 +470,6 @@ void raw_data_block(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
/* SBR data will be read directly in the SCE/LFE/CPE element */
if ((hInfo->error = fill_element(hDecoder, ld, drc
#ifdef SBR_DEC
- //, (ch_ele == 0) ? INVALID_SBR_ELEMENT : (ch_ele-1)
, INVALID_SBR_ELEMENT
#endif
)) > 0)
@@ -463,67 +484,48 @@ void raw_data_block(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
{
case 1:
decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
case 2:
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
case 3:
decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
case 4:
decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
case 5:
decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
case 6:
decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
decode_sce_lfe(hDecoder, hInfo, ld, ID_LFE);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
- case 7:
+ case 7: /* 8 channels */
decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
decode_cpe(hDecoder, hInfo, ld, ID_CPE);
- ch_ele++;
decode_sce_lfe(hDecoder, hInfo, ld, ID_LFE);
- ch_ele++;
if (hInfo->error > 0)
return;
break;
@@ -995,6 +997,12 @@ static uint8_t fill_element(faacDecHandle hDecoder, bitfile *ld, drc_info *drc
/* parse the SBR data */
hDecoder->sbr[sbr_ele]->ret = sbr_extension_data(ld, hDecoder->sbr[sbr_ele], count);
+#if (defined(PS_DEC) || defined(DRM_PS))
+ if (hDecoder->sbr[sbr_ele]->ps_used)
+ {
+ hDecoder->ps_used[sbr_ele] = 1;
+ }
+#endif
} else {
#endif
while (count > 0)
@@ -1133,6 +1141,8 @@ void aac_scalable_main_element(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
else
cpe.ele_id = ID_SCE;
+ hDecoder->element_output_channels[hDecoder->fr_ch_ele] = (this_layer_stereo ? 2 : 0);
+
for (ch = 0; ch < (this_layer_stereo ? 2 : 1); ch++)
{
ic_stream *ics;
@@ -1145,9 +1155,6 @@ void aac_scalable_main_element(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
spec_data = spec_data2;
}
- hDecoder->internal_channel[channels+ch] = channels+ch;
- hDecoder->channel_element[channels+ch] = hDecoder->fr_ch_ele;
-
hInfo->error = individual_channel_stream(hDecoder, &cpe, ld, ics, 1, spec_data);
if (hInfo->error > 0)
return;
@@ -1202,6 +1209,12 @@ void aac_scalable_main_element(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
faad_getbits(&ld_sbr, 8); /* Skip 8-bit CRC */
hDecoder->sbr[0]->ret = sbr_extension_data(&ld_sbr, hDecoder->sbr[0], count);
+#if (defined(PS_DEC) || defined(DRM_PS))
+ if (hDecoder->sbr[0]->ps_used)
+ {
+ hDecoder->ps_used[0] = 1;
+ }
+#endif
/* check CRC */
/* no need to check it if there was already an error */
@@ -1227,9 +1240,19 @@ void aac_scalable_main_element(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
return;
}
+ /* map output channels position to internal data channels */
+ if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2)
+ {
+ /* this might be faulty when pce_set is true */
+ hDecoder->internal_channel[channels] = channels;
+ hDecoder->internal_channel[channels+1] = channels+1;
+ } else {
+ hDecoder->internal_channel[channels] = channels;
+ }
+
hDecoder->element_id[hDecoder->fr_ch_ele] = cpe.ele_id;
- hDecoder->fr_channels += (this_layer_stereo ? 2 : 1);
+ hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele];
hDecoder->fr_ch_ele++;
return;
@@ -1624,8 +1647,6 @@ static uint8_t decode_scale_factors(ic_stream *ics, bitfile *ld)
/* decode intensity position */
t = huffman_scale_factor(ld);
- if (t < 0)
- return 9;
is_position += (t - 60);
ics->scale_factors[g][sfb] = is_position;
@@ -1640,8 +1661,6 @@ static uint8_t decode_scale_factors(ic_stream *ics, bitfile *ld)
DEBUGVAR(1,73,"scale_factor_data(): first noise")) - 256;
} else {
t = huffman_scale_factor(ld);
- if (t < 0)
- return 9;
t -= 60;
}
noise_energy += t;
@@ -1656,8 +1675,6 @@ static uint8_t decode_scale_factors(ic_stream *ics, bitfile *ld)
/* decode scale factor */
t = huffman_scale_factor(ld);
- if (t < 0)
- return 9;
scale_factor += (t - 60);
if (scale_factor < 0 || scale_factor > 255)
return 4;