1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Context Adaptive Binary Arithmetic Coder inline functions
25 */
26
27 #ifndef AVCODEC_CABAC_FUNCTIONS_H
28 #define AVCODEC_CABAC_FUNCTIONS_H
29
30 #include <stddef.h>
31 #include <stdint.h>
32
34 #include "config.h"
35
36 #ifndef UNCHECKED_BITSTREAM_READER
37 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
38 #endif
39
40 #if ARCH_AARCH64
42 #endif
43 #if ARCH_ARM
45 #endif
46 #if ARCH_X86
48 #endif
49 #if ARCH_MIPS
51 #endif
52 #if ARCH_LOONGARCH64
54 #endif
55
60
61 #if !defined(get_cabac_bypass) || !defined(get_cabac_terminate)
63 #if CABAC_BITS == 16
64 c->low+= (
c->bytestream[0]<<9) + (
c->bytestream[1]<<1);
65 #else
66 c->low+=
c->bytestream[0]<<1;
67 #endif
69 #if !UNCHECKED_BITSTREAM_READER
70 if (
c->bytestream <
c->bytestream_end)
71 #endif
73 }
74 #endif
75
76 #ifndef get_cabac_terminate
78 int shift= (uint32_t)(
c->range - 0x100)>>31;
83 }
84 #endif
85
86 #ifndef get_cabac_inline
89 unsigned x;
90 #if !HAVE_FAST_CLZ
91 x=
c->low ^ (
c->low-1);
93 #else
95 #endif
96
98
99 #if CABAC_BITS == 16
100 x+= (
c->bytestream[0]<<9) + (
c->bytestream[1]<<1);
101 #else
102 x+=
c->bytestream[0]<<1;
103 #endif
104
106 #if !UNCHECKED_BITSTREAM_READER
107 if (
c->bytestream <
c->bytestream_end)
108 #endif
110 }
111 #endif
112
113 #ifndef get_cabac_inline
118
119 c->range -= RangeLPS;
121
123 c->range += (RangeLPS -
c->range) & lps_mask;
124
128
130 c->range<<= lps_mask;
135 }
136 #endif
137
140 }
141
144 }
145
146 #ifndef get_cabac_bypass
148 int range;
150
153
156 return 0;
157 }else{
159 return 1;
160 }
161 }
162 #endif
163
164 #ifndef get_cabac_bypass_sign
168
171
178 }
179 #endif
180
181 /**
182 * @return the number of bytes read or 0 if no end
183 */
184 #ifndef get_cabac_terminate
189 return 0;
190 }else{
191 return c->bytestream -
c->bytestream_start;
192 }
193 }
194 #endif
195
196 /**
197 * Skip @p n bytes and reset the decoder.
198 * @return the address of the first skipped byte or NULL if there's less than @p n bytes left
199 */
200 #ifndef skip_bytes
202 const uint8_t *ptr =
c->bytestream;
203
205 ptr--;
206 #if CABAC_BITS == 16
208 ptr--;
209 #endif
210 if ((
int) (
c->bytestream_end - ptr) < n)
214
215 return ptr;
216 }
217 #endif
218
219 #endif /* AVCODEC_CABAC_FUNCTIONS_H */