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 | #if H_3D_ARP |
---|
68 | m_ppcWeightedTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
69 | #endif |
---|
70 | |
---|
71 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
72 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
73 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
74 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
75 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
76 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
77 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
78 | |
---|
79 | UInt uiNumPartitions; |
---|
80 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
81 | { |
---|
82 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
83 | UInt uiWidth = uiMaxWidth >> i; |
---|
84 | UInt uiHeight = uiMaxHeight >> i; |
---|
85 | |
---|
86 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
87 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
88 | |
---|
89 | #if H_3D_ARP |
---|
90 | m_ppcWeightedTempCU[i] = new TComDataCU; m_ppcWeightedTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
91 | #endif |
---|
92 | |
---|
93 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight); |
---|
94 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight); |
---|
95 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight); |
---|
96 | |
---|
97 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight); |
---|
98 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight); |
---|
99 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight); |
---|
100 | |
---|
101 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight); |
---|
102 | } |
---|
103 | |
---|
104 | m_bEncodeDQP = false; |
---|
105 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
106 | m_LCUPredictionSAD = 0; |
---|
107 | m_addSADDepth = 0; |
---|
108 | m_temporalSAD = 0; |
---|
109 | #endif |
---|
110 | |
---|
111 | // initialize partition order. |
---|
112 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
113 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
114 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
115 | |
---|
116 | // initialize conversion matrix from partition index to pel |
---|
117 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
118 | } |
---|
119 | |
---|
120 | Void TEncCu::destroy() |
---|
121 | { |
---|
122 | Int i; |
---|
123 | |
---|
124 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
125 | { |
---|
126 | if(m_ppcBestCU[i]) |
---|
127 | { |
---|
128 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
129 | } |
---|
130 | if(m_ppcTempCU[i]) |
---|
131 | { |
---|
132 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
133 | } |
---|
134 | #if H_3D_ARP |
---|
135 | if(m_ppcWeightedTempCU[i]) |
---|
136 | { |
---|
137 | m_ppcWeightedTempCU[i]->destroy(); delete m_ppcWeightedTempCU[i]; m_ppcWeightedTempCU[i] = NULL; |
---|
138 | } |
---|
139 | #endif |
---|
140 | if(m_ppcPredYuvBest[i]) |
---|
141 | { |
---|
142 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
143 | } |
---|
144 | if(m_ppcResiYuvBest[i]) |
---|
145 | { |
---|
146 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
147 | } |
---|
148 | if(m_ppcRecoYuvBest[i]) |
---|
149 | { |
---|
150 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
151 | } |
---|
152 | if(m_ppcPredYuvTemp[i]) |
---|
153 | { |
---|
154 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
155 | } |
---|
156 | if(m_ppcResiYuvTemp[i]) |
---|
157 | { |
---|
158 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
159 | } |
---|
160 | if(m_ppcRecoYuvTemp[i]) |
---|
161 | { |
---|
162 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
163 | } |
---|
164 | if(m_ppcOrigYuv[i]) |
---|
165 | { |
---|
166 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
167 | } |
---|
168 | } |
---|
169 | if(m_ppcBestCU) |
---|
170 | { |
---|
171 | delete [] m_ppcBestCU; |
---|
172 | m_ppcBestCU = NULL; |
---|
173 | } |
---|
174 | if(m_ppcTempCU) |
---|
175 | { |
---|
176 | delete [] m_ppcTempCU; |
---|
177 | m_ppcTempCU = NULL; |
---|
178 | } |
---|
179 | |
---|
180 | #if H_3D_ARP |
---|
181 | if(m_ppcWeightedTempCU) |
---|
182 | { |
---|
183 | delete [] m_ppcWeightedTempCU; |
---|
184 | m_ppcWeightedTempCU = NULL; |
---|
185 | } |
---|
186 | #endif |
---|
187 | if(m_ppcPredYuvBest) |
---|
188 | { |
---|
189 | delete [] m_ppcPredYuvBest; |
---|
190 | m_ppcPredYuvBest = NULL; |
---|
191 | } |
---|
192 | if(m_ppcResiYuvBest) |
---|
193 | { |
---|
194 | delete [] m_ppcResiYuvBest; |
---|
195 | m_ppcResiYuvBest = NULL; |
---|
196 | } |
---|
197 | if(m_ppcRecoYuvBest) |
---|
198 | { |
---|
199 | delete [] m_ppcRecoYuvBest; |
---|
200 | m_ppcRecoYuvBest = NULL; |
---|
201 | } |
---|
202 | if(m_ppcPredYuvTemp) |
---|
203 | { |
---|
204 | delete [] m_ppcPredYuvTemp; |
---|
205 | m_ppcPredYuvTemp = NULL; |
---|
206 | } |
---|
207 | if(m_ppcResiYuvTemp) |
---|
208 | { |
---|
209 | delete [] m_ppcResiYuvTemp; |
---|
210 | m_ppcResiYuvTemp = NULL; |
---|
211 | } |
---|
212 | if(m_ppcRecoYuvTemp) |
---|
213 | { |
---|
214 | delete [] m_ppcRecoYuvTemp; |
---|
215 | m_ppcRecoYuvTemp = NULL; |
---|
216 | } |
---|
217 | if(m_ppcOrigYuv) |
---|
218 | { |
---|
219 | delete [] m_ppcOrigYuv; |
---|
220 | m_ppcOrigYuv = NULL; |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | /** \param pcEncTop pointer of encoder class |
---|
225 | */ |
---|
226 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
227 | { |
---|
228 | m_pcEncCfg = pcEncTop; |
---|
229 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
230 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
231 | m_pcBitCounter = pcEncTop->getBitCounter(); |
---|
232 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
233 | |
---|
234 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
235 | m_pcCavlcCoder = pcEncTop->getCavlcCoder(); |
---|
236 | m_pcSbacCoder = pcEncTop->getSbacCoder(); |
---|
237 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
238 | |
---|
239 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
240 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
241 | |
---|
242 | m_bUseSBACRD = pcEncTop->getUseSBACRD(); |
---|
243 | m_pcRateCtrl = pcEncTop->getRateCtrl(); |
---|
244 | } |
---|
245 | |
---|
246 | // ==================================================================================================================== |
---|
247 | // Public member functions |
---|
248 | // ==================================================================================================================== |
---|
249 | |
---|
250 | /** \param rpcCU pointer of CU data class |
---|
251 | */ |
---|
252 | Void TEncCu::compressCU( TComDataCU*& rpcCU ) |
---|
253 | { |
---|
254 | // initialize CU data |
---|
255 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
256 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
257 | |
---|
258 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
259 | m_addSADDepth = 0; |
---|
260 | m_LCUPredictionSAD = 0; |
---|
261 | m_temporalSAD = 0; |
---|
262 | #endif |
---|
263 | |
---|
264 | // analysis of CU |
---|
265 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
266 | |
---|
267 | #if ADAPTIVE_QP_SELECTION |
---|
268 | if( m_pcEncCfg->getUseAdaptQpSelect() ) |
---|
269 | { |
---|
270 | if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII |
---|
271 | { |
---|
272 | xLcuCollectARLStats( rpcCU); |
---|
273 | } |
---|
274 | } |
---|
275 | #endif |
---|
276 | } |
---|
277 | /** \param pcCU pointer of CU data class |
---|
278 | */ |
---|
279 | Void TEncCu::encodeCU ( TComDataCU* pcCU ) |
---|
280 | { |
---|
281 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
282 | { |
---|
283 | setdQPFlag(true); |
---|
284 | } |
---|
285 | |
---|
286 | // Encode CU data |
---|
287 | xEncodeCU( pcCU, 0, 0 ); |
---|
288 | } |
---|
289 | |
---|
290 | // ==================================================================================================================== |
---|
291 | // Protected member functions |
---|
292 | // ==================================================================================================================== |
---|
293 | /** Derive small set of test modes for AMP encoder speed-up |
---|
294 | *\param rpcBestCU |
---|
295 | *\param eParentPartSize |
---|
296 | *\param bTestAMP_Hor |
---|
297 | *\param bTestAMP_Ver |
---|
298 | *\param bTestMergeAMP_Hor |
---|
299 | *\param bTestMergeAMP_Ver |
---|
300 | *\returns Void |
---|
301 | */ |
---|
302 | #if AMP_ENC_SPEEDUP |
---|
303 | #if AMP_MRG |
---|
304 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver) |
---|
305 | #else |
---|
306 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver) |
---|
307 | #endif |
---|
308 | { |
---|
309 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
310 | { |
---|
311 | bTestAMP_Hor = true; |
---|
312 | } |
---|
313 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
314 | { |
---|
315 | bTestAMP_Ver = true; |
---|
316 | } |
---|
317 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false ) |
---|
318 | { |
---|
319 | bTestAMP_Hor = true; |
---|
320 | bTestAMP_Ver = true; |
---|
321 | } |
---|
322 | |
---|
323 | #if AMP_MRG |
---|
324 | //! Utilizing the partition size of parent PU |
---|
325 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
326 | { |
---|
327 | bTestMergeAMP_Hor = true; |
---|
328 | bTestMergeAMP_Ver = true; |
---|
329 | } |
---|
330 | |
---|
331 | if ( eParentPartSize == SIZE_NONE ) //! if parent is intra |
---|
332 | { |
---|
333 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
334 | { |
---|
335 | bTestMergeAMP_Hor = true; |
---|
336 | } |
---|
337 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
338 | { |
---|
339 | bTestMergeAMP_Ver = true; |
---|
340 | } |
---|
341 | } |
---|
342 | |
---|
343 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false ) |
---|
344 | { |
---|
345 | bTestMergeAMP_Hor = true; |
---|
346 | bTestMergeAMP_Ver = true; |
---|
347 | } |
---|
348 | |
---|
349 | if ( rpcBestCU->getWidth(0) == 64 ) |
---|
350 | { |
---|
351 | bTestAMP_Hor = false; |
---|
352 | bTestAMP_Ver = false; |
---|
353 | } |
---|
354 | #else |
---|
355 | //! Utilizing the partition size of parent PU |
---|
356 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
357 | { |
---|
358 | bTestAMP_Hor = true; |
---|
359 | bTestAMP_Ver = true; |
---|
360 | } |
---|
361 | |
---|
362 | if ( eParentPartSize == SIZE_2Nx2N ) |
---|
363 | { |
---|
364 | bTestAMP_Hor = false; |
---|
365 | bTestAMP_Ver = false; |
---|
366 | } |
---|
367 | #endif |
---|
368 | } |
---|
369 | #endif |
---|
370 | |
---|
371 | // ==================================================================================================================== |
---|
372 | // Protected member functions |
---|
373 | // ==================================================================================================================== |
---|
374 | /** Compress a CU block recursively with enabling sub-LCU-level delta QP |
---|
375 | *\param rpcBestCU |
---|
376 | *\param rpcTempCU |
---|
377 | *\param uiDepth |
---|
378 | *\returns Void |
---|
379 | * |
---|
380 | *- for loop of QP value to compress the current CU with all possible QP |
---|
381 | */ |
---|
382 | #if AMP_ENC_SPEEDUP |
---|
383 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize ) |
---|
384 | #else |
---|
385 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
386 | #endif |
---|
387 | { |
---|
388 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
389 | |
---|
390 | #if H_3D_QTLPC |
---|
391 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
---|
392 | TComPic *pcTexture = rpcBestCU->getSlice()->getTexturePic(); |
---|
393 | |
---|
394 | Bool depthMapDetect = (pcTexture != NULL); |
---|
395 | Bool bIntraSliceDetect = (rpcBestCU->getSlice()->getSliceType() == I_SLICE); |
---|
396 | |
---|
397 | Bool rapPic = (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
398 | |
---|
399 | Bool bTry2NxN = true; |
---|
400 | Bool bTryNx2N = true; |
---|
401 | #endif |
---|
402 | // get Original YUV data from picture |
---|
403 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
404 | |
---|
405 | // variables for fast encoder decision |
---|
406 | Bool bEarlySkip = false; |
---|
407 | Bool bTrySplit = true; |
---|
408 | Double fRD_Skip = MAX_DOUBLE; |
---|
409 | |
---|
410 | // variable for Early CU determination |
---|
411 | Bool bSubBranch = true; |
---|
412 | |
---|
413 | // variable for Cbf fast mode PU decision |
---|
414 | Bool doNotBlockPu = true; |
---|
415 | Bool earlyDetectionSkipMode = false; |
---|
416 | |
---|
417 | Bool bTrySplitDQP = true; |
---|
418 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
419 | DisInfo DvInfo; |
---|
420 | DvInfo.bDV = false; |
---|
421 | DvInfo.m_acNBDV.setZero(); |
---|
422 | DvInfo.m_aVIdxCan = 0; |
---|
423 | #if H_3D_NBDV_REF |
---|
424 | DvInfo.m_acDoNBDV.setZero(); |
---|
425 | #endif |
---|
426 | #endif |
---|
427 | static Double afCost[ MAX_CU_DEPTH ]; |
---|
428 | static Int aiNum [ MAX_CU_DEPTH ]; |
---|
429 | |
---|
430 | if ( rpcBestCU->getAddr() == 0 ) |
---|
431 | { |
---|
432 | ::memset( afCost, 0, sizeof( afCost ) ); |
---|
433 | ::memset( aiNum, 0, sizeof( aiNum ) ); |
---|
434 | } |
---|
435 | |
---|
436 | Bool bBoundary = false; |
---|
437 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
438 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
439 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
440 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
441 | |
---|
442 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
---|
443 | Int iMinQP; |
---|
444 | Int iMaxQP; |
---|
445 | Bool isAddLowestQP = false; |
---|
446 | Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
447 | |
---|
448 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
449 | { |
---|
450 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
451 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
452 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
453 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
454 | { |
---|
455 | isAddLowestQP = true; |
---|
456 | iMinQP = iMinQP - 1; |
---|
457 | } |
---|
458 | } |
---|
459 | else |
---|
460 | { |
---|
461 | iMinQP = rpcTempCU->getQP(0); |
---|
462 | iMaxQP = rpcTempCU->getQP(0); |
---|
463 | } |
---|
464 | |
---|
465 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
466 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
467 | { |
---|
468 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
469 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
470 | } |
---|
471 | #else |
---|
472 | if(m_pcEncCfg->getUseRateCtrl()) |
---|
473 | { |
---|
474 | Int qp = m_pcRateCtrl->getUnitQP(); |
---|
475 | iMinQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
476 | iMaxQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
477 | } |
---|
478 | #endif |
---|
479 | #if H_3D_IC |
---|
480 | Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE ); |
---|
481 | bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC(); |
---|
482 | #endif |
---|
483 | // If slice start or slice end is within this cu... |
---|
484 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
485 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart(); |
---|
486 | Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart()); |
---|
487 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
488 | // We need to split, so don't try these modes. |
---|
489 | if(!bSliceEnd && !bSliceStart && bInsidePicture ) |
---|
490 | { |
---|
491 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
492 | Bool bIVFMerge = false; |
---|
493 | Int iIVFMaxD = 0; |
---|
494 | Bool bFMD = false; |
---|
495 | #endif |
---|
496 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
497 | { |
---|
498 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
499 | { |
---|
500 | iQP = lowestQP; |
---|
501 | } |
---|
502 | // variables for fast encoder decision |
---|
503 | bEarlySkip = false; |
---|
504 | bTrySplit = true; |
---|
505 | fRD_Skip = MAX_DOUBLE; |
---|
506 | |
---|
507 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
508 | #if H_3D_QTLPC |
---|
509 | //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU |
---|
510 | |
---|
511 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL()) |
---|
512 | { |
---|
513 | TComDataCU* pcTextureCU = pcTexture->getCU( rpcBestCU->getAddr() ); //Corresponding texture LCU |
---|
514 | UInt uiCUIdx = rpcBestCU->getZorderIdxInCU(); |
---|
515 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); //Depth cannot be more partitionned than the texture. |
---|
516 | if (pcTextureCU->getDepth(uiCUIdx) > uiDepth || pcTextureCU->getPartitionSize(uiCUIdx) == SIZE_NxN) //Texture was split. |
---|
517 | { |
---|
518 | bTrySplit = true; |
---|
519 | bTryNx2N = true; |
---|
520 | bTry2NxN = true; |
---|
521 | } |
---|
522 | else |
---|
523 | { |
---|
524 | bTrySplit = false; |
---|
525 | bTryNx2N = false; |
---|
526 | bTry2NxN = false; |
---|
527 | } |
---|
528 | } |
---|
529 | #endif |
---|
530 | |
---|
531 | #if H_3D_NBDV |
---|
532 | #if !MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
533 | DisInfo DvInfo; |
---|
534 | DvInfo.bDV = false; |
---|
535 | DvInfo.m_acNBDV.setZero(); |
---|
536 | DvInfo.m_aVIdxCan = 0; |
---|
537 | #if H_3D_NBDV_REF |
---|
538 | DvInfo.m_acDoNBDV.setZero(); |
---|
539 | #endif |
---|
540 | #endif |
---|
541 | if( rpcTempCU->getSlice()->getSliceType() != I_SLICE ) |
---|
542 | { |
---|
543 | #if H_3D_ARP && H_3D_IV_MERGE |
---|
544 | if( rpcTempCU->getSlice()->getVPS()->getUseAdvRP(rpcTempCU->getSlice()->getLayerId()) || rpcTempCU->getSlice()->getVPS()->getIvMvPredFlag(rpcTempCU->getSlice()->getLayerId()) ) |
---|
545 | #else |
---|
546 | #if H_3D_ARP |
---|
547 | if( rpcTempCU->getSlice()->getVPS()->getUseAdvRP(rpcTempCU->getSlice()->getLayerId()) ) |
---|
548 | #else |
---|
549 | #if H_3D_IV_MERGE |
---|
550 | if( rpcTempCU->getSlice()->getVPS()->getIvMvPredFlag(rpcTempCU->getSlice()->getLayerId()) ) |
---|
551 | #else |
---|
552 | if (0) |
---|
553 | #endif |
---|
554 | #endif |
---|
555 | #endif |
---|
556 | { |
---|
557 | PartSize ePartTemp = rpcTempCU->getPartitionSize(0); |
---|
558 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
559 | #if H_3D_NBDV_REF |
---|
560 | if(rpcTempCU->getSlice()->getVPS()->getDepthRefinementFlag( rpcTempCU->getSlice()->getLayerIdInVps())) |
---|
561 | DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo, true); |
---|
562 | else |
---|
563 | #endif |
---|
564 | DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo); |
---|
565 | |
---|
566 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
567 | rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
568 | rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth ); |
---|
569 | } |
---|
570 | } |
---|
571 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
572 | if(rpcTempCU->getSlice()->getViewIndex() && !rpcTempCU->getSlice()->getIsDepth()) |
---|
573 | { |
---|
574 | PartSize ePartTemp = rpcTempCU->getPartitionSize(0); |
---|
575 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
576 | rpcTempCU->getIVNStatus( 0, &DvInfo, bIVFMerge, iIVFMaxD); |
---|
577 | rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth ); |
---|
578 | } |
---|
579 | #endif |
---|
580 | #endif |
---|
581 | // do inter modes, SKIP and 2Nx2N |
---|
582 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
583 | { |
---|
584 | #if H_3D_IC |
---|
585 | for( UInt uiICId = 0; uiICId < ( bICEnabled ? 2 : 1 ); uiICId++ ) |
---|
586 | { |
---|
587 | Bool bICFlag = uiICId ? true : false; |
---|
588 | #endif |
---|
589 | // 2Nx2N |
---|
590 | if(m_pcEncCfg->getUseEarlySkipDetection()) |
---|
591 | { |
---|
592 | #if H_3D_IC |
---|
593 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
594 | #endif |
---|
595 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
596 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N |
---|
597 | #else |
---|
598 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N |
---|
599 | #endif |
---|
600 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
601 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
602 | #endif |
---|
603 | } |
---|
604 | // SKIP |
---|
605 | #if H_3D_IC |
---|
606 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
607 | #endif |
---|
608 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N |
---|
609 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
610 | bFMD = bIVFMerge && rpcBestCU->isSkipped(0); |
---|
611 | #endif |
---|
612 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
613 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
614 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
615 | #endif |
---|
616 | // fast encoder decision for early skip |
---|
617 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
618 | { |
---|
619 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
620 | if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] ) |
---|
621 | { |
---|
622 | bEarlySkip = true; |
---|
623 | bTrySplit = false; |
---|
624 | } |
---|
625 | } |
---|
626 | |
---|
627 | if(!m_pcEncCfg->getUseEarlySkipDetection()) |
---|
628 | { |
---|
629 | // 2Nx2N, NxN |
---|
630 | if ( !bEarlySkip ) |
---|
631 | { |
---|
632 | #if H_3D_IC |
---|
633 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
634 | #endif |
---|
635 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
636 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP ); |
---|
637 | #else |
---|
638 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP ); |
---|
639 | #endif |
---|
640 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
641 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
642 | #endif |
---|
643 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
644 | { |
---|
645 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
646 | } |
---|
647 | } |
---|
648 | } |
---|
649 | #if H_3D_IC |
---|
650 | } |
---|
651 | #endif |
---|
652 | } |
---|
653 | |
---|
654 | #if H_3D_QTLPC |
---|
655 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL()) |
---|
656 | { |
---|
657 | bTrySplitDQP = bTrySplit; |
---|
658 | } |
---|
659 | else |
---|
660 | { |
---|
661 | #endif |
---|
662 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
663 | { |
---|
664 | if(iQP == iBaseQP) |
---|
665 | { |
---|
666 | bTrySplitDQP = bTrySplit; |
---|
667 | } |
---|
668 | } |
---|
669 | else |
---|
670 | { |
---|
671 | bTrySplitDQP = bTrySplit; |
---|
672 | } |
---|
673 | #if H_3D_QTLPC |
---|
674 | } |
---|
675 | #endif |
---|
676 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
677 | { |
---|
678 | iQP = iMinQP; |
---|
679 | } |
---|
680 | } |
---|
681 | |
---|
682 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
683 | if ( uiDepth <= m_addSADDepth ) |
---|
684 | { |
---|
685 | m_LCUPredictionSAD += m_temporalSAD; |
---|
686 | m_addSADDepth = uiDepth; |
---|
687 | } |
---|
688 | #endif |
---|
689 | |
---|
690 | #if H_3D_DIM_ENC |
---|
691 | if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) |
---|
692 | { |
---|
693 | earlyDetectionSkipMode = false; |
---|
694 | } |
---|
695 | #endif |
---|
696 | |
---|
697 | if(!earlyDetectionSkipMode) |
---|
698 | { |
---|
699 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
700 | { |
---|
701 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
702 | { |
---|
703 | iQP = lowestQP; |
---|
704 | } |
---|
705 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
706 | |
---|
707 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
708 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
709 | { |
---|
710 | // 2Nx2N, NxN |
---|
711 | if ( !bEarlySkip ) |
---|
712 | { |
---|
713 | if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
714 | { |
---|
715 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu |
---|
716 | #if H_3D_QTLPC |
---|
717 | && bTrySplit |
---|
718 | #endif |
---|
719 | ) |
---|
720 | { |
---|
721 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
722 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFMD ); |
---|
723 | #else |
---|
724 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
725 | #endif |
---|
726 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
727 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
728 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
729 | #endif |
---|
730 | } |
---|
731 | } |
---|
732 | } |
---|
733 | |
---|
734 | // 2NxN, Nx2N |
---|
735 | if(doNotBlockPu |
---|
736 | #if H_3D_QTLPC |
---|
737 | && bTryNx2N |
---|
738 | #endif |
---|
739 | ) |
---|
740 | { |
---|
741 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
742 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFMD ); |
---|
743 | #else |
---|
744 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); |
---|
745 | #endif |
---|
746 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
747 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
748 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
749 | #endif |
---|
750 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
751 | { |
---|
752 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
753 | } |
---|
754 | } |
---|
755 | if(doNotBlockPu |
---|
756 | #if H_3D_QTLPC |
---|
757 | && bTry2NxN |
---|
758 | #endif |
---|
759 | ) |
---|
760 | { |
---|
761 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
762 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN, bFMD ); |
---|
763 | #else |
---|
764 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); |
---|
765 | #endif |
---|
766 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
767 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
768 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
769 | #endif |
---|
770 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
771 | { |
---|
772 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
773 | } |
---|
774 | } |
---|
775 | |
---|
776 | #if 1 |
---|
777 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
778 | if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) |
---|
779 | { |
---|
780 | #if AMP_ENC_SPEEDUP |
---|
781 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
782 | |
---|
783 | #if AMP_MRG |
---|
784 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
785 | |
---|
786 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
787 | #else |
---|
788 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
789 | #endif |
---|
790 | |
---|
791 | //! Do horizontal AMP |
---|
792 | if ( bTestAMP_Hor ) |
---|
793 | { |
---|
794 | if(doNotBlockPu |
---|
795 | #if H_3D_QTLPC |
---|
796 | && bTry2NxN |
---|
797 | #endif |
---|
798 | ) |
---|
799 | { |
---|
800 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
801 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD ); |
---|
802 | #else |
---|
803 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
804 | #endif |
---|
805 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
806 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
807 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
808 | #endif |
---|
809 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
810 | { |
---|
811 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
812 | } |
---|
813 | } |
---|
814 | if(doNotBlockPu |
---|
815 | #if H_3D_QTLPC |
---|
816 | && bTry2NxN |
---|
817 | #endif |
---|
818 | ) |
---|
819 | { |
---|
820 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
821 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD ); |
---|
822 | #else |
---|
823 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
824 | #endif |
---|
825 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
826 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
827 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
828 | #endif |
---|
829 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
830 | { |
---|
831 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
832 | } |
---|
833 | } |
---|
834 | } |
---|
835 | #if AMP_MRG |
---|
836 | else if ( bTestMergeAMP_Hor ) |
---|
837 | { |
---|
838 | if(doNotBlockPu |
---|
839 | #if H_3D_QTLPC |
---|
840 | && bTry2NxN |
---|
841 | #endif |
---|
842 | ) |
---|
843 | { |
---|
844 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
845 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD, true ); |
---|
846 | #else |
---|
847 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); |
---|
848 | #endif |
---|
849 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
850 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
851 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
852 | #endif |
---|
853 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
854 | { |
---|
855 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
856 | } |
---|
857 | } |
---|
858 | if(doNotBlockPu |
---|
859 | #if H_3D_QTLPC |
---|
860 | && bTry2NxN |
---|
861 | #endif |
---|
862 | ) |
---|
863 | { |
---|
864 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
865 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD, true ); |
---|
866 | #else |
---|
867 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); |
---|
868 | #endif |
---|
869 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
870 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
871 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
872 | #endif |
---|
873 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
874 | { |
---|
875 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
876 | } |
---|
877 | } |
---|
878 | } |
---|
879 | #endif |
---|
880 | |
---|
881 | //! Do horizontal AMP |
---|
882 | if ( bTestAMP_Ver ) |
---|
883 | { |
---|
884 | if(doNotBlockPu |
---|
885 | #if H_3D_QTLPC |
---|
886 | && bTryNx2N |
---|
887 | #endif |
---|
888 | ) |
---|
889 | { |
---|
890 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
891 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD ); |
---|
892 | #else |
---|
893 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
894 | #endif |
---|
895 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
896 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
897 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
898 | #endif |
---|
899 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
900 | { |
---|
901 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
902 | } |
---|
903 | } |
---|
904 | if(doNotBlockPu |
---|
905 | #if H_3D_QTLPC |
---|
906 | && bTryNx2N |
---|
907 | #endif |
---|
908 | ) |
---|
909 | { |
---|
910 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
911 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD ); |
---|
912 | #else |
---|
913 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
914 | #endif |
---|
915 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
916 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
917 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
918 | #endif |
---|
919 | } |
---|
920 | } |
---|
921 | #if AMP_MRG |
---|
922 | else if ( bTestMergeAMP_Ver ) |
---|
923 | { |
---|
924 | if(doNotBlockPu |
---|
925 | #if H_3D_QTLPC |
---|
926 | && bTryNx2N |
---|
927 | #endif |
---|
928 | ) |
---|
929 | { |
---|
930 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
931 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD, true ); |
---|
932 | #else |
---|
933 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); |
---|
934 | #endif |
---|
935 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
936 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
937 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
938 | #endif |
---|
939 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
940 | { |
---|
941 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
942 | } |
---|
943 | } |
---|
944 | if(doNotBlockPu |
---|
945 | #if H_3D_QTLPC |
---|
946 | && bTryNx2N |
---|
947 | #endif |
---|
948 | ) |
---|
949 | { |
---|
950 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
951 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD, true ); |
---|
952 | #else |
---|
953 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); |
---|
954 | #endif |
---|
955 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
956 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
957 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
958 | #endif |
---|
959 | } |
---|
960 | } |
---|
961 | #endif |
---|
962 | |
---|
963 | #else |
---|
964 | #if H_3D_QTLPC |
---|
965 | if (bTry2NxN) |
---|
966 | { |
---|
967 | #endif |
---|
968 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
969 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
970 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
971 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
972 | #endif |
---|
973 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
974 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
975 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
976 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
977 | #endif |
---|
978 | #if H_3D_QTLPC |
---|
979 | } |
---|
980 | if (bTryNx2N) |
---|
981 | { |
---|
982 | #endif |
---|
983 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
984 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
985 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
986 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
987 | #endif |
---|
988 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
989 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
990 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
991 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
992 | #endif |
---|
993 | #if H_3D_QTLPC |
---|
994 | } |
---|
995 | #endif |
---|
996 | |
---|
997 | #endif |
---|
998 | } |
---|
999 | #endif |
---|
1000 | } |
---|
1001 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
1002 | if(!bFMD) |
---|
1003 | { |
---|
1004 | #endif |
---|
1005 | // do normal intra modes |
---|
1006 | #if H_3D_DIM_ENC |
---|
1007 | if ( !bEarlySkip || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) ) |
---|
1008 | #else |
---|
1009 | if ( !bEarlySkip ) |
---|
1010 | #endif |
---|
1011 | { |
---|
1012 | // speedup for inter frames |
---|
1013 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
1014 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
1015 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
1016 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 |
---|
1017 | #if H_3D_DIM_ENC |
---|
1018 | || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) |
---|
1019 | #endif |
---|
1020 | ) // avoid very complex intra if it is unlikely |
---|
1021 | { |
---|
1022 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
1023 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1024 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1025 | { |
---|
1026 | #if H_3D_QTLPC //Try IntraNxN |
---|
1027 | if(bTrySplit) |
---|
1028 | { |
---|
1029 | #endif |
---|
1030 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
1031 | { |
---|
1032 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
1033 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1034 | } |
---|
1035 | #if H_3D_QTLPC |
---|
1036 | } |
---|
1037 | #endif |
---|
1038 | } |
---|
1039 | } |
---|
1040 | } |
---|
1041 | |
---|
1042 | // test PCM |
---|
1043 | if(pcPic->getSlice(0)->getSPS()->getUsePCM() |
---|
1044 | && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) |
---|
1045 | && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) |
---|
1046 | { |
---|
1047 | UInt uiRawBits = (2 * g_bitDepthY + g_bitDepthC) * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) / 2; |
---|
1048 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
1049 | #if H_3D_VSO // M7 |
---|
1050 | Double dRDCostTemp = m_pcRdCost->getUseVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0); |
---|
1051 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp )) |
---|
1052 | #else |
---|
1053 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
1054 | #endif |
---|
1055 | { |
---|
1056 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
1057 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1058 | } |
---|
1059 | } |
---|
1060 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
1061 | } |
---|
1062 | #endif |
---|
1063 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
1064 | { |
---|
1065 | iQP = iMinQP; |
---|
1066 | } |
---|
1067 | } |
---|
1068 | } |
---|
1069 | |
---|
1070 | m_pcEntropyCoder->resetBits(); |
---|
1071 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
1072 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1073 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1074 | { |
---|
1075 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1076 | } |
---|
1077 | |
---|
1078 | #if H_3D_VSO // M8 |
---|
1079 | if ( m_pcRdCost->getUseVSO() ) |
---|
1080 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
1081 | else |
---|
1082 | #endif |
---|
1083 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
1084 | |
---|
1085 | // accumulate statistics for early skip |
---|
1086 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
1087 | { |
---|
1088 | if ( rpcBestCU->isSkipped(0) ) |
---|
1089 | { |
---|
1090 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
1091 | afCost[ iIdx ] += rpcBestCU->getTotalCost(); |
---|
1092 | aiNum [ iIdx ] ++; |
---|
1093 | } |
---|
1094 | } |
---|
1095 | |
---|
1096 | // Early CU determination |
---|
1097 | if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) ) |
---|
1098 | { |
---|
1099 | bSubBranch = false; |
---|
1100 | } |
---|
1101 | else |
---|
1102 | { |
---|
1103 | bSubBranch = true; |
---|
1104 | } |
---|
1105 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
1106 | if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0)) |
---|
1107 | { |
---|
1108 | bSubBranch = false; |
---|
1109 | } |
---|
1110 | #endif |
---|
1111 | } |
---|
1112 | else if(!(bSliceEnd && bInsidePicture)) |
---|
1113 | { |
---|
1114 | bBoundary = true; |
---|
1115 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
1116 | m_addSADDepth++; |
---|
1117 | #endif |
---|
1118 | } |
---|
1119 | |
---|
1120 | // copy orginal YUV samples to PCM buffer |
---|
1121 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
1122 | { |
---|
1123 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
1124 | } |
---|
1125 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
1126 | { |
---|
1127 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
1128 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
1129 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
1130 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
1131 | { |
---|
1132 | isAddLowestQP = true; |
---|
1133 | iMinQP = iMinQP - 1; |
---|
1134 | } |
---|
1135 | } |
---|
1136 | else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
1137 | { |
---|
1138 | iMinQP = iBaseQP; |
---|
1139 | iMaxQP = iBaseQP; |
---|
1140 | } |
---|
1141 | else |
---|
1142 | { |
---|
1143 | Int iStartQP; |
---|
1144 | if( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
1145 | { |
---|
1146 | iStartQP = rpcTempCU->getQP(0); |
---|
1147 | } |
---|
1148 | else |
---|
1149 | { |
---|
1150 | UInt uiCurSliceStartPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
1151 | iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx); |
---|
1152 | } |
---|
1153 | iMinQP = iStartQP; |
---|
1154 | iMaxQP = iStartQP; |
---|
1155 | } |
---|
1156 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1157 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
1158 | { |
---|
1159 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
1160 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
1161 | } |
---|
1162 | #else |
---|
1163 | if(m_pcEncCfg->getUseRateCtrl()) |
---|
1164 | { |
---|
1165 | Int qp = m_pcRateCtrl->getUnitQP(); |
---|
1166 | iMinQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
1167 | iMaxQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
1168 | } |
---|
1169 | #endif |
---|
1170 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
1171 | { |
---|
1172 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
1173 | { |
---|
1174 | iQP = lowestQP; |
---|
1175 | } |
---|
1176 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1177 | |
---|
1178 | // further split |
---|
1179 | if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1180 | { |
---|
1181 | #if H_3D_VSO // M9 |
---|
1182 | // reset Model |
---|
1183 | if( m_pcRdCost->getUseRenModel() ) |
---|
1184 | { |
---|
1185 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( ); |
---|
1186 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight( ); |
---|
1187 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
---|
1188 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
1189 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1190 | } |
---|
1191 | #endif |
---|
1192 | |
---|
1193 | UChar uhNextDepth = uiDepth+1; |
---|
1194 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
1195 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
1196 | |
---|
1197 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
1198 | { |
---|
1199 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
1200 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
1201 | |
---|
1202 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
1203 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1204 | { |
---|
1205 | if( m_bUseSBACRD ) |
---|
1206 | { |
---|
1207 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
1208 | { |
---|
1209 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
1210 | } |
---|
1211 | else |
---|
1212 | { |
---|
1213 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
1214 | } |
---|
1215 | } |
---|
1216 | |
---|
1217 | #if AMP_ENC_SPEEDUP |
---|
1218 | if ( rpcBestCU->isIntra(0) ) |
---|
1219 | { |
---|
1220 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE ); |
---|
1221 | } |
---|
1222 | else |
---|
1223 | { |
---|
1224 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) ); |
---|
1225 | } |
---|
1226 | #else |
---|
1227 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
1228 | #endif |
---|
1229 | |
---|
1230 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
1231 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
1232 | } |
---|
1233 | else if (bInSlice) |
---|
1234 | { |
---|
1235 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
1236 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
1237 | } |
---|
1238 | } |
---|
1239 | |
---|
1240 | if( !bBoundary ) |
---|
1241 | { |
---|
1242 | m_pcEntropyCoder->resetBits(); |
---|
1243 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
1244 | |
---|
1245 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1246 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1247 | { |
---|
1248 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1249 | } |
---|
1250 | } |
---|
1251 | |
---|
1252 | #if H_3D_VSO // M10 |
---|
1253 | if ( m_pcRdCost->getUseVSO() ) |
---|
1254 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1255 | else |
---|
1256 | #endif |
---|
1257 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1258 | |
---|
1259 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
1260 | { |
---|
1261 | Bool hasResidual = false; |
---|
1262 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
1263 | { |
---|
1264 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) && |
---|
1265 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
1266 | { |
---|
1267 | hasResidual = true; |
---|
1268 | break; |
---|
1269 | } |
---|
1270 | } |
---|
1271 | |
---|
1272 | UInt uiTargetPartIdx; |
---|
1273 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getSliceSegmentCurStartCUAddr() ) |
---|
1274 | { |
---|
1275 | uiTargetPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
1276 | } |
---|
1277 | else |
---|
1278 | { |
---|
1279 | uiTargetPartIdx = 0; |
---|
1280 | } |
---|
1281 | if ( hasResidual ) |
---|
1282 | { |
---|
1283 | #if !RDO_WITHOUT_DQP_BITS |
---|
1284 | m_pcEntropyCoder->resetBits(); |
---|
1285 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
1286 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
1287 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1288 | { |
---|
1289 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1290 | } |
---|
1291 | #if H_3D_VSO // M11 |
---|
1292 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1293 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1294 | else |
---|
1295 | #endif |
---|
1296 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1297 | #endif |
---|
1298 | |
---|
1299 | Bool foundNonZeroCbf = false; |
---|
1300 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), rpcTempCU, 0, uiDepth, foundNonZeroCbf ); |
---|
1301 | assert( foundNonZeroCbf ); |
---|
1302 | } |
---|
1303 | else |
---|
1304 | { |
---|
1305 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
1306 | } |
---|
1307 | } |
---|
1308 | |
---|
1309 | if( m_bUseSBACRD ) |
---|
1310 | { |
---|
1311 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1312 | } |
---|
1313 | Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
1314 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
---|
1315 | Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
1316 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3); |
---|
1317 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
1318 | { |
---|
1319 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
---|
1320 | } |
---|
1321 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction |
---|
1322 | } // with sub partitioned prediction. |
---|
1323 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
1324 | { |
---|
1325 | iQP = iMinQP; |
---|
1326 | } |
---|
1327 | } |
---|
1328 | |
---|
1329 | |
---|
1330 | #if H_3D_VSO // M12 |
---|
1331 | if( m_pcRdCost->getUseRenModel() ) |
---|
1332 | { |
---|
1333 | UInt uiWidth = m_ppcRecoYuvBest[uiDepth]->getWidth ( ); |
---|
1334 | UInt uiHeight = m_ppcRecoYuvBest[uiDepth]->getHeight ( ); |
---|
1335 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
1336 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride ( ); |
---|
1337 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1338 | } |
---|
1339 | #endif |
---|
1340 | |
---|
1341 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
1342 | |
---|
1343 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
---|
1344 | if( bBoundary ||(bSliceEnd && bInsidePicture)) |
---|
1345 | { |
---|
1346 | return; |
---|
1347 | } |
---|
1348 | |
---|
1349 | // Assert if Best prediction mode is NONE |
---|
1350 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
1351 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
1352 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
1353 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
1354 | } |
---|
1355 | |
---|
1356 | /** finish encoding a cu and handle end-of-slice conditions |
---|
1357 | * \param pcCU |
---|
1358 | * \param uiAbsPartIdx |
---|
1359 | * \param uiDepth |
---|
1360 | * \returns Void |
---|
1361 | */ |
---|
1362 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1363 | { |
---|
1364 | TComPic* pcPic = pcCU->getPic(); |
---|
1365 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1366 | |
---|
1367 | //Calculate end address |
---|
1368 | UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; |
---|
1369 | |
---|
1370 | UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
1371 | UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
1372 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1373 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1374 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
1375 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
1376 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
1377 | { |
---|
1378 | uiInternalAddress--; |
---|
1379 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1380 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1381 | } |
---|
1382 | uiInternalAddress++; |
---|
1383 | if(uiInternalAddress==pcCU->getPic()->getNumPartInCU()) |
---|
1384 | { |
---|
1385 | uiInternalAddress = 0; |
---|
1386 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
1387 | } |
---|
1388 | UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
1389 | |
---|
1390 | // Encode slice finish |
---|
1391 | Bool bTerminateSlice = false; |
---|
1392 | if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress) |
---|
1393 | { |
---|
1394 | bTerminateSlice = true; |
---|
1395 | } |
---|
1396 | UInt uiGranularityWidth = g_uiMaxCUWidth; |
---|
1397 | uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1398 | uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1399 | Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth)) |
---|
1400 | &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); |
---|
1401 | |
---|
1402 | if(granularityBoundary) |
---|
1403 | { |
---|
1404 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
1405 | if (!bTerminateSlice) |
---|
1406 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
1407 | } |
---|
1408 | |
---|
1409 | Int numberOfWrittenBits = 0; |
---|
1410 | if (m_pcBitCounter) |
---|
1411 | { |
---|
1412 | numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1413 | } |
---|
1414 | |
---|
1415 | // Calculate slice end IF this CU puts us over slice bit size. |
---|
1416 | UInt iGranularitySize = pcCU->getPic()->getNumPartInCU(); |
---|
1417 | Int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; |
---|
1418 | if(iGranularityEnd<=pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
1419 | { |
---|
1420 | iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); |
---|
1421 | } |
---|
1422 | // Set slice end parameter |
---|
1423 | if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) |
---|
1424 | { |
---|
1425 | pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); |
---|
1426 | pcSlice->setSliceCurEndCUAddr(iGranularityEnd); |
---|
1427 | return; |
---|
1428 | } |
---|
1429 | // Set dependent slice end parameter |
---|
1430 | if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceSegmentBits()+numberOfWrittenBits > pcSlice->getSliceSegmentArgument()<<3) |
---|
1431 | { |
---|
1432 | pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); |
---|
1433 | return; |
---|
1434 | } |
---|
1435 | if(granularityBoundary) |
---|
1436 | { |
---|
1437 | pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); |
---|
1438 | pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits); |
---|
1439 | if (m_pcBitCounter) |
---|
1440 | { |
---|
1441 | m_pcEntropyCoder->resetBits(); |
---|
1442 | } |
---|
1443 | } |
---|
1444 | } |
---|
1445 | |
---|
1446 | /** Compute QP for each CU |
---|
1447 | * \param pcCU Target CU |
---|
1448 | * \param uiDepth CU depth |
---|
1449 | * \returns quantization parameter |
---|
1450 | */ |
---|
1451 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
1452 | { |
---|
1453 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
1454 | Int iQpOffset = 0; |
---|
1455 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
1456 | { |
---|
1457 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
1458 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
1459 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
1460 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
1461 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
1462 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
1463 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
1464 | |
---|
1465 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
1466 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
1467 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
1468 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
1469 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
1470 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
1471 | } |
---|
1472 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
1473 | } |
---|
1474 | |
---|
1475 | /** encode a CU block recursively |
---|
1476 | * \param pcCU |
---|
1477 | * \param uiAbsPartIdx |
---|
1478 | * \param uiDepth |
---|
1479 | * \returns Void |
---|
1480 | */ |
---|
1481 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1482 | { |
---|
1483 | TComPic* pcPic = pcCU->getPic(); |
---|
1484 | |
---|
1485 | Bool bBoundary = false; |
---|
1486 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1487 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
1488 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1489 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
1490 | |
---|
1491 | #if H_MV_ENC_DEC_TRAC |
---|
1492 | DTRACE_CU_S("=========== coding_quadtree ===========\n") |
---|
1493 | DTRACE_CU("x0", uiLPelX) |
---|
1494 | DTRACE_CU("x1", uiTPelY) |
---|
1495 | DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth) |
---|
1496 | DTRACE_CU("cqtDepth" , uiDepth) |
---|
1497 | #endif |
---|
1498 | |
---|
1499 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1500 | // If slice start is within this cu... |
---|
1501 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
1502 | pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); |
---|
1503 | // We need to split, so don't try these modes. |
---|
1504 | if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1505 | { |
---|
1506 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1507 | } |
---|
1508 | else |
---|
1509 | { |
---|
1510 | bBoundary = true; |
---|
1511 | } |
---|
1512 | |
---|
1513 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
1514 | { |
---|
1515 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
1516 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
1517 | { |
---|
1518 | setdQPFlag(true); |
---|
1519 | } |
---|
1520 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1521 | { |
---|
1522 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1523 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1524 | Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
1525 | if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1526 | { |
---|
1527 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
1528 | } |
---|
1529 | } |
---|
1530 | return; |
---|
1531 | } |
---|
1532 | |
---|
1533 | #if H_MV_ENC_DEC_TRAC |
---|
1534 | DTRACE_CU_S("=========== coding_unit ===========\n") |
---|
1535 | #endif |
---|
1536 | |
---|
1537 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
1538 | { |
---|
1539 | setdQPFlag(true); |
---|
1540 | } |
---|
1541 | if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
1542 | { |
---|
1543 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
1544 | } |
---|
1545 | if( !pcCU->getSlice()->isIntra() ) |
---|
1546 | { |
---|
1547 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1548 | } |
---|
1549 | |
---|
1550 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1551 | { |
---|
1552 | #if H_MV_ENC_DEC_TRAC |
---|
1553 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
1554 | DTRACE_PU("x0", uiLPelX) |
---|
1555 | DTRACE_PU("x1", uiTPelY) |
---|
1556 | #endif |
---|
1557 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
1558 | #if H_3D_IC |
---|
1559 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
1560 | #endif |
---|
1561 | #if H_3D_ARP |
---|
1562 | m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx ); |
---|
1563 | #endif |
---|
1564 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1565 | return; |
---|
1566 | } |
---|
1567 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1568 | |
---|
1569 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1570 | |
---|
1571 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
1572 | { |
---|
1573 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
1574 | |
---|
1575 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
1576 | { |
---|
1577 | // Encode slice finish |
---|
1578 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1579 | return; |
---|
1580 | } |
---|
1581 | } |
---|
1582 | |
---|
1583 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1584 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1585 | #if H_3D_IC |
---|
1586 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
1587 | #endif |
---|
1588 | #if H_3D_ARP |
---|
1589 | m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx ); |
---|
1590 | #endif |
---|
1591 | #if LGE_INTER_SDC_E0156 |
---|
1592 | m_pcEntropyCoder->encodeInterSDCFlag( pcCU, uiAbsPartIdx, false ); |
---|
1593 | #endif |
---|
1594 | |
---|
1595 | // Encode Coefficients |
---|
1596 | Bool bCodeDQP = getdQPFlag(); |
---|
1597 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP ); |
---|
1598 | setdQPFlag( bCodeDQP ); |
---|
1599 | |
---|
1600 | // --- write terminating bit --- |
---|
1601 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1602 | } |
---|
1603 | |
---|
1604 | #if RATE_CONTROL_INTRA |
---|
1605 | Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) |
---|
1606 | { |
---|
1607 | Int k, i, j, jj; |
---|
1608 | Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0; |
---|
1609 | |
---|
1610 | for( k = 0; k < 64; k += 8 ) |
---|
1611 | { |
---|
1612 | diff[k+0] = piOrg[0] ; |
---|
1613 | diff[k+1] = piOrg[1] ; |
---|
1614 | diff[k+2] = piOrg[2] ; |
---|
1615 | diff[k+3] = piOrg[3] ; |
---|
1616 | diff[k+4] = piOrg[4] ; |
---|
1617 | diff[k+5] = piOrg[5] ; |
---|
1618 | diff[k+6] = piOrg[6] ; |
---|
1619 | diff[k+7] = piOrg[7] ; |
---|
1620 | |
---|
1621 | piOrg += iStrideOrg; |
---|
1622 | } |
---|
1623 | |
---|
1624 | //horizontal |
---|
1625 | for (j=0; j < 8; j++) |
---|
1626 | { |
---|
1627 | jj = j << 3; |
---|
1628 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
1629 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
1630 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
1631 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
1632 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
1633 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
1634 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
1635 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
1636 | |
---|
1637 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
1638 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
1639 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
1640 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
1641 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
1642 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
1643 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
1644 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
1645 | |
---|
1646 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
1647 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
1648 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
1649 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
1650 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
1651 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
1652 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
1653 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
1654 | } |
---|
1655 | |
---|
1656 | //vertical |
---|
1657 | for (i=0; i < 8; i++) |
---|
1658 | { |
---|
1659 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
1660 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
1661 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
1662 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
1663 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
1664 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
1665 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
1666 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
1667 | |
---|
1668 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
1669 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
1670 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
1671 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
1672 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
1673 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
1674 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
1675 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
1676 | |
---|
1677 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
1678 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
1679 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
1680 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
1681 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
1682 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
1683 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
1684 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
1685 | } |
---|
1686 | |
---|
1687 | for (i = 0; i < 8; i++) |
---|
1688 | { |
---|
1689 | for (j = 0; j < 8; j++) |
---|
1690 | { |
---|
1691 | iSumHad += abs(m2[i][j]); |
---|
1692 | } |
---|
1693 | } |
---|
1694 | iSumHad -= abs(m2[0][0]); |
---|
1695 | iSumHad =(iSumHad+2)>>2; |
---|
1696 | return(iSumHad); |
---|
1697 | } |
---|
1698 | |
---|
1699 | Int TEncCu::updateLCUDataISlice(TComDataCU* pcCU, Int LCUIdx, Int width, Int height) |
---|
1700 | { |
---|
1701 | Int xBl, yBl; |
---|
1702 | const Int iBlkSize = 8; |
---|
1703 | |
---|
1704 | Pel* pOrgInit = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0); |
---|
1705 | Int iStrideOrig = pcCU->getPic()->getPicYuvOrg()->getStride(); |
---|
1706 | Pel *pOrg; |
---|
1707 | |
---|
1708 | Int iSumHad = 0; |
---|
1709 | for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize) |
---|
1710 | { |
---|
1711 | for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize) |
---|
1712 | { |
---|
1713 | pOrg = pOrgInit + iStrideOrig*yBl + xBl; |
---|
1714 | iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig); |
---|
1715 | } |
---|
1716 | } |
---|
1717 | return(iSumHad); |
---|
1718 | } |
---|
1719 | #endif |
---|
1720 | |
---|
1721 | /** check RD costs for a CU block encoded with merge |
---|
1722 | * \param rpcBestCU |
---|
1723 | * \param rpcTempCU |
---|
1724 | * \returns Void |
---|
1725 | */ |
---|
1726 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode ) |
---|
1727 | { |
---|
1728 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
1729 | #if H_3D_IV_MERGE |
---|
1730 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
1731 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
1732 | #else |
---|
1733 | TComMvField cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists |
---|
1734 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1735 | #endif |
---|
1736 | Int numValidMergeCand = 0; |
---|
1737 | |
---|
1738 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
1739 | { |
---|
1740 | uhInterDirNeighbours[ui] = 0; |
---|
1741 | } |
---|
1742 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1743 | #if H_3D_IC |
---|
1744 | Bool bICFlag = rpcTempCU->getICFlag( 0 ); |
---|
1745 | #endif |
---|
1746 | #if H_3D_VSO // M1 //nececcary here? |
---|
1747 | if( m_pcRdCost->getUseRenModel() ) |
---|
1748 | { |
---|
1749 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
1750 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
1751 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1752 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1753 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1754 | } |
---|
1755 | #endif |
---|
1756 | |
---|
1757 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1758 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
1759 | |
---|
1760 | #if H_3D_VSP |
---|
1761 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
1762 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
1763 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
1764 | InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM]; |
---|
1765 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,inheritedVSPDisInfo, numValidMergeCand ); |
---|
1766 | #else |
---|
1767 | #if MTK_VSP_FIX_E0172 |
---|
1768 | Int vspDir[MRG_MAX_NUM_CANDS_MEM]; |
---|
1769 | memset(vspDir, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
1770 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,vspDir, numValidMergeCand ); |
---|
1771 | #else |
---|
1772 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag, numValidMergeCand ); |
---|
1773 | #endif |
---|
1774 | #endif//end of MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
1775 | #else |
---|
1776 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
1777 | #endif |
---|
1778 | |
---|
1779 | #if H_3D_IV_MERGE |
---|
1780 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS_MEM]; |
---|
1781 | #else |
---|
1782 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; |
---|
1783 | #endif |
---|
1784 | for( UInt ui = 0; ui < numValidMergeCand; ++ui ) |
---|
1785 | { |
---|
1786 | mergeCandBuffer[ui] = 0; |
---|
1787 | } |
---|
1788 | |
---|
1789 | Bool bestIsSkip = false; |
---|
1790 | |
---|
1791 | UInt iteration; |
---|
1792 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
1793 | { |
---|
1794 | iteration = 1; |
---|
1795 | } |
---|
1796 | else |
---|
1797 | { |
---|
1798 | iteration = 2; |
---|
1799 | } |
---|
1800 | |
---|
1801 | #if H_3D_ARP |
---|
1802 | Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1; |
---|
1803 | if( nARPWMax < 0 || !rpcTempCU->getDvInfo(0).bDV ) |
---|
1804 | { |
---|
1805 | nARPWMax = 0; |
---|
1806 | } |
---|
1807 | for( Int nARPW=nARPWMax; nARPW >= 0 ; nARPW-- ) |
---|
1808 | { |
---|
1809 | memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS*sizeof(Int) ); |
---|
1810 | #endif |
---|
1811 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
1812 | { |
---|
1813 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
1814 | { |
---|
1815 | #if H_3D_IC |
---|
1816 | if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() ) |
---|
1817 | { |
---|
1818 | if( bICFlag && uiMergeCand == 0 ) |
---|
1819 | { |
---|
1820 | continue; |
---|
1821 | } |
---|
1822 | } |
---|
1823 | #endif |
---|
1824 | if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) |
---|
1825 | { |
---|
1826 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
1827 | { |
---|
1828 | // set MC parameters |
---|
1829 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1830 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
1831 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1832 | #if H_3D_IC |
---|
1833 | rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth ); |
---|
1834 | #endif |
---|
1835 | #if H_3D_ARP |
---|
1836 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
1837 | #endif |
---|
1838 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1839 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1840 | #if H_3D_VSP |
---|
1841 | rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth ); |
---|
1842 | #if MTK_VSP_FIX_ALIGN_WD_E0172 |
---|
1843 | rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth ); |
---|
1844 | #endif |
---|
1845 | #if MTK_VSP_FIX_E0172 |
---|
1846 | rpcTempCU->setVSPDirSubParts( vspDir[uiMergeCand], 0, 0, uhDepth ); |
---|
1847 | #endif |
---|
1848 | #endif |
---|
1849 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1850 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1851 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1852 | |
---|
1853 | #if H_3D_ARP |
---|
1854 | if( nARPW ) |
---|
1855 | { |
---|
1856 | Bool bSignalflag[2] = { true, true }; |
---|
1857 | for( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ ) |
---|
1858 | { |
---|
1859 | Int iRefIdx = cMvFieldNeighbours[uiRefListIdx + 2*uiMergeCand].getRefIdx(); |
---|
1860 | RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
1861 | if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) ) |
---|
1862 | { |
---|
1863 | bSignalflag[uiRefListIdx] = false; |
---|
1864 | } |
---|
1865 | } |
---|
1866 | if( !bSignalflag[0] && !bSignalflag[1] ) |
---|
1867 | { |
---|
1868 | rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth ); |
---|
1869 | } |
---|
1870 | } |
---|
1871 | #endif |
---|
1872 | // do MC |
---|
1873 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1874 | // estimate residual and encode everything |
---|
1875 | #if H_3D_VSO //M2 |
---|
1876 | if( m_pcRdCost->getUseRenModel() ) |
---|
1877 | { //Reset |
---|
1878 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
1879 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
1880 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); |
---|
1881 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
1882 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1883 | } |
---|
1884 | #endif |
---|
1885 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
1886 | m_ppcOrigYuv [uhDepth], |
---|
1887 | m_ppcPredYuvTemp[uhDepth], |
---|
1888 | m_ppcResiYuvTemp[uhDepth], |
---|
1889 | m_ppcResiYuvBest[uhDepth], |
---|
1890 | m_ppcRecoYuvTemp[uhDepth], |
---|
1891 | (uiNoResidual? true:false)); |
---|
1892 | |
---|
1893 | |
---|
1894 | if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 ) |
---|
1895 | { |
---|
1896 | // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 |
---|
1897 | mergeCandBuffer[uiMergeCand] = 1; |
---|
1898 | } |
---|
1899 | |
---|
1900 | rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth ); |
---|
1901 | #if LGE_INTER_SDC_E0156 |
---|
1902 | TComDataCU *rpcTempCUPre = rpcTempCU; |
---|
1903 | #endif |
---|
1904 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
1905 | xCheckDQP( rpcTempCU ); |
---|
1906 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
1907 | #if LGE_INTER_SDC_E0156 |
---|
1908 | if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual ) |
---|
1909 | { |
---|
1910 | if( rpcTempCU != rpcTempCUPre ) |
---|
1911 | { |
---|
1912 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
1913 | rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); |
---|
1914 | } |
---|
1915 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
1916 | rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); |
---|
1917 | rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth ); |
---|
1918 | #if H_3D_VSO //M2 |
---|
1919 | if( m_pcRdCost->getUseRenModel() ) |
---|
1920 | { //Reset |
---|
1921 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
1922 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
1923 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); |
---|
1924 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
1925 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1926 | } |
---|
1927 | #endif |
---|
1928 | m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, |
---|
1929 | m_ppcOrigYuv[uhDepth], |
---|
1930 | ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], |
---|
1931 | m_ppcResiYuvTemp[uhDepth], |
---|
1932 | m_ppcRecoYuvTemp[uhDepth], |
---|
1933 | uhDepth ); |
---|
1934 | |
---|
1935 | xCheckDQP( rpcTempCU ); |
---|
1936 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1937 | } |
---|
1938 | #endif |
---|
1939 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
1940 | |
---|
1941 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
1942 | { |
---|
1943 | #if LGE_INTER_SDC_E0156 |
---|
1944 | if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) ) |
---|
1945 | { |
---|
1946 | bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 ); |
---|
1947 | } |
---|
1948 | else |
---|
1949 | { |
---|
1950 | #endif |
---|
1951 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
1952 | #if LGE_INTER_SDC_E0156 |
---|
1953 | } |
---|
1954 | #endif |
---|
1955 | } |
---|
1956 | } |
---|
1957 | } |
---|
1958 | } |
---|
1959 | |
---|
1960 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
1961 | { |
---|
1962 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
1963 | { |
---|
1964 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
1965 | { |
---|
1966 | *earlyDetectionSkipMode = true; |
---|
1967 | } |
---|
1968 | else |
---|
1969 | { |
---|
1970 | Int absoulte_MV=0; |
---|
1971 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
1972 | { |
---|
1973 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
1974 | { |
---|
1975 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
1976 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
1977 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
1978 | absoulte_MV+=iHor+iVer; |
---|
1979 | } |
---|
1980 | } |
---|
1981 | |
---|
1982 | if(absoulte_MV == 0) |
---|
1983 | { |
---|
1984 | *earlyDetectionSkipMode = true; |
---|
1985 | } |
---|
1986 | } |
---|
1987 | } |
---|
1988 | } |
---|
1989 | } |
---|
1990 | #if H_3D_ARP |
---|
1991 | } |
---|
1992 | #endif |
---|
1993 | } |
---|
1994 | |
---|
1995 | |
---|
1996 | #if AMP_MRG |
---|
1997 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
1998 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFMD, Bool bUseMRG) |
---|
1999 | #else |
---|
2000 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG) |
---|
2001 | #endif |
---|
2002 | #else |
---|
2003 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
2004 | #endif |
---|
2005 | { |
---|
2006 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
2007 | if(!(bFMD && (ePartSize == SIZE_2Nx2N))) //have motion estimation or merge check |
---|
2008 | { |
---|
2009 | #endif |
---|
2010 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2011 | #if H_3D_ARP |
---|
2012 | Int iLayerId = rpcTempCU->getSlice()->getLayerId(); |
---|
2013 | Bool bFirstTime = true; |
---|
2014 | Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1; |
---|
2015 | |
---|
2016 | if( nARPWMax < 0 || ePartSize != SIZE_2Nx2N || !rpcTempCU->getDvInfo(0).bDV ) |
---|
2017 | { |
---|
2018 | nARPWMax = 0; |
---|
2019 | } |
---|
2020 | |
---|
2021 | for( Int nARPW = 0; nARPW <= nARPWMax; nARPW++ ) |
---|
2022 | { |
---|
2023 | if( bFirstTime == false && rpcTempCU->getSlice()->getVPS()->getUseAdvRP( iLayerId ) ) |
---|
2024 | { |
---|
2025 | rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0) ); |
---|
2026 | } |
---|
2027 | #endif |
---|
2028 | #if H_3D_VSO // M3 |
---|
2029 | if( m_pcRdCost->getUseRenModel() ) |
---|
2030 | { |
---|
2031 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
2032 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
2033 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
2034 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
2035 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2036 | } |
---|
2037 | #endif |
---|
2038 | |
---|
2039 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
2040 | |
---|
2041 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
2042 | |
---|
2043 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
2044 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
2045 | rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
2046 | |
---|
2047 | #if H_3D_ARP |
---|
2048 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
2049 | #endif |
---|
2050 | |
---|
2051 | #if H_3D_ARP |
---|
2052 | if( bFirstTime == false && nARPWMax ) |
---|
2053 | { |
---|
2054 | rpcTempCU->copyPartFrom( m_ppcWeightedTempCU[uhDepth] , 0 , uhDepth ); |
---|
2055 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
2056 | |
---|
2057 | m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth] ); |
---|
2058 | |
---|
2059 | if(rpcTempCU->getPartitionSize(0)==SIZE_2Nx2N) |
---|
2060 | { |
---|
2061 | Bool bSignalflag[2] = { true, true }; |
---|
2062 | for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ ) |
---|
2063 | { |
---|
2064 | RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
2065 | Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0); |
---|
2066 | if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) ) |
---|
2067 | { |
---|
2068 | bSignalflag[uiRefListIdx] = false; |
---|
2069 | } |
---|
2070 | } |
---|
2071 | if( !bSignalflag[0] && !bSignalflag[1] ) |
---|
2072 | { |
---|
2073 | rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth ); |
---|
2074 | } |
---|
2075 | } |
---|
2076 | } |
---|
2077 | else |
---|
2078 | { |
---|
2079 | bFirstTime = false; |
---|
2080 | #endif |
---|
2081 | #if AMP_MRG |
---|
2082 | rpcTempCU->setMergeAMP (true); |
---|
2083 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
2084 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bFMD, false, bUseMRG ); |
---|
2085 | #else |
---|
2086 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG ); |
---|
2087 | #endif |
---|
2088 | #else |
---|
2089 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
2090 | #endif |
---|
2091 | #if H_3D_ARP |
---|
2092 | if( nARPWMax ) |
---|
2093 | { |
---|
2094 | m_ppcWeightedTempCU[uhDepth]->copyPartFrom( rpcTempCU , 0 , uhDepth ); |
---|
2095 | |
---|
2096 | Bool bSignalflag[2] = { true, true }; |
---|
2097 | for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ ) |
---|
2098 | { |
---|
2099 | RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
2100 | Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0); |
---|
2101 | if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) ) |
---|
2102 | { |
---|
2103 | bSignalflag[uiRefListIdx] = false; |
---|
2104 | } |
---|
2105 | } |
---|
2106 | if( !bSignalflag[0] && !bSignalflag[1]) |
---|
2107 | { |
---|
2108 | rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth ); |
---|
2109 | } |
---|
2110 | } |
---|
2111 | } |
---|
2112 | #endif |
---|
2113 | |
---|
2114 | #if AMP_MRG |
---|
2115 | if ( !rpcTempCU->getMergeAMP() ) |
---|
2116 | { |
---|
2117 | #if H_3D_ARP |
---|
2118 | if( nARPWMax ) |
---|
2119 | { |
---|
2120 | continue; |
---|
2121 | } |
---|
2122 | else |
---|
2123 | #endif |
---|
2124 | return; |
---|
2125 | } |
---|
2126 | #endif |
---|
2127 | |
---|
2128 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
2129 | if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
2130 | { |
---|
2131 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
2132 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
2133 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
2134 | m_temporalSAD = (Int)SAD; |
---|
2135 | } |
---|
2136 | #endif |
---|
2137 | |
---|
2138 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
2139 | |
---|
2140 | |
---|
2141 | #if H_3D_VSO // M4 |
---|
2142 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
2143 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2144 | else |
---|
2145 | #endif |
---|
2146 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2147 | #if LGE_INTER_SDC_E0156 |
---|
2148 | TComDataCU *rpcTempCUPre = rpcTempCU; |
---|
2149 | #endif |
---|
2150 | xCheckDQP( rpcTempCU ); |
---|
2151 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2152 | #if LGE_INTER_SDC_E0156 |
---|
2153 | if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() ) |
---|
2154 | { |
---|
2155 | if( rpcTempCU != rpcTempCUPre ) |
---|
2156 | { |
---|
2157 | Int orgQP = rpcBestCU->getQP( 0 ); |
---|
2158 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
2159 | rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); |
---|
2160 | } |
---|
2161 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
2162 | rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); |
---|
2163 | rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth ); |
---|
2164 | #if H_3D_VSO // M3 |
---|
2165 | if( m_pcRdCost->getUseRenModel() ) |
---|
2166 | { |
---|
2167 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
2168 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
2169 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
2170 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
2171 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2172 | } |
---|
2173 | #endif |
---|
2174 | |
---|
2175 | m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, |
---|
2176 | m_ppcOrigYuv[uhDepth], |
---|
2177 | ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], |
---|
2178 | m_ppcResiYuvTemp[uhDepth], |
---|
2179 | m_ppcRecoYuvTemp[uhDepth], |
---|
2180 | uhDepth ); |
---|
2181 | |
---|
2182 | xCheckDQP( rpcTempCU ); |
---|
2183 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2184 | } |
---|
2185 | #endif |
---|
2186 | #if H_3D_ARP |
---|
2187 | } |
---|
2188 | #endif |
---|
2189 | #if MTK_FAST_TEXTURE_ENCODING_E0173 |
---|
2190 | } |
---|
2191 | #endif |
---|
2192 | } |
---|
2193 | |
---|
2194 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
2195 | { |
---|
2196 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2197 | |
---|
2198 | #if H_3D_VSO // M5 |
---|
2199 | if( m_pcRdCost->getUseRenModel() ) |
---|
2200 | { |
---|
2201 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth (); |
---|
2202 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight (); |
---|
2203 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr(); |
---|
2204 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride (); |
---|
2205 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2206 | } |
---|
2207 | #endif |
---|
2208 | |
---|
2209 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
2210 | |
---|
2211 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
2212 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2213 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth ); |
---|
2214 | |
---|
2215 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
2216 | UInt uiPreCalcDistC = 0; |
---|
2217 | if( !bSeparateLumaChroma ) |
---|
2218 | { |
---|
2219 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
2220 | } |
---|
2221 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
2222 | |
---|
2223 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
2224 | |
---|
2225 | #if H_3D_DIM_SDC |
---|
2226 | if( !rpcTempCU->getSDCFlag( 0 ) ) |
---|
2227 | #endif |
---|
2228 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
2229 | |
---|
2230 | m_pcEntropyCoder->resetBits(); |
---|
2231 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
2232 | { |
---|
2233 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
2234 | } |
---|
2235 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2236 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
2237 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
2238 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
2239 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
2240 | |
---|
2241 | // Encode Coefficients |
---|
2242 | Bool bCodeDQP = getdQPFlag(); |
---|
2243 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP ); |
---|
2244 | setdQPFlag( bCodeDQP ); |
---|
2245 | |
---|
2246 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2247 | |
---|
2248 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2249 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2250 | { |
---|
2251 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2252 | } |
---|
2253 | |
---|
2254 | #if H_3D_VSO // M6 |
---|
2255 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
2256 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2257 | else |
---|
2258 | #endif |
---|
2259 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2260 | |
---|
2261 | xCheckDQP( rpcTempCU ); |
---|
2262 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
---|
2263 | } |
---|
2264 | |
---|
2265 | /** Check R-D costs for a CU with PCM mode. |
---|
2266 | * \param rpcBestCU pointer to best mode CU data structure |
---|
2267 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
2268 | * \returns Void |
---|
2269 | * |
---|
2270 | * \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. |
---|
2271 | */ |
---|
2272 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2273 | { |
---|
2274 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2275 | |
---|
2276 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
2277 | |
---|
2278 | rpcTempCU->setIPCMFlag(0, true); |
---|
2279 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
2280 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
2281 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2282 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
2283 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth ); |
---|
2284 | |
---|
2285 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
2286 | |
---|
2287 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
2288 | |
---|
2289 | m_pcEntropyCoder->resetBits(); |
---|
2290 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
2291 | { |
---|
2292 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
2293 | } |
---|
2294 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2295 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
2296 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
2297 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
2298 | |
---|
2299 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2300 | |
---|
2301 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2302 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2303 | { |
---|
2304 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2305 | } |
---|
2306 | #if H_3D_VSO // M44 |
---|
2307 | if ( m_pcRdCost->getUseVSO() ) |
---|
2308 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2309 | else |
---|
2310 | #endif |
---|
2311 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2312 | |
---|
2313 | xCheckDQP( rpcTempCU ); |
---|
2314 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
2315 | } |
---|
2316 | |
---|
2317 | /** check whether current try is the best with identifying the depth of current try |
---|
2318 | * \param rpcBestCU |
---|
2319 | * \param rpcTempCU |
---|
2320 | * \returns Void |
---|
2321 | */ |
---|
2322 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
2323 | { |
---|
2324 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
2325 | { |
---|
2326 | TComYuv* pcYuv; |
---|
2327 | // Change Information data |
---|
2328 | TComDataCU* pcCU = rpcBestCU; |
---|
2329 | rpcBestCU = rpcTempCU; |
---|
2330 | rpcTempCU = pcCU; |
---|
2331 | |
---|
2332 | // Change Prediction data |
---|
2333 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
2334 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
2335 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
2336 | |
---|
2337 | // Change Reconstruction data |
---|
2338 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
2339 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
2340 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
2341 | |
---|
2342 | pcYuv = NULL; |
---|
2343 | pcCU = NULL; |
---|
2344 | |
---|
2345 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
2346 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
2347 | } |
---|
2348 | } |
---|
2349 | |
---|
2350 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
2351 | { |
---|
2352 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
2353 | |
---|
2354 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
2355 | { |
---|
2356 | if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) |
---|
2357 | { |
---|
2358 | #if !RDO_WITHOUT_DQP_BITS |
---|
2359 | m_pcEntropyCoder->resetBits(); |
---|
2360 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
2361 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
2362 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2363 | { |
---|
2364 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2365 | } |
---|
2366 | #if H_3D_VSO // M45 |
---|
2367 | if ( m_pcRdCost->getUseVSO() ) |
---|
2368 | pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
2369 | else |
---|
2370 | #endif |
---|
2371 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
2372 | #endif |
---|
2373 | } |
---|
2374 | else |
---|
2375 | { |
---|
2376 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
2377 | } |
---|
2378 | } |
---|
2379 | } |
---|
2380 | |
---|
2381 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
2382 | { |
---|
2383 | pDst->iN = pSrc->iN; |
---|
2384 | for (Int i = 0; i < pSrc->iN; i++) |
---|
2385 | { |
---|
2386 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
2387 | } |
---|
2388 | } |
---|
2389 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
---|
2390 | { |
---|
2391 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
2392 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
2393 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2394 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2395 | pcSlice->getSliceSegmentCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2396 | Bool bSliceEnd = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2397 | pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2398 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2399 | { |
---|
2400 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
2401 | UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); |
---|
2402 | UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); |
---|
2403 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
2404 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
2405 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
2406 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
2407 | } |
---|
2408 | else |
---|
2409 | { |
---|
2410 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
2411 | |
---|
2412 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
2413 | { |
---|
2414 | UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); |
---|
2415 | UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); |
---|
2416 | |
---|
2417 | Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && |
---|
2418 | rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
2419 | if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2420 | { |
---|
2421 | xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv |
---|
2422 | } |
---|
2423 | } |
---|
2424 | } |
---|
2425 | } |
---|
2426 | |
---|
2427 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
2428 | { |
---|
2429 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
2430 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
2431 | } |
---|
2432 | |
---|
2433 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
2434 | * \param pcCU pointer to current CU |
---|
2435 | * \param pcOrgYuv pointer to original sample array |
---|
2436 | * \returns Void |
---|
2437 | */ |
---|
2438 | Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) |
---|
2439 | { |
---|
2440 | |
---|
2441 | UInt width = pCU->getWidth(0); |
---|
2442 | UInt height = pCU->getHeight(0); |
---|
2443 | |
---|
2444 | Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); |
---|
2445 | Pel* pDstY = pCU->getPCMSampleY(); |
---|
2446 | UInt srcStride = pOrgYuv->getStride(); |
---|
2447 | |
---|
2448 | for(Int y = 0; y < height; y++ ) |
---|
2449 | { |
---|
2450 | for(Int x = 0; x < width; x++ ) |
---|
2451 | { |
---|
2452 | pDstY[x] = pSrcY[x]; |
---|
2453 | } |
---|
2454 | pDstY += width; |
---|
2455 | pSrcY += srcStride; |
---|
2456 | } |
---|
2457 | |
---|
2458 | Pel* pSrcCb = pOrgYuv->getCbAddr(); |
---|
2459 | Pel* pSrcCr = pOrgYuv->getCrAddr();; |
---|
2460 | |
---|
2461 | Pel* pDstCb = pCU->getPCMSampleCb(); |
---|
2462 | Pel* pDstCr = pCU->getPCMSampleCr();; |
---|
2463 | |
---|
2464 | UInt srcStrideC = pOrgYuv->getCStride(); |
---|
2465 | UInt heightC = height >> 1; |
---|
2466 | UInt widthC = width >> 1; |
---|
2467 | |
---|
2468 | for(Int y = 0; y < heightC; y++ ) |
---|
2469 | { |
---|
2470 | for(Int x = 0; x < widthC; x++ ) |
---|
2471 | { |
---|
2472 | pDstCb[x] = pSrcCb[x]; |
---|
2473 | pDstCr[x] = pSrcCr[x]; |
---|
2474 | } |
---|
2475 | pDstCb += widthC; |
---|
2476 | pDstCr += widthC; |
---|
2477 | pSrcCb += srcStrideC; |
---|
2478 | pSrcCr += srcStrideC; |
---|
2479 | } |
---|
2480 | } |
---|
2481 | |
---|
2482 | #if ADAPTIVE_QP_SELECTION |
---|
2483 | /** Collect ARL statistics from one block |
---|
2484 | */ |
---|
2485 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
2486 | { |
---|
2487 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
2488 | { |
---|
2489 | Int u = abs( rpcCoeff[ n ] ); |
---|
2490 | Int absc = rpcArlCoeff[ n ]; |
---|
2491 | |
---|
2492 | if( u != 0 ) |
---|
2493 | { |
---|
2494 | if( u < LEVEL_RANGE ) |
---|
2495 | { |
---|
2496 | cSum[ u ] += ( Double )absc; |
---|
2497 | numSamples[ u ]++; |
---|
2498 | } |
---|
2499 | else |
---|
2500 | { |
---|
2501 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
2502 | numSamples[ LEVEL_RANGE ]++; |
---|
2503 | } |
---|
2504 | } |
---|
2505 | } |
---|
2506 | |
---|
2507 | return 0; |
---|
2508 | } |
---|
2509 | |
---|
2510 | /** Collect ARL statistics from one LCU |
---|
2511 | * \param pcCU |
---|
2512 | */ |
---|
2513 | Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) |
---|
2514 | { |
---|
2515 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
---|
2516 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
---|
2517 | |
---|
2518 | TCoeff* pCoeffY = rpcCU->getCoeffY(); |
---|
2519 | Int* pArlCoeffY = rpcCU->getArlCoeffY(); |
---|
2520 | |
---|
2521 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
2522 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
---|
2523 | |
---|
2524 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
2525 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
2526 | |
---|
2527 | // Collect stats to cSum[][] and numSamples[][] |
---|
2528 | for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) |
---|
2529 | { |
---|
2530 | UInt uiTrIdx = rpcCU->getTransformIdx(i); |
---|
2531 | |
---|
2532 | if(rpcCU->getPredictionMode(i) == MODE_INTER) |
---|
2533 | if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) |
---|
2534 | { |
---|
2535 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
2536 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
2537 | |
---|
2538 | pCoeffY += uiMinNumCoeffInCU; |
---|
2539 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
2540 | } |
---|
2541 | |
---|
2542 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
2543 | { |
---|
2544 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
2545 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
2546 | } |
---|
2547 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
2548 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
2549 | } |
---|
2550 | #endif |
---|
2551 | //! \} |
---|