[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.38, Thu Aug 7 15:41:33 2003 UTC revision 1.95.2.50, Thu Nov 13 22:35:30 2003 UTC
# Line 389  Line 389 
389                  image_null(&pEnc->queue[n].image);                  image_null(&pEnc->queue[n].image);
390    
391    
392          for (n = 0; n < pEnc->mbParam.max_bframes+1; n++)          for (n = 0; n < pEnc->mbParam.max_bframes+1; n++) {
         {  
393                  if (image_create                  if (image_create
394                          (&pEnc->queue[n].image, pEnc->mbParam.edged_width,                          (&pEnc->queue[n].image, pEnc->mbParam.edged_width,
395                           pEnc->mbParam.edged_height) < 0)                           pEnc->mbParam.edged_height) < 0)
396                          goto xvid_err_memory5;                          goto xvid_err_memory5;
   
397          }          }
398    
   
399          /* timestamp stuff */          /* timestamp stuff */
400    
401          pEnc->mbParam.m_stamp = 0;          pEnc->mbParam.m_stamp = 0;
# Line 423  Line 420 
420    
421    xvid_err_memory5:    xvid_err_memory5:
422    
423          if (pEnc->mbParam.max_bframes > 0) {          for (n = 0; n < pEnc->mbParam.max_bframes+1; n++) {
424          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,  
425                                                    pEnc->mbParam.edged_height);                                                    pEnc->mbParam.edged_height);
426                  }                  }
427    
428                  xvid_free(pEnc->queue);                  xvid_free(pEnc->queue);
         }  
429    
430    xvid_err_memory4:    xvid_err_memory4:
431    
# Line 445  Line 439 
439    
440                          image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width,                          image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width,
441                                                    pEnc->mbParam.edged_height);                                                    pEnc->mbParam.edged_height);
   
442                          xvid_free(pEnc->bframes[i]->mbs);                          xvid_free(pEnc->bframes[i]->mbs);
   
443                          xvid_free(pEnc->bframes[i]);                          xvid_free(pEnc->bframes[i]);
   
444                  }                  }
445    
446                  xvid_free(pEnc->bframes);                  xvid_free(pEnc->bframes);
# Line 538  Line 529 
529          int i;          int i;
530    
531          /* B Frames specific */          /* B Frames specific */
         if (pEnc->mbParam.max_bframes > 0) {  
   
532                  for (i = 0; i < pEnc->mbParam.max_bframes+1; i++) {                  for (i = 0; i < pEnc->mbParam.max_bframes+1; i++) {
   
533                          image_destroy(&pEnc->queue[i].image, pEnc->mbParam.edged_width,                          image_destroy(&pEnc->queue[i].image, pEnc->mbParam.edged_width,
534                                            pEnc->mbParam.edged_height);                                            pEnc->mbParam.edged_height);
535                  }                  }
                 xvid_free(pEnc->queue);  
         }  
536    
537            xvid_free(pEnc->queue);
538    
539          if (pEnc->mbParam.max_bframes > 0) {          if (pEnc->mbParam.max_bframes > 0) {
540    
# Line 558  Line 545 
545    
546                          image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width,                          image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width,
547                                            pEnc->mbParam.edged_height);                                            pEnc->mbParam.edged_height);
   
548                          xvid_free(pEnc->bframes[i]->mbs);                          xvid_free(pEnc->bframes[i]->mbs);
   
