Mercurial > libavcodec.hg
comparison common.c @ 1875:45a1592dadca libavcodec
* moving some of the commonly used bit reading/writing functions
from common.c -> common.h so that they can be inlined.
+ performace gain ~1% (measured with DV decoding)
+ code bloat 0.05%
Looks like a win-win solution.
author | romansh |
---|---|
date | Fri, 12 Mar 2004 23:39:38 +0000 |
parents | 920e6381e1fe |
children | 7b345b735ac7 |
comparison
equal
deleted
inserted
replaced
1874:fab737b59790 | 1875:45a1592dadca |
---|---|
43 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | 43 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
44 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | 44 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
45 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 | 45 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
46 }; | 46 }; |
47 | 47 |
48 void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) | |
49 { | |
50 s->buf = buffer; | |
51 s->buf_end = s->buf + buffer_size; | |
52 #ifdef ALT_BITSTREAM_WRITER | |
53 s->index=0; | |
54 ((uint32_t*)(s->buf))[0]=0; | |
55 // memset(buffer, 0, buffer_size); | |
56 #else | |
57 s->buf_ptr = s->buf; | |
58 s->bit_left=32; | |
59 s->bit_buf=0; | |
60 #endif | |
61 } | |
62 | |
63 //#ifdef CONFIG_ENCODERS | |
64 #if 1 | |
65 | |
66 /* return the number of bits output */ | |
67 int put_bits_count(PutBitContext *s) | |
68 { | |
69 #ifdef ALT_BITSTREAM_WRITER | |
70 return s->index; | |
71 #else | |
72 return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; | |
73 #endif | |
74 } | |
75 | |
76 void align_put_bits(PutBitContext *s) | 48 void align_put_bits(PutBitContext *s) |
77 { | 49 { |
78 #ifdef ALT_BITSTREAM_WRITER | 50 #ifdef ALT_BITSTREAM_WRITER |
79 put_bits(s,( - s->index) & 7,0); | 51 put_bits(s,( - s->index) & 7,0); |
80 #else | 52 #else |
81 put_bits(s,s->bit_left & 7,0); | 53 put_bits(s,s->bit_left & 7,0); |
82 #endif | 54 #endif |
83 } | 55 } |
84 | 56 |
85 #endif //CONFIG_ENCODERS | |
86 | |
87 /* pad the end of the output stream with zeros */ | |
88 void flush_put_bits(PutBitContext *s) | |
89 { | |
90 #ifdef ALT_BITSTREAM_WRITER | |
91 align_put_bits(s); | |
92 #else | |
93 s->bit_buf<<= s->bit_left; | |
94 while (s->bit_left < 32) { | |
95 /* XXX: should test end of buffer */ | |
96 *s->buf_ptr++=s->bit_buf >> 24; | |
97 s->bit_buf<<=8; | |
98 s->bit_left+=8; | |
99 } | |
100 s->bit_left=32; | |
101 s->bit_buf=0; | |
102 #endif | |
103 } | |
104 | |
105 #ifdef CONFIG_ENCODERS | |
106 | |
107 void put_string(PutBitContext * pbc, char *s, int put_zero) | 57 void put_string(PutBitContext * pbc, char *s, int put_zero) |
108 { | 58 { |
109 while(*s){ | 59 while(*s){ |
110 put_bits(pbc, 8, *s); | 60 put_bits(pbc, 8, *s); |
111 s++; | 61 s++; |
113 if(put_zero) | 63 if(put_zero) |
114 put_bits(pbc, 8, 0); | 64 put_bits(pbc, 8, 0); |
115 } | 65 } |
116 | 66 |
117 /* bit input functions */ | 67 /* bit input functions */ |
118 | |
119 #endif //CONFIG_ENCODERS | |
120 | |
121 /** | |
122 * init GetBitContext. | |
123 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits | |
124 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end | |
125 * @param bit_size the size of the buffer in bits | |
126 */ | |
127 void init_get_bits(GetBitContext *s, | |
128 const uint8_t *buffer, int bit_size) | |
129 { | |
130 const int buffer_size= (bit_size+7)>>3; | |
131 | |
132 s->buffer= buffer; | |
133 s->size_in_bits= bit_size; | |
134 s->buffer_end= buffer + buffer_size; | |
135 #ifdef ALT_BITSTREAM_READER | |
136 s->index=0; | |
137 #elif defined LIBMPEG2_BITSTREAM_READER | |
138 #ifdef LIBMPEG2_BITSTREAM_READER_HACK | |
139 if ((int)buffer&1) { | |
140 /* word alignment */ | |
141 s->cache = (*buffer++)<<24; | |
142 s->buffer_ptr = buffer; | |
143 s->bit_count = 16-8; | |
144 } else | |
145 #endif | |
146 { | |
147 s->buffer_ptr = buffer; | |
148 s->bit_count = 16; | |
149 s->cache = 0; | |
150 } | |
151 #elif defined A32_BITSTREAM_READER | |
152 s->buffer_ptr = (uint32_t*)buffer; | |
153 s->bit_count = 32; | |
154 s->cache0 = 0; | |
155 s->cache1 = 0; | |
156 #endif | |
157 { | |
158 OPEN_READER(re, s) | |
159 UPDATE_CACHE(re, s) | |
160 UPDATE_CACHE(re, s) | |
161 CLOSE_READER(re, s) | |
162 } | |
163 #ifdef A32_BITSTREAM_READER | |
164 s->cache1 = 0; | |
165 #endif | |
166 } | |
167 | 68 |
168 /** | 69 /** |
169 * reads 0-32 bits. | 70 * reads 0-32 bits. |
170 */ | 71 */ |
171 unsigned int get_bits_long(GetBitContext *s, int n){ | 72 unsigned int get_bits_long(GetBitContext *s, int n){ |