[svn] / branches / dev-api-3 / xvidcore / src / bitstream / bitstream.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/bitstream/bitstream.c

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

revision 579, Sat Oct 5 21:37:44 2002 UTC revision 619, Sat Nov 2 15:52:31 2002 UTC
# Line 41  Line 41 
41    *                                                                            *    *                                                                            *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44      *  28.10.2002 GMC support - gruel                                                                                        *
45    *  04.10.2002 qpel support - Isibaar                                                                             *    *  04.10.2002 qpel support - Isibaar                                                                             *
46    *  11.07.2002 add VOP width & height return to dec when dec->width           *    *  11.07.2002 add VOP width & height return to dec when dec->width           *
47    *             or dec->height is 0  (for use in examples/ex1.c)               *    *             or dec->height is 0  (for use in examples/ex1.c)               *
# Line 68  Line 69 
69  #include "bitstream.h"  #include "bitstream.h"
70  #include "zigzag.h"  #include "zigzag.h"
71  #include "../quant/quant_matrix.h"  #include "../quant/quant_matrix.h"
72    #include "mbcoding.h"
73    
74    
75  static uint32_t __inline  static uint32_t __inline
# Line 579  Line 581 
581    
582                          // fix a little bug by MinChen <chenm002@163.com>                          // fix a little bug by MinChen <chenm002@163.com>
583                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&
584                                  (coding_type == P_VOP)) {                                  ( (coding_type == P_VOP) || (coding_type == S_VOP) ) ) {
585                                  *rounding = BitstreamGetBit(bs);        // rounding_type                                  *rounding = BitstreamGetBit(bs);        // rounding_type
586                                  DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding);                                  DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding);
587                          }                          }
# Line 702  Line 704 
704  void  void
705  BitstreamWriteVolHeader(Bitstream * const bs,  BitstreamWriteVolHeader(Bitstream * const bs,
706                                                  const MBParam * pParam,                                                  const MBParam * pParam,
707                                                  const FRAMEINFO * frame)                                                  const FRAMEINFO * const frame)
708  {  {
709            int vol_ver_id=1;
710    
711            if ( (pParam->m_quarterpel) || (frame->global_flags & XVID_GMC) )
712                    vol_ver_id = 2;
713    
714          // video object_start_code & vo_id          // video object_start_code & vo_id
715          BitstreamPad(bs);          BitstreamPad(bs);
716          BitstreamPutBits(bs, VO_START_CODE, 27);          BitstreamPutBits(bs, VO_START_CODE, 27);
# Line 716  Line 723 
723          BitstreamPutBit(bs, 0);         // random_accessible_vol          BitstreamPutBit(bs, 0);         // random_accessible_vol
724          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication
725    
726          if (pParam->m_quarterpel == 0)          if (vol_ver_id == 1)
727          {          {
728                  BitstreamPutBit(bs, 0);                         // is_object_layer_identified (0=not given)                  BitstreamPutBit(bs, 0);                         // is_object_layer_identified (0=not given)
729          }          }
730          else          else
731          {          {
732                  BitstreamPutBit(bs, 1);         // is_object_layer_identified                  BitstreamPutBit(bs, 1);         // is_object_layer_identified
733                  BitstreamPutBits(bs, 2, 4);     // vol_ver_id == 2                  BitstreamPutBits(bs, vol_ver_id, 4);    // vol_ver_id == 2
734                  BitstreamPutBits(bs, 0, 3); // vol_ver_priority = 0 ??                  BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==lowest, 7==highest) ??
735          }          }
736    
737          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)
# Line 732  Line 739 
739          BitstreamPutBit(bs, 1); // vol_control_parameters          BitstreamPutBit(bs, 1); // vol_control_parameters
740          BitstreamPutBits(bs, 1, 2);     // chroma_format 1="4:2:0"          BitstreamPutBits(bs, 1, 2);     // chroma_format 1="4:2:0"
741    
 #ifdef BFRAMES  
742          if (pParam->max_bframes > 0) {          if (pParam->max_bframes > 0) {
743                  BitstreamPutBit(bs, 0); // low_delay                  BitstreamPutBit(bs, 0); // low_delay
744          } else          } else
 #endif  
745          {          {
746                  BitstreamPutBit(bs, 1); // low_delay                  BitstreamPutBit(bs, 1); // low_delay
747          }          }
# Line 751  Line 756 
756             25fps        res=25      inc=1             25fps        res=25      inc=1
757             29.97fps res=30000   inc=1001             29.97fps res=30000   inc=1001
758           */           */
 #ifdef BFRAMES  
759          BitstreamPutBits(bs, pParam->fbase, 16);          BitstreamPutBits(bs, pParam->fbase, 16);
 #else  
         BitstreamPutBits(bs, pParam->fbase, 16);  
 #endif  
760    
761          WRITE_MARKER();          WRITE_MARKER();
762    
 #ifdef BFRAMES  
763          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
764          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, 1);         // fixed_vop_rate = 1  
         BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment  
 #endif  