549                          xvid_free(pEnc->bframes[i]);                          xvid_free(pEnc->bframes[i]);
550                  }                  }
551    
# Line 663  Line 648 
648      data.mb_height = pEnc->mbParam.mb_height;      data.mb_height = pEnc->mbParam.mb_height;
649      data.fincr = frame->fincr;      data.fincr = frame->fincr;
650      data.fbase = pEnc->mbParam.fbase;      data.fbase = pEnc->mbParam.fbase;
651            data.bquant_ratio = pEnc->mbParam.bquant_ratio;
652            data.bquant_offset = pEnc->mbParam.bquant_offset;
653    
654      for (i=0; i<3; i++) {      for (i=0; i<3; i++) {
655          data.min_quant[i] = pEnc->mbParam.min_quant[i];          data.min_quant[i] = pEnc->mbParam.min_quant[i];
# Line 1009  Line 996 
996                                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
997    
998                                  /* convert B-VOP to P-VOP */                                  /* convert B-VOP to P-VOP */
999                  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;
1000                                    pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */
1001                                    pEnc->current->quant /= pEnc->mbParam.bquant_ratio;
1002    
1003                  if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {                  if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {
1004                              image_copy(&pEnc->sOriginal, &pEnc->current->image,                              image_copy(&pEnc->sOriginal, &pEnc->current->image,
# Line 1097  Line 1086 
1086    
1087          if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {          if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1088                  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,
1089                          "%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);
1090          }          }
1091    
1092          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Line 1176  Line 1165 
1165                  }                  }
1166    
1167                  /* convert B-VOP quant to P-VOP */                  /* convert B-VOP quant to P-VOP */
1168                  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;
1169                    pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */
1170                    pEnc->current->quant /= pEnc->mbParam.bquant_ratio;
1171          type = P_VOP;          type = P_VOP;
1172      }      }
1173    
# Line 1199  Line 1190 
1190    
1191                  /* ---- update vol flags at IVOP ----------- */                  /* ---- update vol flags at IVOP ----------- */
1192                  pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags;                  pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags;
1193                    switch(frame->par) {
1194                    case XVID_PAR_11_VGA:
1195                    case XVID_PAR_43_PAL:
1196                    case XVID_PAR_43_NTSC:
1197                    case XVID_PAR_169_PAL:
1198                    case XVID_PAR_169_NTSC:
1199                    case XVID_PAR_EXT:
1200                            pEnc->mbParam.par = frame->par;
1201                            break;
1202                    default:
1203                            pEnc->mbParam.par = XVID_PAR_EXT;
1204                            break;
1205                    }
1206                    pEnc->mbParam.par_width = (frame->par_width)?frame->par_width:1;
1207                    pEnc->mbParam.par_height = (frame->par_height)?frame->par_height:1;
1208    
1209          if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) {          if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) {
1210                          if (frame->quant_intra_matrix != NULL)                          if (frame->quant_intra_matrix != NULL)
# Line 1406  Line 1412 
1412          pEnc->fMvPrevSigma = -1;          pEnc->fMvPrevSigma = -1;
1413          pEnc->mbParam.m_fcode = 2;          pEnc->mbParam.m_fcode = 2;
1414    
1415            pEnc->current->is_edged = 0; /* not edged */
1416            pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */
1417    
1418          return 1;                                       /* intra */          return 1;                                       /* intra */
1419  }  }
1420    
# Line 1448  Line 1457 
1457          }          }
1458    
1459    
1460            if (!reference->is_edged) {
1461          start_timer();          start_timer();
1462          image_setedges(pRef, pParam->edged_width, pParam->edged_height,          image_setedges(pRef, pParam->edged_width, pParam->edged_height,
1463                                     pParam->width, pParam->height);                                     pParam->width, pParam->height);
1464          stop_edges_timer();          stop_edges_timer();
1465                    reference->is_edged = 1;
1466            }
1467    
1468          pParam->m_rounding_type = 1 - pParam->m_rounding_type;          pParam->m_rounding_type = 1 - pParam->m_rounding_type;
1469          current->rounding_type = pParam->m_rounding_type;          current->rounding_type = pParam->m_rounding_type;
# Line 1463  Line 1475 
1475                  iLimit = mb_width * mb_height + 1;                  iLimit = mb_width * mb_height + 1;
1476    
1477          if ((current->vop_flags & XVID_VOP_HALFPEL)) {          if ((current->vop_flags & XVID_VOP_HALFPEL)) {
1478                    if (reference->is_interpolated != current->rounding_type) {
1479                  start_timer();                  start_timer();
1480                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,
1481                                                    &pEnc->vInterHV, pParam->edged_width,                                                    &pEnc->vInterHV, pParam->edged_width,
# Line 1470  Line 1483 
1483                                                    (pParam->vol_flags & XVID_VOL_QUARTERPEL),                                                    (pParam->vol_flags & XVID_VOL_QUARTERPEL),
1484                                                    current->rounding_type);                                                    current->rounding_type);
1485                  stop_inter_timer();                  stop_inter_timer();
1486                            reference->is_interpolated = current->rounding_type;
1487                    }
1488          }          }
1489    
1490          current->coding_type = P_VOP;          current->coding_type = P_VOP;
# Line 1492  Line 1507 
1507                                                                  &pEnc->vInterH,                                                                  &pEnc->vInterH,
1508                                                                  &pEnc->vInterV,                                                                  &pEnc->vInterV,
1509                                                                  &pEnc->vInterHV);                                                                  &pEnc->vInterHV);
1510                          gmcval += /*current->quant */ 2 * (int)(pParam->mb_width*pParam->mb_height);                  } else {
                 }  
   
