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

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

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