765    
766          WRITE_MARKER();          WRITE_MARKER();
767          BitstreamPutBits(bs, pParam->width, 13);        // width          BitstreamPutBits(bs, pParam->width, 13);        // width
# Line 776  Line 772 
772          BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING);    // interlace          BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING);    // interlace
773          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)
774    
775          if (pParam->m_quarterpel == 0)          if (vol_ver_id != 1)
776          {          {       if (frame->global_flags & XVID_GMC)
777                  BitstreamPutBit(bs, 0);         // sprite_enable                  {       BitstreamPutBits(bs, 2, 2);             // sprite_enable=='GMC'
778                            BitstreamPutBits(bs, 2, 6);             // no_of_sprite_warping_points
779                            BitstreamPutBits(bs, 3, 2);             // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16
780                            BitstreamPutBit(bs, 0);                 // sprite_brightness_change (not supported)
781    
782    /* currently we use no_of_sprite_warping_points==2, sprite_warping_accuracy==3
783       for DivX5 compatability */
784    
785                    } else
786                            BitstreamPutBits(bs, 0, 2);             // sprite_enable==off
787          }          }
788          else          else
789          {                  BitstreamPutBit(bs, 0);         // sprite_enable==off
                 BitstreamPutBits(bs, 0, 2);             // sprite_enable  
         }  
