annotate golomb.h @ 3308:57078a058b96 libavcodec

fix compilation of 3dnowext instinsincs, both on ia32 and AMD64. 3dnow intrinsincs are for now only compiled if 3dnowext support is available. (I should add smth that checks for plain 3dnow later)
author gpoirier
date Tue, 16 May 2006 14:24:45 +0000
parents 0b546eab515d
children 5b901881d6ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
1 /*
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
2 * exp golomb vlc stuff
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
4 * Copyright (c) 2004 Alex Beregszaszi
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
5 *
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
10 *
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
14 * Lesser General Public License for more details.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
15 *
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
19 *
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
20 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
21
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
22 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
23 * @file golomb.h
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
24 * @brief
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
25 * exp golomb vlc stuff
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
26 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
27 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
28
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
29 #define INVALID_VLC 0x80000000
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
30
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
31 extern const uint8_t ff_golomb_vlc_len[512];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
32 extern const uint8_t ff_ue_golomb_vlc_code[512];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
33 extern const int8_t ff_se_golomb_vlc_code[512];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
34 extern const uint8_t ff_ue_golomb_len[256];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
35
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
36 extern const uint8_t ff_interleaved_golomb_vlc_len[256];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
37 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
38 extern const int8_t ff_interleaved_se_golomb_vlc_code[256];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
39
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
40
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
41 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
42 * read unsigned exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
43 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
44 static inline int get_ue_golomb(GetBitContext *gb){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
45 unsigned int buf;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
46 int log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
47
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
48 OPEN_READER(re, gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
49 UPDATE_CACHE(re, gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
50 buf=GET_CACHE(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
51
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
52 if(buf >= (1<<27)){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
53 buf >>= 32 - 9;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
54 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
55 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
56
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
57 return ff_ue_golomb_vlc_code[buf];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
58 }else{
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
59 log= 2*av_log2(buf) - 31;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
60 buf>>= log;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
61 buf--;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
62 LAST_SKIP_BITS(re, gb, 32 - log);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
63 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
64
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
65 return buf;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
66 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
67 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
68
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
69 static inline int svq3_get_ue_golomb(GetBitContext *gb){
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
70 uint32_t buf;
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
71 int log;
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
72
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
73 OPEN_READER(re, gb);
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
74 UPDATE_CACHE(re, gb);
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
75 buf=GET_CACHE(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
76
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
77 if(buf&0xAA800000){
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
78 buf >>= 32 - 8;
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
79 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
80 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
81
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
82 return ff_interleaved_ue_golomb_vlc_code[buf];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
83 }else{
2087
a4d3699c6636 1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents: 1812
diff changeset
84 LAST_SKIP_BITS(re, gb, 8);
a4d3699c6636 1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents: 1812
diff changeset
85 UPDATE_CACHE(re, gb);
a4d3699c6636 1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents: 1812
diff changeset
86 buf |= 1 | (GET_CACHE(re, gb) >> 8);
a4d3699c6636 1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents: 1812
diff changeset
87
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
88 if((buf & 0xAAAAAAAA) == 0)
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
89 return INVALID_VLC;
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
90
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
91 for(log=31; (buf & 0x80000000) == 0; log--){
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
92 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
93 }
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
94
2087
a4d3699c6636 1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents: 1812
diff changeset
95 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8);
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
96 CLOSE_READER(re, gb);
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
97
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
98 return ((buf << log) >> log) - 1;
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
99 }
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
100 }
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
101
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
102 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
103 * read unsigned truncated exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
104 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
105 static inline int get_te0_golomb(GetBitContext *gb, int range){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
106 assert(range >= 1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
107
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
108 if(range==1) return 0;
1169
4e891257d3e2 multiple reference frames support
michaelni
parents: 1168
diff changeset
109 else if(range==2) return get_bits1(gb)^1;
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
110 else return get_ue_golomb(gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
111 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
112
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
113 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
114 * read unsigned truncated exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
115 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
116 static inline int get_te_golomb(GetBitContext *gb, int range){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
117 assert(range >= 1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
118
1169
4e891257d3e2 multiple reference frames support
michaelni
parents: 1168
diff changeset
119 if(range==2) return get_bits1(gb)^1;
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
120 else return get_ue_golomb(gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
121 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
122
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
123
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
124 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
125 * read signed exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
126 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
127 static inline int get_se_golomb(GetBitContext *gb){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
128 unsigned int buf;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
129 int log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
130
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
131 OPEN_READER(re, gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
132 UPDATE_CACHE(re, gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
133 buf=GET_CACHE(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
134
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
135 if(buf >= (1<<27)){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
136 buf >>= 32 - 9;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
137 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
138 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
139
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
140 return ff_se_golomb_vlc_code[buf];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
141 }else{
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
142 log= 2*av_log2(buf) - 31;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
143 buf>>= log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
144
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
145 LAST_SKIP_BITS(re, gb, 32 - log);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
146 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
147
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
148 if(buf&1) buf= -(buf>>1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
149 else buf= (buf>>1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
150
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
151 return buf;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
152 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
153 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
154
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
155 static inline int svq3_get_se_golomb(GetBitContext *gb){
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
156 unsigned int buf;
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
157 int log;
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
158
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
159 OPEN_READER(re, gb);
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
160 UPDATE_CACHE(re, gb);
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
161 buf=GET_CACHE(re, gb);
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
162
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
163 if(buf&0xAA800000){
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
164 buf >>= 32 - 8;
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
165 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
166 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
167
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
168 return ff_interleaved_se_golomb_vlc_code[buf];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
169 }else{
2439
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
170 LAST_SKIP_BITS(re, gb, 8);
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
171 UPDATE_CACHE(re, gb);
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
172 buf |= 1 | (GET_CACHE(re, gb) >> 8);
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
173
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
174 if((buf & 0xAAAAAAAA) == 0)
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
175 return INVALID_VLC;
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
176
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
177 for(log=31; (buf & 0x80000000) == 0; log--){
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
178 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
179 }
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
180
2439
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
181 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8);
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
182 CLOSE_READER(re, gb);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
183
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
184 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1;
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
185 }
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
186 }
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
187
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
188 /**
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
189 * read unsigned golomb rice code (ffv1).
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
190 */
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
191 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
192 unsigned int buf;
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
193 int log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
194
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
195 OPEN_READER(re, gb);
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
196 UPDATE_CACHE(re, gb);
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
197 buf=GET_CACHE(re, gb);
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
198
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
199 log= av_log2(buf);
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
200
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
201 if(log > 31-limit){
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
202 buf >>= log - k;
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
203 buf += (30-log)<<k;
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
204 LAST_SKIP_BITS(re, gb, 32 + k - log);
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
205 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
206
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
207 return buf;
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
208 }else{
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
209 buf >>= 32 - limit - esc_len;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
210 LAST_SKIP_BITS(re, gb, esc_len + limit);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
211 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
212
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
213 return buf + limit - 1;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
214 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
215 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
216
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
217 /**
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
218 * read unsigned golomb rice code (jpegls).
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
219 */
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
220 static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
221 unsigned int buf;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
222 int log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
223
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
224 OPEN_READER(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
225 UPDATE_CACHE(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
226 buf=GET_CACHE(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
227
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
228 log= av_log2(buf);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
229
1362
michaelni
parents: 1361
diff changeset
230 if(log > 31-11){
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
231 buf >>= log - k;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
232 buf += (30-log)<<k;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
233 LAST_SKIP_BITS(re, gb, 32 + k - log);
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
234 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
235
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
236 return buf;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
237 }else{
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
238 int i;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
239 for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
240 LAST_SKIP_BITS(re, gb, 1);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
241 UPDATE_CACHE(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
242 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
243 SKIP_BITS(re, gb, 1);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
244
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
245 if(i < limit - 1){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
246 if(k){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
247 buf = SHOW_UBITS(re, gb, k);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
248 LAST_SKIP_BITS(re, gb, k);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
249 }else{
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
250 buf=0;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
251 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
252
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
253 CLOSE_READER(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
254 return buf + (i<<k);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
255 }else if(i == limit - 1){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
256 buf = SHOW_UBITS(re, gb, esc_len);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
257 LAST_SKIP_BITS(re, gb, esc_len);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
258 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
259
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
260 return buf + 1;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
261 }else
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
262 return -1;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
263 }
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
264 }
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
265
1812
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
266 /**
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
267 * read signed golomb rice code (ffv1).
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
268 */
2220
21947e176d4d get/set_sr_golomb() cleanup
michael
parents: 2215
diff changeset
269 static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len){
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
270 int v= get_ur_golomb(gb, k, limit, esc_len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
271
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
272 v++;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
273 if (v&1) return v>>1;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
274 else return -(v>>1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
275
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
276 // return (v>>1) ^ -(v&1);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
277 }
2220
21947e176d4d get/set_sr_golomb() cleanup
michael
parents: 2215
diff changeset
278
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
279 /**
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
280 * read signed golomb rice code (flac).
1812
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
281 */
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
282 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
283 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len);
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
284 return (v>>1) ^ -(v&1);
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
285 }
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
286
2525
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
287 /**
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
288 * read unsigned golomb rice code (shorten).
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
289 */
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
290 static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
291 return get_ur_golomb_jpegls(gb, k, INT_MAX, 0);
2525
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
292 }
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
293
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
294 /**
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
295 * read signed golomb rice code (shorten).
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
296 */
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
297 static inline int get_sr_golomb_shorten(GetBitContext* gb, int k)
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
298 {
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
299 int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0);
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
300 if (uvar & 1)
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
301 return ~(uvar >> 1);
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
302 else
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
303 return uvar >> 1;
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
304 }
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
305
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
306
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
307
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
308 #ifdef TRACE
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
309
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2220
diff changeset
310 static inline int get_ue(GetBitContext *s, char *file, const char *func, int line){
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
311 int show= show_bits(s, 24);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
312 int pos= get_bits_count(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
313 int i= get_ue_golomb(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
314 int len= get_bits_count(s) - pos;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
315 int bits= show>>(24-len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
316
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
317 print_bin(bits, len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
318
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
319 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
320
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
321 return i;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
322 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
323
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2220
diff changeset
324 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
325 int show= show_bits(s, 24);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
326 int pos= get_bits_count(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
327 int i= get_se_golomb(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
328 int len= get_bits_count(s) - pos;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
329 int bits= show>>(24-len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
330
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
331 print_bin(bits, len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
332
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
333 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
334
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
335 return i;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
336 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
337
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2220
diff changeset
338 static inline int get_te(GetBitContext *s, int r, char *file, const char *func, int line){
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
339 int show= show_bits(s, 24);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
340 int pos= get_bits_count(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
341 int i= get_te0_golomb(s, r);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
342 int len= get_bits_count(s) - pos;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
343 int bits= show>>(24-len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
344
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
345 print_bin(bits, len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
346
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
347 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
348
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
349 return i;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
350 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
351
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
352 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
353 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
354 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
355 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
356
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
357 #endif
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
358
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
359 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
360 * write unsigned exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
361 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
362 static inline void set_ue_golomb(PutBitContext *pb, int i){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
363 int e;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
364
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
365 assert(i>=0);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
366
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
367 #if 0
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
368 if(i=0){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
369 put_bits(pb, 1, 1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
370 return;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
371 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
372 #endif
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
373 if(i<256)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
374 put_bits(pb, ff_ue_golomb_len[i], i+1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
375 else{
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
376 e= av_log2(i+1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
377
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
378 put_bits(pb, 2*e+1, i+1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
379 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
380 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
381
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
382 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
383 * write truncated unsigned exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
384 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
385 static inline void set_te_golomb(PutBitContext *pb, int i, int range){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
386 assert(range >= 1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
387 assert(i<=range);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
388
1169
4e891257d3e2 multiple reference frames support
michaelni
parents: 1168
diff changeset
389 if(range==2) put_bits(pb, 1, i^1);
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
390 else set_ue_golomb(pb, i);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
391 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
392
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
393 /**
2905
926ea374947f set_se_golomb can only write 16bits, add a note about this (ok, maybe it's brain dead using it with more than 16bits, but..)
alex
parents: 2525
diff changeset
394 * write signed exp golomb code. 16 bits at most.
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
395 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
396 static inline void set_se_golomb(PutBitContext *pb, int i){
2905
926ea374947f set_se_golomb can only write 16bits, add a note about this (ok, maybe it's brain dead using it with more than 16bits, but..)
alex
parents: 2525
diff changeset
397 // if (i>32767 || i<-32767)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
398 // av_log(NULL,AV_LOG_ERROR,"value out of range %d\n", i);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
399 #if 0
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
400 if(i<=0) i= -2*i;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
401 else i= 2*i-1;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
402 #elif 1
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
403 i= 2*i-1;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
404 if(i<0) i^= -1; //FIXME check if gcc does the right thing
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
405 #else
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
406 i= 2*i-1;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
407 i^= (i>>31);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
408 #endif
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
409 set_ue_golomb(pb, i);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
410 }
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
411
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
412 /**
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
413 * write unsigned golomb rice code (ffv1).
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
414 */
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
415 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
416 int e;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
417
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
418 assert(i>=0);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
419
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
420 e= i>>k;
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
421 if(e<limit){
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
422 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1)));
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
423 }else{
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
424 put_bits(pb, limit + esc_len, i - limit + 1);
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
425 }
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
426 }
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
427
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
428 /**
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
429 * write unsigned golomb rice code (jpegls).
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
430 */
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
431 static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, int limit, int esc_len){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
432 int e;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
433
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
434 assert(i>=0);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
435
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
436 e= (i>>k) + 1;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
437 if(e<limit){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
438 put_bits(pb, e, 1);
1362
michaelni
parents: 1361
diff changeset
439 if(k)
michaelni
parents: 1361
diff changeset
440 put_bits(pb, k, i&((1<<k)-1));
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
441 }else{
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
442 put_bits(pb, limit , 1);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
443 put_bits(pb, esc_len, i - 1);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
444 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
445 }
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
446
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
447 /**
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
448 * write signed golomb rice code (ffv1).
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
449 */
2220
21947e176d4d get/set_sr_golomb() cleanup
michael
parents: 2215
diff changeset
450 static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
451 int v;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
452
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
453 v = -2*i-1;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
454 v ^= (v>>31);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
455
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
456 set_ur_golomb(pb, v, k, limit, esc_len);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
457 }
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
458
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
459 /**
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
460 * write signed golomb rice code (flac).
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
461 */
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
462 static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit, int esc_len){
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
463 int v;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
464
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
465 v = -2*i-1;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
466 v ^= (v>>31);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
467
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
468 set_ur_golomb_jpegls(pb, v, k, limit, esc_len);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
469 }