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