[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[56] | 6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
[5] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
[56] | 34 | /** \file TEncGOP.cpp |
---|
[2] | 35 | \brief GOP encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
[56] | 38 | #include <list> |
---|
| 39 | #include <algorithm> |
---|
| 40 | |
---|
[2] | 41 | #include "TEncTop.h" |
---|
| 42 | #include "TEncGOP.h" |
---|
| 43 | #include "TEncAnalyze.h" |
---|
[56] | 44 | #include "libmd5/MD5.h" |
---|
| 45 | #include "TLibCommon/SEI.h" |
---|
| 46 | #include "TLibCommon/NAL.h" |
---|
| 47 | #include "NALwrite.h" |
---|
| 48 | #include "../../App/TAppEncoder/TAppEncTop.h" |
---|
[2] | 49 | |
---|
| 50 | #include <time.h> |
---|
[56] | 51 | #include <math.h> |
---|
[2] | 52 | |
---|
[56] | 53 | using namespace std; |
---|
[2] | 54 | |
---|
[56] | 55 | //! \ingroup TLibEncoder |
---|
| 56 | //! \{ |
---|
| 57 | |
---|
[2] | 58 | // ==================================================================================================================== |
---|
| 59 | // Constructor / destructor / initialization / destroy |
---|
| 60 | // ==================================================================================================================== |
---|
| 61 | |
---|
[56] | 62 | TEncGOP::TEncGOP() |
---|
[2] | 63 | { |
---|
[56] | 64 | m_iLastIDR = 0; |
---|
| 65 | m_iGopSize = 0; |
---|
| 66 | m_iNumPicCoded = 0; //Niko |
---|
| 67 | m_bFirst = true; |
---|
| 68 | |
---|
[2] | 69 | m_pcCfg = NULL; |
---|
| 70 | m_pcSliceEncoder = NULL; |
---|
| 71 | m_pcListPic = NULL; |
---|
[56] | 72 | |
---|
[2] | 73 | m_pcEntropyCoder = NULL; |
---|
| 74 | m_pcCavlcCoder = NULL; |
---|
| 75 | m_pcSbacCoder = NULL; |
---|
| 76 | m_pcBinCABAC = NULL; |
---|
[5] | 77 | #if DEPTH_MAP_GENERATION |
---|
[2] | 78 | m_pcDepthMapGenerator = NULL; |
---|
[5] | 79 | #endif |
---|
[295] | 80 | #if H3D_IVRP |
---|
[2] | 81 | m_pcResidualGenerator = NULL; |
---|
[5] | 82 | #endif |
---|
[56] | 83 | |
---|
| 84 | m_bSeqFirst = true; |
---|
| 85 | |
---|
[2] | 86 | m_bRefreshPending = 0; |
---|
[56] | 87 | m_pocCRA = 0; |
---|
[2] | 88 | |
---|
| 89 | return; |
---|
| 90 | } |
---|
| 91 | |
---|
[56] | 92 | TEncGOP::~TEncGOP() |
---|
[2] | 93 | { |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /** Create list to contain pointers to LCU start addresses of slice. |
---|
| 97 | * \param iWidth, iHeight are picture width, height. iMaxCUWidth, iMaxCUHeight are LCU width, height. |
---|
| 98 | */ |
---|
[56] | 99 | Void TEncGOP::create( Int iWidth, Int iHeight, UInt iMaxCUWidth, UInt iMaxCUHeight ) |
---|
[2] | 100 | { |
---|
| 101 | UInt uiWidthInCU = ( iWidth %iMaxCUWidth ) ? iWidth /iMaxCUWidth + 1 : iWidth /iMaxCUWidth; |
---|
| 102 | UInt uiHeightInCU = ( iHeight%iMaxCUHeight ) ? iHeight/iMaxCUHeight + 1 : iHeight/iMaxCUHeight; |
---|
| 103 | UInt uiNumCUsInFrame = uiWidthInCU * uiHeightInCU; |
---|
[56] | 104 | m_uiStoredStartCUAddrForEncodingSlice = new UInt [uiNumCUsInFrame*(1<<(g_uiMaxCUDepth<<1))+1]; |
---|
| 105 | m_uiStoredStartCUAddrForEncodingEntropySlice = new UInt [uiNumCUsInFrame*(1<<(g_uiMaxCUDepth<<1))+1]; |
---|
| 106 | m_bLongtermTestPictureHasBeenCoded = 0; |
---|
| 107 | m_bLongtermTestPictureHasBeenCoded2 = 0; |
---|
[2] | 108 | } |
---|
| 109 | |
---|
[56] | 110 | Void TEncGOP::destroy() |
---|
[2] | 111 | { |
---|
| 112 | delete [] m_uiStoredStartCUAddrForEncodingSlice; m_uiStoredStartCUAddrForEncodingSlice = NULL; |
---|
| 113 | delete [] m_uiStoredStartCUAddrForEncodingEntropySlice; m_uiStoredStartCUAddrForEncodingEntropySlice = NULL; |
---|
| 114 | } |
---|
| 115 | |
---|
[56] | 116 | Void TEncGOP::init ( TEncTop* pcTEncTop ) |
---|
[2] | 117 | { |
---|
| 118 | m_pcEncTop = pcTEncTop; |
---|
| 119 | m_pcCfg = pcTEncTop; |
---|
| 120 | m_pcSliceEncoder = pcTEncTop->getSliceEncoder(); |
---|
| 121 | m_pcListPic = pcTEncTop->getListPic(); |
---|
[56] | 122 | |
---|
[2] | 123 | m_pcEntropyCoder = pcTEncTop->getEntropyCoder(); |
---|
| 124 | m_pcCavlcCoder = pcTEncTop->getCavlcCoder(); |
---|
| 125 | m_pcSbacCoder = pcTEncTop->getSbacCoder(); |
---|
| 126 | m_pcBinCABAC = pcTEncTop->getBinCABAC(); |
---|
| 127 | m_pcLoopFilter = pcTEncTop->getLoopFilter(); |
---|
| 128 | m_pcBitCounter = pcTEncTop->getBitCounter(); |
---|
[56] | 129 | |
---|
[5] | 130 | #if DEPTH_MAP_GENERATION |
---|
[2] | 131 | m_pcDepthMapGenerator = pcTEncTop->getDepthMapGenerator(); |
---|
[5] | 132 | #endif |
---|
[295] | 133 | #if H3D_IVRP |
---|
[2] | 134 | m_pcResidualGenerator = pcTEncTop->getResidualGenerator(); |
---|
[5] | 135 | #endif |
---|
[56] | 136 | |
---|
[2] | 137 | // Adaptive Loop filter |
---|
| 138 | m_pcAdaptiveLoopFilter = pcTEncTop->getAdaptiveLoopFilter(); |
---|
| 139 | //--Adaptive Loop filter |
---|
| 140 | m_pcSAO = pcTEncTop->getSAO(); |
---|
| 141 | m_pcRdCost = pcTEncTop->getRdCost(); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | // ==================================================================================================================== |
---|
| 145 | // Public member functions |
---|
| 146 | // ==================================================================================================================== |
---|
| 147 | |
---|
[56] | 148 | Void TEncGOP::initGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP) |
---|
[2] | 149 | { |
---|
[56] | 150 | xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut ); |
---|
| 151 | m_iNumPicCoded = 0; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid) |
---|
| 155 | { |
---|
| 156 | TComPic* pcPic; |
---|
| 157 | TComPicYuv* pcPicYuvRecOut; |
---|
[2] | 158 | TComSlice* pcSlice; |
---|
[56] | 159 | TComOutputBitstream *pcBitstreamRedirect; |
---|
| 160 | pcBitstreamRedirect = new TComOutputBitstream; |
---|
| 161 | AccessUnit::iterator itLocationToPushSliceHeaderNALU; // used to store location where NALU containing slice header is to be inserted |
---|
| 162 | UInt uiOneBitstreamPerSliceLength = 0; |
---|
| 163 | TEncSbac* pcSbacCoders = NULL; |
---|
| 164 | TComOutputBitstream* pcSubstreamsOut = NULL; |
---|
[5] | 165 | |
---|
[56] | 166 | { |
---|
| 167 | UInt uiColDir = 1; |
---|
[2] | 168 | //-- For time output for each slice |
---|
| 169 | long iBeforeTime = clock(); |
---|
[56] | 170 | |
---|
| 171 | //select uiColDir |
---|
| 172 | Int iCloseLeft=1, iCloseRight=-1; |
---|
| 173 | for(Int i = 0; i<m_pcCfg->getGOPEntry(iGOPid).m_numRefPics; i++) |
---|
| 174 | { |
---|
| 175 | Int iRef = m_pcCfg->getGOPEntry(iGOPid).m_referencePics[i]; |
---|
| 176 | if(iRef>0&&(iRef<iCloseRight||iCloseRight==-1)) |
---|
| 177 | { |
---|
| 178 | iCloseRight=iRef; |
---|
| 179 | } |
---|
| 180 | else if(iRef<0&&(iRef>iCloseLeft||iCloseLeft==1)) |
---|
| 181 | { |
---|
| 182 | iCloseLeft=iRef; |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | if(iCloseRight>-1) |
---|
| 186 | { |
---|
| 187 | iCloseRight=iCloseRight+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
| 188 | } |
---|
| 189 | if(iCloseLeft<1) |
---|
| 190 | { |
---|
| 191 | iCloseLeft=iCloseLeft+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
| 192 | while(iCloseLeft<0) |
---|
| 193 | { |
---|
| 194 | iCloseLeft+=m_iGopSize; |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | Int iLeftQP=0, iRightQP=0; |
---|
| 198 | for(Int i=0; i<m_iGopSize; i++) |
---|
| 199 | { |
---|
| 200 | if(m_pcCfg->getGOPEntry(i).m_POC==(iCloseLeft%m_iGopSize)+1) |
---|
| 201 | { |
---|
| 202 | iLeftQP= m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
| 203 | } |
---|
| 204 | if (m_pcCfg->getGOPEntry(i).m_POC==(iCloseRight%m_iGopSize)+1) |
---|
| 205 | { |
---|
| 206 | iRightQP=m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | if(iCloseRight>-1&&iRightQP<iLeftQP) |
---|
| 210 | { |
---|
| 211 | uiColDir=0; |
---|
| 212 | } |
---|
[2] | 213 | |
---|
[56] | 214 | /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding |
---|
| 215 | UInt uiPOCCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
| 216 | Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
| 217 | if(iPOCLast == 0) |
---|
| 218 | { |
---|
| 219 | uiPOCCurr=0; |
---|
| 220 | iTimeOffset = 1; |
---|
| 221 | } |
---|
| 222 | if(uiPOCCurr>=m_pcCfg->getFrameToBeEncoded()) |
---|
| 223 | { |
---|
| 224 | return; |
---|
| 225 | } |
---|
| 226 | if( getNalUnitTypeBaseViewMvc( uiPOCCurr ) == NAL_UNIT_CODED_SLICE_IDR ) |
---|
| 227 | { |
---|
| 228 | m_iLastIDR = uiPOCCurr; |
---|
| 229 | } |
---|
[5] | 230 | |
---|
[56] | 231 | /* start a new access unit: create an entry in the list of output |
---|
| 232 | * access units */ |
---|
| 233 | accessUnitsInGOP.push_back(AccessUnit()); |
---|
| 234 | AccessUnit& accessUnit = accessUnitsInGOP.back(); |
---|
| 235 | xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, uiPOCCurr ); |
---|
| 236 | |
---|
[2] | 237 | // Slice data initialization |
---|
| 238 | pcPic->clearSliceBuffer(); |
---|
| 239 | assert(pcPic->getNumAllocatedSlice() == 1); |
---|
| 240 | m_pcSliceEncoder->setSliceIdx(0); |
---|
| 241 | pcPic->setCurrSliceIdx(0); |
---|
[56] | 242 | |
---|
| 243 | std::vector<TComAPS>& vAPS = m_pcEncTop->getAPS(); |
---|
[210] | 244 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[280] | 245 | #if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137 |
---|
| 246 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getEncTop()->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getIsDepth() ); |
---|
| 247 | #else |
---|
[77] | 248 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getEncTop()->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS() ); |
---|
[280] | 249 | #endif |
---|
[77] | 250 | #else |
---|
[56] | 251 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() ); |
---|
[77] | 252 | #endif |
---|
[56] | 253 | pcSlice->setLastIDR(m_iLastIDR); |
---|
[2] | 254 | pcSlice->setSliceIdx(0); |
---|
[56] | 255 | pcSlice->setViewId( m_pcEncTop->getViewId() ); |
---|
[231] | 256 | pcSlice->setIsDepth( m_pcEncTop->getIsDepth() ); |
---|
[280] | 257 | #if INTER_VIEW_VECTOR_SCALING_C0115 |
---|
| 258 | pcSlice->setIVScalingFlag( m_pcEncTop->getUseIVS() ); |
---|
| 259 | #endif |
---|
[5] | 260 | |
---|
[56] | 261 | m_pcEncTop->getSPS()->setDisInter4x4(m_pcEncTop->getDisInter4x4()); |
---|
| 262 | pcSlice->setScalingList ( m_pcEncTop->getScalingList() ); |
---|
| 263 | if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF) |
---|
| 264 | { |
---|
| 265 | m_pcEncTop->getTrQuant()->setFlatScalingList(); |
---|
| 266 | m_pcEncTop->getTrQuant()->setUseScalingList(false); |
---|
| 267 | } |
---|
| 268 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
| 269 | { |
---|
| 270 | pcSlice->setDefaultScalingList (); |
---|
| 271 | pcSlice->getScalingList()->setScalingListPresentFlag(true); |
---|
| 272 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
| 273 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
| 274 | } |
---|
| 275 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
| 276 | { |
---|
| 277 | if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile())) |
---|
| 278 | { |
---|
| 279 | pcSlice->setDefaultScalingList (); |
---|
| 280 | } |
---|
| 281 | pcSlice->getScalingList()->checkDcOfMatrix(); |
---|
| 282 | pcSlice->getScalingList()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList()); |
---|
| 283 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
| 284 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
| 285 | } |
---|
| 286 | else |
---|
| 287 | { |
---|
| 288 | printf("error : ScalingList == %d no support\n",m_pcEncTop->getUseScalingListId()); |
---|
| 289 | assert(0); |
---|
| 290 | } |
---|
[2] | 291 | |
---|
[56] | 292 | #if HHI_INTERVIEW_SKIP |
---|
| 293 | if ( m_pcEncTop->getInterViewSkip() ) |
---|
| 294 | { |
---|
| 295 | m_pcEncTop->getEncTop()->getUsedPelsMap( pcPic->getViewId(), pcPic->getPOC(), pcPic->getUsedPelsMap() ); |
---|
| 296 | } |
---|
| 297 | #endif |
---|
| 298 | // Slice info. refinement |
---|
| 299 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
| 300 | { |
---|
[210] | 301 | #if QC_REM_IDV_B0046 |
---|
| 302 | if( m_pcCfg->getGOPEntry(pcSlice->getSPS()->getViewId() && ((getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDR) || (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_CRA))? MAX_GOP : iGOPid ).m_sliceType == 'P' ) { pcSlice->setSliceType( P_SLICE ); } |
---|
| 303 | #else |
---|
| 304 | if( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) { pcSlice->setSliceType( P_SLICE ); } |
---|
| 305 | #endif |
---|
| 306 | } |
---|
[5] | 307 | |
---|
[2] | 308 | // Set the nal unit type |
---|
[56] | 309 | pcSlice->setNalUnitType( getNalUnitType(uiPOCCurr) ); |
---|
| 310 | pcSlice->setNalUnitTypeBaseViewMvc( getNalUnitTypeBaseViewMvc(uiPOCCurr) ); |
---|
[2] | 311 | |
---|
[56] | 312 | // Do decoding refresh marking if any |
---|
| 313 | pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic); |
---|
| 314 | |
---|
| 315 | if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 ) |
---|
| 316 | { |
---|
| 317 | pcSlice->decodingMarkingForNoTMVP( rcListPic, pcSlice->getPOC() ); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | m_pcEncTop->selectReferencePictureSet(pcSlice, uiPOCCurr, iGOPid,rcListPic); |
---|
| 321 | pcSlice->getRPS()->setNumberOfLongtermPictures(0); |
---|
| 322 | |
---|
| 323 | if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) |
---|
| 324 | { |
---|
| 325 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS()); |
---|
| 326 | } |
---|
| 327 | pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); |
---|
| 328 | |
---|
[294] | 329 | #if H0566_TLA_SET_FOR_SWITCHING_POINTS |
---|
[56] | 330 | if(pcSlice->getTLayer() > 0) |
---|
| 331 | { |
---|
| 332 | if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic, pcSlice->getRPS())) |
---|
| 333 | { |
---|
| 334 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA); |
---|
| 335 | } |
---|
| 336 | } |
---|
[2] | 337 | #endif |
---|
| 338 | |
---|
[210] | 339 | #if !QC_REM_IDV_B0046 |
---|
[56] | 340 | pcSlice->setNumRefIdx( REF_PIC_LIST_0, min( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) ); |
---|
| 341 | pcSlice->setNumRefIdx( REF_PIC_LIST_1, min( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) ); |
---|
[210] | 342 | #else |
---|
[280] | 343 | |
---|
[231] | 344 | Bool bNalRAP = ((getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_CRA) || (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDR)) && (pcSlice->getSPS()->getViewId()) ? 1: 0; |
---|
| 345 | pcSlice->setNumRefIdx( REF_PIC_LIST_0, min( m_pcCfg->getGOPEntry( bNalRAP ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) ); |
---|
| 346 | pcSlice->setNumRefIdx( REF_PIC_LIST_1, min( m_pcCfg->getGOPEntry( bNalRAP ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) ); |
---|
[210] | 347 | #endif |
---|
[231] | 348 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
| 349 | refPicListModification->setRefPicListModificationFlagL0( false ); |
---|
[56] | 350 | refPicListModification->setRefPicListModificationFlagL1( false ); |
---|
| 351 | xSetRefPicListModificationsMvc( pcSlice, uiPOCCurr, iGOPid ); |
---|
[5] | 352 | |
---|
[56] | 353 | #if ADAPTIVE_QP_SELECTION |
---|
| 354 | pcSlice->setTrQuant( m_pcEncTop->getTrQuant() ); |
---|
| 355 | #endif |
---|
| 356 | // Set reference list |
---|
| 357 | TAppEncTop* tAppEncTop = m_pcEncTop->getEncTop(); |
---|
| 358 | assert( tAppEncTop != NULL ); |
---|
[2] | 359 | |
---|
[210] | 360 | |
---|
| 361 | #if FLEX_CODING_ORDER_M23723 |
---|
| 362 | TComPic * pcTexturePic; |
---|
| 363 | if(m_pcEncTop->getIsDepth() == 1) |
---|
| 364 | { |
---|
| 365 | TComPicYuv * recText; |
---|
| 366 | recText = tAppEncTop->getPicYuvFromView(m_pcEncTop->getViewId(), pcSlice->getPOC(), false ,true); |
---|
| 367 | if(recText == NULL) |
---|
| 368 | { |
---|
| 369 | pcSlice->setTexturePic(NULL); |
---|
| 370 | } |
---|
| 371 | else |
---|
| 372 | { |
---|
| 373 | pcTexturePic = m_pcEncTop->getIsDepth() ? tAppEncTop->getPicFromView( m_pcEncTop->getViewId(), pcSlice->getPOC(), false ) : NULL; |
---|
| 374 | pcSlice->setTexturePic( pcTexturePic ); |
---|
| 375 | } |
---|
| 376 | } |
---|
| 377 | else |
---|
| 378 | { |
---|
| 379 | pcTexturePic = m_pcEncTop->getIsDepth() ? tAppEncTop->getPicFromView( m_pcEncTop->getViewId(), pcSlice->getPOC(), false ) : NULL; |
---|
| 380 | assert( !m_pcEncTop->getIsDepth() || pcTexturePic != NULL ); |
---|
| 381 | pcSlice->setTexturePic( pcTexturePic ); |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | #else |
---|
[56] | 385 | TComPic * const pcTexturePic = m_pcEncTop->getIsDepth() ? tAppEncTop->getPicFromView( m_pcEncTop->getViewId(), pcSlice->getPOC(), false ) : NULL; |
---|
| 386 | assert( !m_pcEncTop->getIsDepth() || pcTexturePic != NULL ); |
---|
| 387 | pcSlice->setTexturePic( pcTexturePic ); |
---|
[5] | 388 | |
---|
[210] | 389 | #endif |
---|
[56] | 390 | std::vector<TComPic*> apcInterViewRefPics = tAppEncTop->getInterViewRefPics( m_pcEncTop->getViewId(), pcSlice->getPOC(), m_pcEncTop->getIsDepth(), pcSlice->getSPS() ); |
---|
| 391 | pcSlice->setRefPicListMvc( rcListPic, apcInterViewRefPics ); |
---|
| 392 | |
---|
| 393 | // Slice info. refinement |
---|
| 394 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
| 395 | { |
---|
[210] | 396 | #if !QC_REM_IDV_B0046 |
---|
[56] | 397 | if( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) { pcSlice->setSliceType( P_SLICE ); } |
---|
[210] | 398 | #else |
---|
| 399 | Bool bRAP = ((getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_CRA) || (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDR)) && (pcSlice->getSPS()->getViewId()) ? 1: 0; |
---|
| 400 | if( m_pcCfg->getGOPEntry( bRAP ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) { pcSlice->setSliceType( P_SLICE ); } |
---|
| 401 | #endif |
---|
[56] | 402 | } |
---|
| 403 | |
---|
| 404 | if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb()) |
---|
| 405 | { |
---|
| 406 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0); |
---|
| 407 | pcSlice->setRefPicListCombinationFlag(false); |
---|
| 408 | pcSlice->setRefPicListModificationFlagLC(false); |
---|
| 409 | } |
---|
| 410 | else |
---|
| 411 | { |
---|
| 412 | pcSlice->setRefPicListCombinationFlag(pcSlice->getSPS()->getUseLComb()); |
---|
| 413 | pcSlice->setRefPicListModificationFlagLC(pcSlice->getSPS()->getLCMod()); |
---|
| 414 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0)); |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | if (pcSlice->getSliceType() == B_SLICE) |
---|
| 418 | { |
---|
| 419 | pcSlice->setColDir(uiColDir); |
---|
| 420 | Bool bLowDelay = true; |
---|
| 421 | Int iCurrPOC = pcSlice->getPOC(); |
---|
| 422 | Int iRefIdx = 0; |
---|
| 423 | |
---|
| 424 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
| 425 | { |
---|
| 426 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 427 | { |
---|
| 428 | bLowDelay = false; |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
| 432 | { |
---|
| 433 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 434 | { |
---|
| 435 | bLowDelay = false; |
---|
| 436 | } |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | pcSlice->setCheckLDC(bLowDelay); |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | uiColDir = 1-uiColDir; |
---|
| 443 | |
---|
| 444 | //------------------------------------------------------------- |
---|
| 445 | pcSlice->setRefPOCnViewListsMvc(); |
---|
| 446 | |
---|
| 447 | pcSlice->setNoBackPredFlag( false ); |
---|
| 448 | if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag()) |
---|
| 449 | { |
---|
| 450 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
| 451 | { |
---|
| 452 | pcSlice->setNoBackPredFlag( true ); |
---|
| 453 | int i; |
---|
| 454 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
| 455 | { |
---|
| 456 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
| 457 | { |
---|
| 458 | pcSlice->setNoBackPredFlag( false ); |
---|
| 459 | break; |
---|
| 460 | } |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | if(pcSlice->getNoBackPredFlag()) |
---|
| 466 | { |
---|
| 467 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0); |
---|
| 468 | } |
---|
| 469 | pcSlice->generateCombinedList(); |
---|
| 470 | |
---|
| 471 | #if HHI_VSO |
---|
[5] | 472 | Bool bUseVSO = m_pcEncTop->getUseVSO(); |
---|
[2] | 473 | m_pcRdCost->setUseVSO( bUseVSO ); |
---|
[100] | 474 | #if SAIT_VSO_EST_A0033 |
---|
| 475 | m_pcRdCost->setUseEstimatedVSD( m_pcEncTop->getUseEstimatedVSD() ); |
---|
| 476 | #endif |
---|
[2] | 477 | |
---|
| 478 | if ( bUseVSO ) |
---|
[5] | 479 | { |
---|
[2] | 480 | Int iVSOMode = m_pcEncTop->getVSOMode(); |
---|
[5] | 481 | m_pcRdCost->setVSOMode( iVSOMode ); |
---|
[120] | 482 | |
---|
[5] | 483 | #if HHI_VSO_DIST_INT |
---|
| 484 | m_pcRdCost->setAllowNegDist( m_pcEncTop->getAllowNegDist() ); |
---|
[2] | 485 | #endif |
---|
| 486 | |
---|
[100] | 487 | |
---|
| 488 | #if SAIT_VSO_EST_A0033 |
---|
[210] | 489 | #ifdef FLEX_CODING_ORDER_M23723 |
---|
| 490 | { |
---|
| 491 | Bool flagRec; |
---|
| 492 | flagRec = ((m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), false, true) == NULL) ? false: true); |
---|
| 493 | m_pcRdCost->setVideoRecPicYuv( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), false, flagRec ) ); |
---|
| 494 | m_pcRdCost->setDepthPicYuv ( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), true, false ) ); |
---|
| 495 | } |
---|
| 496 | #else |
---|
| 497 | m_pcRdCost->setVideoRecPicYuv( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), false, true ) ); |
---|
| 498 | m_pcRdCost->setDepthPicYuv ( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), true, false ) ); |
---|
[100] | 499 | #endif |
---|
[210] | 500 | #endif |
---|
[115] | 501 | #if LGE_WVSO_A0119 |
---|
[120] | 502 | Bool bUseWVSO = m_pcEncTop->getUseWVSO(); |
---|
| 503 | m_pcRdCost->setUseWVSO( bUseWVSO ); |
---|
[115] | 504 | #endif |
---|
[100] | 505 | |
---|
[2] | 506 | } |
---|
[5] | 507 | #endif |
---|
[56] | 508 | /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice |
---|
| 509 | // Slice compression |
---|
| 510 | if (m_pcCfg->getUseASR()) |
---|
| 511 | { |
---|
| 512 | m_pcSliceEncoder->setSearchRange(pcSlice); |
---|
| 513 | } |
---|
[2] | 514 | |
---|
[56] | 515 | Bool bGPBcheck=false; |
---|
| 516 | if ( pcSlice->getSliceType() == B_SLICE) |
---|
[2] | 517 | { |
---|
| 518 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
| 519 | { |
---|
[56] | 520 | bGPBcheck=true; |
---|
[2] | 521 | int i; |
---|
| 522 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
| 523 | { |
---|
[56] | 524 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
[2] | 525 | { |
---|
[56] | 526 | bGPBcheck=false; |
---|
[2] | 527 | break; |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | } |
---|
| 531 | } |
---|
[56] | 532 | if(bGPBcheck) |
---|
[2] | 533 | { |
---|
[56] | 534 | pcSlice->setMvdL1ZeroFlag(true); |
---|
[2] | 535 | } |
---|
[56] | 536 | else |
---|
| 537 | { |
---|
| 538 | pcSlice->setMvdL1ZeroFlag(false); |
---|
| 539 | } |
---|
| 540 | pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); |
---|
[5] | 541 | |
---|
[56] | 542 | UInt uiNumSlices = 1; |
---|
| 543 | |
---|
| 544 | UInt uiInternalAddress = pcPic->getNumPartInCU()-4; |
---|
| 545 | UInt uiExternalAddress = pcPic->getPicSym()->getNumberOfCUsInFrame()-1; |
---|
| 546 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 547 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 548 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 549 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
| 550 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
[2] | 551 | { |
---|
[56] | 552 | uiInternalAddress--; |
---|
| 553 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 554 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
[2] | 555 | } |
---|
[56] | 556 | uiInternalAddress++; |
---|
| 557 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
[2] | 558 | { |
---|
[56] | 559 | uiInternalAddress = 0; |
---|
| 560 | uiExternalAddress++; |
---|
[2] | 561 | } |
---|
[56] | 562 | UInt uiRealEndAddress = uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress; |
---|
[2] | 563 | |
---|
[56] | 564 | UInt uiCummulativeTileWidth; |
---|
| 565 | UInt uiCummulativeTileHeight; |
---|
| 566 | Int p, j; |
---|
| 567 | UInt uiEncCUAddr; |
---|
| 568 | |
---|
| 569 | |
---|
| 570 | if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 ) //derive the tile parameters from PPS |
---|
| 571 | { |
---|
| 572 | //set NumColumnsMinus1 and NumRowsMinus1 |
---|
| 573 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
| 574 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
| 575 | |
---|
| 576 | //create the TComTileArray |
---|
| 577 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
| 578 | |
---|
| 579 | if( pcSlice->getPPS()->getUniformSpacingIdr() == 1 ) |
---|
| 580 | { |
---|
| 581 | //set the width for each tile |
---|
| 582 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 583 | { |
---|
| 584 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
| 585 | { |
---|
| 586 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
| 587 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
| 588 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
| 589 | } |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | //set the height for each tile |
---|
| 593 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 594 | { |
---|
| 595 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
| 596 | { |
---|
| 597 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
| 598 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
| 599 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
| 600 | } |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | else |
---|
| 604 | { |
---|
| 605 | //set the width for each tile |
---|
| 606 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 607 | { |
---|
| 608 | uiCummulativeTileWidth = 0; |
---|
| 609 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++) |
---|
| 610 | { |
---|
| 611 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getPPS()->getColumnWidth(p) ); |
---|
| 612 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(p); |
---|
| 613 | } |
---|
| 614 | pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | //set the height for each tile |
---|
| 618 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 619 | { |
---|
| 620 | uiCummulativeTileHeight = 0; |
---|
| 621 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++) |
---|
| 622 | { |
---|
| 623 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getPPS()->getRowHeight(p) ); |
---|
| 624 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(p); |
---|
| 625 | } |
---|
| 626 | pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
| 627 | } |
---|
| 628 | } |
---|
| 629 | } |
---|
| 630 | else //derive the tile parameters from SPS |
---|
| 631 | { |
---|
| 632 | //set NumColumnsMins1 and NumRowsMinus1 |
---|
| 633 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() ); |
---|
| 634 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() ); |
---|
| 635 | |
---|
| 636 | //create the TComTileArray |
---|
| 637 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
| 638 | |
---|
| 639 | if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 ) |
---|
| 640 | { |
---|
| 641 | //set the width for each tile |
---|
| 642 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 643 | { |
---|
| 644 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
| 645 | { |
---|
| 646 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
| 647 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
| 648 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
| 649 | } |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | //set the height for each tile |
---|
| 653 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 654 | { |
---|
| 655 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
| 656 | { |
---|
| 657 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
| 658 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
| 659 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
| 660 | } |
---|
| 661 | } |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | else |
---|
| 665 | { |
---|
| 666 | //set the width for each tile |
---|
| 667 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 668 | { |
---|
| 669 | uiCummulativeTileWidth = 0; |
---|
| 670 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++) |
---|
| 671 | { |
---|
| 672 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getSPS()->getColumnWidth(p) ); |
---|
| 673 | uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(p); |
---|
| 674 | } |
---|
| 675 | pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | //set the height for each tile |
---|
| 679 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 680 | { |
---|
| 681 | uiCummulativeTileHeight = 0; |
---|
| 682 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++) |
---|
| 683 | { |
---|
| 684 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getSPS()->getRowHeight(p) ); |
---|
| 685 | uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(p); |
---|
| 686 | } |
---|
| 687 | pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
| 688 | } |
---|
| 689 | } |
---|
| 690 | } |
---|
| 691 | |
---|
| 692 | //initialize each tile of the current picture |
---|
| 693 | pcPic->getPicSym()->xInitTiles(); |
---|
| 694 | |
---|
| 695 | // Allocate some coders, now we know how many tiles there are. |
---|
| 696 | Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); |
---|
| 697 | |
---|
| 698 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
| 699 | for(p=0, uiEncCUAddr=0; p<pcPic->getPicSym()->getNumberOfCUsInFrame(); p++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
| 700 | { |
---|
| 701 | pcPic->getPicSym()->setCUOrderMap(p, uiEncCUAddr); |
---|
| 702 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, p); |
---|
| 703 | } |
---|
| 704 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 705 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 706 | if (pcSlice->getPPS()->getEntropyCodingMode()) |
---|
| 707 | { |
---|
| 708 | // Allocate some coders, now we know how many tiles there are. |
---|
| 709 | m_pcEncTop->createWPPCoders(iNumSubstreams); |
---|
| 710 | pcSbacCoders = m_pcEncTop->getSbacCoders(); |
---|
| 711 | pcSubstreamsOut = new TComOutputBitstream[iNumSubstreams]; |
---|
| 712 | } |
---|
| 713 | |
---|
[2] | 714 | UInt uiStartCUAddrSliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEncodingSlice" containing locations of slice boundaries |
---|
| 715 | UInt uiStartCUAddrSlice = 0; // used to keep track of current slice's starting CU addr. |
---|
| 716 | pcSlice->setSliceCurStartCUAddr( uiStartCUAddrSlice ); // Setting "start CU addr" for current slice |
---|
[56] | 717 | memset(m_uiStoredStartCUAddrForEncodingSlice, 0, sizeof(UInt) * (pcPic->getPicSym()->getNumberOfCUsInFrame()*pcPic->getNumPartInCU()+1)); |
---|
[2] | 718 | |
---|
| 719 | UInt uiStartCUAddrEntropySliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEntropyEncodingSlice" containing locations of slice boundaries |
---|
| 720 | UInt uiStartCUAddrEntropySlice = 0; // used to keep track of current Entropy slice's starting CU addr. |
---|
| 721 | pcSlice->setEntropySliceCurStartCUAddr( uiStartCUAddrEntropySlice ); // Setting "start CU addr" for current Entropy slice |
---|
[56] | 722 | |
---|
| 723 | memset(m_uiStoredStartCUAddrForEncodingEntropySlice, 0, sizeof(UInt) * (pcPic->getPicSym()->getNumberOfCUsInFrame()*pcPic->getNumPartInCU()+1)); |
---|
[2] | 724 | UInt uiNextCUAddr = 0; |
---|
| 725 | m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++] = uiNextCUAddr; |
---|
| 726 | m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++] = uiNextCUAddr; |
---|
| 727 | |
---|
[5] | 728 | #if DEPTH_MAP_GENERATION |
---|
[2] | 729 | // init view component and predict virtual depth map |
---|
| 730 | m_pcDepthMapGenerator->initViewComponent( pcPic ); |
---|
[289] | 731 | #if !H3D_NBDV |
---|
[2] | 732 | m_pcDepthMapGenerator->predictDepthMap ( pcPic ); |
---|
[56] | 733 | #endif |
---|
[100] | 734 | #endif |
---|
[292] | 735 | #if H3D_IVMP |
---|
[2] | 736 | m_pcDepthMapGenerator->covertOrgDepthMap( pcPic ); |
---|
[5] | 737 | #endif |
---|
[295] | 738 | #if H3D_IVRP |
---|
[2] | 739 | m_pcResidualGenerator->initViewComponent( pcPic ); |
---|
[5] | 740 | #endif |
---|
[2] | 741 | |
---|
[289] | 742 | #if H3D_NBDV |
---|
[189] | 743 | if(pcSlice->getViewId() && pcSlice->getSPS()->getMultiviewMvPredMode()) |
---|
| 744 | { |
---|
| 745 | Int iColPoc = pcSlice->getRefPOC(RefPicList(pcSlice->getColDir()), pcSlice->getColRefIdx()); |
---|
| 746 | pcPic->setRapbCheck(pcPic->getDisCandRefPictures(iColPoc)); |
---|
| 747 | } |
---|
| 748 | #endif |
---|
[56] | 749 | while(uiNextCUAddr<uiRealEndAddress) // determine slice boundaries |
---|
[2] | 750 | { |
---|
| 751 | pcSlice->setNextSlice ( false ); |
---|
| 752 | pcSlice->setNextEntropySlice( false ); |
---|
| 753 | assert(pcPic->getNumAllocatedSlice() == uiStartCUAddrSliceIdx); |
---|
| 754 | m_pcSliceEncoder->precompressSlice( pcPic ); |
---|
| 755 | m_pcSliceEncoder->compressSlice ( pcPic ); |
---|
| 756 | |
---|
| 757 | Bool bNoBinBitConstraintViolated = (!pcSlice->isNextSlice() && !pcSlice->isNextEntropySlice()); |
---|
| 758 | if (pcSlice->isNextSlice() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)) |
---|
| 759 | { |
---|
| 760 | uiStartCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
| 761 | // Reconstruction slice |
---|
| 762 | m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++] = uiStartCUAddrSlice; |
---|
| 763 | // Entropy slice |
---|
| 764 | if (uiStartCUAddrEntropySliceIdx>0 && m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx-1] != uiStartCUAddrSlice) |
---|
| 765 | { |
---|
| 766 | m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++] = uiStartCUAddrSlice; |
---|
| 767 | } |
---|
[56] | 768 | |
---|
| 769 | if (uiStartCUAddrSlice < uiRealEndAddress) |
---|
[2] | 770 | { |
---|
[56] | 771 | pcPic->allocateNewSlice(); |
---|
[2] | 772 | pcPic->setCurrSliceIdx ( uiStartCUAddrSliceIdx-1 ); |
---|
| 773 | m_pcSliceEncoder->setSliceIdx ( uiStartCUAddrSliceIdx-1 ); |
---|
| 774 | pcSlice = pcPic->getSlice ( uiStartCUAddrSliceIdx-1 ); |
---|
| 775 | pcSlice->copySliceInfo ( pcPic->getSlice(0) ); |
---|
| 776 | pcSlice->setSliceIdx ( uiStartCUAddrSliceIdx-1 ); |
---|
| 777 | pcSlice->setSliceCurStartCUAddr ( uiStartCUAddrSlice ); |
---|
| 778 | pcSlice->setEntropySliceCurStartCUAddr ( uiStartCUAddrSlice ); |
---|
| 779 | pcSlice->setSliceBits(0); |
---|
[56] | 780 | uiNumSlices ++; |
---|
[2] | 781 | } |
---|
| 782 | } |
---|
| 783 | else if (pcSlice->isNextEntropySlice() || (bNoBinBitConstraintViolated && m_pcCfg->getEntropySliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)) |
---|
| 784 | { |
---|
| 785 | uiStartCUAddrEntropySlice = pcSlice->getEntropySliceCurEndCUAddr(); |
---|
| 786 | m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++] = uiStartCUAddrEntropySlice; |
---|
| 787 | pcSlice->setEntropySliceCurStartCUAddr( uiStartCUAddrEntropySlice ); |
---|
| 788 | } |
---|
| 789 | else |
---|
| 790 | { |
---|
| 791 | uiStartCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
| 792 | uiStartCUAddrEntropySlice = pcSlice->getEntropySliceCurEndCUAddr(); |
---|
[56] | 793 | } |
---|
[2] | 794 | |
---|
| 795 | uiNextCUAddr = (uiStartCUAddrSlice > uiStartCUAddrEntropySlice) ? uiStartCUAddrSlice : uiStartCUAddrEntropySlice; |
---|
| 796 | } |
---|
| 797 | m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++] = pcSlice->getSliceCurEndCUAddr(); |
---|
| 798 | m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++] = pcSlice->getSliceCurEndCUAddr(); |
---|
[56] | 799 | |
---|
[2] | 800 | pcSlice = pcPic->getSlice(0); |
---|
| 801 | |
---|
[295] | 802 | #if H3D_IVRP |
---|
[2] | 803 | // set residual picture |
---|
| 804 | m_pcResidualGenerator->setRecResidualPic( pcPic ); |
---|
[5] | 805 | #endif |
---|
| 806 | #if DEPTH_MAP_GENERATION |
---|
[289] | 807 | #if !H3D_NBDV |
---|
[2] | 808 | // update virtual depth map |
---|
| 809 | m_pcDepthMapGenerator->updateDepthMap( pcPic ); |
---|
[5] | 810 | #endif |
---|
[100] | 811 | #endif |
---|
[2] | 812 | |
---|
| 813 | //-- Loop filter |
---|
[56] | 814 | Bool bLFCrossTileBoundary = (pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)? |
---|
| 815 | (pcSlice->getPPS()->getLFCrossTileBoundaryFlag()):(pcSlice->getPPS()->getSPS()->getLFCrossTileBoundaryFlag()); |
---|
| 816 | m_pcLoopFilter->setCfg(pcSlice->getPPS()->getDeblockingFilterControlPresent(), pcSlice->getLoopFilterDisable(), pcSlice->getLoopFilterBetaOffset(), pcSlice->getLoopFilterTcOffset(), bLFCrossTileBoundary); |
---|
[2] | 817 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
| 818 | |
---|
| 819 | pcSlice = pcPic->getSlice(0); |
---|
[56] | 820 | if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()) |
---|
| 821 | { |
---|
| 822 | Int sliceGranularity = pcSlice->getPPS()->getSliceGranularity(); |
---|
| 823 | pcPic->createNonDBFilterInfo(m_uiStoredStartCUAddrForEncodingSlice, uiNumSlices, sliceGranularity, pcSlice->getSPS()->getLFCrossSliceBoundaryFlag(),pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary); |
---|
| 824 | } |
---|
[2] | 825 | |
---|
[56] | 826 | |
---|
| 827 | pcSlice = pcPic->getSlice(0); |
---|
| 828 | |
---|
| 829 | if(pcSlice->getSPS()->getUseSAO()) |
---|
[2] | 830 | { |
---|
[56] | 831 | m_pcSAO->createPicSaoInfo(pcPic, uiNumSlices); |
---|
| 832 | } |
---|
[2] | 833 | |
---|
[56] | 834 | AlfParamSet* alfSliceParams = NULL; |
---|
| 835 | std::vector<AlfCUCtrlInfo>* alfCUCtrlParam = NULL; |
---|
| 836 | pcSlice = pcPic->getSlice(0); |
---|
[2] | 837 | |
---|
[56] | 838 | if(pcSlice->getSPS()->getUseALF()) |
---|
| 839 | { |
---|
| 840 | m_pcAdaptiveLoopFilter->createPicAlfInfo(pcPic, uiNumSlices, pcSlice->getSliceQp()); |
---|
| 841 | m_pcAdaptiveLoopFilter->initALFEnc(m_pcCfg->getALFParamInSlice(), m_pcCfg->getALFPicBasedEncode(), uiNumSlices, alfSliceParams, alfCUCtrlParam); |
---|
[2] | 842 | } |
---|
[56] | 843 | |
---|
[2] | 844 | /////////////////////////////////////////////////////////////////////////////////////////////////// File writing |
---|
| 845 | // Set entropy coder |
---|
| 846 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 847 | |
---|
[56] | 848 | /* write various header sets. */ |
---|
| 849 | if ( m_bSeqFirst ) |
---|
[2] | 850 | { |
---|
[210] | 851 | #if QC_MVHEVC_B0046 |
---|
| 852 | if(!m_pcEncTop->getLayerId()) |
---|
| 853 | { |
---|
| 854 | #endif |
---|
| 855 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[77] | 856 | { |
---|
| 857 | OutputNALUnit nalu(NAL_UNIT_VPS, true, m_pcEncTop->getLayerId()); |
---|
| 858 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 859 | m_pcEntropyCoder->encodeVPS(m_pcEncTop->getEncTop()->getVPS()); |
---|
| 860 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 861 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 862 | } |
---|
| 863 | #endif |
---|
[210] | 864 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[77] | 865 | OutputNALUnit nalu(NAL_UNIT_SPS, true, m_pcEncTop->getLayerId()); |
---|
| 866 | #else |
---|
[56] | 867 | OutputNALUnit nalu(NAL_UNIT_SPS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[77] | 868 | #endif |
---|
[56] | 869 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 870 | pcSlice->getSPS()->setNumSubstreams( pcSlice->getPPS()->getNumSubstreams() ); |
---|
[280] | 871 | #if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068 |
---|
[56] | 872 | m_pcEntropyCoder->encodeSPS(pcSlice->getSPS(), m_pcEncTop->getIsDepth()); |
---|
| 873 | #else |
---|
| 874 | m_pcEntropyCoder->encodeSPS(pcSlice->getSPS()); |
---|
| 875 | #endif |
---|
| 876 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 877 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
[2] | 878 | |
---|
[210] | 879 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
| 880 | #if QC_MVHEVC_B0046 |
---|
[77] | 881 | nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getLayerId()); |
---|
| 882 | #else |
---|
[210] | 883 | nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getLayerId()); |
---|
| 884 | #endif |
---|
| 885 | #else |
---|
[56] | 886 | nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[77] | 887 | #endif |
---|
[56] | 888 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 889 | m_pcEntropyCoder->encodePPS(pcSlice->getPPS()); |
---|
| 890 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 891 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
[210] | 892 | #if QC_MVHEVC_B0046 |
---|
[2] | 893 | } |
---|
[210] | 894 | #endif |
---|
| 895 | m_bSeqFirst = false; |
---|
| 896 | } |
---|
[5] | 897 | |
---|
[2] | 898 | /* use the main bitstream buffer for storing the marshalled picture */ |
---|
[56] | 899 | m_pcEntropyCoder->setBitstream(NULL); |
---|
[2] | 900 | |
---|
| 901 | uiStartCUAddrSliceIdx = 0; |
---|
[56] | 902 | uiStartCUAddrSlice = 0; |
---|
[2] | 903 | |
---|
| 904 | uiStartCUAddrEntropySliceIdx = 0; |
---|
[56] | 905 | uiStartCUAddrEntropySlice = 0; |
---|
[2] | 906 | uiNextCUAddr = 0; |
---|
| 907 | pcSlice = pcPic->getSlice(uiStartCUAddrSliceIdx); |
---|
[56] | 908 | |
---|
| 909 | Int processingState = (pcSlice->getSPS()->getUseALF() || pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getScalingListFlag() || pcSlice->getSPS()->getUseDF())?(EXECUTE_INLOOPFILTER):(ENCODE_SLICE); |
---|
| 910 | |
---|
| 911 | static Int iCurrAPSIdx = 0; |
---|
| 912 | Int iCodedAPSIdx = 0; |
---|
| 913 | TComSlice* pcSliceForAPS = NULL; |
---|
| 914 | |
---|
| 915 | bool skippedSlice=false; |
---|
| 916 | while (uiNextCUAddr < uiRealEndAddress) // Iterate over all slices |
---|
[2] | 917 | { |
---|
[56] | 918 | switch(processingState) |
---|
| 919 | { |
---|
| 920 | case ENCODE_SLICE: |
---|
| 921 | { |
---|
[2] | 922 | pcSlice->setNextSlice ( false ); |
---|
| 923 | pcSlice->setNextEntropySlice( false ); |
---|
| 924 | if (uiNextCUAddr == m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx]) |
---|
| 925 | { |
---|
| 926 | pcSlice = pcPic->getSlice(uiStartCUAddrSliceIdx); |
---|
[56] | 927 | #if COLLOCATED_REF_IDX |
---|
| 928 | if(uiStartCUAddrSliceIdx > 0 && pcSlice->getSliceType()!= I_SLICE) |
---|
| 929 | { |
---|
| 930 | pcSlice->checkColRefIdx(uiStartCUAddrSliceIdx, pcPic); |
---|
| 931 | } |
---|
| 932 | #endif |
---|
[2] | 933 | pcPic->setCurrSliceIdx(uiStartCUAddrSliceIdx); |
---|
| 934 | m_pcSliceEncoder->setSliceIdx(uiStartCUAddrSliceIdx); |
---|
| 935 | assert(uiStartCUAddrSliceIdx == pcSlice->getSliceIdx()); |
---|
| 936 | // Reconstruction slice |
---|
| 937 | pcSlice->setSliceCurStartCUAddr( uiNextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 938 | pcSlice->setSliceCurEndCUAddr ( m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx+1 ] ); |
---|
| 939 | // Entropy slice |
---|
| 940 | pcSlice->setEntropySliceCurStartCUAddr( uiNextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 941 | pcSlice->setEntropySliceCurEndCUAddr ( m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx+1 ] ); |
---|
| 942 | |
---|
| 943 | pcSlice->setNextSlice ( true ); |
---|
| 944 | |
---|
| 945 | uiStartCUAddrSliceIdx++; |
---|
| 946 | uiStartCUAddrEntropySliceIdx++; |
---|
[56] | 947 | } |
---|
[2] | 948 | else if (uiNextCUAddr == m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx]) |
---|
| 949 | { |
---|
| 950 | // Entropy slice |
---|
| 951 | pcSlice->setEntropySliceCurStartCUAddr( uiNextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 952 | pcSlice->setEntropySliceCurEndCUAddr ( m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx+1 ] ); |
---|
| 953 | |
---|
| 954 | pcSlice->setNextEntropySlice( true ); |
---|
| 955 | |
---|
| 956 | uiStartCUAddrEntropySliceIdx++; |
---|
| 957 | } |
---|
| 958 | |
---|
[56] | 959 | pcSlice->setRPS(pcPic->getSlice(0)->getRPS()); |
---|
| 960 | pcSlice->setRPSidx(pcPic->getSlice(0)->getRPSidx()); |
---|
| 961 | UInt uiDummyStartCUAddr; |
---|
| 962 | UInt uiDummyBoundingCUAddr; |
---|
| 963 | m_pcSliceEncoder->xDetermineStartAndBoundingCUAddr(uiDummyStartCUAddr,uiDummyBoundingCUAddr,pcPic,true); |
---|
| 964 | |
---|
| 965 | uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
| 966 | uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
| 967 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 968 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 969 | uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 970 | uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
| 971 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
[2] | 972 | { |
---|
[56] | 973 | uiInternalAddress--; |
---|
| 974 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 975 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
[2] | 976 | } |
---|
[56] | 977 | uiInternalAddress++; |
---|
| 978 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
| 979 | { |
---|
| 980 | uiInternalAddress = 0; |
---|
| 981 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
| 982 | } |
---|
| 983 | UInt uiEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
| 984 | if(uiEndAddress<=pcSlice->getEntropySliceCurStartCUAddr()) { |
---|
| 985 | UInt uiBoundingAddrSlice, uiBoundingAddrEntropySlice; |
---|
| 986 | uiBoundingAddrSlice = m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx]; |
---|
| 987 | uiBoundingAddrEntropySlice = m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx]; |
---|
| 988 | uiNextCUAddr = min(uiBoundingAddrSlice, uiBoundingAddrEntropySlice); |
---|
| 989 | if(pcSlice->isNextSlice()) |
---|
| 990 | { |
---|
| 991 | skippedSlice=true; |
---|
| 992 | } |
---|
| 993 | continue; |
---|
| 994 | } |
---|
| 995 | if(skippedSlice) |
---|
| 996 | { |
---|
| 997 | pcSlice->setNextSlice ( true ); |
---|
| 998 | pcSlice->setNextEntropySlice( false ); |
---|
| 999 | } |
---|
| 1000 | skippedSlice=false; |
---|
| 1001 | if (pcSlice->getPPS()->getEntropyCodingMode()) |
---|
| 1002 | { |
---|
| 1003 | pcSlice->allocSubstreamSizes( iNumSubstreams ); |
---|
| 1004 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
| 1005 | pcSubstreamsOut[ui].clear(); |
---|
| 1006 | } |
---|
[2] | 1007 | |
---|
[56] | 1008 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 1009 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1010 | /* start slice NALunit */ |
---|
[77] | 1011 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced(), |
---|
[210] | 1012 | #if !VIDYO_VPS_INTEGRATION &!QC_MVHEVC_B0046 |
---|
[77] | 1013 | m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() ); |
---|
[56] | 1014 | #else |
---|
[77] | 1015 | m_pcEncTop->getLayerId(), pcSlice->getTLayer() ); |
---|
[56] | 1016 | #endif |
---|
[77] | 1017 | |
---|
[56] | 1018 | Bool bEntropySlice = (!pcSlice->isNextSlice()); |
---|
| 1019 | if (!bEntropySlice) |
---|
| 1020 | { |
---|
| 1021 | uiOneBitstreamPerSliceLength = 0; // start of a new slice |
---|
| 1022 | } |
---|
[5] | 1023 | |
---|
[56] | 1024 | // used while writing slice header |
---|
| 1025 | Int iTransmitLWHeader = (m_pcCfg->getTileMarkerFlag()==0) ? 0 : 1; |
---|
| 1026 | pcSlice->setTileMarkerFlag ( iTransmitLWHeader ); |
---|
| 1027 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1028 | #if !CABAC_INIT_FLAG |
---|
| 1029 | pcSlice->setCABACinitIDC(pcSlice->getSliceType()); |
---|
| 1030 | #endif |
---|
[5] | 1031 | |
---|
[56] | 1032 | m_pcEntropyCoder->encodeSliceHeader(pcSlice); |
---|
| 1033 | |
---|
| 1034 | if(pcSlice->isNextSlice()) |
---|
[2] | 1035 | { |
---|
[56] | 1036 | if (pcSlice->getSPS()->getUseALF()) |
---|
| 1037 | { |
---|
| 1038 | if(pcSlice->getAlfEnabledFlag()) |
---|
| 1039 | { |
---|
| 1040 | |
---|
| 1041 | if( pcSlice->getSPS()->getUseALFCoefInSlice()) |
---|
| 1042 | { |
---|
| 1043 | Int iNumSUinLCU = 1<< (g_uiMaxCUDepth << 1); |
---|
| 1044 | Int firstLCUAddr = pcSlice->getSliceCurStartCUAddr() / iNumSUinLCU; |
---|
| 1045 | Bool isAcrossSlice = pcSlice->getSPS()->getLFCrossSliceBoundaryFlag(); |
---|
| 1046 | m_pcEntropyCoder->encodeAlfParam( &(alfSliceParams[pcSlice->getSliceIdx()]), false, firstLCUAddr, isAcrossSlice); |
---|
| 1047 | } |
---|
| 1048 | |
---|
| 1049 | if( !pcSlice->getSPS()->getUseALFCoefInSlice()) |
---|
| 1050 | { |
---|
| 1051 | AlfCUCtrlInfo& cAlfCUCtrlParam = (*alfCUCtrlParam)[pcSlice->getSliceIdx()]; |
---|
| 1052 | if(cAlfCUCtrlParam.cu_control_flag) |
---|
| 1053 | { |
---|
| 1054 | m_pcEntropyCoder->setAlfCtrl( true ); |
---|
| 1055 | m_pcEntropyCoder->setMaxAlfCtrlDepth(cAlfCUCtrlParam.alf_max_depth); |
---|
| 1056 | m_pcCavlcCoder->setAlfCtrl(true); |
---|
| 1057 | m_pcCavlcCoder->setMaxAlfCtrlDepth(cAlfCUCtrlParam.alf_max_depth); |
---|
| 1058 | } |
---|
| 1059 | else |
---|
| 1060 | { |
---|
| 1061 | m_pcEntropyCoder->setAlfCtrl(false); |
---|
| 1062 | } |
---|
| 1063 | m_pcEntropyCoder->encodeAlfCtrlParam(cAlfCUCtrlParam, m_pcAdaptiveLoopFilter->getNumCUsInPic()); |
---|
| 1064 | |
---|
| 1065 | } |
---|
| 1066 | } |
---|
| 1067 | } |
---|
| 1068 | } |
---|
| 1069 | m_pcEntropyCoder->encodeTileMarkerFlag(pcSlice); |
---|
[5] | 1070 | |
---|
[56] | 1071 | // is it needed? |
---|
| 1072 | { |
---|
| 1073 | if (!bEntropySlice) |
---|
| 1074 | { |
---|
| 1075 | pcBitstreamRedirect->writeAlignOne(); |
---|
| 1076 | } |
---|
| 1077 | else |
---|
| 1078 | { |
---|
| 1079 | // We've not completed our slice header info yet, do the alignment later. |
---|
| 1080 | } |
---|
| 1081 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
| 1082 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
| 1083 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1084 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
| 1085 | { |
---|
| 1086 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 1087 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1088 | } |
---|
| 1089 | } |
---|
| 1090 | |
---|
| 1091 | if(pcSlice->isNextSlice()) |
---|
| 1092 | { |
---|
| 1093 | // set entropy coder for writing |
---|
| 1094 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
| 1095 | { |
---|
| 1096 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
[2] | 1097 | { |
---|
[56] | 1098 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 1099 | m_pcEntropyCoder->resetEntropy (); |
---|
[2] | 1100 | } |
---|
[56] | 1101 | pcSbacCoders[0].load(m_pcSbacCoder); |
---|
| 1102 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[0], pcSlice ); //ALF is written in substream #0 with CABAC coder #0 (see ALF param encoding below) |
---|
| 1103 | } |
---|
| 1104 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1105 | // File writing |
---|
| 1106 | if (!bEntropySlice) |
---|
| 1107 | { |
---|
| 1108 | m_pcEntropyCoder->setBitstream(pcBitstreamRedirect); |
---|
| 1109 | } |
---|
| 1110 | else |
---|
| 1111 | { |
---|
| 1112 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1113 | } |
---|
| 1114 | // for now, override the TILES_DECODER setting in order to write substreams. |
---|
| 1115 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[0] ); |
---|
[5] | 1116 | |
---|
[56] | 1117 | } |
---|
| 1118 | pcSlice->setFinalized(true); |
---|
| 1119 | |
---|
| 1120 | m_pcSbacCoder->load( &pcSbacCoders[0] ); |
---|
| 1121 | |
---|
| 1122 | pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength ); |
---|
| 1123 | if (!bEntropySlice) |
---|
| 1124 | { |
---|
| 1125 | pcSlice->setTileLocationCount ( 0 ); |
---|
| 1126 | m_pcSliceEncoder->encodeSlice(pcPic, pcBitstreamRedirect, pcSubstreamsOut); // redirect is only used for CAVLC tile position info. |
---|
| 1127 | } |
---|
| 1128 | else |
---|
| 1129 | { |
---|
| 1130 | m_pcSliceEncoder->encodeSlice(pcPic, &nalu.m_Bitstream, pcSubstreamsOut); // nalu.m_Bitstream is only used for CAVLC tile position info. |
---|
| 1131 | } |
---|
| 1132 | |
---|
| 1133 | { |
---|
| 1134 | // Construct the final bitstream by flushing and concatenating substreams. |
---|
| 1135 | // The final bitstream is either nalu.m_Bitstream or pcBitstreamRedirect; |
---|
| 1136 | UInt* puiSubstreamSizes = pcSlice->getSubstreamSizes(); |
---|
| 1137 | UInt uiTotalCodedSize = 0; // for padding calcs. |
---|
| 1138 | UInt uiNumSubstreamsPerTile = iNumSubstreams; |
---|
| 1139 | if (iNumSubstreams > 1) |
---|
| 1140 | { |
---|
| 1141 | uiNumSubstreamsPerTile /= pcPic->getPicSym()->getNumTiles(); |
---|
| 1142 | } |
---|
| 1143 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
| 1144 | { |
---|
| 1145 | // Flush all substreams -- this includes empty ones. |
---|
| 1146 | // Terminating bit and flush. |
---|
| 1147 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 1148 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[ui] ); |
---|
| 1149 | m_pcEntropyCoder->encodeTerminatingBit( 1 ); |
---|
| 1150 | m_pcEntropyCoder->encodeSliceFinish(); |
---|
| 1151 | pcSubstreamsOut[ui].write( 1, 1 ); // stop bit. |
---|
| 1152 | pcSubstreamsOut[ui].writeAlignZero(); |
---|
| 1153 | // Byte alignment is necessary between tiles when tiles are independent. |
---|
| 1154 | uiTotalCodedSize += pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
| 1155 | |
---|
[2] | 1156 | { |
---|
[56] | 1157 | Bool bNextSubstreamInNewTile = ((ui+1) < iNumSubstreams) |
---|
| 1158 | && ((ui+1)%uiNumSubstreamsPerTile == 0); |
---|
| 1159 | if (bNextSubstreamInNewTile) |
---|
[2] | 1160 | { |
---|
[56] | 1161 | // byte align. |
---|
| 1162 | while (uiTotalCodedSize&0x7) |
---|
| 1163 | { |
---|
| 1164 | pcSubstreamsOut[ui].write(0, 1); |
---|
| 1165 | uiTotalCodedSize++; |
---|
| 1166 | } |
---|
[2] | 1167 | } |
---|
[56] | 1168 | Bool bRecordOffsetNext = m_pcCfg->getTileLocationInSliceHeaderFlag() |
---|
| 1169 | && bNextSubstreamInNewTile; |
---|
| 1170 | if (bRecordOffsetNext) |
---|
| 1171 | pcSlice->setTileLocation(ui/uiNumSubstreamsPerTile, pcSlice->getTileOffstForMultES()+(uiTotalCodedSize>>3)); |
---|
[2] | 1172 | } |
---|
[56] | 1173 | if (ui+1 < pcSlice->getPPS()->getNumSubstreams()) |
---|
| 1174 | puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
| 1175 | } |
---|
| 1176 | // Complete the slice header info. |
---|
| 1177 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 1178 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1179 | if (m_pcCfg->getTileLocationInSliceHeaderFlag()==0) |
---|
| 1180 | { |
---|
| 1181 | pcSlice->setTileLocationCount( 0 ); |
---|
| 1182 | } |
---|
| 1183 | m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice ); |
---|
| 1184 | // Substreams... |
---|
| 1185 | TComOutputBitstream *pcOut = pcBitstreamRedirect; |
---|
| 1186 | // xWriteTileLocation will perform byte-alignment... |
---|
| 1187 | { |
---|
| 1188 | if (bEntropySlice) |
---|
| 1189 | { |
---|
| 1190 | // In these cases, padding is necessary here. |
---|
| 1191 | pcOut = &nalu.m_Bitstream; |
---|
| 1192 | pcOut->writeAlignOne(); |
---|
| 1193 | } |
---|
| 1194 | } |
---|
| 1195 | UInt uiAccumulatedLength = 0; |
---|
| 1196 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams(); ui++ ) |
---|
| 1197 | { |
---|
| 1198 | pcOut->addSubstream(&pcSubstreamsOut[ui]); |
---|
[5] | 1199 | |
---|
[56] | 1200 | // Update tile marker location information |
---|
| 1201 | for (Int uiMrkIdx = 0; uiMrkIdx < pcSubstreamsOut[ui].getTileMarkerLocationCount(); uiMrkIdx++) |
---|
| 1202 | { |
---|
| 1203 | UInt uiBottom = pcOut->getTileMarkerLocationCount(); |
---|
| 1204 | pcOut->setTileMarkerLocation ( uiBottom, uiAccumulatedLength + pcSubstreamsOut[ui].getTileMarkerLocation( uiMrkIdx ) ); |
---|
| 1205 | pcOut->setTileMarkerLocationCount ( uiBottom + 1 ); |
---|
| 1206 | } |
---|
| 1207 | uiAccumulatedLength = (pcOut->getNumberOfWrittenBits() >> 3); |
---|
| 1208 | } |
---|
| 1209 | } |
---|
| 1210 | |
---|
| 1211 | UInt uiBoundingAddrSlice, uiBoundingAddrEntropySlice; |
---|
| 1212 | uiBoundingAddrSlice = m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx]; |
---|
| 1213 | uiBoundingAddrEntropySlice = m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx]; |
---|
| 1214 | uiNextCUAddr = min(uiBoundingAddrSlice, uiBoundingAddrEntropySlice); |
---|
| 1215 | // If current NALU is the first NALU of slice (containing slice header) and more NALUs exist (due to multiple entropy slices) then buffer it. |
---|
| 1216 | // If current NALU is the last NALU of slice and a NALU was buffered, then (a) Write current NALU (b) Update an write buffered NALU at approproate location in NALU list. |
---|
| 1217 | Bool bNALUAlignedWrittenToList = false; // used to ensure current NALU is not written more than once to the NALU list. |
---|
| 1218 | xWriteTileLocationToSliceHeader(nalu, pcBitstreamRedirect, pcSlice); |
---|
| 1219 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1220 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1221 | bNALUAlignedWrittenToList = true; |
---|
| 1222 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment |
---|
| 1223 | |
---|
| 1224 | if (!bNALUAlignedWrittenToList) |
---|
| 1225 | { |
---|
| 1226 | { |
---|
| 1227 | nalu.m_Bitstream.writeAlignZero(); |
---|
| 1228 | } |
---|
| 1229 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1230 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits() + 24; // length of bitstream after byte-alignment + 3 byte startcode 0x000001 |
---|
| 1231 | } |
---|
| 1232 | |
---|
| 1233 | |
---|
| 1234 | processingState = ENCODE_SLICE; |
---|
| 1235 | } |
---|
| 1236 | break; |
---|
| 1237 | case EXECUTE_INLOOPFILTER: |
---|
| 1238 | { |
---|
| 1239 | TComAPS cAPS; |
---|
| 1240 | allocAPS(&cAPS, pcSlice->getSPS()); |
---|
| 1241 | cAPS.setSaoInterleavingFlag(m_pcCfg->getSaoInterleavingFlag()); |
---|
| 1242 | // set entropy coder for RD |
---|
| 1243 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 1244 | |
---|
| 1245 | if ( pcSlice->getSPS()->getUseSAO() ) |
---|
[2] | 1246 | { |
---|
[56] | 1247 | m_pcEntropyCoder->resetEntropy(); |
---|
| 1248 | m_pcEntropyCoder->setBitstream( m_pcBitCounter ); |
---|
| 1249 | m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), NULL); |
---|
| 1250 | SAOParam& cSaoParam = *(cAPS.getSaoParam()); |
---|
| 1251 | |
---|
| 1252 | #if SAO_CHROMA_LAMBDA |
---|
| 1253 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); |
---|
| 1254 | #else |
---|
| 1255 | #if ALF_CHROMA_LAMBDA |
---|
| 1256 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma()); |
---|
| 1257 | #else |
---|
| 1258 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda()); |
---|
| 1259 | #endif |
---|
| 1260 | #endif |
---|
| 1261 | m_pcSAO->endSaoEnc(); |
---|
| 1262 | |
---|
| 1263 | m_pcAdaptiveLoopFilter->PCMLFDisableProcess(pcPic); |
---|
[2] | 1264 | } |
---|
[56] | 1265 | |
---|
| 1266 | // adaptive loop filter |
---|
| 1267 | if ( pcSlice->getSPS()->getUseALF()) |
---|
| 1268 | { |
---|
| 1269 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1270 | m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); |
---|
| 1271 | m_pcAdaptiveLoopFilter->startALFEnc(pcPic, m_pcEntropyCoder ); |
---|
| 1272 | AlfParamSet* pAlfEncParam = (pcSlice->getSPS()->getUseALFCoefInSlice())?( alfSliceParams ):( cAPS.getAlfParam()); |
---|
| 1273 | #if ALF_CHROMA_LAMBDA |
---|
| 1274 | #if HHI_INTERVIEW_SKIP |
---|
| 1275 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), m_pcEncTop->getInterViewSkip() ); |
---|
| 1276 | #else |
---|
| 1277 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma() ); |
---|
| 1278 | #endif |
---|
| 1279 | #else |
---|
| 1280 | #if SAO_CHROMA_LAMBDA |
---|
| 1281 | #if HHI_INTERVIEW_SKIP |
---|
| 1282 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), m_pcEncTop->getInterViewSkip()); |
---|
| 1283 | #else |
---|
| 1284 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma()); |
---|
| 1285 | #endif |
---|
| 1286 | #else |
---|
| 1287 | #if HHI_INTERVIEW_SKIP |
---|
| 1288 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambda(), m_pcEncTop->getInterViewSkip() ); |
---|
| 1289 | #else |
---|
| 1290 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambda()); |
---|
| 1291 | #endif |
---|
| 1292 | #endif |
---|
| 1293 | #endif |
---|
[5] | 1294 | |
---|
[56] | 1295 | m_pcAdaptiveLoopFilter->endALFEnc(); |
---|
| 1296 | |
---|
| 1297 | m_pcAdaptiveLoopFilter->PCMLFDisableProcess(pcPic); |
---|
| 1298 | } |
---|
| 1299 | iCodedAPSIdx = iCurrAPSIdx; |
---|
| 1300 | pcSliceForAPS = pcSlice; |
---|
| 1301 | |
---|
| 1302 | assignNewAPS(cAPS, iCodedAPSIdx, vAPS, pcSliceForAPS); |
---|
| 1303 | iCurrAPSIdx = (iCurrAPSIdx +1)%MAX_NUM_SUPPORTED_APS; |
---|
| 1304 | processingState = ENCODE_APS; |
---|
| 1305 | |
---|
| 1306 | //set APS link to the slices |
---|
| 1307 | for(Int s=0; s< uiNumSlices; s++) |
---|
[2] | 1308 | { |
---|
[56] | 1309 | if (pcSlice->getSPS()->getUseALF()) |
---|
| 1310 | { |
---|
| 1311 | pcPic->getSlice(s)->setAlfEnabledFlag( (pcSlice->getSPS()->getUseALFCoefInSlice())?(alfSliceParams[s].isEnabled[ALF_Y]):(cAPS.getAlfEnabled()) ); |
---|
| 1312 | } |
---|
| 1313 | if (pcSlice->getSPS()->getUseSAO()) |
---|
| 1314 | { |
---|
| 1315 | pcPic->getSlice(s)->setSaoEnabledFlag((cAPS.getSaoParam()->bSaoFlag[0]==1)?true:false); |
---|
| 1316 | } |
---|
| 1317 | pcPic->getSlice(s)->setAPS(&(vAPS[iCodedAPSIdx])); |
---|
| 1318 | pcPic->getSlice(s)->setAPSId(iCodedAPSIdx); |
---|
[2] | 1319 | } |
---|
[56] | 1320 | } |
---|
| 1321 | break; |
---|
| 1322 | case ENCODE_APS: |
---|
| 1323 | { |
---|
[210] | 1324 | #if VIDYO_VPS_INTEGRATION | QC_MVHEVC_B0046 |
---|
[77] | 1325 | OutputNALUnit nalu(NAL_UNIT_APS, true, m_pcEncTop->getLayerId()); |
---|
| 1326 | #else |
---|
[56] | 1327 | OutputNALUnit nalu(NAL_UNIT_APS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[77] | 1328 | #endif |
---|
[56] | 1329 | encodeAPS(&(vAPS[iCodedAPSIdx]), nalu.m_Bitstream, pcSliceForAPS); |
---|
| 1330 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1331 | |
---|
| 1332 | processingState = ENCODE_SLICE; |
---|
[2] | 1333 | } |
---|
[56] | 1334 | break; |
---|
| 1335 | default: |
---|
| 1336 | { |
---|
| 1337 | printf("Not a supported encoding state\n"); |
---|
| 1338 | assert(0); |
---|
| 1339 | exit(-1); |
---|
| 1340 | } |
---|
[2] | 1341 | } |
---|
[56] | 1342 | } // end iteration over slices |
---|
[5] | 1343 | |
---|
| 1344 | |
---|
[56] | 1345 | if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()) |
---|
| 1346 | { |
---|
| 1347 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 1348 | { |
---|
| 1349 | m_pcSAO->destroyPicSaoInfo(); |
---|
| 1350 | } |
---|
[5] | 1351 | |
---|
[56] | 1352 | if(pcSlice->getSPS()->getUseALF()) |
---|
[2] | 1353 | { |
---|
[56] | 1354 | m_pcAdaptiveLoopFilter->uninitALFEnc(alfSliceParams, alfCUCtrlParam); |
---|
| 1355 | m_pcAdaptiveLoopFilter->destroyPicAlfInfo(); |
---|
[2] | 1356 | } |
---|
[5] | 1357 | |
---|
[56] | 1358 | pcPic->destroyNonDBFilterInfo(); |
---|
| 1359 | } |
---|
[5] | 1360 | |
---|
[56] | 1361 | #if HHI_INTERVIEW_SKIP |
---|
| 1362 | if (pcPic->getUsedPelsMap()) |
---|
| 1363 | pcPic->removeUsedPelsMapBuffer() ; |
---|
[5] | 1364 | #endif |
---|
[292] | 1365 | #if H3D_IVMP |
---|
[56] | 1366 | pcPic->removeOrgDepthMapBuffer(); |
---|
| 1367 | #endif |
---|
| 1368 | |
---|
| 1369 | // pcPic->compressMotion(); |
---|
| 1370 | m_pocLastCoded = pcPic->getPOC(); |
---|
| 1371 | |
---|
[2] | 1372 | //-- For time output for each slice |
---|
| 1373 | Double dEncTime = (double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
[5] | 1374 | |
---|
[56] | 1375 | const char* digestStr = NULL; |
---|
| 1376 | if (m_pcCfg->getPictureDigestEnabled()) |
---|
| 1377 | { |
---|
[2] | 1378 | /* calculate MD5sum for entire reconstructed picture */ |
---|
| 1379 | SEIpictureDigest sei_recon_picture_digest; |
---|
| 1380 | sei_recon_picture_digest.method = SEIpictureDigest::MD5; |
---|
| 1381 | calcMD5(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
[56] | 1382 | digestStr = digestToString(sei_recon_picture_digest.digest); |
---|
[2] | 1383 | |
---|
[210] | 1384 | #if VIDYO_VPS_INTEGRATION | QC_MVHEVC_B0046 |
---|
[77] | 1385 | OutputNALUnit nalu(NAL_UNIT_SEI, false, m_pcEncTop->getLayerId()); |
---|
| 1386 | #else |
---|
[56] | 1387 | OutputNALUnit nalu(NAL_UNIT_SEI, false, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[77] | 1388 | #endif |
---|
[56] | 1389 | |
---|
[2] | 1390 | /* write the SEI messages */ |
---|
| 1391 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
[56] | 1392 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
[2] | 1393 | m_pcEntropyCoder->encodeSEI(sei_recon_picture_digest); |
---|
[56] | 1394 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
[2] | 1395 | |
---|
[56] | 1396 | /* insert the SEI message NALUnit before any Slice NALUnits */ |
---|
| 1397 | AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); |
---|
| 1398 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
[2] | 1399 | } |
---|
| 1400 | |
---|
[56] | 1401 | xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime ); |
---|
| 1402 | if (digestStr) |
---|
| 1403 | printf(" [MD5:%s]", digestStr); |
---|
[2] | 1404 | |
---|
[56] | 1405 | #if FIXED_ROUNDING_FRAME_MEMORY |
---|
| 1406 | /* TODO: this should happen after copyToPic(pcPicYuvRecOut) */ |
---|
| 1407 | pcPic->getPicYuvRec()->xFixedRoundingPic(); |
---|
| 1408 | #endif |
---|
[2] | 1409 | pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut); |
---|
[56] | 1410 | |
---|
[2] | 1411 | pcPic->setReconMark ( true ); |
---|
[5] | 1412 | |
---|
[56] | 1413 | pcPic->setUsedForTMVP ( true ); |
---|
| 1414 | |
---|
| 1415 | m_bFirst = false; |
---|
| 1416 | m_iNumPicCoded++; |
---|
| 1417 | |
---|
| 1418 | /* logging: insert a newline at end of picture period */ |
---|
| 1419 | printf("\n"); |
---|
| 1420 | fflush(stdout); |
---|
| 1421 | } |
---|
| 1422 | |
---|
| 1423 | delete[] pcSubstreamsOut; |
---|
| 1424 | delete pcBitstreamRedirect; |
---|
| 1425 | |
---|
[2] | 1426 | } |
---|
| 1427 | |
---|
[56] | 1428 | /** Memory allocation for APS |
---|
| 1429 | * \param [out] pAPS APS pointer |
---|
| 1430 | * \param [in] pSPS SPS pointer |
---|
| 1431 | */ |
---|
| 1432 | Void TEncGOP::allocAPS (TComAPS* pAPS, TComSPS* pSPS) |
---|
[2] | 1433 | { |
---|
[56] | 1434 | if(pSPS->getUseSAO()) |
---|
| 1435 | { |
---|
| 1436 | pAPS->createSaoParam(); |
---|
| 1437 | m_pcSAO->allocSaoParam(pAPS->getSaoParam()); |
---|
| 1438 | } |
---|
| 1439 | if(pSPS->getUseALF()) |
---|
| 1440 | { |
---|
| 1441 | pAPS->createAlfParam(); |
---|
| 1442 | //alf Enabled flag in APS is false after pAPS->createAlfParam(); |
---|
| 1443 | if(!pSPS->getUseALFCoefInSlice()) |
---|
| 1444 | { |
---|
| 1445 | pAPS->getAlfParam()->create(m_pcAdaptiveLoopFilter->getNumLCUInPicWidth(), m_pcAdaptiveLoopFilter->getNumLCUInPicHeight(), m_pcAdaptiveLoopFilter->getNumCUsInPic()); |
---|
| 1446 | pAPS->getAlfParam()->createALFParam(); |
---|
| 1447 | } |
---|
| 1448 | } |
---|
| 1449 | } |
---|
| 1450 | |
---|
| 1451 | /** Memory deallocation for APS |
---|
| 1452 | * \param [out] pAPS APS pointer |
---|
| 1453 | * \param [in] pSPS SPS pointer |
---|
| 1454 | */ |
---|
| 1455 | Void TEncGOP::freeAPS (TComAPS* pAPS, TComSPS* pSPS) |
---|
| 1456 | { |
---|
| 1457 | if(pSPS->getUseSAO()) |
---|
| 1458 | { |
---|
| 1459 | if(pAPS->getSaoParam() != NULL) |
---|
| 1460 | { |
---|
| 1461 | m_pcSAO->freeSaoParam(pAPS->getSaoParam()); |
---|
| 1462 | pAPS->destroySaoParam(); |
---|
| 1463 | |
---|
| 1464 | } |
---|
| 1465 | } |
---|
| 1466 | if(pSPS->getUseALF()) |
---|
| 1467 | { |
---|
| 1468 | if(pAPS->getAlfParam() != NULL) |
---|
| 1469 | { |
---|
| 1470 | if(!pSPS->getUseALFCoefInSlice()) |
---|
| 1471 | { |
---|
| 1472 | pAPS->getAlfParam()->releaseALFParam(); |
---|
| 1473 | } |
---|
| 1474 | pAPS->destroyAlfParam(); |
---|
| 1475 | } |
---|
| 1476 | } |
---|
| 1477 | } |
---|
| 1478 | |
---|
| 1479 | /** Assign APS object into APS container according to APS ID |
---|
| 1480 | * \param [in] cAPS APS object |
---|
| 1481 | * \param [in] apsID APS ID |
---|
| 1482 | * \param [in,out] vAPS APS container |
---|
| 1483 | * \param [in] pcSlice pointer to slice |
---|
| 1484 | */ |
---|
| 1485 | Void TEncGOP::assignNewAPS(TComAPS& cAPS, Int apsID, std::vector<TComAPS>& vAPS, TComSlice* pcSlice) |
---|
| 1486 | { |
---|
| 1487 | |
---|
| 1488 | cAPS.setAPSID(apsID); |
---|
| 1489 | if(pcSlice->getPOC() == 0) |
---|
| 1490 | { |
---|
| 1491 | cAPS.setScalingListEnabled(pcSlice->getSPS()->getScalingListFlag()); |
---|
| 1492 | } |
---|
| 1493 | else |
---|
| 1494 | { |
---|
| 1495 | cAPS.setScalingListEnabled(false); |
---|
| 1496 | } |
---|
| 1497 | |
---|
| 1498 | cAPS.setSaoEnabled(pcSlice->getSPS()->getUseSAO() ? (cAPS.getSaoParam()->bSaoFlag[0] ):(false)); |
---|
| 1499 | cAPS.setAlfEnabled(pcSlice->getSPS()->getUseALF() ? (cAPS.getAlfParam()->isEnabled[0]):(false)); |
---|
| 1500 | cAPS.setLoopFilterOffsetInAPS(m_pcCfg->getLoopFilterOffsetInAPS()); |
---|
| 1501 | cAPS.setLoopFilterDisable(m_pcCfg->getLoopFilterDisable()); |
---|
| 1502 | cAPS.setLoopFilterBetaOffset(m_pcCfg->getLoopFilterBetaOffset()); |
---|
| 1503 | cAPS.setLoopFilterTcOffset(m_pcCfg->getLoopFilterTcOffset()); |
---|
| 1504 | |
---|
| 1505 | //assign new APS into APS container |
---|
| 1506 | Int apsBufSize= (Int)vAPS.size(); |
---|
| 1507 | |
---|
| 1508 | if(apsID >= apsBufSize) |
---|
| 1509 | { |
---|
| 1510 | vAPS.resize(apsID +1); |
---|
| 1511 | } |
---|
| 1512 | |
---|
| 1513 | freeAPS(&(vAPS[apsID]), pcSlice->getSPS()); |
---|
| 1514 | vAPS[apsID] = cAPS; |
---|
| 1515 | } |
---|
| 1516 | |
---|
| 1517 | |
---|
| 1518 | /** encode APS syntax elements |
---|
| 1519 | * \param [in] pcAPS APS pointer |
---|
| 1520 | * \param [in, out] APSbs bitstream |
---|
| 1521 | * \param [in] pointer to slice (just used for entropy coder initialization) |
---|
| 1522 | */ |
---|
| 1523 | Void TEncGOP::encodeAPS(TComAPS* pcAPS, TComOutputBitstream& APSbs, TComSlice* pcSlice) |
---|
| 1524 | { |
---|
| 1525 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice); |
---|
| 1526 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1527 | m_pcEntropyCoder->setBitstream(&APSbs); |
---|
| 1528 | |
---|
| 1529 | m_pcEntropyCoder->encodeAPSInitInfo(pcAPS); |
---|
| 1530 | if(pcAPS->getScalingListEnabled()) |
---|
| 1531 | { |
---|
| 1532 | m_pcEntropyCoder->encodeScalingList( pcSlice->getScalingList() ); |
---|
| 1533 | } |
---|
| 1534 | if(pcAPS->getLoopFilterOffsetInAPS()) |
---|
| 1535 | { |
---|
| 1536 | m_pcEntropyCoder->encodeDFParams(pcAPS); |
---|
| 1537 | } |
---|
| 1538 | m_pcEntropyCoder->encodeSaoParam(pcAPS); |
---|
| 1539 | m_pcEntropyCoder->encodeAPSAlfFlag( pcAPS->getAlfEnabled()?1:0); |
---|
| 1540 | if(pcAPS->getAlfEnabled()) |
---|
| 1541 | { |
---|
| 1542 | m_pcEntropyCoder->encodeAlfParam(pcAPS->getAlfParam()); |
---|
| 1543 | } |
---|
| 1544 | |
---|
| 1545 | m_pcEntropyCoder->encodeApsExtensionFlag(); |
---|
| 1546 | //neither SAO and ALF is enabled |
---|
| 1547 | writeRBSPTrailingBits(APSbs); |
---|
| 1548 | } |
---|
| 1549 | |
---|
| 1550 | Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits ) |
---|
| 1551 | { |
---|
[2] | 1552 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
| 1553 | Bool bCalcDist = false; |
---|
[56] | 1554 | m_pcLoopFilter->setCfg(pcSlice->getPPS()->getDeblockingFilterControlPresent(), pcSlice->getLoopFilterDisable(), m_pcCfg->getLoopFilterBetaOffset(), m_pcCfg->getLoopFilterTcOffset(), m_pcCfg->getLFCrossTileBoundaryFlag()); |
---|
[2] | 1555 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
[56] | 1556 | |
---|
[2] | 1557 | m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice ); |
---|
| 1558 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1559 | m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); |
---|
[56] | 1560 | pcSlice = pcPic->getSlice(0); |
---|
| 1561 | if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()) |
---|
| 1562 | { |
---|
| 1563 | pcPic->createNonDBFilterInfo(); |
---|
| 1564 | } |
---|
| 1565 | |
---|
[2] | 1566 | // Adaptive Loop filter |
---|
| 1567 | if( pcSlice->getSPS()->getUseALF() ) |
---|
| 1568 | { |
---|
[56] | 1569 | m_pcAdaptiveLoopFilter->createPicAlfInfo(pcPic); |
---|
| 1570 | |
---|
| 1571 | AlfParamSet* alfParamSet; |
---|
| 1572 | std::vector<AlfCUCtrlInfo>* alfCUCtrlParam = NULL; |
---|
| 1573 | alfParamSet= new AlfParamSet; |
---|
| 1574 | alfParamSet->create( m_pcAdaptiveLoopFilter->getNumLCUInPicWidth(), m_pcAdaptiveLoopFilter->getNumLCUInPicHeight(), m_pcAdaptiveLoopFilter->getNumCUsInPic()); |
---|
| 1575 | alfParamSet->createALFParam(); |
---|
| 1576 | m_pcAdaptiveLoopFilter->initALFEnc(false, true, 1, alfParamSet, alfCUCtrlParam); |
---|
[2] | 1577 | m_pcAdaptiveLoopFilter->startALFEnc(pcPic, m_pcEntropyCoder); |
---|
[56] | 1578 | |
---|
[5] | 1579 | |
---|
[56] | 1580 | |
---|
| 1581 | #if ALF_CHROMA_LAMBDA |
---|
| 1582 | #if HHI_INTERVIEW_SKIP |
---|
| 1583 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), m_pcEncTop->getInterViewSkip() ); |
---|
| 1584 | #else |
---|
| 1585 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma() ); |
---|
| 1586 | #endif |
---|
| 1587 | #else |
---|
| 1588 | #if SAO_CHROMA_LAMBDA |
---|
| 1589 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambdaLuma(), m_pcEncTop->getInterViewSkip()); |
---|
| 1590 | #if HHI_INTERVIEW_SKIP |
---|
| 1591 | #else |
---|
| 1592 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambdaLuma()); |
---|
| 1593 | #endif |
---|
| 1594 | #else |
---|
| 1595 | #if HHI_INTERVIEW_SKIP |
---|
| 1596 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambda(), m_pcEncTop->getInterViewSkip()); |
---|
| 1597 | #else |
---|
| 1598 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambda()); |
---|
| 1599 | #endif |
---|
| 1600 | #endif |
---|
| 1601 | #endif |
---|
| 1602 | |
---|
[2] | 1603 | m_pcAdaptiveLoopFilter->endALFEnc(); |
---|
[56] | 1604 | |
---|
| 1605 | alfParamSet->releaseALFParam(); |
---|
| 1606 | delete alfParamSet; |
---|
| 1607 | delete alfCUCtrlParam; |
---|
| 1608 | m_pcAdaptiveLoopFilter->PCMLFDisableProcess(pcPic); |
---|
| 1609 | m_pcAdaptiveLoopFilter->destroyPicAlfInfo(); |
---|
[2] | 1610 | } |
---|
[56] | 1611 | if( pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()) |
---|
| 1612 | { |
---|
| 1613 | pcPic->destroyNonDBFilterInfo(); |
---|
| 1614 | } |
---|
| 1615 | |
---|
[2] | 1616 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1617 | ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[56] | 1618 | |
---|
[2] | 1619 | if (!bCalcDist) |
---|
| 1620 | ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec()); |
---|
| 1621 | } |
---|
| 1622 | |
---|
| 1623 | // ==================================================================================================================== |
---|
| 1624 | // Protected member functions |
---|
| 1625 | // ==================================================================================================================== |
---|
| 1626 | |
---|
[56] | 1627 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ) |
---|
[2] | 1628 | { |
---|
[56] | 1629 | assert( iNumPicRcvd > 0 ); |
---|
| 1630 | // Exception for the first frame |
---|
| 1631 | if ( iPOCLast == 0 ) |
---|
| 1632 | { |
---|
| 1633 | m_iGopSize = 1; |
---|
| 1634 | } |
---|
| 1635 | else |
---|
| 1636 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
| 1637 | |
---|
| 1638 | assert (m_iGopSize > 0); |
---|
| 1639 | |
---|
| 1640 | return; |
---|
| 1641 | } |
---|
| 1642 | |
---|
| 1643 | Void TEncGOP::xGetBuffer( TComList<TComPic*>& rcListPic, |
---|
| 1644 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
| 1645 | Int iNumPicRcvd, |
---|
| 1646 | Int iTimeOffset, |
---|
| 1647 | TComPic*& rpcPic, |
---|
| 1648 | TComPicYuv*& rpcPicYuvRecOut, |
---|
| 1649 | UInt uiPOCCurr ) |
---|
| 1650 | { |
---|
| 1651 | Int i; |
---|
| 1652 | // Rec. output |
---|
| 1653 | TComList<TComPicYuv*>::iterator iterPicYuvRec = rcListPicYuvRecOut.end(); |
---|
| 1654 | for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ ) |
---|
| 1655 | { |
---|
| 1656 | iterPicYuvRec--; |
---|
| 1657 | } |
---|
| 1658 | |
---|
| 1659 | rpcPicYuvRecOut = *(iterPicYuvRec); |
---|
| 1660 | |
---|
| 1661 | // Current pic. |
---|
| 1662 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
| 1663 | while (iterPic != rcListPic.end()) |
---|
| 1664 | { |
---|
| 1665 | rpcPic = *(iterPic); |
---|
| 1666 | rpcPic->setCurrSliceIdx(0); |
---|
| 1667 | if (rpcPic->getPOC() == (Int)uiPOCCurr) |
---|
| 1668 | { |
---|
| 1669 | break; |
---|
| 1670 | } |
---|
| 1671 | iterPic++; |
---|
| 1672 | } |
---|
| 1673 | |
---|
| 1674 | assert (rpcPic->getPOC() == (Int)uiPOCCurr); |
---|
| 1675 | |
---|
| 1676 | return; |
---|
| 1677 | } |
---|
| 1678 | |
---|
| 1679 | UInt64 TEncGOP::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1) |
---|
| 1680 | { |
---|
[2] | 1681 | Int x, y; |
---|
| 1682 | Pel* pSrc0 = pcPic0 ->getLumaAddr(); |
---|
| 1683 | Pel* pSrc1 = pcPic1 ->getLumaAddr(); |
---|
| 1684 | #if IBDI_DISTORTION |
---|
| 1685 | Int iShift = g_uiBitIncrement; |
---|
| 1686 | Int iOffset = 1<<(g_uiBitIncrement-1); |
---|
| 1687 | #else |
---|
| 1688 | UInt uiShift = g_uiBitIncrement<<1; |
---|
| 1689 | #endif |
---|
| 1690 | Int iTemp; |
---|
[56] | 1691 | |
---|
[2] | 1692 | Int iStride = pcPic0->getStride(); |
---|
| 1693 | Int iWidth = pcPic0->getWidth(); |
---|
| 1694 | Int iHeight = pcPic0->getHeight(); |
---|
[56] | 1695 | |
---|
[2] | 1696 | UInt64 uiTotalDiff = 0; |
---|
[56] | 1697 | |
---|
[2] | 1698 | for( y = 0; y < iHeight; y++ ) |
---|
| 1699 | { |
---|
| 1700 | for( x = 0; x < iWidth; x++ ) |
---|
| 1701 | { |
---|
| 1702 | #if IBDI_DISTORTION |
---|
| 1703 | iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp; |
---|
| 1704 | #else |
---|
| 1705 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 1706 | #endif |
---|
| 1707 | } |
---|
| 1708 | pSrc0 += iStride; |
---|
| 1709 | pSrc1 += iStride; |
---|
| 1710 | } |
---|
[56] | 1711 | |
---|
[2] | 1712 | iHeight >>= 1; |
---|
| 1713 | iWidth >>= 1; |
---|
| 1714 | iStride >>= 1; |
---|
[56] | 1715 | |
---|
[2] | 1716 | pSrc0 = pcPic0->getCbAddr(); |
---|
| 1717 | pSrc1 = pcPic1->getCbAddr(); |
---|
[56] | 1718 | |
---|
[2] | 1719 | for( y = 0; y < iHeight; y++ ) |
---|
| 1720 | { |
---|
| 1721 | for( x = 0; x < iWidth; x++ ) |
---|
| 1722 | { |
---|
| 1723 | #if IBDI_DISTORTION |
---|
| 1724 | iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp; |
---|
| 1725 | #else |
---|
| 1726 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 1727 | #endif |
---|
| 1728 | } |
---|
| 1729 | pSrc0 += iStride; |
---|
| 1730 | pSrc1 += iStride; |
---|
| 1731 | } |
---|
[56] | 1732 | |
---|
[2] | 1733 | pSrc0 = pcPic0->getCrAddr(); |
---|
| 1734 | pSrc1 = pcPic1->getCrAddr(); |
---|
[56] | 1735 | |
---|
[2] | 1736 | for( y = 0; y < iHeight; y++ ) |
---|
| 1737 | { |
---|
| 1738 | for( x = 0; x < iWidth; x++ ) |
---|
| 1739 | { |
---|
| 1740 | #if IBDI_DISTORTION |
---|
| 1741 | iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp; |
---|
| 1742 | #else |
---|
| 1743 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 1744 | #endif |
---|
| 1745 | } |
---|
| 1746 | pSrc0 += iStride; |
---|
| 1747 | pSrc1 += iStride; |
---|
| 1748 | } |
---|
[56] | 1749 | |
---|
[2] | 1750 | return uiTotalDiff; |
---|
| 1751 | } |
---|
| 1752 | |
---|
[56] | 1753 | #if VERBOSE_RATE |
---|
| 1754 | static const char* nalUnitTypeToString(NalUnitType type) |
---|
[2] | 1755 | { |
---|
[56] | 1756 | switch (type) |
---|
| 1757 | { |
---|
| 1758 | case NAL_UNIT_CODED_SLICE: return "SLICE"; |
---|
[210] | 1759 | #if !QC_REM_IDV_B0046 |
---|
[56] | 1760 | case NAL_UNIT_CODED_SLICE_IDV: return "IDV"; |
---|
[210] | 1761 | #endif |
---|
[56] | 1762 | case NAL_UNIT_CODED_SLICE_CRA: return "CRA"; |
---|
| 1763 | case NAL_UNIT_CODED_SLICE_TLA: return "TLA"; |
---|
| 1764 | case NAL_UNIT_CODED_SLICE_IDR: return "IDR"; |
---|
| 1765 | case NAL_UNIT_SEI: return "SEI"; |
---|
| 1766 | case NAL_UNIT_SPS: return "SPS"; |
---|
| 1767 | case NAL_UNIT_PPS: return "PPS"; |
---|
| 1768 | case NAL_UNIT_FILLER_DATA: return "FILLER"; |
---|
| 1769 | default: return "UNK"; |
---|
| 1770 | } |
---|
| 1771 | } |
---|
| 1772 | #endif |
---|
| 1773 | |
---|
| 1774 | Void TEncGOP::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit& accessUnit, Double dEncTime ) |
---|
| 1775 | { |
---|
[2] | 1776 | Int x, y; |
---|
| 1777 | UInt64 uiSSDY = 0; |
---|
| 1778 | UInt64 uiSSDU = 0; |
---|
| 1779 | UInt64 uiSSDV = 0; |
---|
[56] | 1780 | |
---|
[2] | 1781 | Double dYPSNR = 0.0; |
---|
| 1782 | Double dUPSNR = 0.0; |
---|
| 1783 | Double dVPSNR = 0.0; |
---|
[56] | 1784 | |
---|
[2] | 1785 | //===== calculate PSNR ===== |
---|
| 1786 | Pel* pOrg = pcPic ->getPicYuvOrg()->getLumaAddr(); |
---|
| 1787 | Pel* pRec = pcPicD->getLumaAddr(); |
---|
| 1788 | Int iStride = pcPicD->getStride(); |
---|
[56] | 1789 | |
---|
[2] | 1790 | Int iWidth; |
---|
| 1791 | Int iHeight; |
---|
[56] | 1792 | |
---|
[2] | 1793 | iWidth = pcPicD->getWidth () - m_pcEncTop->getPad(0); |
---|
| 1794 | iHeight = pcPicD->getHeight() - m_pcEncTop->getPad(1); |
---|
[56] | 1795 | |
---|
[2] | 1796 | Int iSize = iWidth*iHeight; |
---|
[56] | 1797 | |
---|
[2] | 1798 | for( y = 0; y < iHeight; y++ ) |
---|
| 1799 | { |
---|
| 1800 | for( x = 0; x < iWidth; x++ ) |
---|
| 1801 | { |
---|
| 1802 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 1803 | uiSSDY += iDiff * iDiff; |
---|
| 1804 | } |
---|
| 1805 | pOrg += iStride; |
---|
| 1806 | pRec += iStride; |
---|
| 1807 | } |
---|
[56] | 1808 | |
---|
| 1809 | #if HHI_VSO |
---|
[77] | 1810 | #if HHI_VSO_SYNTH_DIST_OUT |
---|
[2] | 1811 | if ( m_pcRdCost->getUseRenModel() ) |
---|
| 1812 | { |
---|
[56] | 1813 | unsigned int maxval = 255 * (1<<(g_uiBitDepth + g_uiBitIncrement -8)); |
---|
| 1814 | Double fRefValueY = (double) maxval * maxval * iSize; |
---|
| 1815 | Double fRefValueC = fRefValueY / 4.0; |
---|
[5] | 1816 | TRenModel* pcRenModel = m_pcEncTop->getEncTop()->getRenModel(); |
---|
| 1817 | Int64 iDistVSOY, iDistVSOU, iDistVSOV; |
---|
| 1818 | pcRenModel->getTotalSSE( iDistVSOY, iDistVSOU, iDistVSOV ); |
---|
[2] | 1819 | dYPSNR = ( iDistVSOY ? 10.0 * log10( fRefValueY / (Double) iDistVSOY ) : 99.99 ); |
---|
| 1820 | dUPSNR = ( iDistVSOU ? 10.0 * log10( fRefValueC / (Double) iDistVSOU ) : 99.99 ); |
---|
| 1821 | dVPSNR = ( iDistVSOV ? 10.0 * log10( fRefValueC / (Double) iDistVSOV ) : 99.99 ); |
---|
| 1822 | } |
---|
| 1823 | else |
---|
[5] | 1824 | #endif |
---|
[77] | 1825 | #endif |
---|
[5] | 1826 | { |
---|
[2] | 1827 | iHeight >>= 1; |
---|
| 1828 | iWidth >>= 1; |
---|
| 1829 | iStride >>= 1; |
---|
| 1830 | pOrg = pcPic ->getPicYuvOrg()->getCbAddr(); |
---|
| 1831 | pRec = pcPicD->getCbAddr(); |
---|
[56] | 1832 | |
---|
[2] | 1833 | for( y = 0; y < iHeight; y++ ) |
---|
| 1834 | { |
---|
| 1835 | for( x = 0; x < iWidth; x++ ) |
---|
| 1836 | { |
---|
| 1837 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 1838 | uiSSDU += iDiff * iDiff; |
---|
| 1839 | } |
---|
| 1840 | pOrg += iStride; |
---|
| 1841 | pRec += iStride; |
---|
| 1842 | } |
---|
[56] | 1843 | |
---|
[2] | 1844 | pOrg = pcPic ->getPicYuvOrg()->getCrAddr(); |
---|
| 1845 | pRec = pcPicD->getCrAddr(); |
---|
[56] | 1846 | |
---|
[2] | 1847 | for( y = 0; y < iHeight; y++ ) |
---|
| 1848 | { |
---|
| 1849 | for( x = 0; x < iWidth; x++ ) |
---|
| 1850 | { |
---|
| 1851 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 1852 | uiSSDV += iDiff * iDiff; |
---|
| 1853 | } |
---|
| 1854 | pOrg += iStride; |
---|
| 1855 | pRec += iStride; |
---|
| 1856 | } |
---|
[56] | 1857 | |
---|
| 1858 | unsigned int maxval = 255 * (1<<(g_uiBitDepth + g_uiBitIncrement -8)); |
---|
| 1859 | Double fRefValueY = (double) maxval * maxval * iSize; |
---|
| 1860 | Double fRefValueC = fRefValueY / 4.0; |
---|
[2] | 1861 | dYPSNR = ( uiSSDY ? 10.0 * log10( fRefValueY / (Double)uiSSDY ) : 99.99 ); |
---|
| 1862 | dUPSNR = ( uiSSDU ? 10.0 * log10( fRefValueC / (Double)uiSSDU ) : 99.99 ); |
---|
| 1863 | dVPSNR = ( uiSSDV ? 10.0 * log10( fRefValueC / (Double)uiSSDV ) : 99.99 ); |
---|
| 1864 | } |
---|
[56] | 1865 | /* calculate the size of the access unit, excluding: |
---|
| 1866 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
| 1867 | * - SEI NAL units |
---|
| 1868 | */ |
---|
| 1869 | unsigned numRBSPBytes = 0; |
---|
| 1870 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
| 1871 | { |
---|
| 1872 | unsigned numRBSPBytes_nal = unsigned((*it)->m_nalUnitData.str().size()); |
---|
| 1873 | #if VERBOSE_RATE |
---|
| 1874 | printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal); |
---|
| 1875 | #endif |
---|
| 1876 | if ((*it)->m_nalUnitType != NAL_UNIT_SEI) |
---|
| 1877 | numRBSPBytes += numRBSPBytes_nal; |
---|
| 1878 | } |
---|
[5] | 1879 | |
---|
[56] | 1880 | unsigned uibits = numRBSPBytes * 8; |
---|
[2] | 1881 | m_vRVM_RP.push_back( uibits ); |
---|
| 1882 | |
---|
| 1883 | //===== add PSNR ===== |
---|
[56] | 1884 | m_pcEncTop->getAnalyzeAll()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
[2] | 1885 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
| 1886 | if (pcSlice->isIntra()) |
---|
| 1887 | { |
---|
[56] | 1888 | m_pcEncTop->getAnalyzeI()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
[2] | 1889 | } |
---|
| 1890 | if (pcSlice->isInterP()) |
---|
| 1891 | { |
---|
[56] | 1892 | m_pcEncTop->getAnalyzeP()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
[2] | 1893 | } |
---|
| 1894 | if (pcSlice->isInterB()) |
---|
| 1895 | { |
---|
[56] | 1896 | m_pcEncTop->getAnalyzeB()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
[2] | 1897 | } |
---|
| 1898 | |
---|
[56] | 1899 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
| 1900 | if (!pcSlice->isReferenced()) c += 32; |
---|
[5] | 1901 | |
---|
[56] | 1902 | #if ADAPTIVE_QP_SELECTION |
---|
| 1903 | printf("%s View %3d POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
| 1904 | pcSlice->getIsDepth() ? "Depth " : "Texture", |
---|
| 1905 | pcSlice->getViewId(), |
---|
| 1906 | pcSlice->getPOC(), |
---|
| 1907 | pcSlice->getTLayer(), |
---|
| 1908 | c, |
---|
| 1909 | pcSlice->getSliceQpBase(), |
---|
| 1910 | pcSlice->getSliceQp(), |
---|
| 1911 | uibits ); |
---|
| 1912 | #else |
---|
| 1913 | printf("%s View %3d POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
| 1914 | pcSlice->getIsDepth() ? "Depth " : "Texture", |
---|
| 1915 | pcSlice->getViewId(), |
---|
| 1916 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
| 1917 | pcSlice->getTLayer(), |
---|
| 1918 | c, |
---|
| 1919 | pcSlice->getSliceQp(), |
---|
| 1920 | uibits ); |
---|
| 1921 | #endif |
---|
| 1922 | |
---|
| 1923 | printf(" [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", dYPSNR, dUPSNR, dVPSNR ); |
---|
| 1924 | printf(" [ET %5.0f ]", dEncTime ); |
---|
| 1925 | |
---|
[2] | 1926 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
| 1927 | { |
---|
[56] | 1928 | printf(" [L%d ", iRefList); |
---|
[2] | 1929 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
| 1930 | { |
---|
[56] | 1931 | if( pcSlice->getViewId() != pcSlice->getRefViewId( RefPicList(iRefList), iRefIndex ) ) |
---|
[2] | 1932 | { |
---|
[56] | 1933 | printf( "V%d ", pcSlice->getRefViewId( RefPicList(iRefList), iRefIndex ) ); |
---|
[2] | 1934 | } |
---|
| 1935 | else |
---|
[56] | 1936 | { |
---|
| 1937 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
| 1938 | } |
---|
[2] | 1939 | } |
---|
[56] | 1940 | printf("]"); |
---|
[2] | 1941 | } |
---|
| 1942 | if(pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0 && !pcSlice->getNoBackPredFlag()) |
---|
| 1943 | { |
---|
[56] | 1944 | printf(" [LC "); |
---|
[2] | 1945 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(REF_PIC_LIST_C); iRefIndex++) |
---|
| 1946 | { |
---|
[56] | 1947 | if( pcSlice->getViewId() != pcSlice->getRefViewId( (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex) ) ) |
---|
| 1948 | { |
---|
| 1949 | printf( "V%d ", pcSlice->getRefViewId( (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex) ) ); |
---|
| 1950 | } |
---|
| 1951 | else |
---|
| 1952 | { |
---|
| 1953 | printf ("%d ", pcSlice->getRefPOC((RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex))-pcSlice->getLastIDR()); |
---|
| 1954 | } |
---|
[2] | 1955 | } |
---|
[56] | 1956 | printf("]"); |
---|
[2] | 1957 | } |
---|
| 1958 | } |
---|
| 1959 | |
---|
| 1960 | /** Function for deciding the nal_unit_type. |
---|
| 1961 | * \param uiPOCCurr POC of the current picture |
---|
| 1962 | * \returns the nal_unit type of the picture |
---|
| 1963 | * This function checks the configuration and returns the appropriate nal_unit_type for the picture. |
---|
| 1964 | */ |
---|
[56] | 1965 | NalUnitType TEncGOP::getNalUnitType(UInt uiPOCCurr) |
---|
[2] | 1966 | { |
---|
[56] | 1967 | Bool bInterViewOnlySlice = ( m_pcCfg->getGOPEntry(MAX_GOP).m_POC == 0 && (m_pcCfg->getGOPEntry(MAX_GOP).m_sliceType == 'P' || m_pcCfg->getGOPEntry(MAX_GOP).m_sliceType == 'B') ); |
---|
| 1968 | |
---|
[2] | 1969 | if (uiPOCCurr == 0) |
---|
| 1970 | { |
---|
[56] | 1971 | if( bInterViewOnlySlice ) |
---|
| 1972 | { |
---|
[210] | 1973 | #if !QC_REM_IDV_B0046 |
---|
[56] | 1974 | return NAL_UNIT_CODED_SLICE_IDV; |
---|
[210] | 1975 | #else |
---|
| 1976 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 1977 | #endif |
---|
[56] | 1978 | } |
---|
| 1979 | else |
---|
| 1980 | { |
---|
| 1981 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 1982 | } |
---|
[2] | 1983 | } |
---|
| 1984 | if (uiPOCCurr % m_pcCfg->getIntraPeriod() == 0) |
---|
| 1985 | { |
---|
| 1986 | if (m_pcCfg->getDecodingRefreshType() == 1) |
---|
| 1987 | { |
---|
[56] | 1988 | if( bInterViewOnlySlice ) |
---|
| 1989 | { |
---|
[210] | 1990 | #if !QC_REM_IDV_B0046 |
---|
[56] | 1991 | return NAL_UNIT_CODED_SLICE_IDV; |
---|
[210] | 1992 | #else |
---|
| 1993 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
| 1994 | #endif |
---|
[56] | 1995 | } |
---|
| 1996 | else |
---|
| 1997 | { |
---|
| 1998 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
| 1999 | } |
---|
[2] | 2000 | } |
---|
| 2001 | else if (m_pcCfg->getDecodingRefreshType() == 2) |
---|
| 2002 | { |
---|
[56] | 2003 | if( bInterViewOnlySlice ) |
---|
| 2004 | { |
---|
[210] | 2005 | #if !QC_REM_IDV_B0046 |
---|
[56] | 2006 | return NAL_UNIT_CODED_SLICE_IDV; |
---|
[210] | 2007 | #else |
---|
| 2008 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 2009 | #endif |
---|
[56] | 2010 | } |
---|
| 2011 | else |
---|
| 2012 | { |
---|
| 2013 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 2014 | } |
---|
| 2015 | } |
---|
| 2016 | } |
---|
| 2017 | return NAL_UNIT_CODED_SLICE; |
---|
| 2018 | } |
---|
| 2019 | |
---|
| 2020 | NalUnitType TEncGOP::getNalUnitTypeBaseViewMvc(UInt uiPOCCurr) |
---|
| 2021 | { |
---|
| 2022 | if( uiPOCCurr == 0 ) |
---|
| 2023 | { |
---|
| 2024 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 2025 | } |
---|
| 2026 | if( uiPOCCurr % m_pcCfg->getIntraPeriod() == 0 ) |
---|
| 2027 | { |
---|
| 2028 | if( m_pcCfg->getDecodingRefreshType() == 1 ) |
---|
| 2029 | { |
---|
| 2030 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
| 2031 | } |
---|
| 2032 | else if( m_pcCfg->getDecodingRefreshType() == 2 ) |
---|
| 2033 | { |
---|
[2] | 2034 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 2035 | } |
---|
| 2036 | } |
---|
| 2037 | return NAL_UNIT_CODED_SLICE; |
---|
| 2038 | } |
---|
| 2039 | |
---|
[56] | 2040 | Double TEncGOP::xCalculateRVM() |
---|
[2] | 2041 | { |
---|
| 2042 | Double dRVM = 0; |
---|
[56] | 2043 | |
---|
| 2044 | if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFrameToBeEncoded() > RVM_VCEGAM10_M * 2 ) |
---|
[2] | 2045 | { |
---|
| 2046 | // calculate RVM only for lowdelay configurations |
---|
| 2047 | std::vector<Double> vRL , vB; |
---|
| 2048 | size_t N = m_vRVM_RP.size(); |
---|
| 2049 | vRL.resize( N ); |
---|
| 2050 | vB.resize( N ); |
---|
[56] | 2051 | |
---|
[2] | 2052 | Int i; |
---|
| 2053 | Double dRavg = 0 , dBavg = 0; |
---|
| 2054 | vB[RVM_VCEGAM10_M] = 0; |
---|
| 2055 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
| 2056 | { |
---|
| 2057 | vRL[i] = 0; |
---|
| 2058 | for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ ) |
---|
| 2059 | vRL[i] += m_vRVM_RP[j]; |
---|
| 2060 | vRL[i] /= ( 2 * RVM_VCEGAM10_M ); |
---|
| 2061 | vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i]; |
---|
| 2062 | dRavg += m_vRVM_RP[i]; |
---|
| 2063 | dBavg += vB[i]; |
---|
| 2064 | } |
---|
[56] | 2065 | |
---|
[2] | 2066 | dRavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
| 2067 | dBavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
[56] | 2068 | |
---|
[2] | 2069 | double dSigamB = 0; |
---|
| 2070 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
| 2071 | { |
---|
| 2072 | Double tmp = vB[i] - dBavg; |
---|
| 2073 | dSigamB += tmp * tmp; |
---|
| 2074 | } |
---|
| 2075 | dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) ); |
---|
[56] | 2076 | |
---|
[2] | 2077 | double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) ); |
---|
[56] | 2078 | |
---|
[2] | 2079 | dRVM = dSigamB / dRavg * f; |
---|
| 2080 | } |
---|
[56] | 2081 | |
---|
[2] | 2082 | return( dRVM ); |
---|
| 2083 | } |
---|
[56] | 2084 | |
---|
| 2085 | /** Determine the difference between consecutive tile sizes (in bytes) and writes it to bistream rNalu [slice header] |
---|
| 2086 | * \param rpcBitstreamRedirect contains the bitstream to be concatenated to rNalu. rpcBitstreamRedirect contains slice payload. rpcSlice contains tile location information. |
---|
| 2087 | * \returns Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. |
---|
| 2088 | */ |
---|
| 2089 | Void TEncGOP::xWriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice) |
---|
| 2090 | { |
---|
| 2091 | { |
---|
| 2092 | } |
---|
[2] | 2093 | |
---|
[56] | 2094 | // Byte-align |
---|
| 2095 | rNalu.m_Bitstream.writeAlignOne(); |
---|
| 2096 | |
---|
| 2097 | // Update tile marker locations |
---|
| 2098 | TComOutputBitstream *pcOut = &rNalu.m_Bitstream; |
---|
| 2099 | UInt uiAccumulatedLength = pcOut->getNumberOfWrittenBits() >> 3; |
---|
| 2100 | for (Int uiMrkIdx = 0; uiMrkIdx < rpcBitstreamRedirect->getTileMarkerLocationCount(); uiMrkIdx++) |
---|
| 2101 | { |
---|
| 2102 | UInt uiBottom = pcOut->getTileMarkerLocationCount(); |
---|
| 2103 | pcOut->setTileMarkerLocation ( uiBottom, uiAccumulatedLength + rpcBitstreamRedirect->getTileMarkerLocation( uiMrkIdx ) ); |
---|
| 2104 | pcOut->setTileMarkerLocationCount ( uiBottom + 1 ); |
---|
| 2105 | } |
---|
| 2106 | |
---|
| 2107 | // Perform bitstream concatenation |
---|
| 2108 | if (rpcBitstreamRedirect->getNumberOfWrittenBits() > 0) |
---|
| 2109 | { |
---|
| 2110 | UInt uiBitCount = rpcBitstreamRedirect->getNumberOfWrittenBits(); |
---|
| 2111 | if (rpcBitstreamRedirect->getByteStreamLength()>0) |
---|
| 2112 | { |
---|
| 2113 | UChar *pucStart = reinterpret_cast<UChar*>(rpcBitstreamRedirect->getByteStream()); |
---|
| 2114 | UInt uiWriteByteCount = 0; |
---|
| 2115 | while (uiWriteByteCount < (uiBitCount >> 3) ) |
---|
| 2116 | { |
---|
| 2117 | UInt uiBits = (*pucStart); |
---|
| 2118 | rNalu.m_Bitstream.write(uiBits, 8); |
---|
| 2119 | pucStart++; |
---|
| 2120 | uiWriteByteCount++; |
---|
| 2121 | } |
---|
| 2122 | } |
---|
| 2123 | UInt uiBitsHeld = (uiBitCount & 0x07); |
---|
| 2124 | for (UInt uiIdx=0; uiIdx < uiBitsHeld; uiIdx++) |
---|
| 2125 | { |
---|
| 2126 | rNalu.m_Bitstream.write((rpcBitstreamRedirect->getHeldBits() & (1 << (7-uiIdx))) >> (7-uiIdx), 1); |
---|
| 2127 | } |
---|
| 2128 | } |
---|
| 2129 | |
---|
| 2130 | m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream); |
---|
| 2131 | |
---|
| 2132 | delete rpcBitstreamRedirect; |
---|
| 2133 | rpcBitstreamRedirect = new TComOutputBitstream; |
---|
| 2134 | } |
---|
| 2135 | |
---|
| 2136 | Void TEncGOP::xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt uiPOCCurr, UInt iGOPid ) |
---|
| 2137 | { |
---|
| 2138 | if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getSPS()->getListsModificationPresentFlag()) || pcSlice->getSPS()->getNumberOfUsableInterViewRefs() == 0 ) |
---|
| 2139 | { |
---|
| 2140 | return; |
---|
| 2141 | } |
---|
| 2142 | |
---|
| 2143 | // analyze inter-view modifications |
---|
[210] | 2144 | #if !QC_REM_IDV_B0046 |
---|
[56] | 2145 | GOPEntryMvc gem = m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ); |
---|
[210] | 2146 | #else |
---|
| 2147 | Bool bRAP = ((getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDR) || (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_CRA)) && (pcSlice->getSPS()->getViewId()) ? 1:0; |
---|
| 2148 | GOPEntryMvc gem = m_pcCfg->getGOPEntry( bRAP ? MAX_GOP : iGOPid ); |
---|
| 2149 | #endif |
---|
[56] | 2150 | Int numL0Modifications = 0; |
---|
| 2151 | Int numL1Modifications = 0; |
---|
| 2152 | for( Int k = 0; k < gem.m_numInterViewRefPics; k++ ) |
---|
| 2153 | { |
---|
| 2154 | if( gem.m_interViewRefPosL0[k] > 0 ) { numL0Modifications++; } |
---|
| 2155 | if( gem.m_interViewRefPosL1[k] > 0 ) { numL1Modifications++; } |
---|
| 2156 | } |
---|
| 2157 | |
---|
| 2158 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
| 2159 | Int maxRefListSize = pcSlice->getNumPocTotalCurrMvc(); |
---|
| 2160 | Int numTemporalRefs = pcSlice->getNumPocTotalCurr(); |
---|
| 2161 | |
---|
| 2162 | // set L0 inter-view modifications |
---|
| 2163 | if( (maxRefListSize > 1) && (numL0Modifications > 0) ) |
---|
| 2164 | { |
---|
| 2165 | refPicListModification->setRefPicListModificationFlagL0( true ); |
---|
| 2166 | Int tempListEntryL0[16]; |
---|
| 2167 | for( Int k = 0; k < 16; k++ ) { tempListEntryL0[k] = -1; } |
---|
| 2168 | |
---|
| 2169 | Bool hasModification = false; |
---|
| 2170 | for( Int k = 0; k < gem.m_numInterViewRefPics; k++ ) |
---|
| 2171 | { |
---|
| 2172 | if( gem.m_interViewRefPosL0[k] > 0 ) |
---|
| 2173 | { |
---|
| 2174 | for( Int l = 0; l < pcSlice->getSPS()->getNumberOfUsableInterViewRefs(); l++ ) |
---|
| 2175 | { |
---|
| 2176 | if( gem.m_interViewRefs[k] == pcSlice->getSPS()->getUsableInterViewRef( l ) && (gem.m_interViewRefPosL0[k] - 1) != (numTemporalRefs + l) ) |
---|
| 2177 | { |
---|
| 2178 | tempListEntryL0[gem.m_interViewRefPosL0[k]-1] = numTemporalRefs + l; |
---|
| 2179 | hasModification = true; |
---|
| 2180 | } |
---|
| 2181 | } |
---|
| 2182 | } |
---|
| 2183 | } |
---|
| 2184 | |
---|
| 2185 | if( hasModification ) |
---|
| 2186 | { |
---|
[100] | 2187 | Int temporalRefIdx = 0; |
---|
| 2188 | for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++ ) |
---|
| 2189 | { |
---|
| 2190 | if( tempListEntryL0[i] >= 0 ) |
---|
| 2191 | { |
---|
| 2192 | refPicListModification->setRefPicSetIdxL0( i, tempListEntryL0[i] ); |
---|
| 2193 | } |
---|
| 2194 | else |
---|
| 2195 | { |
---|
| 2196 | refPicListModification->setRefPicSetIdxL0( i, temporalRefIdx ); |
---|
| 2197 | temporalRefIdx++; |
---|
| 2198 | } |
---|
| 2199 | } |
---|
| 2200 | } |
---|
[56] | 2201 | else |
---|
| 2202 | { |
---|
| 2203 | refPicListModification->setRefPicListModificationFlagL0( false ); |
---|
| 2204 | } |
---|
| 2205 | } |
---|
| 2206 | |
---|
| 2207 | // set L1 inter-view modifications |
---|
| 2208 | if( (maxRefListSize > 1) && (numL1Modifications > 0) ) |
---|
| 2209 | { |
---|
| 2210 | refPicListModification->setRefPicListModificationFlagL1( true ); |
---|
| 2211 | Int tempListEntryL1[16]; |
---|
| 2212 | for( Int k = 0; k < 16; k++ ) { tempListEntryL1[k] = -1; } |
---|
| 2213 | |
---|
| 2214 | Bool hasModification = false; |
---|
| 2215 | for( Int k = 0; k < gem.m_numInterViewRefPics; k++ ) |
---|
| 2216 | { |
---|
| 2217 | if( gem.m_interViewRefPosL1[k] > 0 ) |
---|
| 2218 | { |
---|
| 2219 | for( Int l = 0; l < pcSlice->getSPS()->getNumberOfUsableInterViewRefs(); l++ ) |
---|
| 2220 | { |
---|
| 2221 | if( gem.m_interViewRefs[k] == pcSlice->getSPS()->getUsableInterViewRef( l ) && (gem.m_interViewRefPosL1[k] - 1) != (numTemporalRefs + l) ) |
---|
| 2222 | { |
---|
| 2223 | tempListEntryL1[gem.m_interViewRefPosL1[k]-1] = numTemporalRefs + l; |
---|
| 2224 | hasModification = true; |
---|
| 2225 | } |
---|
| 2226 | } |
---|
| 2227 | } |
---|
| 2228 | } |
---|
| 2229 | |
---|
| 2230 | if( hasModification ) |
---|
| 2231 | { |
---|
[100] | 2232 | Int temporalRefIdx = 0; |
---|
| 2233 | for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++ ) |
---|
| 2234 | { |
---|
| 2235 | if( tempListEntryL1[i] >= 0 ) |
---|
| 2236 | { |
---|
| 2237 | refPicListModification->setRefPicSetIdxL1( i, tempListEntryL1[i] ); |
---|
| 2238 | } |
---|
| 2239 | else |
---|
| 2240 | { |
---|
| 2241 | refPicListModification->setRefPicSetIdxL1( i, temporalRefIdx ); |
---|
| 2242 | temporalRefIdx++; |
---|
| 2243 | } |
---|
| 2244 | } |
---|
[56] | 2245 | } |
---|
| 2246 | else |
---|
| 2247 | { |
---|
| 2248 | refPicListModification->setRefPicListModificationFlagL1( false ); |
---|
| 2249 | } |
---|
| 2250 | } |
---|
| 2251 | |
---|
| 2252 | return; |
---|
| 2253 | } |
---|
| 2254 | //! \} |
---|