[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.11, Sat Dec 14 09:39:42 2002 UTC revision 1.39.2.3, Sat Mar 15 17:03:17 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 173  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 230  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 326  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 432  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;
439          uint32_t start_code;          uint32_t start_code;
440          uint32_t time_incr = 0;          uint32_t time_incr = 0;
441          int32_t time_increment;          int32_t time_increment = 0;
442          int resize = 0;          int resize = 0;
443    
444          do {          do {
# Line 464  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 557  Line 558 
558                                  DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);                                  DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);
559                                  if (BitstreamGetBit(bs))        // vbv_parameters                                  if (BitstreamGetBit(bs))        // vbv_parameters
560                                  {                                  {
561                                            unsigned int bitrate;
562                                            unsigned int buffer_size;
563                                            unsigned int occupancy;
564    
565                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");
566                                          BitstreamSkip(bs, 15);  // first_half_bitrate  
567                                            bitrate = BitstreamGetBits(bs,15) << 15;        // first_half_bit_rate
568                                          READ_MARKER();                                          READ_MARKER();
569                                          BitstreamSkip(bs, 15);  // latter_half_bitrate                                          bitrate |= BitstreamGetBits(bs,15);             // latter_half_bit_rate
570                                          READ_MARKER();                                          READ_MARKER();
571                                          BitstreamSkip(bs, 15);  // first_half_vbv_buffer_size  
572                                            buffer_size = BitstreamGetBits(bs, 15) << 3;    // first_half_vbv_buffer_size
573                                          READ_MARKER();                                          READ_MARKER();
574                                          BitstreamSkip(bs, 3);   // latter_half_vbv_buffer_size                                          buffer_size |= BitstreamGetBits(bs, 3);         // latter_half_vbv_buffer_size
575                                          BitstreamSkip(bs, 11);  // first_half_vbv_occupancy  
576                                            occupancy = BitstreamGetBits(bs, 11) << 15;     // first_half_vbv_occupancy
577                                          READ_MARKER();                                          READ_MARKER();
578                                          BitstreamSkip(bs, 15);  // latter_half_vbv_occupancy                                          occupancy |= BitstreamGetBits(bs, 15);  // latter_half_vbv_occupancy
579                                          READ_MARKER();                                          READ_MARKER();
580    
581                                            DPRINTF(DPRINTF_HEADER,"bitrate %d (unit=400 bps)", bitrate);
582                                            DPRINTF(DPRINTF_HEADER,"buffer_size %d (unit=16384 bits)", buffer_size);
583                                            DPRINTF(DPRINTF_HEADER,"occupancy %d (unit=64 bits)", occupancy);
584                                  }                                  }
585                          }else{                          }else{
586                                  dec->low_delay = dec->low_delay_default;                                  dec->low_delay = dec->low_delay_default;
# Line 628  Line 640 
640                                          {                                          {
641                                                  if (dec->fixed_dimensions)                                                  if (dec->fixed_dimensions)
642                                                  {                                                  {
643                                                          DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream");                                                          DPRINTF(DPRINTF_ERROR, "decoder width/height does not match bitstream");
644                                                          return -1;                                                          return -1;
645                                                  }                                                  }
646                                                  resize = 1;                                                  resize = 1;
# Line 826  Line 838 
838                                  READ_MARKER();                                  READ_MARKER();
839                                  seconds = BitstreamGetBits(bs, 6);                                  seconds = BitstreamGetBits(bs, 6);
840    
841                                  DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours);                                  DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours,minutes,seconds);
842                          }                          }
843                          BitstreamSkip(bs, 1);   // closed_gov                          BitstreamSkip(bs, 1);   // closed_gov
844                          BitstreamSkip(bs, 1);   // broken_link                          BitstreamSkip(bs, 1);   // broken_link
# Line 1000  Line 1012 
1012                                          }                                          }
1013                                          READ_MARKER();                                          READ_MARKER();
1014    
1015                                          gmc_mv[i].x = x;                                          gmc_warp->duv[i].x = x;
1016                                          gmc_mv[i].y = y;                                          gmc_warp->duv[i].y = y;
1017    
1018                                          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);
1019                                  }                                  }
# Line 1056  Line 1068 
1068                                  BitstreamSkip(bs, 8);                                  BitstreamSkip(bs, 8);
1069                          }                          }
1070    
1071                          DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp);                          DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s", tmp);
1072    
1073                      /* divx detection */                      /* divx detection */
1074                          i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed);                          i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed);
# Line 1111  Line 1123 
1123  */  */
1124  void  void
1125  BitstreamWriteVolHeader(Bitstream * const bs,  BitstreamWriteVolHeader(Bitstream * const bs,
1126                                                  const MBParam * pParam,                                                  const MBParam * pParam)
                                                 const FRAMEINFO * const frame)  
