[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 |
---|
| 80 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[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 |
---|
| 133 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[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 | #if !REMOVE_TILE_DEPENDENCE |
---|
| 162 | OutputNALUnit *naluBuffered = NULL; |
---|
| 163 | Bool bIteratorAtListStart = false; |
---|
| 164 | #endif |
---|
| 165 | AccessUnit::iterator itLocationToPushSliceHeaderNALU; // used to store location where NALU containing slice header is to be inserted |
---|
| 166 | UInt uiOneBitstreamPerSliceLength = 0; |
---|
| 167 | TEncSbac* pcSbacCoders = NULL; |
---|
| 168 | TComOutputBitstream* pcSubstreamsOut = NULL; |
---|
[5] | 169 | |
---|
[56] | 170 | { |
---|
| 171 | UInt uiColDir = 1; |
---|
[2] | 172 | //-- For time output for each slice |
---|
| 173 | long iBeforeTime = clock(); |
---|
[56] | 174 | |
---|
| 175 | //select uiColDir |
---|
| 176 | Int iCloseLeft=1, iCloseRight=-1; |
---|
| 177 | for(Int i = 0; i<m_pcCfg->getGOPEntry(iGOPid).m_numRefPics; i++) |
---|
| 178 | { |
---|
| 179 | Int iRef = m_pcCfg->getGOPEntry(iGOPid).m_referencePics[i]; |
---|
| 180 | if(iRef>0&&(iRef<iCloseRight||iCloseRight==-1)) |
---|
| 181 | { |
---|
| 182 | iCloseRight=iRef; |
---|
| 183 | } |
---|
| 184 | else if(iRef<0&&(iRef>iCloseLeft||iCloseLeft==1)) |
---|
| 185 | { |
---|
| 186 | iCloseLeft=iRef; |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | if(iCloseRight>-1) |
---|
| 190 | { |
---|
| 191 | iCloseRight=iCloseRight+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
| 192 | } |
---|
| 193 | if(iCloseLeft<1) |
---|
| 194 | { |
---|
| 195 | iCloseLeft=iCloseLeft+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
| 196 | while(iCloseLeft<0) |
---|
| 197 | { |
---|
| 198 | iCloseLeft+=m_iGopSize; |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | Int iLeftQP=0, iRightQP=0; |
---|
| 202 | for(Int i=0; i<m_iGopSize; i++) |
---|
| 203 | { |
---|
| 204 | if(m_pcCfg->getGOPEntry(i).m_POC==(iCloseLeft%m_iGopSize)+1) |
---|
| 205 | { |
---|
| 206 | iLeftQP= m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
| 207 | } |
---|
| 208 | if (m_pcCfg->getGOPEntry(i).m_POC==(iCloseRight%m_iGopSize)+1) |
---|
| 209 | { |
---|
| 210 | iRightQP=m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | if(iCloseRight>-1&&iRightQP<iLeftQP) |
---|
| 214 | { |
---|
| 215 | uiColDir=0; |
---|
| 216 | } |
---|
[2] | 217 | |
---|
[56] | 218 | /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding |
---|
| 219 | UInt uiPOCCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
| 220 | Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
| 221 | if(iPOCLast == 0) |
---|
| 222 | { |
---|
| 223 | uiPOCCurr=0; |
---|
| 224 | iTimeOffset = 1; |
---|
| 225 | } |
---|
| 226 | if(uiPOCCurr>=m_pcCfg->getFrameToBeEncoded()) |
---|
| 227 | { |
---|
| 228 | return; |
---|
| 229 | } |
---|
| 230 | if( getNalUnitTypeBaseViewMvc( uiPOCCurr ) == NAL_UNIT_CODED_SLICE_IDR ) |
---|
| 231 | { |
---|
| 232 | m_iLastIDR = uiPOCCurr; |
---|
| 233 | } |
---|
[5] | 234 | |
---|
[56] | 235 | /* start a new access unit: create an entry in the list of output |
---|
| 236 | * access units */ |
---|
| 237 | accessUnitsInGOP.push_back(AccessUnit()); |
---|
| 238 | AccessUnit& accessUnit = accessUnitsInGOP.back(); |
---|
| 239 | xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, uiPOCCurr ); |
---|
| 240 | |
---|
[2] | 241 | // Slice data initialization |
---|
| 242 | pcPic->clearSliceBuffer(); |
---|
| 243 | assert(pcPic->getNumAllocatedSlice() == 1); |
---|
| 244 | m_pcSliceEncoder->setSliceIdx(0); |
---|
| 245 | pcPic->setCurrSliceIdx(0); |
---|
[56] | 246 | |
---|
| 247 | std::vector<TComAPS>& vAPS = m_pcEncTop->getAPS(); |
---|
[77] | 248 | #if VIDYO_VPS_INTEGRATION |
---|
| 249 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getEncTop()->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS() ); |
---|
| 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() ); |
---|
| 256 | pcSlice->setIsDepth( m_pcEncTop->getIsDepth() ); |
---|
[5] | 257 | |
---|
[56] | 258 | m_pcEncTop->getSPS()->setDisInter4x4(m_pcEncTop->getDisInter4x4()); |
---|
| 259 | pcSlice->setScalingList ( m_pcEncTop->getScalingList() ); |
---|
| 260 | if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF) |
---|
| 261 | { |
---|
| 262 | m_pcEncTop->getTrQuant()->setFlatScalingList(); |
---|
| 263 | m_pcEncTop->getTrQuant()->setUseScalingList(false); |
---|
| 264 | } |
---|
| 265 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
| 266 | { |
---|
| 267 | pcSlice->setDefaultScalingList (); |
---|
| 268 | pcSlice->getScalingList()->setScalingListPresentFlag(true); |
---|
| 269 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
| 270 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
| 271 | } |
---|
| 272 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
| 273 | { |
---|
| 274 | if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile())) |
---|
| 275 | { |
---|
| 276 | pcSlice->setDefaultScalingList (); |
---|
| 277 | } |
---|
| 278 | #if SCALING_LIST |
---|
| 279 | pcSlice->getScalingList()->checkDcOfMatrix(); |
---|
| 280 | #endif |
---|
| 281 | pcSlice->getScalingList()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList()); |
---|
| 282 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
| 283 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
| 284 | } |
---|
| 285 | else |
---|
| 286 | { |
---|
| 287 | printf("error : ScalingList == %d no support\n",m_pcEncTop->getUseScalingListId()); |
---|
| 288 | assert(0); |
---|
| 289 | } |
---|
[2] | 290 | |
---|
[56] | 291 | #if HHI_INTERVIEW_SKIP |
---|
| 292 | if ( m_pcEncTop->getInterViewSkip() ) |
---|
| 293 | { |
---|
| 294 | m_pcEncTop->getEncTop()->getUsedPelsMap( pcPic->getViewId(), pcPic->getPOC(), pcPic->getUsedPelsMap() ); |
---|
| 295 | } |
---|
| 296 | #endif |
---|
| 297 | // Slice info. refinement |
---|
| 298 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
| 299 | { |
---|
| 300 | if( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) { pcSlice->setSliceType( P_SLICE ); } |
---|
| 301 | } |
---|
[5] | 302 | |
---|
[2] | 303 | // Set the nal unit type |
---|
[56] | 304 | pcSlice->setNalUnitType( getNalUnitType(uiPOCCurr) ); |
---|
| 305 | pcSlice->setNalUnitTypeBaseViewMvc( getNalUnitTypeBaseViewMvc(uiPOCCurr) ); |
---|
[2] | 306 | |
---|
[56] | 307 | // Do decoding refresh marking if any |
---|
| 308 | pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic); |
---|
| 309 | |
---|
| 310 | if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 ) |
---|
| 311 | { |
---|
| 312 | pcSlice->decodingMarkingForNoTMVP( rcListPic, pcSlice->getPOC() ); |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | m_pcEncTop->selectReferencePictureSet(pcSlice, uiPOCCurr, iGOPid,rcListPic); |
---|
| 316 | pcSlice->getRPS()->setNumberOfLongtermPictures(0); |
---|
| 317 | |
---|
| 318 | if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) |
---|
| 319 | { |
---|
| 320 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS()); |
---|
| 321 | } |
---|
| 322 | pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); |
---|
| 323 | |
---|
| 324 | #if H0566_TLA && H0566_TLA_SET_FOR_SWITCHING_POINTS |
---|
| 325 | if(pcSlice->getTLayer() > 0) |
---|
| 326 | { |
---|
| 327 | if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic, pcSlice->getRPS())) |
---|
| 328 | { |
---|
| 329 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA); |
---|
| 330 | } |
---|
| 331 | } |
---|
[2] | 332 | #endif |
---|
| 333 | |
---|
[56] | 334 | 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()) ) ); |
---|
| 335 | 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()) ) ); |
---|
[2] | 336 | |
---|
[56] | 337 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
| 338 | refPicListModification->setRefPicListModificationFlagL0( false ); |
---|
| 339 | #if !H0137_0138_LIST_MODIFICATION |
---|
| 340 | refPicListModification->setNumberOfRefPicListModificationsL0(0); |
---|
| 341 | #endif |
---|
| 342 | refPicListModification->setRefPicListModificationFlagL1( false ); |
---|
| 343 | #if !H0137_0138_LIST_MODIFICATION |
---|
| 344 | refPicListModification->setNumberOfRefPicListModificationsL1(0); |
---|
| 345 | #endif |
---|
| 346 | xSetRefPicListModificationsMvc( pcSlice, uiPOCCurr, iGOPid ); |
---|
[5] | 347 | |
---|
[56] | 348 | #if ADAPTIVE_QP_SELECTION |
---|
| 349 | pcSlice->setTrQuant( m_pcEncTop->getTrQuant() ); |
---|
| 350 | #endif |
---|
| 351 | // Set reference list |
---|
| 352 | TAppEncTop* tAppEncTop = m_pcEncTop->getEncTop(); |
---|
| 353 | assert( tAppEncTop != NULL ); |
---|
[2] | 354 | |
---|
[56] | 355 | TComPic * const pcTexturePic = m_pcEncTop->getIsDepth() ? tAppEncTop->getPicFromView( m_pcEncTop->getViewId(), pcSlice->getPOC(), false ) : NULL; |
---|
| 356 | assert( !m_pcEncTop->getIsDepth() || pcTexturePic != NULL ); |
---|
| 357 | pcSlice->setTexturePic( pcTexturePic ); |
---|
[5] | 358 | |
---|
[56] | 359 | std::vector<TComPic*> apcInterViewRefPics = tAppEncTop->getInterViewRefPics( m_pcEncTop->getViewId(), pcSlice->getPOC(), m_pcEncTop->getIsDepth(), pcSlice->getSPS() ); |
---|
| 360 | pcSlice->setRefPicListMvc( rcListPic, apcInterViewRefPics ); |
---|
| 361 | |
---|
| 362 | // Slice info. refinement |
---|
| 363 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
| 364 | { |
---|
| 365 | if( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) { pcSlice->setSliceType( P_SLICE ); } |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb()) |
---|
| 369 | { |
---|
| 370 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0); |
---|
| 371 | pcSlice->setRefPicListCombinationFlag(false); |
---|
| 372 | pcSlice->setRefPicListModificationFlagLC(false); |
---|
| 373 | } |
---|
| 374 | else |
---|
| 375 | { |
---|
| 376 | pcSlice->setRefPicListCombinationFlag(pcSlice->getSPS()->getUseLComb()); |
---|
| 377 | pcSlice->setRefPicListModificationFlagLC(pcSlice->getSPS()->getLCMod()); |
---|
| 378 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0)); |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | if (pcSlice->getSliceType() == B_SLICE) |
---|
| 382 | { |
---|
| 383 | pcSlice->setColDir(uiColDir); |
---|
| 384 | Bool bLowDelay = true; |
---|
| 385 | Int iCurrPOC = pcSlice->getPOC(); |
---|
| 386 | Int iRefIdx = 0; |
---|
| 387 | |
---|
| 388 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
| 389 | { |
---|
| 390 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 391 | { |
---|
| 392 | bLowDelay = false; |
---|
| 393 | } |
---|
| 394 | } |
---|
| 395 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
| 396 | { |
---|
| 397 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 398 | { |
---|
| 399 | bLowDelay = false; |
---|
| 400 | } |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | pcSlice->setCheckLDC(bLowDelay); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | uiColDir = 1-uiColDir; |
---|
| 407 | |
---|
| 408 | //------------------------------------------------------------- |
---|
| 409 | pcSlice->setRefPOCnViewListsMvc(); |
---|
| 410 | |
---|
| 411 | pcSlice->setNoBackPredFlag( false ); |
---|
| 412 | if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag()) |
---|
| 413 | { |
---|
| 414 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
| 415 | { |
---|
| 416 | pcSlice->setNoBackPredFlag( true ); |
---|
| 417 | int i; |
---|
| 418 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
| 419 | { |
---|
| 420 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
| 421 | { |
---|
| 422 | pcSlice->setNoBackPredFlag( false ); |
---|
| 423 | break; |
---|
| 424 | } |
---|
| 425 | } |
---|
| 426 | } |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | if(pcSlice->getNoBackPredFlag()) |
---|
| 430 | { |
---|
| 431 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0); |
---|
| 432 | } |
---|
| 433 | pcSlice->generateCombinedList(); |
---|
| 434 | |
---|
| 435 | #if HHI_VSO |
---|
[5] | 436 | Bool bUseVSO = m_pcEncTop->getUseVSO(); |
---|
[2] | 437 | m_pcRdCost->setUseVSO( bUseVSO ); |
---|
[100] | 438 | #if SAIT_VSO_EST_A0033 |
---|
| 439 | m_pcRdCost->setUseEstimatedVSD( m_pcEncTop->getUseEstimatedVSD() ); |
---|
| 440 | #endif |
---|
[2] | 441 | |
---|
| 442 | if ( bUseVSO ) |
---|
[5] | 443 | { |
---|
[2] | 444 | Int iVSOMode = m_pcEncTop->getVSOMode(); |
---|
[5] | 445 | m_pcRdCost->setVSOMode( iVSOMode ); |
---|
[120] | 446 | |
---|
[5] | 447 | #if HHI_VSO_DIST_INT |
---|
| 448 | m_pcRdCost->setAllowNegDist( m_pcEncTop->getAllowNegDist() ); |
---|
[2] | 449 | #endif |
---|
| 450 | |
---|
[100] | 451 | |
---|
| 452 | #if SAIT_VSO_EST_A0033 |
---|
[102] | 453 | m_pcRdCost->setVideoRecPicYuv( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), false, true ) ); |
---|
| 454 | m_pcRdCost->setDepthPicYuv ( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), true, false ) ); |
---|
[100] | 455 | #endif |
---|
[115] | 456 | #if LGE_WVSO_A0119 |
---|
[120] | 457 | Bool bUseWVSO = m_pcEncTop->getUseWVSO(); |
---|
| 458 | m_pcRdCost->setUseWVSO( bUseWVSO ); |
---|
[115] | 459 | #endif |
---|
[100] | 460 | |
---|
[2] | 461 | } |
---|
[5] | 462 | #endif |
---|
[56] | 463 | /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice |
---|
| 464 | // Slice compression |
---|
| 465 | if (m_pcCfg->getUseASR()) |
---|
| 466 | { |
---|
| 467 | m_pcSliceEncoder->setSearchRange(pcSlice); |
---|
| 468 | } |
---|
[2] | 469 | |
---|
[56] | 470 | #if H0111_MVD_L1_ZERO |
---|
| 471 | Bool bGPBcheck=false; |
---|
| 472 | if ( pcSlice->getSliceType() == B_SLICE) |
---|
[2] | 473 | { |
---|
| 474 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
| 475 | { |
---|
[56] | 476 | bGPBcheck=true; |
---|
[2] | 477 | int i; |
---|
| 478 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
| 479 | { |
---|
[56] | 480 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
[2] | 481 | { |
---|
[56] | 482 | bGPBcheck=false; |
---|
[2] | 483 | break; |
---|
| 484 | } |
---|
| 485 | } |
---|
| 486 | } |
---|
| 487 | } |
---|
[56] | 488 | if(bGPBcheck) |
---|
[2] | 489 | { |
---|
[56] | 490 | pcSlice->setMvdL1ZeroFlag(true); |
---|
[2] | 491 | } |
---|
[56] | 492 | else |
---|
| 493 | { |
---|
| 494 | pcSlice->setMvdL1ZeroFlag(false); |
---|
| 495 | } |
---|
| 496 | pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); |
---|
[2] | 497 | #endif |
---|
[5] | 498 | |
---|
[56] | 499 | UInt uiNumSlices = 1; |
---|
| 500 | |
---|
| 501 | UInt uiInternalAddress = pcPic->getNumPartInCU()-4; |
---|
| 502 | UInt uiExternalAddress = pcPic->getPicSym()->getNumberOfCUsInFrame()-1; |
---|
| 503 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 504 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 505 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 506 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
| 507 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
[2] | 508 | { |
---|
[56] | 509 | uiInternalAddress--; |
---|
| 510 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 511 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
[2] | 512 | } |
---|
[56] | 513 | uiInternalAddress++; |
---|
| 514 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
[2] | 515 | { |
---|
[56] | 516 | uiInternalAddress = 0; |
---|
| 517 | uiExternalAddress++; |
---|
[2] | 518 | } |
---|
[56] | 519 | UInt uiRealEndAddress = uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress; |
---|
[2] | 520 | |
---|
[56] | 521 | UInt uiCummulativeTileWidth; |
---|
| 522 | UInt uiCummulativeTileHeight; |
---|
| 523 | Int p, j; |
---|
| 524 | UInt uiEncCUAddr; |
---|
| 525 | |
---|
| 526 | #if !REMOVE_TILE_DEPENDENCE |
---|
| 527 | if(pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1) |
---|
| 528 | { |
---|
| 529 | pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getTileBoundaryIndependenceIdr() ); |
---|
| 530 | } |
---|
| 531 | else |
---|
| 532 | { |
---|
| 533 | pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getSPS()->getTileBoundaryIndependenceIdr() ); |
---|
| 534 | |
---|
| 535 | } |
---|
[2] | 536 | #endif |
---|
| 537 | |
---|
[56] | 538 | if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 ) //derive the tile parameters from PPS |
---|
| 539 | { |
---|
| 540 | //set NumColumnsMinus1 and NumRowsMinus1 |
---|
| 541 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
| 542 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
| 543 | |
---|
| 544 | //create the TComTileArray |
---|
| 545 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
| 546 | |
---|
| 547 | if( pcSlice->getPPS()->getUniformSpacingIdr() == 1 ) |
---|
| 548 | { |
---|
| 549 | //set the width for each tile |
---|
| 550 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 551 | { |
---|
| 552 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
| 553 | { |
---|
| 554 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
| 555 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
| 556 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | //set the height for each tile |
---|
| 561 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 562 | { |
---|
| 563 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
| 564 | { |
---|
| 565 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
| 566 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
| 567 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
| 568 | } |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | else |
---|
| 572 | { |
---|
| 573 | //set the width for each tile |
---|
| 574 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 575 | { |
---|
| 576 | uiCummulativeTileWidth = 0; |
---|
| 577 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++) |
---|
| 578 | { |
---|
| 579 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getPPS()->getColumnWidth(p) ); |
---|
| 580 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(p); |
---|
| 581 | } |
---|
| 582 | pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | //set the height for each tile |
---|
| 586 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 587 | { |
---|
| 588 | uiCummulativeTileHeight = 0; |
---|
| 589 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++) |
---|
| 590 | { |
---|
| 591 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getPPS()->getRowHeight(p) ); |
---|
| 592 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(p); |
---|
| 593 | } |
---|
| 594 | pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
| 595 | } |
---|
| 596 | } |
---|
| 597 | } |
---|
| 598 | else //derive the tile parameters from SPS |
---|
| 599 | { |
---|
| 600 | //set NumColumnsMins1 and NumRowsMinus1 |
---|
| 601 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() ); |
---|
| 602 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() ); |
---|
| 603 | |
---|
| 604 | //create the TComTileArray |
---|
| 605 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
| 606 | |
---|
| 607 | if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 ) |
---|
| 608 | { |
---|
| 609 | //set the width for each tile |
---|
| 610 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 611 | { |
---|
| 612 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
| 613 | { |
---|
| 614 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
| 615 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
| 616 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | //set the height for each tile |
---|
| 621 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 622 | { |
---|
| 623 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
| 624 | { |
---|
| 625 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
| 626 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
| 627 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
| 628 | } |
---|
| 629 | } |
---|
| 630 | } |
---|
| 631 | |
---|
| 632 | else |
---|
| 633 | { |
---|
| 634 | //set the width for each tile |
---|
| 635 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 636 | { |
---|
| 637 | uiCummulativeTileWidth = 0; |
---|
| 638 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++) |
---|
| 639 | { |
---|
| 640 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getSPS()->getColumnWidth(p) ); |
---|
| 641 | uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(p); |
---|
| 642 | } |
---|
| 643 | pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | //set the height for each tile |
---|
| 647 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 648 | { |
---|
| 649 | uiCummulativeTileHeight = 0; |
---|
| 650 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++) |
---|
| 651 | { |
---|
| 652 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getSPS()->getRowHeight(p) ); |
---|
| 653 | uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(p); |
---|
| 654 | } |
---|
| 655 | pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
| 656 | } |
---|
| 657 | } |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | //initialize each tile of the current picture |
---|
| 661 | pcPic->getPicSym()->xInitTiles(); |
---|
| 662 | |
---|
| 663 | // Allocate some coders, now we know how many tiles there are. |
---|
| 664 | Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); |
---|
| 665 | |
---|
| 666 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
| 667 | for(p=0, uiEncCUAddr=0; p<pcPic->getPicSym()->getNumberOfCUsInFrame(); p++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
| 668 | { |
---|
| 669 | pcPic->getPicSym()->setCUOrderMap(p, uiEncCUAddr); |
---|
| 670 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, p); |
---|
| 671 | } |
---|
| 672 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 673 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 674 | if (pcSlice->getPPS()->getEntropyCodingMode()) |
---|
| 675 | { |
---|
| 676 | // Allocate some coders, now we know how many tiles there are. |
---|
| 677 | m_pcEncTop->createWPPCoders(iNumSubstreams); |
---|
| 678 | pcSbacCoders = m_pcEncTop->getSbacCoders(); |
---|
| 679 | pcSubstreamsOut = new TComOutputBitstream[iNumSubstreams]; |
---|
| 680 | } |
---|
| 681 | |
---|
[2] | 682 | UInt uiStartCUAddrSliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEncodingSlice" containing locations of slice boundaries |
---|
| 683 | UInt uiStartCUAddrSlice = 0; // used to keep track of current slice's starting CU addr. |
---|
| 684 | pcSlice->setSliceCurStartCUAddr( uiStartCUAddrSlice ); // Setting "start CU addr" for current slice |
---|
[56] | 685 | memset(m_uiStoredStartCUAddrForEncodingSlice, 0, sizeof(UInt) * (pcPic->getPicSym()->getNumberOfCUsInFrame()*pcPic->getNumPartInCU()+1)); |
---|
[2] | 686 | |
---|
| 687 | UInt uiStartCUAddrEntropySliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEntropyEncodingSlice" containing locations of slice boundaries |
---|
| 688 | UInt uiStartCUAddrEntropySlice = 0; // used to keep track of current Entropy slice's starting CU addr. |
---|
| 689 | pcSlice->setEntropySliceCurStartCUAddr( uiStartCUAddrEntropySlice ); // Setting "start CU addr" for current Entropy slice |
---|
[56] | 690 | |
---|
| 691 | memset(m_uiStoredStartCUAddrForEncodingEntropySlice, 0, sizeof(UInt) * (pcPic->getPicSym()->getNumberOfCUsInFrame()*pcPic->getNumPartInCU()+1)); |
---|
[2] | 692 | UInt uiNextCUAddr = 0; |
---|
| 693 | m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++] = uiNextCUAddr; |
---|
| 694 | m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++] = uiNextCUAddr; |
---|
| 695 | |
---|
[5] | 696 | #if DEPTH_MAP_GENERATION |
---|
[2] | 697 | // init view component and predict virtual depth map |
---|
| 698 | m_pcDepthMapGenerator->initViewComponent( pcPic ); |
---|
[187] | 699 | #if !QC_MULTI_DIS_CAN_A0097 |
---|
[2] | 700 | m_pcDepthMapGenerator->predictDepthMap ( pcPic ); |
---|
[56] | 701 | #endif |
---|
[100] | 702 | #endif |
---|
[5] | 703 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
[2] | 704 | m_pcDepthMapGenerator->covertOrgDepthMap( pcPic ); |
---|
[5] | 705 | #endif |
---|
| 706 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[2] | 707 | m_pcResidualGenerator->initViewComponent( pcPic ); |
---|
[5] | 708 | #endif |
---|
[2] | 709 | |
---|
[185] | 710 | #if QC_SIMPLE_NBDV_B0047 |
---|
| 711 | if(pcSlice->getViewId() && pcSlice->getSPS()->getMultiviewMvPredMode()) |
---|
| 712 | { |
---|
| 713 | Int iColPoc = pcSlice->getRefPOC(RefPicList(pcSlice->getColDir()), pcSlice->getColRefIdx()); |
---|
| 714 | pcPic->setRapbCheck(pcPic->getDisCandRefPictures(iColPoc)); |
---|
| 715 | } |
---|
| 716 | #endif |
---|
[56] | 717 | while(uiNextCUAddr<uiRealEndAddress) // determine slice boundaries |
---|
[2] | 718 | { |
---|
| 719 | pcSlice->setNextSlice ( false ); |
---|
| 720 | pcSlice->setNextEntropySlice( false ); |
---|
| 721 | assert(pcPic->getNumAllocatedSlice() == uiStartCUAddrSliceIdx); |
---|
| 722 | m_pcSliceEncoder->precompressSlice( pcPic ); |
---|
| 723 | m_pcSliceEncoder->compressSlice ( pcPic ); |
---|
| 724 | |
---|
| 725 | Bool bNoBinBitConstraintViolated = (!pcSlice->isNextSlice() && !pcSlice->isNextEntropySlice()); |
---|
| 726 | if (pcSlice->isNextSlice() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)) |
---|
| 727 | { |
---|
| 728 | uiStartCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
| 729 | // Reconstruction slice |
---|
| 730 | m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++] = uiStartCUAddrSlice; |
---|
| 731 | // Entropy slice |
---|
| 732 | if (uiStartCUAddrEntropySliceIdx>0 && m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx-1] != uiStartCUAddrSlice) |
---|
| 733 | { |
---|
| 734 | m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++] = uiStartCUAddrSlice; |
---|
| 735 | } |
---|
[56] | 736 | |
---|
| 737 | if (uiStartCUAddrSlice < uiRealEndAddress) |
---|
[2] | 738 | { |
---|
[56] | 739 | pcPic->allocateNewSlice(); |
---|
[2] | 740 | pcPic->setCurrSliceIdx ( uiStartCUAddrSliceIdx-1 ); |
---|
| 741 | m_pcSliceEncoder->setSliceIdx ( uiStartCUAddrSliceIdx-1 ); |
---|
| 742 | pcSlice = pcPic->getSlice ( uiStartCUAddrSliceIdx-1 ); |
---|
| 743 | pcSlice->copySliceInfo ( pcPic->getSlice(0) ); |
---|
| 744 | pcSlice->setSliceIdx ( uiStartCUAddrSliceIdx-1 ); |
---|
| 745 | pcSlice->setSliceCurStartCUAddr ( uiStartCUAddrSlice ); |
---|
| 746 | pcSlice->setEntropySliceCurStartCUAddr ( uiStartCUAddrSlice ); |
---|
| 747 | pcSlice->setSliceBits(0); |
---|
[56] | 748 | uiNumSlices ++; |
---|
[2] | 749 | } |
---|
| 750 | } |
---|
| 751 | else if (pcSlice->isNextEntropySlice() || (bNoBinBitConstraintViolated && m_pcCfg->getEntropySliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)) |
---|
| 752 | { |
---|
| 753 | uiStartCUAddrEntropySlice = pcSlice->getEntropySliceCurEndCUAddr(); |
---|
| 754 | m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++] = uiStartCUAddrEntropySlice; |
---|
| 755 | pcSlice->setEntropySliceCurStartCUAddr( uiStartCUAddrEntropySlice ); |
---|
| 756 | } |
---|
| 757 | else |
---|
| 758 | { |
---|
| 759 | uiStartCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
| 760 | uiStartCUAddrEntropySlice = pcSlice->getEntropySliceCurEndCUAddr(); |
---|
[56] | 761 | } |
---|
[2] | 762 | |
---|
| 763 | uiNextCUAddr = (uiStartCUAddrSlice > uiStartCUAddrEntropySlice) ? uiStartCUAddrSlice : uiStartCUAddrEntropySlice; |
---|
| 764 | } |
---|
| 765 | m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++] = pcSlice->getSliceCurEndCUAddr(); |
---|
| 766 | m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++] = pcSlice->getSliceCurEndCUAddr(); |
---|
[56] | 767 | |
---|
[2] | 768 | pcSlice = pcPic->getSlice(0); |
---|
| 769 | |
---|
[5] | 770 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
[2] | 771 | // set residual picture |
---|
| 772 | m_pcResidualGenerator->setRecResidualPic( pcPic ); |
---|
[5] | 773 | #endif |
---|
| 774 | #if DEPTH_MAP_GENERATION |
---|
[187] | 775 | #if !QC_MULTI_DIS_CAN_A0097 |
---|
[2] | 776 | // update virtual depth map |
---|
| 777 | m_pcDepthMapGenerator->updateDepthMap( pcPic ); |
---|
[5] | 778 | #endif |
---|
[100] | 779 | #endif |
---|
[2] | 780 | |
---|
| 781 | //-- Loop filter |
---|
[56] | 782 | Bool bLFCrossTileBoundary = (pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)? |
---|
| 783 | (pcSlice->getPPS()->getLFCrossTileBoundaryFlag()):(pcSlice->getPPS()->getSPS()->getLFCrossTileBoundaryFlag()); |
---|
| 784 | #if DBL_CONTROL |
---|
| 785 | m_pcLoopFilter->setCfg(pcSlice->getPPS()->getDeblockingFilterControlPresent(), pcSlice->getLoopFilterDisable(), pcSlice->getLoopFilterBetaOffset(), pcSlice->getLoopFilterTcOffset(), bLFCrossTileBoundary); |
---|
| 786 | #else |
---|
| 787 | m_pcLoopFilter->setCfg(pcSlice->getLoopFilterDisable(), pcSlice->getLoopFilterBetaOffset(), pcSlice->getLoopFilterTcOffset(), bLFCrossTileBoundary); |
---|
| 788 | #endif |
---|
[2] | 789 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
| 790 | |
---|
| 791 | pcSlice = pcPic->getSlice(0); |
---|
[56] | 792 | if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()) |
---|
| 793 | { |
---|
| 794 | Int sliceGranularity = pcSlice->getPPS()->getSliceGranularity(); |
---|
| 795 | pcPic->createNonDBFilterInfo(m_uiStoredStartCUAddrForEncodingSlice, uiNumSlices, sliceGranularity, pcSlice->getSPS()->getLFCrossSliceBoundaryFlag(),pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary); |
---|
| 796 | } |
---|
[2] | 797 | |
---|
[56] | 798 | |
---|
| 799 | pcSlice = pcPic->getSlice(0); |
---|
| 800 | |
---|
| 801 | if(pcSlice->getSPS()->getUseSAO()) |
---|
[2] | 802 | { |
---|
[56] | 803 | m_pcSAO->createPicSaoInfo(pcPic, uiNumSlices); |
---|
| 804 | } |
---|
[2] | 805 | |
---|
[56] | 806 | #if LCU_SYNTAX_ALF |
---|
| 807 | AlfParamSet* alfSliceParams = NULL; |
---|
| 808 | std::vector<AlfCUCtrlInfo>* alfCUCtrlParam = NULL; |
---|
| 809 | #else |
---|
| 810 | std::vector<AlfCUCtrlInfo> vAlfCUCtrlParam; |
---|
| 811 | #endif |
---|
| 812 | pcSlice = pcPic->getSlice(0); |
---|
[2] | 813 | |
---|
[56] | 814 | if(pcSlice->getSPS()->getUseALF()) |
---|
| 815 | { |
---|
| 816 | #if LCU_SYNTAX_ALF |
---|
| 817 | m_pcAdaptiveLoopFilter->createPicAlfInfo(pcPic, uiNumSlices, pcSlice->getSliceQp()); |
---|
| 818 | m_pcAdaptiveLoopFilter->initALFEnc(m_pcCfg->getALFParamInSlice(), m_pcCfg->getALFPicBasedEncode(), uiNumSlices, alfSliceParams, alfCUCtrlParam); |
---|
| 819 | #else |
---|
| 820 | vAlfCUCtrlParam.resize(uiNumSlices); |
---|
| 821 | m_pcAdaptiveLoopFilter->createPicAlfInfo(pcPic, uiNumSlices); |
---|
| 822 | #endif |
---|
[2] | 823 | } |
---|
[56] | 824 | |
---|
[2] | 825 | /////////////////////////////////////////////////////////////////////////////////////////////////// File writing |
---|
| 826 | // Set entropy coder |
---|
| 827 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 828 | |
---|
[56] | 829 | /* write various header sets. */ |
---|
| 830 | if ( m_bSeqFirst ) |
---|
[2] | 831 | { |
---|
[77] | 832 | #if VIDYO_VPS_INTEGRATION |
---|
| 833 | { |
---|
| 834 | OutputNALUnit nalu(NAL_UNIT_VPS, true, m_pcEncTop->getLayerId()); |
---|
| 835 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 836 | m_pcEntropyCoder->encodeVPS(m_pcEncTop->getEncTop()->getVPS()); |
---|
| 837 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 838 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 839 | } |
---|
| 840 | #endif |
---|
[56] | 841 | #if NAL_REF_FLAG |
---|
[77] | 842 | #if VIDYO_VPS_INTEGRATION |
---|
| 843 | OutputNALUnit nalu(NAL_UNIT_SPS, true, m_pcEncTop->getLayerId()); |
---|
| 844 | #else |
---|
[56] | 845 | OutputNALUnit nalu(NAL_UNIT_SPS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[77] | 846 | #endif |
---|
[56] | 847 | #else |
---|
| 848 | OutputNALUnit nalu(NAL_UNIT_SPS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
| 849 | #endif |
---|
| 850 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 851 | #if TILES_WPP_ENTRY_POINT_SIGNALLING |
---|
| 852 | pcSlice->getSPS()->setNumSubstreams( pcSlice->getPPS()->getNumSubstreams() ); |
---|
| 853 | #endif |
---|
| 854 | #if HHI_MPI |
---|
| 855 | m_pcEntropyCoder->encodeSPS(pcSlice->getSPS(), m_pcEncTop->getIsDepth()); |
---|
| 856 | #else |
---|
| 857 | m_pcEntropyCoder->encodeSPS(pcSlice->getSPS()); |
---|
| 858 | #endif |
---|
| 859 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 860 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
[2] | 861 | |
---|
[56] | 862 | #if NAL_REF_FLAG |
---|
[77] | 863 | #if VIDYO_VPS_INTEGRATION |
---|
| 864 | nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getLayerId()); |
---|
| 865 | #else |
---|
[56] | 866 | nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[77] | 867 | #endif |
---|
[56] | 868 | #else |
---|
| 869 | nalu = NALUnit(NAL_UNIT_PPS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
| 870 | #endif |
---|
| 871 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 872 | m_pcEntropyCoder->encodePPS(pcSlice->getPPS()); |
---|
| 873 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 874 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
[5] | 875 | |
---|
[56] | 876 | m_bSeqFirst = false; |
---|
[2] | 877 | } |
---|
[5] | 878 | |
---|
[2] | 879 | /* use the main bitstream buffer for storing the marshalled picture */ |
---|
[56] | 880 | m_pcEntropyCoder->setBitstream(NULL); |
---|
[2] | 881 | |
---|
| 882 | uiStartCUAddrSliceIdx = 0; |
---|
[56] | 883 | uiStartCUAddrSlice = 0; |
---|
[2] | 884 | |
---|
| 885 | uiStartCUAddrEntropySliceIdx = 0; |
---|
[56] | 886 | uiStartCUAddrEntropySlice = 0; |
---|
[2] | 887 | uiNextCUAddr = 0; |
---|
| 888 | pcSlice = pcPic->getSlice(uiStartCUAddrSliceIdx); |
---|
[56] | 889 | |
---|
| 890 | Int processingState = (pcSlice->getSPS()->getUseALF() || pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getScalingListFlag() || pcSlice->getSPS()->getUseDF())?(EXECUTE_INLOOPFILTER):(ENCODE_SLICE); |
---|
| 891 | |
---|
| 892 | static Int iCurrAPSIdx = 0; |
---|
| 893 | Int iCodedAPSIdx = 0; |
---|
| 894 | TComSlice* pcSliceForAPS = NULL; |
---|
| 895 | |
---|
| 896 | bool skippedSlice=false; |
---|
| 897 | while (uiNextCUAddr < uiRealEndAddress) // Iterate over all slices |
---|
[2] | 898 | { |
---|
[56] | 899 | switch(processingState) |
---|
| 900 | { |
---|
| 901 | case ENCODE_SLICE: |
---|
| 902 | { |
---|
[2] | 903 | pcSlice->setNextSlice ( false ); |
---|
| 904 | pcSlice->setNextEntropySlice( false ); |
---|
| 905 | if (uiNextCUAddr == m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx]) |
---|
| 906 | { |
---|
| 907 | pcSlice = pcPic->getSlice(uiStartCUAddrSliceIdx); |
---|
[56] | 908 | #if COLLOCATED_REF_IDX |
---|
| 909 | if(uiStartCUAddrSliceIdx > 0 && pcSlice->getSliceType()!= I_SLICE) |
---|
| 910 | { |
---|
| 911 | pcSlice->checkColRefIdx(uiStartCUAddrSliceIdx, pcPic); |
---|
| 912 | } |
---|
| 913 | #endif |
---|
[2] | 914 | pcPic->setCurrSliceIdx(uiStartCUAddrSliceIdx); |
---|
| 915 | m_pcSliceEncoder->setSliceIdx(uiStartCUAddrSliceIdx); |
---|
| 916 | assert(uiStartCUAddrSliceIdx == pcSlice->getSliceIdx()); |
---|
| 917 | // Reconstruction slice |
---|
| 918 | pcSlice->setSliceCurStartCUAddr( uiNextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 919 | pcSlice->setSliceCurEndCUAddr ( m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx+1 ] ); |
---|
| 920 | // Entropy slice |
---|
| 921 | pcSlice->setEntropySliceCurStartCUAddr( uiNextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 922 | pcSlice->setEntropySliceCurEndCUAddr ( m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx+1 ] ); |
---|
| 923 | |
---|
| 924 | pcSlice->setNextSlice ( true ); |
---|
| 925 | |
---|
| 926 | uiStartCUAddrSliceIdx++; |
---|
| 927 | uiStartCUAddrEntropySliceIdx++; |
---|
[56] | 928 | } |
---|
[2] | 929 | else if (uiNextCUAddr == m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx]) |
---|
| 930 | { |
---|
| 931 | // Entropy slice |
---|
| 932 | pcSlice->setEntropySliceCurStartCUAddr( uiNextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 933 | pcSlice->setEntropySliceCurEndCUAddr ( m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx+1 ] ); |
---|
| 934 | |
---|
| 935 | pcSlice->setNextEntropySlice( true ); |
---|
| 936 | |
---|
| 937 | uiStartCUAddrEntropySliceIdx++; |
---|
| 938 | } |
---|
| 939 | |
---|
[56] | 940 | pcSlice->setRPS(pcPic->getSlice(0)->getRPS()); |
---|
| 941 | pcSlice->setRPSidx(pcPic->getSlice(0)->getRPSidx()); |
---|
| 942 | UInt uiDummyStartCUAddr; |
---|
| 943 | UInt uiDummyBoundingCUAddr; |
---|
| 944 | m_pcSliceEncoder->xDetermineStartAndBoundingCUAddr(uiDummyStartCUAddr,uiDummyBoundingCUAddr,pcPic,true); |
---|
| 945 | |
---|
| 946 | uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
| 947 | uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
| 948 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 949 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 950 | uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 951 | uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
| 952 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
[2] | 953 | { |
---|
[56] | 954 | uiInternalAddress--; |
---|
| 955 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 956 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
[2] | 957 | } |
---|
[56] | 958 | uiInternalAddress++; |
---|
| 959 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
| 960 | { |
---|
| 961 | uiInternalAddress = 0; |
---|
| 962 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
| 963 | } |
---|
| 964 | UInt uiEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
| 965 | if(uiEndAddress<=pcSlice->getEntropySliceCurStartCUAddr()) { |
---|
| 966 | UInt uiBoundingAddrSlice, uiBoundingAddrEntropySlice; |
---|
| 967 | uiBoundingAddrSlice = m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx]; |
---|
| 968 | uiBoundingAddrEntropySlice = m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx]; |
---|
| 969 | uiNextCUAddr = min(uiBoundingAddrSlice, uiBoundingAddrEntropySlice); |
---|
| 970 | if(pcSlice->isNextSlice()) |
---|
| 971 | { |
---|
| 972 | skippedSlice=true; |
---|
| 973 | } |
---|
| 974 | continue; |
---|
| 975 | } |
---|
| 976 | if(skippedSlice) |
---|
| 977 | { |
---|
| 978 | pcSlice->setNextSlice ( true ); |
---|
| 979 | pcSlice->setNextEntropySlice( false ); |
---|
| 980 | } |
---|
| 981 | skippedSlice=false; |
---|
| 982 | if (pcSlice->getPPS()->getEntropyCodingMode()) |
---|
| 983 | { |
---|
| 984 | pcSlice->allocSubstreamSizes( iNumSubstreams ); |
---|
| 985 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
| 986 | pcSubstreamsOut[ui].clear(); |
---|
| 987 | } |
---|
[2] | 988 | |
---|
[56] | 989 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 990 | m_pcEntropyCoder->resetEntropy (); |
---|
| 991 | /* start slice NALunit */ |
---|
| 992 | #if H0388 |
---|
| 993 | #if NAL_REF_FLAG |
---|
[77] | 994 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced(), |
---|
| 995 | #if !VIDYO_VPS_INTEGRATION |
---|
| 996 | m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() ); |
---|
[56] | 997 | #else |
---|
[77] | 998 | m_pcEncTop->getLayerId(), pcSlice->getTLayer() ); |
---|
[56] | 999 | #endif |
---|
| 1000 | #else |
---|
[77] | 1001 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, |
---|
| 1002 | #if !VIDYO_VPS_INTEGRATION |
---|
| 1003 | m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() ); |
---|
| 1004 | #else |
---|
| 1005 | m_pcEncTop->getLayerId(), pcSlice->getTLayer() ); |
---|
[56] | 1006 | #endif |
---|
[77] | 1007 | #endif |
---|
| 1008 | #else |
---|
| 1009 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, |
---|
| 1010 | #if !VIDYO_VPS_INTEGRATION |
---|
| 1011 | m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer(), true ); |
---|
| 1012 | #else |
---|
| 1013 | m_pcEncTop->getLayerId(), pcSlice->getTLayer(), true ); |
---|
| 1014 | #endif |
---|
| 1015 | |
---|
| 1016 | #endif |
---|
| 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 LCU_SYNTAX_ALF |
---|
| 1039 | if(pcSlice->getAlfEnabledFlag()) |
---|
[2] | 1040 | #else |
---|
[56] | 1041 | if(pcSlice->getAPS()->getAlfEnabled()) |
---|
[2] | 1042 | #endif |
---|
[56] | 1043 | { |
---|
| 1044 | |
---|
| 1045 | #if LCU_SYNTAX_ALF |
---|
| 1046 | if( pcSlice->getSPS()->getUseALFCoefInSlice()) |
---|
| 1047 | { |
---|
| 1048 | Int iNumSUinLCU = 1<< (g_uiMaxCUDepth << 1); |
---|
| 1049 | Int firstLCUAddr = pcSlice->getSliceCurStartCUAddr() / iNumSUinLCU; |
---|
| 1050 | Bool isAcrossSlice = pcSlice->getSPS()->getLFCrossSliceBoundaryFlag(); |
---|
| 1051 | m_pcEntropyCoder->encodeAlfParam( &(alfSliceParams[pcSlice->getSliceIdx()]), false, firstLCUAddr, isAcrossSlice); |
---|
| 1052 | } |
---|
| 1053 | |
---|
| 1054 | if( !pcSlice->getSPS()->getUseALFCoefInSlice()) |
---|
| 1055 | { |
---|
| 1056 | AlfCUCtrlInfo& cAlfCUCtrlParam = (*alfCUCtrlParam)[pcSlice->getSliceIdx()]; |
---|
| 1057 | #else |
---|
| 1058 | AlfCUCtrlInfo& cAlfCUCtrlParam = vAlfCUCtrlParam[pcSlice->getSliceIdx()]; |
---|
[2] | 1059 | #endif |
---|
[56] | 1060 | if(cAlfCUCtrlParam.cu_control_flag) |
---|
| 1061 | { |
---|
| 1062 | m_pcEntropyCoder->setAlfCtrl( true ); |
---|
| 1063 | m_pcEntropyCoder->setMaxAlfCtrlDepth(cAlfCUCtrlParam.alf_max_depth); |
---|
| 1064 | m_pcCavlcCoder->setAlfCtrl(true); |
---|
| 1065 | m_pcCavlcCoder->setMaxAlfCtrlDepth(cAlfCUCtrlParam.alf_max_depth); |
---|
| 1066 | } |
---|
| 1067 | else |
---|
| 1068 | { |
---|
| 1069 | m_pcEntropyCoder->setAlfCtrl(false); |
---|
| 1070 | } |
---|
| 1071 | m_pcEntropyCoder->encodeAlfCtrlParam(cAlfCUCtrlParam, m_pcAdaptiveLoopFilter->getNumCUsInPic()); |
---|
| 1072 | |
---|
| 1073 | #if LCU_SYNTAX_ALF |
---|
| 1074 | } |
---|
| 1075 | #endif |
---|
| 1076 | } |
---|
| 1077 | } |
---|
| 1078 | } |
---|
| 1079 | m_pcEntropyCoder->encodeTileMarkerFlag(pcSlice); |
---|
[5] | 1080 | |
---|
[56] | 1081 | // is it needed? |
---|
| 1082 | { |
---|
| 1083 | if (!bEntropySlice) |
---|
| 1084 | { |
---|
| 1085 | pcBitstreamRedirect->writeAlignOne(); |
---|
| 1086 | } |
---|
| 1087 | else |
---|
| 1088 | { |
---|
| 1089 | // We've not completed our slice header info yet, do the alignment later. |
---|
| 1090 | } |
---|
| 1091 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
| 1092 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
| 1093 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1094 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
| 1095 | { |
---|
| 1096 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 1097 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1098 | } |
---|
| 1099 | } |
---|
| 1100 | |
---|
| 1101 | if(pcSlice->isNextSlice()) |
---|
| 1102 | { |
---|
| 1103 | // set entropy coder for writing |
---|
| 1104 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
| 1105 | { |
---|
| 1106 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
[2] | 1107 | { |
---|
[56] | 1108 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 1109 | m_pcEntropyCoder->resetEntropy (); |
---|
[2] | 1110 | } |
---|
[56] | 1111 | pcSbacCoders[0].load(m_pcSbacCoder); |
---|
| 1112 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[0], pcSlice ); //ALF is written in substream #0 with CABAC coder #0 (see ALF param encoding below) |
---|
| 1113 | } |
---|
| 1114 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1115 | // File writing |
---|
| 1116 | if (!bEntropySlice) |
---|
| 1117 | { |
---|
| 1118 | m_pcEntropyCoder->setBitstream(pcBitstreamRedirect); |
---|
| 1119 | } |
---|
| 1120 | else |
---|
| 1121 | { |
---|
| 1122 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1123 | } |
---|
| 1124 | // for now, override the TILES_DECODER setting in order to write substreams. |
---|
| 1125 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[0] ); |
---|
[5] | 1126 | |
---|
[56] | 1127 | } |
---|
| 1128 | pcSlice->setFinalized(true); |
---|
| 1129 | |
---|
| 1130 | m_pcSbacCoder->load( &pcSbacCoders[0] ); |
---|
| 1131 | |
---|
| 1132 | pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength ); |
---|
| 1133 | if (!bEntropySlice) |
---|
| 1134 | { |
---|
| 1135 | pcSlice->setTileLocationCount ( 0 ); |
---|
| 1136 | m_pcSliceEncoder->encodeSlice(pcPic, pcBitstreamRedirect, pcSubstreamsOut); // redirect is only used for CAVLC tile position info. |
---|
| 1137 | } |
---|
| 1138 | else |
---|
| 1139 | { |
---|
| 1140 | m_pcSliceEncoder->encodeSlice(pcPic, &nalu.m_Bitstream, pcSubstreamsOut); // nalu.m_Bitstream is only used for CAVLC tile position info. |
---|
| 1141 | } |
---|
| 1142 | |
---|
| 1143 | { |
---|
| 1144 | // Construct the final bitstream by flushing and concatenating substreams. |
---|
| 1145 | // The final bitstream is either nalu.m_Bitstream or pcBitstreamRedirect; |
---|
| 1146 | UInt* puiSubstreamSizes = pcSlice->getSubstreamSizes(); |
---|
| 1147 | UInt uiTotalCodedSize = 0; // for padding calcs. |
---|
| 1148 | UInt uiNumSubstreamsPerTile = iNumSubstreams; |
---|
| 1149 | #if !REMOVE_TILE_DEPENDENCE |
---|
| 1150 | #if WPP_SIMPLIFICATION |
---|
| 1151 | if (pcPic->getPicSym()->getTileBoundaryIndependenceIdr() && iNumSubstreams > 1) |
---|
| 1152 | #else |
---|
| 1153 | if (pcPic->getPicSym()->getTileBoundaryIndependenceIdr() && pcSlice->getPPS()->getEntropyCodingSynchro()) |
---|
| 1154 | #endif |
---|
| 1155 | uiNumSubstreamsPerTile /= pcPic->getPicSym()->getNumTiles(); |
---|
| 1156 | #else |
---|
| 1157 | #if WPP_SIMPLIFICATION |
---|
| 1158 | if (iNumSubstreams > 1) |
---|
| 1159 | #else |
---|
| 1160 | if (pcSlice->getPPS()->getEntropyCodingSynchro()) |
---|
| 1161 | #endif |
---|
| 1162 | { |
---|
| 1163 | uiNumSubstreamsPerTile /= pcPic->getPicSym()->getNumTiles(); |
---|
| 1164 | } |
---|
| 1165 | #endif |
---|
| 1166 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
| 1167 | { |
---|
| 1168 | // Flush all substreams -- this includes empty ones. |
---|
| 1169 | // Terminating bit and flush. |
---|
| 1170 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 1171 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[ui] ); |
---|
| 1172 | m_pcEntropyCoder->encodeTerminatingBit( 1 ); |
---|
| 1173 | m_pcEntropyCoder->encodeSliceFinish(); |
---|
| 1174 | pcSubstreamsOut[ui].write( 1, 1 ); // stop bit. |
---|
| 1175 | #if TILES_WPP_ENTRY_POINT_SIGNALLING |
---|
| 1176 | pcSubstreamsOut[ui].writeAlignZero(); |
---|
| 1177 | #endif |
---|
| 1178 | // Byte alignment is necessary between tiles when tiles are independent. |
---|
| 1179 | uiTotalCodedSize += pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
| 1180 | |
---|
[2] | 1181 | { |
---|
[56] | 1182 | Bool bNextSubstreamInNewTile = ((ui+1) < iNumSubstreams) |
---|
| 1183 | && ((ui+1)%uiNumSubstreamsPerTile == 0); |
---|
| 1184 | if (bNextSubstreamInNewTile) |
---|
[2] | 1185 | { |
---|
[56] | 1186 | // byte align. |
---|
| 1187 | while (uiTotalCodedSize&0x7) |
---|
| 1188 | { |
---|
| 1189 | pcSubstreamsOut[ui].write(0, 1); |
---|
| 1190 | uiTotalCodedSize++; |
---|
| 1191 | } |
---|
[2] | 1192 | } |
---|
[56] | 1193 | Bool bRecordOffsetNext = m_pcCfg->getTileLocationInSliceHeaderFlag() |
---|
| 1194 | && bNextSubstreamInNewTile; |
---|
| 1195 | if (bRecordOffsetNext) |
---|
| 1196 | pcSlice->setTileLocation(ui/uiNumSubstreamsPerTile, pcSlice->getTileOffstForMultES()+(uiTotalCodedSize>>3)); |
---|
[2] | 1197 | } |
---|
[56] | 1198 | if (ui+1 < pcSlice->getPPS()->getNumSubstreams()) |
---|
| 1199 | puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
| 1200 | } |
---|
| 1201 | // Complete the slice header info. |
---|
| 1202 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 1203 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1204 | #if TILES_WPP_ENTRY_POINT_SIGNALLING |
---|
| 1205 | if (m_pcCfg->getTileLocationInSliceHeaderFlag()==0) |
---|
| 1206 | { |
---|
| 1207 | pcSlice->setTileLocationCount( 0 ); |
---|
| 1208 | } |
---|
| 1209 | m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice ); |
---|
| 1210 | #else |
---|
| 1211 | m_pcEntropyCoder->encodeSliceHeaderSubstreamTable(pcSlice); |
---|
[2] | 1212 | #endif |
---|
[56] | 1213 | // Substreams... |
---|
| 1214 | TComOutputBitstream *pcOut = pcBitstreamRedirect; |
---|
| 1215 | // xWriteTileLocation will perform byte-alignment... |
---|
| 1216 | { |
---|
| 1217 | if (bEntropySlice) |
---|
| 1218 | { |
---|
| 1219 | // In these cases, padding is necessary here. |
---|
| 1220 | pcOut = &nalu.m_Bitstream; |
---|
| 1221 | pcOut->writeAlignOne(); |
---|
| 1222 | } |
---|
| 1223 | } |
---|
| 1224 | UInt uiAccumulatedLength = 0; |
---|
| 1225 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams(); ui++ ) |
---|
| 1226 | { |
---|
| 1227 | pcOut->addSubstream(&pcSubstreamsOut[ui]); |
---|
[5] | 1228 | |
---|
[56] | 1229 | // Update tile marker location information |
---|
| 1230 | for (Int uiMrkIdx = 0; uiMrkIdx < pcSubstreamsOut[ui].getTileMarkerLocationCount(); uiMrkIdx++) |
---|
| 1231 | { |
---|
| 1232 | UInt uiBottom = pcOut->getTileMarkerLocationCount(); |
---|
| 1233 | pcOut->setTileMarkerLocation ( uiBottom, uiAccumulatedLength + pcSubstreamsOut[ui].getTileMarkerLocation( uiMrkIdx ) ); |
---|
| 1234 | pcOut->setTileMarkerLocationCount ( uiBottom + 1 ); |
---|
| 1235 | } |
---|
| 1236 | uiAccumulatedLength = (pcOut->getNumberOfWrittenBits() >> 3); |
---|
| 1237 | } |
---|
| 1238 | } |
---|
| 1239 | |
---|
| 1240 | UInt uiBoundingAddrSlice, uiBoundingAddrEntropySlice; |
---|
| 1241 | uiBoundingAddrSlice = m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx]; |
---|
| 1242 | uiBoundingAddrEntropySlice = m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx]; |
---|
| 1243 | uiNextCUAddr = min(uiBoundingAddrSlice, uiBoundingAddrEntropySlice); |
---|
| 1244 | #if !REMOVE_TILE_DEPENDENCE |
---|
| 1245 | Bool bNextCUInNewSlice = (uiNextCUAddr >= uiRealEndAddress) || (uiNextCUAddr == m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx]); |
---|
[2] | 1246 | #endif |
---|
[56] | 1247 | // If current NALU is the first NALU of slice (containing slice header) and more NALUs exist (due to multiple entropy slices) then buffer it. |
---|
| 1248 | // 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. |
---|
| 1249 | Bool bNALUAlignedWrittenToList = false; // used to ensure current NALU is not written more than once to the NALU list. |
---|
| 1250 | #if !REMOVE_TILE_DEPENDENCE |
---|
| 1251 | if (pcSlice->getSPS()->getTileBoundaryIndependenceIdr() && !pcSlice->getSPS()->getTileBoundaryIndependenceIdr()) |
---|
| 1252 | { |
---|
| 1253 | if (bNextCUInNewSlice) |
---|
| 1254 | { |
---|
| 1255 | if (!bEntropySlice) // there were no entropy slices |
---|
[2] | 1256 | { |
---|
[56] | 1257 | xWriteTileLocationToSliceHeader(nalu, pcBitstreamRedirect, pcSlice); |
---|
[2] | 1258 | } |
---|
[56] | 1259 | // (a) writing current NALU |
---|
| 1260 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1261 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1262 | bNALUAlignedWrittenToList = true; |
---|
| 1263 | |
---|
| 1264 | // (b) update and write buffered NALU |
---|
| 1265 | if (bEntropySlice) // if entropy slices existed in the slice then perform concatenation for the buffered nalu-bitstream and buffered payload bitstream |
---|
[2] | 1266 | { |
---|
[56] | 1267 | // Perform bitstream concatenation of slice header and partial slice payload |
---|
| 1268 | xWriteTileLocationToSliceHeader((*naluBuffered), pcBitstreamRedirect, pcSlice); |
---|
| 1269 | if (bIteratorAtListStart) |
---|
| 1270 | { |
---|
| 1271 | itLocationToPushSliceHeaderNALU = accessUnit.begin(); |
---|
| 1272 | } |
---|
| 1273 | else |
---|
| 1274 | { |
---|
| 1275 | itLocationToPushSliceHeaderNALU++; |
---|
| 1276 | } |
---|
| 1277 | accessUnit.insert(itLocationToPushSliceHeaderNALU, (new NALUnitEBSP((*naluBuffered))) ); |
---|
| 1278 | |
---|
| 1279 | // free buffered nalu |
---|
| 1280 | delete naluBuffered; |
---|
| 1281 | naluBuffered = NULL; |
---|
[2] | 1282 | } |
---|
[56] | 1283 | } |
---|
| 1284 | else // another entropy slice exists |
---|
| 1285 | { |
---|
| 1286 | // Is this start-of-slice NALU? i.e. the one containing slice header. If Yes, then buffer it. |
---|
| 1287 | if (!bEntropySlice) |
---|
[2] | 1288 | { |
---|
[56] | 1289 | // store a pointer to where NALU for slice header is to be written in NALU list |
---|
| 1290 | itLocationToPushSliceHeaderNALU = accessUnit.end(); |
---|
| 1291 | if (accessUnit.begin() == accessUnit.end()) |
---|
[2] | 1292 | { |
---|
[56] | 1293 | bIteratorAtListStart = true; |
---|
[2] | 1294 | } |
---|
[56] | 1295 | else |
---|
| 1296 | { |
---|
| 1297 | bIteratorAtListStart = false; |
---|
| 1298 | itLocationToPushSliceHeaderNALU--; |
---|
| 1299 | } |
---|
| 1300 | |
---|
| 1301 | // buffer nalu for later writing |
---|
| 1302 | #if H0388 |
---|
| 1303 | naluBuffered = new OutputNALUnit( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() ); |
---|
| 1304 | #else |
---|
| 1305 | naluBuffered = new OutputNALUnit(pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer(), true); |
---|
| 1306 | #endif |
---|
| 1307 | copyNaluData( (*naluBuffered), nalu ); |
---|
| 1308 | |
---|
| 1309 | // perform byte-alignment to get appropriate bitstream length (used for explicit tile location signaling in slice header) |
---|
| 1310 | writeRBSPTrailingBits((*pcBitstreamRedirect)); |
---|
| 1311 | bNALUAlignedWrittenToList = true; // This is not really a write to bitsream but buffered for later. The flag is set to prevent writing of current NALU to list. |
---|
| 1312 | uiOneBitstreamPerSliceLength += pcBitstreamRedirect->getNumberOfWrittenBits(); // length of bitstream after byte-alignment |
---|
[2] | 1313 | } |
---|
[56] | 1314 | else // write out entropy slice |
---|
[2] | 1315 | { |
---|
[56] | 1316 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1317 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1318 | bNALUAlignedWrittenToList = true; |
---|
| 1319 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment |
---|
[2] | 1320 | } |
---|
[56] | 1321 | } |
---|
| 1322 | } |
---|
| 1323 | else |
---|
| 1324 | { |
---|
| 1325 | #endif |
---|
| 1326 | xWriteTileLocationToSliceHeader(nalu, pcBitstreamRedirect, pcSlice); |
---|
| 1327 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1328 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1329 | bNALUAlignedWrittenToList = true; |
---|
| 1330 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment |
---|
| 1331 | #if !REMOVE_TILE_DEPENDENCE |
---|
| 1332 | } |
---|
| 1333 | #endif |
---|
| 1334 | |
---|
| 1335 | if (!bNALUAlignedWrittenToList) |
---|
| 1336 | { |
---|
| 1337 | { |
---|
| 1338 | nalu.m_Bitstream.writeAlignZero(); |
---|
| 1339 | } |
---|
| 1340 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1341 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits() + 24; // length of bitstream after byte-alignment + 3 byte startcode 0x000001 |
---|
| 1342 | } |
---|
| 1343 | |
---|
| 1344 | |
---|
| 1345 | processingState = ENCODE_SLICE; |
---|
| 1346 | } |
---|
| 1347 | break; |
---|
| 1348 | case EXECUTE_INLOOPFILTER: |
---|
| 1349 | { |
---|
| 1350 | TComAPS cAPS; |
---|
| 1351 | allocAPS(&cAPS, pcSlice->getSPS()); |
---|
| 1352 | #if SAO_UNIT_INTERLEAVING |
---|
| 1353 | cAPS.setSaoInterleavingFlag(m_pcCfg->getSaoInterleavingFlag()); |
---|
| 1354 | #endif |
---|
| 1355 | // set entropy coder for RD |
---|
| 1356 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 1357 | |
---|
| 1358 | if ( pcSlice->getSPS()->getUseSAO() ) |
---|
[2] | 1359 | { |
---|
[56] | 1360 | m_pcEntropyCoder->resetEntropy(); |
---|
| 1361 | m_pcEntropyCoder->setBitstream( m_pcBitCounter ); |
---|
| 1362 | m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), NULL); |
---|
| 1363 | SAOParam& cSaoParam = *(cAPS.getSaoParam()); |
---|
| 1364 | |
---|
| 1365 | #if SAO_CHROMA_LAMBDA |
---|
| 1366 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); |
---|
| 1367 | #else |
---|
| 1368 | #if ALF_CHROMA_LAMBDA |
---|
| 1369 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma()); |
---|
| 1370 | #else |
---|
| 1371 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda()); |
---|
| 1372 | #endif |
---|
| 1373 | #endif |
---|
| 1374 | m_pcSAO->endSaoEnc(); |
---|
| 1375 | |
---|
| 1376 | m_pcAdaptiveLoopFilter->PCMLFDisableProcess(pcPic); |
---|
[2] | 1377 | } |
---|
[56] | 1378 | |
---|
| 1379 | // adaptive loop filter |
---|
| 1380 | #if !LCU_SYNTAX_ALF |
---|
| 1381 | UInt64 uiDist, uiBits; |
---|
[2] | 1382 | #endif |
---|
[56] | 1383 | if ( pcSlice->getSPS()->getUseALF()) |
---|
| 1384 | { |
---|
| 1385 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1386 | m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); |
---|
| 1387 | m_pcAdaptiveLoopFilter->startALFEnc(pcPic, m_pcEntropyCoder ); |
---|
| 1388 | #if LCU_SYNTAX_ALF |
---|
| 1389 | AlfParamSet* pAlfEncParam = (pcSlice->getSPS()->getUseALFCoefInSlice())?( alfSliceParams ):( cAPS.getAlfParam()); |
---|
| 1390 | #if ALF_CHROMA_LAMBDA |
---|
| 1391 | #if HHI_INTERVIEW_SKIP |
---|
| 1392 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), m_pcEncTop->getInterViewSkip() ); |
---|
| 1393 | #else |
---|
| 1394 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma() ); |
---|
| 1395 | #endif |
---|
| 1396 | #else |
---|
| 1397 | #if SAO_CHROMA_LAMBDA |
---|
| 1398 | #if HHI_INTERVIEW_SKIP |
---|
| 1399 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), m_pcEncTop->getInterViewSkip()); |
---|
| 1400 | #else |
---|
| 1401 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma()); |
---|
| 1402 | #endif |
---|
| 1403 | #else |
---|
| 1404 | #if HHI_INTERVIEW_SKIP |
---|
| 1405 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambda(), m_pcEncTop->getInterViewSkip() ); |
---|
| 1406 | #else |
---|
| 1407 | m_pcAdaptiveLoopFilter->ALFProcess(pAlfEncParam, alfCUCtrlParam, pcPic->getSlice(0)->getLambda()); |
---|
| 1408 | #endif |
---|
| 1409 | #endif |
---|
| 1410 | #endif |
---|
[5] | 1411 | |
---|
[56] | 1412 | #else |
---|
| 1413 | ALFParam& cAlfParam = *( cAPS.getAlfParam()); |
---|
| 1414 | |
---|
| 1415 | #if ALF_CHROMA_LAMBDA |
---|
| 1416 | #if HHI_INTERVIEW_SKIP |
---|
| 1417 | m_pcAdaptiveLoopFilter->ALFProcess( &cAlfParam, &vAlfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), uiDist, uiBits, m_pcEncTop->getInterViewSkip()); |
---|
| 1418 | #else |
---|
| 1419 | m_pcAdaptiveLoopFilter->ALFProcess( &cAlfParam, &vAlfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), uiDist, uiBits); |
---|
| 1420 | #endif |
---|
| 1421 | #else |
---|
| 1422 | #if SAO_CHROMA_LAMBDA |
---|
| 1423 | #if HHI_INTERVIEW_SKIP |
---|
| 1424 | m_pcAdaptiveLoopFilter->ALFProcess( &cAlfParam, &vAlfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), uiDist, uiBits, m_pcEncTop->getInterViewSkip()); |
---|
| 1425 | #else |
---|
| 1426 | m_pcAdaptiveLoopFilter->ALFProcess( &cAlfParam, &vAlfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), uiDist, uiBits); |
---|
| 1427 | #endif |
---|
| 1428 | #else |
---|
| 1429 | #if HHI_INTERVIEW_SKIP |
---|
| 1430 | m_pcAdaptiveLoopFilter->ALFProcess( &cAlfParam, &vAlfCUCtrlParam, pcPic->getSlice(0)->getLambdaLuma(), uiDist, uiBits, m_pcEncTop->getInterViewSkip()); |
---|
| 1431 | #else |
---|
| 1432 | m_pcAdaptiveLoopFilter->ALFProcess( &cAlfParam, &vAlfCUCtrlParam, pcPic->getSlice(0)->getLambda(), uiDist, uiBits); |
---|
| 1433 | #endif |
---|
| 1434 | #endif |
---|
| 1435 | #endif |
---|
| 1436 | #endif |
---|
| 1437 | m_pcAdaptiveLoopFilter->endALFEnc(); |
---|
| 1438 | |
---|
| 1439 | m_pcAdaptiveLoopFilter->PCMLFDisableProcess(pcPic); |
---|
| 1440 | } |
---|
| 1441 | iCodedAPSIdx = iCurrAPSIdx; |
---|
| 1442 | pcSliceForAPS = pcSlice; |
---|
| 1443 | |
---|
| 1444 | assignNewAPS(cAPS, iCodedAPSIdx, vAPS, pcSliceForAPS); |
---|
| 1445 | iCurrAPSIdx = (iCurrAPSIdx +1)%MAX_NUM_SUPPORTED_APS; |
---|
| 1446 | processingState = ENCODE_APS; |
---|
| 1447 | |
---|
| 1448 | //set APS link to the slices |
---|
| 1449 | for(Int s=0; s< uiNumSlices; s++) |
---|
[2] | 1450 | { |
---|
[56] | 1451 | if (pcSlice->getSPS()->getUseALF()) |
---|
| 1452 | { |
---|
| 1453 | #if LCU_SYNTAX_ALF |
---|
| 1454 | pcPic->getSlice(s)->setAlfEnabledFlag( (pcSlice->getSPS()->getUseALFCoefInSlice())?(alfSliceParams[s].isEnabled[ALF_Y]):(cAPS.getAlfEnabled()) ); |
---|
| 1455 | #else |
---|
| 1456 | pcPic->getSlice(s)->setAlfEnabledFlag((cAPS.getAlfParam()->alf_flag==1)?true:false); |
---|
| 1457 | #endif |
---|
| 1458 | } |
---|
| 1459 | if (pcSlice->getSPS()->getUseSAO()) |
---|
| 1460 | { |
---|
| 1461 | pcPic->getSlice(s)->setSaoEnabledFlag((cAPS.getSaoParam()->bSaoFlag[0]==1)?true:false); |
---|
| 1462 | } |
---|
| 1463 | pcPic->getSlice(s)->setAPS(&(vAPS[iCodedAPSIdx])); |
---|
| 1464 | pcPic->getSlice(s)->setAPSId(iCodedAPSIdx); |
---|
[2] | 1465 | } |
---|
[56] | 1466 | } |
---|
| 1467 | break; |
---|
| 1468 | case ENCODE_APS: |
---|
| 1469 | { |
---|
| 1470 | #if NAL_REF_FLAG |
---|
[77] | 1471 | #if VIDYO_VPS_INTEGRATION |
---|
| 1472 | OutputNALUnit nalu(NAL_UNIT_APS, true, m_pcEncTop->getLayerId()); |
---|
| 1473 | #else |
---|
[56] | 1474 | OutputNALUnit nalu(NAL_UNIT_APS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[77] | 1475 | #endif |
---|
[56] | 1476 | #else |
---|
| 1477 | OutputNALUnit nalu(NAL_UNIT_APS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[2] | 1478 | #endif |
---|
[56] | 1479 | encodeAPS(&(vAPS[iCodedAPSIdx]), nalu.m_Bitstream, pcSliceForAPS); |
---|
| 1480 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1481 | |
---|
| 1482 | processingState = ENCODE_SLICE; |
---|
[2] | 1483 | } |
---|
[56] | 1484 | break; |
---|
| 1485 | default: |
---|
| 1486 | { |
---|
| 1487 | printf("Not a supported encoding state\n"); |
---|
| 1488 | assert(0); |
---|
| 1489 | exit(-1); |
---|
| 1490 | } |
---|
[2] | 1491 | } |
---|
[56] | 1492 | } // end iteration over slices |
---|
[5] | 1493 | |
---|
| 1494 | |
---|
[56] | 1495 | if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()) |
---|
| 1496 | { |
---|
| 1497 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 1498 | { |
---|
| 1499 | m_pcSAO->destroyPicSaoInfo(); |
---|
| 1500 | } |
---|
[5] | 1501 | |
---|
[56] | 1502 | if(pcSlice->getSPS()->getUseALF()) |
---|
[2] | 1503 | { |
---|
[56] | 1504 | #if LCU_SYNTAX_ALF |
---|
| 1505 | m_pcAdaptiveLoopFilter->uninitALFEnc(alfSliceParams, alfCUCtrlParam); |
---|
| 1506 | #endif |
---|
| 1507 | m_pcAdaptiveLoopFilter->destroyPicAlfInfo(); |
---|
[2] | 1508 | } |
---|
[5] | 1509 | |
---|
[56] | 1510 | pcPic->destroyNonDBFilterInfo(); |
---|
| 1511 | } |
---|
[5] | 1512 | |
---|
[56] | 1513 | #if HHI_INTERVIEW_SKIP |
---|
| 1514 | if (pcPic->getUsedPelsMap()) |
---|
| 1515 | pcPic->removeUsedPelsMapBuffer() ; |
---|
[5] | 1516 | #endif |
---|
[56] | 1517 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
| 1518 | pcPic->removeOrgDepthMapBuffer(); |
---|
| 1519 | #endif |
---|
| 1520 | |
---|
| 1521 | // pcPic->compressMotion(); |
---|
| 1522 | m_pocLastCoded = pcPic->getPOC(); |
---|
| 1523 | |
---|
[2] | 1524 | //-- For time output for each slice |
---|
| 1525 | Double dEncTime = (double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
[5] | 1526 | |
---|
[56] | 1527 | const char* digestStr = NULL; |
---|
| 1528 | if (m_pcCfg->getPictureDigestEnabled()) |
---|
| 1529 | { |
---|
[2] | 1530 | /* calculate MD5sum for entire reconstructed picture */ |
---|
| 1531 | SEIpictureDigest sei_recon_picture_digest; |
---|
| 1532 | sei_recon_picture_digest.method = SEIpictureDigest::MD5; |
---|
| 1533 | calcMD5(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
[56] | 1534 | digestStr = digestToString(sei_recon_picture_digest.digest); |
---|
[2] | 1535 | |
---|
[56] | 1536 | #if NAL_REF_FLAG |
---|
[77] | 1537 | #if VIDYO_VPS_INTEGRATION |
---|
| 1538 | OutputNALUnit nalu(NAL_UNIT_SEI, false, m_pcEncTop->getLayerId()); |
---|
| 1539 | #else |
---|
[56] | 1540 | OutputNALUnit nalu(NAL_UNIT_SEI, false, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
[77] | 1541 | #endif |
---|
[56] | 1542 | #else |
---|
| 1543 | OutputNALUnit nalu(NAL_UNIT_SEI, NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth()); |
---|
| 1544 | #endif |
---|
| 1545 | |
---|
[2] | 1546 | /* write the SEI messages */ |
---|
| 1547 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
[56] | 1548 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
[2] | 1549 | m_pcEntropyCoder->encodeSEI(sei_recon_picture_digest); |
---|
[56] | 1550 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
[2] | 1551 | |
---|
[56] | 1552 | /* insert the SEI message NALUnit before any Slice NALUnits */ |
---|
| 1553 | AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); |
---|
| 1554 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
[2] | 1555 | } |
---|
| 1556 | |
---|
[56] | 1557 | xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime ); |
---|
| 1558 | if (digestStr) |
---|
| 1559 | printf(" [MD5:%s]", digestStr); |
---|
[2] | 1560 | |
---|
[56] | 1561 | #if FIXED_ROUNDING_FRAME_MEMORY |
---|
| 1562 | /* TODO: this should happen after copyToPic(pcPicYuvRecOut) */ |
---|
| 1563 | pcPic->getPicYuvRec()->xFixedRoundingPic(); |
---|
| 1564 | #endif |
---|
[2] | 1565 | pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut); |
---|
[56] | 1566 | |
---|
[2] | 1567 | pcPic->setReconMark ( true ); |
---|
[5] | 1568 | |
---|
[56] | 1569 | pcPic->setUsedForTMVP ( true ); |
---|
| 1570 | |
---|
| 1571 | m_bFirst = false; |
---|
| 1572 | m_iNumPicCoded++; |
---|
| 1573 | |
---|
| 1574 | /* logging: insert a newline at end of picture period */ |
---|
| 1575 | printf("\n"); |
---|
| 1576 | fflush(stdout); |
---|
| 1577 | } |
---|
| 1578 | |
---|
| 1579 | delete[] pcSubstreamsOut; |
---|
| 1580 | delete pcBitstreamRedirect; |
---|
| 1581 | |
---|
[2] | 1582 | } |
---|
| 1583 | |
---|
[56] | 1584 | /** Memory allocation for APS |
---|
| 1585 | * \param [out] pAPS APS pointer |
---|
| 1586 | * \param [in] pSPS SPS pointer |
---|
| 1587 | */ |
---|
| 1588 | Void TEncGOP::allocAPS (TComAPS* pAPS, TComSPS* pSPS) |
---|
[2] | 1589 | { |
---|
[56] | 1590 | if(pSPS->getUseSAO()) |
---|
| 1591 | { |
---|
| 1592 | pAPS->createSaoParam(); |
---|
| 1593 | m_pcSAO->allocSaoParam(pAPS->getSaoParam()); |
---|
| 1594 | } |
---|
| 1595 | if(pSPS->getUseALF()) |
---|
| 1596 | { |
---|
| 1597 | pAPS->createAlfParam(); |
---|
| 1598 | #if LCU_SYNTAX_ALF |
---|
| 1599 | //alf Enabled flag in APS is false after pAPS->createAlfParam(); |
---|
| 1600 | if(!pSPS->getUseALFCoefInSlice()) |
---|
| 1601 | { |
---|
| 1602 | pAPS->getAlfParam()->create(m_pcAdaptiveLoopFilter->getNumLCUInPicWidth(), m_pcAdaptiveLoopFilter->getNumLCUInPicHeight(), m_pcAdaptiveLoopFilter->getNumCUsInPic()); |
---|
| 1603 | pAPS->getAlfParam()->createALFParam(); |
---|
| 1604 | } |
---|
| 1605 | #else |
---|
| 1606 | m_pcAdaptiveLoopFilter->allocALFParam(pAPS->getAlfParam()); |
---|
| 1607 | #endif |
---|
| 1608 | } |
---|
| 1609 | } |
---|
| 1610 | |
---|
| 1611 | /** Memory deallocation for APS |
---|
| 1612 | * \param [out] pAPS APS pointer |
---|
| 1613 | * \param [in] pSPS SPS pointer |
---|
| 1614 | */ |
---|
| 1615 | Void TEncGOP::freeAPS (TComAPS* pAPS, TComSPS* pSPS) |
---|
| 1616 | { |
---|
| 1617 | if(pSPS->getUseSAO()) |
---|
| 1618 | { |
---|
| 1619 | if(pAPS->getSaoParam() != NULL) |
---|
| 1620 | { |
---|
| 1621 | m_pcSAO->freeSaoParam(pAPS->getSaoParam()); |
---|
| 1622 | pAPS->destroySaoParam(); |
---|
| 1623 | |
---|
| 1624 | } |
---|
| 1625 | } |
---|
| 1626 | if(pSPS->getUseALF()) |
---|
| 1627 | { |
---|
| 1628 | if(pAPS->getAlfParam() != NULL) |
---|
| 1629 | { |
---|
| 1630 | #if LCU_SYNTAX_ALF |
---|
| 1631 | if(!pSPS->getUseALFCoefInSlice()) |
---|
| 1632 | { |
---|
| 1633 | pAPS->getAlfParam()->releaseALFParam(); |
---|
| 1634 | } |
---|
| 1635 | #else |
---|
| 1636 | m_pcAdaptiveLoopFilter->freeALFParam(pAPS->getAlfParam()); |
---|
| 1637 | #endif |
---|
| 1638 | pAPS->destroyAlfParam(); |
---|
| 1639 | } |
---|
| 1640 | } |
---|
| 1641 | } |
---|
| 1642 | |
---|
| 1643 | /** Assign APS object into APS container according to APS ID |
---|
| 1644 | * \param [in] cAPS APS object |
---|
| 1645 | * \param [in] apsID APS ID |
---|
| 1646 | * \param [in,out] vAPS APS container |
---|
| 1647 | * \param [in] pcSlice pointer to slice |
---|
| 1648 | */ |
---|
| 1649 | Void TEncGOP::assignNewAPS(TComAPS& cAPS, Int apsID, std::vector<TComAPS>& vAPS, TComSlice* pcSlice) |
---|
| 1650 | { |
---|
| 1651 | |
---|
| 1652 | cAPS.setAPSID(apsID); |
---|
| 1653 | if(pcSlice->getPOC() == 0) |
---|
| 1654 | { |
---|
| 1655 | cAPS.setScalingListEnabled(pcSlice->getSPS()->getScalingListFlag()); |
---|
| 1656 | } |
---|
| 1657 | else |
---|
| 1658 | { |
---|
| 1659 | cAPS.setScalingListEnabled(false); |
---|
| 1660 | } |
---|
| 1661 | |
---|
| 1662 | cAPS.setSaoEnabled(pcSlice->getSPS()->getUseSAO() ? (cAPS.getSaoParam()->bSaoFlag[0] ):(false)); |
---|
| 1663 | #if LCU_SYNTAX_ALF |
---|
| 1664 | cAPS.setAlfEnabled(pcSlice->getSPS()->getUseALF() ? (cAPS.getAlfParam()->isEnabled[0]):(false)); |
---|
| 1665 | #else |
---|
| 1666 | cAPS.setAlfEnabled(pcSlice->getSPS()->getUseALF() ? (cAPS.getAlfParam()->alf_flag ==1):(false)); |
---|
| 1667 | #endif |
---|
| 1668 | cAPS.setLoopFilterOffsetInAPS(m_pcCfg->getLoopFilterOffsetInAPS()); |
---|
| 1669 | cAPS.setLoopFilterDisable(m_pcCfg->getLoopFilterDisable()); |
---|
| 1670 | cAPS.setLoopFilterBetaOffset(m_pcCfg->getLoopFilterBetaOffset()); |
---|
| 1671 | cAPS.setLoopFilterTcOffset(m_pcCfg->getLoopFilterTcOffset()); |
---|
| 1672 | |
---|
| 1673 | //assign new APS into APS container |
---|
| 1674 | Int apsBufSize= (Int)vAPS.size(); |
---|
| 1675 | |
---|
| 1676 | if(apsID >= apsBufSize) |
---|
| 1677 | { |
---|
| 1678 | vAPS.resize(apsID +1); |
---|
| 1679 | } |
---|
| 1680 | |
---|
| 1681 | freeAPS(&(vAPS[apsID]), pcSlice->getSPS()); |
---|
| 1682 | vAPS[apsID] = cAPS; |
---|
| 1683 | } |
---|
| 1684 | |
---|
| 1685 | |
---|
| 1686 | /** encode APS syntax elements |
---|
| 1687 | * \param [in] pcAPS APS pointer |
---|
| 1688 | * \param [in, out] APSbs bitstream |
---|
| 1689 | * \param [in] pointer to slice (just used for entropy coder initialization) |
---|
| 1690 | */ |
---|
| 1691 | Void TEncGOP::encodeAPS(TComAPS* pcAPS, TComOutputBitstream& APSbs, TComSlice* pcSlice) |
---|
| 1692 | { |
---|
| 1693 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice); |
---|
| 1694 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1695 | m_pcEntropyCoder->setBitstream(&APSbs); |
---|
| 1696 | |
---|
| 1697 | m_pcEntropyCoder->encodeAPSInitInfo(pcAPS); |
---|
| 1698 | if(pcAPS->getScalingListEnabled()) |
---|
| 1699 | { |
---|
| 1700 | m_pcEntropyCoder->encodeScalingList( pcSlice->getScalingList() ); |
---|
| 1701 | } |
---|
| 1702 | if(pcAPS->getLoopFilterOffsetInAPS()) |
---|
| 1703 | { |
---|
| 1704 | m_pcEntropyCoder->encodeDFParams(pcAPS); |
---|
| 1705 | } |
---|
| 1706 | #if SAO_UNIT_INTERLEAVING |
---|
| 1707 | m_pcEntropyCoder->encodeSaoParam(pcAPS); |
---|
| 1708 | #else |
---|
| 1709 | if(pcAPS->getSaoEnabled()) |
---|
| 1710 | { |
---|
| 1711 | m_pcEntropyCoder->encodeSaoParam(pcAPS->getSaoParam()); |
---|
| 1712 | } |
---|
| 1713 | #endif |
---|
| 1714 | #if LCU_SYNTAX_ALF |
---|
| 1715 | m_pcEntropyCoder->encodeAPSAlfFlag( pcAPS->getAlfEnabled()?1:0); |
---|
| 1716 | #endif |
---|
| 1717 | if(pcAPS->getAlfEnabled()) |
---|
| 1718 | { |
---|
| 1719 | m_pcEntropyCoder->encodeAlfParam(pcAPS->getAlfParam()); |
---|
| 1720 | } |
---|
| 1721 | |
---|
| 1722 | m_pcEntropyCoder->encodeApsExtensionFlag(); |
---|
| 1723 | //neither SAO and ALF is enabled |
---|
| 1724 | writeRBSPTrailingBits(APSbs); |
---|
| 1725 | } |
---|
| 1726 | |
---|
| 1727 | Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits ) |
---|
| 1728 | { |
---|
[2] | 1729 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
| 1730 | Bool bCalcDist = false; |
---|
[56] | 1731 | #if DBL_CONTROL |
---|
| 1732 | m_pcLoopFilter->setCfg(pcSlice->getPPS()->getDeblockingFilterControlPresent(), pcSlice->getLoopFilterDisable(), m_pcCfg->getLoopFilterBetaOffset(), m_pcCfg->getLoopFilterTcOffset(), m_pcCfg->getLFCrossTileBoundaryFlag()); |
---|
| 1733 | #else |
---|
| 1734 | m_pcLoopFilter->setCfg(pcSlice->getLoopFilterDisable(), m_pcCfg->getLoopFilterBetaOffset(), m_pcCfg->getLoopFilterTcOffset(), m_pcCfg->getLFCrossTileBoundaryFlag()); |
---|
| 1735 | #endif |
---|
[2] | 1736 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
[56] | 1737 | |
---|
[2] | 1738 | m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice ); |
---|
| 1739 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1740 | m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); |
---|
[56] | 1741 | pcSlice = pcPic->getSlice(0); |
---|
| 1742 | if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()) |
---|
| 1743 | { |
---|
| 1744 | pcPic->createNonDBFilterInfo(); |
---|
| 1745 | } |
---|
| 1746 | |
---|
[2] | 1747 | // Adaptive Loop filter |
---|
| 1748 | if( pcSlice->getSPS()->getUseALF() ) |
---|
| 1749 | { |
---|
[56] | 1750 | m_pcAdaptiveLoopFilter->createPicAlfInfo(pcPic); |
---|
| 1751 | |
---|
| 1752 | #if LCU_SYNTAX_ALF |
---|
| 1753 | AlfParamSet* alfParamSet; |
---|
| 1754 | std::vector<AlfCUCtrlInfo>* alfCUCtrlParam = NULL; |
---|
| 1755 | alfParamSet= new AlfParamSet; |
---|
| 1756 | alfParamSet->create( m_pcAdaptiveLoopFilter->getNumLCUInPicWidth(), m_pcAdaptiveLoopFilter->getNumLCUInPicHeight(), m_pcAdaptiveLoopFilter->getNumCUsInPic()); |
---|
| 1757 | alfParamSet->createALFParam(); |
---|
| 1758 | m_pcAdaptiveLoopFilter->initALFEnc(false, true, 1, alfParamSet, alfCUCtrlParam); |
---|
| 1759 | #else |
---|
[2] | 1760 | ALFParam cAlfParam; |
---|
| 1761 | m_pcAdaptiveLoopFilter->allocALFParam(&cAlfParam); |
---|
[56] | 1762 | #endif |
---|
[2] | 1763 | m_pcAdaptiveLoopFilter->startALFEnc(pcPic, m_pcEntropyCoder); |
---|
[56] | 1764 | |
---|
[5] | 1765 | |
---|
[56] | 1766 | #if LCU_SYNTAX_ALF |
---|
| 1767 | |
---|
| 1768 | #if ALF_CHROMA_LAMBDA |
---|
| 1769 | #if HHI_INTERVIEW_SKIP |
---|
| 1770 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), m_pcEncTop->getInterViewSkip() ); |
---|
| 1771 | #else |
---|
| 1772 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma() ); |
---|
| 1773 | #endif |
---|
| 1774 | #else |
---|
| 1775 | #if SAO_CHROMA_LAMBDA |
---|
| 1776 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambdaLuma(), m_pcEncTop->getInterViewSkip()); |
---|
| 1777 | #if HHI_INTERVIEW_SKIP |
---|
| 1778 | #else |
---|
| 1779 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambdaLuma()); |
---|
| 1780 | #endif |
---|
| 1781 | #else |
---|
| 1782 | #if HHI_INTERVIEW_SKIP |
---|
| 1783 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambda(), m_pcEncTop->getInterViewSkip()); |
---|
| 1784 | #else |
---|
| 1785 | m_pcAdaptiveLoopFilter->ALFProcess(alfParamSet, NULL, pcPic->getSlice(0)->getLambda()); |
---|
| 1786 | #endif |
---|
| 1787 | #endif |
---|
| 1788 | #endif |
---|
| 1789 | |
---|
| 1790 | #else |
---|
| 1791 | #if ALF_CHROMA_LAMBDA |
---|
| 1792 | m_pcAdaptiveLoopFilter->ALFProcess(&cAlfParam, NULL, pcSlice->getLambdaLuma(), pcSlice->getLambdaChroma(), ruiDist, ruiBits, m_pcEncTop->getInterViewSkip()); |
---|
| 1793 | #if HHI_INTERVIEW_SKIP |
---|
| 1794 | #else |
---|
| 1795 | m_pcAdaptiveLoopFilter->ALFProcess(&cAlfParam, NULL, pcSlice->getLambdaLuma(), pcSlice->getLambdaChroma(), ruiDist, ruiBits); |
---|
| 1796 | #endif |
---|
| 1797 | #else |
---|
| 1798 | #if SAO_CHROMA_LAMBDA |
---|
| 1799 | #if HHI_INTERVIEW_SKIP |
---|
| 1800 | m_pcAdaptiveLoopFilter->ALFProcess(&cAlfParam, NULL, pcSlice->getLambdaLuma(), ruiDist, ruiBits, m_pcEncTop->getInterViewSkip()); |
---|
| 1801 | #else |
---|
| 1802 | m_pcAdaptiveLoopFilter->ALFProcess(&cAlfParam, NULL, pcSlice->getLambdaLuma(), ruiDist, ruiBits); |
---|
| 1803 | #endif |
---|
| 1804 | #else |
---|
| 1805 | #if HHI_INTERVIEW_SKIP |
---|
| 1806 | m_pcAdaptiveLoopFilter->ALFProcess(&cAlfParam, NULL, pcSlice->getLambda(), ruiDist, ruiBits, m_pcEncTop->getInterViewSkip()); |
---|
| 1807 | #else |
---|
| 1808 | m_pcAdaptiveLoopFilter->ALFProcess(&cAlfParam, NULL, pcSlice->getLambda(), ruiDist, ruiBits); |
---|
| 1809 | #endif |
---|
| 1810 | #endif |
---|
| 1811 | |
---|
| 1812 | #endif |
---|
| 1813 | #endif |
---|
[2] | 1814 | m_pcAdaptiveLoopFilter->endALFEnc(); |
---|
[56] | 1815 | |
---|
| 1816 | #if LCU_SYNTAX_ALF |
---|
| 1817 | alfParamSet->releaseALFParam(); |
---|
| 1818 | delete alfParamSet; |
---|
| 1819 | delete alfCUCtrlParam; |
---|
| 1820 | #else |
---|
[2] | 1821 | m_pcAdaptiveLoopFilter->freeALFParam(&cAlfParam); |
---|
[56] | 1822 | #endif |
---|
| 1823 | m_pcAdaptiveLoopFilter->PCMLFDisableProcess(pcPic); |
---|
| 1824 | m_pcAdaptiveLoopFilter->destroyPicAlfInfo(); |
---|
[2] | 1825 | } |
---|
[56] | 1826 | if( pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()) |
---|
| 1827 | { |
---|
| 1828 | pcPic->destroyNonDBFilterInfo(); |
---|
| 1829 | } |
---|
| 1830 | |
---|
[2] | 1831 | m_pcEntropyCoder->resetEntropy (); |
---|
| 1832 | ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[56] | 1833 | |
---|
[2] | 1834 | if (!bCalcDist) |
---|
| 1835 | ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec()); |
---|
| 1836 | } |
---|
| 1837 | |
---|
| 1838 | // ==================================================================================================================== |
---|
| 1839 | // Protected member functions |
---|
| 1840 | // ==================================================================================================================== |
---|
| 1841 | |
---|
[56] | 1842 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ) |
---|
[2] | 1843 | { |
---|
[56] | 1844 | assert( iNumPicRcvd > 0 ); |
---|
| 1845 | // Exception for the first frame |
---|
| 1846 | if ( iPOCLast == 0 ) |
---|
| 1847 | { |
---|
| 1848 | m_iGopSize = 1; |
---|
| 1849 | } |
---|
| 1850 | else |
---|
| 1851 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
| 1852 | |
---|
| 1853 | assert (m_iGopSize > 0); |
---|
| 1854 | |
---|
| 1855 | return; |
---|
| 1856 | } |
---|
| 1857 | |
---|
| 1858 | Void TEncGOP::xGetBuffer( TComList<TComPic*>& rcListPic, |
---|
| 1859 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
| 1860 | Int iNumPicRcvd, |
---|
| 1861 | Int iTimeOffset, |
---|
| 1862 | TComPic*& rpcPic, |
---|
| 1863 | TComPicYuv*& rpcPicYuvRecOut, |
---|
| 1864 | UInt uiPOCCurr ) |
---|
| 1865 | { |
---|
| 1866 | Int i; |
---|
| 1867 | // Rec. output |
---|
| 1868 | TComList<TComPicYuv*>::iterator iterPicYuvRec = rcListPicYuvRecOut.end(); |
---|
| 1869 | for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ ) |
---|
| 1870 | { |
---|
| 1871 | iterPicYuvRec--; |
---|
| 1872 | } |
---|
| 1873 | |
---|
| 1874 | rpcPicYuvRecOut = *(iterPicYuvRec); |
---|
| 1875 | |
---|
| 1876 | // Current pic. |
---|
| 1877 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
| 1878 | while (iterPic != rcListPic.end()) |
---|
| 1879 | { |
---|
| 1880 | rpcPic = *(iterPic); |
---|
| 1881 | rpcPic->setCurrSliceIdx(0); |
---|
| 1882 | if (rpcPic->getPOC() == (Int)uiPOCCurr) |
---|
| 1883 | { |
---|
| 1884 | break; |
---|
| 1885 | } |
---|
| 1886 | iterPic++; |
---|
| 1887 | } |
---|
| 1888 | |
---|
| 1889 | assert (rpcPic->getPOC() == (Int)uiPOCCurr); |
---|
| 1890 | |
---|
| 1891 | return; |
---|
| 1892 | } |
---|
| 1893 | |
---|
| 1894 | UInt64 TEncGOP::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1) |
---|
| 1895 | { |
---|
[2] | 1896 | Int x, y; |
---|
| 1897 | Pel* pSrc0 = pcPic0 ->getLumaAddr(); |
---|
| 1898 | Pel* pSrc1 = pcPic1 ->getLumaAddr(); |
---|
| 1899 | #if IBDI_DISTORTION |
---|
| 1900 | Int iShift = g_uiBitIncrement; |
---|
| 1901 | Int iOffset = 1<<(g_uiBitIncrement-1); |
---|
| 1902 | #else |
---|
| 1903 | UInt uiShift = g_uiBitIncrement<<1; |
---|
| 1904 | #endif |
---|
| 1905 | Int iTemp; |
---|
[56] | 1906 | |
---|
[2] | 1907 | Int iStride = pcPic0->getStride(); |
---|
| 1908 | Int iWidth = pcPic0->getWidth(); |
---|
| 1909 | Int iHeight = pcPic0->getHeight(); |
---|
[56] | 1910 | |
---|
[2] | 1911 | UInt64 uiTotalDiff = 0; |
---|
[56] | 1912 | |
---|
[2] | 1913 | for( y = 0; y < iHeight; y++ ) |
---|
| 1914 | { |
---|
| 1915 | for( x = 0; x < iWidth; x++ ) |
---|
| 1916 | { |
---|
| 1917 | #if IBDI_DISTORTION |
---|
| 1918 | iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp; |
---|
| 1919 | #else |
---|
| 1920 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 1921 | #endif |
---|
| 1922 | } |
---|
| 1923 | pSrc0 += iStride; |
---|
| 1924 | pSrc1 += iStride; |
---|
| 1925 | } |
---|
[56] | 1926 | |
---|
[2] | 1927 | iHeight >>= 1; |
---|
| 1928 | iWidth >>= 1; |
---|
| 1929 | iStride >>= 1; |
---|
[56] | 1930 | |
---|
[2] | 1931 | pSrc0 = pcPic0->getCbAddr(); |
---|
| 1932 | pSrc1 = pcPic1->getCbAddr(); |
---|
[56] | 1933 | |
---|
[2] | 1934 | for( y = 0; y < iHeight; y++ ) |
---|
| 1935 | { |
---|
| 1936 | for( x = 0; x < iWidth; x++ ) |
---|
| 1937 | { |
---|
| 1938 | #if IBDI_DISTORTION |
---|
| 1939 | iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp; |
---|
| 1940 | #else |
---|
| 1941 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 1942 | #endif |
---|
| 1943 | } |
---|
| 1944 | pSrc0 += iStride; |
---|
| 1945 | pSrc1 += iStride; |
---|
| 1946 | } |
---|
[56] | 1947 | |
---|
[2] | 1948 | pSrc0 = pcPic0->getCrAddr(); |
---|
| 1949 | pSrc1 = pcPic1->getCrAddr(); |
---|
[56] | 1950 | |
---|
[2] | 1951 | for( y = 0; y < iHeight; y++ ) |
---|
| 1952 | { |
---|
| 1953 | for( x = 0; x < iWidth; x++ ) |
---|
| 1954 | { |
---|
| 1955 | #if IBDI_DISTORTION |
---|
| 1956 | iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp; |
---|
| 1957 | #else |
---|
| 1958 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 1959 | #endif |
---|
| 1960 | } |
---|
| 1961 | pSrc0 += iStride; |
---|
| 1962 | pSrc1 += iStride; |
---|
| 1963 | } |
---|
[56] | 1964 | |
---|
[2] | 1965 | return uiTotalDiff; |
---|
| 1966 | } |
---|
| 1967 | |
---|
[56] | 1968 | #if VERBOSE_RATE |
---|
| 1969 | static const char* nalUnitTypeToString(NalUnitType type) |
---|
[2] | 1970 | { |
---|
[56] | 1971 | switch (type) |
---|
| 1972 | { |
---|
| 1973 | case NAL_UNIT_CODED_SLICE: return "SLICE"; |
---|
| 1974 | #if H0566_TLA |
---|
| 1975 | case NAL_UNIT_CODED_SLICE_IDV: return "IDV"; |
---|
| 1976 | case NAL_UNIT_CODED_SLICE_CRA: return "CRA"; |
---|
| 1977 | case NAL_UNIT_CODED_SLICE_TLA: return "TLA"; |
---|
| 1978 | #else |
---|
| 1979 | case NAL_UNIT_CODED_SLICE_CDR: return "CDR"; |
---|
| 1980 | #endif |
---|
| 1981 | case NAL_UNIT_CODED_SLICE_IDR: return "IDR"; |
---|
| 1982 | case NAL_UNIT_SEI: return "SEI"; |
---|
| 1983 | case NAL_UNIT_SPS: return "SPS"; |
---|
| 1984 | case NAL_UNIT_PPS: return "PPS"; |
---|
| 1985 | case NAL_UNIT_FILLER_DATA: return "FILLER"; |
---|
| 1986 | default: return "UNK"; |
---|
| 1987 | } |
---|
| 1988 | } |
---|
| 1989 | #endif |
---|
| 1990 | |
---|
| 1991 | Void TEncGOP::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit& accessUnit, Double dEncTime ) |
---|
| 1992 | { |
---|
[2] | 1993 | Int x, y; |
---|
| 1994 | UInt64 uiSSDY = 0; |
---|
| 1995 | UInt64 uiSSDU = 0; |
---|
| 1996 | UInt64 uiSSDV = 0; |
---|
[56] | 1997 | |
---|
[2] | 1998 | Double dYPSNR = 0.0; |
---|
| 1999 | Double dUPSNR = 0.0; |
---|
| 2000 | Double dVPSNR = 0.0; |
---|
[56] | 2001 | |
---|
[2] | 2002 | //===== calculate PSNR ===== |
---|
| 2003 | Pel* pOrg = pcPic ->getPicYuvOrg()->getLumaAddr(); |
---|
| 2004 | Pel* pRec = pcPicD->getLumaAddr(); |
---|
| 2005 | Int iStride = pcPicD->getStride(); |
---|
[56] | 2006 | |
---|
[2] | 2007 | Int iWidth; |
---|
| 2008 | Int iHeight; |
---|
[56] | 2009 | |
---|
[2] | 2010 | iWidth = pcPicD->getWidth () - m_pcEncTop->getPad(0); |
---|
| 2011 | iHeight = pcPicD->getHeight() - m_pcEncTop->getPad(1); |
---|
[56] | 2012 | |
---|
[2] | 2013 | Int iSize = iWidth*iHeight; |
---|
[56] | 2014 | |
---|
[2] | 2015 | for( y = 0; y < iHeight; y++ ) |
---|
| 2016 | { |
---|
| 2017 | for( x = 0; x < iWidth; x++ ) |
---|
| 2018 | { |
---|
| 2019 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 2020 | uiSSDY += iDiff * iDiff; |
---|
| 2021 | } |
---|
| 2022 | pOrg += iStride; |
---|
| 2023 | pRec += iStride; |
---|
| 2024 | } |
---|
[56] | 2025 | |
---|
| 2026 | #if HHI_VSO |
---|
[77] | 2027 | #if HHI_VSO_SYNTH_DIST_OUT |
---|
[2] | 2028 | if ( m_pcRdCost->getUseRenModel() ) |
---|
| 2029 | { |
---|
[56] | 2030 | unsigned int maxval = 255 * (1<<(g_uiBitDepth + g_uiBitIncrement -8)); |
---|
| 2031 | Double fRefValueY = (double) maxval * maxval * iSize; |
---|
| 2032 | Double fRefValueC = fRefValueY / 4.0; |
---|
[5] | 2033 | TRenModel* pcRenModel = m_pcEncTop->getEncTop()->getRenModel(); |
---|
| 2034 | Int64 iDistVSOY, iDistVSOU, iDistVSOV; |
---|
| 2035 | pcRenModel->getTotalSSE( iDistVSOY, iDistVSOU, iDistVSOV ); |
---|
[2] | 2036 | dYPSNR = ( iDistVSOY ? 10.0 * log10( fRefValueY / (Double) iDistVSOY ) : 99.99 ); |
---|
| 2037 | dUPSNR = ( iDistVSOU ? 10.0 * log10( fRefValueC / (Double) iDistVSOU ) : 99.99 ); |
---|
| 2038 | dVPSNR = ( iDistVSOV ? 10.0 * log10( fRefValueC / (Double) iDistVSOV ) : 99.99 ); |
---|
| 2039 | } |
---|
| 2040 | else |
---|
[5] | 2041 | #endif |
---|
[77] | 2042 | #endif |
---|
[5] | 2043 | { |
---|
[2] | 2044 | iHeight >>= 1; |
---|
| 2045 | iWidth >>= 1; |
---|
| 2046 | iStride >>= 1; |
---|
| 2047 | pOrg = pcPic ->getPicYuvOrg()->getCbAddr(); |
---|
| 2048 | pRec = pcPicD->getCbAddr(); |
---|
[56] | 2049 | |
---|
[2] | 2050 | for( y = 0; y < iHeight; y++ ) |
---|
| 2051 | { |
---|
| 2052 | for( x = 0; x < iWidth; x++ ) |
---|
| 2053 | { |
---|
| 2054 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 2055 | uiSSDU += iDiff * iDiff; |
---|
| 2056 | } |
---|
| 2057 | pOrg += iStride; |
---|
| 2058 | pRec += iStride; |
---|
| 2059 | } |
---|
[56] | 2060 | |
---|
[2] | 2061 | pOrg = pcPic ->getPicYuvOrg()->getCrAddr(); |
---|
| 2062 | pRec = pcPicD->getCrAddr(); |
---|
[56] | 2063 | |
---|
[2] | 2064 | for( y = 0; y < iHeight; y++ ) |
---|
| 2065 | { |
---|
| 2066 | for( x = 0; x < iWidth; x++ ) |
---|
| 2067 | { |
---|
| 2068 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 2069 | uiSSDV += iDiff * iDiff; |
---|
| 2070 | } |
---|
| 2071 | pOrg += iStride; |
---|
| 2072 | pRec += iStride; |
---|
| 2073 | } |
---|
[56] | 2074 | |
---|
| 2075 | unsigned int maxval = 255 * (1<<(g_uiBitDepth + g_uiBitIncrement -8)); |
---|
| 2076 | Double fRefValueY = (double) maxval * maxval * iSize; |
---|
| 2077 | Double fRefValueC = fRefValueY / 4.0; |
---|
[2] | 2078 | dYPSNR = ( uiSSDY ? 10.0 * log10( fRefValueY / (Double)uiSSDY ) : 99.99 ); |
---|
| 2079 | dUPSNR = ( uiSSDU ? 10.0 * log10( fRefValueC / (Double)uiSSDU ) : 99.99 ); |
---|
| 2080 | dVPSNR = ( uiSSDV ? 10.0 * log10( fRefValueC / (Double)uiSSDV ) : 99.99 ); |
---|
| 2081 | } |
---|
[56] | 2082 | /* calculate the size of the access unit, excluding: |
---|
| 2083 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
| 2084 | * - SEI NAL units |
---|
| 2085 | */ |
---|
| 2086 | unsigned numRBSPBytes = 0; |
---|
| 2087 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
| 2088 | { |
---|
| 2089 | unsigned numRBSPBytes_nal = unsigned((*it)->m_nalUnitData.str().size()); |
---|
| 2090 | #if VERBOSE_RATE |
---|
| 2091 | printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal); |
---|
| 2092 | #endif |
---|
| 2093 | if ((*it)->m_nalUnitType != NAL_UNIT_SEI) |
---|
| 2094 | numRBSPBytes += numRBSPBytes_nal; |
---|
| 2095 | } |
---|
[5] | 2096 | |
---|
[56] | 2097 | unsigned uibits = numRBSPBytes * 8; |
---|
[2] | 2098 | m_vRVM_RP.push_back( uibits ); |
---|
| 2099 | |
---|
| 2100 | //===== add PSNR ===== |
---|
[56] | 2101 | m_pcEncTop->getAnalyzeAll()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
[2] | 2102 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
| 2103 | if (pcSlice->isIntra()) |
---|
| 2104 | { |
---|
[56] | 2105 | m_pcEncTop->getAnalyzeI()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
[2] | 2106 | } |
---|
| 2107 | if (pcSlice->isInterP()) |
---|
| 2108 | { |
---|
[56] | 2109 | m_pcEncTop->getAnalyzeP()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
[2] | 2110 | } |
---|
| 2111 | if (pcSlice->isInterB()) |
---|
| 2112 | { |
---|
[56] | 2113 | m_pcEncTop->getAnalyzeB()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
[2] | 2114 | } |
---|
| 2115 | |
---|
[56] | 2116 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
| 2117 | if (!pcSlice->isReferenced()) c += 32; |
---|
[5] | 2118 | |
---|
[56] | 2119 | #if ADAPTIVE_QP_SELECTION |
---|
| 2120 | printf("%s View %3d POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
| 2121 | pcSlice->getIsDepth() ? "Depth " : "Texture", |
---|
| 2122 | pcSlice->getViewId(), |
---|
| 2123 | pcSlice->getPOC(), |
---|
| 2124 | pcSlice->getTLayer(), |
---|
| 2125 | c, |
---|
| 2126 | pcSlice->getSliceQpBase(), |
---|
| 2127 | pcSlice->getSliceQp(), |
---|
| 2128 | uibits ); |
---|
| 2129 | #else |
---|
| 2130 | printf("%s View %3d POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
| 2131 | pcSlice->getIsDepth() ? "Depth " : "Texture", |
---|
| 2132 | pcSlice->getViewId(), |
---|
| 2133 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
| 2134 | pcSlice->getTLayer(), |
---|
| 2135 | c, |
---|
| 2136 | pcSlice->getSliceQp(), |
---|
| 2137 | uibits ); |
---|
| 2138 | #endif |
---|
| 2139 | |
---|
| 2140 | printf(" [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", dYPSNR, dUPSNR, dVPSNR ); |
---|
| 2141 | printf(" [ET %5.0f ]", dEncTime ); |
---|
| 2142 | |
---|
[2] | 2143 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
| 2144 | { |
---|
[56] | 2145 | printf(" [L%d ", iRefList); |
---|
[2] | 2146 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
| 2147 | { |
---|
[56] | 2148 | if( pcSlice->getViewId() != pcSlice->getRefViewId( RefPicList(iRefList), iRefIndex ) ) |
---|
[2] | 2149 | { |
---|
[56] | 2150 | printf( "V%d ", pcSlice->getRefViewId( RefPicList(iRefList), iRefIndex ) ); |
---|
[2] | 2151 | } |
---|
| 2152 | else |
---|
[56] | 2153 | { |
---|
| 2154 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
| 2155 | } |
---|
[2] | 2156 | } |
---|
[56] | 2157 | printf("]"); |
---|
[2] | 2158 | } |
---|
| 2159 | if(pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0 && !pcSlice->getNoBackPredFlag()) |
---|
| 2160 | { |
---|
[56] | 2161 | printf(" [LC "); |
---|
[2] | 2162 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(REF_PIC_LIST_C); iRefIndex++) |
---|
| 2163 | { |
---|
[56] | 2164 | if( pcSlice->getViewId() != pcSlice->getRefViewId( (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex) ) ) |
---|
| 2165 | { |
---|
| 2166 | printf( "V%d ", pcSlice->getRefViewId( (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex) ) ); |
---|
| 2167 | } |
---|
| 2168 | else |
---|
| 2169 | { |
---|
| 2170 | printf ("%d ", pcSlice->getRefPOC((RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex))-pcSlice->getLastIDR()); |
---|
| 2171 | } |
---|
[2] | 2172 | } |
---|
[56] | 2173 | printf("]"); |
---|
[2] | 2174 | } |
---|
| 2175 | } |
---|
| 2176 | |
---|
| 2177 | /** Function for deciding the nal_unit_type. |
---|
| 2178 | * \param uiPOCCurr POC of the current picture |
---|
| 2179 | * \returns the nal_unit type of the picture |
---|
| 2180 | * This function checks the configuration and returns the appropriate nal_unit_type for the picture. |
---|
| 2181 | */ |
---|
[56] | 2182 | NalUnitType TEncGOP::getNalUnitType(UInt uiPOCCurr) |
---|
[2] | 2183 | { |
---|
[56] | 2184 | 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') ); |
---|
| 2185 | |
---|
[2] | 2186 | if (uiPOCCurr == 0) |
---|
| 2187 | { |
---|
[56] | 2188 | if( bInterViewOnlySlice ) |
---|
| 2189 | { |
---|
| 2190 | return NAL_UNIT_CODED_SLICE_IDV; |
---|
| 2191 | } |
---|
| 2192 | else |
---|
| 2193 | { |
---|
| 2194 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 2195 | } |
---|
[2] | 2196 | } |
---|
| 2197 | if (uiPOCCurr % m_pcCfg->getIntraPeriod() == 0) |
---|
| 2198 | { |
---|
| 2199 | if (m_pcCfg->getDecodingRefreshType() == 1) |
---|
| 2200 | { |
---|
[56] | 2201 | if( bInterViewOnlySlice ) |
---|
| 2202 | { |
---|
| 2203 | return NAL_UNIT_CODED_SLICE_IDV; |
---|
| 2204 | } |
---|
| 2205 | else |
---|
| 2206 | { |
---|
| 2207 | #if H0566_TLA |
---|
| 2208 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
| 2209 | #else |
---|
[2] | 2210 | return NAL_UNIT_CODED_SLICE_CDR; |
---|
[56] | 2211 | #endif |
---|
| 2212 | } |
---|
[2] | 2213 | } |
---|
| 2214 | else if (m_pcCfg->getDecodingRefreshType() == 2) |
---|
| 2215 | { |
---|
[56] | 2216 | if( bInterViewOnlySlice ) |
---|
| 2217 | { |
---|
| 2218 | return NAL_UNIT_CODED_SLICE_IDV; |
---|
| 2219 | } |
---|
| 2220 | else |
---|
| 2221 | { |
---|
| 2222 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 2223 | } |
---|
| 2224 | } |
---|
| 2225 | } |
---|
| 2226 | return NAL_UNIT_CODED_SLICE; |
---|
| 2227 | } |
---|
| 2228 | |
---|
| 2229 | NalUnitType TEncGOP::getNalUnitTypeBaseViewMvc(UInt uiPOCCurr) |
---|
| 2230 | { |
---|
| 2231 | if( uiPOCCurr == 0 ) |
---|
| 2232 | { |
---|
| 2233 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 2234 | } |
---|
| 2235 | if( uiPOCCurr % m_pcCfg->getIntraPeriod() == 0 ) |
---|
| 2236 | { |
---|
| 2237 | if( m_pcCfg->getDecodingRefreshType() == 1 ) |
---|
| 2238 | { |
---|
| 2239 | #if H0566_TLA |
---|
| 2240 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
| 2241 | #else |
---|
| 2242 | return NAL_UNIT_CODED_SLICE_CDR; |
---|
| 2243 | #endif |
---|
| 2244 | } |
---|
| 2245 | else if( m_pcCfg->getDecodingRefreshType() == 2 ) |
---|
| 2246 | { |
---|
[2] | 2247 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
| 2248 | } |
---|
| 2249 | } |
---|
| 2250 | return NAL_UNIT_CODED_SLICE; |
---|
| 2251 | } |
---|
| 2252 | |
---|
[56] | 2253 | Double TEncGOP::xCalculateRVM() |
---|
[2] | 2254 | { |
---|
| 2255 | Double dRVM = 0; |
---|
[56] | 2256 | |
---|
| 2257 | if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFrameToBeEncoded() > RVM_VCEGAM10_M * 2 ) |
---|
[2] | 2258 | { |
---|
| 2259 | // calculate RVM only for lowdelay configurations |
---|
| 2260 | std::vector<Double> vRL , vB; |
---|
| 2261 | size_t N = m_vRVM_RP.size(); |
---|
| 2262 | vRL.resize( N ); |
---|
| 2263 | vB.resize( N ); |
---|
[56] | 2264 | |
---|
[2] | 2265 | Int i; |
---|
| 2266 | Double dRavg = 0 , dBavg = 0; |
---|
| 2267 | vB[RVM_VCEGAM10_M] = 0; |
---|
| 2268 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
| 2269 | { |
---|
| 2270 | vRL[i] = 0; |
---|
| 2271 | for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ ) |
---|
| 2272 | vRL[i] += m_vRVM_RP[j]; |
---|
| 2273 | vRL[i] /= ( 2 * RVM_VCEGAM10_M ); |
---|
| 2274 | vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i]; |
---|
| 2275 | dRavg += m_vRVM_RP[i]; |
---|
| 2276 | dBavg += vB[i]; |
---|
| 2277 | } |
---|
[56] | 2278 | |
---|
[2] | 2279 | dRavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
| 2280 | dBavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
[56] | 2281 | |
---|
[2] | 2282 | double dSigamB = 0; |
---|
| 2283 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
| 2284 | { |
---|
| 2285 | Double tmp = vB[i] - dBavg; |
---|
| 2286 | dSigamB += tmp * tmp; |
---|
| 2287 | } |
---|
| 2288 | dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) ); |
---|
[56] | 2289 | |
---|
[2] | 2290 | double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) ); |
---|
[56] | 2291 | |
---|
[2] | 2292 | dRVM = dSigamB / dRavg * f; |
---|
| 2293 | } |
---|
[56] | 2294 | |
---|
[2] | 2295 | return( dRVM ); |
---|
| 2296 | } |
---|
[56] | 2297 | |
---|
| 2298 | /** Determine the difference between consecutive tile sizes (in bytes) and writes it to bistream rNalu [slice header] |
---|
| 2299 | * \param rpcBitstreamRedirect contains the bitstream to be concatenated to rNalu. rpcBitstreamRedirect contains slice payload. rpcSlice contains tile location information. |
---|
| 2300 | * \returns Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. |
---|
| 2301 | */ |
---|
| 2302 | Void TEncGOP::xWriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice) |
---|
| 2303 | { |
---|
| 2304 | { |
---|
| 2305 | #if !TILES_WPP_ENTRY_POINT_SIGNALLING |
---|
| 2306 | Int iTransmitTileLocationInSliceHeader = (rpcSlice->getTileLocationCount()==0 || m_pcCfg->getTileLocationInSliceHeaderFlag()==0) ? 0 : 1; |
---|
| 2307 | rNalu.m_Bitstream.write(iTransmitTileLocationInSliceHeader, 1); // write flag indicating whether tile location information communicated in slice header |
---|
| 2308 | |
---|
| 2309 | if (iTransmitTileLocationInSliceHeader) |
---|
| 2310 | { |
---|
| 2311 | rNalu.m_Bitstream.write(rpcSlice->getTileLocationCount()-1, 5); // write number of tiles |
---|
| 2312 | |
---|
| 2313 | Int *aiDiff; |
---|
| 2314 | aiDiff = new Int [rpcSlice->getTileLocationCount()]; |
---|
| 2315 | |
---|
| 2316 | // Find largest number of bits required by Diff |
---|
| 2317 | Int iLastSize = 0, iDiffMax = 0, iDiffMin = 0; |
---|
| 2318 | for (UInt uiIdx=0; uiIdx<rpcSlice->getTileLocationCount(); uiIdx++) |
---|
| 2319 | { |
---|
| 2320 | Int iCurDiff, iCurSize; |
---|
| 2321 | if (uiIdx==0) |
---|
| 2322 | { |
---|
| 2323 | iCurDiff = rpcSlice->getTileLocation( uiIdx ); |
---|
| 2324 | iLastSize = rpcSlice->getTileLocation( uiIdx ); |
---|
| 2325 | } |
---|
| 2326 | else |
---|
| 2327 | { |
---|
| 2328 | iCurSize = rpcSlice->getTileLocation( uiIdx ) - rpcSlice->getTileLocation( uiIdx-1 ); |
---|
| 2329 | iCurDiff = iCurSize - iLastSize; |
---|
| 2330 | iLastSize = iCurSize; |
---|
| 2331 | } |
---|
| 2332 | // Store Diff so it may be written to slice header later without re-calculating. |
---|
| 2333 | aiDiff[uiIdx] = iCurDiff; |
---|
| 2334 | |
---|
| 2335 | if (iCurDiff>iDiffMax) |
---|
| 2336 | { |
---|
| 2337 | iDiffMax = iCurDiff; |
---|
| 2338 | } |
---|
| 2339 | if (iCurDiff<iDiffMin) |
---|
| 2340 | { |
---|
| 2341 | iDiffMin = iCurDiff; |
---|
| 2342 | } |
---|
| 2343 | } |
---|
| 2344 | |
---|
| 2345 | Int iDiffMinAbs, iDiffMaxAbs; |
---|
| 2346 | iDiffMinAbs = (iDiffMin<0) ? (-iDiffMin) : iDiffMin; |
---|
| 2347 | iDiffMaxAbs = (iDiffMax<0) ? (-iDiffMax) : iDiffMax; |
---|
| 2348 | |
---|
| 2349 | Int iBitsUsedByDiff = 0, iDiffAbsLargest; |
---|
| 2350 | iDiffAbsLargest = (iDiffMinAbs < iDiffMaxAbs) ? iDiffMaxAbs : iDiffMinAbs; |
---|
| 2351 | while (1) |
---|
| 2352 | { |
---|
| 2353 | if (iDiffAbsLargest >= (1 << iBitsUsedByDiff) ) |
---|
| 2354 | { |
---|
| 2355 | iBitsUsedByDiff++; |
---|
| 2356 | } |
---|
| 2357 | else |
---|
| 2358 | { |
---|
| 2359 | break; |
---|
| 2360 | } |
---|
| 2361 | } |
---|
| 2362 | iBitsUsedByDiff++; |
---|
| 2363 | |
---|
| 2364 | if (iBitsUsedByDiff > 32) |
---|
| 2365 | { |
---|
| 2366 | printf("\nDiff magnitude uses more than 32-bits"); |
---|
| 2367 | assert ( 0 ); |
---|
| 2368 | exit ( 0 ); // trying to catch any problems with using fixed bits for Diff information |
---|
| 2369 | } |
---|
| 2370 | |
---|
| 2371 | rNalu.m_Bitstream.write( iBitsUsedByDiff-1, 5 ); // write number of bits used by Diff |
---|
| 2372 | |
---|
| 2373 | // Write diff to slice header (rNalu) |
---|
| 2374 | for (UInt uiIdx=0; uiIdx<rpcSlice->getTileLocationCount(); uiIdx++) |
---|
| 2375 | { |
---|
| 2376 | Int iCurDiff = aiDiff[uiIdx]; |
---|
| 2377 | |
---|
| 2378 | // write sign of diff |
---|
| 2379 | if (uiIdx!=0) |
---|
| 2380 | { |
---|
| 2381 | if (iCurDiff<0) |
---|
| 2382 | { |
---|
| 2383 | rNalu.m_Bitstream.write(1, 1); |
---|
| 2384 | } |
---|
| 2385 | else |
---|
| 2386 | { |
---|
| 2387 | rNalu.m_Bitstream.write(0, 1); |
---|
| 2388 | } |
---|
| 2389 | } |
---|
| 2390 | |
---|
| 2391 | // write abs value of diff |
---|
| 2392 | Int iAbsDiff = (iCurDiff<0) ? (-iCurDiff) : iCurDiff; |
---|
| 2393 | if (iAbsDiff > ((((UInt64)1)<<32)-1)) |
---|
| 2394 | { |
---|
| 2395 | printf("\niAbsDiff exceeds 32-bit limit"); |
---|
| 2396 | exit(0); |
---|
| 2397 | } |
---|
| 2398 | rNalu.m_Bitstream.write( iAbsDiff, iBitsUsedByDiff-1 ); |
---|
| 2399 | } |
---|
| 2400 | |
---|
| 2401 | delete [] aiDiff; |
---|
| 2402 | } |
---|
[2] | 2403 | #endif |
---|
[56] | 2404 | } |
---|
[2] | 2405 | |
---|
[56] | 2406 | // Byte-align |
---|
| 2407 | rNalu.m_Bitstream.writeAlignOne(); |
---|
| 2408 | |
---|
| 2409 | // Update tile marker locations |
---|
| 2410 | TComOutputBitstream *pcOut = &rNalu.m_Bitstream; |
---|
| 2411 | UInt uiAccumulatedLength = pcOut->getNumberOfWrittenBits() >> 3; |
---|
| 2412 | for (Int uiMrkIdx = 0; uiMrkIdx < rpcBitstreamRedirect->getTileMarkerLocationCount(); uiMrkIdx++) |
---|
| 2413 | { |
---|
| 2414 | UInt uiBottom = pcOut->getTileMarkerLocationCount(); |
---|
| 2415 | pcOut->setTileMarkerLocation ( uiBottom, uiAccumulatedLength + rpcBitstreamRedirect->getTileMarkerLocation( uiMrkIdx ) ); |
---|
| 2416 | pcOut->setTileMarkerLocationCount ( uiBottom + 1 ); |
---|
| 2417 | } |
---|
| 2418 | |
---|
| 2419 | // Perform bitstream concatenation |
---|
| 2420 | if (rpcBitstreamRedirect->getNumberOfWrittenBits() > 0) |
---|
| 2421 | { |
---|
| 2422 | UInt uiBitCount = rpcBitstreamRedirect->getNumberOfWrittenBits(); |
---|
| 2423 | if (rpcBitstreamRedirect->getByteStreamLength()>0) |
---|
| 2424 | { |
---|
| 2425 | UChar *pucStart = reinterpret_cast<UChar*>(rpcBitstreamRedirect->getByteStream()); |
---|
| 2426 | UInt uiWriteByteCount = 0; |
---|
| 2427 | while (uiWriteByteCount < (uiBitCount >> 3) ) |
---|
| 2428 | { |
---|
| 2429 | UInt uiBits = (*pucStart); |
---|
| 2430 | rNalu.m_Bitstream.write(uiBits, 8); |
---|
| 2431 | pucStart++; |
---|
| 2432 | uiWriteByteCount++; |
---|
| 2433 | } |
---|
| 2434 | } |
---|
| 2435 | UInt uiBitsHeld = (uiBitCount & 0x07); |
---|
| 2436 | for (UInt uiIdx=0; uiIdx < uiBitsHeld; uiIdx++) |
---|
| 2437 | { |
---|
| 2438 | rNalu.m_Bitstream.write((rpcBitstreamRedirect->getHeldBits() & (1 << (7-uiIdx))) >> (7-uiIdx), 1); |
---|
| 2439 | } |
---|
| 2440 | } |
---|
| 2441 | |
---|
| 2442 | m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream); |
---|
| 2443 | |
---|
| 2444 | delete rpcBitstreamRedirect; |
---|
| 2445 | rpcBitstreamRedirect = new TComOutputBitstream; |
---|
| 2446 | } |
---|
| 2447 | |
---|
| 2448 | Void TEncGOP::xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt uiPOCCurr, UInt iGOPid ) |
---|
| 2449 | { |
---|
| 2450 | if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getSPS()->getListsModificationPresentFlag()) || pcSlice->getSPS()->getNumberOfUsableInterViewRefs() == 0 ) |
---|
| 2451 | { |
---|
| 2452 | return; |
---|
| 2453 | } |
---|
| 2454 | |
---|
| 2455 | // analyze inter-view modifications |
---|
| 2456 | GOPEntryMvc gem = m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ); |
---|
| 2457 | Int numL0Modifications = 0; |
---|
| 2458 | Int numL1Modifications = 0; |
---|
| 2459 | for( Int k = 0; k < gem.m_numInterViewRefPics; k++ ) |
---|
| 2460 | { |
---|
| 2461 | if( gem.m_interViewRefPosL0[k] > 0 ) { numL0Modifications++; } |
---|
| 2462 | if( gem.m_interViewRefPosL1[k] > 0 ) { numL1Modifications++; } |
---|
| 2463 | } |
---|
| 2464 | |
---|
| 2465 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
| 2466 | Int maxRefListSize = pcSlice->getNumPocTotalCurrMvc(); |
---|
| 2467 | Int numTemporalRefs = pcSlice->getNumPocTotalCurr(); |
---|
| 2468 | |
---|
| 2469 | // set L0 inter-view modifications |
---|
| 2470 | if( (maxRefListSize > 1) && (numL0Modifications > 0) ) |
---|
| 2471 | { |
---|
| 2472 | refPicListModification->setRefPicListModificationFlagL0( true ); |
---|
| 2473 | Int tempListEntryL0[16]; |
---|
| 2474 | for( Int k = 0; k < 16; k++ ) { tempListEntryL0[k] = -1; } |
---|
| 2475 | |
---|
| 2476 | Bool hasModification = false; |
---|
| 2477 | for( Int k = 0; k < gem.m_numInterViewRefPics; k++ ) |
---|
| 2478 | { |
---|
| 2479 | if( gem.m_interViewRefPosL0[k] > 0 ) |
---|
| 2480 | { |
---|
| 2481 | for( Int l = 0; l < pcSlice->getSPS()->getNumberOfUsableInterViewRefs(); l++ ) |
---|
| 2482 | { |
---|
| 2483 | if( gem.m_interViewRefs[k] == pcSlice->getSPS()->getUsableInterViewRef( l ) && (gem.m_interViewRefPosL0[k] - 1) != (numTemporalRefs + l) ) |
---|
| 2484 | { |
---|
| 2485 | tempListEntryL0[gem.m_interViewRefPosL0[k]-1] = numTemporalRefs + l; |
---|
| 2486 | hasModification = true; |
---|
| 2487 | } |
---|
| 2488 | } |
---|
| 2489 | } |
---|
| 2490 | } |
---|
| 2491 | |
---|
| 2492 | if( hasModification ) |
---|
| 2493 | { |
---|
[100] | 2494 | Int temporalRefIdx = 0; |
---|
| 2495 | for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++ ) |
---|
| 2496 | { |
---|
| 2497 | if( tempListEntryL0[i] >= 0 ) |
---|
| 2498 | { |
---|
| 2499 | refPicListModification->setRefPicSetIdxL0( i, tempListEntryL0[i] ); |
---|
| 2500 | } |
---|
| 2501 | else |
---|
| 2502 | { |
---|
| 2503 | refPicListModification->setRefPicSetIdxL0( i, temporalRefIdx ); |
---|
| 2504 | temporalRefIdx++; |
---|
| 2505 | } |
---|
| 2506 | } |
---|
| 2507 | } |
---|
[56] | 2508 | else |
---|
| 2509 | { |
---|
| 2510 | refPicListModification->setRefPicListModificationFlagL0( false ); |
---|
| 2511 | } |
---|
| 2512 | } |
---|
| 2513 | |
---|
| 2514 | // set L1 inter-view modifications |
---|
| 2515 | if( (maxRefListSize > 1) && (numL1Modifications > 0) ) |
---|
| 2516 | { |
---|
| 2517 | refPicListModification->setRefPicListModificationFlagL1( true ); |
---|
| 2518 | Int tempListEntryL1[16]; |
---|
| 2519 | for( Int k = 0; k < 16; k++ ) { tempListEntryL1[k] = -1; } |
---|
| 2520 | |
---|
| 2521 | Bool hasModification = false; |
---|
| 2522 | for( Int k = 0; k < gem.m_numInterViewRefPics; k++ ) |
---|
| 2523 | { |
---|
| 2524 | if( gem.m_interViewRefPosL1[k] > 0 ) |
---|
| 2525 | { |
---|
| 2526 | for( Int l = 0; l < pcSlice->getSPS()->getNumberOfUsableInterViewRefs(); l++ ) |
---|
| 2527 | { |
---|
| 2528 | if( gem.m_interViewRefs[k] == pcSlice->getSPS()->getUsableInterViewRef( l ) && (gem.m_interViewRefPosL1[k] - 1) != (numTemporalRefs + l) ) |
---|
| 2529 | { |
---|
| 2530 | tempListEntryL1[gem.m_interViewRefPosL1[k]-1] = numTemporalRefs + l; |
---|
| 2531 | hasModification = true; |
---|
| 2532 | } |
---|
| 2533 | } |
---|
| 2534 | } |
---|
| 2535 | } |
---|
| 2536 | |
---|
| 2537 | if( hasModification ) |
---|
| 2538 | { |
---|
[100] | 2539 | Int temporalRefIdx = 0; |
---|
| 2540 | for( Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++ ) |
---|
| 2541 | { |
---|
| 2542 | if( tempListEntryL1[i] >= 0 ) |
---|
| 2543 | { |
---|
| 2544 | refPicListModification->setRefPicSetIdxL1( i, tempListEntryL1[i] ); |
---|
| 2545 | } |
---|
| 2546 | else |
---|
| 2547 | { |
---|
| 2548 | refPicListModification->setRefPicSetIdxL1( i, temporalRefIdx ); |
---|
| 2549 | temporalRefIdx++; |
---|
| 2550 | } |
---|
| 2551 | } |
---|
[56] | 2552 | } |
---|
| 2553 | else |
---|
| 2554 | { |
---|
| 2555 | refPicListModification->setRefPicListModificationFlagL1( false ); |
---|
| 2556 | } |
---|
| 2557 | } |
---|
| 2558 | |
---|
| 2559 | return; |
---|
| 2560 | } |
---|
| 2561 | //! \} |
---|