Changeset 1402 in 3DVCSoftware for branches/HTM-16.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp
- Timestamp:
- 26 May 2016, 15:03:18 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-16.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp
r1401 r1402 108 108 m_associatedIRAPType = NAL_UNIT_CODED_SLICE_IDR_N_LP; 109 109 m_associatedIRAPPOC = 0; 110 #if W0038_DB_OPT 111 m_pcDeblockingTempPicYuv = NULL; 112 #endif 110 113 return; 111 114 } … … 125 128 Void TEncGOP::destroy() 126 129 { 130 #if W0038_DB_OPT 131 if (m_pcDeblockingTempPicYuv) 132 { 133 m_pcDeblockingTempPicYuv->destroy(); 134 delete m_pcDeblockingTempPicYuv; 135 m_pcDeblockingTempPicYuv = NULL; 136 } 137 #endif 127 138 } 128 139 … … 502 513 seiMessages.push_back(seiChromaResamplingFilterHint); 503 514 } 515 #if U0033_ALTERNATIVE_TRANSFER_CHARACTERISTICS_SEI 516 if(m_pcCfg->getSEIAlternativeTransferCharacteristicsSEIEnable()) 517 { 518 SEIAlternativeTransferCharacteristics *seiAlternativeTransferCharacteristics = new SEIAlternativeTransferCharacteristics; 519 m_seiEncoder.initSEIAlternativeTransferCharacteristics(seiAlternativeTransferCharacteristics); 520 seiMessages.push_back(seiAlternativeTransferCharacteristics); 521 } 522 #endif 504 523 } 505 524 … … 1727 1746 estimatedCpbFullness -= m_pcRateCtrl->getBufferingRate(); 1728 1747 // prevent underflow 1748 #if V0078_ADAPTIVE_LOWER_BOUND 1749 if (estimatedCpbFullness - estimatedBits < m_pcRateCtrl->getRCPic()->getLowerBound()) 1750 { 1751 estimatedBits = max(200, estimatedCpbFullness - m_pcRateCtrl->getRCPic()->getLowerBound()); 1752 } 1753 #else 1729 1754 if (estimatedCpbFullness - estimatedBits < (Int)(m_pcRateCtrl->getCpbSize()*0.1f)) 1730 1755 { 1731 1756 estimatedBits = max(200, estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.1f)); 1732 1757 } 1758 #endif 1733 1759 1734 1760 m_pcRateCtrl->getRCPic()->setTargetBits(estimatedBits); … … 1769 1795 estimatedCpbFullness -= m_pcRateCtrl->getBufferingRate(); 1770 1796 // prevent underflow 1797 #if V0078_ADAPTIVE_LOWER_BOUND 1798 if (estimatedCpbFullness - bits < m_pcRateCtrl->getRCPic()->getLowerBound()) 1799 { 1800 bits = estimatedCpbFullness - m_pcRateCtrl->getRCPic()->getLowerBound(); 1801 } 1802 #else 1771 1803 if (estimatedCpbFullness - bits < (Int)(m_pcRateCtrl->getCpbSize()*0.1f)) 1772 1804 { 1773 1805 bits = estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.1f); 1774 1806 } 1807 #endif 1775 1808 } 1776 1809 #endif … … 1902 1935 if ( m_pcCfg->getDeblockingFilterMetric() ) 1903 1936 { 1937 #if W0038_DB_OPT 1938 if ( m_pcCfg->getDeblockingFilterMetric()==2 ) 1939 { 1940 applyDeblockingFilterParameterSelection(pcPic, uiNumSliceSegments, iGOPid); 1941 } 1942 else 1943 { 1944 #endif 1904 1945 applyDeblockingFilterMetric(pcPic, uiNumSliceSegments); 1946 #if W0038_DB_OPT 1947 } 1948 #endif 1905 1949 } 1906 1950 m_pcLoopFilter->loopFilterPic( pcPic ); … … 1954 1998 m_pcEncTop->getRDGoOnSbacCoder()->setBitstream(&tempBitCounter); 1955 1999 m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice); 2000 #if OPTIONAL_RESET_SAO_ENCODING_AFTER_IRAP 2001 m_pcSAO->SAOProcess(pcPic, sliceEnabled, pcPic->getSlice(0)->getLambdas(), 2002 m_pcCfg->getTestSAODisableAtPictureLevel(), 2003 m_pcCfg->getSaoEncodingRate(), 2004 m_pcCfg->getSaoEncodingRateChroma(), 2005 m_pcCfg->getSaoCtuBoundary(), 2006 m_pcCfg->getSaoResetEncoderStateAfterIRAP()); 2007 #else 1956 2008 m_pcSAO->SAOProcess(pcPic, sliceEnabled, pcPic->getSlice(0)->getLambdas(), m_pcCfg->getTestSAODisableAtPictureLevel(), m_pcCfg->getSaoEncodingRate(), m_pcCfg->getSaoEncodingRateChroma(), m_pcCfg->getSaoCtuBoundary()); 2009 #endif 1957 2010 m_pcSAO->PCMLFDisableProcess(pcPic); 1958 2011 m_pcEncTop->getRDGoOnSbacCoder()->setBitstream(NULL); … … 2186 2239 //--CFG_KDY 2187 2240 const Int rateMultiplier=(isField?2:1); 2188 m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier );2189 m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier );2190 m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier );2191 m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier );2241 m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier / (Double)m_pcCfg->getTemporalSubsampleRatio()); 2242 m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier / (Double)m_pcCfg->getTemporalSubsampleRatio()); 2243 m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier / (Double)m_pcCfg->getTemporalSubsampleRatio()); 2244 m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier / (Double)m_pcCfg->getTemporalSubsampleRatio()); 2192 2245 const ChromaFormat chFmt = m_pcCfg->getChromaFormatIdc(); 2193 2246 … … 2224 2277 { 2225 2278 //-- interlaced summary 2279 #if TEMPORAL_SUBSAMPLE 2280 m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate() / (Double)m_pcCfg->getTemporalSubsampleRatio()); 2281 #else 2226 2282 m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate()); 2283 #endif 2227 2284 m_gcAnalyzeAll_in.setBits(m_gcAnalyzeAll.getBits()); 2228 2285 // prior to the above statement, the interlace analyser does not contain the correct total number of bits. … … 2959 3016 assert(noCol > 1); 2960 3017 assert(noRows > 1); 2961 UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64));2962 UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64));3018 std::vector<UInt64> colSAD(noCol, UInt64(0)); 3019 std::vector<UInt64> rowSAD(noRows, UInt64(0)); 2963 3020 UInt colIdx = 0; 2964 3021 UInt rowIdx = 0; … … 2972 3029 const Int thr1 = 2*bitdepthScale; 2973 3030 UInt a = 0; 2974 2975 memset(colSAD, 0, noCol*sizeof(UInt64));2976 memset(rowSAD, 0, noRows*sizeof(UInt64));2977 3031 2978 3032 if (maxTBsize > minBlockArtSize) … … 3064 3118 } 3065 3119 } 3066 3067 free(colSAD); 3068 free(rowSAD); 3069 } 3120 } 3121 3122 #if W0038_DB_OPT 3123 Void TEncGOP::applyDeblockingFilterParameterSelection( TComPic* pcPic, const UInt numSlices, const Int gopID ) 3124 { 3125 enum DBFltParam 3126 { 3127 DBFLT_PARAM_AVAILABLE = 0, 3128 DBFLT_DISABLE_FLAG, 3129 DBFLT_BETA_OFFSETD2, 3130 DBFLT_TC_OFFSETD2, 3131 //NUM_DBFLT_PARAMS 3132 }; 3133 const Int MAX_BETA_OFFSET = 3; 3134 const Int MIN_BETA_OFFSET = -3; 3135 const Int MAX_TC_OFFSET = 3; 3136 const Int MIN_TC_OFFSET = -3; 3137 3138 TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec(); 3139 TComPicYuv* pcPicYuvOrg = pcPic ->getPicYuvOrg(); 3140 3141 const Int currQualityLayer = (pcPic->getSlice(0)->getSliceType() != I_SLICE) ? m_pcCfg->getGOPEntry(gopID).m_temporalId+1 : 0; 3142 assert(currQualityLayer <MAX_ENCODER_DEBLOCKING_QUALITY_LAYERS); 3143 3144 if(!m_pcDeblockingTempPicYuv) 3145 { 3146 m_pcDeblockingTempPicYuv = new TComPicYuv; 3147 m_pcDeblockingTempPicYuv->create( m_pcEncTop->getSourceWidth(), m_pcEncTop->getSourceHeight(), m_pcEncTop->getChromaFormatIdc(), pcPic->getSlice(0)->getSPS()->getMaxCUWidth(), pcPic->getSlice(0)->getSPS()->getMaxCUHeight(), pcPic->getSlice(0)->getSPS()->getMaxTotalCUDepth(),true ); 3148 memset(m_DBParam, 0, sizeof(m_DBParam)); 3149 } 3150 3151 //preserve current reconstruction 3152 pcPicYuvRec->copyToPic(m_pcDeblockingTempPicYuv); 3153 3154 const Bool bNoFiltering = m_DBParam[currQualityLayer][DBFLT_PARAM_AVAILABLE] && m_DBParam[currQualityLayer][DBFLT_DISABLE_FLAG]==false /*&& pcPic->getTLayer()==0*/; 3155 const Int maxBetaOffsetDiv2 = bNoFiltering? Clip3(MIN_BETA_OFFSET, MAX_BETA_OFFSET, m_DBParam[currQualityLayer][DBFLT_BETA_OFFSETD2]+1) : MAX_BETA_OFFSET; 3156 const Int minBetaOffsetDiv2 = bNoFiltering? Clip3(MIN_BETA_OFFSET, MAX_BETA_OFFSET, m_DBParam[currQualityLayer][DBFLT_BETA_OFFSETD2]-1) : MIN_BETA_OFFSET; 3157 const Int maxTcOffsetDiv2 = bNoFiltering? Clip3(MIN_TC_OFFSET, MAX_TC_OFFSET, m_DBParam[currQualityLayer][DBFLT_TC_OFFSETD2]+2) : MAX_TC_OFFSET; 3158 const Int minTcOffsetDiv2 = bNoFiltering? Clip3(MIN_TC_OFFSET, MAX_TC_OFFSET, m_DBParam[currQualityLayer][DBFLT_TC_OFFSETD2]-2) : MIN_TC_OFFSET; 3159 3160 UInt64 distBetaPrevious = std::numeric_limits<UInt64>::max(); 3161 UInt64 distMin = std::numeric_limits<UInt64>::max(); 3162 Bool bDBFilterDisabledBest = true; 3163 Int betaOffsetDiv2Best = 0; 3164 Int tcOffsetDiv2Best = 0; 3165 3166 for(Int betaOffsetDiv2=maxBetaOffsetDiv2; betaOffsetDiv2>=minBetaOffsetDiv2; betaOffsetDiv2--) 3167 { 3168 UInt64 distTcMin = std::numeric_limits<UInt64>::max(); 3169 for(Int tcOffsetDiv2=maxTcOffsetDiv2; tcOffsetDiv2 >= minTcOffsetDiv2; tcOffsetDiv2--) 3170 { 3171 for (Int i=0; i<numSlices; i++) 3172 { 3173 pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true); 3174 pcPic->getSlice(i)->setDeblockingFilterDisable(false); 3175 pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( betaOffsetDiv2 ); 3176 pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( tcOffsetDiv2 ); 3177 } 3178 m_pcDeblockingTempPicYuv->copyToPic(pcPicYuvRec); // restore reconstruction 3179 m_pcLoopFilter->loopFilterPic( pcPic ); 3180 const UInt64 dist = xFindDistortionFrame(pcPicYuvOrg, pcPicYuvRec, pcPic->getPicSym()->getSPS().getBitDepths()); 3181 if(dist < distMin) 3182 { 3183 distMin = dist; 3184 bDBFilterDisabledBest = false; 3185 betaOffsetDiv2Best = betaOffsetDiv2; 3186 tcOffsetDiv2Best = tcOffsetDiv2; 3187 } 3188 if(dist < distTcMin) 3189 { 3190 distTcMin = dist; 3191 } 3192 else if(tcOffsetDiv2 <-2) 3193 { 3194 break; 3195 } 3196 } 3197 if(betaOffsetDiv2<-1 && distTcMin >= distBetaPrevious) 3198 { 3199 break; 3200 } 3201 distBetaPrevious = distTcMin; 3202 } 3203 3204 //update: 3205 m_DBParam[currQualityLayer][DBFLT_PARAM_AVAILABLE] = 1; 3206 m_DBParam[currQualityLayer][DBFLT_DISABLE_FLAG] = bDBFilterDisabledBest; 3207 m_DBParam[currQualityLayer][DBFLT_BETA_OFFSETD2] = betaOffsetDiv2Best; 3208 m_DBParam[currQualityLayer][DBFLT_TC_OFFSETD2] = tcOffsetDiv2Best; 3209 3210 m_pcDeblockingTempPicYuv->copyToPic(pcPicYuvRec); //restore reconstruction 3211 3212 if(bDBFilterDisabledBest) 3213 { 3214 for (Int i=0; i<numSlices; i++) 3215 { 3216 pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true); 3217 pcPic->getSlice(i)->setDeblockingFilterDisable(true); 3218 } 3219 } 3220 else if(betaOffsetDiv2Best ==pcPic->getSlice(0)->getPPS()->getDeblockingFilterBetaOffsetDiv2() && tcOffsetDiv2Best==pcPic->getSlice(0)->getPPS()->getDeblockingFilterTcOffsetDiv2()) 3221 { 3222 for (Int i=0; i<numSlices; i++) 3223 { 3224 pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false); 3225 pcPic->getSlice(i)->setDeblockingFilterDisable( pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() ); 3226 pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); 3227 pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2() ); 3228 } 3229 } 3230 else 3231 { 3232 for (Int i=0; i<numSlices; i++) 3233 { 3234 pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true); 3235 pcPic->getSlice(i)->setDeblockingFilterDisable( false ); 3236 pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2(betaOffsetDiv2Best); 3237 pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2(tcOffsetDiv2Best); 3238 } 3239 } 3240 } 3241 #endif 3070 3242 3071 3243 #if NH_MV
Note: See TracChangeset for help on using the changeset viewer.