1127  {  {
1128            static const unsigned int vo_id = 0;
1129            static const unsigned int vol_id = 0;
1130          int vol_ver_id=1;          int vol_ver_id=1;
1131            int profile = 0x03;     /* simple profile/level 3 */
1132    
1133          if ( pParam->m_quarterpel ||  (frame->global_flags & XVID_GMC) ||          if ( (pParam->vol_flags & XVID_QUARTERPEL) ||
1134                   (pParam->global & XVID_GLOBAL_REDUCED))           (pParam->vol_flags & XVID_GMC) ||
1135                     (pParam->vol_flags & XVID_REDUCED_ENABLE))
1136                  vol_ver_id = 2;                  vol_ver_id = 2;
1137    
1138            if ((pParam->vol_flags & XVID_REDUCED_ENABLE))
1139                    profile = 0x93; /* advanced realtime simple profile/level 3 */
1140    
1141            if ((pParam->vol_flags & XVID_QUARTERPEL) ||
1142            (pParam->vol_flags & XVID_GMC))
1143                    profile = 0xf3; /* advanced simple profile/level 2 */
1144    
1145            // visual_object_sequence_start_code
1146    //      BitstreamPad(bs);
1147    /* no padding here, anymore. You have to make sure that you are
1148       byte aligned, and that always 1-8 padding bits have been written */
1149    
1150            BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32);
1151            BitstreamPutBits(bs, profile, 8);
1152    
1153            // visual_object_start_code
1154            BitstreamPad(bs);
1155            BitstreamPutBits(bs, VISOBJ_START_CODE, 32);
1156            BitstreamPutBits(bs, 0, 1);             // is_visual_object_identifier
1157            BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4);             // visual_object_type
1158    
1159          // video object_start_code & vo_id          // video object_start_code & vo_id
1160          BitstreamPad(bs);          BitstreamPad(bs);
1161          BitstreamPutBits(bs, VO_START_CODE, 27);          BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32);
         BitstreamPutBits(bs, 0, 5);  
