[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.13, Sat Sep 21 03:07:56 2002 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 program is an implementation of a part of one or more MPEG-4
9    *  would be at such party's own risk.  The original developer of this        *   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
10    *  software module and his/her company, and subsequent editors and their     *   *  to use this software module in hardware or software products are
11    *  companies, will have no liability for use of this software or             *   *  advised that its use may infringe existing patents or copyrights, and
12    *  modifications or derivatives thereof.                                     *   *  any such use would be at such party's own risk.  The original
13    *                                                                            *   *  developer of this software module and his/her company, and subsequent
14    *  XviD is free software; you can redistribute it and/or modify it           *   *  editors and their companies, will have no liability for use of this
15    *  under the terms of the GNU General Public License as published by         *   *  software or modifications or derivatives thereof.
16    *  the Free Software Foundation; either version 2 of the License, or         *   *
17    *  (at your option) any later version.                                       *   *  This program is free software ; you can redistribute it and/or modify
18    *                                                                            *   *  it under the terms of the GNU General Public License as published by
19    *  XviD is distributed in the hope that it will be useful, but               *   *  the Free Software Foundation ; either version 2 of the License, or
20    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *   *  (at your option) any later version.
21    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *   *
22    *  GNU General Public License for more details.                              *   *  This program is distributed in the hope that it will be useful,
23    *                                                                            *   *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
24    *  You should have received a copy of the GNU General Public License         *   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25    *  along with this program; if not, write to the Free Software               *   *  GNU General Public License for more details.
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    *                                                                            *   ****************************************************************************/
   *  Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au>                    *  
   *                                                                            *  
   *  For more information visit the XviD homepage: http://www.xvid.org         *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                                                                                                        *  
   *  Revision history:                                                         *  
   *                                                                            *  
   *  28.06.2002 addded BitstreamNumBitsToByteAlign()                           *  
   *                    BitstreamShowBitsFromByteAlign()                        *  
   *  26.03.2002 interlacing support - modified putvol/vopheaders paramters     *  
   *  04.03.2002 putbits speedup (Isibaar)                                      *  
   *  03.03.2002 merged BITREADER and BITWRITER (Isibaar)                       *  
   *      16.12.2001     inital version                                                     *  
   *                                                                                                                                                        *  
   ******************************************************************************/  
34    
35  #ifndef _BITSTREAM_H_  #ifndef _BITSTREAM_H_
36  #define _BITSTREAM_H_  #define _BITSTREAM_H_
# Line 57  Line 39 
39  #include "../decoder.h"  #include "../decoder.h"
40  #include "../encoder.h"  #include "../encoder.h"
41    
 // comment any #defs we dont use  
42    
43  /* start codes */  /*****************************************************************************
44     * Constants
45     ****************************************************************************/
46    
47    // comment any #defs we dont use
48    
49  #define VIDOBJ_START_CODE               0x00000100      /* ..0x0000011f  */  #define VIDOBJ_START_CODE               0x00000100      /* ..0x0000011f  */
50  #define VIDOBJLAY_START_CODE    0x00000120      /* ..0x0000012f */  #define VIDOBJLAY_START_CODE    0x00000120      /* ..0x0000012f */
# Line 69  Line 54 
54  #define GRPOFVOP_START_CODE             0x000001b3  #define GRPOFVOP_START_CODE             0x000001b3
55  //#define VIDSESERR_ERROR_CODE  0x000001b4  //#define VIDSESERR_ERROR_CODE  0x000001b4
56  #define VISOBJ_START_CODE               0x000001b5  #define VISOBJ_START_CODE               0x000001b5
57  #define VOP_START_CODE                  0x000001b6  //#define SLICE_START_CODE      0x000001b7
58  //#define STUFFING_START_CODE   0x000001c3  //#define EXT_START_CODE        0x000001b8
59    
60    
61  #define VISOBJ_TYPE_VIDEO                               1  #define VISOBJ_TYPE_VIDEO                               1
# Line 84  Line 69 
69  //#define VIDOBJLAY_TYPE_SIMPLE_SCALABLE    2  //#define VIDOBJLAY_TYPE_SIMPLE_SCALABLE    2
70  #define VIDOBJLAY_TYPE_CORE                             3  #define VIDOBJLAY_TYPE_CORE                             3
71  #define VIDOBJLAY_TYPE_MAIN                             4  #define VIDOBJLAY_TYPE_MAIN                             4
 //#define VIDOBJLAY_TYPE_NBIT                           5  
 //#define VIDOBJLAY_TYPE_ANIM_TEXT                      6  
 //#define VIDOBJLAY_TYPE_ANIM_MESH                      7  
 //#define VIDOBJLAY_TYPE_SIMPLE_FACE            8  
 //#define VIDOBJLAY_TYPE_STILL_SCALABLE         9  
 #define VIDOBJLAY_TYPE_ART_SIMPLE               10  
 //#define VIDOBJLAY_TYPE_CORE_SCALABLE          11  
 #define VIDOBJLAY_TYPE_ACE                              12  
 //#define VIDOBJLAY_TYPE_SIMPLE_FBA                     13  
72    
73    
74  //#define VIDOBJLAY_AR_SQUARE           1  //#define VIDOBJLAY_AR_SQUARE           1
# Line 108  Line 84 
84  #define VIDOBJLAY_SHAPE_BINARY_ONLY             2  #define VIDOBJLAY_SHAPE_BINARY_ONLY             2
85  #define VIDOBJLAY_SHAPE_GRAYSCALE               3  #define VIDOBJLAY_SHAPE_GRAYSCALE               3
86    
87    #define VO_START_CODE   0x8
88  #define SPRITE_NONE             0  #define VOL_START_CODE  0x12
89  #define SPRITE_STATIC   1  #define VOP_START_CODE  0x1b6
 #define SPRITE_GMC              2  
   
   
90    
91  #define READ_MARKER()   BitstreamSkip(bs, 1)  #define READ_MARKER()   BitstreamSkip(bs, 1)
92  #define WRITE_MARKER()  BitstreamPutBit(bs, 1)  #define WRITE_MARKER()  BitstreamPutBit(bs, 1)
# Line 131  Line 104 
104  #define RESYNC_MARKER 1  #define RESYNC_MARKER 1
105    
106    
107  int read_video_packet_header(Bitstream *bs,  /*****************************************************************************
108                                                  DECODER * dec,   * Prototypes
109                                                  const int addbits,   ****************************************************************************/
110                                                  int * quant,  
111                                                  int * fcode_forward,  int
112                                                  int  * fcode_backward,  read_video_packet_header(Bitstream *bs, const int addbits, int * quant);
                                                 int * intra_dc_threshold);  
113    
114    
115  // header stuff  // header stuff
116  int BitstreamReadHeaders(Bitstream * bs,  int BitstreamReadHeaders(Bitstream * bs,
117                                                   DECODER * dec,                                                   DECODER * dec,
118                                                   uint32_t * rounding,                                                   uint32_t * rounding,
                                                  uint32_t * reduced_resolution,  
119                                                   uint32_t * quant,                                                   uint32_t * quant,
120                                                   uint32_t * fcode_forward,                                                   uint32_t * fcode_forward,
121                                                   uint32_t * fcode_backward,                                                   uint32_t * fcode_backward,
122                                                   uint32_t * intra_dc_threshold,                                                   uint32_t * intra_dc_threshold);
                                                  WARPPOINTS * gmc_warp);  
123    
124    
125  void BitstreamWriteVolHeader(Bitstream * const bs,  void BitstreamWriteVolHeader(Bitstream * const bs,
126                                                           const MBParam * pParam,                                                           const MBParam * pParam,
127                                                           const FRAMEINFO * const frame);                                                           const FRAMEINFO * frame);
128    
129  void BitstreamWriteVopHeader(Bitstream * const bs,  void BitstreamWriteVopHeader(Bitstream * const bs,
130                                                           const MBParam * pParam,                                                           const MBParam * pParam,
131                                                           const FRAMEINFO * const frame,                                                           const FRAMEINFO * frame,
132                                                           int vop_coded);                                                           int vop_coded);
133    
134  void BitstreamWriteUserData(Bitstream * const bs,  /*****************************************************************************
135                                                          uint8_t * data,   * Inlined functions
136                                                          const int length);   ****************************************************************************/
137    
138  /* initialise bitstream structure */  /* initialise bitstream structure */
139    
# Line 240  Line 210 
210    
211  /* skip n bits forward in bitstream */  /* skip n bits forward in bitstream */
212    
213  static __inline void  static void __inline
214  BitstreamSkip(Bitstream * const bs,  BitstreamSkip(Bitstream * const bs,
215                            const uint32_t bits)                            const uint32_t bits)
216  {  {
# Line 262  Line 232 
232    
233    
234  // number of bits to next byte alignment  // number of bits to next byte alignment
235  static __inline uint32_t  static uint32_t __inline
236  BitstreamNumBitsToByteAlign(Bitstream *bs)  BitstreamNumBitsToByteAlign(Bitstream *bs)
237  {  {
238          uint32_t n = (32 - bs->pos) % 8;          uint32_t n = (32 - bs->pos) % 8;
# Line 271  Line 241 
241    
242    
243  // show nbits from next byte alignment  // show nbits from next byte alignment
244  static __inline uint32_t  static uint32_t __inline
245  BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)  BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits)
246  {  {
247          int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);          int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs);
# Line 293  Line 263 
263    
264  /* move forward to the next byte boundary */  /* move forward to the next byte boundary */
265    
266  static __inline void  static void __inline
267  BitstreamByteAlign(Bitstream * const bs)  BitstreamByteAlign(Bitstream * const bs)
268  {  {
269          uint32_t remainder = bs->pos % 8;          uint32_t remainder = bs->pos % 8;
# Line 358  Line 328 
328  }  }
329    
330    
331    /* pad bitstream to the next byte boundary */
332    
333    static void __inline
334    BitstreamPad(Bitstream * const bs)
335    {
336            uint32_t remainder = bs->pos % 8;
337    
338            if (remainder) {
339                    BitstreamForward(bs, 8 - remainder);
340            }
341    }
342    
343    
344  /* read n bits from bitstream */  /* read n bits from bitstream */
345    
346  static uint32_t __inline  static uint32_t __inline
# Line 420  Line 403 
403          }          }
404  }  }
405    
   
 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);  
 }  
   
   
406  #endif                                                  /* _BITSTREAM_H_ */  #endif                                                  /* _BITSTREAM_H_ */

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

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