1511                  gmcval = globalSAD(&current->warp, pParam, current->mbs,                  gmcval = globalSAD(&current->warp, pParam, current->mbs,
1512                                                          current,                                                          current,
1513                                                          &reference->image,                                                          &reference->image,
1514                                                          &current->image,                                                          &current->image,
1515                                                          pEnc->vGMC.y);                                                          pEnc->vGMC.y);
1516                    }
1517    
1518                  gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height);                  gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height);
1519    
1520  /* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */  /* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */
# Line 1568  Line 1583 
1583    
1584                                  current->sStat.kblks++;                                  current->sStat.kblks++;
1585    
1586                                    if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE)
1587                                    {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1588                                            qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */
1589                                            qcoeff[5*64+0]=0;
1590                                    }
1591                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);
1592                                  stop_coding_timer();                                  stop_coding_timer();
1593                                  continue;                                  continue;
# Line 1772  Line 1792 
1792                  memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height);                  memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height);
1793          }          }
1794    
1795            pEnc->current->is_edged = 0; /* not edged */
1796            pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */
1797    
1798            /* what was this frame's interpolated reference will become
1799                    forward (past) reference in b-frame coding */
1800    
1801            image_swap(&pEnc->vInterH, &pEnc->f_refh);
1802            image_swap(&pEnc->vInterV, &pEnc->f_refv);
1803            image_swap(&pEnc->vInterHV, &pEnc->f_refhv);
1804    
1805    
1806          /* XXX: debug          /* XXX: debug
1807          {          {
1808                  char s[100];                  char s[100];
# Line 1823  Line 1854 
1854  #endif  #endif
1855    
1856          /* forward  */          /* forward  */
1857            if (!pEnc->reference->is_edged) {
1858          image_setedges(f_ref, pEnc->mbParam.edged_width,          image_setedges(f_ref, pEnc->mbParam.edged_width,
1859                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1860                                     pEnc->mbParam.height);                                     pEnc->mbParam.height);
1861                    pEnc->current->is_edged = 1;
1862            }
1863    
1864            if (pEnc->reference->is_interpolated != 0) {
1865          start_timer();          start_timer();
1866          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,
1867                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1868                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);
1869          stop_inter_timer();          stop_inter_timer();
1870                    pEnc->reference->is_interpolated = 0;
1871            }
1872    
1873          /* backward */          /* backward */
1874            if (!pEnc->current->is_edged) {
1875          image_setedges(b_ref, pEnc->mbParam.edged_width,          image_setedges(b_ref, pEnc->mbParam.edged_width,
1876                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1877                                     pEnc->mbParam.height);                                     pEnc->mbParam.height);
1878                    pEnc->current->is_edged = 1;
1879            }
1880    
1881            if (pEnc->current->is_interpolated != 0) {
1882          start_timer();          start_timer();
1883          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1884                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1885                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);                                            (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);
1886          stop_inter_timer();          stop_inter_timer();
1887                    pEnc->current->is_interpolated = 0;
1888            }
1889    
1890          start_timer();          start_timer();
1891          MotionEstimationBVOP(&pEnc->mbParam, frame,          MotionEstimationBVOP(&pEnc->mbParam, frame,
# Line 1867  Line 1912 
1912          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
1913                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
1914                          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;  
1915    
1916                          /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */                          /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */
1917                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
1918                                  /* mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0; */                                  if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {
1919                                            MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image,
1920                                                                                            NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0);
1921                                    }
1922    
1923                                  continue;                                  continue;
1924                          }                          }
1925    
# Line 1894  Line 1942 
1942                                  }                                  }
1943                          }                          }
1944    
1945  #ifdef BFRAMES_DEC_DEBUG                          /* keep only bits 5-2 -- Chroma blocks will just be skipped by the
1946          BFRAME_DEBUG                           * coding function for BFrames, that's why we don't zero teh DC
1947  #endif                           * coeffs */
1948                            if ((frame->vop_flags & XVID_VOP_GREYSCALE))
1949                                    mb->cbp &= 0x3C;
1950    
1951                          start_timer();                          start_timer();
1952                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,                          MBCodingBVOP(frame, mb, qcoeff, frame->fcode, frame->bcode, bs,
1953                                                   &frame->sStat, direction);                                                   &frame->sStat);
1954                          stop_coding_timer();                          stop_coding_timer();
1955                  }                  }
1956          }          }

Legend:
Removed from v.1.95.2.38  
changed lines
  Added in v.1.95.2.50

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