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 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP ); |
---|
413 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP ); |
---|
414 | } |
---|
415 | else |
---|
416 | { |
---|
417 | iMinQP = rpcTempCU->getQP(0); |
---|
418 | iMaxQP = rpcTempCU->getQP(0); |
---|
419 | } |
---|
420 | |
---|
421 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
422 | { |
---|
423 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
424 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
425 | } |
---|
426 | |
---|
427 | // transquant-bypass (TQB) processing loop variable initialisation --- |
---|
428 | |
---|
429 | 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. |
---|
430 | |
---|
431 | if ( (rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) ) |
---|
432 | { |
---|
433 | isAddLowestQP = true; // mark that the first iteration is to cost TQB mode. |
---|
434 | iMinQP = iMinQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs |
---|
435 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
436 | { |
---|
437 | iMaxQP = iMinQP; |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
442 | // We need to split, so don't try these modes. |
---|
443 | #if REPN_FORMAT_IN_VPS |
---|
444 | if ( ( uiRPelX < rpcBestCU->getSlice()->getPicWidthInLumaSamples() ) && |
---|
445 | ( uiBPelY < rpcBestCU->getSlice()->getPicHeightInLumaSamples() ) ) |
---|
446 | #else |
---|
447 | if ( ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && |
---|
448 | ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
449 | #endif |
---|
450 | { |
---|
451 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
452 | if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange()) |
---|
453 | { |
---|
454 | Int iQP = iBaseQP; |
---|
455 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
456 | |
---|
457 | if( bIsLosslessMode ) |
---|
458 | { |
---|
459 | iQP = lowestQP; |
---|
460 | } |
---|
461 | |
---|
462 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
463 | |
---|
464 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode, true ); |
---|
465 | } |
---|
466 | else |
---|
467 | { |
---|
468 | #endif |
---|
469 | #if (ENCODER_FAST_MODE) |
---|
470 | Bool testInter = true; |
---|
471 | if (rpcBestCU->getLayerId() > 0) |
---|
472 | { |
---|
473 | if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx()) |
---|
474 | { |
---|
475 | testInter = false; |
---|
476 | } |
---|
477 | if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx()) |
---|
478 | { |
---|
479 | testInter = false; |
---|
480 | } |
---|
481 | } |
---|
482 | #endif |
---|
483 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
484 | { |
---|
485 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
486 | |
---|
487 | if (bIsLosslessMode) |
---|
488 | { |
---|
489 | iQP = lowestQP; |
---|
490 | } |
---|
491 | |
---|
492 | m_ChromaQpAdjIdc = 0; |
---|
493 | if (pcSlice->getUseChromaQpAdj()) |
---|
494 | { |
---|
495 | /* Pre-estimation of chroma QP based on input block activity may be performed |
---|
496 | * here, using for example m_ppcOrigYuv[uiDepth] */ |
---|
497 | /* To exercise the current code, the index used for adjustment is based on |
---|
498 | * block position |
---|
499 | */ |
---|
500 | Int lgMinCuSize = pcSlice->getSPS()->getLog2MinCodingBlockSize(); |
---|
501 | m_ChromaQpAdjIdc = ((uiLPelX >> lgMinCuSize) + (uiTPelY >> lgMinCuSize)) % (pcSlice->getPPS()->getChromaQpAdjTableSize() + 1); |
---|
502 | } |
---|
503 | |
---|
504 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
505 | |
---|
506 | // do inter modes, SKIP and 2Nx2N |
---|
507 | #if (ENCODER_FAST_MODE == 1) |
---|
508 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
509 | #else |
---|
510 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
511 | #endif |
---|
512 | { |
---|
513 | // 2Nx2N |
---|
514 | if(m_pcEncCfg->getUseEarlySkipDetection()) |
---|
515 | { |
---|
516 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
517 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N |
---|
518 | } |
---|
519 | // SKIP |
---|
520 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), &earlyDetectionSkipMode );//by Merge for inter_2Nx2N |
---|
521 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
522 | |
---|
523 | #if (ENCODER_FAST_MODE == 2) |
---|
524 | if (testInter) |
---|
525 | { |
---|
526 | #endif |
---|
527 | if(!m_pcEncCfg->getUseEarlySkipDetection()) |
---|
528 | { |
---|
529 | // 2Nx2N, NxN |
---|
530 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
531 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
532 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
533 | { |
---|
534 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
535 | } |
---|
536 | } |
---|
537 | #if (ENCODER_FAST_MODE == 2) |
---|
538 | } |
---|
539 | #endif |
---|
540 | } |
---|
541 | |
---|
542 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
543 | { |
---|
544 | iQP = iMinQP; |
---|
545 | } |
---|
546 | } |
---|
547 | |
---|
548 | if(!earlyDetectionSkipMode) |
---|
549 | { |
---|
550 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
551 | { |
---|
552 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); // If lossless, then iQP is irrelevant for subsequent modules. |
---|
553 | |
---|
554 | if (bIsLosslessMode) |
---|
555 | { |
---|
556 | iQP = lowestQP; |
---|
557 | } |
---|
558 | |
---|
559 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
560 | |
---|
561 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
562 | #if (ENCODER_FAST_MODE) |
---|
563 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
564 | #else |
---|
565 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
566 | #endif |
---|
567 | { |
---|
568 | // 2Nx2N, NxN |
---|
569 | if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
570 | { |
---|
571 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu) |
---|
572 | { |
---|
573 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
574 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | if(doNotBlockPu) |
---|
579 | { |
---|
580 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
581 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
582 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
583 | { |
---|
584 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
585 | } |
---|
586 | } |
---|
587 | if(doNotBlockPu) |
---|
588 | { |
---|
589 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
590 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
591 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
592 | { |
---|
593 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
594 | } |
---|
595 | } |
---|
596 | |
---|
597 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
598 | if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) |
---|
599 | { |
---|
600 | #if AMP_ENC_SPEEDUP |
---|
601 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
602 | |
---|
603 | #if AMP_MRG |
---|
604 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
605 | |
---|
606 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
607 | #else |
---|
608 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
609 | #endif |
---|
610 | |
---|
611 | //! Do horizontal AMP |
---|
612 | if ( bTestAMP_Hor ) |
---|
613 | { |
---|
614 | if(doNotBlockPu) |
---|
615 | { |
---|
616 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
617 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
618 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
619 | { |
---|
620 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
621 | } |
---|
622 | } |
---|
623 | if(doNotBlockPu) |
---|
624 | { |
---|
625 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
626 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
627 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
628 | { |
---|
629 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
630 | } |
---|
631 | } |
---|
632 | } |
---|
633 | #if AMP_MRG |
---|
634 | else if ( bTestMergeAMP_Hor ) |
---|
635 | { |
---|
636 | if(doNotBlockPu) |
---|
637 | { |
---|
638 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
639 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
640 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
641 | { |
---|
642 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
643 | } |
---|
644 | } |
---|
645 | if(doNotBlockPu) |
---|
646 | { |
---|
647 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
648 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
649 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
650 | { |
---|
651 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
652 | } |
---|
653 | } |
---|
654 | } |
---|
655 | #endif |
---|
656 | |
---|
657 | //! Do horizontal AMP |
---|
658 | if ( bTestAMP_Ver ) |
---|
659 | { |
---|
660 | if(doNotBlockPu) |
---|
661 | { |
---|
662 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
663 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
664 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
665 | { |
---|
666 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
667 | } |
---|
668 | } |
---|
669 | if(doNotBlockPu) |
---|
670 | { |
---|
671 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
672 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
673 | } |
---|
674 | } |
---|
675 | #if AMP_MRG |
---|
676 | else if ( bTestMergeAMP_Ver ) |
---|
677 | { |
---|
678 | if(doNotBlockPu) |
---|
679 | { |
---|
680 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
681 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
682 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
683 | { |
---|
684 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
685 | } |
---|
686 | } |
---|
687 | if(doNotBlockPu) |
---|
688 | { |
---|
689 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
690 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
691 | } |
---|
692 | } |
---|
693 | #endif |
---|
694 | |
---|
695 | #else |
---|
696 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
697 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
698 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
699 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
700 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
701 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
702 | |
---|
703 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
704 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
705 | |
---|
706 | #endif |
---|
707 | } |
---|
708 | } |
---|
709 | |
---|
710 | // do normal intra modes |
---|
711 | // speedup for inter frames |
---|
712 | Double intraCost = 0.0; |
---|
713 | |
---|
714 | if((rpcBestCU->getSlice()->getSliceType() == I_SLICE) || |
---|
715 | #if ENCODER_FAST_MODE |
---|
716 | ( rpcBestCU->getPredictionMode(0) != MODE_INTRA && rpcBestCU->getPredictionMode(0) != MODE_INTER ) || // if there is no valid inter prediction |
---|
717 | !testInter || |
---|
718 | #endif |
---|
719 | (rpcBestCU->getCbf( 0, COMPONENT_Y ) != 0) || |
---|
720 | ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) || |
---|
721 | ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) ) // avoid very complex intra if it is unlikely |
---|
722 | { |
---|
723 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, intraCost, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
724 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
725 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
726 | { |
---|
727 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
728 | { |
---|
729 | Double tmpIntraCost; |
---|
730 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, tmpIntraCost, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
731 | intraCost = std::min(intraCost, tmpIntraCost); |
---|
732 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
733 | } |
---|
734 | } |
---|
735 | } |
---|
736 | |
---|
737 | // test PCM |
---|
738 | if(pcPic->getSlice(0)->getSPS()->getUsePCM() |
---|
739 | && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) |
---|
740 | && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) |
---|
741 | { |
---|
742 | UInt uiRawBits = getTotalBits(rpcBestCU->getWidth(0), rpcBestCU->getHeight(0), rpcBestCU->getPic()->getChromaFormat(), g_bitDepth); |
---|
743 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
744 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
745 | { |
---|
746 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
747 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
748 | } |
---|
749 | } |
---|
750 | #if ENCODER_FAST_MODE |
---|
751 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
752 | if(pcPic->getLayerId() > 0 && !m_disableILP) |
---|
753 | #else |
---|
754 | if(pcPic->getLayerId() > 0) |
---|
755 | #endif |
---|
756 | { |
---|
757 | for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++) |
---|
758 | { |
---|
759 | xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getVPS()->getRefLayerId( pcSlice->getLayerId(), pcSlice->getInterLayerPredLayerIdc(refLayer) ) ); |
---|
760 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
761 | } |
---|
762 | } |
---|
763 | #endif |
---|
764 | |
---|
765 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
766 | { |
---|
767 | iQP = iMinQP; |
---|
768 | } |
---|
769 | } |
---|
770 | } |
---|
771 | |
---|
772 | m_pcEntropyCoder->resetBits(); |
---|
773 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
774 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
775 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
776 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
777 | |
---|
778 | // Early CU determination |
---|
779 | if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) ) |
---|
780 | { |
---|
781 | bSubBranch = false; |
---|
782 | } |
---|
783 | else |
---|
784 | { |
---|
785 | bSubBranch = true; |
---|
786 | } |
---|
787 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
788 | } |
---|
789 | #endif |
---|
790 | } |
---|
791 | else |
---|
792 | { |
---|
793 | bBoundary = true; |
---|
794 | } |
---|
795 | |
---|
796 | // copy orginal YUV samples to PCM buffer |
---|
797 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
798 | { |
---|
799 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
800 | } |
---|
801 | |
---|
802 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
803 | { |
---|
804 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
805 | #if REPN_FORMAT_IN_VPS |
---|
806 | iMinQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
807 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
808 | #else |
---|
809 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP ); |
---|
810 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP ); |
---|
811 | #endif |
---|
812 | } |
---|
813 | else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
814 | { |
---|
815 | iMinQP = iBaseQP; |
---|
816 | iMaxQP = iBaseQP; |
---|
817 | } |
---|
818 | else |
---|
819 | { |
---|
820 | const Int iStartQP = rpcTempCU->getQP(0); |
---|
821 | iMinQP = iStartQP; |
---|
822 | iMaxQP = iStartQP; |
---|
823 | } |
---|
824 | |
---|
825 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
826 | { |
---|
827 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
828 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
829 | } |
---|
830 | |
---|
831 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
832 | { |
---|
833 | iMaxQP = iMinQP; // If all TUs are forced into using transquant bypass, do not loop here. |
---|
834 | } |
---|
835 | |
---|
836 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
837 | { |
---|
838 | const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true. |
---|
839 | |
---|
840 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
841 | |
---|
842 | // further split |
---|
843 | if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
844 | { |
---|
845 | UChar uhNextDepth = uiDepth+1; |
---|
846 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
847 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
848 | DEBUG_STRING_NEW(sTempDebug) |
---|
849 | |
---|
850 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
851 | { |
---|
852 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
853 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
854 | |
---|
855 | #if REPN_FORMAT_IN_VPS |
---|
856 | if( ( pcSubBestPartCU->getCUPelX() < pcSlice->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
857 | #else |
---|
858 | if( ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
859 | #endif |
---|
860 | { |
---|
861 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
862 | { |
---|
863 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
864 | } |
---|
865 | else |
---|
866 | { |
---|
867 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
868 | } |
---|
869 | |
---|
870 | #if AMP_ENC_SPEEDUP |
---|
871 | DEBUG_STRING_NEW(sChild) |
---|
872 | if ( !rpcBestCU->isInter(0) ) |
---|
873 | { |
---|
874 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES ); |
---|
875 | } |
---|
876 | else |
---|
877 | { |
---|
878 | |
---|
879 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), rpcBestCU->getPartitionSize(0) ); |
---|
880 | } |
---|
881 | DEBUG_STRING_APPEND(sTempDebug, sChild) |
---|
882 | #else |
---|
883 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
884 | #endif |
---|
885 | |
---|
886 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
887 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
888 | } |
---|
889 | else |
---|
890 | { |
---|
891 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
892 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
893 | } |
---|
894 | } |
---|
895 | |
---|
896 | if( !bBoundary ) |
---|
897 | { |
---|
898 | m_pcEntropyCoder->resetBits(); |
---|
899 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
900 | |
---|
901 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
902 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
903 | } |
---|
904 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
905 | |
---|
906 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
907 | { |
---|
908 | Bool hasResidual = false; |
---|
909 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
910 | { |
---|
911 | if( ( rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Y) |
---|
912 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cb) && (numberValidComponents > COMPONENT_Cb)) |
---|
913 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cr) && (numberValidComponents > COMPONENT_Cr)) ) ) |
---|
914 | { |
---|
915 | hasResidual = true; |
---|
916 | break; |
---|
917 | } |
---|
918 | } |
---|
919 | |
---|
920 | UInt uiTargetPartIdx = 0; |
---|
921 | if ( hasResidual ) |
---|
922 | { |
---|
923 | #if !RDO_WITHOUT_DQP_BITS |
---|
924 | m_pcEntropyCoder->resetBits(); |
---|
925 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
926 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
927 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
928 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
929 | #endif |
---|
930 | |
---|
931 | Bool foundNonZeroCbf = false; |
---|
932 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth, foundNonZeroCbf ); |
---|
933 | assert( foundNonZeroCbf ); |
---|
934 | } |
---|
935 | else |
---|
936 | { |
---|
937 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
938 | } |
---|
939 | } |
---|
940 | |
---|
941 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
942 | |
---|
943 | // TODO: this does not account for the slice bytes already written. See other instances of FIXED_NUMBER_OF_BYTES |
---|
944 | Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
945 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
---|
946 | Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
947 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3); |
---|
948 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
949 | { |
---|
950 | if (m_pcEncCfg->getCostMode()==COST_MIXED_LOSSLESS_LOSSY_CODING) |
---|
951 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost() + (1.0 / m_pcRdCost->getLambda()); |
---|
952 | else |
---|
953 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
---|
954 | } |
---|
955 | |
---|
956 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTempDebug) DEBUG_STRING_PASS_INTO(false) ); // RD compare current larger prediction |
---|
957 | // with sub partitioned prediction. |
---|
958 | } |
---|
959 | } |
---|
960 | |
---|
961 | DEBUG_STRING_APPEND(sDebug_, sDebug); |
---|
962 | |
---|
963 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
964 | |
---|
965 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
---|
966 | if (bBoundary) |
---|
967 | { |
---|
968 | return; |
---|
969 | } |
---|
970 | |
---|
971 | // Assert if Best prediction mode is NONE |
---|
972 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
973 | assert( rpcBestCU->getPartitionSize ( 0 ) != NUMBER_OF_PART_SIZES ); |
---|
974 | assert( rpcBestCU->getPredictionMode( 0 ) != NUMBER_OF_PREDICTION_MODES ); |
---|
975 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
976 | } |
---|
977 | |
---|
978 | /** finish encoding a cu and handle end-of-slice conditions |
---|
979 | * \param pcCU |
---|
980 | * \param uiAbsPartIdx |
---|
981 | * \param uiDepth |
---|
982 | * \returns Void |
---|
983 | */ |
---|
984 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
985 | { |
---|
986 | TComPic* pcPic = pcCU->getPic(); |
---|
987 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
988 | |
---|
989 | //Calculate end address |
---|
990 | const Int currentCTUTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pcCU->getCtuRsAddr()); |
---|
991 | const Bool isLastSubCUOfCtu = pcCU->isLastSubCUOfCtu(uiAbsPartIdx); |
---|
992 | if ( isLastSubCUOfCtu ) |
---|
993 | { |
---|
994 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
995 | // i.e. when the slice segment CurEnd CTU address is the current CTU address+1. |
---|
996 | if (pcSlice->getSliceSegmentCurEndCtuTsAddr() != currentCTUTsAddr+1) |
---|
997 | { |
---|
998 | m_pcEntropyCoder->encodeTerminatingBit( 0 ); |
---|
999 | } |
---|
1000 | } |
---|
1001 | } |
---|
1002 | |
---|
1003 | /** Compute QP for each CU |
---|
1004 | * \param pcCU Target CU |
---|
1005 | * \param uiDepth CU depth |
---|
1006 | * \returns quantization parameter |
---|
1007 | */ |
---|
1008 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
1009 | { |
---|
1010 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
1011 | Int iQpOffset = 0; |
---|
1012 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
1013 | { |
---|
1014 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
1015 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
1016 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
1017 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
1018 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
1019 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
1020 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
1021 | |
---|
1022 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
1023 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
1024 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
1025 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
1026 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
1027 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
1028 | } |
---|
1029 | #if REPN_FORMAT_IN_VPS |
---|
1030 | return Clip3(-pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
1031 | #else |
---|
1032 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQp+iQpOffset ); |
---|
1033 | #endif |
---|
1034 | } |
---|
1035 | |
---|
1036 | /** encode a CU block recursively |
---|
1037 | * \param pcCU |
---|
1038 | * \param uiAbsPartIdx |
---|
1039 | * \param uiDepth |
---|
1040 | * \returns Void |
---|
1041 | */ |
---|
1042 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1043 | { |
---|
1044 | TComPic* pcPic = pcCU->getPic(); |
---|
1045 | |
---|
1046 | Bool bBoundary = false; |
---|
1047 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1048 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
1049 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1050 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
1051 | |
---|
1052 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1053 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
1054 | if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange()) |
---|
1055 | { |
---|
1056 | pcCU->setSkipFlagSubParts(true, uiAbsPartIdx, uiDepth); |
---|
1057 | } |
---|
1058 | #endif |
---|
1059 | |
---|
1060 | #if REPN_FORMAT_IN_VPS |
---|
1061 | if( ( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
1062 | #else |
---|
1063 | if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1064 | #endif |
---|
1065 | { |
---|
1066 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1067 | } |
---|
1068 | else |
---|
1069 | { |
---|
1070 | bBoundary = true; |
---|
1071 | } |
---|
1072 | |
---|
1073 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
1074 | { |
---|
1075 | UInt uiQNumParts = ( pcPic->getNumPartitionsInCtu() >> (uiDepth<<1) )>>2; |
---|
1076 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
1077 | { |
---|
1078 | setdQPFlag(true); |
---|
1079 | } |
---|
1080 | |
---|
1081 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuChromaQpAdjSize() && pcCU->getSlice()->getUseChromaQpAdj()) |
---|
1082 | { |
---|
1083 | setCodeChromaQpAdjFlag(true); |
---|
1084 | } |
---|
1085 | |
---|
1086 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1087 | { |
---|
1088 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1089 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1090 | #if REPN_FORMAT_IN_VPS |
---|
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) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
1103 | { |
---|
1104 | setdQPFlag(true); |
---|
1105 | } |
---|
1106 | |
---|
1107 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuChromaQpAdjSize() && 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 | * \returns Void |
---|
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 | rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth ); |
---|
1372 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
1373 | xCheckDQP( rpcTempCU ); |
---|
1374 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr)); |
---|
1375 | |
---|
1376 | rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); |
---|
1377 | |
---|
1378 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
1379 | { |
---|
1380 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
1381 | } |
---|
1382 | } |
---|
1383 | } |
---|
1384 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
1385 | } |
---|
1386 | #endif |
---|
1387 | #if REF_IDX_ME_ZEROMV |
---|
1388 | } |
---|
1389 | #endif |
---|
1390 | } |
---|
1391 | |
---|
1392 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
1393 | { |
---|
1394 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
1395 | { |
---|
1396 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
1397 | { |
---|
1398 | *earlyDetectionSkipMode = true; |
---|
1399 | } |
---|
1400 | else if(m_pcEncCfg->getFastSearch() != SELECTIVE) |
---|
1401 | { |
---|
1402 | Int absoulte_MV=0; |
---|
1403 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
1404 | { |
---|
1405 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
1406 | { |
---|
1407 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
1408 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
1409 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
1410 | absoulte_MV+=iHor+iVer; |
---|
1411 | } |
---|
1412 | } |
---|
1413 | |
---|
1414 | if(absoulte_MV == 0) |
---|
1415 | { |
---|
1416 | *earlyDetectionSkipMode = true; |
---|
1417 | } |
---|
1418 | } |
---|
1419 | } |
---|
1420 | } |
---|
1421 | } |
---|
1422 | DEBUG_STRING_APPEND(sDebug, bestStr) |
---|
1423 | } |
---|
1424 | |
---|
1425 | |
---|
1426 | #if AMP_MRG |
---|
1427 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG) |
---|
1428 | #else |
---|
1429 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
1430 | #endif |
---|
1431 | { |
---|
1432 | DEBUG_STRING_NEW(sTest) |
---|
1433 | |
---|
1434 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1435 | |
---|
1436 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
1437 | |
---|
1438 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
1439 | |
---|
1440 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
1441 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
1442 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_ChromaQpAdjIdc, 0, uhDepth ); |
---|
1443 | |
---|
1444 | #if SVC_EXTENSION |
---|
1445 | #if AMP_MRG |
---|
1446 | rpcTempCU->setMergeAMP (true); |
---|
1447 | 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 ); |
---|
1448 | #else |
---|
1449 | Bool ret = m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
1450 | #endif |
---|
1451 | |
---|
1452 | if( !ret ) |
---|
1453 | { |
---|
1454 | return; |
---|
1455 | } |
---|
1456 | #else |
---|
1457 | #if AMP_MRG |
---|
1458 | rpcTempCU->setMergeAMP (true); |
---|
1459 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG ); |
---|
1460 | #else |
---|
1461 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
1462 | #endif |
---|
1463 | #endif |
---|
1464 | |
---|
1465 | #if AMP_MRG |
---|
1466 | if ( !rpcTempCU->getMergeAMP() ) |
---|
1467 | { |
---|
1468 | return; |
---|
1469 | } |
---|
1470 | #endif |
---|
1471 | |
---|
1472 | 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) ); |
---|
1473 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1474 | |
---|
1475 | #ifdef DEBUG_STRING |
---|
1476 | DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
1477 | #endif |
---|
1478 | |
---|
1479 | xCheckDQP( rpcTempCU ); |
---|
1480 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
1481 | } |
---|
1482 | |
---|
1483 | Void TEncCu::xCheckRDCostIntra( TComDataCU *&rpcBestCU, |
---|
1484 | TComDataCU *&rpcTempCU, |
---|
1485 | Double &cost, |
---|
1486 | PartSize eSize |
---|
1487 | DEBUG_STRING_FN_DECLARE(sDebug) ) |
---|
1488 | { |
---|
1489 | DEBUG_STRING_NEW(sTest) |
---|
1490 | |
---|
1491 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
1492 | |
---|
1493 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
1494 | |
---|
1495 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
1496 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
1497 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_ChromaQpAdjIdc, 0, uiDepth ); |
---|
1498 | |
---|
1499 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
1500 | |
---|
1501 | Distortion uiPreCalcDistC = 0; |
---|
1502 | if (rpcBestCU->getPic()->getChromaFormat()==CHROMA_400) |
---|
1503 | { |
---|
1504 | bSeparateLumaChroma=true; |
---|
1505 | } |
---|
1506 | |
---|
1507 | Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]; |
---|
1508 | |
---|
1509 | if( !bSeparateLumaChroma ) |
---|
1510 | { |
---|
1511 | // after this function, the direction will be PLANAR, DC, HOR or VER |
---|
1512 | // however, if Luma ends up being one of those, the chroma dir must be later changed to DM_CHROMA. |
---|
1513 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
1514 | } |
---|
1515 | m_pcPredSearch->estIntraPredQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma, uiPreCalcDistC, bSeparateLumaChroma DEBUG_STRING_PASS_INTO(sTest) ); |
---|
1516 | |
---|
1517 | m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() ); |
---|
1518 | |
---|
1519 | if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400) |
---|
1520 | { |
---|
1521 | m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma, uiPreCalcDistC DEBUG_STRING_PASS_INTO(sTest) ); |
---|
1522 | } |
---|
1523 | |
---|
1524 | m_pcEntropyCoder->resetBits(); |
---|
1525 | |
---|
1526 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
1527 | { |
---|
1528 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
1529 | } |
---|
1530 | |
---|
1531 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
1532 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
1533 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
1534 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 ); |
---|
1535 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
1536 | |
---|
1537 | // Encode Coefficients |
---|
1538 | Bool bCodeDQP = getdQPFlag(); |
---|
1539 | Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag(); |
---|
1540 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag ); |
---|
1541 | setCodeChromaQpAdjFlag( codeChromaQpAdjFlag ); |
---|
1542 | setdQPFlag( bCodeDQP ); |
---|
1543 | |
---|
1544 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1545 | |
---|
1546 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1547 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1548 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1549 | |
---|
1550 | xCheckDQP( rpcTempCU ); |
---|
1551 | |
---|
1552 | cost = rpcTempCU->getTotalCost(); |
---|
1553 | |
---|
1554 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
1555 | } |
---|
1556 | |
---|
1557 | |
---|
1558 | /** Check R-D costs for a CU with PCM mode. |
---|
1559 | * \param rpcBestCU pointer to best mode CU data structure |
---|
1560 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
1561 | * \returns Void |
---|
1562 | * |
---|
1563 | * \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. |
---|
1564 | */ |
---|
1565 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1566 | { |
---|
1567 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
1568 | |
---|
1569 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
1570 | |
---|
1571 | rpcTempCU->setIPCMFlag(0, true); |
---|
1572 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
1573 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
1574 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
1575 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
1576 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_ChromaQpAdjIdc, 0, uiDepth ); |
---|
1577 | |
---|
1578 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
1579 | |
---|
1580 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
1581 | |
---|
1582 | m_pcEntropyCoder->resetBits(); |
---|
1583 | |
---|
1584 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
1585 | { |
---|
1586 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
1587 | } |
---|
1588 | |
---|
1589 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
1590 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
1591 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
1592 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
1593 | |
---|
1594 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1595 | |
---|
1596 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1597 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1598 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1599 | |
---|
1600 | xCheckDQP( rpcTempCU ); |
---|
1601 | DEBUG_STRING_NEW(a) |
---|
1602 | DEBUG_STRING_NEW(b) |
---|
1603 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(a) DEBUG_STRING_PASS_INTO(b)); |
---|
1604 | } |
---|
1605 | |
---|
1606 | /** check whether current try is the best with identifying the depth of current try |
---|
1607 | * \param rpcBestCU |
---|
1608 | * \param rpcTempCU |
---|
1609 | * \returns Void |
---|
1610 | */ |
---|
1611 | 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) ) |
---|
1612 | { |
---|
1613 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
1614 | { |
---|
1615 | TComYuv* pcYuv; |
---|
1616 | // Change Information data |
---|
1617 | TComDataCU* pcCU = rpcBestCU; |
---|
1618 | rpcBestCU = rpcTempCU; |
---|
1619 | rpcTempCU = pcCU; |
---|
1620 | |
---|
1621 | // Change Prediction data |
---|
1622 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
1623 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
1624 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
1625 | |
---|
1626 | // Change Reconstruction data |
---|
1627 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
1628 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
1629 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
1630 | |
---|
1631 | pcYuv = NULL; |
---|
1632 | pcCU = NULL; |
---|
1633 | |
---|
1634 | // store temp best CI for next CU coding |
---|
1635 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
1636 | |
---|
1637 | |
---|
1638 | #ifdef DEBUG_STRING |
---|
1639 | DEBUG_STRING_SWAP(sParent, sTest) |
---|
1640 | const PredMode predMode=rpcBestCU->getPredictionMode(0); |
---|
1641 | if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo) |
---|
1642 | { |
---|
1643 | std::stringstream ss(stringstream::out); |
---|
1644 | ss <<"###: " << (predMode==MODE_INTRA?"Intra ":"Inter ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl; |
---|
1645 | sParent+=ss.str(); |
---|
1646 | } |
---|
1647 | #endif |
---|
1648 | } |
---|
1649 | } |
---|
1650 | |
---|
1651 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
1652 | { |
---|
1653 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
1654 | |
---|
1655 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
1656 | { |
---|
1657 | if ( pcCU->getQtRootCbf( 0) ) |
---|
1658 | { |
---|
1659 | #if !RDO_WITHOUT_DQP_BITS |
---|
1660 | m_pcEntropyCoder->resetBits(); |
---|
1661 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
1662 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
1663 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1664 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
1665 | #endif |
---|
1666 | } |
---|
1667 | else |
---|
1668 | { |
---|
1669 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
1670 | } |
---|
1671 | } |
---|
1672 | } |
---|
1673 | |
---|
1674 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
1675 | { |
---|
1676 | pDst->iN = pSrc->iN; |
---|
1677 | for (Int i = 0; i < pSrc->iN; i++) |
---|
1678 | { |
---|
1679 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
1680 | } |
---|
1681 | } |
---|
1682 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
---|
1683 | { |
---|
1684 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
1685 | UInt uiSrcBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiSrcDepth); |
---|
1686 | UInt uiBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiDepth); |
---|
1687 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
1688 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
1689 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
1690 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
1691 | |
---|
1692 | m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
1693 | } |
---|
1694 | |
---|
1695 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
1696 | { |
---|
1697 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
1698 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
1699 | m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx); |
---|
1700 | } |
---|
1701 | |
---|
1702 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
1703 | * \param pcCU pointer to current CU |
---|
1704 | * \param pcOrgYuv pointer to original sample array |
---|
1705 | * \returns Void |
---|
1706 | */ |
---|
1707 | Void TEncCu::xFillPCMBuffer ( TComDataCU* pCU, TComYuv* pOrgYuv ) |
---|
1708 | { |
---|
1709 | const ChromaFormat format = pCU->getPic()->getChromaFormat(); |
---|
1710 | const UInt numberValidComponents = getNumberValidComponents(format); |
---|
1711 | for (UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++) |
---|
1712 | { |
---|
1713 | const ComponentID component = ComponentID(componentIndex); |
---|
1714 | |
---|
1715 | const UInt width = pCU->getWidth(0) >> getComponentScaleX(component, format); |
---|
1716 | const UInt height = pCU->getHeight(0) >> getComponentScaleY(component, format); |
---|
1717 | |
---|
1718 | Pel *source = pOrgYuv->getAddr(component, 0, width); |
---|
1719 | Pel *destination = pCU->getPCMSample(component); |
---|
1720 | |
---|
1721 | const UInt sourceStride = pOrgYuv->getStride(component); |
---|
1722 | |
---|
1723 | for (Int line = 0; line < height; line++) |
---|
1724 | { |
---|
1725 | for (Int column = 0; column < width; column++) |
---|
1726 | { |
---|
1727 | destination[column] = source[column]; |
---|
1728 | } |
---|
1729 | |
---|
1730 | source += sourceStride; |
---|
1731 | destination += width; |
---|
1732 | } |
---|
1733 | } |
---|
1734 | } |
---|
1735 | |
---|
1736 | #if ADAPTIVE_QP_SELECTION |
---|
1737 | /** Collect ARL statistics from one block |
---|
1738 | */ |
---|
1739 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
1740 | { |
---|
1741 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
1742 | { |
---|
1743 | TCoeff u = abs( rpcCoeff[ n ] ); |
---|
1744 | TCoeff absc = rpcArlCoeff[ n ]; |
---|
1745 | |
---|
1746 | if( u != 0 ) |
---|
1747 | { |
---|
1748 | if( u < LEVEL_RANGE ) |
---|
1749 | { |
---|
1750 | cSum[ u ] += ( Double )absc; |
---|
1751 | numSamples[ u ]++; |
---|
1752 | } |
---|
1753 | else |
---|
1754 | { |
---|
1755 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
1756 | numSamples[ LEVEL_RANGE ]++; |
---|
1757 | } |
---|
1758 | } |
---|
1759 | } |
---|
1760 | |
---|
1761 | return 0; |
---|
1762 | } |
---|
1763 | |
---|
1764 | /** Collect ARL statistics from one CTU |
---|
1765 | * \param pcCU |
---|
1766 | */ |
---|
1767 | Void TEncCu::xCtuCollectARLStats(TComDataCU* pCtu ) |
---|
1768 | { |
---|
1769 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
---|
1770 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
---|
1771 | |
---|
1772 | TCoeff* pCoeffY = pCtu->getCoeff(COMPONENT_Y); |
---|
1773 | TCoeff* pArlCoeffY = pCtu->getArlCoeff(COMPONENT_Y); |
---|
1774 | |
---|
1775 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
1776 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
---|
1777 | |
---|
1778 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
1779 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
1780 | |
---|
1781 | // Collect stats to cSum[][] and numSamples[][] |
---|
1782 | for(Int i = 0; i < pCtu->getTotalNumPart(); i ++ ) |
---|
1783 | { |
---|
1784 | UInt uiTrIdx = pCtu->getTransformIdx(i); |
---|
1785 | |
---|
1786 | if(pCtu->isInter(i) && pCtu->getCbf( i, COMPONENT_Y, uiTrIdx ) ) |
---|
1787 | { |
---|
1788 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
1789 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
1790 | |
---|
1791 | pCoeffY += uiMinNumCoeffInCU; |
---|
1792 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
1793 | } |
---|
1794 | |
---|
1795 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
1796 | { |
---|
1797 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
1798 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
1799 | } |
---|
1800 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
1801 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
1802 | } |
---|
1803 | #endif |
---|
1804 | |
---|
1805 | #if SVC_EXTENSION |
---|
1806 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
1807 | Bool TEncCu::xCheckTileSetConstraint( TComDataCU*& rpcCU ) |
---|
1808 | { |
---|
1809 | Bool disableILP = false; |
---|
1810 | |
---|
1811 | if (rpcCU->getLayerId() == (m_pcEncCfg->getNumLayer() - 1) && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getCtuRsAddr()) >= 0) |
---|
1812 | { |
---|
1813 | if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getCtuRsAddr()) == 2) |
---|
1814 | { |
---|
1815 | disableILP = true; |
---|
1816 | } |
---|
1817 | if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getCtuRsAddr()) == 1) |
---|
1818 | { |
---|
1819 | Int currCUaddr = rpcCU->getCtuRsAddr(); |
---|
1820 | Int frameWitdhInCU = rpcCU->getPic()->getPicSym()->getFrameWidthInCtus(); |
---|
1821 | Int frameHeightInCU = rpcCU->getPic()->getPicSym()->getFrameHeightInCtus(); |
---|
1822 | Bool leftCUExists = (currCUaddr % frameWitdhInCU) > 0; |
---|
1823 | Bool aboveCUExists = (currCUaddr / frameWitdhInCU) > 0; |
---|
1824 | Bool rightCUExists = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1); |
---|
1825 | Bool belowCUExists = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1); |
---|
1826 | Int currTileSetIdx = rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr); |
---|
1827 | // Check if CU is at tile set boundary |
---|
1828 | if ( (leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-1) != currTileSetIdx) || |
---|
1829 | (leftCUExists && aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) || |
---|
1830 | (aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) || |
---|
1831 | (aboveCUExists && rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) || |
---|
1832 | (rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+1) != currTileSetIdx) || |
---|
1833 | (rightCUExists && belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) || |
---|
1834 | (belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) || |
---|
1835 | (belowCUExists && leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) ) |
---|
1836 | { |
---|
1837 | disableILP = true; // Disable ILP in tile set boundary CU |
---|
1838 | } |
---|
1839 | } |
---|
1840 | } |
---|
1841 | |
---|
1842 | return disableILP; |
---|
1843 | } |
---|
1844 | |
---|
1845 | Void TEncCu::xVerifyTileSetConstraint( TComDataCU*& rpcCU ) |
---|
1846 | { |
---|
1847 | if (rpcCU->getLayerId() == (m_pcEncCfg->getNumLayer() - 1) && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getCtuRsAddr()) >= 0 && |
---|
1848 | m_disableILP) |
---|
1849 | { |
---|
1850 | UInt numPartitions = rpcCU->getPic()->getNumPartitionsInCtu(); |
---|
1851 | for (UInt i = 0; i < numPartitions; i++) |
---|
1852 | { |
---|
1853 | if (!rpcCU->isIntra(i)) |
---|
1854 | { |
---|
1855 | for (UInt refList = 0; refList < 2; refList++) |
---|
1856 | { |
---|
1857 | if (rpcCU->getInterDir(i) & (1<<refList)) |
---|
1858 | { |
---|
1859 | TComCUMvField *mvField = rpcCU->getCUMvField(RefPicList(refList)); |
---|
1860 | if (mvField->getRefIdx(i) >= 0) |
---|
1861 | { |
---|
1862 | assert(!(rpcCU->getSlice()->getRefPic(RefPicList(refList), mvField->getRefIdx(i))->isILR(rpcCU->getLayerId()))); |
---|
1863 | } |
---|
1864 | } |
---|
1865 | } |
---|
1866 | } |
---|
1867 | } |
---|
1868 | } |
---|
1869 | } |
---|
1870 | #endif |
---|
1871 | |
---|
1872 | #if ENCODER_FAST_MODE |
---|
1873 | Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt refLayerId) |
---|
1874 | { |
---|
1875 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1876 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
1877 | #if SKIP_FLAG |
---|
1878 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
1879 | #endif |
---|
1880 | rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); //2Nx2N |
---|
1881 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
1882 | rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagForceValue(), 0, uhDepth ); |
---|
1883 | Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], refLayerId ); |
---|
1884 | if(!exitILR) |
---|
1885 | { |
---|
1886 | return; |
---|
1887 | } |
---|
1888 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
1889 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1890 | xCheckDQP( rpcTempCU ); |
---|
1891 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
1892 | return; |
---|
1893 | } |
---|
1894 | #endif |
---|
1895 | #endif //SVC_EXTENSION |
---|
1896 | //! \} |
---|