[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.10.2.5, Sat Jan 11 14:59:24 2003 UTC revision 1.16.2.1, Fri Apr 4 22:12:07 2003 UTC
# Line 1  Line 1 
1   /******************************************************************************  /*****************************************************************************
2    *                                                                            *   *
3    *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *   *  XVID MPEG-4 VIDEO CODEC
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    *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *   *  Copyright (C) 2001-2002 - Peter Ross <pross@xvid.org>
7    *  software module in hardware or software products are advised that its     *   *
8    *  use may infringe existing patents or copyrights, and any such use         *   *  This file is part of XviD, a free MPEG-4 video encoder/decoder
9    *  would be at such party's own risk.  The original developer of this        *   *
10    *  software module and his/her company, and subsequent editors and their     *   *  XviD is free software; you can redistribute it and/or modify it
11    *  companies, will have no liability for use of this software or             *   *  under the terms of the GNU General Public License as published by
12    *  modifications or derivatives thereof.                                     *   *  the Free Software Foundation; either version 2 of the License, or
13    *                                                                            *   *  (at your option) any later version.
14    *  XviD is free software; you can redistribute it and/or modify it           *   *
15    *  under the terms of the GNU General Public License as published by         *   *  This program is distributed in the hope that it will be useful,
16    *  the Free Software Foundation; either version 2 of the License, or         *   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17    *  (at your option) any later version.                                       *   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    *                                                                            *   *  GNU General Public License for more details.
19    *  XviD is distributed in the hope that it will be useful, but               *   *
20    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *   *  You should have received a copy of the GNU General Public License
21    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *   *  along with this program; if not, write to the Free Software
22    *  GNU General Public License for more details.                              *   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23    *                                                                            *   *
24    *  You should have received a copy of the GNU General Public License         *   *  Under section 8 of the GNU General Public License, the copyright
25    *  along with this program; if not, write to the Free Software               *   *  holders of XVID explicitly forbid distribution in the following
26    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *   *  countries:
27    *                                                                            *   *
28    ******************************************************************************/   *    - Japan
29     *    - United States of America
30   /******************************************************************************   *
31    *                                                                            *   *  Linking XviD statically or dynamically with other modules is making a
32    *  bitstream.h                                                               *   *  combined work based on XviD.  Thus, the terms and conditions of the
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    *  For more information visit the XviD homepage: http://www.xvid.org         *   *  permission to link XviD with independent modules that communicate with
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    *  Revision history:                                                         *   *  combined work), being distributed under the terms of the GNU General
43    *                                                                            *   *  Public License plus this exception.  An independent module is a module
44    *  28.06.2002 addded BitstreamNumBitsToByteAlign()                           *   *  which is not derived from or based on XviD.
45    *                    BitstreamShowBitsFromByteAlign()                        *   *
46    *  26.03.2002 interlacing support - modified putvol/vopheaders paramters     *   *  Note that people who make modified versions of XviD are not obligated
47    *  04.03.2002 putbits speedup (Isibaar)                                      *   *  to grant this special exception for their modified versions; it is
48    *  03.03.2002 merged BITREADER and BITWRITER (Isibaar)                       *   *  their choice whether to do so.  The GNU General Public License gives
49    *      16.12.2001     inital version                                                     *   *  permission to release a modified version without this exception; this
50    *                                                                                                                                                        *   *  exception also makes it possible to release a modified version which
51    ******************************************************************************/   *  carries forward this exception.
52     *
53     * $Id$
54     *
55     ****************************************************************************/
56    
57  #ifndef _BITSTREAM_H_  #ifndef _BITSTREAM_H_
58  #define _BITSTREAM_H_  #define _BITSTREAM_H_
59    
60    #include <stdio.h>
61    
62  #include "../portab.h"  #include "../portab.h"
63  #include "../decoder.h"  #include "../decoder.h"
64  #include "../encoder.h"  #include "../encoder.h"
65    
 // comment any #defs we dont use  
66    
67  /* start codes */  /*****************************************************************************
68     * Constants
69     ****************************************************************************/
70    
71    /* comment any #defs we dont use */
72    
73  #define VIDOBJ_START_CODE               0x00000100      /* ..0x0000011f  */  #define VIDOBJ_START_CODE               0x00000100      /* ..0x0000011f  */
74  #define VIDOBJLAY_START_CODE    0x00000120      /* ..0x0000012f */  #define VIDOBJLAY_START_CODE    0x00000120      /* ..0x0000012f */
# Line 67  Line 76 
76  #define VISOBJSEQ_STOP_CODE             0x000001b1      /* ??? */  #define VISOBJSEQ_STOP_CODE             0x000001b1      /* ??? */
77  #define USERDATA_START_CODE             0x000001b2  #define USERDATA_START_CODE             0x000001b2
78  #define GRPOFVOP_START_CODE             0x000001b3  #define GRPOFVOP_START_CODE             0x000001b3
79  //#define VIDSESERR_ERROR_CODE  0x000001b4  /*#define VIDSESERR_ERROR_CODE  0x000001b4 */
80  #define VISOBJ_START_CODE               0x000001b5  #define VISOBJ_START_CODE               0x000001b5
81  #define VOP_START_CODE                  0x000001b6  /*#define SLICE_START_CODE      0x000001b7 */
82  //#define STUFFING_START_CODE   0x000001c3  /*#define EXT_START_CODE        0x000001b8 */
83    
84    
85  #define VISOBJ_TYPE_VIDEO                               1  #define VISOBJ_TYPE_VIDEO                               1
86  //#define VISOBJ_TYPE_STILLTEXTURE      2  /*#define VISOBJ_TYPE_STILLTEXTURE      2 */
87  //#define VISOBJ_TYPE_MESH              3  /*#define VISOBJ_TYPE_MESH              3 */
88  //#define VISOBJ_TYPE_FBA               4  /*#define VISOBJ_TYPE_FBA               4 */
89  //#define VISOBJ_TYPE_3DMESH            5  /*#define VISOBJ_TYPE_3DMESH            5 */
90    
91    
92  #define VIDOBJLAY_TYPE_SIMPLE                   1  #define VIDOBJLAY_TYPE_SIMPLE                   1
93  //#define VIDOBJLAY_TYPE_SIMPLE_SCALABLE    2  /*#define VIDOBJLAY_TYPE_SIMPLE_SCALABLE    2 */
94  #define VIDOBJLAY_TYPE_CORE                             3  #define VIDOBJLAY_TYPE_CORE                             3
95  #define VIDOBJLAY_TYPE_MAIN                             4  #define VIDOBJLAY_TYPE_MAIN                             4
96  //#define VIDOBJLAY_TYPE_NBIT                           5  
97  //#define VIDOBJLAY_TYPE_ANIM_TEXT                      6  
98  //#define VIDOBJLAY_TYPE_ANIM_MESH                      7  /*#define VIDOBJLAY_AR_SQUARE           1 */
99  //#define VIDOBJLAY_TYPE_SIMPLE_FACE            8  /*#define VIDOBJLAY_AR_625TYPE_43       2 */
100  //#define VIDOBJLAY_TYPE_STILL_SCALABLE         9  /*#define VIDOBJLAY_AR_525TYPE_43       3 */
101  #define VIDOBJLAY_TYPE_ART_SIMPLE               10  /*#define VIDOBJLAY_AR_625TYPE_169      8 */
102  //#define VIDOBJLAY_TYPE_CORE_SCALABLE          11  /*#define VIDOBJLAY_AR_525TYPE_169      9 */
 #define VIDOBJLAY_TYPE_ACE                              12  
 //#define VIDOBJLAY_TYPE_SIMPLE_FBA                     13  
   
   
 //#define VIDOBJLAY_AR_SQUARE           1  
 //#define VIDOBJLAY_AR_625TYPE_43       2  
 //#define VIDOBJLAY_AR_525TYPE_43       3  
 //#define VIDOBJLAY_AR_625TYPE_169      8  
 //#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 SPRITE_NONE             0  #define VOL_START_CODE  0x12
113  #define SPRITE_STATIC   1  #define VOP_START_CODE  0x1b6
 #define SPRITE_GMC              2  
   
   
114    
115  #define READ_MARKER()   BitstreamSkip(bs, 1)  #define READ_MARKER()   BitstreamSkip(bs, 1)
116  #define WRITE_MARKER()  BitstreamPutBit(bs, 1)  #define WRITE_MARKER()  BitstreamPutBit(bs, 1)
117    
118  // vop coding types  /* vop coding types  */
119  // intra, prediction, backward, sprite, not_coded  /* intra, prediction, backward, sprite, not_coded */
120  #define I_VOP   0  #define I_VOP   0
121  #define P_VOP   1  #define P_VOP   1
122  #define B_VOP   2  #define B_VOP   2
123  #define S_VOP   3  #define S_VOP   3
124  #define N_VOP   4  #define N_VOP   4
125    
126  // resync-specific  /* resync-specific */
127  #define NUMBITS_VP_RESYNC_MARKER  17  #define NUMBITS_VP_RESYNC_MARKER  17
128  #define RESYNC_MARKER 1  #define RESYNC_MARKER 1
129    
130    
131  int read_video_packet_header(Bitstream *bs,  /*****************************************************************************
132                                                  DECODER * dec,   * Prototypes
133                                                  const int addbits,   ****************************************************************************/
134                                                  int * quant,  
135                                                  int * fcode_forward,  int
136                                                  int  * fcode_backward,  read_video_packet_header(Bitstream *bs, const int addbits, int * quant);
                                                 int * intra_dc_threshold);  
137    
138    
139  // header stuff  /* header stuff */
140  int BitstreamReadHeaders(Bitstream * bs,  int BitstreamReadHeaders(Bitstream * bs,
141                                                   DECODER * dec,                                                   DECODER * dec,
142                                                   uint32_t * rounding,                                                   uint32_t * rounding,
                                                  uint32_t * reduced_resolution,  
143                                                   uint32_t * quant,                                                   uint32_t * quant,
144                                                   uint32_t * fcode_forward,                                                   uint32_t * fcode_forward,
145                                                   uint32_t * fcode_backward,                                                   uint32_t * fcode_backward,
146                                                   uint32_t * intra_dc_threshold,                                                   uint32_t * intra_dc_threshold);
                                                  WARPPOINTS * gmc_warp);  
147    
148    
149  void BitstreamWriteVolHeader(Bitstream * const bs,  void BitstreamWriteVolHeader(Bitstream * const bs,
150                                                           const MBParam * pParam,                                                           const MBParam * pParam,
151                                                           const FRAMEINFO * const frame);                                                           const FRAMEINFO * frame);
152    
153  void BitstreamWriteVopHeader(Bitstream * const bs,  void BitstreamWriteVopHeader(Bitstream * const bs,
154                                                           const MBParam * pParam,                                                           const MBParam * pParam,
155                                                           const FRAMEINFO * const frame,                                                           const FRAMEINFO * frame,
156                                                           int vop_coded);                                                           int vop_coded);
157    
158  void BitstreamWriteUserData(Bitstream * const bs,  /*****************************************************************************
159                                                          uint8_t * data,   * Inlined functions
160                                                          const int length);   ****************************************************************************/
161    
162  /* initialise bitstream structure */  /* initialise bitstream structure */
163    
# Line 173  Line 167 
167                            uint32_t length)                            uint32_t length)
168  {  {
169          uint32_t tmp;          uint32_t tmp;
170            size_t bitpos;
171            ptr_t adjbitstream = (ptr_t)bitstream;
172    
173          bs->start = bs->tail = (uint32_t *) bitstream;          /*
174             * Start the stream on a uint32_t boundary, by rounding down to the
175             * previous uint32_t and skipping the intervening bytes.
176             */
177            bitpos = ((sizeof(uint32_t)-1) & (size_t)bitstream);
178            adjbitstream = adjbitstream - bitpos;
179            bs->start = bs->tail = (uint32_t *) adjbitstream;
180    
181          tmp = *(uint32_t *) bitstream;          tmp = *bs->start;
182  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
183          BSWAP(tmp);          BSWAP(tmp);
184  #endif  #endif
185          bs->bufa = tmp;          bs->bufa = tmp;
186    
187          tmp = *((uint32_t *) bitstream + 1);          tmp = *(bs->start + 1);
188  #ifndef ARCH_IS_BIG_ENDIAN  #ifndef ARCH_IS_BIG_ENDIAN
189          BSWAP(tmp);          BSWAP(tmp);
190  #endif  #endif
191          bs->bufb = tmp;          bs->bufb = tmp;
192    
193          bs->buf = 0;          bs->buf = 0;
194          bs->pos = 0;          bs->pos = bs->initpos = bitpos*8;
195          bs->length = length;          bs->length = length;
196  }  }
197    
# Line 216  Line 218 
218          bs->bufb = tmp;          bs->bufb = tmp;
219    
220          bs->buf = 0;          bs->buf = 0;
221          bs->pos = 0;          bs->pos = bs->initpos;
222  }  }
223    
224    
# Line 240  Line 242 
242    
243  /* skip n bits forward in bitstream */  /* skip n bits forward in bitstream */
244    
245  static __inline void  static void __inline
246  BitstreamSkip(Bitstream * const bs,  BitstreamSkip(Bitstream * const bs,
247                            const uint32_t bits)                            const uint32_t bits)
248  {  {
# Line 261  Line 263 
263  }  }
264    
265    
266  // number of bits to next byte alignment  /* number of bits to next byte alignment */
267  static __inline uint32_t  static uint32_t __inline
268  BitstreamNumBitsToByteAlign(Bitstream *bs)  BitstreamNumBitsToByteAlign(Bitstream *bs)
269  {  {
270          uint32_t n = (32 - bs->pos) % 8;          uint32_t n = (32 - bs->pos) % 8;
# Line 270  Line 272 
272  }  }
273    
274    
275  // show nbits from next byte alignment  /* show nbits from next byte alignment */
276  static __inline uint32_t  static uint32_t __inline
277  BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)  BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)
278  {  {
279          int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);          int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);
# Line 293  Line 295 
295    
296  /* move forward to the next byte boundary */  /* move forward to the next byte boundary */
297    
298  static __inline void  static void __inline
299  BitstreamByteAlign(Bitstream * const bs)  BitstreamByteAlign(Bitstream * const bs)
300  {  {
301          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
# Line 309  Line 311 
311  static uint32_t __inline  static uint32_t __inline
312  BitstreamPos(const Bitstream * const bs)  BitstreamPos(const Bitstream * const bs)
313  {  {
314          return 8 * ((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos;          return((uint32_t)(8*((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos - bs->initpos));
315  }  }
316    
317    
# Line 320  Line 322 
322  static uint32_t __inline  static uint32_t __inline
323  BitstreamLength(Bitstream * const bs)  BitstreamLength(Bitstream * const bs)
324  {  {
325          uint32_t len = (ptr_t) bs->tail - (ptr_t) bs->start;          uint32_t len = (uint32_t)((ptr_t)bs->tail - (ptr_t)bs->start);
326    
327          if (bs->pos) {          if (bs->pos) {
328                  uint32_t b = bs->buf;                  uint32_t b = bs->buf;
# Line 333  Line 335 
335                  len += (bs->pos + 7) / 8;                  len += (bs->pos + 7) / 8;
336          }          }
337    
338            /* initpos is always on a byte boundary */
339            if (bs->initpos)
340                    len -= bs->initpos/8;
341    
342          return len;          return len;
343  }  }
344    
# Line 358  Line 364 
364  }  }
365    
366    
367    /* pad bitstream to the next byte boundary */
368    
369    static void __inline
370    BitstreamPad(Bitstream * const bs)
371    {
372            uint32_t remainder = bs->pos % 8;
373    
374            if (remainder) {
375                    BitstreamForward(bs, 8 - remainder);
376            }
377    }
378    
379    
380  /* read n bits from bitstream */  /* read n bits from bitstream */
381    
382  static uint32_t __inline  static uint32_t __inline
# Line 420  Line 439 
439          }          }
440  }  }
441    
   
 static const int stuffing_codes[8] =  
 {  
                 /* nbits     stuffing code */  
         0,              /* 1          0 */  
         1,              /* 2          01 */  
         3,              /* 3          011 */  
         7,              /* 4          0111 */  
         0xf,    /* 5          01111 */  
         0x1f,   /* 6          011111 */  
         0x3f,   /* 7          0111111 */  
         0x7f,   /* 8          01111111 */  
 };  
   
 /* pad bitstream to the next byte boundary */  
   
 static void __inline  
 BitstreamPad(Bitstream * const bs)  
 {  
         int bits = 8 - (bs->pos % 8);  
         if (bits < 8)  
         {  
                 BitstreamPutBits(bs, stuffing_codes[bits - 1], bits);  
         }  
 }  
   
   
 /* pad bitstream to the next byte boundary  
    alway pad: even if currently at the byte boundary */  
   
 static void __inline  
 BitstreamPadAlways(Bitstream * const bs)  
 {  
         int bits = 8 - (bs->pos % 8);  
         BitstreamPutBits(bs, stuffing_codes[bits - 1], bits);  
 }  
   
   
442  #endif                                                  /* _BITSTREAM_H_ */  #endif                                                  /* _BITSTREAM_H_ */

Legend:
Removed from v.1.10.2.5  
changed lines
  Added in v.1.16.2.1

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