[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.39, Fri Aug 22 16:11:58 2003 UTC revision 1.95.2.54, Wed Nov 19 15:42:38 2003 UTC
# Line 188  Line 188 
188          pcreate.zones = pEnc->zones;          pcreate.zones = pEnc->zones;
189          pcreate.width = pEnc->mbParam.width;          pcreate.width = pEnc->mbParam.width;
190          pcreate.height = pEnc->mbParam.height;          pcreate.height = pEnc->mbParam.height;
191                    pcreate.mb_width = pEnc->mbParam.mb_width;
192                    pcreate.mb_height = pEnc->mbParam.mb_height;
193          pcreate.fincr = pEnc->mbParam.fincr;          pcreate.fincr = pEnc->mbParam.fincr;
194          pcreate.fbase = pEnc->mbParam.fbase;          pcreate.fbase = pEnc->mbParam.fbase;
195          pcreate.param = create->plugins[n].param;          pcreate.param = create->plugins[n].param;
# Line 263  Line 265 
265          image_null(&pEnc->reference->image);          image_null(&pEnc->reference->image);
266          image_null(&pEnc->vInterH);          image_null(&pEnc->vInterH);
267          image_null(&pEnc->vInterV);          image_null(&pEnc->vInterV);
         image_null(&pEnc->vInterVf);  
268          image_null(&pEnc->vInterHV);          image_null(&pEnc->vInterHV);
         image_null(&pEnc->vInterHVf);  
269    
270          if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {          if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {
271          if (image_create          if (image_create
# Line 309  Line 309 
309                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
310                  goto xvid_err_memory3;                  goto xvid_err_memory3;
311          if (image_create          if (image_create
                 (&pEnc->vInterVf, pEnc->mbParam.edged_width,  
                  pEnc->mbParam.edged_height) < 0)  
                 goto xvid_err_memory3;  
         if (image_create  
312                  (&pEnc->vInterHV, pEnc->mbParam.edged_width,                  (&pEnc->vInterHV, pEnc->mbParam.edged_width,
313                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
314                  goto xvid_err_memory3;                  goto xvid_err_memory3;
         if (image_create  
                 (&pEnc->vInterHVf, pEnc->mbParam.edged_width,  
                  pEnc->mbParam.edged_height) < 0)  
                 goto xvid_err_memory3;  
315    
316  /* Create full bitplane for GMC, this might be wasteful */  /* Create full bitplane for GMC, this might be wasteful */
317          if (image_create          if (image_create
# Line 389  Line 381 
381                  image_null(&pEnc->queue[n].image);                  image_null(&pEnc->queue[n].image);
382    
383    
384          for (n = 0; n < pEnc->mbParam.max_bframes+1; n++)          for (n = 0; n < pEnc->mbParam.max_bframes+1; n++) {
         {  
385                  if (image_create                  if (image_create
386                          (&pEnc->queue[n].image, pEnc->mbParam.edged_width,                          (&pEnc->queue[n].image, pEnc->mbParam.edged_width,
387                           pEnc->mbParam.edged_height) < 0)                           pEnc->mbParam.edged_height) < 0)
388                          goto xvid_err_memory5;                          goto xvid_err_memory5;
   
389          }          }
390    
   
391          /* timestamp stuff */          /* timestamp stuff */
392    
393          pEnc->mbParam.m_stamp = 0;          pEnc->mbParam.m_stamp = 0;
# Line 423  Line 412 
412    
413    xvid_err_memory5:    xvid_err_memory5:
414    
415          if (pEnc->mbParam.max_bframes > 0) {          for (n = 0; n < pEnc->mbParam.max_bframes+1; n++) {
416          int i;                          image_destroy(&pEnc->queue[n].image, pEnc->mbParam.edged_width,
   
                 for (i = 0; i < pEnc->mbParam.max_bframes+1; i++) {  
                         image_destroy(&pEnc->queue[i].image, pEnc->mbParam.edged_width,  
417                                                    pEnc->mbParam.edged_height);                                                    pEnc->mbParam.edged_height);
418                  }                  }
419    
420                  xvid_free(pEnc->queue);                  xvid_free(pEnc->queue);
         }  
421    
422    xvid_err_memory4:    xvid_err_memory4:
423    
# Line 445  Line 431 
431    
432                          image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width,                          image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width,
433                                                    pEnc->mbParam.edged_height);                                                    pEnc->mbParam.edged_height);
   
434                          xvid_free(pEnc->bframes[i]->mbs);                          xvid_free(pEnc->bframes[i]->mbs);
   
435                          xvid_free(pEnc->bframes[i]);                          xvid_free(pEnc->bframes[i]);
   
436                  }                  }
437    
438                  xvid_free(pEnc->bframes);                  xvid_free(pEnc->bframes);
# Line 479  Line 462 
462                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
463          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width,
464                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
         image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width,  
                                   pEnc->mbParam.edged_height);  
465          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width,
466                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
         image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,  
                                   pEnc->mbParam.edged_height);  
467    
468  /* destroy GMC image */  /* destroy GMC image */
469          image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width,
# Line 538  Line 517 
517          int i;          int i;
518    
519          /* B Frames specific */          /* B Frames specific */
         if (pEnc->mbParam.max_bframes > 0) {  
   
520                  for (i = 0; i < pEnc->mbParam.max_bframes+1; i++) {                  for (i = 0; i < pEnc->mbParam.max_bframes+1; i++) {
   
521                          image_destroy(&pEnc->queue[i].image, pEnc->mbParam.edged_width,                          image_destroy(&pEnc->queue[i].image, pEnc->mbParam.edged_width,
522                                            pEnc->mbParam.edged_height);                                            pEnc->mbParam.edged_height);
523                  }                  }
                 xvid_free(pEnc->queue);  
         }  
524    
525            xvid_free(pEnc->queue);
526    
527          if (pEnc->mbParam.max_bframes > 0) {          if (pEnc->mbParam.max_bframes > 0) {
528    
# Line 558  Line 533 
533    
534                          image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width,                          image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width,
535                                            pEnc->mbParam.edged_height);                                            pEnc->mbParam.edged_height);
   
536                          xvid_free(pEnc->bframes[i]->mbs);                          xvid_free(pEnc->bframes[i]->mbs);
   
537                          xvid_free(pEnc->bframes[i]);                          xvid_free(pEnc->bframes[i]);
538                  }                  }
539    
# Line 578  Line 551 
551                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
552          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width,
553                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
         image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width,  
                                   pEnc->mbParam.edged_height);  
554          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width,
555                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
         image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,  
                                   pEnc->mbParam.edged_height);  
   
556          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
557                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
558          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,
# Line 663  Line 631 
631      data.mb_height = pEnc->mbParam.mb_height;      data.mb_height = pEnc->mbParam.mb_height;
632      data.fincr = frame->fincr;      data.fincr = frame->fincr;
633      data.fbase = pEnc->mbParam.fbase;      data.fbase = pEnc->mbParam.fbase;
634            data.bquant_ratio = pEnc->mbParam.bquant_ratio;
635            data.bquant_offset = pEnc->mbParam.bquant_offset;
636    
637      for (i=0; i<3; i++) {      for (i=0; i<3; i++) {
638          data.min_quant[i] = pEnc->mbParam.min_quant[i];          data.min_quant[i] = pEnc->mbParam.min_quant[i];
# Line 691  Line 661 
661          data.type = *type;          data.type = *type;
662          data.quant = *quant;          data.quant = *quant;
663    
664                    data.vol_flags = frame->vol_flags;
665                    data.vop_flags = frame->vop_flags;
666                    data.motion_flags = frame->motion_flags;
667    
668            } else if (opt == XVID_PLG_FRAME) {
669                    data.type = coding2type(frame->coding_type);
670                    data.quant = frame->quant;
671    
672                  if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {                  if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {
673              data.dquant = pEnc->temp_dquants;              data.dquant = pEnc->temp_dquants;
674              data.dquant_stride = pEnc->mbParam.mb_width;              data.dquant_stride = pEnc->mbParam.mb_width;
675                          memset(data.dquant, 0, data.mb_width*data.mb_height);                          memset(data.dquant, 0, data.mb_width*data.mb_height);
676          }          }
677    
         data.vol_flags = frame->vol_flags;  
         data.vop_flags = frame->vop_flags;  
         data.motion_flags = frame->motion_flags;  
   
678      } else { /* XVID_PLG_AFTER */      } else { /* XVID_PLG_AFTER */
679          if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {          if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {
680              data.original.csp = XVID_CSP_USER;              data.original.csp = XVID_CSP_USER;
# Line 785  Line 759 
759          *type = data.type;          *type = data.type;
760          *quant = data.quant > 0 ? data.quant : 2;   /* default */          *quant = data.quant > 0 ? data.quant : 2;   /* default */
761    
762                    frame->vol_flags = data.vol_flags;
763                    frame->vop_flags = data.vop_flags;
764                    frame->motion_flags = data.motion_flags;
765    
766            } else if (opt == XVID_PLG_FRAME) {
767    
768          if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {          if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {
769              for (j=0; j<pEnc->mbParam.mb_height; j++)              for (j=0; j<pEnc->mbParam.mb_height; j++)
770              for (i=0; i<pEnc->mbParam.mb_width; i++) {              for (i=0; i<pEnc->mbParam.mb_width; i++) {
# Line 796  Line 776 
776                  frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0;                  frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0;
777              }              }
778          }          }
779                    frame->mbs[0].quant = data.quant; /* BEFORE2 will not affect the quant in stats */
         frame->vol_flags = data.vol_flags;  
         frame->vop_flags = data.vop_flags;  
         frame->motion_flags = data.motion_flags;  
780      }      }
781    
782    
783  }  }
784    
785    
# Line 964  Line 943 
943                          tmp = pEnc->current->seconds;                          tmp = pEnc->current->seconds;
944                          pEnc->current->seconds = 0; /* force time_base = 0 */                          pEnc->current->seconds = 0; /* force time_base = 0 */
945    
946                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0, pEnc->current->quant);
947                          BitstreamPad(&bs);                          BitstreamPad(&bs);
948                          pEnc->current->seconds = tmp;                          pEnc->current->seconds = tmp;
949    
# Line 1009  Line 988 
988                                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
989    
990                                  /* convert B-VOP to P-VOP */                                  /* convert B-VOP to P-VOP */
991                  pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio;                                  pEnc->current->quant  = 100*pEnc->current->quant - pEnc->mbParam.bquant_offset;
992                                    pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */
993                                    pEnc->current->quant /= pEnc->mbParam.bquant_ratio;
994    
995                  if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {                  if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {
996                              image_copy(&pEnc->sOriginal, &pEnc->current->image,                              image_copy(&pEnc->sOriginal, &pEnc->current->image,
# Line 1084  Line 1065 
1065                  }else{                  }else{
1066                          type = MEanalysis(&pEnc->reference->image, pEnc->current,                          type = MEanalysis(&pEnc->reference->image, pEnc->current,
1067                                          &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval,                                          &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval,
1068                                          pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold);                                                            pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold,
1069                                                              (pEnc->bframes) ? pEnc->bframes[pEnc->bframenum_head]->mbs: NULL);
1070                  }                  }
1071          }          }
1072    
# Line 1097  Line 1079 
1079    
1080          if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {          if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1081                  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,
1082                          "%i  st:%i  if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum);                          "%d  st:%lld  if:%d", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum);
1083          }          }
1084    
1085          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Line 1176  Line 1158 
1158                  }                  }
1159    
1160                  /* convert B-VOP quant to P-VOP */                  /* convert B-VOP quant to P-VOP */
1161                  pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio;                  pEnc->current->quant  = 100*pEnc->current->quant - pEnc->mbParam.bquant_offset;
1162                    pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */
1163                    pEnc->current->quant /= pEnc->mbParam.bquant_ratio;
1164          type = P_VOP;          type = P_VOP;
1165      }      }
1166    
# Line 1199  Line 1183 
1183    
1184                  /* ---- update vol flags at IVOP ----------- */                  /* ---- update vol flags at IVOP ----------- */
1185                  pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags;                  pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags;
1186                    switch(frame->par) {
1187                    case XVID_PAR_11_VGA:
1188                    case XVID_PAR_43_PAL:
1189                    case XVID_PAR_43_NTSC:
1190                    case XVID_PAR_169_PAL:
1191                    case XVID_PAR_169_NTSC:
1192                    case XVID_PAR_EXT:
1193                            pEnc->mbParam.par = frame->par;
1194                            break;
1195                    default:
1196                            pEnc->mbParam.par = XVID_PAR_EXT;
1197                            break;
1198                    }
1199                    pEnc->mbParam.par_width = (frame->par_width)?frame->par_width:1;
1200                    pEnc->mbParam.par_height = (frame->par_height)?frame->par_height:1;
1201    
1202          if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) {          if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) {
1203                          if (frame->quant_intra_matrix != NULL)                          if (frame->quant_intra_matrix != NULL)
# Line 1282  Line 1281 
1281    
1282  static void SetMacroblockQuants(MBParam * const pParam, FRAMEINFO * frame)  static void SetMacroblockQuants(MBParam * const pParam, FRAMEINFO * frame)
1283  {  {
1284      unsigned int i,j;          unsigned int i;
1285      int quant = frame->quant;          MACROBLOCK * pMB = frame->mbs;
1286            int quant = frame->mbs[0].quant; /* set by XVID_PLG_FRAME */
1287      if (quant > 31)      if (quant > 31)
1288                  frame->quant = quant = 31;                  frame->quant = quant = 31;
1289          else if (quant < 1)          else if (quant < 1)
1290                  frame->quant = quant = 1;                  frame->quant = quant = 1;
1291    
1292      for (j=0; j<pParam->mb_height; j++)          for (i = 0; i < pParam->mb_height * pParam->mb_width; i++) {
     for (i=0; i<pParam->mb_width; i++) {  
         MACROBLOCK * pMB = &frame->mbs[j*pParam->mb_width + i];  
1293          quant += pMB->dquant;          quant += pMB->dquant;
1294          if (quant > 31)          if (quant > 31)
1295                          quant = 31;                          quant = 31;
1296                  else if (quant < 1)                  else if (quant < 1)
1297                          quant = 1;                          quant = 1;
1298          pMB->quant = quant;          pMB->quant = quant;
1299                    pMB++;
1300      }      }
1301  }  }
1302    
# Line 1353  Line 1352 
1352          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;
1353          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1354    
1355            call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
1356    
1357      SetMacroblockQuants(&pEnc->mbParam, pEnc->current);      SetMacroblockQuants(&pEnc->mbParam, pEnc->current);
1358    
1359          BitstreamWriteVolHeader(bs, &pEnc->mbParam);          BitstreamWriteVolHeader(bs, &pEnc->mbParam);
# Line 1361  Line 1362 
1362    
1363          BitstreamPad(bs);          BitstreamPad(bs);
1364    
1365          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1, pEnc->current->mbs[0].quant);
1366    
1367          pEnc->current->sStat.iTextBits = 0;          pEnc->current->sStat.iTextBits = 0;
1368          pEnc->current->sStat.kblks = mb_width * mb_height;          pEnc->current->sStat.kblks = mb_width * mb_height;
# Line 1406  Line 1407 
1407          pEnc->fMvPrevSigma = -1;          pEnc->fMvPrevSigma = -1;
1408          pEnc->mbParam.m_fcode = 2;          pEnc->mbParam.m_fcode = 2;
1409    
1410            pEnc->current->is_edged = 0; /* not edged */
1411            pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */
1412    
1413          return 1;                                       /* intra */          return 1;                                       /* intra */
1414  }  }
1415    
# Line 1448  Line 1452 
1452          }          }
1453    
1454    
1455            if (!reference->is_edged) {
1456          start_timer();          start_timer();
1457          image_setedges(pRef, pParam->edged_width, pParam->edged_height,          image_setedges(pRef, pParam->edged_width, pParam->edged_height,
1458                                     pParam->width, pParam->height);                                     pParam->width, pParam->height);
1459          stop_edges_timer();          stop_edges_timer();
1460                    reference->is_edged = 1;
1461            }
1462    
1463          pParam->m_rounding_type = 1 - pParam->m_rounding_type;          pParam->m_rounding_type = 1 - pParam->m_rounding_type;
1464          current->rounding_type = pParam->m_rounding_type;          current->rounding_type = pParam->m_rounding_type;
# Line 1463  Line 1470 
1470                  iLimit = mb_width * mb_height + 1;                  iLimit = mb_width * mb_height + 1;
1471    
1472          if ((current->vop_flags & XVID_VOP_HALFPEL)) {          if ((current->vop_flags & XVID_VOP_HALFPEL)) {
1473                    if (reference->is_interpolated != current->rounding_type) {
1474                  start_timer();                  start_timer();
1475                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,
1476                                                    &pEnc->vInterHV, pParam->edged_width,                                                    &pEnc->vInterHV, pParam->edged_width,
# Line 1470  Line 1478 
1478                                                    (pParam->vol_flags & XVID_VOL_QUARTERPEL),                                                    (pParam->vol_flags & XVID_VOL_QUARTERPEL),
1479                                                    current->rounding_type);                                                    current->rounding_type);
1480                  stop_inter_timer();                  stop_inter_timer();
1481                            reference->is_interpolated = current->rounding_type;
1482                    }
1483          }          }
1484    
1485          current->coding_type = P_VOP;          current->coding_type = P_VOP;
1486    
1487            call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
1488    
1489      SetMacroblockQuants(&pEnc->mbParam, current);      SetMacroblockQuants(&pEnc->mbParam, current);
1490    
# Line 1492  Line 1503 
1503                                                                  &pEnc->vInterH,                                                                  &pEnc->vInterH,
1504                                                                  &pEnc->vInterV,                                                                  &pEnc->vInterV,
1505                                                                  &pEnc->vInterHV);                                                                  &pEnc->vInterHV);
1506                          gmcval += /*current->quant */ 2 * (int)(pParam->mb_width*pParam->mb_height);                  } else {
                 }  
   
