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