[cvs] / xvidcore / src / bitstream / bitstream.h Repository:
ViewVC logotype

Diff of /xvidcore/src/bitstream/bitstream.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2, Tue Mar 26 11:16:08 2002 UTC revision 1.8, Thu Jun 20 14:05:58 2002 UTC
# Line 111  Line 111 
111  #define N_VOP   4  #define N_VOP   4
112    
113    
 typedef struct  
 {  
         uint32_t bufa;  
         uint32_t bufb;  
         uint32_t buf;  
         uint32_t pos;  
         uint32_t *tail;  
         uint32_t *start;  
         uint32_t length;  
 }  
 Bitstream;  
   
   
114  // header stuff  // header stuff
115  int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding,  int BitstreamReadHeaders(Bitstream * bs,
116                                                   uint32_t * quant, uint32_t * fcode, uint32_t * intra_dc_threshold);                                                   DECODER * dec,
117                                                     uint32_t * rounding,
118                                                     uint32_t * quant,
119                                                     uint32_t * fcode_forward,
120                                                     uint32_t * fcode_backward,
121                                                     uint32_t * intra_dc_threshold);
122    
123    
124  void BitstreamWriteVolHeader(Bitstream * const bs,  void BitstreamWriteVolHeader(Bitstream * const bs,
125                                                  const MBParam * pParam);                                                           const MBParam * pParam,
126                                                             const FRAMEINFO * frame);
127    
128  void BitstreamWriteVopHeader(Bitstream * const bs,  void BitstreamWriteVopHeader(Bitstream * const bs,
129                                                  const MBParam * pParam);                                                           const MBParam * pParam,
130                                                             const FRAMEINFO * frame,
131                                                             int vop_coded);
132    
133    void BitstreamWriteUserData(Bitstream * const bs,
134                                                            uint8_t * data,
135                                                            const int length);
136    
137  /* initialise bitstream structure */  /* initialise bitstream structure */
138    
139  static void __inline BitstreamInit(Bitstream * const bs,  static void __inline
140    BitstreamInit(Bitstream * const bs,
141                                                                     void * const bitstream,                                                                     void * const bitstream,
142                                                                     uint32_t length)                                                                     uint32_t length)
143  {  {
# Line 167  Line 165 
165    
166  /* reset bitstream state */  /* reset bitstream state */
167    
168  static void __inline BitstreamReset(Bitstream * const bs)  static void __inline
169    BitstreamReset(Bitstream * const bs)
170  {  {
171          uint32_t tmp;          uint32_t tmp;
172    
# Line 192  Line 191 
191    
192  /* reads n bits from bitstream without changing the stream pos */  /* reads n bits from bitstream without changing the stream pos */
193    
194  static uint32_t __inline BitstreamShowBits(Bitstream * const bs,  static uint32_t __inline
195    BitstreamShowBits(Bitstream * const bs,
196                                                                                     const uint32_t bits)                                                                                     const uint32_t bits)
197  {  {
198          int nbit = (bits + bs->pos) - 32;          int nbit = (bits + bs->pos) - 32;
199          if (nbit > 0)  
200          {          if (nbit > 0) {
201                  return ((bs->bufa & (0xffffffff >> bs->pos)) << nbit) |                  return ((bs->bufa & (0xffffffff >> bs->pos)) << nbit) | (bs->
202                                  (bs->bufb >> (32 - nbit));                                                                                                                                   bufb >> (32 -
203          }                                                                                                                                                    nbit));
204          else          } else {
         {  
205                  return (bs->bufa & (0xffffffff >> bs->pos)) >> (32 - bs->pos - bits);                  return (bs->bufa & (0xffffffff >> bs->pos)) >> (32 - bs->pos - bits);
206          }          }
207  }  }
# Line 210  Line 209 
209    
210  /* skip n bits forward in bitstream */  /* skip n bits forward in bitstream */
211    
212  static __inline void BitstreamSkip(Bitstream * const bs, const uint32_t bits)  static __inline void
213    BitstreamSkip(Bitstream * const bs,
214                              const uint32_t bits)
215  {  {
216          bs->pos += bits;          bs->pos += bits;
217    
218          if (bs->pos >= 32)          if (bs->pos >= 32) {
         {  
219                  uint32_t tmp;                  uint32_t tmp;
220    
221                  bs->bufa = bs->bufb;                  bs->bufa = bs->bufb;
# Line 232  Line 232 
232    
233  /* move forward to the next byte boundary */  /* move forward to the next byte boundary */
234    
235  static __inline void BitstreamByteAlign(Bitstream * const bs)  static __inline void
236    BitstreamByteAlign(Bitstream * const bs)
237  {  {
238          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
239          if (remainder)  
240          {          if (remainder) {
241                  BitstreamSkip(bs, 8 - remainder);                  BitstreamSkip(bs, 8 - remainder);
242          }          }
243  }  }
# Line 244  Line 245 
245    
246  /* bitstream length (unit bits) */  /* bitstream length (unit bits) */
247    
248  static uint32_t __inline BitstreamPos(const Bitstream * const bs)  static uint32_t __inline
249    BitstreamPos(const Bitstream * const bs)
250  {  {
251      return 8 * ((uint32_t)bs->tail - (uint32_t)bs->start) + bs->pos;          return 8 * ((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos;
252  }  }
253    
254    
# Line 254  Line 256 
256          NOTE: assumes no futher bitstream functions will be called.          NOTE: assumes no futher bitstream functions will be called.
257   */   */
258    
259  static uint32_t __inline BitstreamLength(Bitstream * const bs)  static uint32_t __inline
260    BitstreamLength(Bitstream * const bs)
261  {  {
262          uint32_t len = (uint32_t) bs->tail - (uint32_t) bs->start;          uint32_t len = (ptr_t) bs->tail - (ptr_t) bs->start;
263    
264      if (bs->pos)          if (bs->pos) {
     {  
265                  uint32_t b = bs->buf;                  uint32_t b = bs->buf;
266    
267  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
268                  BSWAP(b);                  BSWAP(b);
269  #endif  #endif
# Line 275  Line 278 
278    
279  /* move bitstream position forward by n bits and write out buffer if needed */  /* move bitstream position forward by n bits and write out buffer if needed */
280    
281  static void __inline BitstreamForward(Bitstream * const bs, const uint32_t bits)  static void __inline
282    BitstreamForward(Bitstream * const bs,
283                                     const uint32_t bits)
284  {  {
285      bs->pos += bits;      bs->pos += bits;
286    
287      if (bs->pos >= 32)          if (bs->pos >= 32) {
     {  
288                  uint32_t b = bs->buf;                  uint32_t b = bs->buf;
289    
290  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
291                  BSWAP(b);                  BSWAP(b);
292  #endif  #endif
# Line 294  Line 299 
299    
300  /* pad bitstream to the next byte boundary */  /* pad bitstream to the next byte boundary */
301    
302  static void __inline BitstreamPad(Bitstream * const bs)  static void __inline
303    BitstreamPad(Bitstream * const bs)
304  {  {
305          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
306    
307      if (remainder)          if (remainder) {
     {  
308                  BitstreamForward(bs, 8 - remainder);                  BitstreamForward(bs, 8 - remainder);
309      }      }
310  }  }
# Line 307  Line 312 
312    
313  /* read n bits from bitstream */  /* read n bits from bitstream */
314    
315  static uint32_t __inline BitstreamGetBits(Bitstream * const bs,  static uint32_t __inline
316    BitstreamGetBits(Bitstream * const bs,
317                                                                                    const uint32_t n)                                                                                    const uint32_t n)
318  {  {
319          uint32_t ret = BitstreamShowBits(bs, n);          uint32_t ret = BitstreamShowBits(bs, n);
320    
321          BitstreamSkip(bs, n);          BitstreamSkip(bs, n);
322          return ret;          return ret;
323  }  }
# Line 318  Line 325 
325    
326  /* read single bit from bitstream */  /* read single bit from bitstream */
327    
328  static uint32_t __inline BitstreamGetBit(Bitstream * const bs)  static uint32_t __inline
329    BitstreamGetBit(Bitstream * const bs)
330  {  {
331          return BitstreamGetBits(bs, 1);          return BitstreamGetBits(bs, 1);
332  }  }
# Line 326  Line 334 
334    
335  /* write single bit to bitstream */  /* write single bit to bitstream */
336    
337  static void __inline BitstreamPutBit(Bitstream * const bs,  static void __inline
338    BitstreamPutBit(Bitstream * const bs,
339                                                                          const uint32_t bit)                                                                          const uint32_t bit)
340  {  {
341      if (bit)      if (bit)
# Line 338  Line 347 
347    
348  /* write n bits to bitstream */  /* write n bits to bitstream */
349    
350  static void __inline BitstreamPutBits(Bitstream * const bs,  static void __inline
351    BitstreamPutBits(Bitstream * const bs,
352                                                                          const uint32_t value,                                                                          const uint32_t value,
353                                                                          const uint32_t size)                                                                          const uint32_t size)
354  {  {

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.8

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4