1507                  gmcval = globalSAD(&current->warp, pParam, current->mbs,                  gmcval = globalSAD(&current->warp, pParam, current->mbs,
1508                                                          current,                                                          current,
1509                                                          &reference->image,                                                          &reference->image,
1510                                                          &current->image,                                                          &current->image,
1511                                                          pEnc->vGMC.y);                                                          pEnc->vGMC.y);
1512                    }
1513    
1514                  gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height);                  gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height);
1515    
1516  /* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */  /* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */
# Line 1544  Line 1555 
1555                  BitstreamPad(bs);                  BitstreamPad(bs);
1556          }          }
1557    
1558          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);
1559    
1560          current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =          current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =
1561                  current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;                  current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;
# Line 1765  Line 1776 
1776                  BitstreamReset(bs);                  BitstreamReset(bs);
1777    
1778                  set_timecodes(current,reference,pParam->fbase);                  set_timecodes(current,reference,pParam->fbase);
1779                  BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 0);                  BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 0, current->mbs[0].quant);
1780    
1781                  /* copy reference frame details into the current frame */                  /* copy reference frame details into the current frame */
1782                  current->quant = reference->quant;                  current->quant = reference->quant;
# Line 1777  Line 1788 
1788                  memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height);                  memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height);
1789          }          }
1790    
1791            pEnc->current->is_edged = 0; /* not edged */
1792            pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */
1793    
1794            /* what was this frame's interpolated reference will become
1795                    forward (past) reference in b-frame coding */
1796    
1797            image_swap(&pEnc->vInterH, &pEnc->f_refh);
1798            image_swap(&pEnc->vInterV, &pEnc->f_refv);
1799            image_swap(&pEnc->vInterHV, &pEnc->f_refhv);
1800    
1801    
1802          /* XXX: debug          /* XXX: debug
1803          {          {
1804                  char s[100];                  char s[100];
# Line 1828  Line 1850 
1850  #endif  #endif
1851    
1852          /* forward  */          /* forward  */
1853            if (!pEnc->reference->is_edged) {
1854          image_setedges(f_ref, pEnc->mbParam.edged_width,          image_setedges(f_ref, pEnc->mbParam.edged_width,
1855                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1856                                     pEnc->mbParam.height);                                     pEnc->mbParam.height);
1857                    pEnc->current->is_edged = 1;
1858            }
1859    
1860            if (pEnc->reference->is_interpolated != 0) {
1861          start_timer();          start_timer();
1862          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,
1863                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1864                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);
1865          stop_inter_timer();          stop_inter_timer();
1866                    pEnc->reference->is_interpolated = 0;
1867            }
1868    
1869          /* backward */          /* backward */
1870            if (!pEnc->current->is_edged) {
1871          image_setedges(b_ref, pEnc->mbParam.edged_width,          image_setedges(b_ref, pEnc->mbParam.edged_width,
1872                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1873                                     pEnc->mbParam.height);                                     pEnc->mbParam.height);
1874                    pEnc->current->is_edged = 1;
1875            }
1876    
1877            if (pEnc->current->is_interpolated != 0) {
1878          start_timer();          start_timer();
1879          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1880                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1881                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);
1882          stop_inter_timer();          stop_inter_timer();
1883                    pEnc->current->is_interpolated = 0;
1884            }
1885    
1886            frame->coding_type = B_VOP;
1887            call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
1888    
1889          start_timer();          start_timer();
1890          MotionEstimationBVOP(&pEnc->mbParam, frame,          MotionEstimationBVOP(&pEnc->mbParam, frame,
# Line 1857  Line 1896 
1896                                                   &pEnc->vInterV, &pEnc->vInterHV);                                                   &pEnc->vInterV, &pEnc->vInterHV);
1897          stop_motion_timer();          stop_motion_timer();
1898    
         frame->coding_type = B_VOP;  
   
1899          set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);
1900          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant);
1901    
1902          frame->sStat.iTextBits = 0;          frame->sStat.iTextBits = 0;
1903          frame->sStat.iMvSum = 0;          frame->sStat.iMvSum = 0;
# Line 1872  Line 1909 
1909          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
1910                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
1911                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
                         int direction = frame->vop_flags & XVID_VOP_ALTERNATESCAN ? 2 : 0;  
1912    
1913                          /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */                          /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */
1914                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
1915                                  /* mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0; */                                  if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {
1916                                            MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image,
1917                                                                                            NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0);
1918                                    }
1919    
1920                                  continue;                                  continue;
1921                          }                          }
1922    
# Line 1906  Line 1946 
1946                                  mb->cbp &= 0x3C;                                  mb->cbp &= 0x3C;
1947    
1948                          start_timer();                          start_timer();
1949                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,                          MBCodingBVOP(frame, mb, qcoeff, frame->fcode, frame->bcode, bs,
1950                                                   &frame->sStat, direction);                                                   &frame->sStat);
1951                          stop_coding_timer();                          stop_coding_timer();
1952                  }                  }
1953          }          }

Legend:
Removed from v.1.95.2.39  
changed lines
  Added in v.1.95.2.54

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