[svn] / trunk / xvidcore / src / bitstream / bitstream.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/bitstream/bitstream.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 294, Fri Jul 12 00:49:59 2002 UTC revision 514, Sun Sep 22 17:01:36 2002 UTC
# Line 1  Line 1 
1   /******************************************************************************  /*****************************************************************************
   *                                                                            *  
   *  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 <pross@cs.rmit.edu.au>                    *  
   *                                                                            *  
   *  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 <chenm001@163.com>                                     *  
   *  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 <chenm001@163.com>                                    *  
   *  08.05.2002  add low_delay support for B_VOP decode                        *  
   *              MinChen <chenm001@163.com>                                    *  
   *  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 <chenm001@163.com>      *  
   *  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                                         *  
2    *    *
3    ******************************************************************************/   *  XVID MPEG-4 VIDEO CODEC
4     *  - Bitstream reader/writer functions -
5     *
6     *  Copyright (C) 2001-2002 - Peter Ross <pross@xvid.org>
7     *
8     *  This program is an implementation of a part of one or more MPEG-4
9     *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
10     *  to use this software module in hardware or software products are
11     *  advised that its use may infringe existing patents or copyrights, and
12     *  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     *  editors and their companies, will have no liability for use of this
15     *  software or modifications or derivatives thereof.
16     *
17     *  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     *  the Free Software Foundation ; either version 2 of the License, or
20     *  (at your option) any later version.
21     *
22     *  This program is distributed in the hope that it will be useful,
23     *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
24     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25     *  GNU General Public License for more details.
26     *
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.c,v 1.33 2002-09-22 17:01:36 edgomez Exp $
32     *
33     ****************************************************************************/
34    
35  #include "bitstream.h"  #include "bitstream.h"
36  #include "zigzag.h"  #include "zigzag.h"
37  #include "../quant/quant_matrix.h"  #include "../quant/quant_matrix.h"
38    
39    /*****************************************************************************
40     * Functions
41     ****************************************************************************/
42    
43  static uint32_t __inline  static uint32_t __inline
44  log2bin(uint32_t value)  log2bin(uint32_t value)
# Line 190  Line 161 
161          uint32_t coding_type;          uint32_t coding_type;
162          uint32_t start_code;          uint32_t start_code;
163          uint32_t time_incr = 0;          uint32_t time_incr = 0;
164          int32_t time_increment;          int32_t time_increment = 0;
165    
166          do {          do {
167                  BitstreamByteAlign(bs);                  BitstreamByteAlign(bs);
# Line 330  Line 301 
301    
302                          DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution);                          DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution);
303    
304                          time_increment_resolution--;  //                      time_increment_resolution--;
305    
306                          if (time_increment_resolution > 0) {                          if (time_increment_resolution > 0) {
307                                  dec->time_inc_bits = log2bin(time_increment_resolution);                                  dec->time_inc_bits = log2bin(time_increment_resolution-1);
308                          } else {                          } else {
309                                  // dec->time_inc_bits = 0;                                  // dec->time_inc_bits = 0;
310                                  // for "old" xvid compatibility, set time_inc_bits = 1                                  // for "old" xvid compatibility, set time_inc_bits = 1
# Line 446  Line 417 
417    
418    
419                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
420                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sampe                                          DPRINTF(DPRINTF_DEBUG, "QUARTERPEL BITSTREAM");
421                                          if (dec->quarterpel) {                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sample
                                                 DPRINTF(DPRINTF_ERROR, "quarter_sample not supported");  
422                                          }                                          }
423                                  } else {                                  else
424                                          dec->quarterpel = 0;                                          dec->quarterpel = 0;
425                                  }  
426    
427                                  if (!BitstreamGetBit(bs))       // complexity_estimation_disable                                  if (!BitstreamGetBit(bs))       // complexity_estimation_disable
428                                  {                                  {
# Line 547  Line 517 
517                          if (coding_type != B_VOP) {                          if (coding_type != B_VOP) {
518                                  dec->last_time_base = dec->time_base;                                  dec->last_time_base = dec->time_base;
519                                  dec->time_base += time_incr;                                  dec->time_base += time_incr;
520                                  dec->time =                                  dec->time = time_increment;
521                                          dec->time_base * time_increment_resolution +  
522    /*                                      dec->time_base * time_increment_resolution +
523                                          time_increment;                                          time_increment;
524                                  dec->time_pp = (uint32_t) (dec->time - dec->last_non_b_time);  */                              dec->time_pp = (uint32_t)
525                                            (time_increment_resolution + dec->time - dec->last_non_b_time)%time_increment_resolution;
526                                  dec->last_non_b_time = dec->time;                                  dec->last_non_b_time = dec->time;
527                          } else {                          } else {
528                                  dec->time =                                  dec->time = time_increment;
529    /*
530                                          (dec->last_time_base +                                          (dec->last_time_base +
531                                           time_incr) * time_increment_resolution + time_increment;                                           time_incr) * time_increment_resolution + time_increment;
532                                  dec->time_bp = (uint32_t) (dec->last_non_b_time - dec->time);  */
533                                    dec->time_bp = (uint32_t)
534                                            (time_increment_resolution + dec->last_non_b_time - dec->time)%time_increment_resolution;
535                          }                          }
536    
537                          READ_MARKER();                          READ_MARKER();
# Line 710  Line 685 
685          BitstreamPutBit(bs, 0);         // is_object_layer_identified (0=not given)          BitstreamPutBit(bs, 0);         // is_object_layer_identified (0=not given)
686          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)
687    
 #ifdef BFRAMES  
         if (pParam->max_bframes > 0) {  
                 //DPRINTF("low_delay=1");  
688                  BitstreamPutBit(bs, 1); // vol_control_parameters                  BitstreamPutBit(bs, 1); // vol_control_parameters
689                  BitstreamPutBits(bs, 1, 2);     // chroma_format 1="4:2:0"                  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)  
         }  
690    
691            BitstreamPutBit(bs, 1); // low_delay
692    
693            BitstreamPutBit(bs, 0); // vbv_parameters (0=not given)
694    
695          BitstreamPutBits(bs, 0, 2);     // video_object_layer_shape (0=rectangular)          BitstreamPutBits(bs, 0, 2);     // video_object_layer_shape (0=rectangular)
696    
697          WRITE_MARKER();          WRITE_MARKER();
698    
699          /* time_increment_resolution; ignored by current decore versions          /*
700             eg. 2fps     res=2       inc=1           * time_increment_resolution; ignored by current decore versions
701             25fps        res=25      inc=1           *  eg. 2fps     res=2       inc=1
702             29.97fps res=30000   inc=1001           *      25fps    res=25      inc=1
703             *      29.97fps res=30000   inc=1001
704           */           */
 #ifdef BFRAMES  
705          BitstreamPutBits(bs, pParam->fbase, 16);          BitstreamPutBits(bs, pParam->fbase, 16);
706  #else  
         BitstreamPutBits(bs, 2, 16);  
 #endif  
707    
708          WRITE_MARKER();          WRITE_MARKER();
709    
 #ifdef BFRAMES  
710          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
711          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment
 #else  
         BitstreamPutBit(bs, 0);         // fixed_vop_rate = 0  
 #endif  
712    
713          WRITE_MARKER();          WRITE_MARKER();
714          BitstreamPutBits(bs, pParam->width, 13);        // width          BitstreamPutBits(bs, pParam->width, 13);        // width
# Line 796  Line 758 
758                                                  const FRAMEINFO * frame,                                                  const FRAMEINFO * frame,
759                                                  int vop_coded)                                                  int vop_coded)
760  {  {
 #ifdef BFRAMES  
761          uint32_t i;          uint32_t i;
762  #endif  
763          BitstreamPad(bs);          BitstreamPad(bs);
764          BitstreamPutBits(bs, VOP_START_CODE, 32);          BitstreamPutBits(bs, VOP_START_CODE, 32);
765    
766          BitstreamPutBits(bs, frame->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
767    
768          // time_base = 0  write n x PutBit(1), PutBit(0)          // time_base = 0  write n x PutBit(1), PutBit(0)
 #ifdef BFRAMES  
769          for (i = 0; i < frame->seconds; i++) {          for (i = 0; i < frame->seconds; i++) {
770                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
771          }          }
772          BitstreamPutBit(bs, 0);          BitstreamPutBit(bs, 0);
 #else  
         BitstreamPutBits(bs, 0, 1);  
 #endif  
773    
774          WRITE_MARKER();          WRITE_MARKER();
775    
776          // time_increment: value=nth_of_sec, nbits = log2(resolution)          // time_increment: value=nth_of_sec, nbits = log2(resolution)
 #ifdef BFRAMES  
777          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));
         /*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks,  
                         frame->coding_type == I_VOP ? 'I' : frame->coding_type ==  
                         P_VOP ? 'P' : 'B');*/  
 #else  
         BitstreamPutBits(bs, 1, 1);  
 #endif  
778    
779          WRITE_MARKER();          WRITE_MARKER();
780    
# Line 854  Line 804 
804                  BitstreamPutBits(bs, frame->bcode, 3);  // backward_fixed_code                  BitstreamPutBits(bs, frame->bcode, 3);  // backward_fixed_code
805    
806  }  }
   
   
 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);  
         }  
   
 }  

Legend:
Removed from v.294  
changed lines
  Added in v.514

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4