[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.28.2.7, Sun Dec 8 05:36:20 2002 UTC revision 1.28.2.19, Tue Jan 14 10:30:39 2003 UTC
# Line 41  Line 41 
41    *                                                                            *    *                                                                            *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44    *  28.10.2002 GMC support - gruel                                                                                        *    *  05.01.2003 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 67  Line 67 
67    
68    
69  #include <string.h>  #include <string.h>
70    #include <stdio.h>
71    
72  #include "bitstream.h"  #include "bitstream.h"
73  #include "zigzag.h"  #include "zigzag.h"
74  #include "../quant/quant_matrix.h"  #include "../quant/quant_matrix.h"
# Line 77  Line 79 
79  log2bin(uint32_t value)  log2bin(uint32_t value)
80  {  {
81  /* Changed by Chenm001 */  /* Changed by Chenm001 */
82  #ifndef WIN32  #if !defined(_MSC_VER)
83          int n = 0;          int n = 0;
84    
85          while (value) {          while (value) {
# Line 171  Line 173 
173    
174          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
175          {          {
176                  *quant = BitstreamGetBits(bs, 5);       /* quant_scale */                  *quant = BitstreamGetBits(bs, dec->quant_bits); /* quant_scale */
177                  DPRINTF(DPRINTF_HEADER, "quant %i", *quant);                  DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
178          }          }
179    
# Line 228  Line 230 
230                          if (coding_type == B_VOP && fcode_backward)                          if (coding_type == B_VOP && fcode_backward)
231                          {                          {
232                                  *fcode_backward = BitstreamGetBits(bs, 3);                                  *fcode_backward = BitstreamGetBits(bs, 3);
233                                  DPRINTF(DPRINTF_HEADER,"fcode_backward %i", fcode_backward);                                  DPRINTF(DPRINTF_HEADER,"fcode_backward %i", *fcode_backward);
234                          }                          }
235                  }                  }
236    
# Line 324  Line 326 
326  {  {
327          ESTIMATION * e = &dec->estimation;          ESTIMATION * e = &dec->estimation;
328    
329          if (e->method == 0)          if (e->method == 0 || e->method == 1)
330          {          {
331                  if (coding_type == I_VOP) {                  if (coding_type == I_VOP) {
332                          if (e->opaque)          BitstreamSkip(bs, 8);   /* dcecs_opaque */                          if (e->opaque)          BitstreamSkip(bs, 8);   /* dcecs_opaque */
# Line 430  Line 432 
432                                           uint32_t * fcode_forward,                                           uint32_t * fcode_forward,
433                                           uint32_t * fcode_backward,                                           uint32_t * fcode_backward,
434                                           uint32_t * intra_dc_threshold,                                           uint32_t * intra_dc_threshold,
435                                           VECTOR * gmc_mv)                                           WARPPOINTS *gmc_warp)
436  {  {
437          uint32_t vol_ver_id;          uint32_t vol_ver_id;
438          uint32_t coding_type;          uint32_t coding_type;
# Line 462  Line 464 
464                          DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>");                          DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>");
465    
466                  } else if (start_code == VISOBJ_START_CODE) {                  } else if (start_code == VISOBJ_START_CODE) {
467                            int visobj_ver_id;
468    
469                          DPRINTF(DPRINTF_STARTCODE, "<visual_object>");                          DPRINTF(DPRINTF_STARTCODE, "<visual_object>");
470    
471                          BitstreamSkip(bs, 32);  // visual_object_start_code                          BitstreamSkip(bs, 32);  // visual_object_start_code
472                          if (BitstreamGetBit(bs))        // is_visual_object_identified                          if (BitstreamGetBit(bs))        // is_visual_object_identified
473                          {                          {
474                                  vol_ver_id = BitstreamGetBits(bs, 4);   // visual_object_ver_id                                  visobj_ver_id = BitstreamGetBits(bs, 4);        // visual_object_ver_id
475                                  DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id);                                  DPRINTF(DPRINTF_HEADER,"visobj_ver_id %i", visobj_ver_id);
476                                  BitstreamSkip(bs, 3);   // visual_object_priority                                  BitstreamSkip(bs, 3);   // visual_object_priority
477                          } else {                          } else {
478                                  vol_ver_id = 1;                                  visobj_ver_id = 1;
479                          }                          }
480    
481                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type
# Line 568  Line 571 
571                                          BitstreamSkip(bs, 15);  // latter_half_vbv_occupancy                                          BitstreamSkip(bs, 15);  // latter_half_vbv_occupancy
572                                          READ_MARKER();                                          READ_MARKER();
573                                  }                                  }
574                            }else{
575                                    dec->low_delay = dec->low_delay_default;
576                          }                          }
577    
578                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape
# Line 822  Line 827 
827                                  READ_MARKER();                                  READ_MARKER();
828                                  seconds = BitstreamGetBits(bs, 6);                                  seconds = BitstreamGetBits(bs, 6);
829    
830                                  DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours);                                  DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours,minutes,seconds);
831                          }                          }
832                          BitstreamSkip(bs, 1);   // closed_gov                          BitstreamSkip(bs, 1);   // closed_gov
833                          BitstreamSkip(bs, 1);   // broken_link                          BitstreamSkip(bs, 1);   // broken_link
# Line 872  Line 877 
877                                  dec->time_bp = (uint32_t)                                  dec->time_bp = (uint32_t)
878                                          (dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution;                                          (dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution;
879                          }                          }
880                            DPRINTF(DPRINTF_HEADER,"time_pp=%i", dec->time_pp);
881                            DPRINTF(DPRINTF_HEADER,"time_bp=%i", dec->time_bp);
882    
883                          READ_MARKER();                          READ_MARKER();
884    
# Line 994  Line 1001 
1001                                          }                                          }
1002                                          READ_MARKER();                                          READ_MARKER();
1003    
1004                                          gmc_mv[i].x = x;                                          gmc_warp->duv[i].x = x;
1005                                          gmc_mv[i].y = y;                                          gmc_warp->duv[i].y = y;
1006    
1007                                          DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y);                                          DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y);
1008                                  }                                  }
# Line 1034  Line 1041 
1041    
1042                  } else if (start_code == USERDATA_START_CODE) {                  } else if (start_code == USERDATA_START_CODE) {
1043                          char tmp[256];                          char tmp[256];
1044                      int i, version, build, packed;                      int i, version, build;
1045                            char packed;
1046    
1047                          BitstreamSkip(bs, 32);  // user_data_start_code                          BitstreamSkip(bs, 32);  // user_data_start_code
1048    
# Line 1107  Line 1115 
1115                                                  const MBParam * pParam,                                                  const MBParam * pParam,
1116                                                  const FRAMEINFO * const frame)                                                  const FRAMEINFO * const frame)
1117  {  {
1118            static const unsigned int vo_id = 0;
1119            static const unsigned int vol_id = 0;
1120          int vol_ver_id=1;          int vol_ver_id=1;
1121            int profile = 0x03;     /* simple profile/level 3 */
1122    
1123          if ( (pParam->m_quarterpel) || (frame->global_flags & XVID_GMC) )          if ( pParam->m_quarterpel ||  (frame->global_flags & XVID_GMC) ||
1124                     (pParam->global & XVID_GLOBAL_REDUCED))
1125                  vol_ver_id = 2;                  vol_ver_id = 2;
1126    
1127            if ((pParam->global & XVID_GLOBAL_REDUCED))
1128                    profile = 0x93; /* advanced realtime simple profile/level 3 */
1129    
1130            if (pParam->m_quarterpel ||  (frame->global_flags & XVID_GMC))
1131                    profile = 0xf3; /* advanced simple profile/level 2 */
1132    
1133            // visual_object_sequence_start_code
1134    //      BitstreamPad(bs);
1135    /* no padding here, anymore. You have to make sure that you are
1136       byte aligned, and that always 1-8 padding bits have been written */
1137    
1138            BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32);
1139            BitstreamPutBits(bs, profile, 8);
1140    
1141            // visual_object_start_code
1142            BitstreamPad(bs);
1143            BitstreamPutBits(bs, VISOBJ_START_CODE, 32);
1144            BitstreamPutBits(bs, 0, 1);             // is_visual_object_identifier
1145            BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4);             // visual_object_type
1146    
1147          // video object_start_code & vo_id          // video object_start_code & vo_id
1148          BitstreamPad(bs);          BitstreamPad(bs);
1149          BitstreamPutBits(bs, VO_START_CODE, 27);          BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32);
         BitstreamPutBits(bs, 0, 5);  
