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