Changeset 655 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncGOP.cpp


Ignore:
Timestamp:
23 Oct 2013, 23:01:30 (11 years ago)
Author:
tech
Message:

Merged 8.1-Cleanup@654

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r622 r655  
    153153#endif
    154154#endif
     155
     156#if KWU_FIX_URQ
     157  m_pcRateCtrl           = pcTEncTop->getRateCtrl();
     158#endif
    155159}
    156160
     
    351355#endif
    352356#if H_MV
    353 Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid)
    354 #else
    355 Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
     357Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid, bool isField, bool isTff)
     358#else
     359Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, bool isField, bool isTff)
    356360#endif
    357361{
     
    367371
    368372#if !H_MV
    369   xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
     373  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
     374
    370375 
    371376  m_iNumPicCoded = 0;
     
    439444
    440445    /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding
    441     Int pocCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC;
    442     Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
    443     if(iPOCLast == 0)
     446    Int iTimeOffset;
     447    Int pocCurr;
     448   
     449    if(iPOCLast == 0) //case first frame or first top field
    444450    {
    445451      pocCurr=0;
    446452      iTimeOffset = 1;
     453    }
     454    else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value
     455    {
     456      pocCurr = 1;
     457      iTimeOffset = 1;
     458    }
     459    else
     460    {
     461      pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
     462      iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
    447463    }
    448464    if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
     
    463479    accessUnitsInGOP.push_back(AccessUnit());
    464480    AccessUnit& accessUnit = accessUnitsInGOP.back();
    465     xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr );
     481    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField);
    466482
    467483    //  Slice data initialization
     
    472488
    473489
    474 #if H_MV5
    475490#if H_MV
    476     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
    477 #else
    478     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
    479 #endif
    480 #else
    481 #if H_3D
    482     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
    483 #else
    484     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
    485 #endif
    486 #endif
     491    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId(), isField  );     
     492#else
     493    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField  );
     494#endif
     495   
     496    //Set Frame/Field coding
     497    pcSlice->getPic()->setField(isField);
     498
    487499    pcSlice->setLastIDR(m_iLastIDR);
    488500    pcSlice->setSliceIdx(0);
    489501#if H_MV
    490 #if H_MV5
    491502    pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer0, &m_refPicSetInterLayer1 );
    492 #else
    493     pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer );
    494 #endif
    495503    pcPic  ->setLayerId     ( getLayerId()   );
    496504    pcPic  ->setViewId      ( getViewId()    );   
     
    508516    pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
    509517    pcSlice->setScalingList ( m_pcEncTop->getScalingList()  );
    510     pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip());
    511518    if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
    512519    {
     
    562569    if(pcSlice->getTemporalLayerNonReferenceFlag())
    563570    {
    564       if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
     571      if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
     572          !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
     573        // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker)
    565574      {
    566575        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
     
    655664    refPicListModification->setRefPicListModificationFlagL1(0);
    656665#if H_MV
    657 #if H_MV5
    658666    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 1 )
    659667    {
     
    699707    xSetRefPicListModificationsMv( tempRefPicLists, pcSlice, iGOPid );   
    700708#else
    701     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
    702     {
    703       pcSlice->setDiscardableFlag           ( false );     
    704     }   
    705 
    706     TComVPS*           vps = pcSlice->getVPS();
    707     Int       layerIdInVps = vps    ->getLayerIdInVps( getLayerId());
    708     Int numDirectRefLayers = vps    ->getNumDirectRefLayers( layerIdInVps );
    709     GOPEntry gopEntry      = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid );     
    710    
    711     if ( getLayerId() > 0 && numDirectRefLayers > 0 )
    712     {         
    713       pcSlice->setInterLayerPredEnabledFlag ( gopEntry.m_numActiveRefLayerPics > 0 );     
    714       if ( pcSlice->getInterLayerPredEnabledFlag() && numDirectRefLayers > 1 )
    715       {
    716         if ( !vps->getMaxOneActiveRefLayerFlag() )
    717         {   
    718           pcSlice->setNumInterLayerRefPicsMinus1( gopEntry.m_numActiveRefLayerPics - 1 );
    719         }
    720         for (Int i = 0; i < gopEntry.m_numActiveRefLayerPics; i++ )
    721         {
    722           pcSlice->setInterLayerPredLayerIdc( i, gopEntry.m_interLayerPredLayerIdc[ i ] );
    723         }
    724       }
    725     }
    726     assert( pcSlice->getNumActiveRefLayerPics() == gopEntry.m_numActiveRefLayerPics );
    727    
    728     if ( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0 && pcSlice->getNumActiveRefLayerPics() > 0)
    729     {
    730       pcSlice->setInterLayerSamplePredOnlyFlag( gopEntry.m_numRefPics == 0 );
    731     }   
    732 
    733     pcSlice->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer );
    734     pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
    735     pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
    736 
    737     xSetRefPicListModificationsMv( pcSlice, iGOPid );   
    738 
    739     pcSlice->setActiveMotionPredRefLayers( );
    740 
    741     if ( getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 && pcSlice->getEnableTMVPFlag() &&
    742         ( pcSlice->getSliceType() == B_SLICE || pcSlice->getSliceType() == P_SLICE ))
    743     {
    744       pcSlice->setAltCollocatedIndicationFlag( gopEntry.m_collocatedRefLayerIdx >= 0 );
    745       if ( pcSlice->getNumActiveRefLayerPics() && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
    746       {
    747         pcSlice->setCollocatedRefLayerIdx( gopEntry.m_collocatedRefLayerIdx );
    748       }
    749     }
    750 
    751 #endif
    752 #else
    753709    pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
    754710    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
     
    760716
    761717    //  Set reference list
    762 #if H_MV5
    763718#if H_MV   
    764719    pcSlice->setRefPicList( tempRefPicLists, usedAsLongTerm, numPocTotalCurr );
     
    782737      }
    783738    }
    784 #endif
    785 #else
    786 #if H_MV   
    787     pcSlice->setRefPicList( rcListPic, m_refPicSetInterLayer );
    788 #if H_3D_ARP
    789     pcSlice->setARPStepNum();
    790     if(pcSlice->getARPStepNum() > 1)
    791     {
    792       for(Int iLayerId = 0; iLayerId < getLayerId(); iLayerId ++ )
    793       {
    794         Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
    795         Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
    796         if( iViewIdx<getViewIndex() && !bIsDepth )
    797         {
    798           pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
    799         }
    800       }
    801     }
    802 #endif
    803 #else
    804     pcSlice->setRefPicList ( rcListPic );
    805 #endif
    806739#endif
    807740#if H_3D
     
    913846
    914847    // SAIT_VSO_EST_A0033
     848#if H_3D_FCO
     849    Bool flagRec;
     850    flagRec =  ((m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), true) == NULL) ? false: true);
     851    pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), flagRec ) );
     852    pcRdCost->setDepthPicYuv   ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true, pcSlice->getPOC(), false ) );
     853#else
    915854    pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false , pcSlice->getPOC(), true ) );
    916855    pcRdCost->setDepthPicYuv   ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true  , pcSlice->getPOC(), false ) );
     856#endif
    917857
    918858    // LGE_WVSO_A0119
     
    970910      }
    971911      m_pcRateCtrl->initRCPic( frameLevel );
     912
     913#if KWU_RC_MADPRED_E0227
     914      if(m_pcCfg->getLayerId() != 0)
     915      {
     916        m_pcRateCtrl->getRCPic()->setIVPic( m_pcEncTop->getEncTop()->getTEncTop(0)->getRateCtrl()->getRCPic() );
     917      }
     918#endif
     919
    972920      estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits();
    973921
     
    1014962      else    // normal case
    1015963      {
     964#if KWU_RC_MADPRED_E0227
     965        if(m_pcRateCtrl->getLayerID() != 0)
     966        {
     967          list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
     968          lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambdaIV( listPreviousPicture, pcSlice->getPOC() );
     969          sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
     970        }
     971        else
     972        {
     973#endif
    1016974        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
    1017975#if RATE_CONTROL_INTRA
     
    1021979#endif
    1022980        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
     981#if KWU_RC_MADPRED_E0227
     982        }
     983#endif
    1023984      }
    1024985
     
    11551116        pcPic->setNumDdvCandPics(pcPic->getDisCandRefPictures(iColPoc));
    11561117      }
     1118#endif
    11571119#if H_3D
    11581120      pcSlice->setDepthToDisparityLUTs();
    11591121
    11601122#endif
    1161 #endif
    1162 #if MTK_NBDV_TN_FIX_E0172
     1123
     1124#if H_3D_NBDV
    11631125      if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
    11641126      {
    11651127        pcPic->checkTemporalIVRef();
    11661128      }
    1167 #endif
    1168 #if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
     1129
    11691130      if(pcSlice->getIsDepth())
    11701131      {
     
    14121373        }
    14131374      }
    1414       pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
     1375      pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the .
    14151376      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
    14161377      Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
     
    18621823        pcPic->destroyNonDBFilterInfo();
    18631824      }
    1864 #if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
     1825#if H_3D
    18651826      pcPic->compressMotion(2);
    18661827#endif
     
    18981859          digestStr = digestToString(sei_recon_picture_digest.digest, 4);
    18991860        }
    1900 #if H_MV_FIX_LID_PIC_HASH_SEI_T40
     1861#if H_MV
    19011862        OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), getLayerId() );
    19021863#else
     
    19401901      xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime );
    19411902
     1903    //In case of field coding, compute the interlaced PSNR for both fields
     1904    if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
     1905    {
     1906      //get complementary top field
     1907      TComPic* pcPicTop;
     1908      TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
     1909      while ((*iterPic)->getPOC() != pcPic->getPOC()-1)
     1910      {
     1911        iterPic ++;
     1912      }
     1913      pcPicTop = *(iterPic);
     1914      xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
     1915    }
     1916   
    19421917      if (digestStr)
    19431918      {
     
    20722047            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    20732048          m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     2049          pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
    20742050          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
    20752051          writeRBSPTrailingBits(nalu.m_Bitstream);
     
    21662142      pcPic->setReconMark   ( true );
    21672143#if H_MV
    2168 #if H_MV5
    21692144      TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
    2170 #else
    2171       TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); 
    2172 #endif
    21732145      std::vector<Int> temp;
    21742146      TComSlice::markCurrPic( pcPic );
     
    21842156      delete[] pcSubstreamsOut;
    21852157  }
    2186 #if !RATE_CONTROL_LAMBDA_DOMAIN
     2158#if !KWU_FIX_URQ && !RATE_CONTROL_LAMBDA_DOMAIN
    21872159  if(m_pcCfg->getUseRateCtrl())
    21882160  {
     
    21962168
    21972169#if !H_MV
    2198   assert ( m_iNumPicCoded == iNumPicRcvd );
     2170  assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) );
    21992171#endif
    22002172}
    22012173
    22022174#if !H_MV
    2203 Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
     2175Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, bool isField)
    22042176{
    22052177  assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic());
     
    22072179   
    22082180  //--CFG_KDY
     2181  if(isField)
     2182  {
     2183    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2184    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2185    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2186    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2187  }
     2188  else
     2189  {
    22092190  m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
    22102191  m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
    22112192  m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
    22122193  m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
     2194  }
    22132195 
    22142196  //-- all
     
    22332215  m_gcAnalyzeB.printSummary('B');
    22342216#endif
     2217
     2218  if(isField)
     2219  {
     2220    //-- interlaced summary
     2221    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate());
     2222    printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
     2223    m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll.getBits());
     2224   
     2225#if _SUMMARY_OUT_
     2226    m_gcAnalyzeAll_in.printSummaryOutInterlaced();
     2227#endif
     2228  }
    22352229
    22362230  printf("\nRVM: %.3lf\n" , xCalculateRVM());
     
    22762270// Protected member functions
    22772271// ====================================================================================================================
     2272
     2273
     2274Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField )
     2275{
     2276  assert( iNumPicRcvd > 0 );
     2277  //  Exception for the first frames
     2278  if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField  && (iPOCLast == 0))  )
     2279  {
     2280    m_iGopSize    = 1;
     2281  }
     2282  else
     2283  {
     2284    m_iGopSize    = m_pcCfg->getGOPSize();
     2285  }
     2286  assert (m_iGopSize > 0);
     2287 
     2288  return;
     2289}
    22782290
    22792291Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut )
     
    22992311                         TComPic*&                 rpcPic,
    23002312                         TComPicYuv*&              rpcPicYuvRecOut,
    2301                          Int                       pocCurr )
     2313                         Int                       pocCurr,
     2314                         bool                      isField)
    23022315{
    23032316  Int i;
    23042317  //  Rec. output
    23052318  TComList<TComPicYuv*>::iterator     iterPicYuvRec = rcListPicYuvRecOut.end();
    2306   for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ )
     2319 
     2320  if (isField)
     2321  {
     2322    for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ )
     2323    {
     2324      iterPicYuvRec--;
     2325    }
     2326  }
     2327  else
     2328  {
     2329    for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ )
    23072330  {
    23082331    iterPicYuvRec--;
    23092332  }
    23102333 
     2334  }
     2335 
     2336  if (isField)
     2337  {
     2338    if(pocCurr == 1)
     2339    {
     2340      iterPicYuvRec++;
     2341    }
     2342  }
    23112343  rpcPicYuvRecOut = *(iterPicYuvRec);
    23122344 
     
    23232355    iterPic++;
    23242356  }
    2325  
     2357
     2358#if !H_MV
     2359  assert( rpcPic != NULL );
     2360#endif
    23262361  assert (rpcPic->getPOC() == pocCurr);
    23272362 
     
    26422677}
    26432678
     2679
     2680Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, bool isTff)
     2681{
     2682 
     2683  for (Int y = 0; y < height; y++)
     2684  {
     2685    for (Int x = 0; x < width; x++)
     2686    {
     2687      dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
     2688      dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     2689    }
     2690    top += stride;
     2691    bottom += stride;
     2692    dst += stride*2;
     2693  }
     2694}
     2695
     2696
     2697Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime )
     2698{
     2699#if  H_MV
     2700  assert( 0 ); // Field coding and MV need to be aligned.
     2701#else
     2702  Int     x, y;
     2703 
     2704  UInt64 uiSSDY_in  = 0;
     2705  UInt64 uiSSDU_in  = 0;
     2706  UInt64 uiSSDV_in  = 0;
     2707 
     2708  Double  dYPSNR_in  = 0.0;
     2709  Double  dUPSNR_in  = 0.0;
     2710  Double  dVPSNR_in  = 0.0;
     2711 
     2712  /*------ INTERLACED PSNR -----------*/
     2713 
     2714  /* Luma */
     2715 
     2716  Pel*  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr();
     2717  Pel*  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr();
     2718  Pel*  pRecTop = pcPicRecTop->getLumaAddr();
     2719  Pel*  pRecBottom = pcPicRecBottom->getLumaAddr();
     2720 
     2721  Int   iWidth;
     2722  Int   iHeight;
     2723  Int iStride;
     2724 
     2725  iWidth  = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0);
     2726  iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1);
     2727  iStride = pcPicOrgTop->getPicYuvOrg()->getStride();
     2728  Int   iSize   = iWidth*iHeight;
     2729  bool isTff = pcPicOrgTop->isTopField();
     2730 
     2731  TComPicYuv* pcOrgInterlaced = new TComPicYuv;
     2732  pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     2733 
     2734  TComPicYuv* pcRecInterlaced = new TComPicYuv;
     2735  pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     2736 
     2737  Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr();
     2738  Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr();
     2739 
     2740  //=== Interlace fields ====
     2741  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     2742  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     2743 
     2744  //===== calculate PSNR =====
     2745  for( y = 0; y < iHeight << 1; y++ )
     2746  {
     2747    for( x = 0; x < iWidth; x++ )
     2748    {
     2749      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     2750      uiSSDY_in   += iDiff * iDiff;
     2751    }
     2752    pOrgInterlaced += iStride;
     2753    pRecInterlaced += iStride;
     2754  }
     2755 
     2756  /*Chroma*/
     2757 
     2758  iHeight >>= 1;
     2759  iWidth  >>= 1;
     2760  iStride >>= 1;
     2761 
     2762  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr();
     2763  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr();
     2764  pRecTop = pcPicRecTop->getCbAddr();
     2765  pRecBottom = pcPicRecBottom->getCbAddr();
     2766  pOrgInterlaced = pcOrgInterlaced->getCbAddr();
     2767  pRecInterlaced = pcRecInterlaced->getCbAddr();
     2768 
     2769  //=== Interlace fields ====
     2770  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     2771  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     2772 
     2773  //===== calculate PSNR =====
     2774  for( y = 0; y < iHeight << 1; y++ )
     2775  {
     2776    for( x = 0; x < iWidth; x++ )
     2777    {
     2778      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     2779      uiSSDU_in   += iDiff * iDiff;
     2780    }
     2781    pOrgInterlaced += iStride;
     2782    pRecInterlaced += iStride;
     2783  }
     2784 
     2785  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr();
     2786  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr();
     2787  pRecTop = pcPicRecTop->getCrAddr();
     2788  pRecBottom = pcPicRecBottom->getCrAddr();
     2789  pOrgInterlaced = pcOrgInterlaced->getCrAddr();
     2790  pRecInterlaced = pcRecInterlaced->getCrAddr();
     2791 
     2792  //=== Interlace fields ====
     2793  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     2794  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     2795 
     2796  //===== calculate PSNR =====
     2797  for( y = 0; y < iHeight << 1; y++ )
     2798  {
     2799    for( x = 0; x < iWidth; x++ )
     2800    {
     2801      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     2802      uiSSDV_in   += iDiff * iDiff;
     2803    }
     2804    pOrgInterlaced += iStride;
     2805    pRecInterlaced += iStride;
     2806  }
     2807 
     2808  Int maxvalY = 255 << (g_bitDepthY-8);
     2809  Int maxvalC = 255 << (g_bitDepthC-8);
     2810  Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2;
     2811  Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0;
     2812  dYPSNR_in            = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 );
     2813  dUPSNR_in            = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 );
     2814  dVPSNR_in            = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 );
     2815 
     2816  /* calculate the size of the access unit, excluding:
     2817   *  - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
     2818   *  - SEI NAL units
     2819   */
     2820  UInt numRBSPBytes = 0;
     2821  for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
     2822  {
     2823    UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
     2824   
     2825    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
     2826      numRBSPBytes += numRBSPBytes_nal;
     2827  }
     2828 
     2829  UInt uibits = numRBSPBytes * 8 ;
     2830 
     2831  //===== add PSNR =====
     2832  m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits);
     2833 
     2834  printf("\n                                      Interlaced frame %d: [Y %6.4lf dB    U %6.4lf dB    V %6.4lf dB]", pcPicOrgBottom->getPOC()/2 , dYPSNR_in, dUPSNR_in, dVPSNR_in );
     2835 
     2836  pcOrgInterlaced->destroy();
     2837  delete pcOrgInterlaced;
     2838  pcRecInterlaced->destroy();
     2839  delete pcRecInterlaced;
     2840#endif
     2841}
    26442842/** Function for deciding the nal_unit_type.
    26452843 * \param pocCurr POC of the current picture
     
    30023200
    30033201#if H_MV
    3004 #if H_MV5
    30053202Void TEncGOP::xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid )
    30063203{
     
    30863283  }
    30873284}
    3088 #else
    3089 Void TEncGOP::xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid )
    3090 {
    3091   Int layer    = pcSlice->getLayerIdInVps( );
    3092  
    3093   if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || pcSlice->getNumActiveRefLayerPics() == 0 )
    3094   {
    3095     return;
    3096   }
    3097 
    3098   // analyze inter-view modifications
    3099   GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( layer > 0) ) ? MAX_GOP : iGOPid );
    3100   assert( ge.m_numActiveRefLayerPics == pcSlice->getNumActiveRefLayerPics() );
    3101  
    3102   Int maxRefListSize  = pcSlice->getNumRpsCurrTempList();
    3103   Int numTemporalRefs = maxRefListSize - pcSlice->getNumActiveRefLayerPics();
    3104 
    3105   for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1
    3106   {
    3107     // set inter-view modifications   
    3108     Int tempList[16];
    3109     for( Int k = 0; k < 16; k++ )
    3110     {
    3111       tempList[ k ] = -1;
    3112     }
    3113 
    3114     Bool isModified = false;
    3115     if ( maxRefListSize > 1 )
    3116     {
    3117       for( Int k = 0, orgIdx = numTemporalRefs; k < ge.m_numActiveRefLayerPics; k++, orgIdx++ )
    3118       {
    3119           Int targetIdx = ge.m_interViewRefPosL[ li ][ k ];
    3120 
    3121         isModified = ( targetIdx != orgIdx ) && ( targetIdx >= 0  );
    3122         if ( isModified )
    3123             {
    3124           assert( tempList[ targetIdx ] == -1 ); // Assert when two inter layer reference pictures are sorted to the same position
    3125               tempList[ targetIdx ] = orgIdx;             
    3126         }
    3127       }
    3128     }
    3129 
    3130     TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
    3131     refPicListModification->setRefPicListModificationFlagL( li, isModified ); 
    3132 
    3133       if( isModified )
    3134       {
    3135         Int temporalRefIdx = 0;
    3136         for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ )
    3137         {
    3138           if( tempList[i] >= 0 )
    3139           {
    3140             refPicListModification->setRefPicSetIdxL( li, i, tempList[i] );
    3141           }
    3142           else
    3143           {
    3144             refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx );
    3145             temporalRefIdx++;
    3146           }
    3147         }
    3148       }
    3149   }
    3150 }
    3151 #endif
    31523285#endif
    31533286//! \}
Note: See TracChangeset for help on using the changeset viewer.