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-2011, 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 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 | |
---|
35 | /** \file TEncCU.cpp |
---|
36 | \brief CU encoder class |
---|
37 | */ |
---|
38 | |
---|
39 | #include <stdio.h> |
---|
40 | #include "TEncTop.h" |
---|
41 | #include "TEncCu.h" |
---|
42 | #include "TEncAnalyze.h" |
---|
43 | |
---|
44 | // ==================================================================================================================== |
---|
45 | // Constructor / destructor / create / destroy |
---|
46 | // ==================================================================================================================== |
---|
47 | |
---|
48 | /** |
---|
49 | \param uiTotalDepth total number of allowable depth |
---|
50 | \param uiMaxWidth largest CU width |
---|
51 | \param uiMaxHeight largest CU height |
---|
52 | */ |
---|
53 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight) |
---|
54 | { |
---|
55 | Int i; |
---|
56 | |
---|
57 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
58 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
59 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
60 | |
---|
61 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
62 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
63 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
64 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
65 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
66 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
67 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
68 | m_ppcResPredTmp = new TComYuv*[m_uhTotalDepth-1]; |
---|
69 | #if POZNAN_CU_SKIP |
---|
70 | m_ppcAvailYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
71 | #endif |
---|
72 | #if POZNAN_CU_SYNTH |
---|
73 | m_ppcSynthYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
74 | #endif |
---|
75 | |
---|
76 | |
---|
77 | #if HHI_MPI |
---|
78 | m_puhDepthSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
79 | m_puhWidthSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
80 | m_puhHeightSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
---|
81 | #endif |
---|
82 | UInt uiNumPartitions; |
---|
83 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
84 | { |
---|
85 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
86 | UInt uiWidth = uiMaxWidth >> i; |
---|
87 | UInt uiHeight = uiMaxHeight >> i; |
---|
88 | |
---|
89 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false ); |
---|
90 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false ); |
---|
91 | |
---|
92 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight); |
---|
93 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight); |
---|
94 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight); |
---|
95 | |
---|
96 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight); |
---|
97 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight); |
---|
98 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight); |
---|
99 | |
---|
100 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight); |
---|
101 | |
---|
102 | #if POZNAN_CU_SKIP |
---|
103 | m_ppcAvailYuv [i] = new TComYuv; m_ppcAvailYuv [i]->create(uiWidth, uiHeight); |
---|
104 | #endif |
---|
105 | #if POZNAN_CU_SYNTH |
---|
106 | m_ppcSynthYuv [i] = new TComYuv; m_ppcSynthYuv [i]->create(uiWidth, uiHeight); |
---|
107 | #endif |
---|
108 | |
---|
109 | |
---|
110 | m_ppcResPredTmp [i] = new TComYuv; m_ppcResPredTmp [i]->create(uiWidth, uiHeight); |
---|
111 | } |
---|
112 | |
---|
113 | // initialize partition order. |
---|
114 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
115 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
116 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
117 | |
---|
118 | // initialize conversion matrix from partition index to pel |
---|
119 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
120 | } |
---|
121 | |
---|
122 | Void TEncCu::destroy() |
---|
123 | { |
---|
124 | Int i; |
---|
125 | |
---|
126 | #if HHI_MPI |
---|
127 | delete[] m_puhDepthSaved; m_puhDepthSaved = NULL; |
---|
128 | delete[] m_puhWidthSaved; m_puhWidthSaved = NULL; |
---|
129 | delete[] m_puhHeightSaved; m_puhHeightSaved = NULL; |
---|
130 | #endif |
---|
131 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
132 | { |
---|
133 | if(m_ppcBestCU[i]) |
---|
134 | { |
---|
135 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
136 | } |
---|
137 | if(m_ppcTempCU[i]) |
---|
138 | { |
---|
139 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
140 | } |
---|
141 | if(m_ppcPredYuvBest[i]) |
---|
142 | { |
---|
143 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
144 | } |
---|
145 | if(m_ppcResiYuvBest[i]) |
---|
146 | { |
---|
147 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
148 | } |
---|
149 | if(m_ppcRecoYuvBest[i]) |
---|
150 | { |
---|
151 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
152 | } |
---|
153 | if(m_ppcPredYuvTemp[i]) |
---|
154 | { |
---|
155 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
156 | } |
---|
157 | if(m_ppcResiYuvTemp[i]) |
---|
158 | { |
---|
159 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
160 | } |
---|
161 | if(m_ppcRecoYuvTemp[i]) |
---|
162 | { |
---|
163 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
164 | } |
---|
165 | if(m_ppcOrigYuv[i]) |
---|
166 | { |
---|
167 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
168 | } |
---|
169 | #if POZNAN_CU_SKIP |
---|
170 | if(m_ppcAvailYuv[i]) |
---|
171 | { |
---|
172 | m_ppcAvailYuv[i]->destroy(); delete m_ppcAvailYuv[i]; m_ppcAvailYuv[i] = NULL; |
---|
173 | } |
---|
174 | #endif |
---|
175 | #if POZNAN_CU_SYNTH |
---|
176 | if(m_ppcSynthYuv[i]) |
---|
177 | { |
---|
178 | m_ppcSynthYuv[i]->destroy(); delete m_ppcSynthYuv[i]; m_ppcSynthYuv[i] = NULL; |
---|
179 | } |
---|
180 | #endif |
---|
181 | if(m_ppcResPredTmp[i]) |
---|
182 | { |
---|
183 | m_ppcResPredTmp [i]->destroy(); delete m_ppcResPredTmp[i]; m_ppcResPredTmp[i] = NULL; |
---|
184 | } |
---|
185 | } |
---|
186 | if(m_ppcBestCU) |
---|
187 | { |
---|
188 | delete [] m_ppcBestCU; |
---|
189 | m_ppcBestCU = NULL; |
---|
190 | } |
---|
191 | if(m_ppcTempCU) |
---|
192 | { |
---|
193 | delete [] m_ppcTempCU; |
---|
194 | m_ppcTempCU = NULL; |
---|
195 | } |
---|
196 | |
---|
197 | if(m_ppcPredYuvBest) |
---|
198 | { |
---|
199 | delete [] m_ppcPredYuvBest; |
---|
200 | m_ppcPredYuvBest = NULL; |
---|
201 | } |
---|
202 | if(m_ppcResiYuvBest) |
---|
203 | { |
---|
204 | delete [] m_ppcResiYuvBest; |
---|
205 | m_ppcResiYuvBest = NULL; |
---|
206 | } |
---|
207 | if(m_ppcRecoYuvBest) |
---|
208 | { |
---|
209 | delete [] m_ppcRecoYuvBest; |
---|
210 | m_ppcRecoYuvBest = NULL; |
---|
211 | } |
---|
212 | if(m_ppcPredYuvTemp) |
---|
213 | { |
---|
214 | delete [] m_ppcPredYuvTemp; |
---|
215 | m_ppcPredYuvTemp = NULL; |
---|
216 | } |
---|
217 | if(m_ppcResiYuvTemp) |
---|
218 | { |
---|
219 | delete [] m_ppcResiYuvTemp; |
---|
220 | m_ppcResiYuvTemp = NULL; |
---|
221 | } |
---|
222 | if(m_ppcRecoYuvTemp) |
---|
223 | { |
---|
224 | delete [] m_ppcRecoYuvTemp; |
---|
225 | m_ppcRecoYuvTemp = NULL; |
---|
226 | } |
---|
227 | if(m_ppcOrigYuv) |
---|
228 | { |
---|
229 | delete [] m_ppcOrigYuv; |
---|
230 | m_ppcOrigYuv = NULL; |
---|
231 | } |
---|
232 | #if POZNAN_CU_SKIP |
---|
233 | if(m_ppcAvailYuv) |
---|
234 | { |
---|
235 | delete [] m_ppcAvailYuv; |
---|
236 | m_ppcAvailYuv = NULL; |
---|
237 | } |
---|
238 | #endif |
---|
239 | #if POZNAN_CU_SYNTH |
---|
240 | if(m_ppcSynthYuv) |
---|
241 | { |
---|
242 | delete [] m_ppcSynthYuv; |
---|
243 | m_ppcSynthYuv = NULL; |
---|
244 | } |
---|
245 | #endif |
---|
246 | if(m_ppcResPredTmp) |
---|
247 | { |
---|
248 | delete [] m_ppcResPredTmp; |
---|
249 | m_ppcResPredTmp = NULL; |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | /** \param pcEncTop pointer of encoder class |
---|
254 | */ |
---|
255 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
256 | { |
---|
257 | m_pcEncCfg = pcEncTop; |
---|
258 | m_pcEncTop = pcEncTop; |
---|
259 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
260 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
261 | m_pcBitCounter = pcEncTop->getBitCounter(); |
---|
262 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
263 | |
---|
264 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
265 | m_pcCavlcCoder = pcEncTop->getCavlcCoder(); |
---|
266 | m_pcSbacCoder = pcEncTop->getSbacCoder(); |
---|
267 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
268 | |
---|
269 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
270 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
271 | |
---|
272 | m_bUseSBACRD = pcEncTop->getUseSBACRD(); |
---|
273 | } |
---|
274 | |
---|
275 | // ==================================================================================================================== |
---|
276 | // Public member functions |
---|
277 | // ==================================================================================================================== |
---|
278 | |
---|
279 | /** \param rpcCU pointer of CU data class |
---|
280 | */ |
---|
281 | Void TEncCu::compressCU( TComDataCU*& rpcCU ) |
---|
282 | { |
---|
283 | // single-QP coding mode |
---|
284 | if ( rpcCU->getSlice()->getSPS()->getUseDQP() == false ) |
---|
285 | { |
---|
286 | // initialize CU data |
---|
287 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
288 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
289 | |
---|
290 | // analysis of CU |
---|
291 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
292 | } |
---|
293 | // multiple-QP coding mode |
---|
294 | else |
---|
295 | { |
---|
296 | Int iQP = rpcCU->getSlice()->getSliceQp(); |
---|
297 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
298 | Int i; |
---|
299 | Int iBestQP = iQP; |
---|
300 | Double fBestCost = MAX_DOUBLE; |
---|
301 | |
---|
302 | rpcCU->getSlice()->setSliceQp( iQP ); |
---|
303 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
304 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
305 | m_ppcBestCU[0]->setQPSubParts( iQP, 0, 0 ); |
---|
306 | m_ppcTempCU[0]->setQPSubParts( iQP, 0, 0 ); |
---|
307 | |
---|
308 | // first try |
---|
309 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
310 | |
---|
311 | // for non-zero residual case |
---|
312 | if ( !( m_ppcBestCU[0]->isSkipped( 0 ) && m_ppcBestCU[0]->getDepth( 0 ) == 0 ) ) |
---|
313 | { |
---|
314 | // add dQP bits |
---|
315 | m_pcEntropyCoder->resetBits(); |
---|
316 | m_pcEntropyCoder->encodeQP( m_ppcBestCU[0], 0, false ); |
---|
317 | m_ppcBestCU[0]->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
318 | |
---|
319 | |
---|
320 | #if HHI_VSO |
---|
321 | if ( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
322 | { |
---|
323 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCostVSO( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
324 | } |
---|
325 | else |
---|
326 | #endif |
---|
327 | { |
---|
328 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCost( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
329 | } |
---|
330 | |
---|
331 | fBestCost = m_ppcBestCU[0]->getTotalCost(); |
---|
332 | |
---|
333 | // try every case |
---|
334 | for ( i=iQP-idQP; i<=iQP+idQP; i++ ) |
---|
335 | { |
---|
336 | if ( i == iQP ) continue; |
---|
337 | |
---|
338 | rpcCU->getSlice()->setSliceQp( i ); |
---|
339 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
340 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
341 | m_ppcBestCU[0]->setQPSubParts( i, 0, 0 ); |
---|
342 | m_ppcTempCU[0]->setQPSubParts( i, 0, 0 ); |
---|
343 | |
---|
344 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
345 | |
---|
346 | // add dQP bits |
---|
347 | rpcCU->getSlice()->setSliceQp( iQP ); |
---|
348 | m_pcEntropyCoder->resetBits(); |
---|
349 | m_pcEntropyCoder->encodeQP( m_ppcBestCU[0], 0, false ); |
---|
350 | m_ppcBestCU[0]->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
351 | |
---|
352 | #if HHI_VSO |
---|
353 | if (m_pcRdCost->getUseLambdaScaleVSO()) |
---|
354 | { |
---|
355 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCostVSO( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
356 | } |
---|
357 | else |
---|
358 | #endif |
---|
359 | { |
---|
360 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCost( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
361 | } |
---|
362 | |
---|
363 | if ( fBestCost > m_ppcBestCU[0]->getTotalCost() ) |
---|
364 | { |
---|
365 | fBestCost = m_ppcBestCU[0]->getTotalCost(); |
---|
366 | iBestQP = i; |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | // perform best case |
---|
371 | rpcCU->getSlice()->setSliceQp( iBestQP ); |
---|
372 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
373 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
374 | m_ppcBestCU[0]->setQPSubParts( iBestQP, 0, 0 ); |
---|
375 | m_ppcTempCU[0]->setQPSubParts( iBestQP, 0, 0 ); |
---|
376 | |
---|
377 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
378 | |
---|
379 | // add dQP bits |
---|
380 | rpcCU->getSlice()->setSliceQp( iQP ); |
---|
381 | m_pcEntropyCoder->resetBits(); |
---|
382 | m_pcEntropyCoder->encodeQP( m_ppcBestCU[0], 0, false ); |
---|
383 | m_ppcBestCU[0]->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
384 | |
---|
385 | #if HHI_VSO |
---|
386 | if (m_pcRdCost->getUseLambdaScaleVSO()) |
---|
387 | { |
---|
388 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCostVSO( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
389 | } |
---|
390 | else |
---|
391 | #endif |
---|
392 | { |
---|
393 | m_ppcBestCU[0]->getTotalCost() = m_pcRdCost->calcRdCost( m_ppcBestCU[0]->getTotalBits(), m_ppcBestCU[0]->getTotalDistortion() ); |
---|
394 | } |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | #if POZNAN_EIVD & !POZNAN_EIVD_COMPRESS_ME_DATA |
---|
399 | //save motion data for every CU point |
---|
400 | xSaveEIVDData(m_ppcBestCU[0]); |
---|
401 | #endif |
---|
402 | |
---|
403 | } |
---|
404 | |
---|
405 | /** \param pcCU pointer of CU data class, bForceTerminate when set to true terminates slice (default is false). |
---|
406 | */ |
---|
407 | Void TEncCu::encodeCU ( TComDataCU* pcCU, Bool bForceTerminate ) |
---|
408 | { |
---|
409 | #if SNY_DQP |
---|
410 | if ( pcCU->getSlice()->getSPS()->getUseDQP() ) |
---|
411 | { |
---|
412 | pcCU->setdQPFlag(true); |
---|
413 | } |
---|
414 | #endif//SNY_DQP |
---|
415 | // encode CU data |
---|
416 | xEncodeCU( pcCU, 0, 0 ); |
---|
417 | |
---|
418 | #if SNY_DQP |
---|
419 | // dQP: only for LCU |
---|
420 | if ( pcCU->getSlice()->getSPS()->getUseDQP() ) |
---|
421 | { |
---|
422 | if ( pcCU->isSkipped( 0 ) && pcCU->getDepth( 0 ) == 0 ) |
---|
423 | { |
---|
424 | } |
---|
425 | else if ( pcCU->getdQPFlag())// non-skip |
---|
426 | { |
---|
427 | |
---|
428 | m_pcEntropyCoder->encodeQP( pcCU, 0 ); |
---|
429 | pcCU->setdQPFlag(false); |
---|
430 | } |
---|
431 | } |
---|
432 | #else |
---|
433 | // dQP: only for LCU |
---|
434 | if ( pcCU->getSlice()->getSPS()->getUseDQP() ) |
---|
435 | { |
---|
436 | if ( pcCU->isSkipped( 0 ) && pcCU->getDepth( 0 ) == 0 ) |
---|
437 | { |
---|
438 | } |
---|
439 | else |
---|
440 | { |
---|
441 | m_pcEntropyCoder->encodeQP( pcCU, 0 ); |
---|
442 | } |
---|
443 | } |
---|
444 | #endif//SNY_DQP |
---|
445 | |
---|
446 | //--- write terminating bit --- |
---|
447 | Bool bTerminateSlice = bForceTerminate; |
---|
448 | UInt uiCUAddr = pcCU->getAddr(); |
---|
449 | |
---|
450 | if (uiCUAddr == (pcCU->getPic()->getNumCUsInFrame()-1) ) |
---|
451 | bTerminateSlice = true; |
---|
452 | |
---|
453 | if (uiCUAddr == (pcCU->getSlice()->getSliceCurEndCUAddr()-1)) |
---|
454 | bTerminateSlice = true; |
---|
455 | |
---|
456 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
457 | |
---|
458 | // Encode slice finish |
---|
459 | if ( bTerminateSlice ) |
---|
460 | { |
---|
461 | m_pcEntropyCoder->encodeSliceFinish(); |
---|
462 | } |
---|
463 | } |
---|
464 | |
---|
465 | // ==================================================================================================================== |
---|
466 | // Protected member functions |
---|
467 | // ==================================================================================================================== |
---|
468 | |
---|
469 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
470 | { |
---|
471 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
472 | |
---|
473 | // get Original YUV data from picture |
---|
474 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
475 | #if POZNAN_CU_SKIP |
---|
476 | if (pcPic->getPicYuvAvail()) m_ppcAvailYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvAvail(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
477 | #endif |
---|
478 | #if POZNAN_CU_SYNTH |
---|
479 | if (pcPic->getPicYuvSynth()) m_ppcSynthYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvSynth(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
480 | #endif |
---|
481 | |
---|
482 | #if POZNAN_CU_SKIP |
---|
483 | Bool bWholeCUCanBeSynthesized = false; |
---|
484 | Bool bOneSubCUCanNotBeSynthesied = false; |
---|
485 | Bool bSubCUCanBeSynthesized[4]; |
---|
486 | Bool * pbSubCUCanBeSynthesized = bSubCUCanBeSynthesized; |
---|
487 | pcPic->checkSynthesisAvailability(rpcBestCU, rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, pbSubCUCanBeSynthesized); //KUBA SYNTH |
---|
488 | Int iSubCUCanNotBeSynthesized = 0; |
---|
489 | Int iSubCUCanBeSynthesizedCnt = 0; |
---|
490 | for(Int i = 0; i < 4; i++) |
---|
491 | { |
---|
492 | if (!bSubCUCanBeSynthesized[i]) |
---|
493 | { |
---|
494 | iSubCUCanNotBeSynthesized = i; |
---|
495 | } |
---|
496 | else |
---|
497 | { |
---|
498 | iSubCUCanBeSynthesizedCnt ++; |
---|
499 | } |
---|
500 | } |
---|
501 | if(iSubCUCanBeSynthesizedCnt == 4) |
---|
502 | { |
---|
503 | bWholeCUCanBeSynthesized = true; |
---|
504 | } |
---|
505 | else if(iSubCUCanBeSynthesizedCnt == 3) |
---|
506 | { |
---|
507 | bOneSubCUCanNotBeSynthesied = true; |
---|
508 | } |
---|
509 | #endif |
---|
510 | // variables for fast encoder decision |
---|
511 | TComDataCU* pcTempCU; |
---|
512 | Bool bEarlySkip = false; |
---|
513 | Bool bTrySplit = true; |
---|
514 | Double fRD_Skip = MAX_DOUBLE; |
---|
515 | |
---|
516 | static Double afCost[ MAX_CU_DEPTH ]; |
---|
517 | static Int aiNum [ MAX_CU_DEPTH ]; |
---|
518 | |
---|
519 | if ( rpcBestCU->getAddr() == 0 ) |
---|
520 | { |
---|
521 | ::memset( afCost, 0, sizeof( afCost ) ); |
---|
522 | ::memset( aiNum, 0, sizeof( aiNum ) ); |
---|
523 | } |
---|
524 | |
---|
525 | Bool bBoundary = false; |
---|
526 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
527 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
528 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
529 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
530 | |
---|
531 | #if ( HHI_INTERVIEW_SKIP) |
---|
532 | Bool bFullyRenderedSec = true ; |
---|
533 | if( m_pcEncCfg->getInterViewSkip() ) |
---|
534 | { |
---|
535 | Pel* pUsedSamples ; |
---|
536 | UInt uiStride ; |
---|
537 | pUsedSamples = pcPic->getUsedPelsMap()->getLumaAddr( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
538 | uiStride = pcPic->getUsedPelsMap()->getStride(); |
---|
539 | |
---|
540 | for ( Int y=0; y<m_ppcOrigYuv[uiDepth]->getHeight(); y++) |
---|
541 | { |
---|
542 | for ( Int x=0; x<m_ppcOrigYuv[uiDepth]->getWidth(); x++) |
---|
543 | { |
---|
544 | if( pUsedSamples[x] !=0 ) |
---|
545 | { |
---|
546 | bFullyRenderedSec = false ; |
---|
547 | break ; |
---|
548 | } |
---|
549 | } |
---|
550 | if ( !bFullyRenderedSec ) |
---|
551 | { |
---|
552 | break; |
---|
553 | } |
---|
554 | pUsedSamples += uiStride ; |
---|
555 | } |
---|
556 | } |
---|
557 | else |
---|
558 | { |
---|
559 | bFullyRenderedSec = false ; |
---|
560 | } |
---|
561 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
562 | if( bFullyRenderedSec ) |
---|
563 | { |
---|
564 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
565 | } |
---|
566 | else |
---|
567 | { |
---|
568 | m_pcRdCost->setLambdaScale( 1 ); |
---|
569 | } |
---|
570 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
571 | #endif |
---|
572 | |
---|
573 | #endif |
---|
574 | if( ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getWidth() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getHeight() ) ) |
---|
575 | { |
---|
576 | // do CU Skip |
---|
577 | #if POZNAN_CU_SKIP |
---|
578 | if(bWholeCUCanBeSynthesized) |
---|
579 | { |
---|
580 | // printf("CUSkip %d %d %d\n",rpcBestCU->getCUPelX(),rpcBestCU->getCUPelY(),rpcBestCU->getWidth()); |
---|
581 | rpcBestCU->getTotalCost() = 0; // Cost of synthesised CU is zero |
---|
582 | rpcBestCU->getTotalBits() = 0; // Cost of synthesised CU is zero |
---|
583 | rpcBestCU->getTotalDistortion() = 0; // Distortion of synthesised CU is zero |
---|
584 | rpcBestCU->setPredModeSubParts( MODE_SYNTH, 0, uiDepth ); |
---|
585 | rpcBestCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
586 | #if POZNAN_CU_SYNTH |
---|
587 | m_ppcRecoYuvBest[uiDepth]->copyFromPicYuv(pcPic->getPicYuvSynth(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU()); // First copy synthesis YUV part to CU encoder reconstruction YUV structure |
---|
588 | //m_ppcRecoYuvBest[uiDepth]->copyFromPicYuv(pcPic->getPicYuvAvail(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU()); // First copy synthesis YUV part to CU encoder reconstruction YUV structure |
---|
589 | #endif |
---|
590 | UInt uiInitTrDepth = rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1; |
---|
591 | rpcBestCU->copyToPic(uiDepth, 0, uiInitTrDepth); |
---|
592 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth ); // Next copy it to reconstruction YUV buffer in coded picture |
---|
593 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); //Not needed any more ?? |
---|
594 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
595 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
596 | |
---|
597 | #if HHI_VSO//?? |
---|
598 | if( m_pcRdCost->getUseRenModel() ) |
---|
599 | { |
---|
600 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
601 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
602 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
603 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride(); |
---|
604 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
605 | } |
---|
606 | #endif |
---|
607 | return; |
---|
608 | } |
---|
609 | else if (bOneSubCUCanNotBeSynthesied && (uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )) // If only one from subCU can not be synthesised than force NxN split but donot signal it in the stream |
---|
610 | { |
---|
611 | //printf("CUSkip - OneCanNotBe %d %d %d\n",rpcBestCU->getCUPelX(),rpcBestCU->getCUPelY(),rpcBestCU->getWidth()); |
---|
612 | // further split !!!!go to line 866!!! |
---|
613 | #if HHI_VSO |
---|
614 | // reset Model |
---|
615 | if( m_pcRdCost->getUseRenModel() ) |
---|
616 | { |
---|
617 | UInt uiWidth = m_ppcBestCU[uiDepth]->getWidth ( 0 ); |
---|
618 | UInt uiHeight = m_ppcBestCU[uiDepth]->getHeight( 0 ); |
---|
619 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
---|
620 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
621 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
622 | } |
---|
623 | #endif |
---|
624 | |
---|
625 | UChar uhNextDepth = uiDepth + 1; |
---|
626 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
627 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
628 | |
---|
629 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) //UInt uiPartUnitIdx = iSubCUNotSynthesied; |
---|
630 | { |
---|
631 | pcSubBestPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
632 | pcSubTempPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
633 | // pcSubBestPartCU->setLastCodedQP( rpcBestCU->getLastCodedQP() ); |
---|
634 | // pcSubTempPartCU->setLastCodedQP( rpcBestCU->getLastCodedQP() ); |
---|
635 | |
---|
636 | if( ( pcSubBestPartCU->getCUPelX() < pcSubBestPartCU->getSlice()->getSPS()->getWidth() ) && ( pcSubBestPartCU->getCUPelY() < pcSubBestPartCU->getSlice()->getSPS()->getHeight() ) ) |
---|
637 | { |
---|
638 | if( m_bUseSBACRD ) |
---|
639 | { |
---|
640 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
641 | { |
---|
642 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
643 | } |
---|
644 | else |
---|
645 | { |
---|
646 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
647 | } |
---|
648 | } |
---|
649 | |
---|
650 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); //Compress SubCU's |
---|
651 | |
---|
652 | #if HHI_VSO |
---|
653 | if( m_pcRdCost->getUseRenModel() ) |
---|
654 | { |
---|
655 | UInt uiWidth = pcSubBestPartCU->getWidth ( 0 ); |
---|
656 | UInt uiHeight = pcSubBestPartCU->getHeight( 0 ); |
---|
657 | Pel* piSrc = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getLumaAddr( 0 ); |
---|
658 | UInt uiSrcStride = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getStride(); |
---|
659 | m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
660 | } |
---|
661 | #endif |
---|
662 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
663 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
664 | } |
---|
665 | } |
---|
666 | |
---|
667 | if( !bBoundary ) |
---|
668 | { |
---|
669 | m_pcEntropyCoder->resetBits(); |
---|
670 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
671 | |
---|
672 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
673 | } |
---|
674 | |
---|
675 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
676 | if( bFullyRenderedSec ) |
---|
677 | { |
---|
678 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
679 | } |
---|
680 | else |
---|
681 | { |
---|
682 | m_pcRdCost->setLambdaScale( 1 ); |
---|
683 | } |
---|
684 | #endif |
---|
685 | #if HHI_VSO |
---|
686 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
687 | { |
---|
688 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
689 | } |
---|
690 | else |
---|
691 | #endif |
---|
692 | { |
---|
693 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
694 | } |
---|
695 | |
---|
696 | if( m_bUseSBACRD ) |
---|
697 | { |
---|
698 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
699 | } |
---|
700 | //Copy Tmp to Best |
---|
701 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); //Roznica z naszym koder // RD compare current larger prediction |
---|
702 | |
---|
703 | #if HHI_VSO |
---|
704 | if( m_pcRdCost->getUseRenModel() ) |
---|
705 | { |
---|
706 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
707 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
708 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
709 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride(); |
---|
710 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
711 | } |
---|
712 | #endif |
---|
713 | //Copy result to pic |
---|
714 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
715 | |
---|
716 | if( bBoundary ) |
---|
717 | return; |
---|
718 | |
---|
719 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth ); // Copy Yuv data to picture Yuv |
---|
720 | |
---|
721 | // Assert if Best prediction mode is NONE |
---|
722 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
723 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); //Not needed any more? |
---|
724 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
725 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
726 | return; |
---|
727 | } |
---|
728 | #endif |
---|
729 | |
---|
730 | // do inter modes |
---|
731 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
732 | { |
---|
733 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
734 | // check availability of residual prediction |
---|
735 | Bool bResPredAvailable = false; |
---|
736 | Bool bResPredAllowed = (!rpcBestCU->getSlice()->getSPS()->isDepth () ); |
---|
737 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId () ); |
---|
738 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
---|
739 | if( bResPredAllowed ) |
---|
740 | { |
---|
741 | bResPredAvailable = rpcBestCU->getResidualSamples( 0, m_ppcResPredTmp[uiDepth] ); |
---|
742 | } |
---|
743 | |
---|
744 | for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ ) |
---|
745 | { |
---|
746 | Bool bResPredFlag = ( uiResPrdId > 0 ); |
---|
747 | #endif |
---|
748 | |
---|
749 | // SKIP |
---|
750 | pcTempCU = rpcTempCU; |
---|
751 | |
---|
752 | if( pcPic->getSlice(0)->getSPS()->getUseMRG() ) |
---|
753 | { |
---|
754 | #if !HHI_MRG_SKIP |
---|
755 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
756 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
757 | #endif |
---|
758 | xCheckRDCostAMVPSkip ( rpcBestCU, rpcTempCU ); rpcTempCU->initEstData(); |
---|
759 | #endif |
---|
760 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
761 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
762 | #endif |
---|
763 | #if HHI_INTERVIEW_SKIP |
---|
764 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
765 | #else |
---|
766 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU ); rpcTempCU->initEstData(); |
---|
767 | #endif |
---|
768 | } |
---|
769 | else |
---|
770 | { |
---|
771 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
772 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
773 | #endif |
---|
774 | xCheckRDCostAMVPSkip ( rpcBestCU, rpcTempCU ); rpcTempCU->initEstData(); |
---|
775 | } |
---|
776 | |
---|
777 | // fast encoder decision for early skip |
---|
778 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
779 | { |
---|
780 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
781 | if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] ) |
---|
782 | { |
---|
783 | bEarlySkip = true; |
---|
784 | bTrySplit = false; |
---|
785 | } |
---|
786 | } |
---|
787 | |
---|
788 | // 2Nx2N, NxN |
---|
789 | if ( !bEarlySkip ) |
---|
790 | { |
---|
791 | #if HHI_DISABLE_INTER_NxN_SPLIT |
---|
792 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
793 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
794 | #endif |
---|
795 | #if HHI_INTERVIEW_SKIP |
---|
796 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
797 | #else |
---|
798 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData(); |
---|
799 | #endif |
---|
800 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
801 | { |
---|
802 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
803 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
804 | #endif |
---|
805 | #if HHI_INTERVIEW_SKIP |
---|
806 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
807 | #else |
---|
808 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); rpcTempCU->initEstData(); |
---|
809 | #endif |
---|
810 | } |
---|
811 | #else |
---|
812 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
813 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
814 | #endif |
---|
815 | #if HHI_INTERVIEW_SKIP |
---|
816 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
817 | #else |
---|
818 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData(); |
---|
819 | #endif |
---|
820 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
821 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
822 | #endif |
---|
823 | #if HHI_INTERVIEW_SKIP |
---|
824 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
825 | #else |
---|
826 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); rpcTempCU->initEstData(); |
---|
827 | #endif |
---|
828 | #endif |
---|
829 | } |
---|
830 | |
---|
831 | #if HHI_RMP_SWITCH |
---|
832 | if( pcPic->getSlice(0)->getSPS()->getUseRMP() ) |
---|
833 | #endif |
---|
834 | { // 2NxN, Nx2N |
---|
835 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
836 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
837 | #endif |
---|
838 | #if HHI_INTERVIEW_SKIP |
---|
839 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
840 | #else |
---|
841 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); rpcTempCU->initEstData(); |
---|
842 | #endif |
---|
843 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
844 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
---|
845 | #endif |
---|
846 | #if HHI_INTERVIEW_SKIP |
---|
847 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN, bFullyRenderedSec ); rpcTempCU->initEstData(); |
---|
848 | #else |
---|
849 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); rpcTempCU->initEstData(); |
---|
850 | #endif |
---|
851 | } |
---|
852 | |
---|
853 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
854 | } // uiResPrdId |
---|
855 | #endif |
---|
856 | } |
---|
857 | |
---|
858 | // do normal intra modes |
---|
859 | if ( !bEarlySkip ) |
---|
860 | { |
---|
861 | // speedup for inter frames |
---|
862 | #if HHI_INTERVIEW_SKIP |
---|
863 | if( ( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
864 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
865 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
866 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) && !bFullyRenderedSec ) // avoid very complex intra if it is unlikely |
---|
867 | #else |
---|
868 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
869 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
870 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
871 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely |
---|
872 | #endif |
---|
873 | { |
---|
874 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData(); |
---|
875 | #if MTK_DISABLE_INTRA_NxN_SPLIT |
---|
876 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
877 | #endif |
---|
878 | { |
---|
879 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
880 | { |
---|
881 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); rpcTempCU->initEstData(); |
---|
882 | } |
---|
883 | } |
---|
884 | } |
---|
885 | } |
---|
886 | |
---|
887 | m_pcEntropyCoder->resetBits(); |
---|
888 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
889 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
890 | |
---|
891 | #if HHI_VSO |
---|
892 | if (m_pcRdCost->getUseLambdaScaleVSO()) |
---|
893 | { |
---|
894 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
895 | } |
---|
896 | else |
---|
897 | #endif |
---|
898 | { |
---|
899 | #if HHI_INTERVIEW_SKIP |
---|
900 | if( m_pcEncCfg->getInterViewSkip()) |
---|
901 | { |
---|
902 | TComYuv* pRec = m_ppcRecoYuvBest[ uiDepth ]; |
---|
903 | TComYuv* pOrg = m_ppcOrigYuv [ uiDepth ]; |
---|
904 | Pel* pUsedY = pcPic->getUsedPelsMap()->getLumaAddr( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
905 | Pel* pUsedU = pcPic->getUsedPelsMap()->getCbAddr ( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
906 | Pel* pUsedV = pcPic->getUsedPelsMap()->getCrAddr ( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
907 | Int iUStrdY = pcPic->getUsedPelsMap()->getStride (); |
---|
908 | Int iUStrdC = pcPic->getUsedPelsMap()->getCStride (); |
---|
909 | UInt uiWdt = rpcBestCU->getWidth ( 0 ); |
---|
910 | UInt uiHgt = rpcBestCU->getHeight( 0 ); |
---|
911 | UInt uiDist = ( m_pcRdCost->getDistPart( pRec->getLumaAddr(), pRec->getStride(), pOrg->getLumaAddr(), pOrg->getStride(), pUsedY, iUStrdY, uiWdt, uiHgt ) |
---|
912 | + m_pcRdCost->getDistPart( pRec->getCbAddr(), pRec->getCStride(), pOrg->getCbAddr(), pOrg->getCStride(), pUsedU, iUStrdC, uiWdt >> 1, uiHgt >> 1 ) |
---|
913 | + m_pcRdCost->getDistPart( pRec->getCrAddr(), pRec->getCStride(), pOrg->getCrAddr(), pOrg->getCStride(), pUsedV, iUStrdC, uiWdt >> 1, uiHgt >> 1 ) ); |
---|
914 | // printf("\nD(as is) = %d, D(new) = %d, diff = %d", rpcBestCU->getTotalDistortion(), uiDist, Int(rpcBestCU->getTotalDistortion()-uiDist) ); |
---|
915 | rpcBestCU->getTotalDistortion() = uiDist; |
---|
916 | } |
---|
917 | #endif |
---|
918 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
919 | } |
---|
920 | |
---|
921 | |
---|
922 | // accumulate statistics for early skip |
---|
923 | if ( m_pcEncCfg->getUseFastEnc() ) |
---|
924 | { |
---|
925 | if ( rpcBestCU->isSkipped(0) ) |
---|
926 | { |
---|
927 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
---|
928 | afCost[ iIdx ] += rpcBestCU->getTotalCost(); |
---|
929 | aiNum [ iIdx ] ++; |
---|
930 | } |
---|
931 | } |
---|
932 | #if HHI_MPI |
---|
933 | if( rpcBestCU->getSlice()->getSPS()->getUseMVI() && rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
934 | { |
---|
935 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, false, false ); rpcTempCU->initEstData(); |
---|
936 | rpcTempCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, 0, uiDepth ); |
---|
937 | rpcTempCU->setDepthSubParts( uiDepth, 0 ); |
---|
938 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, true, false ); rpcTempCU->initEstData(); |
---|
939 | } |
---|
940 | #endif |
---|
941 | } |
---|
942 | else |
---|
943 | { |
---|
944 | bBoundary = true; |
---|
945 | } |
---|
946 | |
---|
947 | // further split |
---|
948 | if( bTrySplit && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
949 | { |
---|
950 | #if HHI_VSO |
---|
951 | // reset Model |
---|
952 | if( m_pcRdCost->getUseRenModel() ) |
---|
953 | { |
---|
954 | UInt uiWidth = m_ppcBestCU[uiDepth]->getWidth ( 0 ); |
---|
955 | UInt uiHeight = m_ppcBestCU[uiDepth]->getHeight( 0 ); |
---|
956 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
---|
957 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
958 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
959 | } |
---|
960 | #endif |
---|
961 | |
---|
962 | UChar uhNextDepth = uiDepth+1; |
---|
963 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
964 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
965 | |
---|
966 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
967 | { |
---|
968 | pcSubBestPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
969 | pcSubTempPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
970 | |
---|
971 | if( ( pcSubBestPartCU->getCUPelX() < pcSubBestPartCU->getSlice()->getSPS()->getWidth() ) && ( pcSubBestPartCU->getCUPelY() < pcSubBestPartCU->getSlice()->getSPS()->getHeight() ) ) |
---|
972 | { |
---|
973 | if( m_bUseSBACRD ) |
---|
974 | { |
---|
975 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
976 | { |
---|
977 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
978 | } |
---|
979 | else |
---|
980 | { |
---|
981 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
982 | } |
---|
983 | } |
---|
984 | |
---|
985 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
986 | |
---|
987 | #if HHI_VSO |
---|
988 | if( m_pcRdCost->getUseRenModel() ) |
---|
989 | { |
---|
990 | UInt uiWidth = pcSubBestPartCU->getWidth ( 0 ); |
---|
991 | UInt uiHeight = pcSubBestPartCU->getHeight( 0 ); |
---|
992 | Pel* piSrc = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getLumaAddr( 0 ); |
---|
993 | UInt uiSrcStride = m_ppcRecoYuvBest[pcSubBestPartCU->getDepth(0)]->getStride(); |
---|
994 | m_pcRdCost->setRenModelData( pcSubBestPartCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
995 | } |
---|
996 | #endif |
---|
997 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
998 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
999 | } |
---|
1000 | } |
---|
1001 | |
---|
1002 | if( !bBoundary ) |
---|
1003 | { |
---|
1004 | m_pcEntropyCoder->resetBits(); |
---|
1005 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
1006 | |
---|
1007 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
1008 | } |
---|
1009 | |
---|
1010 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
---|
1011 | if( bFullyRenderedSec ) |
---|
1012 | { |
---|
1013 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
---|
1014 | } |
---|
1015 | else |
---|
1016 | { |
---|
1017 | m_pcRdCost->setLambdaScale( 1 ); |
---|
1018 | } |
---|
1019 | #endif |
---|
1020 | #if HHI_VSO |
---|
1021 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1022 | { |
---|
1023 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1024 | } |
---|
1025 | else |
---|
1026 | #endif |
---|
1027 | { |
---|
1028 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1029 | } |
---|
1030 | |
---|
1031 | if( m_bUseSBACRD ) |
---|
1032 | { |
---|
1033 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1034 | } |
---|
1035 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); // RD compare current larger prediction |
---|
1036 | |
---|
1037 | #if HHI_VSO |
---|
1038 | if( m_pcRdCost->getUseRenModel() ) |
---|
1039 | { |
---|
1040 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
1041 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
1042 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
1043 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride(); |
---|
1044 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1045 | } |
---|
1046 | #endif |
---|
1047 | } // with sub partitioned prediction. |
---|
1048 | |
---|
1049 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
1050 | |
---|
1051 | if( bBoundary ) |
---|
1052 | return; |
---|
1053 | |
---|
1054 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth ); // Copy Yuv data to picture Yuv |
---|
1055 | |
---|
1056 | // Assert if Best prediction mode is NONE |
---|
1057 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
1058 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
1059 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
1060 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
1061 | } |
---|
1062 | |
---|
1063 | /** encode a CU block recursively |
---|
1064 | * \param pcCU |
---|
1065 | * \param uiAbsPartIdx |
---|
1066 | * \param uiDepth |
---|
1067 | * \returns Void |
---|
1068 | */ |
---|
1069 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1070 | { |
---|
1071 | TComPic* pcPic = pcCU->getPic(); |
---|
1072 | |
---|
1073 | #if POZNAN_CU_SKIP |
---|
1074 | if( pcCU->isCUSkiped( uiAbsPartIdx ) && uiDepth == pcCU->getDepth( uiAbsPartIdx )) //If CU Skiped no information is coded into stream |
---|
1075 | return; |
---|
1076 | #endif |
---|
1077 | |
---|
1078 | Bool bBoundary = false; |
---|
1079 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1080 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
1081 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1082 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
1083 | |
---|
1084 | #if POZNAN_CU_SKIP |
---|
1085 | Bool bDontSendSplitFlag = false; |
---|
1086 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) //check if CU has 3 synthesied subCU - no split flag is send in that case |
---|
1087 | { |
---|
1088 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
1089 | Int iCUSkipCounter = 0; |
---|
1090 | UInt uiAbsPartIdxTmp = uiAbsPartIdx; |
---|
1091 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdxTmp+=uiQNumParts ) |
---|
1092 | { |
---|
1093 | if(pcCU->isCUSkiped(uiAbsPartIdxTmp) && (pcCU->getDepth( uiAbsPartIdxTmp ) == uiDepth + 1) ) |
---|
1094 | { |
---|
1095 | iCUSkipCounter++; |
---|
1096 | } |
---|
1097 | } |
---|
1098 | if(iCUSkipCounter == 3) |
---|
1099 | { |
---|
1100 | bDontSendSplitFlag = true; |
---|
1101 | } |
---|
1102 | } |
---|
1103 | #endif |
---|
1104 | |
---|
1105 | if( ( uiRPelX < pcCU->getSlice()->getSPS()->getWidth() ) && ( uiBPelY < pcCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1106 | { |
---|
1107 | #if POZNAN_CU_SKIP |
---|
1108 | if(!bDontSendSplitFlag) |
---|
1109 | #endif |
---|
1110 | #if HHI_MPI |
---|
1111 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth < pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
1112 | #endif |
---|
1113 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1114 | } |
---|
1115 | else |
---|
1116 | { |
---|
1117 | bBoundary = true; |
---|
1118 | } |
---|
1119 | |
---|
1120 | #if HHI_MPI |
---|
1121 | if( uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
---|
1122 | { |
---|
1123 | xSaveDepthWidthHeight( pcCU ); |
---|
1124 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
---|
1125 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
---|
1126 | |
---|
1127 | if( ( uiRPelX < pcCU->getSlice()->getSPS()->getWidth() ) && ( uiBPelY < pcCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1128 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1129 | if( !pcCU->getSlice()->isIntra() ) |
---|
1130 | { |
---|
1131 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1132 | } |
---|
1133 | |
---|
1134 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1135 | { |
---|
1136 | #if HHI_MRG_SKIP |
---|
1137 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1138 | #else |
---|
1139 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) //if ( ref. frame list0 has at least 1 entry ) |
---|
1140 | { |
---|
1141 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_0); |
---|
1142 | } |
---|
1143 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) //if ( ref. frame list1 has at least 1 entry ) |
---|
1144 | { |
---|
1145 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_1); |
---|
1146 | } |
---|
1147 | #endif |
---|
1148 | xRestoreDepthWidthHeight( pcCU ); |
---|
1149 | |
---|
1150 | #if POZNAN_STAT_JK |
---|
1151 | if(m_bStatFileEnabled) xStatFile(pcCU, uiAbsPartIdx, uiDepth); |
---|
1152 | #endif |
---|
1153 | |
---|
1154 | return; |
---|
1155 | } |
---|
1156 | |
---|
1157 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1158 | |
---|
1159 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1160 | |
---|
1161 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1162 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1163 | xRestoreDepthWidthHeight( pcCU ); |
---|
1164 | } |
---|
1165 | #endif |
---|
1166 | |
---|
1167 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
1168 | { |
---|
1169 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
1170 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1171 | { |
---|
1172 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1173 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1174 | |
---|
1175 | if( ( uiLPelX < pcCU->getSlice()->getSPS()->getWidth() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1176 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
1177 | } |
---|
1178 | return; |
---|
1179 | } |
---|
1180 | |
---|
1181 | #if POZNAN_STAT_JK |
---|
1182 | if(m_bStatFileEnabled) xStatFile(pcCU, uiAbsPartIdx, uiDepth); |
---|
1183 | #endif |
---|
1184 | |
---|
1185 | #if TSB_ALF_HEADER |
---|
1186 | #else |
---|
1187 | m_pcEntropyCoder->encodeAlfCtrlFlag( pcCU, uiAbsPartIdx ); |
---|
1188 | #endif |
---|
1189 | |
---|
1190 | #if HHI_MPI |
---|
1191 | if( !pcCU->getSlice()->isIntra() && pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1192 | #else |
---|
1193 | if( !pcCU->getSlice()->isIntra() ) |
---|
1194 | #endif |
---|
1195 | { |
---|
1196 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1197 | } |
---|
1198 | |
---|
1199 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1200 | { |
---|
1201 | #if HHI_MRG_SKIP |
---|
1202 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1203 | #else |
---|
1204 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) //if ( ref. frame list0 has at least 1 entry ) |
---|
1205 | { |
---|
1206 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_0); |
---|
1207 | } |
---|
1208 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) //if ( ref. frame list1 has at least 1 entry ) |
---|
1209 | { |
---|
1210 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_1); |
---|
1211 | } |
---|
1212 | #endif |
---|
1213 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1214 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1215 | #endif |
---|
1216 | return; |
---|
1217 | } |
---|
1218 | #if HHI_MPI |
---|
1219 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1220 | { |
---|
1221 | #endif |
---|
1222 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1223 | |
---|
1224 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1225 | |
---|
1226 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1227 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1228 | |
---|
1229 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1230 | if( !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
1231 | { |
---|
1232 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1233 | } |
---|
1234 | #endif |
---|
1235 | #if HHI_MPI |
---|
1236 | } |
---|
1237 | #endif |
---|
1238 | |
---|
1239 | // Encode Coefficients |
---|
1240 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx) ); |
---|
1241 | } |
---|
1242 | |
---|
1243 | Void TEncCu::xCheckRDCostSkip( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
1244 | { |
---|
1245 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1246 | |
---|
1247 | #if HHI_VSO |
---|
1248 | if( m_pcRdCost->getUseRenModel() ) |
---|
1249 | { |
---|
1250 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1251 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1252 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1253 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1254 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1255 | } |
---|
1256 | #endif |
---|
1257 | |
---|
1258 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1259 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1260 | |
---|
1261 | m_pcPredSearch->predInterSkipSearch ( rpcTempCU, |
---|
1262 | m_ppcOrigYuv [uhDepth], |
---|
1263 | m_ppcPredYuvTemp[uhDepth], |
---|
1264 | m_ppcResiYuvTemp[uhDepth], |
---|
1265 | m_ppcRecoYuvTemp[uhDepth] ); |
---|
1266 | |
---|
1267 | m_pcPredSearch->encodeResAndCalcRdInterCU ( rpcTempCU, |
---|
1268 | m_ppcOrigYuv [uhDepth], |
---|
1269 | m_ppcPredYuvTemp[uhDepth], |
---|
1270 | m_ppcResiYuvTemp[uhDepth], |
---|
1271 | m_ppcResiYuvBest[uhDepth], |
---|
1272 | m_ppcRecoYuvTemp[uhDepth], |
---|
1273 | m_ppcResPredTmp [uhDepth], |
---|
1274 | bSkipRes ); |
---|
1275 | |
---|
1276 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1277 | } |
---|
1278 | |
---|
1279 | /** check RD costs for a CU block encoded with merge |
---|
1280 | * \param rpcBestCU |
---|
1281 | * \param rpcTempCU |
---|
1282 | * \returns Void |
---|
1283 | */ |
---|
1284 | #if HHI_INTERVIEW_SKIP |
---|
1285 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
1286 | #else |
---|
1287 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1288 | #endif |
---|
1289 | { |
---|
1290 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
1291 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
1292 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1293 | UInt uiNeighbourCandIdx[MRG_MAX_NUM_CANDS]; //MVs with same idx => same cand |
---|
1294 | #if POZNAN_EIVD_CALC_PRED_DATA |
---|
1295 | TComMP* pcMP = rpcTempCU->getSlice()->getMP(); |
---|
1296 | #endif |
---|
1297 | |
---|
1298 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1299 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1300 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1301 | #endif |
---|
1302 | |
---|
1303 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
1304 | { |
---|
1305 | uhInterDirNeighbours[ui] = 0; |
---|
1306 | uiNeighbourCandIdx[ui] = 0; |
---|
1307 | } |
---|
1308 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1309 | |
---|
1310 | #if HHI_VSO |
---|
1311 | if( m_pcRdCost->getUseRenModel() ) |
---|
1312 | { |
---|
1313 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1314 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1315 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1316 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1317 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1318 | } |
---|
1319 | #endif |
---|
1320 | |
---|
1321 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1322 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, uiNeighbourCandIdx ); |
---|
1323 | |
---|
1324 | Bool bValidCands = false; |
---|
1325 | for( UInt uiMergeCand = 0; uiMergeCand < MRG_MAX_NUM_CANDS; ++uiMergeCand ) |
---|
1326 | { |
---|
1327 | if( uiNeighbourCandIdx[uiMergeCand] == ( uiMergeCand + 1 ) ) |
---|
1328 | { |
---|
1329 | #if HHI_MRG_SKIP |
---|
1330 | TComYuv* pcPredYuvTemp = NULL; |
---|
1331 | #if HHI_INTERVIEW_SKIP |
---|
1332 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < 2; ++uiNoResidual ) |
---|
1333 | #else |
---|
1334 | for( UInt uiNoResidual = 0; uiNoResidual < 2; ++uiNoResidual ) |
---|
1335 | #endif |
---|
1336 | { |
---|
1337 | #endif |
---|
1338 | bValidCands = true; |
---|
1339 | // set MC parameters |
---|
1340 | #if HHI_MRG_SKIP |
---|
1341 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1342 | #else |
---|
1343 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1344 | #endif |
---|
1345 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1346 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1347 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1348 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1349 | for( UInt uiInner = 0; uiInner < MRG_MAX_NUM_CANDS; uiInner++ ) |
---|
1350 | { |
---|
1351 | rpcTempCU->setNeighbourCandIdxSubParts( uiInner, uiNeighbourCandIdx[uiInner], 0, 0,uhDepth ); |
---|
1352 | } |
---|
1353 | #if POZNAN_EIVD_CALC_PRED_DATA |
---|
1354 | if(uiMergeCand==POZNAN_EIVD_MRG_CAND) |
---|
1355 | { |
---|
1356 | rpcTempCU->getCUMvField2nd( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand].getMv(), cMvFieldNeighbours[0 + 2*uiMergeCand].getRefIdx(), SIZE_2Nx2N, 0, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1357 | rpcTempCU->getCUMvField2nd( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand].getMv(), cMvFieldNeighbours[1 + 2*uiMergeCand].getRefIdx(), SIZE_2Nx2N, 0, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1358 | } |
---|
1359 | else |
---|
1360 | #endif |
---|
1361 | { |
---|
1362 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand].getMv(), cMvFieldNeighbours[0 + 2*uiMergeCand].getRefIdx(), SIZE_2Nx2N, 0, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1363 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand].getMv(), cMvFieldNeighbours[1 + 2*uiMergeCand].getRefIdx(), SIZE_2Nx2N, 0, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
1364 | } |
---|
1365 | |
---|
1366 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1367 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1368 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1369 | #endif |
---|
1370 | |
---|
1371 | #if HHI_MRG_SKIP |
---|
1372 | // do MC |
---|
1373 | #if HHI_INTERVIEW_SKIP |
---|
1374 | if ( (uiNoResidual == 0) || bSkipRes ){ |
---|
1375 | #else |
---|
1376 | if ( uiNoResidual == 0 ){ |
---|
1377 | #endif |
---|
1378 | |
---|
1379 | #if POZNAN_EIVD |
---|
1380 | if(uiMergeCand==POZNAN_EIVD_MRG_CAND){ |
---|
1381 | m_pcPredSearch->motionCompensation_EIVD ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1382 | #if POZNAN_EIVD_CALC_PRED_DATA |
---|
1383 | pcMP->setEIVDPredMVField(REF_PIC_LIST_0, rpcTempCU); |
---|
1384 | pcMP->setEIVDPredMVField(REF_PIC_LIST_1, rpcTempCU); |
---|
1385 | #endif |
---|
1386 | } |
---|
1387 | else |
---|
1388 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1389 | #else |
---|
1390 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1391 | #endif |
---|
1392 | // save pred adress |
---|
1393 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
1394 | |
---|
1395 | } |
---|
1396 | else { |
---|
1397 | if ( pcPredYuvTemp != m_ppcPredYuvTemp[uhDepth]) { |
---|
1398 | //adress changes take best (old temp) |
---|
1399 | pcPredYuvTemp = m_ppcPredYuvBest[uhDepth]; |
---|
1400 | } |
---|
1401 | #if POZNAN_EIVD_CALC_PRED_DATA |
---|
1402 | if(uiMergeCand==POZNAN_EIVD_MRG_CAND) |
---|
1403 | { |
---|
1404 | //copy motion data representing CU with EIVD for uiNoResidual==0 case |
---|
1405 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->copyFrom(pcMP->getEIVDPredMVField(REF_PIC_LIST_0),rpcTempCU->getTotalNumPart(),0); |
---|
1406 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->copyFrom(pcMP->getEIVDPredMVField(REF_PIC_LIST_1),rpcTempCU->getTotalNumPart(),0); |
---|
1407 | } |
---|
1408 | #endif |
---|
1409 | } |
---|
1410 | #if HHI_VSO |
---|
1411 | if( m_pcRdCost->getUseRenModel() ) |
---|
1412 | { //Reset |
---|
1413 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1414 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1415 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1416 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1417 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1418 | } |
---|
1419 | #endif |
---|
1420 | |
---|
1421 | // estimate residual and encode everything |
---|
1422 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
1423 | m_ppcOrigYuv [uhDepth], |
---|
1424 | pcPredYuvTemp, |
---|
1425 | m_ppcResiYuvTemp[uhDepth], |
---|
1426 | m_ppcResiYuvBest[uhDepth], |
---|
1427 | m_ppcRecoYuvTemp[uhDepth], |
---|
1428 | m_ppcResPredTmp [uhDepth], |
---|
1429 | (uiNoResidual? true:false) ); |
---|
1430 | Bool bQtRootCbf = rpcTempCU->getQtRootCbf(0) == 1; |
---|
1431 | #else |
---|
1432 | #if POZNAN_EIVD |
---|
1433 | // do MC |
---|
1434 | if(uiMergeCand==POZNAN_EIVD_MRG_CAND){ |
---|
1435 | m_pcPredSearch->motionCompensation_EIVD ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1436 | #if POZNAN_EIVD_CALC_PRED_DATA |
---|
1437 | pcMP->setEIVDPredMVField(REF_PIC_LIST_0, rpcTempCU); |
---|
1438 | pcMP->setEIVDPredMVField(REF_PIC_LIST_1, rpcTempCU); |
---|
1439 | #endif |
---|
1440 | } |
---|
1441 | else |
---|
1442 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1443 | |
---|
1444 | #endif |
---|
1445 | |
---|
1446 | // estimate residual and encode everything |
---|
1447 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
1448 | m_ppcOrigYuv [uhDepth], |
---|
1449 | m_ppcPredYuvTemp[uhDepth], |
---|
1450 | m_ppcResiYuvTemp[uhDepth], |
---|
1451 | m_ppcResiYuvBest[uhDepth], |
---|
1452 | m_ppcRecoYuvTemp[uhDepth], |
---|
1453 | m_ppcResPredTmp [uhDepth], |
---|
1454 | false ); |
---|
1455 | #endif |
---|
1456 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth ); |
---|
1457 | |
---|
1458 | rpcTempCU->initEstData(); |
---|
1459 | #if HHI_MRG_SKIP |
---|
1460 | if (!bQtRootCbf) |
---|
1461 | break; |
---|
1462 | } |
---|
1463 | #endif |
---|
1464 | } |
---|
1465 | } |
---|
1466 | } |
---|
1467 | |
---|
1468 | #if HHI_INTERVIEW_SKIP |
---|
1469 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes) |
---|
1470 | #else |
---|
1471 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
1472 | #endif |
---|
1473 | { |
---|
1474 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1475 | |
---|
1476 | #if HHI_VSO |
---|
1477 | if( m_pcRdCost->getUseRenModel() ) |
---|
1478 | { |
---|
1479 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1480 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1481 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1482 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1483 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1484 | } |
---|
1485 | #endif |
---|
1486 | |
---|
1487 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
1488 | |
---|
1489 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1490 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1491 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1492 | #endif |
---|
1493 | rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); |
---|
1494 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1495 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1496 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1497 | #endif |
---|
1498 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
1499 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
1500 | |
---|
1501 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1502 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
1503 | { // subtract residual prediction from original in motion search |
---|
1504 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ), true ); |
---|
1505 | } |
---|
1506 | #endif |
---|
1507 | #if HHI_INTERVIEW_SKIP |
---|
1508 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes ); |
---|
1509 | #else |
---|
1510 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
1511 | #endif |
---|
1512 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1513 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
1514 | { // add residual prediction to original again |
---|
1515 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ) ); |
---|
1516 | } |
---|
1517 | #endif |
---|
1518 | |
---|
1519 | #if PART_MRG |
---|
1520 | if (rpcTempCU->getWidth(0) > 8 && !rpcTempCU->getMergeFlag(0) && (ePartSize != SIZE_2Nx2N && ePartSize != SIZE_NxN)) |
---|
1521 | { |
---|
1522 | return; |
---|
1523 | } |
---|
1524 | #endif |
---|
1525 | #if HHI_INTERVIEW_SKIP |
---|
1526 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth],bSkipRes ); |
---|
1527 | #else |
---|
1528 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth], false ); |
---|
1529 | #endif |
---|
1530 | |
---|
1531 | #if HHI_VSO |
---|
1532 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
1533 | { |
---|
1534 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1535 | } |
---|
1536 | else |
---|
1537 | #endif |
---|
1538 | { |
---|
1539 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1540 | } |
---|
1541 | |
---|
1542 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1543 | } |
---|
1544 | |
---|
1545 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
1546 | { |
---|
1547 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
1548 | |
---|
1549 | #if HHI_VSO |
---|
1550 | if( m_pcRdCost->getUseRenModel() ) |
---|
1551 | { |
---|
1552 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1553 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1554 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( ); |
---|
1555 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
1556 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1557 | } |
---|
1558 | #endif |
---|
1559 | |
---|
1560 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
1561 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
1562 | |
---|
1563 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
1564 | Dist uiPreCalcDistC = 0; |
---|
1565 | if( !bSeparateLumaChroma ) |
---|
1566 | { |
---|
1567 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
1568 | } |
---|
1569 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
1570 | |
---|
1571 | #if LM_CHROMA |
---|
1572 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
1573 | #endif |
---|
1574 | |
---|
1575 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
1576 | |
---|
1577 | m_pcEntropyCoder->resetBits(); |
---|
1578 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
1579 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
1580 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
1581 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
1582 | |
---|
1583 | // Encode Coefficients |
---|
1584 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0) ); |
---|
1585 | |
---|
1586 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1587 | |
---|
1588 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1589 | #if HHI_VSO |
---|
1590 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1591 | { |
---|
1592 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1593 | } |
---|
1594 | else |
---|
1595 | #endif |
---|
1596 | { |
---|
1597 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1598 | } |
---|
1599 | |
---|
1600 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
1601 | } |
---|
1602 | |
---|
1603 | // check whether current try is the best |
---|
1604 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhDepth ) |
---|
1605 | { |
---|
1606 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
1607 | { |
---|
1608 | TComYuv* pcYuv; |
---|
1609 | |
---|
1610 | // Change Information data |
---|
1611 | TComDataCU* pcCU = rpcBestCU; |
---|
1612 | rpcBestCU = rpcTempCU; |
---|
1613 | rpcTempCU = pcCU; |
---|
1614 | |
---|
1615 | // Change Prediction data |
---|
1616 | pcYuv = m_ppcPredYuvBest[uhDepth]; |
---|
1617 | m_ppcPredYuvBest[uhDepth] = m_ppcPredYuvTemp[uhDepth]; |
---|
1618 | m_ppcPredYuvTemp[uhDepth] = pcYuv; |
---|
1619 | |
---|
1620 | // Change Reconstruction data |
---|
1621 | pcYuv = m_ppcRecoYuvBest[uhDepth]; |
---|
1622 | m_ppcRecoYuvBest[uhDepth] = m_ppcRecoYuvTemp[uhDepth]; |
---|
1623 | m_ppcRecoYuvTemp[uhDepth] = pcYuv; |
---|
1624 | |
---|
1625 | pcYuv = NULL; |
---|
1626 | pcCU = NULL; |
---|
1627 | |
---|
1628 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
1629 | m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_NEXT_BEST]); |
---|
1630 | } |
---|
1631 | } |
---|
1632 | |
---|
1633 | Void TEncCu::xCheckRDCostAMVPSkip ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1634 | { |
---|
1635 | UChar uhDepth = rpcTempCU->getDepth(0); |
---|
1636 | |
---|
1637 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1638 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1639 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1640 | #endif |
---|
1641 | |
---|
1642 | AMVPInfo cAMVPInfo0; |
---|
1643 | cAMVPInfo0.iN = 0; |
---|
1644 | |
---|
1645 | AMVPInfo cAMVPInfo1; |
---|
1646 | cAMVPInfo1.iN = 0; |
---|
1647 | |
---|
1648 | if (rpcTempCU->getAMVPMode(0) == AM_EXPL) |
---|
1649 | { |
---|
1650 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1651 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1652 | |
---|
1653 | if ( rpcTempCU->getSlice()->isInterP() && rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
1654 | { |
---|
1655 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_0, 0, &cAMVPInfo0); |
---|
1656 | } |
---|
1657 | else if ( rpcTempCU->getSlice()->isInterB() && |
---|
1658 | rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 && |
---|
1659 | rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
1660 | { |
---|
1661 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_0, 0, &cAMVPInfo0); |
---|
1662 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_1, 0, &cAMVPInfo1); |
---|
1663 | } |
---|
1664 | else |
---|
1665 | { |
---|
1666 | assert( 0 ); |
---|
1667 | } |
---|
1668 | } |
---|
1669 | |
---|
1670 | Int iMVP0, iMVP1; |
---|
1671 | |
---|
1672 | for (iMVP0 = (cAMVPInfo0.iN > 0? 0:-1); iMVP0 < cAMVPInfo0.iN; iMVP0++) |
---|
1673 | { |
---|
1674 | for (iMVP1 = (cAMVPInfo1.iN > 0? 0:-1); iMVP1 < cAMVPInfo1.iN; iMVP1++) |
---|
1675 | { |
---|
1676 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1677 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1678 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1679 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1680 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1681 | #endif |
---|
1682 | |
---|
1683 | if (rpcTempCU->getSlice()->isInterB()) |
---|
1684 | rpcTempCU->setInterDirSubParts( 3, 0, 0, uhDepth ); |
---|
1685 | |
---|
1686 | rpcTempCU->setMVPIdxSubParts( iMVP0, REF_PIC_LIST_0, 0, 0, uhDepth ); |
---|
1687 | rpcTempCU->setMVPIdxSubParts( iMVP1, REF_PIC_LIST_1, 0, 0, uhDepth ); |
---|
1688 | |
---|
1689 | rpcTempCU->setMVPNumSubParts( cAMVPInfo0.iN, REF_PIC_LIST_0, 0, 0, uhDepth ); |
---|
1690 | rpcTempCU->setMVPNumSubParts( cAMVPInfo1.iN, REF_PIC_LIST_1, 0, 0, uhDepth ); |
---|
1691 | |
---|
1692 | xCopyAMVPInfo(&cAMVPInfo0, rpcTempCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo()); |
---|
1693 | xCopyAMVPInfo(&cAMVPInfo1, rpcTempCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); |
---|
1694 | xCheckRDCostSkip ( rpcBestCU, rpcTempCU, true ); rpcTempCU->initEstData(); |
---|
1695 | } |
---|
1696 | } |
---|
1697 | } |
---|
1698 | |
---|
1699 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
1700 | { |
---|
1701 | pDst->iN = pSrc->iN; |
---|
1702 | for (Int i = 0; i < pSrc->iN; i++) |
---|
1703 | { |
---|
1704 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
1705 | } |
---|
1706 | } |
---|
1707 | |
---|
1708 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsZorderIdx, UInt uiDepth) |
---|
1709 | { |
---|
1710 | m_ppcRecoYuvBest[uiDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsZorderIdx ); |
---|
1711 | } |
---|
1712 | |
---|
1713 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
1714 | { |
---|
1715 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
1716 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
1717 | } |
---|
1718 | |
---|
1719 | #if HHI_MPI |
---|
1720 | Void TEncCu::xCheckRDCostMvInheritance( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhTextureModeDepth, Bool bSkipResidual, Bool bRecursiveCall ) |
---|
1721 | { |
---|
1722 | assert( rpcTempCU->getSlice()->getSPS()->isDepth() ); |
---|
1723 | TComDataCU *pcTextureCU = rpcTempCU->getSlice()->getTexturePic()->getCU( rpcTempCU->getAddr() ); |
---|
1724 | |
---|
1725 | const UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1726 | assert( bRecursiveCall == ( uhDepth != uhTextureModeDepth ) ); |
---|
1727 | |
---|
1728 | if( uhDepth == uhTextureModeDepth ) |
---|
1729 | { |
---|
1730 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
1731 | { |
---|
1732 | if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) |
---|
1733 | #if POZNAN_CU_SKIP |
---|
1734 | || pcTextureCU->isCUSkiped( rpcTempCU->getZorderIdxInCU() + ui ) |
---|
1735 | #endif |
---|
1736 | ) |
---|
1737 | { |
---|
1738 | return; |
---|
1739 | } |
---|
1740 | } |
---|
1741 | } |
---|
1742 | |
---|
1743 | #if HHI_VSO |
---|
1744 | if( m_pcRdCost->getUseRenModel() && !bRecursiveCall) |
---|
1745 | { |
---|
1746 | UInt uiWidth = m_ppcTempCU [uhDepth]->getWidth ( 0 ); |
---|
1747 | UInt uiHeight = m_ppcTempCU [uhDepth]->getHeight( 0 ); |
---|
1748 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( 0 ); |
---|
1749 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1750 | m_pcRdCost->setRenModelData( m_ppcTempCU[uhDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1751 | } |
---|
1752 | #endif |
---|
1753 | |
---|
1754 | Bool bSplit = uhDepth < pcTextureCU->getDepth( rpcTempCU->getZorderIdxInCU() ); |
---|
1755 | if( bSplit ) |
---|
1756 | { |
---|
1757 | const UChar uhNextDepth = uhDepth+1; |
---|
1758 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
1759 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
1760 | |
---|
1761 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
1762 | { |
---|
1763 | pcSubBestPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
1764 | pcSubTempPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
1765 | |
---|
1766 | if( ( pcSubBestPartCU->getCUPelX() < pcSubBestPartCU->getSlice()->getSPS()->getWidth() ) && ( pcSubBestPartCU->getCUPelY() < pcSubBestPartCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1767 | { |
---|
1768 | if( m_bUseSBACRD ) |
---|
1769 | { |
---|
1770 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
1771 | { |
---|
1772 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhDepth][CI_CURR_BEST]); |
---|
1773 | } |
---|
1774 | else |
---|
1775 | { |
---|
1776 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
1777 | } |
---|
1778 | } |
---|
1779 | |
---|
1780 | xCheckRDCostMvInheritance( pcSubBestPartCU, pcSubTempPartCU, uhTextureModeDepth, bSkipResidual, true ); |
---|
1781 | |
---|
1782 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
1783 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
1784 | } |
---|
1785 | } |
---|
1786 | |
---|
1787 | if( uhDepth == uhTextureModeDepth ) |
---|
1788 | { |
---|
1789 | xAddMVISignallingBits( rpcTempCU ); |
---|
1790 | } |
---|
1791 | |
---|
1792 | if( m_bUseSBACRD ) |
---|
1793 | { |
---|
1794 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]); |
---|
1795 | } |
---|
1796 | } |
---|
1797 | else |
---|
1798 | { |
---|
1799 | rpcTempCU->setTextureModeDepthSubParts( uhTextureModeDepth, 0, uhDepth ); |
---|
1800 | rpcTempCU->copyTextureMotionDataFrom( pcTextureCU, uhDepth, rpcTempCU->getZorderIdxInCU() ); |
---|
1801 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
---|
1802 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
1803 | { |
---|
1804 | assert( rpcTempCU->getInterDir( ui ) != 0 ); |
---|
1805 | assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE ); |
---|
1806 | } |
---|
1807 | rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth ); |
---|
1808 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1809 | |
---|
1810 | // get Original YUV data from picture |
---|
1811 | m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
1812 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth], bSkipResidual ); |
---|
1813 | |
---|
1814 | if( uhDepth == uhTextureModeDepth ) |
---|
1815 | { |
---|
1816 | xAddMVISignallingBits( rpcTempCU ); |
---|
1817 | } |
---|
1818 | } |
---|
1819 | |
---|
1820 | #if HHI_VSO |
---|
1821 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
1822 | { |
---|
1823 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1824 | } |
---|
1825 | else |
---|
1826 | #endif |
---|
1827 | { |
---|
1828 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1829 | } |
---|
1830 | |
---|
1831 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1832 | |
---|
1833 | #if HHI_VSO |
---|
1834 | if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() ) |
---|
1835 | { |
---|
1836 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
1837 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
1838 | Pel* piSrc = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 ); |
---|
1839 | UInt uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride(); |
---|
1840 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1841 | } |
---|
1842 | #endif |
---|
1843 | } |
---|
1844 | |
---|
1845 | Void TEncCu::xAddMVISignallingBits( TComDataCU* pcCU ) |
---|
1846 | { |
---|
1847 | const UChar uhDepth = pcCU->getTextureModeDepth( 0 ); |
---|
1848 | m_pcEntropyCoder->resetBits(); |
---|
1849 | xSaveDepthWidthHeight( pcCU ); |
---|
1850 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uhDepth, g_uiMaxCUHeight>>uhDepth, 0, uhDepth ); |
---|
1851 | pcCU->setDepthSubParts( uhDepth, 0 ); |
---|
1852 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1853 | pcCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); |
---|
1854 | pcCU->setMergeIndexSubParts( 0, 0, 0, uhDepth ); |
---|
1855 | |
---|
1856 | { |
---|
1857 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
1858 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1859 | UInt uiNeighbourCandIdx[MRG_MAX_NUM_CANDS]; //MVs with same idx => same cand |
---|
1860 | |
---|
1861 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
1862 | { |
---|
1863 | uhInterDirNeighbours[ui] = 0; |
---|
1864 | uiNeighbourCandIdx[ui] = 0; |
---|
1865 | } |
---|
1866 | pcCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, uiNeighbourCandIdx ); |
---|
1867 | for( UInt uiMergeCand = 0; uiMergeCand < MRG_MAX_NUM_CANDS; uiMergeCand++ ) |
---|
1868 | { |
---|
1869 | pcCU->setNeighbourCandIdxSubParts( uiMergeCand, uiNeighbourCandIdx[uiMergeCand], 0, 0,uhDepth ); |
---|
1870 | } |
---|
1871 | } |
---|
1872 | |
---|
1873 | // check for skip mode |
---|
1874 | { |
---|
1875 | Bool bAllZero = true; |
---|
1876 | for( UInt ui = 0; ui < pcCU->getTotalNumPart(); ui++ ) |
---|
1877 | { |
---|
1878 | if( pcCU->getCbf( ui, TEXT_LUMA ) || pcCU->getCbf( ui, TEXT_CHROMA_U ) || pcCU->getCbf( ui, TEXT_CHROMA_V ) ) |
---|
1879 | { |
---|
1880 | bAllZero = false; |
---|
1881 | break; |
---|
1882 | } |
---|
1883 | } |
---|
1884 | if( bAllZero ) |
---|
1885 | pcCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1886 | } |
---|
1887 | |
---|
1888 | |
---|
1889 | m_pcEntropyCoder->encodeSplitFlag( pcCU, 0, uhDepth, true ); |
---|
1890 | m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true ); |
---|
1891 | |
---|
1892 | if( pcCU->isSkipped( 0 ) ) |
---|
1893 | { |
---|
1894 | #if HHI_MRG_SKIP |
---|
1895 | m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true ); |
---|
1896 | #else |
---|
1897 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) //if ( ref. frame list0 has at least 1 entry ) |
---|
1898 | { |
---|
1899 | m_pcEntropyCoder->encodeMVPIdx( pcCU, 0, REF_PIC_LIST_0, true ); |
---|
1900 | } |
---|
1901 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) //if ( ref. frame list1 has at least 1 entry ) |
---|
1902 | { |
---|
1903 | m_pcEntropyCoder->encodeMVPIdx( pcCU, 0, REF_PIC_LIST_1, true ); |
---|
1904 | } |
---|
1905 | #endif |
---|
1906 | } |
---|
1907 | else |
---|
1908 | { |
---|
1909 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
---|
1910 | m_pcEntropyCoder->encodePartSize( pcCU, 0, uhDepth, true ); |
---|
1911 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1912 | m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); |
---|
1913 | } |
---|
1914 | xRestoreDepthWidthHeight( pcCU ); |
---|
1915 | |
---|
1916 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1917 | } |
---|
1918 | |
---|
1919 | Void TEncCu::xSaveDepthWidthHeight( TComDataCU* pcCU ) |
---|
1920 | { |
---|
1921 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
1922 | memcpy( m_puhDepthSaved, pcCU->getDepth(), iSizeInUchar ); |
---|
1923 | memcpy( m_puhWidthSaved, pcCU->getWidth(), iSizeInUchar ); |
---|
1924 | memcpy( m_puhHeightSaved, pcCU->getHeight(), iSizeInUchar ); |
---|
1925 | } |
---|
1926 | |
---|
1927 | Void TEncCu::xRestoreDepthWidthHeight( TComDataCU* pcCU ) |
---|
1928 | { |
---|
1929 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
1930 | memcpy( pcCU->getDepth(), m_puhDepthSaved, iSizeInUchar ); |
---|
1931 | memcpy( pcCU->getWidth(), m_puhWidthSaved, iSizeInUchar ); |
---|
1932 | memcpy( pcCU->getHeight(), m_puhHeightSaved, iSizeInUchar ); |
---|
1933 | } |
---|
1934 | #endif |
---|