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

Diff of /xvidcore/src/encoder.c

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

revision 1.95.2.12, Sun Mar 23 04:01:48 2003 UTC revision 1.95.2.18, Wed Apr 2 20:43:56 2003 UTC
# Line 116  Line 116 
116    
117    
118  int  int
119  enc_create(xvid_enc_create_t * create, xvid_enc_rc_t * rc)  enc_create(xvid_enc_create_t * create)
120  {  {
121          Encoder *pEnc;          Encoder *pEnc;
122      int n;      int n;
123    
124          if (XVID_MAJOR(create->version) != 1 || (rc && XVID_MAJOR(rc->version) != 1))   /* v1.x.x */          if (XVID_MAJOR(create->version) != 1)   /* v1.x.x */
125                  return XVID_ERR_VERSION;                  return XVID_ERR_VERSION;
126    
127          if (create->width%2 || create->height%2)          if (create->width%2 || create->height%2)
# Line 181  Line 181 
181          }          }
182      }      }
183    
184      if ((pEnc->mbParam.global_flags & XVID_EXTRASTATS_ENABLE) ||      if ((pEnc->mbParam.global_flags & XVID_GLOBAL_EXTRASTATS_ENABLE) ||
185          (pEnc->mbParam.plugin_flags & XVID_REQPSNR)) {          (pEnc->mbParam.plugin_flags & XVID_REQPSNR)) {
186          pEnc->mbParam.plugin_flags |= XVID_REQORIGINAL; /* psnr calculation requires the original */          pEnc->mbParam.plugin_flags |= XVID_REQORIGINAL; /* psnr calculation requires the original */
187      }      }
# Line 202  Line 202 
202          pEnc->mbParam.frame_drop_ratio = MAX(create->frame_drop_ratio, 0);          pEnc->mbParam.frame_drop_ratio = MAX(create->frame_drop_ratio, 0);
203    
204      /* max keyframe interval */      /* max keyframe interval */
205      pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <=0 ? 250 : create->max_key_interval;      pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <= 0 ?
206      /*XXX: replace 250 hard code with "10seconds * framerate" */                  10 * pEnc->mbParam.fbase / pEnc->mbParam.fincr : create->max_key_interval;
207    
208          /* Bitrate allocator defaults          /* Bitrate allocator defaults
209    
# Line 683  Line 683 
683              data.original.stride[2] = pEnc->mbParam.edged_width/2;              data.original.stride[2] = pEnc->mbParam.edged_width/2;
684          }          }
685    
686          if ((frame->vol_flags & XVID_EXTRASTATS) ||          if ((frame->vol_flags & XVID_VOL_EXTRASTATS) ||
687              (pEnc->mbParam.plugin_flags & XVID_REQPSNR)) {              (pEnc->mbParam.plugin_flags & XVID_REQPSNR)) {
688    
689                          data.sse_y =                          data.sse_y =
# Line 855  Line 855 
855                  if (image_input                  if (image_input
856                          (&q->image, pEnc->mbParam.width, pEnc->mbParam.height,                          (&q->image, pEnc->mbParam.width, pEnc->mbParam.height,
857                          pEnc->mbParam.edged_width, (uint8_t**)xFrame->input.plane, xFrame->input.stride,                          pEnc->mbParam.edged_width, (uint8_t**)xFrame->input.plane, xFrame->input.stride,
858                          xFrame->input.csp, xFrame->vol_flags & XVID_INTERLACING))                          xFrame->input.csp, xFrame->vol_flags & XVID_VOL_INTERLACING))
859                  {                  {
860                          emms();                          emms();
861                          return XVID_ERR_FORMAT;                          return XVID_ERR_FORMAT;
862                  }                  }
863                  stop_conv_timer();                  stop_conv_timer();
864    
865                  if ((xFrame->vop_flags & XVID_CHROMAOPT)) {                  if ((xFrame->vop_flags & XVID_VOP_CHROMAOPT)) {
866                          image_chroma_optimize(&q->image,                          image_chroma_optimize(&q->image,
867                                  pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width);                                  pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width);
868                  }                  }
# Line 919  Line 919 
919                     indentical to the future-referece frame.                     indentical to the future-referece frame.
920                  */                  */
921    
922                  if ((pEnc->mbParam.global_flags & XVID_PACKED && pEnc->bframenum_tail > 0)) {                  if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED && pEnc->bframenum_tail > 0)) {
923                          int tmp;                          int tmp;
924                          int bits;                          int bits;
925    
# Line 961  Line 961 
961                  if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */                  if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */
962                  {                  {
963    
964              if (!(pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->mbParam.max_bframes > 0) {              if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0) {
965                  call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                  call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);
966              }              }
967    
# Line 1006  Line 1006 
1006           * init pEnc->current fields           * init pEnc->current fields
1007           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
1008    
         inc_frame_num(pEnc);  
   
1009      pEnc->current->fincr = pEnc->mbParam.fincr>0 ? pEnc->mbParam.fincr : frame->fincr;      pEnc->current->fincr = pEnc->mbParam.fincr>0 ? pEnc->mbParam.fincr : frame->fincr;
1010        inc_frame_num(pEnc);
1011      pEnc->current->vol_flags = pEnc->mbParam.vol_flags;      pEnc->current->vol_flags = pEnc->mbParam.vol_flags;
1012      pEnc->current->vop_flags = frame->vop_flags;      pEnc->current->vop_flags = frame->vop_flags;
1013          pEnc->current->motion_flags = frame->motion;          pEnc->current->motion_flags = frame->motion;
# Line 1016  Line 1015 
1015          pEnc->current->bcode = pEnc->mbParam.m_fcode;          pEnc->current->bcode = pEnc->mbParam.m_fcode;
1016    
1017    
1018      if ((xFrame->vop_flags & XVID_CHROMAOPT)) {      if ((xFrame->vop_flags & XVID_VOP_CHROMAOPT)) {
1019              image_chroma_optimize(&pEnc->current->image,              image_chroma_optimize(&pEnc->current->image,
1020                      pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width);                      pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width);
1021      }      }
# Line 1042  Line 1041 
1041                  }else{                  }else{
1042                          type = MEanalysis(&pEnc->reference->image, pEnc->current,                          type = MEanalysis(&pEnc->reference->image, pEnc->current,
1043                                          &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval,                                          &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval,
1044                                          pEnc->iFrameNum, pEnc->bframenum_tail);                                          pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold);
1045    
1046              if (type == B_VOP && !(pEnc->current->vop_flags & XVID_DYNAMIC_BFRAMES)) {              if (type == B_VOP && !(pEnc->current->vop_flags & XVID_VOP_DYNAMIC_BFRAMES)) {
1047                  type = P_VOP;   /* disable dynamic bframes */                  type = P_VOP;   /* disable dynamic bframes */
1048              }              }
1049                  }                  }
# Line 1061  Line 1060 
1060    
1061          pEnc->iFrameNum++;          pEnc->iFrameNum++;
1062    
1063          if ((pEnc->current->vop_flags & XVID_DEBUG)) {          if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1064                  image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,                  image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,
1065                          "%i  st:%i  if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum);                          "%i  st:%i  if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum);
1066          }          }
# Line 1071  Line 1070 
1070       * (we dont encode here, rather we store the frame in the bframes queue, to be encoded later)       * (we dont encode here, rather we store the frame in the bframes queue, to be encoded later)
1071           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
1072          if (type == B_VOP) {          if (type == B_VOP) {
1073                  if ((pEnc->current->vop_flags & XVID_DEBUG)) {                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1074                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");
1075                  }                  }
1076    
# Line 1102  Line 1101 
1101      }      }
1102    
1103      /* for unpacked bframes, output the stats for the last encoded frame */      /* for unpacked bframes, output the stats for the last encoded frame */
1104      if (!(pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0)      if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0)
1105      {      {
1106          if (pEnc->current->stamp > 0) {          if (pEnc->current->stamp > 0) {
1107              call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);              call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);
# Line 1116  Line 1115 
1115       * if the frame prior to an iframe is scheduled as a bframe, we must change it to a pframe       * if the frame prior to an iframe is scheduled as a bframe, we must change it to a pframe
1116       * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */       * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
1117    
1118      if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_CLOSED_GOP) && pEnc->bframenum_tail > 0) {      if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP) && pEnc->bframenum_tail > 0) {
1119    
1120                  // place this frame back on the encoding-queue (head)                  // place this frame back on the encoding-queue (head)
1121                  // we will deal with it next time                  // we will deal with it next time
# Line 1132  Line 1131 
1131                  pEnc->bframenum_tail--;                  pEnc->bframenum_tail--;
1132                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
1133    
1134                  if ((pEnc->current->vop_flags & XVID_DEBUG)) {                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1135                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP");
1136                  }                  }
1137    
# Line 1152  Line 1151 
1151                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
1152                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1153    
1154                  if ((pEnc->current->vop_flags & XVID_DEBUG)) {                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1155                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");
1156                  }                  }
1157    
# Line 1160  Line 1159 
1159                  /* ---- update vol flags at IVOP ----------- */                  /* ---- update vol flags at IVOP ----------- */
1160                  pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags;                  pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags;
1161    
1162          if ((pEnc->mbParam.vol_flags & XVID_MPEGQUANT)) {          if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) {
1163                          if (frame->quant_intra_matrix != NULL)                          if (frame->quant_intra_matrix != NULL)
1164                                  set_intra_matrix(frame->quant_intra_matrix);                                  set_intra_matrix(frame->quant_intra_matrix);
1165                          if (frame->quant_inter_matrix != NULL)                          if (frame->quant_inter_matrix != NULL)
# Line 1169  Line 1168 
1168    
1169          /* prevent vol/vop misuse */          /* prevent vol/vop misuse */
1170    
1171          if (!(pEnc->current->vol_flags & XVID_REDUCED_ENABLE))          if (!(pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE))
1172              pEnc->current->vop_flags &= ~XVID_REDUCED;              pEnc->current->vop_flags &= ~XVID_VOP_REDUCED;
1173    
1174          if (!(pEnc->current->vol_flags & XVID_INTERLACING))          if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING))
1175              pEnc->current->vop_flags &= ~(XVID_TOPFIELDFIRST|XVID_ALTERNATESCAN);              pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN);
1176    
1177                  /* ^^^------------------------ */                  /* ^^^------------------------ */
1178    
# Line 1195  Line 1194 
1194                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
1195                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1196    
1197                  if ((pEnc->current->vop_flags & XVID_DEBUG)) {                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1198                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");
1199                  }                  }
1200    
# Line 1217  Line 1216 
1216      pEnc->flush_bframes = 1;      pEnc->flush_bframes = 1;
1217    
1218          /* packed & queued_bframes: dont bother outputting stats, we do so after the flush */          /* packed & queued_bframes: dont bother outputting stats, we do so after the flush */
1219          if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) {          if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {
1220                  goto repeat;                  goto repeat;
1221          }          }
1222    
1223      /* packed or no-bframes: output stats */      /* packed or no-bframes: output stats */
1224      if ((pEnc->mbParam.global_flags & XVID_PACKED) || pEnc->mbParam.max_bframes == 0) {      if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) || pEnc->mbParam.max_bframes == 0) {
1225          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);
1226          }          }
1227    
# Line 1291  Line 1290 
1290    
1291          uint16_t x, y;          uint16_t x, y;
1292    
1293          if ((pEnc->current->vol_flags & XVID_REDUCED_ENABLE))          if ((pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE))
1294          {          {
1295                  mb_width = (pEnc->mbParam.width + 31) / 32;                  mb_width = (pEnc->mbParam.width + 31) / 32;
1296                  mb_height = (pEnc->mbParam.height + 31) / 32;                  mb_height = (pEnc->mbParam.height + 31) / 32;
# Line 1337  Line 1336 
1336                          stop_prediction_timer();                          stop_prediction_timer();
1337    
1338                          start_timer();                          start_timer();
1339                          if (pEnc->current->vop_flags & XVID_GREYSCALE)                          if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE)
1340                          {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */                          {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1341                                  qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */                                  qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */
1342                                  qcoeff[5*64+0]=0;                                  qcoeff[5*64+0]=0;
# Line 1346  Line 1345 
1345                          stop_coding_timer();                          stop_coding_timer();
1346                  }                  }
1347    
1348          if ((pEnc->current->vop_flags & XVID_REDUCED))          if ((pEnc->current->vop_flags & XVID_VOP_REDUCED))
1349          {          {
1350                  image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,                  image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,
1351                          pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,                          pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,
# Line 1354  Line 1353 
1353          }          }
1354          emms();          emms();
1355    
1356    /* XXX: Remove the two #if 0 blocks when we are sure we must always pad the stream */
1357    #if 0
1358          /* for divx5 compatibility, we must always pad between the packed p and b frames */          /* for divx5 compatibility, we must always pad between the packed p and b frames */
1359          if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0)          if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0)
1360    #endif
1361                  BitstreamPadAlways(bs);                  BitstreamPadAlways(bs);
1362    #if 0
1363          else          else
1364                  BitstreamPad(bs);                  BitstreamPad(bs);
1365    #endif
1366      pEnc->current->length = (BitstreamPos(bs) - bits) / 8;      pEnc->current->length = (BitstreamPos(bs) - bits) / 8;
1367    
1368          pEnc->fMvPrevSigma = -1;          pEnc->fMvPrevSigma = -1;
# Line 1401  Line 1405 
1405          /* IMAGE *pCurrent = &pEnc->current->image; */          /* IMAGE *pCurrent = &pEnc->current->image; */
1406          IMAGE *pRef = &pEnc->reference->image;          IMAGE *pRef = &pEnc->reference->image;
1407    
1408          if ((pEnc->current->vop_flags & XVID_REDUCED))          if ((pEnc->current->vop_flags & XVID_VOP_REDUCED))
1409          {          {
1410                  mb_width = (pEnc->mbParam.width + 31) / 32;                  mb_width = (pEnc->mbParam.width + 31) / 32;
1411                  mb_height = (pEnc->mbParam.height + 31) / 32;                  mb_height = (pEnc->mbParam.height + 31) / 32;
# Line 1423  Line 1427 
1427          else          else
1428                  iLimit = mb_width * mb_height + 1;                  iLimit = mb_width * mb_height + 1;
1429    
1430          if ((pEnc->current->vop_flags & XVID_HALFPEL)) {          if ((pEnc->current->vop_flags & XVID_VOP_HALFPEL)) {
1431                  start_timer();                  start_timer();
1432                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,
1433                                                    &pEnc->vInterHV, pEnc->mbParam.edged_width,                                                    &pEnc->vInterHV, pEnc->mbParam.edged_width,
1434                                                    pEnc->mbParam.edged_height,                                                    pEnc->mbParam.edged_height,
1435                                                    (pEnc->mbParam.vol_flags & XVID_QUARTERPEL),                                                    (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL),
1436                                                    pEnc->current->rounding_type);                                                    pEnc->current->rounding_type);
1437                  stop_inter_timer();                  stop_inter_timer();
1438          }          }
# Line 1451  Line 1455 
1455    
1456          if (bIntra == 1) return FrameCodeI(pEnc, bs);          if (bIntra == 1) return FrameCodeI(pEnc, bs);
1457    
1458          if ( ( pEnc->current->vol_flags & XVID_GMC )          if ( ( pEnc->current->vol_flags & XVID_VOL_GMC )
1459                  && ( (pEnc->current->warp.duv[1].x != 0) || (pEnc->current->warp.duv[1].y != 0) ) )                  && ( (pEnc->current->warp.duv[1].x != 0) || (pEnc->current->warp.duv[1].y != 0) ) )
1460          {          {
1461                  pEnc->current->coding_type = S_VOP;                  pEnc->current->coding_type = S_VOP;
# Line 1463  Line 1467 
1467                  generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image,                  generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image,
1468                                  pEnc->mbParam.mb_width, pEnc->mbParam.mb_height,                                  pEnc->mbParam.mb_width, pEnc->mbParam.mb_height,
1469                                  pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2,                                  pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2,
1470                                  pEnc->mbParam.m_fcode, (pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0,                                  pEnc->mbParam.m_fcode, (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0,
1471                                  pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC);                                  pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC);
1472    
1473          }          }
# Line 1512  Line 1516 
1516                                          pEnc->vGMC.y + 16*y*pEnc->mbParam.edged_width + 16*x,                                          pEnc->vGMC.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1517                                          pEnc->mbParam.edged_width, 65536);                                          pEnc->mbParam.edged_width, 65536);
1518    
1519                                  if (pEnc->current->motion_flags & PMV_CHROMA16) {                                  if (pEnc->current->motion_flags & XVID_ME_CHROMA16) {
1520                                          iSAD += sad8(pEnc->current->image.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x,                                          iSAD += sad8(pEnc->current->image.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x,
1521                                          pEnc->vGMC.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2);                                          pEnc->vGMC.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2);
1522    
# Line 1522  Line 1526 
1526    
1527                                  if (iSAD <= pMB->sad16) {               /* mode decision GMC */                                  if (iSAD <= pMB->sad16) {               /* mode decision GMC */
1528    
1529                                          if ((pEnc->mbParam.vol_flags & XVID_QUARTERPEL))                                          if ((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL))
1530                                                  pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;                                                  pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;
1531                                          else                                          else
1532                                                  pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;                                                  pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
# Line 1545  Line 1549 
1549                                                                   dct_codes, pEnc->mbParam.width,                                                                   dct_codes, pEnc->mbParam.width,
1550                                                                   pEnc->mbParam.height,                                                                   pEnc->mbParam.height,
1551                                                                   pEnc->mbParam.edged_width,                                                                   pEnc->mbParam.edged_width,
1552                                                                   (pEnc->current->vol_flags & XVID_QUARTERPEL),                                                                   (pEnc->current->vol_flags & XVID_VOL_QUARTERPEL),
1553                                                                   (pEnc->current->vop_flags & XVID_REDUCED),                                                                   (pEnc->current->vop_flags & XVID_VOP_REDUCED),
1554                                                                   pEnc->current->rounding_type);                                                                   pEnc->current->rounding_type);
1555    
1556                          stop_comp_timer();                          stop_comp_timer();
# Line 1581  Line 1585 
1585                          if (pEnc->current->coding_type == S_VOP)                          if (pEnc->current->coding_type == S_VOP)
1586                                  skip_possible &= (pMB->mcsel == 1);                                  skip_possible &= (pMB->mcsel == 1);
1587                          else if (pEnc->current->coding_type == P_VOP) {                          else if (pEnc->current->coding_type == P_VOP) {
1588                                  if ((pEnc->mbParam.vol_flags & XVID_QUARTERPEL))                                  if ((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL))
1589                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );
1590                                  else                                  else
1591                                          skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );                                          skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );
# Line 1608  Line 1612 
1612                                          }                                          }
1613    
1614                                          if (!bSkip) {   /* no SKIP, but trivial block */                                          if (!bSkip) {   /* no SKIP, but trivial block */
1615                                                  if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) {                                                  if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) {
1616                                                          VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);                                                          VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1617                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1618                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
# Line 1635  Line 1639 
1639                          }                          }
1640                          /* ordinary case: normal coded INTER/INTER4V block */                          /* ordinary case: normal coded INTER/INTER4V block */
1641    
1642                          if ((pEnc->current->vop_flags & XVID_GREYSCALE))                          if ((pEnc->current->vop_flags & XVID_VOP_GREYSCALE))
1643                          {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */                          {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1644                                  qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */                                  qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */
1645                                  qcoeff[5*64+0]=0;                                  qcoeff[5*64+0]=0;
1646                          }                          }
1647    
1648                          if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) {                          if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) {
1649                                  VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);                                  VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1650                                  pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x;                                  pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x;
1651                                  pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y;                                  pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y;
# Line 1658  Line 1662 
1662                          {       int k;                          {       int k;
1663                                  for (k=1;k<4;k++)                                  for (k=1;k<4;k++)
1664                                  {                                  {
1665                                          if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) {                                          if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) {
1666                                                  VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k);                                                  VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k);
1667                                                  pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x;                                                  pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x;
1668                                                  pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y;                                                  pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y;
# Line 1679  Line 1683 
1683                  }                  }
1684          }          }
1685    
1686          if ((pEnc->current->vop_flags & XVID_REDUCED))          if ((pEnc->current->vop_flags & XVID_VOP_REDUCED))
1687          {          {
1688                  image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,                  image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,
1689                          pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,                          pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,
# Line 1701  Line 1705 
1705          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);
1706    
1707          if ((fSigma > iSearchRange / 3)          if ((fSigma > iSearchRange / 3)
1708          && (pEnc->mbParam.m_fcode <= (3 +  (pEnc->mbParam.vol_flags & XVID_QUARTERPEL?1:0)  ))) /* maximum search range 128 */          && (pEnc->mbParam.m_fcode <= (3 +  (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL?1:0)  )))     /* maximum search range 128 */
1709          {          {
1710                  pEnc->mbParam.m_fcode++;                  pEnc->mbParam.m_fcode++;
1711                  iSearchRange *= 2;                  iSearchRange *= 2;
1712          } else if ((fSigma < iSearchRange / 6)          } else if ((fSigma < iSearchRange / 6)
1713                             && (pEnc->fMvPrevSigma >= 0)                             && (pEnc->fMvPrevSigma >= 0)
1714                             && (pEnc->fMvPrevSigma < iSearchRange / 6)                             && (pEnc->fMvPrevSigma < iSearchRange / 6)
1715                             && (pEnc->mbParam.m_fcode >= (2 + (pEnc->mbParam.vol_flags & XVID_QUARTERPEL?1:0) )))        /* minimum search range 16 */                             && (pEnc->mbParam.m_fcode >= (2 + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL?1:0) )))    /* minimum search range 16 */
1716          {          {
1717                  pEnc->mbParam.m_fcode--;                  pEnc->mbParam.m_fcode--;
1718                  iSearchRange /= 2;                  iSearchRange /= 2;
# Line 1755  Line 1759 
1759          }          }
1760          */          */
1761    
1762    /* XXX: Remove the two #if 0 blocks when we are sure we must always pad the stream */
1763    #if 0
1764          /* for divx5 compatibility, we must always pad between the packed p and b frames */          /* for divx5 compatibility, we must always pad between the packed p and b frames */
1765          if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0)          if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0)
1766    #endif
1767                  BitstreamPadAlways(bs);                  BitstreamPadAlways(bs);
1768    #if 0
1769          else          else
1770                  BitstreamPad(bs);                  BitstreamPad(bs);
1771    #endif
1772    
1773      pEnc->current->length = (BitstreamPos(bs) - bits) / 8;      pEnc->current->length = (BitstreamPos(bs) - bits) / 8;
1774    
# Line 1787  Line 1796 
1796                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \
1797          }          }
1798    
1799          /* XXX: pEnc->current->global_flags &= ~XVID_REDUCED;  reduced resoltion not yet supported */          /* XXX: pEnc->current->global_flags &= ~XVID_VOP_REDUCED;  reduced resoltion not yet supported */
1800    
1801          if (!first){          if (!first){
1802                  fp=fopen("C:\\XVIDDBGE.TXT","w");                  fp=fopen("C:\\XVIDDBGE.TXT","w");
# Line 1803  Line 1812 
1812          start_timer();          start_timer();
1813          image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,          image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
1814                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1815                                            (pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0);                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);
1816          stop_inter_timer();          stop_inter_timer();
1817    
1818          /* backward */          /* backward */
# Line 1813  Line 1822 
1822          start_timer();          start_timer();
1823          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1824                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1825                                            (pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0);                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);
1826          stop_inter_timer();          stop_inter_timer();
1827    
1828          start_timer();          start_timer();
# Line 1850  Line 1859 
1859          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
1860                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
1861                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
1862                          int direction = frame->vop_flags & XVID_ALTERNATESCAN ? 2 : 0;                          int direction = frame->vop_flags & XVID_VOP_ALTERNATESCAN ? 2 : 0;
1863    
1864                          /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */                          /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */
1865                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
# Line 1891  Line 1900 
1900    
1901          /* TODO: dynamic fcode/bcode ??? */          /* TODO: dynamic fcode/bcode ??? */
1902    
1903      BitstreamPad(bs);      BitstreamPadAlways(bs);
1904          frame->length = (BitstreamPos(bs) - bits) / 8;          frame->length = (BitstreamPos(bs) - bits) / 8;
1905    
1906  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG

Legend:
Removed from v.1.95.2.12  
changed lines
  Added in v.1.95.2.18

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