Changeset 431 in SHVCSoftware for branches/SHM-3.1-dev/source/Lib/TLibEncoder


Ignore:
Timestamp:
11 Oct 2013, 05:54:02 (11 years ago)
Author:
seregin
Message:

initial porting of HM12

Location:
branches/SHM-3.1-dev/source/Lib/TLibEncoder
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncAnalyze.cpp

    r313 r431  
    5757#endif
    5858
     59TEncAnalyze             m_gcAnalyzeAll_in;
    5960//! \}
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncAnalyze.h

    r313 r431  
    131131    fclose(pFile);
    132132  }
     133
     134  Void    printOutInterlaced ( Char cDelim, Double bits )
     135  {
     136    Double dFps     =   m_dFrmRate; //--CFG_KDY
     137    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
     138   
     139    printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
     140    //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
     141    printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
     142           getNumPic(), cDelim,
     143           bits * dScale,
     144           getPsnrY() / (Double)getNumPic(),
     145           getPsnrU() / (Double)getNumPic(),
     146           getPsnrV() / (Double)getNumPic() );
     147  }
     148 
     149  Void    printSummaryOutInterlaced (Int bits)
     150  {
     151    FILE* pFile = fopen ("summaryTotal.txt", "at");
     152    Double dFps     =   m_dFrmRate; //--CFG_KDY
     153    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
     154   
     155    fprintf(pFile, "%f\t %f\t %f\t %f\n", bits * dScale,
     156            getPsnrY() / (Double)getNumPic(),
     157            getPsnrU() / (Double)getNumPic(),
     158            getPsnrV() / (Double)getNumPic() );
     159    fclose(pFile);
     160  }
    133161 
    134162  Void    printSummary(Char ch)
     
    178206#endif
    179207
     208extern TEncAnalyze             m_gcAnalyzeAll_in;
    180209//! \}
    181210
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp

    r427 r431  
    12811281      if( !pcSlice->getPocResetFlag() )
    12821282      {
    1283         picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
     1283        picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    12841284      }
    12851285      else
    12861286      {
    1287         picOrderCntLSB = (pcSlice->getPocValueBeforeReset()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
    1288       }
    1289 #else
    1290       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
     1287        picOrderCntLSB = (pcSlice->getPocValueBeforeReset()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
     1288      }
     1289#else
     1290      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    12911291#endif
    12921292      WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
     
    21422142{
    21432143  // Bool state = true, state2 = false;
    2144   Int lsb = ltrpPOC % (1<<pcSlice->getSPS()->getBitsForPOC());
     2144  Int lsb = ltrpPOC & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    21452145  for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++)
    21462146  {
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCu.cpp

    r389 r431  
    379379  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
    380380
    381   // variables for fast encoder decision
    382   Bool    bEarlySkip  = false;
    383   Bool    bTrySplit    = true;
    384   Double  fRD_Skip    = MAX_DOUBLE;
    385 
    386381  // variable for Early CU determination
    387382  Bool    bSubBranch = true;
     
    390385  Bool    doNotBlockPu = true;
    391386  Bool earlyDetectionSkipMode = false;
    392 
    393   Bool    bTrySplitDQP  = true;
    394 
    395   static  Double  afCost[ MAX_CU_DEPTH ];
    396   static  Int      aiNum [ MAX_CU_DEPTH ];
    397 
    398   if ( rpcBestCU->getAddr() == 0 )
    399   {
    400     ::memset( afCost, 0, sizeof( afCost ) );
    401     ::memset( aiNum,  0, sizeof( aiNum  ) );
    402   }
    403387
    404388  Bool bBoundary = false;
     
    471455    if (rpcBestCU->getLayerId() > 0)
    472456    {
    473         if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx())
    474             testInter = false;
    475         if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx())
    476             testInter = false;
     457      if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx())
     458      {
     459        testInter = false;
     460      }
     461      if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx())
     462      {
     463        testInter = false;
     464      }
    477465#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
    478         if( pcSlice->getInterLayerSamplePredOnlyFlag() )
    479             testInter = false;
     466      if( pcSlice->getInterLayerSamplePredOnlyFlag() )
     467      {
     468        testInter = false;
     469      }
    480470#endif
    481471    }
     
    487477        iQP = lowestQP;
    488478      }
    489       // variables for fast encoder decision
    490       bEarlySkip  = false;
    491       bTrySplit    = true;
    492       fRD_Skip    = MAX_DOUBLE;
    493479
    494480      rpcTempCU->initEstData( uiDepth, iQP );
     
    509495        xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
    510496        rpcTempCU->initEstData( uiDepth, iQP );
    511 
    512         // fast encoder decision for early skip
    513         if ( m_pcEncCfg->getUseFastEnc() )
    514         {
    515           Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
    516           if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] )
    517           {
    518             bEarlySkip = true;
    519             bTrySplit  = false;
    520           }
    521         }
     497       
    522498#if (ENCODER_FAST_MODE == 2)
    523499        if (testInter)
    524500        {
    525501#endif
    526 
    527502        if(!m_pcEncCfg->getUseEarlySkipDetection())
    528503        {
    529504          // 2Nx2N, NxN
    530           if ( !bEarlySkip )
     505          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
     506          if(m_pcEncCfg->getUseCbfFastMode())
    531507          {
    532             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
    533             if(m_pcEncCfg->getUseCbfFastMode())
    534             {
    535               doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    536             }
     508            doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    537509          }
    538510        }
    539511#if (ENCODER_FAST_MODE == 2)
    540     }
    541 #endif
    542 
    543       }
    544 
    545       if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
    546       {
    547         if(iQP == iBaseQP)
    548         {
    549           bTrySplitDQP = bTrySplit;
    550         }
    551       }
    552       else
    553       {
    554         bTrySplitDQP = bTrySplit;
    555       }
     512        }
     513#endif
     514      }
     515
    556516      if (isAddLowestQP && (iQP == lowestQP))
    557517      {
     
    580540        // do inter modes, NxN, 2NxN, and Nx2N
    581541#if (ENCODER_FAST_MODE)
    582       if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
     542        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
    583543#else
    584544        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
     
    586546        {
    587547          // 2Nx2N, NxN
    588           if ( !bEarlySkip )
     548          if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
    589549          {
    590             if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
     550            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
    591551            {
    592               if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
    593               {
    594                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
    595                 rpcTempCU->initEstData( uiDepth, iQP );
    596               }
     552              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
     553              rpcTempCU->initEstData( uiDepth, iQP );
    597554            }
    598555          }
     
    734691
    735692        // do normal intra modes
    736         if ( !bEarlySkip )
    737         {
    738693          // speedup for inter frames
    739694#if (ENCODER_FAST_MODE)
     
    761716            }
    762717          }
    763         }
    764718
    765719        // test PCM
     
    803757    rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
    804758
    805     // accumulate statistics for early skip
    806     if ( m_pcEncCfg->getUseFastEnc() )
    807     {
    808       if ( rpcBestCU->isSkipped(0) )
    809       {
    810         Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
    811         afCost[ iIdx ] += rpcBestCU->getTotalCost();
    812         aiNum [ iIdx ] ++;
    813       }
    814     }
    815 
    816759    // Early CU determination
    817760    if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
     
    896839
    897840    // further split
    898     if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
     841    if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
    899842    {
    900843      UChar       uhNextDepth         = uiDepth+1;
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp

    r429 r431  
    375375// ====================================================================================================================
    376376#if SVC_EXTENSION
    377 Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
    378 #else
    379 Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
     377Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff)
     378#else
     379Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff)
    380380#endif
    381381{
     
    390390  TComOutputBitstream* pcSubstreamsOut = NULL;
    391391
    392   xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
     392  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
    393393
    394394  m_iNumPicCoded = 0;
     
    463463
    464464    /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding
    465     Int pocCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC;
    466     Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
    467     if(iPOCLast == 0)
     465    Int iTimeOffset;
     466    Int pocCurr;
     467   
     468    if(iPOCLast == 0) //case first frame or first top field
    468469    {
    469470      pocCurr=0;
    470471      iTimeOffset = 1;
    471472    }
     473    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
     474    {
     475      pocCurr = 1;
     476      iTimeOffset = 1;
     477    }
     478    else
     479    {
     480      pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
     481      iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
     482    }
     483
    472484    if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
    473485    {
     
    490502    accessUnitsInGOP.push_back(AccessUnit());
    491503    AccessUnit& accessUnit = accessUnitsInGOP.back();
    492     xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr );
     504    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField );
    493505
    494506    //  Slice data initialization
     
    499511#if SVC_EXTENSION
    500512    pcPic->setLayerId( m_layerId );
    501     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS() );
    502 #else
    503     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
    504 #endif
     513    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS(), isField );
     514#else
     515    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField );
     516#endif
     517
     518    //Set Frame/Field coding
     519    pcSlice->getPic()->setField(isField);
     520
    505521#if POC_RESET_FLAG
    506522    if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files.
     
    602618    pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
    603619    pcSlice->setScalingList ( m_pcEncTop->getScalingList()  );
    604     pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip());
    605620    if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
    606621    {
     
    818833      }
    819834    }
    820 #endif //SVC_EXTENSION
     835#endif //#if SVC_EXTENSION
    821836    if(pcSlice->getTemporalLayerNonReferenceFlag())
    822837    {
    823       if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
     838      if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
     839          !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
     840        // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker)
    824841      {
    825842        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
     
    863880        else
    864881        {
    865           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R);
     882          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
    866883        }
    867884#if ALIGN_TSA_STSA_PICS
     
    875892            {
    876893              assert( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) ||
    877                       ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R ) );
     894                      ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R ) );
    878895              // TSA pictures are aligned within an access unit.
    879896            }
     
    10191036      if( pcSlice->getMFMEnabledFlag() )
    10201037#else
    1021         if( pcSlice->getSPS()->getMFMEnabledFlag() )
    1022 #endif
    1023         {
    1024           pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic());
     1038      if( pcSlice->getSPS()->getMFMEnabledFlag() )
     1039#endif
     1040      {
     1041        pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic());
    10251042#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
    1026           pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
    1027 #endif
    1028         }
    1029 #else
    1030     //  Set reference list
    1031     pcSlice->setRefPicList ( rcListPic );
     1043        pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
     1044#endif
     1045      }
     1046#else
     1047      //  Set reference list
     1048      pcSlice->setRefPicList ( rcListPic );
    10321049#endif //SVC_EXTENSION
    10331050      pcSlice->setRefPicListModificationSvc();
     
    10801097#endif
    10811098    }
    1082 #endif
     1099#else //SVC_EXTENSION
     1100    //  Set reference list
     1101    pcSlice->setRefPicList ( rcListPic );
     1102#endif //#if SVC_EXTENSION
    10831103
    10841104    //  Slice info. refinement
     
    16621682        }
    16631683      }
    1664       pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
     1684      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 .
    16651685#if POC_RESET_FLAG
    16661686      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded;
     
    22012221      xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime );
    22022222
     2223      //In case of field coding, compute the interlaced PSNR for both fields
     2224      if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
     2225      {
     2226        //get complementary top field
     2227        TComPic* pcPicTop;
     2228        TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
     2229        while ((*iterPic)->getPOC() != pcPic->getPOC()-1)
     2230        {
     2231          iterPic ++;
     2232        }
     2233        pcPicTop = *(iterPic);
     2234        xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
     2235      }
     2236
    22032237      if (digestStr)
    22042238      {
     
    23332367            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    23342368          m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     2369          pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
    23352370          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
    23362371          writeRBSPTrailingBits(nalu.m_Bitstream);
     
    24512486
    24522487#if SVC_EXTENSION
    2453   assert ( m_iNumPicCoded <= 1 );
    2454 #else
    2455   assert ( m_iNumPicCoded == iNumPicRcvd );
     2488  assert ( m_iNumPicCoded <= 1 || (isField && iPOCLast == 1) );
     2489#else
     2490  assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) );
    24562491#endif
    24572492}
    24582493
    24592494#if !SVC_EXTENSION
    2460 Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
     2495Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, Bool isField)
    24612496{
    24622497  assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic());
     
    24642499   
    24652500  //--CFG_KDY
    2466   m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
    2467   m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
    2468   m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
    2469   m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
     2501  if(isField)
     2502  {
     2503    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2504    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2505    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2506    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2507  }
     2508   else
     2509  {
     2510    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
     2511    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
     2512    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
     2513    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
     2514  }
    24702515 
    24712516  //-- all
     
    24902535  m_gcAnalyzeB.printSummary('B');
    24912536#endif
     2537
     2538  if(isField)
     2539  {
     2540    //-- interlaced summary
     2541    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate());
     2542    printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
     2543    m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll.getBits());
     2544   
     2545#if _SUMMARY_OUT_
     2546    m_gcAnalyzeAll_in.printSummaryOutInterlaced();
     2547#endif
     2548  }
    24922549
    24932550  printf("\nRVM: %.3lf\n" , xCalculateRVM());
     
    25312588// ====================================================================================================================
    25322589
     2590
     2591Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField )
     2592{
     2593  assert( iNumPicRcvd > 0 );
     2594  //  Exception for the first frames
     2595  if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField  && (iPOCLast == 0))  )
     2596  {
     2597    m_iGopSize    = 1;
     2598  }
     2599  else
     2600  {
     2601    m_iGopSize    = m_pcCfg->getGOPSize();
     2602  }
     2603  assert (m_iGopSize > 0);
     2604 
     2605  return;
     2606}
     2607
    25332608Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut )
    25342609{
     
    25532628                         TComPic*&                 rpcPic,
    25542629                         TComPicYuv*&              rpcPicYuvRecOut,
    2555                          Int                       pocCurr )
     2630                         Int                       pocCurr,
     2631                         Bool                      isField)
    25562632{
    25572633  Int i;
    25582634  //  Rec. output
    25592635  TComList<TComPicYuv*>::iterator     iterPicYuvRec = rcListPicYuvRecOut.end();
    2560   for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ )
    2561   {
    2562     iterPicYuvRec--;
    2563   }
    2564  
     2636
     2637  if (isField)
     2638  {
     2639    for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ )
     2640    {
     2641      iterPicYuvRec--;
     2642    }
     2643  }
     2644  else
     2645  {
     2646    for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ )
     2647    {
     2648      iterPicYuvRec--;
     2649    }
     2650  }
     2651 
     2652  if (isField)
     2653  {
     2654    if(pocCurr == 1)
     2655    {
     2656      iterPicYuvRec++;
     2657    }
     2658  }
    25652659  rpcPicYuvRecOut = *(iterPicYuvRec);
    25662660 
     
    26472741  switch (type)
    26482742  {
    2649     case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
    2650     case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
    2651     case NAL_UNIT_CODED_SLICE_TSA_R:      return "TSA_R";
    2652     case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
    2653     case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
    2654     case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N";
     2743    case NAL_UNIT_CODED_SLICE_TRAIL_R:    return "TRAIL_R";
     2744    case NAL_UNIT_CODED_SLICE_TRAIL_N:    return "TRAIL_N";
     2745    case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
     2746    case NAL_UNIT_CODED_SLICE_TSA_N:      return "TSA_N";
     2747    case NAL_UNIT_CODED_SLICE_STSA_R:     return "STSA_R";
     2748    case NAL_UNIT_CODED_SLICE_STSA_N:     return "STSA_N";
    26552749    case NAL_UNIT_CODED_SLICE_BLA_W_LP:   return "BLA_W_LP";
    26562750    case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
    2657     case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP";
     2751    case NAL_UNIT_CODED_SLICE_BLA_N_LP:   return "BLA_N_LP";
    26582752    case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
    2659     case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP";
    2660     case NAL_UNIT_CODED_SLICE_CRA: return "CRA";
     2753    case NAL_UNIT_CODED_SLICE_IDR_N_LP:   return "IDR_N_LP";
     2754    case NAL_UNIT_CODED_SLICE_CRA:        return "CRA";
    26612755    case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
    26622756    case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
    2663     case NAL_UNIT_VPS: return "VPS";
    2664     case NAL_UNIT_SPS: return "SPS";
    2665     case NAL_UNIT_PPS: return "PPS";
    2666     case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD";
    2667     case NAL_UNIT_EOS: return "EOS";
    2668     case NAL_UNIT_EOB: return "EOB";
    2669     case NAL_UNIT_FILLER_DATA: return "FILLER";
     2757    case NAL_UNIT_VPS:                    return "VPS";
     2758    case NAL_UNIT_SPS:                    return "SPS";
     2759    case NAL_UNIT_PPS:                    return "PPS";
     2760    case NAL_UNIT_ACCESS_UNIT_DELIMITER:  return "AUD";
     2761    case NAL_UNIT_EOS:                    return "EOS";
     2762    case NAL_UNIT_EOB:                    return "EOB";
     2763    case NAL_UNIT_FILLER_DATA:            return "FILLER";
    26702764    case NAL_UNIT_PREFIX_SEI:             return "SEI";
    26712765    case NAL_UNIT_SUFFIX_SEI:             return "SEI";
    2672     default: return "UNK";
     2766    default:                              return "UNK";
    26732767  }
    26742768}
     
    28742968    printf("]");
    28752969  }
     2970}
     2971
     2972
     2973Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, Bool isTff)
     2974{
     2975 
     2976  for (Int y = 0; y < height; y++)
     2977  {
     2978    for (Int x = 0; x < width; x++)
     2979    {
     2980      dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
     2981      dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     2982    }
     2983    top += stride;
     2984    bottom += stride;
     2985    dst += stride*2;
     2986  }
     2987}
     2988
     2989Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime )
     2990{
     2991  Int     x, y;
     2992 
     2993  UInt64 uiSSDY_in  = 0;
     2994  UInt64 uiSSDU_in  = 0;
     2995  UInt64 uiSSDV_in  = 0;
     2996 
     2997  Double  dYPSNR_in  = 0.0;
     2998  Double  dUPSNR_in  = 0.0;
     2999  Double  dVPSNR_in  = 0.0;
     3000 
     3001  /*------ INTERLACED PSNR -----------*/
     3002 
     3003  /* Luma */
     3004 
     3005  Pel*  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr();
     3006  Pel*  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr();
     3007  Pel*  pRecTop = pcPicRecTop->getLumaAddr();
     3008  Pel*  pRecBottom = pcPicRecBottom->getLumaAddr();
     3009 
     3010  Int   iWidth;
     3011  Int   iHeight;
     3012  Int iStride;
     3013 
     3014  iWidth  = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0);
     3015  iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1);
     3016  iStride = pcPicOrgTop->getPicYuvOrg()->getStride();
     3017  Int   iSize   = iWidth*iHeight;
     3018  bool isTff = pcPicOrgTop->isTopField();
     3019 
     3020  TComPicYuv* pcOrgInterlaced = new TComPicYuv;
     3021  pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     3022 
     3023  TComPicYuv* pcRecInterlaced = new TComPicYuv;
     3024  pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     3025 
     3026  Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr();
     3027  Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr();
     3028 
     3029  //=== Interlace fields ====
     3030  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3031  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3032 
     3033  //===== calculate PSNR =====
     3034  for( y = 0; y < iHeight << 1; y++ )
     3035  {
     3036    for( x = 0; x < iWidth; x++ )
     3037    {
     3038      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3039      uiSSDY_in   += iDiff * iDiff;
     3040    }
     3041    pOrgInterlaced += iStride;
     3042    pRecInterlaced += iStride;
     3043  }
     3044 
     3045  /*Chroma*/
     3046 
     3047  iHeight >>= 1;
     3048  iWidth  >>= 1;
     3049  iStride >>= 1;
     3050 
     3051  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr();
     3052  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr();
     3053  pRecTop = pcPicRecTop->getCbAddr();
     3054  pRecBottom = pcPicRecBottom->getCbAddr();
     3055  pOrgInterlaced = pcOrgInterlaced->getCbAddr();
     3056  pRecInterlaced = pcRecInterlaced->getCbAddr();
     3057 
     3058  //=== Interlace fields ====
     3059  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3060  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3061 
     3062  //===== calculate PSNR =====
     3063  for( y = 0; y < iHeight << 1; y++ )
     3064  {
     3065    for( x = 0; x < iWidth; x++ )
     3066    {
     3067      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3068      uiSSDU_in   += iDiff * iDiff;
     3069    }
     3070    pOrgInterlaced += iStride;
     3071    pRecInterlaced += iStride;
     3072  }
     3073 
     3074  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr();
     3075  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr();
     3076  pRecTop = pcPicRecTop->getCrAddr();
     3077  pRecBottom = pcPicRecBottom->getCrAddr();
     3078  pOrgInterlaced = pcOrgInterlaced->getCrAddr();
     3079  pRecInterlaced = pcRecInterlaced->getCrAddr();
     3080 
     3081  //=== Interlace fields ====
     3082  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3083  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3084 
     3085  //===== calculate PSNR =====
     3086  for( y = 0; y < iHeight << 1; y++ )
     3087  {
     3088    for( x = 0; x < iWidth; x++ )
     3089    {
     3090      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3091      uiSSDV_in   += iDiff * iDiff;
     3092    }
     3093    pOrgInterlaced += iStride;
     3094    pRecInterlaced += iStride;
     3095  }
     3096 
     3097  Int maxvalY = 255 << (g_bitDepthY-8);
     3098  Int maxvalC = 255 << (g_bitDepthC-8);
     3099  Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2;
     3100  Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0;
     3101  dYPSNR_in            = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 );
     3102  dUPSNR_in            = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 );
     3103  dVPSNR_in            = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 );
     3104 
     3105  /* calculate the size of the access unit, excluding:
     3106   *  - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
     3107   *  - SEI NAL units
     3108   */
     3109  UInt numRBSPBytes = 0;
     3110  for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
     3111  {
     3112    UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
     3113   
     3114    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
     3115      numRBSPBytes += numRBSPBytes_nal;
     3116  }
     3117 
     3118  UInt uibits = numRBSPBytes * 8 ;
     3119 
     3120  //===== add PSNR =====
     3121  m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits);
     3122 
     3123  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 );
     3124 
     3125  pcOrgInterlaced->destroy();
     3126  delete pcOrgInterlaced;
     3127  pcRecInterlaced->destroy();
     3128  delete pcRecInterlaced;
    28763129}
    28773130
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.h

    r345 r431  
    145145  Void  init        ( TEncTop* pcTEncTop );
    146146#if SVC_EXTENSION
    147   Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
     147  Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
    148148#else
    149   Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
     149  Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
    150150#endif
    151151  Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
     
    156156  TComList<TComPic*>*   getListPic()      { return m_pcListPic; }
    157157 
    158   Void  printOutSummary      ( UInt uiNumAllPicCoded );
     158#if !SVC_EXTENSION
     159  Void  printOutSummary      ( UInt uiNumAllPicCoded, Bool isField);
     160#endif
    159161  Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
    160162 
     
    166168
    167169protected:
     170 
     171  Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField );
    168172  Void  xInitGOP          ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut );
    169   Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr );
     173  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField );
    170174 
    171175  Void  xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime );
     176  Void  xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime );
    172177 
    173178  UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1);
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp

    r401 r431  
    180180#if SVC_EXTENSION
    181181//\param vps          VPS associated with the slice
    182 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps )
    183 #else
    184 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
     182Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps, Bool isField )
     183#else
     184Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, Bool isField )
    185185#endif
    186186{
     
    298298    Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    299299    Int    SHIFT_QP = 12;
    300     Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
     300
     301    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
     302
    301303#if FULL_NBIT
    302304    Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSlice.h

    r313 r431  
    118118#if SVC_EXTENSION
    119119  Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
    120                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps );
     120                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps, Bool isField );
    121121#else
    122122  Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
    123                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
     123                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, Bool isField );
    124124#endif
    125125
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp

    r414 r431  
    308308}
    309309
    310 Void TEncTop::init()
     310Void TEncTop::init(Bool isFieldCoding)
    311311{
    312312  // initialize SPS
     
    319319  m_cPPS.setSPS(&m_cSPS);
    320320  xInitPPS();
    321   xInitRPS();
     321  xInitRPS(isFieldCoding);
    322322
    323323  xInitPPSforTiles();
     
    396396
    397397  // compress GOP
    398   m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
     398  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    399399
    400400#if RATE_CONTROL_LAMBDA_DOMAIN
     
    456456
    457457  // compress GOP
    458   m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
     458
     459  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    459460
    460461#if RATE_CONTROL_LAMBDA_DOMAIN
     
    467468  iNumEncoded         = m_iNumPicRcvd;
    468469  m_iNumPicRcvd       = 0;
     470  m_uiNumAllPicCoded += iNumEncoded;
     471}
     472#endif
     473
     474/**------------------------------------------------
     475 Separate interlaced frame into two fields
     476 -------------------------------------------------**/
     477void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
     478{
     479  if (!isTop)
     480  {
     481    org += stride;
     482  }
     483  for (Int y = 0; y < height>>1; y++)
     484  {
     485    for (Int x = 0; x < width; x++)
     486    {
     487      dstField[x] = org[x];
     488    }
     489   
     490    dstField += stride;
     491    org += stride*2;
     492  }
     493 
     494}
     495
     496#if SVC_EXTENSION
     497Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff )
     498{
     499  if (pcPicYuvOrg)
     500  {
     501    /* -- TOP FIELD -- */
     502    /* -- Top field initialization -- */
     503   
     504    TComPic *pcTopField;
     505    xGetNewPicBuffer( pcTopField );
     506    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     507    pcTopField->setReconMark (false);
     508   
     509    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
     510    pcTopField->getPicYuvRec()->setBorderExtension(false);
     511    pcTopField->setTopField(isTff);
     512   
     513    Int nHeight = pcPicYuvOrg->getHeight();
     514    Int nWidth = pcPicYuvOrg->getWidth();
     515    Int nStride = pcPicYuvOrg->getStride();
     516    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
     517    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
     518   
     519    // Get pointers
     520    Pel * PicBufY = pcPicYuvOrg->getBufY();
     521    Pel * PicBufU = pcPicYuvOrg->getBufU();
     522    Pel * PicBufV = pcPicYuvOrg->getBufV();
     523   
     524    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
     525    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
     526    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
     527   
     528    // compute image characteristics
     529    if ( getUseAdaptiveQP() )
     530    {
     531      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
     532    }
     533   
     534    /* -- Defield -- */
     535   
     536    Bool isTop = isTff;
     537   
     538    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
     539    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     540    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     541
     542    /* -- BOTTOM FIELD -- */
     543    /* -- Bottom field initialization -- */
     544   
     545    TComPic* pcBottomField;
     546    xGetNewPicBuffer( pcBottomField );
     547    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     548    pcBottomField->setReconMark (false);
     549   
     550    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
     551    pcBottomField->getPicYuvRec()->setBorderExtension(false);
     552    pcBottomField->setTopField(!isTff);
     553   
     554    nHeight = pcPicYuvOrg->getHeight();
     555    nWidth = pcPicYuvOrg->getWidth();
     556    nStride = pcPicYuvOrg->getStride();
     557    nPadLuma = pcPicYuvOrg->getLumaMargin();
     558    nPadChroma = pcPicYuvOrg->getChromaMargin();
     559   
     560    // Get pointers
     561    PicBufY = pcPicYuvOrg->getBufY();
     562    PicBufU = pcPicYuvOrg->getBufU();
     563    PicBufV = pcPicYuvOrg->getBufV();
     564   
     565    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
     566    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
     567    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
     568   
     569    // Compute image characteristics
     570    if ( getUseAdaptiveQP() )
     571    {
     572      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
     573    }
     574   
     575    /* -- Defield -- */
     576   
     577    isTop = !isTff;
     578   
     579    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
     580    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     581    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     582   
     583  }
     584}
     585
     586Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff )
     587{
     588  // compress GOP
     589  if (m_iPOCLast == 0) // compress field 0
     590  {
     591    m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     592  }
     593
     594  if (pcPicYuvOrg)
     595  {
     596    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
     597    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
     598    {
     599      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
     600    }
     601    else
     602    {
     603      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     604    }
     605    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
     606  }
     607 
     608  // compress GOP
     609  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     610
     611  m_uiNumAllPicCoded ++;
     612}
     613#else
     614Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
     615{
     616  /* -- TOP FIELD -- */
     617 
     618  if (pcPicYuvOrg)
     619  {
     620   
     621    /* -- Top field initialization -- */
     622   
     623    TComPic *pcTopField;
     624    xGetNewPicBuffer( pcTopField );
     625    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     626    pcTopField->setReconMark (false);
     627   
     628    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
     629    pcTopField->getPicYuvRec()->setBorderExtension(false);
     630    pcTopField->setTopField(isTff);
     631   
     632    Int nHeight = pcPicYuvOrg->getHeight();
     633    Int nWidth = pcPicYuvOrg->getWidth();
     634    Int nStride = pcPicYuvOrg->getStride();
     635    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
     636    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
     637   
     638    // Get pointers
     639    Pel * PicBufY = pcPicYuvOrg->getBufY();
     640    Pel * PicBufU = pcPicYuvOrg->getBufU();
     641    Pel * PicBufV = pcPicYuvOrg->getBufV();
     642   
     643    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
     644    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
     645    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
     646   
     647    // compute image characteristics
     648    if ( getUseAdaptiveQP() )
     649    {
     650      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
     651    }
     652   
     653    /* -- Defield -- */
     654   
     655    Bool isTop = isTff;
     656   
     657    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
     658    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     659    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     660   
     661  }
     662 
     663  if (m_iPOCLast == 0) // compress field 0
     664  {
     665    m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     666  }
     667 
     668  /* -- BOTTOM FIELD -- */
     669 
     670  if (pcPicYuvOrg)
     671  {
     672   
     673    /* -- Bottom field initialization -- */
     674   
     675    TComPic* pcBottomField;
     676    xGetNewPicBuffer( pcBottomField );
     677    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     678    pcBottomField->setReconMark (false);
     679   
     680    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
     681    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
     682    {
     683      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
     684    }
     685    else
     686    {
     687      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     688    }
     689    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
     690   
     691    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
     692    pcBottomField->getPicYuvRec()->setBorderExtension(false);
     693    pcBottomField->setTopField(!isTff);
     694   
     695    int nHeight = pcPicYuvOrg->getHeight();
     696    int nWidth = pcPicYuvOrg->getWidth();
     697    int nStride = pcPicYuvOrg->getStride();
     698    int nPadLuma = pcPicYuvOrg->getLumaMargin();
     699    int nPadChroma = pcPicYuvOrg->getChromaMargin();
     700   
     701    // Get pointers
     702    Pel * PicBufY = pcPicYuvOrg->getBufY();
     703    Pel * PicBufU = pcPicYuvOrg->getBufU();
     704    Pel * PicBufV = pcPicYuvOrg->getBufV();
     705   
     706    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
     707    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
     708    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
     709   
     710    // Compute image characteristics
     711    if ( getUseAdaptiveQP() )
     712    {
     713      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
     714    }
     715   
     716    /* -- Defield -- */
     717   
     718    Bool isTop = !isTff;
     719   
     720    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
     721    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     722    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     723   
     724  }
     725 
     726  if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) )
     727  {
     728    iNumEncoded = 0;
     729    return;
     730  }
     731 
     732  // compress GOP
     733  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     734 
     735  iNumEncoded = m_iNumPicRcvd;
     736  m_iNumPicRcvd = 0;
    469737  m_uiNumAllPicCoded += iNumEncoded;
    470738}
     
    9111179
    9121180//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
    913 Void TEncTop::xInitRPS()
     1181Void TEncTop::xInitRPS(Bool isFieldCoding)
    9141182{
    9151183  TComReferencePictureSet*      rps;
    9161184 
    917   m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
     1185  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1);
    9181186  TComRPSList* rpsList = m_cSPS.getRPSList();
    9191187
     
    10161284        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
    10171285        rps->setNumberOfNegativePictures(numNeg);
    1018         rps->setNumberOfPositivePictures(numNeg+numPos);
     1286        rps->setNumberOfPictures(numNeg+numPos);
    10191287      }
    10201288      if (numPos != rps->getNumberOfPositivePictures())
     
    10221290        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
    10231291        rps->setNumberOfPositivePictures(numPos);
    1024         rps->setNumberOfPositivePictures(numNeg+numPos);
     1292        rps->setNumberOfPictures(numNeg+numPos);
    10251293      }
    10261294      RPSTemp.setNumberOfPictures(numNeg+numPos);
     
    10861354#endif //INTER_RPS_AUTO
    10871355  }
    1088  
     1356  //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file.
     1357  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
     1358  if (isFieldCoding)
     1359  {
     1360    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
     1361    rps->setNumberOfPictures(1);
     1362    rps->setNumberOfNegativePictures(1);
     1363    rps->setNumberOfPositivePictures(0);
     1364    rps->setNumberOfLongtermPictures(0);
     1365    rps->setDeltaPOC(0,-1);
     1366    rps->setPOC(0,0);
     1367    rps->setUsed(0,true);
     1368    rps->setInterRPSPrediction(false);
     1369    rps->setDeltaRIdxMinus1(0);
     1370    rps->setDeltaRPS(0);
     1371    rps->setNumRefIdc(0);
     1372}
    10891373}
    10901374
     
    10951379{
    10961380  slice->setRPSidx(GOPid);
    1097 
    10981381  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
    10991382  {   
     
    11191402  }
    11201403
     1404  if(POCCurr == 1 && slice->getPic()->isField())
     1405  {
     1406    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
     1407  }
     1408
    11211409  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
    11221410  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
    1123 
    11241411}
    11251412
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.h

    r414 r431  
    144144  Window                  m_scaledRefLayerWindow[MAX_LAYERS];
    145145#endif
    146 #endif
    147146#if POC_RESET_FLAG
    148147  Int                     m_pocAdjustmentValue;
     148#endif
    149149#endif
    150150protected:
     
    154154 
    155155  Void  xInitPPSforTiles  ();
    156   Void  xInitRPS          ();                             ///< initialize PPS from encoder options
     156  Void  xInitRPS          (Bool isFieldCoding);           ///< initialize PPS from encoder options
    157157#if SVC_EXTENSION
    158158  Void xInitILRP();
     
    164164  Void      create          ();
    165165  Void      destroy         ();
    166   Void      init            ();
     166  Void      init            (Bool isFieldCoding);
    167167  Void      deletePicBuffer ();
    168168
     
    209209  Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
    210210  Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
    211 #endif
    212211#if SCALED_REF_LAYER_OFFSETS
    213212  Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
    214213  UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
    215214  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
     215#endif
    216216#endif
    217217
     
    236236  fstream*  getBLSyntaxFile() { return m_pBLSyntaxFile; }
    237237#endif
    238   Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP  );
     238  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP );
    239239  Void      encodePrep( TComPicYuv* pcPicYuvOrg );
     240  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff );
     241  Void      encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff );
    240242#if VPS_EXTN_DIRECT_REF_LAYERS
    241243  TEncTop*  getRefLayerEnc(UInt refLayerIdc);
    242244#endif
    243 #else
    244   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
    245               std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); 
    246 #endif
    247 
    248   void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); }
    249245#if POC_RESET_FLAG
    250246  Int  getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
    251247  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
    252248#endif
     249#else //SVC_EXTENSION
     250  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
     251              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );
     252
     253  /// encode several number of pictures until end-of-sequence
     254  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
     255              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff);
     256
     257  Void printSummary(Bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField); }
     258#endif //#if SVC_EXTENSION
    253259};
    254260
Note: See TracChangeset for help on using the changeset viewer.