Changeset 1318 in SHVCSoftware


Ignore:
Timestamp:
21 Jul 2015, 20:19:19 (9 years ago)
Author:
seregin
Message:

port rev 4393

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

Legend:

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

    r1310 r1318  
    24062406    pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag());
    24072407
     2408
    24082409    Double lambda            = 0.0;
    24092410    Int actualHeadBits       = 0;
     
    24112412    Int estimatedBits        = 0;
    24122413    Int tmpBitsBeforeWriting = 0;
    2413     if ( m_pcCfg->getUseRateCtrl() )
     2414    if ( m_pcCfg->getUseRateCtrl() ) // TODO: does this work with multiple slices and slice-segments?
    24142415    {
    24152416      Int frameLevel = m_pcRateCtrl->getRCSeq()->getGOPID2Level( iGOPid );
     
    24382439      else if ( frameLevel == 0 )   // intra case, but use the model
    24392440      {
    2440         m_pcSliceEncoder->calCostSliceI(pcPic);
     2441        m_pcSliceEncoder->calCostSliceI(pcPic); // TODO: This only analyses the first slice segment - what about the others?
    24412442
    24422443        if ( m_pcCfg->getIntraPeriod() != 1 )   // do not refine allocated bits for all intra case
     
    25052506      {
    25062507        m_pcSliceEncoder->precompressSlice( pcPic );
    2507         m_pcSliceEncoder->compressSlice   ( pcPic );
     2508        m_pcSliceEncoder->compressSlice   ( pcPic, false );
    25082509
    25092510        const UInt curSliceSegmentEnd = pcSlice->getSliceSegmentCurEndCtuTsAddr();
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp

    r1316 r1318  
    639639    printf( "\nMultiple QP optimization is not allowed when rate control is enabled." );
    640640    assert(0);
     641    return;
    641642  }
    642643
    643644  TComSlice* pcSlice        = pcPic->getSlice(getSliceIdx());
     645
     646  if (pcSlice->getDependentSliceSegmentFlag())
     647  {
     648    // if this is a dependent slice segment, then it was optimised
     649    // when analysing the entire slice.
     650    return;
     651  }
     652
     653  if (pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES)
     654  {
     655    // TODO: investigate use of average cost per CTU so that this Slice Mode can be used.
     656    printf( "\nUnable to optimise Slice-level QP if Slice Mode is set to FIXED_NUMBER_OF_BYTES\n" );
     657    assert(0);
     658    return;
     659  }
     660
    644661  Double     dPicRdCostBest = MAX_DOUBLE;
    645662  UInt       uiQpIdxBest = 0;
     
    667684  m_pcRdCost      ->setFrameLambda(dFrameLambda);
    668685
    669   const UInt initialSliceQp=pcSlice->getSliceQp();
    670686  // for each QP candidate
    671687  for ( UInt uiQpIdx = 0; uiQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; uiQpIdx++ )
     
    678694
    679695    // try compress
    680     compressSlice   ( pcPic );
    681 
    682     Double dPicRdCost;
    683     UInt64 uiPicDist        = m_uiPicDist;
    684     // TODO: will this work if multiple slices are being used? There may not be any reconstruction data yet.
    685     //       Will this also be ideal if a byte-restriction is placed on the slice?
    686     //         - what if the last CTU was sometimes included, sometimes not, and that had all the distortion?
    687     m_pcGOPEncoder->preLoopFilterPicAll( pcPic, uiPicDist );
     696    compressSlice   ( pcPic, true );
     697
     698    UInt64 uiPicDist        = m_uiPicDist; // Distortion, as calculated by compressSlice.
     699    // NOTE: This distortion is the chroma-weighted SSE distortion for the slice.
     700    //       Previously a standard SSE distortion was calculated (for the entire frame).
     701    //       Which is correct?
     702
     703    // TODO: Update loop filter, SAO and distortion calculation to work on one slice only.
     704    // m_pcGOPEncoder->preLoopFilterPicAll( pcPic, uiPicDist );
    688705
    689706    // compute RD cost and choose the best
    690     dPicRdCost = m_pcRdCost->calcRdCost64( m_uiPicTotalBits, uiPicDist, true, DF_SSE_FRAME);
     707    Double dPicRdCost = m_pcRdCost->calcRdCost64( m_uiPicTotalBits, uiPicDist, true, DF_SSE_FRAME); // NOTE: Is the 'true' parameter really necessary?
    691708
    692709    if ( dPicRdCost < dPicRdCostBest )
     
    697714  }
    698715
    699   if (pcSlice->getDependentSliceSegmentFlag() && initialSliceQp!=m_piRdPicQp[uiQpIdxBest] )
    700   {
    701     // TODO: this won't work with dependent slices: they do not have their own QP.
    702     fprintf(stderr,"ERROR - attempt to change QP for a dependent slice-segment, having already coded the slice\n");
    703     assert(pcSlice->getDependentSliceSegmentFlag()==false || initialSliceQp==m_piRdPicQp[uiQpIdxBest]);
    704   }
    705716  // set best values
    706717  pcSlice       ->setSliceQp             ( m_piRdPicQp    [uiQpIdxBest] );
     
    711722}
    712723
    713 Void TEncSlice::calCostSliceI(TComPic* pcPic)
     724Void TEncSlice::calCostSliceI(TComPic* pcPic) // TODO: this only analyses the first slice segment. What about the others?
    714725{
    715726  Double            iSumHadSlice      = 0;
     
    755766/** \param pcPic   picture class
    756767 */
    757 Void TEncSlice::compressSlice( TComPic* pcPic )
    758 {
     768Void TEncSlice::compressSlice( TComPic* pcPic, const Bool bCompressEntireSlice )
     769{
     770  // if bCompressEntireSlice is true, then the entire slice (not slice segment) is compressed,
     771  //   effectively disabling the slice-segment-mode.
     772
    759773  UInt   startCtuTsAddr;
    760774  UInt   boundingCtuTsAddr;
     
    762776  pcSlice->setSliceSegmentBits(0);
    763777  xDetermineStartAndBoundingCtuTsAddr ( startCtuTsAddr, boundingCtuTsAddr, pcPic );
     778  if (bCompressEntireSlice)
     779  {
     780    boundingCtuTsAddr = pcSlice->getSliceCurEndCtuTsAddr();
     781    pcSlice->setSliceSegmentCurEndCtuTsAddr(boundingCtuTsAddr);
     782  }
    764783
    765784  // initialize cost values - these are used by precompressSlice (they should be parameters).
     
    817836  {
    818837    // TODO: this won't work with dependent slices: they do not have their own QP. Check fix to mask clause execution with && !(pcSlice->getDependentSliceSegmentFlag())
    819     m_pcTrQuant->clearSliceARLCnt();
     838    m_pcTrQuant->clearSliceARLCnt(); // TODO: this looks wrong for multiple slices - the results of all but the last slice will be cleared before they are used (all slices compressed, and then all slices encoded)
    820839    if(pcSlice->getSliceType()!=I_SLICE)
    821840    {
     
    970989      boundingCtuTsAddr=validEndOfSliceCtuTsAddr;
    971990    }
    972     else if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+numberOfWrittenBits > (pcSlice->getSliceSegmentArgument()<<3))
     991    else if((!bCompressEntireSlice) && pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+numberOfWrittenBits > (pcSlice->getSliceSegmentArgument()<<3))
    973992    {
    974993      pcSlice->setSliceSegmentCurEndCtuTsAddr(validEndOfSliceCtuTsAddr);
     
    12251244  if( m_pcCfg->getUseAdaptQpSelect() )
    12261245  {
    1227     m_pcTrQuant->storeSliceQpNext(pcSlice);
     1246    m_pcTrQuant->storeSliceQpNext(pcSlice); // TODO: this will only be storing the adaptive QP state of the very last slice-segment that is not dependent in the frame... Perhaps this should be moved to the compress slice loop.
    12281247  }
    12291248#endif
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.h

    r1307 r1318  
    124124  Void    resetQP             ( TComPic* pic, Int sliceQP, Double lambda );
    125125  // compress and encode slice
    126   Void    precompressSlice    ( TComPic* pcPic                                     );      ///< precompress slice for multi-loop opt.
    127   Void    compressSlice       ( TComPic* pcPic                                     );      ///< analysis stage of slice
     126  Void    precompressSlice    ( TComPic* pcPic                                     );      ///< precompress slice for multi-loop slice-level QP opt.
     127  Void    compressSlice       ( TComPic* pcPic, const Bool bCompressEntireSlice    );      ///< analysis stage of slice
    128128  Void    calCostSliceI       ( TComPic* pcPic );
    129129  Void    encodeSlice         ( TComPic* pcPic, TComOutputBitstream* pcSubstreams, UInt &numBinsCoded );
Note: See TracChangeset for help on using the changeset viewer.