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