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