annotate get_bits.h @ 10805:55a1d93c534c libavcodec

Set bits_per_coded_sample in the raw video encoder. Aside from being the correct thing to do, this also fixes issue 1299.
author jai_menon
date Fri, 08 Jan 2010 05:08:02 +0000
parents 3be801dcc8a1
children 4289d95e5022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
1 /*
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
3 *
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
4 * This file is part of FFmpeg.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
5 *
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
10 *
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
14 * Lesser General Public License for more details.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
15 *
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
19 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
20
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
21 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
22 * @file libavcodec/get_bits.h
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
23 * bitstream reader API header.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
24 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
25
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
26 #ifndef AVCODEC_GET_BITS_H
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
27 #define AVCODEC_GET_BITS_H
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
28
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
29 #include <stdint.h>
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
30 #include <stdlib.h>
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
31 #include <assert.h>
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
32 #include "libavutil/bswap.h"
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
33 #include "libavutil/common.h"
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
34 #include "libavutil/intreadwrite.h"
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
35 #include "libavutil/log.h"
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
36 #include "mathops.h"
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
37
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
38 #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
39 # define ALT_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
40 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
41
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
42 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
10703
3be801dcc8a1 ARM: use ALT_BITSTREAM_READER on cores with fast unaligned access
mru
parents: 10504
diff changeset
43 # if ARCH_ARM && !HAVE_FAST_UNALIGNED
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
44 # define A32_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
45 # else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
46 # define ALT_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
47 //#define LIBMPEG2_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
48 //#define A32_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
49 # endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
50 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
51
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
52 #if ARCH_X86
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
53 // avoid +32 for shift optimization (gcc should do that ...)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
54 static inline int32_t NEG_SSR32( int32_t a, int8_t s){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
55 __asm__ ("sarl %1, %0\n\t"
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
56 : "+r" (a)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
57 : "ic" ((uint8_t)(-s))
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
58 );
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
59 return a;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
60 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
61 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
62 __asm__ ("shrl %1, %0\n\t"
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
63 : "+r" (a)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
64 : "ic" ((uint8_t)(-s))
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
65 );
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
66 return a;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
67 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
68 #else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
69 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
70 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
71 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
72
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
73 /* bit input */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
74 /* buffer, buffer_end and size_in_bits must be present and used by every reader */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
75 typedef struct GetBitContext {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
76 const uint8_t *buffer, *buffer_end;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
77 #ifdef ALT_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
78 int index;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
79 #elif defined LIBMPEG2_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
80 uint8_t *buffer_ptr;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
81 uint32_t cache;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
82 int bit_count;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
83 #elif defined A32_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
84 uint32_t *buffer_ptr;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
85 uint32_t cache0;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
86 uint32_t cache1;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
87 int bit_count;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
88 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
89 int size_in_bits;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
90 } GetBitContext;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
91
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
92 #define VLC_TYPE int16_t
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
93
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
94 typedef struct VLC {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
95 int bits;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
96 VLC_TYPE (*table)[2]; ///< code, bits
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
97 int table_size, table_allocated;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
98 } VLC;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
99
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
100 typedef struct RL_VLC_ELEM {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
101 int16_t level;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
102 int8_t len;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
103 uint8_t run;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
104 } RL_VLC_ELEM;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
105
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
106 /* Bitstream reader API docs:
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
107 name
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
108 arbitrary name which is used as prefix for the internal variables
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
109
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
110 gb
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
111 getbitcontext
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
112
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
113 OPEN_READER(name, gb)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
114 loads gb into local variables
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
115
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
116 CLOSE_READER(name, gb)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
117 stores local vars in gb
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
118
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
119 UPDATE_CACHE(name, gb)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
120 refills the internal cache from the bitstream
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
121 after this call at least MIN_CACHE_BITS will be available,
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
122
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
123 GET_CACHE(name, gb)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
124 will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
125
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
126 SHOW_UBITS(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
127 will return the next num bits
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
128
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
129 SHOW_SBITS(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
130 will return the next num bits and do sign extension
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
131
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
132 SKIP_BITS(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
133 will skip over the next num bits
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
134 note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
135
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
136 SKIP_CACHE(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
137 will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
138
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
139 SKIP_COUNTER(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
140 will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
141
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
142 LAST_SKIP_CACHE(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
143 will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
144
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
145 LAST_SKIP_BITS(name, gb, num)
10163
24c03529ccbe Fix a typo in the documentation.
benoit
parents: 10148
diff changeset
146 is equivalent to LAST_SKIP_CACHE; SKIP_COUNTER
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
147
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
148 for examples see get_bits, show_bits, skip_bits, get_vlc
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
149 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
150
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
151 #ifdef ALT_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
152 # define MIN_CACHE_BITS 25
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
153
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
154 # define OPEN_READER(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
155 int name##_index= (gb)->index;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
156 int name##_cache= 0;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
157
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
158 # define CLOSE_READER(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
159 (gb)->index= name##_index;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
160
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
161 # ifdef ALT_BITSTREAM_READER_LE
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
162 # define UPDATE_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
163 name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
164
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
165 # define SKIP_CACHE(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
166 name##_cache >>= (num);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
167 # else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
168 # define UPDATE_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
169 name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
170
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
171 # define SKIP_CACHE(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
172 name##_cache <<= (num);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
173 # endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
174
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
175 // FIXME name?
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
176 # define SKIP_COUNTER(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
177 name##_index += (num);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
178
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
179 # define SKIP_BITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
180 {\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
181 SKIP_CACHE(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
182 SKIP_COUNTER(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
183 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
184
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
185 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
186 # define LAST_SKIP_CACHE(name, gb, num) ;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
187
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
188 # ifdef ALT_BITSTREAM_READER_LE
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
189 # define SHOW_UBITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
190 ((name##_cache) & (NEG_USR32(0xffffffff,num)))
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
191
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
192 # define SHOW_SBITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
193 NEG_SSR32((name##_cache)<<(32-(num)), num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
194 # else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
195 # define SHOW_UBITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
196 NEG_USR32(name##_cache, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
197
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
198 # define SHOW_SBITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
199 NEG_SSR32(name##_cache, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
200 # endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
201
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
202 # define GET_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
203 ((uint32_t)name##_cache)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
204
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
205 static inline int get_bits_count(GetBitContext *s){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
206 return s->index;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
207 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
208
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
209 static inline void skip_bits_long(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
210 s->index += n;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
211 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
212
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
213 #elif defined LIBMPEG2_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
214 //libmpeg2 like reader
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
215
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
216 # define MIN_CACHE_BITS 17
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
217
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
218 # define OPEN_READER(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
219 int name##_bit_count=(gb)->bit_count;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
220 int name##_cache= (gb)->cache;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
221 uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
222
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
223 # define CLOSE_READER(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
224 (gb)->bit_count= name##_bit_count;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
225 (gb)->cache= name##_cache;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
226 (gb)->buffer_ptr= name##_buffer_ptr;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
227
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
228 # define UPDATE_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
229 if(name##_bit_count >= 0){\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
230 name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
231 name##_buffer_ptr+=2;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
232 name##_bit_count-= 16;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
233 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
234
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
235 # define SKIP_CACHE(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
236 name##_cache <<= (num);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
237
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
238 # define SKIP_COUNTER(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
239 name##_bit_count += (num);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
240
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
241 # define SKIP_BITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
242 {\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
243 SKIP_CACHE(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
244 SKIP_COUNTER(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
245 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
246
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
247 # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
248 # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
249
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
250 # define SHOW_UBITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
251 NEG_USR32(name##_cache, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
252
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
253 # define SHOW_SBITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
254 NEG_SSR32(name##_cache, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
255
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
256 # define GET_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
257 ((uint32_t)name##_cache)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
258
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
259 static inline int get_bits_count(GetBitContext *s){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
260 return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
261 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
262
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
263 static inline void skip_bits_long(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
264 OPEN_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
265 re_bit_count += n;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
266 re_buffer_ptr += 2*(re_bit_count>>4);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
267 re_bit_count &= 15;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
268 re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
269 UPDATE_CACHE(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
270 CLOSE_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
271 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
272
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
273 #elif defined A32_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
274
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
275 # define MIN_CACHE_BITS 32
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
276
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
277 # define OPEN_READER(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
278 int name##_bit_count=(gb)->bit_count;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
279 uint32_t name##_cache0= (gb)->cache0;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
280 uint32_t name##_cache1= (gb)->cache1;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
281 uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
282
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
283 # define CLOSE_READER(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
284 (gb)->bit_count= name##_bit_count;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
285 (gb)->cache0= name##_cache0;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
286 (gb)->cache1= name##_cache1;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
287 (gb)->buffer_ptr= name##_buffer_ptr;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
288
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
289 # define UPDATE_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
290 if(name##_bit_count > 0){\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
291 const uint32_t next= be2me_32( *name##_buffer_ptr );\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
292 name##_cache0 |= NEG_USR32(next,name##_bit_count);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
293 name##_cache1 |= next<<name##_bit_count;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
294 name##_buffer_ptr++;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
295 name##_bit_count-= 32;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
296 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
297
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
298 #if ARCH_X86
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
299 # define SKIP_CACHE(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
300 __asm__(\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
301 "shldl %2, %1, %0 \n\t"\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
302 "shll %2, %1 \n\t"\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
303 : "+r" (name##_cache0), "+r" (name##_cache1)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
304 : "Ic" ((uint8_t)(num))\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
305 );
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
306 #else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
307 # define SKIP_CACHE(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
308 name##_cache0 <<= (num);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
309 name##_cache0 |= NEG_USR32(name##_cache1,num);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
310 name##_cache1 <<= (num);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
311 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
312
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
313 # define SKIP_COUNTER(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
314 name##_bit_count += (num);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
315
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
316 # define SKIP_BITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
317 {\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
318 SKIP_CACHE(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
319 SKIP_COUNTER(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
320 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
321
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
322 # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
323 # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
324
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
325 # define SHOW_UBITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
326 NEG_USR32(name##_cache0, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
327
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
328 # define SHOW_SBITS(name, gb, num)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
329 NEG_SSR32(name##_cache0, num)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
330
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
331 # define GET_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
332 (name##_cache0)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
333
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
334 static inline int get_bits_count(GetBitContext *s){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
335 return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
336 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
337
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
338 static inline void skip_bits_long(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
339 OPEN_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
340 re_bit_count += n;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
341 re_buffer_ptr += re_bit_count>>5;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
342 re_bit_count &= 31;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
343 re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
344 re_cache1 = 0;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
345 UPDATE_CACHE(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
346 CLOSE_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
347 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
348
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
349 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
350
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
351 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
352 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
353 * if MSB not set it is negative
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
354 * @param n length in bits
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
355 * @author BERO
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
356 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
357 static inline int get_xbits(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
358 register int sign;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
359 register int32_t cache;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
360 OPEN_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
361 UPDATE_CACHE(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
362 cache = GET_CACHE(re,s);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
363 sign=(~cache)>>31;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
364 LAST_SKIP_BITS(re, s, n)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
365 CLOSE_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
366 return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
367 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
368
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
369 static inline int get_sbits(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
370 register int tmp;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
371 OPEN_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
372 UPDATE_CACHE(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
373 tmp= SHOW_SBITS(re, s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
374 LAST_SKIP_BITS(re, s, n)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
375 CLOSE_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
376 return tmp;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
377 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
378
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
379 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
380 * reads 1-17 bits.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
381 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
382 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
383 static inline unsigned int get_bits(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
384 register int tmp;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
385 OPEN_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
386 UPDATE_CACHE(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
387 tmp= SHOW_UBITS(re, s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
388 LAST_SKIP_BITS(re, s, n)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
389 CLOSE_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
390 return tmp;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
391 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
392
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
393 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
394 * shows 1-17 bits.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
395 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
396 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
397 static inline unsigned int show_bits(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
398 register int tmp;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
399 OPEN_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
400 UPDATE_CACHE(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
401 tmp= SHOW_UBITS(re, s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
402 // CLOSE_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
403 return tmp;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
404 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
405
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
406 static inline void skip_bits(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
407 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
408 OPEN_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
409 UPDATE_CACHE(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
410 LAST_SKIP_BITS(re, s, n)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
411 CLOSE_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
412 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
413
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
414 static inline unsigned int get_bits1(GetBitContext *s){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
415 #ifdef ALT_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
416 int index= s->index;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
417 uint8_t result= s->buffer[ index>>3 ];
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
418 #ifdef ALT_BITSTREAM_READER_LE
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
419 result>>= (index&0x07);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
420 result&= 1;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
421 #else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
422 result<<= (index&0x07);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
423 result>>= 8 - 1;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
424 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
425 index++;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
426 s->index= index;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
427
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
428 return result;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
429 #else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
430 return get_bits(s, 1);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
431 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
432 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
433
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
434 static inline unsigned int show_bits1(GetBitContext *s){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
435 return show_bits(s, 1);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
436 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
437
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
438 static inline void skip_bits1(GetBitContext *s){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
439 skip_bits(s, 1);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
440 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
441
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
442 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
443 * reads 0-32 bits.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
444 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
445 static inline unsigned int get_bits_long(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
446 if(n<=17) return get_bits(s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
447 else{
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
448 #ifdef ALT_BITSTREAM_READER_LE
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
449 int ret= get_bits(s, 16);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
450 return ret | (get_bits(s, n-16) << 16);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
451 #else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
452 int ret= get_bits(s, 16) << (n-16);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
453 return ret | get_bits(s, n-16);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
454 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
455 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
456 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
457
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
458 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
459 * reads 0-32 bits as a signed integer.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
460 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
461 static inline int get_sbits_long(GetBitContext *s, int n) {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
462 return sign_extend(get_bits_long(s, n), n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
463 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
464
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
465 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
466 * shows 0-32 bits.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
467 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
468 static inline unsigned int show_bits_long(GetBitContext *s, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
469 if(n<=17) return show_bits(s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
470 else{
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
471 GetBitContext gb= *s;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
472 return get_bits_long(&gb, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
473 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
474 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
475
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
476 static inline int check_marker(GetBitContext *s, const char *msg)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
477 {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
478 int bit= get_bits1(s);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
479 if(!bit)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
480 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
481
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
482 return bit;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
483 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
484
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
485 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
486 * init GetBitContext.
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
487 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
488 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
489 * @param bit_size the size of the buffer in bits
10148
732dfbf67524 Try to clarify that anyone using get_bits must check for buffer overrun
reimar
parents: 9428
diff changeset
490 *
732dfbf67524 Try to clarify that anyone using get_bits must check for buffer overrun
reimar
parents: 9428
diff changeset
491 * While GetBitContext stores the buffer size, for performance reasons you are
732dfbf67524 Try to clarify that anyone using get_bits must check for buffer overrun
reimar
parents: 9428
diff changeset
492 * responsible for checking for the buffer end yourself (take advantage of the padding)!
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
493 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
494 static inline void init_get_bits(GetBitContext *s,
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
495 const uint8_t *buffer, int bit_size)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
496 {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
497 int buffer_size= (bit_size+7)>>3;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
498 if(buffer_size < 0 || bit_size < 0) {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
499 buffer_size = bit_size = 0;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
500 buffer = NULL;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
501 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
502
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
503 s->buffer= buffer;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
504 s->size_in_bits= bit_size;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
505 s->buffer_end= buffer + buffer_size;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
506 #ifdef ALT_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
507 s->index=0;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
508 #elif defined LIBMPEG2_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
509 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
510 s->bit_count = 16 + 8*((intptr_t)buffer&1);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
511 skip_bits_long(s, 0);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
512 #elif defined A32_BITSTREAM_READER
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
513 s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
514 s->bit_count = 32 + 8*((intptr_t)buffer&3);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
515 skip_bits_long(s, 0);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
516 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
517 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
518
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
519 static inline void align_get_bits(GetBitContext *s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
520 {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
521 int n= (-get_bits_count(s)) & 7;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
522 if(n) skip_bits(s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
523 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
524
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
525 #define init_vlc(vlc, nb_bits, nb_codes,\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
526 bits, bits_wrap, bits_size,\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
527 codes, codes_wrap, codes_size,\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
528 flags)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
529 init_vlc_sparse(vlc, nb_bits, nb_codes,\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
530 bits, bits_wrap, bits_size,\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
531 codes, codes_wrap, codes_size,\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
532 NULL, 0, 0, flags)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
533
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
534 int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
535 const void *bits, int bits_wrap, int bits_size,
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
536 const void *codes, int codes_wrap, int codes_size,
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
537 const void *symbols, int symbols_wrap, int symbols_size,
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
538 int flags);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
539 #define INIT_VLC_LE 2
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
540 #define INIT_VLC_USE_NEW_STATIC 4
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
541 void free_vlc(VLC *vlc);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
542
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
543 #define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
544 {\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
545 static VLC_TYPE table[static_size][2];\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
546 (vlc)->table= table;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
547 (vlc)->table_allocated= static_size;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
548 init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
549 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
550
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
551
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
552 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
553 *
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
554 * if the vlc code is invalid and max_depth=1 than no bits will be removed
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
555 * if the vlc code is invalid and max_depth>1 than the number of bits removed
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
556 * is undefined
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
557 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
558 #define GET_VLC(code, name, gb, table, bits, max_depth)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
559 {\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
560 int n, index, nb_bits;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
561 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
562 index= SHOW_UBITS(name, gb, bits);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
563 code = table[index][0];\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
564 n = table[index][1];\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
565 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
566 if(max_depth > 1 && n < 0){\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
567 LAST_SKIP_BITS(name, gb, bits)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
568 UPDATE_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
569 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
570 nb_bits = -n;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
571 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
572 index= SHOW_UBITS(name, gb, nb_bits) + code;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
573 code = table[index][0];\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
574 n = table[index][1];\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
575 if(max_depth > 2 && n < 0){\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
576 LAST_SKIP_BITS(name, gb, nb_bits)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
577 UPDATE_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
578 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
579 nb_bits = -n;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
580 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
581 index= SHOW_UBITS(name, gb, nb_bits) + code;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
582 code = table[index][0];\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
583 n = table[index][1];\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
584 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
585 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
586 SKIP_BITS(name, gb, n)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
587 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
588
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
589 #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
590 {\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
591 int n, index, nb_bits;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
592 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
593 index= SHOW_UBITS(name, gb, bits);\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
594 level = table[index].level;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
595 n = table[index].len;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
596 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
597 if(max_depth > 1 && n < 0){\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
598 SKIP_BITS(name, gb, bits)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
599 if(need_update){\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
600 UPDATE_CACHE(name, gb)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
601 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
602 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
603 nb_bits = -n;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
604 \
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
605 index= SHOW_UBITS(name, gb, nb_bits) + level;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
606 level = table[index].level;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
607 n = table[index].len;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
608 }\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
609 run= table[index].run;\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
610 SKIP_BITS(name, gb, n)\
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
611 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
612
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
613
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
614 /**
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
615 * parses a vlc code, faster then get_vlc()
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
616 * @param bits is the number of bits which will be read at once, must be
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
617 * identical to nb_bits in init_vlc()
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
618 * @param max_depth is the number of times bits bits must be read to completely
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
619 * read the longest vlc code
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
620 * = (max_vlc_length + bits - 1) / bits
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
621 */
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
622 static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
623 int bits, int max_depth)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
624 {
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
625 int code;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
626
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
627 OPEN_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
628 UPDATE_CACHE(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
629
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
630 GET_VLC(code, re, s, table, bits, max_depth)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
631
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
632 CLOSE_READER(re, s)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
633 return code;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
634 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
635
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
636 //#define TRACE
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
637
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
638 #ifdef TRACE
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
639 static inline void print_bin(int bits, int n){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
640 int i;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
641
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
642 for(i=n-1; i>=0; i--){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
643 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
644 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
645 for(i=n; i<24; i++)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
646 av_log(NULL, AV_LOG_DEBUG, " ");
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
647 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
648
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
649 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
650 int r= get_bits(s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
651
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
652 print_bin(r, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
653 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
654 return r;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
655 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
656 static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
657 int show= show_bits(s, 24);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
658 int pos= get_bits_count(s);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
659 int r= get_vlc2(s, table, bits, max_depth);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
660 int len= get_bits_count(s) - pos;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
661 int bits2= show>>(24-len);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
662
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
663 print_bin(bits2, len);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
664
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
665 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
666 return r;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
667 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
668 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
669 int show= show_bits(s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
670 int r= get_xbits(s, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
671
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
672 print_bin(show, n);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
673 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
674 return r;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
675 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
676
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
677 #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
678 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
679 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
680 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
681 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
682
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
683 #define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
684
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
685 #else //TRACE
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
686 #define tprintf(p, ...) {}
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
687 #endif
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
688
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
689 static inline int decode012(GetBitContext *gb){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
690 int n;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
691 n = get_bits1(gb);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
692 if (n == 0)
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
693 return 0;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
694 else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
695 return get_bits1(gb) + 1;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
696 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
697
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
698 static inline int decode210(GetBitContext *gb){
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
699 if (get_bits1(gb))
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
700 return 0;
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
701 else
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
702 return 2 - get_bits1(gb);
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
703 }
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
704
10504
9f16f997c41b Make get_bits_left() available for use in libavcodec (was previously held
rbultje
parents: 10501
diff changeset
705 static inline int get_bits_left(GetBitContext *gb)
9f16f997c41b Make get_bits_left() available for use in libavcodec (was previously held
rbultje
parents: 10501
diff changeset
706 {
9f16f997c41b Make get_bits_left() available for use in libavcodec (was previously held
rbultje
parents: 10501
diff changeset
707 return gb->size_in_bits - get_bits_count(gb);
9f16f997c41b Make get_bits_left() available for use in libavcodec (was previously held
rbultje
parents: 10501
diff changeset
708 }
9f16f997c41b Make get_bits_left() available for use in libavcodec (was previously held
rbultje
parents: 10501
diff changeset
709
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents:
diff changeset
710 #endif /* AVCODEC_GET_BITS_H */