annotate golomb.h @ 11969:3cd4cd0509cd libavcodec

Remove PPC perf counter support This functionality is better accessed through tools like oprofile.
author mru
date Sat, 26 Jun 2010 22:23:35 +0000
parents 7dd2a45249a9
children
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 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3353
diff changeset
6 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3353
diff changeset
7 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3353
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3353
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
12 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3353
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
16 * Lesser General Public License for more details.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
17 *
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3353
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
21 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
22
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
23 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 10164
diff changeset
24 * @file
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
25 * @brief
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
26 * exp golomb vlc stuff
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
27 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
28 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
29
7760
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 7260
diff changeset
30 #ifndef AVCODEC_GOLOMB_H
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 7260
diff changeset
31 #define AVCODEC_GOLOMB_H
5163
9ecbfc0c82bf add multiple inclusion guards to headers
mru
parents: 5162
diff changeset
32
5162
4394344397d8 include all prerequisites in header files
mru
parents: 4053
diff changeset
33 #include <stdint.h>
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9411
diff changeset
34 #include "get_bits.h"
9411
4cb7c65fc775 Split bitstream.h, put the bitstream writer stuff in the new file
stefano
parents: 9020
diff changeset
35 #include "put_bits.h"
5162
4394344397d8 include all prerequisites in header files
mru
parents: 4053
diff changeset
36
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
37 #define INVALID_VLC 0x80000000
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
38
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
39 extern const uint8_t ff_golomb_vlc_len[512];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
40 extern const uint8_t ff_ue_golomb_vlc_code[512];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
41 extern const int8_t ff_se_golomb_vlc_code[512];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
42 extern const uint8_t ff_ue_golomb_len[256];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
43
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
44 extern const uint8_t ff_interleaved_golomb_vlc_len[256];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
45 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
46 extern const int8_t ff_interleaved_se_golomb_vlc_code[256];
5546
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
47 extern const uint8_t ff_interleaved_dirac_golomb_vlc_code[256];
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
48
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
49
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
50 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
51 * read unsigned exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
52 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
53 static inline int get_ue_golomb(GetBitContext *gb){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
54 unsigned int buf;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
55 int log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
56
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
57 OPEN_READER(re, gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
58 UPDATE_CACHE(re, gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
59 buf=GET_CACHE(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
60
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
61 if(buf >= (1<<27)){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
62 buf >>= 32 - 9;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
63 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
64 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
65
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
66 return ff_ue_golomb_vlc_code[buf];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
67 }else{
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
68 log= 2*av_log2(buf) - 31;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
69 buf>>= log;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
70 buf--;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
71 LAST_SKIP_BITS(re, gb, 32 - log);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
72 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
73
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
74 return buf;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
75 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
76 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
77
8449
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
78 /**
8969
9218ef5d5afb Clarify get_ue_golomb_31() behavior with >31.
michael
parents: 8718
diff changeset
79 * read unsigned exp golomb code, constraint to a max of 31.
9218ef5d5afb Clarify get_ue_golomb_31() behavior with >31.
michael
parents: 8718
diff changeset
80 * the return value is undefined if the stored value exceeds 31.
8449
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
81 */
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
82 static inline int get_ue_golomb_31(GetBitContext *gb){
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
83 unsigned int buf;
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
84
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
85 OPEN_READER(re, gb);
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
86 UPDATE_CACHE(re, gb);
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
87 buf=GET_CACHE(re, gb);
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
88
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
89 buf >>= 32 - 9;
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
90 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
91 CLOSE_READER(re, gb);
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
92
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
93 return ff_ue_golomb_vlc_code[buf];
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
94 }
d6faaf27eacf Add get_ue_golomb_31()
michael
parents: 7869
diff changeset
95
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
96 static inline int svq3_get_ue_golomb(GetBitContext *gb){
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
97 uint32_t buf;
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
98
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
99 OPEN_READER(re, gb);
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
100 UPDATE_CACHE(re, gb);
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
101 buf=GET_CACHE(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
102
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
103 if(buf&0xAA800000){
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
104 buf >>= 32 - 8;
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
105 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
106 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
107
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
108 return ff_interleaved_ue_golomb_vlc_code[buf];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
109 }else{
5546
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
110 int ret = 1;
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
111
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
112 while (1) {
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
113 buf >>= 32 - 8;
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
114 LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
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
115
5546
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
116 if (ff_interleaved_golomb_vlc_len[buf] != 9){
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
117 ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1;
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
118 ret |= ff_interleaved_dirac_golomb_vlc_code[buf];
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
119 break;
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
120 }
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
121 ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
122 UPDATE_CACHE(re, gb);
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
123 buf = GET_CACHE(re, gb);
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
124 }
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
125
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
126 CLOSE_READER(re, gb);
5546
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
127 return ret - 1;
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
128 }
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
129 }
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
130
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
131 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
132 * read unsigned truncated exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
133 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
134 static inline int get_te0_golomb(GetBitContext *gb, int range){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
135 assert(range >= 1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
136
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
137 if(range==1) return 0;
1169
4e891257d3e2 multiple reference frames support
michaelni
parents: 1168
diff changeset
138 else if(range==2) return get_bits1(gb)^1;
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
139 else return get_ue_golomb(gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
140 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
141
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
142 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
143 * read unsigned truncated exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
144 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
145 static inline int get_te_golomb(GetBitContext *gb, int range){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
146 assert(range >= 1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
147
1169
4e891257d3e2 multiple reference frames support
michaelni
parents: 1168
diff changeset
148 if(range==2) return get_bits1(gb)^1;
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
149 else return get_ue_golomb(gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
150 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
151
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 * read signed exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
155 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
156 static inline int get_se_golomb(GetBitContext *gb){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
157 unsigned int buf;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
158 int log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
159
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
160 OPEN_READER(re, gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
161 UPDATE_CACHE(re, gb);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
162 buf=GET_CACHE(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
163
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
164 if(buf >= (1<<27)){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
165 buf >>= 32 - 9;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
166 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
167 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
168
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
169 return ff_se_golomb_vlc_code[buf];
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
170 }else{
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
171 log= 2*av_log2(buf) - 31;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
172 buf>>= log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
173
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
174 LAST_SKIP_BITS(re, gb, 32 - log);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
175 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
176
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
177 if(buf&1) buf= -(buf>>1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
178 else buf= (buf>>1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
179
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
180 return buf;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
181 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
182 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
183
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
184 static inline int svq3_get_se_golomb(GetBitContext *gb){
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
185 unsigned int buf;
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
186 int log;
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
187
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
188 OPEN_READER(re, gb);
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
189 UPDATE_CACHE(re, gb);
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
190 buf=GET_CACHE(re, gb);
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
191
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
192 if(buf&0xAA800000){
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
193 buf >>= 32 - 8;
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
194 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
195 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
196
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
197 return ff_interleaved_se_golomb_vlc_code[buf];
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
198 }else{
2439
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
199 LAST_SKIP_BITS(re, gb, 8);
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
200 UPDATE_CACHE(re, gb);
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
201 buf |= 1 | (GET_CACHE(re, gb) >> 8);
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
202
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
203 if((buf & 0xAAAAAAAA) == 0)
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
204 return INVALID_VLC;
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
205
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
206 for(log=31; (buf & 0x80000000) == 0; log--){
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
207 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
208 }
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
209
2439
6684c0e9e28f svq3_get_se_golomb() fix
michael
parents: 2438
diff changeset
210 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8);
1250
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
211 CLOSE_READER(re, gb);
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
212
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
213 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1;
fa181d095027 optimizations
michaelni
parents: 1234
diff changeset
214 }
1234
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
215 }
fc2a7eefa9cc svq3 decoder by anonymous
michaelni
parents: 1169
diff changeset
216
5546
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
217 static inline int dirac_get_se_golomb(GetBitContext *gb){
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
218 uint32_t buf;
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
219 uint32_t ret;
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
220
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
221 ret = svq3_get_ue_golomb(gb);
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
222
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
223 if (ret) {
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
224 OPEN_READER(re, gb);
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
225 UPDATE_CACHE(re, gb);
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
226 buf = SHOW_SBITS(re, gb, 1);
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
227 LAST_SKIP_BITS(re, gb, 1);
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
228 ret = (ret ^ buf) - buf;
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
229 CLOSE_READER(re, gb);
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
230 }
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
231
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
232 return ret;
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
233 }
e12027d324cc Make the Golomb decoder work for Dirac
marco
parents: 5215
diff changeset
234
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
235 /**
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
236 * read unsigned golomb rice code (ffv1).
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
237 */
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
238 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
239 unsigned int buf;
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
240 int log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
241
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
242 OPEN_READER(re, gb);
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
243 UPDATE_CACHE(re, gb);
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
244 buf=GET_CACHE(re, gb);
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
245
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
246 log= av_log2(buf);
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
247
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
248 if(log > 31-limit){
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
249 buf >>= log - k;
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
250 buf += (30-log)<<k;
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
251 LAST_SKIP_BITS(re, gb, 32 + k - log);
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
252 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
253
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
254 return buf;
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
255 }else{
10164
944071b6fcb4 Make get_ur_golomb capable of reading 16 bit values.
benoit
parents: 9428
diff changeset
256 LAST_SKIP_BITS(re, gb, limit);
944071b6fcb4 Make get_ur_golomb capable of reading 16 bit values.
benoit
parents: 9428
diff changeset
257 UPDATE_CACHE(re, gb);
944071b6fcb4 Make get_ur_golomb capable of reading 16 bit values.
benoit
parents: 9428
diff changeset
258
944071b6fcb4 Make get_ur_golomb capable of reading 16 bit values.
benoit
parents: 9428
diff changeset
259 buf = SHOW_UBITS(re, gb, esc_len);
944071b6fcb4 Make get_ur_golomb capable of reading 16 bit values.
benoit
parents: 9428
diff changeset
260
944071b6fcb4 Make get_ur_golomb capable of reading 16 bit values.
benoit
parents: 9428
diff changeset
261 LAST_SKIP_BITS(re, gb, esc_len);
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
262 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
263
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
264 return buf + limit - 1;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
265 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
266 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
267
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
268 /**
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
269 * read unsigned golomb rice code (jpegls).
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
270 */
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
271 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
272 unsigned int buf;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
273 int log;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
274
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
275 OPEN_READER(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
276 UPDATE_CACHE(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
277 buf=GET_CACHE(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
278
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
279 log= av_log2(buf);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
280
9020
97b991a32b85 Fix get_ur_golomb_jpegls() with A32_BITSTREAM_READER
mru
parents: 8969
diff changeset
281 if(log - k >= 32-MIN_CACHE_BITS+(MIN_CACHE_BITS==32) && 32-log < limit){
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
282 buf >>= log - k;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
283 buf += (30-log)<<k;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
284 LAST_SKIP_BITS(re, gb, 32 + k - log);
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
285 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
286
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
287 return buf;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
288 }else{
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
289 int i;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
290 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
291 LAST_SKIP_BITS(re, gb, 1);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
292 UPDATE_CACHE(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
293 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
294 SKIP_BITS(re, gb, 1);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
295
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
296 if(i < limit - 1){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
297 if(k){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
298 buf = SHOW_UBITS(re, gb, k);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
299 LAST_SKIP_BITS(re, gb, k);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
300 }else{
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
301 buf=0;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
302 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
303
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
304 CLOSE_READER(re, gb);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
305 return buf + (i<<k);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
306 }else if(i == limit - 1){
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
307 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
308 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
309 CLOSE_READER(re, gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
310
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
311 return buf + 1;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
312 }else
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
313 return -1;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
314 }
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
315 }
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
316
1812
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
317 /**
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
318 * read signed golomb rice code (ffv1).
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
319 */
2220
21947e176d4d get/set_sr_golomb() cleanup
michael
parents: 2215
diff changeset
320 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
321 int v= get_ur_golomb(gb, k, limit, esc_len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
322
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
323 v++;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
324 if (v&1) return v>>1;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
325 else return -(v>>1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
326
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
327 // return (v>>1) ^ -(v&1);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
328 }
2220
21947e176d4d get/set_sr_golomb() cleanup
michael
parents: 2215
diff changeset
329
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
330 /**
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
331 * read signed golomb rice code (flac).
1812
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
332 */
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
333 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
334 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len);
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
335 return (v>>1) ^ -(v&1);
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
336 }
6d762acfff5d flac fixes:
michael
parents: 1362
diff changeset
337
2525
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
338 /**
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
339 * read unsigned golomb rice code (shorten).
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
340 */
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
341 static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
342 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
343 }
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
344
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
345 /**
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
346 * read signed golomb rice code (shorten).
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
347 */
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
348 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
349 {
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
350 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
351 if (uvar & 1)
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
352 return ~(uvar >> 1);
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
353 else
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
354 return uvar >> 1;
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
355 }
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
356
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
357
b47af698085e shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 2439
diff changeset
358
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
359 #ifdef TRACE
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
360
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2220
diff changeset
361 static inline int get_ue(GetBitContext *s, char *file, const char *func, int line){
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
362 int show= show_bits(s, 24);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
363 int pos= get_bits_count(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
364 int i= get_ue_golomb(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
365 int len= get_bits_count(s) - pos;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
366 int bits= show>>(24-len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
367
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
368 print_bin(bits, len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
369
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
370 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
371
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
372 return i;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
373 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
374
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2220
diff changeset
375 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
376 int show= show_bits(s, 24);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
377 int pos= get_bits_count(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
378 int i= get_se_golomb(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
379 int len= get_bits_count(s) - pos;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
380 int bits= show>>(24-len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
381
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
382 print_bin(bits, len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
383
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
384 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
385
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
386 return i;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
387 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
388
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2220
diff changeset
389 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
390 int show= show_bits(s, 24);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
391 int pos= get_bits_count(s);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
392 int i= get_te0_golomb(s, r);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
393 int len= get_bits_count(s) - pos;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
394 int bits= show>>(24-len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
395
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
396 print_bin(bits, len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
397
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
398 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
399
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
400 return i;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
401 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
402
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
403 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
404 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
405 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
406 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
407
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
408 #endif
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
409
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
410 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
411 * write unsigned exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
412 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
413 static inline void set_ue_golomb(PutBitContext *pb, int i){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
414 int e;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
415
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
416 assert(i>=0);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
417
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
418 #if 0
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
419 if(i=0){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
420 put_bits(pb, 1, 1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
421 return;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
422 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
423 #endif
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
424 if(i<256)
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
425 put_bits(pb, ff_ue_golomb_len[i], i+1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
426 else{
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
427 e= av_log2(i+1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
428
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
429 put_bits(pb, 2*e+1, i+1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
430 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
431 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
432
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
433 /**
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
434 * write truncated unsigned exp golomb code.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
435 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
436 static inline void set_te_golomb(PutBitContext *pb, int i, int range){
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
437 assert(range >= 1);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
438 assert(i<=range);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
439
1169
4e891257d3e2 multiple reference frames support
michaelni
parents: 1168
diff changeset
440 if(range==2) put_bits(pb, 1, i^1);
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
441 else set_ue_golomb(pb, i);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
442 }
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
443
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
444 /**
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
445 * write signed exp golomb code. 16 bits at most.
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
446 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
447 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
448 // if (i>32767 || i<-32767)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
449 // 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
450 #if 0
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
451 if(i<=0) i= -2*i;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
452 else i= 2*i-1;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
453 #elif 1
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
454 i= 2*i-1;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
455 if(i<0) i^= -1; //FIXME check if gcc does the right thing
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
456 #else
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
457 i= 2*i-1;
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
458 i^= (i>>31);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
459 #endif
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
460 set_ue_golomb(pb, i);
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
461 }
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
462
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
463 /**
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
464 * write unsigned golomb rice code (ffv1).
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
465 */
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
466 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
467 int e;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
468
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
469 assert(i>=0);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
470
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
471 e= i>>k;
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
472 if(e<limit){
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
473 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1)));
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
474 }else{
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
475 put_bits(pb, limit + esc_len, i - limit + 1);
1306
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
476 }
799839d1e2e1 golomb rice codes
michaelni
parents: 1250
diff changeset
477 }
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
478
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
479 /**
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
480 * write unsigned golomb rice code (jpegls).
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
481 */
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
482 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
483 int e;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
484
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
485 assert(i>=0);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2905
diff changeset
486
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
487 e= (i>>k) + 1;
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
488 if(e<limit){
3353
5b901881d6ed first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents: 3036
diff changeset
489 while(e > 31) {
5b901881d6ed first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents: 3036
diff changeset
490 put_bits(pb, 31, 0);
5b901881d6ed first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents: 3036
diff changeset
491 e -= 31;
5b901881d6ed first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents: 3036
diff changeset
492 }
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
493 put_bits(pb, e, 1);
1362
michaelni
parents: 1361
diff changeset
494 if(k)
7260
3ec34b551aae bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents: 5830
diff changeset
495 put_sbits(pb, k, i);
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
496 }else{
4053
fb4e436780fb handle limit>32 for set_ur_golomb_jpegls()
kostya
parents: 3947
diff changeset
497 while(limit > 31) {
fb4e436780fb handle limit>32 for set_ur_golomb_jpegls()
kostya
parents: 3947
diff changeset
498 put_bits(pb, 31, 0);
fb4e436780fb handle limit>32 for set_ur_golomb_jpegls()
kostya
parents: 3947
diff changeset
499 limit -= 31;
fb4e436780fb handle limit>32 for set_ur_golomb_jpegls()
kostya
parents: 3947
diff changeset
500 }
1361
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
501 put_bits(pb, limit , 1);
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
502 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
503 }
8479b875a989 golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents: 1306
diff changeset
504 }
2215
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
505
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
506 /**
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
507 * write signed golomb rice code (ffv1).
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
508 */
2220
21947e176d4d get/set_sr_golomb() cleanup
michael
parents: 2215
diff changeset
509 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
510 int v;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
511
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
512 v = -2*i-1;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
513 v ^= (v>>31);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
514
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
515 set_ur_golomb(pb, v, k, limit, esc_len);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
516 }
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
517
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
518 /**
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
519 * write signed golomb rice code (flac).
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
520 */
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
521 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
522 int v;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
523
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
524 v = -2*i-1;
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
525 v ^= (v>>31);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
526
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
527 set_ur_golomb_jpegls(pb, v, k, limit, esc_len);
2a767157935e new signed golomb routines
alex
parents: 2087
diff changeset
528 }
5163
9ecbfc0c82bf add multiple inclusion guards to headers
mru
parents: 5162
diff changeset
529
7760
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 7260
diff changeset
530 #endif /* AVCODEC_GOLOMB_H */