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_ |
61 |
#include "../decoder.h" |
#include "../decoder.h" |
62 |
#include "../encoder.h" |
#include "../encoder.h" |
63 |
|
|
64 |
|
|
65 |
|
/***************************************************************************** |
66 |
|
* Constants |
67 |
|
****************************************************************************/ |
68 |
|
|
69 |
// comment any #defs we dont use |
// comment any #defs we dont use |
70 |
|
|
71 |
#define VIDOBJ_START_CODE 0x00000100 /* ..0x0000011f */ |
#define VIDOBJ_START_CODE 0x00000100 /* ..0x0000011f */ |
126 |
#define RESYNC_MARKER 1 |
#define RESYNC_MARKER 1 |
127 |
|
|
128 |
|
|
129 |
|
/***************************************************************************** |
130 |
|
* Prototypes |
131 |
|
****************************************************************************/ |
132 |
|
|
133 |
int |
int |
134 |
read_video_packet_header(Bitstream *bs, int addbits); |
read_video_packet_header(Bitstream *bs, const int addbits, int * quant); |
135 |
|
|
136 |
|
|
137 |
// header stuff |
// header stuff |
153 |
const FRAMEINFO * frame, |
const FRAMEINFO * frame, |
154 |
int vop_coded); |
int vop_coded); |
155 |
|
|
156 |
void BitstreamWriteUserData(Bitstream * const bs, |
/***************************************************************************** |
157 |
uint8_t * data, |
* Inlined functions |
158 |
const int length); |
****************************************************************************/ |
159 |
|
|
160 |
/* initialise bitstream structure */ |
/* initialise bitstream structure */ |
161 |
|
|
232 |
|
|
233 |
/* skip n bits forward in bitstream */ |
/* skip n bits forward in bitstream */ |
234 |
|
|
235 |
static __inline void |
static void __inline |
236 |
BitstreamSkip(Bitstream * const bs, |
BitstreamSkip(Bitstream * const bs, |
237 |
const uint32_t bits) |
const uint32_t bits) |
238 |
{ |
{ |
254 |
|
|
255 |
|
|
256 |
// number of bits to next byte alignment |
// number of bits to next byte alignment |
257 |
static __inline uint32_t |
static uint32_t __inline |
258 |
BitstreamNumBitsToByteAlign(Bitstream *bs) |
BitstreamNumBitsToByteAlign(Bitstream *bs) |
259 |
{ |
{ |
260 |
uint32_t n = (32 - bs->pos) % 8; |
uint32_t n = (32 - bs->pos) % 8; |
263 |
|
|
264 |
|
|
265 |
// show nbits from next byte alignment |
// show nbits from next byte alignment |
266 |
static __inline uint32_t |
static uint32_t __inline |
267 |
BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits) |
BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits) |
268 |
{ |
{ |
269 |
int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs); |
int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs); |
285 |
|
|
286 |
/* move forward to the next byte boundary */ |
/* move forward to the next byte boundary */ |
287 |
|
|
288 |
static __inline void |
static void __inline |
289 |
BitstreamByteAlign(Bitstream * const bs) |
BitstreamByteAlign(Bitstream * const bs) |
290 |
{ |
{ |
291 |
uint32_t remainder = bs->pos % 8; |
uint32_t remainder = bs->pos % 8; |