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 |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2016, ITU/ISO/IEC |
---|
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. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
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 | */ |
---|
33 | |
---|
34 | /** \file TEncCu.cpp |
---|
35 | \brief Coding Unit (CU) encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <stdio.h> |
---|
39 | #include "TEncTop.h" |
---|
40 | #include "TEncCu.h" |
---|
41 | #include "TEncAnalyze.h" |
---|
42 | #include "TLibCommon/Debug.h" |
---|
43 | |
---|
44 | #include <cmath> |
---|
45 | #include <algorithm> |
---|
46 | using namespace std; |
---|
47 | |
---|
48 | |
---|
49 | //! \ingroup TLibEncoder |
---|
50 | //! \{ |
---|
51 | |
---|
52 | // ==================================================================================================================== |
---|
53 | // Constructor / destructor / create / destroy |
---|
54 | // ==================================================================================================================== |
---|
55 | |
---|
56 | /** |
---|
57 | \param uhTotalDepth total number of allowable depth |
---|
58 | \param uiMaxWidth largest CU width |
---|
59 | \param uiMaxHeight largest CU height |
---|
60 | \param chromaFormat chroma format |
---|
61 | */ |
---|
62 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormat) |
---|
63 | { |
---|
64 | Int i; |
---|
65 | |
---|
66 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
67 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
68 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
69 | |
---|
70 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
71 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
72 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
73 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
74 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
75 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
76 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
77 | |
---|
78 | UInt uiNumPartitions; |
---|
79 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
80 | { |
---|
81 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
82 | UInt uiWidth = uiMaxWidth >> i; |
---|
83 | UInt uiHeight = uiMaxHeight >> i; |
---|
84 | |
---|
85 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
86 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
87 | |
---|
88 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
89 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
90 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
91 | |
---|
92 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
93 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
94 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
95 | |
---|
96 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight, chromaFormat); |
---|
97 | } |
---|
98 | |
---|
99 | m_bEncodeDQP = false; |
---|
100 | m_stillToCodeChromaQpOffsetFlag = false; |
---|
101 | m_cuChromaQpOffsetIdxPlus1 = 0; |
---|
102 | m_bFastDeltaQP = false; |
---|
103 | |
---|
104 | // initialize partition order. |
---|
105 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
106 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
107 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
108 | |
---|
109 | // initialize conversion matrix from partition index to pel |
---|
110 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
111 | } |
---|
112 | |
---|
113 | Void TEncCu::destroy() |
---|
114 | { |
---|
115 | Int i; |
---|
116 | |
---|
117 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
118 | { |
---|
119 | if(m_ppcBestCU[i]) |
---|
120 | { |
---|
121 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
122 | } |
---|
123 | if(m_ppcTempCU[i]) |
---|
124 | { |
---|
125 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
126 | } |
---|
127 | if(m_ppcPredYuvBest[i]) |
---|
128 | { |
---|
129 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
130 | } |
---|
131 | if(m_ppcResiYuvBest[i]) |
---|
132 | { |
---|
133 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
134 | } |
---|
135 | if(m_ppcRecoYuvBest[i]) |
---|
136 | { |
---|
137 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
138 | } |
---|
139 | if(m_ppcPredYuvTemp[i]) |
---|
140 | { |
---|
141 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
142 | } |
---|
143 | if(m_ppcResiYuvTemp[i]) |
---|
144 | { |
---|
145 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
146 | } |
---|
147 | if(m_ppcRecoYuvTemp[i]) |
---|
148 | { |
---|
149 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
150 | } |
---|
151 | if(m_ppcOrigYuv[i]) |
---|
152 | { |
---|
153 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
154 | } |
---|
155 | } |
---|
156 | if(m_ppcBestCU) |
---|
157 | { |
---|
158 | delete [] m_ppcBestCU; |
---|
159 | m_ppcBestCU = NULL; |
---|
160 | } |
---|
161 | if(m_ppcTempCU) |
---|
162 | { |
---|
163 | delete [] m_ppcTempCU; |
---|
164 | m_ppcTempCU = NULL; |
---|
165 | } |
---|
166 | |
---|
167 | if(m_ppcPredYuvBest) |
---|
168 | { |
---|
169 | delete [] m_ppcPredYuvBest; |
---|
170 | m_ppcPredYuvBest = NULL; |
---|
171 | } |
---|
172 | if(m_ppcResiYuvBest) |
---|
173 | { |
---|
174 | delete [] m_ppcResiYuvBest; |
---|
175 | m_ppcResiYuvBest = NULL; |
---|
176 | } |
---|
177 | if(m_ppcRecoYuvBest) |
---|
178 | { |
---|
179 | delete [] m_ppcRecoYuvBest; |
---|
180 | m_ppcRecoYuvBest = NULL; |
---|
181 | } |
---|
182 | if(m_ppcPredYuvTemp) |
---|
183 | { |
---|
184 | delete [] m_ppcPredYuvTemp; |
---|
185 | m_ppcPredYuvTemp = NULL; |
---|
186 | } |
---|
187 | if(m_ppcResiYuvTemp) |
---|
188 | { |
---|
189 | delete [] m_ppcResiYuvTemp; |
---|
190 | m_ppcResiYuvTemp = NULL; |
---|
191 | } |
---|
192 | if(m_ppcRecoYuvTemp) |
---|
193 | { |
---|
194 | delete [] m_ppcRecoYuvTemp; |
---|
195 | m_ppcRecoYuvTemp = NULL; |
---|
196 | } |
---|
197 | if(m_ppcOrigYuv) |
---|
198 | { |
---|
199 | delete [] m_ppcOrigYuv; |
---|
200 | m_ppcOrigYuv = NULL; |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | /** \param pcEncTop pointer of encoder class |
---|
205 | */ |
---|
206 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
207 | { |
---|
208 | m_pcEncCfg = pcEncTop; |
---|
209 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
210 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
211 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
212 | |
---|
213 | #if SVC_EXTENSION |
---|
214 | m_ppcTEncTop = pcEncTop->getLayerEnc(); |
---|
215 | #endif |
---|
216 | |
---|
217 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
218 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
219 | |
---|
220 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
221 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
222 | |
---|
223 | m_pcRateCtrl = pcEncTop->getRateCtrl(); |
---|
224 | } |
---|
225 | |
---|
226 | // ==================================================================================================================== |
---|
227 | // Public member functions |
---|
228 | // ==================================================================================================================== |
---|
229 | |
---|
230 | /** |
---|
231 | \param pCtu pointer of CU data class |
---|
232 | */ |
---|
233 | Void TEncCu::compressCtu( TComDataCU* pCtu ) |
---|
234 | { |
---|
235 | // initialize CU data |
---|
236 | m_ppcBestCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() ); |
---|
237 | m_ppcTempCU[0]->initCtu( pCtu->getPic(), pCtu->getCtuRsAddr() ); |
---|
238 | |
---|
239 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
240 | m_disableILP = xCheckTileSetConstraint(pCtu); |
---|
241 | m_pcPredSearch->setDisableILP(m_disableILP); |
---|
242 | #endif |
---|
243 | |
---|
244 | // analysis of CU |
---|
245 | DEBUG_STRING_NEW(sDebug) |
---|
246 | |
---|
247 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
248 | DEBUG_STRING_OUTPUT(std::cout, sDebug) |
---|
249 | |
---|
250 | #if ADAPTIVE_QP_SELECTION |
---|
251 | if( m_pcEncCfg->getUseAdaptQpSelect() ) |
---|
252 | { |
---|
253 | if(pCtu->getSlice()->getSliceType()!=I_SLICE) //IIII |
---|
254 | { |
---|
255 | xCtuCollectARLStats( pCtu ); |
---|
256 | } |
---|
257 | } |
---|
258 | #endif |
---|
259 | |
---|
260 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
261 | xVerifyTileSetConstraint(pCtu); |
---|
262 | #endif |
---|
263 | } |
---|
264 | /** \param pCtu pointer of CU data class |
---|
265 | */ |
---|
266 | Void TEncCu::encodeCtu ( TComDataCU* pCtu ) |
---|
267 | { |
---|
268 | if ( pCtu->getSlice()->getPPS()->getUseDQP() ) |
---|
269 | { |
---|
270 | setdQPFlag(true); |
---|
271 | } |
---|
272 | |
---|
273 | if ( pCtu->getSlice()->getUseChromaQpAdj() ) |
---|
274 | { |
---|
275 | setCodeChromaQpAdjFlag(true); |
---|
276 | } |
---|
277 | |
---|
278 | // Encode CU data |
---|
279 | xEncodeCU( pCtu, 0, 0 ); |
---|
280 | } |
---|
281 | |
---|
282 | // ==================================================================================================================== |
---|
283 | // Protected member functions |
---|
284 | // ==================================================================================================================== |
---|
285 | //! Derive small set of test modes for AMP encoder speed-up |
---|
286 | #if AMP_ENC_SPEEDUP |
---|
287 | #if AMP_MRG |
---|
288 | Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver) |
---|
289 | #else |
---|
290 | Void TEncCu::deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver) |
---|
291 | #endif |
---|
292 | { |
---|
293 | if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
294 | { |
---|
295 | bTestAMP_Hor = true; |
---|
296 | } |
---|
297 | else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
298 | { |
---|
299 | bTestAMP_Ver = true; |
---|
300 | } |
---|
301 | else if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->getMergeFlag(0) == false && pcBestCU->isSkipped(0) == false ) |
---|
302 | { |
---|
303 | bTestAMP_Hor = true; |
---|
304 | bTestAMP_Ver = true; |
---|
305 | } |
---|
306 | |
---|
307 | #if AMP_MRG |
---|
308 | //! Utilizing the partition size of parent PU |
---|
309 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
310 | { |
---|
311 | bTestMergeAMP_Hor = true; |
---|
312 | bTestMergeAMP_Ver = true; |
---|
313 | } |
---|
314 | |
---|
315 | if ( eParentPartSize == NUMBER_OF_PART_SIZES ) //! if parent is intra |
---|
316 | { |
---|
317 | if ( pcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
318 | { |
---|
319 | bTestMergeAMP_Hor = true; |
---|
320 | } |
---|
321 | else if ( pcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
322 | { |
---|
323 | bTestMergeAMP_Ver = true; |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | if ( pcBestCU->getPartitionSize(0) == SIZE_2Nx2N && pcBestCU->isSkipped(0) == false ) |
---|
328 | { |
---|
329 | bTestMergeAMP_Hor = true; |
---|
330 | bTestMergeAMP_Ver = true; |
---|
331 | } |
---|
332 | |
---|
333 | if ( pcBestCU->getWidth(0) == 64 ) |
---|
334 | { |
---|
335 | bTestAMP_Hor = false; |
---|
336 | bTestAMP_Ver = false; |
---|
337 | } |
---|
338 | #else |
---|
339 | //! Utilizing the partition size of parent PU |
---|
340 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
341 | { |
---|
342 | bTestAMP_Hor = true; |
---|
343 | bTestAMP_Ver = true; |
---|
344 | } |
---|
345 | |
---|
346 | if ( eParentPartSize == SIZE_2Nx2N ) |
---|
347 | { |
---|
348 | bTestAMP_Hor = false; |
---|
349 | bTestAMP_Ver = false; |
---|
350 | } |
---|
351 | #endif |
---|
352 | } |
---|
353 | #endif |
---|
354 | |
---|
355 | |
---|
356 | // ==================================================================================================================== |
---|
357 | // Protected member functions |
---|
358 | // ==================================================================================================================== |
---|
359 | /** Compress a CU block recursively with enabling sub-CTU-level delta QP |
---|
360 | * - for loop of QP value to compress the current CU with all possible QP |
---|
361 | */ |
---|
362 | #if AMP_ENC_SPEEDUP |
---|
363 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug_), PartSize eParentPartSize ) |
---|
364 | #else |
---|
365 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth ) |
---|
366 | #endif |
---|
367 | { |
---|
368 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
369 | DEBUG_STRING_NEW(sDebug) |
---|
370 | const TComPPS &pps=*(rpcTempCU->getSlice()->getPPS()); |
---|
371 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
372 | |
---|
373 | // These are only used if getFastDeltaQp() is true |
---|
374 | const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>sps.getLog2DiffMaxMinCodingBlockSize(), sps.getMaxCUHeight(), 32u); |
---|
375 | |
---|
376 | // get Original YUV data from picture |
---|
377 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu() ); |
---|
378 | |
---|
379 | // variable for Cbf fast mode PU decision |
---|
380 | Bool doNotBlockPu = true; |
---|
381 | Bool earlyDetectionSkipMode = false; |
---|
382 | |
---|
383 | const UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
384 | const UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
385 | const UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
386 | const UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
387 | const UInt uiWidth = rpcBestCU->getWidth(0); |
---|
388 | |
---|
389 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
---|
390 | Int iMinQP; |
---|
391 | Int iMaxQP; |
---|
392 | Bool isAddLowestQP = false; |
---|
393 | |
---|
394 | const UInt numberValidComponents = rpcBestCU->getPic()->getNumberValidComponents(); |
---|
395 | |
---|
396 | if( uiDepth <= pps.getMaxCuDQPDepth() ) |
---|
397 | { |
---|
398 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
399 | iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP ); |
---|
400 | iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP ); |
---|
401 | } |
---|
402 | else |
---|
403 | { |
---|
404 | iMinQP = rpcTempCU->getQP(0); |
---|
405 | iMaxQP = rpcTempCU->getQP(0); |
---|
406 | } |
---|
407 | |
---|
408 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
409 | { |
---|
410 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
411 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
412 | } |
---|
413 | |
---|
414 | // transquant-bypass (TQB) processing loop variable initialisation --- |
---|
415 | |
---|
416 | const Int lowestQP = iMinQP; // For TQB, use this QP which is the lowest non TQB QP tested (rather than QP'=0) - that way delta QPs are smaller, and TQB can be tested at all CU levels. |
---|
417 | |
---|
418 | if ( (pps.getTransquantBypassEnableFlag()) ) |
---|
419 | { |
---|
420 | isAddLowestQP = true; // mark that the first iteration is to cost TQB mode. |
---|
421 | iMinQP = iMinQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs |
---|
422 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
423 | { |
---|
424 | iMaxQP = iMinQP; |
---|
425 | } |
---|
426 | } |
---|
427 | |
---|
428 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
429 | const Bool bBoundary = !( uiRPelX < sps.getPicWidthInLumaSamples() && uiBPelY < sps.getPicHeightInLumaSamples() ); |
---|
430 | |
---|
431 | if ( !bBoundary ) |
---|
432 | { |
---|
433 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
434 | if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange()) |
---|
435 | { |
---|
436 | Int iQP = iBaseQP; |
---|
437 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
438 | |
---|
439 | if( bIsLosslessMode ) |
---|
440 | { |
---|
441 | iQP = lowestQP; |
---|
442 | } |
---|
443 | |
---|
444 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
445 | |
---|
446 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode, true ); |
---|
447 | } |
---|
448 | else |
---|
449 | { |
---|
450 | #endif |
---|
451 | #if ENCODER_FAST_MODE |
---|
452 | Bool testInter = true; |
---|
453 | if( rpcBestCU->getPic()->getLayerId() > 0 ) |
---|
454 | { |
---|
455 | if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx()) |
---|
456 | { |
---|
457 | testInter = false; |
---|
458 | } |
---|
459 | if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx()) |
---|
460 | { |
---|
461 | testInter = false; |
---|
462 | } |
---|
463 | } |
---|
464 | #endif |
---|
465 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
466 | { |
---|
467 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
468 | |
---|
469 | if (bIsLosslessMode) |
---|
470 | { |
---|
471 | iQP = lowestQP; |
---|
472 | } |
---|
473 | |
---|
474 | m_cuChromaQpOffsetIdxPlus1 = 0; |
---|
475 | if (pcSlice->getUseChromaQpAdj()) |
---|
476 | { |
---|
477 | /* Pre-estimation of chroma QP based on input block activity may be performed |
---|
478 | * here, using for example m_ppcOrigYuv[uiDepth] */ |
---|
479 | /* To exercise the current code, the index used for adjustment is based on |
---|
480 | * block position |
---|
481 | */ |
---|
482 | Int lgMinCuSize = sps.getLog2MinCodingBlockSize() + |
---|
483 | std::max<Int>(0, sps.getLog2DiffMaxMinCodingBlockSize()-Int(pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth())); |
---|
484 | m_cuChromaQpOffsetIdxPlus1 = ((uiLPelX >> lgMinCuSize) + (uiTPelY >> lgMinCuSize)) % (pps.getPpsRangeExtension().getChromaQpOffsetListLen() + 1); |
---|
485 | } |
---|
486 | |
---|
487 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
488 | |
---|
489 | // do inter modes, SKIP and 2Nx2N |
---|
490 | #if ENCODER_FAST_MODE == 1 |
---|
491 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
492 | #else |
---|
493 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
494 | #endif |
---|
495 | { |
---|
496 | // 2Nx2N |
---|
497 | if(m_pcEncCfg->getUseEarlySkipDetection()) |
---|
498 | { |
---|
499 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
500 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N |
---|
501 | } |
---|
502 | // SKIP |
---|
503 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), &earlyDetectionSkipMode );//by Merge for inter_2Nx2N |
---|
504 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
505 | |
---|
506 | #if ENCODER_FAST_MODE == 2 |
---|
507 | if (testInter) |
---|
508 | { |
---|
509 | #endif |
---|
510 | if(!m_pcEncCfg->getUseEarlySkipDetection()) |
---|
511 | { |
---|
512 | // 2Nx2N, NxN |
---|
513 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
514 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
515 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
516 | { |
---|
517 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
518 | } |
---|
519 | } |
---|
520 | #if ENCODER_FAST_MODE == 2 |
---|
521 | } |
---|
522 | #endif |
---|
523 | } |
---|
524 | |
---|
525 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
526 | { |
---|
527 | iQP = iMinQP; |
---|
528 | } |
---|
529 | } |
---|
530 | |
---|
531 | if(!earlyDetectionSkipMode) |
---|
532 | { |
---|
533 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
534 | { |
---|
535 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); // If lossless, then iQP is irrelevant for subsequent modules. |
---|
536 | |
---|
537 | if (bIsLosslessMode) |
---|
538 | { |
---|
539 | iQP = lowestQP; |
---|
540 | } |
---|
541 | |
---|
542 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
543 | |
---|
544 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
545 | #if ENCODER_FAST_MODE |
---|
546 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
547 | #else |
---|
548 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
549 | #endif |
---|
550 | { |
---|
551 | // 2Nx2N, NxN |
---|
552 | |
---|
553 | if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
554 | { |
---|
555 | if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() && doNotBlockPu) |
---|
556 | { |
---|
557 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
558 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
559 | } |
---|
560 | } |
---|
561 | |
---|
562 | if(doNotBlockPu) |
---|
563 | { |
---|
564 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
565 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
566 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
567 | { |
---|
568 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
569 | } |
---|
570 | } |
---|
571 | if(doNotBlockPu) |
---|
572 | { |
---|
573 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
574 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
575 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
576 | { |
---|
577 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
582 | if(sps.getUseAMP() && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) |
---|
583 | { |
---|
584 | #if AMP_ENC_SPEEDUP |
---|
585 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
586 | |
---|
587 | #if AMP_MRG |
---|
588 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
589 | |
---|
590 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
591 | #else |
---|
592 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
593 | #endif |
---|
594 | |
---|
595 | //! Do horizontal AMP |
---|
596 | if ( bTestAMP_Hor ) |
---|
597 | { |
---|
598 | if(doNotBlockPu) |
---|
599 | { |
---|
600 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
601 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
602 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
603 | { |
---|
604 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
605 | } |
---|
606 | } |
---|
607 | if(doNotBlockPu) |
---|
608 | { |
---|
609 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
610 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
611 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
612 | { |
---|
613 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
614 | } |
---|
615 | } |
---|
616 | } |
---|
617 | #if AMP_MRG |
---|
618 | else if ( bTestMergeAMP_Hor ) |
---|
619 | { |
---|
620 | if(doNotBlockPu) |
---|
621 | { |
---|
622 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
623 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
624 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
625 | { |
---|
626 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
627 | } |
---|
628 | } |
---|
629 | if(doNotBlockPu) |
---|
630 | { |
---|
631 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
632 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
633 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
634 | { |
---|
635 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
636 | } |
---|
637 | } |
---|
638 | } |
---|
639 | #endif |
---|
640 | |
---|
641 | //! Do horizontal AMP |
---|
642 | if ( bTestAMP_Ver ) |
---|
643 | { |
---|
644 | if(doNotBlockPu) |
---|
645 | { |
---|
646 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
647 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
648 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
649 | { |
---|
650 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
651 | } |
---|
652 | } |
---|
653 | if(doNotBlockPu) |
---|
654 | { |
---|
655 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
656 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
657 | } |
---|
658 | } |
---|
659 | #if AMP_MRG |
---|
660 | else if ( bTestMergeAMP_Ver ) |
---|
661 | { |
---|
662 | if(doNotBlockPu) |
---|
663 | { |
---|
664 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
665 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
666 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
667 | { |
---|
668 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
669 | } |
---|
670 | } |
---|
671 | if(doNotBlockPu) |
---|
672 | { |
---|
673 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
674 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
675 | } |
---|
676 | } |
---|
677 | #endif |
---|
678 | |
---|
679 | #else |
---|
680 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
681 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
682 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
683 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
684 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
685 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
686 | |
---|
687 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
688 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
689 | |
---|
690 | #endif |
---|
691 | } |
---|
692 | } |
---|
693 | |
---|
694 | // do normal intra modes |
---|
695 | // speedup for inter frames |
---|
696 | if((rpcBestCU->getSlice()->getSliceType() == I_SLICE) || |
---|
697 | #if ENCODER_FAST_MODE |
---|
698 | rpcBestCU->getPredictionMode(0) == NUMBER_OF_PREDICTION_MODES || // if there is no valid inter prediction |
---|
699 | !testInter || |
---|
700 | #endif |
---|
701 | ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && ( |
---|
702 | (rpcBestCU->getCbf( 0, COMPONENT_Y ) != 0) || |
---|
703 | ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) || |
---|
704 | ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) // avoid very complex intra if it is unlikely |
---|
705 | ))) |
---|
706 | { |
---|
707 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
708 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
709 | if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() ) |
---|
710 | { |
---|
711 | if( rpcTempCU->getWidth(0) > ( 1 << sps.getQuadtreeTULog2MinSize() ) ) |
---|
712 | { |
---|
713 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
714 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
715 | } |
---|
716 | } |
---|
717 | } |
---|
718 | |
---|
719 | // test PCM |
---|
720 | if(sps.getUsePCM() |
---|
721 | && rpcTempCU->getWidth(0) <= (1<<sps.getPCMLog2MaxSize()) |
---|
722 | && rpcTempCU->getWidth(0) >= (1<<sps.getPCMLog2MinSize()) ) |
---|
723 | { |
---|
724 | UInt uiRawBits = getTotalBits(rpcBestCU->getWidth(0), rpcBestCU->getHeight(0), rpcBestCU->getPic()->getChromaFormat(), sps.getBitDepths().recon); |
---|
725 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
726 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
727 | { |
---|
728 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
729 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
730 | } |
---|
731 | } |
---|
732 | #if ENCODER_FAST_MODE |
---|
733 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
734 | if(pcPic->getLayerId() > 0 && !m_disableILP) |
---|
735 | #else |
---|
736 | if(pcPic->getLayerId() > 0) |
---|
737 | #endif |
---|
738 | { |
---|
739 | for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++) |
---|
740 | { |
---|
741 | xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getVPS()->getRefLayerId( pcSlice->getLayerId(), pcSlice->getInterLayerPredLayerIdc(refLayer) ) ); |
---|
742 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
743 | } |
---|
744 | } |
---|
745 | #endif |
---|
746 | |
---|
747 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
748 | { |
---|
749 | iQP = iMinQP; |
---|
750 | } |
---|
751 | } |
---|
752 | } |
---|
753 | |
---|
754 | if( rpcBestCU->getTotalCost()!=MAX_DOUBLE ) |
---|
755 | { |
---|
756 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
757 | m_pcEntropyCoder->resetBits(); |
---|
758 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
759 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
760 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
761 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
762 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
763 | } |
---|
764 | |
---|
765 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
766 | } |
---|
767 | #endif |
---|
768 | } |
---|
769 | |
---|
770 | // copy original YUV samples to PCM buffer |
---|
771 | if( rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
772 | { |
---|
773 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
774 | } |
---|
775 | |
---|
776 | if( uiDepth == pps.getMaxCuDQPDepth() ) |
---|
777 | { |
---|
778 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
779 | iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP ); |
---|
780 | iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP ); |
---|
781 | } |
---|
782 | else if( uiDepth < pps.getMaxCuDQPDepth() ) |
---|
783 | { |
---|
784 | iMinQP = iBaseQP; |
---|
785 | iMaxQP = iBaseQP; |
---|
786 | } |
---|
787 | else |
---|
788 | { |
---|
789 | const Int iStartQP = rpcTempCU->getQP(0); |
---|
790 | iMinQP = iStartQP; |
---|
791 | iMaxQP = iStartQP; |
---|
792 | } |
---|
793 | |
---|
794 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
795 | { |
---|
796 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
797 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
798 | } |
---|
799 | |
---|
800 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
801 | { |
---|
802 | iMaxQP = iMinQP; // If all TUs are forced into using transquant bypass, do not loop here. |
---|
803 | } |
---|
804 | |
---|
805 | const Bool bSubBranch = bBoundary || !( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isSkipped(0) ); |
---|
806 | |
---|
807 | if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary)) |
---|
808 | { |
---|
809 | // further split |
---|
810 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
811 | { |
---|
812 | const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true. |
---|
813 | |
---|
814 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
815 | |
---|
816 | UChar uhNextDepth = uiDepth+1; |
---|
817 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
818 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
819 | DEBUG_STRING_NEW(sTempDebug) |
---|
820 | |
---|
821 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
822 | { |
---|
823 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
824 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
825 | |
---|
826 | if( ( pcSubBestPartCU->getCUPelX() < sps.getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < sps.getPicHeightInLumaSamples() ) ) |
---|
827 | { |
---|
828 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
829 | { |
---|
830 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
831 | } |
---|
832 | else |
---|
833 | { |
---|
834 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
835 | } |
---|
836 | |
---|
837 | #if AMP_ENC_SPEEDUP |
---|
838 | DEBUG_STRING_NEW(sChild) |
---|
839 | if ( !(rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isInter(0)) ) |
---|
840 | { |
---|
841 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES ); |
---|
842 | } |
---|
843 | else |
---|
844 | { |
---|
845 | |
---|
846 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), rpcBestCU->getPartitionSize(0) ); |
---|
847 | } |
---|
848 | DEBUG_STRING_APPEND(sTempDebug, sChild) |
---|
849 | #else |
---|
850 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
851 | #endif |
---|
852 | |
---|
853 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
854 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
855 | } |
---|
856 | else |
---|
857 | { |
---|
858 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
859 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
860 | } |
---|
861 | } |
---|
862 | |
---|
863 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
864 | if( !bBoundary ) |
---|
865 | { |
---|
866 | m_pcEntropyCoder->resetBits(); |
---|
867 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
868 | |
---|
869 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
870 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
871 | } |
---|
872 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
873 | |
---|
874 | if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
875 | { |
---|
876 | Bool hasResidual = false; |
---|
877 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
878 | { |
---|
879 | if( ( rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Y) |
---|
880 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cb) && (numberValidComponents > COMPONENT_Cb)) |
---|
881 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cr) && (numberValidComponents > COMPONENT_Cr)) ) ) |
---|
882 | { |
---|
883 | hasResidual = true; |
---|
884 | break; |
---|
885 | } |
---|
886 | } |
---|
887 | |
---|
888 | if ( hasResidual ) |
---|
889 | { |
---|
890 | m_pcEntropyCoder->resetBits(); |
---|
891 | m_pcEntropyCoder->encodeQP( rpcTempCU, 0, false ); |
---|
892 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
893 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
894 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
895 | |
---|
896 | Bool foundNonZeroCbf = false; |
---|
897 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( 0 ), 0, uiDepth, foundNonZeroCbf ); |
---|
898 | assert( foundNonZeroCbf ); |
---|
899 | } |
---|
900 | else |
---|
901 | { |
---|
902 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
903 | } |
---|
904 | } |
---|
905 | |
---|
906 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
907 | |
---|
908 | // If the configuration being tested exceeds the maximum number of bytes for a slice / slice-segment, then |
---|
909 | // a proper RD evaluation cannot be performed. Therefore, termination of the |
---|
910 | // slice/slice-segment must be made prior to this CTU. |
---|
911 | // This can be achieved by forcing the decision to be that of the rpcTempCU. |
---|
912 | // The exception is each slice / slice-segment must have at least one CTU. |
---|
913 | if (rpcBestCU->getTotalCost()!=MAX_DOUBLE) |
---|
914 | { |
---|
915 | const Bool isEndOfSlice = pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
916 | && ((pcSlice->getSliceBits()+rpcBestCU->getTotalBits())>pcSlice->getSliceArgument()<<3) |
---|
917 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()) |
---|
918 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()); |
---|
919 | const Bool isEndOfSliceSegment = pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
920 | && ((pcSlice->getSliceSegmentBits()+rpcBestCU->getTotalBits()) > pcSlice->getSliceSegmentArgument()<<3) |
---|
921 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()); |
---|
922 | // Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice. |
---|
923 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
924 | { |
---|
925 | rpcBestCU->getTotalCost()=MAX_DOUBLE; |
---|
926 | } |
---|
927 | } |
---|
928 | |
---|
929 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTempDebug) DEBUG_STRING_PASS_INTO(false) ); // RD compare current larger prediction |
---|
930 | // with sub partitioned prediction. |
---|
931 | } |
---|
932 | } |
---|
933 | |
---|
934 | DEBUG_STRING_APPEND(sDebug_, sDebug); |
---|
935 | |
---|
936 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
937 | |
---|
938 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu(), uiDepth, uiDepth ); // Copy Yuv data to picture Yuv |
---|
939 | if (bBoundary) |
---|
940 | { |
---|
941 | return; |
---|
942 | } |
---|
943 | |
---|
944 | // Assert if Best prediction mode is NONE |
---|
945 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
946 | assert( rpcBestCU->getPartitionSize ( 0 ) != NUMBER_OF_PART_SIZES ); |
---|
947 | assert( rpcBestCU->getPredictionMode( 0 ) != NUMBER_OF_PREDICTION_MODES ); |
---|
948 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
949 | } |
---|
950 | |
---|
951 | /** finish encoding a cu and handle end-of-slice conditions |
---|
952 | * \param pcCU |
---|
953 | * \param uiAbsPartIdx |
---|
954 | * \param uiDepth |
---|
955 | * \returns Void |
---|
956 | */ |
---|
957 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
958 | { |
---|
959 | TComPic* pcPic = pcCU->getPic(); |
---|
960 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
961 | |
---|
962 | //Calculate end address |
---|
963 | const Int currentCTUTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pcCU->getCtuRsAddr()); |
---|
964 | const Bool isLastSubCUOfCtu = pcCU->isLastSubCUOfCtu(uiAbsPartIdx); |
---|
965 | if ( isLastSubCUOfCtu ) |
---|
966 | { |
---|
967 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
968 | // i.e. when the slice segment CurEnd CTU address is the current CTU address+1. |
---|
969 | if (pcSlice->getSliceSegmentCurEndCtuTsAddr() != currentCTUTsAddr+1) |
---|
970 | { |
---|
971 | m_pcEntropyCoder->encodeTerminatingBit( 0 ); |
---|
972 | } |
---|
973 | } |
---|
974 | } |
---|
975 | |
---|
976 | /** Compute QP for each CU |
---|
977 | * \param pcCU Target CU |
---|
978 | * \param uiDepth CU depth |
---|
979 | * \returns quantization parameter |
---|
980 | */ |
---|
981 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
982 | { |
---|
983 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
984 | Int iQpOffset = 0; |
---|
985 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
986 | { |
---|
987 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
988 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
989 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
990 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
991 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
992 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
993 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
994 | |
---|
995 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
996 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
997 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
998 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
999 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
1000 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
1001 | } |
---|
1002 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQp+iQpOffset ); |
---|
1003 | } |
---|
1004 | |
---|
1005 | /** encode a CU block recursively |
---|
1006 | * \param pcCU |
---|
1007 | * \param uiAbsPartIdx |
---|
1008 | * \param uiDepth |
---|
1009 | * \returns Void |
---|
1010 | */ |
---|
1011 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1012 | { |
---|
1013 | TComPic *const pcPic = pcCU->getPic(); |
---|
1014 | TComSlice *const pcSlice = pcCU->getSlice(); |
---|
1015 | const TComSPS &sps =*(pcSlice->getSPS()); |
---|
1016 | const TComPPS &pps =*(pcSlice->getPPS()); |
---|
1017 | |
---|
1018 | const UInt maxCUWidth = sps.getMaxCUWidth(); |
---|
1019 | const UInt maxCUHeight = sps.getMaxCUHeight(); |
---|
1020 | |
---|
1021 | Bool bBoundary = false; |
---|
1022 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1023 | const UInt uiRPelX = uiLPelX + (maxCUWidth>>uiDepth) - 1; |
---|
1024 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1025 | const UInt uiBPelY = uiTPelY + (maxCUHeight>>uiDepth) - 1; |
---|
1026 | |
---|
1027 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
1028 | if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange()) |
---|
1029 | { |
---|
1030 | pcCU->setSkipFlagSubParts(true, uiAbsPartIdx, uiDepth); |
---|
1031 | } |
---|
1032 | #endif |
---|
1033 | |
---|
1034 | if( ( uiRPelX < sps.getPicWidthInLumaSamples() ) && ( uiBPelY < sps.getPicHeightInLumaSamples() ) ) |
---|
1035 | { |
---|
1036 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1037 | } |
---|
1038 | else |
---|
1039 | { |
---|
1040 | bBoundary = true; |
---|
1041 | } |
---|
1042 | |
---|
1043 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary ) |
---|
1044 | { |
---|
1045 | UInt uiQNumParts = ( pcPic->getNumPartitionsInCtu() >> (uiDepth<<1) )>>2; |
---|
1046 | if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
1047 | { |
---|
1048 | setdQPFlag(true); |
---|
1049 | } |
---|
1050 | |
---|
1051 | if( uiDepth == pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj()) |
---|
1052 | { |
---|
1053 | setCodeChromaQpAdjFlag(true); |
---|
1054 | } |
---|
1055 | |
---|
1056 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1057 | { |
---|
1058 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1059 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1060 | |
---|
1061 | if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) ) |
---|
1062 | { |
---|
1063 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
1064 | } |
---|
1065 | } |
---|
1066 | return; |
---|
1067 | } |
---|
1068 | |
---|
1069 | if( uiDepth <= pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
1070 | { |
---|
1071 | setdQPFlag(true); |
---|
1072 | } |
---|
1073 | |
---|
1074 | if( uiDepth <= pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj()) |
---|
1075 | { |
---|
1076 | setCodeChromaQpAdjFlag(true); |
---|
1077 | } |
---|
1078 | |
---|
1079 | if (pps.getTransquantBypassEnableFlag()) |
---|
1080 | { |
---|
1081 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
1082 | } |
---|
1083 | |
---|
1084 | if( !pcSlice->isIntra() ) |
---|
1085 | { |
---|
1086 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1087 | } |
---|
1088 | |
---|
1089 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1090 | { |
---|
1091 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
1092 | finishCU(pcCU,uiAbsPartIdx); |
---|
1093 | return; |
---|
1094 | } |
---|
1095 | |
---|
1096 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1097 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1098 | |
---|
1099 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
1100 | { |
---|
1101 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
1102 | |
---|
1103 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
1104 | { |
---|
1105 | // Encode slice finish |
---|
1106 | finishCU(pcCU,uiAbsPartIdx); |
---|
1107 | return; |
---|
1108 | } |
---|
1109 | } |
---|
1110 | |
---|
1111 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1112 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1113 | |
---|
1114 | // Encode Coefficients |
---|
1115 | Bool bCodeDQP = getdQPFlag(); |
---|
1116 | Bool codeChromaQpAdj = getCodeChromaQpAdjFlag(); |
---|
1117 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, codeChromaQpAdj ); |
---|
1118 | setCodeChromaQpAdjFlag( codeChromaQpAdj ); |
---|
1119 | setdQPFlag( bCodeDQP ); |
---|
1120 | |
---|
1121 | // --- write terminating bit --- |
---|
1122 | finishCU(pcCU,uiAbsPartIdx); |
---|
1123 | } |
---|
1124 | |
---|
1125 | Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) |
---|
1126 | { |
---|
1127 | Int k, i, j, jj; |
---|
1128 | Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0; |
---|
1129 | |
---|
1130 | for( k = 0; k < 64; k += 8 ) |
---|
1131 | { |
---|
1132 | diff[k+0] = piOrg[0] ; |
---|
1133 | diff[k+1] = piOrg[1] ; |
---|
1134 | diff[k+2] = piOrg[2] ; |
---|
1135 | diff[k+3] = piOrg[3] ; |
---|
1136 | diff[k+4] = piOrg[4] ; |
---|
1137 | diff[k+5] = piOrg[5] ; |
---|
1138 | diff[k+6] = piOrg[6] ; |
---|
1139 | diff[k+7] = piOrg[7] ; |
---|
1140 | |
---|
1141 | piOrg += iStrideOrg; |
---|
1142 | } |
---|
1143 | |
---|
1144 | //horizontal |
---|
1145 | for (j=0; j < 8; j++) |
---|
1146 | { |
---|
1147 | jj = j << 3; |
---|
1148 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
1149 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
1150 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
1151 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
1152 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
1153 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
1154 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
1155 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
1156 | |
---|
1157 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
1158 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
1159 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
1160 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
1161 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
1162 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
1163 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
1164 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
1165 | |
---|
1166 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
1167 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
1168 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
1169 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
1170 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
1171 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
1172 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
1173 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
1174 | } |
---|
1175 | |
---|
1176 | //vertical |
---|
1177 | for (i=0; i < 8; i++) |
---|
1178 | { |
---|
1179 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
1180 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
1181 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
1182 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
1183 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
1184 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
1185 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
1186 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
1187 | |
---|
1188 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
1189 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
1190 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
1191 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
1192 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
1193 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
1194 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
1195 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
1196 | |
---|
1197 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
1198 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
1199 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
1200 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
1201 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
1202 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
1203 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
1204 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
1205 | } |
---|
1206 | |
---|
1207 | for (i = 0; i < 8; i++) |
---|
1208 | { |
---|
1209 | for (j = 0; j < 8; j++) |
---|
1210 | { |
---|
1211 | iSumHad += abs(m2[i][j]); |
---|
1212 | } |
---|
1213 | } |
---|
1214 | iSumHad -= abs(m2[0][0]); |
---|
1215 | iSumHad =(iSumHad+2)>>2; |
---|
1216 | return(iSumHad); |
---|
1217 | } |
---|
1218 | |
---|
1219 | Int TEncCu::updateCtuDataISlice(TComDataCU* pCtu, Int width, Int height) |
---|
1220 | { |
---|
1221 | Int xBl, yBl; |
---|
1222 | const Int iBlkSize = 8; |
---|
1223 | |
---|
1224 | Pel* pOrgInit = pCtu->getPic()->getPicYuvOrg()->getAddr(COMPONENT_Y, pCtu->getCtuRsAddr(), 0); |
---|
1225 | Int iStrideOrig = pCtu->getPic()->getPicYuvOrg()->getStride(COMPONENT_Y); |
---|
1226 | Pel *pOrg; |
---|
1227 | |
---|
1228 | Int iSumHad = 0; |
---|
1229 | for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize) |
---|
1230 | { |
---|
1231 | for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize) |
---|
1232 | { |
---|
1233 | pOrg = pOrgInit + iStrideOrig*yBl + xBl; |
---|
1234 | iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig); |
---|
1235 | } |
---|
1236 | } |
---|
1237 | return(iSumHad); |
---|
1238 | } |
---|
1239 | |
---|
1240 | /** check RD costs for a CU block encoded with merge |
---|
1241 | * \param rpcBestCU |
---|
1242 | * \param rpcTempCU |
---|
1243 | * \param earlyDetectionSkipMode |
---|
1244 | */ |
---|
1245 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
1246 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode, Bool bUseSkip ) |
---|
1247 | #else |
---|
1248 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode ) |
---|
1249 | #endif |
---|
1250 | { |
---|
1251 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
1252 | if(getFastDeltaQp()) |
---|
1253 | { |
---|
1254 | return; // never check merge in fast deltaqp mode |
---|
1255 | } |
---|
1256 | TComMvField cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists |
---|
1257 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1258 | Int numValidMergeCand = 0; |
---|
1259 | const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); |
---|
1260 | |
---|
1261 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
1262 | { |
---|
1263 | uhInterDirNeighbours[ui] = 0; |
---|
1264 | } |
---|
1265 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1266 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level |
---|
1267 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
1268 | |
---|
1269 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; |
---|
1270 | for( UInt ui = 0; ui < numValidMergeCand; ++ui ) |
---|
1271 | { |
---|
1272 | mergeCandBuffer[ui] = 0; |
---|
1273 | } |
---|
1274 | |
---|
1275 | Bool bestIsSkip = false; |
---|
1276 | |
---|
1277 | UInt iteration; |
---|
1278 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
1279 | { |
---|
1280 | iteration = 1; |
---|
1281 | } |
---|
1282 | else |
---|
1283 | { |
---|
1284 | iteration = 2; |
---|
1285 | } |
---|
1286 | DEBUG_STRING_NEW(bestStr) |
---|
1287 | |
---|
1288 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
1289 | for( UInt uiNoResidual = bUseSkip?1:0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
1290 | #else |
---|
1291 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
1292 | #endif |
---|
1293 | { |
---|
1294 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
1295 | { |
---|
1296 | #if REF_IDX_ME_ZEROMV |
---|
1297 | Bool bZeroMVILR = rpcTempCU->checkZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]); |
---|
1298 | |
---|
1299 | if( bZeroMVILR ) |
---|
1300 | { |
---|
1301 | #endif |
---|
1302 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
1303 | if (!(rpcTempCU->isInterLayerReference(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]) && m_disableILP)) |
---|
1304 | { |
---|
1305 | #endif |
---|
1306 | if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) |
---|
1307 | { |
---|
1308 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
1309 | { |
---|
1310 | DEBUG_STRING_NEW(tmpStr) |
---|
1311 | // set MC parameters |
---|
1312 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to CTU level |
---|
1313 | rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth ); |
---|
1314 | rpcTempCU->setChromaQpAdjSubParts( bTransquantBypassFlag ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth ); |
---|
1315 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level |
---|
1316 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
1317 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
1318 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
1319 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1320 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1321 | |
---|
1322 | // do MC |
---|
1323 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1324 | // estimate residual and encode everything |
---|
1325 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
1326 | m_ppcOrigYuv [uhDepth], |
---|
1327 | m_ppcPredYuvTemp[uhDepth], |
---|
1328 | m_ppcResiYuvTemp[uhDepth], |
---|
1329 | m_ppcResiYuvBest[uhDepth], |
---|
1330 | m_ppcRecoYuvTemp[uhDepth], |
---|
1331 | (uiNoResidual != 0) DEBUG_STRING_PASS_INTO(tmpStr) ); |
---|
1332 | |
---|
1333 | #if DEBUG_STRING |
---|
1334 | DebugInterPredResiReco(tmpStr, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
1335 | #endif |
---|
1336 | |
---|
1337 | if ((uiNoResidual == 0) && (rpcTempCU->getQtRootCbf(0) == 0)) |
---|
1338 | { |
---|
1339 | // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 |
---|
1340 | mergeCandBuffer[uiMergeCand] = 1; |
---|
1341 | } |
---|
1342 | |
---|
1343 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
1344 | xCheckDQP( rpcTempCU ); |
---|
1345 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr)); |
---|
1346 | |
---|
1347 | rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); |
---|
1348 | |
---|
1349 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
1350 | { |
---|
1351 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
1352 | } |
---|
1353 | } |
---|
1354 | } |
---|
1355 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
1356 | } |
---|
1357 | #endif |
---|
1358 | #if REF_IDX_ME_ZEROMV |
---|
1359 | } |
---|
1360 | #endif |
---|
1361 | } |
---|
1362 | |
---|
1363 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
1364 | { |
---|
1365 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
1366 | { |
---|
1367 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
1368 | { |
---|
1369 | *earlyDetectionSkipMode = true; |
---|
1370 | } |
---|
1371 | else if(m_pcEncCfg->getMotionEstimationSearchMethod() != MESEARCH_SELECTIVE) |
---|
1372 | { |
---|
1373 | Int absoulte_MV=0; |
---|
1374 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
1375 | { |
---|
1376 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
1377 | { |
---|
1378 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
1379 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
1380 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
1381 | absoulte_MV+=iHor+iVer; |
---|
1382 | } |
---|
1383 | } |
---|
1384 | |
---|
1385 | if(absoulte_MV == 0) |
---|
1386 | { |
---|
1387 | *earlyDetectionSkipMode = true; |
---|
1388 | } |
---|
1389 | } |
---|
1390 | } |
---|
1391 | } |
---|
1392 | } |
---|
1393 | DEBUG_STRING_APPEND(sDebug, bestStr) |
---|
1394 | } |
---|
1395 | |
---|
1396 | |
---|
1397 | #if AMP_MRG |
---|
1398 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG) |
---|
1399 | #else |
---|
1400 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
1401 | #endif |
---|
1402 | { |
---|
1403 | DEBUG_STRING_NEW(sTest) |
---|
1404 | |
---|
1405 | if(getFastDeltaQp()) |
---|
1406 | { |
---|
1407 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
1408 | const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u); |
---|
1409 | if(ePartSize != SIZE_2Nx2N || rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize) |
---|
1410 | { |
---|
1411 | return; // only check necessary 2Nx2N Inter in fast deltaqp mode |
---|
1412 | } |
---|
1413 | } |
---|
1414 | |
---|
1415 | // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
1416 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1417 | |
---|
1418 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
1419 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
1420 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth ); |
---|
1421 | |
---|
1422 | #if SVC_EXTENSION |
---|
1423 | #if AMP_MRG |
---|
1424 | rpcTempCU->setMergeAMP (true); |
---|
1425 | Bool ret = m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG ); |
---|
1426 | #else |
---|
1427 | Bool ret = m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
1428 | #endif |
---|
1429 | |
---|
1430 | if( !ret ) |
---|
1431 | { |
---|
1432 | return; |
---|
1433 | } |
---|
1434 | #else |
---|
1435 | #if AMP_MRG |
---|
1436 | rpcTempCU->setMergeAMP (true); |
---|
1437 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG ); |
---|
1438 | #else |
---|
1439 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
1440 | #endif |
---|
1441 | #endif |
---|
1442 | |
---|
1443 | #if AMP_MRG |
---|
1444 | if ( !rpcTempCU->getMergeAMP() ) |
---|
1445 | { |
---|
1446 | return; |
---|
1447 | } |
---|
1448 | #endif |
---|
1449 | |
---|
1450 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false DEBUG_STRING_PASS_INTO(sTest) ); |
---|
1451 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1452 | |
---|
1453 | #if DEBUG_STRING |
---|
1454 | DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
1455 | #endif |
---|
1456 | |
---|
1457 | xCheckDQP( rpcTempCU ); |
---|
1458 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
1459 | } |
---|
1460 | |
---|
1461 | Void TEncCu::xCheckRDCostIntra( TComDataCU *&rpcBestCU, |
---|
1462 | TComDataCU *&rpcTempCU, |
---|
1463 | PartSize eSize |
---|
1464 | DEBUG_STRING_FN_DECLARE(sDebug) ) |
---|
1465 | { |
---|
1466 | DEBUG_STRING_NEW(sTest) |
---|
1467 | |
---|
1468 | if(getFastDeltaQp()) |
---|
1469 | { |
---|
1470 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
1471 | const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u); |
---|
1472 | if(rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize) |
---|
1473 | { |
---|
1474 | return; // only check necessary 2Nx2N Intra in fast deltaqp mode |
---|
1475 | } |
---|
1476 | } |
---|
1477 | |
---|
1478 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
1479 | |
---|
1480 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
1481 | |
---|
1482 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
1483 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
1484 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth ); |
---|
1485 | |
---|
1486 | Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]; |
---|
1487 | |
---|
1488 | m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) ); |
---|
1489 | |
---|
1490 | m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() ); |
---|
1491 | |
---|
1492 | if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400) |
---|
1493 | { |
---|
1494 | m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) ); |
---|
1495 | } |
---|
1496 | |
---|
1497 | m_pcEntropyCoder->resetBits(); |
---|
1498 | |
---|
1499 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
1500 | { |
---|
1501 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
1502 | } |
---|
1503 | |
---|
1504 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
1505 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
1506 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
1507 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 ); |
---|
1508 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
1509 | |
---|
1510 | // Encode Coefficients |
---|
1511 | Bool bCodeDQP = getdQPFlag(); |
---|
1512 | Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag(); |
---|
1513 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag ); |
---|
1514 | setCodeChromaQpAdjFlag( codeChromaQpAdjFlag ); |
---|
1515 | setdQPFlag( bCodeDQP ); |
---|
1516 | |
---|
1517 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1518 | |
---|
1519 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1520 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1521 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1522 | |
---|
1523 | xCheckDQP( rpcTempCU ); |
---|
1524 | |
---|
1525 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
1526 | } |
---|
1527 | |
---|
1528 | |
---|
1529 | /** Check R-D costs for a CU with PCM mode. |
---|
1530 | * \param rpcBestCU pointer to best mode CU data structure |
---|
1531 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
1532 | * \returns Void |
---|
1533 | * |
---|
1534 | * \note Current PCM implementation encodes sample values in a lossless way. The distortion of PCM mode CUs are zero. PCM mode is selected if the best mode yields bits greater than that of PCM mode. |
---|
1535 | */ |
---|
1536 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1537 | { |
---|
1538 | if(getFastDeltaQp()) |
---|
1539 | { |
---|
1540 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
1541 | const UInt fastDeltaQPCuMaxPCMSize = Clip3((UInt)1<<sps.getPCMLog2MinSize(), (UInt)1<<sps.getPCMLog2MaxSize(), 32u); |
---|
1542 | if (rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxPCMSize) |
---|
1543 | { |
---|
1544 | return; // only check necessary PCM in fast deltaqp mode |
---|
1545 | } |
---|
1546 | } |
---|
1547 | |
---|
1548 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
1549 | |
---|
1550 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
1551 | |
---|
1552 | rpcTempCU->setIPCMFlag(0, true); |
---|
1553 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
1554 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
1555 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
1556 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
1557 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth ); |
---|
1558 | |
---|
1559 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
1560 | |
---|
1561 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
1562 | |
---|
1563 | m_pcEntropyCoder->resetBits(); |
---|
1564 | |
---|
1565 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
1566 | { |
---|
1567 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
1568 | } |
---|
1569 | |
---|
1570 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
1571 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
1572 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
1573 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
1574 | |
---|
1575 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1576 | |
---|
1577 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1578 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1579 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1580 | |
---|
1581 | xCheckDQP( rpcTempCU ); |
---|
1582 | DEBUG_STRING_NEW(a) |
---|
1583 | DEBUG_STRING_NEW(b) |
---|
1584 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(a) DEBUG_STRING_PASS_INTO(b)); |
---|
1585 | } |
---|
1586 | |
---|
1587 | /** check whether current try is the best with identifying the depth of current try |
---|
1588 | * \param rpcBestCU |
---|
1589 | * \param rpcTempCU |
---|
1590 | * \param uiDepth |
---|
1591 | */ |
---|
1592 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sParent) DEBUG_STRING_FN_DECLARE(sTest) DEBUG_STRING_PASS_INTO(Bool bAddSizeInfo) ) |
---|
1593 | { |
---|
1594 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
1595 | { |
---|
1596 | TComYuv* pcYuv; |
---|
1597 | // Change Information data |
---|
1598 | TComDataCU* pcCU = rpcBestCU; |
---|
1599 | rpcBestCU = rpcTempCU; |
---|
1600 | rpcTempCU = pcCU; |
---|
1601 | |
---|
1602 | // Change Prediction data |
---|
1603 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
1604 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
1605 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
1606 | |
---|
1607 | // Change Reconstruction data |
---|
1608 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
1609 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
1610 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
1611 | |
---|
1612 | pcYuv = NULL; |
---|
1613 | pcCU = NULL; |
---|
1614 | |
---|
1615 | // store temp best CI for next CU coding |
---|
1616 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
1617 | |
---|
1618 | |
---|
1619 | #if DEBUG_STRING |
---|
1620 | DEBUG_STRING_SWAP(sParent, sTest) |
---|
1621 | const PredMode predMode=rpcBestCU->getPredictionMode(0); |
---|
1622 | if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo) |
---|
1623 | { |
---|
1624 | std::stringstream ss(stringstream::out); |
---|
1625 | ss <<"###: " << (predMode==MODE_INTRA?"Intra ":"Inter ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl; |
---|
1626 | sParent+=ss.str(); |
---|
1627 | } |
---|
1628 | #endif |
---|
1629 | } |
---|
1630 | } |
---|
1631 | |
---|
1632 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
1633 | { |
---|
1634 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
1635 | |
---|
1636 | const TComPPS &pps = *(pcCU->getSlice()->getPPS()); |
---|
1637 | if ( pps.getUseDQP() && uiDepth <= pps.getMaxCuDQPDepth() ) |
---|
1638 | { |
---|
1639 | if ( pcCU->getQtRootCbf( 0) ) |
---|
1640 | { |
---|
1641 | m_pcEntropyCoder->resetBits(); |
---|
1642 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
1643 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
1644 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1645 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
1646 | } |
---|
1647 | else |
---|
1648 | { |
---|
1649 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
1650 | } |
---|
1651 | } |
---|
1652 | } |
---|
1653 | |
---|
1654 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
1655 | { |
---|
1656 | pDst->iN = pSrc->iN; |
---|
1657 | for (Int i = 0; i < pSrc->iN; i++) |
---|
1658 | { |
---|
1659 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
1660 | } |
---|
1661 | } |
---|
1662 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth ) |
---|
1663 | { |
---|
1664 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
1665 | UInt uiSrcBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiSrcDepth); |
---|
1666 | UInt uiBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiDepth); |
---|
1667 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
1668 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
1669 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
1670 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
1671 | |
---|
1672 | m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
1673 | } |
---|
1674 | |
---|
1675 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
1676 | { |
---|
1677 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
1678 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
1679 | m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx); |
---|
1680 | } |
---|
1681 | |
---|
1682 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
1683 | * \param pCU pointer to current CU |
---|
1684 | * \param pOrgYuv pointer to original sample array |
---|
1685 | */ |
---|
1686 | Void TEncCu::xFillPCMBuffer ( TComDataCU* pCU, TComYuv* pOrgYuv ) |
---|
1687 | { |
---|
1688 | const ChromaFormat format = pCU->getPic()->getChromaFormat(); |
---|
1689 | const UInt numberValidComponents = getNumberValidComponents(format); |
---|
1690 | for (UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++) |
---|
1691 | { |
---|
1692 | const ComponentID component = ComponentID(componentIndex); |
---|
1693 | |
---|
1694 | const UInt width = pCU->getWidth(0) >> getComponentScaleX(component, format); |
---|
1695 | const UInt height = pCU->getHeight(0) >> getComponentScaleY(component, format); |
---|
1696 | |
---|
1697 | Pel *source = pOrgYuv->getAddr(component, 0, width); |
---|
1698 | Pel *destination = pCU->getPCMSample(component); |
---|
1699 | |
---|
1700 | const UInt sourceStride = pOrgYuv->getStride(component); |
---|
1701 | |
---|
1702 | for (Int line = 0; line < height; line++) |
---|
1703 | { |
---|
1704 | for (Int column = 0; column < width; column++) |
---|
1705 | { |
---|
1706 | destination[column] = source[column]; |
---|
1707 | } |
---|
1708 | |
---|
1709 | source += sourceStride; |
---|
1710 | destination += width; |
---|
1711 | } |
---|
1712 | } |
---|
1713 | } |
---|
1714 | |
---|
1715 | #if ADAPTIVE_QP_SELECTION |
---|
1716 | /** Collect ARL statistics from one block |
---|
1717 | */ |
---|
1718 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
1719 | { |
---|
1720 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
1721 | { |
---|
1722 | TCoeff u = abs( rpcCoeff[ n ] ); |
---|
1723 | TCoeff absc = rpcArlCoeff[ n ]; |
---|
1724 | |
---|
1725 | if( u != 0 ) |
---|
1726 | { |
---|
1727 | if( u < LEVEL_RANGE ) |
---|
1728 | { |
---|
1729 | cSum[ u ] += ( Double )absc; |
---|
1730 | numSamples[ u ]++; |
---|
1731 | } |
---|
1732 | else |
---|
1733 | { |
---|
1734 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
1735 | numSamples[ LEVEL_RANGE ]++; |
---|
1736 | } |
---|
1737 | } |
---|
1738 | } |
---|
1739 | |
---|
1740 | return 0; |
---|
1741 | } |
---|
1742 | |
---|
1743 | //! Collect ARL statistics from one CTU |
---|
1744 | Void TEncCu::xCtuCollectARLStats(TComDataCU* pCtu ) |
---|
1745 | { |
---|
1746 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to data type and quantization output |
---|
1747 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to data type and quantization output |
---|
1748 | |
---|
1749 | TCoeff* pCoeffY = pCtu->getCoeff(COMPONENT_Y); |
---|
1750 | TCoeff* pArlCoeffY = pCtu->getArlCoeff(COMPONENT_Y); |
---|
1751 | const TComSPS &sps = *(pCtu->getSlice()->getSPS()); |
---|
1752 | |
---|
1753 | const UInt uiMinCUWidth = sps.getMaxCUWidth() >> sps.getMaxTotalCUDepth(); // NOTE: ed - this is not the minimum CU width. It is the square-root of the number of coefficients per part. |
---|
1754 | const UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; // NOTE: ed - what is this? |
---|
1755 | |
---|
1756 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
1757 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
1758 | |
---|
1759 | // Collect stats to cSum[][] and numSamples[][] |
---|
1760 | for(Int i = 0; i < pCtu->getTotalNumPart(); i ++ ) |
---|
1761 | { |
---|
1762 | UInt uiTrIdx = pCtu->getTransformIdx(i); |
---|
1763 | |
---|
1764 | if(pCtu->isInter(i) && pCtu->getCbf( i, COMPONENT_Y, uiTrIdx ) ) |
---|
1765 | { |
---|
1766 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
1767 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
1768 | |
---|
1769 | pCoeffY += uiMinNumCoeffInCU; |
---|
1770 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
1771 | } |
---|
1772 | |
---|
1773 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
1774 | { |
---|
1775 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
1776 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
1777 | } |
---|
1778 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
1779 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
1780 | } |
---|
1781 | #endif |
---|
1782 | |
---|
1783 | #if SVC_EXTENSION |
---|
1784 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
1785 | Bool TEncCu::xCheckTileSetConstraint( TComDataCU*& rpcCU ) |
---|
1786 | { |
---|
1787 | Bool disableILP = false; |
---|
1788 | |
---|
1789 | if (rpcCU->getPic()->getLayerId() == (m_pcEncCfg->getNumLayer() - 1) && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getCtuRsAddr()) >= 0) |
---|
1790 | { |
---|
1791 | if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getCtuRsAddr()) == 2) |
---|
1792 | { |
---|
1793 | disableILP = true; |
---|
1794 | } |
---|
1795 | if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getCtuRsAddr()) == 1) |
---|
1796 | { |
---|
1797 | Int currCUaddr = rpcCU->getCtuRsAddr(); |
---|
1798 | Int frameWitdhInCU = rpcCU->getPic()->getPicSym()->getFrameWidthInCtus(); |
---|
1799 | Int frameHeightInCU = rpcCU->getPic()->getPicSym()->getFrameHeightInCtus(); |
---|
1800 | Bool leftCUExists = (currCUaddr % frameWitdhInCU) > 0; |
---|
1801 | Bool aboveCUExists = (currCUaddr / frameWitdhInCU) > 0; |
---|
1802 | Bool rightCUExists = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1); |
---|
1803 | Bool belowCUExists = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1); |
---|
1804 | Int currTileSetIdx = rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr); |
---|
1805 | // Check if CU is at tile set boundary |
---|
1806 | if ( (leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-1) != currTileSetIdx) || |
---|
1807 | (leftCUExists && aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) || |
---|
1808 | (aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) || |
---|
1809 | (aboveCUExists && rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) || |
---|
1810 | (rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+1) != currTileSetIdx) || |
---|
1811 | (rightCUExists && belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) || |
---|
1812 | (belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) || |
---|
1813 | (belowCUExists && leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) ) |
---|
1814 | { |
---|
1815 | disableILP = true; // Disable ILP in tile set boundary CU |
---|
1816 | } |
---|
1817 | } |
---|
1818 | } |
---|
1819 | |
---|
1820 | return disableILP; |
---|
1821 | } |
---|
1822 | |
---|
1823 | Void TEncCu::xVerifyTileSetConstraint( TComDataCU*& rpcCU ) |
---|
1824 | { |
---|
1825 | if( rpcCU->getPic()->getLayerId() == (m_pcEncCfg->getNumLayer() - 1) && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && |
---|
1826 | rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getCtuRsAddr()) >= 0 && m_disableILP ) |
---|
1827 | { |
---|
1828 | UInt numPartitions = rpcCU->getPic()->getNumPartitionsInCtu(); |
---|
1829 | for (UInt i = 0; i < numPartitions; i++) |
---|
1830 | { |
---|
1831 | if (!rpcCU->isIntra(i)) |
---|
1832 | { |
---|
1833 | for (UInt refList = 0; refList < 2; refList++) |
---|
1834 | { |
---|
1835 | if (rpcCU->getInterDir(i) & (1<<refList)) |
---|
1836 | { |
---|
1837 | TComCUMvField *mvField = rpcCU->getCUMvField(RefPicList(refList)); |
---|
1838 | if (mvField->getRefIdx(i) >= 0) |
---|
1839 | { |
---|
1840 | assert(!(rpcCU->getSlice()->getRefPic(RefPicList(refList), mvField->getRefIdx(i))->isILR(rpcCU->getPic()->getLayerId()))); |
---|
1841 | } |
---|
1842 | } |
---|
1843 | } |
---|
1844 | } |
---|
1845 | } |
---|
1846 | } |
---|
1847 | } |
---|
1848 | #endif |
---|
1849 | |
---|
1850 | #if ENCODER_FAST_MODE |
---|
1851 | Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt refLayerId) |
---|
1852 | { |
---|
1853 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1854 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
1855 | #if SKIP_FLAG |
---|
1856 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
1857 | #endif |
---|
1858 | rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); //2Nx2N |
---|
1859 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
1860 | rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagForceValue(), 0, uhDepth ); |
---|
1861 | Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], refLayerId ); |
---|
1862 | if(!exitILR) |
---|
1863 | { |
---|
1864 | return; |
---|
1865 | } |
---|
1866 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
1867 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1868 | xCheckDQP( rpcTempCU ); |
---|
1869 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
1870 | return; |
---|
1871 | } |
---|
1872 | #endif |
---|
1873 | #endif //SVC_EXTENSION |
---|
1874 | //! \} |
---|