[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.41, Mon Jul 28 12:36:29 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 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 1058  Line 1070 
1070    
1071                          DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp);                          DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp);
1072    
1073                            /* read xvid bitstream version */
1074                            if(strncmp(tmp, "XviD", 4) == 0) {
1075                                    sscanf(tmp, "XviD%d", &dec->bs_version);
1076                                    DPRINTF(DPRINTF_HEADER, "xvid bitstream version=%i", dec->bs_version);
1077                            }
1078    
1079                      /* divx detection */                      /* divx detection */
1080                          i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed);                          i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed);
1081                          if (i < 2)                          if (i < 2)
# Line 1114  Line 1132 
1132                                                  const MBParam * pParam,                                                  const MBParam * pParam,
1133                                                  const FRAMEINFO * const frame)                                                  const FRAMEINFO * const frame)
1134  {  {
1135            static const unsigned int vo_id = 0;
1136            static const unsigned int vol_id = 0;
1137          int vol_ver_id=1;          int vol_ver_id=1;
1138            int profile = 0x03;     /* simple profile/level 3 */
1139    
1140          if ( pParam->m_quarterpel ||  (frame->global_flags & XVID_GMC) ||          if ( pParam->m_quarterpel ||  (frame->global_flags & XVID_GMC) ||
1141                   (pParam->global & XVID_GLOBAL_REDUCED))                   (pParam->global & XVID_GLOBAL_REDUCED))
1142                  vol_ver_id = 2;                  vol_ver_id = 2;
1143    
1144          // video object_start_code & vo_id          if ((pParam->global & XVID_GLOBAL_REDUCED))
1145                    profile = 0x93; /* advanced realtime simple profile/level 3 */
1146    
1147            if (pParam->m_quarterpel ||  (frame->global_flags & XVID_GMC))
1148                    profile = 0xf3; /* advanced simple profile/level 2 */
1149    
1150            // visual_object_sequence_start_code
1151    //      BitstreamPad(bs);
1152    /* no padding here, anymore. You have to make sure that you are
1153       byte aligned, and that always 1-8 padding bits have been written */
1154    
1155            BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32);
1156            BitstreamPutBits(bs, profile, 8);
1157    
1158            // visual_object_start_code
1159          BitstreamPad(bs);          BitstreamPad(bs);
1160          BitstreamPutBits(bs, VO_START_CODE, 27);          BitstreamPutBits(bs, VISOBJ_START_CODE, 32);
1161          BitstreamPutBits(bs, 0, 5);          BitstreamPutBits(bs, 0, 1);             // is_visual_object_identifier
1162    
1163            /* Video type */
1164            BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4);             // visual_object_type
1165            BitstreamPutBit(bs, 0); /* video_signal_type */
1166    
1167            // video object_start_code & vo_id
1168            BitstreamPadAlways(bs); // next_start_code()
1169            BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32);
1170    
1171          // video_object_layer_start_code & vol_id          // video_object_layer_start_code & vol_id
1172          BitstreamPutBits(bs, VOL_START_CODE, 28);          BitstreamPad(bs);
1173          BitstreamPutBits(bs, 0, 4);          BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32);
1174    
1175          BitstreamPutBit(bs, 0);         // random_accessible_vol          BitstreamPutBit(bs, 0);         // random_accessible_vol
1176          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication
# Line 1140  Line 1183 
1183          {          {
1184                  BitstreamPutBit(bs, 1);         // is_object_layer_identified                  BitstreamPutBit(bs, 1);         // is_object_layer_identified
1185                  BitstreamPutBits(bs, vol_ver_id, 4);    // vol_ver_id == 2                  BitstreamPutBits(bs, vol_ver_id, 4);    // vol_ver_id == 2
1186                  BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==lowest, 7==highest) ??                  BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==highest, 7==lowest)
1187          }          }
1188    
1189          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)
# Line 1236  Line 1279 
1279    
1280          BitstreamPutBit(bs, 0);         // scalability          BitstreamPutBit(bs, 0);         // scalability
1281    
1282            BitstreamPadAlways(bs); // next_start_code()
1283    
1284            /* fake divx5 id, to ensure compatibility with divx5 decoder */
1285    #define DIVX5_ID "DivX501b481p"
1286            if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) {
1287                    BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID));
1288            }
1289    
1290            /* xvid id */
1291    #define XVID_ID "XviD" XVID_BS_VERSION
1292            BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID));
1293  }  }
1294    
1295    
# Line 1251  Line 1305 
1305  {  {
1306          uint32_t i;          uint32_t i;
1307    
1308          BitstreamPad(bs);  //      BitstreamPad(bs);
1309    /* no padding here, anymore. You have to make sure that you are
1310       byte aligned, and that always 1-8 padding bits have been written */
1311    
1312          BitstreamPutBits(bs, VOP_START_CODE, 32);          BitstreamPutBits(bs, VOP_START_CODE, 32);
1313    
1314          BitstreamPutBits(bs, frame->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
# Line 1275  Line 1332 
1332    
1333          if (!vop_coded) {          if (!vop_coded) {
1334                  BitstreamPutBits(bs, 0, 1);                  BitstreamPutBits(bs, 0, 1);
1335    #if 0
1336                    BitstreamPadAlways(bs); /*  next_start_code() */
1337    #endif
1338                    /* NB: It's up to the function caller to write the next_start_code().
1339                     * At the moment encoder.c respects that requisite because a VOP
1340                     * always ends with a next_start_code either if it's coded or not
1341                     * and encoder.c terminates a frame with a next_start_code in whatever
1342                     * case */
1343                  return;                  return;
1344          }          }
1345    
# Line 1294  Line 1359 
1359          }          }
1360    
1361          if (frame->coding_type == S_VOP) {          if (frame->coding_type == S_VOP) {
1362                  if (1)  {               // no_of_sprite_warping_points>=1                  if (1)  {               // no_of_sprite_warping_points>=1 (we use 2!)
1363                          if (pParam->m_quarterpel)                          int k;
1364                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0]                          for (k=0;k<2;k++)
1365                          else                          {
1366                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0]                                  bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); // du[k]
1367                          WRITE_MARKER();                          WRITE_MARKER();
1368    
1369                          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]  
1370                          WRITE_MARKER();                          WRITE_MARKER();
1371    
   
1372                          if (pParam->m_quarterpel)                          if (pParam->m_quarterpel)
1373                          {                          {
1374                                  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);
1375                          }                          }
1376                          else                          else
1377                          {                          {
1378                                  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);
1379                          }                          }
   
1380                  }                  }
 /* 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();  
1381                  }                  }
                 // no support for brightness_change!  
1382          }          }
1383    
1384    

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

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