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