--- trunk/xvidcore/src/bitstream/bitstream.c 2002/07/19 13:34:32 316 +++ trunk/xvidcore/src/bitstream/bitstream.c 2002/09/12 19:06:37 478 @@ -1,73 +1,44 @@ - /****************************************************************************** - * * - * This file is part of XviD, a free MPEG-4 video encoder/decoder * - * * - * XviD is an implementation of a part of one or more MPEG-4 Video tools * - * as specified in ISO/IEC 14496-2 standard. Those intending to use this * - * software module in hardware or software products are advised that its * - * use may infringe existing patents or copyrights, and any such use * - * would be at such party's own risk. The original developer of this * - * software module and his/her company, and subsequent editors and their * - * companies, will have no liability for use of this software or * - * modifications or derivatives thereof. * - * * - * XviD is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * XviD is distributed in the hope that it will be useful, but * - * WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - ******************************************************************************/ - - /****************************************************************************** - * * - * bitstream.c * - * * - * Copyright (C) 2001 - Peter Ross * - * * - * For more information visit the XviD homepage: http://www.xvid.org * - * * - ******************************************************************************/ - - /****************************************************************************** - * * - * Revision history: * - * * - * 11.07.2002 add VOP width & height return to dec when dec->width * - * or dec->height is 0 (for use in examples/ex1.c) * - * MinChen * - * 22.05.2002 bs_put_matrix fix * - * 20.05.2002 added BitstreamWriteUserData * - * 19.06.2002 Fix a little bug in use custom quant matrix * - * MinChen * - * 08.05.2002 add low_delay support for B_VOP decode * - * MinChen * - * 06.05.2002 low_delay * - * 06.05.2002 fixed fincr/fbase error * - * 01.05.2002 added BVOP support to BitstreamWriteVopHeader * - * 15.04.2002 rewrite log2bin use asm386 By MinChen * - * 26.03.2002 interlacing support * - * 03.03.2002 qmatrix writing * - * 03.03.2002 merged BITREADER and BITWRITER * - * 30.02.2002 intra_dc_threshold support * - * 04.12.2001 support for additional headers * - * 16.12.2001 inital version * - * - ******************************************************************************/ - +/***************************************************************************** + * + * XVID MPEG-4 VIDEO CODEC + * - Bitstream reader/writer functions - + * + * Copyright (C) 2001-2002 - Peter Ross + * + * This program is an implementation of a part of one or more MPEG-4 + * Video tools as specified in ISO/IEC 14496-2 standard. Those intending + * to use this software module in hardware or software products are + * advised that its use may infringe existing patents or copyrights, and + * any such use would be at such party's own risk. The original + * developer of this software module and his/her company, and subsequent + * editors and their companies, will have no liability for use of this + * software or modifications or derivatives thereof. + * + * This program is free software ; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation ; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY ; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * 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.c,v 1.30 2002-09-12 19:06:37 edgomez Exp $ + * + ****************************************************************************/ #include "bitstream.h" #include "zigzag.h" #include "../quant/quant_matrix.h" +/***************************************************************************** + * Functions + ****************************************************************************/ static uint32_t __inline log2bin(uint32_t value) @@ -190,7 +161,7 @@ uint32_t coding_type; uint32_t start_code; uint32_t time_incr = 0; - int32_t time_increment; + int32_t time_increment = 0; do { BitstreamByteAlign(bs); @@ -446,13 +417,12 @@ if (vol_ver_id != 1) { - dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe - if (dec->quarterpel) { - DPRINTF(DPRINTF_ERROR, "quarter_sample not supported"); - } - } else { - dec->quarterpel = 0; + DEBUG("QUARTERPEL BITSTREAM"); + dec->quarterpel = BitstreamGetBit(bs); // quarter_sample } + else + dec->quarterpel = 0; + if (!BitstreamGetBit(bs)) // complexity_estimation_disable { @@ -715,19 +685,18 @@ BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) + BitstreamPutBit(bs, 1); // vol_control_parameters + BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" + #ifdef BFRAMES if (pParam->max_bframes > 0) { - //DPRINTF("low_delay=1"); - BitstreamPutBit(bs, 1); // vol_control_parameters - BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" BitstreamPutBit(bs, 0); // low_delay - BitstreamPutBit(bs, 0); // vbv_parameters (0=not given) } else #endif { - BitstreamPutBits(bs, 0, 1); // vol_control_parameters (0=not given) + BitstreamPutBit(bs, 1); // low_delay } - + BitstreamPutBit(bs, 0); // vbv_parameters (0=not given) BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) @@ -741,7 +710,7 @@ #ifdef BFRAMES BitstreamPutBits(bs, pParam->fbase, 16); #else - BitstreamPutBits(bs, 2, 16); + BitstreamPutBits(bs, pParam->fbase, 16); #endif WRITE_MARKER(); @@ -750,7 +719,8 @@ BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment #else - BitstreamPutBit(bs, 0); // fixed_vop_rate = 0 + BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 + BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment #endif WRITE_MARKER(); @@ -801,9 +771,8 @@ const FRAMEINFO * frame, int vop_coded) { -#ifdef BFRAMES uint32_t i; -#endif + BitstreamPad(bs); BitstreamPutBits(bs, VOP_START_CODE, 32); @@ -816,7 +785,11 @@ } BitstreamPutBit(bs, 0); #else - BitstreamPutBits(bs, 0, 1); + for (i = 0; i < frame->seconds; i++) { + BitstreamPutBit(bs, 1); + } + BitstreamPutBit(bs, 0); +// BitstreamPutBits(bs, 0, 1); #endif WRITE_MARKER(); @@ -828,7 +801,8 @@ frame->coding_type == I_VOP ? 'I' : frame->coding_type == P_VOP ? 'P' : 'B');*/ #else - BitstreamPutBits(bs, 1, 1); + BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); +// BitstreamPutBits(bs, 1, 1); #endif WRITE_MARKER(); @@ -859,20 +833,3 @@ BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code } - - -void -BitstreamWriteUserData(Bitstream * const bs, - uint8_t * data, - const int length) -{ - int i; - - BitstreamPad(bs); - BitstreamPutBits(bs, USERDATA_START_CODE, 32); - - for (i = 0; i < length; i++) { - BitstreamPutBits(bs, data[i], 8); - } - -}