annotate libfaad2/bits.c @ 12631:6cbccc0c7d7b

Fix memory corruption, noticable at reallocate image
author iive
date Thu, 24 Jun 2004 12:01:53 +0000
parents d81145997036
children 2ae5ab4331ca
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
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
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.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
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.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
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 **
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
26 ** $Id: bits.c,v 1.3 2004/06/02 22:59:02 diego Exp $
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 #include <string.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "bits.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 /* initialize buffer, call once before first getbits or showbits */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
38 void faad_initbits(bitfile *ld, const void *_buffer, const uint32_t buffer_size)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 uint32_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
42 if (ld == NULL)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
43 return;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
44
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
45 memset(ld, 0, sizeof(bitfile));
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
46
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
47 if (buffer_size == 0 || _buffer == NULL)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
48 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
49 ld->error = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
50 ld->no_more_reading = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
51 return;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
52 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
53
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
54 ld->buffer = faad_malloc((buffer_size+12)*sizeof(uint8_t));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 memset(ld->buffer, 0, (buffer_size+12)*sizeof(uint8_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 memcpy(ld->buffer, _buffer, buffer_size*sizeof(uint8_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 ld->buffer_size = buffer_size;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 tmp = getdword((uint32_t*)ld->buffer);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 ld->bufa = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 tmp = getdword((uint32_t*)ld->buffer + 1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 ld->bufb = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 ld->start = (uint32_t*)ld->buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 ld->tail = ((uint32_t*)ld->buffer + 2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 ld->bits_left = 32;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 ld->bytes_used = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 ld->no_more_reading = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 ld->error = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 void faad_endbits(bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 if (ld)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
79 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
80 if (ld->buffer)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
81 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
82 faad_free(ld->buffer);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
83 ld->buffer = NULL;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
84 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
85 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 uint32_t faad_get_processed_bits(bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
90 return (uint32_t)(8 * (4*(ld->tail - ld->start) - 4) - (ld->bits_left));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 uint8_t faad_byte_align(bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 uint8_t remainder = (uint8_t)((32 - ld->bits_left) % 8);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 if (remainder)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 faad_flushbits(ld, 8 - remainder);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 return (8 - remainder);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
105 void faad_flushbits_ex(bitfile *ld, uint32_t bits)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
106 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
107 uint32_t tmp;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
108
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
109 ld->bufa = ld->bufb;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
110 if (ld->no_more_reading == 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
111 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
112 tmp = getdword(ld->tail);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
113 ld->tail++;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
114 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
115 tmp = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
116 }
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
117 ld->bufb = tmp;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
118 ld->bits_left += (32 - bits);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
119 ld->bytes_used += 4;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
120 if (ld->bytes_used == ld->buffer_size)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
121 ld->no_more_reading = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
122 if (ld->bytes_used > ld->buffer_size)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
123 ld->error = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
124 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
125
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 /* rewind to beginning */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 void faad_rewindbits(bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 uint32_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 tmp = ld->start[0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 #ifndef ARCH_IS_BIG_ENDIAN
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 BSWAP(tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 ld->bufa = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 tmp = ld->start[1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 #ifndef ARCH_IS_BIG_ENDIAN
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 BSWAP(tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 ld->bufb = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 ld->bits_left = 32;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 ld->tail = &ld->start[2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 ld->bytes_used = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 ld->no_more_reading = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 DEBUGDEC)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 uint8_t temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 uint16_t bytes = (uint16_t)bits / 8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 uint8_t remainder = (uint8_t)bits % 8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
156 uint8_t *buffer = (uint8_t*)faad_malloc((bytes+1)*sizeof(uint8_t));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 for (i = 0; i < bytes; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 buffer[i] = (uint8_t)faad_getbits(ld, 8 DEBUGVAR(print,var,dbg));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 if (remainder)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 temp = (uint8_t)faad_getbits(ld, remainder DEBUGVAR(print,var,dbg)) << (8-remainder);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 buffer[bytes] = temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 return buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
173 #ifdef DRM
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
174 /* return the original data buffer */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
175 void *faad_origbitbuffer(bitfile *ld)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
176 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
177 return (void*)ld->start;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
178 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
179
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
180 /* return the original data buffer size */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
181 uint32_t faad_origbitbuffer_size(bitfile *ld)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
182 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
183 return ld->buffer_size;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
184 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
185 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
186
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 /* reversed bit reading routines, used for RVLC and HCR */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 void faad_initbits_rev(bitfile *ld, void *buffer,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 uint32_t bits_in_buffer)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 uint32_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 int32_t index;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 ld->buffer_size = bit2byte(bits_in_buffer);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 index = (bits_in_buffer+31)/32 - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 ld->start = (uint32_t*)buffer + index - 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 tmp = getdword((uint32_t*)buffer + index);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 ld->bufa = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 tmp = getdword((uint32_t*)buffer + index - 1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 ld->bufb = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 ld->tail = (uint32_t*)buffer + index;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 ld->bits_left = bits_in_buffer % 32;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 if (ld->bits_left == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 ld->bits_left = 32;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 ld->bytes_used = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 ld->no_more_reading = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 ld->error = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 }