summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libfaad/bits.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libfaad/bits.c')
-rw-r--r--lib/rbcodec/codecs/libfaad/bits.c208
1 files changed, 208 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libfaad/bits.c b/lib/rbcodec/codecs/libfaad/bits.c
new file mode 100644
index 0000000000..a3640077d8
--- /dev/null
+++ b/lib/rbcodec/codecs/libfaad/bits.c
@@ -0,0 +1,208 @@
1/*
2** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18**
19** Any non-GPL usage of this software or parts of this software is strictly
20** forbidden.
21**
22** Commercial non-GPL licensing of this software is possible.
23** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
24**
25** $Id$
26**/
27
28#include "common.h"
29#include "structs.h"
30
31#include <stdlib.h>
32#include <string.h>
33#include "bits.h"
34
35/* Need to be large enough to fit the largest compressed sample in a file.
36 * Samples were observed to need up to 1500 bytes (400 kbps nero aac).
37 */
38#define BUFFER_SIZE 2048
39static uint8_t static_buffer[BUFFER_SIZE] IBSS_ATTR;
40
41/* initialize buffer, call once before first getbits or showbits */
42void faad_initbits(bitfile *ld, const void *_buffer, const uint32_t buffer_size)
43{
44 uint32_t tmp;
45
46 if (ld == NULL)
47 return;
48
49 memset(ld, 0, sizeof(bitfile));
50
51 if (buffer_size == 0 || _buffer == NULL || (buffer_size+12)>BUFFER_SIZE)
52 {
53 ld->error = 1;
54 ld->no_more_reading = 1;
55 return;
56 }
57
58 ld->buffer = &static_buffer;
59 memset(ld->buffer, 0, (buffer_size+12)*sizeof(uint8_t));
60 memcpy(ld->buffer, _buffer, buffer_size*sizeof(uint8_t));
61
62 ld->buffer_size = buffer_size;
63
64 tmp = getdword((uint32_t*)ld->buffer);
65 ld->bufa = tmp;
66
67 tmp = getdword((uint32_t*)ld->buffer + 1);
68 ld->bufb = tmp;
69
70 ld->start = (uint32_t*)ld->buffer;
71 ld->tail = ((uint32_t*)ld->buffer + 2);
72
73 ld->bits_left = 32;
74
75 ld->bytes_used = 0;
76 ld->no_more_reading = 0;
77 ld->error = 0;
78}
79
80void faad_endbits(bitfile *ld)
81{
82#if 0
83 if (ld)
84 {
85 if (ld->buffer)
86 {
87 faad_free(ld->buffer);
88 ld->buffer = NULL;
89 }
90 }
91#else
92 (void) ld;
93#endif
94}
95
96uint32_t faad_get_processed_bits(bitfile *ld)
97{
98 return (uint32_t)(8 * (4*(ld->tail - ld->start) - 4) - (ld->bits_left));
99}
100
101uint8_t faad_byte_align(bitfile *ld)
102{
103 uint8_t remainder = (uint8_t)((32 - ld->bits_left) % 8);
104
105 if (remainder)
106 {
107 faad_flushbits(ld, 8 - remainder);
108 return (8 - remainder);
109 }
110 return 0;
111}
112
113/* rewind to beginning */
114/* not used
115void faad_rewindbits(bitfile *ld)
116{
117 uint32_t tmp;
118
119 tmp = ld->start[0];
120#ifndef ARCH_IS_BIG_ENDIAN
121 tmp = BSWAP(tmp);
122#endif
123 ld->bufa = tmp;
124
125 tmp = ld->start[1];
126#ifndef ARCH_IS_BIG_ENDIAN
127 tmp = BSWAP(tmp);
128#endif
129 ld->bufb = tmp;
130 ld->bits_left = 32;
131 ld->tail = &ld->start[2];
132 ld->bytes_used = 0;
133 ld->no_more_reading = 0;
134}
135*/
136
137#ifdef ERROR_RESILIENCE
138uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
139 DEBUGDEC)
140{
141 uint16_t i;
142 uint8_t temp;
143 uint16_t bytes = (uint16_t)bits / 8;
144 uint8_t remainder = (uint8_t)bits % 8;
145
146 uint8_t *buffer = (uint8_t*)faad_malloc((bytes+1)*sizeof(uint8_t));
147
148 for (i = 0; i < bytes; i++)
149 {
150 buffer[i] = (uint8_t)faad_getbits(ld, 8 DEBUGVAR(print,var,dbg));
151 }
152
153 if (remainder)
154 {
155 temp = (uint8_t)faad_getbits(ld, remainder DEBUGVAR(print,var,dbg)) << (8-remainder);
156
157 buffer[bytes] = temp;
158 }
159
160 return buffer;
161}
162#endif
163
164#ifdef DRM
165/* return the original data buffer */
166void *faad_origbitbuffer(bitfile *ld)
167{
168 return (void*)ld->start;
169}
170
171/* return the original data buffer size */
172uint32_t faad_origbitbuffer_size(bitfile *ld)
173{
174 return ld->buffer_size;
175}
176#endif
177
178/* reversed bit reading routines, used for RVLC and HCR */
179/* not used
180void faad_initbits_rev(bitfile *ld, void *buffer,
181 uint32_t bits_in_buffer)
182{
183 uint32_t tmp;
184 int32_t index;
185
186 ld->buffer_size = bit2byte(bits_in_buffer);
187
188 index = (bits_in_buffer+31)/32 - 1;
189
190 ld->start = (uint32_t*)buffer + index - 2;
191
192 tmp = getdword((uint32_t*)buffer + index);
193 ld->bufa = tmp;
194
195 tmp = getdword((uint32_t*)buffer + index - 1);
196 ld->bufb = tmp;
197
198 ld->tail = (uint32_t*)buffer + index;
199
200 ld->bits_left = bits_in_buffer % 32;
201 if (ld->bits_left == 0)
202 ld->bits_left = 32;
203
204 ld->bytes_used = 0;
205 ld->no_more_reading = 0;
206 ld->error = 0;
207}
208*/