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