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