[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.4, Thu Apr 25 06:55:00 2002 UTC revision 1.10.2.3, Thu Nov 7 10:28:15 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 80  Line 82 
82  //#define VIDOBJLAY_TYPE_SIMPLE_SCALABLE        2  //#define VIDOBJLAY_TYPE_SIMPLE_SCALABLE        2
83  #define VIDOBJLAY_TYPE_CORE                             3  #define VIDOBJLAY_TYPE_CORE                             3
84  #define VIDOBJLAY_TYPE_MAIN                             4  #define VIDOBJLAY_TYPE_MAIN                             4
85    //#define VIDOBJLAY_TYPE_NBIT                           5
86    //#define VIDOBJLAY_TYPE_ANIM_TEXT                      6
87    //#define VIDOBJLAY_TYPE_ANIM_MESH                      7
88    //#define VIDOBJLAY_TYPE_SIMPLE_FACE            8
89    //#define VIDOBJLAY_TYPE_STILL_SCALABLE         9
90    #define VIDOBJLAY_TYPE_ART_SIMPLE               10
91    //#define VIDOBJLAY_TYPE_CORE_SCALABLE          11
92    #define VIDOBJLAY_TYPE_ACE                              12
93    //#define VIDOBJLAY_TYPE_SIMPLE_FBA                     13
94    
95    
96  //#define VIDOBJLAY_AR_SQUARE                   1  //#define VIDOBJLAY_AR_SQUARE                   1
# Line 95  Line 106 
106  #define VIDOBJLAY_SHAPE_BINARY_ONLY             2  #define VIDOBJLAY_SHAPE_BINARY_ONLY             2
107  #define VIDOBJLAY_SHAPE_GRAYSCALE               3  #define VIDOBJLAY_SHAPE_GRAYSCALE               3
108    
109    
110    #define SPRITE_NONE             0
111    #define SPRITE_STATIC   1
112    #define SPRITE_GMC              2
113    
114    
115  #define VO_START_CODE   0x8  #define VO_START_CODE   0x8
116  #define VOL_START_CODE  0x12  #define VOL_START_CODE  0x12
117  #define VOP_START_CODE  0x1b6  #define VOP_START_CODE  0x1b6
# Line 110  Line 127 
127  #define S_VOP   3  #define S_VOP   3
128  #define N_VOP   4  #define N_VOP   4
129    
130    // resync-specific
131    #define NUMBITS_VP_RESYNC_MARKER  17
132    #define RESYNC_MARKER 1
133    
134    
135    int read_video_packet_header(Bitstream *bs,
136                                                    DECODER * dec,
137                                                    const int addbits,
138                                                    int * quant,
139                                                    int * fcode_forward,
140                                                    int  * fcode_backward,
141                                                    int * intra_dc_threshold);
142    
143    
144  // header stuff  // header stuff
145  int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding,  int BitstreamReadHeaders(Bitstream * bs,
146                                                   uint32_t * quant, uint32_t * fcode, uint32_t * intra_dc_threshold);                                                   DECODER * dec,
147                                                     uint32_t * rounding,
148                                                     uint32_t * reduced_resolution,
149                                                     uint32_t * quant,
150                                                     uint32_t * fcode_forward,
151                                                     uint32_t * fcode_backward,
152                                                     uint32_t * intra_dc_threshold,
153                                                     VECTOR * gmc_mv);
154    
155    
156  void BitstreamWriteVolHeader(Bitstream * const bs,  void BitstreamWriteVolHeader(Bitstream * const bs,
157                                                  const MBParam * pParam,                                                  const MBParam * pParam,
158                                                  const FRAMEINFO * frame);                                                           const FRAMEINFO * const frame);
159    
160  void BitstreamWriteVopHeader(Bitstream * const bs,  void BitstreamWriteVopHeader(Bitstream * const bs,
161                                                  const MBParam * pParam,                                                  const MBParam * pParam,
162                                                  const FRAMEINFO * frame);                                                           const FRAMEINFO * const frame,
163                                                             int vop_coded);
164    
165    void BitstreamWriteUserData(Bitstream * const bs,
166                                                            uint8_t * data,
167                                                            const int length);
168    
169  /* initialise bitstream structure */  /* initialise bitstream structure */
170    
171  static void __inline BitstreamInit(Bitstream * const bs,  static void __inline
172    BitstreamInit(Bitstream * const bs,
173                                                                     void * const bitstream,                                                                     void * const bitstream,
174                                                                     uint32_t length)                                                                     uint32_t length)
175  {  {
# Line 154  Line 197 
197    
198  /* reset bitstream state */  /* reset bitstream state */
199    
200  static void __inline BitstreamReset(Bitstream * const bs)  static void __inline
201    BitstreamReset(Bitstream * const bs)
202  {  {
203          uint32_t tmp;          uint32_t tmp;
204    
# Line 179  Line 223 
223    
224  /* reads n bits from bitstream without changing the stream pos */  /* reads n bits from bitstream without changing the stream pos */
225    
226  static uint32_t __inline BitstreamShowBits(Bitstream * const bs,  static uint32_t __inline
227    BitstreamShowBits(Bitstream * const bs,
228                                                                                     const uint32_t bits)                                                                                     const uint32_t bits)
229  {  {
230          int nbit = (bits + bs->pos) - 32;          int nbit = (bits + bs->pos) - 32;
231          if (nbit > 0)  
232          {          if (nbit > 0) {
233                  return ((bs->bufa & (0xffffffff >> bs->pos)) << nbit) |                  return ((bs->bufa & (0xffffffff >> bs->pos)) << nbit) | (bs->
234                                  (bs->bufb >> (32 - nbit));                                                                                                                                   bufb >> (32 -
235          }                                                                                                                                                    nbit));
236          else          } else {
         {  
237                  return (bs->bufa & (0xffffffff >> bs->pos)) >> (32 - bs->pos - bits);                  return (bs->bufa & (0xffffffff >> bs->pos)) >> (32 - bs->pos - bits);
238          }          }
239  }  }
# Line 197  Line 241 
241    
242  /* skip n bits forward in bitstream */  /* skip n bits forward in bitstream */
243    
244  static __inline void BitstreamSkip(Bitstream * const bs, const uint32_t bits)  static __inline void
245    BitstreamSkip(Bitstream * const bs,
246                              const uint32_t bits)
247  {  {
248          bs->pos += bits;          bs->pos += bits;
249    
250          if (bs->pos >= 32)          if (bs->pos >= 32) {
         {  
251                  uint32_t tmp;                  uint32_t tmp;
252    
253                  bs->bufa = bs->bufb;                  bs->bufa = bs->bufb;
# Line 217  Line 262 
262  }  }
263    
264    
265    // number of bits to next byte alignment
266    static __inline uint32_t
267    BitstreamNumBitsToByteAlign(Bitstream *bs)
268    {
269            uint32_t n = (32 - bs->pos) % 8;
270            return n == 0 ? 8 : n;
271    }
272    
273    
274    // show nbits from next byte alignment
275    static __inline uint32_t
276    BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)
277    {
278            int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);
279            int nbit = (bits + bspos) - 32;
280    
281            if (bspos >= 32) {
282                    return bs->bufb >> (32 - nbit);
283            } else  if (nbit > 0) {
284                    return ((bs->bufa & (0xffffffff >> bspos)) << nbit) | (bs->
285                                                                                                                                     bufb >> (32 -
286                                                                                                                                                      nbit));
287            } else {
288                    return (bs->bufa & (0xffffffff >> bspos)) >> (32 - bspos - bits);
289            }
290    
291    }
292    
293    
294    
295  /* move forward to the next byte boundary */  /* move forward to the next byte boundary */
296    
297  static __inline void BitstreamByteAlign(Bitstream * const bs)  static __inline void
298    BitstreamByteAlign(Bitstream * const bs)
299  {  {
300          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
301          if (remainder)  
302          {          if (remainder) {
303                  BitstreamSkip(bs, 8 - remainder);                  BitstreamSkip(bs, 8 - remainder);
304          }          }
305  }  }
# Line 231  Line 307 
307    
308  /* bitstream length (unit bits) */  /* bitstream length (unit bits) */
309    
310  static uint32_t __inline BitstreamPos(const Bitstream * const bs)  static uint32_t __inline
311    BitstreamPos(const Bitstream * const bs)
312  {  {
313      return 8 * ((uint32_t)bs->tail - (uint32_t)bs->start) + bs->pos;          return 8 * ((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos;
314  }  }
315    
316    
# Line 241  Line 318 
318          NOTE: assumes no futher bitstream functions will be called.          NOTE: assumes no futher bitstream functions will be called.
319   */   */
320    
321  static uint32_t __inline BitstreamLength(Bitstream * const bs)  static uint32_t __inline
322    BitstreamLength(Bitstream * const bs)
323  {  {
324          uint32_t len = (uint32_t) bs->tail - (uint32_t) bs->start;          uint32_t len = (ptr_t) bs->tail - (ptr_t) bs->start;
325    
326      if (bs->pos)          if (bs->pos) {
     {  
327                  uint32_t b = bs->buf;                  uint32_t b = bs->buf;
328    
329  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
330                  BSWAP(b);                  BSWAP(b);
331  #endif  #endif
# Line 262  Line 340 
340    
341  /* 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 */
342    
343  static void __inline BitstreamForward(Bitstream * const bs, const uint32_t bits)  static void __inline
344    BitstreamForward(Bitstream * const bs,
345                                     const uint32_t bits)
346  {  {
347      bs->pos += bits;      bs->pos += bits;
348    
349      if (bs->pos >= 32)          if (bs->pos >= 32) {
     {  
350                  uint32_t b = bs->buf;                  uint32_t b = bs->buf;
351    
352  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
353                  BSWAP(b);                  BSWAP(b);
354  #endif  #endif
# Line 279  Line 359 
359  }  }
360    
361    
 /* pad bitstream to the next byte boundary */  
   
 static void __inline BitstreamPad(Bitstream * const bs)  
 {  
         uint32_t remainder = bs->pos % 8;  
   
     if (remainder)  
     {  
                 BitstreamForward(bs, 8 - remainder);  
     }  
 }  
   
   
362  /* read n bits from bitstream */  /* read n bits from bitstream */
363    
364  static uint32_t __inline BitstreamGetBits(Bitstream * const bs,  static uint32_t __inline
365    BitstreamGetBits(Bitstream * const bs,
366                                                                                    const uint32_t n)                                                                                    const uint32_t n)
367  {  {
368          uint32_t ret = BitstreamShowBits(bs, n);          uint32_t ret = BitstreamShowBits(bs, n);
369    
370          BitstreamSkip(bs, n);          BitstreamSkip(bs, n);
371          return ret;          return ret;
372  }  }
# Line 305  Line 374 
374    
375  /* read single bit from bitstream */  /* read single bit from bitstream */
376    
377  static uint32_t __inline BitstreamGetBit(Bitstream * const bs)  static uint32_t __inline
378    BitstreamGetBit(Bitstream * const bs)
379  {  {
380          return BitstreamGetBits(bs, 1);          return BitstreamGetBits(bs, 1);
381  }  }
# Line 313  Line 383 
383    
384  /* write single bit to bitstream */  /* write single bit to bitstream */
385    
386  static void __inline BitstreamPutBit(Bitstream * const bs,  static void __inline
387    BitstreamPutBit(Bitstream * const bs,
388                                                                          const uint32_t bit)                                                                          const uint32_t bit)
389  {  {
390      if (bit)      if (bit)
# Line 325  Line 396 
396    
397  /* write n bits to bitstream */  /* write n bits to bitstream */
398    
399  static void __inline BitstreamPutBits(Bitstream * const bs,  static void __inline
400    BitstreamPutBits(Bitstream * const bs,
401                                                                          const uint32_t value,                                                                          const uint32_t value,
402                                                                          const uint32_t size)                                                                          const uint32_t size)
403  {  {
# Line 349  Line 421 
421          }          }
422  }  }
423    
424    
425    static const int stuffing_codes[8] =
426    {
427                    /* nbits     stuffing code */
428            0,              /* 1          0 */
429            1,              /* 2          01 */
430            3,              /* 3          011 */
431            7,              /* 4          0111 */
432            0xf,    /* 5          01111 */
433            0x1f,   /* 6          011111 */
434            0x3f,   /* 7          0111111 */
435            0x7f,   /* 8          01111111 */
436    };
437    
438    /* pad bitstream to the next byte boundary */
439    
440    static void __inline
441    BitstreamPad(Bitstream * const bs)
442    {
443            int bits = 8 - (bs->pos % 8);
444            if (bits < 8)
445            {
446                    BitstreamPutBits(bs, stuffing_codes[bits - 1], bits);
447            }
448    }
449    
450    
451    /* pad bitstream to the next byte boundary
452       alway pad: even if currently at the byte boundary */
453    
454    static void __inline
455    BitstreamPadAlways(Bitstream * const bs)
456    {
457            int bits = 8 - (bs->pos % 8);
458            BitstreamPutBits(bs, stuffing_codes[bits - 1], bits);
459    }
460    
461    
462  #endif /* _BITSTREAM_H_ */  #endif /* _BITSTREAM_H_ */

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.10.2.3

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