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

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

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

revision 1.1, Fri Mar 8 02:44:34 2002 UTC revision 1.8, Wed May 1 13:00:02 2002 UTC
# Line 41  Line 41 
41    *                                                                                                                                                        *    *                                                                                                                                                        *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44      *  01.05.2002 added BVOP support to BitstreamWriteVopHeader
45      *  15.04.2002 rewrite log2bin use asm386  By MinChen <chenm001@163.com>      *
46      *  26.03.2002 interlacing support                                                                                        *
47    *  03.03.2002 qmatrix writing                                                                                            *    *  03.03.2002 qmatrix writing                                                                                            *
48    *  03.03.2002 merged BITREADER and BITWRITER                                                             *    *  03.03.2002 merged BITREADER and BITWRITER                                                             *
49    *      30.02.2002     intra_dc_threshold support                                                                         *    *      30.02.2002     intra_dc_threshold support                                                                         *
# Line 52  Line 55 
55    
56  #include "bitstream.h"  #include "bitstream.h"
57  #include "zigzag.h"  #include "zigzag.h"
58    #include "../quant/quant_matrix.h"
59    
60    
61  static int __inline log2bin(int value)  static int __inline log2bin(int value)
62  {  {
63    /* Changed by Chenm001 */
64    #ifndef WIN32
65          int n = 0;          int n = 0;
66          while (value)          while (value)
67          {          {
# Line 63  Line 69 
69                  n++;                  n++;
70          }          }
71          return n;          return n;
72    #else
73            __asm{
74                    bsr eax,value
75                    inc eax
76            }
77    #endif
78  }  }
79    
80    
# Line 79  Line 91 
91  };  };
92    
93    
94    void bs_get_matrix(Bitstream * bs, uint8_t * matrix)
95    {
96            int i = 0;
97        int last, value = 0;
98    
99        do
100            {
101                    last = value;
102            value = BitstreamGetBits(bs, 8);
103            matrix[ scan_tables[0][i++] ]  = value;
104        }
105        while (value != 0 && i < 64);
106    
107            while (i < 64)
108            {
109                    matrix[ scan_tables[0][i++] ]  = last;
110            }
111    }
112    
113  /*  /*
114  decode headers  decode headers
115  returns coding_type, or -1 if error  returns coding_type, or -1 if error
# Line 264  Line 295 
295    
296                                  }                                  }
297    
298                                  if (BitstreamGetBit(bs))                                // interlaced                                  if ((dec->interlacing = BitstreamGetBit(bs)))
299                                  {                                  {
300                                          DEBUG("TODO: interlaced");                                          DEBUG("vol: interlacing");
                                         // TODO  
                                         return -1;  
301                                  }                                  }
302    
303                                  if (!BitstreamGetBit(bs))                               // obmc_disable                                  if (!BitstreamGetBit(bs))                               // obmc_disable
# Line 314  Line 343 
343                                  {                                  {
344                                          if (BitstreamGetBit(bs))                // load_intra_quant_mat                                          if (BitstreamGetBit(bs))                // load_intra_quant_mat
345                                          {                                          {
346                                                  DEBUG("TODO: load_intra_quant_mat");                                                  uint8_t matrix[64];
347                                                  // TODO                                                  bs_get_matrix(bs, matrix);
348                                                  return -1;                                                  set_intra_matrix(matrix);
349                                          }                                          }
350                                            else
351                                                    set_intra_matrix(get_default_intra_matrix());
352    
353                                          if (BitstreamGetBit(bs))                // load_inter_quant_mat                                          if (BitstreamGetBit(bs))                // load_inter_quant_mat
354                                          {                                          {
355                                                  DEBUG("TODO: load_inter_quant_mat");                                                  uint8_t matrix[64];
356                                                  // TODO                                                  bs_get_matrix(bs, matrix);
357                                                  return -1;                                                  set_inter_matrix(matrix);
358                                          }                                          }
359                                            else
360                                                    set_inter_matrix(get_default_inter_matrix());
361    
362                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)
363                                          {                                          {
# Line 331  Line 365 
365                                                  DEBUG("TODO: grayscale matrix stuff");                                                  DEBUG("TODO: grayscale matrix stuff");
366                                                  return -1;                                                  return -1;
367                                          }                                          }
368    
369                                  }                                  }
370    
371    
# Line 492  Line 527 
527                                  // intra_dc_vlc_threshold                                  // intra_dc_vlc_threshold
528                                  *intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ];                                  *intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ];
529    
530                                  /* if (interlaced)                                  if (dec->interlacing)
531                                          {                                          {
532                                                  BitstreamSkip(bs, 1);           // top_field_first                                          if ((dec->top_field_first = BitstreamGetBit(bs)))
533                                                  BitstreamSkip(bs, 1);           // alternative_vertical_scan_flag                                          {
534                                  */                                                  DEBUG("vop: top_field_first");
535                                            }
536                                            if ((dec->alternate_vertical_scan = BitstreamGetBit(bs)))
537                                            {
538                                                    DEBUG("vop: alternate_vertical_scan");
539                                            }
540                                    }
541                          }                          }
542    
543                          *quant = BitstreamGetBits(bs, dec->quant_bits);         // vop_quant                          *quant = BitstreamGetBits(bs, dec->quant_bits);         // vop_quant
# Line 559  Line 600 
600          write vol header          write vol header
601  */  */
602  void BitstreamWriteVolHeader(Bitstream * const bs,  void BitstreamWriteVolHeader(Bitstream * const bs,
603                                                  const int width,                                                  const MBParam * pParam,  const FRAMEINFO * frame)
                                                 const int height,  
                                                 const int quant_type)  
