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