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