604  {  {
605          // video object_start_code & vo_id          // video object_start_code & vo_id
606      BitstreamPad(bs);      BitstreamPad(bs);
# Line 597  Line 636 
636          // BitstreamPutBits(bs, 0, 15);          // BitstreamPutBits(bs, 0, 15);
637    
638          WRITE_MARKER();          WRITE_MARKER();
639          BitstreamPutBits(bs, width, 13);                // width          BitstreamPutBits(bs, pParam->width, 13);                // width
640          WRITE_MARKER();          WRITE_MARKER();
641          BitstreamPutBits(bs, height, 13);               // height          BitstreamPutBits(bs, pParam->height, 13);               // height
642          WRITE_MARKER();          WRITE_MARKER();
643    
644          BitstreamPutBit(bs, 0);         // interlace          BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING);            // interlace
645          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)
646          BitstreamPutBit(bs, 0);         // sprite_enable          BitstreamPutBit(bs, 0);         // sprite_enable
647          BitstreamPutBit(bs, 0);         // not_in_bit          BitstreamPutBit(bs, 0);         // not_in_bit
648    
649          // quant_type   0=h.263  1=mpeg4(quantizer tables)          // quant_type   0=h.263  1=mpeg4(quantizer tables)
650          BitstreamPutBit(bs, quant_type);          BitstreamPutBit(bs, pParam->m_quant_type);
651  /*  
652          if (quant_type)          if (pParam->m_quant_type)
653          {          {
654                  BitstreamPutBit(bs, qmatrix->custom_intra);             // load_intra_quant_mat                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat
655                  if (qmatrix->custom_intra)                  if (get_intra_matrix_status())
656                  {                  {
657                          bs_put_matrix(bs, qmatrix->intra);                          bs_put_matrix(bs, get_intra_matrix());
658                  }                  }
659    
660                  BitstreamPutBit(bs, qmatrix->custom_inter);             // load_inter_quant_mat                  BitstreamPutBit(bs, get_inter_matrix_status());         // load_inter_quant_mat
661                  if (qmatrix->custom_inter)                  if (get_inter_matrix_status())
662                  {                  {
663                          bs_put_matrix(bs, qmatrix->inter);                          bs_put_matrix(bs, get_inter_matrix());
664                  }                  }
665    
666          }          }
 */  
         if (quant_type)  
         {  
                 BitstreamPutBit(bs, 0);         // load_intra_quant_mat  
                 BitstreamPutBit(bs, 0);         // load_inter_quant_mat  
         }  
667    
668          BitstreamPutBit(bs, 1);         // complexity_estimation_disable          BitstreamPutBit(bs, 1);         // complexity_estimation_disable
669          BitstreamPutBit(bs, 1);         // resync_marker_disable          BitstreamPutBit(bs, 1);         // resync_marker_disable
# Line 648  Line 681 
681    (decoder uses these values to determine precise time since last resync)    (decoder uses these values to determine precise time since last resync)
682  */  */
683  void BitstreamWriteVopHeader(Bitstream * const bs,  void BitstreamWriteVopHeader(Bitstream * const bs,
684                            VOP_TYPE prediction_type,                                                  const MBParam * pParam,
685                            const int rounding_type,                                                  const FRAMEINFO * frame)
                           const uint32_t quant,  
                           const uint32_t fcode)  
686  {  {
687    #ifdef BFRAMES
688            uint32_t i;
689    #endif
690      BitstreamPad(bs);      BitstreamPad(bs);
691      BitstreamPutBits(bs, VOP_START_CODE, 32);      BitstreamPutBits(bs, VOP_START_CODE, 32);
692    
693      BitstreamPutBits(bs, prediction_type, 2);      BitstreamPutBits(bs, frame->coding_type, 2);
694    
695          // time_base = 0  write n x PutBit(1), PutBit(0)          // time_base = 0  write n x PutBit(1), PutBit(0)
696    #ifdef BFRAMES
697            for (i = 0; i < frame->seconds; i++)
698            {
699                    BitstreamPutBit(bs, 1);
700            }
701            BitstreamPutBit(bs, 0);
702    #else
703          BitstreamPutBits(bs, 0, 1);          BitstreamPutBits(bs, 0, 1);
704    #endif
705    
706          WRITE_MARKER();          WRITE_MARKER();
707    
708          // time_increment: value=nth_of_sec, nbits = log2(resolution)          // time_increment: value=nth_of_sec, nbits = log2(resolution)
709    #ifdef BFRAMES
710            BitstreamPutBits(bs, frame->ticks, 5);
711            dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, frame->coding_type == I_VOP ? 'I' : frame->coding_type == P_VOP ? 'P' : 'B');
712    #else
713          BitstreamPutBits(bs, 1, 1);          BitstreamPutBits(bs, 1, 1);
714    #endif
715    
716          WRITE_MARKER();          WRITE_MARKER();
717    
718          BitstreamPutBits(bs, 1, 1);                             // vop_coded          BitstreamPutBits(bs, 1, 1);                             // vop_coded
719    
720          if (prediction_type != I_VOP)          if (frame->coding_type != I_VOP)
721                  BitstreamPutBits(bs, rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
722    
723          BitstreamPutBits(bs, 0, 3);                             // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);                             // intra_dc_vlc_threshold
724    
725          BitstreamPutBits(bs, quant, 5);                 // quantizer          if (frame->global_flags & XVID_INTERLACING)
726            {
727                    BitstreamPutBit(bs, 1);         // top field first
728                    BitstreamPutBit(bs, 0);         // alternate vertical scan
729            }
730    
731            BitstreamPutBits(bs, frame->quant, 5);                  // quantizer
732    
733            if (frame->coding_type != I_VOP)
734                    BitstreamPutBits(bs, frame->fcode, 3);          // forward_fixed_code
735    
736            if (frame->coding_type == B_VOP)
737                    BitstreamPutBits(bs, frame->bcode, 3);          // backward_fixed_code
738    
         if (prediction_type != I_VOP)  
                 BitstreamPutBits(bs, fcode, 3);         // fixed_code = [1,4]  
739  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

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