[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.16.2.2, Mon Jul 28 12:39:32 2003 UTC revision 1.17.2.1, Sat Feb 22 08:49:45 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@xvid.org>    *  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 file is part of XviD, a free MPEG-4 video encoder/decoder    *  use may infringe existing patents or copyrights, and any such use         *
9   *    *  would be at such party's own risk.  The original developer of this        *
10   *  XviD is free software; you can redistribute it and/or modify it    *  software module and his/her company, and subsequent editors and their     *
11   *  under the terms of the GNU General Public License as published by    *  companies, will have no liability for use of this software or             *
12   *  the Free Software Foundation; either version 2 of the License, or    *  modifications or derivatives thereof.                                     *
13   *  (at your option) any later version.    *                                                                            *
14   *    *  XviD is free software; you can redistribute it and/or modify it           *
15   *  This program is distributed in the hope that it will be useful,    *  under the terms of the GNU General Public License as published by         *
16   *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *  the Free Software Foundation; either version 2 of the License, or         *
17   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *  (at your option) any later version.                                       *
18   *  GNU General Public License for more details.    *                                                                            *
19   *    *  XviD is distributed in the hope that it will be useful, but               *
20   *  You should have received a copy of the GNU General Public License    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *
21   *  along with this program; if not, write to the Free Software    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA    *  GNU General Public License for more details.                              *
23   *    *                                                                            *
24   *  Under section 8 of the GNU General Public License, the copyright    *  You should have received a copy of the GNU General Public License         *
25   *  holders of XVID explicitly forbid distribution in the following    *  along with this program; if not, write to the Free Software               *
26   *  countries:    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
27   *    *                                                                            *
28   *    - Japan    ******************************************************************************/
29   *    - United States of America  
30   *   /******************************************************************************
31   *  Linking XviD statically or dynamically with other modules is making a    *                                                                            *
32   *  combined work based on XviD.  Thus, the terms and conditions of the    *  bitstream.h                                                               *
33   *  GNU General Public License cover the whole combination.    *                                                                            *
34   *    *  Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au>                    *
35   *  As a special exception, the copyright holders of XviD give you    *                                                                            *
36   *  permission to link XviD with independent modules that communicate with    *  For more information visit the XviD homepage: http://www.xvid.org         *
37   *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the    *                                                                            *
38   *  license terms of these independent modules, and to copy and distribute    ******************************************************************************/
39   *  the resulting combined work under terms of your choice, provided that  
40   *  every copy of the combined work is accompanied by a complete copy of   /******************************************************************************
41   *  the source code of XviD (the version of XviD used to produce the    *                                                                                                                                                        *
42   *  combined work), being distributed under the terms of the GNU General    *  Revision history:                                                         *
43   *  Public License plus this exception.  An independent module is a module    *                                                                            *
44   *  which is not derived from or based on XviD.    *  28.06.2002 addded BitstreamNumBitsToByteAlign()                           *
45   *    *                    BitstreamShowBitsFromByteAlign()                        *
46   *  Note that people who make modified versions of XviD are not obligated    *  26.03.2002 interlacing support - modified putvol/vopheaders paramters     *
47   *  to grant this special exception for their modified versions; it is    *  04.03.2002 putbits speedup (Isibaar)                                      *
48   *  their choice whether to do so.  The GNU General Public License gives    *  03.03.2002 merged BITREADER and BITWRITER (Isibaar)                       *
49   *  permission to release a modified version without this exception; this    *      16.12.2001     inital version                                                     *
50   *  exception also makes it possible to release a modified version which    *                                                                                                                                                        *
51   *  carries forward this exception.    ******************************************************************************/
  *  
  * $Id$  
  *  
  ****************************************************************************/  
52    
53  #ifndef _BITSTREAM_H_  #ifndef _BITSTREAM_H_
54  #define _BITSTREAM_H_  #define _BITSTREAM_H_
55    
 #include <stdio.h>  
   
56  #include "../portab.h"  #include "../portab.h"
57  #include "../decoder.h"  #include "../decoder.h"
58  #include "../encoder.h"  #include "../encoder.h"
59    
60    // comment any #defs we dont use
61    
62  /*****************************************************************************  /* start codes */
  * Constants  
  ****************************************************************************/  
   
 /* comment any #defs we dont use */  
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 */
# Line 76  Line 67 
67  #define VISOBJSEQ_STOP_CODE             0x000001b1      /* ??? */  #define VISOBJSEQ_STOP_CODE             0x000001b1      /* ??? */
68  #define USERDATA_START_CODE             0x000001b2  #define USERDATA_START_CODE             0x000001b2
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
77  /*#define VISOBJ_TYPE_STILLTEXTURE      2 */  //#define VISOBJ_TYPE_STILLTEXTURE      2
78  /*#define VISOBJ_TYPE_MESH              3 */  //#define VISOBJ_TYPE_MESH              3
79  /*#define VISOBJ_TYPE_FBA               4 */  //#define VISOBJ_TYPE_FBA               4
80  /*#define VISOBJ_TYPE_3DMESH            5 */  //#define VISOBJ_TYPE_3DMESH            5
81    
82    
83  #define VIDOBJLAY_TYPE_SIMPLE                   1  #define VIDOBJLAY_TYPE_SIMPLE                   1
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_AR_SQUARE           1 */  //#define VIDOBJLAY_TYPE_ANIM_MESH                      7
90  /*#define VIDOBJLAY_AR_625TYPE_43       2 */  //#define VIDOBJLAY_TYPE_SIMPLE_FACE            8
91  /*#define VIDOBJLAY_AR_525TYPE_43       3 */  //#define VIDOBJLAY_TYPE_STILL_SCALABLE         9
92  /*#define VIDOBJLAY_AR_625TYPE_169      8 */  #define VIDOBJLAY_TYPE_ART_SIMPLE               10
93  /*#define VIDOBJLAY_AR_525TYPE_169      9 */  //#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
99    //#define VIDOBJLAY_AR_625TYPE_43       2
100    //#define VIDOBJLAY_AR_525TYPE_43       3
101    //#define VIDOBJLAY_AR_625TYPE_169      8
102    //#define VIDOBJLAY_AR_525TYPE_169      9
103  #define VIDOBJLAY_AR_EXTPAR                             15  #define VIDOBJLAY_AR_EXTPAR                             15
104    
105    
# Line 108  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)
120    
121  /* vop coding types  */  // vop coding types
122  /* intra, prediction, backward, sprite, not_coded */  // intra, prediction, backward, sprite, not_coded
123  #define I_VOP   0  #define I_VOP   0
124  #define P_VOP   1  #define P_VOP   1
125  #define B_VOP   2  #define B_VOP   2
126  #define S_VOP   3  #define S_VOP   3
127  #define N_VOP   4  #define N_VOP   4
128    
129  /* resync-specific */  // resync-specific
130  #define NUMBITS_VP_RESYNC_MARKER  17  #define NUMBITS_VP_RESYNC_MARKER  17
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);
                                                          const FRAMEINFO * frame);  
