Ticket #186: EntropySliceMode2.patch

File EntropySliceMode2.patch, 11.6 KB (added by rickard, 13 years ago)

Patch for #186

  • source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp

     
    142142  m_uiBitsToFollow  = 0;
    143143  m_uiByte          = 0;
    144144  m_uiBitsLeft      = 9;
     145#if FINE_GRANULARITY_SLICES
     146  if (m_bBinCountingEnabled)
     147  {
     148    m_uiBinsCoded=0;
     149  }
     150#endif
    145151}
    146152
    147153UInt
  • source/Lib/TLibEncoder/TEncCu.cpp

     
    746746#if FINE_GRANULARITY_SLICES
    747747        if(m_pcEncCfg->getUseSBACRD())
    748748        {
    749           rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     749          rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    750750        }
    751751#endif
    752752      }
     
    790790#if FINE_GRANULARITY_SLICES
    791791          if(m_pcEncCfg->getUseSBACRD())
    792792          {
    793             rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     793            rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    794794          }
    795795#endif
    796796          rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    836836      Bool bEntropyLimit=false;
    837837      Bool bSliceLimit=false;
    838838      bSliceLimit=rpcBestCU->getSlice()->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
    839       if(rpcBestCU->getSlice()->getSliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&m_pcEncCfg->getUseSBACRD())
     839      if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&m_pcEncCfg->getUseSBACRD())
    840840      {
    841841        if(rpcBestCU->getTotalBins()>rpcBestCU->getSlice()->getEntropySliceArgument())
    842842        {
    843843          bEntropyLimit=true;
    844844        }
    845845      }
    846       else if(rpcBestCU->getSlice()->getSliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE)
     846      else if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE)
    847847      {
    848848        if(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getEntropySliceArgument())
    849849        {
     
    940940  UInt uiGranularityWidth = g_uiMaxCUWidth>>(pcSlice->getPPS()->getSliceGranularity());
    941941  uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
    942942  uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    943   if(((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
    944     &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)))
     943  Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth))
     944    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight));
     945  if(granularityBoundary)
    945946  {
    946947    m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 );
    947948  }
     
    971972    if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+uiBinsCoded>pcSlice->getEntropySliceArgument())
    972973    {
    973974      pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd);
     975      return;
    974976    }
    975977  }
    976978  else
     
    978980    if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+m_pcBitCounter->getNumberOfWrittenBits()>pcSlice->getEntropySliceArgument())
    979981    {
    980982      pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd);
     983      return;
    981984    }
    982985  }
     986  if(granularityBoundary)
     987  {
     988    pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + m_pcBitCounter->getNumberOfWrittenBits()) );
     989    if(m_pcEncCfg->getUseSBACRD())
     990    {
     991      TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf();
     992      pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+pppcRDSbacCoder->getBinsCoded());
     993      pppcRDSbacCoder->setBinsCoded( 0 );
     994    }
     995    else
     996    {
     997      pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+m_pcBitCounter->getNumberOfWrittenBits());
     998    }
     999    m_pcBitCounter->resetBits();
     1000  }
    9831001}
    9841002#endif
    9851003/** encode a CU block recursively
     
    11941212#if FINE_GRANULARITY_SLICES
    11951213      if(m_pcEncCfg->getUseSBACRD())
    11961214      {
    1197         rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1215        rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    11981216      }
    11991217#endif
    12001218      rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    13151333#if FINE_GRANULARITY_SLICES
    13161334          if(m_pcEncCfg->getUseSBACRD())
    13171335          {
    1318             rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1336            rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    13191337          }
    13201338#endif
    13211339          rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    13801398#if FINE_GRANULARITY_SLICES
    13811399      if(m_pcEncCfg->getUseSBACRD())
    13821400      {
    1383         rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1401        rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    13841402      }
    13851403#endif
    13861404    }
     
    14391457#if FINE_GRANULARITY_SLICES
    14401458  if(m_pcEncCfg->getUseSBACRD())
    14411459  {
    1442     rpcBestCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1460    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    14431461  }
    14441462#endif
    14451463  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    14551473#if FINE_GRANULARITY_SLICES
    14561474      if(m_pcEncCfg->getUseSBACRD())
    14571475      {
    1458         rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1476        rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    14591477      }
    14601478#endif
    14611479      rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    15061524#if FINE_GRANULARITY_SLICES
    15071525  if(m_pcEncCfg->getUseSBACRD())
    15081526  {
    1509     rpcBestCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
     1527    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    15101528  }
    15111529#endif
    15121530  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
  • source/Lib/TLibEncoder/TEncSlice.cpp

     
    560560      // set go-on entropy coder
    561561      m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice );
    562562      m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
    563      
     563#if FINE_GRANULARITY_SLICES
     564      ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
     565#endif
    564566      // run CU encoder
    565567      m_pcCuEncoder->compressCU( pcCU );
    566568     
     
    570572      pppcRDSbacCoder->setBinCountingEnableFlag( true );
    571573#if FINE_GRANULARITY_SLICES
    572574      m_pcBitCounter->resetBits();
     575      pppcRDSbacCoder->setBinsCoded( 0 );
    573576#endif
    574577#if SUB_LCU_DQP
    575578      // restore last QP
     
    579582
    580583      pppcRDSbacCoder->setBinCountingEnableFlag( false );
    581584#if FINE_GRANULARITY_SLICES
    582       pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + m_pcBitCounter->getNumberOfWrittenBits()) );
    583       if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits() ) ) > m_pcCfg->getSliceArgument()<<3)
     585      if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits() + m_pcBitCounter->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
    584586      {
    585587#else
    586588      uiBitsCoded += m_pcBitCounter->getNumberOfWrittenBits();
     
    597599        break;
    598600      }
    599601#if FINE_GRANULARITY_SLICES
    600       pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+pppcRDSbacCoder->getBinsCoded());
    601       if (m_pcCfg->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE && pcSlice->getEntropySliceCounter() > m_pcCfg->getEntropySliceArgument()&&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getEntropySliceCurEndCUAddr())
     602      if (m_pcCfg->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE && pcSlice->getEntropySliceCounter()+pppcRDSbacCoder->getBinsCoded() > m_pcCfg->getEntropySliceArgument()&&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getEntropySliceCurEndCUAddr())
    602603      {
    603604#else
    604605     
     
    612613          uiCUAddr = uiCUAddr + 1;
    613614        }
    614615#endif
     616#if !FINE_GRANULARITY_SLICES
     617        uiBitsCoded -= m_pcBitCounter->getNumberOfWrittenBits();
     618#endif
    615619        pcSlice->setNextEntropySlice( true );
    616620        break;
    617621      }
     
    628632      m_pcCuEncoder->encodeCU( pcCU );
    629633     
    630634#if FINE_GRANULARITY_SLICES
    631       pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + m_pcBitCounter->getNumberOfWrittenBits()) );
    632       if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits() ) ) > m_pcCfg->getSliceArgument()<<3)
     635      if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits()+ m_pcBitCounter->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
    633636      {
    634637#else
    635638      uiBitsCoded += m_pcBitCounter->getNumberOfWrittenBits();
     
    646649        break;
    647650      }
    648651#if FINE_GRANULARITY_SLICES
    649       pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+m_pcBitCounter->getNumberOfWrittenBits());
    650       if (m_pcCfg->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE && pcSlice->getEntropySliceCounter() > m_pcCfg->getEntropySliceArgument()&&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getEntropySliceCurEndCUAddr())
     652      if (m_pcCfg->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE && pcSlice->getEntropySliceCounter()+ m_pcBitCounter->getNumberOfWrittenBits()> m_pcCfg->getEntropySliceArgument()&&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getEntropySliceCurEndCUAddr())
    651653      {
    652654
    653655#else
     
    660662          uiCUAddr = uiCUAddr + 1;
    661663        }
    662664#endif
     665
     666#if !FINE_GRANULARITY_SLICES
     667        uiBitsCoded -= m_pcBitCounter->getNumberOfWrittenBits();
     668#endif
    663669        pcSlice->setNextEntropySlice( true );
    664670        break;
    665671      }