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