157    
158  void BitstreamWriteVopHeader(Bitstream * const bs,  void BitstreamWriteVopHeader(Bitstream * const bs,
159                                                           const MBParam * pParam,                                                           const MBParam * pParam,
160                                                           const FRAMEINFO * frame,                                                           const FRAMEINFO * const frame,
161                                                           int vop_coded);                                                           int vop_coded);
162    
163  /*****************************************************************************  void BitstreamWriteUserData(Bitstream * const bs,
164   * Inlined functions                                                          uint8_t * data,
165   ****************************************************************************/                                                          const int length);
166    
167  /* initialise bitstream structure */  /* initialise bitstream structure */
168    
# Line 167  Line 172 
172                            uint32_t length)                            uint32_t length)
173  {  {
174          uint32_t tmp;          uint32_t tmp;
         size_t bitpos;  
         ptr_t adjbitstream = (ptr_t)bitstream;  
175    
176          /*          bs->start = bs->tail = (uint32_t *) bitstream;
          * Start the stream on a uint32_t boundary, by rounding down to the  
          * previous uint32_t and skipping the intervening bytes.  
          */  
         bitpos = ((sizeof(uint32_t)-1) & (size_t)bitstream);  
         adjbitstream = adjbitstream - bitpos;  
         bs->start = bs->tail = (uint32_t *) adjbitstream;  
177    
178          tmp = *bs->start;          tmp = *(uint32_t *) bitstream;
179  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
180          BSWAP(tmp);          BSWAP(tmp);
181  #endif  #endif
182          bs->bufa = tmp;          bs->bufa = tmp;
183    
184          tmp = *(bs->start + 1);          tmp = *((uint32_t *) bitstream + 1);
185  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
186          BSWAP(tmp);          BSWAP(tmp);
187  #endif  #endif
188          bs->bufb = tmp;          bs->bufb = tmp;
189    
190          bs->buf = 0;          bs->buf = 0;
191          bs->pos = bs->initpos = bitpos*8;          bs->pos = 0;
192          bs->length = length;          bs->length = length;
193  }  }
194    
# Line 218  Line 215 
215          bs->bufb = tmp;          bs->bufb = tmp;
216    
217          bs->buf = 0;          bs->buf = 0;
218          bs->pos = bs->initpos;          bs->pos = 0;
219  }  }
220    
221    
# Line 242  Line 239 
239    
240  /* skip n bits forward in bitstream */  /* skip n bits forward in bitstream */
241    
242  static void __inline  static __inline void
243  BitstreamSkip(Bitstream * const bs,  BitstreamSkip(Bitstream * const bs,
244                            const uint32_t bits)                            const uint32_t bits)
245  {  {
# Line 263  Line 260 
260  }  }
261    
262    
263  /* number of bits to next byte alignment */  // number of bits to next byte alignment
264  static uint32_t __inline  static __inline uint32_t
265  BitstreamNumBitsToByteAlign(Bitstream *bs)  BitstreamNumBitsToByteAlign(Bitstream *bs)
266  {  {
267          uint32_t n = (32 - bs->pos) % 8;          uint32_t n = (32 - bs->pos) % 8;
# Line 272  Line 269 
269  }  }
270    
271    
272  /* show nbits from next byte alignment */  // show nbits from next byte alignment
273  static uint32_t __inline  static __inline uint32_t
274  BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)  BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)
275  {  {
276          int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);          int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);
# Line 295  Line 292 
292    
293  /* move forward to the next byte boundary */  /* move forward to the next byte boundary */
294    
295  static void __inline  static __inline void
296  BitstreamByteAlign(Bitstream * const bs)  BitstreamByteAlign(Bitstream * const bs)
297  {  {
298          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
# Line 311  Line 308 
308  static uint32_t __inline  static uint32_t __inline
309  BitstreamPos(const Bitstream * const bs)  BitstreamPos(const Bitstream * const bs)
310  {  {
311          return((uint32_t)(8*((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos - bs->initpos));          return 8 * ((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos;
312  }  }
313    
314    
# Line 322  Line 319 
319  static uint32_t __inline  static uint32_t __inline
320  BitstreamLength(Bitstream * const bs)  BitstreamLength(Bitstream * const bs)
321  {  {
322          uint32_t len = (uint32_t)((ptr_t)bs->tail - (ptr_t)bs->start);          uint32_t len = (ptr_t) bs->tail - (ptr_t) bs->start;
323    
324          if (bs->pos) {          if (bs->pos) {
325                  uint32_t b = bs->buf;                  uint32_t b = bs->buf;
# Line 335  Line 332 
332                  len += (bs->pos + 7) / 8;                  len += (bs->pos + 7) / 8;
333          }          }
334    
         /* initpos is always on a byte boundary */  
         if (bs->initpos)  
                 len -= bs->initpos/8;  
   
335          return len;          return len;
336  }  }
337    
# Line 363  Line 356 
356          }          }
357  }  }
358    
359    
360  /* read n bits from bitstream */  /* read n bits from bitstream */
361    
362  static uint32_t __inline  static uint32_t __inline
# Line 425  Line 419 
419          }          }
420  }  }
421    
422    
423  static const int stuffing_codes[8] =  static const int stuffing_codes[8] =
424  {  {
425                  /* nbits     stuffing code */                  /* nbits     stuffing code */
# Line 445  Line 440 
440  {  {
441          int bits = 8 - (bs->pos % 8);          int bits = 8 - (bs->pos % 8);
442          if (bits < 8)          if (bits < 8)
443            {
444                  BitstreamPutBits(bs, stuffing_codes[bits - 1], bits);                  BitstreamPutBits(bs, stuffing_codes[bits - 1], bits);
445  }  }
446    }
447    
448  /*  
449   * pad bitstream to the next byte boundary  /* pad bitstream to the next byte boundary
450   * alway pad: even if currently at the byte boundary     alway pad: even if currently at the byte boundary */
  */  
451    
452  static void __inline  static void __inline
453  BitstreamPadAlways(Bitstream * const bs)  BitstreamPadAlways(Bitstream * const bs)
# Line 460  Line 456 
456          BitstreamPutBits(bs, stuffing_codes[bits - 1], bits);          BitstreamPutBits(bs, stuffing_codes[bits - 1], bits);
457  }  }
458    
459    
460  #endif /* _BITSTREAM_H_ */  #endif /* _BITSTREAM_H_ */

Legend:
Removed from v.1.16.2.2  
changed lines
  Added in v.1.17.2.1

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