annotate libfaad2/syntax.c @ 31465:65a4a8ddb552

Remove duplicated MKTAG macro definition, #include libavutil/common.h instead.
author diego
date Wed, 23 Jun 2010 10:59:26 +0000
parents e83eef58b30a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 25836
diff changeset
4 **
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 25836
diff changeset
9 **
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 25836
diff changeset
14 **
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 25836
diff changeset
16 ** along with this program; if not, write to the Free Software
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
25 ** $Id: syntax.c,v 1.82 2004/09/04 14:56:29 menno Exp $
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 Reads the AAC bitstream as defined in 14496-3 (MPEG-4 Audio)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include <string.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "decoder.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 #include "specrec.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 #include "huffman.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 #include "bits.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 #include "pulse.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 #include "analysis.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 #include "drc.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 #include "rvlc.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 #include "sbr_syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 #endif
25833
ed27d1c01f93 in GASpecificConfig 1 bit (extensionflag3) wasn't being read and the comment was misplaced, too
nicodvb
parents: 18141
diff changeset
52 #include "mp4.h"
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
55 /* static function declarations */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
56 static void decode_sce_lfe(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
57 uint8_t id_syn_ele);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
58 static void decode_cpe(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
59 uint8_t id_syn_ele);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
60 static uint8_t single_lfe_channel_element(NeAACDecHandle hDecoder, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
61 uint8_t channel, uint8_t *tag);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
62 static uint8_t channel_pair_element(NeAACDecHandle hDecoder, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
63 uint8_t channel, uint8_t *tag);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
64 #ifdef COUPLING_DEC
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
65 static uint8_t coupling_channel_element(NeAACDecHandle hDecoder, bitfile *ld);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
66 #endif
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
67 static uint16_t data_stream_element(NeAACDecHandle hDecoder, bitfile *ld);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
68 static uint8_t program_config_element(program_config *pce, bitfile *ld);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
69 static uint8_t fill_element(NeAACDecHandle hDecoder, bitfile *ld, drc_info *drc
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
70 #ifdef SBR_DEC
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
71 ,uint8_t sbr_ele
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
72 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
73 );
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
74 static uint8_t individual_channel_stream(NeAACDecHandle hDecoder, element *ele,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
75 bitfile *ld, ic_stream *ics, uint8_t scal_flag,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
76 int16_t *spec_data);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
77 static uint8_t ics_info(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
78 uint8_t common_window);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
79 static uint8_t section_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
80 static uint8_t scale_factor_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
81 #ifdef SSR_DEC
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
82 static void gain_control_data(bitfile *ld, ic_stream *ics);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
83 #endif
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
84 static uint8_t spectral_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
85 int16_t *spectral_data);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
86 static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
87 static uint8_t pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
88 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
89 #ifdef LTP_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
90 static uint8_t ltp_data(NeAACDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
91 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
92 static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
93 static void adts_variable_header(adts_header *adts, bitfile *ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
94 static void adts_error_check(adts_header *adts, bitfile *ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
95 static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
96 static uint8_t excluded_channels(bitfile *ld, drc_info *drc);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
97 #ifdef SCALABLE_DEC
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
98 static int8_t aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
99 bitfile *ld, uint8_t this_layer_stereo);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
100 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
101
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
102
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 /* Table 4.4.1 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 int8_t GASpecificConfig(bitfile *ld, mp4AudioSpecificConfig *mp4ASC,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 program_config *pce_out)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 program_config pce;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 /* 1024 or 960 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 mp4ASC->frameLengthFlag = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 DEBUGVAR(1,138,"GASpecificConfig(): FrameLengthFlag"));
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
112 #ifndef ALLOW_SMALL_FRAMELENGTH
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
113 if (mp4ASC->frameLengthFlag == 1)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
114 return -3;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
115 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 mp4ASC->dependsOnCoreCoder = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 DEBUGVAR(1,139,"GASpecificConfig(): DependsOnCoreCoder"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 if (mp4ASC->dependsOnCoreCoder == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 mp4ASC->coreCoderDelay = (uint16_t)faad_getbits(ld, 14
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 DEBUGVAR(1,140,"GASpecificConfig(): CoreCoderDelay"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 mp4ASC->extensionFlag = faad_get1bit(ld DEBUGVAR(1,141,"GASpecificConfig(): ExtensionFlag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 if (mp4ASC->channelsConfiguration == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
128 if (program_config_element(&pce, ld))
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
129 return -3;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 //mp4ASC->channelsConfiguration = pce.channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 if (pce_out != NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 memcpy(pce_out, &pce, sizeof(program_config));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 if (pce.num_valid_cc_elements)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 return -3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 if (mp4ASC->extensionFlag == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 /* Error resilience not supported yet */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 if (mp4ASC->objectTypeIndex >= ER_OBJECT_START)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 mp4ASC->aacSectionDataResilienceFlag = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 DEBUGVAR(1,144,"GASpecificConfig(): aacSectionDataResilienceFlag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 mp4ASC->aacScalefactorDataResilienceFlag = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 DEBUGVAR(1,145,"GASpecificConfig(): aacScalefactorDataResilienceFlag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 mp4ASC->aacSpectralDataResilienceFlag = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 DEBUGVAR(1,146,"GASpecificConfig(): aacSpectralDataResilienceFlag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 }
25833
ed27d1c01f93 in GASpecificConfig 1 bit (extensionflag3) wasn't being read and the comment was misplaced, too
nicodvb
parents: 18141
diff changeset
154 /* 1 bit: extensionFlag3 */
ed27d1c01f93 in GASpecificConfig 1 bit (extensionflag3) wasn't being read and the comment was misplaced, too
nicodvb
parents: 18141
diff changeset
155 faad_getbits(ld, 1);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 /* Table 4.4.2 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 /* An MPEG-4 Audio decoder is only required to follow the Program
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 Configuration Element in GASpecificConfig(). The decoder shall ignore
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 any Program Configuration Elements that may occur in raw data blocks.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 PCEs transmitted in raw data blocks cannot be used to convey decoder
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 configuration information.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
169 static uint8_t program_config_element(program_config *pce, bitfile *ld)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 memset(pce, 0, sizeof(program_config));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 pce->channels = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 pce->element_instance_tag = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 DEBUGVAR(1,10,"program_config_element(): element_instance_tag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 pce->object_type = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 DEBUGVAR(1,11,"program_config_element(): object_type"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 pce->sf_index = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 DEBUGVAR(1,12,"program_config_element(): sf_index"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 pce->num_front_channel_elements = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 DEBUGVAR(1,13,"program_config_element(): num_front_channel_elements"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 pce->num_side_channel_elements = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 DEBUGVAR(1,14,"program_config_element(): num_side_channel_elements"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 pce->num_back_channel_elements = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 DEBUGVAR(1,15,"program_config_element(): num_back_channel_elements"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 pce->num_lfe_channel_elements = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 DEBUGVAR(1,16,"program_config_element(): num_lfe_channel_elements"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 pce->num_assoc_data_elements = (uint8_t)faad_getbits(ld, 3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 DEBUGVAR(1,17,"program_config_element(): num_assoc_data_elements"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 pce->num_valid_cc_elements = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 DEBUGVAR(1,18,"program_config_element(): num_valid_cc_elements"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 pce->mono_mixdown_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 DEBUGVAR(1,19,"program_config_element(): mono_mixdown_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 if (pce->mono_mixdown_present == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 pce->mono_mixdown_element_number = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 DEBUGVAR(1,20,"program_config_element(): mono_mixdown_element_number"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 pce->stereo_mixdown_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 DEBUGVAR(1,21,"program_config_element(): stereo_mixdown_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 if (pce->stereo_mixdown_present == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 pce->stereo_mixdown_element_number = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 DEBUGVAR(1,22,"program_config_element(): stereo_mixdown_element_number"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 pce->matrix_mixdown_idx_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 DEBUGVAR(1,23,"program_config_element(): matrix_mixdown_idx_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 if (pce->matrix_mixdown_idx_present == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 pce->matrix_mixdown_idx = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 DEBUGVAR(1,24,"program_config_element(): matrix_mixdown_idx"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 pce->pseudo_surround_enable = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 DEBUGVAR(1,25,"program_config_element(): pseudo_surround_enable"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 for (i = 0; i < pce->num_front_channel_elements; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 pce->front_element_is_cpe[i] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 DEBUGVAR(1,26,"program_config_element(): front_element_is_cpe"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 pce->front_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 DEBUGVAR(1,27,"program_config_element(): front_element_tag_select"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 if (pce->front_element_is_cpe[i] & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 pce->cpe_channel[pce->front_element_tag_select[i]] = pce->channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 pce->num_front_channels += 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 pce->channels += 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 pce->sce_channel[pce->front_element_tag_select[i]] = pce->channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 pce->num_front_channels++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 pce->channels++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 for (i = 0; i < pce->num_side_channel_elements; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 pce->side_element_is_cpe[i] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 DEBUGVAR(1,28,"program_config_element(): side_element_is_cpe"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 pce->side_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 DEBUGVAR(1,29,"program_config_element(): side_element_tag_select"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 if (pce->side_element_is_cpe[i] & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 pce->cpe_channel[pce->side_element_tag_select[i]] = pce->channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 pce->num_side_channels += 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 pce->channels += 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 pce->sce_channel[pce->side_element_tag_select[i]] = pce->channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 pce->num_side_channels++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 pce->channels++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 for (i = 0; i < pce->num_back_channel_elements; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 pce->back_element_is_cpe[i] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 DEBUGVAR(1,30,"program_config_element(): back_element_is_cpe"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 pce->back_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 DEBUGVAR(1,31,"program_config_element(): back_element_tag_select"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 if (pce->back_element_is_cpe[i] & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270 pce->cpe_channel[pce->back_element_tag_select[i]] = pce->channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 pce->channels += 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 pce->num_back_channels += 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 pce->sce_channel[pce->back_element_tag_select[i]] = pce->channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 pce->num_back_channels++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 pce->channels++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 for (i = 0; i < pce->num_lfe_channel_elements; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 pce->lfe_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 DEBUGVAR(1,32,"program_config_element(): lfe_element_tag_select"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 pce->sce_channel[pce->lfe_element_tag_select[i]] = pce->channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 pce->num_lfe_channels++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 pce->channels++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 for (i = 0; i < pce->num_assoc_data_elements; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 pce->assoc_data_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 DEBUGVAR(1,33,"program_config_element(): assoc_data_element_tag_select"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 for (i = 0; i < pce->num_valid_cc_elements; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 pce->cc_element_is_ind_sw[i] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 DEBUGVAR(1,34,"program_config_element(): cc_element_is_ind_sw"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 pce->valid_cc_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 DEBUGVAR(1,35,"program_config_element(): valid_cc_element_tag_select"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 faad_byte_align(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 pce->comment_field_bytes = (uint8_t)faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 DEBUGVAR(1,36,"program_config_element(): comment_field_bytes"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 for (i = 0; i < pce->comment_field_bytes; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309 pce->comment_field_data[i] = (uint8_t)faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 DEBUGVAR(1,37,"program_config_element(): comment_field_data"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 pce->comment_field_data[i] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
314 if (pce->channels > MAX_CHANNELS)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
315 return 22;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
316
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
320 static void decode_sce_lfe(NeAACDecHandle hDecoder,
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
321 NeAACDecFrameInfo *hInfo, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
322 uint8_t id_syn_ele)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 uint8_t channels = hDecoder->fr_channels;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
325 uint8_t tag = 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 if (channels+1 > MAX_CHANNELS)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 hInfo->error = 12;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
330 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 if (hDecoder->fr_ch_ele+1 > MAX_SYNTAX_ELEMENTS)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334 hInfo->error = 13;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
335 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
338 /* for SCE hDecoder->element_output_channels[] is not set here because this
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
339 can become 2 when some form of Parametric Stereo coding is used
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
340 */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
342 /* save the syntax element id */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
343 hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
345 /* decode the element */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
346 hInfo->error = single_lfe_channel_element(hDecoder, ld, channels, &tag);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
348 /* map output channels position to internal data channels */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
349 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
350 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
351 /* this might be faulty when pce_set is true */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 hDecoder->internal_channel[channels] = channels;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
353 hDecoder->internal_channel[channels+1] = channels+1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
354 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
355 if (hDecoder->pce_set)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
356 hDecoder->internal_channel[hDecoder->pce.sce_channel[tag]] = channels;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
357 else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
358 hDecoder->internal_channel[channels] = channels;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
359 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
361 hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362 hDecoder->fr_ch_ele++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
365 static void decode_cpe(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
366 uint8_t id_syn_ele)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 uint8_t channels = hDecoder->fr_channels;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
369 uint8_t tag = 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 if (channels+2 > MAX_CHANNELS)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373 hInfo->error = 12;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
374 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376 if (hDecoder->fr_ch_ele+1 > MAX_SYNTAX_ELEMENTS)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 hInfo->error = 13;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
379 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
382 /* for CPE the number of output channels is always 2 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
383 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
384 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
385 /* element_output_channels not set yet */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
386 hDecoder->element_output_channels[hDecoder->fr_ch_ele] = 2;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
387 } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != 2) {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
388 /* element inconsistency */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
389 hInfo->error = 21;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
390 return;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
391 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
393 /* save the syntax element id */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
394 hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
396 /* decode the element */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
397 hInfo->error = channel_pair_element(hDecoder, ld, channels, &tag);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
399 /* map output channel position to internal data channels */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 if (hDecoder->pce_set)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
402 hDecoder->internal_channel[hDecoder->pce.cpe_channel[tag]] = channels;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
403 hDecoder->internal_channel[hDecoder->pce.cpe_channel[tag]+1] = channels+1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 hDecoder->internal_channel[channels] = channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 hDecoder->internal_channel[channels+1] = channels+1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409 hDecoder->fr_channels += 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410 hDecoder->fr_ch_ele++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
413 void raw_data_block(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
414 bitfile *ld, program_config *pce, drc_info *drc)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 uint8_t id_syn_ele;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418 hDecoder->fr_channels = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 hDecoder->fr_ch_ele = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420 hDecoder->first_syn_ele = 25;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 hDecoder->has_lfe = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424 if (hDecoder->object_type < ER_OBJECT_START)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 /* Table 4.4.3: raw_data_block() */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 while ((id_syn_ele = (uint8_t)faad_getbits(ld, LEN_SE_ID
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
429 DEBUGVAR(1,4,"NeAACDecDecode(): id_syn_ele"))) != ID_END)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 switch (id_syn_ele) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 case ID_SCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433 if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
434 decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
436 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
437 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438 case ID_CPE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439 if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
440 decode_cpe(hDecoder, hInfo, ld, id_syn_ele);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
442 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
444 case ID_LFE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445 hDecoder->has_lfe++;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
446 decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
448 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450 case ID_CCE: /* not implemented yet, but skip the bits */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
451 #ifdef COUPLING_DEC
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452 hInfo->error = coupling_channel_element(hDecoder, ld);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
453 #else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
454 hInfo->error = 6;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
455 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
457 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 case ID_DSE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460 data_stream_element(hDecoder, ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462 case ID_PCE:
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
463 /* 14496-4: 5.6.4.1.2.1.3: */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
464 /* program_configuration_element()'s in access units shall be ignored */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
465 program_config_element(pce, ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
466 //if ((hInfo->error = program_config_element(pce, ld)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
467 // return;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
468 //hDecoder->pce_set = 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470 case ID_FIL:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471 /* one sbr_info describes a channel_element not a channel! */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
472 /* if we encounter SBR data here: error */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
473 /* SBR data will be read directly in the SCE/LFE/CPE element */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 if ((hInfo->error = fill_element(hDecoder, ld, drc
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475 #ifdef SBR_DEC
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
476 , INVALID_SBR_ELEMENT
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478 )) > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
479 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 /* Table 262: er_raw_data_block() */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486 switch (hDecoder->channelConfiguration)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488 case 1:
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
489 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
490 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
491 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493 case 2:
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
494 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
496 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
498 case 3:
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
499 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
500 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
502 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 case 4:
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
505 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
506 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
507 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
509 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511 case 5:
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
512 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
513 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
514 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
516 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
517 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
518 case 6:
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
519 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
520 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
521 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
522 decode_sce_lfe(hDecoder, hInfo, ld, ID_LFE);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
524 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 break;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
526 case 7: /* 8 channels */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
527 decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
528 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
529 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
530 decode_cpe(hDecoder, hInfo, ld, ID_CPE);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
531 decode_sce_lfe(hDecoder, hInfo, ld, ID_LFE);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
532 if (hInfo->error > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
533 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
534 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
535 default:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
536 hInfo->error = 7;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
537 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
538 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
539 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
540 cnt = bits_to_decode() / 8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
541 while (cnt >= 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
542 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
543 cnt -= extension_payload(cnt);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
544 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
545 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
546 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
547 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
548
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
549 /* new in corrigendum 14496-3:2002 */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
550 #ifdef DRM
25836
bc425ba00960 added code to check and handle the presence of LATM streams in the init() and decode() functions
nicodvb
parents: 25834
diff changeset
551 if (hDecoder->object_type != DRM_ER_LC && !hDecoder->latm_header_present)
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
552 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
553 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
554 faad_byte_align(ld);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
555 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
556
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
557 return;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
558 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
559
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
560 /* Table 4.4.4 and */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
561 /* Table 4.4.9 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
562 static uint8_t single_lfe_channel_element(NeAACDecHandle hDecoder, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
563 uint8_t channel, uint8_t *tag)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
564 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
565 uint8_t retval = 0;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
566 element sce = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
567 ic_stream *ics = &(sce.ics1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
568 ALIGN int16_t spec_data[1024] = {0};
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
569
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
570 sce.element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
571 DEBUGVAR(1,38,"single_lfe_channel_element(): element_instance_tag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
572
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
573 *tag = sce.element_instance_tag;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
574 sce.channel = channel;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
575 sce.paired_channel = -1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
576
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
577 retval = individual_channel_stream(hDecoder, &sce, ld, ics, 0, spec_data);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
578 if (retval > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
579 return retval;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
580
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
581 #ifdef SBR_DEC
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
582 /* check if next bitstream element is a fill element */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
583 /* if so, read it now so SBR decoding can be done in case of a file with SBR */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
584 if (faad_showbits(ld, LEN_SE_ID) == ID_FIL)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
585 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
586 faad_flushbits(ld, LEN_SE_ID);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
587
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
588 /* one sbr_info describes a channel_element not a channel! */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
589 if ((retval = fill_element(hDecoder, ld, hDecoder->drc, hDecoder->fr_ch_ele)) > 0)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
590 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
591 return retval;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
592 }
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
593 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
594 #endif
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
595
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
596 /* noiseless coding is done, spectral reconstruction is done now */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
597 retval = reconstruct_single_channel(hDecoder, ics, &sce, spec_data);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
598 if (retval > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
599 return retval;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
600
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
601 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
602 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
603
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
604 /* Table 4.4.5 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
605 static uint8_t channel_pair_element(NeAACDecHandle hDecoder, bitfile *ld,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
606 uint8_t channels, uint8_t *tag)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
607 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
608 ALIGN int16_t spec_data1[1024] = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
609 ALIGN int16_t spec_data2[1024] = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
610 element cpe = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
611 ic_stream *ics1 = &(cpe.ics1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
612 ic_stream *ics2 = &(cpe.ics2);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
613 uint8_t result;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
614
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
615 cpe.channel = channels;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
616 cpe.paired_channel = channels+1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
617
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
618 cpe.element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
619 DEBUGVAR(1,39,"channel_pair_element(): element_instance_tag"));
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
620 *tag = cpe.element_instance_tag;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
621
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
622 if ((cpe.common_window = faad_get1bit(ld
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
623 DEBUGVAR(1,40,"channel_pair_element(): common_window"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
624 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
625 /* both channels have common ics information */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
626 if ((result = ics_info(hDecoder, ics1, ld, cpe.common_window)) > 0)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
627 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
628
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
629 ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
630 DEBUGVAR(1,41,"channel_pair_element(): ms_mask_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
631 if (ics1->ms_mask_present == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
632 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
633 uint8_t g, sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
634 for (g = 0; g < ics1->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
635 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
636 for (sfb = 0; sfb < ics1->max_sfb; sfb++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
637 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
638 ics1->ms_used[g][sfb] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
639 DEBUGVAR(1,42,"channel_pair_element(): faad_get1bit"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
640 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
641 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
642 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
643
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
644 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
645 if ((hDecoder->object_type >= ER_OBJECT_START) && (ics1->predictor_data_present))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
646 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
647 if ((
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
648 #ifdef LTP_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
649 ics1->ltp.data_present =
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
650 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
651 faad_get1bit(ld DEBUGVAR(1,50,"channel_pair_element(): ltp.data_present"))) & 1)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
652 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
653 #ifdef LTP_DEC
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
654 if ((result = ltp_data(hDecoder, ics1, &(ics1->ltp), ld)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
655 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
656 return result;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
657 }
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
658 #else
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
659 return 26;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
660 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
661 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
662 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
663 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
664
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
665 memcpy(ics2, ics1, sizeof(ic_stream));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
666 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
667 ics1->ms_mask_present = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
668 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
669
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
670 if ((result = individual_channel_stream(hDecoder, &cpe, ld, ics1,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
671 0, spec_data1)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
672 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
673 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
674 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
675
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
676 #ifdef ERROR_RESILIENCE
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
677 if (cpe.common_window && (hDecoder->object_type >= ER_OBJECT_START) &&
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
678 (ics1->predictor_data_present))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
679 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
680 if ((
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
681 #ifdef LTP_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
682 ics1->ltp2.data_present =
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
683 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
684 faad_get1bit(ld DEBUGVAR(1,50,"channel_pair_element(): ltp.data_present"))) & 1)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
685 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
686 #ifdef LTP_DEC
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
687 if ((result = ltp_data(hDecoder, ics1, &(ics1->ltp2), ld)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
688 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
689 return result;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
690 }
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
691 #else
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
692 return 26;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
693 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
694 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
695 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
696 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
697
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
698 if ((result = individual_channel_stream(hDecoder, &cpe, ld, ics2,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
699 0, spec_data2)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
700 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
701 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
702 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
703
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
704 #ifdef SBR_DEC
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
705 /* check if next bitstream element is a fill element */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
706 /* if so, read it now so SBR decoding can be done in case of a file with SBR */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
707 if (faad_showbits(ld, LEN_SE_ID) == ID_FIL)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
708 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
709 faad_flushbits(ld, LEN_SE_ID);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
710
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
711 /* one sbr_info describes a channel_element not a channel! */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
712 if ((result = fill_element(hDecoder, ld, hDecoder->drc, hDecoder->fr_ch_ele)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
713 {
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
714 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
715 }
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
716 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
717 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
718
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
719 /* noiseless coding is done, spectral reconstruction is done now */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
720 if ((result = reconstruct_channel_pair(hDecoder, ics1, ics2, &cpe,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
721 spec_data1, spec_data2)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
722 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
723 return result;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
724 }
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
725
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
726 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
727 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
728
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
729 /* Table 4.4.6 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
730 static uint8_t ics_info(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
731 uint8_t common_window)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
732 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
733 uint8_t retval = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
734
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
735 /* ics->ics_reserved_bit = */ faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
736 DEBUGVAR(1,43,"ics_info(): ics_reserved_bit"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
737 ics->window_sequence = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
738 DEBUGVAR(1,44,"ics_info(): window_sequence"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
739 ics->window_shape = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
740 DEBUGVAR(1,45,"ics_info(): window_shape"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
741
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
742 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
743 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
744 ics->max_sfb = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
745 DEBUGVAR(1,46,"ics_info(): max_sfb (short)"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
746 ics->scale_factor_grouping = (uint8_t)faad_getbits(ld, 7
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
747 DEBUGVAR(1,47,"ics_info(): scale_factor_grouping"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
748 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
749 ics->max_sfb = (uint8_t)faad_getbits(ld, 6
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
750 DEBUGVAR(1,48,"ics_info(): max_sfb (long)"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
751 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
752
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
753 /* get the grouping information */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
754 if ((retval = window_grouping_info(hDecoder, ics)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
755 return retval;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
756
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
757 /* should be an error */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
758 /* check the range of max_sfb */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
759 if (ics->max_sfb > ics->num_swb)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
760 return 16;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
761
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
762 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
763 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
764 if ((ics->predictor_data_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
765 DEBUGVAR(1,49,"ics_info(): predictor_data_present"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
766 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
767 if (hDecoder->object_type == MAIN) /* MPEG2 style AAC predictor */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
768 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
769 uint8_t sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
770
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
771 uint8_t limit = min(ics->max_sfb, max_pred_sfb(hDecoder->sf_index));
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
772 #ifdef MAIN_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
773 ics->pred.limit = limit;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
774 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
775
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
776 if ((
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
777 #ifdef MAIN_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
778 ics->pred.predictor_reset =
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
779 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
780 faad_get1bit(ld DEBUGVAR(1,53,"ics_info(): pred.predictor_reset"))) & 1)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
781 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
782 #ifdef MAIN_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
783 ics->pred.predictor_reset_group_number =
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
784 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
785 (uint8_t)faad_getbits(ld, 5 DEBUGVAR(1,54,"ics_info(): pred.predictor_reset_group_number"));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
786 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
787
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
788 for (sfb = 0; sfb < limit; sfb++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
789 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
790 #ifdef MAIN_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
791 ics->pred.prediction_used[sfb] =
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
792 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
793 faad_get1bit(ld DEBUGVAR(1,55,"ics_info(): pred.prediction_used"));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
794 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
795 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
796 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
797 else { /* Long Term Prediction */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
798 if (hDecoder->object_type < ER_OBJECT_START)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
799 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
800 if ((ics->ltp.data_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
801 DEBUGVAR(1,50,"ics_info(): ltp.data_present"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
802 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
803 if ((retval = ltp_data(hDecoder, ics, &(ics->ltp), ld)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
804 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
805 return retval;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
806 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
807 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
808 if (common_window)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
809 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
810 if ((ics->ltp2.data_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
811 DEBUGVAR(1,51,"ics_info(): ltp2.data_present"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
812 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
813 if ((retval = ltp_data(hDecoder, ics, &(ics->ltp2), ld)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
814 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
815 return retval;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
816 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
817 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
818 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
819 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
820 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
821 if (!common_window && (hDecoder->object_type >= ER_OBJECT_START))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
822 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
823 if ((ics->ltp.data_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
824 DEBUGVAR(1,50,"ics_info(): ltp.data_present"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
825 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
826 ltp_data(hDecoder, ics, &(ics->ltp), ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
827 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
828 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
829 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
830 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
831 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
832 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
833 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
834
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
835 return retval;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
836 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
837
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
838 /* Table 4.4.7 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
839 static uint8_t pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
840 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
841 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
842
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
843 pul->number_pulse = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
844 DEBUGVAR(1,56,"pulse_data(): number_pulse"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
845 pul->pulse_start_sfb = (uint8_t)faad_getbits(ld, 6
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
846 DEBUGVAR(1,57,"pulse_data(): pulse_start_sfb"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
847
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
848 /* check the range of pulse_start_sfb */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
849 if (pul->pulse_start_sfb > ics->num_swb)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
850 return 16;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
851
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
852 for (i = 0; i < pul->number_pulse+1; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
853 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
854 pul->pulse_offset[i] = (uint8_t)faad_getbits(ld, 5
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
855 DEBUGVAR(1,58,"pulse_data(): pulse_offset"));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
856 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
857 printf("%d\n", pul->pulse_offset[i]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
858 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
859 pul->pulse_amp[i] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
860 DEBUGVAR(1,59,"pulse_data(): pulse_amp"));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
861 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
862 printf("%d\n", pul->pulse_amp[i]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
863 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
864 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
865
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
866 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
867 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
868
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
869 #ifdef COUPLING_DEC
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
870 /* Table 4.4.8: Currently just for skipping the bits... */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
871 static uint8_t coupling_channel_element(NeAACDecHandle hDecoder, bitfile *ld)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
872 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
873 uint8_t c, result = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
874 uint8_t ind_sw_cce_flag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
875 uint8_t num_gain_element_lists = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
876 uint8_t num_coupled_elements = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
877
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
878 element el_empty = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
879 ic_stream ics_empty = {0};
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
880 int16_t sh_data[1024];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
881
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
882 c = faad_getbits(ld, LEN_TAG
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
883 DEBUGVAR(1,900,"coupling_channel_element(): element_instance_tag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
884
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
885 ind_sw_cce_flag = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
886 DEBUGVAR(1,901,"coupling_channel_element(): ind_sw_cce_flag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
887 num_coupled_elements = faad_getbits(ld, 3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
888 DEBUGVAR(1,902,"coupling_channel_element(): num_coupled_elements"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
889
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
890 for (c = 0; c < num_coupled_elements + 1; c++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
891 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
892 uint8_t cc_target_is_cpe, cc_target_tag_select;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
893
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
894 num_gain_element_lists++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
895
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
896 cc_target_is_cpe = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
897 DEBUGVAR(1,903,"coupling_channel_element(): cc_target_is_cpe"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
898 cc_target_tag_select = faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
899 DEBUGVAR(1,904,"coupling_channel_element(): cc_target_tag_select"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
900
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
901 if (cc_target_is_cpe)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
902 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
903 uint8_t cc_l = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
904 DEBUGVAR(1,905,"coupling_channel_element(): cc_l"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
905 uint8_t cc_r = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
906 DEBUGVAR(1,906,"coupling_channel_element(): cc_r"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
907
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
908 if (cc_l && cc_r)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
909 num_gain_element_lists++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
910 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
911 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
912
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
913 faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
914 DEBUGVAR(1,907,"coupling_channel_element(): cc_domain"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
915 faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
916 DEBUGVAR(1,908,"coupling_channel_element(): gain_element_sign"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
917 faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
918 DEBUGVAR(1,909,"coupling_channel_element(): gain_element_scale"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
919
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
920 if ((result = individual_channel_stream(hDecoder, &el_empty, ld, &ics_empty,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
921 0, sh_data)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
922 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
923 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
924 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
925
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
926 for (c = 1; c < num_gain_element_lists; c++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
927 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
928 uint8_t cge;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
929
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
930 if (ind_sw_cce_flag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
931 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
932 cge = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
933 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
934 cge = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
935 DEBUGVAR(1,910,"coupling_channel_element(): common_gain_element_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
936 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
937
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
938 if (cge)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
939 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
940 huffman_scale_factor(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
941 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
942 uint8_t g, sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
943
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
944 for (g = 0; g < ics_empty.num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
945 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
946 for (sfb = 0; sfb < ics_empty.max_sfb; sfb++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
947 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
948 if (ics_empty.sfb_cb[g][sfb] != ZERO_HCB)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
949 huffman_scale_factor(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
950 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
951 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
952 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
953 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
954
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
955 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
956 }
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
957 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
958
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
959 /* Table 4.4.10 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
960 static uint16_t data_stream_element(NeAACDecHandle hDecoder, bitfile *ld)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
961 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
962 uint8_t byte_aligned;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
963 uint16_t i, count;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
964
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
965 /* element_instance_tag = */ faad_getbits(ld, LEN_TAG
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
966 DEBUGVAR(1,60,"data_stream_element(): element_instance_tag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
967 byte_aligned = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
968 DEBUGVAR(1,61,"data_stream_element(): byte_aligned"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
969 count = (uint16_t)faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
970 DEBUGVAR(1,62,"data_stream_element(): count"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
971 if (count == 255)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
972 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
973 count += (uint16_t)faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
974 DEBUGVAR(1,63,"data_stream_element(): extra count"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
975 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
976 if (byte_aligned)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
977 faad_byte_align(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
978
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
979 for (i = 0; i < count; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
980 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
981 faad_getbits(ld, LEN_BYTE
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
982 DEBUGVAR(1,64,"data_stream_element(): data_stream_byte"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
983 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
984
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
985 return count;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
986 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
987
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
988 /* Table 4.4.11 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
989 static uint8_t fill_element(NeAACDecHandle hDecoder, bitfile *ld, drc_info *drc
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
990 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
991 ,uint8_t sbr_ele
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
992 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
993 )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
994 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
995 uint16_t count;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
996 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
997 uint8_t bs_extension_type;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
998 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
999
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1000 count = (uint16_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1001 DEBUGVAR(1,65,"fill_element(): count"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1002 if (count == 15)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1003 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1004 count += (uint16_t)faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1005 DEBUGVAR(1,66,"fill_element(): extra count")) - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1006 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1007
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1008 if (count > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1009 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1010 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1011 bs_extension_type = (uint8_t)faad_showbits(ld, 4);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1012
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1013 if ((bs_extension_type == EXT_SBR_DATA) ||
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1014 (bs_extension_type == EXT_SBR_DATA_CRC))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1015 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1016 if (sbr_ele == INVALID_SBR_ELEMENT)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1017 return 24;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1018
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1019 if (!hDecoder->sbr[sbr_ele])
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1020 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1021 hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength,
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1022 hDecoder->element_id[sbr_ele], 2*get_sample_rate(hDecoder->sf_index),
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1023 hDecoder->downSampledSBR
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1024 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1025 , 0
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1026 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1027 );
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1028 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1029
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1030 hDecoder->sbr_present_flag = 1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1031
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1032 /* parse the SBR data */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1033 hDecoder->sbr[sbr_ele]->ret = sbr_extension_data(ld, hDecoder->sbr[sbr_ele], count);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1034
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1035 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1036 if (hDecoder->sbr[sbr_ele]->ret > 0)
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1037 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1038 printf("%s\n", NeAACDecGetErrorMessage(hDecoder->sbr[sbr_ele]->ret));
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1039 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1040 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1041
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1042 #if (defined(PS_DEC) || defined(DRM_PS))
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1043 if (hDecoder->sbr[sbr_ele]->ps_used)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1044 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1045 hDecoder->ps_used[sbr_ele] = 1;
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1046
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1047 /* set element independent flag to 1 as well */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1048 hDecoder->ps_used_global = 1;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1049 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1050 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1051 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1052 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1053 while (count > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1054 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1055 count -= extension_payload(ld, drc, count);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1056 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1057 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1058 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1059 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1060 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1061
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1062 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1063 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1064
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1065 /* Table 4.4.12 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1066 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1067 static void gain_control_data(bitfile *ld, ic_stream *ics)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1068 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1069 uint8_t bd, wd, ad;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1070 ssr_info *ssr = &(ics->ssr);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1071
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1072 ssr->max_band = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1073 DEBUGVAR(1,1000,"gain_control_data(): max_band"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1074
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1075 if (ics->window_sequence == ONLY_LONG_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1076 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1077 for (bd = 1; bd <= ssr->max_band; bd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1078 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1079 for (wd = 0; wd < 1; wd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1080 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1081 ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1082 DEBUGVAR(1,1001,"gain_control_data(): adjust_num"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1083
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1084 for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1085 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1086 ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1087 DEBUGVAR(1,1002,"gain_control_data(): alevcode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1088 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 5
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1089 DEBUGVAR(1,1003,"gain_control_data(): aloccode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1090 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1091 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1092 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1093 } else if (ics->window_sequence == LONG_START_SEQUENCE) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1094 for (bd = 1; bd <= ssr->max_band; bd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1095 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1096 for (wd = 0; wd < 2; wd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1097 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1098 ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1099 DEBUGVAR(1,1001,"gain_control_data(): adjust_num"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1100
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1101 for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1102 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1103 ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1104 DEBUGVAR(1,1002,"gain_control_data(): alevcode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1105 if (wd == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1106 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1107 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1108 DEBUGVAR(1,1003,"gain_control_data(): aloccode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1109 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1110 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1111 DEBUGVAR(1,1003,"gain_control_data(): aloccode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1112 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1113 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1114 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1115 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1116 } else if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1117 for (bd = 1; bd <= ssr->max_band; bd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1118 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1119 for (wd = 0; wd < 8; wd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1120 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1121 ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1122 DEBUGVAR(1,1001,"gain_control_data(): adjust_num"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1123
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1124 for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1125 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1126 ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1127 DEBUGVAR(1,1002,"gain_control_data(): alevcode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1128 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1129 DEBUGVAR(1,1003,"gain_control_data(): aloccode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1130 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1131 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1132 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1133 } else if (ics->window_sequence == LONG_STOP_SEQUENCE) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1134 for (bd = 1; bd <= ssr->max_band; bd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1135 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1136 for (wd = 0; wd < 2; wd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1137 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1138 ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1139 DEBUGVAR(1,1001,"gain_control_data(): adjust_num"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1140
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1141 for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1142 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1143 ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1144 DEBUGVAR(1,1002,"gain_control_data(): alevcode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1146 if (wd == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1147 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1148 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1149 DEBUGVAR(1,1003,"gain_control_data(): aloccode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1150 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1151 ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 5
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1152 DEBUGVAR(1,1003,"gain_control_data(): aloccode"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1153 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1154 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1155 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1156 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1157 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1158 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1159 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1160
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1161 #ifdef SCALABLE_DEC
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1162 /* Table 4.4.13 ASME */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1163 void aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1164 bitfile *ld, program_config *pce, drc_info *drc)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1165 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1166 uint8_t retval = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1167 uint8_t channels = hDecoder->fr_channels = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1168 uint8_t ch;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1169 uint8_t this_layer_stereo = (hDecoder->channelConfiguration > 1) ? 1 : 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1170 element cpe = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1171 ic_stream *ics1 = &(cpe.ics1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1172 ic_stream *ics2 = &(cpe.ics2);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1173 int16_t *spec_data;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1174 ALIGN int16_t spec_data1[1024] = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1175 ALIGN int16_t spec_data2[1024] = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1176
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1177 hDecoder->fr_ch_ele = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1178
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1179 hInfo->error = aac_scalable_main_header(hDecoder, ics1, ics2, ld, this_layer_stereo);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1180 if (hInfo->error > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1181 return;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1182
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1183 cpe.common_window = 1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1184 if (this_layer_stereo)
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1185 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1186 hDecoder->element_id[0] = ID_CPE;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1187 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0)
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1188 hDecoder->element_output_channels[hDecoder->fr_ch_ele] = 2;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1189 } else {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1190 hDecoder->element_id[0] = ID_SCE;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1191 }
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1192
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1193 for (ch = 0; ch < (this_layer_stereo ? 2 : 1); ch++)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1194 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1195 ic_stream *ics;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1196 if (ch == 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1197 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1198 ics = ics1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1199 spec_data = spec_data1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1200 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1201 ics = ics2;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1202 spec_data = spec_data2;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1203 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1204
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1205 hInfo->error = individual_channel_stream(hDecoder, &cpe, ld, ics, 1, spec_data);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1206 if (hInfo->error > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1207 return;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1208 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1209
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1210 #ifdef DRM
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1211 #ifdef SBR_DEC
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1212 /* In case of DRM we need to read the SBR info before channel reconstruction */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1213 if ((hDecoder->sbr_present_flag == 1) && (hDecoder->object_type == DRM_ER_LC))
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1214 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1215 bitfile ld_sbr = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1216 uint32_t i;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1217 uint16_t count = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1218 uint8_t *revbuffer;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1219 uint8_t *prevbufstart;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1220 uint8_t *pbufend;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1221
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1222 /* all forward bitreading should be finished at this point */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1223 uint32_t bitsconsumed = faad_get_processed_bits(ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1224 uint32_t buffer_size = faad_origbitbuffer_size(ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1225 uint8_t *buffer = (uint8_t*)faad_origbitbuffer(ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1226
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1227 if (bitsconsumed + 8 > buffer_size*8)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1228 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1229 hInfo->error = 14;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1230 return;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1231 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1232
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1233 if (!hDecoder->sbr[0])
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1234 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1235 hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0],
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1236 2*get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1237 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1238
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1239 /* Reverse bit reading of SBR data in DRM audio frame */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1240 revbuffer = (uint8_t*)faad_malloc(buffer_size*sizeof(uint8_t));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1241 prevbufstart = revbuffer;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1242 pbufend = &buffer[buffer_size - 1];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1243 for (i = 0; i < buffer_size; i++)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1244 *prevbufstart++ = tabFlipbits[*pbufend--];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1245
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1246 /* Set SBR data */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1247 /* consider 8 bits from AAC-CRC */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1248 count = (uint16_t)bit2byte(buffer_size*8 - bitsconsumed);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1249 faad_initbits(&ld_sbr, revbuffer, count);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1250
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1251 hDecoder->sbr[0]->sample_rate = get_sample_rate(hDecoder->sf_index);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1252 hDecoder->sbr[0]->sample_rate *= 2;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1253
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1254 faad_getbits(&ld_sbr, 8); /* Skip 8-bit CRC */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1255
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1256 hDecoder->sbr[0]->ret = sbr_extension_data(&ld_sbr, hDecoder->sbr[0], count);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1257 #if (defined(PS_DEC) || defined(DRM_PS))
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1258 if (hDecoder->sbr[0]->ps_used)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1259 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1260 hDecoder->ps_used[0] = 1;
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1261 hDecoder->ps_used_global = 1;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1262 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1263 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1264
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1265 /* check CRC */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1266 /* no need to check it if there was already an error */
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1267 if (hDecoder->sbr[0]->ret == 0)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1268 hDecoder->sbr[0]->ret = (uint8_t)faad_check_CRC(&ld_sbr, (uint16_t)faad_get_processed_bits(&ld_sbr) - 8);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1269
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1270 /* SBR data was corrupted, disable it until the next header */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1271 if (hDecoder->sbr[0]->ret != 0)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1272 {
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 25836
diff changeset
1273 hDecoder->sbr[0]->header_count = 0;
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
1274 }
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1275
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1276 faad_endbits(&ld_sbr);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1277
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1278 if (revbuffer)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1279 faad_free(revbuffer);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1280 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1281 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1282 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1283
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1284 if (this_layer_stereo)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1285 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1286 hInfo->error = reconstruct_channel_pair(hDecoder, ics1, ics2, &cpe, spec_data1, spec_data2);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1287 if (hInfo->error > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1288 return;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1289 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1290 hInfo->error = reconstruct_single_channel(hDecoder, ics1, &cpe, spec_data1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1291 if (hInfo->error > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1292 return;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1293 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1294
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1295 /* map output channels position to internal data channels */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1296 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1297 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1298 /* this might be faulty when pce_set is true */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1299 hDecoder->internal_channel[channels] = channels;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1300 hDecoder->internal_channel[channels+1] = channels+1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1301 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1302 hDecoder->internal_channel[channels] = channels;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1303 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1304
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1305 hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1306 hDecoder->fr_ch_ele++;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1307
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1308 return;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1309 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1310
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1311 /* Table 4.4.15 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1312 static int8_t aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1313 bitfile *ld, uint8_t this_layer_stereo)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1314 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1315 uint8_t retval = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1316 uint8_t ch;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1317 ic_stream *ics;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1318
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1319 /* ics1->ics_reserved_bit = */ faad_get1bit(ld
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1320 DEBUGVAR(1,300,"aac_scalable_main_header(): ics_reserved_bits"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1321 ics1->window_sequence = (uint8_t)faad_getbits(ld, 2
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1322 DEBUGVAR(1,301,"aac_scalable_main_header(): window_sequence"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1323 ics1->window_shape = faad_get1bit(ld
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1324 DEBUGVAR(1,302,"aac_scalable_main_header(): window_shape"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1325
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1326 if (ics1->window_sequence == EIGHT_SHORT_SEQUENCE)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1327 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1328 ics1->max_sfb = (uint8_t)faad_getbits(ld, 4
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1329 DEBUGVAR(1,303,"aac_scalable_main_header(): max_sfb (short)"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1330 ics1->scale_factor_grouping = (uint8_t)faad_getbits(ld, 7
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1331 DEBUGVAR(1,304,"aac_scalable_main_header(): scale_factor_grouping"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1332 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1333 ics1->max_sfb = (uint8_t)faad_getbits(ld, 6
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1334 DEBUGVAR(1,305,"aac_scalable_main_header(): max_sfb (long)"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1335 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1336
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1337 /* get the grouping information */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1338 if ((retval = window_grouping_info(hDecoder, ics1)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1339 return retval;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1340
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1341 /* should be an error */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1342 /* check the range of max_sfb */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1343 if (ics1->max_sfb > ics1->num_swb)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1344 return 16;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1345
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1346 if (this_layer_stereo)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1347 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1348 ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1349 DEBUGVAR(1,306,"aac_scalable_main_header(): ms_mask_present"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1350 if (ics1->ms_mask_present == 1)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1351 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1352 uint8_t g, sfb;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1353 for (g = 0; g < ics1->num_window_groups; g++)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1354 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1355 for (sfb = 0; sfb < ics1->max_sfb; sfb++)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1356 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1357 ics1->ms_used[g][sfb] = faad_get1bit(ld
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1358 DEBUGVAR(1,307,"aac_scalable_main_header(): faad_get1bit"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1359 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1360 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1361 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1362
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1363 memcpy(ics2, ics1, sizeof(ic_stream));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1364 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1365 ics1->ms_mask_present = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1366 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1367
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1368 if (0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1369 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1370 faad_get1bit(ld
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1371 DEBUGVAR(1,308,"aac_scalable_main_header(): tns_channel_mono_layer"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1372 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1373
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1374 for (ch = 0; ch < (this_layer_stereo ? 2 : 1); ch++)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1375 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1376 if (ch == 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1377 ics = ics1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1378 else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1379 ics = ics2;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1380
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1381 if ( 1 /*!tvq_layer_pesent || (tns_aac_tvq_en[ch] == 1)*/)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1382 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1383 if ((ics->tns_data_present = faad_get1bit(ld
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1384 DEBUGVAR(1,309,"aac_scalable_main_header(): tns_data_present"))) & 1)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1385 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1386 #ifdef DRM
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1387 /* different order of data units in DRM */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1388 if (hDecoder->object_type != DRM_ER_LC)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1389 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1390 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1391 tns_data(ics, &(ics->tns), ld);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1392 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1393 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1394 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1395 #if 0
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1396 if (0 /*core_flag || tvq_layer_pesent*/)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1397 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1398 if ((ch==0) || ((ch==1) && (core_stereo || tvq_stereo))
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1399 diff_control_data();
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1400 if (mono_stereo_flag)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1401 diff_control_data_lr();
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1402 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1403 #endif
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1404 if ((
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1405 #ifdef LTP_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1406 ics->ltp.data_present =
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1407 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1408 faad_get1bit(ld DEBUGVAR(1,310,"aac_scalable_main_header(): ltp.data_present"))) & 1)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1409 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1410 #ifdef LTP_DEC
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1411 if ((retval = ltp_data(hDecoder, ics, &(ics->ltp), ld)) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1412 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1413 return retval;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1414 }
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1415 #else
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1416 return 26;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1417 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1418 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1419 #if 0
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1420 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1421 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1422 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1423
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1424 return 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1425 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1426 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1427
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1428 /* Table 4.4.24 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1429 static uint8_t individual_channel_stream(NeAACDecHandle hDecoder, element *ele,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1430 bitfile *ld, ic_stream *ics, uint8_t scal_flag,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1431 int16_t *spec_data)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1432 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1433 uint8_t result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1434
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1435 ics->global_gain = (uint8_t)faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1436 DEBUGVAR(1,67,"individual_channel_stream(): global_gain"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1437
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1438 if (!ele->common_window && !scal_flag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1439 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1440 if ((result = ics_info(hDecoder, ics, ld, ele->common_window)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1441 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1442 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1443
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1444 if ((result = section_data(hDecoder, ics, ld)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1445 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1446
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1447 if ((result = scale_factor_data(hDecoder, ics, ld)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1448 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1449
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1450 if (!scal_flag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1451 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1452 /**
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1453 ** NOTE: It could be that pulse data is available in scalable AAC too,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1454 ** as said in Amendment 1, this could be only the case for ER AAC,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1455 ** though. (have to check this out later)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1456 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1457 /* get pulse data */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1458 if ((ics->pulse_data_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1459 DEBUGVAR(1,68,"individual_channel_stream(): pulse_data_present"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1460 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1461 if ((result = pulse_data(ics, &(ics->pul), ld)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1462 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1463 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1464
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1465 /* get tns data */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1466 if ((ics->tns_data_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1467 DEBUGVAR(1,69,"individual_channel_stream(): tns_data_present"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1468 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1469 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1470 if (hDecoder->object_type < ER_OBJECT_START)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1471 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1472 tns_data(ics, &(ics->tns), ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1473 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1474
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1475 /* get gain control data */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1476 if ((ics->gain_control_data_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1477 DEBUGVAR(1,70,"individual_channel_stream(): gain_control_data_present"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1478 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1479 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1480 if (hDecoder->object_type != SSR)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1481 return 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1482 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1483 gain_control_data(ld, ics);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1484 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1485 return 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1486 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1487 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1488 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1489
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1490 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1491 if (hDecoder->aacSpectralDataResilienceFlag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1492 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1493 ics->length_of_reordered_spectral_data = (uint16_t)faad_getbits(ld, 14
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1494 DEBUGVAR(1,147,"individual_channel_stream(): length_of_reordered_spectral_data"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1495
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1496 if (hDecoder->channelConfiguration == 2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1497 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1498 if (ics->length_of_reordered_spectral_data > 6144)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1499 ics->length_of_reordered_spectral_data = 6144;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1500 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1501 if (ics->length_of_reordered_spectral_data > 12288)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1502 ics->length_of_reordered_spectral_data = 12288;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1503 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1504
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1505 ics->length_of_longest_codeword = (uint8_t)faad_getbits(ld, 6
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1506 DEBUGVAR(1,148,"individual_channel_stream(): length_of_longest_codeword"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1507 if (ics->length_of_longest_codeword >= 49)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1508 ics->length_of_longest_codeword = 49;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1509 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1510
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1511 /* RVLC spectral data is put here */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1512 if (hDecoder->aacScalefactorDataResilienceFlag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1513 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1514 if ((result = rvlc_decode_scale_factors(ics, ld)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1515 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1516 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1517
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 25836
diff changeset
1518 if (hDecoder->object_type >= ER_OBJECT_START)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1519 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1520 if (ics->tns_data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1521 tns_data(ics, &(ics->tns), ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1522 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1523
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1524 #ifdef DRM
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1525 /* CRC check */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1526 if (hDecoder->object_type == DRM_ER_LC)
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1527 if ((result = (uint8_t)faad_check_CRC(ld, (uint16_t)faad_get_processed_bits(ld) - 8)) > 0)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1528 return result;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1529 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1530
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1531 if (hDecoder->aacSpectralDataResilienceFlag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1532 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1533 /* error resilient spectral data decoding */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1534 if ((result = reordered_spectral_data(hDecoder, ics, ld, spec_data)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1535 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1536 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1537 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1538 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1539 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1540 /* decode the spectral data */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1541 if ((result = spectral_data(hDecoder, ics, ld, spec_data)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1542 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1543 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1544 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1545 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1546 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1547 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1548
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1549 /* pulse coding reconstruction */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1550 if (ics->pulse_data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1551 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1552 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1553 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1554 if ((result = pulse_decode(ics, spec_data, hDecoder->frameLength)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1555 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1556 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1557 return 2; /* pulse coding not allowed for short blocks */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1558 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1559 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1560
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1561 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1562 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1563
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1564 /* Table 4.4.25 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1565 static uint8_t section_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1566 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1567 uint8_t g;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1568 uint8_t sect_esc_val, sect_bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1569
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1570 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1571 sect_bits = 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1572 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1573 sect_bits = 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1574 sect_esc_val = (1<<sect_bits) - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1575
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1576 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1577 printf("\ntotal sfb %d\n", ics->max_sfb);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1578 printf(" sect top cb\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1579 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1580
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1581 for (g = 0; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1582 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1583 uint8_t k = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1584 uint8_t i = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1585
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1586 while (k < ics->max_sfb)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1587 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1588 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1589 uint8_t vcb11 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1590 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1591 uint8_t sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1592 uint8_t sect_len_incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1593 uint16_t sect_len = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1594 uint8_t sect_cb_bits = 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1595
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1596 /* if "faad_getbits" detects error and returns "0", "k" is never
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1597 incremented and we cannot leave the while loop */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1598 if ((ld->error != 0) || (ld->no_more_reading))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1599 return 14;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1600
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1601 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1602 if (hDecoder->aacSectionDataResilienceFlag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1603 sect_cb_bits = 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1604 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1605
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1606 ics->sect_cb[g][i] = (uint8_t)faad_getbits(ld, sect_cb_bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1607 DEBUGVAR(1,71,"section_data(): sect_cb"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1608
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1609 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1610 printf("%d\n", ics->sect_cb[g][i]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1611 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1612
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1613 if (ics->sect_cb[g][i] == NOISE_HCB)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1614 ics->noise_used = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1615
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1616 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1617 if (hDecoder->aacSectionDataResilienceFlag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1618 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1619 if ((ics->sect_cb[g][i] == 11) ||
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1620 ((ics->sect_cb[g][i] >= 16) && (ics->sect_cb[g][i] <= 32)))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1621 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1622 vcb11 = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1623 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1624 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1625 if (vcb11)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1626 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1627 sect_len_incr = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1628 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1629 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1630 sect_len_incr = (uint8_t)faad_getbits(ld, sect_bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1631 DEBUGVAR(1,72,"section_data(): sect_len_incr"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1632 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1633 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1634 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1635 while ((sect_len_incr == sect_esc_val) /* &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1636 (k+sect_len < ics->max_sfb)*/)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1637 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1638 sect_len += sect_len_incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1639 sect_len_incr = (uint8_t)faad_getbits(ld, sect_bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1640 DEBUGVAR(1,72,"section_data(): sect_len_incr"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1641 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1642
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1643 sect_len += sect_len_incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1644
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1645 ics->sect_start[g][i] = k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1646 ics->sect_end[g][i] = k + sect_len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1647
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1648 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1649 printf("%d\n", ics->sect_start[g][i]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1650 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1651 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1652 printf("%d\n", ics->sect_end[g][i]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1653 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1654
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1655 if (k + sect_len >= 8*15)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1656 return 15;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1657 if (i >= 8*15)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1658 return 15;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1659
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1660 for (sfb = k; sfb < k + sect_len; sfb++)
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1661 {
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1662 ics->sfb_cb[g][sfb] = ics->sect_cb[g][i];
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1663 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1664 printf("%d\n", ics->sfb_cb[g][sfb]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1665 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1666 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1667
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1668 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1669 printf(" %6d %6d %6d\n",
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1670 i,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1671 ics->sect_end[g][i],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1672 ics->sect_cb[g][i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1673 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1674
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1675 k += sect_len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1676 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1677 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1678 ics->num_sec[g] = i;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1679 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1680 printf("%d\n", ics->num_sec[g]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1681 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1682 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1683
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1684 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1685 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1686 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1687
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1688 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1689 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1690
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1691 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1692 * decode_scale_factors()
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1693 * decodes the scalefactors from the bitstream
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1694 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1695 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1696 * All scalefactors (and also the stereo positions and pns energies) are
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1697 * transmitted using Huffman coded DPCM relative to the previous active
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1698 * scalefactor (respectively previous stereo position or previous pns energy,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1699 * see subclause 4.6.2 and 4.6.3). The first active scalefactor is
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1700 * differentially coded relative to the global gain.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1701 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1702 static uint8_t decode_scale_factors(ic_stream *ics, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1703 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1704 uint8_t g, sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1705 int16_t t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1706 int8_t noise_pcm_flag = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1707
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1708 int16_t scale_factor = ics->global_gain;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1709 int16_t is_position = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1710 int16_t noise_energy = ics->global_gain - 90;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1711
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1712 for (g = 0; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1713 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1714 for (sfb = 0; sfb < ics->max_sfb; sfb++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1715 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1716 switch (ics->sfb_cb[g][sfb])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1717 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1718 case ZERO_HCB: /* zero book */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1719 ics->scale_factors[g][sfb] = 0;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1720 //#define SF_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1721 #ifdef SF_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1722 printf("%d\n", ics->scale_factors[g][sfb]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1723 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1724 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1725 case INTENSITY_HCB: /* intensity books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1726 case INTENSITY_HCB2:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1727
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1728 /* decode intensity position */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1729 t = huffman_scale_factor(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1730 is_position += (t - 60);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1731 ics->scale_factors[g][sfb] = is_position;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1732 #ifdef SF_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1733 printf("%d\n", ics->scale_factors[g][sfb]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1734 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1735
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1736 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1737 case NOISE_HCB: /* noise books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1738
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1739 /* decode noise energy */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1740 if (noise_pcm_flag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1741 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1742 noise_pcm_flag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1743 t = (int16_t)faad_getbits(ld, 9
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1744 DEBUGVAR(1,73,"scale_factor_data(): first noise")) - 256;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1745 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1746 t = huffman_scale_factor(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1747 t -= 60;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1748 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1749 noise_energy += t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1750 ics->scale_factors[g][sfb] = noise_energy;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1751 #ifdef SF_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1752 printf("%d\n", ics->scale_factors[g][sfb]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1753 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1754
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1755 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1756 default: /* spectral books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1757
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1758 /* ics->scale_factors[g][sfb] must be between 0 and 255 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1759
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1760 ics->scale_factors[g][sfb] = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1761
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1762 /* decode scale factor */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1763 t = huffman_scale_factor(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1764 scale_factor += (t - 60);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1765 if (scale_factor < 0 || scale_factor > 255)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1766 return 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1767 ics->scale_factors[g][sfb] = scale_factor;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1768 #ifdef SF_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1769 printf("%d\n", ics->scale_factors[g][sfb]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1770 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1771
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1772 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1773 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1774 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1775 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1776
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1777 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1778 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1779
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1780 /* Table 4.4.26 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1781 static uint8_t scale_factor_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1782 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1783 uint8_t ret = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1784 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1785 int64_t count = faad_get_ts();
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1786 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1787
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1788 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1789 if (!hDecoder->aacScalefactorDataResilienceFlag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1790 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1791 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1792 ret = decode_scale_factors(ics, ld);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1793 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1794 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1795 /* In ER AAC the parameters for RVLC are seperated from the actual
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1796 data that holds the scale_factors.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1797 Strangely enough, 2 parameters for HCR are put inbetween them.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1798 */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1799 ret = rvlc_scale_factor_data(ics, ld);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1800 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1801 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1802
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1803 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1804 count = faad_get_ts() - count;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1805 hDecoder->scalefac_cycles += count;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1806 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1807
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1808 return ret;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1809 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1810
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1811 /* Table 4.4.27 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1812 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1813 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1814 uint8_t w, filt, i, start_coef_bits, coef_bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1815 uint8_t n_filt_bits = 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1816 uint8_t length_bits = 6;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1817 uint8_t order_bits = 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1818
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1819 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1820 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1821 n_filt_bits = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1822 length_bits = 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1823 order_bits = 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1824 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1825
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1826 for (w = 0; w < ics->num_windows; w++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1827 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1828 tns->n_filt[w] = (uint8_t)faad_getbits(ld, n_filt_bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1829 DEBUGVAR(1,74,"tns_data(): n_filt"));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1830 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1831 printf("%d\n", tns->n_filt[w]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1832 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1833
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1834 if (tns->n_filt[w])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1835 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1836 if ((tns->coef_res[w] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1837 DEBUGVAR(1,75,"tns_data(): coef_res"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1838 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1839 start_coef_bits = 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1840 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1841 start_coef_bits = 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1842 }
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1843 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1844 printf("%d\n", tns->coef_res[w]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1845 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1846 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1847
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1848 for (filt = 0; filt < tns->n_filt[w]; filt++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1849 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1850 tns->length[w][filt] = (uint8_t)faad_getbits(ld, length_bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1851 DEBUGVAR(1,76,"tns_data(): length"));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1852 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1853 printf("%d\n", tns->length[w][filt]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1854 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1855 tns->order[w][filt] = (uint8_t)faad_getbits(ld, order_bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1856 DEBUGVAR(1,77,"tns_data(): order"));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1857 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1858 printf("%d\n", tns->order[w][filt]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1859 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1860 if (tns->order[w][filt])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1861 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1862 tns->direction[w][filt] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1863 DEBUGVAR(1,78,"tns_data(): direction"));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1864 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1865 printf("%d\n", tns->direction[w][filt]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1866 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1867 tns->coef_compress[w][filt] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1868 DEBUGVAR(1,79,"tns_data(): coef_compress"));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1869 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1870 printf("%d\n", tns->coef_compress[w][filt]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1871 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1872
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1873 coef_bits = start_coef_bits - tns->coef_compress[w][filt];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1874 for (i = 0; i < tns->order[w][filt]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1875 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1876 tns->coef[w][filt][i] = (uint8_t)faad_getbits(ld, coef_bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1877 DEBUGVAR(1,80,"tns_data(): coef"));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1878 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1879 printf("%d\n", tns->coef[w][filt][i]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1880 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1881 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1882 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1883 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1884 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1885 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1886
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1887 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1888 /* Table 4.4.28 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1889 static uint8_t ltp_data(NeAACDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1890 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1891 uint8_t sfb, w;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1892
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1893 ltp->lag = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1894
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1895 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1896 if (hDecoder->object_type == LD)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1897 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1898 ltp->lag_update = (uint8_t)faad_getbits(ld, 1
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1899 DEBUGVAR(1,142,"ltp_data(): lag_update"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1900
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1901 if (ltp->lag_update)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1902 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1903 ltp->lag = (uint16_t)faad_getbits(ld, 10
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1904 DEBUGVAR(1,81,"ltp_data(): lag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1905 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1906 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1907 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1908 ltp->lag = (uint16_t)faad_getbits(ld, 11
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1909 DEBUGVAR(1,81,"ltp_data(): lag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1910 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1911 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1912 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1913
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1914 /* Check length of lag */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1915 if (ltp->lag > (hDecoder->frameLength << 1))
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1916 return 18;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1917
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1918 ltp->coef = (uint8_t)faad_getbits(ld, 3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1919 DEBUGVAR(1,82,"ltp_data(): coef"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1920
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1921 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1922 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1923 for (w = 0; w < ics->num_windows; w++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1924 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1925 if ((ltp->short_used[w] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1926 DEBUGVAR(1,83,"ltp_data(): short_used"))) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1927 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1928 ltp->short_lag_present[w] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1929 DEBUGVAR(1,84,"ltp_data(): short_lag_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1930 if (ltp->short_lag_present[w])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1931 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1932 ltp->short_lag[w] = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1933 DEBUGVAR(1,85,"ltp_data(): short_lag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1934 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1935 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1936 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1937 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1938 ltp->last_band = (ics->max_sfb < MAX_LTP_SFB ? ics->max_sfb : MAX_LTP_SFB);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1939
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1940 for (sfb = 0; sfb < ltp->last_band; sfb++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1941 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1942 ltp->long_used[sfb] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1943 DEBUGVAR(1,86,"ltp_data(): long_used"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1944 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1945 }
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1946
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1947 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1948 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1949 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1950
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1951 /* Table 4.4.29 */
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1952 static uint8_t spectral_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1953 int16_t *spectral_data)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1954 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1955 int8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1956 uint8_t g;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1957 uint16_t inc, k, p = 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1958 uint8_t groups = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1959 uint8_t sect_cb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1960 uint8_t result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1961 uint16_t nshort = hDecoder->frameLength/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1962
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1963 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1964 int64_t count = faad_get_ts();
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1965 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1966
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1967 for(g = 0; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1968 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1969 p = groups*nshort;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1970
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1971 for (i = 0; i < ics->num_sec[g]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1972 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1973 sect_cb = ics->sect_cb[g][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1974
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1975 inc = (sect_cb >= FIRST_PAIR_HCB) ? 2 : 4;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
1976
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1977 switch (sect_cb)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1978 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1979 case ZERO_HCB:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1980 case NOISE_HCB:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1981 case INTENSITY_HCB:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1982 case INTENSITY_HCB2:
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1983 //#define SD_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1984 #ifdef SD_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1985 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1986 int j;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1987 for (j = ics->sect_sfb_offset[g][ics->sect_start[g][i]]; j < ics->sect_sfb_offset[g][ics->sect_end[g][i]]; j++)
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1988 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1989 printf("%d\n", 0);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1990 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1991 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1992 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1993 //#define SFBO_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1994 #ifdef SFBO_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1995 printf("%d\n", ics->sect_sfb_offset[g][ics->sect_start[g][i]]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
1996 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1997 p += (ics->sect_sfb_offset[g][ics->sect_end[g][i]] -
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1998 ics->sect_sfb_offset[g][ics->sect_start[g][i]]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1999 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2000 default:
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2001 #ifdef SFBO_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2002 printf("%d\n", ics->sect_sfb_offset[g][ics->sect_start[g][i]]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2003 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2004 for (k = ics->sect_sfb_offset[g][ics->sect_start[g][i]];
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2005 k < ics->sect_sfb_offset[g][ics->sect_end[g][i]]; k += inc)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2006 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2007 if ((result = huffman_spectral_data(sect_cb, ld, &spectral_data[p])) > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2008 return result;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2009 #ifdef SD_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2010 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2011 int j;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2012 for (j = p; j < p+inc; j++)
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2013 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2014 printf("%d\n", spectral_data[j]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2015 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2016 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
2017 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2018 p += inc;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2019 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2020 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2021 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2022 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2023 groups += ics->window_group_length[g];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2024 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2025
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2026 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2027 count = faad_get_ts() - count;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2028 hDecoder->spectral_cycles += count;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2029 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2030
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2031 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2032 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2033
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2034 /* Table 4.4.30 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2035 static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2036 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2037 uint16_t i, n, dataElementLength;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2038 uint8_t dataElementLengthPart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2039 uint8_t align = 4, data_element_version, loopCounter;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2040
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2041 uint8_t extension_type = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2042 DEBUGVAR(1,87,"extension_payload(): extension_type"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2043
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2044 switch (extension_type)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2045 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2046 case EXT_DYNAMIC_RANGE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2047 drc->present = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2048 n = dynamic_range_info(ld, drc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2049 return n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2050 case EXT_FILL_DATA:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2051 /* fill_nibble = */ faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2052 DEBUGVAR(1,136,"extension_payload(): fill_nibble")); /* must be ‘0000’ */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2053 for (i = 0; i < count-1; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2054 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2055 /* fill_byte[i] = */ faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2056 DEBUGVAR(1,88,"extension_payload(): fill_byte")); /* must be ‘10100101’ */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2057 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2058 return count;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2059 case EXT_DATA_ELEMENT:
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2060 data_element_version = (uint8_t)faad_getbits(ld, 4
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2061 DEBUGVAR(1,400,"extension_payload(): data_element_version"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2062 switch (data_element_version)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2063 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2064 case ANC_DATA:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2065 loopCounter = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2066 dataElementLength = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2067 do {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2068 dataElementLengthPart = (uint8_t)faad_getbits(ld, 8
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2069 DEBUGVAR(1,401,"extension_payload(): dataElementLengthPart"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2070 dataElementLength += dataElementLengthPart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2071 loopCounter++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2072 } while (dataElementLengthPart == 255);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2073
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2074 for (i = 0; i < dataElementLength; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2075 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2076 /* data_element_byte[i] = */ faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2077 DEBUGVAR(1,402,"extension_payload(): data_element_byte"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2078 return (dataElementLength+loopCounter+1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2079 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2080 default:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2081 align = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2082 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2083 case EXT_FIL:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2084 default:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2085 faad_getbits(ld, align
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2086 DEBUGVAR(1,88,"extension_payload(): fill_nibble"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2087 for (i = 0; i < count-1; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2088 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2089 /* other_bits[i] = */ faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2090 DEBUGVAR(1,89,"extension_payload(): fill_bit"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2091 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2092 return count;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2093 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2094 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2095
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2096 /* Table 4.4.31 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2097 static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2098 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2099 uint8_t i, n = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2100 uint8_t band_incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2101
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2102 drc->num_bands = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2103
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2104 if (faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2105 DEBUGVAR(1,90,"dynamic_range_info(): has instance_tag")) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2106 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2107 drc->pce_instance_tag = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2108 DEBUGVAR(1,91,"dynamic_range_info(): pce_instance_tag"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2109 /* drc->drc_tag_reserved_bits = */ faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2110 DEBUGVAR(1,92,"dynamic_range_info(): drc_tag_reserved_bits"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2111 n++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2112 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2113
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2114 drc->excluded_chns_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2115 DEBUGVAR(1,93,"dynamic_range_info(): excluded_chns_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2116 if (drc->excluded_chns_present == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2117 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2118 n += excluded_channels(ld, drc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2119 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2120
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2121 if (faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2122 DEBUGVAR(1,94,"dynamic_range_info(): has bands data")) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2123 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2124 band_incr = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2125 DEBUGVAR(1,95,"dynamic_range_info(): band_incr"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2126 /* drc->drc_bands_reserved_bits = */ faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2127 DEBUGVAR(1,96,"dynamic_range_info(): drc_bands_reserved_bits"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2128 n++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2129 drc->num_bands += band_incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2130
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2131 for (i = 0; i < drc->num_bands; i++);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2132 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2133 drc->band_top[i] = (uint8_t)faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2134 DEBUGVAR(1,97,"dynamic_range_info(): band_top"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2135 n++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2136 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2137 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2138
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2139 if (faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2140 DEBUGVAR(1,98,"dynamic_range_info(): has prog_ref_level")) & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2141 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2142 drc->prog_ref_level = (uint8_t)faad_getbits(ld, 7
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2143 DEBUGVAR(1,99,"dynamic_range_info(): prog_ref_level"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2144 /* drc->prog_ref_level_reserved_bits = */ faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2145 DEBUGVAR(1,100,"dynamic_range_info(): prog_ref_level_reserved_bits"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2146 n++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2147 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2148
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2149 for (i = 0; i < drc->num_bands; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2150 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2151 drc->dyn_rng_sgn[i] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2152 DEBUGVAR(1,101,"dynamic_range_info(): dyn_rng_sgn"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2153 drc->dyn_rng_ctl[i] = (uint8_t)faad_getbits(ld, 7
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2154 DEBUGVAR(1,102,"dynamic_range_info(): dyn_rng_ctl"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2155 n++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2156 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2157
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2158 return n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2159 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2160
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2161 /* Table 4.4.32 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2162 static uint8_t excluded_channels(bitfile *ld, drc_info *drc)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2163 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2164 uint8_t i, n = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2165 uint8_t num_excl_chan = 7;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2166
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2167 for (i = 0; i < 7; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2168 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2169 drc->exclude_mask[i] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2170 DEBUGVAR(1,103,"excluded_channels(): exclude_mask"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2171 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2172 n++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2173
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2174 while ((drc->additional_excluded_chns[n-1] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2175 DEBUGVAR(1,104,"excluded_channels(): additional_excluded_chns"))) == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2176 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2177 for (i = num_excl_chan; i < num_excl_chan+7; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2178 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2179 drc->exclude_mask[i] = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2180 DEBUGVAR(1,105,"excluded_channels(): exclude_mask"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2181 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2182 n++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2183 num_excl_chan += 7;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2184 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2185
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2186 return n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2187 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2188
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2189 /* Annex A: Audio Interchange Formats */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2190
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2191 /* Table 1.A.2 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2192 void get_adif_header(adif_header *adif, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2193 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2194 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2195
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2196 /* adif_id[0] = */ faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2197 DEBUGVAR(1,106,"get_adif_header(): adif_id[0]"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2198 /* adif_id[1] = */ faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2199 DEBUGVAR(1,107,"get_adif_header(): adif_id[1]"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2200 /* adif_id[2] = */ faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2201 DEBUGVAR(1,108,"get_adif_header(): adif_id[2]"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2202 /* adif_id[3] = */ faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2203 DEBUGVAR(1,109,"get_adif_header(): adif_id[3]"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2204 adif->copyright_id_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2205 DEBUGVAR(1,110,"get_adif_header(): copyright_id_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2206 if(adif->copyright_id_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2207 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2208 for (i = 0; i < 72/8; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2209 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2210 adif->copyright_id[i] = (int8_t)faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2211 DEBUGVAR(1,111,"get_adif_header(): copyright_id"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2212 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2213 adif->copyright_id[i] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2214 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2215 adif->original_copy = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2216 DEBUGVAR(1,112,"get_adif_header(): original_copy"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2217 adif->home = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2218 DEBUGVAR(1,113,"get_adif_header(): home"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2219 adif->bitstream_type = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2220 DEBUGVAR(1,114,"get_adif_header(): bitstream_type"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2221 adif->bitrate = faad_getbits(ld, 23
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2222 DEBUGVAR(1,115,"get_adif_header(): bitrate"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2223 adif->num_program_config_elements = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2224 DEBUGVAR(1,116,"get_adif_header(): num_program_config_elements"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2225
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2226 for (i = 0; i < adif->num_program_config_elements + 1; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2227 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2228 if(adif->bitstream_type == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2229 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2230 adif->adif_buffer_fullness = faad_getbits(ld, 20
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2231 DEBUGVAR(1,117,"get_adif_header(): adif_buffer_fullness"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2232 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2233 adif->adif_buffer_fullness = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2234 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2235
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2236 program_config_element(&adif->pce[i], ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2237 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2238 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2239
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2240 /* Table 1.A.5 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2241 uint8_t adts_frame(adts_header *adts, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2242 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2243 /* faad_byte_align(ld); */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2244 if (adts_fixed_header(adts, ld))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2245 return 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2246 adts_variable_header(adts, ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2247 adts_error_check(adts, ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2248
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2249 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2250 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2251
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2252 /* Table 1.A.6 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2253 static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2254 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2255 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2256 uint8_t sync_err = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2257
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2258 /* try to recover from sync errors */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2259 for (i = 0; i < 768; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2260 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2261 adts->syncword = (uint16_t)faad_showbits(ld, 12);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2262 if (adts->syncword != 0xFFF)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2263 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2264 faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2265 DEBUGVAR(0,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2266 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2267 sync_err = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2268 faad_getbits(ld, 12
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2269 DEBUGVAR(1,118,"adts_fixed_header(): syncword"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2270 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2271 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2272 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2273 if (sync_err)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2274 return 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2275
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2276 adts->id = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2277 DEBUGVAR(1,119,"adts_fixed_header(): id"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2278 adts->layer = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2279 DEBUGVAR(1,120,"adts_fixed_header(): layer"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2280 adts->protection_absent = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2281 DEBUGVAR(1,121,"adts_fixed_header(): protection_absent"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2282 adts->profile = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2283 DEBUGVAR(1,122,"adts_fixed_header(): profile"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2284 adts->sf_index = (uint8_t)faad_getbits(ld, 4
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2285 DEBUGVAR(1,123,"adts_fixed_header(): sf_index"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2286 adts->private_bit = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2287 DEBUGVAR(1,124,"adts_fixed_header(): private_bit"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2288 adts->channel_configuration = (uint8_t)faad_getbits(ld, 3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2289 DEBUGVAR(1,125,"adts_fixed_header(): channel_configuration"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2290 adts->original = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2291 DEBUGVAR(1,126,"adts_fixed_header(): original"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2292 adts->home = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2293 DEBUGVAR(1,127,"adts_fixed_header(): home"));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
2294
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
2295 if (adts->old_format == 1)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
2296 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
2297 /* Removed in corrigendum 14496-3:2002 */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2298 if (adts->id == 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2299 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2300 adts->emphasis = (uint8_t)faad_getbits(ld, 2
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2301 DEBUGVAR(1,128,"adts_fixed_header(): emphasis"));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
2302 }
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
2303 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2304
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2305 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2306 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2307
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2308 /* Table 1.A.7 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2309 static void adts_variable_header(adts_header *adts, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2310 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2311 adts->copyright_identification_bit = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2312 DEBUGVAR(1,129,"adts_variable_header(): copyright_identification_bit"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2313 adts->copyright_identification_start = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2314 DEBUGVAR(1,130,"adts_variable_header(): copyright_identification_start"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2315 adts->aac_frame_length = (uint16_t)faad_getbits(ld, 13
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2316 DEBUGVAR(1,131,"adts_variable_header(): aac_frame_length"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2317 adts->adts_buffer_fullness = (uint16_t)faad_getbits(ld, 11
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2318 DEBUGVAR(1,132,"adts_variable_header(): adts_buffer_fullness"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2319 adts->no_raw_data_blocks_in_frame = (uint8_t)faad_getbits(ld, 2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2320 DEBUGVAR(1,133,"adts_variable_header(): no_raw_data_blocks_in_frame"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2321 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2322
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2323 /* Table 1.A.8 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2324 static void adts_error_check(adts_header *adts, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2325 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2326 if (adts->protection_absent == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2327 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2328 adts->crc_check = (uint16_t)faad_getbits(ld, 16
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2329 DEBUGVAR(1,134,"adts_error_check(): crc_check"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2330 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2331 }
25834
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2332
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2333 /* LATM parsing functions */
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2334
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2335 static uint32_t latm_get_value(bitfile *ld)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2336 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2337 uint32_t l, value;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2338 uint8_t bytesForValue;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2339
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2340 bytesForValue = (uint8_t)faad_getbits(ld, 2);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2341 value = 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2342 for(l=0; l<bytesForValue; l++)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2343 value = (value << 8) | (uint8_t)faad_getbits(ld, 8);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2344
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2345 return value;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2346 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2347
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2348
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2349 static uint32_t latmParsePayload(latm_header *latm, bitfile *ld)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2350 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2351 //assuming there's only one program with a single layer and 1 subFrame,
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2352 //allStreamsSametimeframing is set,
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2353 uint32_t framelen;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2354 uint8_t tmp;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2355
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2356 //this should be the payload length field for the current configuration
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2357 framelen = 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2358 if(latm->framelen_type==0)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2359 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2360 do
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2361 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2362 tmp = (uint8_t)faad_getbits(ld, 8);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2363 framelen += tmp;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2364 } while(tmp==0xff);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2365 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2366 else if(latm->framelen_type==1)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2367 framelen=latm->frameLength;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2368
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2369 return framelen;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2370 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2371
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2372
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2373 static uint32_t latmAudioMuxElement(latm_header *latm, bitfile *ld)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2374 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2375 uint32_t ascLen, asc_bits=0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2376 uint32_t x1, y1, m, n, i;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2377 program_config pce;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2378 mp4AudioSpecificConfig mp4ASC;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2379
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2380 latm->useSameStreamMux = (uint8_t)faad_getbits(ld, 1);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2381 if(!latm->useSameStreamMux)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2382 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2383 //parseSameStreamMuxConfig
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2384 latm->version = (uint8_t) faad_getbits(ld, 1);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2385 if(latm->version)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2386 latm->versionA = (uint8_t) faad_getbits(ld, 1);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2387 if(latm->versionA)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2388 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2389 //dunno the payload format for versionA
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2390 fprintf(stderr, "versionA not supported\n");
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2391 return 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2392 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2393 if(latm->version) //read taraBufferFullness
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2394 latm_get_value(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2395 latm->allStreamsSameTimeFraming = (uint8_t)faad_getbits(ld, 1);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2396 latm->numSubFrames = (uint8_t)faad_getbits(ld, 6) + 1;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2397 latm->numPrograms = (uint8_t)faad_getbits(ld, 4) + 1;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2398 latm->numLayers = faad_getbits(ld, 3) + 1;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2399 if(latm->numPrograms>1 || !latm->allStreamsSameTimeFraming || latm->numSubFrames>1 || latm->numLayers>1)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2400 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2401 fprintf(stderr, "\r\nUnsupported LATM configuration: %d programs/ %d subframes, %d layers, allstreams: %d\n",
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2402 latm->numPrograms, latm->numSubFrames, latm->numLayers, latm->allStreamsSameTimeFraming);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2403 return 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2404 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2405 ascLen = 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2406 if(latm->version)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2407 ascLen = latm_get_value(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2408
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2409 x1 = faad_get_processed_bits(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2410 if(AudioSpecificConfigFromBitfile(ld, &mp4ASC, &pce, 0, 1) < 0)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2411 return 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2412
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2413 //horrid hack to unread the ASC bits and store them in latm->ASC
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2414 //the correct code would rely on an ideal faad_ungetbits()
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2415 y1 = faad_get_processed_bits(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2416 if((y1-x1) <= MAX_ASC_BYTES*8)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2417 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2418 faad_rewindbits(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2419 m = x1;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2420 while(m>0)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2421 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2422 n = min(m, 32);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2423 faad_getbits(ld, n);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2424 m -= n;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2425 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2426
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2427 i = 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2428 m = latm->ASCbits = y1 - x1;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2429 while(m > 0)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2430 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2431 n = min(m, 8);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2432 latm->ASC[i++] = (uint8_t) faad_getbits(ld, n);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2433 m -= n;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2434 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2435 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2436
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2437 asc_bits = y1-x1;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2438
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2439 if(ascLen>asc_bits)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2440 faad_getbits(ld, ascLen-asc_bits);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2441
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2442 latm->framelen_type = (uint8_t) faad_getbits(ld, 3);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2443 if(latm->framelen_type == 0)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2444 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2445 latm->frameLength = 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2446 faad_getbits(ld, 8); //buffer fullness for frame_len_type==0, useless
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2447 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2448 else if(latm->framelen_type == 1)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2449 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2450 latm->frameLength = faad_getbits(ld, 9);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2451 if(latm->frameLength==0)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2452 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2453 fprintf(stderr, "Invalid frameLength: 0\r\n");
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2454 return 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2455 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2456 latm->frameLength = (latm->frameLength+20)*8;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2457 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2458 else
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2459 { //hellish CELP or HCVX stuff, discard
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2460 fprintf(stderr, "Unsupported CELP/HCVX framelentype: %d\n", latm->framelen_type);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2461 return 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2462 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2463
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2464 latm->otherDataLenBits = 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2465 if(faad_getbits(ld, 1))
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2466 { //other data present
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2467 int esc, tmp;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2468 if(latm->version)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2469 latm->otherDataLenBits = latm_get_value(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2470 else do
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2471 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2472 esc = faad_getbits(ld, 1);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2473 tmp = faad_getbits(ld, 8);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2474 latm->otherDataLenBits = (latm->otherDataLenBits << 8) + tmp;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2475 } while(esc);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2476 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2477 if(faad_getbits(ld, 1)) //crc
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2478 faad_getbits(ld, 8);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2479 latm->inited = 1;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2480 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2481
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2482 //read payload
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2483 if(latm->inited)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2484 return latmParsePayload(latm, ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2485 else
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2486 return 0;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2487 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2488
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2489
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2490 uint32_t faad_latm_frame(latm_header *latm, bitfile *ld)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2491 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2492 uint16_t len;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2493 uint32_t initpos, endpos, firstpos, ret;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2494
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2495 firstpos = faad_get_processed_bits(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2496 while(!ld->error && !ld->no_more_reading)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2497 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2498 faad_byte_align(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2499 if(faad_showbits(ld, 11) != 0x2B7)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2500 {
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2501 faad_getbits(ld, 8);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2502 continue;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2503 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2504 faad_getbits(ld, 11);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2505 len = faad_getbits(ld, 13);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2506 if(!len)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2507 continue;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2508 initpos = faad_get_processed_bits(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2509 ret = latmAudioMuxElement(latm, ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2510 endpos = faad_get_processed_bits(ld);
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2511 if(ret>0)
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2512 return (len*8)-(endpos-initpos);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 25836
diff changeset
2513 //faad_getbits(ld, initpos-endpos); //go back to initpos, but is valid a getbits(-N) ?
25834
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2514 }
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2515 return -1U;
69a4d646e55d generic functions and structures to parse and statekeep LATM streams
nicodvb
parents: 25833
diff changeset
2516 }