790    
791          BitstreamPutBit(bs, 0);         // not_in_bit          BitstreamPutBit(bs, 0);         // not_8_bit
792    
793          // quant_type   0=h.263  1=mpeg4(quantizer tables)          // quant_type   0=h.263  1=mpeg4(quantizer tables)
794          BitstreamPutBit(bs, pParam->m_quant_type);          BitstreamPutBit(bs, pParam->m_quant_type);
# Line 803  Line 806 
806    
807          }          }
808    
809            if (vol_ver_id != 1) {
810          if (pParam->m_quarterpel)          if (pParam->m_quarterpel)
811          {                          BitstreamPutBit(bs, 1);         //  quarterpel
812                  BitstreamPutBit(bs, 1);                  else
813                            BitstreamPutBit(bs, 0);         // no quarterpel
814          }          }
815    
816          BitstreamPutBit(bs, 1);         // complexity_estimation_disable          BitstreamPutBit(bs, 1);         // complexity_estimation_disable
817          BitstreamPutBit(bs, 1);         // resync_marker_disable          BitstreamPutBit(bs, 1);         // resync_marker_disable
818          BitstreamPutBit(bs, 0);         // data_partitioned          BitstreamPutBit(bs, 0);         // data_partitioned
819    
820          if (pParam->m_quarterpel)          if (vol_ver_id != 1)
821          {          {
822                  BitstreamPutBit(bs, 0);         // newpred_enable                  BitstreamPutBit(bs, 0);         // newpred_enable
823                  BitstreamPutBit(bs, 0);         // reduced_resolution_vop_enabled                  BitstreamPutBit(bs, 0);         // reduced_resolution_vop_enabled
824          }          }
825    
826          BitstreamPutBit(bs, 0);         // scalability          BitstreamPutBit(bs, 0);         // scalability
827    
828  }  }
829    
830    
831  /*  /*
832    write vop header    write vop header
   
   NOTE: doesnt handle bother with time_base & time_inc  
   time_base = n seconds since last resync (eg. last iframe)  
   time_inc = nth of a second since last resync  
   (decoder uses these values to determine precise time since last resync)  
833  */  */
834  void  void
835  BitstreamWriteVopHeader(Bitstream * const bs,  BitstreamWriteVopHeader(Bitstream * const bs,
836                                                  const MBParam * pParam,                                                  const MBParam * pParam,
837                                                  const FRAMEINFO * frame,                                                  const FRAMEINFO * const frame,
838                                                  int vop_coded)                                                  int vop_coded)
839  {  {
840          uint32_t i;          uint32_t i;
# Line 843  Line 844 
844    
845          BitstreamPutBits(bs, frame->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
846    
 #ifdef BFRAMES  
         for (i = 0; i < frame->seconds; i++) {  
                 BitstreamPutBit(bs, 1);  
         }  
         BitstreamPutBit(bs, 0);  
 #else  
847          for (i = 0; i < frame->seconds; i++) {          for (i = 0; i < frame->seconds; i++) {
848                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
849          }          }
850          BitstreamPutBit(bs, 0);          BitstreamPutBit(bs, 0);
 //      BitstreamPutBits(bs, 0, 1);  
 #endif  
851    
852          WRITE_MARKER();          WRITE_MARKER();
853    
854          // time_increment: value=nth_of_sec, nbits = log2(resolution)          // time_increment: value=nth_of_sec, nbits = log2(resolution)
855  #ifdef BFRAMES  
856          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));
857          /*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks,          /*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks,
858                          frame->coding_type == I_VOP ? 'I' : frame->coding_type ==                          frame->coding_type == I_VOP ? 'I' : frame->coding_type ==
859                          P_VOP ? 'P' : 'B');*/                          P_VOP ? 'P' : 'B');*/
 #else  
         BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));  
 //      BitstreamPutBits(bs, 1, 1);  
 #endif  
860    
861          WRITE_MARKER();          WRITE_MARKER();
862    
# Line 878  Line 867 
867    
868          BitstreamPutBits(bs, 1, 1);     // vop_coded          BitstreamPutBits(bs, 1, 1);     // vop_coded
869    
870          if (frame->coding_type == P_VOP)          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )
871                  BitstreamPutBits(bs, frame->rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
872    
873          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold
# Line 888  Line 877 
877                  BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN));                  BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN));
878          }          }
879    
880            if (frame->coding_type == S_VOP) {
881                    if (1)  {               // no_of_sprite_warping_points>=1
882                            if (pParam->m_quarterpel)
883                                    bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0]
884                            else
885                                    bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0]
886                            WRITE_MARKER();
887    
888                            if (pParam->m_quarterpel)
889                                    bs_put_spritetrajectory(bs, frame->GMC_MV.y/2 ); // dv[0]
890                            else
891                                    bs_put_spritetrajectory(bs, frame->GMC_MV.y ); // dv[0]
892                            WRITE_MARKER();
893                    }
894    /* GMC is halfpel in bitstream, even though GMC_MV was pseudo-qpel (2*halfpel) */
895    
896                    if (2) {                // no_of_sprite_warping_points>=2 (for DivX5 compat)
897                            bs_put_spritetrajectory(bs, 0 );
898                            WRITE_MARKER();
899                            bs_put_spritetrajectory(bs, 0 );
900                            WRITE_MARKER();
901                    }
902                    // no support for brightness_change!
903            }
904    
905          BitstreamPutBits(bs, frame->quant, 5);  // quantizer          BitstreamPutBits(bs, frame->quant, 5);  // quantizer
906    
907          if (frame->coding_type != I_VOP)          if (frame->coding_type != I_VOP)
# Line 898  Line 912 
912    
913  }  }
914    
   
915  void  void
916  BitstreamWriteUserData(Bitstream * const bs,  BitstreamWriteUserData(Bitstream * const bs,
917                                                  uint8_t * data,                                                  uint8_t * data,

Legend:
Removed from v.579  
changed lines
  Added in v.619

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