Ignore:
Timestamp:
3 Feb 2014, 11:35:43 (10 years ago)
Author:
rwth
Message:
  • first version of DBBP (requires some cleanup)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-9.3-dev1-RWTH/source/Lib/TLibEncoder/TEncCu.cpp

    r809 r816  
    7676  m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1];
    7777  m_ppcOrigYuv     = new TComYuv*[m_uhTotalDepth-1];
     78#if H_3D_DBBP
     79  m_ppcOrigYuvDBBP = new TComYuv*[m_uhTotalDepth-1];
     80#endif
    7881 
    7982  UInt uiNumPartitions;
     
    100103   
    101104    m_ppcOrigYuv    [i] = new TComYuv; m_ppcOrigYuv    [i]->create(uiWidth, uiHeight);
     105#if H_3D_DBBP
     106    m_ppcOrigYuvDBBP[i] = new TComYuv; m_ppcOrigYuvDBBP[i]->create(uiWidth, uiHeight);
     107#endif
    102108  }
    103109 
     
    180186      m_ppcOrigYuv[i]->destroy();     delete m_ppcOrigYuv[i];     m_ppcOrigYuv[i] = NULL;
    181187    }
     188#if H_3D_DBBP
     189    if(m_ppcOrigYuvDBBP[i])
     190    {
     191      m_ppcOrigYuvDBBP[i]->destroy(); delete m_ppcOrigYuvDBBP[i]; m_ppcOrigYuvDBBP[i] = NULL;
     192    }
     193#endif
    182194  }
    183195  if(m_ppcBestCU)
     
    234246    m_ppcOrigYuv = NULL;
    235247  }
     248#if H_3D_DBBP
     249  if(m_ppcOrigYuvDBBP)
     250  {
     251    delete [] m_ppcOrigYuvDBBP;
     252    m_ppcOrigYuvDBBP = NULL;
     253  }
     254#endif
    236255}
    237256
     
    654673            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    655674#endif
     675         
     676#if H_3D_DBBP
     677          if( m_pcEncCfg->getUseDBBP() )
     678          {
     679            xCheckRDCostInterDBBP( rpcBestCU, rpcTempCU, false );
     680            rpcTempCU->initEstData( uiDepth, iQP );
     681#if H_3D_VSP
     682            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     683#endif
     684          }
     685#endif
     686         
    656687            if(m_pcEncCfg->getUseCbfFastMode())
    657688            {
     
    23102341}
    23112342
     2343#if H_3D_DBBP
     2344Void TEncCu::xInvalidateOriginalSegments( TComYuv* pOrigYuv, TComYuv* pOrigYuvTemp, Bool* pMask, UInt uiValidSegment )
     2345{
     2346  UInt  uiWidth     = pOrigYuv->getWidth ( );
     2347  UInt  uiHeight    = pOrigYuv->getHeight( );
     2348  Pel*  piSrc       = pOrigYuv->getLumaAddr( );
     2349  UInt  uiSrcStride = pOrigYuv->getStride();
     2350  Pel*  piDst       = pOrigYuvTemp->getLumaAddr( );
     2351  UInt  uiDstStride = pOrigYuvTemp->getStride();
     2352 
     2353  UInt  uiMaskStride= MAX_CU_SIZE;
     2354 
     2355  AOF( uiWidth == uiHeight );
     2356 
     2357  // backup pointer
     2358  Bool* pMaskStart = pMask;
     2359 
     2360  for (Int y=0; y<uiHeight; y++)
     2361  {
     2362    for (Int x=0; x<uiWidth; x++)
     2363    {
     2364      UChar ucSegment = (UChar)pMask[x];
     2365      assert( ucSegment < 2 );
     2366     
     2367      piDst[x] = (ucSegment==uiValidSegment)?piSrc[x]:DBBP_INVALID_SHORT;
     2368    }
     2369   
     2370    piSrc  += uiSrcStride;
     2371    piDst  += uiDstStride;
     2372    pMask  += uiMaskStride;
     2373  }
     2374 
     2375  // now invalidate chroma
     2376  Pel*  piSrcU       = pOrigYuv->getCbAddr();
     2377  Pel*  piSrcV       = pOrigYuv->getCrAddr();
     2378  UInt  uiSrcStrideC = pOrigYuv->getCStride();
     2379  Pel*  piDstU       = pOrigYuvTemp->getCbAddr( );
     2380  Pel*  piDstV       = pOrigYuvTemp->getCrAddr( );
     2381  UInt  uiDstStrideC = pOrigYuvTemp->getCStride();
     2382  pMask = pMaskStart;
     2383 
     2384  for (Int y=0; y<uiHeight/2; y++)
     2385  {
     2386    for (Int x=0; x<uiWidth/2; x++)
     2387    {
     2388      UChar ucSegment = (UChar)pMask[x*2];
     2389      assert( ucSegment < 2 );
     2390     
     2391      piDstU[x] = (ucSegment==uiValidSegment)?piSrcU[x]:DBBP_INVALID_SHORT;
     2392      piDstV[x] = (ucSegment==uiValidSegment)?piSrcV[x]:DBBP_INVALID_SHORT;
     2393    }
     2394   
     2395    piSrcU  += uiSrcStrideC;
     2396    piSrcV  += uiSrcStrideC;
     2397    piDstU  += uiDstStrideC;
     2398    piDstV  += uiDstStrideC;
     2399    pMask   += 2*uiMaskStride;
     2400  }
     2401}
     2402
     2403Void TEncCu::xCheckRDCostInterDBBP( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bUseMRG )
     2404{
     2405  AOF( !rpcTempCU->getSlice()->getIsDepth() );
     2406 
     2407 
     2408  UChar uhDepth = rpcTempCU->getDepth( 0 );
     2409 
     2410#if H_3D_VSO
     2411  if( m_pcRdCost->getUseRenModel() )
     2412  {
     2413    UInt  uiWidth     = m_ppcOrigYuv[uhDepth]->getWidth ( );
     2414    UInt  uiHeight    = m_ppcOrigYuv[uhDepth]->getHeight( );
     2415    Pel*  piSrc       = m_ppcOrigYuv[uhDepth]->getLumaAddr( );
     2416    UInt  uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride();
     2417    m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight );
     2418  }
     2419#endif
     2420 
     2421  UInt uiWidth  = rpcTempCU->getWidth(0);
     2422  UInt uiHeight = rpcTempCU->getHeight(0);
     2423  AOF( uiWidth == uiHeight );
     2424 
     2425  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N,  0, uhDepth );
     2426 
     2427  // get coded and reconstructed depth view
     2428  UInt uiDepthStride = 0;
     2429  Pel* pDepthPels = rpcTempCU->getVirtualDepthBlock(0, uiWidth, uiHeight, uiDepthStride);
     2430  AOF( pDepthPels != NULL );
     2431  AOF( uiDepthStride != 0 );
     2432 
     2433  // derive partitioning from depth
     2434  PartSize eVirtualPartSize = m_pcPredSearch->getPartitionSizeFromDepth(pDepthPels, uiDepthStride, uiWidth);
     2435 
     2436  // derive segmentation mask from depth
     2437  Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
     2438  Bool bValidMask = m_pcPredSearch->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, uiWidth, uiHeight, pMask);
     2439 
     2440  if( !bValidMask )
     2441    return;
     2442 
     2443  // find optimal motion/disparity vector for each segment
     2444  DisInfo originalDvInfo = rpcTempCU->getDvInfo(0);
     2445  DBBPTmpData* pDBBPTmpData = rpcTempCU->getDBBPTmpData();
     2446  TComYuv* apPredYuv[2] = { m_ppcRecoYuvTemp[uhDepth], m_ppcPredYuvTemp[uhDepth] };
     2447 
     2448  // find optimal motion vector fields for both segments (as 2Nx2N)
     2449  rpcTempCU->setDepthSubParts( uhDepth, 0 );
     2450  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N,  0, uhDepth );
     2451  rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth );
     2452  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
     2453  {
     2454    rpcTempCU->setDBBPFlagSubParts(true, 0, 0, uhDepth);
     2455    rpcTempCU->setDvInfoSubParts(originalDvInfo, 0, uhDepth);
     2456   
     2457    // invalidate all other segments in original YUV
     2458    xInvalidateOriginalSegments(m_ppcOrigYuv[uhDepth], m_ppcOrigYuvDBBP[uhDepth], pMask, uiSegment);
     2459   
     2460    // do motion estimation for this segment
     2461    g_bTestVirtualParts = true;
     2462    rpcTempCU->getDBBPTmpData()->eVirtualPartSize = eVirtualPartSize;
     2463    rpcTempCU->getDBBPTmpData()->uiVirtualPartIndex = uiSegment;
     2464    m_pcPredSearch->predInterSearch( rpcTempCU, m_ppcOrigYuvDBBP[uhDepth], apPredYuv[uiSegment], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], false, false, bUseMRG );
     2465    g_bTestVirtualParts = false;
     2466   
     2467    // extract motion parameters of full block for this segment
     2468    pDBBPTmpData->auhInterDir[uiSegment] = rpcTempCU->getInterDir(0);
     2469   
     2470    pDBBPTmpData->abMergeFlag[uiSegment] = rpcTempCU->getMergeFlag(0);
     2471    pDBBPTmpData->auhMergeIndex[uiSegment] = rpcTempCU->getMergeIndex(0);
     2472   
     2473    pDBBPTmpData->ahVSPFlag[uiSegment] = rpcTempCU->getVSPFlag(0);
     2474    pDBBPTmpData->acDvInfo[uiSegment] = rpcTempCU->getDvInfo(0);
     2475   
     2476    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
     2477    {
     2478      RefPicList eRefList = (RefPicList)uiRefListIdx;
     2479     
     2480      pDBBPTmpData->acMvd[uiSegment][eRefList] = rpcTempCU->getCUMvField(eRefList)->getMvd(0);
     2481      pDBBPTmpData->aiMvpNum[uiSegment][eRefList] = rpcTempCU->getMVPNum(eRefList, 0);
     2482      pDBBPTmpData->aiMvpIdx[uiSegment][eRefList] = rpcTempCU->getMVPIdx(eRefList, 0);
     2483     
     2484      rpcTempCU->getMvField(rpcTempCU, 0, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList]);
     2485    }
     2486  }
     2487 
     2488  rpcTempCU->setDepthSubParts( uhDepth, 0 );
     2489  rpcTempCU->setPartSizeSubParts  ( eVirtualPartSize,  0, uhDepth );
     2490  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
     2491 
     2492  UInt uiPUOffset = ( g_auiPUOffset[UInt( eVirtualPartSize )] << ( ( rpcTempCU->getSlice()->getSPS()->getMaxCUDepth() - uhDepth ) << 1 ) ) >> 4;
     2493  for( UInt uiSegment = 0; uiSegment < 2; uiSegment++ )
     2494  {
     2495    UInt uiPartAddr = uiSegment*uiPUOffset;
     2496   
     2497    rpcTempCU->setDBBPFlagSubParts(true, uiPartAddr, uiSegment, uhDepth);
     2498   
     2499    // now set stored information from 2Nx2N motion search to each partition
     2500    rpcTempCU->setInterDirSubParts(pDBBPTmpData->auhInterDir[uiSegment], uiPartAddr, uiSegment, uhDepth); // interprets depth relative to LCU level
     2501   
     2502    rpcTempCU->setMergeFlagSubParts(pDBBPTmpData->abMergeFlag[uiSegment], uiPartAddr, uiSegment, uhDepth);
     2503    rpcTempCU->setMergeIndexSubParts(pDBBPTmpData->auhMergeIndex[uiSegment], uiPartAddr, uiSegment, uhDepth);
     2504   
     2505    rpcTempCU->setVSPFlagSubParts(pDBBPTmpData->ahVSPFlag[uiSegment], uiPartAddr, uiSegment, uhDepth);
     2506    rpcTempCU->setDvInfoSubParts(pDBBPTmpData->acDvInfo[uiSegment], uiPartAddr, uiSegment, uhDepth);
     2507   
     2508    for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
     2509    {
     2510      RefPicList eRefList = (RefPicList)uiRefListIdx;
     2511     
     2512      rpcTempCU->getCUMvField( eRefList )->setAllMvd(pDBBPTmpData->acMvd[uiSegment][eRefList], eVirtualPartSize, uiPartAddr, 0, uiSegment);
     2513      rpcTempCU->setMVPNum(eRefList, uiPartAddr, pDBBPTmpData->aiMvpNum[uiSegment][eRefList]);
     2514      rpcTempCU->setMVPIdx(eRefList, uiPartAddr, pDBBPTmpData->aiMvpIdx[uiSegment][eRefList]);
     2515     
     2516#if NTT_STORE_SPDV_VSP_G0148
     2517      if( rpcTempCU->getVSPFlag( uiPartAddr ) != 0 )
     2518      {
     2519        if ( rpcTempCU->getInterDir(uiPartAddr) & (1<<uiRefListIdx) )
     2520        {
     2521          UInt dummy;
     2522          Int vspSize;
     2523          Int width, height;
     2524          rpcTempCU->getPartIndexAndSize( uiSegment, dummy, width, height, uiPartAddr, rpcTempCU->getTotalNumPart()==256 );
     2525          AOF( dummy == uiPartAddr );
     2526          rpcTempCU->setMvFieldPUForVSP( rpcTempCU, uiPartAddr, width, height, eRefList, pDBBPTmpData->acMvField[uiSegment][eRefList].getRefIdx(), vspSize );
     2527          rpcTempCU->setVSPFlag( uiPartAddr, vspSize );
     2528        }
     2529      }
     2530      else
     2531#endif
     2532      rpcTempCU->getCUMvField( eRefList )->setAllMvField( pDBBPTmpData->acMvField[uiSegment][eRefList], eVirtualPartSize, uiPartAddr, 0, uiSegment ); // interprets depth relative to rpcTempCU level
     2533    }
     2534  }
     2535 
     2536  // reconstruct final prediction signal by combining both segments
     2537  m_pcPredSearch->combineSegmentsWithMask(apPredYuv, m_ppcPredYuvTemp[uhDepth], pMask, uiWidth, uiHeight);
     2538 
     2539  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
     2540 
     2541  xCheckDQP( rpcTempCU );
     2542  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
     2543}
     2544#endif
     2545
    23122546Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize )
    23132547{
Note: See TracChangeset for help on using the changeset viewer.