41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
* 26.03.2002 interlacing support - modified putvol/vopheaders paramters |
* 28.06.2002 addded BitstreamNumBitsToByteAlign() * |
45 |
|
* BitstreamShowBitsFromByteAlign() * |
46 |
|
* 26.03.2002 interlacing support - modified putvol/vopheaders paramters * |
47 |
* 04.03.2002 putbits speedup (Isibaar) * |
* 04.03.2002 putbits speedup (Isibaar) * |
48 |
* 03.03.2002 merged BITREADER and BITWRITER (Isibaar) * |
* 03.03.2002 merged BITREADER and BITWRITER (Isibaar) * |
49 |
* 16.12.2001 inital version * |
* 16.12.2001 inital version * |
112 |
#define S_VOP 3 |
#define S_VOP 3 |
113 |
#define N_VOP 4 |
#define N_VOP 4 |
114 |
|
|
115 |
|
// resync-specific |
116 |
|
#define NUMBITS_VP_RESYNC_MARKER 17 |
117 |
|
#define RESYNC_MARKER 1 |
118 |
|
|
119 |
|
|
120 |
|
int |
121 |
|
read_video_packet_header(Bitstream *bs, const int addbits, int * quant); |
122 |
|
|
123 |
|
|
124 |
// header stuff |
// header stuff |
125 |
int BitstreamReadHeaders(Bitstream * bs, |
int BitstreamReadHeaders(Bitstream * bs, |
133 |
|
|
134 |
void BitstreamWriteVolHeader(Bitstream * const bs, |
void BitstreamWriteVolHeader(Bitstream * const bs, |
135 |
const MBParam * pParam, |
const MBParam * pParam, |
136 |
const FRAMEINFO * frame); |
const FRAMEINFO * const frame); |
137 |
|
|
138 |
void BitstreamWriteVopHeader(Bitstream * const bs, |
void BitstreamWriteVopHeader(Bitstream * const bs, |
139 |
const MBParam * pParam, |
const MBParam * pParam, |
140 |
const FRAMEINFO * frame); |
const FRAMEINFO * const frame, |
141 |
|
int vop_coded); |
142 |
|
|
143 |
|
void BitstreamWriteUserData(Bitstream * const bs, |
144 |
|
uint8_t * data, |
145 |
|
const int length); |
146 |
|
|
147 |
/* initialise bitstream structure */ |
/* initialise bitstream structure */ |
148 |
|
|
240 |
} |
} |
241 |
|
|
242 |
|
|
243 |
|
// number of bits to next byte alignment |
244 |
|
static __inline uint32_t |
245 |
|
BitstreamNumBitsToByteAlign(Bitstream *bs) |
246 |
|
{ |
247 |
|
uint32_t n = (32 - bs->pos) % 8; |
248 |
|
return n == 0 ? 8 : n; |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
|
// show nbits from next byte alignment |
253 |
|
static __inline uint32_t |
254 |
|
BitstreamShowBitsFromByteAlign(Bitstream *bs, int bits) |
255 |
|
{ |
256 |
|
int bspos = bs->pos + BitstreamNumBitsToByteAlign(bs); |
257 |
|
int nbit = (bits + bspos) - 32; |
258 |
|
|
259 |
|
if (bspos >= 32) { |
260 |
|
return bs->bufb >> (32 - nbit); |
261 |
|
} else if (nbit > 0) { |
262 |
|
return ((bs->bufa & (0xffffffff >> bspos)) << nbit) | (bs-> |
263 |
|
bufb >> (32 - |
264 |
|
nbit)); |
265 |
|
} else { |
266 |
|
return (bs->bufa & (0xffffffff >> bspos)) >> (32 - bspos - bits); |
267 |
|
} |
268 |
|
|
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
/* move forward to the next byte boundary */ |
/* move forward to the next byte boundary */ |
274 |
|
|
275 |
static __inline void |
static __inline void |
288 |
static uint32_t __inline |
static uint32_t __inline |
289 |
BitstreamPos(const Bitstream * const bs) |
BitstreamPos(const Bitstream * const bs) |
290 |
{ |
{ |
291 |
return 8 * ((uint32_t) bs->tail - (uint32_t) bs->start) + bs->pos; |
return 8 * ((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos; |
292 |
} |
} |
293 |
|
|
294 |
|
|
299 |
static uint32_t __inline |
static uint32_t __inline |
300 |
BitstreamLength(Bitstream * const bs) |
BitstreamLength(Bitstream * const bs) |
301 |
{ |
{ |
302 |
uint32_t len = (uint32_t) bs->tail - (uint32_t) bs->start; |
uint32_t len = (ptr_t) bs->tail - (ptr_t) bs->start; |
303 |
|
|
304 |
if (bs->pos) { |
if (bs->pos) { |
305 |
uint32_t b = bs->buf; |
uint32_t b = bs->buf; |
337 |
} |
} |
338 |
|
|
339 |
|
|
|
/* pad bitstream to the next byte boundary */ |
|
|
|
|
|
static void __inline |
|
|
BitstreamPad(Bitstream * const bs) |
|
|
{ |
|
|
uint32_t remainder = bs->pos % 8; |
|
|
|
|
|
if (remainder) { |
|
|
BitstreamForward(bs, 8 - remainder); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
340 |
/* read n bits from bitstream */ |
/* read n bits from bitstream */ |
341 |
|
|
342 |
static uint32_t __inline |
static uint32_t __inline |
399 |
} |
} |
400 |
} |
} |
401 |
|
|
402 |
|
|
403 |
|
static const int stuffing_codes[8] = |
404 |
|
{ |
405 |
|
/* nbits stuffing code */ |
406 |
|
0, /* 1 0 */ |
407 |
|
1, /* 2 01 */ |
408 |
|
3, /* 3 011 */ |
409 |
|
7, /* 4 0111 */ |
410 |
|
0xf, /* 5 01111 */ |
411 |
|
0x1f, /* 6 011111 */ |
412 |
|
0x3f, /* 7 0111111 */ |
413 |
|
0x7f, /* 8 01111111 */ |
414 |
|
}; |
415 |
|
|
416 |
|
/* pad bitstream to the next byte boundary */ |
417 |
|
|
418 |
|
static void __inline |
419 |
|
BitstreamPad(Bitstream * const bs) |
420 |
|
{ |
421 |
|
int bits = 8 - (bs->pos % 8); |
422 |
|
if (bits < 8) |
423 |
|
{ |
424 |
|
BitstreamPutBits(bs, stuffing_codes[bits - 1], bits); |
425 |
|
} |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
|
/* pad bitstream to the next byte boundary |
430 |
|
alway pad: even if currently at the byte boundary */ |
431 |
|
|
432 |
|
static void __inline |
433 |
|
BitstreamPadAlways(Bitstream * const bs) |
434 |
|
{ |
435 |
|
int bits = 8 - (bs->pos % 8); |
436 |
|
BitstreamPutBits(bs, stuffing_codes[bits - 1], bits); |
437 |
|
} |
438 |
|
|
439 |
|
|
440 |
#endif /* _BITSTREAM_H_ */ |
#endif /* _BITSTREAM_H_ */ |