[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.10, Sun Jun 30 10:46:29 2002 UTC
# Line 41  Line 41 
41    *                                                                                                                                                        *    *                                                                                                                                                        *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44    *  26.03.2002 interlacing support - modified putvol/vopheaders paramters    *  28.06.2002 addded BitstreamNumBitsToByteAlign()                           *
45      *                    BitstreamShowBitsFromByteAlign()                        *
46      *  26.03.2002 interlacing support - modified putvol/vopheaders paramters     *
47    *  04.03.2002 putbits speedup (Isibaar)                                      *    *  04.03.2002 putbits speedup (Isibaar)                                      *
48    *  03.03.2002 merged BITREADER and BITWRITER (Isibaar)                       *    *  03.03.2002 merged BITREADER and BITWRITER (Isibaar)                       *
49    *      16.12.2001     inital version                                                     *    *      16.12.2001     inital version                                                     *
# Line 110  Line 112 
112  #define S_VOP   3  #define S_VOP   3
113  #define N_VOP   4  #define N_VOP   4
114    
115    // resync-specific
116    #define NUMBITS_VP_RESYNC_MARKER  17
117    #define RESYNC_MARKER 1
118    
119  typedef struct  
120  {  int
121          uint32_t bufa;  read_video_packet_header(Bitstream *bs, const int addbits, int * quant);
         uint32_t bufb;  
         uint32_t buf;  
         uint32_t pos;  
         uint32_t *tail;  
         uint32_t *start;  
         uint32_t length;  
 }  
 Bitstream;  
122    
123    
124  // header stuff  // header stuff
125  int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding,  int BitstreamReadHeaders(Bitstream * bs,
126                                                   uint32_t * quant, uint32_t * fcode, uint32_t * intra_dc_threshold);                                                   DECODER * dec,
127                                                     uint32_t * rounding,
128                                                     uint32_t * quant,
129                                                     uint32_t * fcode_forward,
130                                                     uint32_t * fcode_backward,
131                                                     uint32_t * intra_dc_threshold);
132    
133    
134  void BitstreamWriteVolHeader(Bitstream * const bs,  void BitstreamWriteVolHeader(Bitstream * const bs,
135                                                  const MBParam * pParam);                                                           const MBParam * pParam,
136                                                             const FRAMEINFO * frame);
137    
138  void BitstreamWriteVopHeader(Bitstream * const bs,  void BitstreamWriteVopHeader(Bitstream * const bs,
139                                                  const MBParam * pParam);                                                           const MBParam * pParam,
140                                                             const FRAMEINFO * frame,
141                                                             int vop_coded);
142    
143    void BitstreamWriteUserData(Bitstream * const bs,
144                                                            uint8_t * data,
145                                                            const int length);
146    
147  /* initialise bitstream structure */  /* initialise bitstream structure */
148    
149  static void __inline BitstreamInit(Bitstream * const bs,  static void __inline
150    BitstreamInit(Bitstream * const bs,
151                                                                     void * const bitstream,                                                                     void * const bitstream,
152                                                                     uint32_t length)                                                                     uint32_t length)
153  {  {
# Line 167  Line 175 
175    
176  /* reset bitstream state */  /* reset bitstream state */
177    
178  static void __inline BitstreamReset(Bitstream * const bs)  static void __inline
179    BitstreamReset(Bitstream * const bs)
180  {  {
181          uint32_t tmp;          uint32_t tmp;
182    
# Line 192  Line 201 
201    
202  /* reads n bits from bitstream without changing the stream pos */  /* reads n bits from bitstream without changing the stream pos */
203    
204  static uint32_t __inline BitstreamShowBits(Bitstream * const bs,  static uint32_t __inline
205    BitstreamShowBits(Bitstream * const bs,
206                                                                                     const uint32_t bits)                                                                                     const uint32_t bits)
207  {  {
208          int nbit = (bits + bs->pos) - 32;          int nbit = (bits + bs->pos) - 32;
209          if (nbit > 0)  
210          {          if (nbit > 0) {
211                  return ((bs->bufa & (0xffffffff >> bs->pos)) << nbit) |                  return ((bs->bufa & (0xffffffff >> bs->pos)) << nbit) | (bs->
212                                  (bs->bufb >> (32 - nbit));                                                                                                                                   bufb >> (32 -
213          }                                                                                                                                                    nbit));
214          else          } else {
         {  
215                  return (bs->bufa & (0xffffffff >> bs->pos)) >> (32 - bs->pos - bits);                  return (bs->bufa & (0xffffffff >> bs->pos)) >> (32 - bs->pos - bits);
216          }          }
217  }  }
# Line 210  Line 219 
219    
220  /* skip n bits forward in bitstream */  /* skip n bits forward in bitstream */
221    
222  static __inline void BitstreamSkip(Bitstream * const bs, const uint32_t bits)  static __inline void
223    BitstreamSkip(Bitstream * const bs,
224                              const uint32_t bits)
225  {  {
226          bs->pos += bits;          bs->pos += bits;
227    
228          if (bs->pos >= 32)          if (bs->pos >= 32) {
         {  
229                  uint32_t tmp;                  uint32_t tmp;
230    
231                  bs->bufa = bs->bufb;                  bs->bufa = bs->bufb;
# Line 230  Line 240 
240  }  }
241    
242    
243    // number of bits to next byte alignment
244    static __inline uint32_t
245    BitstreamNumBitsToByteAlign(Bitstream *bs)
246    {
247            uint32_t n = (32 - bs->pos) % 8;
248            return n == 0 ? 8 : n;
249    }
250    
251    
252    // show nbits from next byte alignment
253    static __inline uint32_t
254    BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)
255    {
256            int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);
257            int nbit = (bits + bspos) - 32;
258    
259            if (bspos >= 32) {
260                    return bs->bufb >> (32 - nbit);
261            } else  if (nbit > 0) {
262                    return ((bs->bufa & (0xffffffff >> bspos)) << nbit) | (bs->
263                                                                                                                                     bufb >> (32 -
264                                                                                                                                                      nbit));
265            } else {
266                    return (bs->bufa & (0xffffffff >> bspos)) >> (32 - bspos - bits);
267            }
268    
269    }
270    
271    
272    
273  /* move forward to the next byte boundary */  /* move forward to the next byte boundary */
274    
275  static __inline void BitstreamByteAlign(Bitstream * const bs)  static __inline void
276    BitstreamByteAlign(Bitstream * const bs)
277  {  {
278          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
279          if (remainder)  
280          {          if (remainder) {
281                  BitstreamSkip(bs, 8 - remainder);                  BitstreamSkip(bs, 8 - remainder);
282          }          }
283  }  }
# Line 244  Line 285 
285    
286  /* bitstream length (unit bits) */  /* bitstream length (unit bits) */
287    
288  static uint32_t __inline BitstreamPos(const Bitstream * const bs)  static uint32_t __inline
289    BitstreamPos(const Bitstream * const bs)
290  {  {
291      return 8 * ((uint32_t)bs->tail - (uint32_t)bs->start) + bs->pos;          return 8 * ((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos;
292  }  }
293    
294    
# Line 254  Line 296 
296          NOTE: assumes no futher bitstream functions will be called.          NOTE: assumes no futher bitstream functions will be called.
297   */   */
298    
299  static uint32_t __inline BitstreamLength(Bitstream * const bs)  static uint32_t __inline
300    BitstreamLength(Bitstream * const bs)
301  {  {
302          uint32_t len = (uint32_t) bs->tail - (uint32_t) bs->start;          uint32_t len = (ptr_t) bs->tail - (ptr_t) bs->start;
303    
304      if (bs->pos)          if (bs->pos) {
     {  
305                  uint32_t b = bs->buf;                  uint32_t b = bs->buf;
306    
307  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
308                  BSWAP(b);                  BSWAP(b);
309  #endif  #endif
# Line 275  Line 318 
318    
319  /* 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 */
320    
321  static void __inline BitstreamForward(Bitstream * const bs, const uint32_t bits)  static void __inline
322    BitstreamForward(Bitstream * const bs,
323                                     const uint32_t bits)
324  {  {
325      bs->pos += bits;      bs->pos += bits;
326    
327      if (bs->pos >= 32)          if (bs->pos >= 32) {
     {  
328                  uint32_t b = bs->buf;                  uint32_t b = bs->buf;
329    
330  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
331                  BSWAP(b);                  BSWAP(b);
332  #endif  #endif
# Line 294  Line 339 
339    
340  /* pad bitstream to the next byte boundary */  /* pad bitstream to the next byte boundary */
341    
342  static void __inline BitstreamPad(Bitstream * const bs)  static void __inline
343    BitstreamPad(Bitstream * const bs)
344  {  {
345          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
346    
347      if (remainder)          if (remainder) {
     {  
348                  BitstreamForward(bs, 8 - remainder);                  BitstreamForward(bs, 8 - remainder);
349      }      }
350  }  }
# Line 307  Line 352 
352    
353  /* read n bits from bitstream */  /* read n bits from bitstream */
354    
355  static uint32_t __inline BitstreamGetBits(Bitstream * const bs,  static uint32_t __inline
356    BitstreamGetBits(Bitstream * const bs,
357                                                                                    const uint32_t n)                                                                                    const uint32_t n)
358  {  {
359          uint32_t ret = BitstreamShowBits(bs, n);          uint32_t ret = BitstreamShowBits(bs, n);
360    
361          BitstreamSkip(bs, n);          BitstreamSkip(bs, n);
362          return ret;          return ret;
363  }  }
# Line 318  Line 365 
365    
366  /* read single bit from bitstream */  /* read single bit from bitstream */
367    
368  static uint32_t __inline BitstreamGetBit(Bitstream * const bs)  static uint32_t __inline
369    BitstreamGetBit(Bitstream * const bs)
370  {  {
371          return BitstreamGetBits(bs, 1);          return BitstreamGetBits(bs, 1);
372  }  }
# Line 326  Line 374 
374    
375  /* write single bit to bitstream */  /* write single bit to bitstream */
376    
377  static void __inline BitstreamPutBit(Bitstream * const bs,  static void __inline
378    BitstreamPutBit(Bitstream * const bs,
379                                                                          const uint32_t bit)                                                                          const uint32_t bit)
380  {  {
381      if (bit)      if (bit)
# Line 338  Line 387 
387    
388  /* write n bits to bitstream */  /* write n bits to bitstream */
389    
390  static void __inline BitstreamPutBits(Bitstream * const bs,  static void __inline
391    BitstreamPutBits(Bitstream * const bs,
392                                                                          const uint32_t value,                                                                          const uint32_t value,
393                                                                          const uint32_t size)                                                                          const uint32_t size)
394  {  {

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

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