--- bitstream.h 2003/12/20 11:54:37 1.17.2.9 +++ bitstream.h 2010/12/28 19:19:43 1.26 @@ -19,7 +19,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: bitstream.h,v 1.17.2.9 2003/12/20 11:54:37 Isibaar Exp $ + * $Id: bitstream.h,v 1.26 2010/12/28 19:19:43 Isibaar Exp $ * ****************************************************************************/ @@ -128,7 +128,6 @@ int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding, - uint32_t * reduced_resolution, uint32_t * quant, uint32_t * fcode_forward, uint32_t * fcode_backward, @@ -138,7 +137,8 @@ void BitstreamWriteVolHeader(Bitstream * const bs, const MBParam * pParam, - const FRAMEINFO * const frame); + const FRAMEINFO * const frame, + const int num_slices); void BitstreamWriteVopHeader(Bitstream * const bs, const MBParam * pParam, @@ -147,8 +147,31 @@ unsigned int quant); void BitstreamWriteUserData(Bitstream * const bs, - uint8_t * data, - const int length); + const char *data, + const unsigned int length); + +void +BitstreamWriteEndOfSequence(Bitstream * const bs); + +void +BitstreamWriteGroupOfVopHeader(Bitstream * const bs, + const MBParam * pParam, + uint32_t is_closed_gov); + +void write_video_packet_header(Bitstream * const bs, + const MBParam * pParam, + const FRAMEINFO * const frame, + int mbnum); + +/***************************************************************************** + * Bitstream + ****************************************************************************/ + +/* Input buffer should be readable as full chunks of 8bytes, including +the end of the buffer. Padding might be appropriate. If only chunks +of 4bytes are applicable, define XVID_SAFE_BS_TAIL. Note that this will +slow decoding, so consider this as a last-resort solution */ +/* #define XVID_SAFE_BS_TAIL */ /* initialise bitstream structure */ @@ -181,8 +204,12 @@ #endif bs->bufb = tmp; - bs->buf = 0; - bs->pos = bs->initpos = bitpos*8; + bs->pos = bs->initpos = (uint32_t) bitpos*8; + /* preserve the intervening bytes */ + if (bs->initpos > 0) + bs->buf = bs->bufa & (0xffffffff << (32 - bs->initpos)); + else + bs->buf = 0; bs->length = length; } @@ -208,7 +235,11 @@ #endif bs->bufb = tmp; - bs->buf = 0; + /* preserve the intervening bytes */ + if (bs->initpos > 0) + bs->buf = bs->bufa & (0xffffffff << (32 - bs->initpos)); + else + bs->buf = 0; bs->pos = bs->initpos; } @@ -243,12 +274,22 @@ uint32_t tmp; bs->bufa = bs->bufb; - tmp = *((uint32_t *) bs->tail + 2); +#if defined(XVID_SAFE_BS_TAIL) + if (bs->tail<(bs->start+((bs->length+3)>>2))) +#endif + { + tmp = *((uint32_t *) bs->tail + 2); #ifndef ARCH_IS_BIG_ENDIAN - BSWAP(tmp); + BSWAP(tmp); +#endif + bs->bufb = tmp; + bs->tail++; + } +#if defined(XVID_SAFE_BS_TAIL) + else { + bs->bufb = 0; + } #endif - bs->bufb = tmp; - bs->tail++; bs->pos -= 32; } }