Ignore:
Timestamp:
14 Oct 2013, 20:13:58 (12 years ago)
Author:
kwu-htm
Message:

"JCT3V-E0227 : Inter-view MAD prediction for 3D multi-view video" is integrated by KWU. Configuration has changed by adding rate control for URQ and the integrated view-wise target bitrate allocation and inter-view MAD prediction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp

    r608 r635  
    537537  m_lastPicture  = NULL;
    538538#endif
     539
     540#if KWU_RC_MADPRED_E0227
     541  m_lastIVPicture = NULL;
     542#endif
     543
    539544  m_picActualHeaderBits = 0;
    540545#if !M0036_RC_IMPROVEMENT
     
    544549  m_picQP               = 0;
    545550  m_picLambda           = 0.0;
     551
     552#if KWU_RC_MADPRED_E0227
     553  m_IVtotalMAD            = 0.0;
     554#endif
    546555}
    547556
     
    621630}
    622631
     632#if KWU_RC_MADPRED_E0227
     633Void TEncRCPic::addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures )
     634{
     635  m_lastIVPicture = NULL;
     636  m_lastIVPicture = this;
     637}
     638
     639Void TEncRCPic::setIVPic( TEncRCPic* BaseRCPic )
     640{
     641  m_lastIVPicture = BaseRCPic;
     642}
     643#endif
     644
     645#if KWU_RC_MADPRED_E0227
     646Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int LayerID )
     647#else
    623648Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures )
     649#endif
    624650{
    625651  destroy();
     
    673699      Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
    674700      m_LCUs[LCUIdx].m_numberOfPixel = currWidth * currHeight;
     701
     702#if KWU_RC_MADPRED_E0227
     703      m_LCUs[LCUIdx].m_CUWidth = currWidth;
     704      m_LCUs[LCUIdx].m_CUHeight = currHeight;
     705      m_LCUs[LCUIdx].m_IVMAD = -1.0;
     706#endif
    675707    }
    676708  }
     
    683715  m_picLambda           = 0.0;
    684716
     717
     718#if KWU_RC_MADPRED_E0227
     719  m_LayerID = LayerID;
     720  m_lastIVPicture = NULL;
     721  m_IVtotalMAD            = 0.0;
     722#endif
     723
     724
    685725#if !M0036_RC_IMPROVEMENT
    686726  m_lastPicture = NULL;
    687727  list<TEncRCPic*>::reverse_iterator it;
     728  for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
     729  {
     730    if ( (*it)->getFrameLevel() == m_frameLevel )
     731    {
     732      m_lastPicture = (*it);
     733      break;
     734    }
     735  }
     736#endif
     737
     738#if KWU_RC_MADPRED_E0227
     739  list<TEncRCPic*>::reverse_iterator it;
     740  if( m_LayerID != 0)
     741  {
     742    m_lastIVPicture = NULL;
     743    for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
     744    {
     745      if ( (*it)->getLayerID() == 0 )
     746      {
     747        m_lastIVPicture = (*it);
     748        break;
     749      }
     750    }
     751  }
     752
     753  m_lastPicture = NULL;
    688754  for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
    689755  {
     
    856922}
    857923
     924
     925#if KWU_RC_MADPRED_E0227
     926Double TEncRCPic::estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int CurPOC )
     927{
     928  Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
     929  Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
     930  Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
     931  Double estLambda = alpha * pow( bpp, beta );
     932  Double lastLevelLambda = -1.0;
     933  Double lastPicLambda   = -1.0;
     934  Double lastValidLambda = -1.0;
     935  list<TEncRCPic*>::iterator it;
     936
     937  if(listPreviousPictures.size() == 0 || CurPOC%8 == 0)
     938  {
     939    lastLevelLambda = m_lastIVPicture->getPicActualLambda();
     940    lastPicLambda     = m_lastIVPicture->getPicActualLambda();
     941  }
     942  else
     943  {
     944    for ( it = listPreviousPictures.begin(); it != listPreviousPictures.end(); it++ )
     945    {
     946      if ( (*it)->getFrameLevel() == m_frameLevel )
     947      {
     948        lastLevelLambda = (*it)->getPicActualLambda();
     949      }
     950      lastPicLambda     = (*it)->getPicActualLambda();
     951
     952      if ( lastPicLambda > 0.0 )
     953      {
     954        lastValidLambda = lastPicLambda;
     955      }
     956    }
     957  }
     958
     959  if ( lastLevelLambda > 0.0 )
     960  {
     961    lastLevelLambda = Clip3( 0.1, 10000.0, lastLevelLambda );
     962    estLambda = Clip3( lastLevelLambda * pow( 2.0, -3.0/3.0 ), lastLevelLambda * pow( 2.0, 3.0/3.0 ), estLambda );
     963  }
     964
     965  if ( lastPicLambda > 0.0 )
     966  {
     967    lastPicLambda = Clip3( 0.1, 2000.0, lastPicLambda );
     968    estLambda = Clip3( lastPicLambda * pow( 2.0, -10.0/3.0 ), lastPicLambda * pow( 2.0, 10.0/3.0 ), estLambda );
     969  }
     970  else if ( lastValidLambda > 0.0 )
     971  {
     972    lastValidLambda = Clip3( 0.1, 2000.0, lastValidLambda );
     973    estLambda = Clip3( lastValidLambda * pow(2.0, -10.0/3.0), lastValidLambda * pow(2.0, 10.0/3.0), estLambda );
     974  }
     975  else
     976  {
     977    estLambda = Clip3( 0.1, 10000.0, estLambda );
     978  }
     979
     980  if ( estLambda < 0.1 )
     981  {
     982    estLambda = 0.1;
     983  }
     984
     985  m_estPicLambda = estLambda;
     986  return estLambda;
     987}
     988#endif
     989
     990
    858991#if RATE_CONTROL_INTRA
    859992Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 
     
    9371070}
    9381071
     1072
     1073#if KWU_RC_MADPRED_E0227
     1074Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction, Int* iDisparity )
     1075{
     1076  Int   LCUIdx    = getLCUCoded();
     1077  Double bpp      = -1.0;
     1078  Int avgBits     = 0;
     1079#if !M0036_RC_IMPROVEMENT
     1080  Double totalMAD = -1.0;
     1081  Double MAD      = -1.0;
     1082#endif
     1083
     1084  Double totalMAD = -1.0;
     1085  Double MAD      = -1.0;
     1086
     1087  Double IVMAD      = -1.0;
     1088  Double SAD = 0.0;
     1089  Int     x, y;
     1090  Int Sum = 0;
     1091
     1092  {
     1093    Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     1094    Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvPred()->getLumaAddr(pcCU->getAddr(), 0);
     1095    Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     1096    Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
     1097
     1098    Int   iWidth  = m_LCUs[ LCUIdx ].m_CUWidth;
     1099    Int   iHeight = m_LCUs[ LCUIdx ].m_CUHeight;
     1100
     1101    for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
     1102    {
     1103      for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
     1104      {
     1105        Sum += pDep[x];
     1106      }
     1107      pDep += iStride;
     1108    }
     1109
     1110    Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
     1111
     1112    //Int iDisparity = pDepthGen->RCGetDisparityFromVirtDepth(0, (Int)AvgDepth);
     1113
     1114    Double dFL = FocalLen * abs( BasePos - CurPos );
     1115    Double dZ  = abs( 1.0 / Znear - 1.0 / Zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / Zfar);
     1116    *iDisparity = (Int)(Direction*dFL * dZ);
     1117    Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
     1118
     1119    Int Disp = *iDisparity;
     1120    Int PosX, PosY;
     1121    pcCU->getPosInPic(0, PosX, PosY);
     1122    if((PosX + *iDisparity) < 0 || (PosX + *iDisparity + iWidth) >= pcCU->getSlice()->getSPS()->getMaxCUWidth())
     1123      Disp = 0;
     1124
     1125    for( y = 0; y < iHeight; y++ )
     1126    {
     1127      for( x = 0; x < iWidth; x++ )
     1128      {
     1129        SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)]
     1130                  - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)] )>>shift;
     1131      }
     1132      pOrg += iStride;
     1133      pRec += iStride;
     1134    }
     1135    IVMAD = SAD / (Double)(iHeight * iWidth);
     1136    IVMAD = IVMAD * IVMAD;
     1137
     1138    m_LCUs[ LCUIdx ].m_IVMAD = IVMAD;
     1139    if(m_lastPicture)
     1140      m_LCUs[ LCUIdx ].m_MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;
     1141
     1142    MAD = m_LCUs[ LCUIdx ].m_IVMAD;
     1143
     1144    if(m_lastPicture)
     1145    {
     1146      totalMAD = m_lastPicture->getTotalMAD();      // get total MAD of temporal frame
     1147      for ( Int i=0; i<LCUIdx; i++ )
     1148      {
     1149        totalMAD -= m_lastPicture->getLCU(i).m_MAD;
     1150      }
     1151    }
     1152    else
     1153    {
     1154      totalMAD = m_lastIVPicture->getTotalMAD();      // get total MAD of inter-view frame
     1155      for ( Int i=0; i<LCUIdx; i++ )
     1156      {
     1157        totalMAD -= m_lastIVPicture->getLCU(i).m_MAD;
     1158      }
     1159    }
     1160
     1161
     1162    if ( totalMAD > 0.1 )
     1163    {
     1164      avgBits = Int( (m_bitsLeft * MAD) / totalMAD );
     1165    }
     1166    else
     1167    {
     1168      avgBits = Int( (m_bitsLeft) / m_LCULeft );
     1169    }
     1170  }
     1171
     1172  if ( avgBits < 5 )
     1173  {
     1174    avgBits = 5;
     1175  }
     1176
     1177  bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
     1178  m_LCUs[ LCUIdx ].m_targetBits = avgBits;
     1179
     1180  return bpp;
     1181}
     1182#endif
     1183
     1184
     1185
     1186
    9391187Double TEncRCPic::getLCUEstLambda( Double bpp )
    9401188{
     
    11851433  }
    11861434  m_picLambda           = averageLambda;
    1187 #if !M0036_RC_IMPROVEMENT
     1435#if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
     1436  m_totalMAD = 0;
    11881437  for ( Int i=0; i<m_numberOfLCU; i++ )
    11891438  {
     
    13931642
    13941643#if M0036_RC_IMPROVEMENT
     1644#if KWU_RC_MADPRED_E0227
     1645Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP], Int LayerID )
     1646#else
    13951647Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
     1648#endif
    13961649#else
    13971650Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
     
    16071860  }
    16081861
     1862#if KWU_RC_MADPRED_E0227
     1863  setLayerID(LayerID);
     1864#endif
     1865
    16091866  delete[] bitsRatio;
    16101867  delete[] GOPID2Level;
     
    16141871{
    16151872  m_encRCPic = new TEncRCPic;
     1873#if KWU_RC_MADPRED_E0227
     1874  m_encRCPic->create( m_encRCSeq, m_encRCGOP, frameLevel, m_listRCPictures, m_LayerID );
     1875#else
    16161876  m_encRCPic->create( m_encRCSeq, m_encRCGOP, frameLevel, m_listRCPictures );
     1877#endif
    16171878}
    16181879
     
    18152076  m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0); 
    18162077  m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
    1817   m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
    1818   m_currBitrate              = ( targetKbps << 10 );
     2078  m_prevBitrate              = ( targetKbps * 1000 );  // in units of 1,024 bps
     2079  m_currBitrate              = ( targetKbps * 1000 );
    18192080  m_frameRate                = frameRate;
    18202081  m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
     
    21922453
    21932454  Pel*  pOrg   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
    2194   Pel*  pRec   = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
     2455  Pel*  pRec   = pcCU->getPic()->getPicYuvPred()->getLumaAddr(pcCU->getAddr(), 0);
    21952456  Int   stride = pcCU->getPic()->getStride();
    21962457
     
    22122473}
    22132474
     2475
     2476#if KWU_RC_MADPRED_E0227
     2477Void  TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int iQP, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction)
     2478{
     2479  Int     x, y;
     2480  double dMAD = 0.0;
     2481  Int Sum = 0;
     2482  Double SAD = 0.0;
     2483
     2484  Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     2485  Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvPred()->getLumaAddr(pcCU->getAddr(), 0);
     2486  Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     2487  Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
     2488
     2489  Int   iWidth  = m_pcLCUData[m_indexLCU].m_widthInPixel;
     2490  Int   iHeight = m_pcLCUData[m_indexLCU].m_heightInPixel;
     2491
     2492  for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
     2493  {
     2494    for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
     2495    {
     2496      Sum += pDep[x];
     2497    }
     2498    pDep += iStride;
     2499  }
     2500
     2501  Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
     2502
     2503  //Int iDisparity = pDepthGen->RCGetDisparityFromVirtDepth(0, (Int)AvgDepth);
     2504
     2505  Double dFL = FocalLen * abs( BasePos - CurPos );
     2506  Double dZ  = abs( 1.0 / Znear - 1.0 / Zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / Zfar);
     2507  Int   iDisparity = (Int)(Direction*dFL * dZ);
     2508  Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
     2509  Int Disp = iDisparity;
     2510
     2511  for( y = 0; y < iHeight; y++ )
     2512  {
     2513    for( x = 0; x < iWidth; x++ )
     2514    {
     2515      SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)]
     2516      - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)] )>>shift;
     2517    }
     2518    pOrg += iStride;
     2519    pRec += iStride;
     2520  }
     2521  m_pcLCUData[m_indexLCU].m_qp   = iQP;
     2522  m_pcLCUData[m_indexLCU].m_costMAD  = (SAD /(Double)(iWidth*iHeight));
     2523  m_pcLCUData[m_indexLCU].m_bits = (Int)uiBits;
     2524}
     2525#endif
     2526
     2527
    22142528Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)
    22152529{
Note: See TracChangeset for help on using the changeset viewer.