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_QTLIMIT_PREDCODING_B0068 |
---|
454 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
---|
455 | TComPic *pcTexture = rpcBestCU->getSlice()->getTexturePic(); |
---|
456 | |
---|
457 | Bool depthMapDetect = (pcTexture != NULL); |
---|
458 | Bool bIntraSliceDetect = (rpcBestCU->getSlice()->getSliceType() == I_SLICE); |
---|
459 | |
---|
460 | Bool bTry2NxN = true; |
---|
461 | Bool bTryNx2N = true; |
---|
462 | #endif |
---|
463 | |
---|
464 | // get Original YUV data from picture |
---|
465 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
466 | |
---|
467 | // variables for fast encoder decision |
---|
468 | Bool bEarlySkip = false; |
---|
469 | Bool bTrySplit = true; |
---|
470 | Double fRD_Skip = MAX_DOUBLE; |
---|
471 | |
---|
472 | // variable for Early CU determination |
---|
473 | Bool bSubBranch = true; |
---|
474 | |
---|
475 | // variable for Cbf fast mode PU decision |
---|
476 | Bool doNotBlockPu = true; |
---|
477 | |
---|
478 | Bool bTrySplitDQP = true; |
---|
479 | |
---|
480 | static Double afCost [ MAX_CU_DEPTH ]; |
---|
481 | static Int aiNum [ MAX_CU_DEPTH ]; |
---|
482 | |
---|
483 | if ( rpcBestCU->getAddr() == 0 ) |
---|
484 | { |
---|
485 | ::memset( afCost, 0, sizeof( afCost ) ); |
---|
486 | ::memset( aiNum, 0, sizeof( aiNum ) ); |
---|
487 | } |
---|
488 | |
---|
489 | Bool bBoundary = false; |
---|
490 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
491 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
492 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
493 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
494 | |
---|
495 | #if LGE_ILLUCOMP_B0045 |
---|
496 | Bool bICEnabled = (!rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getViewId()); |
---|
497 | |
---|
498 | bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC(); |
---|
499 | #endif |
---|
500 | |
---|
501 | #if HHI_INTERVIEW_SKIP |
---|
502 | Bool bFullyRenderedSec = true ; |
---|
503 | if( m_pcEncCfg->getInterViewSkip() ) |
---|
504 | { |
---|
505 | Pel* pUsedSamples ; |
---|
506 | UInt uiStride ; |
---|
507 | pUsedSamples = pcPic->getUsedPelsMap()->getLumaAddr( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
508 | uiStride = pcPic->getUsedPelsMap()->getStride(); |
---|
509 | |
---|
510 | for ( Int y=0; y<m_ppcOrigYuv[uiDepth]->getHeight(); y++) |
---|
511 | { |
---|
512 | for ( Int x=0; x<m_ppcOrigYuv[uiDepth]->getWidth(); x++) |
---|
513 | { |
---|
514 | if( pUsedSamples[x] !=0 ) |
---|
515 | { |
---|
516 | bFullyRenderedSec = false ; |
---|
517 | break ; |
---|
518 | } |
---|
519 | } |
---|
520 | if ( !bFullyRenderedSec ) |
---|
521 | { |
---|
522 | break; |
---|
523 | } |
---|
524 | pUsedSamples += uiStride ; |
---|
525 | } |
---|
526 | } |
---|
527 | else |
---|
528 | { |
---|
529 | bFullyRenderedSec = false ; |
---|
530 | } |
---|
531 | |
---|
532 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
533 | if( bFullyRenderedSec ) |
---|
534 | { |
---|
535 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
536 | } |
---|
537 | else |
---|
538 | { |
---|
539 | m_pcRdCost->setLambdaScale( 1 ); |
---|
540 | } |
---|
541 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
542 | #endif |
---|
543 | |
---|
544 | #endif |
---|
545 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
---|
546 | Int iMinQP; |
---|
547 | Int iMaxQP; |
---|
548 | #if LOSSLESS_CODING |
---|
549 | Bool isAddLowestQP = false; |
---|
550 | #if H0736_AVC_STYLE_QP_RANGE |
---|
551 | Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
552 | #else |
---|
553 | Int lowestQP = 0; |
---|
554 | #endif |
---|
555 | #endif |
---|
556 | |
---|
557 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
558 | { |
---|
559 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
560 | #if H0736_AVC_STYLE_QP_RANGE |
---|
561 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
562 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
563 | #if LOSSLESS_CODING |
---|
564 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
565 | { |
---|
566 | isAddLowestQP = true; |
---|
567 | iMinQP = iMinQP - 1; |
---|
568 | |
---|
569 | } |
---|
570 | #endif |
---|
571 | #else |
---|
572 | iMinQP = Clip3( MIN_QP, MAX_QP, iBaseQP-idQP ); |
---|
573 | iMaxQP = Clip3( MIN_QP, MAX_QP, iBaseQP+idQP ); |
---|
574 | #if LOSSLESS_CODING |
---|
575 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
576 | { |
---|
577 | isAddLowestQP = true; |
---|
578 | iMinQP = iMinQP - 1; |
---|
579 | } |
---|
580 | #endif |
---|
581 | #endif |
---|
582 | } |
---|
583 | else |
---|
584 | { |
---|
585 | iMinQP = rpcTempCU->getQP(0); |
---|
586 | iMaxQP = rpcTempCU->getQP(0); |
---|
587 | } |
---|
588 | |
---|
589 | // If slice start or slice end is within this cu... |
---|
590 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
591 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getEntropySliceCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart(); |
---|
592 | Bool bSliceEnd = (pcSlice->getEntropySliceCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getEntropySliceCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart()); |
---|
593 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
594 | // We need to split, so don't try these modes. |
---|
595 | if(!bSliceEnd && !bSliceStart && bInsidePicture ) |
---|
596 | { |
---|
597 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
598 | { |
---|
599 | #if LOSSLESS_CODING |
---|
600 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
601 | { |
---|
602 | iQP = lowestQP; |
---|
603 | } |
---|
604 | #endif |
---|
605 | // variables for fast encoder decision |
---|
606 | bEarlySkip = false; |
---|
607 | bTrySplit = true; |
---|
608 | fRD_Skip = MAX_DOUBLE; |
---|
609 | |
---|
610 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
611 | |
---|
612 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
613 | //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU |
---|
614 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC()) |
---|
615 | { |
---|
616 | TComDataCU* pcTextureCU = pcTexture->getCU( rpcBestCU->getAddr() ); //Corresponding texture LCU |
---|
617 | UInt uiCUIdx = rpcBestCU->getZorderIdxInCU(); |
---|
618 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); //Depth cannot be more partitionned than the texture. |
---|
619 | if (pcTextureCU->getDepth(uiCUIdx) > uiDepth || pcTextureCU->getPartitionSize(uiCUIdx) == SIZE_NxN) //Texture was split. |
---|
620 | { |
---|
621 | bTrySplit = true; |
---|
622 | bTryNx2N = true; |
---|
623 | bTry2NxN = true; |
---|
624 | } |
---|
625 | else |
---|
626 | { |
---|
627 | bTrySplit = false; |
---|
628 | bTryNx2N = false; |
---|
629 | bTry2NxN = false; |
---|
630 | } |
---|
631 | } |
---|
632 | #endif |
---|
633 | |
---|
634 | // do inter modes, SKIP and 2Nx2N |
---|
635 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
636 | { |
---|
637 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
638 | // check availability of residual prediction |
---|
639 | Bool bResPredAvailable = false; |
---|
640 | Bool bResPredAllowed = (!rpcBestCU->getSlice()->getSPS()->isDepth () ); |
---|
641 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId () ); |
---|
642 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
---|
643 | if( bResPredAllowed ) |
---|
644 | { |
---|
645 | bResPredAvailable = rpcBestCU->getResidualSamples( 0, |
---|
646 | #if QC_SIMPLIFIEDIVRP_M24938 |
---|
647 | true , |
---|
648 | #endif |
---|
649 | m_ppcResPredTmp[uiDepth] ); |
---|
650 | } |
---|
651 | |
---|
652 | for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ ) |
---|
653 | { |
---|
654 | Bool bResPredFlag = ( uiResPrdId > 0 ); |
---|
655 | #if LGE_ILLUCOMP_B0045 |
---|
656 | for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++) |
---|
657 | { |
---|
658 | Bool bICFlag = (uiICId ? true : false); |
---|
659 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
660 | #endif |
---|
661 | #endif |
---|
662 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
663 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
664 | #endif |
---|
665 | // SKIP |
---|
666 | #if HHI_INTERVIEW_SKIP |
---|
667 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, bFullyRenderedSec ); |
---|
668 | #else |
---|
669 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU ); |
---|
670 | #endif |
---|
671 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
672 | |
---|
673 | // fast encoder decision for early skip |
---|
674 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
675 | { |
---|
676 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
677 | if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] ) |
---|
678 | { |
---|
679 | bEarlySkip = true; |
---|
680 | bTrySplit = false; |
---|
681 | } |
---|
682 | } |
---|
683 | #if LGE_ILLUCOMP_B0045_ENCSIMP |
---|
684 | if(bICFlag && rpcBestCU->getMergeFlag(0) && !rpcBestCU->getICFlag(0)) |
---|
685 | { |
---|
686 | bICEnabled = false; |
---|
687 | break; |
---|
688 | } |
---|
689 | #endif |
---|
690 | // 2Nx2N, NxN |
---|
691 | if ( !bEarlySkip ) |
---|
692 | { |
---|
693 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
694 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
695 | #endif |
---|
696 | #if HHI_INTERVIEW_SKIP |
---|
697 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); |
---|
698 | |
---|
699 | #else |
---|
700 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
701 | #endif |
---|
702 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
703 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
704 | { |
---|
705 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
706 | } |
---|
707 | } |
---|
708 | #if LGE_ILLUCOMP_B0045 |
---|
709 | } |
---|
710 | #endif |
---|
711 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
712 | } // uiResPrdId |
---|
713 | #endif |
---|
714 | } // != I_SLICE |
---|
715 | |
---|
716 | #if LGE_ILLUCOMP_B0045_ENCSIMP |
---|
717 | bICEnabled = rpcBestCU->getICFlag(0); |
---|
718 | #endif |
---|
719 | |
---|
720 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
721 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC()) |
---|
722 | { |
---|
723 | bTrySplitDQP = bTrySplit; |
---|
724 | } |
---|
725 | else |
---|
726 | { |
---|
727 | #endif |
---|
728 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
729 | { |
---|
730 | if(iQP == iBaseQP) |
---|
731 | { |
---|
732 | bTrySplitDQP = bTrySplit; |
---|
733 | } |
---|
734 | } |
---|
735 | else |
---|
736 | { |
---|
737 | bTrySplitDQP = bTrySplit; |
---|
738 | } |
---|
739 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
740 | } |
---|
741 | #endif |
---|
742 | |
---|
743 | #if LOSSLESS_CODING |
---|
744 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
745 | { |
---|
746 | iQP = iMinQP; |
---|
747 | } |
---|
748 | #endif |
---|
749 | } // end for iMinQP to iMaxQP |
---|
750 | |
---|
751 | |
---|
752 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
753 | { |
---|
754 | #if LOSSLESS_CODING |
---|
755 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
756 | { |
---|
757 | iQP = lowestQP; |
---|
758 | } |
---|
759 | #endif |
---|
760 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
761 | |
---|
762 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
763 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
764 | { |
---|
765 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
766 | // check availability of residual prediction |
---|
767 | Bool bResPredAvailable = false; |
---|
768 | Bool bResPredAllowed = (!rpcBestCU->getSlice()->getSPS()->isDepth () ); |
---|
769 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId () ); |
---|
770 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
---|
771 | if( bResPredAllowed ) |
---|
772 | { |
---|
773 | bResPredAvailable = rpcBestCU->getResidualSamples( 0, |
---|
774 | #if QC_SIMPLIFIEDIVRP_M24938 |
---|
775 | true, |
---|
776 | #endif |
---|
777 | m_ppcResPredTmp[uiDepth] ); |
---|
778 | } |
---|
779 | |
---|
780 | for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ ) |
---|
781 | { |
---|
782 | Bool bResPredFlag = ( uiResPrdId > 0 ); |
---|
783 | #if LGE_ILLUCOMP_B0045 |
---|
784 | for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++) |
---|
785 | { |
---|
786 | Bool bICFlag = (uiICId ? true : false); |
---|
787 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
788 | #endif |
---|
789 | #endif |
---|
790 | // 2Nx2N, NxN |
---|
791 | if ( !bEarlySkip ) |
---|
792 | { |
---|
793 | |
---|
794 | if(!( rpcBestCU->getSlice()->getSPS()->getDisInter4x4() && (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
795 | { |
---|
796 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu) |
---|
797 | { |
---|
798 | #if OL_QTLIMIT_PREDCODING_B0068 //try InterNxN |
---|
799 | if(bTrySplit) |
---|
800 | { |
---|
801 | #endif |
---|
802 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
803 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
804 | #endif |
---|
805 | #if HHI_INTERVIEW_SKIP |
---|
806 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFullyRenderedSec ); |
---|
807 | #else |
---|
808 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
809 | #endif |
---|
810 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
811 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
812 | } |
---|
813 | #endif |
---|
814 | } |
---|
815 | } |
---|
816 | } |
---|
817 | |
---|
818 | { // 2NxN, Nx2N |
---|
819 | #if OL_QTLIMIT_PREDCODING_B0068 //try Nx2N |
---|
820 | if(bTryNx2N) |
---|
821 | { |
---|
822 | #endif |
---|
823 | if(doNotBlockPu) |
---|
824 | { |
---|
825 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
826 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
827 | #endif |
---|
828 | #if HHI_INTERVIEW_SKIP |
---|
829 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFullyRenderedSec ); |
---|
830 | #else |
---|
831 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); |
---|
832 | #endif |
---|
833 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
834 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
835 | { |
---|
836 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
837 | } |
---|
838 | } |
---|
839 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
840 | } |
---|
841 | #endif |
---|
842 | |
---|
843 | #if OL_QTLIMIT_PREDCODING_B0068 //try 2NxN |
---|
844 | if(bTry2NxN) |
---|
845 | { |
---|
846 | #endif |
---|
847 | if(doNotBlockPu) |
---|
848 | { |
---|
849 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
850 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
851 | #endif |
---|
852 | #if HHI_INTERVIEW_SKIP |
---|
853 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxN, bFullyRenderedSec ); |
---|
854 | #else |
---|
855 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); |
---|
856 | #endif |
---|
857 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
858 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
859 | { |
---|
860 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
861 | } |
---|
862 | } |
---|
863 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
864 | } |
---|
865 | #endif |
---|
866 | } |
---|
867 | |
---|
868 | #if 1 |
---|
869 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
870 | if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) |
---|
871 | { |
---|
872 | #if AMP_ENC_SPEEDUP |
---|
873 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
874 | |
---|
875 | #if AMP_MRG |
---|
876 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
877 | |
---|
878 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
879 | #else |
---|
880 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
881 | #endif |
---|
882 | |
---|
883 | //! Do horizontal AMP |
---|
884 | if ( bTestAMP_Hor ) |
---|
885 | { |
---|
886 | #if OL_QTLIMIT_PREDCODING_B0068 //try 2NxnU & 2NxnD |
---|
887 | if(bTry2NxN) |
---|
888 | { |
---|
889 | #endif |
---|
890 | if(doNotBlockPu) |
---|
891 | { |
---|
892 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
893 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
894 | #endif |
---|
895 | #if HHI_INTERVIEW_SKIP |
---|
896 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec ); |
---|
897 | #else |
---|
898 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
899 | #endif |
---|
900 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
901 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
902 | { |
---|
903 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
904 | } |
---|
905 | } |
---|
906 | if(doNotBlockPu) |
---|
907 | { |
---|
908 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
909 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
910 | #endif |
---|
911 | #if HHI_INTERVIEW_SKIP |
---|
912 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec ); |
---|
913 | #else |
---|
914 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
915 | #endif |
---|
916 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
917 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
918 | { |
---|
919 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
920 | } |
---|
921 | } |
---|
922 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
923 | } |
---|
924 | #endif |
---|
925 | } |
---|
926 | #if AMP_MRG |
---|
927 | else if ( bTestMergeAMP_Hor ) |
---|
928 | { |
---|
929 | #if OL_QTLIMIT_PREDCODING_B0068 //try 2NxnU & 2NxnD Merge |
---|
930 | if(bTry2NxN) |
---|
931 | { |
---|
932 | #endif |
---|
933 | if(doNotBlockPu) |
---|
934 | { |
---|
935 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
936 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
937 | #endif |
---|
938 | #if HHI_INTERVIEW_SKIP |
---|
939 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec, true ); |
---|
940 | #else |
---|
941 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); |
---|
942 | #endif |
---|
943 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
944 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
945 | { |
---|
946 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
947 | } |
---|
948 | } |
---|
949 | if(doNotBlockPu) |
---|
950 | { |
---|
951 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
952 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
953 | #endif |
---|
954 | #if HHI_INTERVIEW_SKIP |
---|
955 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec, true ); |
---|
956 | #else |
---|
957 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); |
---|
958 | #endif |
---|
959 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
960 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
961 | { |
---|
962 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
963 | } |
---|
964 | } |
---|
965 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
966 | } |
---|
967 | #endif |
---|
968 | } |
---|
969 | #endif |
---|
970 | |
---|
971 | //! Do horizontal AMP |
---|
972 | if ( bTestAMP_Ver ) |
---|
973 | { |
---|
974 | #if OL_QTLIMIT_PREDCODING_B0068 //try nLx2N & nRx2N |
---|
975 | if(bTryNx2N) |
---|
976 | { |
---|
977 | #endif |
---|
978 | if(doNotBlockPu) |
---|
979 | { |
---|
980 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
981 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
982 | #endif |
---|
983 | #if HHI_INTERVIEW_SKIP |
---|
984 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec ); |
---|
985 | #else |
---|
986 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
987 | #endif |
---|
988 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
989 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
990 | { |
---|
991 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
992 | } |
---|
993 | } |
---|
994 | if(doNotBlockPu) |
---|
995 | { |
---|
996 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
997 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
998 | #endif |
---|
999 | #if HHI_INTERVIEW_SKIP |
---|
1000 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec ); |
---|
1001 | #else |
---|
1002 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
1003 | #endif |
---|
1004 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1005 | } |
---|
1006 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
1007 | } |
---|
1008 | #endif |
---|
1009 | } |
---|
1010 | #if AMP_MRG |
---|
1011 | else if ( bTestMergeAMP_Ver ) |
---|
1012 | { |
---|
1013 | #if OL_QTLIMIT_PREDCODING_B0068 //try nLx2N & nRx2N (Merge) |
---|
1014 | if(bTryNx2N) |
---|
1015 | { |
---|
1016 | #endif |
---|
1017 | if(doNotBlockPu) |
---|
1018 | { |
---|
1019 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1020 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1021 | #endif |
---|
1022 | #if HHI_INTERVIEW_SKIP |
---|
1023 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec, true ); |
---|
1024 | #else |
---|
1025 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); |
---|
1026 | #endif |
---|
1027 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1028 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
1029 | { |
---|
1030 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
1031 | } |
---|
1032 | } |
---|
1033 | if(doNotBlockPu) |
---|
1034 | { |
---|
1035 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1036 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1037 | #endif |
---|
1038 | #if HHI_INTERVIEW_SKIP |
---|
1039 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec, true ); |
---|
1040 | #else |
---|
1041 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); |
---|
1042 | #endif |
---|
1043 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1044 | } |
---|
1045 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
1046 | } |
---|
1047 | #endif |
---|
1048 | } |
---|
1049 | #endif |
---|
1050 | |
---|
1051 | #else |
---|
1052 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1053 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1054 | #endif |
---|
1055 | #if HHI_INTERVIEW_SKIP |
---|
1056 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec ); |
---|
1057 | #else |
---|
1058 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
1059 | #endif |
---|
1060 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1061 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1062 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1063 | #endif |
---|
1064 | #if HHI_INTERVIEW_SKIP |
---|
1065 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec ); |
---|
1066 | #else |
---|
1067 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
1068 | #endif |
---|
1069 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1070 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1071 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1072 | #endif |
---|
1073 | #if HHI_INTERVIEW_SKIP |
---|
1074 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec ); |
---|
1075 | #else |
---|
1076 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
1077 | #endif |
---|
1078 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1079 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1080 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
1081 | #endif |
---|
1082 | #if HHI_INTERVIEW_SKIP |
---|
1083 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec ); |
---|
1084 | #else |
---|
1085 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
1086 | #endif |
---|
1087 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1088 | |
---|
1089 | #endif |
---|
1090 | } //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
1091 | #endif |
---|
1092 | #if LGE_ILLUCOMP_B0045 |
---|
1093 | } |
---|
1094 | #endif |
---|
1095 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1096 | } // uiResPrdId |
---|
1097 | #endif |
---|
1098 | } // != I_SLICE |
---|
1099 | |
---|
1100 | // initialize PCM flag |
---|
1101 | rpcTempCU->setIPCMFlag( 0, false); |
---|
1102 | rpcTempCU->setIPCMFlagSubParts ( false, 0, uiDepth); //SUB_LCU_DQP |
---|
1103 | |
---|
1104 | // do normal intra modes |
---|
1105 | if ( !bEarlySkip ) |
---|
1106 | { |
---|
1107 | // speedup for inter frames |
---|
1108 | #if HHI_INTERVIEW_SKIP |
---|
1109 | if( ( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
1110 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
1111 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
1112 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) && !bFullyRenderedSec ) // avoid very complex intra if it is unlikely |
---|
1113 | #else |
---|
1114 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
1115 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
1116 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
1117 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely |
---|
1118 | #endif |
---|
1119 | { |
---|
1120 | #if LGE_ILLUCOMP_B0045 |
---|
1121 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
---|
1122 | #endif |
---|
1123 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
1124 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1125 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1126 | { |
---|
1127 | #if OL_QTLIMIT_PREDCODING_B0068 //Try IntraNxN |
---|
1128 | if(bTrySplit) |
---|
1129 | { |
---|
1130 | #endif |
---|
1131 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
1132 | { |
---|
1133 | #if LGE_ILLUCOMP_B0045 |
---|
1134 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
---|
1135 | #endif |
---|
1136 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
1137 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1138 | } |
---|
1139 | #if OL_QTLIMIT_PREDCODING_B0068 |
---|
1140 | } |
---|
1141 | #endif |
---|
1142 | } |
---|
1143 | } |
---|
1144 | } |
---|
1145 | |
---|
1146 | // test PCM |
---|
1147 | if(pcPic->getSlice(0)->getSPS()->getUsePCM() |
---|
1148 | && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) |
---|
1149 | && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) |
---|
1150 | { |
---|
1151 | UInt uiRawBits = (g_uiBitDepth * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) * 3 / 2); |
---|
1152 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
1153 | #if HHI_VSO |
---|
1154 | Double dRDCostTemp = m_pcRdCost->getUseVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0); |
---|
1155 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp )) |
---|
1156 | #else |
---|
1157 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
1158 | #endif |
---|
1159 | { |
---|
1160 | #if LGE_ILLUCOMP_B0045 |
---|
1161 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
---|
1162 | #endif |
---|
1163 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
1164 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1165 | } |
---|
1166 | } |
---|
1167 | #if HHI_MPI |
---|
1168 | if( rpcBestCU->getSlice()->getSPS()->getUseMVI() && rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
1169 | { |
---|
1170 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, false, false ); |
---|
1171 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1172 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, true, false ); |
---|
1173 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1174 | } |
---|
1175 | #endif |
---|
1176 | #if LOSSLESS_CODING |
---|
1177 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
1178 | { |
---|
1179 | iQP = iMinQP; |
---|
1180 | } |
---|
1181 | #endif |
---|
1182 | } |
---|
1183 | |
---|
1184 | m_pcEntropyCoder->resetBits(); |
---|
1185 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
1186 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1187 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1188 | { |
---|
1189 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1190 | } |
---|
1191 | |
---|
1192 | #if HHI_VSO |
---|
1193 | if ( m_pcRdCost->getUseVSO() ) |
---|
1194 | { |
---|
1195 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
1196 | } |
---|
1197 | else |
---|
1198 | #endif |
---|
1199 | { |
---|
1200 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
1201 | } |
---|
1202 | |
---|
1203 | // accumulate statistics for early skip |
---|
1204 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
1205 | { |
---|
1206 | if ( rpcBestCU->isSkipped(0) ) |
---|
1207 | { |
---|
1208 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
1209 | afCost[ iIdx ] += rpcBestCU->getTotalCost(); |
---|
1210 | aiNum [ iIdx ] ++; |
---|
1211 | } |
---|
1212 | } |
---|
1213 | |
---|
1214 | // Early CU determination |
---|
1215 | if( m_pcEncCfg->getUseEarlyCU() && ((*rpcBestCU->getPredictionMode()) == 0) ) |
---|
1216 | { |
---|
1217 | bSubBranch = false; |
---|
1218 | } |
---|
1219 | else |
---|
1220 | { |
---|
1221 | bSubBranch = true; |
---|
1222 | } |
---|
1223 | #if HHI_INTERVIEW_SKIP |
---|
1224 | rpcBestCU->setRenderableSubParts(bFullyRenderedSec,0,rpcBestCU->getDepth( 0 )) ; |
---|
1225 | #endif |
---|
1226 | } |
---|
1227 | else if(!(bSliceEnd && bInsidePicture)) |
---|
1228 | { |
---|
1229 | bBoundary = true; |
---|
1230 | } |
---|
1231 | |
---|
1232 | #if LOSSLESS_CODING |
---|
1233 | // copy orginal YUV samples to PCM buffer |
---|
1234 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
1235 | { |
---|
1236 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
1237 | } |
---|
1238 | #endif |
---|
1239 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
1240 | { |
---|
1241 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
1242 | #if H0736_AVC_STYLE_QP_RANGE |
---|
1243 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
1244 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
1245 | #if LOSSLESS_CODING |
---|
1246 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
1247 | { |
---|
1248 | isAddLowestQP = true; |
---|
1249 | iMinQP = iMinQP - 1; |
---|
1250 | } |
---|
1251 | #endif |
---|
1252 | #else |
---|
1253 | iMinQP = Clip3( MIN_QP, MAX_QP, iBaseQP-idQP ); |
---|
1254 | iMaxQP = Clip3( MIN_QP, MAX_QP, iBaseQP+idQP ); |
---|
1255 | #if LOSSLESS_CODING |
---|
1256 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
1257 | { |
---|
1258 | isAddLowestQP = true; |
---|
1259 | iMinQP = iMinQP - 1; |
---|
1260 | } |
---|
1261 | #endif |
---|
1262 | #endif |
---|
1263 | } |
---|
1264 | else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
1265 | { |
---|
1266 | iMinQP = iBaseQP; |
---|
1267 | iMaxQP = iBaseQP; |
---|
1268 | } |
---|
1269 | else |
---|
1270 | { |
---|
1271 | Int iStartQP; |
---|
1272 | if( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getEntropySliceCurStartCUAddr()) |
---|
1273 | { |
---|
1274 | iStartQP = rpcTempCU->getQP(0); |
---|
1275 | } |
---|
1276 | else |
---|
1277 | { |
---|
1278 | UInt uiCurSliceStartPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
1279 | iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx); |
---|
1280 | } |
---|
1281 | iMinQP = iStartQP; |
---|
1282 | iMaxQP = iStartQP; |
---|
1283 | } |
---|
1284 | |
---|
1285 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
1286 | { |
---|
1287 | #if LOSSLESS_CODING |
---|
1288 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
1289 | { |
---|
1290 | iQP = lowestQP; |
---|
1291 | } |
---|
1292 | #endif |
---|
1293 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
1294 | |
---|
1295 | // further split |
---|
1296 | if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
1297 | { |
---|
1298 | #if HHI_VSO |
---|
1299 | // reset Model |
---|
1300 | if( m_pcRdCost->getUseRenModel() ) |
---|
1301 | { |
---|
1302 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( ); |
---|
1303 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight( ); |
---|
1304 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
---|
1305 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
1306 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1307 | } |
---|
1308 | #endif |
---|
1309 | UChar uhNextDepth = uiDepth+1; |
---|
1310 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
1311 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
1312 | |
---|
1313 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
1314 | { |
---|
1315 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
1316 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
1317 | |
---|
1318 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getEntropySliceCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getEntropySliceCurEndCUAddr(); |
---|
1319 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1320 | { |
---|
1321 | if( m_bUseSBACRD ) |
---|
1322 | { |
---|
1323 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
1324 | { |
---|
1325 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
1326 | } |
---|
1327 | else |
---|
1328 | { |
---|
1329 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
1330 | } |
---|
1331 | } |
---|
1332 | |
---|
1333 | #if AMP_ENC_SPEEDUP |
---|
1334 | if ( rpcBestCU->isIntra(0) ) |
---|
1335 | { |
---|
1336 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE ); |
---|
1337 | } |
---|
1338 | else |
---|
1339 | { |
---|
1340 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) ); |
---|
1341 | } |
---|
1342 | #else |
---|
1343 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
1344 | #endif |
---|
1345 | |
---|
1346 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
1347 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
1348 | |
---|
1349 | #if HHI_VSO |
---|
1350 | #if HHI_VSO_SET_OPTIM |
---|
1351 | #else |
---|
1352 | if( m_pcRdCost->getUseRenModel() ) // necessary ?? |
---|
1353 | { |
---|
1354 | UInt uiWidth = m_ppcRecoYuvBest[uhNextDepth]->getWidth ( ); |
---|
1355 | UInt uiHeight = m_ppcRecoYuvBest[uhNextDepth]->getHeight ( ); |
---|
1356 | Pel* piSrc = m_ppcRecoYuvBest[uhNextDepth]->getLumaAddr( 0 ); |
---|
1357 | UInt uiSrcStride = m_ppcRecoYuvBest[uhNextDepth]->getStride ( ); |
---|
1358 | m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1359 | } |
---|
1360 | #endif |
---|
1361 | #endif |
---|
1362 | } |
---|
1363 | else if (bInSlice) |
---|
1364 | { |
---|
1365 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
1366 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
1367 | } |
---|
1368 | } |
---|
1369 | |
---|
1370 | if( !bBoundary ) |
---|
1371 | { |
---|
1372 | m_pcEntropyCoder->resetBits(); |
---|
1373 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
1374 | |
---|
1375 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1376 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1377 | { |
---|
1378 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1379 | } |
---|
1380 | } |
---|
1381 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
1382 | if( bFullyRenderedSec ) |
---|
1383 | { |
---|
1384 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
1385 | } |
---|
1386 | else |
---|
1387 | { |
---|
1388 | m_pcRdCost->setLambdaScale( 1 ); |
---|
1389 | } |
---|
1390 | #endif |
---|
1391 | |
---|
1392 | #if HHI_VSO |
---|
1393 | if ( m_pcRdCost->getUseVSO() ) |
---|
1394 | { |
---|
1395 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1396 | } |
---|
1397 | else |
---|
1398 | #endif |
---|
1399 | { |
---|
1400 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1401 | } |
---|
1402 | |
---|
1403 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
1404 | { |
---|
1405 | Bool bHasRedisual = false; |
---|
1406 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
1407 | { |
---|
1408 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getEntropySliceCurStartCUAddr() ) && |
---|
1409 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
1410 | { |
---|
1411 | bHasRedisual = true; |
---|
1412 | break; |
---|
1413 | } |
---|
1414 | } |
---|
1415 | |
---|
1416 | UInt uiTargetPartIdx; |
---|
1417 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getEntropySliceCurStartCUAddr() ) |
---|
1418 | { |
---|
1419 | uiTargetPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
1420 | } |
---|
1421 | else |
---|
1422 | { |
---|
1423 | uiTargetPartIdx = 0; |
---|
1424 | } |
---|
1425 | if ( bHasRedisual ) |
---|
1426 | { |
---|
1427 | #if !RDO_WITHOUT_DQP_BITS |
---|
1428 | m_pcEntropyCoder->resetBits(); |
---|
1429 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
1430 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
1431 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1432 | { |
---|
1433 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1434 | } |
---|
1435 | #if HHI_VSO |
---|
1436 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1437 | { |
---|
1438 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1439 | } |
---|
1440 | else |
---|
1441 | #endif |
---|
1442 | { |
---|
1443 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1444 | } |
---|
1445 | #endif |
---|
1446 | } |
---|
1447 | else |
---|
1448 | { |
---|
1449 | #if LOSSLESS_CODING |
---|
1450 | if (((rpcTempCU->getQP(uiTargetPartIdx) != rpcTempCU->getRefQP(uiTargetPartIdx)) ) && (rpcTempCU->getSlice()->getSPS()->getUseLossless())) |
---|
1451 | { |
---|
1452 | rpcTempCU->getTotalCost() = MAX_DOUBLE; |
---|
1453 | } |
---|
1454 | #endif |
---|
1455 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
1456 | } |
---|
1457 | } |
---|
1458 | |
---|
1459 | if( m_bUseSBACRD ) |
---|
1460 | { |
---|
1461 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1462 | } |
---|
1463 | Bool bEntropyLimit=false; |
---|
1464 | Bool bSliceLimit=false; |
---|
1465 | bSliceLimit=rpcBestCU->getSlice()->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
---|
1466 | if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&m_pcEncCfg->getUseSBACRD()) |
---|
1467 | { |
---|
1468 | if(rpcBestCU->getTotalBins()>rpcBestCU->getSlice()->getEntropySliceArgument()) |
---|
1469 | { |
---|
1470 | bEntropyLimit=true; |
---|
1471 | } |
---|
1472 | } |
---|
1473 | else if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE) |
---|
1474 | { |
---|
1475 | if(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getEntropySliceArgument()) |
---|
1476 | { |
---|
1477 | bEntropyLimit=true; |
---|
1478 | } |
---|
1479 | } |
---|
1480 | if(rpcBestCU->getDepth(0)>=rpcBestCU->getSlice()->getPPS()->getSliceGranularity()) |
---|
1481 | { |
---|
1482 | bSliceLimit=false; |
---|
1483 | bEntropyLimit=false; |
---|
1484 | } |
---|
1485 | if(bSliceLimit||bEntropyLimit) |
---|
1486 | { |
---|
1487 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
---|
1488 | } |
---|
1489 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction |
---|
1490 | } // with sub partitioned prediction. |
---|
1491 | #if LOSSLESS_CODING |
---|
1492 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
1493 | { |
---|
1494 | iQP = iMinQP; |
---|
1495 | } |
---|
1496 | #endif |
---|
1497 | } // SPLIT- QP Loop |
---|
1498 | |
---|
1499 | #if HHI_VSO |
---|
1500 | if( m_pcRdCost->getUseRenModel() ) |
---|
1501 | { |
---|
1502 | UInt uiWidth = m_ppcRecoYuvBest[uiDepth]->getWidth ( ); |
---|
1503 | UInt uiHeight = m_ppcRecoYuvBest[uiDepth]->getHeight ( ); |
---|
1504 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
1505 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride ( ); |
---|
1506 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1507 | } |
---|
1508 | #endif |
---|
1509 | |
---|
1510 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
1511 | |
---|
1512 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
---|
1513 | if( bBoundary ||(bSliceEnd && bInsidePicture)) |
---|
1514 | { |
---|
1515 | return; |
---|
1516 | } |
---|
1517 | |
---|
1518 | // Assert if Best prediction mode is NONE |
---|
1519 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
1520 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
1521 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
1522 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
1523 | } |
---|
1524 | |
---|
1525 | /** finish encoding a cu and handle end-of-slice conditions |
---|
1526 | * \param pcCU |
---|
1527 | * \param uiAbsPartIdx |
---|
1528 | * \param uiDepth |
---|
1529 | * \returns Void |
---|
1530 | */ |
---|
1531 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1532 | { |
---|
1533 | TComPic* pcPic = pcCU->getPic(); |
---|
1534 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1535 | |
---|
1536 | //Calculate end address |
---|
1537 | UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; |
---|
1538 | |
---|
1539 | UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
1540 | UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
1541 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1542 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1543 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
1544 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
1545 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
1546 | { |
---|
1547 | uiInternalAddress--; |
---|
1548 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1549 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1550 | } |
---|
1551 | uiInternalAddress++; |
---|
1552 | if(uiInternalAddress==pcCU->getPic()->getNumPartInCU()) |
---|
1553 | { |
---|
1554 | uiInternalAddress = 0; |
---|
1555 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
1556 | } |
---|
1557 | UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
1558 | |
---|
1559 | // Encode slice finish |
---|
1560 | Bool bTerminateSlice = false; |
---|
1561 | if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress) |
---|
1562 | { |
---|
1563 | bTerminateSlice = true; |
---|
1564 | } |
---|
1565 | UInt uiGranularityWidth = g_uiMaxCUWidth>>(pcSlice->getPPS()->getSliceGranularity()); |
---|
1566 | uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1567 | uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1568 | Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth)) |
---|
1569 | &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); |
---|
1570 | |
---|
1571 | #if BURST_IPCM |
---|
1572 | if(granularityBoundary && (!(pcCU->getIPCMFlag(uiAbsPartIdx) && ( pcCU->getNumSucIPCM() > 1 )))) |
---|
1573 | #else |
---|
1574 | if(granularityBoundary) |
---|
1575 | #endif |
---|
1576 | { |
---|
1577 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
1578 | if (!bTerminateSlice) |
---|
1579 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
1580 | } |
---|
1581 | |
---|
1582 | Int numberOfWrittenBits = 0; |
---|
1583 | if (m_pcBitCounter) |
---|
1584 | { |
---|
1585 | numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1586 | } |
---|
1587 | |
---|
1588 | // Calculate slice end IF this CU puts us over slice bit size. |
---|
1589 | unsigned iGranularitySize = pcCU->getPic()->getNumPartInCU()>>(pcSlice->getPPS()->getSliceGranularity()<<1); |
---|
1590 | int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; |
---|
1591 | if(iGranularityEnd<=pcSlice->getEntropySliceCurStartCUAddr()) |
---|
1592 | { |
---|
1593 | iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); |
---|
1594 | } |
---|
1595 | // Set slice end parameter |
---|
1596 | if(pcSlice->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) |
---|
1597 | { |
---|
1598 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1599 | pcSlice->setSliceCurEndCUAddr(iGranularityEnd); |
---|
1600 | return; |
---|
1601 | } |
---|
1602 | // Set entropy slice end parameter |
---|
1603 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1604 | { |
---|
1605 | TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); |
---|
1606 | UInt uiBinsCoded = pppcRDSbacCoder->getBinsCoded(); |
---|
1607 | if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+uiBinsCoded>pcSlice->getEntropySliceArgument()) |
---|
1608 | { |
---|
1609 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1610 | return; |
---|
1611 | } |
---|
1612 | } |
---|
1613 | else |
---|
1614 | { |
---|
1615 | if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+numberOfWrittenBits>pcSlice->getEntropySliceArgument()) |
---|
1616 | { |
---|
1617 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1618 | return; |
---|
1619 | } |
---|
1620 | } |
---|
1621 | if(granularityBoundary) |
---|
1622 | { |
---|
1623 | pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); |
---|
1624 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1625 | { |
---|
1626 | TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); |
---|
1627 | pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+pppcRDSbacCoder->getBinsCoded()); |
---|
1628 | pppcRDSbacCoder->setBinsCoded( 0 ); |
---|
1629 | } |
---|
1630 | else |
---|
1631 | { |
---|
1632 | pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+numberOfWrittenBits); |
---|
1633 | } |
---|
1634 | if (m_pcBitCounter) |
---|
1635 | { |
---|
1636 | m_pcEntropyCoder->resetBits(); |
---|
1637 | } |
---|
1638 | } |
---|
1639 | } |
---|
1640 | |
---|
1641 | /** Compute QP for each CU |
---|
1642 | * \param pcCU Target CU |
---|
1643 | * \param uiDepth CU depth |
---|
1644 | * \returns quantization parameter |
---|
1645 | */ |
---|
1646 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
1647 | { |
---|
1648 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
1649 | Int iQpOffset = 0; |
---|
1650 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
1651 | { |
---|
1652 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
1653 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
1654 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
1655 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
1656 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
1657 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
1658 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
1659 | |
---|
1660 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
1661 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
1662 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
1663 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
1664 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
1665 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
1666 | } |
---|
1667 | #if H0736_AVC_STYLE_QP_RANGE |
---|
1668 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
1669 | #else |
---|
1670 | return Clip3( MIN_QP, MAX_QP, iBaseQp+iQpOffset ); |
---|
1671 | #endif |
---|
1672 | } |
---|
1673 | |
---|
1674 | /** encode a CU block recursively |
---|
1675 | * \param pcCU |
---|
1676 | * \param uiAbsPartIdx |
---|
1677 | * \param uiDepth |
---|
1678 | * \returns Void |
---|
1679 | */ |
---|
1680 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1681 | { |
---|
1682 | TComPic* pcPic = pcCU->getPic(); |
---|
1683 | |
---|
1684 | Bool bBoundary = false; |
---|
1685 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1686 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
1687 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1688 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
1689 | |
---|
1690 | #if BURST_IPCM |
---|
1691 | if( getCheckBurstIPCMFlag() ) |
---|
1692 | { |
---|
1693 | pcCU->setLastCUSucIPCMFlag( checkLastCUSucIPCM( pcCU, uiAbsPartIdx )); |
---|
1694 | pcCU->setNumSucIPCM( countNumSucIPCM ( pcCU, uiAbsPartIdx ) ); |
---|
1695 | } |
---|
1696 | #endif |
---|
1697 | |
---|
1698 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1699 | // If slice start is within this cu... |
---|
1700 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
1701 | pcSlice->getEntropySliceCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); |
---|
1702 | // We need to split, so don't try these modes. |
---|
1703 | if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1704 | { |
---|
1705 | #if HHI_MPI |
---|
1706 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth < pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
1707 | { |
---|
1708 | #endif |
---|
1709 | |
---|
1710 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1711 | |
---|
1712 | #if HHI_MPI |
---|
1713 | } |
---|
1714 | #endif |
---|
1715 | } |
---|
1716 | else |
---|
1717 | { |
---|
1718 | bBoundary = true; |
---|
1719 | } |
---|
1720 | |
---|
1721 | #if HHI_MPI |
---|
1722 | if( uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
1723 | { |
---|
1724 | xSaveDepthWidthHeight( pcCU ); |
---|
1725 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
1726 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
1727 | |
---|
1728 | if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1729 | { |
---|
1730 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1731 | } |
---|
1732 | |
---|
1733 | if( !pcCU->getSlice()->isIntra() ) |
---|
1734 | { |
---|
1735 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1736 | } |
---|
1737 | |
---|
1738 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1739 | { |
---|
1740 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1741 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1742 | xRestoreDepthWidthHeight( pcCU ); |
---|
1743 | return; |
---|
1744 | } |
---|
1745 | |
---|
1746 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1747 | |
---|
1748 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1749 | |
---|
1750 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1751 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1752 | xRestoreDepthWidthHeight( pcCU ); |
---|
1753 | } |
---|
1754 | #endif |
---|
1755 | |
---|
1756 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
1757 | { |
---|
1758 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
1759 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
1760 | { |
---|
1761 | setdQPFlag(true); |
---|
1762 | } |
---|
1763 | #if BURST_IPCM |
---|
1764 | pcCU->setNumSucIPCM(0); |
---|
1765 | pcCU->setLastCUSucIPCMFlag(false); |
---|
1766 | #endif |
---|
1767 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1768 | { |
---|
1769 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1770 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1771 | Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getEntropySliceCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getEntropySliceCurEndCUAddr(); |
---|
1772 | if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1773 | { |
---|
1774 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
1775 | } |
---|
1776 | } |
---|
1777 | return; |
---|
1778 | } |
---|
1779 | |
---|
1780 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
1781 | { |
---|
1782 | setdQPFlag(true); |
---|
1783 | } |
---|
1784 | #if HHI_MPI |
---|
1785 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1786 | { |
---|
1787 | #endif |
---|
1788 | if( !pcCU->getSlice()->isIntra() ) |
---|
1789 | { |
---|
1790 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1791 | } |
---|
1792 | #if HHI_MPI |
---|
1793 | } |
---|
1794 | #endif |
---|
1795 | |
---|
1796 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1797 | { |
---|
1798 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1799 | #if LGE_ILLUCOMP_B0045 |
---|
1800 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
1801 | #endif |
---|
1802 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1803 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1804 | #endif |
---|
1805 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1806 | return; |
---|
1807 | } |
---|
1808 | #if HHI_MPI |
---|
1809 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1810 | { |
---|
1811 | #endif |
---|
1812 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1813 | |
---|
1814 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1815 | |
---|
1816 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
1817 | { |
---|
1818 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
1819 | |
---|
1820 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
1821 | { |
---|
1822 | // Encode slice finish |
---|
1823 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1824 | return; |
---|
1825 | } |
---|
1826 | } |
---|
1827 | |
---|
1828 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1829 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1830 | #if LGE_ILLUCOMP_B0045 |
---|
1831 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
1832 | #endif |
---|
1833 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1834 | if( !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
1835 | { |
---|
1836 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1837 | } |
---|
1838 | #endif |
---|
1839 | #if HHI_MPI |
---|
1840 | } |
---|
1841 | #endif |
---|
1842 | |
---|
1843 | // Encode Coefficients |
---|
1844 | Bool bCodeDQP = getdQPFlag(); |
---|
1845 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP ); |
---|
1846 | setdQPFlag( bCodeDQP ); |
---|
1847 | |
---|
1848 | // --- write terminating bit --- |
---|
1849 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1850 | } |
---|
1851 | |
---|
1852 | /** check RD costs for a CU block encoded with merge |
---|
1853 | * \param rpcBestCU |
---|
1854 | * \param rpcTempCU |
---|
1855 | * \returns Void |
---|
1856 | */ |
---|
1857 | #if HHI_INTERVIEW_SKIP |
---|
1858 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
1859 | #else |
---|
1860 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1861 | #endif |
---|
1862 | { |
---|
1863 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
1864 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
1865 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
1866 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
1867 | #else |
---|
1868 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
1869 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1870 | #endif |
---|
1871 | Int numValidMergeCand = 0; |
---|
1872 | |
---|
1873 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1874 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1875 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1876 | #endif |
---|
1877 | #if LGE_ILLUCOMP_B0045 |
---|
1878 | Bool bICFlag = rpcTempCU->getICFlag(0); |
---|
1879 | #endif |
---|
1880 | |
---|
1881 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
1882 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS_MEM; ++ui ) |
---|
1883 | #else |
---|
1884 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
1885 | #endif |
---|
1886 | { |
---|
1887 | uhInterDirNeighbours[ui] = 0; |
---|
1888 | } |
---|
1889 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1890 | |
---|
1891 | #if HHI_VSO |
---|
1892 | if( m_pcRdCost->getUseRenModel() ) |
---|
1893 | { |
---|
1894 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
1895 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
1896 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1897 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1898 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1899 | } |
---|
1900 | #endif |
---|
1901 | |
---|
1902 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1903 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
1904 | |
---|
1905 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
1906 | Bool bestIsSkip = false; |
---|
1907 | #endif |
---|
1908 | |
---|
1909 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
1910 | { |
---|
1911 | { |
---|
1912 | TComYuv* pcPredYuvTemp = NULL; |
---|
1913 | #if LOSSLESS_CODING |
---|
1914 | UInt iteration; |
---|
1915 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
1916 | { |
---|
1917 | iteration = 1; |
---|
1918 | } |
---|
1919 | else |
---|
1920 | { |
---|
1921 | iteration = 2; |
---|
1922 | } |
---|
1923 | |
---|
1924 | #if HHI_INTERVIEW_SKIP |
---|
1925 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < iteration; ++uiNoResidual ) |
---|
1926 | #else |
---|
1927 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
1928 | #endif |
---|
1929 | #else |
---|
1930 | #if HHI_INTERVIEW_SKIP |
---|
1931 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < 2; ++uiNoResidual ) |
---|
1932 | #else |
---|
1933 | for( UInt uiNoResidual = 0; uiNoResidual < 2; ++uiNoResidual ) |
---|
1934 | #endif |
---|
1935 | #endif |
---|
1936 | { |
---|
1937 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
1938 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
1939 | { |
---|
1940 | #endif |
---|
1941 | // set MC parameters |
---|
1942 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1943 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1944 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1945 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1946 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1947 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1948 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1949 | |
---|
1950 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1951 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1952 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1953 | #endif |
---|
1954 | #if LGE_ILLUCOMP_B0045 |
---|
1955 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uhDepth); |
---|
1956 | #endif |
---|
1957 | |
---|
1958 | // do MC |
---|
1959 | #if HHI_INTERVIEW_SKIP |
---|
1960 | if ( (uiNoResidual == 0) || bSkipRes ) |
---|
1961 | #else |
---|
1962 | if ( uiNoResidual == 0 ) |
---|
1963 | #endif |
---|
1964 | { |
---|
1965 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1966 | // save pred adress |
---|
1967 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
1968 | |
---|
1969 | } |
---|
1970 | else |
---|
1971 | { |
---|
1972 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
1973 | if( bestIsSkip) |
---|
1974 | { |
---|
1975 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1976 | // save pred adress |
---|
1977 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
1978 | } |
---|
1979 | else |
---|
1980 | { |
---|
1981 | #endif |
---|
1982 | if ( pcPredYuvTemp != m_ppcPredYuvTemp[uhDepth]) |
---|
1983 | { |
---|
1984 | //adress changes take best (old temp) |
---|
1985 | pcPredYuvTemp = m_ppcPredYuvBest[uhDepth]; |
---|
1986 | } |
---|
1987 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
1988 | } |
---|
1989 | #endif |
---|
1990 | } |
---|
1991 | #if HHI_VSO |
---|
1992 | if( m_pcRdCost->getUseRenModel() ) |
---|
1993 | { //Reset |
---|
1994 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
1995 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
1996 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); |
---|
1997 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
1998 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1999 | } |
---|
2000 | #endif |
---|
2001 | // estimate residual and encode everything |
---|
2002 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2003 | m_ppcOrigYuv [uhDepth], |
---|
2004 | pcPredYuvTemp, |
---|
2005 | m_ppcResiYuvTemp[uhDepth], |
---|
2006 | m_ppcResiYuvBest[uhDepth], |
---|
2007 | m_ppcRecoYuvTemp[uhDepth], |
---|
2008 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2009 | m_ppcResPredTmp [uhDepth], |
---|
2010 | #endif |
---|
2011 | (uiNoResidual? true:false) ); |
---|
2012 | Bool bQtRootCbf = rpcTempCU->getQtRootCbf(0) == 1; |
---|
2013 | |
---|
2014 | #if H0736_AVC_STYLE_QP_RANGE |
---|
2015 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
2016 | xCheckDQP( rpcTempCU ); |
---|
2017 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2018 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
2019 | #else |
---|
2020 | UInt uiOrgQP = rpcTempCU->getQP( 0 ); |
---|
2021 | xCheckDQP( rpcTempCU ); |
---|
2022 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2023 | rpcTempCU->initEstData( uhDepth, uiOrgQP ); |
---|
2024 | #endif |
---|
2025 | |
---|
2026 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2027 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
2028 | { |
---|
2029 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
2030 | } |
---|
2031 | #endif |
---|
2032 | |
---|
2033 | if (!bQtRootCbf) |
---|
2034 | break; |
---|
2035 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2036 | } |
---|
2037 | #endif |
---|
2038 | } |
---|
2039 | } |
---|
2040 | } |
---|
2041 | } |
---|
2042 | |
---|
2043 | #if AMP_MRG |
---|
2044 | #if HHI_INTERVIEW_SKIP |
---|
2045 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes, Bool bUseMRG) |
---|
2046 | #else |
---|
2047 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG) |
---|
2048 | #endif |
---|
2049 | #else |
---|
2050 | #if HHI_INTERVIEW_SKIP |
---|
2051 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes) |
---|
2052 | #else |
---|
2053 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
2054 | #endif |
---|
2055 | #endif |
---|
2056 | { |
---|
2057 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2058 | |
---|
2059 | #if HHI_VSO |
---|
2060 | if( m_pcRdCost->getUseRenModel() ) |
---|
2061 | { |
---|
2062 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
2063 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
2064 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
2065 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
2066 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2067 | } |
---|
2068 | #endif |
---|
2069 | |
---|
2070 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
2071 | |
---|
2072 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2073 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
2074 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
2075 | #endif |
---|
2076 | |
---|
2077 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
2078 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2079 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
2080 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
2081 | #endif |
---|
2082 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
2083 | |
---|
2084 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2085 | #if !LG_RESTRICTEDRESPRED_M24766 |
---|
2086 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
2087 | { // subtract residual prediction from original in motion search |
---|
2088 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ), true ); |
---|
2089 | } |
---|
2090 | #endif |
---|
2091 | #endif |
---|
2092 | |
---|
2093 | #if AMP_MRG |
---|
2094 | rpcTempCU->setMergeAMP (true); |
---|
2095 | #if HHI_INTERVIEW_SKIP |
---|
2096 | #if LG_RESTRICTEDRESPRED_M24766 |
---|
2097 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG ); |
---|
2098 | #else |
---|
2099 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG ); |
---|
2100 | #endif |
---|
2101 | #else |
---|
2102 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG ); |
---|
2103 | #endif |
---|
2104 | #else |
---|
2105 | #if HHI_INTERVIEW_SKIP |
---|
2106 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes ); |
---|
2107 | #else |
---|
2108 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
2109 | #endif |
---|
2110 | #endif |
---|
2111 | |
---|
2112 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2113 | #if !LG_RESTRICTEDRESPRED_M24766 |
---|
2114 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
2115 | { // add residual prediction to original again |
---|
2116 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ) ); |
---|
2117 | } |
---|
2118 | #endif |
---|
2119 | #endif |
---|
2120 | |
---|
2121 | #if AMP_MRG |
---|
2122 | if ( !rpcTempCU->getMergeAMP() ) |
---|
2123 | { |
---|
2124 | return; |
---|
2125 | } |
---|
2126 | #endif |
---|
2127 | |
---|
2128 | #if HHI_INTERVIEW_SKIP |
---|
2129 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2130 | m_ppcOrigYuv[uhDepth], |
---|
2131 | m_ppcPredYuvTemp[uhDepth], |
---|
2132 | m_ppcResiYuvTemp[uhDepth], |
---|
2133 | m_ppcResiYuvBest[uhDepth], |
---|
2134 | m_ppcRecoYuvTemp[uhDepth], |
---|
2135 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2136 | m_ppcResPredTmp [uhDepth], |
---|
2137 | #endif |
---|
2138 | bSkipRes ); |
---|
2139 | #else |
---|
2140 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2141 | m_ppcOrigYuv[uhDepth], |
---|
2142 | m_ppcPredYuvTemp[uhDepth], |
---|
2143 | m_ppcResiYuvTemp[uhDepth], |
---|
2144 | m_ppcResiYuvBest[uhDepth], |
---|
2145 | m_ppcRecoYuvTemp[uhDepth], |
---|
2146 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2147 | m_ppcResPredTmp [uhDepth], |
---|
2148 | #endif |
---|
2149 | false ); |
---|
2150 | #endif |
---|
2151 | #if HHI_VSO |
---|
2152 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
2153 | { |
---|
2154 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2155 | } |
---|
2156 | else |
---|
2157 | #endif |
---|
2158 | { |
---|
2159 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2160 | } |
---|
2161 | |
---|
2162 | xCheckDQP( rpcTempCU ); |
---|
2163 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2164 | } |
---|
2165 | |
---|
2166 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
2167 | { |
---|
2168 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2169 | |
---|
2170 | #if HHI_VSO |
---|
2171 | if( m_pcRdCost->getUseRenModel() ) |
---|
2172 | { |
---|
2173 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth (); |
---|
2174 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight (); |
---|
2175 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr(); |
---|
2176 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride (); |
---|
2177 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2178 | } |
---|
2179 | #endif |
---|
2180 | |
---|
2181 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
2182 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2183 | |
---|
2184 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
2185 | Dist uiPreCalcDistC = 0; |
---|
2186 | if( !bSeparateLumaChroma ) |
---|
2187 | { |
---|
2188 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
2189 | } |
---|
2190 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
2191 | |
---|
2192 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
2193 | |
---|
2194 | #if RWTH_SDC_DLT_B0036 |
---|
2195 | if( !rpcTempCU->getSDCFlag( 0 ) ) |
---|
2196 | #endif |
---|
2197 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
2198 | |
---|
2199 | m_pcEntropyCoder->resetBits(); |
---|
2200 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2201 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
2202 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
2203 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
2204 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
2205 | |
---|
2206 | // Encode Coefficients |
---|
2207 | Bool bCodeDQP = getdQPFlag(); |
---|
2208 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP ); |
---|
2209 | setdQPFlag( bCodeDQP ); |
---|
2210 | |
---|
2211 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2212 | |
---|
2213 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2214 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2215 | { |
---|
2216 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2217 | } |
---|
2218 | #if HHI_VSO |
---|
2219 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
2220 | { |
---|
2221 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2222 | } |
---|
2223 | else |
---|
2224 | #endif |
---|
2225 | { |
---|
2226 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2227 | } |
---|
2228 | |
---|
2229 | xCheckDQP( rpcTempCU ); |
---|
2230 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
---|
2231 | } |
---|
2232 | |
---|
2233 | /** Check R-D costs for a CU with PCM mode. |
---|
2234 | * \param rpcBestCU pointer to best mode CU data structure |
---|
2235 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
2236 | * \returns Void |
---|
2237 | * |
---|
2238 | * \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. |
---|
2239 | */ |
---|
2240 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2241 | { |
---|
2242 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2243 | |
---|
2244 | rpcTempCU->setIPCMFlag(0, true); |
---|
2245 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
2246 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
2247 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2248 | |
---|
2249 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
2250 | |
---|
2251 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
2252 | |
---|
2253 | m_pcEntropyCoder->resetBits(); |
---|
2254 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2255 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
2256 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
2257 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
2258 | |
---|
2259 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2260 | |
---|
2261 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2262 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2263 | { |
---|
2264 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2265 | } |
---|
2266 | #if HHI_VSO |
---|
2267 | if ( m_pcRdCost->getUseVSO() ) |
---|
2268 | { |
---|
2269 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2270 | } |
---|
2271 | else |
---|
2272 | #endif |
---|
2273 | { |
---|
2274 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2275 | } |
---|
2276 | |
---|
2277 | xCheckDQP( rpcTempCU ); |
---|
2278 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
2279 | } |
---|
2280 | |
---|
2281 | // check whether current try is the best |
---|
2282 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2283 | { |
---|
2284 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
2285 | { |
---|
2286 | TComYuv* pcYuv; |
---|
2287 | UChar uhDepth = rpcBestCU->getDepth(0); |
---|
2288 | |
---|
2289 | // Change Information data |
---|
2290 | TComDataCU* pcCU = rpcBestCU; |
---|
2291 | rpcBestCU = rpcTempCU; |
---|
2292 | rpcTempCU = pcCU; |
---|
2293 | |
---|
2294 | // Change Prediction data |
---|
2295 | pcYuv = m_ppcPredYuvBest[uhDepth]; |
---|
2296 | m_ppcPredYuvBest[uhDepth] = m_ppcPredYuvTemp[uhDepth]; |
---|
2297 | m_ppcPredYuvTemp[uhDepth] = pcYuv; |
---|
2298 | |
---|
2299 | // Change Reconstruction data |
---|
2300 | pcYuv = m_ppcRecoYuvBest[uhDepth]; |
---|
2301 | m_ppcRecoYuvBest[uhDepth] = m_ppcRecoYuvTemp[uhDepth]; |
---|
2302 | m_ppcRecoYuvTemp[uhDepth] = pcYuv; |
---|
2303 | |
---|
2304 | pcYuv = NULL; |
---|
2305 | pcCU = NULL; |
---|
2306 | |
---|
2307 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
2308 | m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_NEXT_BEST]); |
---|
2309 | } |
---|
2310 | } |
---|
2311 | |
---|
2312 | /** check whether current try is the best with identifying the depth of current try |
---|
2313 | * \param rpcBestCU |
---|
2314 | * \param rpcTempCU |
---|
2315 | * \returns Void |
---|
2316 | */ |
---|
2317 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
2318 | { |
---|
2319 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
2320 | { |
---|
2321 | TComYuv* pcYuv; |
---|
2322 | // Change Information data |
---|
2323 | TComDataCU* pcCU = rpcBestCU; |
---|
2324 | rpcBestCU = rpcTempCU; |
---|
2325 | rpcTempCU = pcCU; |
---|
2326 | |
---|
2327 | // Change Prediction data |
---|
2328 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
2329 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
2330 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
2331 | |
---|
2332 | // Change Reconstruction data |
---|
2333 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
2334 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
2335 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
2336 | |
---|
2337 | pcYuv = NULL; |
---|
2338 | pcCU = NULL; |
---|
2339 | |
---|
2340 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
2341 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
2342 | } |
---|
2343 | } |
---|
2344 | |
---|
2345 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
2346 | { |
---|
2347 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
2348 | |
---|
2349 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
2350 | { |
---|
2351 | if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) |
---|
2352 | { |
---|
2353 | #if !RDO_WITHOUT_DQP_BITS |
---|
2354 | m_pcEntropyCoder->resetBits(); |
---|
2355 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
2356 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
2357 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2358 | { |
---|
2359 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2360 | } |
---|
2361 | |
---|
2362 | // GT: Change here?? |
---|
2363 | #if HHI_VSO |
---|
2364 | if ( m_pcRdCost->getUseVSO() ) |
---|
2365 | { |
---|
2366 | pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
2367 | } |
---|
2368 | else |
---|
2369 | #endif |
---|
2370 | { |
---|
2371 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
2372 | } |
---|
2373 | #endif |
---|
2374 | } |
---|
2375 | else |
---|
2376 | { |
---|
2377 | #if LOSSLESS_CODING |
---|
2378 | if (( ( pcCU->getRefQP( 0 ) != pcCU->getQP( 0 )) ) && (pcCU->getSlice()->getSPS()->getUseLossless())) |
---|
2379 | { |
---|
2380 | pcCU->getTotalCost() = MAX_DOUBLE; |
---|
2381 | } |
---|
2382 | #endif |
---|
2383 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
2384 | } |
---|
2385 | } |
---|
2386 | } |
---|
2387 | |
---|
2388 | #if BURST_IPCM |
---|
2389 | /** Check whether the last CU shares the same root as the current CU and is IPCM or not. |
---|
2390 | * \param pcCU |
---|
2391 | * \param uiCurAbsPartIdx |
---|
2392 | * \returns Bool |
---|
2393 | */ |
---|
2394 | Bool TEncCu::checkLastCUSucIPCM( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) |
---|
2395 | { |
---|
2396 | Bool lastCUSucIPCMFlag = false; |
---|
2397 | |
---|
2398 | UInt curDepth = pcCU->getDepth(uiCurAbsPartIdx); |
---|
2399 | UInt shift = ((pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx())->getSPS()->getMaxCUDepth() - curDepth)<<1); |
---|
2400 | UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); |
---|
2401 | |
---|
2402 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2403 | if( pcSlice->getEntropySliceCurStartCUAddr() == ( pcCU->getSCUAddr() + uiCurAbsPartIdx ) ) |
---|
2404 | { |
---|
2405 | return false; |
---|
2406 | } |
---|
2407 | |
---|
2408 | if(curDepth > 0 && startPartUnitIdx > 0) |
---|
2409 | { |
---|
2410 | Int lastValidPartIdx = pcCU->getLastValidPartIdx((Int) uiCurAbsPartIdx ); |
---|
2411 | |
---|
2412 | if( lastValidPartIdx >= 0 ) |
---|
2413 | { |
---|
2414 | if(( pcCU->getSliceStartCU( uiCurAbsPartIdx ) == pcCU->getSliceStartCU( (UInt) lastValidPartIdx )) |
---|
2415 | && |
---|
2416 | ( pcCU->getDepth( uiCurAbsPartIdx ) == pcCU->getDepth( (UInt) lastValidPartIdx )) |
---|
2417 | && |
---|
2418 | pcCU->getIPCMFlag( (UInt) lastValidPartIdx ) ) |
---|
2419 | { |
---|
2420 | lastCUSucIPCMFlag = true; |
---|
2421 | } |
---|
2422 | } |
---|
2423 | } |
---|
2424 | |
---|
2425 | return lastCUSucIPCMFlag; |
---|
2426 | } |
---|
2427 | |
---|
2428 | /** Count the number of successive IPCM CUs sharing the same root. |
---|
2429 | * \param pcCU |
---|
2430 | * \param uiCurAbsPartIdx |
---|
2431 | * \returns Int |
---|
2432 | */ |
---|
2433 | Int TEncCu::countNumSucIPCM ( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) |
---|
2434 | { |
---|
2435 | Int numSucIPCM = 0; |
---|
2436 | UInt CurDepth = pcCU->getDepth(uiCurAbsPartIdx); |
---|
2437 | |
---|
2438 | if( pcCU->getIPCMFlag(uiCurAbsPartIdx) ) |
---|
2439 | { |
---|
2440 | if(CurDepth == 0) |
---|
2441 | { |
---|
2442 | numSucIPCM = 1; |
---|
2443 | } |
---|
2444 | else |
---|
2445 | { |
---|
2446 | TComPic* pcPic = pcCU->getPic(); |
---|
2447 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2448 | UInt qNumParts = ( pcPic->getNumPartInCU() >> ((CurDepth-1)<<1) )>>2; |
---|
2449 | |
---|
2450 | Bool continueFlag = true; |
---|
2451 | UInt absPartIdx = uiCurAbsPartIdx; |
---|
2452 | UInt shift = ((pcSlice->getSPS()->getMaxCUDepth() - CurDepth)<<1); |
---|
2453 | UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); |
---|
2454 | |
---|
2455 | for ( UInt partUnitIdx = startPartUnitIdx; partUnitIdx < 4 && continueFlag; partUnitIdx++, absPartIdx+=qNumParts ) |
---|
2456 | { |
---|
2457 | UInt lPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ]; |
---|
2458 | UInt tPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ]; |
---|
2459 | Bool inSliceFlag = ( pcCU->getSCUAddr()+absPartIdx+qNumParts>pcSlice->getEntropySliceCurStartCUAddr() ) && ( pcCU->getSCUAddr()+absPartIdx < pcSlice->getEntropySliceCurEndCUAddr()); |
---|
2460 | |
---|
2461 | if( inSliceFlag && ( lPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( tPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2462 | { |
---|
2463 | UInt uiDepth = pcCU->getDepth(absPartIdx); |
---|
2464 | |
---|
2465 | if( ( CurDepth == uiDepth) && pcCU->getIPCMFlag( absPartIdx ) ) |
---|
2466 | { |
---|
2467 | numSucIPCM++; |
---|
2468 | } |
---|
2469 | else |
---|
2470 | { |
---|
2471 | continueFlag = false; |
---|
2472 | } |
---|
2473 | } |
---|
2474 | } |
---|
2475 | } |
---|
2476 | } |
---|
2477 | |
---|
2478 | return numSucIPCM; |
---|
2479 | } |
---|
2480 | #endif |
---|
2481 | |
---|
2482 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
2483 | { |
---|
2484 | pDst->iN = pSrc->iN; |
---|
2485 | for (Int i = 0; i < pSrc->iN; i++) |
---|
2486 | { |
---|
2487 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
2488 | } |
---|
2489 | } |
---|
2490 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
---|
2491 | { |
---|
2492 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
2493 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
2494 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2495 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2496 | pcSlice->getEntropySliceCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2497 | Bool bSliceEnd = pcSlice->getEntropySliceCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2498 | pcSlice->getEntropySliceCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2499 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2500 | { |
---|
2501 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
2502 | UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); |
---|
2503 | UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); |
---|
2504 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
2505 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
2506 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
2507 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
2508 | } |
---|
2509 | else |
---|
2510 | { |
---|
2511 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
2512 | |
---|
2513 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
2514 | { |
---|
2515 | UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); |
---|
2516 | UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); |
---|
2517 | |
---|
2518 | Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getEntropySliceCurStartCUAddr() && |
---|
2519 | rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getEntropySliceCurEndCUAddr(); |
---|
2520 | if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2521 | { |
---|
2522 | xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv |
---|
2523 | } |
---|
2524 | } |
---|
2525 | } |
---|
2526 | } |
---|
2527 | |
---|
2528 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
2529 | { |
---|
2530 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
2531 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
2532 | } |
---|
2533 | |
---|
2534 | #if LOSSLESS_CODING |
---|
2535 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
2536 | * \param pcCU pointer to current CU |
---|
2537 | * \param pcOrgYuv pointer to original sample array |
---|
2538 | * \returns Void |
---|
2539 | */ |
---|
2540 | Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) |
---|
2541 | { |
---|
2542 | |
---|
2543 | UInt width = pCU->getWidth(0); |
---|
2544 | UInt height = pCU->getHeight(0); |
---|
2545 | |
---|
2546 | Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); |
---|
2547 | Pel* pDstY = pCU->getPCMSampleY(); |
---|
2548 | UInt srcStride = pOrgYuv->getStride(); |
---|
2549 | |
---|
2550 | for(Int y = 0; y < height; y++ ) |
---|
2551 | { |
---|
2552 | for(Int x = 0; x < width; x++ ) |
---|
2553 | { |
---|
2554 | pDstY[x] = pSrcY[x]; |
---|
2555 | } |
---|
2556 | pDstY += width; |
---|
2557 | pSrcY += srcStride; |
---|
2558 | } |
---|
2559 | |
---|
2560 | Pel* pSrcCb = pOrgYuv->getCbAddr(); |
---|
2561 | Pel* pSrcCr = pOrgYuv->getCrAddr();; |
---|
2562 | |
---|
2563 | Pel* pDstCb = pCU->getPCMSampleCb(); |
---|
2564 | Pel* pDstCr = pCU->getPCMSampleCr();; |
---|
2565 | |
---|
2566 | UInt srcStrideC = pOrgYuv->getCStride(); |
---|
2567 | UInt heightC = height >> 1; |
---|
2568 | UInt widthC = width >> 1; |
---|
2569 | |
---|
2570 | for(Int y = 0; y < heightC; y++ ) |
---|
2571 | { |
---|
2572 | for(Int x = 0; x < widthC; x++ ) |
---|
2573 | { |
---|
2574 | pDstCb[x] = pSrcCb[x]; |
---|
2575 | pDstCr[x] = pSrcCr[x]; |
---|
2576 | } |
---|
2577 | pDstCb += widthC; |
---|
2578 | pDstCr += widthC; |
---|
2579 | pSrcCb += srcStrideC; |
---|
2580 | pSrcCr += srcStrideC; |
---|
2581 | } |
---|
2582 | } |
---|
2583 | #endif |
---|
2584 | |
---|
2585 | #if ADAPTIVE_QP_SELECTION |
---|
2586 | /** Collect ARL statistics from one block |
---|
2587 | */ |
---|
2588 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
2589 | { |
---|
2590 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
2591 | { |
---|
2592 | Int u = abs( rpcCoeff[ n ] ); |
---|
2593 | Int absc = rpcArlCoeff[ n ]; |
---|
2594 | |
---|
2595 | if( u != 0 ) |
---|
2596 | { |
---|
2597 | if( u < LEVEL_RANGE ) |
---|
2598 | { |
---|
2599 | cSum[ u ] += ( Double )absc; |
---|
2600 | numSamples[ u ]++; |
---|
2601 | } |
---|
2602 | else |
---|
2603 | { |
---|
2604 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
2605 | numSamples[ LEVEL_RANGE ]++; |
---|
2606 | } |
---|
2607 | } |
---|
2608 | } |
---|
2609 | |
---|
2610 | return 0; |
---|
2611 | } |
---|
2612 | |
---|
2613 | /** Collect ARL statistics from one LCU |
---|
2614 | * \param pcCU |
---|
2615 | */ |
---|
2616 | Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) |
---|
2617 | { |
---|
2618 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
---|
2619 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
---|
2620 | |
---|
2621 | TCoeff* pCoeffY = rpcCU->getCoeffY(); |
---|
2622 | Int* pArlCoeffY = rpcCU->getArlCoeffY(); |
---|
2623 | |
---|
2624 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
2625 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
---|
2626 | |
---|
2627 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
2628 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
2629 | |
---|
2630 | // Collect stats to cSum[][] and numSamples[][] |
---|
2631 | for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) |
---|
2632 | { |
---|
2633 | UInt uiTrIdx = rpcCU->getTransformIdx(i); |
---|
2634 | |
---|
2635 | if(rpcCU->getPredictionMode(i) == MODE_INTER) |
---|
2636 | if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) |
---|
2637 | { |
---|
2638 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
2639 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
2640 | |
---|
2641 | pCoeffY += uiMinNumCoeffInCU; |
---|
2642 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
2643 | } |
---|
2644 | |
---|
2645 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
2646 | { |
---|
2647 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
2648 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
2649 | } |
---|
2650 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
2651 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
2652 | } |
---|
2653 | #endif |
---|
2654 | |
---|
2655 | #if HHI_MPI |
---|
2656 | Void TEncCu::xCheckRDCostMvInheritance( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhTextureModeDepth, Bool bSkipResidual, Bool bRecursiveCall ) |
---|
2657 | { |
---|
2658 | assert( rpcTempCU->getSlice()->getIsDepth() ); |
---|
2659 | TComDataCU *pcTextureCU = rpcTempCU->getSlice()->getTexturePic()->getCU( rpcTempCU->getAddr() ); |
---|
2660 | |
---|
2661 | const UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2662 | const Int iQP = rpcTempCU->getQP( 0 ); |
---|
2663 | assert( bRecursiveCall == ( uhDepth != uhTextureModeDepth ) ); |
---|
2664 | |
---|
2665 | #if !MTK_UNCONSTRAINED_MVI_B0083 |
---|
2666 | if( uhDepth == uhTextureModeDepth ) |
---|
2667 | { |
---|
2668 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
2669 | { |
---|
2670 | if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) ) |
---|
2671 | { |
---|
2672 | return; |
---|
2673 | } |
---|
2674 | } |
---|
2675 | } |
---|
2676 | #endif |
---|
2677 | |
---|
2678 | #if HHI_VSO |
---|
2679 | if( m_pcRdCost->getUseRenModel() && !bRecursiveCall) |
---|
2680 | { |
---|
2681 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
2682 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
2683 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr(); |
---|
2684 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
2685 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2686 | } |
---|
2687 | #endif |
---|
2688 | |
---|
2689 | Bool bSplit = uhDepth < pcTextureCU->getDepth( rpcTempCU->getZorderIdxInCU() ); |
---|
2690 | if( bSplit ) |
---|
2691 | { |
---|
2692 | const UChar uhNextDepth = uhDepth+1; |
---|
2693 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
2694 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
2695 | |
---|
2696 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
2697 | { |
---|
2698 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
2699 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
2700 | |
---|
2701 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
2702 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getEntropySliceCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getEntropySliceCurEndCUAddr(); |
---|
2703 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2704 | { |
---|
2705 | if( m_bUseSBACRD ) |
---|
2706 | { |
---|
2707 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
2708 | { |
---|
2709 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhDepth][CI_CURR_BEST]); |
---|
2710 | } |
---|
2711 | else |
---|
2712 | { |
---|
2713 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
2714 | } |
---|
2715 | } |
---|
2716 | |
---|
2717 | xCheckRDCostMvInheritance( pcSubBestPartCU, pcSubTempPartCU, uhTextureModeDepth, bSkipResidual, true ); |
---|
2718 | |
---|
2719 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
2720 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
2721 | } |
---|
2722 | else if (bInSlice) |
---|
2723 | { |
---|
2724 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
2725 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
2726 | } |
---|
2727 | } |
---|
2728 | |
---|
2729 | if( uhDepth == uhTextureModeDepth ) |
---|
2730 | { |
---|
2731 | xAddMVISignallingBits( rpcTempCU ); |
---|
2732 | } |
---|
2733 | |
---|
2734 | // DQP stuff |
---|
2735 | { |
---|
2736 | if( (g_uiMaxCUWidth>>uhDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
2737 | { |
---|
2738 | TComPic *pcPic = rpcTempCU->getPic(); |
---|
2739 | TComSlice *pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
2740 | Bool bHasRedisual = false; |
---|
2741 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
2742 | { |
---|
2743 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getEntropySliceCurStartCUAddr() ) && |
---|
2744 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
2745 | { |
---|
2746 | bHasRedisual = true; |
---|
2747 | break; |
---|
2748 | } |
---|
2749 | } |
---|
2750 | |
---|
2751 | UInt uiTargetPartIdx; |
---|
2752 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getEntropySliceCurStartCUAddr() ) |
---|
2753 | { |
---|
2754 | uiTargetPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
2755 | } |
---|
2756 | else |
---|
2757 | { |
---|
2758 | uiTargetPartIdx = 0; |
---|
2759 | } |
---|
2760 | if ( ! bHasRedisual ) |
---|
2761 | { |
---|
2762 | #if LOSSLESS_CODING |
---|
2763 | if (((rpcTempCU->getQP(uiTargetPartIdx) != rpcTempCU->getRefQP(uiTargetPartIdx)) ) && (rpcTempCU->getSlice()->getSPS()->getUseLossless())) |
---|
2764 | { |
---|
2765 | rpcTempCU->getTotalCost() = MAX_DOUBLE; |
---|
2766 | } |
---|
2767 | #endif |
---|
2768 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uhDepth ); // set QP to default QP |
---|
2769 | } |
---|
2770 | } |
---|
2771 | } |
---|
2772 | |
---|
2773 | if( m_bUseSBACRD ) |
---|
2774 | { |
---|
2775 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]); |
---|
2776 | } |
---|
2777 | } |
---|
2778 | else |
---|
2779 | { |
---|
2780 | rpcTempCU->setTextureModeDepthSubParts( uhTextureModeDepth, 0, uhDepth ); |
---|
2781 | rpcTempCU->copyTextureMotionDataFrom( pcTextureCU, uhDepth, rpcTempCU->getZorderIdxInCU() ); |
---|
2782 | #if FIX_MPI_B0065 |
---|
2783 | UInt uiAbsPartIdx = rpcTempCU->getZorderIdxInCU(); |
---|
2784 | if( rpcTempCU->getDepth(0) > pcTextureCU->getDepth(uiAbsPartIdx)) |
---|
2785 | { |
---|
2786 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
---|
2787 | } |
---|
2788 | else |
---|
2789 | { |
---|
2790 | PartSize partSize = pcTextureCU->getPartitionSize(uiAbsPartIdx); |
---|
2791 | rpcTempCU->setPartSizeSubParts( partSize, 0, uhDepth ); |
---|
2792 | } |
---|
2793 | #else |
---|
2794 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
---|
2795 | #endif |
---|
2796 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
2797 | { |
---|
2798 | assert( rpcTempCU->getInterDir( ui ) != 0 ); |
---|
2799 | assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE ); |
---|
2800 | } |
---|
2801 | rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth ); |
---|
2802 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
2803 | |
---|
2804 | // get Original YUV data from picture |
---|
2805 | m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
2806 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2807 | m_ppcOrigYuv[uhDepth], |
---|
2808 | m_ppcPredYuvTemp[uhDepth], |
---|
2809 | m_ppcResiYuvTemp[uhDepth], |
---|
2810 | m_ppcResiYuvBest[uhDepth], |
---|
2811 | m_ppcRecoYuvTemp[uhDepth], |
---|
2812 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2813 | m_ppcResPredTmp [uhDepth], |
---|
2814 | #endif |
---|
2815 | bSkipResidual ); |
---|
2816 | |
---|
2817 | if( uhDepth == uhTextureModeDepth ) |
---|
2818 | { |
---|
2819 | xAddMVISignallingBits( rpcTempCU ); |
---|
2820 | } |
---|
2821 | xCheckDQP( rpcTempCU ); |
---|
2822 | } |
---|
2823 | |
---|
2824 | #if HHI_VSO |
---|
2825 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
2826 | { |
---|
2827 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2828 | } |
---|
2829 | else |
---|
2830 | #endif |
---|
2831 | { |
---|
2832 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2833 | } |
---|
2834 | |
---|
2835 | if( rpcTempCU->getPredictionMode( 0 ) == MODE_SKIP && uhDepth == uhTextureModeDepth ) |
---|
2836 | { |
---|
2837 | if( rpcTempCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uhDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
2838 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uhDepth ); // set QP to default QP |
---|
2839 | } |
---|
2840 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
2841 | rpcBestCU->copyToPic(uhDepth); // Copy Best data to Picture for next partition prediction. |
---|
2842 | |
---|
2843 | #if HHI_VSO |
---|
2844 | if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() ) |
---|
2845 | { |
---|
2846 | UInt uiWidth = m_ppcRecoYuvBest[uhDepth]->getWidth ( ); |
---|
2847 | UInt uiHeight = m_ppcRecoYuvBest[uhDepth]->getHeight ( ); |
---|
2848 | UInt uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride ( ); |
---|
2849 | Pel* piSrc = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 ); |
---|
2850 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2851 | } |
---|
2852 | #endif |
---|
2853 | } |
---|
2854 | |
---|
2855 | Void TEncCu::xAddMVISignallingBits( TComDataCU* pcCU ) |
---|
2856 | { |
---|
2857 | const UChar uhDepth = pcCU->getTextureModeDepth( 0 ); |
---|
2858 | m_pcEntropyCoder->resetBits(); |
---|
2859 | xSaveDepthWidthHeight( pcCU ); |
---|
2860 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uhDepth, g_uiMaxCUHeight>>uhDepth, 0, uhDepth ); |
---|
2861 | pcCU->setDepthSubParts( uhDepth, 0 ); |
---|
2862 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
2863 | pcCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); |
---|
2864 | pcCU->setMergeIndexSubParts( HHI_MPI_MERGE_POS, 0, 0, uhDepth ); |
---|
2865 | |
---|
2866 | // check for skip mode |
---|
2867 | { |
---|
2868 | Bool bAllZero = true; |
---|
2869 | for( UInt ui = 0; ui < pcCU->getTotalNumPart(); ui++ ) |
---|
2870 | { |
---|
2871 | if( pcCU->getCbf( ui, TEXT_LUMA ) || pcCU->getCbf( ui, TEXT_CHROMA_U ) || pcCU->getCbf( ui, TEXT_CHROMA_V ) ) |
---|
2872 | { |
---|
2873 | bAllZero = false; |
---|
2874 | break; |
---|
2875 | } |
---|
2876 | } |
---|
2877 | if( bAllZero ) |
---|
2878 | pcCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
2879 | } |
---|
2880 | |
---|
2881 | |
---|
2882 | m_pcEntropyCoder->encodeSplitFlag( pcCU, 0, uhDepth, true ); |
---|
2883 | m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true ); |
---|
2884 | |
---|
2885 | if( pcCU->isSkipped( 0 ) ) |
---|
2886 | { |
---|
2887 | m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true ); |
---|
2888 | #if LGE_ILLUCOMP_B0045 |
---|
2889 | m_pcEntropyCoder->encodeICFlag( pcCU, 0, true ); |
---|
2890 | #endif |
---|
2891 | } |
---|
2892 | else |
---|
2893 | { |
---|
2894 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
---|
2895 | m_pcEntropyCoder->encodePartSize( pcCU, 0, uhDepth, true ); |
---|
2896 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
2897 | m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); |
---|
2898 | #if LGE_ILLUCOMP_B0045 |
---|
2899 | m_pcEntropyCoder->encodeICFlag( pcCU, 0, true ); |
---|
2900 | #endif |
---|
2901 | } |
---|
2902 | xRestoreDepthWidthHeight( pcCU ); |
---|
2903 | |
---|
2904 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2905 | } |
---|
2906 | |
---|
2907 | Void TEncCu::xSaveDepthWidthHeight( TComDataCU* pcCU ) |
---|
2908 | { |
---|
2909 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
2910 | memcpy( m_puhDepthSaved, pcCU->getDepth(), iSizeInUchar ); |
---|
2911 | memcpy( m_puhWidthSaved, pcCU->getWidth(), iSizeInUchar ); |
---|
2912 | memcpy( m_puhHeightSaved, pcCU->getHeight(), iSizeInUchar ); |
---|
2913 | } |
---|
2914 | |
---|
2915 | Void TEncCu::xRestoreDepthWidthHeight( TComDataCU* pcCU ) |
---|
2916 | { |
---|
2917 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
2918 | memcpy( pcCU->getDepth(), m_puhDepthSaved, iSizeInUchar ); |
---|
2919 | memcpy( pcCU->getWidth(), m_puhWidthSaved, iSizeInUchar ); |
---|
2920 | memcpy( pcCU->getHeight(), m_puhHeightSaved, iSizeInUchar ); |
---|
2921 | } |
---|
2922 | #endif |
---|
2923 | |
---|
2924 | //! \} |
---|