[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 |
---|
[1200] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1200] | 6 | * Copyright (c) 2010-2015, 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> |
---|
[608] | 40 | #include <functional> |
---|
[56] | 41 | |
---|
[2] | 42 | #include "TEncTop.h" |
---|
| 43 | #include "TEncGOP.h" |
---|
| 44 | #include "TEncAnalyze.h" |
---|
[56] | 45 | #include "libmd5/MD5.h" |
---|
| 46 | #include "TLibCommon/SEI.h" |
---|
| 47 | #include "TLibCommon/NAL.h" |
---|
| 48 | #include "NALwrite.h" |
---|
[2] | 49 | #include <time.h> |
---|
[56] | 50 | #include <math.h> |
---|
[2] | 51 | |
---|
[1200] | 52 | #include <deque> |
---|
[56] | 53 | using namespace std; |
---|
[1200] | 54 | |
---|
[56] | 55 | //! \ingroup TLibEncoder |
---|
| 56 | //! \{ |
---|
| 57 | |
---|
[2] | 58 | // ==================================================================================================================== |
---|
| 59 | // Constructor / destructor / initialization / destroy |
---|
| 60 | // ==================================================================================================================== |
---|
[608] | 61 | Int getLSB(Int poc, Int maxLSB) |
---|
| 62 | { |
---|
| 63 | if (poc >= 0) |
---|
| 64 | { |
---|
| 65 | return poc % maxLSB; |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | return (maxLSB - ((-poc) % maxLSB)) % maxLSB; |
---|
| 70 | } |
---|
| 71 | } |
---|
[2] | 72 | |
---|
[56] | 73 | TEncGOP::TEncGOP() |
---|
[2] | 74 | { |
---|
[56] | 75 | m_iLastIDR = 0; |
---|
| 76 | m_iGopSize = 0; |
---|
| 77 | m_iNumPicCoded = 0; //Niko |
---|
| 78 | m_bFirst = true; |
---|
[964] | 79 | m_iLastRecoveryPicPOC = 0; |
---|
[1200] | 80 | |
---|
[2] | 81 | m_pcCfg = NULL; |
---|
| 82 | m_pcSliceEncoder = NULL; |
---|
| 83 | m_pcListPic = NULL; |
---|
[1200] | 84 | |
---|
[2] | 85 | m_pcEntropyCoder = NULL; |
---|
| 86 | m_pcCavlcCoder = NULL; |
---|
| 87 | m_pcSbacCoder = NULL; |
---|
| 88 | m_pcBinCABAC = NULL; |
---|
[1200] | 89 | |
---|
[56] | 90 | m_bSeqFirst = true; |
---|
[1200] | 91 | |
---|
[2] | 92 | m_bRefreshPending = 0; |
---|
[608] | 93 | m_pocCRA = 0; |
---|
| 94 | m_numLongTermRefPicSPS = 0; |
---|
| 95 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
---|
| 96 | ::memset(m_ltRefPicUsedByCurrPicFlag, 0, sizeof(m_ltRefPicUsedByCurrPicFlag)); |
---|
| 97 | m_lastBPSEI = 0; |
---|
[1200] | 98 | m_bufferingPeriodSEIPresentInAU = false; |
---|
| 99 | #if NH_MV |
---|
[608] | 100 | m_layerId = 0; |
---|
| 101 | m_viewId = 0; |
---|
| 102 | m_pocLastCoded = -1; |
---|
[1200] | 103 | #if NH_3D |
---|
[608] | 104 | m_viewIndex = 0; |
---|
| 105 | m_isDepth = false; |
---|
| 106 | #endif |
---|
| 107 | #endif |
---|
[872] | 108 | m_associatedIRAPType = NAL_UNIT_CODED_SLICE_IDR_N_LP; |
---|
| 109 | m_associatedIRAPPOC = 0; |
---|
[2] | 110 | return; |
---|
| 111 | } |
---|
| 112 | |
---|
[56] | 113 | TEncGOP::~TEncGOP() |
---|
[2] | 114 | { |
---|
| 115 | } |
---|
| 116 | |
---|
[1200] | 117 | /** Create list to contain pointers to CTU start addresses of slice. |
---|
[2] | 118 | */ |
---|
[608] | 119 | Void TEncGOP::create() |
---|
[2] | 120 | { |
---|
[56] | 121 | m_bLongtermTestPictureHasBeenCoded = 0; |
---|
| 122 | m_bLongtermTestPictureHasBeenCoded2 = 0; |
---|
[2] | 123 | } |
---|
| 124 | |
---|
[56] | 125 | Void TEncGOP::destroy() |
---|
[2] | 126 | { |
---|
| 127 | } |
---|
| 128 | |
---|
[56] | 129 | Void TEncGOP::init ( TEncTop* pcTEncTop ) |
---|
[2] | 130 | { |
---|
| 131 | m_pcEncTop = pcTEncTop; |
---|
| 132 | m_pcCfg = pcTEncTop; |
---|
[1200] | 133 | m_seiEncoder.init(m_pcCfg, pcTEncTop, this); |
---|
[2] | 134 | m_pcSliceEncoder = pcTEncTop->getSliceEncoder(); |
---|
| 135 | m_pcListPic = pcTEncTop->getListPic(); |
---|
[1200] | 136 | |
---|
[2] | 137 | m_pcEntropyCoder = pcTEncTop->getEntropyCoder(); |
---|
| 138 | m_pcCavlcCoder = pcTEncTop->getCavlcCoder(); |
---|
| 139 | m_pcSbacCoder = pcTEncTop->getSbacCoder(); |
---|
| 140 | m_pcBinCABAC = pcTEncTop->getBinCABAC(); |
---|
| 141 | m_pcLoopFilter = pcTEncTop->getLoopFilter(); |
---|
[1200] | 142 | |
---|
[608] | 143 | m_pcSAO = pcTEncTop->getSAO(); |
---|
| 144 | m_pcRateCtrl = pcTEncTop->getRateCtrl(); |
---|
| 145 | m_lastBPSEI = 0; |
---|
| 146 | m_totalCoded = 0; |
---|
| 147 | |
---|
[1200] | 148 | #if NH_MV |
---|
[608] | 149 | m_ivPicLists = pcTEncTop->getIvPicLists(); |
---|
| 150 | m_layerId = pcTEncTop->getLayerId(); |
---|
| 151 | m_viewId = pcTEncTop->getViewId(); |
---|
[1200] | 152 | #if NH_3D |
---|
[608] | 153 | m_viewIndex = pcTEncTop->getViewIndex(); |
---|
| 154 | m_isDepth = pcTEncTop->getIsDepth(); |
---|
[5] | 155 | #endif |
---|
| 156 | #endif |
---|
[1279] | 157 | #if NH_3D_IC |
---|
[1084] | 158 | m_aICEnableCandidate = pcTEncTop->getICEnableCandidate(); |
---|
| 159 | m_aICEnableNum = pcTEncTop->getICEnableNum(); |
---|
[1066] | 160 | #endif |
---|
[655] | 161 | #if KWU_FIX_URQ |
---|
| 162 | m_pcRateCtrl = pcTEncTop->getRateCtrl(); |
---|
| 163 | #endif |
---|
[2] | 164 | } |
---|
| 165 | |
---|
[1200] | 166 | Int TEncGOP::xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps) |
---|
[608] | 167 | { |
---|
[1200] | 168 | OutputNALUnit nalu(NAL_UNIT_VPS); |
---|
| 169 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 170 | m_pcEntropyCoder->encodeVPS(vps); |
---|
| 171 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 172 | return (Int)(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
[608] | 173 | } |
---|
| 174 | |
---|
[1200] | 175 | Int TEncGOP::xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps) |
---|
[608] | 176 | { |
---|
[1200] | 177 | #if NH_MV |
---|
| 178 | OutputNALUnit nalu(NAL_UNIT_SPS, 0, getLayerId() ); |
---|
| 179 | #else |
---|
| 180 | OutputNALUnit nalu(NAL_UNIT_SPS); |
---|
| 181 | #endif |
---|
| 182 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 183 | m_pcEntropyCoder->encodeSPS(sps); |
---|
| 184 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 185 | return (Int)(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
| 186 | |
---|
[608] | 187 | } |
---|
| 188 | |
---|
[1200] | 189 | Int TEncGOP::xWritePPS (AccessUnit &accessUnit, const TComPPS *pps) |
---|
[608] | 190 | { |
---|
[1200] | 191 | #if NH_MV |
---|
| 192 | OutputNALUnit nalu(NAL_UNIT_PPS, 0, getLayerId() ); |
---|
| 193 | #else |
---|
| 194 | OutputNALUnit nalu(NAL_UNIT_PPS); |
---|
| 195 | #endif |
---|
| 196 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 197 | m_pcEntropyCoder->encodePPS(pps); |
---|
| 198 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 199 | return (Int)(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
[608] | 200 | } |
---|
| 201 | |
---|
[1200] | 202 | |
---|
| 203 | Int TEncGOP::xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice) |
---|
[608] | 204 | { |
---|
[1200] | 205 | Int actualTotalBits = 0; |
---|
[608] | 206 | |
---|
[1200] | 207 | #if NH_MV |
---|
| 208 | if ( getLayerId() == 0 ) |
---|
| 209 | { |
---|
| 210 | actualTotalBits += xWriteVPS(accessUnit, m_pcEncTop->getVPS()); |
---|
| 211 | } |
---|
| 212 | #else |
---|
| 213 | actualTotalBits += xWriteVPS(accessUnit, m_pcEncTop->getVPS()); |
---|
| 214 | #endif |
---|
| 215 | actualTotalBits += xWriteSPS(accessUnit, slice->getSPS()); |
---|
| 216 | actualTotalBits += xWritePPS(accessUnit, slice->getPPS()); |
---|
[608] | 217 | |
---|
[1200] | 218 | return actualTotalBits; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | // write SEI list into one NAL unit and add it to the Access unit at auPos |
---|
| 222 | Void TEncGOP::xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps) |
---|
| 223 | { |
---|
| 224 | // don't do anything, if we get an empty list |
---|
| 225 | if (seiMessages.empty()) |
---|
[608] | 226 | { |
---|
[1200] | 227 | return; |
---|
| 228 | } |
---|
| 229 | #if NH_MV |
---|
| 230 | OutputNALUnit nalu(naluType, temporalId, getLayerId() ); |
---|
| 231 | #else |
---|
| 232 | OutputNALUnit nalu(naluType, temporalId); |
---|
| 233 | #endif |
---|
| 234 | m_seiWriter.writeSEImessages(nalu.m_Bitstream, seiMessages, sps, false); |
---|
| 235 | auPos = accessUnit.insert(auPos, new NALUnitEBSP(nalu)); |
---|
| 236 | auPos++; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | Void TEncGOP::xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps) |
---|
| 240 | { |
---|
| 241 | // don't do anything, if we get an empty list |
---|
| 242 | if (seiMessages.empty()) |
---|
| 243 | { |
---|
| 244 | return; |
---|
| 245 | } |
---|
| 246 | for (SEIMessages::const_iterator sei = seiMessages.begin(); sei!=seiMessages.end(); sei++ ) |
---|
| 247 | { |
---|
| 248 | SEIMessages tmpMessages; |
---|
| 249 | tmpMessages.push_back(*sei); |
---|
| 250 | #if NH_MV |
---|
| 251 | OutputNALUnit nalu(naluType, temporalId, getLayerId() ); |
---|
| 252 | #else |
---|
| 253 | OutputNALUnit nalu(naluType, temporalId); |
---|
| 254 | #endif |
---|
| 255 | m_seiWriter.writeSEImessages(nalu.m_Bitstream, tmpMessages, sps, false); |
---|
| 256 | auPos = accessUnit.insert(auPos, new NALUnitEBSP(nalu)); |
---|
| 257 | auPos++; |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | Void TEncGOP::xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages) |
---|
| 262 | { |
---|
| 263 | if (deleteMessages) |
---|
| 264 | { |
---|
| 265 | deleteSEIs(seiMessages); |
---|
| 266 | } |
---|
| 267 | else |
---|
| 268 | { |
---|
| 269 | seiMessages.clear(); |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | // write SEI messages as separate NAL units ordered |
---|
| 274 | Void TEncGOP::xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite) |
---|
| 275 | { |
---|
| 276 | AccessUnit::iterator itNalu = accessUnit.begin(); |
---|
| 277 | |
---|
| 278 | while ( (itNalu!=accessUnit.end())&& |
---|
| 279 | ( (*itNalu)->m_nalUnitType==NAL_UNIT_ACCESS_UNIT_DELIMITER |
---|
| 280 | || (*itNalu)->m_nalUnitType==NAL_UNIT_VPS |
---|
| 281 | || (*itNalu)->m_nalUnitType==NAL_UNIT_SPS |
---|
| 282 | || (*itNalu)->m_nalUnitType==NAL_UNIT_PPS |
---|
| 283 | )) |
---|
| 284 | { |
---|
| 285 | itNalu++; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | SEIMessages localMessages = seiMessages; |
---|
| 289 | SEIMessages currentMessages; |
---|
| 290 | |
---|
| 291 | #if ENC_DEC_TRACE |
---|
| 292 | g_HLSTraceEnable = !testWrite; |
---|
| 293 | #endif |
---|
| 294 | // The case that a specific SEI is not present is handled in xWriteSEI (empty list) |
---|
| 295 | |
---|
| 296 | // Active parameter sets SEI must always be the first SEI |
---|
| 297 | currentMessages = extractSeisByType(localMessages, SEI::ACTIVE_PARAMETER_SETS); |
---|
| 298 | assert (currentMessages.size() <= 1); |
---|
| 299 | xWriteSEI(NAL_UNIT_PREFIX_SEI, currentMessages, accessUnit, itNalu, temporalId, sps); |
---|
| 300 | xClearSEIs(currentMessages, !testWrite); |
---|
| 301 | |
---|
| 302 | // Buffering period SEI must always be following active parameter sets |
---|
| 303 | currentMessages = extractSeisByType(localMessages, SEI::BUFFERING_PERIOD); |
---|
| 304 | assert (currentMessages.size() <= 1); |
---|
| 305 | xWriteSEI(NAL_UNIT_PREFIX_SEI, currentMessages, accessUnit, itNalu, temporalId, sps); |
---|
| 306 | xClearSEIs(currentMessages, !testWrite); |
---|
| 307 | |
---|
| 308 | // Picture timing SEI must always be following buffering period |
---|
| 309 | currentMessages = extractSeisByType(localMessages, SEI::PICTURE_TIMING); |
---|
| 310 | assert (currentMessages.size() <= 1); |
---|
| 311 | xWriteSEI(NAL_UNIT_PREFIX_SEI, currentMessages, accessUnit, itNalu, temporalId, sps); |
---|
| 312 | xClearSEIs(currentMessages, !testWrite); |
---|
| 313 | |
---|
| 314 | // Decoding unit info SEI must always be following picture timing |
---|
| 315 | if (!duInfoSeiMessages.empty()) |
---|
| 316 | { |
---|
| 317 | currentMessages.push_back(duInfoSeiMessages.front()); |
---|
| 318 | if (!testWrite) |
---|
[608] | 319 | { |
---|
[1200] | 320 | duInfoSeiMessages.pop_front(); |
---|
[608] | 321 | } |
---|
[1200] | 322 | xWriteSEI(NAL_UNIT_PREFIX_SEI, currentMessages, accessUnit, itNalu, temporalId, sps); |
---|
| 323 | xClearSEIs(currentMessages, !testWrite); |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | // Scalable nesting SEI must always be the following DU info |
---|
| 327 | currentMessages = extractSeisByType(localMessages, SEI::SCALABLE_NESTING); |
---|
| 328 | xWriteSEISeparately(NAL_UNIT_PREFIX_SEI, currentMessages, accessUnit, itNalu, temporalId, sps); |
---|
| 329 | xClearSEIs(currentMessages, !testWrite); |
---|
| 330 | |
---|
| 331 | // And finally everything else one by one |
---|
| 332 | xWriteSEISeparately(NAL_UNIT_PREFIX_SEI, localMessages, accessUnit, itNalu, temporalId, sps); |
---|
| 333 | xClearSEIs(localMessages, !testWrite); |
---|
| 334 | |
---|
| 335 | if (!testWrite) |
---|
| 336 | { |
---|
| 337 | seiMessages.clear(); |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | |
---|
| 342 | Void TEncGOP::xWriteLeadingSEIMessages (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData) |
---|
| 343 | { |
---|
| 344 | AccessUnit testAU; |
---|
| 345 | SEIMessages picTimingSEIs = getSeisByType(seiMessages, SEI::PICTURE_TIMING); |
---|
| 346 | assert (picTimingSEIs.size() < 2); |
---|
| 347 | SEIPictureTiming * picTiming = picTimingSEIs.empty() ? NULL : (SEIPictureTiming*) picTimingSEIs.front(); |
---|
| 348 | |
---|
| 349 | // test writing |
---|
| 350 | xWriteLeadingSEIOrdered(seiMessages, duInfoSeiMessages, testAU, temporalId, sps, true); |
---|
| 351 | // update Timing and DU info SEI |
---|
| 352 | xUpdateDuData(testAU, duData); |
---|
| 353 | xUpdateTimingSEI(picTiming, duData, sps); |
---|
| 354 | xUpdateDuInfoSEI(duInfoSeiMessages, picTiming); |
---|
| 355 | // actual writing |
---|
| 356 | xWriteLeadingSEIOrdered(seiMessages, duInfoSeiMessages, accessUnit, temporalId, sps, false); |
---|
| 357 | |
---|
| 358 | // testAU will automatically be cleaned up when losing scope |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | Void TEncGOP::xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps) |
---|
| 362 | { |
---|
| 363 | // Note: using accessUnit.end() works only as long as this function is called after slice coding and before EOS/EOB NAL units |
---|
| 364 | AccessUnit::iterator pos = accessUnit.end(); |
---|
| 365 | xWriteSEISeparately(NAL_UNIT_SUFFIX_SEI, seiMessages, accessUnit, pos, temporalId, sps); |
---|
| 366 | deleteSEIs(seiMessages); |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | Void TEncGOP::xWriteDuSEIMessages (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData) |
---|
| 370 | { |
---|
| 371 | const TComHRD *hrd = sps->getVuiParameters()->getHrdParameters(); |
---|
| 372 | |
---|
| 373 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 374 | { |
---|
| 375 | Int naluIdx = 0; |
---|
| 376 | AccessUnit::iterator nalu = accessUnit.begin(); |
---|
| 377 | |
---|
| 378 | // skip over first DU, we have a DU info SEI there already |
---|
| 379 | while (naluIdx < duData[0].accumNalsDU && nalu!=accessUnit.end()) |
---|
[608] | 380 | { |
---|
[1200] | 381 | naluIdx++; |
---|
| 382 | nalu++; |
---|
[608] | 383 | } |
---|
[1200] | 384 | |
---|
| 385 | SEIMessages::iterator duSEI = duInfoSeiMessages.begin(); |
---|
| 386 | // loop over remaining DUs |
---|
| 387 | for (Int duIdx = 1; duIdx < duData.size(); duIdx++) |
---|
[608] | 388 | { |
---|
[1200] | 389 | if (duSEI == duInfoSeiMessages.end()) |
---|
[608] | 390 | { |
---|
[1200] | 391 | // if the number of generated SEIs matches the number of DUs, this should not happen |
---|
| 392 | assert (false); |
---|
| 393 | return; |
---|
[608] | 394 | } |
---|
[1200] | 395 | // write the next SEI |
---|
| 396 | SEIMessages tmpSEI; |
---|
| 397 | tmpSEI.push_back(*duSEI); |
---|
| 398 | xWriteSEI(NAL_UNIT_PREFIX_SEI, tmpSEI, accessUnit, nalu, temporalId, sps); |
---|
| 399 | // nalu points to the position after the SEI, so we have to increase the index as well |
---|
| 400 | naluIdx++; |
---|
| 401 | while ((naluIdx < duData[duIdx].accumNalsDU) && nalu!=accessUnit.end()) |
---|
| 402 | { |
---|
| 403 | naluIdx++; |
---|
| 404 | nalu++; |
---|
| 405 | } |
---|
| 406 | duSEI++; |
---|
[608] | 407 | } |
---|
[1200] | 408 | } |
---|
| 409 | deleteSEIs(duInfoSeiMessages); |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | Void TEncGOP::xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps) |
---|
| 413 | { |
---|
| 414 | #if NH_MV |
---|
| 415 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, 0, getLayerId()); |
---|
| 416 | #else |
---|
| 417 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
| 418 | #endif |
---|
| 419 | if(m_pcCfg->getActiveParameterSetsSEIEnabled()) |
---|
| 420 | { |
---|
| 421 | SEIActiveParameterSets *sei = new SEIActiveParameterSets; |
---|
| 422 | m_seiEncoder.initSEIActiveParameterSets (sei, m_pcCfg->getVPS(), sps); |
---|
| 423 | seiMessages.push_back(sei); |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | if(m_pcCfg->getFramePackingArrangementSEIEnabled()) |
---|
| 427 | { |
---|
| 428 | SEIFramePacking *sei = new SEIFramePacking; |
---|
| 429 | m_seiEncoder.initSEIFramePacking (sei, m_iNumPicCoded); |
---|
| 430 | seiMessages.push_back(sei); |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | if(m_pcCfg->getSegmentedRectFramePackingArrangementSEIEnabled()) |
---|
| 434 | { |
---|
| 435 | SEISegmentedRectFramePacking *sei = new SEISegmentedRectFramePacking; |
---|
| 436 | m_seiEncoder.initSEISegmentedRectFramePacking(sei); |
---|
| 437 | seiMessages.push_back(sei); |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | if (m_pcCfg->getDisplayOrientationSEIAngle()) |
---|
| 441 | { |
---|
| 442 | SEIDisplayOrientation *sei = new SEIDisplayOrientation; |
---|
| 443 | m_seiEncoder.initSEIDisplayOrientation(sei); |
---|
| 444 | seiMessages.push_back(sei); |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | if(m_pcCfg->getToneMappingInfoSEIEnabled()) |
---|
| 448 | { |
---|
| 449 | SEIToneMappingInfo *sei = new SEIToneMappingInfo; |
---|
| 450 | m_seiEncoder.initSEIToneMappingInfo (sei); |
---|
| 451 | seiMessages.push_back(sei); |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | if(m_pcCfg->getTMCTSSEIEnabled()) |
---|
| 455 | { |
---|
| 456 | SEITempMotionConstrainedTileSets *sei = new SEITempMotionConstrainedTileSets; |
---|
| 457 | m_seiEncoder.initSEITempMotionConstrainedTileSets(sei, pps); |
---|
| 458 | seiMessages.push_back(sei); |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | if(m_pcCfg->getTimeCodeSEIEnabled()) |
---|
| 462 | { |
---|
| 463 | SEITimeCode *seiTimeCode = new SEITimeCode; |
---|
| 464 | m_seiEncoder.initSEITimeCode(seiTimeCode); |
---|
| 465 | seiMessages.push_back(seiTimeCode); |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | if(m_pcCfg->getKneeSEIEnabled()) |
---|
| 469 | { |
---|
| 470 | SEIKneeFunctionInfo *sei = new SEIKneeFunctionInfo; |
---|
| 471 | m_seiEncoder.initSEIKneeFunctionInfo(sei); |
---|
| 472 | seiMessages.push_back(sei); |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | if(m_pcCfg->getMasteringDisplaySEI().colourVolumeSEIEnabled) |
---|
| 476 | { |
---|
| 477 | const TComSEIMasteringDisplay &seiCfg=m_pcCfg->getMasteringDisplaySEI(); |
---|
| 478 | SEIMasteringDisplayColourVolume *sei = new SEIMasteringDisplayColourVolume; |
---|
| 479 | sei->values = seiCfg; |
---|
| 480 | seiMessages.push_back(sei); |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | #if NH_MV |
---|
| 484 | if( m_pcCfg->getSubBitstreamPropSEIEnabled() && ( getLayerId() == 0 ) ) |
---|
| 485 | { |
---|
| 486 | SEISubBitstreamProperty *sei = new SEISubBitstreamProperty; |
---|
| 487 | m_seiEncoder.initSEISubBitstreamProperty( sei, sps ); |
---|
| 488 | seiMessages.push_back(sei); |
---|
| 489 | } |
---|
| 490 | #endif |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | Void TEncGOP::xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice) |
---|
| 494 | { |
---|
| 495 | if( ( m_pcCfg->getBufferingPeriodSEIEnabled() ) && ( slice->getSliceType() == I_SLICE ) && |
---|
| 496 | ( slice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
| 497 | ( ( slice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
| 498 | || ( slice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
| 499 | { |
---|
| 500 | SEIBufferingPeriod *bufferingPeriodSEI = new SEIBufferingPeriod(); |
---|
| 501 | m_seiEncoder.initSEIBufferingPeriod(bufferingPeriodSEI, slice); |
---|
| 502 | seiMessages.push_back(bufferingPeriodSEI); |
---|
| 503 | m_bufferingPeriodSEIPresentInAU = true; |
---|
| 504 | |
---|
| 505 | if (m_pcCfg->getScalableNestingSEIEnabled()) |
---|
[608] | 506 | { |
---|
[1200] | 507 | SEIBufferingPeriod *bufferingPeriodSEIcopy = new SEIBufferingPeriod(); |
---|
| 508 | bufferingPeriodSEI->copyTo(*bufferingPeriodSEIcopy); |
---|
| 509 | nestedSeiMessages.push_back(bufferingPeriodSEIcopy); |
---|
[608] | 510 | } |
---|
[1200] | 511 | } |
---|
| 512 | |
---|
| 513 | if (picInGOP ==0 && m_pcCfg->getSOPDescriptionSEIEnabled() ) // write SOP description SEI (if enabled) at the beginning of GOP |
---|
| 514 | { |
---|
| 515 | SEISOPDescription* sopDescriptionSEI = new SEISOPDescription(); |
---|
| 516 | m_seiEncoder.initSEISOPDescription(sopDescriptionSEI, slice, picInGOP, m_iLastIDR, m_iGopSize); |
---|
| 517 | seiMessages.push_back(sopDescriptionSEI); |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | if( ( m_pcEncTop->getRecoveryPointSEIEnabled() ) && ( slice->getSliceType() == I_SLICE ) ) |
---|
| 521 | { |
---|
| 522 | if( m_pcEncTop->getGradualDecodingRefreshInfoEnabled() && !slice->getRapPicFlag() ) |
---|
[608] | 523 | { |
---|
[1200] | 524 | // Gradual decoding refresh SEI |
---|
| 525 | SEIGradualDecodingRefreshInfo *gradualDecodingRefreshInfoSEI = new SEIGradualDecodingRefreshInfo(); |
---|
| 526 | gradualDecodingRefreshInfoSEI->m_gdrForegroundFlag = true; // Indicating all "foreground" |
---|
| 527 | seiMessages.push_back(gradualDecodingRefreshInfoSEI); |
---|
[608] | 528 | } |
---|
[1200] | 529 | // Recovery point SEI |
---|
| 530 | SEIRecoveryPoint *recoveryPointSEI = new SEIRecoveryPoint(); |
---|
| 531 | m_seiEncoder.initSEIRecoveryPoint(recoveryPointSEI, slice); |
---|
| 532 | seiMessages.push_back(recoveryPointSEI); |
---|
[608] | 533 | } |
---|
[1200] | 534 | if (m_pcCfg->getTemporalLevel0IndexSEIEnabled()) |
---|
| 535 | { |
---|
| 536 | SEITemporalLevel0Index *temporalLevel0IndexSEI = new SEITemporalLevel0Index(); |
---|
| 537 | m_seiEncoder.initTemporalLevel0IndexSEI(temporalLevel0IndexSEI, slice); |
---|
| 538 | seiMessages.push_back(temporalLevel0IndexSEI); |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | if(slice->getSPS()->getVuiParametersPresentFlag() && m_pcCfg->getChromaSamplingFilterHintEnabled() && ( slice->getSliceType() == I_SLICE )) |
---|
| 542 | { |
---|
| 543 | SEIChromaSamplingFilterHint *seiChromaSamplingFilterHint = new SEIChromaSamplingFilterHint; |
---|
| 544 | m_seiEncoder.initSEIChromaSamplingFilterHint(seiChromaSamplingFilterHint, m_pcCfg->getChromaSamplingHorFilterIdc(), m_pcCfg->getChromaSamplingVerFilterIdc()); |
---|
| 545 | seiMessages.push_back(seiChromaSamplingFilterHint); |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | if( m_pcEncTop->getNoDisplaySEITLayer() && ( slice->getTLayer() >= m_pcEncTop->getNoDisplaySEITLayer() ) ) |
---|
| 549 | { |
---|
| 550 | SEINoDisplay *seiNoDisplay = new SEINoDisplay; |
---|
| 551 | seiNoDisplay->m_noDisplay = true; |
---|
| 552 | seiMessages.push_back(seiNoDisplay); |
---|
| 553 | } |
---|
[608] | 554 | } |
---|
| 555 | |
---|
[1200] | 556 | Void TEncGOP::xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages) |
---|
[872] | 557 | { |
---|
[1200] | 558 | SEIMessages tmpMessages; |
---|
| 559 | while (!nestedSeiMessages.empty()) |
---|
| 560 | { |
---|
| 561 | SEI* sei=nestedSeiMessages.front(); |
---|
| 562 | nestedSeiMessages.pop_front(); |
---|
| 563 | tmpMessages.push_back(sei); |
---|
| 564 | SEIScalableNesting *nestingSEI = new SEIScalableNesting(); |
---|
| 565 | m_seiEncoder.initSEIScalableNesting(nestingSEI, tmpMessages); |
---|
| 566 | seiMessages.push_back(nestingSEI); |
---|
| 567 | tmpMessages.clear(); |
---|
| 568 | } |
---|
| 569 | } |
---|
[872] | 570 | |
---|
[1200] | 571 | Void TEncGOP::xCreatePictureTimingSEI (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData) |
---|
| 572 | { |
---|
| 573 | Int picSptDpbOutputDuDelay = 0; |
---|
| 574 | #if !NH_MV |
---|
| 575 | SEIPictureTiming *pictureTimingSEI = new SEIPictureTiming(); |
---|
| 576 | #endif |
---|
[872] | 577 | |
---|
[1200] | 578 | const TComVUI *vui = slice->getSPS()->getVuiParameters(); |
---|
| 579 | const TComHRD *hrd = vui->getHrdParameters(); |
---|
| 580 | |
---|
| 581 | // update decoding unit parameters |
---|
| 582 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
| 583 | ( slice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
| 584 | ( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() ) ) |
---|
| 585 | { |
---|
| 586 | #if NH_MV |
---|
| 587 | // Preliminary fix to avoid memory leak. |
---|
| 588 | SEIPictureTiming *pictureTimingSEI = new SEIPictureTiming(); |
---|
[872] | 589 | #endif |
---|
| 590 | |
---|
[1200] | 591 | // DU parameters |
---|
| 592 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 593 | { |
---|
| 594 | UInt numDU = (UInt) duData.size(); |
---|
| 595 | pictureTimingSEI->m_numDecodingUnitsMinus1 = ( numDU - 1 ); |
---|
| 596 | pictureTimingSEI->m_duCommonCpbRemovalDelayFlag = false; |
---|
| 597 | pictureTimingSEI->m_numNalusInDuMinus1.resize( numDU ); |
---|
| 598 | pictureTimingSEI->m_duCpbRemovalDelayMinus1.resize( numDU ); |
---|
| 599 | } |
---|
| 600 | pictureTimingSEI->m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<Double>(hrd->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the . |
---|
| 601 | pictureTimingSEI->m_picDpbOutputDelay = slice->getSPS()->getNumReorderPics(slice->getSPS()->getMaxTLayers()-1) + slice->getPOC() - m_totalCoded; |
---|
| 602 | if(m_pcCfg->getEfficientFieldIRAPEnabled() && IRAPGOPid > 0 && IRAPGOPid < m_iGopSize) |
---|
| 603 | { |
---|
| 604 | // if pictures have been swapped there is likely one more picture delay on their tid. Very rough approximation |
---|
| 605 | pictureTimingSEI->m_picDpbOutputDelay ++; |
---|
| 606 | } |
---|
| 607 | Int factor = hrd->getTickDivisorMinus2() + 2; |
---|
| 608 | pictureTimingSEI->m_picDpbOutputDuDelay = factor * pictureTimingSEI->m_picDpbOutputDelay; |
---|
| 609 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
| 610 | { |
---|
| 611 | picSptDpbOutputDuDelay = factor * pictureTimingSEI->m_picDpbOutputDelay; |
---|
| 612 | } |
---|
| 613 | if (m_bufferingPeriodSEIPresentInAU) |
---|
| 614 | { |
---|
| 615 | m_lastBPSEI = m_totalCoded; |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 619 | { |
---|
| 620 | Int i; |
---|
| 621 | UInt64 ui64Tmp; |
---|
| 622 | UInt uiPrev = 0; |
---|
| 623 | UInt numDU = ( pictureTimingSEI->m_numDecodingUnitsMinus1 + 1 ); |
---|
| 624 | std::vector<UInt> &rDuCpbRemovalDelayMinus1 = pictureTimingSEI->m_duCpbRemovalDelayMinus1; |
---|
| 625 | UInt maxDiff = ( hrd->getTickDivisorMinus2() + 2 ) - 1; |
---|
| 626 | |
---|
| 627 | for( i = 0; i < numDU; i ++ ) |
---|
| 628 | { |
---|
| 629 | pictureTimingSEI->m_numNalusInDuMinus1[ i ] = ( i == 0 ) ? ( duData[i].accumNalsDU - 1 ) : ( duData[i].accumNalsDU- duData[i-1].accumNalsDU - 1 ); |
---|
| 630 | } |
---|
| 631 | |
---|
| 632 | if( numDU == 1 ) |
---|
| 633 | { |
---|
| 634 | rDuCpbRemovalDelayMinus1[ 0 ] = 0; /* don't care */ |
---|
| 635 | } |
---|
| 636 | else |
---|
| 637 | { |
---|
| 638 | rDuCpbRemovalDelayMinus1[ numDU - 1 ] = 0;/* by definition */ |
---|
| 639 | UInt tmp = 0; |
---|
| 640 | UInt accum = 0; |
---|
| 641 | |
---|
| 642 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
| 643 | { |
---|
| 644 | ui64Tmp = ( ( ( duData[numDU - 1].accumBitsDU - duData[i].accumBitsDU ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
| 645 | if( (UInt)ui64Tmp > maxDiff ) |
---|
| 646 | { |
---|
| 647 | tmp ++; |
---|
| 648 | } |
---|
| 649 | } |
---|
| 650 | uiPrev = 0; |
---|
| 651 | |
---|
| 652 | UInt flag = 0; |
---|
| 653 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
| 654 | { |
---|
| 655 | flag = 0; |
---|
| 656 | ui64Tmp = ( ( ( duData[numDU - 1].accumBitsDU - duData[i].accumBitsDU ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
| 657 | |
---|
| 658 | if( (UInt)ui64Tmp > maxDiff ) |
---|
| 659 | { |
---|
| 660 | if(uiPrev >= maxDiff - tmp) |
---|
| 661 | { |
---|
| 662 | ui64Tmp = uiPrev + 1; |
---|
| 663 | flag = 1; |
---|
| 664 | } |
---|
| 665 | else ui64Tmp = maxDiff - tmp + 1; |
---|
| 666 | } |
---|
| 667 | rDuCpbRemovalDelayMinus1[ i ] = (UInt)ui64Tmp - uiPrev - 1; |
---|
| 668 | if( (Int)rDuCpbRemovalDelayMinus1[ i ] < 0 ) |
---|
| 669 | { |
---|
| 670 | rDuCpbRemovalDelayMinus1[ i ] = 0; |
---|
| 671 | } |
---|
| 672 | else if (tmp > 0 && flag == 1) |
---|
| 673 | { |
---|
| 674 | tmp --; |
---|
| 675 | } |
---|
| 676 | accum += rDuCpbRemovalDelayMinus1[ i ] + 1; |
---|
| 677 | uiPrev = accum; |
---|
| 678 | } |
---|
| 679 | } |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | if( m_pcCfg->getPictureTimingSEIEnabled() ) |
---|
| 683 | { |
---|
| 684 | pictureTimingSEI->m_picStruct = (isField && slice->getPic()->isTopField())? 1 : isField? 2 : 0; |
---|
| 685 | seiMessages.push_back(pictureTimingSEI); |
---|
| 686 | |
---|
| 687 | if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI |
---|
| 688 | { |
---|
| 689 | SEIPictureTiming *pictureTimingSEIcopy = new SEIPictureTiming(); |
---|
| 690 | pictureTimingSEI->copyTo(*pictureTimingSEIcopy); |
---|
| 691 | nestedSeiMessages.push_back(pictureTimingSEIcopy); |
---|
| 692 | } |
---|
| 693 | } |
---|
| 694 | |
---|
| 695 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 696 | { |
---|
| 697 | for( Int i = 0; i < ( pictureTimingSEI->m_numDecodingUnitsMinus1 + 1 ); i ++ ) |
---|
| 698 | { |
---|
| 699 | SEIDecodingUnitInfo *duInfoSEI = new SEIDecodingUnitInfo(); |
---|
| 700 | duInfoSEI->m_decodingUnitIdx = i; |
---|
| 701 | duInfoSEI->m_duSptCpbRemovalDelay = pictureTimingSEI->m_duCpbRemovalDelayMinus1[i] + 1; |
---|
| 702 | duInfoSEI->m_dpbOutputDuDelayPresentFlag = false; |
---|
| 703 | duInfoSEI->m_picSptDpbOutputDuDelay = picSptDpbOutputDuDelay; |
---|
| 704 | |
---|
| 705 | duInfoSeiMessages.push_back(duInfoSEI); |
---|
| 706 | } |
---|
| 707 | } |
---|
| 708 | } |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | Void TEncGOP::xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData) |
---|
[608] | 712 | { |
---|
[1200] | 713 | if (duData.empty()) |
---|
| 714 | { |
---|
| 715 | return; |
---|
| 716 | } |
---|
| 717 | // fix first |
---|
| 718 | UInt numNalUnits = (UInt)testAU.size(); |
---|
| 719 | UInt numRBSPBytes = 0; |
---|
| 720 | for (AccessUnit::const_iterator it = testAU.begin(); it != testAU.end(); it++) |
---|
| 721 | { |
---|
| 722 | numRBSPBytes += UInt((*it)->m_nalUnitData.str().size()); |
---|
| 723 | } |
---|
| 724 | duData[0].accumBitsDU += ( numRBSPBytes << 3 ); |
---|
| 725 | duData[0].accumNalsDU += numNalUnits; |
---|
[608] | 726 | |
---|
[1200] | 727 | // adapt cumulative sums for all following DUs |
---|
| 728 | // and add one DU info SEI, if enabled |
---|
| 729 | for (Int i=1; i<duData.size(); i++) |
---|
[608] | 730 | { |
---|
[1200] | 731 | if (m_pcCfg->getDecodingUnitInfoSEIEnabled()) |
---|
| 732 | { |
---|
| 733 | numNalUnits += 1; |
---|
| 734 | numRBSPBytes += ( 5 << 3 ); |
---|
| 735 | } |
---|
| 736 | duData[i].accumBitsDU += numRBSPBytes; // probably around 5 bytes |
---|
| 737 | duData[i].accumNalsDU += numNalUnits; |
---|
| 738 | } |
---|
[608] | 739 | |
---|
[1200] | 740 | // The last DU may have a trailing SEI |
---|
| 741 | if (m_pcCfg->getDecodedPictureHashSEIEnabled()) |
---|
| 742 | { |
---|
| 743 | duData.back().accumBitsDU += ( 20 << 3 ); // probably around 20 bytes - should be further adjusted, e.g. by type |
---|
| 744 | duData.back().accumNalsDU += 1; |
---|
[608] | 745 | } |
---|
| 746 | |
---|
[1200] | 747 | } |
---|
| 748 | Void TEncGOP::xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps) |
---|
| 749 | { |
---|
| 750 | if (!pictureTimingSEI) |
---|
[608] | 751 | { |
---|
[1200] | 752 | return; |
---|
[608] | 753 | } |
---|
[1200] | 754 | const TComVUI *vui = sps->getVuiParameters(); |
---|
| 755 | const TComHRD *hrd = vui->getHrdParameters(); |
---|
| 756 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
[608] | 757 | { |
---|
[1200] | 758 | Int i; |
---|
| 759 | UInt64 ui64Tmp; |
---|
| 760 | UInt uiPrev = 0; |
---|
| 761 | UInt numDU = ( pictureTimingSEI->m_numDecodingUnitsMinus1 + 1 ); |
---|
| 762 | std::vector<UInt> &rDuCpbRemovalDelayMinus1 = pictureTimingSEI->m_duCpbRemovalDelayMinus1; |
---|
| 763 | UInt maxDiff = ( hrd->getTickDivisorMinus2() + 2 ) - 1; |
---|
[608] | 764 | |
---|
[1200] | 765 | for( i = 0; i < numDU; i ++ ) |
---|
| 766 | { |
---|
| 767 | pictureTimingSEI->m_numNalusInDuMinus1[ i ] = ( i == 0 ) ? ( duData[i].accumNalsDU - 1 ) : ( duData[i].accumNalsDU- duData[i-1].accumNalsDU - 1 ); |
---|
| 768 | } |
---|
| 769 | |
---|
| 770 | if( numDU == 1 ) |
---|
| 771 | { |
---|
| 772 | rDuCpbRemovalDelayMinus1[ 0 ] = 0; /* don't care */ |
---|
| 773 | } |
---|
| 774 | else |
---|
| 775 | { |
---|
| 776 | rDuCpbRemovalDelayMinus1[ numDU - 1 ] = 0;/* by definition */ |
---|
| 777 | UInt tmp = 0; |
---|
| 778 | UInt accum = 0; |
---|
| 779 | |
---|
| 780 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
| 781 | { |
---|
| 782 | ui64Tmp = ( ( ( duData[numDU - 1].accumBitsDU - duData[i].accumBitsDU ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
| 783 | if( (UInt)ui64Tmp > maxDiff ) |
---|
| 784 | { |
---|
| 785 | tmp ++; |
---|
| 786 | } |
---|
| 787 | } |
---|
| 788 | uiPrev = 0; |
---|
| 789 | |
---|
| 790 | UInt flag = 0; |
---|
| 791 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
| 792 | { |
---|
| 793 | flag = 0; |
---|
| 794 | ui64Tmp = ( ( ( duData[numDU - 1].accumBitsDU - duData[i].accumBitsDU ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
| 795 | |
---|
| 796 | if( (UInt)ui64Tmp > maxDiff ) |
---|
| 797 | { |
---|
| 798 | if(uiPrev >= maxDiff - tmp) |
---|
| 799 | { |
---|
| 800 | ui64Tmp = uiPrev + 1; |
---|
| 801 | flag = 1; |
---|
| 802 | } |
---|
| 803 | else ui64Tmp = maxDiff - tmp + 1; |
---|
| 804 | } |
---|
| 805 | rDuCpbRemovalDelayMinus1[ i ] = (UInt)ui64Tmp - uiPrev - 1; |
---|
| 806 | if( (Int)rDuCpbRemovalDelayMinus1[ i ] < 0 ) |
---|
| 807 | { |
---|
| 808 | rDuCpbRemovalDelayMinus1[ i ] = 0; |
---|
| 809 | } |
---|
| 810 | else if (tmp > 0 && flag == 1) |
---|
| 811 | { |
---|
| 812 | tmp --; |
---|
| 813 | } |
---|
| 814 | accum += rDuCpbRemovalDelayMinus1[ i ] + 1; |
---|
| 815 | uiPrev = accum; |
---|
| 816 | } |
---|
| 817 | } |
---|
[608] | 818 | } |
---|
[1200] | 819 | } |
---|
| 820 | Void TEncGOP::xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI) |
---|
| 821 | { |
---|
| 822 | if (duInfoSeiMessages.empty() || (pictureTimingSEI == NULL)) |
---|
[608] | 823 | { |
---|
[1200] | 824 | return; |
---|
[608] | 825 | } |
---|
[1200] | 826 | |
---|
| 827 | Int i=0; |
---|
| 828 | |
---|
| 829 | for (SEIMessages::iterator du = duInfoSeiMessages.begin(); du!= duInfoSeiMessages.end(); du++) |
---|
[872] | 830 | { |
---|
[1200] | 831 | SEIDecodingUnitInfo *duInfoSEI = (SEIDecodingUnitInfo*) (*du); |
---|
| 832 | duInfoSEI->m_decodingUnitIdx = i; |
---|
| 833 | duInfoSEI->m_duSptCpbRemovalDelay = pictureTimingSEI->m_duCpbRemovalDelayMinus1[i] + 1; |
---|
| 834 | duInfoSEI->m_dpbOutputDuDelayPresentFlag = false; |
---|
| 835 | i++; |
---|
[872] | 836 | } |
---|
[608] | 837 | } |
---|
| 838 | |
---|
[1200] | 839 | static Void |
---|
| 840 | cabac_zero_word_padding(TComSlice *const pcSlice, TComPic *const pcPic, const std::size_t binCountsInNalUnits, const std::size_t numBytesInVclNalUnits, std::ostringstream &nalUnitData, const Bool cabacZeroWordPaddingEnabled) |
---|
[2] | 841 | { |
---|
[1200] | 842 | const TComSPS &sps=*(pcSlice->getSPS()); |
---|
| 843 | const Int log2subWidthCxsubHeightC = (pcPic->getComponentScaleX(COMPONENT_Cb)+pcPic->getComponentScaleY(COMPONENT_Cb)); |
---|
| 844 | const Int minCuWidth = pcPic->getMinCUWidth(); |
---|
| 845 | const Int minCuHeight = pcPic->getMinCUHeight(); |
---|
| 846 | const Int paddedWidth = ((sps.getPicWidthInLumaSamples() + minCuWidth - 1) / minCuWidth) * minCuWidth; |
---|
| 847 | const Int paddedHeight= ((sps.getPicHeightInLumaSamples() + minCuHeight - 1) / minCuHeight) * minCuHeight; |
---|
| 848 | const Int rawBits = paddedWidth * paddedHeight * |
---|
| 849 | (sps.getBitDepth(CHANNEL_TYPE_LUMA) + 2*(sps.getBitDepth(CHANNEL_TYPE_CHROMA)>>log2subWidthCxsubHeightC)); |
---|
| 850 | const std::size_t threshold = (32/3)*numBytesInVclNalUnits + (rawBits/32); |
---|
| 851 | if (binCountsInNalUnits >= threshold) |
---|
| 852 | { |
---|
| 853 | // need to add additional cabac zero words (each one accounts for 3 bytes (=00 00 03)) to increase numBytesInVclNalUnits |
---|
| 854 | const std::size_t targetNumBytesInVclNalUnits = ((binCountsInNalUnits - (rawBits/32))*3+31)/32; |
---|
| 855 | |
---|
| 856 | if (targetNumBytesInVclNalUnits>numBytesInVclNalUnits) // It should be! |
---|
| 857 | { |
---|
| 858 | const std::size_t numberOfAdditionalBytesNeeded=targetNumBytesInVclNalUnits - numBytesInVclNalUnits; |
---|
| 859 | const std::size_t numberOfAdditionalCabacZeroWords=(numberOfAdditionalBytesNeeded+2)/3; |
---|
| 860 | const std::size_t numberOfAdditionalCabacZeroBytes=numberOfAdditionalCabacZeroWords*3; |
---|
| 861 | if (cabacZeroWordPaddingEnabled) |
---|
| 862 | { |
---|
| 863 | std::vector<Char> zeroBytesPadding(numberOfAdditionalCabacZeroBytes, Char(0)); |
---|
| 864 | for(std::size_t i=0; i<numberOfAdditionalCabacZeroWords; i++) |
---|
| 865 | { |
---|
| 866 | zeroBytesPadding[i*3+2]=3; // 00 00 03 |
---|
| 867 | } |
---|
| 868 | nalUnitData.write(&(zeroBytesPadding[0]), numberOfAdditionalCabacZeroBytes); |
---|
| 869 | printf("Adding %d bytes of padding\n", UInt(numberOfAdditionalCabacZeroWords*3)); |
---|
| 870 | } |
---|
| 871 | else |
---|
| 872 | { |
---|
| 873 | printf("Standard would normally require adding %d bytes of padding\n", UInt(numberOfAdditionalCabacZeroWords*3)); |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | } |
---|
[56] | 877 | } |
---|
[1200] | 878 | |
---|
| 879 | class EfficientFieldIRAPMapping |
---|
[56] | 880 | { |
---|
[1200] | 881 | private: |
---|
| 882 | Int IRAPGOPid; |
---|
| 883 | Bool IRAPtoReorder; |
---|
| 884 | Bool swapIRAPForward; |
---|
[5] | 885 | |
---|
[1200] | 886 | public: |
---|
| 887 | EfficientFieldIRAPMapping() : |
---|
| 888 | IRAPGOPid(-1), |
---|
| 889 | IRAPtoReorder(false), |
---|
| 890 | swapIRAPForward(false) |
---|
| 891 | { } |
---|
[655] | 892 | |
---|
[1200] | 893 | Void initialize(const Bool isField, const Int gopSize, const Int POCLast, const Int numPicRcvd, const Int lastIDR, TEncGOP *pEncGop, TEncCfg *pCfg); |
---|
| 894 | |
---|
| 895 | Int adjustGOPid(const Int gopID); |
---|
| 896 | Int restoreGOPid(const Int gopID); |
---|
| 897 | Int GetIRAPGOPid() const { return IRAPGOPid; } |
---|
| 898 | }; |
---|
| 899 | |
---|
| 900 | Void EfficientFieldIRAPMapping::initialize(const Bool isField, const Int gopSize, const Int POCLast, const Int numPicRcvd, const Int lastIDR, TEncGOP *pEncGop, TEncCfg *pCfg ) |
---|
| 901 | { |
---|
[964] | 902 | if(isField) |
---|
| 903 | { |
---|
| 904 | Int pocCurr; |
---|
[1200] | 905 | for ( Int iGOPid=0; iGOPid < gopSize; iGOPid++ ) |
---|
[964] | 906 | { |
---|
| 907 | // determine actual POC |
---|
[1200] | 908 | if(POCLast == 0) //case first frame or first top field |
---|
[964] | 909 | { |
---|
| 910 | pocCurr=0; |
---|
| 911 | } |
---|
[1200] | 912 | else if(POCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value |
---|
[964] | 913 | { |
---|
| 914 | pocCurr = 1; |
---|
| 915 | } |
---|
| 916 | else |
---|
| 917 | { |
---|
[1200] | 918 | pocCurr = POCLast - numPicRcvd + pCfg->getGOPEntry(iGOPid).m_POC - isField; |
---|
[964] | 919 | } |
---|
| 920 | |
---|
| 921 | // check if POC corresponds to IRAP |
---|
[1200] | 922 | NalUnitType tmpUnitType = pEncGop->getNalUnitType(pocCurr, lastIDR, isField); |
---|
[964] | 923 | if(tmpUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && tmpUnitType <= NAL_UNIT_CODED_SLICE_CRA) // if picture is an IRAP |
---|
| 924 | { |
---|
[1200] | 925 | if(pocCurr%2 == 0 && iGOPid < gopSize-1 && pCfg->getGOPEntry(iGOPid).m_POC == pCfg->getGOPEntry(iGOPid+1).m_POC-1) |
---|
[964] | 926 | { // if top field and following picture in enc order is associated bottom field |
---|
| 927 | IRAPGOPid = iGOPid; |
---|
| 928 | IRAPtoReorder = true; |
---|
| 929 | swapIRAPForward = true; |
---|
| 930 | break; |
---|
| 931 | } |
---|
[1200] | 932 | if(pocCurr%2 != 0 && iGOPid > 0 && pCfg->getGOPEntry(iGOPid).m_POC == pCfg->getGOPEntry(iGOPid-1).m_POC+1) |
---|
[964] | 933 | { |
---|
| 934 | // if picture is an IRAP remember to process it first |
---|
| 935 | IRAPGOPid = iGOPid; |
---|
| 936 | IRAPtoReorder = true; |
---|
| 937 | swapIRAPForward = false; |
---|
| 938 | break; |
---|
| 939 | } |
---|
| 940 | } |
---|
| 941 | } |
---|
| 942 | } |
---|
[1200] | 943 | } |
---|
| 944 | |
---|
| 945 | Int EfficientFieldIRAPMapping::adjustGOPid(const Int GOPid) |
---|
| 946 | { |
---|
| 947 | if(IRAPtoReorder) |
---|
[56] | 948 | { |
---|
[1200] | 949 | if(swapIRAPForward) |
---|
[964] | 950 | { |
---|
[1200] | 951 | if(GOPid == IRAPGOPid) |
---|
[964] | 952 | { |
---|
[1200] | 953 | return IRAPGOPid +1; |
---|
[964] | 954 | } |
---|
[1200] | 955 | else if(GOPid == IRAPGOPid +1) |
---|
[964] | 956 | { |
---|
[1200] | 957 | return IRAPGOPid; |
---|
[964] | 958 | } |
---|
| 959 | } |
---|
[1200] | 960 | else |
---|
[608] | 961 | { |
---|
[1200] | 962 | if(GOPid == IRAPGOPid -1) |
---|
[56] | 963 | { |
---|
[1200] | 964 | return IRAPGOPid; |
---|
[56] | 965 | } |
---|
[1200] | 966 | else if(GOPid == IRAPGOPid) |
---|
[56] | 967 | { |
---|
[1200] | 968 | return IRAPGOPid -1; |
---|
[56] | 969 | } |
---|
[608] | 970 | } |
---|
[1200] | 971 | } |
---|
| 972 | return GOPid; |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | Int EfficientFieldIRAPMapping::restoreGOPid(const Int GOPid) |
---|
| 976 | { |
---|
| 977 | if(IRAPtoReorder) |
---|
| 978 | { |
---|
| 979 | if(swapIRAPForward) |
---|
[608] | 980 | { |
---|
[1200] | 981 | if(GOPid == IRAPGOPid) |
---|
[56] | 982 | { |
---|
[1200] | 983 | IRAPtoReorder = false; |
---|
| 984 | return IRAPGOPid +1; |
---|
[56] | 985 | } |
---|
[1200] | 986 | else if(GOPid == IRAPGOPid +1) |
---|
| 987 | { |
---|
| 988 | return GOPid -1; |
---|
| 989 | } |
---|
[608] | 990 | } |
---|
[1200] | 991 | else |
---|
[608] | 992 | { |
---|
[1200] | 993 | if(GOPid == IRAPGOPid) |
---|
[56] | 994 | { |
---|
[1200] | 995 | return IRAPGOPid -1; |
---|
[56] | 996 | } |
---|
[1200] | 997 | else if(GOPid == IRAPGOPid -1) |
---|
[56] | 998 | { |
---|
[1200] | 999 | IRAPtoReorder = false; |
---|
| 1000 | return IRAPGOPid; |
---|
[56] | 1001 | } |
---|
[608] | 1002 | } |
---|
[1200] | 1003 | } |
---|
| 1004 | return GOPid; |
---|
| 1005 | } |
---|
| 1006 | |
---|
| 1007 | |
---|
| 1008 | static UInt calculateCollocatedFromL1Flag(TEncCfg *pCfg, const Int GOPid, const Int gopSize) |
---|
| 1009 | { |
---|
| 1010 | Int iCloseLeft=1, iCloseRight=-1; |
---|
| 1011 | for(Int i = 0; i<pCfg->getGOPEntry(GOPid).m_numRefPics; i++) |
---|
| 1012 | { |
---|
| 1013 | Int iRef = pCfg->getGOPEntry(GOPid).m_referencePics[i]; |
---|
| 1014 | if(iRef>0&&(iRef<iCloseRight||iCloseRight==-1)) |
---|
[608] | 1015 | { |
---|
[1200] | 1016 | iCloseRight=iRef; |
---|
[608] | 1017 | } |
---|
[1200] | 1018 | else if(iRef<0&&(iRef>iCloseLeft||iCloseLeft==1)) |
---|
| 1019 | { |
---|
| 1020 | iCloseLeft=iRef; |
---|
| 1021 | } |
---|
| 1022 | } |
---|
| 1023 | if(iCloseRight>-1) |
---|
| 1024 | { |
---|
| 1025 | iCloseRight=iCloseRight+pCfg->getGOPEntry(GOPid).m_POC-1; |
---|
| 1026 | } |
---|
| 1027 | if(iCloseLeft<1) |
---|
| 1028 | { |
---|
| 1029 | iCloseLeft=iCloseLeft+pCfg->getGOPEntry(GOPid).m_POC-1; |
---|
| 1030 | while(iCloseLeft<0) |
---|
| 1031 | { |
---|
| 1032 | iCloseLeft+=gopSize; |
---|
| 1033 | } |
---|
| 1034 | } |
---|
| 1035 | Int iLeftQP=0, iRightQP=0; |
---|
| 1036 | for(Int i=0; i<gopSize; i++) |
---|
| 1037 | { |
---|
| 1038 | if(pCfg->getGOPEntry(i).m_POC==(iCloseLeft%gopSize)+1) |
---|
| 1039 | { |
---|
| 1040 | iLeftQP= pCfg->getGOPEntry(i).m_QPOffset; |
---|
| 1041 | } |
---|
| 1042 | if (pCfg->getGOPEntry(i).m_POC==(iCloseRight%gopSize)+1) |
---|
| 1043 | { |
---|
| 1044 | iRightQP=pCfg->getGOPEntry(i).m_QPOffset; |
---|
| 1045 | } |
---|
| 1046 | } |
---|
| 1047 | if(iCloseRight>-1&&iRightQP<iLeftQP) |
---|
| 1048 | { |
---|
| 1049 | return 0; |
---|
| 1050 | } |
---|
| 1051 | else |
---|
| 1052 | { |
---|
| 1053 | return 1; |
---|
| 1054 | } |
---|
| 1055 | } |
---|
[2] | 1056 | |
---|
[1200] | 1057 | // ==================================================================================================================== |
---|
| 1058 | // Public member functions |
---|
| 1059 | // ==================================================================================================================== |
---|
| 1060 | #if NH_MV |
---|
| 1061 | Void TEncGOP::initGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP) |
---|
| 1062 | { |
---|
| 1063 | xInitGOP( iPOCLast, iNumPicRcvd, false ); |
---|
| 1064 | m_iNumPicCoded = 0; |
---|
| 1065 | } |
---|
| 1066 | #endif |
---|
| 1067 | #if NH_MV |
---|
| 1068 | Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, |
---|
| 1069 | TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, |
---|
| 1070 | Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Int iGOPid ) |
---|
| 1071 | #else |
---|
| 1072 | Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, |
---|
| 1073 | TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, |
---|
| 1074 | Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ) |
---|
| 1075 | #endif |
---|
| 1076 | { |
---|
| 1077 | // TODO: Split this function up. |
---|
| 1078 | |
---|
| 1079 | TComPic* pcPic = NULL; |
---|
| 1080 | TComPicYuv* pcPicYuvRecOut; |
---|
| 1081 | TComSlice* pcSlice; |
---|
| 1082 | TComOutputBitstream *pcBitstreamRedirect; |
---|
| 1083 | pcBitstreamRedirect = new TComOutputBitstream; |
---|
| 1084 | AccessUnit::iterator itLocationToPushSliceHeaderNALU; // used to store location where NALU containing slice header is to be inserted |
---|
| 1085 | #if !NH_MV |
---|
| 1086 | xInitGOP( iPOCLast, iNumPicRcvd, isField ); |
---|
| 1087 | #endif |
---|
| 1088 | |
---|
| 1089 | m_iNumPicCoded = 0; |
---|
| 1090 | SEIMessages leadingSeiMessages; |
---|
| 1091 | SEIMessages nestedSeiMessages; |
---|
| 1092 | SEIMessages duInfoSeiMessages; |
---|
| 1093 | SEIMessages trailingSeiMessages; |
---|
| 1094 | std::deque<DUData> duData; |
---|
| 1095 | SEIDecodingUnitInfo decodingUnitInfoSEI; |
---|
| 1096 | |
---|
| 1097 | EfficientFieldIRAPMapping effFieldIRAPMap; |
---|
| 1098 | if (m_pcCfg->getEfficientFieldIRAPEnabled()) |
---|
| 1099 | { |
---|
| 1100 | effFieldIRAPMap.initialize(isField, m_iGopSize, iPOCLast, iNumPicRcvd, m_iLastIDR, this, m_pcCfg); |
---|
| 1101 | } |
---|
| 1102 | |
---|
| 1103 | // reset flag indicating whether pictures have been encoded |
---|
| 1104 | #if !NH_MV |
---|
| 1105 | for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ ) |
---|
| 1106 | #endif |
---|
| 1107 | { |
---|
| 1108 | m_pcCfg->setEncodedFlag(iGOPid, false); |
---|
| 1109 | } |
---|
| 1110 | #if !NH_MV |
---|
| 1111 | for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ ) |
---|
| 1112 | #endif |
---|
| 1113 | { |
---|
| 1114 | if (m_pcCfg->getEfficientFieldIRAPEnabled()) |
---|
| 1115 | { |
---|
| 1116 | iGOPid=effFieldIRAPMap.adjustGOPid(iGOPid); |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | //-- For time output for each slice |
---|
| 1120 | clock_t iBeforeTime = clock(); |
---|
| 1121 | |
---|
| 1122 | UInt uiColDir = calculateCollocatedFromL1Flag(m_pcCfg, iGOPid, m_iGopSize); |
---|
| 1123 | |
---|
[608] | 1124 | /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding |
---|
[655] | 1125 | Int iTimeOffset; |
---|
| 1126 | Int pocCurr; |
---|
| 1127 | if(iPOCLast == 0) //case first frame or first top field |
---|
[608] | 1128 | { |
---|
| 1129 | pocCurr=0; |
---|
| 1130 | iTimeOffset = 1; |
---|
| 1131 | } |
---|
[655] | 1132 | else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value |
---|
| 1133 | { |
---|
| 1134 | pocCurr = 1; |
---|
| 1135 | iTimeOffset = 1; |
---|
| 1136 | } |
---|
| 1137 | else |
---|
| 1138 | { |
---|
[1200] | 1139 | pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - ((isField && m_iGopSize>1) ? 1:0); |
---|
[655] | 1140 | iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
| 1141 | } |
---|
[1200] | 1142 | |
---|
[608] | 1143 | if(pocCurr>=m_pcCfg->getFramesToBeEncoded()) |
---|
| 1144 | { |
---|
[1200] | 1145 | if (m_pcCfg->getEfficientFieldIRAPEnabled()) |
---|
[964] | 1146 | { |
---|
[1200] | 1147 | iGOPid=effFieldIRAPMap.restoreGOPid(iGOPid); |
---|
[964] | 1148 | } |
---|
[1200] | 1149 | #if NH_MV |
---|
[608] | 1150 | delete pcBitstreamRedirect; |
---|
| 1151 | return; |
---|
| 1152 | #else |
---|
| 1153 | continue; |
---|
| 1154 | #endif |
---|
| 1155 | } |
---|
[5] | 1156 | |
---|
[872] | 1157 | if( getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
[608] | 1158 | { |
---|
| 1159 | m_iLastIDR = pocCurr; |
---|
[1200] | 1160 | } |
---|
[608] | 1161 | // start a new access unit: create an entry in the list of output access units |
---|
| 1162 | accessUnitsInGOP.push_back(AccessUnit()); |
---|
| 1163 | AccessUnit& accessUnit = accessUnitsInGOP.back(); |
---|
[1200] | 1164 | xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField ); |
---|
[56] | 1165 | |
---|
[608] | 1166 | // Slice data initialization |
---|
| 1167 | pcPic->clearSliceBuffer(); |
---|
[1200] | 1168 | pcPic->allocateNewSlice(); |
---|
[608] | 1169 | m_pcSliceEncoder->setSliceIdx(0); |
---|
| 1170 | pcPic->setCurrSliceIdx(0); |
---|
[1200] | 1171 | #if NH_MV |
---|
| 1172 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iGOPid, pcSlice, m_pcEncTop->getVPS(), getLayerId(), isField ); |
---|
[622] | 1173 | #else |
---|
[1200] | 1174 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iGOPid, pcSlice, isField ); |
---|
[622] | 1175 | #endif |
---|
[1200] | 1176 | |
---|
[655] | 1177 | //Set Frame/Field coding |
---|
| 1178 | pcSlice->getPic()->setField(isField); |
---|
| 1179 | |
---|
[608] | 1180 | pcSlice->setLastIDR(m_iLastIDR); |
---|
| 1181 | pcSlice->setSliceIdx(0); |
---|
[1200] | 1182 | #if NH_MV |
---|
[622] | 1183 | pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); |
---|
[608] | 1184 | pcPic ->setLayerId ( getLayerId() ); |
---|
| 1185 | pcPic ->setViewId ( getViewId() ); |
---|
[1200] | 1186 | #if !NH_3D |
---|
[608] | 1187 | pcSlice->setLayerId ( getLayerId() ); |
---|
| 1188 | pcSlice->setViewId ( getViewId() ); |
---|
| 1189 | pcSlice->setVPS ( m_pcEncTop->getVPS() ); |
---|
[77] | 1190 | #else |
---|
[608] | 1191 | pcPic ->setViewIndex ( getViewIndex() ); |
---|
| 1192 | pcPic ->setIsDepth( getIsDepth() ); |
---|
| 1193 | pcSlice->setCamparaSlice( pcPic->getCodedScale(), pcPic->getCodedOffset() ); |
---|
[77] | 1194 | #endif |
---|
[608] | 1195 | #endif |
---|
| 1196 | //set default slice level flag to the same as SPS level flag |
---|
| 1197 | pcSlice->setLFCrossSliceBoundaryFlag( pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() ); |
---|
[1200] | 1198 | #if NH_MV |
---|
[608] | 1199 | // Set the nal unit type |
---|
[872] | 1200 | pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField)); |
---|
[608] | 1201 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
| 1202 | { |
---|
| 1203 | if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) |
---|
| 1204 | { |
---|
| 1205 | pcSlice->setSliceType( P_SLICE ); |
---|
| 1206 | } |
---|
| 1207 | } |
---|
[872] | 1208 | |
---|
| 1209 | // To be checked! |
---|
| 1210 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
| 1211 | { |
---|
| 1212 | if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'I' ) |
---|
| 1213 | { |
---|
| 1214 | pcSlice->setSliceType( I_SLICE ); |
---|
| 1215 | } |
---|
| 1216 | } |
---|
[608] | 1217 | #else |
---|
[1200] | 1218 | |
---|
[608] | 1219 | if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P') |
---|
| 1220 | { |
---|
| 1221 | pcSlice->setSliceType(P_SLICE); |
---|
| 1222 | } |
---|
[872] | 1223 | if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='I') |
---|
| 1224 | { |
---|
| 1225 | pcSlice->setSliceType(I_SLICE); |
---|
| 1226 | } |
---|
| 1227 | |
---|
[608] | 1228 | // Set the nal unit type |
---|
[872] | 1229 | pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField)); |
---|
[608] | 1230 | #endif |
---|
| 1231 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
| 1232 | { |
---|
[655] | 1233 | if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R && |
---|
| 1234 | !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE)) |
---|
| 1235 | // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker) |
---|
[56] | 1236 | { |
---|
[608] | 1237 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N); |
---|
[56] | 1238 | } |
---|
[608] | 1239 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RADL_R) |
---|
[56] | 1240 | { |
---|
[608] | 1241 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RADL_N); |
---|
[56] | 1242 | } |
---|
[608] | 1243 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RASL_R) |
---|
[56] | 1244 | { |
---|
[608] | 1245 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RASL_N); |
---|
[56] | 1246 | } |
---|
[210] | 1247 | } |
---|
[1200] | 1248 | if (m_pcCfg->getEfficientFieldIRAPEnabled()) |
---|
| 1249 | { |
---|
[964] | 1250 | if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
| 1251 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
| 1252 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
| 1253 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
| 1254 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 1255 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // IRAP picture |
---|
| 1256 | { |
---|
| 1257 | m_associatedIRAPType = pcSlice->getNalUnitType(); |
---|
| 1258 | m_associatedIRAPPOC = pocCurr; |
---|
| 1259 | } |
---|
| 1260 | pcSlice->setAssociatedIRAPType(m_associatedIRAPType); |
---|
| 1261 | pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC); |
---|
[1200] | 1262 | } |
---|
| 1263 | // Do decoding refresh marking if any |
---|
| 1264 | pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcCfg->getEfficientFieldIRAPEnabled()); |
---|
[608] | 1265 | m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid); |
---|
[1200] | 1266 | if (!m_pcCfg->getEfficientFieldIRAPEnabled()) |
---|
| 1267 | { |
---|
[872] | 1268 | if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
| 1269 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
| 1270 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
| 1271 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
| 1272 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 1273 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // IRAP picture |
---|
| 1274 | { |
---|
| 1275 | m_associatedIRAPType = pcSlice->getNalUnitType(); |
---|
| 1276 | m_associatedIRAPPOC = pocCurr; |
---|
| 1277 | } |
---|
| 1278 | pcSlice->setAssociatedIRAPType(m_associatedIRAPType); |
---|
| 1279 | pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC); |
---|
[1200] | 1280 | } |
---|
[964] | 1281 | if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false, m_iLastRecoveryPicPOC, m_pcCfg->getDecodingRefreshType() == 3) != 0) || (pcSlice->isIRAP()) |
---|
[1200] | 1282 | || (m_pcCfg->getEfficientFieldIRAPEnabled() && isField && pcSlice->getAssociatedIRAPType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getAssociatedIRAPType() <= NAL_UNIT_CODED_SLICE_CRA && pcSlice->getAssociatedIRAPPOC() == pcSlice->getPOC()+1) |
---|
[964] | 1283 | ) |
---|
| 1284 | { |
---|
[1200] | 1285 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP(), m_iLastRecoveryPicPOC, m_pcCfg->getDecodingRefreshType() == 3, m_pcCfg->getEfficientFieldIRAPEnabled()); |
---|
[964] | 1286 | } |
---|
[1200] | 1287 | |
---|
[608] | 1288 | pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); |
---|
[56] | 1289 | |
---|
[872] | 1290 | if(pcSlice->getTLayer() > 0 |
---|
| 1291 | && !( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N // Check if not a leading picture |
---|
| 1292 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R |
---|
| 1293 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N |
---|
| 1294 | || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R ) |
---|
| 1295 | ) |
---|
[608] | 1296 | { |
---|
| 1297 | if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag()) |
---|
[56] | 1298 | { |
---|
[608] | 1299 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
| 1300 | { |
---|
| 1301 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
| 1302 | } |
---|
| 1303 | else |
---|
| 1304 | { |
---|
[872] | 1305 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R); |
---|
[608] | 1306 | } |
---|
[56] | 1307 | } |
---|
[608] | 1308 | else if(pcSlice->isStepwiseTemporalLayerSwitchingPointCandidate(rcListPic)) |
---|
[56] | 1309 | { |
---|
[608] | 1310 | Bool isSTSA=true; |
---|
| 1311 | for(Int ii=iGOPid+1;(ii<m_pcCfg->getGOPSize() && isSTSA==true);ii++) |
---|
| 1312 | { |
---|
| 1313 | Int lTid= m_pcCfg->getGOPEntry(ii).m_temporalId; |
---|
[1200] | 1314 | if(lTid==pcSlice->getTLayer()) |
---|
[608] | 1315 | { |
---|
[1200] | 1316 | const TComReferencePictureSet* nRPS = pcSlice->getSPS()->getRPSList()->getReferencePictureSet(ii); |
---|
[608] | 1317 | for(Int jj=0;jj<nRPS->getNumberOfPictures();jj++) |
---|
| 1318 | { |
---|
[1200] | 1319 | if(nRPS->getUsed(jj)) |
---|
[608] | 1320 | { |
---|
| 1321 | Int tPoc=m_pcCfg->getGOPEntry(ii).m_POC+nRPS->getDeltaPOC(jj); |
---|
| 1322 | Int kk=0; |
---|
| 1323 | for(kk=0;kk<m_pcCfg->getGOPSize();kk++) |
---|
| 1324 | { |
---|
| 1325 | if(m_pcCfg->getGOPEntry(kk).m_POC==tPoc) |
---|
[1200] | 1326 | { |
---|
[608] | 1327 | break; |
---|
[1200] | 1328 | } |
---|
[608] | 1329 | } |
---|
| 1330 | Int tTid=m_pcCfg->getGOPEntry(kk).m_temporalId; |
---|
| 1331 | if(tTid >= pcSlice->getTLayer()) |
---|
| 1332 | { |
---|
| 1333 | isSTSA=false; |
---|
| 1334 | break; |
---|
| 1335 | } |
---|
| 1336 | } |
---|
| 1337 | } |
---|
| 1338 | } |
---|
| 1339 | } |
---|
| 1340 | if(isSTSA==true) |
---|
[1200] | 1341 | { |
---|
[608] | 1342 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
| 1343 | { |
---|
| 1344 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
| 1345 | } |
---|
| 1346 | else |
---|
| 1347 | { |
---|
| 1348 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R); |
---|
| 1349 | } |
---|
| 1350 | } |
---|
[56] | 1351 | } |
---|
[608] | 1352 | } |
---|
| 1353 | arrangeLongtermPicturesInRPS(pcSlice, rcListPic); |
---|
| 1354 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
| 1355 | refPicListModification->setRefPicListModificationFlagL0(0); |
---|
| 1356 | refPicListModification->setRefPicListModificationFlagL1(0); |
---|
[1200] | 1357 | #if NH_MV |
---|
[738] | 1358 | if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 ) |
---|
[622] | 1359 | { |
---|
| 1360 | // Some more sophisticated algorithm to determine discardable_flag might be added here. |
---|
| 1361 | pcSlice->setDiscardableFlag ( false ); |
---|
| 1362 | } |
---|
| 1363 | |
---|
[1200] | 1364 | const TComVPS* vps = pcSlice->getVPS(); |
---|
| 1365 | #if NH_3D |
---|
[1124] | 1366 | Int numDirectRefLayers = vps ->getNumRefListLayers( getLayerId() ); |
---|
| 1367 | #else |
---|
[622] | 1368 | Int numDirectRefLayers = vps ->getNumDirectRefLayers( getLayerId() ); |
---|
[1124] | 1369 | #endif |
---|
[1200] | 1370 | #if NH_3D |
---|
[1179] | 1371 | pcSlice->setIvPicLists( m_ivPicLists ); |
---|
| 1372 | |
---|
| 1373 | Int gopNum = (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid; |
---|
| 1374 | GOPEntry gopEntry = m_pcCfg->getGOPEntry( gopNum ); |
---|
| 1375 | #else |
---|
[622] | 1376 | GOPEntry gopEntry = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid ); |
---|
[1179] | 1377 | #endif |
---|
[1196] | 1378 | |
---|
| 1379 | |
---|
[622] | 1380 | |
---|
[738] | 1381 | Bool interLayerPredLayerIdcPresentFlag = false; |
---|
[622] | 1382 | if ( getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && numDirectRefLayers > 0 ) |
---|
| 1383 | { |
---|
| 1384 | pcSlice->setInterLayerPredEnabledFlag ( gopEntry.m_numActiveRefLayerPics > 0 ); |
---|
| 1385 | if ( pcSlice->getInterLayerPredEnabledFlag() && numDirectRefLayers > 1 ) |
---|
| 1386 | { |
---|
| 1387 | if ( !vps->getMaxOneActiveRefLayerFlag() ) |
---|
| 1388 | { |
---|
| 1389 | pcSlice->setNumInterLayerRefPicsMinus1( gopEntry.m_numActiveRefLayerPics - 1 ); |
---|
| 1390 | } |
---|
[1200] | 1391 | #if NH_3D |
---|
[1124] | 1392 | if ( gopEntry.m_numActiveRefLayerPics != vps->getNumRefListLayers( getLayerId() ) ) |
---|
| 1393 | #else |
---|
[622] | 1394 | if ( gopEntry.m_numActiveRefLayerPics != vps->getNumDirectRefLayers( getLayerId() ) ) |
---|
[1124] | 1395 | #endif |
---|
[622] | 1396 | { |
---|
[738] | 1397 | interLayerPredLayerIdcPresentFlag = true; |
---|
[622] | 1398 | for (Int i = 0; i < gopEntry.m_numActiveRefLayerPics; i++ ) |
---|
| 1399 | { |
---|
| 1400 | pcSlice->setInterLayerPredLayerIdc( i, gopEntry.m_interLayerPredLayerIdc[ i ] ); |
---|
| 1401 | } |
---|
| 1402 | } |
---|
| 1403 | } |
---|
| 1404 | } |
---|
[738] | 1405 | if ( !interLayerPredLayerIdcPresentFlag ) |
---|
| 1406 | { |
---|
| 1407 | for( Int i = 0; i < pcSlice->getNumActiveRefLayerPics(); i++ ) |
---|
| 1408 | { |
---|
| 1409 | pcSlice->setInterLayerPredLayerIdc(i, pcSlice->getRefLayerPicIdc( i ) ); |
---|
| 1410 | } |
---|
| 1411 | } |
---|
| 1412 | |
---|
| 1413 | |
---|
[622] | 1414 | assert( pcSlice->getNumActiveRefLayerPics() == gopEntry.m_numActiveRefLayerPics ); |
---|
| 1415 | |
---|
[1200] | 1416 | #if NH_3D |
---|
[1179] | 1417 | if ( m_pcEncTop->decProcAnnexI() ) |
---|
| 1418 | { |
---|
[1200] | 1419 | pcSlice->deriveInCmpPredAndCpAvailFlag( ); |
---|
[1179] | 1420 | if ( pcSlice->getInCmpPredAvailFlag() ) |
---|
| 1421 | { |
---|
| 1422 | pcSlice->setInCompPredFlag( gopEntry.m_interCompPredFlag ); |
---|
| 1423 | } |
---|
| 1424 | else |
---|
| 1425 | { |
---|
| 1426 | if (gopEntry.m_interCompPredFlag ) |
---|
| 1427 | { |
---|
| 1428 | if ( gopNum == MAX_GOP) |
---|
| 1429 | { |
---|
| 1430 | printf( "\nError: FrameI_l%d cannot enable inter-component prediction.\n", pcSlice->getVPS()->getLayerIdInVps( getLayerId() ) ); |
---|
| 1431 | } |
---|
| 1432 | else |
---|
| 1433 | { |
---|
| 1434 | printf( "\nError: Frame%d_l%d cannot enable inter-component prediction.\n", gopNum, pcSlice->getVPS()->getLayerIdInVps( getLayerId() ) ); |
---|
| 1435 | } |
---|
| 1436 | |
---|
| 1437 | exit(EXIT_FAILURE); |
---|
| 1438 | } |
---|
| 1439 | } |
---|
| 1440 | pcSlice->init3dToolParameters(); |
---|
| 1441 | pcSlice->checkInCompPredRefLayers(); |
---|
[1200] | 1442 | } |
---|
[1179] | 1443 | |
---|
[1279] | 1444 | #if NH_3D_IV_MERGE |
---|
[1200] | 1445 | // This needs to be done after initialization of 3D tool parameters. |
---|
[1179] | 1446 | pcSlice->setMaxNumMergeCand ( m_pcCfg->getMaxNumMergeCand() + ( ( pcSlice->getMpiFlag( ) || pcSlice->getIvMvPredFlag( ) || pcSlice->getViewSynthesisPredFlag( ) ) ? 1 : 0 )); |
---|
| 1447 | #endif |
---|
[1200] | 1448 | #endif |
---|
[1179] | 1449 | |
---|
[622] | 1450 | pcSlice->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); |
---|
| 1451 | pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer0.size() + (Int) m_refPicSetInterLayer1.size()) ) ); |
---|
| 1452 | pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer0.size() + (Int) m_refPicSetInterLayer1.size()) ) ); |
---|
| 1453 | |
---|
| 1454 | std::vector< TComPic* > tempRefPicLists[2]; |
---|
| 1455 | std::vector< Bool > usedAsLongTerm [2]; |
---|
| 1456 | Int numPocTotalCurr; |
---|
| 1457 | |
---|
| 1458 | pcSlice->getTempRefPicLists( rcListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); |
---|
| 1459 | |
---|
| 1460 | |
---|
| 1461 | xSetRefPicListModificationsMv( tempRefPicLists, pcSlice, iGOPid ); |
---|
| 1462 | #else |
---|
[608] | 1463 | pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
| 1464 | pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
[210] | 1465 | #endif |
---|
[608] | 1466 | // Set reference list |
---|
[1200] | 1467 | #if NH_MV |
---|
[622] | 1468 | pcSlice->setRefPicList( tempRefPicLists, usedAsLongTerm, numPocTotalCurr ); |
---|
| 1469 | #else |
---|
| 1470 | pcSlice->setRefPicList ( rcListPic ); |
---|
| 1471 | #endif |
---|
[1279] | 1472 | #if NH_3D_NBDV |
---|
[1124] | 1473 | pcSlice->setDefaultRefView(); |
---|
| 1474 | #endif |
---|
[1279] | 1475 | #if NH_3D_ARP |
---|
[622] | 1476 | //GT: This seems to be broken when layerId in vps is not equal to layerId in nuh |
---|
[724] | 1477 | pcSlice->setARPStepNum(m_ivPicLists); |
---|
[622] | 1478 | #endif |
---|
[1279] | 1479 | #if NH_3D_IC |
---|
[1066] | 1480 | pcSlice->setICEnableCandidate( m_aICEnableCandidate ); |
---|
| 1481 | pcSlice->setICEnableNum( m_aICEnableNum ); |
---|
| 1482 | #endif |
---|
[1200] | 1483 | |
---|
[608] | 1484 | // Slice info. refinement |
---|
[1200] | 1485 | #if NH_MV |
---|
[608] | 1486 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
| 1487 | { |
---|
| 1488 | if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() == true && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) |
---|
| 1489 | { |
---|
| 1490 | pcSlice->setSliceType( P_SLICE ); |
---|
[443] | 1491 | } |
---|
[608] | 1492 | } |
---|
[210] | 1493 | #else |
---|
[608] | 1494 | if ( (pcSlice->getSliceType() == B_SLICE) && (pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) ) |
---|
| 1495 | { |
---|
| 1496 | pcSlice->setSliceType ( P_SLICE ); |
---|
| 1497 | } |
---|
[210] | 1498 | #endif |
---|
[1200] | 1499 | pcSlice->setEncCABACTableIdx(m_pcSliceEncoder->getEncCABACTableIdx()); |
---|
| 1500 | |
---|
[608] | 1501 | if (pcSlice->getSliceType() == B_SLICE) |
---|
| 1502 | { |
---|
| 1503 | pcSlice->setColFromL0Flag(1-uiColDir); |
---|
| 1504 | Bool bLowDelay = true; |
---|
| 1505 | Int iCurrPOC = pcSlice->getPOC(); |
---|
| 1506 | Int iRefIdx = 0; |
---|
| 1507 | |
---|
| 1508 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
[56] | 1509 | { |
---|
[608] | 1510 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
[56] | 1511 | { |
---|
[608] | 1512 | bLowDelay = false; |
---|
[56] | 1513 | } |
---|
| 1514 | } |
---|
[608] | 1515 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
[56] | 1516 | { |
---|
[608] | 1517 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
[56] | 1518 | { |
---|
[608] | 1519 | bLowDelay = false; |
---|
[56] | 1520 | } |
---|
| 1521 | } |
---|
| 1522 | |
---|
[1200] | 1523 | pcSlice->setCheckLDC(bLowDelay); |
---|
[608] | 1524 | } |
---|
| 1525 | else |
---|
| 1526 | { |
---|
[1200] | 1527 | pcSlice->setCheckLDC(true); |
---|
[608] | 1528 | } |
---|
| 1529 | |
---|
| 1530 | uiColDir = 1-uiColDir; |
---|
| 1531 | |
---|
| 1532 | //------------------------------------------------------------- |
---|
| 1533 | pcSlice->setRefPOCList(); |
---|
| 1534 | |
---|
| 1535 | pcSlice->setList1IdxToList0Idx(); |
---|
[1279] | 1536 | #if NH_3D_TMVP |
---|
[608] | 1537 | if(pcSlice->getLayerId()) |
---|
| 1538 | pcSlice->generateAlterRefforTMVP(); |
---|
| 1539 | #endif |
---|
[1200] | 1540 | |
---|
[608] | 1541 | if (m_pcEncTop->getTMVPModeId() == 2) |
---|
| 1542 | { |
---|
| 1543 | if (iGOPid == 0) // first picture in SOP (i.e. forward B) |
---|
[56] | 1544 | { |
---|
[608] | 1545 | pcSlice->setEnableTMVPFlag(0); |
---|
[56] | 1546 | } |
---|
[608] | 1547 | else |
---|
| 1548 | { |
---|
| 1549 | // Note: pcSlice->getColFromL0Flag() is assumed to be always 0 and getcolRefIdx() is always 0. |
---|
| 1550 | pcSlice->setEnableTMVPFlag(1); |
---|
| 1551 | } |
---|
| 1552 | } |
---|
| 1553 | else if (m_pcEncTop->getTMVPModeId() == 1) |
---|
| 1554 | { |
---|
| 1555 | pcSlice->setEnableTMVPFlag(1); |
---|
| 1556 | } |
---|
| 1557 | else |
---|
| 1558 | { |
---|
| 1559 | pcSlice->setEnableTMVPFlag(0); |
---|
| 1560 | } |
---|
[1200] | 1561 | #if NH_MV |
---|
[608] | 1562 | if( pcSlice->getIdrPicFlag() ) |
---|
| 1563 | { |
---|
| 1564 | pcSlice->setEnableTMVPFlag(0); |
---|
| 1565 | } |
---|
[100] | 1566 | #endif |
---|
[2] | 1567 | |
---|
[1200] | 1568 | #if NH_3D_VSO |
---|
[608] | 1569 | // Should be moved to TEncTop !!! |
---|
| 1570 | Bool bUseVSO = m_pcEncTop->getUseVSO(); |
---|
| 1571 | |
---|
| 1572 | TComRdCost* pcRdCost = m_pcEncTop->getRdCost(); |
---|
| 1573 | |
---|
| 1574 | pcRdCost->setUseVSO( bUseVSO ); |
---|
| 1575 | |
---|
| 1576 | // SAIT_VSO_EST_A0033 |
---|
| 1577 | pcRdCost->setUseEstimatedVSD( m_pcEncTop->getUseEstimatedVSD() ); |
---|
| 1578 | |
---|
[2] | 1579 | if ( bUseVSO ) |
---|
[5] | 1580 | { |
---|
[2] | 1581 | Int iVSOMode = m_pcEncTop->getVSOMode(); |
---|
[608] | 1582 | pcRdCost->setVSOMode( iVSOMode ); |
---|
| 1583 | pcRdCost->setAllowNegDist( m_pcEncTop->getAllowNegDist() ); |
---|
[120] | 1584 | |
---|
[608] | 1585 | // SAIT_VSO_EST_A0033 |
---|
[655] | 1586 | #if H_3D_FCO |
---|
| 1587 | Bool flagRec; |
---|
| 1588 | flagRec = ((m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), true) == NULL) ? false: true); |
---|
| 1589 | pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), flagRec ) ); |
---|
| 1590 | pcRdCost->setDepthPicYuv ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true, pcSlice->getPOC(), false ) ); |
---|
| 1591 | #else |
---|
[608] | 1592 | pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false , pcSlice->getPOC(), true ) ); |
---|
| 1593 | pcRdCost->setDepthPicYuv ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true , pcSlice->getPOC(), false ) ); |
---|
[655] | 1594 | #endif |
---|
[2] | 1595 | |
---|
[608] | 1596 | // LGE_WVSO_A0119 |
---|
[120] | 1597 | Bool bUseWVSO = m_pcEncTop->getUseWVSO(); |
---|
[608] | 1598 | pcRdCost->setUseWVSO( bUseWVSO ); |
---|
[100] | 1599 | |
---|
[2] | 1600 | } |
---|
[5] | 1601 | #endif |
---|
[1200] | 1602 | |
---|
[608] | 1603 | /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice |
---|
| 1604 | // Slice compression |
---|
| 1605 | if (m_pcCfg->getUseASR()) |
---|
| 1606 | { |
---|
| 1607 | m_pcSliceEncoder->setSearchRange(pcSlice); |
---|
| 1608 | } |
---|
[2] | 1609 | |
---|
[608] | 1610 | Bool bGPBcheck=false; |
---|
| 1611 | if ( pcSlice->getSliceType() == B_SLICE) |
---|
| 1612 | { |
---|
| 1613 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
[2] | 1614 | { |
---|
[608] | 1615 | bGPBcheck=true; |
---|
| 1616 | Int i; |
---|
| 1617 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
[2] | 1618 | { |
---|
[1200] | 1619 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
[2] | 1620 | { |
---|
[608] | 1621 | bGPBcheck=false; |
---|
| 1622 | break; |
---|
[2] | 1623 | } |
---|
| 1624 | } |
---|
| 1625 | } |
---|
[608] | 1626 | } |
---|
| 1627 | if(bGPBcheck) |
---|
| 1628 | { |
---|
| 1629 | pcSlice->setMvdL1ZeroFlag(true); |
---|
| 1630 | } |
---|
| 1631 | else |
---|
| 1632 | { |
---|
| 1633 | pcSlice->setMvdL1ZeroFlag(false); |
---|
| 1634 | } |
---|
| 1635 | pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); |
---|
| 1636 | |
---|
[1200] | 1637 | |
---|
[608] | 1638 | Double lambda = 0.0; |
---|
| 1639 | Int actualHeadBits = 0; |
---|
| 1640 | Int actualTotalBits = 0; |
---|
| 1641 | Int estimatedBits = 0; |
---|
| 1642 | Int tmpBitsBeforeWriting = 0; |
---|
[1200] | 1643 | if ( m_pcCfg->getUseRateCtrl() ) // TODO: does this work with multiple slices and slice-segments? |
---|
[608] | 1644 | { |
---|
| 1645 | Int frameLevel = m_pcRateCtrl->getRCSeq()->getGOPID2Level( iGOPid ); |
---|
| 1646 | if ( pcPic->getSlice(0)->getSliceType() == I_SLICE ) |
---|
[2] | 1647 | { |
---|
[608] | 1648 | frameLevel = 0; |
---|
[2] | 1649 | } |
---|
[608] | 1650 | m_pcRateCtrl->initRCPic( frameLevel ); |
---|
[655] | 1651 | |
---|
| 1652 | #if KWU_RC_MADPRED_E0227 |
---|
| 1653 | if(m_pcCfg->getLayerId() != 0) |
---|
| 1654 | { |
---|
| 1655 | m_pcRateCtrl->getRCPic()->setIVPic( m_pcEncTop->getEncTop()->getTEncTop(0)->getRateCtrl()->getRCPic() ); |
---|
| 1656 | } |
---|
| 1657 | #endif |
---|
| 1658 | |
---|
[608] | 1659 | estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits(); |
---|
| 1660 | |
---|
| 1661 | Int sliceQP = m_pcCfg->getInitialQP(); |
---|
| 1662 | if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified |
---|
[56] | 1663 | { |
---|
[608] | 1664 | Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 ); |
---|
| 1665 | Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames ); |
---|
| 1666 | Double dQPFactor = 0.57*dLambda_scale; |
---|
| 1667 | Int SHIFT_QP = 12; |
---|
| 1668 | Int bitdepth_luma_qp_scale = 0; |
---|
| 1669 | Double qp_temp = (Double) sliceQP + bitdepth_luma_qp_scale - SHIFT_QP; |
---|
| 1670 | lambda = dQPFactor*pow( 2.0, qp_temp/3.0 ); |
---|
[56] | 1671 | } |
---|
[608] | 1672 | else if ( frameLevel == 0 ) // intra case, but use the model |
---|
| 1673 | { |
---|
[1200] | 1674 | m_pcSliceEncoder->calCostSliceI(pcPic); // TODO: This only analyses the first slice segment - what about the others? |
---|
| 1675 | |
---|
[608] | 1676 | if ( m_pcCfg->getIntraPeriod() != 1 ) // do not refine allocated bits for all intra case |
---|
| 1677 | { |
---|
| 1678 | Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); |
---|
| 1679 | bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits ); |
---|
| 1680 | if ( bits < 200 ) |
---|
| 1681 | { |
---|
| 1682 | bits = 200; |
---|
| 1683 | } |
---|
| 1684 | m_pcRateCtrl->getRCPic()->setTargetBits( bits ); |
---|
| 1685 | } |
---|
[5] | 1686 | |
---|
[608] | 1687 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
| 1688 | m_pcRateCtrl->getRCPic()->getLCUInitTargetBits(); |
---|
| 1689 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); |
---|
| 1690 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
[2] | 1691 | } |
---|
[608] | 1692 | else // normal case |
---|
[2] | 1693 | { |
---|
[655] | 1694 | #if KWU_RC_MADPRED_E0227 |
---|
| 1695 | if(m_pcRateCtrl->getLayerID() != 0) |
---|
| 1696 | { |
---|
| 1697 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
| 1698 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambdaIV( listPreviousPicture, pcSlice->getPOC() ); |
---|
| 1699 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
| 1700 | } |
---|
| 1701 | else |
---|
| 1702 | { |
---|
| 1703 | #endif |
---|
[608] | 1704 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
| 1705 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); |
---|
| 1706 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
[655] | 1707 | #if KWU_RC_MADPRED_E0227 |
---|
| 1708 | } |
---|
| 1709 | #endif |
---|
[2] | 1710 | } |
---|
| 1711 | |
---|
[1200] | 1712 | sliceQP = Clip3( -pcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, sliceQP ); |
---|
[608] | 1713 | m_pcRateCtrl->getRCPic()->setPicEstQP( sliceQP ); |
---|
| 1714 | |
---|
| 1715 | m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda ); |
---|
| 1716 | } |
---|
| 1717 | |
---|
[1200] | 1718 | UInt uiNumSliceSegments = 1; |
---|
[608] | 1719 | |
---|
[1279] | 1720 | #if NH_3D_NBDV |
---|
[608] | 1721 | if(pcSlice->getViewIndex() && !pcSlice->getIsDepth()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done. |
---|
[313] | 1722 | { |
---|
[1279] | 1723 | Int iColPoc = pcSlice->getRefPOC(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx()); |
---|
[608] | 1724 | pcPic->setNumDdvCandPics(pcPic->getDisCandRefPictures(iColPoc)); |
---|
[313] | 1725 | } |
---|
[655] | 1726 | #endif |
---|
[1200] | 1727 | #if NH_3D |
---|
[608] | 1728 | pcSlice->setDepthToDisparityLUTs(); |
---|
[313] | 1729 | |
---|
[56] | 1730 | #endif |
---|
[655] | 1731 | |
---|
[1279] | 1732 | #if NH_3D_NBDV |
---|
[608] | 1733 | if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done. |
---|
| 1734 | { |
---|
| 1735 | pcPic->checkTemporalIVRef(); |
---|
| 1736 | } |
---|
[655] | 1737 | |
---|
[608] | 1738 | if(pcSlice->getIsDepth()) |
---|
[189] | 1739 | { |
---|
[608] | 1740 | pcPic->checkTextureRef(); |
---|
[189] | 1741 | } |
---|
| 1742 | #endif |
---|
[1200] | 1743 | // Allocate some coders, now the number of tiles are known. |
---|
| 1744 | const Int numSubstreamsColumns = (pcSlice->getPPS()->getNumTileColumnsMinus1() + 1); |
---|
| 1745 | const Int numSubstreamRows = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() ? pcPic->getFrameHeightInCtus() : (pcSlice->getPPS()->getNumTileRowsMinus1() + 1); |
---|
| 1746 | const Int numSubstreams = numSubstreamRows * numSubstreamsColumns; |
---|
| 1747 | std::vector<TComOutputBitstream> substreamsOut(numSubstreams); |
---|
| 1748 | |
---|
| 1749 | // now compress (trial encode) the various slice segments (slices, and dependent slices) |
---|
[608] | 1750 | { |
---|
[1200] | 1751 | const UInt numberOfCtusInFrame=pcPic->getPicSym()->getNumberOfCtusInFrame(); |
---|
| 1752 | pcSlice->setSliceCurStartCtuTsAddr( 0 ); |
---|
| 1753 | pcSlice->setSliceSegmentCurStartCtuTsAddr( 0 ); |
---|
[608] | 1754 | |
---|
[1200] | 1755 | for(UInt nextCtuTsAddr = 0; nextCtuTsAddr < numberOfCtusInFrame; ) |
---|
[2] | 1756 | { |
---|
[1200] | 1757 | m_pcSliceEncoder->precompressSlice( pcPic ); |
---|
[1287] | 1758 | m_pcSliceEncoder->compressSlice ( pcPic, false, false ); |
---|
[608] | 1759 | |
---|
[1200] | 1760 | const UInt curSliceSegmentEnd = pcSlice->getSliceSegmentCurEndCtuTsAddr(); |
---|
| 1761 | if (curSliceSegmentEnd < numberOfCtusInFrame) |
---|
[2] | 1762 | { |
---|
[1200] | 1763 | const Bool bNextSegmentIsDependentSlice=curSliceSegmentEnd<pcSlice->getSliceCurEndCtuTsAddr(); |
---|
| 1764 | const UInt sliceBits=pcSlice->getSliceBits(); |
---|
| 1765 | pcPic->allocateNewSlice(); |
---|
| 1766 | // prepare for next slice |
---|
| 1767 | pcPic->setCurrSliceIdx ( uiNumSliceSegments ); |
---|
| 1768 | m_pcSliceEncoder->setSliceIdx ( uiNumSliceSegments ); |
---|
| 1769 | pcSlice = pcPic->getSlice ( uiNumSliceSegments ); |
---|
| 1770 | assert(pcSlice->getPPS()!=0); |
---|
| 1771 | pcSlice->copySliceInfo ( pcPic->getSlice(uiNumSliceSegments-1) ); |
---|
| 1772 | pcSlice->setSliceIdx ( uiNumSliceSegments ); |
---|
| 1773 | if (bNextSegmentIsDependentSlice) |
---|
| 1774 | { |
---|
| 1775 | pcSlice->setSliceBits(sliceBits); |
---|
| 1776 | } |
---|
| 1777 | else |
---|
| 1778 | { |
---|
| 1779 | pcSlice->setSliceCurStartCtuTsAddr ( curSliceSegmentEnd ); |
---|
| 1780 | pcSlice->setSliceBits(0); |
---|
| 1781 | } |
---|
| 1782 | pcSlice->setDependentSliceSegmentFlag(bNextSegmentIsDependentSlice); |
---|
| 1783 | pcSlice->setSliceSegmentCurStartCtuTsAddr ( curSliceSegmentEnd ); |
---|
| 1784 | // TODO: optimise cabac_init during compress slice to improve multi-slice operation |
---|
| 1785 | // pcSlice->setEncCABACTableIdx(m_pcSliceEncoder->getEncCABACTableIdx()); |
---|
| 1786 | uiNumSliceSegments ++; |
---|
[2] | 1787 | } |
---|
[1200] | 1788 | nextCtuTsAddr = curSliceSegmentEnd; |
---|
[2] | 1789 | } |
---|
[608] | 1790 | } |
---|
[2] | 1791 | |
---|
[1200] | 1792 | duData.clear(); |
---|
[608] | 1793 | pcSlice = pcPic->getSlice(0); |
---|
[2] | 1794 | |
---|
[1200] | 1795 | // SAO parameter estimation using non-deblocked pixels for CTU bottom and right boundary areas |
---|
| 1796 | if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoCtuBoundary() ) |
---|
[608] | 1797 | { |
---|
[872] | 1798 | m_pcSAO->getPreDBFStatistics(pcPic); |
---|
[608] | 1799 | } |
---|
| 1800 | |
---|
| 1801 | //-- Loop filter |
---|
| 1802 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
| 1803 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
| 1804 | if ( m_pcCfg->getDeblockingFilterMetric() ) |
---|
| 1805 | { |
---|
[1200] | 1806 | applyDeblockingFilterMetric(pcPic, uiNumSliceSegments); |
---|
[608] | 1807 | } |
---|
| 1808 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
| 1809 | |
---|
| 1810 | /////////////////////////////////////////////////////////////////////////////////////////////////// File writing |
---|
| 1811 | // Set entropy coder |
---|
[1200] | 1812 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder ); |
---|
[608] | 1813 | if ( m_bSeqFirst ) |
---|
| 1814 | { |
---|
[1200] | 1815 | // write various parameter sets |
---|
| 1816 | actualTotalBits += xWriteParameterSets(accessUnit, pcSlice); |
---|
[773] | 1817 | #if PPS_FIX_DEPTH |
---|
| 1818 | if(!pcSlice->getIsDepth() || !pcSlice->getViewIndex() ) |
---|
| 1819 | { |
---|
| 1820 | #endif |
---|
| 1821 | #if PPS_FIX_DEPTH |
---|
| 1822 | } |
---|
| 1823 | #endif |
---|
[608] | 1824 | |
---|
[1200] | 1825 | |
---|
| 1826 | // create prefix SEI messages at the beginning of the sequence |
---|
| 1827 | assert(leadingSeiMessages.empty()); |
---|
| 1828 | xCreateIRAPLeadingSEIMessages(leadingSeiMessages, pcSlice->getSPS(), pcSlice->getPPS()); |
---|
| 1829 | |
---|
[210] | 1830 | m_bSeqFirst = false; |
---|
| 1831 | } |
---|
[5] | 1832 | |
---|
[1200] | 1833 | // reset presence of BP SEI indication |
---|
| 1834 | m_bufferingPeriodSEIPresentInAU = false; |
---|
| 1835 | // create prefix SEI associated with a picture |
---|
| 1836 | xCreatePerPictureSEIMessages(iGOPid, leadingSeiMessages, nestedSeiMessages, pcSlice); |
---|
| 1837 | |
---|
| 1838 | /* use the main bitstream buffer for storing the marshalled picture */ |
---|
| 1839 | m_pcEntropyCoder->setBitstream(NULL); |
---|
| 1840 | |
---|
| 1841 | pcSlice = pcPic->getSlice(0); |
---|
| 1842 | |
---|
| 1843 | if (pcSlice->getSPS()->getUseSAO()) |
---|
[608] | 1844 | { |
---|
[1200] | 1845 | Bool sliceEnabled[MAX_NUM_COMPONENT]; |
---|
| 1846 | TComBitCounter tempBitCounter; |
---|
| 1847 | tempBitCounter.resetBits(); |
---|
| 1848 | m_pcEncTop->getRDGoOnSbacCoder()->setBitstream(&tempBitCounter); |
---|
| 1849 | m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice); |
---|
| 1850 | m_pcSAO->SAOProcess(pcPic, sliceEnabled, pcPic->getSlice(0)->getLambdas(), m_pcCfg->getTestSAODisableAtPictureLevel(), m_pcCfg->getSaoEncodingRate(), m_pcCfg->getSaoEncodingRateChroma(), m_pcCfg->getSaoCtuBoundary()); |
---|
| 1851 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
| 1852 | m_pcEncTop->getRDGoOnSbacCoder()->setBitstream(NULL); |
---|
[2] | 1853 | |
---|
[1200] | 1854 | //assign SAO slice header |
---|
| 1855 | for(Int s=0; s< uiNumSliceSegments; s++) |
---|
| 1856 | { |
---|
| 1857 | pcPic->getSlice(s)->setSaoEnabledFlag(CHANNEL_TYPE_LUMA, sliceEnabled[COMPONENT_Y]); |
---|
| 1858 | assert(sliceEnabled[COMPONENT_Cb] == sliceEnabled[COMPONENT_Cr]); |
---|
| 1859 | pcPic->getSlice(s)->setSaoEnabledFlag(CHANNEL_TYPE_CHROMA, sliceEnabled[COMPONENT_Cb]); |
---|
| 1860 | } |
---|
| 1861 | } |
---|
[2] | 1862 | |
---|
[1200] | 1863 | // pcSlice is currently slice 0. |
---|
| 1864 | std::size_t binCountsInNalUnits = 0; // For implementation of cabac_zero_word stuffing (section 7.4.3.10) |
---|
| 1865 | std::size_t numBytesInVclNalUnits = 0; // For implementation of cabac_zero_word stuffing (section 7.4.3.10) |
---|
[56] | 1866 | |
---|
[1200] | 1867 | for( UInt sliceSegmentStartCtuTsAddr = 0, sliceIdxCount=0; sliceSegmentStartCtuTsAddr < pcPic->getPicSym()->getNumberOfCtusInFrame(); sliceIdxCount++, sliceSegmentStartCtuTsAddr=pcSlice->getSliceSegmentCurEndCtuTsAddr() ) |
---|
| 1868 | { |
---|
| 1869 | pcSlice = pcPic->getSlice(sliceIdxCount); |
---|
| 1870 | if(sliceIdxCount > 0 && pcSlice->getSliceType()!= I_SLICE) |
---|
[2] | 1871 | { |
---|
[1200] | 1872 | pcSlice->checkColRefIdx(sliceIdxCount, pcPic); |
---|
[608] | 1873 | } |
---|
[1200] | 1874 | pcPic->setCurrSliceIdx(sliceIdxCount); |
---|
| 1875 | m_pcSliceEncoder->setSliceIdx(sliceIdxCount); |
---|
[2] | 1876 | |
---|
[1200] | 1877 | pcSlice->setRPS(pcPic->getSlice(0)->getRPS()); |
---|
| 1878 | pcSlice->setRPSidx(pcPic->getSlice(0)->getRPSidx()); |
---|
[2] | 1879 | |
---|
[1200] | 1880 | for ( UInt ui = 0 ; ui < numSubstreams; ui++ ) |
---|
| 1881 | { |
---|
| 1882 | substreamsOut[ui].clear(); |
---|
| 1883 | } |
---|
[2] | 1884 | |
---|
[1200] | 1885 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder ); |
---|
| 1886 | m_pcEntropyCoder->resetEntropy ( pcSlice ); |
---|
| 1887 | /* start slice NALunit */ |
---|
| 1888 | #if NH_MV |
---|
| 1889 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer(), getLayerId() ); |
---|
| 1890 | #else |
---|
| 1891 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer() ); |
---|
| 1892 | #endif |
---|
| 1893 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
[2] | 1894 | |
---|
[1200] | 1895 | pcSlice->setNoRaslOutputFlag(false); |
---|
| 1896 | if (pcSlice->isIRAP()) |
---|
[608] | 1897 | { |
---|
[1200] | 1898 | if (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) |
---|
[2] | 1899 | { |
---|
[1200] | 1900 | pcSlice->setNoRaslOutputFlag(true); |
---|
[2] | 1901 | } |
---|
[1200] | 1902 | //the inference for NoOutputPriorPicsFlag |
---|
| 1903 | // KJS: This cannot happen at the encoder |
---|
| 1904 | if (!m_bFirst && pcSlice->isIRAP() && pcSlice->getNoRaslOutputFlag()) |
---|
[56] | 1905 | { |
---|
[1200] | 1906 | if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA) |
---|
| 1907 | { |
---|
| 1908 | pcSlice->setNoOutputPriorPicsFlag(true); |
---|
| 1909 | } |
---|
[56] | 1910 | } |
---|
[608] | 1911 | } |
---|
[2] | 1912 | |
---|
[1200] | 1913 | pcSlice->setEncCABACTableIdx(m_pcSliceEncoder->getEncCABACTableIdx()); |
---|
[608] | 1914 | |
---|
[1200] | 1915 | tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 1916 | m_pcEntropyCoder->encodeSliceHeader(pcSlice); |
---|
| 1917 | actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting ); |
---|
[608] | 1918 | |
---|
[1200] | 1919 | pcSlice->setFinalized(true); |
---|
[608] | 1920 | |
---|
[1200] | 1921 | pcSlice->clearSubstreamSizes( ); |
---|
[608] | 1922 | { |
---|
[1200] | 1923 | UInt numBinsCoded = 0; |
---|
| 1924 | m_pcSliceEncoder->encodeSlice(pcPic, &(substreamsOut[0]), numBinsCoded); |
---|
| 1925 | binCountsInNalUnits+=numBinsCoded; |
---|
[608] | 1926 | } |
---|
| 1927 | |
---|
| 1928 | { |
---|
[1200] | 1929 | // Construct the final bitstream by concatenating substreams. |
---|
| 1930 | // The final bitstream is either nalu.m_Bitstream or pcBitstreamRedirect; |
---|
| 1931 | // Complete the slice header info. |
---|
| 1932 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder ); |
---|
| 1933 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1934 | m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice ); |
---|
| 1935 | |
---|
| 1936 | // Append substreams... |
---|
| 1937 | TComOutputBitstream *pcOut = pcBitstreamRedirect; |
---|
| 1938 | const Int numZeroSubstreamsAtStartOfSlice = pcPic->getSubstreamForCtuAddr(pcSlice->getSliceSegmentCurStartCtuTsAddr(), false, pcSlice); |
---|
| 1939 | const Int numSubstreamsToCode = pcSlice->getNumberOfSubstreamSizes()+1; |
---|
| 1940 | for ( UInt ui = 0 ; ui < numSubstreamsToCode; ui++ ) |
---|
[56] | 1941 | { |
---|
[1200] | 1942 | pcOut->addSubstream(&(substreamsOut[ui+numZeroSubstreamsAtStartOfSlice])); |
---|
[56] | 1943 | } |
---|
[608] | 1944 | } |
---|
[5] | 1945 | |
---|
[1200] | 1946 | // If current NALU is the first NALU of slice (containing slice header) and more NALUs exist (due to multiple dependent slices) then buffer it. |
---|
| 1947 | // 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. |
---|
| 1948 | Bool bNALUAlignedWrittenToList = false; // used to ensure current NALU is not written more than once to the NALU list. |
---|
| 1949 | xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect); |
---|
| 1950 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1951 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
| 1952 | numBytesInVclNalUnits += (std::size_t)(accessUnit.back()->m_nalUnitData.str().size()); |
---|
| 1953 | bNALUAlignedWrittenToList = true; |
---|
| 1954 | |
---|
| 1955 | if (!bNALUAlignedWrittenToList) |
---|
[608] | 1956 | { |
---|
[1200] | 1957 | nalu.m_Bitstream.writeAlignZero(); |
---|
[608] | 1958 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1959 | } |
---|
| 1960 | |
---|
[1200] | 1961 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
| 1962 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
| 1963 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
| 1964 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) && |
---|
| 1965 | ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) ) |
---|
[964] | 1966 | { |
---|
[1200] | 1967 | UInt numNalus = 0; |
---|
| 1968 | UInt numRBSPBytes = 0; |
---|
| 1969 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
| 1970 | { |
---|
| 1971 | numRBSPBytes += UInt((*it)->m_nalUnitData.str().size()); |
---|
| 1972 | numNalus ++; |
---|
| 1973 | } |
---|
| 1974 | duData.push_back(DUData()); |
---|
| 1975 | duData.back().accumBitsDU = ( numRBSPBytes << 3 ); |
---|
| 1976 | duData.back().accumNalsDU = numNalus; |
---|
[964] | 1977 | } |
---|
[1200] | 1978 | } // end iteration over slices |
---|
[608] | 1979 | |
---|
[1200] | 1980 | // cabac_zero_words processing |
---|
| 1981 | cabac_zero_word_padding(pcSlice, pcPic, binCountsInNalUnits, numBytesInVclNalUnits, accessUnit.back()->m_nalUnitData, m_pcCfg->getCabacZeroWordPaddingEnabled()); |
---|
| 1982 | #if NH_3D |
---|
| 1983 | pcPic->compressMotion(2); |
---|
[608] | 1984 | #else |
---|
[1200] | 1985 | pcPic->compressMotion(); |
---|
[608] | 1986 | #endif |
---|
[1200] | 1987 | #if NH_MV |
---|
| 1988 | m_pocLastCoded = pcPic->getPOC(); |
---|
[964] | 1989 | #endif |
---|
| 1990 | |
---|
[1200] | 1991 | //-- For time output for each slice |
---|
| 1992 | Double dEncTime = (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
[608] | 1993 | |
---|
[1200] | 1994 | std::string digestStr; |
---|
| 1995 | if (m_pcCfg->getDecodedPictureHashSEIEnabled()) |
---|
| 1996 | { |
---|
| 1997 | SEIDecodedPictureHash *decodedPictureHashSei = new SEIDecodedPictureHash(); |
---|
| 1998 | m_seiEncoder.initDecodedPictureHashSEI(decodedPictureHashSei, pcPic, digestStr, pcSlice->getSPS()->getBitDepths()); |
---|
| 1999 | trailingSeiMessages.push_back(decodedPictureHashSei); |
---|
| 2000 | } |
---|
| 2001 | xWriteTrailingSEIMessages(trailingSeiMessages, accessUnit, pcSlice->getTLayer(), pcSlice->getSPS()); |
---|
[608] | 2002 | |
---|
[1200] | 2003 | m_pcCfg->setEncodedFlag(iGOPid, true); |
---|
[5] | 2004 | |
---|
[1200] | 2005 | xCalculateAddPSNRs( isField, isTff, iGOPid, pcPic, accessUnit, rcListPic, dEncTime, snr_conversion, printFrameMSE ); |
---|
[56] | 2006 | |
---|
[1200] | 2007 | if (!digestStr.empty()) |
---|
| 2008 | { |
---|
| 2009 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
[56] | 2010 | { |
---|
[1200] | 2011 | printf(" [MD5:%s]", digestStr.c_str()); |
---|
[608] | 2012 | } |
---|
[1200] | 2013 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
[608] | 2014 | { |
---|
[1200] | 2015 | printf(" [CRC:%s]", digestStr.c_str()); |
---|
[2] | 2016 | } |
---|
[1200] | 2017 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
[655] | 2018 | { |
---|
[1200] | 2019 | printf(" [Checksum:%s]", digestStr.c_str()); |
---|
[655] | 2020 | } |
---|
| 2021 | } |
---|
[1200] | 2022 | |
---|
| 2023 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
[872] | 2024 | { |
---|
[1200] | 2025 | Double avgQP = m_pcRateCtrl->getRCPic()->calAverageQP(); |
---|
| 2026 | Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda(); |
---|
| 2027 | if ( avgLambda < 0.0 ) |
---|
[872] | 2028 | { |
---|
[1200] | 2029 | avgLambda = lambda; |
---|
[872] | 2030 | } |
---|
[1200] | 2031 | |
---|
| 2032 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType()); |
---|
| 2033 | m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() ); |
---|
| 2034 | |
---|
| 2035 | m_pcRateCtrl->getRCSeq()->updateAfterPic( actualTotalBits ); |
---|
| 2036 | if ( pcSlice->getSliceType() != I_SLICE ) |
---|
[608] | 2037 | { |
---|
[1200] | 2038 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( actualTotalBits ); |
---|
[608] | 2039 | } |
---|
[1200] | 2040 | else // for intra picture, the estimated bits are used to update the current status in the GOP |
---|
[608] | 2041 | { |
---|
[1200] | 2042 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( estimatedBits ); |
---|
[608] | 2043 | } |
---|
[1200] | 2044 | } |
---|
[5] | 2045 | |
---|
[1200] | 2046 | xCreatePictureTimingSEI(m_pcCfg->getEfficientFieldIRAPEnabled()?effFieldIRAPMap.GetIRAPGOPid():0, leadingSeiMessages, nestedSeiMessages, duInfoSeiMessages, pcSlice, isField, duData); |
---|
| 2047 | if (m_pcCfg->getScalableNestingSEIEnabled()) |
---|
| 2048 | { |
---|
| 2049 | xCreateScalableNestingSEI (leadingSeiMessages, nestedSeiMessages); |
---|
| 2050 | } |
---|
| 2051 | xWriteLeadingSEIMessages(leadingSeiMessages, duInfoSeiMessages, accessUnit, pcSlice->getTLayer(), pcSlice->getSPS(), duData); |
---|
| 2052 | xWriteDuSEIMessages(duInfoSeiMessages, accessUnit, pcSlice->getTLayer(), pcSlice->getSPS(), duData); |
---|
[56] | 2053 | |
---|
[1200] | 2054 | pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut); |
---|
[56] | 2055 | |
---|
[1200] | 2056 | pcPic->setReconMark ( true ); |
---|
| 2057 | #if NH_MV |
---|
[622] | 2058 | TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); |
---|
[608] | 2059 | std::vector<Int> temp; |
---|
| 2060 | TComSlice::markCurrPic( pcPic ); |
---|
| 2061 | #endif |
---|
[1200] | 2062 | m_bFirst = false; |
---|
| 2063 | m_iNumPicCoded++; |
---|
| 2064 | m_totalCoded ++; |
---|
| 2065 | /* logging: insert a newline at end of picture period */ |
---|
| 2066 | printf("\n"); |
---|
| 2067 | fflush(stdout); |
---|
[56] | 2068 | |
---|
[1200] | 2069 | if (m_pcCfg->getEfficientFieldIRAPEnabled()) |
---|
[964] | 2070 | { |
---|
[1200] | 2071 | iGOPid=effFieldIRAPMap.restoreGOPid(iGOPid); |
---|
[964] | 2072 | } |
---|
[1200] | 2073 | } // iGOPid-loop |
---|
| 2074 | |
---|
[608] | 2075 | delete pcBitstreamRedirect; |
---|
[56] | 2076 | |
---|
[1200] | 2077 | #if !NH_MV |
---|
| 2078 | assert ( (m_iNumPicCoded == iNumPicRcvd) ); |
---|
[608] | 2079 | #endif |
---|
[56] | 2080 | } |
---|
| 2081 | |
---|
[1200] | 2082 | Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths) |
---|
[56] | 2083 | { |
---|
[608] | 2084 | assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic()); |
---|
[1200] | 2085 | |
---|
| 2086 | |
---|
[608] | 2087 | //--CFG_KDY |
---|
[1200] | 2088 | const Int rateMultiplier=(isField?2:1); |
---|
| 2089 | m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier ); |
---|
| 2090 | m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier ); |
---|
| 2091 | m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier ); |
---|
| 2092 | m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate()*rateMultiplier ); |
---|
| 2093 | const ChromaFormat chFmt = m_pcCfg->getChromaFormatIdc(); |
---|
| 2094 | |
---|
[608] | 2095 | //-- all |
---|
[1200] | 2096 | #if NH_MV |
---|
| 2097 | printf( "\n\nSUMMARY -------------------------------------------- LayerId %2d\n", getLayerId() ); |
---|
| 2098 | #else |
---|
[608] | 2099 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
[1200] | 2100 | #endif |
---|
| 2101 | m_gcAnalyzeAll.printOut('a', chFmt, printMSEBasedSNR, printSequenceMSE, bitDepths); |
---|
| 2102 | |
---|
[608] | 2103 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
[1200] | 2104 | m_gcAnalyzeI.printOut('i', chFmt, printMSEBasedSNR, printSequenceMSE, bitDepths); |
---|
| 2105 | |
---|
[608] | 2106 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
[1200] | 2107 | m_gcAnalyzeP.printOut('p', chFmt, printMSEBasedSNR, printSequenceMSE, bitDepths); |
---|
| 2108 | |
---|
[608] | 2109 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
[1200] | 2110 | m_gcAnalyzeB.printOut('b', chFmt, printMSEBasedSNR, printSequenceMSE, bitDepths); |
---|
[56] | 2111 | |
---|
[1200] | 2112 | if (!m_pcCfg->getSummaryOutFilename().empty()) |
---|
| 2113 | { |
---|
| 2114 | m_gcAnalyzeAll.printSummary(chFmt, printSequenceMSE, bitDepths, m_pcCfg->getSummaryOutFilename()); |
---|
| 2115 | } |
---|
| 2116 | |
---|
| 2117 | if (!m_pcCfg->getSummaryPicFilenameBase().empty()) |
---|
| 2118 | { |
---|
| 2119 | m_gcAnalyzeI.printSummary(chFmt, printSequenceMSE, bitDepths, m_pcCfg->getSummaryPicFilenameBase()+"I.txt"); |
---|
| 2120 | m_gcAnalyzeP.printSummary(chFmt, printSequenceMSE, bitDepths, m_pcCfg->getSummaryPicFilenameBase()+"P.txt"); |
---|
| 2121 | m_gcAnalyzeB.printSummary(chFmt, printSequenceMSE, bitDepths, m_pcCfg->getSummaryPicFilenameBase()+"B.txt"); |
---|
| 2122 | } |
---|
| 2123 | |
---|
[655] | 2124 | if(isField) |
---|
| 2125 | { |
---|
| 2126 | //-- interlaced summary |
---|
| 2127 | m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate()); |
---|
[1200] | 2128 | m_gcAnalyzeAll_in.setBits(m_gcAnalyzeAll.getBits()); |
---|
| 2129 | // prior to the above statement, the interlace analyser does not contain the correct total number of bits. |
---|
| 2130 | |
---|
[655] | 2131 | printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" ); |
---|
[1200] | 2132 | m_gcAnalyzeAll_in.printOut('a', chFmt, printMSEBasedSNR, printSequenceMSE, bitDepths); |
---|
| 2133 | |
---|
| 2134 | if (!m_pcCfg->getSummaryOutFilename().empty()) |
---|
| 2135 | { |
---|
| 2136 | m_gcAnalyzeAll_in.printSummary(chFmt, printSequenceMSE, bitDepths, m_pcCfg->getSummaryOutFilename()); |
---|
| 2137 | } |
---|
[655] | 2138 | } |
---|
| 2139 | |
---|
[608] | 2140 | printf("\nRVM: %.3lf\n" , xCalculateRVM()); |
---|
[56] | 2141 | } |
---|
[1200] | 2142 | |
---|
| 2143 | #if NH_3D_VSO |
---|
| 2144 | Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, Dist64& ruiDist ) |
---|
[608] | 2145 | #else |
---|
[1200] | 2146 | Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist ) |
---|
[608] | 2147 | #endif |
---|
[56] | 2148 | { |
---|
[2] | 2149 | Bool bCalcDist = false; |
---|
[608] | 2150 | m_pcLoopFilter->setCfg(m_pcCfg->getLFCrossTileBoundaryFlag()); |
---|
[2] | 2151 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
[1200] | 2152 | |
---|
[2] | 2153 | if (!bCalcDist) |
---|
[1200] | 2154 | { |
---|
| 2155 | ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec(), pcPic->getPicSym()->getSPS().getBitDepths()); |
---|
| 2156 | } |
---|
[2] | 2157 | } |
---|
| 2158 | |
---|
| 2159 | // ==================================================================================================================== |
---|
| 2160 | // Protected member functions |
---|
| 2161 | // ==================================================================================================================== |
---|
| 2162 | |
---|
[655] | 2163 | |
---|
[1200] | 2164 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, Bool isField ) |
---|
[655] | 2165 | { |
---|
| 2166 | assert( iNumPicRcvd > 0 ); |
---|
| 2167 | // Exception for the first frames |
---|
| 2168 | if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField && (iPOCLast == 0)) ) |
---|
| 2169 | { |
---|
| 2170 | m_iGopSize = 1; |
---|
| 2171 | } |
---|
| 2172 | else |
---|
| 2173 | { |
---|
| 2174 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
| 2175 | } |
---|
| 2176 | assert (m_iGopSize > 0); |
---|
[1200] | 2177 | |
---|
[655] | 2178 | return; |
---|
| 2179 | } |
---|
| 2180 | |
---|
[1200] | 2181 | |
---|
[608] | 2182 | Void TEncGOP::xGetBuffer( TComList<TComPic*>& rcListPic, |
---|
[56] | 2183 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
| 2184 | Int iNumPicRcvd, |
---|
| 2185 | Int iTimeOffset, |
---|
| 2186 | TComPic*& rpcPic, |
---|
| 2187 | TComPicYuv*& rpcPicYuvRecOut, |
---|
[655] | 2188 | Int pocCurr, |
---|
[1200] | 2189 | Bool isField) |
---|
[56] | 2190 | { |
---|
| 2191 | Int i; |
---|
| 2192 | // Rec. output |
---|
| 2193 | TComList<TComPicYuv*>::iterator iterPicYuvRec = rcListPicYuvRecOut.end(); |
---|
[1200] | 2194 | |
---|
| 2195 | if (isField && pocCurr > 1 && m_iGopSize!=1) |
---|
[56] | 2196 | { |
---|
[1200] | 2197 | iTimeOffset--; |
---|
[655] | 2198 | } |
---|
[1200] | 2199 | |
---|
| 2200 | for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ ) |
---|
[655] | 2201 | { |
---|
[56] | 2202 | iterPicYuvRec--; |
---|
| 2203 | } |
---|
[1200] | 2204 | |
---|
[56] | 2205 | rpcPicYuvRecOut = *(iterPicYuvRec); |
---|
[1200] | 2206 | |
---|
[56] | 2207 | // Current pic. |
---|
| 2208 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
| 2209 | while (iterPic != rcListPic.end()) |
---|
| 2210 | { |
---|
| 2211 | rpcPic = *(iterPic); |
---|
| 2212 | rpcPic->setCurrSliceIdx(0); |
---|
[608] | 2213 | if (rpcPic->getPOC() == pocCurr) |
---|
[56] | 2214 | { |
---|
| 2215 | break; |
---|
| 2216 | } |
---|
| 2217 | iterPic++; |
---|
| 2218 | } |
---|
[655] | 2219 | |
---|
[1200] | 2220 | #if !NH_MV |
---|
| 2221 | assert (rpcPic != NULL); |
---|
[655] | 2222 | #endif |
---|
[608] | 2223 | assert (rpcPic->getPOC() == pocCurr); |
---|
[1200] | 2224 | |
---|
[56] | 2225 | return; |
---|
| 2226 | } |
---|
| 2227 | |
---|
[1200] | 2228 | #if NH_3D_VSO |
---|
| 2229 | Dist64 TEncGOP::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths) |
---|
[608] | 2230 | #else |
---|
[1200] | 2231 | UInt64 TEncGOP::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths) |
---|
[608] | 2232 | #endif |
---|
[56] | 2233 | { |
---|
[1200] | 2234 | #if NH_3D_VSO |
---|
[608] | 2235 | Dist64 uiTotalDiff = 0; |
---|
| 2236 | #else |
---|
[2] | 2237 | UInt64 uiTotalDiff = 0; |
---|
[608] | 2238 | #endif |
---|
[1200] | 2239 | |
---|
| 2240 | for(Int chan=0; chan<pcPic0 ->getNumberValidComponents(); chan++) |
---|
[2] | 2241 | { |
---|
[1200] | 2242 | const ComponentID ch=ComponentID(chan); |
---|
| 2243 | Pel* pSrc0 = pcPic0 ->getAddr(ch); |
---|
| 2244 | Pel* pSrc1 = pcPic1 ->getAddr(ch); |
---|
| 2245 | UInt uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepths.recon[toChannelType(ch)]-8); |
---|
| 2246 | |
---|
| 2247 | const Int iStride = pcPic0->getStride(ch); |
---|
| 2248 | const Int iWidth = pcPic0->getWidth(ch); |
---|
| 2249 | const Int iHeight = pcPic0->getHeight(ch); |
---|
| 2250 | |
---|
| 2251 | for(Int y = 0; y < iHeight; y++ ) |
---|
[2] | 2252 | { |
---|
[1200] | 2253 | for(Int x = 0; x < iWidth; x++ ) |
---|
| 2254 | { |
---|
| 2255 | Intermediate_Int iTemp = pSrc0[x] - pSrc1[x]; |
---|
| 2256 | uiTotalDiff += UInt64((iTemp*iTemp) >> uiShift); |
---|
| 2257 | } |
---|
| 2258 | pSrc0 += iStride; |
---|
| 2259 | pSrc1 += iStride; |
---|
[2] | 2260 | } |
---|
| 2261 | } |
---|
[1200] | 2262 | |
---|
| 2263 | return uiTotalDiff; |
---|
| 2264 | } |
---|
| 2265 | |
---|
| 2266 | Void TEncGOP::xCalculateAddPSNRs( const Bool isField, const Bool isFieldTopFieldFirst, const Int iGOPid, TComPic* pcPic, const AccessUnit&accessUnit, TComList<TComPic*> &rcListPic, const Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ) |
---|
| 2267 | { |
---|
| 2268 | xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime, snr_conversion, printFrameMSE ); |
---|
| 2269 | |
---|
| 2270 | //In case of field coding, compute the interlaced PSNR for both fields |
---|
| 2271 | if(isField) |
---|
[2] | 2272 | { |
---|
[1200] | 2273 | Bool bothFieldsAreEncoded = false; |
---|
| 2274 | Int correspondingFieldPOC = pcPic->getPOC(); |
---|
| 2275 | Int currentPicGOPPoc = m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
| 2276 | if(pcPic->getPOC() == 0) |
---|
[2] | 2277 | { |
---|
[1200] | 2278 | // particular case for POC 0 and 1. |
---|
| 2279 | // If they are not encoded first and separately from other pictures, we need to change this |
---|
| 2280 | // POC 0 is always encoded first then POC 1 is encoded |
---|
| 2281 | bothFieldsAreEncoded = false; |
---|
[2] | 2282 | } |
---|
[1200] | 2283 | else if(pcPic->getPOC() == 1) |
---|
[2] | 2284 | { |
---|
[1200] | 2285 | // if we are at POC 1, POC 0 has been encoded for sure |
---|
| 2286 | correspondingFieldPOC = 0; |
---|
| 2287 | bothFieldsAreEncoded = true; |
---|
[2] | 2288 | } |
---|
[1200] | 2289 | else |
---|
| 2290 | { |
---|
| 2291 | if(pcPic->getPOC()%2 == 1) |
---|
| 2292 | { |
---|
| 2293 | correspondingFieldPOC -= 1; // all odd POC are associated with the preceding even POC (e.g poc 1 is associated to poc 0) |
---|
| 2294 | currentPicGOPPoc -= 1; |
---|
| 2295 | } |
---|
| 2296 | else |
---|
| 2297 | { |
---|
| 2298 | correspondingFieldPOC += 1; // all even POC are associated with the following odd POC (e.g poc 0 is associated to poc 1) |
---|
| 2299 | currentPicGOPPoc += 1; |
---|
| 2300 | } |
---|
| 2301 | for(Int i = 0; i < m_iGopSize; i ++) |
---|
| 2302 | { |
---|
| 2303 | if(m_pcCfg->getGOPEntry(i).m_POC == currentPicGOPPoc) |
---|
| 2304 | { |
---|
| 2305 | bothFieldsAreEncoded = m_pcCfg->getGOPEntry(i).m_isEncoded; |
---|
| 2306 | break; |
---|
| 2307 | } |
---|
| 2308 | } |
---|
| 2309 | } |
---|
| 2310 | |
---|
| 2311 | if(bothFieldsAreEncoded) |
---|
| 2312 | { |
---|
| 2313 | //get complementary top field |
---|
| 2314 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
| 2315 | while ((*iterPic)->getPOC() != correspondingFieldPOC) |
---|
| 2316 | { |
---|
| 2317 | iterPic ++; |
---|
| 2318 | } |
---|
| 2319 | TComPic* correspondingFieldPic = *(iterPic); |
---|
| 2320 | |
---|
| 2321 | if( (pcPic->isTopField() && isFieldTopFieldFirst) || (!pcPic->isTopField() && !isFieldTopFieldFirst)) |
---|
| 2322 | { |
---|
| 2323 | xCalculateInterlacedAddPSNR(pcPic, correspondingFieldPic, pcPic->getPicYuvRec(), correspondingFieldPic->getPicYuvRec(), snr_conversion, printFrameMSE ); |
---|
| 2324 | } |
---|
| 2325 | else |
---|
| 2326 | { |
---|
| 2327 | xCalculateInterlacedAddPSNR(correspondingFieldPic, pcPic, correspondingFieldPic->getPicYuvRec(), pcPic->getPicYuvRec(), snr_conversion, printFrameMSE ); |
---|
| 2328 | } |
---|
| 2329 | } |
---|
[2] | 2330 | } |
---|
| 2331 | } |
---|
| 2332 | |
---|
[1200] | 2333 | Void TEncGOP::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit& accessUnit, Double dEncTime, const InputColourSpaceConversion conversion, const Bool printFrameMSE ) |
---|
[2] | 2334 | { |
---|
[1200] | 2335 | Double dPSNR[MAX_NUM_COMPONENT]; |
---|
| 2336 | |
---|
| 2337 | for(Int i=0; i<MAX_NUM_COMPONENT; i++) |
---|
[56] | 2338 | { |
---|
[1200] | 2339 | dPSNR[i]=0.0; |
---|
[56] | 2340 | } |
---|
| 2341 | |
---|
[1200] | 2342 | TComPicYuv cscd; |
---|
| 2343 | if (conversion!=IPCOLOURSPACE_UNCHANGED) |
---|
| 2344 | { |
---|
| 2345 | cscd.create(pcPicD->getWidth(COMPONENT_Y), pcPicD->getHeight(COMPONENT_Y), pcPicD->getChromaFormat(), pcPicD->getWidth(COMPONENT_Y), pcPicD->getHeight(COMPONENT_Y), 0, false); |
---|
| 2346 | TVideoIOYuv::ColourSpaceConvert(*pcPicD, cscd, conversion, false); |
---|
| 2347 | } |
---|
| 2348 | TComPicYuv &picd=(conversion==IPCOLOURSPACE_UNCHANGED)?*pcPicD : cscd; |
---|
| 2349 | |
---|
[2] | 2350 | //===== calculate PSNR ===== |
---|
[1200] | 2351 | Double MSEyuvframe[MAX_NUM_COMPONENT] = {0, 0, 0}; |
---|
| 2352 | |
---|
| 2353 | for(Int chan=0; chan<pcPicD->getNumberValidComponents(); chan++) |
---|
[2] | 2354 | { |
---|
[1200] | 2355 | const ComponentID ch=ComponentID(chan); |
---|
| 2356 | const TComPicYuv *pOrgPicYuv =(conversion!=IPCOLOURSPACE_UNCHANGED) ? pcPic ->getPicYuvTrueOrg() : pcPic ->getPicYuvOrg(); |
---|
| 2357 | const Pel* pOrg = pOrgPicYuv->getAddr(ch); |
---|
| 2358 | const Int iOrgStride = pOrgPicYuv->getStride(ch); |
---|
| 2359 | Pel* pRec = picd.getAddr(ch); |
---|
| 2360 | const Int iRecStride = picd.getStride(ch); |
---|
| 2361 | |
---|
| 2362 | const Int iWidth = pcPicD->getWidth (ch) - (m_pcEncTop->getPad(0) >> pcPic->getComponentScaleX(ch)); |
---|
| 2363 | const Int iHeight = pcPicD->getHeight(ch) - ((m_pcEncTop->getPad(1) >> (pcPic->isField()?1:0)) >> pcPic->getComponentScaleY(ch)); |
---|
| 2364 | |
---|
| 2365 | Int iSize = iWidth*iHeight; |
---|
| 2366 | |
---|
| 2367 | UInt64 uiSSDtemp=0; |
---|
| 2368 | for(Int y = 0; y < iHeight; y++ ) |
---|
[2] | 2369 | { |
---|
[1200] | 2370 | for(Int x = 0; x < iWidth; x++ ) |
---|
| 2371 | { |
---|
| 2372 | Intermediate_Int iDiff = (Intermediate_Int)( pOrg[x] - pRec[x] ); |
---|
| 2373 | uiSSDtemp += iDiff * iDiff; |
---|
| 2374 | } |
---|
| 2375 | pOrg += iOrgStride; |
---|
| 2376 | pRec += iRecStride; |
---|
[2] | 2377 | } |
---|
[1200] | 2378 | #if NH_3D_VSO |
---|
[608] | 2379 | #if H_3D_VSO_SYNTH_DIST_OUT |
---|
[2] | 2380 | if ( m_pcRdCost->getUseRenModel() ) |
---|
| 2381 | { |
---|
[56] | 2382 | unsigned int maxval = 255 * (1<<(g_uiBitDepth + g_uiBitIncrement -8)); |
---|
| 2383 | Double fRefValueY = (double) maxval * maxval * iSize; |
---|
| 2384 | Double fRefValueC = fRefValueY / 4.0; |
---|
[5] | 2385 | TRenModel* pcRenModel = m_pcEncTop->getEncTop()->getRenModel(); |
---|
| 2386 | Int64 iDistVSOY, iDistVSOU, iDistVSOV; |
---|
| 2387 | pcRenModel->getTotalSSE( iDistVSOY, iDistVSOU, iDistVSOV ); |
---|
[2] | 2388 | dYPSNR = ( iDistVSOY ? 10.0 * log10( fRefValueY / (Double) iDistVSOY ) : 99.99 ); |
---|
| 2389 | dUPSNR = ( iDistVSOU ? 10.0 * log10( fRefValueC / (Double) iDistVSOU ) : 99.99 ); |
---|
| 2390 | dVPSNR = ( iDistVSOV ? 10.0 * log10( fRefValueC / (Double) iDistVSOV ) : 99.99 ); |
---|
| 2391 | } |
---|
| 2392 | else |
---|
[608] | 2393 | { |
---|
[5] | 2394 | #endif |
---|
[77] | 2395 | #endif |
---|
[1200] | 2396 | const Int maxval = 255 << (pcPic->getPicSym()->getSPS().getBitDepth(toChannelType(ch)) - 8); |
---|
| 2397 | const Double fRefValue = (Double) maxval * maxval * iSize; |
---|
| 2398 | dPSNR[ch] = ( uiSSDtemp ? 10.0 * log10( fRefValue / (Double)uiSSDtemp ) : 999.99 ); |
---|
| 2399 | MSEyuvframe[ch] = (Double)uiSSDtemp/(iSize); |
---|
[2] | 2400 | } |
---|
[1200] | 2401 | |
---|
| 2402 | #if NH_3D_VSO |
---|
[608] | 2403 | #if H_3D_VSO_SYNTH_DIST_OUT |
---|
| 2404 | } |
---|
| 2405 | #endif |
---|
[1200] | 2406 | #endif |
---|
[56] | 2407 | /* calculate the size of the access unit, excluding: |
---|
| 2408 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
| 2409 | * - SEI NAL units |
---|
| 2410 | */ |
---|
[608] | 2411 | UInt numRBSPBytes = 0; |
---|
[56] | 2412 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
| 2413 | { |
---|
[608] | 2414 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
[1200] | 2415 | if (m_pcCfg->getSummaryVerboseness() > 0) |
---|
| 2416 | { |
---|
[56] | 2417 | printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal); |
---|
[1200] | 2418 | } |
---|
[608] | 2419 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
| 2420 | { |
---|
[56] | 2421 | numRBSPBytes += numRBSPBytes_nal; |
---|
[608] | 2422 | } |
---|
[56] | 2423 | } |
---|
[5] | 2424 | |
---|
[608] | 2425 | UInt uibits = numRBSPBytes * 8; |
---|
[2] | 2426 | m_vRVM_RP.push_back( uibits ); |
---|
| 2427 | |
---|
| 2428 | //===== add PSNR ===== |
---|
[1200] | 2429 | m_gcAnalyzeAll.addResult (dPSNR, (Double)uibits, MSEyuvframe); |
---|
| 2430 | |
---|
[2] | 2431 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
| 2432 | if (pcSlice->isIntra()) |
---|
| 2433 | { |
---|
[1200] | 2434 | m_gcAnalyzeI.addResult (dPSNR, (Double)uibits, MSEyuvframe); |
---|
[2] | 2435 | } |
---|
| 2436 | if (pcSlice->isInterP()) |
---|
| 2437 | { |
---|
[1200] | 2438 | m_gcAnalyzeP.addResult (dPSNR, (Double)uibits, MSEyuvframe); |
---|
[2] | 2439 | } |
---|
| 2440 | if (pcSlice->isInterB()) |
---|
| 2441 | { |
---|
[1200] | 2442 | m_gcAnalyzeB.addResult (dPSNR, (Double)uibits, MSEyuvframe); |
---|
[2] | 2443 | } |
---|
| 2444 | |
---|
[56] | 2445 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
[1200] | 2446 | if (!pcSlice->isReferenced()) |
---|
| 2447 | { |
---|
| 2448 | c += 32; |
---|
| 2449 | } |
---|
[5] | 2450 | |
---|
[56] | 2451 | #if ADAPTIVE_QP_SELECTION |
---|
[1200] | 2452 | #if NH_MV |
---|
[608] | 2453 | printf("Layer %3d POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
| 2454 | pcSlice->getLayerId(), |
---|
| 2455 | pcSlice->getPOC(), |
---|
| 2456 | pcSlice->getTLayer(), |
---|
| 2457 | c, |
---|
| 2458 | pcSlice->getSliceQpBase(), |
---|
| 2459 | pcSlice->getSliceQp(), |
---|
| 2460 | uibits ); |
---|
| 2461 | #else |
---|
| 2462 | printf("POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
[56] | 2463 | pcSlice->getPOC(), |
---|
| 2464 | pcSlice->getTLayer(), |
---|
| 2465 | c, |
---|
| 2466 | pcSlice->getSliceQpBase(), |
---|
| 2467 | pcSlice->getSliceQp(), |
---|
| 2468 | uibits ); |
---|
[608] | 2469 | #endif |
---|
[56] | 2470 | #else |
---|
[1200] | 2471 | #if NH_MV |
---|
[608] | 2472 | printf("Layer %3d POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
| 2473 | pcSlice->getLayerId(), |
---|
| 2474 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
| 2475 | pcSlice->getTLayer(), |
---|
| 2476 | c, |
---|
| 2477 | pcSlice->getSliceQp(), |
---|
| 2478 | uibits ); |
---|
| 2479 | #else |
---|
| 2480 | printf("POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
[56] | 2481 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
| 2482 | pcSlice->getTLayer(), |
---|
| 2483 | c, |
---|
| 2484 | pcSlice->getSliceQp(), |
---|
| 2485 | uibits ); |
---|
| 2486 | #endif |
---|
[608] | 2487 | #endif |
---|
[1200] | 2488 | #if NH_MV |
---|
| 2489 | printf(" [Y %8.4lf dB U %8.4lf dB V %8.4lf dB]", dPSNR[COMPONENT_Y], dPSNR[COMPONENT_Cb], dPSNR[COMPONENT_Cr] ); |
---|
| 2490 | #else |
---|
| 2491 | printf(" [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", dPSNR[COMPONENT_Y], dPSNR[COMPONENT_Cb], dPSNR[COMPONENT_Cr] ); |
---|
| 2492 | #endif |
---|
| 2493 | if (printFrameMSE) |
---|
| 2494 | { |
---|
| 2495 | printf(" [Y MSE %6.4lf U MSE %6.4lf V MSE %6.4lf]", MSEyuvframe[COMPONENT_Y], MSEyuvframe[COMPONENT_Cb], MSEyuvframe[COMPONENT_Cr] ); |
---|
| 2496 | } |
---|
| 2497 | printf(" [ET %5.0f ]", dEncTime ); |
---|
[56] | 2498 | |
---|
[2] | 2499 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
| 2500 | { |
---|
[56] | 2501 | printf(" [L%d ", iRefList); |
---|
[2] | 2502 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
| 2503 | { |
---|
[1200] | 2504 | #if NH_MV |
---|
[608] | 2505 | if( pcSlice->getLayerId() != pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) ) |
---|
[2] | 2506 | { |
---|
[608] | 2507 | printf( "V%d ", pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) ); |
---|
[2] | 2508 | } |
---|
| 2509 | else |
---|
[56] | 2510 | { |
---|
[608] | 2511 | #endif |
---|
| 2512 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
[1200] | 2513 | #if NH_MV |
---|
[56] | 2514 | } |
---|
[608] | 2515 | #endif |
---|
[2] | 2516 | } |
---|
[56] | 2517 | printf("]"); |
---|
[2] | 2518 | } |
---|
[1200] | 2519 | |
---|
| 2520 | cscd.destroy(); |
---|
[2] | 2521 | } |
---|
| 2522 | |
---|
[1200] | 2523 | Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
| 2524 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
| 2525 | const InputColourSpaceConversion conversion, const Bool printFrameMSE ) |
---|
[655] | 2526 | { |
---|
| 2527 | |
---|
[1200] | 2528 | #if NH_MV |
---|
[655] | 2529 | assert( 0 ); // Field coding and MV need to be aligned. |
---|
| 2530 | #else |
---|
[1200] | 2531 | |
---|
| 2532 | const TComSPS &sps=pcPicOrgFirstField->getPicSym()->getSPS(); |
---|
| 2533 | Double dPSNR[MAX_NUM_COMPONENT]; |
---|
| 2534 | TComPic *apcPicOrgFields[2]={pcPicOrgFirstField, pcPicOrgSecondField}; |
---|
| 2535 | TComPicYuv *apcPicRecFields[2]={pcPicRecFirstField, pcPicRecSecondField}; |
---|
| 2536 | |
---|
| 2537 | for(Int i=0; i<MAX_NUM_COMPONENT; i++) |
---|
[655] | 2538 | { |
---|
[1200] | 2539 | dPSNR[i]=0.0; |
---|
[655] | 2540 | } |
---|
[1200] | 2541 | |
---|
| 2542 | TComPicYuv cscd[2 /* first/second field */]; |
---|
| 2543 | if (conversion!=IPCOLOURSPACE_UNCHANGED) |
---|
[655] | 2544 | { |
---|
[1200] | 2545 | for(UInt fieldNum=0; fieldNum<2; fieldNum++) |
---|
[655] | 2546 | { |
---|
[1200] | 2547 | TComPicYuv &reconField=*(apcPicRecFields[fieldNum]); |
---|
| 2548 | cscd[fieldNum].create(reconField.getWidth(COMPONENT_Y), reconField.getHeight(COMPONENT_Y), reconField.getChromaFormat(), reconField.getWidth(COMPONENT_Y), reconField.getHeight(COMPONENT_Y), 0, false); |
---|
| 2549 | TVideoIOYuv::ColourSpaceConvert(reconField, cscd[fieldNum], conversion, false); |
---|
| 2550 | apcPicRecFields[fieldNum]=cscd+fieldNum; |
---|
[655] | 2551 | } |
---|
| 2552 | } |
---|
[1200] | 2553 | |
---|
[655] | 2554 | //===== calculate PSNR ===== |
---|
[1200] | 2555 | Double MSEyuvframe[MAX_NUM_COMPONENT] = {0, 0, 0}; |
---|
| 2556 | |
---|
| 2557 | assert(apcPicRecFields[0]->getChromaFormat()==apcPicRecFields[1]->getChromaFormat()); |
---|
| 2558 | const UInt numValidComponents=apcPicRecFields[0]->getNumberValidComponents(); |
---|
| 2559 | |
---|
| 2560 | for(Int chan=0; chan<numValidComponents; chan++) |
---|
[655] | 2561 | { |
---|
[1200] | 2562 | const ComponentID ch=ComponentID(chan); |
---|
| 2563 | assert(apcPicRecFields[0]->getWidth(ch)==apcPicRecFields[1]->getWidth(ch)); |
---|
| 2564 | assert(apcPicRecFields[0]->getHeight(ch)==apcPicRecFields[1]->getHeight(ch)); |
---|
| 2565 | |
---|
| 2566 | UInt64 uiSSDtemp=0; |
---|
| 2567 | const Int iWidth = apcPicRecFields[0]->getWidth (ch) - (m_pcEncTop->getPad(0) >> apcPicRecFields[0]->getComponentScaleX(ch)); |
---|
| 2568 | const Int iHeight = apcPicRecFields[0]->getHeight(ch) - ((m_pcEncTop->getPad(1) >> 1) >> apcPicRecFields[0]->getComponentScaleY(ch)); |
---|
| 2569 | |
---|
| 2570 | Int iSize = iWidth*iHeight; |
---|
| 2571 | |
---|
| 2572 | for(UInt fieldNum=0; fieldNum<2; fieldNum++) |
---|
[655] | 2573 | { |
---|
[1200] | 2574 | TComPic *pcPic=apcPicOrgFields[fieldNum]; |
---|
| 2575 | TComPicYuv *pcPicD=apcPicRecFields[fieldNum]; |
---|
| 2576 | |
---|
| 2577 | const Pel* pOrg = (conversion!=IPCOLOURSPACE_UNCHANGED) ? pcPic ->getPicYuvTrueOrg()->getAddr(ch) : pcPic ->getPicYuvOrg()->getAddr(ch); |
---|
| 2578 | Pel* pRec = pcPicD->getAddr(ch); |
---|
| 2579 | const Int iStride = pcPicD->getStride(ch); |
---|
| 2580 | |
---|
| 2581 | |
---|
| 2582 | for(Int y = 0; y < iHeight; y++ ) |
---|
| 2583 | { |
---|
| 2584 | for(Int x = 0; x < iWidth; x++ ) |
---|
| 2585 | { |
---|
| 2586 | Intermediate_Int iDiff = (Intermediate_Int)( pOrg[x] - pRec[x] ); |
---|
| 2587 | uiSSDtemp += iDiff * iDiff; |
---|
| 2588 | } |
---|
| 2589 | pOrg += iStride; |
---|
| 2590 | pRec += iStride; |
---|
| 2591 | } |
---|
[655] | 2592 | } |
---|
[1200] | 2593 | const Int maxval = 255 << (sps.getBitDepth(toChannelType(ch)) - 8); |
---|
| 2594 | const Double fRefValue = (Double) maxval * maxval * iSize*2; |
---|
| 2595 | dPSNR[ch] = ( uiSSDtemp ? 10.0 * log10( fRefValue / (Double)uiSSDtemp ) : 999.99 ); |
---|
| 2596 | MSEyuvframe[ch] = (Double)uiSSDtemp/(iSize*2); |
---|
[655] | 2597 | } |
---|
[1200] | 2598 | |
---|
| 2599 | UInt uibits = 0; // the number of bits for the pair is not calculated here - instead the overall total is used elsewhere. |
---|
| 2600 | |
---|
| 2601 | //===== add PSNR ===== |
---|
| 2602 | m_gcAnalyzeAll_in.addResult (dPSNR, (Double)uibits, MSEyuvframe); |
---|
| 2603 | |
---|
| 2604 | printf("\n Interlaced frame %d: [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", pcPicOrgSecondField->getPOC()/2 , dPSNR[COMPONENT_Y], dPSNR[COMPONENT_Cb], dPSNR[COMPONENT_Cr] ); |
---|
| 2605 | if (printFrameMSE) |
---|
[655] | 2606 | { |
---|
[1200] | 2607 | printf(" [Y MSE %6.4lf U MSE %6.4lf V MSE %6.4lf]", MSEyuvframe[COMPONENT_Y], MSEyuvframe[COMPONENT_Cb], MSEyuvframe[COMPONENT_Cr] ); |
---|
[655] | 2608 | } |
---|
[1200] | 2609 | |
---|
| 2610 | for(UInt fieldNum=0; fieldNum<2; fieldNum++) |
---|
| 2611 | { |
---|
| 2612 | cscd[fieldNum].destroy(); |
---|
| 2613 | } |
---|
[655] | 2614 | #endif |
---|
| 2615 | } |
---|
[1200] | 2616 | |
---|
[2] | 2617 | /** Function for deciding the nal_unit_type. |
---|
[608] | 2618 | * \param pocCurr POC of the current picture |
---|
[1200] | 2619 | * \param lastIDR POC of the last IDR picture |
---|
| 2620 | * \param isField true to indicate field coding |
---|
| 2621 | * \returns the NAL unit type of the picture |
---|
[2] | 2622 | * This function checks the configuration and returns the appropriate nal_unit_type for the picture. |
---|
| 2623 | */ |
---|
[872] | 2624 | NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR, Bool isField) |
---|
[2] | 2625 | { |
---|
[608] | 2626 | if (pocCurr == 0) |
---|
[2] | 2627 | { |
---|
[608] | 2628 | return NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
---|
[2] | 2629 | } |
---|
[1200] | 2630 | |
---|
| 2631 | if(m_pcCfg->getEfficientFieldIRAPEnabled() && isField && pocCurr == 1) |
---|
[964] | 2632 | { |
---|
| 2633 | // to avoid the picture becoming an IRAP |
---|
| 2634 | return NAL_UNIT_CODED_SLICE_TRAIL_R; |
---|
| 2635 | } |
---|
| 2636 | |
---|
| 2637 | if(m_pcCfg->getDecodingRefreshType() != 3 && (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0) |
---|
[2] | 2638 | { |
---|
| 2639 | if (m_pcCfg->getDecodingRefreshType() == 1) |
---|
| 2640 | { |
---|
[56] | 2641 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
[2] | 2642 | } |
---|
| 2643 | else if (m_pcCfg->getDecodingRefreshType() == 2) |
---|
| 2644 | { |
---|
[608] | 2645 | return NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
---|
[56] | 2646 | } |
---|
| 2647 | } |
---|
[608] | 2648 | if(m_pocCRA>0) |
---|
[56] | 2649 | { |
---|
[608] | 2650 | if(pocCurr<m_pocCRA) |
---|
| 2651 | { |
---|
[1200] | 2652 | // All leading pictures are being marked as TFD pictures here since current encoder uses all |
---|
| 2653 | // reference pictures while encoding leading pictures. An encoder can ensure that a leading |
---|
| 2654 | // picture can be still decodable when random accessing to a CRA/CRANT/BLA/BLANT picture by |
---|
| 2655 | // controlling the reference pictures used for encoding that leading picture. Such a leading |
---|
[608] | 2656 | // picture need not be marked as a TFD picture. |
---|
| 2657 | return NAL_UNIT_CODED_SLICE_RASL_R; |
---|
| 2658 | } |
---|
[56] | 2659 | } |
---|
[608] | 2660 | if (lastIDR>0) |
---|
[56] | 2661 | { |
---|
[608] | 2662 | if (pocCurr < lastIDR) |
---|
[56] | 2663 | { |
---|
[608] | 2664 | return NAL_UNIT_CODED_SLICE_RADL_R; |
---|
[56] | 2665 | } |
---|
[2] | 2666 | } |
---|
[608] | 2667 | return NAL_UNIT_CODED_SLICE_TRAIL_R; |
---|
[2] | 2668 | } |
---|
| 2669 | |
---|
[1200] | 2670 | |
---|
[56] | 2671 | Double TEncGOP::xCalculateRVM() |
---|
[2] | 2672 | { |
---|
| 2673 | Double dRVM = 0; |
---|
[1200] | 2674 | |
---|
[608] | 2675 | if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFramesToBeEncoded() > RVM_VCEGAM10_M * 2 ) |
---|
[2] | 2676 | { |
---|
| 2677 | // calculate RVM only for lowdelay configurations |
---|
| 2678 | std::vector<Double> vRL , vB; |
---|
| 2679 | size_t N = m_vRVM_RP.size(); |
---|
| 2680 | vRL.resize( N ); |
---|
| 2681 | vB.resize( N ); |
---|
[1200] | 2682 | |
---|
[2] | 2683 | Int i; |
---|
| 2684 | Double dRavg = 0 , dBavg = 0; |
---|
| 2685 | vB[RVM_VCEGAM10_M] = 0; |
---|
| 2686 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
| 2687 | { |
---|
| 2688 | vRL[i] = 0; |
---|
| 2689 | for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ ) |
---|
[1200] | 2690 | { |
---|
[2] | 2691 | vRL[i] += m_vRVM_RP[j]; |
---|
[1200] | 2692 | } |
---|
[2] | 2693 | vRL[i] /= ( 2 * RVM_VCEGAM10_M ); |
---|
| 2694 | vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i]; |
---|
| 2695 | dRavg += m_vRVM_RP[i]; |
---|
| 2696 | dBavg += vB[i]; |
---|
| 2697 | } |
---|
[1200] | 2698 | |
---|
[2] | 2699 | dRavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
| 2700 | dBavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
[1200] | 2701 | |
---|
[608] | 2702 | Double dSigamB = 0; |
---|
[2] | 2703 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
| 2704 | { |
---|
| 2705 | Double tmp = vB[i] - dBavg; |
---|
| 2706 | dSigamB += tmp * tmp; |
---|
| 2707 | } |
---|
| 2708 | dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) ); |
---|
[1200] | 2709 | |
---|
[608] | 2710 | Double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) ); |
---|
[1200] | 2711 | |
---|
[2] | 2712 | dRVM = dSigamB / dRavg * f; |
---|
| 2713 | } |
---|
[1200] | 2714 | |
---|
[2] | 2715 | return( dRVM ); |
---|
| 2716 | } |
---|
[608] | 2717 | /** Attaches the input bitstream to the stream in the output NAL unit |
---|
| 2718 | Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. |
---|
| 2719 | * \param codedSliceData contains the coded slice data (bitstream) to be concatenated to rNalu |
---|
| 2720 | * \param rNalu target NAL unit |
---|
[56] | 2721 | */ |
---|
[1200] | 2722 | Void TEncGOP::xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* codedSliceData) |
---|
[56] | 2723 | { |
---|
[608] | 2724 | // Byte-align |
---|
| 2725 | rNalu.m_Bitstream.writeByteAlignment(); // Slice header byte-alignment |
---|
| 2726 | |
---|
| 2727 | // Perform bitstream concatenation |
---|
| 2728 | if (codedSliceData->getNumberOfWrittenBits() > 0) |
---|
[1200] | 2729 | { |
---|
[608] | 2730 | rNalu.m_Bitstream.addSubstream(codedSliceData); |
---|
| 2731 | } |
---|
| 2732 | |
---|
| 2733 | m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream); |
---|
| 2734 | |
---|
| 2735 | codedSliceData->clear(); |
---|
| 2736 | } |
---|
| 2737 | |
---|
[1200] | 2738 | // Function will arrange the long-term pictures in the decreasing order of poc_lsb_lt, |
---|
[608] | 2739 | // and among the pictures with the same lsb, it arranges them in increasing delta_poc_msb_cycle_lt value |
---|
| 2740 | Void TEncGOP::arrangeLongtermPicturesInRPS(TComSlice *pcSlice, TComList<TComPic*>& rcListPic) |
---|
| 2741 | { |
---|
[1287] | 2742 | if(pcSlice->getRPS()->getNumberOfLongtermPictures() == 0) |
---|
[56] | 2743 | { |
---|
[608] | 2744 | return; |
---|
[56] | 2745 | } |
---|
[1287] | 2746 | // we can only modify the local RPS! |
---|
| 2747 | assert (pcSlice->getRPSidx()==-1); |
---|
| 2748 | TComReferencePictureSet *rps = pcSlice->getLocalRPS(); |
---|
[2] | 2749 | |
---|
[608] | 2750 | // Arrange long-term reference pictures in the correct order of LSB and MSB, |
---|
| 2751 | // and assign values for pocLSBLT and MSB present flag |
---|
| 2752 | Int longtermPicsPoc[MAX_NUM_REF_PICS], longtermPicsLSB[MAX_NUM_REF_PICS], indices[MAX_NUM_REF_PICS]; |
---|
| 2753 | Int longtermPicsMSB[MAX_NUM_REF_PICS]; |
---|
| 2754 | Bool mSBPresentFlag[MAX_NUM_REF_PICS]; |
---|
| 2755 | ::memset(longtermPicsPoc, 0, sizeof(longtermPicsPoc)); // Store POC values of LTRP |
---|
| 2756 | ::memset(longtermPicsLSB, 0, sizeof(longtermPicsLSB)); // Store POC LSB values of LTRP |
---|
| 2757 | ::memset(longtermPicsMSB, 0, sizeof(longtermPicsMSB)); // Store POC LSB values of LTRP |
---|
| 2758 | ::memset(indices , 0, sizeof(indices)); // Indices to aid in tracking sorted LTRPs |
---|
| 2759 | ::memset(mSBPresentFlag , 0, sizeof(mSBPresentFlag)); // Indicate if MSB needs to be present |
---|
[56] | 2760 | |
---|
[1200] | 2761 | // Get the long-term reference pictures |
---|
[608] | 2762 | Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures(); |
---|
| 2763 | Int i, ctr = 0; |
---|
| 2764 | Int maxPicOrderCntLSB = 1 << pcSlice->getSPS()->getBitsForPOC(); |
---|
| 2765 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
[56] | 2766 | { |
---|
[608] | 2767 | longtermPicsPoc[ctr] = rps->getPOC(i); // LTRP POC |
---|
| 2768 | longtermPicsLSB[ctr] = getLSB(longtermPicsPoc[ctr], maxPicOrderCntLSB); // LTRP POC LSB |
---|
[1200] | 2769 | indices[ctr] = i; |
---|
[608] | 2770 | longtermPicsMSB[ctr] = longtermPicsPoc[ctr] - longtermPicsLSB[ctr]; |
---|
[56] | 2771 | } |
---|
[608] | 2772 | Int numLongPics = rps->getNumberOfLongtermPictures(); |
---|
| 2773 | assert(ctr == numLongPics); |
---|
[56] | 2774 | |
---|
[1200] | 2775 | // Arrange pictures in decreasing order of MSB; |
---|
[608] | 2776 | for(i = 0; i < numLongPics; i++) |
---|
[56] | 2777 | { |
---|
[608] | 2778 | for(Int j = 0; j < numLongPics - 1; j++) |
---|
[56] | 2779 | { |
---|
[608] | 2780 | if(longtermPicsMSB[j] < longtermPicsMSB[j+1]) |
---|
[56] | 2781 | { |
---|
[608] | 2782 | std::swap(longtermPicsPoc[j], longtermPicsPoc[j+1]); |
---|
| 2783 | std::swap(longtermPicsLSB[j], longtermPicsLSB[j+1]); |
---|
| 2784 | std::swap(longtermPicsMSB[j], longtermPicsMSB[j+1]); |
---|
| 2785 | std::swap(indices[j] , indices[j+1] ); |
---|
[56] | 2786 | } |
---|
| 2787 | } |
---|
[608] | 2788 | } |
---|
| 2789 | |
---|
| 2790 | for(i = 0; i < numLongPics; i++) |
---|
| 2791 | { |
---|
| 2792 | // Check if MSB present flag should be enabled. |
---|
| 2793 | // Check if the buffer contains any pictures that have the same LSB. |
---|
[1200] | 2794 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
[608] | 2795 | TComPic* pcPic; |
---|
| 2796 | while ( iterPic != rcListPic.end() ) |
---|
[56] | 2797 | { |
---|
[608] | 2798 | pcPic = *iterPic; |
---|
| 2799 | if( (getLSB(pcPic->getPOC(), maxPicOrderCntLSB) == longtermPicsLSB[i]) && // Same LSB |
---|
| 2800 | (pcPic->getSlice(0)->isReferenced()) && // Reference picture |
---|
| 2801 | (pcPic->getPOC() != longtermPicsPoc[i]) ) // Not the LTRP itself |
---|
| 2802 | { |
---|
| 2803 | mSBPresentFlag[i] = true; |
---|
| 2804 | break; |
---|
| 2805 | } |
---|
[1200] | 2806 | iterPic++; |
---|
[608] | 2807 | } |
---|
[56] | 2808 | } |
---|
| 2809 | |
---|
[608] | 2810 | // tempArray for usedByCurr flag |
---|
| 2811 | Bool tempArray[MAX_NUM_REF_PICS]; ::memset(tempArray, 0, sizeof(tempArray)); |
---|
| 2812 | for(i = 0; i < numLongPics; i++) |
---|
| 2813 | { |
---|
| 2814 | tempArray[i] = rps->getUsed(indices[i]); |
---|
| 2815 | } |
---|
| 2816 | // Now write the final values; |
---|
| 2817 | ctr = 0; |
---|
| 2818 | Int currMSB = 0, currLSB = 0; |
---|
| 2819 | // currPicPoc = currMSB + currLSB |
---|
[1200] | 2820 | currLSB = getLSB(pcSlice->getPOC(), maxPicOrderCntLSB); |
---|
[608] | 2821 | currMSB = pcSlice->getPOC() - currLSB; |
---|
[56] | 2822 | |
---|
[608] | 2823 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
| 2824 | { |
---|
| 2825 | rps->setPOC (i, longtermPicsPoc[ctr]); |
---|
| 2826 | rps->setDeltaPOC (i, - pcSlice->getPOC() + longtermPicsPoc[ctr]); |
---|
| 2827 | rps->setUsed (i, tempArray[ctr]); |
---|
| 2828 | rps->setPocLSBLT (i, longtermPicsLSB[ctr]); |
---|
| 2829 | rps->setDeltaPocMSBCycleLT (i, (currMSB - (longtermPicsPoc[ctr] - longtermPicsLSB[ctr])) / maxPicOrderCntLSB); |
---|
[1200] | 2830 | rps->setDeltaPocMSBPresentFlag(i, mSBPresentFlag[ctr]); |
---|
[56] | 2831 | |
---|
[608] | 2832 | assert(rps->getDeltaPocMSBCycleLT(i) >= 0); // Non-negative value |
---|
| 2833 | } |
---|
| 2834 | for(i = rps->getNumberOfPictures() - 1, ctr = 1; i >= offset; i--, ctr++) |
---|
[56] | 2835 | { |
---|
[608] | 2836 | for(Int j = rps->getNumberOfPictures() - 1 - ctr; j >= offset; j--) |
---|
| 2837 | { |
---|
[1200] | 2838 | // Here at the encoder we know that we have set the full POC value for the LTRPs, hence we |
---|
[608] | 2839 | // don't have to check the MSB present flag values for this constraint. |
---|
| 2840 | assert( rps->getPOC(i) != rps->getPOC(j) ); // If assert fails, LTRP entry repeated in RPS!!! |
---|
| 2841 | } |
---|
[56] | 2842 | } |
---|
[608] | 2843 | } |
---|
[56] | 2844 | |
---|
[1200] | 2845 | Void TEncGOP::applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices ) |
---|
[608] | 2846 | { |
---|
| 2847 | TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec(); |
---|
[1200] | 2848 | Pel* Rec = pcPicYuvRec->getAddr(COMPONENT_Y); |
---|
[608] | 2849 | Pel* tempRec = Rec; |
---|
[1200] | 2850 | Int stride = pcPicYuvRec->getStride(COMPONENT_Y); |
---|
[608] | 2851 | UInt log2maxTB = pcPic->getSlice(0)->getSPS()->getQuadtreeTULog2MaxSize(); |
---|
| 2852 | UInt maxTBsize = (1<<log2maxTB); |
---|
| 2853 | const UInt minBlockArtSize = 8; |
---|
[1200] | 2854 | const UInt picWidth = pcPicYuvRec->getWidth(COMPONENT_Y); |
---|
| 2855 | const UInt picHeight = pcPicYuvRec->getHeight(COMPONENT_Y); |
---|
[608] | 2856 | const UInt noCol = (picWidth>>log2maxTB); |
---|
| 2857 | const UInt noRows = (picHeight>>log2maxTB); |
---|
| 2858 | assert(noCol > 1); |
---|
| 2859 | assert(noRows > 1); |
---|
| 2860 | UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64)); |
---|
| 2861 | UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64)); |
---|
| 2862 | UInt colIdx = 0; |
---|
| 2863 | UInt rowIdx = 0; |
---|
| 2864 | Pel p0, p1, p2, q0, q1, q2; |
---|
[1200] | 2865 | |
---|
[608] | 2866 | Int qp = pcPic->getSlice(0)->getSliceQp(); |
---|
[1200] | 2867 | const Int bitDepthLuma=pcPic->getSlice(0)->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA); |
---|
| 2868 | Int bitdepthScale = 1 << (bitDepthLuma-8); |
---|
[608] | 2869 | Int beta = TComLoopFilter::getBeta( qp ) * bitdepthScale; |
---|
| 2870 | const Int thr2 = (beta>>2); |
---|
| 2871 | const Int thr1 = 2*bitdepthScale; |
---|
| 2872 | UInt a = 0; |
---|
[1200] | 2873 | |
---|
[608] | 2874 | memset(colSAD, 0, noCol*sizeof(UInt64)); |
---|
| 2875 | memset(rowSAD, 0, noRows*sizeof(UInt64)); |
---|
[1200] | 2876 | |
---|
[608] | 2877 | if (maxTBsize > minBlockArtSize) |
---|
[56] | 2878 | { |
---|
[608] | 2879 | // Analyze vertical artifact edges |
---|
| 2880 | for(Int c = maxTBsize; c < picWidth; c += maxTBsize) |
---|
[56] | 2881 | { |
---|
[608] | 2882 | for(Int r = 0; r < picHeight; r++) |
---|
[56] | 2883 | { |
---|
[608] | 2884 | p2 = Rec[c-3]; |
---|
| 2885 | p1 = Rec[c-2]; |
---|
| 2886 | p0 = Rec[c-1]; |
---|
| 2887 | q0 = Rec[c]; |
---|
| 2888 | q1 = Rec[c+1]; |
---|
| 2889 | q2 = Rec[c+2]; |
---|
| 2890 | a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); |
---|
| 2891 | if ( thr1 < a && a < thr2) |
---|
[56] | 2892 | { |
---|
[608] | 2893 | colSAD[colIdx] += abs(p0 - q0); |
---|
[56] | 2894 | } |
---|
[608] | 2895 | Rec += stride; |
---|
[56] | 2896 | } |
---|
[608] | 2897 | colIdx++; |
---|
| 2898 | Rec = tempRec; |
---|
[56] | 2899 | } |
---|
[1200] | 2900 | |
---|
[608] | 2901 | // Analyze horizontal artifact edges |
---|
| 2902 | for(Int r = maxTBsize; r < picHeight; r += maxTBsize) |
---|
[56] | 2903 | { |
---|
[608] | 2904 | for(Int c = 0; c < picWidth; c++) |
---|
[100] | 2905 | { |
---|
[608] | 2906 | p2 = Rec[c + (r-3)*stride]; |
---|
| 2907 | p1 = Rec[c + (r-2)*stride]; |
---|
| 2908 | p0 = Rec[c + (r-1)*stride]; |
---|
| 2909 | q0 = Rec[c + r*stride]; |
---|
| 2910 | q1 = Rec[c + (r+1)*stride]; |
---|
| 2911 | q2 = Rec[c + (r+2)*stride]; |
---|
| 2912 | a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); |
---|
| 2913 | if (thr1 < a && a < thr2) |
---|
[100] | 2914 | { |
---|
[608] | 2915 | rowSAD[rowIdx] += abs(p0 - q0); |
---|
[100] | 2916 | } |
---|
| 2917 | } |
---|
[608] | 2918 | rowIdx++; |
---|
[100] | 2919 | } |
---|
[608] | 2920 | } |
---|
[1200] | 2921 | |
---|
[608] | 2922 | UInt64 colSADsum = 0; |
---|
| 2923 | UInt64 rowSADsum = 0; |
---|
| 2924 | for(Int c = 0; c < noCol-1; c++) |
---|
| 2925 | { |
---|
| 2926 | colSADsum += colSAD[c]; |
---|
| 2927 | } |
---|
| 2928 | for(Int r = 0; r < noRows-1; r++) |
---|
| 2929 | { |
---|
| 2930 | rowSADsum += rowSAD[r]; |
---|
| 2931 | } |
---|
[1200] | 2932 | |
---|
[608] | 2933 | colSADsum <<= 10; |
---|
| 2934 | rowSADsum <<= 10; |
---|
| 2935 | colSADsum /= (noCol-1); |
---|
| 2936 | colSADsum /= picHeight; |
---|
| 2937 | rowSADsum /= (noRows-1); |
---|
| 2938 | rowSADsum /= picWidth; |
---|
[1200] | 2939 | |
---|
[608] | 2940 | UInt64 avgSAD = ((colSADsum + rowSADsum)>>1); |
---|
[1200] | 2941 | avgSAD >>= (bitDepthLuma-8); |
---|
| 2942 | |
---|
[608] | 2943 | if ( avgSAD > 2048 ) |
---|
| 2944 | { |
---|
| 2945 | avgSAD >>= 9; |
---|
| 2946 | Int offset = Clip3(2,6,(Int)avgSAD); |
---|
| 2947 | for (Int i=0; i<uiNumSlices; i++) |
---|
[56] | 2948 | { |
---|
[608] | 2949 | pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true); |
---|
| 2950 | pcPic->getSlice(i)->setDeblockingFilterDisable(false); |
---|
| 2951 | pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( offset ); |
---|
| 2952 | pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( offset ); |
---|
[56] | 2953 | } |
---|
| 2954 | } |
---|
[608] | 2955 | else |
---|
| 2956 | { |
---|
| 2957 | for (Int i=0; i<uiNumSlices; i++) |
---|
| 2958 | { |
---|
| 2959 | pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false); |
---|
| 2960 | pcPic->getSlice(i)->setDeblockingFilterDisable( pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() ); |
---|
| 2961 | pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); |
---|
| 2962 | pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2() ); |
---|
| 2963 | } |
---|
| 2964 | } |
---|
[1200] | 2965 | |
---|
[608] | 2966 | free(colSAD); |
---|
| 2967 | free(rowSAD); |
---|
| 2968 | } |
---|
[56] | 2969 | |
---|
[1200] | 2970 | #if NH_MV |
---|
[622] | 2971 | Void TEncGOP::xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid ) |
---|
| 2972 | { |
---|
| 2973 | |
---|
| 2974 | if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || pcSlice->getNumActiveRefLayerPics() == 0 ) |
---|
| 2975 | { |
---|
| 2976 | return; |
---|
| 2977 | } |
---|
| 2978 | |
---|
| 2979 | GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( pcSlice->getLayerId( ) > 0) ) ? MAX_GOP : iGOPid ); |
---|
| 2980 | assert( ge.m_numActiveRefLayerPics == pcSlice->getNumActiveRefLayerPics() ); |
---|
| 2981 | |
---|
| 2982 | Int numPicsInTempList = pcSlice->getNumRpsCurrTempList(); |
---|
| 2983 | |
---|
| 2984 | // GT: check if SliceType should be checked here. |
---|
| 2985 | for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1 |
---|
| 2986 | { |
---|
| 2987 | Int numPicsInFinalRefList = pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); |
---|
| 2988 | |
---|
| 2989 | Int finalIdxToTempIdxMap[16]; |
---|
| 2990 | for( Int k = 0; k < 16; k++ ) |
---|
| 2991 | { |
---|
| 2992 | finalIdxToTempIdxMap[ k ] = -1; |
---|
| 2993 | } |
---|
| 2994 | |
---|
| 2995 | Bool isModified = false; |
---|
| 2996 | if ( numPicsInTempList > 1 ) |
---|
| 2997 | { |
---|
| 2998 | for( Int k = 0; k < pcSlice->getNumActiveRefLayerPics(); k++ ) |
---|
| 2999 | { |
---|
| 3000 | // get position in temp. list |
---|
| 3001 | Int refPicLayerId = pcSlice->getRefPicLayerId(k); |
---|
| 3002 | Int idxInTempList = 0; |
---|
| 3003 | for (; idxInTempList < numPicsInTempList; idxInTempList++) |
---|
| 3004 | { |
---|
| 3005 | if ( (tempPicLists[li][idxInTempList])->getLayerId() == refPicLayerId ) |
---|
| 3006 | { |
---|
| 3007 | break; |
---|
| 3008 | } |
---|
| 3009 | } |
---|
| 3010 | |
---|
| 3011 | Int idxInFinalList = ge.m_interViewRefPosL[ li ][ k ]; |
---|
| 3012 | |
---|
| 3013 | // Add negative from behind |
---|
| 3014 | idxInFinalList = ( idxInFinalList < 0 )? ( numPicsInTempList + idxInFinalList ) : idxInFinalList; |
---|
| 3015 | |
---|
| 3016 | Bool curIsModified = ( idxInFinalList != idxInTempList ) && ( ( idxInTempList < numPicsInFinalRefList ) || ( idxInFinalList < numPicsInFinalRefList ) ) ; |
---|
| 3017 | if ( curIsModified ) |
---|
| 3018 | { |
---|
| 3019 | isModified = true; |
---|
| 3020 | assert( finalIdxToTempIdxMap[ idxInFinalList ] == -1 ); // Assert when two inter layer reference pictures are sorted to the same position |
---|
| 3021 | } |
---|
| 3022 | finalIdxToTempIdxMap[ idxInFinalList ] = idxInTempList; |
---|
| 3023 | } |
---|
| 3024 | } |
---|
| 3025 | |
---|
| 3026 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
| 3027 | refPicListModification->setRefPicListModificationFlagL( li, isModified ); |
---|
| 3028 | |
---|
| 3029 | if( isModified ) |
---|
| 3030 | { |
---|
| 3031 | Int refIdx = 0; |
---|
| 3032 | |
---|
| 3033 | for( Int i = 0; i < numPicsInFinalRefList; i++ ) |
---|
| 3034 | { |
---|
| 3035 | if( finalIdxToTempIdxMap[i] >= 0 ) |
---|
| 3036 | { |
---|
| 3037 | refPicListModification->setRefPicSetIdxL( li, i, finalIdxToTempIdxMap[i] ); |
---|
| 3038 | } |
---|
| 3039 | else |
---|
| 3040 | { |
---|
| 3041 | ///* Fill gaps with temporal references */// |
---|
| 3042 | // Forward inter layer reference pictures |
---|
| 3043 | while( ( refIdx < numPicsInTempList ) && ( tempPicLists[li][refIdx]->getLayerId() != getLayerId()) ) |
---|
| 3044 | { |
---|
| 3045 | refIdx++; |
---|
| 3046 | } |
---|
| 3047 | refPicListModification->setRefPicSetIdxL( li, i, refIdx ); |
---|
| 3048 | refIdx++; |
---|
| 3049 | } |
---|
| 3050 | } |
---|
| 3051 | } |
---|
| 3052 | } |
---|
| 3053 | } |
---|
[608] | 3054 | #endif |
---|
[56] | 3055 | //! \} |
---|