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 | #endif |
---|
1351 | } |
---|
1352 | else if (bInSlice) |
---|
1353 | { |
---|
1354 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
1355 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
1356 | } |
---|
1357 | } |
---|
1358 | |
---|
1359 | if( !bBoundary ) |
---|
1360 | { |
---|
1361 | m_pcEntropyCoder->resetBits(); |
---|
1362 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
1363 | |
---|
1364 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1365 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1366 | { |
---|
1367 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1368 | } |
---|
1369 | } |
---|
1370 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
1371 | if( bFullyRenderedSec ) |
---|
1372 | { |
---|
1373 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
1374 | } |
---|
1375 | else |
---|
1376 | { |
---|
1377 | m_pcRdCost->setLambdaScale( 1 ); |
---|
1378 | } |
---|
1379 | #endif |
---|
1380 | |
---|
1381 | #if HHI_VSO |
---|
1382 | if ( m_pcRdCost->getUseVSO() ) |
---|
1383 | { |
---|
1384 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1385 | } |
---|
1386 | else |
---|
1387 | #endif |
---|
1388 | { |
---|
1389 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1390 | } |
---|
1391 | |
---|
1392 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
1393 | { |
---|
1394 | Bool bHasRedisual = false; |
---|
1395 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
1396 | { |
---|
1397 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getEntropySliceCurStartCUAddr() ) && |
---|
1398 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
1399 | { |
---|
1400 | bHasRedisual = true; |
---|
1401 | break; |
---|
1402 | } |
---|
1403 | } |
---|
1404 | |
---|
1405 | UInt uiTargetPartIdx; |
---|
1406 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getEntropySliceCurStartCUAddr() ) |
---|
1407 | { |
---|
1408 | uiTargetPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
1409 | } |
---|
1410 | else |
---|
1411 | { |
---|
1412 | uiTargetPartIdx = 0; |
---|
1413 | } |
---|
1414 | if ( bHasRedisual ) |
---|
1415 | { |
---|
1416 | #if !RDO_WITHOUT_DQP_BITS |
---|
1417 | m_pcEntropyCoder->resetBits(); |
---|
1418 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
1419 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
1420 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1421 | { |
---|
1422 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
1423 | } |
---|
1424 | #if HHI_VSO |
---|
1425 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1426 | { |
---|
1427 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1428 | } |
---|
1429 | else |
---|
1430 | #endif |
---|
1431 | { |
---|
1432 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1433 | } |
---|
1434 | #endif |
---|
1435 | } |
---|
1436 | else |
---|
1437 | { |
---|
1438 | #if LOSSLESS_CODING |
---|
1439 | if (((rpcTempCU->getQP(uiTargetPartIdx) != rpcTempCU->getRefQP(uiTargetPartIdx)) ) && (rpcTempCU->getSlice()->getSPS()->getUseLossless())) |
---|
1440 | { |
---|
1441 | rpcTempCU->getTotalCost() = MAX_DOUBLE; |
---|
1442 | } |
---|
1443 | #endif |
---|
1444 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
1445 | } |
---|
1446 | } |
---|
1447 | |
---|
1448 | if( m_bUseSBACRD ) |
---|
1449 | { |
---|
1450 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1451 | } |
---|
1452 | Bool bEntropyLimit=false; |
---|
1453 | Bool bSliceLimit=false; |
---|
1454 | bSliceLimit=rpcBestCU->getSlice()->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
---|
1455 | if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&m_pcEncCfg->getUseSBACRD()) |
---|
1456 | { |
---|
1457 | if(rpcBestCU->getTotalBins()>rpcBestCU->getSlice()->getEntropySliceArgument()) |
---|
1458 | { |
---|
1459 | bEntropyLimit=true; |
---|
1460 | } |
---|
1461 | } |
---|
1462 | else if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE) |
---|
1463 | { |
---|
1464 | if(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getEntropySliceArgument()) |
---|
1465 | { |
---|
1466 | bEntropyLimit=true; |
---|
1467 | } |
---|
1468 | } |
---|
1469 | if(rpcBestCU->getDepth(0)>=rpcBestCU->getSlice()->getPPS()->getSliceGranularity()) |
---|
1470 | { |
---|
1471 | bSliceLimit=false; |
---|
1472 | bEntropyLimit=false; |
---|
1473 | } |
---|
1474 | if(bSliceLimit||bEntropyLimit) |
---|
1475 | { |
---|
1476 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
---|
1477 | } |
---|
1478 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction |
---|
1479 | } // with sub partitioned prediction. |
---|
1480 | #if LOSSLESS_CODING |
---|
1481 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
1482 | { |
---|
1483 | iQP = iMinQP; |
---|
1484 | } |
---|
1485 | #endif |
---|
1486 | } // SPLIT- QP Loop |
---|
1487 | |
---|
1488 | #if HHI_VSO |
---|
1489 | if( m_pcRdCost->getUseRenModel() ) |
---|
1490 | { |
---|
1491 | UInt uiWidth = m_ppcRecoYuvBest[uiDepth]->getWidth ( ); |
---|
1492 | UInt uiHeight = m_ppcRecoYuvBest[uiDepth]->getHeight ( ); |
---|
1493 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
1494 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride ( ); |
---|
1495 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1496 | } |
---|
1497 | #endif |
---|
1498 | |
---|
1499 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
1500 | |
---|
1501 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
---|
1502 | if( bBoundary ||(bSliceEnd && bInsidePicture)) |
---|
1503 | { |
---|
1504 | return; |
---|
1505 | } |
---|
1506 | |
---|
1507 | // Assert if Best prediction mode is NONE |
---|
1508 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
1509 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
1510 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
1511 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
1512 | } |
---|
1513 | |
---|
1514 | /** finish encoding a cu and handle end-of-slice conditions |
---|
1515 | * \param pcCU |
---|
1516 | * \param uiAbsPartIdx |
---|
1517 | * \param uiDepth |
---|
1518 | * \returns Void |
---|
1519 | */ |
---|
1520 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1521 | { |
---|
1522 | TComPic* pcPic = pcCU->getPic(); |
---|
1523 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1524 | |
---|
1525 | //Calculate end address |
---|
1526 | UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; |
---|
1527 | |
---|
1528 | UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
1529 | UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
1530 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1531 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1532 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
1533 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
1534 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
1535 | { |
---|
1536 | uiInternalAddress--; |
---|
1537 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1538 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1539 | } |
---|
1540 | uiInternalAddress++; |
---|
1541 | if(uiInternalAddress==pcCU->getPic()->getNumPartInCU()) |
---|
1542 | { |
---|
1543 | uiInternalAddress = 0; |
---|
1544 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
1545 | } |
---|
1546 | UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
1547 | |
---|
1548 | // Encode slice finish |
---|
1549 | Bool bTerminateSlice = false; |
---|
1550 | if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress) |
---|
1551 | { |
---|
1552 | bTerminateSlice = true; |
---|
1553 | } |
---|
1554 | UInt uiGranularityWidth = g_uiMaxCUWidth>>(pcSlice->getPPS()->getSliceGranularity()); |
---|
1555 | uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1556 | uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1557 | Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth)) |
---|
1558 | &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); |
---|
1559 | |
---|
1560 | #if BURST_IPCM |
---|
1561 | if(granularityBoundary && (!(pcCU->getIPCMFlag(uiAbsPartIdx) && ( pcCU->getNumSucIPCM() > 1 )))) |
---|
1562 | #else |
---|
1563 | if(granularityBoundary) |
---|
1564 | #endif |
---|
1565 | { |
---|
1566 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
1567 | if (!bTerminateSlice) |
---|
1568 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
1569 | } |
---|
1570 | |
---|
1571 | Int numberOfWrittenBits = 0; |
---|
1572 | if (m_pcBitCounter) |
---|
1573 | { |
---|
1574 | numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1575 | } |
---|
1576 | |
---|
1577 | // Calculate slice end IF this CU puts us over slice bit size. |
---|
1578 | unsigned iGranularitySize = pcCU->getPic()->getNumPartInCU()>>(pcSlice->getPPS()->getSliceGranularity()<<1); |
---|
1579 | int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; |
---|
1580 | if(iGranularityEnd<=pcSlice->getEntropySliceCurStartCUAddr()) |
---|
1581 | { |
---|
1582 | iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); |
---|
1583 | } |
---|
1584 | // Set slice end parameter |
---|
1585 | if(pcSlice->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) |
---|
1586 | { |
---|
1587 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1588 | pcSlice->setSliceCurEndCUAddr(iGranularityEnd); |
---|
1589 | return; |
---|
1590 | } |
---|
1591 | // Set entropy slice end parameter |
---|
1592 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1593 | { |
---|
1594 | TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); |
---|
1595 | UInt uiBinsCoded = pppcRDSbacCoder->getBinsCoded(); |
---|
1596 | if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+uiBinsCoded>pcSlice->getEntropySliceArgument()) |
---|
1597 | { |
---|
1598 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1599 | return; |
---|
1600 | } |
---|
1601 | } |
---|
1602 | else |
---|
1603 | { |
---|
1604 | if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+numberOfWrittenBits>pcSlice->getEntropySliceArgument()) |
---|
1605 | { |
---|
1606 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
---|
1607 | return; |
---|
1608 | } |
---|
1609 | } |
---|
1610 | if(granularityBoundary) |
---|
1611 | { |
---|
1612 | pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); |
---|
1613 | if(m_pcEncCfg->getUseSBACRD()) |
---|
1614 | { |
---|
1615 | TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); |
---|
1616 | pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+pppcRDSbacCoder->getBinsCoded()); |
---|
1617 | pppcRDSbacCoder->setBinsCoded( 0 ); |
---|
1618 | } |
---|
1619 | else |
---|
1620 | { |
---|
1621 | pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+numberOfWrittenBits); |
---|
1622 | } |
---|
1623 | if (m_pcBitCounter) |
---|
1624 | { |
---|
1625 | m_pcEntropyCoder->resetBits(); |
---|
1626 | } |
---|
1627 | } |
---|
1628 | } |
---|
1629 | |
---|
1630 | /** Compute QP for each CU |
---|
1631 | * \param pcCU Target CU |
---|
1632 | * \param uiDepth CU depth |
---|
1633 | * \returns quantization parameter |
---|
1634 | */ |
---|
1635 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
1636 | { |
---|
1637 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
1638 | Int iQpOffset = 0; |
---|
1639 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
1640 | { |
---|
1641 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
1642 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
1643 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
1644 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
1645 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
1646 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
1647 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
1648 | |
---|
1649 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
1650 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
1651 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
1652 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
1653 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
1654 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
1655 | } |
---|
1656 | #if H0736_AVC_STYLE_QP_RANGE |
---|
1657 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
1658 | #else |
---|
1659 | return Clip3( MIN_QP, MAX_QP, iBaseQp+iQpOffset ); |
---|
1660 | #endif |
---|
1661 | } |
---|
1662 | |
---|
1663 | /** encode a CU block recursively |
---|
1664 | * \param pcCU |
---|
1665 | * \param uiAbsPartIdx |
---|
1666 | * \param uiDepth |
---|
1667 | * \returns Void |
---|
1668 | */ |
---|
1669 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1670 | { |
---|
1671 | TComPic* pcPic = pcCU->getPic(); |
---|
1672 | |
---|
1673 | Bool bBoundary = false; |
---|
1674 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1675 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
1676 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1677 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
1678 | |
---|
1679 | #if BURST_IPCM |
---|
1680 | if( getCheckBurstIPCMFlag() ) |
---|
1681 | { |
---|
1682 | pcCU->setLastCUSucIPCMFlag( checkLastCUSucIPCM( pcCU, uiAbsPartIdx )); |
---|
1683 | pcCU->setNumSucIPCM( countNumSucIPCM ( pcCU, uiAbsPartIdx ) ); |
---|
1684 | } |
---|
1685 | #endif |
---|
1686 | |
---|
1687 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
1688 | // If slice start is within this cu... |
---|
1689 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
1690 | pcSlice->getEntropySliceCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); |
---|
1691 | // We need to split, so don't try these modes. |
---|
1692 | if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1693 | { |
---|
1694 | #if HHI_MPI |
---|
1695 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth < pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
1696 | { |
---|
1697 | #endif |
---|
1698 | |
---|
1699 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1700 | |
---|
1701 | #if HHI_MPI |
---|
1702 | } |
---|
1703 | #endif |
---|
1704 | } |
---|
1705 | else |
---|
1706 | { |
---|
1707 | bBoundary = true; |
---|
1708 | } |
---|
1709 | |
---|
1710 | #if HHI_MPI |
---|
1711 | if( uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
1712 | { |
---|
1713 | xSaveDepthWidthHeight( pcCU ); |
---|
1714 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
1715 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
1716 | |
---|
1717 | if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1718 | { |
---|
1719 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1720 | } |
---|
1721 | |
---|
1722 | if( !pcCU->getSlice()->isIntra() ) |
---|
1723 | { |
---|
1724 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1725 | } |
---|
1726 | |
---|
1727 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1728 | { |
---|
1729 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1730 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1731 | xRestoreDepthWidthHeight( pcCU ); |
---|
1732 | return; |
---|
1733 | } |
---|
1734 | |
---|
1735 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1736 | |
---|
1737 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1738 | |
---|
1739 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1740 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1741 | xRestoreDepthWidthHeight( pcCU ); |
---|
1742 | } |
---|
1743 | #endif |
---|
1744 | |
---|
1745 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
1746 | { |
---|
1747 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
1748 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
1749 | { |
---|
1750 | setdQPFlag(true); |
---|
1751 | } |
---|
1752 | #if BURST_IPCM |
---|
1753 | pcCU->setNumSucIPCM(0); |
---|
1754 | pcCU->setLastCUSucIPCMFlag(false); |
---|
1755 | #endif |
---|
1756 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1757 | { |
---|
1758 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1759 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1760 | Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getEntropySliceCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getEntropySliceCurEndCUAddr(); |
---|
1761 | if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
1762 | { |
---|
1763 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
1764 | } |
---|
1765 | } |
---|
1766 | return; |
---|
1767 | } |
---|
1768 | |
---|
1769 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
1770 | { |
---|
1771 | setdQPFlag(true); |
---|
1772 | } |
---|
1773 | #if HHI_MPI |
---|
1774 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1775 | { |
---|
1776 | #endif |
---|
1777 | if( !pcCU->getSlice()->isIntra() ) |
---|
1778 | { |
---|
1779 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1780 | } |
---|
1781 | #if HHI_MPI |
---|
1782 | } |
---|
1783 | #endif |
---|
1784 | |
---|
1785 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1786 | { |
---|
1787 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1788 | #if LGE_ILLUCOMP_B0045 |
---|
1789 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
1790 | #endif |
---|
1791 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1792 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1793 | #endif |
---|
1794 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1795 | return; |
---|
1796 | } |
---|
1797 | #if HHI_MPI |
---|
1798 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1799 | { |
---|
1800 | #endif |
---|
1801 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1802 | |
---|
1803 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1804 | |
---|
1805 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
1806 | { |
---|
1807 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
1808 | |
---|
1809 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
1810 | { |
---|
1811 | // Encode slice finish |
---|
1812 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1813 | return; |
---|
1814 | } |
---|
1815 | } |
---|
1816 | |
---|
1817 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1818 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1819 | #if LGE_ILLUCOMP_B0045 |
---|
1820 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
1821 | #endif |
---|
1822 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1823 | if( !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
1824 | { |
---|
1825 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1826 | } |
---|
1827 | #endif |
---|
1828 | #if HHI_MPI |
---|
1829 | } |
---|
1830 | #endif |
---|
1831 | |
---|
1832 | // Encode Coefficients |
---|
1833 | Bool bCodeDQP = getdQPFlag(); |
---|
1834 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP ); |
---|
1835 | setdQPFlag( bCodeDQP ); |
---|
1836 | |
---|
1837 | // --- write terminating bit --- |
---|
1838 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
1839 | } |
---|
1840 | |
---|
1841 | /** check RD costs for a CU block encoded with merge |
---|
1842 | * \param rpcBestCU |
---|
1843 | * \param rpcTempCU |
---|
1844 | * \returns Void |
---|
1845 | */ |
---|
1846 | #if HHI_INTERVIEW_SKIP |
---|
1847 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
1848 | #else |
---|
1849 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1850 | #endif |
---|
1851 | { |
---|
1852 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
1853 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
1854 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
1855 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
1856 | #else |
---|
1857 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
1858 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1859 | #endif |
---|
1860 | Int numValidMergeCand = 0; |
---|
1861 | |
---|
1862 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1863 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1864 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1865 | #endif |
---|
1866 | #if LGE_ILLUCOMP_B0045 |
---|
1867 | Bool bICFlag = rpcTempCU->getICFlag(0); |
---|
1868 | #endif |
---|
1869 | |
---|
1870 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
1871 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS_MEM; ++ui ) |
---|
1872 | #else |
---|
1873 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
1874 | #endif |
---|
1875 | { |
---|
1876 | uhInterDirNeighbours[ui] = 0; |
---|
1877 | } |
---|
1878 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1879 | |
---|
1880 | #if HHI_VSO |
---|
1881 | if( m_pcRdCost->getUseRenModel() ) |
---|
1882 | { |
---|
1883 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
1884 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
1885 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1886 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1887 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1888 | } |
---|
1889 | #endif |
---|
1890 | |
---|
1891 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1892 | #if MERL_VSP_C0152 |
---|
1893 | Int iVSPIndexTrue[3] = {-1, -1, -1}; |
---|
1894 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue ); |
---|
1895 | #else |
---|
1896 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
---|
1897 | #endif |
---|
1898 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
1899 | Bool bestIsSkip = false; |
---|
1900 | #endif |
---|
1901 | |
---|
1902 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
1903 | { |
---|
1904 | { |
---|
1905 | TComYuv* pcPredYuvTemp = NULL; |
---|
1906 | #if LOSSLESS_CODING |
---|
1907 | UInt iteration; |
---|
1908 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
1909 | { |
---|
1910 | iteration = 1; |
---|
1911 | } |
---|
1912 | else |
---|
1913 | { |
---|
1914 | iteration = 2; |
---|
1915 | } |
---|
1916 | |
---|
1917 | #if HHI_INTERVIEW_SKIP |
---|
1918 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < iteration; ++uiNoResidual ) |
---|
1919 | #else |
---|
1920 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
1921 | #endif |
---|
1922 | #else |
---|
1923 | #if HHI_INTERVIEW_SKIP |
---|
1924 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < 2; ++uiNoResidual ) |
---|
1925 | #else |
---|
1926 | for( UInt uiNoResidual = 0; uiNoResidual < 2; ++uiNoResidual ) |
---|
1927 | #endif |
---|
1928 | #endif |
---|
1929 | { |
---|
1930 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
1931 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
1932 | { |
---|
1933 | #endif |
---|
1934 | // set MC parameters |
---|
1935 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1936 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1937 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1938 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1939 | #if MERL_VSP_C0152 |
---|
1940 | { |
---|
1941 | Int iVSPIdx = 0; |
---|
1942 | Int numVSPIdx; |
---|
1943 | numVSPIdx = 3; |
---|
1944 | for (Int i = 0; i < numVSPIdx; i++) |
---|
1945 | { |
---|
1946 | if (iVSPIndexTrue[i] == uiMergeCand) |
---|
1947 | { |
---|
1948 | iVSPIdx = i+1; |
---|
1949 | break; |
---|
1950 | } |
---|
1951 | } |
---|
1952 | rpcTempCU->setVSPIndexSubParts( iVSPIdx, 0, 0, uhDepth ); |
---|
1953 | } |
---|
1954 | #endif |
---|
1955 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1956 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1957 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1958 | |
---|
1959 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1960 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1961 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1962 | #endif |
---|
1963 | #if LGE_ILLUCOMP_B0045 |
---|
1964 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uhDepth); |
---|
1965 | #endif |
---|
1966 | |
---|
1967 | // do MC |
---|
1968 | #if HHI_INTERVIEW_SKIP |
---|
1969 | if ( (uiNoResidual == 0) || bSkipRes ) |
---|
1970 | #else |
---|
1971 | if ( uiNoResidual == 0 ) |
---|
1972 | #endif |
---|
1973 | { |
---|
1974 | #if MERL_VSP_C0152 |
---|
1975 | m_pcPredSearch->motionCompensationBWVSP ( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU() ); |
---|
1976 | #else |
---|
1977 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1978 | #endif |
---|
1979 | // save pred adress |
---|
1980 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
1981 | |
---|
1982 | } |
---|
1983 | else |
---|
1984 | { |
---|
1985 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
1986 | if( bestIsSkip) |
---|
1987 | { |
---|
1988 | #if MERL_VSP_C0152 |
---|
1989 | m_pcPredSearch->motionCompensationBWVSP ( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU() ); |
---|
1990 | #else |
---|
1991 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1992 | #endif |
---|
1993 | // save pred adress |
---|
1994 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
1995 | } |
---|
1996 | else |
---|
1997 | { |
---|
1998 | #endif |
---|
1999 | if ( pcPredYuvTemp != m_ppcPredYuvTemp[uhDepth]) |
---|
2000 | { |
---|
2001 | //adress changes take best (old temp) |
---|
2002 | pcPredYuvTemp = m_ppcPredYuvBest[uhDepth]; |
---|
2003 | } |
---|
2004 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2005 | } |
---|
2006 | #endif |
---|
2007 | } |
---|
2008 | #if HHI_VSO |
---|
2009 | if( m_pcRdCost->getUseRenModel() ) |
---|
2010 | { //Reset |
---|
2011 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
2012 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
2013 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); |
---|
2014 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
2015 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2016 | } |
---|
2017 | #endif |
---|
2018 | // estimate residual and encode everything |
---|
2019 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2020 | m_ppcOrigYuv [uhDepth], |
---|
2021 | pcPredYuvTemp, |
---|
2022 | m_ppcResiYuvTemp[uhDepth], |
---|
2023 | m_ppcResiYuvBest[uhDepth], |
---|
2024 | m_ppcRecoYuvTemp[uhDepth], |
---|
2025 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2026 | m_ppcResPredTmp [uhDepth], |
---|
2027 | #endif |
---|
2028 | (uiNoResidual? true:false) ); |
---|
2029 | Bool bQtRootCbf = rpcTempCU->getQtRootCbf(0) == 1; |
---|
2030 | |
---|
2031 | #if H0736_AVC_STYLE_QP_RANGE |
---|
2032 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
2033 | xCheckDQP( rpcTempCU ); |
---|
2034 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2035 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
2036 | #else |
---|
2037 | UInt uiOrgQP = rpcTempCU->getQP( 0 ); |
---|
2038 | xCheckDQP( rpcTempCU ); |
---|
2039 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2040 | rpcTempCU->initEstData( uhDepth, uiOrgQP ); |
---|
2041 | #endif |
---|
2042 | |
---|
2043 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2044 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
2045 | { |
---|
2046 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
2047 | } |
---|
2048 | #endif |
---|
2049 | |
---|
2050 | if (!bQtRootCbf) |
---|
2051 | break; |
---|
2052 | #if FAST_DECISION_FOR_MRG_RD_COST |
---|
2053 | } |
---|
2054 | #endif |
---|
2055 | } |
---|
2056 | } |
---|
2057 | } |
---|
2058 | } |
---|
2059 | |
---|
2060 | #if AMP_MRG |
---|
2061 | #if HHI_INTERVIEW_SKIP |
---|
2062 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes, Bool bUseMRG) |
---|
2063 | #else |
---|
2064 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG) |
---|
2065 | #endif |
---|
2066 | #else |
---|
2067 | #if HHI_INTERVIEW_SKIP |
---|
2068 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes) |
---|
2069 | #else |
---|
2070 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
2071 | #endif |
---|
2072 | #endif |
---|
2073 | { |
---|
2074 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2075 | |
---|
2076 | #if HHI_VSO |
---|
2077 | if( m_pcRdCost->getUseRenModel() ) |
---|
2078 | { |
---|
2079 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
2080 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
2081 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
2082 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
2083 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2084 | } |
---|
2085 | #endif |
---|
2086 | |
---|
2087 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
2088 | |
---|
2089 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2090 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
2091 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
2092 | #endif |
---|
2093 | |
---|
2094 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
2095 | |
---|
2096 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2097 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
2098 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
2099 | #endif |
---|
2100 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
2101 | |
---|
2102 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2103 | #if !LG_RESTRICTEDRESPRED_M24766 |
---|
2104 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
2105 | { // subtract residual prediction from original in motion search |
---|
2106 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ), true ); |
---|
2107 | } |
---|
2108 | #endif |
---|
2109 | #endif |
---|
2110 | |
---|
2111 | #if AMP_MRG |
---|
2112 | rpcTempCU->setMergeAMP (true); |
---|
2113 | #if HHI_INTERVIEW_SKIP |
---|
2114 | #if LG_RESTRICTEDRESPRED_M24766 |
---|
2115 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG); |
---|
2116 | #else |
---|
2117 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG ); |
---|
2118 | #endif |
---|
2119 | #else |
---|
2120 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG ); |
---|
2121 | #endif |
---|
2122 | #else |
---|
2123 | #if HHI_INTERVIEW_SKIP |
---|
2124 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes ); |
---|
2125 | #else |
---|
2126 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
2127 | #endif |
---|
2128 | #endif |
---|
2129 | |
---|
2130 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2131 | #if !LG_RESTRICTEDRESPRED_M24766 |
---|
2132 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
2133 | { // add residual prediction to original again |
---|
2134 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ) ); |
---|
2135 | } |
---|
2136 | #endif |
---|
2137 | #endif |
---|
2138 | |
---|
2139 | #if AMP_MRG |
---|
2140 | if ( !rpcTempCU->getMergeAMP() ) |
---|
2141 | { |
---|
2142 | return; |
---|
2143 | } |
---|
2144 | #endif |
---|
2145 | |
---|
2146 | #if HHI_INTERVIEW_SKIP |
---|
2147 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2148 | m_ppcOrigYuv[uhDepth], |
---|
2149 | m_ppcPredYuvTemp[uhDepth], |
---|
2150 | m_ppcResiYuvTemp[uhDepth], |
---|
2151 | m_ppcResiYuvBest[uhDepth], |
---|
2152 | m_ppcRecoYuvTemp[uhDepth], |
---|
2153 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2154 | m_ppcResPredTmp [uhDepth], |
---|
2155 | #endif |
---|
2156 | bSkipRes ); |
---|
2157 | #else |
---|
2158 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2159 | m_ppcOrigYuv[uhDepth], |
---|
2160 | m_ppcPredYuvTemp[uhDepth], |
---|
2161 | m_ppcResiYuvTemp[uhDepth], |
---|
2162 | m_ppcResiYuvBest[uhDepth], |
---|
2163 | m_ppcRecoYuvTemp[uhDepth], |
---|
2164 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2165 | m_ppcResPredTmp [uhDepth], |
---|
2166 | #endif |
---|
2167 | false ); |
---|
2168 | #endif |
---|
2169 | #if HHI_VSO |
---|
2170 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
2171 | { |
---|
2172 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2173 | } |
---|
2174 | else |
---|
2175 | #endif |
---|
2176 | { |
---|
2177 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2178 | } |
---|
2179 | |
---|
2180 | xCheckDQP( rpcTempCU ); |
---|
2181 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
2182 | } |
---|
2183 | |
---|
2184 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
2185 | { |
---|
2186 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2187 | |
---|
2188 | #if HHI_VSO |
---|
2189 | if( m_pcRdCost->getUseRenModel() ) |
---|
2190 | { |
---|
2191 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth (); |
---|
2192 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight (); |
---|
2193 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr(); |
---|
2194 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride (); |
---|
2195 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2196 | } |
---|
2197 | #endif |
---|
2198 | |
---|
2199 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
2200 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2201 | |
---|
2202 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
2203 | Dist uiPreCalcDistC = 0; |
---|
2204 | if( !bSeparateLumaChroma ) |
---|
2205 | { |
---|
2206 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
2207 | } |
---|
2208 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
2209 | |
---|
2210 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
2211 | |
---|
2212 | #if RWTH_SDC_DLT_B0036 |
---|
2213 | if( !rpcTempCU->getSDCFlag( 0 ) ) |
---|
2214 | #endif |
---|
2215 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
2216 | |
---|
2217 | m_pcEntropyCoder->resetBits(); |
---|
2218 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2219 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
2220 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
2221 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
2222 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
2223 | |
---|
2224 | // Encode Coefficients |
---|
2225 | Bool bCodeDQP = getdQPFlag(); |
---|
2226 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP ); |
---|
2227 | setdQPFlag( bCodeDQP ); |
---|
2228 | |
---|
2229 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2230 | |
---|
2231 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2232 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2233 | { |
---|
2234 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2235 | } |
---|
2236 | #if HHI_VSO |
---|
2237 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
2238 | { |
---|
2239 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2240 | } |
---|
2241 | else |
---|
2242 | #endif |
---|
2243 | { |
---|
2244 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2245 | } |
---|
2246 | |
---|
2247 | xCheckDQP( rpcTempCU ); |
---|
2248 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
---|
2249 | } |
---|
2250 | |
---|
2251 | /** Check R-D costs for a CU with PCM mode. |
---|
2252 | * \param rpcBestCU pointer to best mode CU data structure |
---|
2253 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
2254 | * \returns Void |
---|
2255 | * |
---|
2256 | * \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. |
---|
2257 | */ |
---|
2258 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2259 | { |
---|
2260 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
2261 | |
---|
2262 | rpcTempCU->setIPCMFlag(0, true); |
---|
2263 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
2264 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
2265 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
2266 | |
---|
2267 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
2268 | |
---|
2269 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
2270 | |
---|
2271 | m_pcEntropyCoder->resetBits(); |
---|
2272 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
2273 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
2274 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
2275 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
2276 | |
---|
2277 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
2278 | |
---|
2279 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2280 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2281 | { |
---|
2282 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2283 | } |
---|
2284 | #if HHI_VSO |
---|
2285 | if ( m_pcRdCost->getUseVSO() ) |
---|
2286 | { |
---|
2287 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2288 | } |
---|
2289 | else |
---|
2290 | #endif |
---|
2291 | { |
---|
2292 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2293 | } |
---|
2294 | |
---|
2295 | xCheckDQP( rpcTempCU ); |
---|
2296 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
2297 | } |
---|
2298 | |
---|
2299 | // check whether current try is the best |
---|
2300 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
2301 | { |
---|
2302 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
2303 | { |
---|
2304 | TComYuv* pcYuv; |
---|
2305 | UChar uhDepth = rpcBestCU->getDepth(0); |
---|
2306 | |
---|
2307 | // Change Information data |
---|
2308 | TComDataCU* pcCU = rpcBestCU; |
---|
2309 | rpcBestCU = rpcTempCU; |
---|
2310 | rpcTempCU = pcCU; |
---|
2311 | |
---|
2312 | // Change Prediction data |
---|
2313 | pcYuv = m_ppcPredYuvBest[uhDepth]; |
---|
2314 | m_ppcPredYuvBest[uhDepth] = m_ppcPredYuvTemp[uhDepth]; |
---|
2315 | m_ppcPredYuvTemp[uhDepth] = pcYuv; |
---|
2316 | |
---|
2317 | // Change Reconstruction data |
---|
2318 | pcYuv = m_ppcRecoYuvBest[uhDepth]; |
---|
2319 | m_ppcRecoYuvBest[uhDepth] = m_ppcRecoYuvTemp[uhDepth]; |
---|
2320 | m_ppcRecoYuvTemp[uhDepth] = pcYuv; |
---|
2321 | |
---|
2322 | pcYuv = NULL; |
---|
2323 | pcCU = NULL; |
---|
2324 | |
---|
2325 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
2326 | m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_NEXT_BEST]); |
---|
2327 | } |
---|
2328 | } |
---|
2329 | |
---|
2330 | /** check whether current try is the best with identifying the depth of current try |
---|
2331 | * \param rpcBestCU |
---|
2332 | * \param rpcTempCU |
---|
2333 | * \returns Void |
---|
2334 | */ |
---|
2335 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
2336 | { |
---|
2337 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
2338 | { |
---|
2339 | TComYuv* pcYuv; |
---|
2340 | // Change Information data |
---|
2341 | TComDataCU* pcCU = rpcBestCU; |
---|
2342 | rpcBestCU = rpcTempCU; |
---|
2343 | rpcTempCU = pcCU; |
---|
2344 | |
---|
2345 | // Change Prediction data |
---|
2346 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
2347 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
2348 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
2349 | |
---|
2350 | // Change Reconstruction data |
---|
2351 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
2352 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
2353 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
2354 | |
---|
2355 | pcYuv = NULL; |
---|
2356 | pcCU = NULL; |
---|
2357 | |
---|
2358 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
2359 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
2360 | } |
---|
2361 | } |
---|
2362 | |
---|
2363 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
2364 | { |
---|
2365 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
2366 | |
---|
2367 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
2368 | { |
---|
2369 | if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) |
---|
2370 | { |
---|
2371 | #if !RDO_WITHOUT_DQP_BITS |
---|
2372 | m_pcEntropyCoder->resetBits(); |
---|
2373 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
2374 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
2375 | if(m_pcEncCfg->getUseSBACRD()) |
---|
2376 | { |
---|
2377 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
2378 | } |
---|
2379 | |
---|
2380 | // GT: Change here?? |
---|
2381 | #if HHI_VSO |
---|
2382 | if ( m_pcRdCost->getUseVSO() ) |
---|
2383 | { |
---|
2384 | pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
2385 | } |
---|
2386 | else |
---|
2387 | #endif |
---|
2388 | { |
---|
2389 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
2390 | } |
---|
2391 | #endif |
---|
2392 | } |
---|
2393 | else |
---|
2394 | { |
---|
2395 | #if LOSSLESS_CODING |
---|
2396 | if (( ( pcCU->getRefQP( 0 ) != pcCU->getQP( 0 )) ) && (pcCU->getSlice()->getSPS()->getUseLossless())) |
---|
2397 | { |
---|
2398 | pcCU->getTotalCost() = MAX_DOUBLE; |
---|
2399 | } |
---|
2400 | #endif |
---|
2401 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
2402 | } |
---|
2403 | } |
---|
2404 | } |
---|
2405 | |
---|
2406 | #if BURST_IPCM |
---|
2407 | /** Check whether the last CU shares the same root as the current CU and is IPCM or not. |
---|
2408 | * \param pcCU |
---|
2409 | * \param uiCurAbsPartIdx |
---|
2410 | * \returns Bool |
---|
2411 | */ |
---|
2412 | Bool TEncCu::checkLastCUSucIPCM( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) |
---|
2413 | { |
---|
2414 | Bool lastCUSucIPCMFlag = false; |
---|
2415 | |
---|
2416 | UInt curDepth = pcCU->getDepth(uiCurAbsPartIdx); |
---|
2417 | UInt shift = ((pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx())->getSPS()->getMaxCUDepth() - curDepth)<<1); |
---|
2418 | UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); |
---|
2419 | |
---|
2420 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2421 | if( pcSlice->getEntropySliceCurStartCUAddr() == ( pcCU->getSCUAddr() + uiCurAbsPartIdx ) ) |
---|
2422 | { |
---|
2423 | return false; |
---|
2424 | } |
---|
2425 | |
---|
2426 | if(curDepth > 0 && startPartUnitIdx > 0) |
---|
2427 | { |
---|
2428 | Int lastValidPartIdx = pcCU->getLastValidPartIdx((Int) uiCurAbsPartIdx ); |
---|
2429 | |
---|
2430 | if( lastValidPartIdx >= 0 ) |
---|
2431 | { |
---|
2432 | if(( pcCU->getSliceStartCU( uiCurAbsPartIdx ) == pcCU->getSliceStartCU( (UInt) lastValidPartIdx )) |
---|
2433 | && |
---|
2434 | ( pcCU->getDepth( uiCurAbsPartIdx ) == pcCU->getDepth( (UInt) lastValidPartIdx )) |
---|
2435 | && |
---|
2436 | pcCU->getIPCMFlag( (UInt) lastValidPartIdx ) ) |
---|
2437 | { |
---|
2438 | lastCUSucIPCMFlag = true; |
---|
2439 | } |
---|
2440 | } |
---|
2441 | } |
---|
2442 | |
---|
2443 | return lastCUSucIPCMFlag; |
---|
2444 | } |
---|
2445 | |
---|
2446 | /** Count the number of successive IPCM CUs sharing the same root. |
---|
2447 | * \param pcCU |
---|
2448 | * \param uiCurAbsPartIdx |
---|
2449 | * \returns Int |
---|
2450 | */ |
---|
2451 | Int TEncCu::countNumSucIPCM ( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) |
---|
2452 | { |
---|
2453 | Int numSucIPCM = 0; |
---|
2454 | UInt CurDepth = pcCU->getDepth(uiCurAbsPartIdx); |
---|
2455 | |
---|
2456 | if( pcCU->getIPCMFlag(uiCurAbsPartIdx) ) |
---|
2457 | { |
---|
2458 | if(CurDepth == 0) |
---|
2459 | { |
---|
2460 | numSucIPCM = 1; |
---|
2461 | } |
---|
2462 | else |
---|
2463 | { |
---|
2464 | TComPic* pcPic = pcCU->getPic(); |
---|
2465 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2466 | UInt qNumParts = ( pcPic->getNumPartInCU() >> ((CurDepth-1)<<1) )>>2; |
---|
2467 | |
---|
2468 | Bool continueFlag = true; |
---|
2469 | UInt absPartIdx = uiCurAbsPartIdx; |
---|
2470 | UInt shift = ((pcSlice->getSPS()->getMaxCUDepth() - CurDepth)<<1); |
---|
2471 | UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); |
---|
2472 | |
---|
2473 | for ( UInt partUnitIdx = startPartUnitIdx; partUnitIdx < 4 && continueFlag; partUnitIdx++, absPartIdx+=qNumParts ) |
---|
2474 | { |
---|
2475 | UInt lPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ]; |
---|
2476 | UInt tPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ]; |
---|
2477 | Bool inSliceFlag = ( pcCU->getSCUAddr()+absPartIdx+qNumParts>pcSlice->getEntropySliceCurStartCUAddr() ) && ( pcCU->getSCUAddr()+absPartIdx < pcSlice->getEntropySliceCurEndCUAddr()); |
---|
2478 | |
---|
2479 | if( inSliceFlag && ( lPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( tPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2480 | { |
---|
2481 | UInt uiDepth = pcCU->getDepth(absPartIdx); |
---|
2482 | |
---|
2483 | if( ( CurDepth == uiDepth) && pcCU->getIPCMFlag( absPartIdx ) ) |
---|
2484 | { |
---|
2485 | numSucIPCM++; |
---|
2486 | } |
---|
2487 | else |
---|
2488 | { |
---|
2489 | continueFlag = false; |
---|
2490 | } |
---|
2491 | } |
---|
2492 | } |
---|
2493 | } |
---|
2494 | } |
---|
2495 | |
---|
2496 | return numSucIPCM; |
---|
2497 | } |
---|
2498 | #endif |
---|
2499 | |
---|
2500 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
2501 | { |
---|
2502 | pDst->iN = pSrc->iN; |
---|
2503 | for (Int i = 0; i < pSrc->iN; i++) |
---|
2504 | { |
---|
2505 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
2506 | } |
---|
2507 | } |
---|
2508 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
---|
2509 | { |
---|
2510 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
2511 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
2512 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
2513 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2514 | pcSlice->getEntropySliceCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2515 | Bool bSliceEnd = pcSlice->getEntropySliceCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
2516 | pcSlice->getEntropySliceCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
2517 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2518 | { |
---|
2519 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
2520 | UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); |
---|
2521 | UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); |
---|
2522 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
2523 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
2524 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
2525 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
2526 | } |
---|
2527 | else |
---|
2528 | { |
---|
2529 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
2530 | |
---|
2531 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
2532 | { |
---|
2533 | UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); |
---|
2534 | UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); |
---|
2535 | |
---|
2536 | Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getEntropySliceCurStartCUAddr() && |
---|
2537 | rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getEntropySliceCurEndCUAddr(); |
---|
2538 | if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2539 | { |
---|
2540 | xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv |
---|
2541 | } |
---|
2542 | } |
---|
2543 | } |
---|
2544 | } |
---|
2545 | |
---|
2546 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
2547 | { |
---|
2548 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
2549 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
2550 | } |
---|
2551 | |
---|
2552 | #if LOSSLESS_CODING |
---|
2553 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
2554 | * \param pcCU pointer to current CU |
---|
2555 | * \param pcOrgYuv pointer to original sample array |
---|
2556 | * \returns Void |
---|
2557 | */ |
---|
2558 | Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) |
---|
2559 | { |
---|
2560 | |
---|
2561 | UInt width = pCU->getWidth(0); |
---|
2562 | UInt height = pCU->getHeight(0); |
---|
2563 | |
---|
2564 | Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); |
---|
2565 | Pel* pDstY = pCU->getPCMSampleY(); |
---|
2566 | UInt srcStride = pOrgYuv->getStride(); |
---|
2567 | |
---|
2568 | for(Int y = 0; y < height; y++ ) |
---|
2569 | { |
---|
2570 | for(Int x = 0; x < width; x++ ) |
---|
2571 | { |
---|
2572 | pDstY[x] = pSrcY[x]; |
---|
2573 | } |
---|
2574 | pDstY += width; |
---|
2575 | pSrcY += srcStride; |
---|
2576 | } |
---|
2577 | |
---|
2578 | Pel* pSrcCb = pOrgYuv->getCbAddr(); |
---|
2579 | Pel* pSrcCr = pOrgYuv->getCrAddr();; |
---|
2580 | |
---|
2581 | Pel* pDstCb = pCU->getPCMSampleCb(); |
---|
2582 | Pel* pDstCr = pCU->getPCMSampleCr();; |
---|
2583 | |
---|
2584 | UInt srcStrideC = pOrgYuv->getCStride(); |
---|
2585 | UInt heightC = height >> 1; |
---|
2586 | UInt widthC = width >> 1; |
---|
2587 | |
---|
2588 | for(Int y = 0; y < heightC; y++ ) |
---|
2589 | { |
---|
2590 | for(Int x = 0; x < widthC; x++ ) |
---|
2591 | { |
---|
2592 | pDstCb[x] = pSrcCb[x]; |
---|
2593 | pDstCr[x] = pSrcCr[x]; |
---|
2594 | } |
---|
2595 | pDstCb += widthC; |
---|
2596 | pDstCr += widthC; |
---|
2597 | pSrcCb += srcStrideC; |
---|
2598 | pSrcCr += srcStrideC; |
---|
2599 | } |
---|
2600 | } |
---|
2601 | #endif |
---|
2602 | |
---|
2603 | #if ADAPTIVE_QP_SELECTION |
---|
2604 | /** Collect ARL statistics from one block |
---|
2605 | */ |
---|
2606 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
2607 | { |
---|
2608 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
2609 | { |
---|
2610 | Int u = abs( rpcCoeff[ n ] ); |
---|
2611 | Int absc = rpcArlCoeff[ n ]; |
---|
2612 | |
---|
2613 | if( u != 0 ) |
---|
2614 | { |
---|
2615 | if( u < LEVEL_RANGE ) |
---|
2616 | { |
---|
2617 | cSum[ u ] += ( Double )absc; |
---|
2618 | numSamples[ u ]++; |
---|
2619 | } |
---|
2620 | else |
---|
2621 | { |
---|
2622 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
2623 | numSamples[ LEVEL_RANGE ]++; |
---|
2624 | } |
---|
2625 | } |
---|
2626 | } |
---|
2627 | |
---|
2628 | return 0; |
---|
2629 | } |
---|
2630 | |
---|
2631 | /** Collect ARL statistics from one LCU |
---|
2632 | * \param pcCU |
---|
2633 | */ |
---|
2634 | Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) |
---|
2635 | { |
---|
2636 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
---|
2637 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
---|
2638 | |
---|
2639 | TCoeff* pCoeffY = rpcCU->getCoeffY(); |
---|
2640 | Int* pArlCoeffY = rpcCU->getArlCoeffY(); |
---|
2641 | |
---|
2642 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
2643 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
---|
2644 | |
---|
2645 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
2646 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
2647 | |
---|
2648 | // Collect stats to cSum[][] and numSamples[][] |
---|
2649 | for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) |
---|
2650 | { |
---|
2651 | UInt uiTrIdx = rpcCU->getTransformIdx(i); |
---|
2652 | |
---|
2653 | if(rpcCU->getPredictionMode(i) == MODE_INTER) |
---|
2654 | if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) |
---|
2655 | { |
---|
2656 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
2657 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
2658 | |
---|
2659 | pCoeffY += uiMinNumCoeffInCU; |
---|
2660 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
2661 | } |
---|
2662 | |
---|
2663 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
2664 | { |
---|
2665 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
2666 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
2667 | } |
---|
2668 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
2669 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
2670 | } |
---|
2671 | #endif |
---|
2672 | |
---|
2673 | #if HHI_MPI |
---|
2674 | Void TEncCu::xCheckRDCostMvInheritance( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhTextureModeDepth, Bool bSkipResidual, Bool bRecursiveCall ) |
---|
2675 | { |
---|
2676 | assert( rpcTempCU->getSlice()->getIsDepth() ); |
---|
2677 | TComDataCU *pcTextureCU = rpcTempCU->getSlice()->getTexturePic()->getCU( rpcTempCU->getAddr() ); |
---|
2678 | |
---|
2679 | const UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
2680 | const Int iQP = rpcTempCU->getQP( 0 ); |
---|
2681 | assert( bRecursiveCall == ( uhDepth != uhTextureModeDepth ) ); |
---|
2682 | |
---|
2683 | #if !MTK_UNCONSTRAINED_MVI_B0083 |
---|
2684 | if( uhDepth == uhTextureModeDepth ) |
---|
2685 | { |
---|
2686 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
2687 | { |
---|
2688 | if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) ) |
---|
2689 | { |
---|
2690 | return; |
---|
2691 | } |
---|
2692 | } |
---|
2693 | } |
---|
2694 | #endif |
---|
2695 | |
---|
2696 | #if HHI_VSO |
---|
2697 | if( m_pcRdCost->getUseRenModel() && !bRecursiveCall) |
---|
2698 | { |
---|
2699 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
2700 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
2701 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr(); |
---|
2702 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
2703 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2704 | } |
---|
2705 | #endif |
---|
2706 | |
---|
2707 | Bool bSplit = uhDepth < pcTextureCU->getDepth( rpcTempCU->getZorderIdxInCU() ); |
---|
2708 | if( bSplit ) |
---|
2709 | { |
---|
2710 | const UChar uhNextDepth = uhDepth+1; |
---|
2711 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
2712 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
2713 | |
---|
2714 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
2715 | { |
---|
2716 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
2717 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
2718 | |
---|
2719 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
2720 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getEntropySliceCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getEntropySliceCurEndCUAddr(); |
---|
2721 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
2722 | { |
---|
2723 | if( m_bUseSBACRD ) |
---|
2724 | { |
---|
2725 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
2726 | { |
---|
2727 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhDepth][CI_CURR_BEST]); |
---|
2728 | } |
---|
2729 | else |
---|
2730 | { |
---|
2731 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
2732 | } |
---|
2733 | } |
---|
2734 | |
---|
2735 | xCheckRDCostMvInheritance( pcSubBestPartCU, pcSubTempPartCU, uhTextureModeDepth, bSkipResidual, true ); |
---|
2736 | |
---|
2737 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
2738 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
2739 | } |
---|
2740 | else if (bInSlice) |
---|
2741 | { |
---|
2742 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
2743 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
2744 | } |
---|
2745 | } |
---|
2746 | |
---|
2747 | if( uhDepth == uhTextureModeDepth ) |
---|
2748 | { |
---|
2749 | xAddMVISignallingBits( rpcTempCU ); |
---|
2750 | } |
---|
2751 | |
---|
2752 | // DQP stuff |
---|
2753 | { |
---|
2754 | if( (g_uiMaxCUWidth>>uhDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
2755 | { |
---|
2756 | TComPic *pcPic = rpcTempCU->getPic(); |
---|
2757 | TComSlice *pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
2758 | Bool bHasRedisual = false; |
---|
2759 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
2760 | { |
---|
2761 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getEntropySliceCurStartCUAddr() ) && |
---|
2762 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
2763 | { |
---|
2764 | bHasRedisual = true; |
---|
2765 | break; |
---|
2766 | } |
---|
2767 | } |
---|
2768 | |
---|
2769 | UInt uiTargetPartIdx; |
---|
2770 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getEntropySliceCurStartCUAddr() ) |
---|
2771 | { |
---|
2772 | uiTargetPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
2773 | } |
---|
2774 | else |
---|
2775 | { |
---|
2776 | uiTargetPartIdx = 0; |
---|
2777 | } |
---|
2778 | if ( ! bHasRedisual ) |
---|
2779 | { |
---|
2780 | #if LOSSLESS_CODING |
---|
2781 | if (((rpcTempCU->getQP(uiTargetPartIdx) != rpcTempCU->getRefQP(uiTargetPartIdx)) ) && (rpcTempCU->getSlice()->getSPS()->getUseLossless())) |
---|
2782 | { |
---|
2783 | rpcTempCU->getTotalCost() = MAX_DOUBLE; |
---|
2784 | } |
---|
2785 | #endif |
---|
2786 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uhDepth ); // set QP to default QP |
---|
2787 | } |
---|
2788 | } |
---|
2789 | } |
---|
2790 | |
---|
2791 | if( m_bUseSBACRD ) |
---|
2792 | { |
---|
2793 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]); |
---|
2794 | } |
---|
2795 | } |
---|
2796 | else |
---|
2797 | { |
---|
2798 | rpcTempCU->setTextureModeDepthSubParts( uhTextureModeDepth, 0, uhDepth ); |
---|
2799 | rpcTempCU->copyTextureMotionDataFrom( pcTextureCU, uhDepth, rpcTempCU->getZorderIdxInCU() ); |
---|
2800 | #if FIX_MPI_B0065 |
---|
2801 | UInt uiAbsPartIdx = rpcTempCU->getZorderIdxInCU(); |
---|
2802 | if( rpcTempCU->getDepth(0) > pcTextureCU->getDepth(uiAbsPartIdx)) |
---|
2803 | { |
---|
2804 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
---|
2805 | } |
---|
2806 | else |
---|
2807 | { |
---|
2808 | PartSize partSize = pcTextureCU->getPartitionSize(uiAbsPartIdx); |
---|
2809 | rpcTempCU->setPartSizeSubParts( partSize, 0, uhDepth ); |
---|
2810 | } |
---|
2811 | #else |
---|
2812 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
---|
2813 | #endif |
---|
2814 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
2815 | { |
---|
2816 | assert( rpcTempCU->getInterDir( ui ) != 0 ); |
---|
2817 | assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE ); |
---|
2818 | #if MERL_VSP_C0152 |
---|
2819 | Int vspIdx = pcTextureCU->getVSPIndex( rpcTempCU->getZorderIdxInCU() + ui); |
---|
2820 | rpcTempCU->setVSPIndex( ui , vspIdx); |
---|
2821 | #endif |
---|
2822 | } |
---|
2823 | |
---|
2824 | rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth ); |
---|
2825 | #if MERL_VSP_C0152 |
---|
2826 | m_pcPredSearch->motionCompensationBWVSP( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU() ); |
---|
2827 | #else |
---|
2828 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
2829 | #endif |
---|
2830 | // get Original YUV data from picture |
---|
2831 | m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
2832 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
2833 | m_ppcOrigYuv[uhDepth], |
---|
2834 | m_ppcPredYuvTemp[uhDepth], |
---|
2835 | m_ppcResiYuvTemp[uhDepth], |
---|
2836 | m_ppcResiYuvBest[uhDepth], |
---|
2837 | m_ppcRecoYuvTemp[uhDepth], |
---|
2838 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
2839 | m_ppcResPredTmp [uhDepth], |
---|
2840 | #endif |
---|
2841 | bSkipResidual ); |
---|
2842 | |
---|
2843 | if( uhDepth == uhTextureModeDepth ) |
---|
2844 | { |
---|
2845 | xAddMVISignallingBits( rpcTempCU ); |
---|
2846 | } |
---|
2847 | xCheckDQP( rpcTempCU ); |
---|
2848 | } |
---|
2849 | |
---|
2850 | #if HHI_VSO |
---|
2851 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
2852 | { |
---|
2853 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2854 | } |
---|
2855 | else |
---|
2856 | #endif |
---|
2857 | { |
---|
2858 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
2859 | } |
---|
2860 | |
---|
2861 | if( rpcTempCU->getPredictionMode( 0 ) == MODE_SKIP && uhDepth == uhTextureModeDepth ) |
---|
2862 | { |
---|
2863 | if( rpcTempCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uhDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
2864 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uhDepth ); // set QP to default QP |
---|
2865 | } |
---|
2866 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
2867 | rpcBestCU->copyToPic(uhDepth); // Copy Best data to Picture for next partition prediction. |
---|
2868 | |
---|
2869 | #if HHI_VSO |
---|
2870 | if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() ) |
---|
2871 | { |
---|
2872 | UInt uiWidth = m_ppcRecoYuvBest[uhDepth]->getWidth ( ); |
---|
2873 | UInt uiHeight = m_ppcRecoYuvBest[uhDepth]->getHeight ( ); |
---|
2874 | UInt uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride ( ); |
---|
2875 | Pel* piSrc = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 ); |
---|
2876 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
2877 | } |
---|
2878 | #endif |
---|
2879 | } |
---|
2880 | |
---|
2881 | Void TEncCu::xAddMVISignallingBits( TComDataCU* pcCU ) |
---|
2882 | { |
---|
2883 | const UChar uhDepth = pcCU->getTextureModeDepth( 0 ); |
---|
2884 | m_pcEntropyCoder->resetBits(); |
---|
2885 | xSaveDepthWidthHeight( pcCU ); |
---|
2886 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uhDepth, g_uiMaxCUHeight>>uhDepth, 0, uhDepth ); |
---|
2887 | pcCU->setDepthSubParts( uhDepth, 0 ); |
---|
2888 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
2889 | pcCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); |
---|
2890 | pcCU->setMergeIndexSubParts( HHI_MPI_MERGE_POS, 0, 0, uhDepth ); |
---|
2891 | |
---|
2892 | // check for skip mode |
---|
2893 | { |
---|
2894 | Bool bAllZero = true; |
---|
2895 | for( UInt ui = 0; ui < pcCU->getTotalNumPart(); ui++ ) |
---|
2896 | { |
---|
2897 | if( pcCU->getCbf( ui, TEXT_LUMA ) || pcCU->getCbf( ui, TEXT_CHROMA_U ) || pcCU->getCbf( ui, TEXT_CHROMA_V ) ) |
---|
2898 | { |
---|
2899 | bAllZero = false; |
---|
2900 | break; |
---|
2901 | } |
---|
2902 | } |
---|
2903 | if( bAllZero ) |
---|
2904 | pcCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
2905 | } |
---|
2906 | |
---|
2907 | |
---|
2908 | m_pcEntropyCoder->encodeSplitFlag( pcCU, 0, uhDepth, true ); |
---|
2909 | m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true ); |
---|
2910 | |
---|
2911 | if( pcCU->isSkipped( 0 ) ) |
---|
2912 | { |
---|
2913 | m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true ); |
---|
2914 | #if LGE_ILLUCOMP_B0045 |
---|
2915 | m_pcEntropyCoder->encodeICFlag( pcCU, 0, true ); |
---|
2916 | #endif |
---|
2917 | } |
---|
2918 | else |
---|
2919 | { |
---|
2920 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
---|
2921 | m_pcEntropyCoder->encodePartSize( pcCU, 0, uhDepth, true ); |
---|
2922 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
2923 | m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); |
---|
2924 | #if LGE_ILLUCOMP_B0045 |
---|
2925 | m_pcEntropyCoder->encodeICFlag( pcCU, 0, true ); |
---|
2926 | #endif |
---|
2927 | } |
---|
2928 | xRestoreDepthWidthHeight( pcCU ); |
---|
2929 | |
---|
2930 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
2931 | } |
---|
2932 | |
---|
2933 | Void TEncCu::xSaveDepthWidthHeight( TComDataCU* pcCU ) |
---|
2934 | { |
---|
2935 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
2936 | memcpy( m_puhDepthSaved, pcCU->getDepth(), iSizeInUchar ); |
---|
2937 | memcpy( m_puhWidthSaved, pcCU->getWidth(), iSizeInUchar ); |
---|
2938 | memcpy( m_puhHeightSaved, pcCU->getHeight(), iSizeInUchar ); |
---|
2939 | } |
---|
2940 | |
---|
2941 | Void TEncCu::xRestoreDepthWidthHeight( TComDataCU* pcCU ) |
---|
2942 | { |
---|
2943 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
2944 | memcpy( pcCU->getDepth(), m_puhDepthSaved, iSizeInUchar ); |
---|
2945 | memcpy( pcCU->getWidth(), m_puhWidthSaved, iSizeInUchar ); |
---|
2946 | memcpy( pcCU->getHeight(), m_puhHeightSaved, iSizeInUchar ); |
---|
2947 | } |
---|
2948 | #endif |
---|
2949 | |
---|
2950 | //! \} |
---|