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@cs.rmit.edu.au> |
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: bitstream.h,v 1.11 2002-09-10 22:25:23 edgomez Exp $ |
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_ |
39 |
#include "../decoder.h" |
#include "../decoder.h" |
40 |
#include "../encoder.h" |
#include "../encoder.h" |
41 |
|
|
42 |
|
|
43 |
|
/***************************************************************************** |
44 |
|
* Constants |
45 |
|
****************************************************************************/ |
46 |
|
|
47 |
// comment any #defs we dont use |
// comment any #defs we dont use |
48 |
|
|
49 |
#define VIDOBJ_START_CODE 0x00000100 /* ..0x0000011f */ |
#define VIDOBJ_START_CODE 0x00000100 /* ..0x0000011f */ |
104 |
#define RESYNC_MARKER 1 |
#define RESYNC_MARKER 1 |
105 |
|
|
106 |
|
|
107 |
|
/***************************************************************************** |
108 |
|
* Prototypes |
109 |
|
****************************************************************************/ |
110 |
|
|
111 |
int |
int |
112 |
read_video_packet_header(Bitstream *bs, const int addbits, int * quant); |
read_video_packet_header(Bitstream *bs, const int addbits, int * quant); |
113 |
|
|
135 |
uint8_t * data, |
uint8_t * data, |
136 |
const int length); |
const int length); |
137 |
|
|
138 |
|
/***************************************************************************** |
139 |
|
* Inlined functions |
140 |
|
****************************************************************************/ |
141 |
|
|
142 |
/* initialise bitstream structure */ |
/* initialise bitstream structure */ |
143 |
|
|
144 |
static void __inline |
static void __inline |
214 |
|
|
215 |
/* skip n bits forward in bitstream */ |
/* skip n bits forward in bitstream */ |
216 |
|
|
217 |
static __inline void |
static void __inline |
218 |
BitstreamSkip(Bitstream * const bs, |
BitstreamSkip(Bitstream * const bs, |
219 |
const uint32_t bits) |
const uint32_t bits) |
220 |
{ |
{ |
236 |
|
|
237 |
|
|
238 |
// number of bits to next byte alignment |
// number of bits to next byte alignment |
239 |
static __inline uint32_t |
static uint32_t __inline |
240 |
BitstreamNumBitsToByteAlign(Bitstream *bs) |
BitstreamNumBitsToByteAlign(Bitstream *bs) |
241 |
{ |
{ |
242 |
uint32_t n = (32 - bs->pos) % 8; |
uint32_t n = (32 - bs->pos) % 8; |
245 |
|
|
246 |
|
|
247 |
// show nbits from next byte alignment |
// show nbits from next byte alignment |
248 |
static __inline uint32_t |
static uint32_t __inline |
249 |
BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits) |
BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits) |
250 |
{ |
{ |
251 |
int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs); |
int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs); |
267 |
|
|
268 |
/* move forward to the next byte boundary */ |
/* move forward to the next byte boundary */ |
269 |
|
|
270 |
static __inline void |
static void __inline |
271 |
BitstreamByteAlign(Bitstream * const bs) |
BitstreamByteAlign(Bitstream * const bs) |
272 |
{ |
{ |
273 |
uint32_t remainder = bs->pos % 8; |
uint32_t remainder = bs->pos % 8; |