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_AVAIL_MAP |
---|
70 | m_ppcAvailYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
71 | #endif |
---|
72 | #if POZNAN_SYNTH_VIEW |
---|
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_AVAIL_MAP |
---|
103 | m_ppcAvailYuv [i] = new TComYuv; m_ppcAvailYuv [i]->create(uiWidth, uiHeight); |
---|
104 | #endif |
---|
105 | #if POZNAN_SYNTH_VIEW |
---|
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_AVAIL_MAP |
---|
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_SYNTH_VIEW |
---|
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_AVAIL_MAP |
---|
233 | if(m_ppcAvailYuv) |
---|
234 | { |
---|
235 | delete [] m_ppcAvailYuv; |
---|
236 | m_ppcAvailYuv = NULL; |
---|
237 | } |
---|
238 | #endif |
---|
239 | #if POZNAN_SYNTH_VIEW |
---|
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_DBMP & !POZNAN_DBMP_COMPRESS_ME_DATA |
---|
399 | //save motion data for every CU point |
---|
400 | xSaveDBMPData(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_AVAIL_MAP |
---|
476 | if (pcPic->getPicYuvAvail()) m_ppcAvailYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvAvail(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
477 | #endif |
---|
478 | #if POZNAN_SYNTH_VIEW |
---|
479 | if (pcPic->getPicYuvSynth()) m_ppcSynthYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvSynth(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
480 | #endif |
---|
481 | |
---|
482 | #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU |
---|
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_ENCODE_ONLY_DISOCCLUDED_CU |
---|
578 | if(bWholeCUCanBeSynthesized) |
---|
579 | { |
---|
580 | rpcBestCU->getTotalCost() = 0; // Cost of synthesised CU is zero |
---|
581 | rpcBestCU->getTotalBits() = 0; // Cost of synthesised CU is zero |
---|
582 | rpcBestCU->getTotalDistortion() = 0; // Distortion of synthesised CU is zero |
---|
583 | rpcBestCU->setPredModeSubParts( MODE_SYNTH, 0, uiDepth ); |
---|
584 | rpcBestCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
585 | #if POZNAN_FILL_OCCLUDED_CU_WITH_SYNTHESIS |
---|
586 | m_ppcRecoYuvBest[uiDepth]->copyFromPicYuv(pcPic->getPicYuvSynth(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU()); // First copy synthesis YUV part to CU encoder reconstruction YUV structure |
---|
587 | #else |
---|
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_ENCODE_ONLY_DISOCCLUDED_CU |
---|
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_ENCODE_ONLY_DISOCCLUDED_CU |
---|
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_ENCODE_ONLY_DISOCCLUDED_CU |
---|
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 | return; |
---|
1150 | } |
---|
1151 | |
---|
1152 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1153 | |
---|
1154 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1155 | |
---|
1156 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1157 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1158 | xRestoreDepthWidthHeight( pcCU ); |
---|
1159 | } |
---|
1160 | #endif |
---|
1161 | |
---|
1162 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
1163 | { |
---|
1164 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
1165 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
1166 | { |
---|
1167 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1168 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
1169 | |
---|
1170 | if( ( uiLPelX < pcCU->getSlice()->getSPS()->getWidth() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1171 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
1172 | } |
---|
1173 | return; |
---|
1174 | } |
---|
1175 | |
---|
1176 | #if TSB_ALF_HEADER |
---|
1177 | #else |
---|
1178 | m_pcEntropyCoder->encodeAlfCtrlFlag( pcCU, uiAbsPartIdx ); |
---|
1179 | #endif |
---|
1180 | |
---|
1181 | #if HHI_MPI |
---|
1182 | if( !pcCU->getSlice()->isIntra() && pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1183 | #else |
---|
1184 | if( !pcCU->getSlice()->isIntra() ) |
---|
1185 | #endif |
---|
1186 | { |
---|
1187 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
1188 | } |
---|
1189 | |
---|
1190 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
1191 | { |
---|
1192 | #if HHI_MRG_SKIP |
---|
1193 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
---|
1194 | #else |
---|
1195 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) //if ( ref. frame list0 has at least 1 entry ) |
---|
1196 | { |
---|
1197 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_0); |
---|
1198 | } |
---|
1199 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) //if ( ref. frame list1 has at least 1 entry ) |
---|
1200 | { |
---|
1201 | m_pcEntropyCoder->encodeMVPIdx( pcCU, uiAbsPartIdx, REF_PIC_LIST_1); |
---|
1202 | } |
---|
1203 | #endif |
---|
1204 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1205 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1206 | #endif |
---|
1207 | return; |
---|
1208 | } |
---|
1209 | #if HHI_MPI |
---|
1210 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
---|
1211 | { |
---|
1212 | #endif |
---|
1213 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
1214 | |
---|
1215 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
1216 | |
---|
1217 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1218 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
1219 | |
---|
1220 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1221 | if( !pcCU->isIntra( uiAbsPartIdx ) ) |
---|
1222 | { |
---|
1223 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
---|
1224 | } |
---|
1225 | #endif |
---|
1226 | #if HHI_MPI |
---|
1227 | } |
---|
1228 | #endif |
---|
1229 | |
---|
1230 | // Encode Coefficients |
---|
1231 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx) ); |
---|
1232 | } |
---|
1233 | |
---|
1234 | Void TEncCu::xCheckRDCostSkip( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
1235 | { |
---|
1236 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1237 | |
---|
1238 | #if HHI_VSO |
---|
1239 | if( m_pcRdCost->getUseRenModel() ) |
---|
1240 | { |
---|
1241 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1242 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1243 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1244 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1245 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1246 | } |
---|
1247 | #endif |
---|
1248 | |
---|
1249 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1250 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1251 | |
---|
1252 | m_pcPredSearch->predInterSkipSearch ( rpcTempCU, |
---|
1253 | m_ppcOrigYuv [uhDepth], |
---|
1254 | m_ppcPredYuvTemp[uhDepth], |
---|
1255 | m_ppcResiYuvTemp[uhDepth], |
---|
1256 | m_ppcRecoYuvTemp[uhDepth] ); |
---|
1257 | |
---|
1258 | m_pcPredSearch->encodeResAndCalcRdInterCU ( rpcTempCU, |
---|
1259 | m_ppcOrigYuv [uhDepth], |
---|
1260 | m_ppcPredYuvTemp[uhDepth], |
---|
1261 | m_ppcResiYuvTemp[uhDepth], |
---|
1262 | m_ppcResiYuvBest[uhDepth], |
---|
1263 | m_ppcRecoYuvTemp[uhDepth], |
---|
1264 | m_ppcResPredTmp [uhDepth], |
---|
1265 | bSkipRes ); |
---|
1266 | |
---|
1267 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1268 | } |
---|
1269 | |
---|
1270 | /** check RD costs for a CU block encoded with merge |
---|
1271 | * \param rpcBestCU |
---|
1272 | * \param rpcTempCU |
---|
1273 | * \returns Void |
---|
1274 | */ |
---|
1275 | #if HHI_INTERVIEW_SKIP |
---|
1276 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
---|
1277 | #else |
---|
1278 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1279 | #endif |
---|
1280 | { |
---|
1281 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
1282 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
1283 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1284 | UInt uiNeighbourCandIdx[MRG_MAX_NUM_CANDS]; //MVs with same idx => same cand |
---|
1285 | #if POZNAN_DBMP_CALC_PRED_DATA |
---|
1286 | TComMP* pcMP = rpcTempCU->getSlice()->getMP(); |
---|
1287 | #endif |
---|
1288 | |
---|
1289 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1290 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1291 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1292 | #endif |
---|
1293 | |
---|
1294 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
1295 | { |
---|
1296 | uhInterDirNeighbours[ui] = 0; |
---|
1297 | uiNeighbourCandIdx[ui] = 0; |
---|
1298 | } |
---|
1299 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1300 | |
---|
1301 | #if HHI_VSO |
---|
1302 | if( m_pcRdCost->getUseRenModel() ) |
---|
1303 | { |
---|
1304 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1305 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1306 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1307 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1308 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1309 | } |
---|
1310 | #endif |
---|
1311 | |
---|
1312 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1313 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, uiNeighbourCandIdx ); |
---|
1314 | |
---|
1315 | Bool bValidCands = false; |
---|
1316 | for( UInt uiMergeCand = 0; uiMergeCand < MRG_MAX_NUM_CANDS; ++uiMergeCand ) |
---|
1317 | { |
---|
1318 | if( uiNeighbourCandIdx[uiMergeCand] == ( uiMergeCand + 1 ) ) |
---|
1319 | { |
---|
1320 | #if HHI_MRG_SKIP |
---|
1321 | TComYuv* pcPredYuvTemp = NULL; |
---|
1322 | #if HHI_INTERVIEW_SKIP |
---|
1323 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < 2; ++uiNoResidual ) |
---|
1324 | #else |
---|
1325 | for( UInt uiNoResidual = 0; uiNoResidual < 2; ++uiNoResidual ) |
---|
1326 | #endif |
---|
1327 | { |
---|
1328 | #endif |
---|
1329 | bValidCands = true; |
---|
1330 | // set MC parameters |
---|
1331 | #if HHI_MRG_SKIP |
---|
1332 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1333 | #else |
---|
1334 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1335 | #endif |
---|
1336 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1337 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1338 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1339 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
1340 | for( UInt uiInner = 0; uiInner < MRG_MAX_NUM_CANDS; uiInner++ ) |
---|
1341 | { |
---|
1342 | rpcTempCU->setNeighbourCandIdxSubParts( uiInner, uiNeighbourCandIdx[uiInner], 0, 0,uhDepth ); |
---|
1343 | } |
---|
1344 | #if POZNAN_DBMP_CALC_PRED_DATA |
---|
1345 | if(uiMergeCand==POZNAN_DBMP_MRG_CAND) |
---|
1346 | { |
---|
1347 | 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 |
---|
1348 | 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 |
---|
1349 | } |
---|
1350 | else |
---|
1351 | #endif |
---|
1352 | { |
---|
1353 | 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 |
---|
1354 | 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 |
---|
1355 | } |
---|
1356 | |
---|
1357 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1358 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1359 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1360 | #endif |
---|
1361 | |
---|
1362 | #if HHI_MRG_SKIP |
---|
1363 | // do MC |
---|
1364 | #if HHI_INTERVIEW_SKIP |
---|
1365 | if ( (uiNoResidual == 0) || bSkipRes ){ |
---|
1366 | #else |
---|
1367 | if ( uiNoResidual == 0 ){ |
---|
1368 | #endif |
---|
1369 | |
---|
1370 | #if POZNAN_DBMP |
---|
1371 | if(uiMergeCand==POZNAN_DBMP_MRG_CAND){ |
---|
1372 | m_pcPredSearch->motionCompensation_DBMP ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1373 | #if POZNAN_DBMP_CALC_PRED_DATA |
---|
1374 | pcMP->setDBMPPredMVField(REF_PIC_LIST_0, rpcTempCU); |
---|
1375 | pcMP->setDBMPPredMVField(REF_PIC_LIST_1, rpcTempCU); |
---|
1376 | #endif |
---|
1377 | } |
---|
1378 | else |
---|
1379 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1380 | #else |
---|
1381 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1382 | #endif |
---|
1383 | // save pred adress |
---|
1384 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
---|
1385 | |
---|
1386 | } |
---|
1387 | else { |
---|
1388 | if ( pcPredYuvTemp != m_ppcPredYuvTemp[uhDepth]) { |
---|
1389 | //adress changes take best (old temp) |
---|
1390 | pcPredYuvTemp = m_ppcPredYuvBest[uhDepth]; |
---|
1391 | } |
---|
1392 | #if POZNAN_DBMP_CALC_PRED_DATA |
---|
1393 | if(uiMergeCand==POZNAN_DBMP_MRG_CAND) |
---|
1394 | { |
---|
1395 | //copy motion data representing CU with DBMP for uiNoResidual==0 case |
---|
1396 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->copyFrom(pcMP->getDBMPPredMVField(REF_PIC_LIST_0),rpcTempCU->getTotalNumPart(),0); |
---|
1397 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->copyFrom(pcMP->getDBMPPredMVField(REF_PIC_LIST_1),rpcTempCU->getTotalNumPart(),0); |
---|
1398 | } |
---|
1399 | #endif |
---|
1400 | } |
---|
1401 | #if HHI_VSO |
---|
1402 | if( m_pcRdCost->getUseRenModel() ) |
---|
1403 | { //Reset |
---|
1404 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1405 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1406 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1407 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1408 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1409 | } |
---|
1410 | #endif |
---|
1411 | |
---|
1412 | // estimate residual and encode everything |
---|
1413 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
1414 | m_ppcOrigYuv [uhDepth], |
---|
1415 | pcPredYuvTemp, |
---|
1416 | m_ppcResiYuvTemp[uhDepth], |
---|
1417 | m_ppcResiYuvBest[uhDepth], |
---|
1418 | m_ppcRecoYuvTemp[uhDepth], |
---|
1419 | m_ppcResPredTmp [uhDepth], |
---|
1420 | (uiNoResidual? true:false) ); |
---|
1421 | Bool bQtRootCbf = rpcTempCU->getQtRootCbf(0) == 1; |
---|
1422 | #else |
---|
1423 | #if POZNAN_DBMP |
---|
1424 | // do MC |
---|
1425 | if(uiMergeCand==POZNAN_DBMP_MRG_CAND){ |
---|
1426 | m_pcPredSearch->motionCompensation_DBMP ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1427 | #if POZNAN_DBMP_CALC_PRED_DATA |
---|
1428 | pcMP->setDBMPPredMVField(REF_PIC_LIST_0, rpcTempCU); |
---|
1429 | pcMP->setDBMPPredMVField(REF_PIC_LIST_1, rpcTempCU); |
---|
1430 | #endif |
---|
1431 | } |
---|
1432 | else |
---|
1433 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1434 | |
---|
1435 | #endif |
---|
1436 | |
---|
1437 | // estimate residual and encode everything |
---|
1438 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
1439 | m_ppcOrigYuv [uhDepth], |
---|
1440 | m_ppcPredYuvTemp[uhDepth], |
---|
1441 | m_ppcResiYuvTemp[uhDepth], |
---|
1442 | m_ppcResiYuvBest[uhDepth], |
---|
1443 | m_ppcRecoYuvTemp[uhDepth], |
---|
1444 | m_ppcResPredTmp [uhDepth], |
---|
1445 | false ); |
---|
1446 | #endif |
---|
1447 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth ); |
---|
1448 | |
---|
1449 | rpcTempCU->initEstData(); |
---|
1450 | #if HHI_MRG_SKIP |
---|
1451 | if (!bQtRootCbf) |
---|
1452 | break; |
---|
1453 | } |
---|
1454 | #endif |
---|
1455 | } |
---|
1456 | } |
---|
1457 | } |
---|
1458 | |
---|
1459 | #if HHI_INTERVIEW_SKIP |
---|
1460 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes) |
---|
1461 | #else |
---|
1462 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
1463 | #endif |
---|
1464 | { |
---|
1465 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1466 | |
---|
1467 | #if HHI_VSO |
---|
1468 | if( m_pcRdCost->getUseRenModel() ) |
---|
1469 | { |
---|
1470 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1471 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1472 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
1473 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1474 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1475 | } |
---|
1476 | #endif |
---|
1477 | |
---|
1478 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
1479 | |
---|
1480 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1481 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1482 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1483 | #endif |
---|
1484 | rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); |
---|
1485 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1486 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1487 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1488 | #endif |
---|
1489 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
1490 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
1491 | |
---|
1492 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1493 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
1494 | { // subtract residual prediction from original in motion search |
---|
1495 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ), true ); |
---|
1496 | } |
---|
1497 | #endif |
---|
1498 | #if HHI_INTERVIEW_SKIP |
---|
1499 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes ); |
---|
1500 | #else |
---|
1501 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
1502 | #endif |
---|
1503 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1504 | if( rpcTempCU->getResPredFlag( 0 ) ) |
---|
1505 | { // add residual prediction to original again |
---|
1506 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ) ); |
---|
1507 | } |
---|
1508 | #endif |
---|
1509 | |
---|
1510 | #if PART_MRG |
---|
1511 | if (rpcTempCU->getWidth(0) > 8 && !rpcTempCU->getMergeFlag(0) && (ePartSize != SIZE_2Nx2N && ePartSize != SIZE_NxN)) |
---|
1512 | { |
---|
1513 | return; |
---|
1514 | } |
---|
1515 | #endif |
---|
1516 | #if HHI_INTERVIEW_SKIP |
---|
1517 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth],bSkipRes ); |
---|
1518 | #else |
---|
1519 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth], false ); |
---|
1520 | #endif |
---|
1521 | |
---|
1522 | #if HHI_VSO |
---|
1523 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
1524 | { |
---|
1525 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1526 | } |
---|
1527 | else |
---|
1528 | #endif |
---|
1529 | { |
---|
1530 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1531 | } |
---|
1532 | |
---|
1533 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1534 | } |
---|
1535 | |
---|
1536 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
1537 | { |
---|
1538 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
1539 | |
---|
1540 | #if HHI_VSO |
---|
1541 | if( m_pcRdCost->getUseRenModel() ) |
---|
1542 | { |
---|
1543 | UInt uiWidth = rpcTempCU->getWidth ( 0 ); |
---|
1544 | UInt uiHeight = rpcTempCU->getHeight( 0 ); |
---|
1545 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( ); |
---|
1546 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
1547 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1548 | } |
---|
1549 | #endif |
---|
1550 | |
---|
1551 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
1552 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
1553 | |
---|
1554 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
1555 | Dist uiPreCalcDistC = 0; |
---|
1556 | if( !bSeparateLumaChroma ) |
---|
1557 | { |
---|
1558 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
1559 | } |
---|
1560 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
1561 | |
---|
1562 | #if LM_CHROMA |
---|
1563 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
1564 | #endif |
---|
1565 | |
---|
1566 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
1567 | |
---|
1568 | m_pcEntropyCoder->resetBits(); |
---|
1569 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
1570 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
1571 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
1572 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
1573 | |
---|
1574 | // Encode Coefficients |
---|
1575 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0) ); |
---|
1576 | |
---|
1577 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
1578 | |
---|
1579 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1580 | #if HHI_VSO |
---|
1581 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
1582 | { |
---|
1583 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1584 | } |
---|
1585 | else |
---|
1586 | #endif |
---|
1587 | { |
---|
1588 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1589 | } |
---|
1590 | |
---|
1591 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
1592 | } |
---|
1593 | |
---|
1594 | // check whether current try is the best |
---|
1595 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhDepth ) |
---|
1596 | { |
---|
1597 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
1598 | { |
---|
1599 | TComYuv* pcYuv; |
---|
1600 | |
---|
1601 | // Change Information data |
---|
1602 | TComDataCU* pcCU = rpcBestCU; |
---|
1603 | rpcBestCU = rpcTempCU; |
---|
1604 | rpcTempCU = pcCU; |
---|
1605 | |
---|
1606 | // Change Prediction data |
---|
1607 | pcYuv = m_ppcPredYuvBest[uhDepth]; |
---|
1608 | m_ppcPredYuvBest[uhDepth] = m_ppcPredYuvTemp[uhDepth]; |
---|
1609 | m_ppcPredYuvTemp[uhDepth] = pcYuv; |
---|
1610 | |
---|
1611 | // Change Reconstruction data |
---|
1612 | pcYuv = m_ppcRecoYuvBest[uhDepth]; |
---|
1613 | m_ppcRecoYuvBest[uhDepth] = m_ppcRecoYuvTemp[uhDepth]; |
---|
1614 | m_ppcRecoYuvTemp[uhDepth] = pcYuv; |
---|
1615 | |
---|
1616 | pcYuv = NULL; |
---|
1617 | pcCU = NULL; |
---|
1618 | |
---|
1619 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
1620 | m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_NEXT_BEST]); |
---|
1621 | } |
---|
1622 | } |
---|
1623 | |
---|
1624 | Void TEncCu::xCheckRDCostAMVPSkip ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
1625 | { |
---|
1626 | UChar uhDepth = rpcTempCU->getDepth(0); |
---|
1627 | |
---|
1628 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1629 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
---|
1630 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
---|
1631 | #endif |
---|
1632 | |
---|
1633 | AMVPInfo cAMVPInfo0; |
---|
1634 | cAMVPInfo0.iN = 0; |
---|
1635 | |
---|
1636 | AMVPInfo cAMVPInfo1; |
---|
1637 | cAMVPInfo1.iN = 0; |
---|
1638 | |
---|
1639 | if (rpcTempCU->getAMVPMode(0) == AM_EXPL) |
---|
1640 | { |
---|
1641 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1642 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1643 | |
---|
1644 | if ( rpcTempCU->getSlice()->isInterP() && rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) |
---|
1645 | { |
---|
1646 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_0, 0, &cAMVPInfo0); |
---|
1647 | } |
---|
1648 | else if ( rpcTempCU->getSlice()->isInterB() && |
---|
1649 | rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 && |
---|
1650 | rpcTempCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) |
---|
1651 | { |
---|
1652 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_0, 0, &cAMVPInfo0); |
---|
1653 | rpcTempCU->fillMvpCand(0, 0, REF_PIC_LIST_1, 0, &cAMVPInfo1); |
---|
1654 | } |
---|
1655 | else |
---|
1656 | { |
---|
1657 | assert( 0 ); |
---|
1658 | } |
---|
1659 | } |
---|
1660 | |
---|
1661 | Int iMVP0, iMVP1; |
---|
1662 | |
---|
1663 | for (iMVP0 = (cAMVPInfo0.iN > 0? 0:-1); iMVP0 < cAMVPInfo0.iN; iMVP0++) |
---|
1664 | { |
---|
1665 | for (iMVP1 = (cAMVPInfo1.iN > 0? 0:-1); iMVP1 < cAMVPInfo1.iN; iMVP1++) |
---|
1666 | { |
---|
1667 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1668 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1669 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
1670 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
---|
1671 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
---|
1672 | #endif |
---|
1673 | |
---|
1674 | if (rpcTempCU->getSlice()->isInterB()) |
---|
1675 | rpcTempCU->setInterDirSubParts( 3, 0, 0, uhDepth ); |
---|
1676 | |
---|
1677 | rpcTempCU->setMVPIdxSubParts( iMVP0, REF_PIC_LIST_0, 0, 0, uhDepth ); |
---|
1678 | rpcTempCU->setMVPIdxSubParts( iMVP1, REF_PIC_LIST_1, 0, 0, uhDepth ); |
---|
1679 | |
---|
1680 | rpcTempCU->setMVPNumSubParts( cAMVPInfo0.iN, REF_PIC_LIST_0, 0, 0, uhDepth ); |
---|
1681 | rpcTempCU->setMVPNumSubParts( cAMVPInfo1.iN, REF_PIC_LIST_1, 0, 0, uhDepth ); |
---|
1682 | |
---|
1683 | xCopyAMVPInfo(&cAMVPInfo0, rpcTempCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo()); |
---|
1684 | xCopyAMVPInfo(&cAMVPInfo1, rpcTempCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()); |
---|
1685 | xCheckRDCostSkip ( rpcBestCU, rpcTempCU, true ); rpcTempCU->initEstData(); |
---|
1686 | } |
---|
1687 | } |
---|
1688 | } |
---|
1689 | |
---|
1690 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
1691 | { |
---|
1692 | pDst->iN = pSrc->iN; |
---|
1693 | for (Int i = 0; i < pSrc->iN; i++) |
---|
1694 | { |
---|
1695 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
1696 | } |
---|
1697 | } |
---|
1698 | |
---|
1699 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsZorderIdx, UInt uiDepth) |
---|
1700 | { |
---|
1701 | m_ppcRecoYuvBest[uiDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsZorderIdx ); |
---|
1702 | } |
---|
1703 | |
---|
1704 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
1705 | { |
---|
1706 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
1707 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
1708 | } |
---|
1709 | |
---|
1710 | #if HHI_MPI |
---|
1711 | Void TEncCu::xCheckRDCostMvInheritance( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhTextureModeDepth, Bool bSkipResidual, Bool bRecursiveCall ) |
---|
1712 | { |
---|
1713 | assert( rpcTempCU->getSlice()->getSPS()->isDepth() ); |
---|
1714 | TComDataCU *pcTextureCU = rpcTempCU->getSlice()->getTexturePic()->getCU( rpcTempCU->getAddr() ); |
---|
1715 | |
---|
1716 | const UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
1717 | assert( bRecursiveCall == ( uhDepth != uhTextureModeDepth ) ); |
---|
1718 | |
---|
1719 | if( uhDepth == uhTextureModeDepth ) |
---|
1720 | { |
---|
1721 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
1722 | { |
---|
1723 | if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) |
---|
1724 | #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU |
---|
1725 | || pcTextureCU->isCUSkiped( rpcTempCU->getZorderIdxInCU() + ui ) |
---|
1726 | #endif |
---|
1727 | ) |
---|
1728 | { |
---|
1729 | return; |
---|
1730 | } |
---|
1731 | } |
---|
1732 | } |
---|
1733 | |
---|
1734 | #if HHI_VSO |
---|
1735 | if( m_pcRdCost->getUseRenModel() && !bRecursiveCall) |
---|
1736 | { |
---|
1737 | UInt uiWidth = m_ppcTempCU [uhDepth]->getWidth ( 0 ); |
---|
1738 | UInt uiHeight = m_ppcTempCU [uhDepth]->getHeight( 0 ); |
---|
1739 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( 0 ); |
---|
1740 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
1741 | m_pcRdCost->setRenModelData( m_ppcTempCU[uhDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1742 | } |
---|
1743 | #endif |
---|
1744 | |
---|
1745 | Bool bSplit = uhDepth < pcTextureCU->getDepth( rpcTempCU->getZorderIdxInCU() ); |
---|
1746 | if( bSplit ) |
---|
1747 | { |
---|
1748 | const UChar uhNextDepth = uhDepth+1; |
---|
1749 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
1750 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
1751 | |
---|
1752 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
1753 | { |
---|
1754 | pcSubBestPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
1755 | pcSubTempPartCU->initSubCU( rpcBestCU, uiPartUnitIdx, uhNextDepth ); // clear sub partition datas or init. |
---|
1756 | |
---|
1757 | if( ( pcSubBestPartCU->getCUPelX() < pcSubBestPartCU->getSlice()->getSPS()->getWidth() ) && ( pcSubBestPartCU->getCUPelY() < pcSubBestPartCU->getSlice()->getSPS()->getHeight() ) ) |
---|
1758 | { |
---|
1759 | if( m_bUseSBACRD ) |
---|
1760 | { |
---|
1761 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
1762 | { |
---|
1763 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhDepth][CI_CURR_BEST]); |
---|
1764 | } |
---|
1765 | else |
---|
1766 | { |
---|
1767 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
1768 | } |
---|
1769 | } |
---|
1770 | |
---|
1771 | xCheckRDCostMvInheritance( pcSubBestPartCU, pcSubTempPartCU, uhTextureModeDepth, bSkipResidual, true ); |
---|
1772 | |
---|
1773 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
1774 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
1775 | } |
---|
1776 | } |
---|
1777 | |
---|
1778 | if( uhDepth == uhTextureModeDepth ) |
---|
1779 | { |
---|
1780 | xAddMVISignallingBits( rpcTempCU ); |
---|
1781 | } |
---|
1782 | |
---|
1783 | if( m_bUseSBACRD ) |
---|
1784 | { |
---|
1785 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]); |
---|
1786 | } |
---|
1787 | } |
---|
1788 | else |
---|
1789 | { |
---|
1790 | rpcTempCU->setTextureModeDepthSubParts( uhTextureModeDepth, 0, uhDepth ); |
---|
1791 | rpcTempCU->copyTextureMotionDataFrom( pcTextureCU, uhDepth, rpcTempCU->getZorderIdxInCU() ); |
---|
1792 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
---|
1793 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
---|
1794 | { |
---|
1795 | assert( rpcTempCU->getInterDir( ui ) != 0 ); |
---|
1796 | assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE ); |
---|
1797 | } |
---|
1798 | rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth ); |
---|
1799 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
1800 | |
---|
1801 | // get Original YUV data from picture |
---|
1802 | m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
1803 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth], bSkipResidual ); |
---|
1804 | |
---|
1805 | if( uhDepth == uhTextureModeDepth ) |
---|
1806 | { |
---|
1807 | xAddMVISignallingBits( rpcTempCU ); |
---|
1808 | } |
---|
1809 | } |
---|
1810 | |
---|
1811 | #if HHI_VSO |
---|
1812 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
1813 | { |
---|
1814 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1815 | } |
---|
1816 | else |
---|
1817 | #endif |
---|
1818 | { |
---|
1819 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
1820 | } |
---|
1821 | |
---|
1822 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
1823 | |
---|
1824 | #if HHI_VSO |
---|
1825 | if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() ) |
---|
1826 | { |
---|
1827 | UInt uiWidth = rpcBestCU->getWidth ( 0 ); |
---|
1828 | UInt uiHeight = rpcBestCU->getHeight( 0 ); |
---|
1829 | Pel* piSrc = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 ); |
---|
1830 | UInt uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride(); |
---|
1831 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
1832 | } |
---|
1833 | #endif |
---|
1834 | } |
---|
1835 | |
---|
1836 | Void TEncCu::xAddMVISignallingBits( TComDataCU* pcCU ) |
---|
1837 | { |
---|
1838 | const UChar uhDepth = pcCU->getTextureModeDepth( 0 ); |
---|
1839 | m_pcEntropyCoder->resetBits(); |
---|
1840 | xSaveDepthWidthHeight( pcCU ); |
---|
1841 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uhDepth, g_uiMaxCUHeight>>uhDepth, 0, uhDepth ); |
---|
1842 | pcCU->setDepthSubParts( uhDepth, 0 ); |
---|
1843 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
---|
1844 | pcCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); |
---|
1845 | pcCU->setMergeIndexSubParts( 0, 0, 0, uhDepth ); |
---|
1846 | |
---|
1847 | { |
---|
1848 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
---|
1849 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
1850 | UInt uiNeighbourCandIdx[MRG_MAX_NUM_CANDS]; //MVs with same idx => same cand |
---|
1851 | |
---|
1852 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
---|
1853 | { |
---|
1854 | uhInterDirNeighbours[ui] = 0; |
---|
1855 | uiNeighbourCandIdx[ui] = 0; |
---|
1856 | } |
---|
1857 | pcCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, uiNeighbourCandIdx ); |
---|
1858 | for( UInt uiMergeCand = 0; uiMergeCand < MRG_MAX_NUM_CANDS; uiMergeCand++ ) |
---|
1859 | { |
---|
1860 | pcCU->setNeighbourCandIdxSubParts( uiMergeCand, uiNeighbourCandIdx[uiMergeCand], 0, 0,uhDepth ); |
---|
1861 | } |
---|
1862 | } |
---|
1863 | |
---|
1864 | // check for skip mode |
---|
1865 | { |
---|
1866 | Bool bAllZero = true; |
---|
1867 | for( UInt ui = 0; ui < pcCU->getTotalNumPart(); ui++ ) |
---|
1868 | { |
---|
1869 | if( pcCU->getCbf( ui, TEXT_LUMA ) || pcCU->getCbf( ui, TEXT_CHROMA_U ) || pcCU->getCbf( ui, TEXT_CHROMA_V ) ) |
---|
1870 | { |
---|
1871 | bAllZero = false; |
---|
1872 | break; |
---|
1873 | } |
---|
1874 | } |
---|
1875 | if( bAllZero ) |
---|
1876 | pcCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
---|
1877 | } |
---|
1878 | |
---|
1879 | |
---|
1880 | m_pcEntropyCoder->encodeSplitFlag( pcCU, 0, uhDepth, true ); |
---|
1881 | m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true ); |
---|
1882 | |
---|
1883 | if( pcCU->isSkipped( 0 ) ) |
---|
1884 | { |
---|
1885 | #if HHI_MRG_SKIP |
---|
1886 | m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true ); |
---|
1887 | #else |
---|
1888 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 ) //if ( ref. frame list0 has at least 1 entry ) |
---|
1889 | { |
---|
1890 | m_pcEntropyCoder->encodeMVPIdx( pcCU, 0, REF_PIC_LIST_0, true ); |
---|
1891 | } |
---|
1892 | if ( pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 ) //if ( ref. frame list1 has at least 1 entry ) |
---|
1893 | { |
---|
1894 | m_pcEntropyCoder->encodeMVPIdx( pcCU, 0, REF_PIC_LIST_1, true ); |
---|
1895 | } |
---|
1896 | #endif |
---|
1897 | } |
---|
1898 | else |
---|
1899 | { |
---|
1900 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
---|
1901 | m_pcEntropyCoder->encodePartSize( pcCU, 0, uhDepth, true ); |
---|
1902 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
1903 | m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); |
---|
1904 | } |
---|
1905 | xRestoreDepthWidthHeight( pcCU ); |
---|
1906 | |
---|
1907 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1908 | } |
---|
1909 | |
---|
1910 | Void TEncCu::xSaveDepthWidthHeight( TComDataCU* pcCU ) |
---|
1911 | { |
---|
1912 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
1913 | memcpy( m_puhDepthSaved, pcCU->getDepth(), iSizeInUchar ); |
---|
1914 | memcpy( m_puhWidthSaved, pcCU->getWidth(), iSizeInUchar ); |
---|
1915 | memcpy( m_puhHeightSaved, pcCU->getHeight(), iSizeInUchar ); |
---|
1916 | } |
---|
1917 | |
---|
1918 | Void TEncCu::xRestoreDepthWidthHeight( TComDataCU* pcCU ) |
---|
1919 | { |
---|
1920 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
---|
1921 | memcpy( pcCU->getDepth(), m_puhDepthSaved, iSizeInUchar ); |
---|
1922 | memcpy( pcCU->getWidth(), m_puhWidthSaved, iSizeInUchar ); |
---|
1923 | memcpy( pcCU->getHeight(), m_puhHeightSaved, iSizeInUchar ); |
---|
1924 | } |
---|
1925 | #endif |
---|