1150    
1151          // video_object_layer_start_code & vol_id          // video_object_layer_start_code & vol_id
1152          BitstreamPutBits(bs, VOL_START_CODE, 28);          BitstreamPad(bs);
1153          BitstreamPutBits(bs, 0, 4);          BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32);
1154    
1155          BitstreamPutBit(bs, 0);         // random_accessible_vol          BitstreamPutBit(bs, 0);         // random_accessible_vol
1156          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication
# Line 1221  Line 1252 
1252          if (vol_ver_id != 1)          if (vol_ver_id != 1)
1253          {          {
1254                  BitstreamPutBit(bs, 0);         // newpred_enable                  BitstreamPutBit(bs, 0);         // newpred_enable
1255                  BitstreamPutBit(bs, 0);         // reduced_resolution_vop_enabled  
1256                    BitstreamPutBit(bs, (pParam->global & XVID_GLOBAL_REDUCED)?1:0);
1257                                                                            /* reduced_resolution_vop_enabled */
1258          }          }
1259    
1260          BitstreamPutBit(bs, 0);         // scalability          BitstreamPutBit(bs, 0);         // scalability
1261    
1262            /* fake divx5 id, to ensure compatibility with divx5 decoder */
1263    #define DIVX5_ID "DivX501b481p"
1264            if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) {
1265                    BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID));
1266            }
1267    
1268            /* xvid id */
1269    #define XVID_ID "XviD" XVID_BS_VERSION
1270            BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID));
1271  }  }
1272    
1273    
# Line 1233  Line 1275 
1275    write vop header    write vop header
1276  */  */
1277  void  void
1278  BitstreamWriteVopHeader(Bitstream * const bs,  BitstreamWriteVopHeader(
1279                                                    Bitstream * const bs,
1280                                                  const MBParam * pParam,                                                  const MBParam * pParam,
1281                                                  const FRAMEINFO * const frame,                                                  const FRAMEINFO * const frame,
1282                                                  int vop_coded)                                                  int vop_coded)
1283  {  {
1284          uint32_t i;          uint32_t i;
1285    
1286          BitstreamPad(bs);  //      BitstreamPad(bs);
1287    /* no padding here, anymore. You have to make sure that you are
1288       byte aligned, and that always 1-8 padding bits have been written */
1289    
1290          BitstreamPutBits(bs, VOP_START_CODE, 32);          BitstreamPutBits(bs, VOP_START_CODE, 32);
1291    
1292          BitstreamPutBits(bs, frame->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
# Line 1272  Line 1318 
1318          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )
1319                  BitstreamPutBits(bs, frame->rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
1320    
1321            if ((pParam->global & XVID_GLOBAL_REDUCED))
1322                    BitstreamPutBit(bs, (frame->global_flags & XVID_REDUCED)?1:0);
1323    
1324          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold
1325    
1326          if (frame->global_flags & XVID_INTERLACING) {          if (frame->global_flags & XVID_INTERLACING) {
# Line 1280  Line 1329 
1329          }          }
1330    
1331          if (frame->coding_type == S_VOP) {          if (frame->coding_type == S_VOP) {
1332                  if (1)  {               // no_of_sprite_warping_points>=1                  if (1)  {               // no_of_sprite_warping_points>=1 (we use 2!)
1333                          if (pParam->m_quarterpel)                          int k;
1334                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0]                          for (k=0;k<2;k++)
1335                          else                          {
1336                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0]                                  bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); // du[k]
1337                          WRITE_MARKER();                          WRITE_MARKER();
1338    
1339                          if (pParam->m_quarterpel)                                  bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k]
                                 bs_put_spritetrajectory(bs, frame->GMC_MV.y/2 ); // dv[0]  
                         else  
                                 bs_put_spritetrajectory(bs, frame->GMC_MV.y ); // dv[0]  
1340                          WRITE_MARKER();                          WRITE_MARKER();
1341    
   
1342                          if (pParam->m_quarterpel)                          if (pParam->m_quarterpel)
1343                          {                          {
1344                                  DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", 0, frame->GMC_MV.x/2, frame->GMC_MV.y/2);                                  DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", k, frame->warp.duv[k].x/2, frame->warp.duv[k].y/2);
1345                          }                          }
1346                          else                          else
1347                          {                          {
1348                                  DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", 0, frame->GMC_MV.x, frame->GMC_MV.y);                                  DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", k, frame->warp.duv[k].x, frame->warp.duv[k].y);
1349                          }                          }
   
1350                  }                  }
 /* GMC is halfpel in bitstream, even though GMC_MV was pseudo-qpel (2*halfpel) */  
   
                 if (2) {                // no_of_sprite_warping_points>=2 (for DivX5 compat)  
                         bs_put_spritetrajectory(bs, 0 );  
                         WRITE_MARKER();  
                         bs_put_spritetrajectory(bs, 0 );  
                         WRITE_MARKER();  
1351                  }                  }
                 // no support for brightness_change!  
1352          }          }
1353    
1354    

Legend:
Removed from v.1.28.2.7  
changed lines
  Added in v.1.28.2.19

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