1162    
1163          // video_object_layer_start_code & vol_id          // video_object_layer_start_code & vol_id
1164          BitstreamPutBits(bs, VOL_START_CODE, 28);          BitstreamPad(bs);
1165          BitstreamPutBits(bs, 0, 4);          BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32);
1166    
1167          BitstreamPutBit(bs, 0);         // random_accessible_vol          BitstreamPutBit(bs, 0);         // random_accessible_vol
1168          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication
# Line 1169  Line 1204 
1204    
1205          WRITE_MARKER();          WRITE_MARKER();
1206    
1207        if (pParam->fincr>0) {
1208          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
1209          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment
1210        }else{
1211            BitstreamPutBit(bs, 0);         // fixed_vop_rate = 0
1212        }
1213    
1214          WRITE_MARKER();          WRITE_MARKER();
1215          BitstreamPutBits(bs, pParam->width, 13);        // width          BitstreamPutBits(bs, pParam->width, 13);        // width
# Line 1178  Line 1217 
1217          BitstreamPutBits(bs, pParam->height, 13);       // height          BitstreamPutBits(bs, pParam->height, 13);       // height
1218          WRITE_MARKER();          WRITE_MARKER();
1219    
1220          BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING);    // interlace          BitstreamPutBit(bs, pParam->vol_flags & XVID_INTERLACING);      // interlace
1221          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)
1222    
1223          if (vol_ver_id != 1)          if (vol_ver_id != 1)
1224          {       if (frame->global_flags & XVID_GMC)          {       if ((pParam->vol_flags & XVID_GMC))
1225                  {       BitstreamPutBits(bs, 2, 2);             // sprite_enable=='GMC'                  {       BitstreamPutBits(bs, 2, 2);             // sprite_enable=='GMC'
1226                          BitstreamPutBits(bs, 2, 6);             // no_of_sprite_warping_points                          BitstreamPutBits(bs, 2, 6);             // no_of_sprite_warping_points
1227                          BitstreamPutBits(bs, 3, 2);             // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16                          BitstreamPutBits(bs, 3, 2);             // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16
# Line 1200  Line 1239 
1239          BitstreamPutBit(bs, 0);         // not_8_bit          BitstreamPutBit(bs, 0);         // not_8_bit
1240    
1241          // quant_type   0=h.263  1=mpeg4(quantizer tables)          // quant_type   0=h.263  1=mpeg4(quantizer tables)
1242          BitstreamPutBit(bs, pParam->m_quant_type);          BitstreamPutBit(bs, pParam->vol_flags & XVID_MPEGQUANT);
1243    
1244          if (pParam->m_quant_type) {          if ((pParam->vol_flags & XVID_MPEGQUANT)) {
1245                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat
1246                  if (get_intra_matrix_status()) {                  if (get_intra_matrix_status()) {
1247                          bs_put_matrix(bs, get_intra_matrix());                          bs_put_matrix(bs, get_intra_matrix());
# Line 1216  Line 1255 
1255          }          }
1256    
1257          if (vol_ver_id != 1) {          if (vol_ver_id != 1) {
1258                  if (pParam->m_quarterpel)                  if ((pParam->vol_flags & XVID_QUARTERPEL))
1259                          BitstreamPutBit(bs, 1);         //  quarterpel                          BitstreamPutBit(bs, 1);         //  quarterpel
1260                  else                  else
1261                          BitstreamPutBit(bs, 0);         // no quarterpel                          BitstreamPutBit(bs, 0);         // no quarterpel
# Line 1230  Line 1269 
1269          {          {
1270                  BitstreamPutBit(bs, 0);         // newpred_enable                  BitstreamPutBit(bs, 0);         // newpred_enable
1271    
1272                  BitstreamPutBit(bs, (pParam->global & XVID_GLOBAL_REDUCED)?1:0);                  BitstreamPutBit(bs, (pParam->vol_flags & XVID_REDUCED_ENABLE)?1:0);
1273                                                                          /* reduced_resolution_vop_enabled */                                                                          /* reduced_resolution_vop_enabled */
1274          }          }
1275    
1276          BitstreamPutBit(bs, 0);         // scalability          BitstreamPutBit(bs, 0);         // scalability
1277    
1278            /* fake divx5 id, to ensure compatibility with divx5 decoder */
1279    #define DIVX5_ID "DivX000b000p"
1280            if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_PACKED)) {
1281                    BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID));
1282            }
1283    
1284            /* xvid id */
1285    #define XVID_ID "XviD" XVID_BS_VERSION
1286            BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID));
1287  }  }
1288    
1289    
# Line 1251  Line 1299 
1299  {  {
1300          uint32_t i;          uint32_t i;
1301    
1302          BitstreamPad(bs);  //      BitstreamPad(bs);
1303    /* no padding here, anymore. You have to make sure that you are
1304       byte aligned, and that always 1-8 padding bits have been written */
1305    
1306          BitstreamPutBits(bs, VOP_START_CODE, 32);          BitstreamPutBits(bs, VOP_START_CODE, 32);
1307    
1308          BitstreamPutBits(bs, frame->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
# Line 1283  Line 1334 
1334          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )
1335                  BitstreamPutBits(bs, frame->rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
1336    
1337          if ((pParam->global & XVID_GLOBAL_REDUCED))          if ((frame->vol_flags & XVID_REDUCED_ENABLE))
1338                  BitstreamPutBit(bs, (frame->global_flags & XVID_REDUCED)?1:0);                  BitstreamPutBit(bs, (frame->vop_flags & XVID_REDUCED)?1:0);
1339    
1340          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold
1341    
1342          if (frame->global_flags & XVID_INTERLACING) {          if ((frame->vol_flags & XVID_INTERLACING)) {
1343                  BitstreamPutBit(bs, (frame->global_flags & XVID_TOPFIELDFIRST));                  BitstreamPutBit(bs, (frame->vop_flags & XVID_TOPFIELDFIRST));
1344                  BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN));                  BitstreamPutBit(bs, (frame->vop_flags & XVID_ALTERNATESCAN));
1345          }          }
1346    
1347          if (frame->coding_type == S_VOP) {          if (frame->coding_type == S_VOP) {
1348                  if (1)  {               // no_of_sprite_warping_points>=1                  if (1)  {               // no_of_sprite_warping_points>=1 (we use 2!)
1349                          if (pParam->m_quarterpel)                          int k;
1350                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0]                          for (k=0;k<2;k++)
1351                          else                          {
1352                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0]                                  bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); // du[k]
1353                          WRITE_MARKER();                          WRITE_MARKER();
1354    
1355                          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]  
1356                          WRITE_MARKER();                          WRITE_MARKER();
1357    
1358                            if ((frame->vol_flags & XVID_QUARTERPEL))
                         if (pParam->m_quarterpel)  
1359                          {                          {
1360                                  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);
1361                          }                          }
1362                          else                          else
1363                          {                          {
1364                                  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);
1365                          }                          }
   
1366                  }                  }
 /* 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();  
1367                  }                  }
                 // no support for brightness_change!  
1368          }          }
1369    
1370    

Legend:
Removed from v.1.28.2.11  
changed lines
  Added in v.1.39.2.3

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