[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.11, Tue Sep 10 22:25:23 2002 UTC revision 1.17, Sat Feb 15 15:22:18 2003 UTC
# Line 1  Line 1 
1  /*****************************************************************************   /******************************************************************************
2   *    *                                                                            *
3   *  XVID MPEG-4 VIDEO CODEC    *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *
4   *  - Bitstream reader/writer inlined functions and constants-    *                                                                            *
5   *    *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *
6   *  Copyright (C) 2001-2002 - Peter Ross <pross@cs.rmit.edu.au>    *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
7   *    *  software module in hardware or software products are advised that its     *
8   *  This program is an implementation of a part of one or more MPEG-4    *  use may infringe existing patents or copyrights, and any such use         *
9   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending    *  would be at such party's own risk.  The original developer of this        *
10   *  to use this software module in hardware or software products are    *  software module and his/her company, and subsequent editors and their     *
11   *  advised that its use may infringe existing patents or copyrights, and    *  companies, will have no liability for use of this software or             *
12   *  any such use would be at such party's own risk.  The original    *  modifications or derivatives thereof.                                     *
13   *  developer of this software module and his/her company, and subsequent    *                                                                            *
14   *  editors and their companies, will have no liability for use of this    *  XviD is free software; you can redistribute it and/or modify it           *
15   *  software or modifications or derivatives thereof.    *  under the terms of the GNU General Public License as published by         *
16   *    *  the Free Software Foundation; either version 2 of the License, or         *
17   *  This program is free software ; you can redistribute it and/or modify    *  (at your option) any later version.                                       *
18   *  it under the terms of the GNU General Public License as published by    *                                                                            *
19   *  the Free Software Foundation ; either version 2 of the License, or    *  XviD is distributed in the hope that it will be useful, but               *
20   *  (at your option) any later version.    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *
21   *    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
22   *  This program is distributed in the hope that it will be useful,    *  GNU General Public License for more details.                              *
23   *  but WITHOUT ANY WARRANTY ; without even the implied warranty of    *                                                                            *
24   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *  You should have received a copy of the GNU General Public License         *
25   *  GNU General Public License for more details.    *  along with this program; if not, write to the Free Software               *
26   *    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
27   *  You should have received a copy of the GNU General Public License    *                                                                            *
28   *  along with this program ; if not, write to the Free Software    ******************************************************************************/
29   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  
30   *   /******************************************************************************
31   * $Id$    *                                                                            *
32   *    *  bitstream.h                                                               *
33   ****************************************************************************/    *                                                                            *
34      *  Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au>                    *
35      *                                                                            *
36      *  For more information visit the XviD homepage: http://www.xvid.org         *
37      *                                                                            *
38      ******************************************************************************/
39    
40     /******************************************************************************
41      *                                                                                                                                                        *
42      *  Revision history:                                                         *
43      *                                                                            *
44      *  28.06.2002 addded BitstreamNumBitsToByteAlign()                           *
45      *                    BitstreamShowBitsFromByteAlign()                        *
46      *  26.03.2002 interlacing support - modified putvol/vopheaders paramters     *
47      *  04.03.2002 putbits speedup (Isibaar)                                      *
48      *  03.03.2002 merged BITREADER and BITWRITER (Isibaar)                       *
49      *      16.12.2001     inital version                                                     *
50      *                                                                                                                                                        *
51      ******************************************************************************/
52    
53  #ifndef _BITSTREAM_H_  #ifndef _BITSTREAM_H_
54  #define _BITSTREAM_H_  #define _BITSTREAM_H_
# Line 39  Line 57 
57  #include "../decoder.h"  #include "../decoder.h"
58  #include "../encoder.h"  #include "../encoder.h"
59    
   
 /*****************************************************************************  
  * Constants  
  ****************************************************************************/  
   
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 54  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 69  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 84  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 104  Line 131 
131  #define RESYNC_MARKER 1  #define RESYNC_MARKER 1
132    
133    
134  /*****************************************************************************  int read_video_packet_header(Bitstream *bs,
135   * Prototypes                                                  DECODER * dec,
136   ****************************************************************************/                                                  const int addbits,
137                                                    int * quant,
138  int                                                  int * fcode_forward,
139  read_video_packet_header(Bitstream *bs, const int addbits, int * quant);                                                  int  * fcode_backward,
140                                                    int * intra_dc_threshold);
141    
142    
143  // header stuff  // header stuff
144  int BitstreamReadHeaders(Bitstream * bs,  int BitstreamReadHeaders(Bitstream * bs,
145                                                   DECODER * dec,                                                   DECODER * dec,
146                                                   uint32_t * rounding,                                                   uint32_t * rounding,
147                                                     uint32_t * reduced_resolution,
148                                                   uint32_t * quant,                                                   uint32_t * quant,
149                                                   uint32_t * fcode_forward,                                                   uint32_t * fcode_forward,
150                                                   uint32_t * fcode_backward,                                                   uint32_t * fcode_backward,
151                                                   uint32_t * intra_dc_threshold);                                                   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 * frame);                                                           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 * frame,                                                           const FRAMEINFO * const frame,
162                                                           int vop_coded);                                                           int vop_coded);
163    
164  void BitstreamWriteUserData(Bitstream * const bs,  void BitstreamWriteUserData(Bitstream * const bs,
165                                                          uint8_t * data,                                                          uint8_t * data,
166                                                          const int length);                                                          const int length);
167    
 /*****************************************************************************  
  * Inlined functions  
  ****************************************************************************/  
   
168  /* initialise bitstream structure */  /* initialise bitstream structure */
169    
170  static void __inline  static void __inline
# Line 214  Line 240 
240    
241  /* skip n bits forward in bitstream */  /* skip n bits forward in bitstream */
242    
243  static void __inline  static __inline void
244  BitstreamSkip(Bitstream * const bs,  BitstreamSkip(Bitstream * const bs,
245                            const uint32_t bits)                            const uint32_t bits)
246  {  {
# Line 236  Line 262 
262    
263    
264  // number of bits to next byte alignment  // number of bits to next byte alignment
265  static uint32_t __inline  static __inline uint32_t
266  BitstreamNumBitsToByteAlign(Bitstream *bs)  BitstreamNumBitsToByteAlign(Bitstream *bs)
267  {  {
268          uint32_t n = (32 - bs->pos) % 8;          uint32_t n = (32 - bs->pos) % 8;
# Line 245  Line 271 
271    
272    
273  // show nbits from next byte alignment  // show nbits from next byte alignment
274  static uint32_t __inline  static __inline uint32_t
275  BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)  BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)
276  {  {
277          int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);          int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);
# Line 267  Line 293 
293    
294  /* move forward to the next byte boundary */  /* move forward to the next byte boundary */
295    
296  static void __inline  static __inline void
297  BitstreamByteAlign(Bitstream * const bs)  BitstreamByteAlign(Bitstream * const bs)
298  {  {
299          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
# Line 332  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  static uint32_t __inline
# Line 407  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.11  
changed lines
  Added in v.1.17

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