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-2012, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncCu.cpp |
---|
35 | \brief Coding Unit (CU) encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <stdio.h> |
---|
39 | #include "TEncTop.h" |
---|
40 | #include "TEncCu.h" |
---|
41 | #include "TEncAnalyze.h" |
---|
42 | |
---|
43 | #include <cmath> |
---|
44 | #include <algorithm> |
---|
45 | using namespace std; |
---|
46 | |
---|
47 | //! \ingroup TLibEncoder |
---|
48 | //! \{ |
---|
49 | |
---|
50 | // ==================================================================================================================== |
---|
51 | // Constructor / destructor / create / destroy |
---|
52 | // ==================================================================================================================== |
---|
53 | |
---|
54 | /** |
---|
55 | \param uiTotalDepth total number of allowable depth |
---|
56 | \param uiMaxWidth largest CU width |
---|
57 | \param uiMaxHeight largest CU height |
---|
58 | */ |
---|
59 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight) |
---|
60 | { |
---|
61 | Int i; |
---|
62 | |
---|
63 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
64 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
65 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
66 | |
---|
67 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
68 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
69 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
70 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
71 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
72 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
73 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
74 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
75 | m_ppcResPredTmp = new TComYuv*[m_uhTotalDepth-1]; |
---|
76 | #endif |
---|
77 | |
---|
78 | #if HHI_MPI |
---|
79 | m_puhDepthSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
80 | m_puhWidthSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
81 | m_puhHeightSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
82 | #endif |
---|
83 | |
---|
84 | UInt uiNumPartitions; |
---|
85 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
86 | { |
---|
87 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
88 | UInt uiWidth = uiMaxWidth >> i; |
---|
89 | UInt uiHeight = uiMaxHeight >> i; |
---|
90 | |
---|
91 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
92 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
93 | |
---|
94 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight); |
---|
95 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight); |
---|
96 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight); |
---|
97 | |
---|
98 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight); |
---|
99 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight); |
---|
100 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight); |
---|
101 | |
---|
102 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight); |
---|
103 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
104 | m_ppcResPredTmp [i] = new TComYuv; m_ppcResPredTmp [i]->create(uiWidth, uiHeight); |
---|
105 | #endif |
---|
106 | } |
---|
107 | |
---|
108 | m_bEncodeDQP = false; |
---|
109 | #if BURST_IPCM |
---|
110 | m_checkBurstIPCMFlag = false; |
---|
111 | #endif |
---|
112 | |
---|
113 | // initialize partition order. |
---|
114 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
115 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
116 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
117 | |
---|
118 | // initialize conversion matrix from partition index to pel |
---|
119 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
120 | initMotionReferIdx ( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
121 | } |
---|
122 | |
---|
123 | Void TEncCu::destroy() |
---|
124 | { |
---|
125 | Int i; |
---|
126 | |
---|
127 | #if HHI_MPI |
---|
128 | delete[] m_puhDepthSaved; m_puhDepthSaved = NULL; |
---|
129 | delete[] m_puhWidthSaved; m_puhWidthSaved = NULL; |
---|
130 | delete[] m_puhHeightSaved; m_puhHeightSaved = NULL; |
---|
131 | #endif |
---|
132 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
133 | { |
---|
134 | if(m_ppcBestCU[i]) |
---|
135 | { |
---|
136 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
137 | } |
---|
138 | if(m_ppcTempCU[i]) |
---|
139 | { |
---|
140 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
141 | } |
---|
142 | if(m_ppcPredYuvBest[i]) |
---|
143 | { |
---|
144 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
145 | } |
---|
146 | if(m_ppcResiYuvBest[i]) |
---|
147 | { |
---|
148 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
149 | } |
---|
150 | if(m_ppcRecoYuvBest[i]) |
---|
151 | { |
---|
152 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
153 | } |
---|
154 | if(m_ppcPredYuvTemp[i]) |
---|
155 | { |
---|
156 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
157 | } |
---|
158 | if(m_ppcResiYuvTemp[i]) |
---|
159 | { |
---|
160 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
161 | } |
---|
162 | if(m_ppcRecoYuvTemp[i]) |
---|
163 | { |
---|
164 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
165 | } |
---|
166 | if(m_ppcOrigYuv[i]) |
---|
167 | { |
---|
168 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
169 | } |
---|
170 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
171 | if(m_ppcResPredTmp[i]) |
---|
172 | { |
---|
173 | m_ppcResPredTmp [i]->destroy(); delete m_ppcResPredTmp[i]; m_ppcResPredTmp[i] = NULL; |
---|
174 | } |
---|
175 | #endif |
---|
176 | } |
---|
177 | if(m_ppcBestCU) |
---|
178 | { |
---|
179 | delete [] m_ppcBestCU; |
---|
180 | m_ppcBestCU = NULL; |
---|
181 | } |
---|
182 | if(m_ppcTempCU) |
---|
183 | { |
---|
184 | delete [] m_ppcTempCU; |
---|
185 | m_ppcTempCU = NULL; |
---|
186 | } |
---|
187 | |
---|
188 | if(m_ppcPredYuvBest) |
---|
189 | { |
---|
190 | delete [] m_ppcPredYuvBest; |
---|
191 | m_ppcPredYuvBest = NULL; |
---|
192 | } |
---|
193 | if(m_ppcResiYuvBest) |
---|
194 | { |
---|
195 | delete [] m_ppcResiYuvBest; |
---|
196 | m_ppcResiYuvBest = NULL; |
---|
197 | } |
---|
198 | if(m_ppcRecoYuvBest) |
---|
199 | { |
---|
200 | delete [] m_ppcRecoYuvBest; |
---|
201 | m_ppcRecoYuvBest = NULL; |
---|
202 | } |
---|
203 | if(m_ppcPredYuvTemp) |
---|
204 | { |
---|
205 | delete [] m_ppcPredYuvTemp; |
---|
206 | m_ppcPredYuvTemp = NULL; |
---|
207 | } |
---|
208 | if(m_ppcResiYuvTemp) |
---|
209 | { |
---|
210 | delete [] m_ppcResiYuvTemp; |
---|
211 | m_ppcResiYuvTemp = NULL; |
---|
212 | } |
---|
213 | if(m_ppcRecoYuvTemp) |
---|
214 | { |
---|
215 | delete [] m_ppcRecoYuvTemp; |
---|
216 | m_ppcRecoYuvTemp = NULL; |
---|
217 | } |
---|
218 | if(m_ppcOrigYuv) |
---|
219 | { |
---|
220 | delete [] m_ppcOrigYuv; |
---|
221 | m_ppcOrigYuv = NULL; |
---|
222 | } |
---|
223 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
224 | if(m_ppcResPredTmp) |
---|
225 | { |
---|
226 | delete [] m_ppcResPredTmp; |
---|
227 | m_ppcResPredTmp = NULL; |
---|
228 | } |
---|
229 | #endif |
---|
230 | } |
---|
231 | |
---|
232 | /** \param pcEncTop pointer of encoder class |
---|
233 | */ |
---|
234 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
235 | { |
---|
236 | m_pcEncCfg = pcEncTop; |
---|
237 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
238 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
239 | m_pcBitCounter = pcEncTop->getBitCounter(); |
---|
240 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
241 | |
---|
242 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
243 | m_pcCavlcCoder = pcEncTop->getCavlcCoder(); |
---|
244 | m_pcSbacCoder = pcEncTop->getSbacCoder(); |
---|
245 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
246 | |
---|
247 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
248 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
249 | |
---|
250 | m_bUseSBACRD = pcEncTop->getUseSBACRD(); |
---|
251 | } |
---|
252 | |
---|
253 | // ==================================================================================================================== |
---|
254 | // Public member functions |
---|
255 | // ==================================================================================================================== |
---|
256 | |
---|
257 | /** \param rpcCU pointer of CU data class |
---|
258 | */ |
---|
259 | Void TEncCu::compressCU( TComDataCU*& rpcCU ) |
---|
260 | { |
---|
261 | // initialize CU data |
---|
262 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
263 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
264 | |
---|
265 | // analysis of CU |
---|
266 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
267 | |
---|
268 | #if ADAPTIVE_QP_SELECTION |
---|
269 | if( m_pcEncCfg->getUseAdaptQpSelect() ) |
---|
270 | { |
---|
271 | if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII |
---|
272 | { |
---|
273 | xLcuCollectARLStats( rpcCU); |
---|
274 | } |
---|
275 | } |
---|
276 | #endif |
---|
277 | } |
---|
278 | /** \param pcCU pointer of CU data class, bForceTerminate when set to true terminates slice (default is false). |
---|
279 | */ |
---|
280 | Void TEncCu::encodeCU ( TComDataCU* pcCU, Bool bForceTerminate ) |
---|
281 | { |
---|
282 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
283 | { |
---|
284 | setdQPFlag(true); |
---|
285 | } |
---|
286 | |
---|
287 | #if BURST_IPCM |
---|
288 | TComPic* pcPic = pcCU->getPic(); |
---|
289 | Bool checkBurstIPCMFlag = (pcPic->getSlice(0)->getSPS()->getUsePCM())? true : false; |
---|
290 | |
---|
291 | setCheckBurstIPCMFlag( checkBurstIPCMFlag ); |
---|
292 | |
---|
293 | pcCU->setNumSucIPCM(0); |
---|
294 | pcCU->setLastCUSucIPCMFlag(false); |
---|
295 | #endif |
---|
296 | |
---|
297 | // Encode CU data |
---|
298 | xEncodeCU( pcCU, 0, 0 ); |
---|
299 | |
---|
300 | #if OL_FLUSH |
---|
301 | bool bTerminateSlice = bForceTerminate; |
---|
302 | UInt uiCUAddr = pcCU->getAddr(); |
---|
303 | /* If at the end of an LCU line but not at the end of a substream, perform CABAC flush */ |
---|
304 | #if WPP_SIMPLIFICATION |
---|
305 | if (!bTerminateSlice && pcCU->getSlice()->getPPS()->getNumSubstreams() > 1) |
---|
306 | #else |
---|
307 | if (!bTerminateSlice && pcCU->getSlice()->getPPS()->getCabacIstateReset()) |
---|
308 | #endif |
---|
309 | { |
---|
310 | Int iNumSubstreams = pcCU->getSlice()->getPPS()->getNumSubstreams(); |
---|
311 | UInt uiWidthInLCUs = pcCU->getPic()->getPicSym()->getFrameWidthInCU(); |
---|
312 | UInt uiCol = uiCUAddr % uiWidthInLCUs; |
---|
313 | UInt uiLin = uiCUAddr / uiWidthInLCUs; |
---|
314 | #if !REMOVE_TILE_DEPENDENCE |
---|
315 | Int iBreakDep = pcCU->getPic()->getPicSym()->getTileBoundaryIndependenceIdr(); |
---|
316 | #endif |
---|
317 | UInt uiTileStartLCU = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr(); |
---|
318 | UInt uiTileLCUX = uiTileStartLCU % uiWidthInLCUs; |
---|
319 | UInt uiTileLCUY = uiTileStartLCU / uiWidthInLCUs; |
---|
320 | UInt uiTileWidth = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getTileWidth(); |
---|
321 | UInt uiTileHeight = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getTileHeight(); |
---|
322 | Int iNumSubstreamsPerTile = iNumSubstreams; |
---|
323 | #if !REMOVE_TILE_DEPENDENCE |
---|
324 | #if WPP_SIMPLIFICATION |
---|
325 | if (iBreakDep && pcCU->getSlice()->getPPS()->getNumSubstreams() > 1) |
---|
326 | #else |
---|
327 | if (iBreakDep && pcCU->getSlice()->getPPS()->getEntropyCodingSynchro()) |
---|
328 | #endif |
---|
329 | iNumSubstreamsPerTile /= pcCU->getPic()->getPicSym()->getNumTiles(); |
---|
330 | if ((iBreakDep && (uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight)) |
---|
331 | || (!iBreakDep && (uiCol == uiWidthInLCUs-1) && (uiLin+iNumSubstreams < pcCU->getPic()->getFrameHeightInCU()))) |
---|
332 | { |
---|
333 | m_pcEntropyCoder->encodeFlush(); |
---|
334 | } |
---|
335 | #else |
---|
336 | #if WPP_SIMPLIFICATION |
---|
337 | if (pcCU->getSlice()->getPPS()->getNumSubstreams() > 1) |
---|
338 | #else |
---|
339 | if (pcCU->getSlice()->getPPS()->getEntropyCodingSynchro()) |
---|
340 | #endif |
---|
341 | { |
---|
342 | iNumSubstreamsPerTile /= pcCU->getPic()->getPicSym()->getNumTiles(); |
---|
343 | } |
---|
344 | if ((uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight)) |
---|
345 | { |
---|
346 | m_pcEntropyCoder->encodeFlush(); |
---|
347 | } |
---|
348 | #endif |
---|
349 | } |
---|
350 | #endif // OL_FLUSH |
---|
351 | } |
---|
352 | |
---|
353 | // ==================================================================================================================== |
---|
354 | // Protected member functions |
---|
355 | // ==================================================================================================================== |
---|
356 | /** Derive small set of test modes for AMP encoder speed-up |
---|
357 | *\param rpcBestCU |
---|
358 | *\param eParentPartSize |
---|
359 | *\param bTestAMP_Hor |
---|
360 | *\param bTestAMP_Ver |
---|
361 | *\param bTestMergeAMP_Hor |
---|
362 | *\param bTestMergeAMP_Ver |
---|
363 | *\returns Void |
---|
364 | */ |
---|
365 | #if AMP_ENC_SPEEDUP |
---|
366 | #if AMP_MRG |
---|
367 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver) |
---|
368 | #else |
---|
369 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver) |
---|
370 | #endif |
---|
371 | { |
---|
372 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
373 | { |
---|
374 | bTestAMP_Hor = true; |
---|
375 | } |
---|
376 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
377 | { |
---|
378 | bTestAMP_Ver = true; |
---|
379 | } |
---|
380 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false ) |
---|
381 | { |
---|
382 | bTestAMP_Hor = true; |
---|
383 | bTestAMP_Ver = true; |
---|
384 | } |
---|
385 | |
---|
386 | #if AMP_MRG |
---|
387 | //! Utilizing the partition size of parent PU |
---|
388 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
389 | { |
---|
390 | bTestMergeAMP_Hor = true; |
---|
391 | bTestMergeAMP_Ver = true; |
---|
392 | } |
---|
393 | |
---|
394 | if ( eParentPartSize == SIZE_NONE ) //! if parent is intra |
---|
395 | { |
---|
396 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
397 | { |
---|
398 | bTestMergeAMP_Hor = true; |
---|
399 | } |
---|
400 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
401 | { |
---|
402 | bTestMergeAMP_Ver = true; |
---|
403 | } |
---|
404 | } |
---|
405 | |
---|
406 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false ) |
---|
407 | { |
---|
408 | bTestMergeAMP_Hor = true; |
---|
409 | bTestMergeAMP_Ver = true; |
---|
410 | } |
---|
411 | |
---|
412 | if ( rpcBestCU->getWidth(0) == 64 ) |
---|
413 | { |
---|
414 | bTestAMP_Hor = false; |
---|
415 | bTestAMP_Ver = false; |
---|
416 | } |
---|
417 | #else |
---|
418 | //! Utilizing the partition size of parent PU |
---|
419 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
420 | { |
---|
421 | bTestAMP_Hor = true; |
---|
422 | bTestAMP_Ver = true; |
---|
423 | } |
---|
424 | |
---|
425 | if ( eParentPartSize == SIZE_2Nx2N ) |
---|
426 | { |
---|
427 | bTestAMP_Hor = false; |
---|
428 | bTestAMP_Ver = false; |
---|
429 | } |
---|
430 | #endif |
---|
431 | } |
---|
432 | #endif |
---|
433 | |
---|
434 | // ==================================================================================================================== |
---|
435 | // Protected member functions |
---|
436 | // ==================================================================================================================== |
---|
437 | /** Compress a CU block recursively with enabling sub-LCU-level delta QP |
---|
438 | *\param rpcBestCU |
---|
439 | *\param rpcTempCU |
---|
440 | *\param uiDepth |
---|
441 | *\returns Void |
---|
442 | * |
---|
443 | *- for loop of QP value to compress the current CU with all possible QP |
---|
444 | */ |
---|
445 | #if AMP_ENC_SPEEDUP |
---|
446 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize ) |
---|
447 | #else |
---|
448 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
449 | #endif |
---|
450 | { |
---|
451 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
452 | |
---|
453 | #if OL_DEPTHLIMIT_A0044 |
---|
454 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
---|
455 | TComPic *pcTexture; |
---|
456 | TComDataCU * pcTextureCU; |
---|
457 | Bool depthMapDetect = false; |
---|
458 | #if !LGE_CLEAN_UP |
---|
459 | UInt uiPrevTexPartIndex = 0; |
---|
460 | #endif |
---|
461 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
462 | Bool bIntraSliceDetect = false; |
---|
463 | #endif |
---|
464 | Bool bTry2NxN = false; |
---|
465 | Bool bTryNx2N = false; |
---|
466 | pcTexture = rpcBestCU->getSlice()->getTexturePic(); |
---|
467 | if(pcTexture != NULL) //depth map being encoded |
---|
468 | { |
---|
469 | depthMapDetect = true; |
---|
470 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
471 | bIntraSliceDetect = (rpcBestCU->getSlice()->getSliceType()==I_SLICE); |
---|
472 | #endif |
---|
473 | if(uiDepth == 0) |
---|
474 | { |
---|
475 | pcTextureCU = pcTexture->getCU( rpcBestCU->getAddr() ); |
---|
476 | pcTexture->setPartInfo(pcTextureCU->readPartInfo()); |
---|
477 | pcTexture->setTexPartIndex(0); |
---|
478 | } |
---|
479 | } |
---|
480 | else |
---|
481 | { |
---|
482 | depthMapDetect = false; |
---|
483 | } |
---|
484 | #endif |
---|
485 | // get Original YUV data from picture |
---|
486 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
487 | |
---|
488 | // variables for fast encoder decision |
---|
489 | Bool bEarlySkip = false; |
---|
490 | Bool bTrySplit = true; |
---|
491 | Double fRD_Skip = MAX_DOUBLE; |
---|
492 | |
---|
493 | // variable for Early CU determination |
---|
494 | Bool bSubBranch = true; |
---|
495 | |
---|
496 | // variable for Cbf fast mode PU decision |
---|
497 | Bool doNotBlockPu = true; |
---|
498 | |
---|
499 | Bool bTrySplitDQP = true; |
---|
500 | |
---|
501 | static Double afCost [ MAX_CU_DEPTH ]; |
---|
502 | static Int aiNum [ MAX_CU_DEPTH ]; |
---|
503 | |
---|
504 | if ( rpcBestCU->getAddr() == 0 ) |
---|
505 | { |
---|
506 | ::memset( afCost, 0, sizeof( afCost ) ); |
---|
507 | ::memset( aiNum, 0, sizeof( aiNum ) ); |
---|
508 | } |
---|
509 | |
---|
510 | Bool bBoundary = false; |
---|
511 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
512 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
513 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
514 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
515 | |
---|
516 | #if LGE_ILLUCOMP_B0045 |
---|
517 | Bool bICEnabled = (!rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getViewId()); |
---|
518 | |
---|
519 | bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC(); |
---|
520 | #endif |
---|
521 | |
---|
522 | #if HHI_INTERVIEW_SKIP |
---|
523 | Bool bFullyRenderedSec = true ; |
---|
524 | if( m_pcEncCfg->getInterViewSkip() ) |
---|
525 | { |
---|
526 | Pel* pUsedSamples ; |
---|
527 | UInt uiStride ; |
---|
528 | pUsedSamples = pcPic->getUsedPelsMap()->getLumaAddr( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
529 | uiStride = pcPic->getUsedPelsMap()->getStride(); |
---|
530 | |
---|
531 | for ( Int y=0; y<m_ppcOrigYuv[uiDepth]->getHeight(); y++) |
---|
532 | { |
---|
533 | for ( Int x=0; x<m_ppcOrigYuv[uiDepth]->getWidth(); x++) |
---|
534 | { |
---|
535 | if( pUsedSamples[x] !=0 ) |
---|
536 | { |
---|
537 | bFullyRenderedSec = false ; |
---|
538 | break ; |
---|
539 | } |
---|
540 | } |
---|
541 | if ( !bFullyRenderedSec ) |
---|
542 | { |
---|
543 | break; |
---|
544 | } |
---|
545 | pUsedSamples += uiStride ; |
---|
546 | } |
---|
547 | } |
---|
548 | else |
---|
549 | { |
---|
550 | bFullyRenderedSec = false ; |
---|
551 | } |
---|
552 | |
---|
553 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
554 | if( bFullyRenderedSec ) |
---|
555 | { |
---|
556 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
557 | } |
---|
558 | else |
---|
559 | { |
---|
560 | m_pcRdCost->setLambdaScale( 1 ); |
---|
561 | } |
---|
562 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
563 | #endif |
---|
564 | |
---|
565 | #endif |
---|
566 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
---|
567 | Int iMinQP; |
---|
568 | Int iMaxQP; |
---|
569 | #if LOSSLESS_CODING |
---|
570 | Bool isAddLowestQP = false; |
---|
571 | #if H0736_AVC_STYLE_QP_RANGE |
---|
572 | Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
573 | #else |
---|
574 | Int lowestQP = 0; |
---|
575 | #endif |
---|
576 | #endif |
---|
577 | |
---|
578 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
579 | { |
---|
580 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
581 | #if H0736_AVC_STYLE_QP_RANGE |
---|
582 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
583 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
584 | #if LOSSLESS_CODING |
---|
585 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
586 | { |
---|
587 | isAddLowestQP = true; |
---|
588 | iMinQP = iMinQP - 1; |
---|
589 | |
---|
590 | } |
---|
591 | #endif |
---|
592 | #else |
---|
593 | iMinQP = Clip3( MIN_QP, MAX_QP, iBaseQP-idQP ); |
---|
594 | iMaxQP = Clip3( MIN_QP, MAX_QP, iBaseQP+idQP ); |
---|
595 | #if LOSSLESS_CODING |
---|
596 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
597 | { |
---|
598 | isAddLowestQP = true; |
---|
599 | iMinQP = iMinQP - 1; |
---|
600 | } |
---|
601 | #endif |
---|
602 | #endif |
---|
603 | } |
---|
604 | else |
---|
605 | { |
---|
606 | iMinQP = rpcTempCU->getQP(0); |
---|
607 | iMaxQP = rpcTempCU->getQP(0); |
---|
608 | } |
---|
609 | |
---|
610 | // If slice start or slice end is within this cu... |
---|
611 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
612 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getEntropySliceCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart(); |
---|
613 | Bool bSliceEnd = (pcSlice->getEntropySliceCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getEntropySliceCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart()); |
---|
614 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
615 | // We need to split, so don't try these modes. |
---|
616 | if(!bSliceEnd && !bSliceStart && bInsidePicture ) |
---|
617 | { |
---|
618 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
619 | { |
---|
620 | #if LOSSLESS_CODING |
---|
621 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
622 | { |
---|
623 | iQP = lowestQP; |
---|
624 | } |
---|
625 | #endif |
---|
626 | // variables for fast encoder decision |
---|
627 | bEarlySkip = false; |
---|
628 | bTrySplit = true; |
---|
629 | fRD_Skip = MAX_DOUBLE; |
---|
630 | |
---|
631 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
632 | |
---|
633 | #if OL_DEPTHLIMIT_A0044 |
---|
634 | //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU |
---|
635 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
636 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
637 | #else |
---|
638 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
639 | #endif |
---|
640 | { |
---|
641 | assert(uiDepth == pcTexture->accessPartInfo(1)); |
---|
642 | if(pcTexture->accessPartInfo(0) == 1) //NxN modes |
---|
643 | { |
---|
644 | bTrySplit = true; |
---|
645 | bTryNx2N = true; |
---|
646 | bTry2NxN = true; |
---|
647 | #if !LGE_CLEAN_UP |
---|
648 | uiPrevTexPartIndex = pcTexture->getTexPartIndex(); |
---|
649 | #endif |
---|
650 | pcTexture->incrementTexPartIndex(); |
---|
651 | } |
---|
652 | else if(pcTexture->accessPartInfo(0) == 0) //2Nx2N modes |
---|
653 | { |
---|
654 | UInt uiTexdepth; |
---|
655 | UInt temp_uiTexPartIndex; |
---|
656 | bTrySplit = false; |
---|
657 | |
---|
658 | //scan ahead till next depth |
---|
659 | uiTexdepth = pcTexture->accessPartInfo(1); |
---|
660 | #if !LGE_CLEAN_UP |
---|
661 | uiPrevTexPartIndex = pcTexture->getTexPartIndex(); |
---|
662 | #endif |
---|
663 | pcTexture->incrementTexPartIndex(); |
---|
664 | temp_uiTexPartIndex = pcTexture->getTexPartIndex(); //store in case to rewind |
---|
665 | |
---|
666 | while(uiTexdepth != pcTexture->accessPartInfo(1) && uiTexdepth != 0) |
---|
667 | { |
---|
668 | if(pcTexture->accessPartInfo(1) < uiTexdepth) |
---|
669 | { |
---|
670 | break; |
---|
671 | } |
---|
672 | pcTexture->incrementTexPartIndex(); |
---|
673 | |
---|
674 | if(pcTexture->accessPartInfo(1) == OL_END_CU) |
---|
675 | { |
---|
676 | pcTexture->setTexPartIndex(temp_uiTexPartIndex); |
---|
677 | uiTexdepth++; |
---|
678 | if(uiTexdepth >= g_uiMaxCUDepth) |
---|
679 | { |
---|
680 | break; |
---|
681 | } |
---|
682 | } |
---|
683 | } |
---|
684 | } |
---|
685 | else if(pcTexture->accessPartInfo(0) == OL_END_CU) |
---|
686 | { |
---|
687 | bTrySplit = false; |
---|
688 | bTryNx2N = false; |
---|
689 | bTry2NxN = false; |
---|
690 | } |
---|
691 | else if(pcTexture->accessPartInfo(0) == 2) //2NxN case |
---|
692 | { |
---|
693 | bTrySplit = false; |
---|
694 | bTryNx2N = false; |
---|
695 | bTry2NxN = true; |
---|
696 | #if !LGE_CLEAN_UP |
---|
697 | uiPrevTexPartIndex = pcTexture->getTexPartIndex(); |
---|
698 | #endif |
---|
699 | pcTexture->incrementTexPartIndex(); ; |
---|
700 | } |
---|
701 | else if(pcTexture->accessPartInfo(0) == 3) //Nx2N case |
---|
702 | { |
---|
703 | bTrySplit = false; |
---|
704 | bTryNx2N = true; |
---|
705 | bTry2NxN = false; |
---|
706 | #if !LGE_CLEAN_UP |
---|
707 | uiPrevTexPartIndex = pcTexture->getTexPartIndex(); |
---|
708 | #endif |
---|
709 | pcTexture->incrementTexPartIndex(); ; |
---|
710 | } |
---|
711 | } |
---|
712 | #endif |
---|
713 | |
---|
714 | |
---|
715 | // do inter modes, SKIP and 2Nx2N |
---|
716 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
717 | { |
---|
718 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
719 | // check availability of residual prediction |
---|
720 | Bool bResPredAvailable = false; |
---|
721 | Bool bResPredAllowed = (!rpcBestCU->getSlice()->getSPS()->isDepth () ); |
---|
722 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId () ); |
---|
723 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
---|
724 | if( bResPredAllowed ) |
---|
725 | { |
---|
726 | bResPredAvailable = rpcBestCU->getResidualSamples( 0, |
---|
727 | #if QC_SIMPLIFIEDIVRP_M24938 |
---|
728 | true , |
---|
729 | #endif |
---|
730 | m_ppcResPredTmp[uiDepth] ); |
---|
731 | } |
---|
732 | |
---|
733 | for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ ) |
---|
734 | { |
---|
735 | Bool bResPredFlag = ( uiResPrdId > 0 ); |
---|
736 | #if LGE_ILLUCOMP_B0045 |
---|
737 | for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++) |
---|
738 | { |
---|
739 | Bool bICFlag = (uiICId ? true : false); |
---|
740 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
741 | #endif |
---|
742 | #endif |
---|
743 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
744 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
745 | #endif |
---|
746 | // SKIP |
---|
747 | #if HHI_INTERVIEW_SKIP |
---|
748 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, bFullyRenderedSec ); |
---|
749 | #else |
---|
750 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU ); |
---|
751 | #endif |
---|
752 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
753 | |
---|
754 | // fast encoder decision for early skip |
---|
755 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
756 | { |
---|
757 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
758 | if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] ) |
---|
759 | { |
---|
760 | bEarlySkip = true; |
---|
761 | bTrySplit = false; |
---|
762 | } |
---|
763 | } |
---|
764 | #if LGE_ILLUCOMP_B0045_ENCSIMP |
---|
765 | if(bICFlag && rpcBestCU->getMergeFlag(0) && !rpcBestCU->getICFlag(0)) |
---|
766 | { |
---|
767 | bICEnabled = false; |
---|
768 | break; |
---|
769 | } |
---|
770 | #endif |
---|
771 | // 2Nx2N, NxN |
---|
772 | if ( !bEarlySkip ) |
---|
773 | { |
---|
774 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
775 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
776 | #endif |
---|
777 | #if HHI_INTERVIEW_SKIP |
---|
778 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); |
---|
779 | |
---|
780 | #else |
---|
781 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
782 | #endif |
---|
783 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
784 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
785 | { |
---|
786 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
787 | } |
---|
788 | } |
---|
789 | #if LGE_ILLUCOMP_B0045 |
---|
790 | } |
---|
791 | #endif |
---|
792 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
793 | } // uiResPrdId |
---|
794 | #endif |
---|
795 | } // != I_SLICE |
---|
796 | |
---|
797 | #if LGE_ILLUCOMP_B0045_ENCSIMP |
---|
798 | bICEnabled = rpcBestCU->getICFlag(0); |
---|
799 | #endif |
---|
800 | |
---|
801 | #if OL_DEPTHLIMIT_A0044 |
---|
802 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
803 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
804 | #else |
---|
805 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
806 | #endif |
---|
807 | { |
---|
808 | bTrySplitDQP = bTrySplit; |
---|
809 | } |
---|
810 | else |
---|
811 | { |
---|
812 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
813 | { |
---|
814 | if(iQP == iBaseQP) |
---|
815 | { |
---|
816 | bTrySplitDQP = bTrySplit; |
---|
817 | } |
---|
818 | } |
---|
819 | else |
---|
820 | { |
---|
821 | bTrySplitDQP = bTrySplit; |
---|
822 | } |
---|
823 | } |
---|
824 | #else |
---|
825 | |
---|
826 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
827 | { |
---|
828 | if(iQP == iBaseQP) |
---|
829 | { |
---|
830 | bTrySplitDQP = bTrySplit; |
---|
831 | } |
---|
832 | } |
---|
833 | else |
---|
834 | { |
---|
835 | bTrySplitDQP = bTrySplit; |
---|
836 | } |
---|
837 | #endif |
---|
838 | #if LOSSLESS_CODING |
---|
839 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
840 | { |
---|
841 | iQP = iMinQP; |
---|
842 | } |
---|
843 | #endif |
---|
844 | } // end for iMinQP to iMaxQP |
---|
845 | |
---|
846 | |
---|
847 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
848 | { |
---|
849 | #if LOSSLESS_CODING |
---|
850 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
851 | { |
---|
852 | iQP = lowestQP; |
---|
853 | } |
---|
854 | #endif |
---|
855 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
856 | |
---|
857 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
858 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
859 | { |
---|
860 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
861 | // check availability of residual prediction |
---|
862 | Bool bResPredAvailable = false; |
---|
863 | Bool bResPredAllowed = (!rpcBestCU->getSlice()->getSPS()->isDepth () ); |
---|
864 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId () ); |
---|
865 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
---|
866 | if( bResPredAllowed ) |
---|
867 | { |
---|
868 | bResPredAvailable = rpcBestCU->getResidualSamples( 0, |
---|
869 | #if QC_SIMPLIFIEDIVRP_M24938 |
---|
870 | true, |
---|
871 | #endif |
---|
872 | m_ppcResPredTmp[uiDepth] ); |
---|
873 | } |
---|
874 | |
---|
875 | for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ ) |
---|
876 | { |
---|
877 | Bool bResPredFlag = ( uiResPrdId > 0 ); |
---|
878 | #if LGE_ILLUCOMP_B0045 |
---|
879 | for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++) |
---|
880 | { |
---|
881 | Bool bICFlag = (uiICId ? true : false); |
---|
882 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
883 | #endif |
---|
884 | #endif |
---|
885 | // 2Nx2N, NxN |
---|
886 | if ( !bEarlySkip ) |
---|
887 | { |
---|
888 | |
---|
889 | if(!( rpcBestCU->getSlice()->getSPS()->getDisInter4x4() && (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
890 | { |
---|
891 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu) |
---|
892 | { |
---|
893 | #if OL_DEPTHLIMIT_A0044 //add code here to select 2NxN or Nx2N or none |
---|
894 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
895 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
896 | #else |
---|
897 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
898 | #endif |
---|
899 | { |
---|
900 | if (bTrySplit) |
---|
901 | { |
---|
902 | #endif |
---|
903 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
904 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
905 | #endif |
---|
906 | #if HHI_INTERVIEW_SKIP |
---|
907 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFullyRenderedSec ); |
---|
908 | #else |
---|
909 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
910 | #endif |
---|
911 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
912 | #if OL_DEPTHLIMIT_A0044 |
---|
913 | }//bTrySplit |
---|
914 | }//depthMapDetect |
---|
915 | else//do things normally |
---|
916 | { |
---|
917 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
918 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
919 | #endif |
---|
920 | #if HHI_INTERVIEW_SKIP |
---|
921 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFullyRenderedSec ); |
---|
922 | #else |
---|
923 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
924 | #endif |
---|
925 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
926 | } |
---|
927 | #endif |
---|
928 | } |
---|
929 | } |
---|
930 | } |
---|
931 | |
---|
932 | { // 2NxN, Nx2N |
---|
933 | #if OL_DEPTHLIMIT_A0044 //add code here to select 2NxN or Nx2N or none |
---|
934 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
935 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
936 | #else |
---|
937 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
938 | #endif |
---|
939 | { |
---|
940 | if (bTryNx2N) |
---|
941 | { |
---|
942 | #endif |
---|
943 | if(doNotBlockPu) |
---|
944 | { |
---|
945 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
946 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
947 | #endif |
---|
948 | #if HHI_INTERVIEW_SKIP |
---|
949 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFullyRenderedSec ); |
---|
950 | #else |
---|
951 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); |
---|
952 | #endif |
---|
953 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
954 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
955 | { |
---|
956 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
957 | } |
---|
958 | } |
---|
959 | #if OL_DEPTHLIMIT_A0044 |
---|
960 | }//bTryNx2N |
---|
961 | }//depthMapDetect |
---|
962 | else//do things normally |
---|
963 | { |
---|
964 | if(doNotBlockPu) |
---|
965 | { |
---|
966 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
967 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
968 | #endif |
---|
969 | #if HHI_INTERVIEW_SKIP |
---|
970 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFullyRenderedSec ); |
---|
971 | #else |
---|
972 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); |
---|
973 | #endif |
---|
974 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
975 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
976 | { |
---|
977 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
978 | } |
---|
979 | } |
---|
980 | } |
---|
981 | #endif |
---|
982 | |
---|
983 | #if OL_DEPTHLIMIT_A0044 //add code here to select 2NxN or Nx2N or none |
---|
984 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
985 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
986 | #else |
---|
987 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
988 | #endif |
---|
989 | { |
---|
990 | if (bTry2NxN) |
---|
991 | { |
---|
992 | #endif |
---|
993 | if(doNotBlockPu) |
---|
994 | { |
---|
995 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
996 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
997 | #endif |
---|
998 | #if HHI_INTERVIEW_SKIP |
---|
999 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxN, bFullyRenderedSec ); |
---|
1000 | #else |
---|
1001 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); |
---|
1002 | #endif |
---|
1003 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1004 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
1005 | { |
---|
1006 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1007 | } |
---|
1008 | } |
---|
1009 | #if OL_DEPTHLIMIT_A0044 |
---|
1010 | }//bTryNx2N |
---|
1011 | }//depthMapDetect |
---|
1012 | else//do things normally |
---|
1013 | { |
---|
1014 | if(doNotBlockPu) |
---|
1015 | { |
---|
1016 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1017 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1018 | #endif |
---|
1019 | #if HHI_INTERVIEW_SKIP |
---|
1020 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxN, bFullyRenderedSec ); |
---|
1021 | #else |
---|
1022 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); |
---|
1023 | #endif |
---|
1024 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1025 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
1026 | { |
---|
1027 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1028 | } |
---|
1029 | } |
---|
1030 | } |
---|
1031 | #endif |
---|
1032 | } |
---|
1033 | |
---|
1034 | #if 1 |
---|
1035 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
1036 | if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) |
---|
1037 | { |
---|
1038 | #if AMP_ENC_SPEEDUP |
---|
1039 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
1040 | |
---|
1041 | #if AMP_MRG |
---|
1042 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
1043 | |
---|
1044 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
1045 | #else |
---|
1046 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
1047 | #endif |
---|
1048 | |
---|
1049 | //! Do horizontal AMP |
---|
1050 | if ( bTestAMP_Hor ) |
---|
1051 | { |
---|
1052 | #if OL_DEPTHLIMIT_A0044 //add code here to select 2NxN or Nx2N or none |
---|
1053 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
1054 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
1055 | #else |
---|
1056 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
1057 | #endif |
---|
1058 | { |
---|
1059 | if (bTry2NxN) |
---|
1060 | { |
---|
1061 | #endif |
---|
1062 | if(doNotBlockPu) |
---|
1063 | { |
---|
1064 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1065 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1066 | #endif |
---|
1067 | #if HHI_INTERVIEW_SKIP |
---|
1068 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec ); |
---|
1069 | #else |
---|
1070 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
1071 | #endif |
---|
1072 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1073 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
1074 | { |
---|
1075 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1076 | } |
---|
1077 | } |
---|
1078 | if(doNotBlockPu) |
---|
1079 | { |
---|
1080 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1081 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1082 | #endif |
---|
1083 | #if HHI_INTERVIEW_SKIP |
---|
1084 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec ); |
---|
1085 | #else |
---|
1086 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
1087 | #endif |
---|
1088 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1089 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
1090 | { |
---|
1091 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1092 | } |
---|
1093 | } |
---|
1094 | #if OL_DEPTHLIMIT_A0044 |
---|
1095 | }//bTry2NxN |
---|
1096 | }//depthMapDetect |
---|
1097 | else//do things normally |
---|
1098 | { |
---|
1099 | if(doNotBlockPu) |
---|
1100 | { |
---|
1101 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1102 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1103 | #endif |
---|
1104 | #if HHI_INTERVIEW_SKIP |
---|
1105 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec ); |
---|
1106 | #else |
---|
1107 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
1108 | #endif |
---|
1109 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1110 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
1111 | { |
---|
1112 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1113 | } |
---|
1114 | } |
---|
1115 | if(doNotBlockPu) |
---|
1116 | { |
---|
1117 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1118 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1119 | #endif |
---|
1120 | #if HHI_INTERVIEW_SKIP |
---|
1121 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec ); |
---|
1122 | #else |
---|
1123 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
1124 | #endif |
---|
1125 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1126 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
1127 | { |
---|
1128 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1129 | } |
---|
1130 | } |
---|
1131 | } |
---|
1132 | #endif |
---|
1133 | } |
---|
1134 | #if AMP_MRG |
---|
1135 | else if ( bTestMergeAMP_Hor ) |
---|
1136 | { |
---|
1137 | #if OL_DEPTHLIMIT_A0044 //add code here to select 2NxN or Nx2N or none |
---|
1138 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
1139 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
1140 | #else |
---|
1141 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
1142 | #endif |
---|
1143 | { |
---|
1144 | if (bTry2NxN) |
---|
1145 | { |
---|
1146 | #endif |
---|
1147 | if(doNotBlockPu) |
---|
1148 | { |
---|
1149 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1150 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1151 | #endif |
---|
1152 | #if HHI_INTERVIEW_SKIP |
---|
1153 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec, true ); |
---|
1154 | #else |
---|
1155 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); |
---|
1156 | #endif |
---|
1157 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1158 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
1159 | { |
---|
1160 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1161 | } |
---|
1162 | } |
---|
1163 | if(doNotBlockPu) |
---|
1164 | { |
---|
1165 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1166 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1167 | #endif |
---|
1168 | #if HHI_INTERVIEW_SKIP |
---|
1169 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec, true ); |
---|
1170 | #else |
---|
1171 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); |
---|
1172 | #endif |
---|
1173 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1174 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
1175 | { |
---|
1176 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1177 | } |
---|
1178 | } |
---|
1179 | #if OL_DEPTHLIMIT_A0044 |
---|
1180 | }//bTry2NxN |
---|
1181 | }//depthMapDetect |
---|
1182 | else//do things normally |
---|
1183 | { |
---|
1184 | if(doNotBlockPu) |
---|
1185 | { |
---|
1186 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1187 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1188 | #endif |
---|
1189 | #if HHI_INTERVIEW_SKIP |
---|
1190 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec, true ); |
---|
1191 | #else |
---|
1192 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); |
---|
1193 | #endif |
---|
1194 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1195 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
1196 | { |
---|
1197 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1198 | } |
---|
1199 | } |
---|
1200 | if(doNotBlockPu) |
---|
1201 | { |
---|
1202 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1203 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1204 | #endif |
---|
1205 | #if HHI_INTERVIEW_SKIP |
---|
1206 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec, true ); |
---|
1207 | #else |
---|
1208 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); |
---|
1209 | #endif |
---|
1210 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1211 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
1212 | { |
---|
1213 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1214 | } |
---|
1215 | } |
---|
1216 | |
---|
1217 | } |
---|
1218 | #endif |
---|
1219 | } |
---|
1220 | #endif |
---|
1221 | |
---|
1222 | //! Do horizontal AMP |
---|
1223 | if ( bTestAMP_Ver ) |
---|
1224 | { |
---|
1225 | #if OL_DEPTHLIMIT_A0044 //add code here to select 2NxN or Nx2N or none |
---|
1226 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
1227 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
1228 | #else |
---|
1229 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
1230 | #endif |
---|
1231 | { |
---|
1232 | if (bTryNx2N) |
---|
1233 | { |
---|
1234 | #endif |
---|
1235 | if(doNotBlockPu) |
---|
1236 | { |
---|
1237 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1238 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1239 | #endif |
---|
1240 | #if HHI_INTERVIEW_SKIP |
---|
1241 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec ); |
---|
1242 | #else |
---|
1243 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
1244 | #endif |
---|
1245 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1246 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
1247 | { |
---|
1248 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1249 | } |
---|
1250 | } |
---|
1251 | if(doNotBlockPu) |
---|
1252 | { |
---|
1253 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1254 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1255 | #endif |
---|
1256 | #if HHI_INTERVIEW_SKIP |
---|
1257 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec ); |
---|
1258 | #else |
---|
1259 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
1260 | #endif |
---|
1261 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1262 | } |
---|
1263 | #if OL_DEPTHLIMIT_A0044 |
---|
1264 | }//bTryNx2N |
---|
1265 | }//depthMapDetect |
---|
1266 | else//do things normally |
---|
1267 | { |
---|
1268 | if(doNotBlockPu) |
---|
1269 | { |
---|
1270 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1271 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1272 | #endif |
---|
1273 | #if HHI_INTERVIEW_SKIP |
---|
1274 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec ); |
---|
1275 | #else |
---|
1276 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
1277 | #endif |
---|
1278 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1279 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
1280 | { |
---|
1281 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1282 | } |
---|
1283 | } |
---|
1284 | if(doNotBlockPu) |
---|
1285 | { |
---|
1286 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1287 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1288 | #endif |
---|
1289 | #if HHI_INTERVIEW_SKIP |
---|
1290 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec ); |
---|
1291 | #else |
---|
1292 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
1293 | #endif |
---|
1294 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1295 | } |
---|
1296 | } |
---|
1297 | #endif |
---|
1298 | } |
---|
1299 | #if AMP_MRG |
---|
1300 | else if ( bTestMergeAMP_Ver ) |
---|
1301 | { |
---|
1302 | #if OL_DEPTHLIMIT_A0044 //add code here to select 2NxN or Nx2N or none |
---|
1303 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
1304 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
1305 | #else |
---|
1306 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
1307 | #endif |
---|
1308 | { |
---|
1309 | if (bTryNx2N) |
---|
1310 | { |
---|
1311 | #endif |
---|
1312 | if(doNotBlockPu) |
---|
1313 | { |
---|
1314 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1315 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1316 | #endif |
---|
1317 | #if HHI_INTERVIEW_SKIP |
---|
1318 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec, true ); |
---|
1319 | #else |
---|
1320 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); |
---|
1321 | #endif |
---|
1322 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1323 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
1324 | { |
---|
1325 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1326 | } |
---|
1327 | } |
---|
1328 | if(doNotBlockPu) |
---|
1329 | { |
---|
1330 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1331 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1332 | #endif |
---|
1333 | #if HHI_INTERVIEW_SKIP |
---|
1334 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec, true ); |
---|
1335 | #else |
---|
1336 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); |
---|
1337 | #endif |
---|
1338 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1339 | } |
---|
1340 | #if OL_DEPTHLIMIT_A0044 |
---|
1341 | }//bTryNx2N |
---|
1342 | }//depthMapDetect |
---|
1343 | else//do things normally |
---|
1344 | { |
---|
1345 | if(doNotBlockPu) |
---|
1346 | { |
---|
1347 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1348 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1349 | #endif |
---|
1350 | #if HHI_INTERVIEW_SKIP |
---|
1351 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec, true ); |
---|
1352 | #else |
---|
1353 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); |
---|
1354 | #endif |
---|
1355 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1356 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
1357 | { |
---|
1358 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1359 | } |
---|
1360 | } |
---|
1361 | if(doNotBlockPu) |
---|
1362 | { |
---|
1363 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1364 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1365 | #endif |
---|
1366 | #if HHI_INTERVIEW_SKIP |
---|
1367 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec, true ); |
---|
1368 | #else |
---|
1369 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); |
---|
1370 | #endif |
---|
1371 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1372 | } |
---|
1373 | } |
---|
1374 | #endif |
---|
1375 | } |
---|
1376 | #endif |
---|
1377 | |
---|
1378 | #else |
---|
1379 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1380 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1381 | #endif |
---|
1382 | #if HHI_INTERVIEW_SKIP |
---|
1383 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec ); |
---|
1384 | #else |
---|
1385 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
1386 | #endif |
---|
1387 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1388 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1389 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1390 | #endif |
---|
1391 | #if HHI_INTERVIEW_SKIP |
---|
1392 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec ); |
---|
1393 | #else |
---|
1394 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
1395 | #endif |
---|
1396 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1397 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1398 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1399 | #endif |
---|
1400 | #if HHI_INTERVIEW_SKIP |
---|
1401 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec ); |
---|
1402 | #else |
---|
1403 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
1404 | #endif |
---|
1405 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1406 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1407 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1408 | #endif |
---|
1409 | #if HHI_INTERVIEW_SKIP |
---|
1410 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec ); |
---|
1411 | #else |
---|
1412 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
1413 | #endif |
---|
1414 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1415 | |
---|
1416 | #endif |
---|
1417 | } //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
1418 | #endif |
---|
1419 | #if LGE_ILLUCOMP_B0045 |
---|
1420 | } |
---|
1421 | #endif |
---|
1422 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1423 | } // uiResPrdId |
---|
1424 | #endif |
---|
1425 | } // != I_SLICE |
---|
1426 | |
---|
1427 | // initialize PCM flag |
---|
1428 | rpcTempCU->setIPCMFlag( 0, false); |
---|
1429 | rpcTempCU->setIPCMFlagSubParts ( false, 0, uiDepth); //SUB_LCU_DQP |
---|
1430 | |
---|
1431 | // do normal intra modes |
---|
1432 | if ( !bEarlySkip ) |
---|
1433 | { |
---|
1434 | // speedup for inter frames |
---|
1435 | #if HHI_INTERVIEW_SKIP |
---|
1436 | if( ( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
1437 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
1438 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
1439 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) && !bFullyRenderedSec ) // avoid very complex intra if it is unlikely |
---|
1440 | #else |
---|
1441 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
1442 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
1443 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
1444 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely |
---|
1445 | #endif |
---|
1446 | { |
---|
1447 | #if LGE_ILLUCOMP_B0045 |
---|
1448 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
---|
1449 | #endif |
---|
1450 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
1451 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1452 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1453 | { |
---|
1454 | #if OL_DEPTHLIMIT_A0044 //add code here to select or deselect NxN mode for Intra |
---|
1455 | #if OL_DO_NOT_LIMIT_INTRA_SLICES_PART |
---|
1456 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseDPL()) |
---|
1457 | #else |
---|
1458 | if(depthMapDetect && sps->getUseDPL()) //depth map being encoded |
---|
1459 | #endif |
---|
1460 | { |
---|
1461 | if (bTrySplit) |
---|
1462 | { |
---|
1463 | |
---|
1464 | #endif |
---|
1465 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
1466 | { |
---|
1467 | #if LGE_ILLUCOMP_B0045 |
---|
1468 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
---|
1469 | #endif |
---|
1470 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
1471 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1472 | } |
---|
1473 | #if OL_DEPTHLIMIT_A0044 |
---|
1474 | }//bTrySplit |
---|
1475 | }//depthMapDetect |
---|
1476 | else |
---|
1477 | { |
---|
1478 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
1479 | { |
---|
1480 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
1481 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1482 | } |
---|
1483 | } |
---|
1484 | #endif |
---|
1485 | } |
---|
1486 | } |
---|
1487 | } |
---|
1488 | |
---|
1489 | // test PCM |
---|
1490 | if(pcPic->getSlice(0)->getSPS()->getUsePCM() |
---|
1491 | && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) |
---|
1492 | && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) |
---|
1493 | { |
---|
1494 | UInt uiRawBits = (g_uiBitDepth * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) * 3 / 2); |
---|
1495 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
1496 | #if HHI_VSO |
---|
1497 | Double dRDCostTemp = m_pcRdCost->getUseVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0); |
---|
1498 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp )) |
---|
1499 | #else |
---|
1500 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
1501 | #endif |
---|
1502 | { |
---|
1503 | #if LGE_ILLUCOMP_B0045 |
---|
1504 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
---|
1505 | #endif |
---|
1506 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
1507 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1508 | } |
---|
1509 | } |
---|
1510 | #if HHI_MPI |
---|
1511 | if( rpcBestCU->getSlice()->getSPS()->getUseMVI() && rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
1512 | { |
---|
1513 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, false, false ); |
---|
1514 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1515 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, true, false ); |
---|
1516 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1517 | } |
---|
1518 | #endif |
---|
1519 | #if LOSSLESS_CODING |
---|
1520 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
1521 | { |
---|
1522 | iQP = iMinQP; |
---|
1523 | } |
---|
1524 | #endif |
---|
1525 | } |
---|
1526 | |
---|
1527 | m_pcEntropyCoder->resetBits(); |
---|
1528 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
1529 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1530 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1531 | { |
---|
1532 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1533 | } |
---|
1534 | |
---|
1535 | #if HHI_VSO |
---|
1536 | if ( m_pcRdCost->getUseVSO() ) |
---|
1537 | { |
---|
1538 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
1539 | } |
---|
1540 | else |
---|
1541 | #endif |
---|
1542 | { |
---|
1543 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
1544 | } |
---|
1545 | |
---|
1546 | // accumulate statistics for early skip |
---|
1547 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
1548 | { |
---|
1549 | if ( rpcBestCU->isSkipped(0) ) |
---|
1550 | { |
---|
1551 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
1552 | afCost[ iIdx ] += rpcBestCU->getTotalCost(); |
---|
1553 | aiNum [ iIdx ] ++; |
---|
1554 | } |
---|
1555 | } |
---|
1556 | |
---|
1557 | // Early CU determination |
---|
1558 | if( m_pcEncCfg->getUseEarlyCU() && ((*rpcBestCU->getPredictionMode()) == 0) ) |
---|
1559 | { |
---|
1560 | bSubBranch = false; |
---|
1561 | } |
---|
1562 | else |
---|
1563 | { |
---|
1564 | bSubBranch = true; |
---|
1565 | } |
---|
1566 | #if HHI_INTERVIEW_SKIP |
---|
1567 | rpcBestCU->setRenderableSubParts(bFullyRenderedSec,0,rpcBestCU->getDepth( 0 )) ; |
---|
1568 | #endif |
---|
1569 | } |
---|
1570 | else if(!(bSliceEnd && bInsidePicture)) |
---|
1571 | { |
---|
1572 | bBoundary = true; |
---|
1573 | } |
---|
1574 | |
---|
1575 | #if LOSSLESS_CODING |
---|
1576 | // copy orginal YUV samples to PCM buffer |
---|
1577 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
1578 | { |
---|
1579 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
1580 | } |
---|
1581 | #endif |
---|
1582 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
1583 | { |
---|
1584 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
1585 | #if H0736_AVC_STYLE_QP_RANGE |
---|
1586 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
1587 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
1588 | #if LOSSLESS_CODING |
---|
1589 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
1590 | { |
---|
1591 | isAddLowestQP = true; |
---|
1592 | iMinQP = iMinQP - 1; |
---|
1593 | } |
---|
1594 | #endif |
---|
1595 | #else |
---|
1596 | iMinQP = Clip3( MIN_QP, MAX_QP, iBaseQP-idQP ); |
---|
1597 | iMaxQP = Clip3( MIN_QP, MAX_QP, iBaseQP+idQP ); |
---|
1598 | #if LOSSLESS_CODING |
---|
1599 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
1600 | { |
---|
1601 | isAddLowestQP = true; |
---|
1602 | iMinQP = iMinQP - 1; |
---|
1603 | } |
---|
1604 | #endif |
---|
1605 | #endif |
---|
1606 | } |
---|
1607 | else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
1608 | { |
---|
1609 | iMinQP = iBaseQP; |
---|
1610 | iMaxQP = iBaseQP; |
---|
1611 | } |
---|
1612 | else |
---|
1613 | { |
---|
1614 | Int iStartQP; |
---|
1615 | if( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getEntropySliceCurStartCUAddr()) |
---|
1616 | { |
---|
1617 | iStartQP = rpcTempCU->getQP(0); |
---|
1618 | } |
---|
1619 | else |
---|
1620 | { |
---|
1621 | UInt uiCurSliceStartPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
1622 | iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx); |
---|
1623 | } |
---|
1624 | iMinQP = iStartQP; |
---|
1625 | iMaxQP = iStartQP; |
---|
1626 | } |
---|
1627 | |
---|
1628 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
1629 | { |
---|
1630 | #if LOSSLESS_CODING |
---|
1631 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
1632 | { |
---|
1633 | iQP = lowestQP; |
---|
1634 | } |
---|
1635 | #endif |
---|
1636 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1637 | |
---|
1638 | // further split |
---|
1639 | if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1640 | { |
---|
1641 | #if HHI_VSO |
---|
1642 | // reset Model |
---|
1643 | if( m_pcRdCost->getUseRenModel() ) |
---|
1644 | { |
---|
1645 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( ); |
---|
1646 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight( ); |
---|
1647 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
---|
1648 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
1649 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1650 | } |
---|
1651 | #endif |
---|
1652 | UChar uhNextDepth = uiDepth+1; |
---|
1653 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
1654 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
1655 | |
---|
1656 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
1657 | { |
---|
1658 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
1659 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
1660 | |
---|
1661 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getEntropySliceCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getEntropySliceCurEndCUAddr(); |
---|
1662 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1663 | { |
---|
1664 | if( m_bUseSBACRD ) |
---|
1665 | { |
---|
1666 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
1667 | { |
---|
1668 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
1669 | } |
---|
1670 | else |
---|
1671 | { |
---|
1672 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
1673 | } |
---|
1674 | } |
---|
1675 | |
---|
1676 | #if AMP_ENC_SPEEDUP |
---|
1677 | if ( rpcBestCU->isIntra(0) ) |
---|
1678 | { |
---|
1679 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE ); |
---|
1680 | } |
---|
1681 | else |
---|
1682 | { |
---|
1683 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) ); |
---|
1684 | } |
---|
1685 | #else |
---|
1686 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
1687 | #endif |
---|
1688 | |
---|
1689 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
1690 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
1691 | |
---|
1692 | #if HHI_VSO |
---|
1693 | #if HHI_VSO_SET_OPTIM |
---|
1694 | #else |
---|
1695 | if( m_pcRdCost->getUseRenModel() ) // necessary ?? |
---|
1696 | { |
---|
1697 | UInt uiWidth = m_ppcRecoYuvBest[uhNextDepth]->getWidth ( ); |
---|
1698 | UInt uiHeight = m_ppcRecoYuvBest[uhNextDepth]->getHeight ( ); |
---|
1699 | Pel* piSrc = m_ppcRecoYuvBest[uhNextDepth]->getLumaAddr( 0 ); |
---|
1700 | UInt uiSrcStride = m_ppcRecoYuvBest[uhNextDepth]->getStride ( ); |
---|
1701 | m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1702 | } |
---|
1703 | #endif |
---|
1704 | #endif |
---|
1705 | } |
---|
1706 | else if (bInSlice) |
---|
1707 | { |
---|
1708 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
1709 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
1710 | } |
---|
1711 | } |
---|
1712 | |
---|
1713 | if( !bBoundary ) |
---|
1714 | { |
---|
1715 | m_pcEntropyCoder->resetBits(); |
---|
1716 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
1717 | |
---|
1718 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1719 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1720 | { |
---|
1721 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1722 | } |
---|
1723 | } |
---|
1724 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
1725 | if( bFullyRenderedSec ) |
---|
1726 | { |
---|
1727 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
1728 | } |
---|
1729 | else |
---|
1730 | { |
---|
1731 | m_pcRdCost->setLambdaScale( 1 ); |
---|
1732 | } |
---|
1733 | #endif |
---|
1734 | |
---|
1735 | #if HHI_VSO |
---|
1736 | if ( m_pcRdCost->getUseVSO() ) |
---|
1737 | { |
---|
1738 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1739 | } |
---|
1740 | else |
---|
1741 | #endif |
---|
1742 | { |
---|
1743 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1744 | } |
---|
1745 | |
---|
1746 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
1747 | { |
---|
1748 | Bool bHasRedisual = false; |
---|
1749 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
1750 | { |
---|
1751 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getEntropySliceCurStartCUAddr() ) && |
---|
1752 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
1753 | { |
---|
1754 | bHasRedisual = true; |
---|
1755 | break; |
---|
1756 | } |
---|
1757 | } |
---|
1758 | |
---|
1759 | UInt uiTargetPartIdx; |
---|
1760 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getEntropySliceCurStartCUAddr() ) |
---|
1761 | { |
---|
1762 | uiTargetPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
1763 | } |
---|
1764 | else |
---|
1765 | { |
---|
1766 | uiTargetPartIdx = 0; |
---|
1767 | } |
---|
1768 | if ( bHasRedisual ) |
---|
1769 | { |
---|
1770 | #if !RDO_WITHOUT_DQP_BITS |
---|
1771 | m_pcEntropyCoder->resetBits(); |
---|
1772 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
1773 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
1774 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1775 | { |
---|
1776 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1777 | } |
---|
1778 | #if HHI_VSO |
---|
1779 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1780 | { |
---|
1781 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1782 | } |
---|
1783 | else |
---|
1784 | #endif |
---|
1785 | { |
---|
1786 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1787 | } |
---|
1788 | #endif |
---|
1789 | } |
---|
1790 | else |
---|
1791 | { |
---|
1792 | #if LOSSLESS_CODING |
---|
1793 | if (((rpcTempCU->getQP(uiTargetPartIdx) != rpcTempCU->getRefQP(uiTargetPartIdx)) ) && (rpcTempCU->getSlice()->getSPS()->getUseLossless())) |
---|
1794 | { |
---|
1795 | rpcTempCU->getTotalCost() = MAX_DOUBLE; |
---|
1796 | } |
---|
1797 | #endif |
---|
1798 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
1799 | } |
---|
1800 | } |
---|
1801 | |
---|
1802 | if( m_bUseSBACRD ) |
---|
1803 | { |
---|
1804 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1805 | } |
---|
1806 | Bool bEntropyLimit=false; |
---|
1807 | Bool bSliceLimit=false; |
---|
1808 | bSliceLimit=rpcBestCU->getSlice()->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
---|
1809 | if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&m_pcEncCfg->getUseSBACRD()) |
---|
1810 | { |
---|
1811 | if(rpcBestCU->getTotalBins()>rpcBestCU->getSlice()->getEntropySliceArgument()) |
---|
1812 | { |
---|
1813 | bEntropyLimit=true; |
---|
1814 | } |
---|
1815 | } |
---|
1816 | else if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE) |
---|
1817 | { |
---|
1818 | if(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getEntropySliceArgument()) |
---|
1819 | { |
---|
1820 | bEntropyLimit=true; |
---|
1821 | } |
---|
1822 | } |
---|
1823 | if(rpcBestCU->getDepth(0)>=rpcBestCU->getSlice()->getPPS()->getSliceGranularity()) |
---|
1824 | { |
---|
1825 | bSliceLimit=false; |
---|
1826 | bEntropyLimit=false; |
---|
1827 | } |
---|
1828 | if(bSliceLimit||bEntropyLimit) |
---|
1829 | { |
---|
1830 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
---|
1831 | } |
---|
1832 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction |
---|
1833 | } // with sub partitioned prediction. |
---|
1834 | #if LOSSLESS_CODING |
---|
1835 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
1836 | { |
---|
1837 | iQP = iMinQP; |
---|
1838 | } |
---|
1839 | #endif |
---|
1840 | } // SPLIT- QP Loop |
---|
1841 | |
---|
1842 | #if HHI_VSO |
---|
1843 | if( m_pcRdCost->getUseRenModel() ) |
---|
1844 | { |
---|
1845 | UInt uiWidth = m_ppcRecoYuvBest[uiDepth]->getWidth ( ); |
---|
1846 | UInt uiHeight = m_ppcRecoYuvBest[uiDepth]->getHeight ( ); |
---|
1847 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
1848 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride ( ); |
---|
1849 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1850 | } |
---|
1851 | #endif |
---|
1852 | |
---|
1853 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
1854 | |
---|
1855 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
---|
1856 | if( bBoundary ||(bSliceEnd && bInsidePicture)) |
---|
1857 | { |
---|
1858 | return; |
---|
1859 | } |
---|
1860 | |
---|
1861 | // Assert if Best prediction mode is NONE |
---|
1862 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
1863 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
1864 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
1865 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
1866 | } |
---|
1867 | |
---|
1868 | /** finish encoding a cu and handle end-of-slice conditions |
---|
1869 | * \param pcCU |
---|
1870 | * \param uiAbsPartIdx |
---|
1871 | * \param uiDepth |
---|
1872 | * \returns Void |
---|
1873 | */ |
---|
1874 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1875 | { |
---|
1876 | TComPic* pcPic = pcCU->getPic(); |
---|
1877 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1878 | |
---|
1879 | //Calculate end address |
---|
1880 | UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; |
---|
1881 | |
---|
1882 | UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
1883 | UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
1884 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1885 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1886 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
1887 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
1888 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
1889 | { |
---|
1890 | uiInternalAddress--; |
---|
1891 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1892 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1893 | } |
---|
1894 | uiInternalAddress++; |
---|
1895 | if(uiInternalAddress==pcCU->getPic()->getNumPartInCU()) |
---|
1896 | { |
---|
1897 | uiInternalAddress = 0; |
---|
1898 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
1899 | } |
---|
1900 | UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
1901 | |
---|
1902 | // Encode slice finish |
---|
1903 | Bool bTerminateSlice = false; |
---|
1904 | if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress) |
---|
1905 | { |
---|
1906 | bTerminateSlice = true; |
---|
1907 | } |
---|
1908 | UInt uiGranularityWidth = g_uiMaxCUWidth>>(pcSlice->getPPS()->getSliceGranularity()); |
---|
1909 | uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1910 | uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1911 | Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth)) |
---|
1912 | &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); |
---|
1913 | |
---|
1914 | #if BURST_IPCM |
---|
1915 | if(granularityBoundary && (!(pcCU->getIPCMFlag(uiAbsPartIdx) && ( pcCU->getNumSucIPCM() > 1 )))) |
---|
1916 | #else |
---|
1917 | if(granularityBoundary) |
---|
1918 | #endif |
---|
1919 | { |
---|
1920 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
1921 | if (!bTerminateSlice) |
---|
1922 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
1923 | } |
---|
1924 | |
---|
1925 | Int numberOfWrittenBits = 0; |
---|
1926 | if (m_pcBitCounter) |
---|
1927 | { |
---|
1928 | numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1929 | } |
---|
1930 | |
---|
1931 | // Calculate slice end IF this CU puts us over slice bit size. |
---|
1932 | unsigned iGranularitySize = pcCU->getPic()->getNumPartInCU()>>(pcSlice->getPPS()->getSliceGranularity()<<1); |
---|
1933 | int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; |
---|
1934 | if(iGranularityEnd<=pcSlice->getEntropySliceCurStartCUAddr()) |
---|
1935 | { |
---|
1936 | iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); |
---|
1937 | } |
---|
1938 | // Set slice end parameter |
---|
1939 | if(pcSlice->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) |
---|
1940 | { |
---|
1941 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1942 | pcSlice->setSliceCurEndCUAddr(iGranularityEnd); |
---|
1943 | return; |
---|
1944 | } |
---|
1945 | // Set entropy slice end parameter |
---|
1946 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1947 | { |
---|
1948 | TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); |
---|
1949 | UInt uiBinsCoded = pppcRDSbacCoder->getBinsCoded(); |
---|
1950 | if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+uiBinsCoded>pcSlice->getEntropySliceArgument()) |
---|
1951 | { |
---|
1952 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1953 | return; |
---|
1954 | } |
---|
1955 | } |
---|
1956 | else |
---|
1957 | { |
---|
1958 | if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+numberOfWrittenBits>pcSlice->getEntropySliceArgument()) |
---|
1959 | { |
---|
1960 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1961 | return; |
---|
1962 | } |
---|
1963 | } |
---|
1964 | if(granularityBoundary) |
---|
1965 | { |
---|
1966 | pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); |
---|
1967 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1968 | { |
---|
1969 | TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); |
---|
1970 | pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+pppcRDSbacCoder->getBinsCoded()); |
---|
1971 | pppcRDSbacCoder->setBinsCoded( 0 ); |
---|
1972 | } |
---|
1973 | else |
---|
1974 | { |
---|
1975 | pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+numberOfWrittenBits); |
---|
1976 | } |
---|
1977 | if (m_pcBitCounter) |
---|
1978 | { |
---|
1979 | m_pcEntropyCoder->resetBits(); |
---|
1980 | } |
---|
1981 | } |
---|
1982 | } |
---|
1983 | |
---|
1984 | /** Compute QP for each CU |
---|
1985 | * \param pcCU Target CU |
---|
1986 | * \param uiDepth CU depth |
---|
1987 | * \returns quantization parameter |
---|
1988 | */ |
---|
1989 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
1990 | { |
---|
1991 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
1992 | Int iQpOffset = 0; |
---|
1993 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
1994 | { |
---|
1995 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
1996 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
1997 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
1998 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
1999 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
2000 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
2001 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
2002 | |
---|
2003 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
2004 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
2005 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
2006 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
2007 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
2008 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
2009 | } |
---|
2010 | #if H0736_AVC_STYLE_QP_RANGE |
---|
2011 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
2012 | #else |
---|
2013 | return Clip3( MIN_QP, MAX_QP, iBaseQp+iQpOffset ); |
---|
2014 | #endif |
---|
2015 | } |
---|
2016 | |
---|
2017 | /** encode a CU block recursively |
---|
2018 | * \param pcCU |
---|
2019 | * \param uiAbsPartIdx |
---|
2020 | * \param uiDepth |
---|
2021 | * \returns Void |
---|
2022 | */ |
---|
2023 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
2024 | { |
---|
2025 | TComPic* pcPic = pcCU->getPic(); |
---|
2026 | |
---|
2027 | Bool bBoundary = false; |
---|
2028 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
2029 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
2030 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
2031 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
2032 | |
---|
2033 | #if BURST_IPCM |
---|
2034 | if( getCheckBurstIPCMFlag() ) |
---|
2035 | { |
---|
2036 | pcCU->setLastCUSucIPCMFlag( checkLastCUSucIPCM( pcCU, uiAbsPartIdx )); |
---|
2037 | pcCU->setNumSucIPCM( countNumSucIPCM ( pcCU, uiAbsPartIdx ) ); |
---|
2038 | } |
---|
2039 | #endif |
---|
2040 | |
---|
2041 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2042 | // If slice start is within this cu... |
---|
2043 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2044 | pcSlice->getEntropySliceCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2045 | // We need to split, so don't try these modes. |
---|
2046 | if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2047 | { |
---|
2048 | #if HHI_MPI |
---|
2049 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth < pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
2050 | { |
---|
2051 | #endif |
---|
2052 | |
---|
2053 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
2054 | |
---|
2055 | #if HHI_MPI |
---|
2056 | } |
---|
2057 | #endif |
---|
2058 | } |
---|
2059 | else |
---|
2060 | { |
---|
2061 | bBoundary = true; |
---|
2062 | } |
---|
2063 | |
---|
2064 | #if HHI_MPI |
---|
2065 | if( uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
2066 | { |
---|
2067 | xSaveDepthWidthHeight( pcCU ); |
---|
2068 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
2069 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
2070 | |
---|
2071 | if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2072 | { |
---|
2073 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
2074 | } |
---|
2075 | |
---|
2076 | if( !pcCU->getSlice()->isIntra() ) |
---|
2077 | { |
---|
2078 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
2079 | } |
---|
2080 | |
---|
2081 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
2082 | { |
---|
2083 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
2084 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
2085 | xRestoreDepthWidthHeight( pcCU ); |
---|
2086 | return; |
---|
2087 | } |
---|
2088 | |
---|
2089 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
2090 | |
---|
2091 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
2092 | |
---|
2093 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
2094 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
2095 | xRestoreDepthWidthHeight( pcCU ); |
---|
2096 | } |
---|
2097 | #endif |
---|
2098 | |
---|
2099 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
2100 | { |
---|
2101 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
2102 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
2103 | { |
---|
2104 | setdQPFlag(true); |
---|
2105 | } |
---|
2106 | #if BURST_IPCM |
---|
2107 | pcCU->setNumSucIPCM(0); |
---|
2108 | pcCU->setLastCUSucIPCMFlag(false); |
---|
2109 | #endif |
---|
2110 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
2111 | { |
---|
2112 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
2113 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
2114 | Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getEntropySliceCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getEntropySliceCurEndCUAddr(); |
---|
2115 | if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2116 | { |
---|
2117 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
2118 | } |
---|
2119 | } |
---|
2120 | return; |
---|
2121 | } |
---|
2122 | |
---|
2123 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
2124 | { |
---|
2125 | setdQPFlag(true); |
---|
2126 | } |
---|
2127 | #if HHI_MPI |
---|
2128 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
2129 | { |
---|
2130 | #endif |
---|
2131 | if( !pcCU->getSlice()->isIntra() ) |
---|
2132 | { |
---|
2133 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
2134 | } |
---|
2135 | #if HHI_MPI |
---|
2136 | } |
---|
2137 | #endif |
---|
2138 | |
---|
2139 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
2140 | { |
---|
2141 | #if OL_DEPTHLIMIT_A0044 |
---|
2142 | if(pcCU->getPartDumpFlag()) |
---|
2143 | { |
---|
2144 | pcCU->updatePartInfo(0,uiDepth); |
---|
2145 | pcCU->incrementPartInfo(); |
---|
2146 | } |
---|
2147 | #endif |
---|
2148 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
2149 | #if LGE_ILLUCOMP_B0045 |
---|
2150 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
2151 | #endif |
---|
2152 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2153 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
2154 | #endif |
---|
2155 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
2156 | return; |
---|
2157 | } |
---|
2158 | #if HHI_MPI |
---|
2159 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
2160 | { |
---|
2161 | #endif |
---|
2162 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
2163 | |
---|
2164 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
2165 | |
---|
2166 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
2167 | { |
---|
2168 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
2169 | |
---|
2170 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
2171 | { |
---|
2172 | // Encode slice finish |
---|
2173 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
2174 | return; |
---|
2175 | } |
---|
2176 | } |
---|
2177 | |
---|
2178 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
2179 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
2180 | #if LGE_ILLUCOMP_B0045 |
---|
2181 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
2182 | #endif |
---|
2183 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2184 | if( !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
2185 | { |
---|
2186 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
2187 | } |
---|
2188 | #endif |
---|
2189 | #if HHI_MPI |
---|
2190 | } |
---|
2191 | #endif |
---|
2192 | |
---|
2193 | // Encode Coefficients |
---|
2194 | Bool bCodeDQP = getdQPFlag(); |
---|
2195 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP ); |
---|
2196 | setdQPFlag( bCodeDQP ); |
---|
2197 | |
---|
2198 | // --- write terminating bit --- |
---|
2199 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
2200 | } |
---|
2201 | |
---|
2202 | /** check RD costs for a CU block encoded with merge |
---|
2203 | * \param rpcBestCU |
---|
2204 | * \param rpcTempCU |
---|
2205 | * \returns Void |
---|
2206 | */ |
---|
2207 | #if HHI_INTERVIEW_SKIP |
---|
2208 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
2209 | #else |
---|
2210 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2211 | #endif |
---|
2212 | { |
---|
2213 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
2214 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
2215 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
2216 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
2217 | #else |
---|
2218 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
2219 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
2220 | #endif |
---|
2221 | Int numValidMergeCand = 0; |
---|
2222 | |
---|
2223 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2224 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
2225 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
2226 | #endif |
---|
2227 | #if LGE_ILLUCOMP_B0045 |
---|
2228 | Bool bICFlag = rpcTempCU->getICFlag(0); |
---|
2229 | #endif |
---|
2230 | |
---|
2231 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
2232 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS_MEM; ++ui ) |
---|
2233 | #else |
---|
2234 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
2235 | #endif |
---|
2236 | { |
---|
2237 | uhInterDirNeighbours[ui] = 0; |
---|
2238 | } |
---|
2239 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2240 | |
---|
2241 | #if HHI_VSO |
---|
2242 | if( m_pcRdCost->getUseRenModel() ) |
---|
2243 | { |
---|
2244 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
2245 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
2246 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
2247 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
2248 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2249 | } |
---|
2250 | #endif |
---|
2251 | |
---|
2252 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
2253 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
2254 | |
---|
2255 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2256 | Bool bestIsSkip = false; |
---|
2257 | #endif |
---|
2258 | |
---|
2259 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
2260 | { |
---|
2261 | { |
---|
2262 | TComYuv* pcPredYuvTemp = NULL; |
---|
2263 | #if LOSSLESS_CODING |
---|
2264 | UInt iteration; |
---|
2265 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
2266 | { |
---|
2267 | iteration = 1; |
---|
2268 | } |
---|
2269 | else |
---|
2270 | { |
---|
2271 | iteration = 2; |
---|
2272 | } |
---|
2273 | |
---|
2274 | #if HHI_INTERVIEW_SKIP |
---|
2275 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < iteration; ++uiNoResidual ) |
---|
2276 | #else |
---|
2277 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
2278 | #endif |
---|
2279 | #else |
---|
2280 | #if HHI_INTERVIEW_SKIP |
---|
2281 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < 2; ++uiNoResidual ) |
---|
2282 | #else |
---|
2283 | for( UInt uiNoResidual = 0; uiNoResidual < 2; ++uiNoResidual ) |
---|
2284 | #endif |
---|
2285 | #endif |
---|
2286 | { |
---|
2287 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2288 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
2289 | { |
---|
2290 | #endif |
---|
2291 | // set MC parameters |
---|
2292 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level |
---|
2293 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
2294 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
2295 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
2296 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
2297 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
2298 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
2299 | |
---|
2300 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2301 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
2302 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
2303 | #endif |
---|
2304 | #if LGE_ILLUCOMP_B0045 |
---|
2305 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uhDepth); |
---|
2306 | #endif |
---|
2307 | |
---|
2308 | // do MC |
---|
2309 | #if HHI_INTERVIEW_SKIP |
---|
2310 | if ( (uiNoResidual == 0) || bSkipRes ){ |
---|
2311 | #else |
---|
2312 | if ( uiNoResidual == 0 ){ |
---|
2313 | #endif |
---|
2314 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
2315 | // save pred adress |
---|
2316 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
2317 | |
---|
2318 | } |
---|
2319 | else |
---|
2320 | { |
---|
2321 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2322 | if( bestIsSkip) |
---|
2323 | { |
---|
2324 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
2325 | // save pred adress |
---|
2326 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
2327 | } |
---|
2328 | else |
---|
2329 | { |
---|
2330 | #endif |
---|
2331 | if ( pcPredYuvTemp != m_ppcPredYuvTemp[uhDepth]) |
---|
2332 | { |
---|
2333 | //adress changes take best (old temp) |
---|
2334 | pcPredYuvTemp = m_ppcPredYuvBest[uhDepth]; |
---|
2335 | } |
---|
2336 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2337 | } |
---|
2338 | #endif |
---|
2339 | } |
---|
2340 | #if HHI_VSO |
---|
2341 | if( m_pcRdCost->getUseRenModel() ) |
---|
2342 | { //Reset |
---|
2343 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
2344 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
2345 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); |
---|
2346 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
2347 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2348 | } |
---|
2349 | #endif |
---|
2350 | // estimate residual and encode everything |
---|
2351 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2352 | m_ppcOrigYuv [uhDepth], |
---|
2353 | pcPredYuvTemp, |
---|
2354 | m_ppcResiYuvTemp[uhDepth], |
---|
2355 | m_ppcResiYuvBest[uhDepth], |
---|
2356 | m_ppcRecoYuvTemp[uhDepth], |
---|
2357 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2358 | m_ppcResPredTmp [uhDepth], |
---|
2359 | #endif |
---|
2360 | (uiNoResidual? true:false) ); |
---|
2361 | Bool bQtRootCbf = rpcTempCU->getQtRootCbf(0) == 1; |
---|
2362 | |
---|
2363 | #if H0736_AVC_STYLE_QP_RANGE |
---|
2364 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
2365 | xCheckDQP( rpcTempCU ); |
---|
2366 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2367 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
2368 | #else |
---|
2369 | UInt uiOrgQP = rpcTempCU->getQP( 0 ); |
---|
2370 | xCheckDQP( rpcTempCU ); |
---|
2371 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2372 | rpcTempCU->initEstData( uhDepth, uiOrgQP ); |
---|
2373 | #endif |
---|
2374 | |
---|
2375 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2376 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
2377 | { |
---|
2378 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
2379 | } |
---|
2380 | #endif |
---|
2381 | |
---|
2382 | if (!bQtRootCbf) |
---|
2383 | break; |
---|
2384 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2385 | } |
---|
2386 | #endif |
---|
2387 | } |
---|
2388 | } |
---|
2389 | } |
---|
2390 | } |
---|
2391 | |
---|
2392 | #if AMP_MRG |
---|
2393 | #if HHI_INTERVIEW_SKIP |
---|
2394 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes, Bool bUseMRG) |
---|
2395 | #else |
---|
2396 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG) |
---|
2397 | #endif |
---|
2398 | #else |
---|
2399 | #if HHI_INTERVIEW_SKIP |
---|
2400 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes) |
---|
2401 | #else |
---|
2402 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
2403 | #endif |
---|
2404 | #endif |
---|
2405 | { |
---|
2406 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2407 | |
---|
2408 | #if HHI_VSO |
---|
2409 | if( m_pcRdCost->getUseRenModel() ) |
---|
2410 | { |
---|
2411 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
2412 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
2413 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
2414 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
2415 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2416 | } |
---|
2417 | #endif |
---|
2418 | |
---|
2419 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
2420 | |
---|
2421 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2422 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
2423 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
2424 | #endif |
---|
2425 | |
---|
2426 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
2427 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2428 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
2429 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
2430 | #endif |
---|
2431 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
2432 | |
---|
2433 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2434 | #if !LG_RESTRICTEDRESPRED_M24766 |
---|
2435 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
2436 | { // subtract residual prediction from original in motion search |
---|
2437 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ), true ); |
---|
2438 | } |
---|
2439 | #endif |
---|
2440 | #endif |
---|
2441 | |
---|
2442 | #if AMP_MRG |
---|
2443 | rpcTempCU->setMergeAMP (true); |
---|
2444 | #if HHI_INTERVIEW_SKIP |
---|
2445 | #if LG_RESTRICTEDRESPRED_M24766 |
---|
2446 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG ); |
---|
2447 | #else |
---|
2448 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG ); |
---|
2449 | #endif |
---|
2450 | #else |
---|
2451 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG ); |
---|
2452 | #endif |
---|
2453 | #else |
---|
2454 | #if HHI_INTERVIEW_SKIP |
---|
2455 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes ); |
---|
2456 | #else |
---|
2457 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
2458 | #endif |
---|
2459 | #endif |
---|
2460 | |
---|
2461 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2462 | #if !LG_RESTRICTEDRESPRED_M24766 |
---|
2463 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
2464 | { // add residual prediction to original again |
---|
2465 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ) ); |
---|
2466 | } |
---|
2467 | #endif |
---|
2468 | #endif |
---|
2469 | |
---|
2470 | #if AMP_MRG |
---|
2471 | if ( !rpcTempCU->getMergeAMP() ) |
---|
2472 | { |
---|
2473 | return; |
---|
2474 | } |
---|
2475 | #endif |
---|
2476 | |
---|
2477 | #if HHI_INTERVIEW_SKIP |
---|
2478 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2479 | m_ppcOrigYuv[uhDepth], |
---|
2480 | m_ppcPredYuvTemp[uhDepth], |
---|
2481 | m_ppcResiYuvTemp[uhDepth], |
---|
2482 | m_ppcResiYuvBest[uhDepth], |
---|
2483 | m_ppcRecoYuvTemp[uhDepth], |
---|
2484 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2485 | m_ppcResPredTmp [uhDepth], |
---|
2486 | #endif |
---|
2487 | bSkipRes ); |
---|
2488 | #else |
---|
2489 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2490 | m_ppcOrigYuv[uhDepth], |
---|
2491 | m_ppcPredYuvTemp[uhDepth], |
---|
2492 | m_ppcResiYuvTemp[uhDepth], |
---|
2493 | m_ppcResiYuvBest[uhDepth], |
---|
2494 | m_ppcRecoYuvTemp[uhDepth], |
---|
2495 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2496 | m_ppcResPredTmp [uhDepth], |
---|
2497 | #endif |
---|
2498 | false ); |
---|
2499 | #endif |
---|
2500 | #if HHI_VSO |
---|
2501 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
2502 | { |
---|
2503 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2504 | } |
---|
2505 | else |
---|
2506 | #endif |
---|
2507 | { |
---|
2508 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2509 | } |
---|
2510 | |
---|
2511 | xCheckDQP( rpcTempCU ); |
---|
2512 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2513 | } |
---|
2514 | |
---|
2515 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
2516 | { |
---|
2517 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2518 | |
---|
2519 | #if HHI_VSO |
---|
2520 | if( m_pcRdCost->getUseRenModel() ) |
---|
2521 | { |
---|
2522 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth (); |
---|
2523 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight (); |
---|
2524 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr(); |
---|
2525 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride (); |
---|
2526 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2527 | } |
---|
2528 | #endif |
---|
2529 | |
---|
2530 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
2531 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2532 | |
---|
2533 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
2534 | Dist uiPreCalcDistC = 0; |
---|
2535 | if( !bSeparateLumaChroma ) |
---|
2536 | { |
---|
2537 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
2538 | } |
---|
2539 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
2540 | |
---|
2541 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
2542 | |
---|
2543 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
2544 | |
---|
2545 | m_pcEntropyCoder->resetBits(); |
---|
2546 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2547 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
2548 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
2549 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
2550 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
2551 | |
---|
2552 | // Encode Coefficients |
---|
2553 | Bool bCodeDQP = getdQPFlag(); |
---|
2554 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP ); |
---|
2555 | setdQPFlag( bCodeDQP ); |
---|
2556 | |
---|
2557 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2558 | |
---|
2559 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2560 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2561 | { |
---|
2562 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2563 | } |
---|
2564 | #if HHI_VSO |
---|
2565 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
2566 | { |
---|
2567 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2568 | } |
---|
2569 | else |
---|
2570 | #endif |
---|
2571 | { |
---|
2572 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2573 | } |
---|
2574 | |
---|
2575 | xCheckDQP( rpcTempCU ); |
---|
2576 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
---|
2577 | } |
---|
2578 | |
---|
2579 | /** Check R-D costs for a CU with PCM mode. |
---|
2580 | * \param rpcBestCU pointer to best mode CU data structure |
---|
2581 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
2582 | * \returns Void |
---|
2583 | * |
---|
2584 | * \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. |
---|
2585 | */ |
---|
2586 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2587 | { |
---|
2588 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2589 | |
---|
2590 | rpcTempCU->setIPCMFlag(0, true); |
---|
2591 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
2592 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
2593 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2594 | |
---|
2595 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
2596 | |
---|
2597 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
2598 | |
---|
2599 | m_pcEntropyCoder->resetBits(); |
---|
2600 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2601 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
2602 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
2603 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
2604 | |
---|
2605 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2606 | |
---|
2607 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2608 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2609 | { |
---|
2610 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2611 | } |
---|
2612 | #if HHI_VSO |
---|
2613 | if ( m_pcRdCost->getUseVSO() ) |
---|
2614 | { |
---|
2615 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2616 | } |
---|
2617 | else |
---|
2618 | #endif |
---|
2619 | { |
---|
2620 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2621 | } |
---|
2622 | |
---|
2623 | xCheckDQP( rpcTempCU ); |
---|
2624 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
2625 | } |
---|
2626 | |
---|
2627 | // check whether current try is the best |
---|
2628 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2629 | { |
---|
2630 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
2631 | { |
---|
2632 | TComYuv* pcYuv; |
---|
2633 | UChar uhDepth = rpcBestCU->getDepth(0); |
---|
2634 | |
---|
2635 | // Change Information data |
---|
2636 | TComDataCU* pcCU = rpcBestCU; |
---|
2637 | rpcBestCU = rpcTempCU; |
---|
2638 | rpcTempCU = pcCU; |
---|
2639 | |
---|
2640 | // Change Prediction data |
---|
2641 | pcYuv = m_ppcPredYuvBest[uhDepth]; |
---|
2642 | m_ppcPredYuvBest[uhDepth] = m_ppcPredYuvTemp[uhDepth]; |
---|
2643 | m_ppcPredYuvTemp[uhDepth] = pcYuv; |
---|
2644 | |
---|
2645 | // Change Reconstruction data |
---|
2646 | pcYuv = m_ppcRecoYuvBest[uhDepth]; |
---|
2647 | m_ppcRecoYuvBest[uhDepth] = m_ppcRecoYuvTemp[uhDepth]; |
---|
2648 | m_ppcRecoYuvTemp[uhDepth] = pcYuv; |
---|
2649 | |
---|
2650 | pcYuv = NULL; |
---|
2651 | pcCU = NULL; |
---|
2652 | |
---|
2653 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
2654 | m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_NEXT_BEST]); |
---|
2655 | } |
---|
2656 | } |
---|
2657 | |
---|
2658 | /** check whether current try is the best with identifying the depth of current try |
---|
2659 | * \param rpcBestCU |
---|
2660 | * \param rpcTempCU |
---|
2661 | * \returns Void |
---|
2662 | */ |
---|
2663 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
2664 | { |
---|
2665 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
2666 | { |
---|
2667 | TComYuv* pcYuv; |
---|
2668 | // Change Information data |
---|
2669 | TComDataCU* pcCU = rpcBestCU; |
---|
2670 | rpcBestCU = rpcTempCU; |
---|
2671 | rpcTempCU = pcCU; |
---|
2672 | |
---|
2673 | // Change Prediction data |
---|
2674 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
2675 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
2676 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
2677 | |
---|
2678 | // Change Reconstruction data |
---|
2679 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
2680 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
2681 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
2682 | |
---|
2683 | pcYuv = NULL; |
---|
2684 | pcCU = NULL; |
---|
2685 | |
---|
2686 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
2687 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
2688 | } |
---|
2689 | } |
---|
2690 | |
---|
2691 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
2692 | { |
---|
2693 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
2694 | |
---|
2695 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
2696 | { |
---|
2697 | if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) |
---|
2698 | { |
---|
2699 | #if !RDO_WITHOUT_DQP_BITS |
---|
2700 | m_pcEntropyCoder->resetBits(); |
---|
2701 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
2702 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
2703 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2704 | { |
---|
2705 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2706 | } |
---|
2707 | |
---|
2708 | // GT: Change here?? |
---|
2709 | #if HHI_VSO |
---|
2710 | if ( m_pcRdCost->getUseVSO() ) |
---|
2711 | { |
---|
2712 | pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
2713 | } |
---|
2714 | else |
---|
2715 | #endif |
---|
2716 | { |
---|
2717 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
2718 | } |
---|
2719 | #endif |
---|
2720 | } |
---|
2721 | else |
---|
2722 | { |
---|
2723 | #if LOSSLESS_CODING |
---|
2724 | if (( ( pcCU->getRefQP( 0 ) != pcCU->getQP( 0 )) ) && (pcCU->getSlice()->getSPS()->getUseLossless())) |
---|
2725 | { |
---|
2726 | pcCU->getTotalCost() = MAX_DOUBLE; |
---|
2727 | } |
---|
2728 | #endif |
---|
2729 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
2730 | } |
---|
2731 | } |
---|
2732 | } |
---|
2733 | |
---|
2734 | #if BURST_IPCM |
---|
2735 | /** Check whether the last CU shares the same root as the current CU and is IPCM or not. |
---|
2736 | * \param pcCU |
---|
2737 | * \param uiCurAbsPartIdx |
---|
2738 | * \returns Bool |
---|
2739 | */ |
---|
2740 | Bool TEncCu::checkLastCUSucIPCM( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) |
---|
2741 | { |
---|
2742 | Bool lastCUSucIPCMFlag = false; |
---|
2743 | |
---|
2744 | UInt curDepth = pcCU->getDepth(uiCurAbsPartIdx); |
---|
2745 | UInt shift = ((pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx())->getSPS()->getMaxCUDepth() - curDepth)<<1); |
---|
2746 | UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); |
---|
2747 | |
---|
2748 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2749 | if( pcSlice->getEntropySliceCurStartCUAddr() == ( pcCU->getSCUAddr() + uiCurAbsPartIdx ) ) |
---|
2750 | { |
---|
2751 | return false; |
---|
2752 | } |
---|
2753 | |
---|
2754 | if(curDepth > 0 && startPartUnitIdx > 0) |
---|
2755 | { |
---|
2756 | Int lastValidPartIdx = pcCU->getLastValidPartIdx((Int) uiCurAbsPartIdx ); |
---|
2757 | |
---|
2758 | if( lastValidPartIdx >= 0 ) |
---|
2759 | { |
---|
2760 | if(( pcCU->getSliceStartCU( uiCurAbsPartIdx ) == pcCU->getSliceStartCU( (UInt) lastValidPartIdx )) |
---|
2761 | && |
---|
2762 | ( pcCU->getDepth( uiCurAbsPartIdx ) == pcCU->getDepth( (UInt) lastValidPartIdx )) |
---|
2763 | && |
---|
2764 | pcCU->getIPCMFlag( (UInt) lastValidPartIdx ) ) |
---|
2765 | { |
---|
2766 | lastCUSucIPCMFlag = true; |
---|
2767 | } |
---|
2768 | } |
---|
2769 | } |
---|
2770 | |
---|
2771 | return lastCUSucIPCMFlag; |
---|
2772 | } |
---|
2773 | |
---|
2774 | /** Count the number of successive IPCM CUs sharing the same root. |
---|
2775 | * \param pcCU |
---|
2776 | * \param uiCurAbsPartIdx |
---|
2777 | * \returns Int |
---|
2778 | */ |
---|
2779 | Int TEncCu::countNumSucIPCM ( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) |
---|
2780 | { |
---|
2781 | Int numSucIPCM = 0; |
---|
2782 | UInt CurDepth = pcCU->getDepth(uiCurAbsPartIdx); |
---|
2783 | |
---|
2784 | if( pcCU->getIPCMFlag(uiCurAbsPartIdx) ) |
---|
2785 | { |
---|
2786 | if(CurDepth == 0) |
---|
2787 | { |
---|
2788 | numSucIPCM = 1; |
---|
2789 | } |
---|
2790 | else |
---|
2791 | { |
---|
2792 | TComPic* pcPic = pcCU->getPic(); |
---|
2793 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2794 | UInt qNumParts = ( pcPic->getNumPartInCU() >> ((CurDepth-1)<<1) )>>2; |
---|
2795 | |
---|
2796 | Bool continueFlag = true; |
---|
2797 | UInt absPartIdx = uiCurAbsPartIdx; |
---|
2798 | UInt shift = ((pcSlice->getSPS()->getMaxCUDepth() - CurDepth)<<1); |
---|
2799 | UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); |
---|
2800 | |
---|
2801 | for ( UInt partUnitIdx = startPartUnitIdx; partUnitIdx < 4 && continueFlag; partUnitIdx++, absPartIdx+=qNumParts ) |
---|
2802 | { |
---|
2803 | UInt lPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ]; |
---|
2804 | UInt tPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ]; |
---|
2805 | Bool inSliceFlag = ( pcCU->getSCUAddr()+absPartIdx+qNumParts>pcSlice->getEntropySliceCurStartCUAddr() ) && ( pcCU->getSCUAddr()+absPartIdx < pcSlice->getEntropySliceCurEndCUAddr()); |
---|
2806 | |
---|
2807 | if( inSliceFlag && ( lPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( tPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2808 | { |
---|
2809 | UInt uiDepth = pcCU->getDepth(absPartIdx); |
---|
2810 | |
---|
2811 | if( ( CurDepth == uiDepth) && pcCU->getIPCMFlag( absPartIdx ) ) |
---|
2812 | { |
---|
2813 | numSucIPCM++; |
---|
2814 | } |
---|
2815 | else |
---|
2816 | { |
---|
2817 | continueFlag = false; |
---|
2818 | } |
---|
2819 | } |
---|
2820 | } |
---|
2821 | } |
---|
2822 | } |
---|
2823 | |
---|
2824 | return numSucIPCM; |
---|
2825 | } |
---|
2826 | #endif |
---|
2827 | |
---|
2828 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
2829 | { |
---|
2830 | pDst->iN = pSrc->iN; |
---|
2831 | for (Int i = 0; i < pSrc->iN; i++) |
---|
2832 | { |
---|
2833 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
2834 | } |
---|
2835 | } |
---|
2836 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
---|
2837 | { |
---|
2838 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
2839 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
2840 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2841 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2842 | pcSlice->getEntropySliceCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2843 | Bool bSliceEnd = pcSlice->getEntropySliceCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2844 | pcSlice->getEntropySliceCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2845 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2846 | { |
---|
2847 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
2848 | UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); |
---|
2849 | UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); |
---|
2850 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
2851 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
2852 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
2853 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
2854 | } |
---|
2855 | else |
---|
2856 | { |
---|
2857 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
2858 | |
---|
2859 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
2860 | { |
---|
2861 | UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); |
---|
2862 | UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); |
---|
2863 | |
---|
2864 | Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getEntropySliceCurStartCUAddr() && |
---|
2865 | rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getEntropySliceCurEndCUAddr(); |
---|
2866 | if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2867 | { |
---|
2868 | xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv |
---|
2869 | } |
---|
2870 | } |
---|
2871 | } |
---|
2872 | } |
---|
2873 | |
---|
2874 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
2875 | { |
---|
2876 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
2877 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
2878 | } |
---|
2879 | |
---|
2880 | #if LOSSLESS_CODING |
---|
2881 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
2882 | * \param pcCU pointer to current CU |
---|
2883 | * \param pcOrgYuv pointer to original sample array |
---|
2884 | * \returns Void |
---|
2885 | */ |
---|
2886 | Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) |
---|
2887 | { |
---|
2888 | |
---|
2889 | UInt width = pCU->getWidth(0); |
---|
2890 | UInt height = pCU->getHeight(0); |
---|
2891 | |
---|
2892 | Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); |
---|
2893 | Pel* pDstY = pCU->getPCMSampleY(); |
---|
2894 | UInt srcStride = pOrgYuv->getStride(); |
---|
2895 | |
---|
2896 | for(Int y = 0; y < height; y++ ) |
---|
2897 | { |
---|
2898 | for(Int x = 0; x < width; x++ ) |
---|
2899 | { |
---|
2900 | pDstY[x] = pSrcY[x]; |
---|
2901 | } |
---|
2902 | pDstY += width; |
---|
2903 | pSrcY += srcStride; |
---|
2904 | } |
---|
2905 | |
---|
2906 | Pel* pSrcCb = pOrgYuv->getCbAddr(); |
---|
2907 | Pel* pSrcCr = pOrgYuv->getCrAddr();; |
---|
2908 | |
---|
2909 | Pel* pDstCb = pCU->getPCMSampleCb(); |
---|
2910 | Pel* pDstCr = pCU->getPCMSampleCr();; |
---|
2911 | |
---|
2912 | UInt srcStrideC = pOrgYuv->getCStride(); |
---|
2913 | UInt heightC = height >> 1; |
---|
2914 | UInt widthC = width >> 1; |
---|
2915 | |
---|
2916 | for(Int y = 0; y < heightC; y++ ) |
---|
2917 | { |
---|
2918 | for(Int x = 0; x < widthC; x++ ) |
---|
2919 | { |
---|
2920 | pDstCb[x] = pSrcCb[x]; |
---|
2921 | pDstCr[x] = pSrcCr[x]; |
---|
2922 | } |
---|
2923 | pDstCb += widthC; |
---|
2924 | pDstCr += widthC; |
---|
2925 | pSrcCb += srcStrideC; |
---|
2926 | pSrcCr += srcStrideC; |
---|
2927 | } |
---|
2928 | } |
---|
2929 | #endif |
---|
2930 | |
---|
2931 | #if ADAPTIVE_QP_SELECTION |
---|
2932 | /** Collect ARL statistics from one block |
---|
2933 | */ |
---|
2934 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
2935 | { |
---|
2936 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
2937 | { |
---|
2938 | Int u = abs( rpcCoeff[ n ] ); |
---|
2939 | Int absc = rpcArlCoeff[ n ]; |
---|
2940 | |
---|
2941 | if( u != 0 ) |
---|
2942 | { |
---|
2943 | if( u < LEVEL_RANGE ) |
---|
2944 | { |
---|
2945 | cSum[ u ] += ( Double )absc; |
---|
2946 | numSamples[ u ]++; |
---|
2947 | } |
---|
2948 | else |
---|
2949 | { |
---|
2950 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
2951 | numSamples[ LEVEL_RANGE ]++; |
---|
2952 | } |
---|
2953 | } |
---|
2954 | } |
---|
2955 | |
---|
2956 | return 0; |
---|
2957 | } |
---|
2958 | |
---|
2959 | /** Collect ARL statistics from one LCU |
---|
2960 | * \param pcCU |
---|
2961 | */ |
---|
2962 | Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) |
---|
2963 | { |
---|
2964 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
---|
2965 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
---|
2966 | |
---|
2967 | TCoeff* pCoeffY = rpcCU->getCoeffY(); |
---|
2968 | Int* pArlCoeffY = rpcCU->getArlCoeffY(); |
---|
2969 | |
---|
2970 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
2971 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
---|
2972 | |
---|
2973 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
2974 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
2975 | |
---|
2976 | // Collect stats to cSum[][] and numSamples[][] |
---|
2977 | for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) |
---|
2978 | { |
---|
2979 | UInt uiTrIdx = rpcCU->getTransformIdx(i); |
---|
2980 | |
---|
2981 | if(rpcCU->getPredictionMode(i) == MODE_INTER) |
---|
2982 | if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) |
---|
2983 | { |
---|
2984 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
2985 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
2986 | |
---|
2987 | pCoeffY += uiMinNumCoeffInCU; |
---|
2988 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
2989 | } |
---|
2990 | |
---|
2991 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
2992 | { |
---|
2993 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
2994 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
2995 | } |
---|
2996 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
2997 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
2998 | } |
---|
2999 | #endif |
---|
3000 | |
---|
3001 | #if HHI_MPI |
---|
3002 | Void TEncCu::xCheckRDCostMvInheritance( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhTextureModeDepth, Bool bSkipResidual, Bool bRecursiveCall ) |
---|
3003 | { |
---|
3004 | assert( rpcTempCU->getSlice()->getIsDepth() ); |
---|
3005 | TComDataCU *pcTextureCU = rpcTempCU->getSlice()->getTexturePic()->getCU( rpcTempCU->getAddr() ); |
---|
3006 | |
---|
3007 | const UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
3008 | const Int iQP = rpcTempCU->getQP( 0 ); |
---|
3009 | assert( bRecursiveCall == ( uhDepth != uhTextureModeDepth ) ); |
---|
3010 | |
---|
3011 | #if !MTK_UNCONSTRAINED_MVI |
---|
3012 | if( uhDepth == uhTextureModeDepth ) |
---|
3013 | { |
---|
3014 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
3015 | { |
---|
3016 | if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) ) |
---|
3017 | { |
---|
3018 | return; |
---|
3019 | } |
---|
3020 | } |
---|
3021 | } |
---|
3022 | #endif |
---|
3023 | |
---|
3024 | #if HHI_VSO |
---|
3025 | if( m_pcRdCost->getUseRenModel() && !bRecursiveCall) |
---|
3026 | { |
---|
3027 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
3028 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
3029 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr(); |
---|
3030 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
3031 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
3032 | } |
---|
3033 | #endif |
---|
3034 | |
---|
3035 | Bool bSplit = uhDepth < pcTextureCU->getDepth( rpcTempCU->getZorderIdxInCU() ); |
---|
3036 | if( bSplit ) |
---|
3037 | { |
---|
3038 | const UChar uhNextDepth = uhDepth+1; |
---|
3039 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
3040 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
3041 | |
---|
3042 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
3043 | { |
---|
3044 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
3045 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
3046 | |
---|
3047 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
3048 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getEntropySliceCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getEntropySliceCurEndCUAddr(); |
---|
3049 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
3050 | { |
---|
3051 | if( m_bUseSBACRD ) |
---|
3052 | { |
---|
3053 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
3054 | { |
---|
3055 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhDepth][CI_CURR_BEST]); |
---|
3056 | } |
---|
3057 | else |
---|
3058 | { |
---|
3059 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
3060 | } |
---|
3061 | } |
---|
3062 | |
---|
3063 | xCheckRDCostMvInheritance( pcSubBestPartCU, pcSubTempPartCU, uhTextureModeDepth, bSkipResidual, true ); |
---|
3064 | |
---|
3065 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
3066 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
3067 | } |
---|
3068 | else if (bInSlice) |
---|
3069 | { |
---|
3070 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
3071 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
3072 | } |
---|
3073 | } |
---|
3074 | |
---|
3075 | if( uhDepth == uhTextureModeDepth ) |
---|
3076 | { |
---|
3077 | xAddMVISignallingBits( rpcTempCU ); |
---|
3078 | } |
---|
3079 | |
---|
3080 | // DQP stuff |
---|
3081 | { |
---|
3082 | if( (g_uiMaxCUWidth>>uhDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
3083 | { |
---|
3084 | TComPic *pcPic = rpcTempCU->getPic(); |
---|
3085 | TComSlice *pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
3086 | Bool bHasRedisual = false; |
---|
3087 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
3088 | { |
---|
3089 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getEntropySliceCurStartCUAddr() ) && |
---|
3090 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
3091 | { |
---|
3092 | bHasRedisual = true; |
---|
3093 | break; |
---|
3094 | } |
---|
3095 | } |
---|
3096 | |
---|
3097 | UInt uiTargetPartIdx; |
---|
3098 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getEntropySliceCurStartCUAddr() ) |
---|
3099 | { |
---|
3100 | uiTargetPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
3101 | } |
---|
3102 | else |
---|
3103 | { |
---|
3104 | uiTargetPartIdx = 0; |
---|
3105 | } |
---|
3106 | if ( ! bHasRedisual ) |
---|
3107 | { |
---|
3108 | #if LOSSLESS_CODING |
---|
3109 | if (((rpcTempCU->getQP(uiTargetPartIdx) != rpcTempCU->getRefQP(uiTargetPartIdx)) ) && (rpcTempCU->getSlice()->getSPS()->getUseLossless())) |
---|
3110 | { |
---|
3111 | rpcTempCU->getTotalCost() = MAX_DOUBLE; |
---|
3112 | } |
---|
3113 | #endif |
---|
3114 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uhDepth ); // set QP to default QP |
---|
3115 | } |
---|
3116 | } |
---|
3117 | } |
---|
3118 | |
---|
3119 | if( m_bUseSBACRD ) |
---|
3120 | { |
---|
3121 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]); |
---|
3122 | } |
---|
3123 | } |
---|
3124 | else |
---|
3125 | { |
---|
3126 | rpcTempCU->setTextureModeDepthSubParts( uhTextureModeDepth, 0, uhDepth ); |
---|
3127 | rpcTempCU->copyTextureMotionDataFrom( pcTextureCU, uhDepth, rpcTempCU->getZorderIdxInCU() ); |
---|
3128 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
---|
3129 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
3130 | { |
---|
3131 | assert( rpcTempCU->getInterDir( ui ) != 0 ); |
---|
3132 | assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE ); |
---|
3133 | } |
---|
3134 | rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth ); |
---|
3135 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
3136 | |
---|
3137 | // get Original YUV data from picture |
---|
3138 | m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
3139 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
3140 | m_ppcOrigYuv[uhDepth], |
---|
3141 | m_ppcPredYuvTemp[uhDepth], |
---|
3142 | m_ppcResiYuvTemp[uhDepth], |
---|
3143 | m_ppcResiYuvBest[uhDepth], |
---|
3144 | m_ppcRecoYuvTemp[uhDepth], |
---|
3145 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
3146 | m_ppcResPredTmp [uhDepth], |
---|
3147 | #endif |
---|
3148 | bSkipResidual ); |
---|
3149 | |
---|
3150 | if( uhDepth == uhTextureModeDepth ) |
---|
3151 | { |
---|
3152 | xAddMVISignallingBits( rpcTempCU ); |
---|
3153 | } |
---|
3154 | xCheckDQP( rpcTempCU ); |
---|
3155 | } |
---|
3156 | |
---|
3157 | #if HHI_VSO |
---|
3158 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
3159 | { |
---|
3160 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
3161 | } |
---|
3162 | else |
---|
3163 | #endif |
---|
3164 | { |
---|
3165 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
3166 | } |
---|
3167 | |
---|
3168 | if( rpcTempCU->getPredictionMode( 0 ) == MODE_SKIP && uhDepth == uhTextureModeDepth ) |
---|
3169 | { |
---|
3170 | if( rpcTempCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uhDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
3171 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uhDepth ); // set QP to default QP |
---|
3172 | } |
---|
3173 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
3174 | rpcBestCU->copyToPic(uhDepth); // Copy Best data to Picture for next partition prediction. |
---|
3175 | |
---|
3176 | #if HHI_VSO |
---|
3177 | if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() ) |
---|
3178 | { |
---|
3179 | UInt uiWidth = m_ppcRecoYuvBest[uhDepth]->getWidth ( ); |
---|
3180 | UInt uiHeight = m_ppcRecoYuvBest[uhDepth]->getHeight ( ); |
---|
3181 | UInt uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride ( ); |
---|
3182 | Pel* piSrc = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 ); |
---|
3183 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
3184 | } |
---|
3185 | #endif |
---|
3186 | } |
---|
3187 | |
---|
3188 | Void TEncCu::xAddMVISignallingBits( TComDataCU* pcCU ) |
---|
3189 | { |
---|
3190 | const UChar uhDepth = pcCU->getTextureModeDepth( 0 ); |
---|
3191 | m_pcEntropyCoder->resetBits(); |
---|
3192 | xSaveDepthWidthHeight( pcCU ); |
---|
3193 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uhDepth, g_uiMaxCUHeight>>uhDepth, 0, uhDepth ); |
---|
3194 | pcCU->setDepthSubParts( uhDepth, 0 ); |
---|
3195 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
3196 | pcCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); |
---|
3197 | pcCU->setMergeIndexSubParts( HHI_MPI_MERGE_POS, 0, 0, uhDepth ); |
---|
3198 | |
---|
3199 | // check for skip mode |
---|
3200 | { |
---|
3201 | Bool bAllZero = true; |
---|
3202 | for( UInt ui = 0; ui < pcCU->getTotalNumPart(); ui++ ) |
---|
3203 | { |
---|
3204 | if( pcCU->getCbf( ui, TEXT_LUMA ) || pcCU->getCbf( ui, TEXT_CHROMA_U ) || pcCU->getCbf( ui, TEXT_CHROMA_V ) ) |
---|
3205 | { |
---|
3206 | bAllZero = false; |
---|
3207 | break; |
---|
3208 | } |
---|
3209 | } |
---|
3210 | if( bAllZero ) |
---|
3211 | pcCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
3212 | } |
---|
3213 | |
---|
3214 | |
---|
3215 | m_pcEntropyCoder->encodeSplitFlag( pcCU, 0, uhDepth, true ); |
---|
3216 | m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true ); |
---|
3217 | |
---|
3218 | if( pcCU->isSkipped( 0 ) ) |
---|
3219 | { |
---|
3220 | m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true ); |
---|
3221 | #if LGE_ILLUCOMP_B0045 |
---|
3222 | m_pcEntropyCoder->encodeICFlag( pcCU, 0, true ); |
---|
3223 | #endif |
---|
3224 | } |
---|
3225 | else |
---|
3226 | { |
---|
3227 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
---|
3228 | m_pcEntropyCoder->encodePartSize( pcCU, 0, uhDepth, true ); |
---|
3229 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
3230 | m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); |
---|
3231 | #if LGE_ILLUCOMP_B0045 |
---|
3232 | m_pcEntropyCoder->encodeICFlag( pcCU, 0, true ); |
---|
3233 | #endif |
---|
3234 | } |
---|
3235 | xRestoreDepthWidthHeight( pcCU ); |
---|
3236 | |
---|
3237 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
3238 | } |
---|
3239 | |
---|
3240 | Void TEncCu::xSaveDepthWidthHeight( TComDataCU* pcCU ) |
---|
3241 | { |
---|
3242 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
3243 | memcpy( m_puhDepthSaved, pcCU->getDepth(), iSizeInUchar ); |
---|
3244 | memcpy( m_puhWidthSaved, pcCU->getWidth(), iSizeInUchar ); |
---|
3245 | memcpy( m_puhHeightSaved, pcCU->getHeight(), iSizeInUchar ); |
---|
3246 | } |
---|
3247 | |
---|
3248 | Void TEncCu::xRestoreDepthWidthHeight( TComDataCU* pcCU ) |
---|
3249 | { |
---|
3250 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
3251 | memcpy( pcCU->getDepth(), m_puhDepthSaved, iSizeInUchar ); |
---|
3252 | memcpy( pcCU->getWidth(), m_puhWidthSaved, iSizeInUchar ); |
---|
3253 | memcpy( pcCU->getHeight(), m_puhHeightSaved, iSizeInUchar ); |
---|
3254 | } |
---|
3255 | #endif |
---|
3256 | |
---|
3257 | //! \} |
---|