summaryrefslogtreecommitdiff
path: root/apps/codecs/libwma/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libwma/common.c')
-rw-r--r--apps/codecs/libwma/common.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/apps/codecs/libwma/common.c b/apps/codecs/libwma/common.c
new file mode 100644
index 0000000000..4d165ed0a8
--- /dev/null
+++ b/apps/codecs/libwma/common.c
@@ -0,0 +1,107 @@
1/*
2 * Common bit i/o utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
21 */
22
23/**
24 * @file common.c
25 * common internal api.
26 */
27
28#include "avcodec.h"
29
30const uint8_t ff_sqrt_tab[128]={
31 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5,
32 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
33 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
34 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11
35};
36
37const uint8_t ff_log2_tab[256]={
38 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
39 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
40 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
41 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
42 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
43 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
44 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
45 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
46};
47
48/**
49 * init GetBitContext.
50 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
51 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
52 * @param bit_size the size of the buffer in bits
53 */
54void init_get_bits(GetBitContext *s,
55 const uint8_t *buffer, int bit_size)
56{
57 const int buffer_size= (bit_size+7)>>3;
58
59 s->buffer= buffer;
60 s->size_in_bits= bit_size;
61 s->buffer_end= buffer + buffer_size;
62 s->index=0;
63 {
64 OPEN_READER(re, s)
65 UPDATE_CACHE(re, s)
66 UPDATE_CACHE(re, s)
67 CLOSE_READER(re, s)
68 }
69}
70
71/**
72 * reads 0-32 bits.
73 */
74unsigned int get_bits_long(GetBitContext *s, int n){
75 if(n<=17) return get_bits(s, n);
76 else{
77 int ret= get_bits(s, 16) << (n-16);
78 return ret | get_bits(s, n-16);
79 }
80}
81
82/**
83 * shows 0-32 bits.
84 */
85unsigned int show_bits_long(GetBitContext *s, int n){
86 if(n<=17) return show_bits(s, n);
87 else{
88 GetBitContext gb= *s;
89 int ret= get_bits_long(s, n);
90 *s= gb;
91 return ret;
92 }
93}
94
95void align_get_bits(GetBitContext *s)
96{
97 int n= (-get_bits_count(s)) & 7;
98 if(n) skip_bits(s, n);
99}
100
101int check_marker(GetBitContext *s, const char *msg)
102{
103 (void)msg;
104 int bit= get_bits1(s);
105 return bit;
106}
107