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