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-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncTop.cpp |
---|
35 | \brief encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TLibCommon/CommonDef.h" |
---|
39 | #include "TEncTop.h" |
---|
40 | #include "TEncPic.h" |
---|
41 | #if FAST_BIT_EST |
---|
42 | #include "TLibCommon/ContextModel.h" |
---|
43 | #endif |
---|
44 | #if H_MV |
---|
45 | #include "../../App/TAppEncoder/TAppEncTop.h" |
---|
46 | #endif |
---|
47 | |
---|
48 | //! \ingroup TLibEncoder |
---|
49 | //! \{ |
---|
50 | |
---|
51 | // ==================================================================================================================== |
---|
52 | // Constructor / destructor / create / destroy |
---|
53 | // ==================================================================================================================== |
---|
54 | |
---|
55 | TEncTop::TEncTop() |
---|
56 | { |
---|
57 | m_iPOCLast = -1; |
---|
58 | m_iNumPicRcvd = 0; |
---|
59 | m_uiNumAllPicCoded = 0; |
---|
60 | m_pppcRDSbacCoder = NULL; |
---|
61 | m_pppcBinCoderCABAC = NULL; |
---|
62 | m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC ); |
---|
63 | #if ENC_DEC_TRACE |
---|
64 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
65 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
66 | g_nSymbolCounter = 0; |
---|
67 | #endif |
---|
68 | |
---|
69 | m_iMaxRefPicNum = 0; |
---|
70 | |
---|
71 | #if FAST_BIT_EST |
---|
72 | ContextModel::buildNextStateTable(); |
---|
73 | #endif |
---|
74 | |
---|
75 | m_pcSbacCoders = NULL; |
---|
76 | m_pcBinCoderCABACs = NULL; |
---|
77 | m_ppppcRDSbacCoders = NULL; |
---|
78 | m_ppppcBinCodersCABAC = NULL; |
---|
79 | m_pcRDGoOnSbacCoders = NULL; |
---|
80 | m_pcRDGoOnBinCodersCABAC = NULL; |
---|
81 | m_pcBitCounters = NULL; |
---|
82 | m_pcRdCosts = NULL; |
---|
83 | #if H_MV |
---|
84 | m_ivPicLists = NULL; |
---|
85 | #endif |
---|
86 | } |
---|
87 | |
---|
88 | TEncTop::~TEncTop() |
---|
89 | { |
---|
90 | #if ENC_DEC_TRACE |
---|
91 | fclose( g_hTrace ); |
---|
92 | #endif |
---|
93 | } |
---|
94 | |
---|
95 | Void TEncTop::create () |
---|
96 | { |
---|
97 | #if !H_MV |
---|
98 | // initialize global variables |
---|
99 | initROM(); |
---|
100 | #endif |
---|
101 | |
---|
102 | // create processing unit classes |
---|
103 | m_cGOPEncoder. create(); |
---|
104 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
105 | m_cCuEncoder. create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
106 | if (m_bUseSAO) |
---|
107 | { |
---|
108 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
109 | #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK |
---|
110 | m_cEncSAO.createEncData(getSaoLcuBoundary()); |
---|
111 | #else |
---|
112 | m_cEncSAO.createEncData(); |
---|
113 | #endif |
---|
114 | } |
---|
115 | #if ADAPTIVE_QP_SELECTION |
---|
116 | if (m_bUseAdaptQpSelect) |
---|
117 | { |
---|
118 | m_cTrQuant.initSliceQpDelta(); |
---|
119 | } |
---|
120 | #endif |
---|
121 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
122 | |
---|
123 | if ( m_RCEnableRateControl ) |
---|
124 | { |
---|
125 | #if KWU_RC_MADPRED_E0227 |
---|
126 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
127 | g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList, getLayerId() ); |
---|
128 | #else |
---|
129 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
130 | g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
---|
131 | #endif |
---|
132 | } |
---|
133 | m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
134 | #if FAST_BIT_EST |
---|
135 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1]; |
---|
136 | #else |
---|
137 | m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
138 | #endif |
---|
139 | |
---|
140 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
141 | { |
---|
142 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
143 | #if FAST_BIT_EST |
---|
144 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
145 | #else |
---|
146 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
147 | #endif |
---|
148 | |
---|
149 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
150 | { |
---|
151 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
152 | #if FAST_BIT_EST |
---|
153 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
154 | #else |
---|
155 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
156 | #endif |
---|
157 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | /** |
---|
163 | - Allocate coders required for wavefront for the nominated number of substreams. |
---|
164 | . |
---|
165 | \param iNumSubstreams Determines how much information to allocate. |
---|
166 | */ |
---|
167 | Void TEncTop::createWPPCoders(Int iNumSubstreams) |
---|
168 | { |
---|
169 | if (m_pcSbacCoders != NULL) |
---|
170 | { |
---|
171 | return; // already generated. |
---|
172 | } |
---|
173 | |
---|
174 | m_iNumSubstreams = iNumSubstreams; |
---|
175 | m_pcSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
176 | m_pcBinCoderCABACs = new TEncBinCABAC [iNumSubstreams]; |
---|
177 | m_pcRDGoOnSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
178 | m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC [iNumSubstreams]; |
---|
179 | m_pcBitCounters = new TComBitCounter [iNumSubstreams]; |
---|
180 | m_pcRdCosts = new TComRdCost [iNumSubstreams]; |
---|
181 | |
---|
182 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
183 | { |
---|
184 | m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] ); |
---|
185 | m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] ); |
---|
186 | } |
---|
187 | |
---|
188 | m_ppppcRDSbacCoders = new TEncSbac*** [iNumSubstreams]; |
---|
189 | m_ppppcBinCodersCABAC = new TEncBinCABAC***[iNumSubstreams]; |
---|
190 | for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) |
---|
191 | { |
---|
192 | m_ppppcRDSbacCoders[ui] = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
193 | m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
194 | |
---|
195 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
196 | { |
---|
197 | m_ppppcRDSbacCoders[ui][iDepth] = new TEncSbac* [CI_NUM]; |
---|
198 | m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM]; |
---|
199 | |
---|
200 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
201 | { |
---|
202 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx] = new TEncSbac; |
---|
203 | m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC; |
---|
204 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] ); |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | Void TEncTop::destroy () |
---|
211 | { |
---|
212 | // destroy processing unit classes |
---|
213 | m_cGOPEncoder. destroy(); |
---|
214 | m_cSliceEncoder. destroy(); |
---|
215 | m_cCuEncoder. destroy(); |
---|
216 | if (m_cSPS.getUseSAO()) |
---|
217 | { |
---|
218 | m_cEncSAO.destroyEncData(); |
---|
219 | m_cEncSAO.destroy(); |
---|
220 | } |
---|
221 | m_cLoopFilter. destroy(); |
---|
222 | m_cRateCtrl. destroy(); |
---|
223 | |
---|
224 | Int iDepth; |
---|
225 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
226 | { |
---|
227 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
228 | { |
---|
229 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
230 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
235 | { |
---|
236 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
237 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
238 | } |
---|
239 | |
---|
240 | delete [] m_pppcRDSbacCoder; |
---|
241 | delete [] m_pppcBinCoderCABAC; |
---|
242 | |
---|
243 | for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ ) |
---|
244 | { |
---|
245 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
246 | { |
---|
247 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
248 | { |
---|
249 | delete m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]; |
---|
250 | delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx]; |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
255 | { |
---|
256 | delete [] m_ppppcRDSbacCoders [ui][iDepth]; |
---|
257 | delete [] m_ppppcBinCodersCABAC[ui][iDepth]; |
---|
258 | } |
---|
259 | delete[] m_ppppcRDSbacCoders [ui]; |
---|
260 | delete[] m_ppppcBinCodersCABAC[ui]; |
---|
261 | } |
---|
262 | delete[] m_ppppcRDSbacCoders; |
---|
263 | delete[] m_ppppcBinCodersCABAC; |
---|
264 | delete[] m_pcSbacCoders; |
---|
265 | delete[] m_pcBinCoderCABACs; |
---|
266 | delete[] m_pcRDGoOnSbacCoders; |
---|
267 | delete[] m_pcRDGoOnBinCodersCABAC; |
---|
268 | delete[] m_pcBitCounters; |
---|
269 | delete[] m_pcRdCosts; |
---|
270 | |
---|
271 | #if !H_MV |
---|
272 | // destroy ROM |
---|
273 | destroyROM(); |
---|
274 | #endif |
---|
275 | |
---|
276 | return; |
---|
277 | } |
---|
278 | |
---|
279 | #if KWU_RC_MADPRED_E0227 |
---|
280 | Void TEncTop::init(TAppEncTop* pcTAppEncTop, Bool isFieldCoding) |
---|
281 | #else |
---|
282 | Void TEncTop::init(Bool isFieldCoding) |
---|
283 | #endif |
---|
284 | { |
---|
285 | // initialize SPS |
---|
286 | #if H_3D |
---|
287 | // Assuming that all PPS indirectly refer to the same VPS via different SPS |
---|
288 | m_cSPS.setVPS(m_cVPS); |
---|
289 | #endif |
---|
290 | xInitSPS(); |
---|
291 | |
---|
292 | /* set the VPS profile information */ |
---|
293 | #if H_MV |
---|
294 | // This seems to be incorrect, but irrelevant for the MV-HEVC |
---|
295 | *(m_cVPS->getPTL()) = *m_cSPS.getPTL(); |
---|
296 | m_cVPS->getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
297 | #else |
---|
298 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
---|
299 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
300 | #endif |
---|
301 | // initialize PPS |
---|
302 | m_cPPS.setSPS(&m_cSPS); |
---|
303 | xInitPPS(); |
---|
304 | xInitRPS(isFieldCoding); |
---|
305 | |
---|
306 | xInitPPSforTiles(); |
---|
307 | |
---|
308 | // initialize processing unit classes |
---|
309 | m_cGOPEncoder. init( this ); |
---|
310 | m_cSliceEncoder.init( this ); |
---|
311 | m_cCuEncoder. init( this ); |
---|
312 | |
---|
313 | #if KWU_RC_MADPRED_E0227 |
---|
314 | m_pcTAppEncTop = pcTAppEncTop; |
---|
315 | #endif |
---|
316 | // initialize transform & quantization class |
---|
317 | m_pcCavlcCoder = getCavlcCoder(); |
---|
318 | |
---|
319 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
---|
320 | m_useRDOQ, |
---|
321 | m_useRDOQTS, |
---|
322 | true |
---|
323 | ,m_useTransformSkipFast |
---|
324 | #if ADAPTIVE_QP_SELECTION |
---|
325 | , m_bUseAdaptQpSelect |
---|
326 | #endif |
---|
327 | ); |
---|
328 | |
---|
329 | // initialize encoder search class |
---|
330 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
331 | |
---|
332 | m_iMaxRefPicNum = 0; |
---|
333 | } |
---|
334 | |
---|
335 | // ==================================================================================================================== |
---|
336 | // Public member functions |
---|
337 | // ==================================================================================================================== |
---|
338 | |
---|
339 | #if H_MV |
---|
340 | Void TEncTop::initNewPic( TComPicYuv* pcPicYuvOrg ) |
---|
341 | { |
---|
342 | TComPic* pcPicCurr = NULL; |
---|
343 | |
---|
344 | // get original YUV |
---|
345 | xGetNewPicBuffer( pcPicCurr ); |
---|
346 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
347 | |
---|
348 | // compute image characteristics |
---|
349 | if ( getUseAdaptiveQP() ) |
---|
350 | { |
---|
351 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
352 | } |
---|
353 | #if H_MV |
---|
354 | pcPicCurr->setLayerId( getLayerId()); |
---|
355 | #endif |
---|
356 | #if H_3D |
---|
357 | pcPicCurr->setScaleOffset( m_aaiCodedScale, m_aaiCodedOffset ); |
---|
358 | #endif |
---|
359 | } |
---|
360 | #endif |
---|
361 | Void TEncTop::deletePicBuffer() |
---|
362 | { |
---|
363 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
364 | Int iSize = Int( m_cListPic.size() ); |
---|
365 | |
---|
366 | for ( Int i = 0; i < iSize; i++ ) |
---|
367 | { |
---|
368 | TComPic* pcPic = *(iterPic++); |
---|
369 | |
---|
370 | pcPic->destroy(); |
---|
371 | delete pcPic; |
---|
372 | pcPic = NULL; |
---|
373 | } |
---|
374 | } |
---|
375 | |
---|
376 | /** |
---|
377 | - Application has picture buffer list with size of GOP + 1 |
---|
378 | - Picture buffer list acts like as ring buffer |
---|
379 | - End of the list has the latest picture |
---|
380 | . |
---|
381 | \param flush cause encoder to encode a partial GOP |
---|
382 | \param pcPicYuvOrg original YUV picture |
---|
383 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
384 | \retval rcListBitstreamOut list of output bitstreams |
---|
385 | \retval iNumEncoded number of encoded pictures |
---|
386 | */ |
---|
387 | #if H_MV |
---|
388 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded , Int gopId ) |
---|
389 | { |
---|
390 | #else |
---|
391 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
392 | { |
---|
393 | #endif |
---|
394 | #if H_3D |
---|
395 | TComPic* picLastCoded = getPic( getGOPEncoder()->getPocLastCoded() ); |
---|
396 | if( picLastCoded ) |
---|
397 | { |
---|
398 | picLastCoded->compressMotion(1); |
---|
399 | } |
---|
400 | #endif |
---|
401 | #if H_MV |
---|
402 | if( gopId == 0) |
---|
403 | { |
---|
404 | m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
405 | #else |
---|
406 | if (pcPicYuvOrg) { |
---|
407 | // get original YUV |
---|
408 | TComPic* pcPicCurr = NULL; |
---|
409 | xGetNewPicBuffer( pcPicCurr ); |
---|
410 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
411 | |
---|
412 | // compute image characteristics |
---|
413 | if ( getUseAdaptiveQP() ) |
---|
414 | { |
---|
415 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
416 | } |
---|
417 | } |
---|
418 | |
---|
419 | if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) |
---|
420 | { |
---|
421 | iNumEncoded = 0; |
---|
422 | return; |
---|
423 | } |
---|
424 | #endif |
---|
425 | |
---|
426 | if ( m_RCEnableRateControl ) |
---|
427 | { |
---|
428 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
429 | } |
---|
430 | #if H_MV |
---|
431 | } |
---|
432 | m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId, false, false ); |
---|
433 | |
---|
434 | if( gopId + 1 == m_cGOPEncoder.getGOPSize() ) |
---|
435 | { |
---|
436 | #else |
---|
437 | // compress GOP |
---|
438 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false); |
---|
439 | #endif |
---|
440 | |
---|
441 | if ( m_RCEnableRateControl ) |
---|
442 | { |
---|
443 | m_cRateCtrl.destroyRCGOP(); |
---|
444 | } |
---|
445 | |
---|
446 | iNumEncoded = m_iNumPicRcvd; |
---|
447 | m_iNumPicRcvd = 0; |
---|
448 | m_uiNumAllPicCoded += iNumEncoded; |
---|
449 | #if H_MV |
---|
450 | } |
---|
451 | #endif |
---|
452 | } |
---|
453 | /**------------------------------------------------ |
---|
454 | Separate interlaced frame into two fields |
---|
455 | -------------------------------------------------**/ |
---|
456 | void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, bool isTop) |
---|
457 | { |
---|
458 | if (!isTop) |
---|
459 | { |
---|
460 | org += stride; |
---|
461 | } |
---|
462 | for (Int y = 0; y < height>>1; y++) |
---|
463 | { |
---|
464 | for (Int x = 0; x < width; x++) |
---|
465 | { |
---|
466 | dstField[x] = org[x]; |
---|
467 | } |
---|
468 | |
---|
469 | dstField += stride; |
---|
470 | org += stride*2; |
---|
471 | } |
---|
472 | |
---|
473 | } |
---|
474 | |
---|
475 | #if H_MV |
---|
476 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff, Int gopId ) |
---|
477 | { |
---|
478 | assert( 0 ); // Field coding and multiview need to be furhter harmonized. |
---|
479 | } |
---|
480 | #else |
---|
481 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff) |
---|
482 | { |
---|
483 | /* -- TOP FIELD -- */ |
---|
484 | |
---|
485 | if (pcPicYuvOrg) |
---|
486 | { |
---|
487 | |
---|
488 | /* -- Top field initialization -- */ |
---|
489 | |
---|
490 | TComPic *pcTopField; |
---|
491 | xGetNewPicBuffer( pcTopField ); |
---|
492 | pcTopField->setReconMark (false); |
---|
493 | |
---|
494 | pcTopField->getSlice(0)->setPOC( m_iPOCLast ); |
---|
495 | pcTopField->getPicYuvRec()->setBorderExtension(false); |
---|
496 | pcTopField->setTopField(isTff); |
---|
497 | |
---|
498 | int nHeight = pcPicYuvOrg->getHeight(); |
---|
499 | int nWidth = pcPicYuvOrg->getWidth(); |
---|
500 | int nStride = pcPicYuvOrg->getStride(); |
---|
501 | int nPadLuma = pcPicYuvOrg->getLumaMargin(); |
---|
502 | int nPadChroma = pcPicYuvOrg->getChromaMargin(); |
---|
503 | |
---|
504 | // Get pointers |
---|
505 | Pel * PicBufY = pcPicYuvOrg->getBufY(); |
---|
506 | Pel * PicBufU = pcPicYuvOrg->getBufU(); |
---|
507 | Pel * PicBufV = pcPicYuvOrg->getBufV(); |
---|
508 | |
---|
509 | Pel * pcTopFieldY = pcTopField->getPicYuvOrg()->getLumaAddr(); |
---|
510 | Pel * pcTopFieldU = pcTopField->getPicYuvOrg()->getCbAddr(); |
---|
511 | Pel * pcTopFieldV = pcTopField->getPicYuvOrg()->getCrAddr(); |
---|
512 | |
---|
513 | /* -- Defield -- */ |
---|
514 | |
---|
515 | bool isTop = isTff; |
---|
516 | |
---|
517 | separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop); |
---|
518 | separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
519 | separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
520 | |
---|
521 | // compute image characteristics |
---|
522 | if ( getUseAdaptiveQP() ) |
---|
523 | { |
---|
524 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) ); |
---|
525 | } |
---|
526 | } |
---|
527 | |
---|
528 | if (m_iPOCLast == 0) // compress field 0 |
---|
529 | { |
---|
530 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); |
---|
531 | } |
---|
532 | |
---|
533 | /* -- BOTTOM FIELD -- */ |
---|
534 | |
---|
535 | if (pcPicYuvOrg) |
---|
536 | { |
---|
537 | |
---|
538 | /* -- Bottom field initialization -- */ |
---|
539 | |
---|
540 | TComPic* pcBottomField; |
---|
541 | xGetNewPicBuffer( pcBottomField ); |
---|
542 | pcBottomField->setReconMark (false); |
---|
543 | |
---|
544 | TComPicYuv* rpcPicYuvRec; |
---|
545 | if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize ) |
---|
546 | { |
---|
547 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
548 | } |
---|
549 | else |
---|
550 | { |
---|
551 | rpcPicYuvRec = new TComPicYuv; |
---|
552 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
553 | } |
---|
554 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
555 | |
---|
556 | pcBottomField->getSlice(0)->setPOC( m_iPOCLast); |
---|
557 | pcBottomField->getPicYuvRec()->setBorderExtension(false); |
---|
558 | pcBottomField->setTopField(!isTff); |
---|
559 | |
---|
560 | int nHeight = pcPicYuvOrg->getHeight(); |
---|
561 | int nWidth = pcPicYuvOrg->getWidth(); |
---|
562 | int nStride = pcPicYuvOrg->getStride(); |
---|
563 | int nPadLuma = pcPicYuvOrg->getLumaMargin(); |
---|
564 | int nPadChroma = pcPicYuvOrg->getChromaMargin(); |
---|
565 | |
---|
566 | // Get pointers |
---|
567 | Pel * PicBufY = pcPicYuvOrg->getBufY(); |
---|
568 | Pel * PicBufU = pcPicYuvOrg->getBufU(); |
---|
569 | Pel * PicBufV = pcPicYuvOrg->getBufV(); |
---|
570 | |
---|
571 | Pel * pcBottomFieldY = pcBottomField->getPicYuvOrg()->getLumaAddr(); |
---|
572 | Pel * pcBottomFieldU = pcBottomField->getPicYuvOrg()->getCbAddr(); |
---|
573 | Pel * pcBottomFieldV = pcBottomField->getPicYuvOrg()->getCrAddr(); |
---|
574 | |
---|
575 | /* -- Defield -- */ |
---|
576 | |
---|
577 | bool isTop = !isTff; |
---|
578 | |
---|
579 | separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop); |
---|
580 | separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
581 | separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
582 | |
---|
583 | // Compute image characteristics |
---|
584 | if ( getUseAdaptiveQP() ) |
---|
585 | { |
---|
586 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) ); |
---|
587 | } |
---|
588 | } |
---|
589 | |
---|
590 | if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) ) |
---|
591 | { |
---|
592 | iNumEncoded = 0; |
---|
593 | return; |
---|
594 | } |
---|
595 | |
---|
596 | // compress GOP |
---|
597 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); |
---|
598 | |
---|
599 | iNumEncoded = m_iNumPicRcvd; |
---|
600 | m_iNumPicRcvd = 0; |
---|
601 | m_uiNumAllPicCoded += iNumEncoded; |
---|
602 | } |
---|
603 | #endif |
---|
604 | // ==================================================================================================================== |
---|
605 | // Protected member functions |
---|
606 | // ==================================================================================================================== |
---|
607 | |
---|
608 | /** |
---|
609 | - Application has picture buffer list with size of GOP + 1 |
---|
610 | - Picture buffer list acts like as ring buffer |
---|
611 | - End of the list has the latest picture |
---|
612 | . |
---|
613 | \retval rpcPic obtained picture buffer |
---|
614 | */ |
---|
615 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
616 | { |
---|
617 | TComSlice::sortPicList(m_cListPic); |
---|
618 | |
---|
619 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
620 | { |
---|
621 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
622 | Int iSize = Int( m_cListPic.size() ); |
---|
623 | for ( Int i = 0; i < iSize; i++ ) |
---|
624 | { |
---|
625 | rpcPic = *(iterPic++); |
---|
626 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
627 | { |
---|
628 | break; |
---|
629 | } |
---|
630 | } |
---|
631 | } |
---|
632 | else |
---|
633 | { |
---|
634 | if ( getUseAdaptiveQP() ) |
---|
635 | { |
---|
636 | TEncPic* pcEPic = new TEncPic; |
---|
637 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
638 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
639 | rpcPic = pcEPic; |
---|
640 | } |
---|
641 | else |
---|
642 | { |
---|
643 | rpcPic = new TComPic; |
---|
644 | |
---|
645 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
646 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
647 | } |
---|
648 | m_cListPic.pushBack( rpcPic ); |
---|
649 | } |
---|
650 | rpcPic->setReconMark (false); |
---|
651 | |
---|
652 | m_iPOCLast++; |
---|
653 | m_iNumPicRcvd++; |
---|
654 | |
---|
655 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
656 | // mark it should be extended |
---|
657 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
658 | |
---|
659 | #if H_MV |
---|
660 | rpcPic->getPicYuvOrg()->setBorderExtension(false); |
---|
661 | #endif |
---|
662 | } |
---|
663 | |
---|
664 | Void TEncTop::xInitSPS() |
---|
665 | { |
---|
666 | #if H_MV |
---|
667 | m_cSPS.setSPSId( getLayerIdInVps() ); |
---|
668 | m_cSPS.setLayerId( getLayerId() ); |
---|
669 | #endif |
---|
670 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
---|
671 | profileTierLevel.setLevelIdc(m_level); |
---|
672 | profileTierLevel.setTierFlag(m_levelTier); |
---|
673 | profileTierLevel.setProfileIdc(m_profile); |
---|
674 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
---|
675 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
676 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
677 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
678 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
679 | |
---|
680 | if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8) |
---|
681 | { |
---|
682 | /* The above constraint is equal to Profile::MAIN */ |
---|
683 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
---|
684 | } |
---|
685 | if (m_profile == Profile::MAIN) |
---|
686 | { |
---|
687 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
---|
688 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
---|
689 | } |
---|
690 | /* XXX: should Main be marked as compatible with still picture? */ |
---|
691 | /* XXX: may be a good idea to refactor the above into a function |
---|
692 | * that chooses the actual compatibility based upon options */ |
---|
693 | |
---|
694 | #if H_MV |
---|
695 | m_cSPS.setUpdateRepFormatFlag ( false ); |
---|
696 | m_cSPS.setSpsInferScalingListFlag ( m_layerId > 0 && m_cVPS->getInDirectDependencyFlag( getLayerIdInVps(), 0 ) ); |
---|
697 | m_cSPS.setSpsScalingListRefLayerId ( 0 ); |
---|
698 | m_cSPS.setSpsExtensionFlag ( true ); |
---|
699 | m_cSPS.setSpsExtensionTypeFlag ( PS_EX_T_MV ,true ); |
---|
700 | #if H_3D |
---|
701 | m_cSPS.setSpsExtensionTypeFlag ( PS_EX_T_3D ,true ); |
---|
702 | #endif |
---|
703 | #endif |
---|
704 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
705 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
706 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
---|
707 | m_cSPS.setMaxCUWidth ( g_uiMaxCUWidth ); |
---|
708 | m_cSPS.setMaxCUHeight ( g_uiMaxCUHeight ); |
---|
709 | m_cSPS.setMaxCUDepth ( g_uiMaxCUDepth ); |
---|
710 | |
---|
711 | Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth ); |
---|
712 | Int log2MinCUSize = 0; |
---|
713 | while(minCUSize > 1) |
---|
714 | { |
---|
715 | minCUSize >>= 1; |
---|
716 | log2MinCUSize++; |
---|
717 | } |
---|
718 | |
---|
719 | m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize); |
---|
720 | m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth); |
---|
721 | |
---|
722 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
723 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
724 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
725 | |
---|
726 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
727 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
728 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
729 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
730 | |
---|
731 | m_cSPS.setTMVPFlagsPresent(false); |
---|
732 | |
---|
733 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
734 | |
---|
735 | Int i; |
---|
736 | |
---|
737 | for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ ) |
---|
738 | { |
---|
739 | m_cSPS.setAMPAcc( i, m_useAMP ); |
---|
740 | //m_cSPS.setAMPAcc( i, 1 ); |
---|
741 | } |
---|
742 | |
---|
743 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
744 | |
---|
745 | #if H_3D_QTLPC |
---|
746 | m_cSPS.setUseQTL( m_bUseQTL ); |
---|
747 | m_cSPS.setUsePC ( m_bUsePC ); |
---|
748 | #endif |
---|
749 | |
---|
750 | for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ ) |
---|
751 | { |
---|
752 | m_cSPS.setAMPAcc(i, 0); |
---|
753 | } |
---|
754 | |
---|
755 | m_cSPS.setBitDepthY( g_bitDepthY ); |
---|
756 | m_cSPS.setBitDepthC( g_bitDepthC ); |
---|
757 | |
---|
758 | m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) ); |
---|
759 | m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) ); |
---|
760 | |
---|
761 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
762 | |
---|
763 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
764 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
---|
765 | for ( i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) |
---|
766 | { |
---|
767 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
768 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
769 | } |
---|
770 | m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma); |
---|
771 | m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma); |
---|
772 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
773 | |
---|
774 | m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 ); |
---|
775 | |
---|
776 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
777 | |
---|
778 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
779 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
780 | { |
---|
781 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
782 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1); |
---|
783 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
784 | pcVUI->setSarWidth(getSarWidth()); |
---|
785 | pcVUI->setSarHeight(getSarHeight()); |
---|
786 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
787 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
788 | #if H_MV |
---|
789 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag() && getLayerId() == 0 ); |
---|
790 | #else |
---|
791 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
792 | #endif |
---|
793 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
794 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
795 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
796 | pcVUI->setColourPrimaries(getColourPrimaries()); |
---|
797 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
798 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
799 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
800 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
801 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
802 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
803 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
---|
804 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
---|
805 | pcVUI->setFieldSeqFlag(false); |
---|
806 | pcVUI->setHrdParametersPresentFlag(false); |
---|
807 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
808 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
809 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
810 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
811 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
812 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
---|
813 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
814 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
815 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
816 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
817 | } |
---|
818 | } |
---|
819 | |
---|
820 | Void TEncTop::xInitPPS() |
---|
821 | { |
---|
822 | #if H_MV |
---|
823 | m_cPPS.setLayerId( getLayerId() ); |
---|
824 | if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 ) |
---|
825 | { |
---|
826 | m_cPPS.setListsModificationPresentFlag( true ); |
---|
827 | } |
---|
828 | m_cPPS.setPPSId( getLayerIdInVps() ); |
---|
829 | m_cPPS.setSPSId( getLayerIdInVps() ); |
---|
830 | #endif |
---|
831 | #if H_3D |
---|
832 | m_cPPS.setDLT( getDLT() ); |
---|
833 | #endif |
---|
834 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
835 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
836 | |
---|
837 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
838 | { |
---|
839 | bUseDQP = true; |
---|
840 | } |
---|
841 | |
---|
842 | if(bUseDQP) |
---|
843 | { |
---|
844 | m_cPPS.setUseDQP(true); |
---|
845 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
846 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
847 | } |
---|
848 | else |
---|
849 | { |
---|
850 | m_cPPS.setUseDQP(false); |
---|
851 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
852 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
853 | } |
---|
854 | |
---|
855 | if ( m_RCEnableRateControl ) |
---|
856 | { |
---|
857 | m_cPPS.setUseDQP(true); |
---|
858 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
859 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
860 | } |
---|
861 | |
---|
862 | m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset ); |
---|
863 | m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset ); |
---|
864 | |
---|
865 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
866 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
---|
867 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
868 | m_cPPS.setUseWP( m_useWeightedPred ); |
---|
869 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
870 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
871 | #if H_MV |
---|
872 | m_cPPS.setNumExtraSliceHeaderBits( 3 ); |
---|
873 | #endif |
---|
874 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
875 | if ( getDeblockingFilterMetric() ) |
---|
876 | { |
---|
877 | m_cPPS.setDeblockingFilterControlPresentFlag (true); |
---|
878 | m_cPPS.setDeblockingFilterOverrideEnabledFlag(true); |
---|
879 | m_cPPS.setPicDisableDeblockingFilterFlag(false); |
---|
880 | m_cPPS.setDeblockingFilterBetaOffsetDiv2(0); |
---|
881 | m_cPPS.setDeblockingFilterTcOffsetDiv2(0); |
---|
882 | } |
---|
883 | else |
---|
884 | { |
---|
885 | m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent ); |
---|
886 | } |
---|
887 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
888 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
889 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
890 | Int histogram[MAX_NUM_REF + 1]; |
---|
891 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
892 | { |
---|
893 | histogram[i]=0; |
---|
894 | } |
---|
895 | for( Int i = 0; i < getGOPSize(); i++ ) |
---|
896 | { |
---|
897 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
---|
898 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
899 | } |
---|
900 | Int maxHist=-1; |
---|
901 | Int bestPos=0; |
---|
902 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
903 | { |
---|
904 | if(histogram[i]>maxHist) |
---|
905 | { |
---|
906 | maxHist=histogram[i]; |
---|
907 | bestPos=i; |
---|
908 | } |
---|
909 | } |
---|
910 | assert(bestPos <= 15); |
---|
911 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
912 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
913 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
914 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
915 | if (m_sliceSegmentMode) |
---|
916 | { |
---|
917 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
---|
918 | } |
---|
919 | if( m_cPPS.getDependentSliceSegmentsEnabledFlag() ) |
---|
920 | { |
---|
921 | Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1; |
---|
922 | m_cSliceEncoder.initCtxMem( NumCtx ); |
---|
923 | for ( UInt st = 0; st < NumCtx; st++ ) |
---|
924 | { |
---|
925 | TEncSbac* ctx = NULL; |
---|
926 | ctx = new TEncSbac; |
---|
927 | ctx->init( &m_cBinCoderCABAC ); |
---|
928 | m_cSliceEncoder.setCtxMem( ctx, st ); |
---|
929 | } |
---|
930 | } |
---|
931 | #if H_3D |
---|
932 | if( m_cVPS->hasCamParInSliceHeader( getViewIndex() ) ) |
---|
933 | { |
---|
934 | m_cPPS.setSliceHeaderExtensionPresentFlag( true ); |
---|
935 | } |
---|
936 | #endif |
---|
937 | } |
---|
938 | |
---|
939 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
940 | Void TEncTop::xInitRPS(Bool isFieldCoding) |
---|
941 | { |
---|
942 | TComReferencePictureSet* rps; |
---|
943 | |
---|
944 | m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1); |
---|
945 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
946 | |
---|
947 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
948 | { |
---|
949 | GOPEntry ge = getGOPEntry(i); |
---|
950 | rps = rpsList->getReferencePictureSet(i); |
---|
951 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
952 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
953 | Int numNeg = 0; |
---|
954 | Int numPos = 0; |
---|
955 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
956 | { |
---|
957 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
958 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
959 | if(ge.m_referencePics[j]>0) |
---|
960 | { |
---|
961 | numPos++; |
---|
962 | } |
---|
963 | else |
---|
964 | { |
---|
965 | numNeg++; |
---|
966 | } |
---|
967 | } |
---|
968 | rps->setNumberOfNegativePictures(numNeg); |
---|
969 | rps->setNumberOfPositivePictures(numPos); |
---|
970 | |
---|
971 | // handle inter RPS intialization from the config file. |
---|
972 | #if AUTO_INTER_RPS |
---|
973 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
974 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
975 | TComReferencePictureSet* RPSRef = rpsList->getReferencePictureSet(i-1); // get the reference RPS |
---|
976 | |
---|
977 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
978 | { |
---|
979 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
980 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
981 | |
---|
982 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
983 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
984 | Int count=0; |
---|
985 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
986 | { |
---|
987 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
988 | rps->setRefIdc(j, 0); |
---|
989 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
990 | { |
---|
991 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
992 | { |
---|
993 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
994 | count++; |
---|
995 | break; |
---|
996 | } |
---|
997 | } |
---|
998 | } |
---|
999 | if (count != rps->getNumberOfPictures()) |
---|
1000 | { |
---|
1001 | printf("Warning: Unable fully predict all delta POCs using the reference RPS index given in the config file. Setting Inter RPS to false for this RPS.\n"); |
---|
1002 | rps->setInterRPSPrediction(0); |
---|
1003 | } |
---|
1004 | } |
---|
1005 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
1006 | { |
---|
1007 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
1008 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1009 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1010 | { |
---|
1011 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
1012 | } |
---|
1013 | #if WRITE_BACK |
---|
1014 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
1015 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
1016 | numNeg = 0; |
---|
1017 | numPos = 0; |
---|
1018 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
1019 | |
---|
1020 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1021 | { |
---|
1022 | if (ge.m_refIdc[j]) |
---|
1023 | { |
---|
1024 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1025 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1026 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1027 | if (deltaPOC<0) |
---|
1028 | { |
---|
1029 | numNeg++; |
---|
1030 | } |
---|
1031 | else |
---|
1032 | { |
---|
1033 | numPos++; |
---|
1034 | } |
---|
1035 | } |
---|
1036 | } |
---|
1037 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
1038 | { |
---|
1039 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1040 | rps->setNumberOfNegativePictures(numNeg); |
---|
1041 | rps->setNumberOfPictures(numNeg+numPos); |
---|
1042 | } |
---|
1043 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
1044 | { |
---|
1045 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1046 | rps->setNumberOfPositivePictures(numPos); |
---|
1047 | rps->setNumberOfPictures(numNeg+numPos); |
---|
1048 | } |
---|
1049 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
1050 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
1051 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
1052 | // check if Delta POC and Used are the same |
---|
1053 | // print warning if they are not. |
---|
1054 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1055 | { |
---|
1056 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
1057 | { |
---|
1058 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
1059 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
1060 | } |
---|
1061 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
1062 | { |
---|
1063 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1064 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
1065 | } |
---|
1066 | } |
---|
1067 | #endif |
---|
1068 | } |
---|
1069 | #else |
---|
1070 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
1071 | if (ge.m_interRPSPrediction) |
---|
1072 | { |
---|
1073 | rps->setDeltaRIdxMinus1(0); |
---|
1074 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
1075 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1076 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1077 | { |
---|
1078 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
1079 | } |
---|
1080 | #if WRITE_BACK |
---|
1081 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
1082 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
1083 | numNeg = 0; |
---|
1084 | numPos = 0; |
---|
1085 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-1); |
---|
1086 | |
---|
1087 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1088 | { |
---|
1089 | if (ge.m_refIdc[j]) |
---|
1090 | { |
---|
1091 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1092 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1093 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1094 | if (deltaPOC<0) |
---|
1095 | { |
---|
1096 | numNeg++; |
---|
1097 | } |
---|
1098 | else |
---|
1099 | { |
---|
1100 | numPos++; |
---|
1101 | } |
---|
1102 | } |
---|
1103 | } |
---|
1104 | rps->setNumberOfNegativePictures(numNeg); |
---|
1105 | rps->setNumberOfPositivePictures(numPos); |
---|
1106 | rps->sortDeltaPOC(); |
---|
1107 | #endif |
---|
1108 | } |
---|
1109 | #endif //INTER_RPS_AUTO |
---|
1110 | } |
---|
1111 | //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file. |
---|
1112 | //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. |
---|
1113 | if (isFieldCoding) |
---|
1114 | { |
---|
1115 | rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs); |
---|
1116 | rps->setNumberOfPictures(1); |
---|
1117 | rps->setNumberOfNegativePictures(1); |
---|
1118 | rps->setNumberOfPositivePictures(0); |
---|
1119 | rps->setNumberOfLongtermPictures(0); |
---|
1120 | rps->setDeltaPOC(0,-1); |
---|
1121 | rps->setPOC(0,0); |
---|
1122 | rps->setUsed(0,true); |
---|
1123 | rps->setInterRPSPrediction(false); |
---|
1124 | rps->setDeltaRIdxMinus1(0); |
---|
1125 | rps->setDeltaRPS(0); |
---|
1126 | rps->setNumRefIdc(0); |
---|
1127 | } |
---|
1128 | } |
---|
1129 | |
---|
1130 | // This is a function that |
---|
1131 | // determines what Reference Picture Set to use |
---|
1132 | // for a specific slice (with POC = POCCurr) |
---|
1133 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
1134 | { |
---|
1135 | #if H_MV |
---|
1136 | if( slice->getRapPicFlag() == true && getLayerId() > 0 && POCCurr == 0 ) |
---|
1137 | { |
---|
1138 | TComReferencePictureSet* rps = slice->getLocalRPS(); |
---|
1139 | rps->setNumberOfNegativePictures(0); |
---|
1140 | rps->setNumberOfPositivePictures(0); |
---|
1141 | rps->setNumberOfLongtermPictures(0); |
---|
1142 | rps->setNumberOfPictures(0); |
---|
1143 | slice->setRPS(rps); |
---|
1144 | } |
---|
1145 | else |
---|
1146 | { |
---|
1147 | #endif |
---|
1148 | slice->setRPSidx(GOPid); |
---|
1149 | |
---|
1150 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1151 | { |
---|
1152 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1153 | { |
---|
1154 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1155 | if(POCIndex == 0) |
---|
1156 | { |
---|
1157 | POCIndex = m_uiIntraPeriod; |
---|
1158 | } |
---|
1159 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1160 | { |
---|
1161 | slice->setRPSidx(extraNum); |
---|
1162 | } |
---|
1163 | } |
---|
1164 | else |
---|
1165 | { |
---|
1166 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1167 | { |
---|
1168 | slice->setRPSidx(extraNum); |
---|
1169 | } |
---|
1170 | } |
---|
1171 | } |
---|
1172 | if(POCCurr == 1 && slice->getPic()->isField()) |
---|
1173 | { |
---|
1174 | slice->setRPSidx(m_iGOPSize+m_extraRPSs); |
---|
1175 | } |
---|
1176 | |
---|
1177 | slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1178 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1179 | #if H_MV |
---|
1180 | } |
---|
1181 | #endif |
---|
1182 | |
---|
1183 | } |
---|
1184 | |
---|
1185 | Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
1186 | { |
---|
1187 | int rpsIdx = GOPid; |
---|
1188 | |
---|
1189 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1190 | { |
---|
1191 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1192 | { |
---|
1193 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1194 | if(POCIndex == 0) |
---|
1195 | { |
---|
1196 | POCIndex = m_uiIntraPeriod; |
---|
1197 | } |
---|
1198 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1199 | { |
---|
1200 | rpsIdx = extraNum; |
---|
1201 | } |
---|
1202 | } |
---|
1203 | else |
---|
1204 | { |
---|
1205 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1206 | { |
---|
1207 | rpsIdx = extraNum; |
---|
1208 | } |
---|
1209 | } |
---|
1210 | } |
---|
1211 | |
---|
1212 | return rpsIdx; |
---|
1213 | } |
---|
1214 | |
---|
1215 | Void TEncTop::xInitPPSforTiles() |
---|
1216 | { |
---|
1217 | m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr ); |
---|
1218 | m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1219 | m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
1220 | if( m_iUniformSpacingIdr == 0 ) |
---|
1221 | { |
---|
1222 | m_cPPS.setColumnWidth( m_puiColumnWidth ); |
---|
1223 | m_cPPS.setRowHeight( m_puiRowHeight ); |
---|
1224 | } |
---|
1225 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
1226 | |
---|
1227 | // # substreams is "per tile" when tiles are independent. |
---|
1228 | if (m_iWaveFrontSynchro |
---|
1229 | ) |
---|
1230 | { |
---|
1231 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)); |
---|
1232 | } |
---|
1233 | } |
---|
1234 | |
---|
1235 | Void TEncCfg::xCheckGSParameters() |
---|
1236 | { |
---|
1237 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
1238 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
1239 | UInt uiCummulativeColumnWidth = 0; |
---|
1240 | UInt uiCummulativeRowHeight = 0; |
---|
1241 | |
---|
1242 | //check the column relative parameters |
---|
1243 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1244 | { |
---|
1245 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1246 | exit( EXIT_FAILURE ); |
---|
1247 | } |
---|
1248 | |
---|
1249 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1250 | { |
---|
1251 | printf( "The current picture can not have so many columns.\n" ); |
---|
1252 | exit( EXIT_FAILURE ); |
---|
1253 | } |
---|
1254 | |
---|
1255 | if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1256 | { |
---|
1257 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1258 | { |
---|
1259 | uiCummulativeColumnWidth += m_puiColumnWidth[i]; |
---|
1260 | } |
---|
1261 | |
---|
1262 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1263 | { |
---|
1264 | printf( "The width of the column is too large.\n" ); |
---|
1265 | exit( EXIT_FAILURE ); |
---|
1266 | } |
---|
1267 | } |
---|
1268 | |
---|
1269 | //check the row relative parameters |
---|
1270 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1271 | { |
---|
1272 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1273 | exit( EXIT_FAILURE ); |
---|
1274 | } |
---|
1275 | |
---|
1276 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1277 | { |
---|
1278 | printf( "The current picture can not have so many rows.\n" ); |
---|
1279 | exit( EXIT_FAILURE ); |
---|
1280 | } |
---|
1281 | |
---|
1282 | if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1283 | { |
---|
1284 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1285 | uiCummulativeRowHeight += m_puiRowHeight[i]; |
---|
1286 | |
---|
1287 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1288 | { |
---|
1289 | printf( "The height of the row is too large.\n" ); |
---|
1290 | exit( EXIT_FAILURE ); |
---|
1291 | } |
---|
1292 | } |
---|
1293 | } |
---|
1294 | #if H_MV |
---|
1295 | Void TEncTop::printSummary( Int numAllPicCoded, Bool isField ) |
---|
1296 | { |
---|
1297 | assert ( !isField ); // Multiview and field coding need to be further unified |
---|
1298 | assert (numAllPicCoded == m_cAnalyzeAll.getNumPic()); |
---|
1299 | |
---|
1300 | //--CFG_KDY |
---|
1301 | m_cAnalyzeAll.setFrmRate( getFrameRate() ); |
---|
1302 | m_cAnalyzeI.setFrmRate( getFrameRate() ); |
---|
1303 | m_cAnalyzeP.setFrmRate( getFrameRate() ); |
---|
1304 | m_cAnalyzeB.setFrmRate( getFrameRate() ); |
---|
1305 | |
---|
1306 | //-- all |
---|
1307 | printf( "\n\nSUMMARY ------------------------------------------- LayerId %2d\n", m_layerId ); |
---|
1308 | |
---|
1309 | m_cAnalyzeAll.printOut('a'); |
---|
1310 | |
---|
1311 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
1312 | m_cAnalyzeI.printOut('i'); |
---|
1313 | |
---|
1314 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
1315 | m_cAnalyzeP.printOut('p'); |
---|
1316 | |
---|
1317 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
1318 | m_cAnalyzeB.printOut('b'); |
---|
1319 | |
---|
1320 | #if _SUMMARY_OUT_ |
---|
1321 | m_cAnalyzeAll.printSummaryOut(); |
---|
1322 | #endif |
---|
1323 | #if _SUMMARY_PIC_ |
---|
1324 | m_cAnalyzeI.printSummary('I'); |
---|
1325 | m_cAnalyzeP.printSummary('P'); |
---|
1326 | m_cAnalyzeB.printSummary('B'); |
---|
1327 | #endif |
---|
1328 | } |
---|
1329 | |
---|
1330 | Int TEncTop::getFrameId(Int iGOPid) |
---|
1331 | { |
---|
1332 | if(m_iPOCLast == 0) |
---|
1333 | { |
---|
1334 | return(0 ); |
---|
1335 | } |
---|
1336 | else |
---|
1337 | { |
---|
1338 | return m_iPOCLast -m_iNumPicRcvd+ getGOPEntry(iGOPid).m_POC ; |
---|
1339 | } |
---|
1340 | } |
---|
1341 | |
---|
1342 | TComPic* TEncTop::getPic( Int poc ) |
---|
1343 | { |
---|
1344 | TComList<TComPic*>* listPic = getListPic(); |
---|
1345 | TComPic* pcPic = NULL; |
---|
1346 | for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++) |
---|
1347 | { |
---|
1348 | if( (*it)->getPOC() == poc ) |
---|
1349 | { |
---|
1350 | pcPic = *it ; |
---|
1351 | break ; |
---|
1352 | } |
---|
1353 | } |
---|
1354 | return pcPic; |
---|
1355 | } |
---|
1356 | #endif |
---|
1357 | |
---|
1358 | #if H_3D_VSO |
---|
1359 | Void TEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset ) |
---|
1360 | { |
---|
1361 | TRenModel* rendererModel = m_cRdCost.getRenModel(); |
---|
1362 | rendererModel->setupPart( iHorOffset, std::min( (Int) g_uiMaxCUHeight, (Int) ( m_iSourceHeight - iHorOffset ) )) ; |
---|
1363 | |
---|
1364 | Int iEncViewSIdx = m_cameraParameters->getBaseId2SortedId()[ iEncViewIdx ]; |
---|
1365 | |
---|
1366 | // setup base views |
---|
1367 | Int iNumOfBV = m_renderModelParameters->getNumOfBaseViewsForView( iEncViewSIdx, iEncContent ); |
---|
1368 | |
---|
1369 | for (Int iCurView = 0; iCurView < iNumOfBV; iCurView++ ) |
---|
1370 | { |
---|
1371 | Int iBaseViewSIdx; |
---|
1372 | Int iVideoDistMode; |
---|
1373 | Int iDepthDistMode; |
---|
1374 | |
---|
1375 | m_renderModelParameters->getBaseViewData( iEncViewSIdx, iEncContent, iCurView, iBaseViewSIdx, iVideoDistMode, iDepthDistMode ); |
---|
1376 | |
---|
1377 | AOT( iVideoDistMode < 0 || iVideoDistMode > 2 ); |
---|
1378 | |
---|
1379 | Int iBaseViewIdx = m_cameraParameters->getBaseSortedId2Id()[ iBaseViewSIdx ]; |
---|
1380 | |
---|
1381 | TComPicYuv* pcPicYuvVideoRec = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, true ); |
---|
1382 | TComPicYuv* pcPicYuvDepthRec = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, true ); |
---|
1383 | TComPicYuv* pcPicYuvVideoOrg = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, false ); |
---|
1384 | TComPicYuv* pcPicYuvDepthOrg = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, false ); |
---|
1385 | |
---|
1386 | TComPicYuv* pcPicYuvVideoRef = ( iVideoDistMode == 2 ) ? pcPicYuvVideoOrg : NULL; |
---|
1387 | TComPicYuv* pcPicYuvDepthRef = ( iDepthDistMode == 2 ) ? pcPicYuvDepthOrg : NULL; |
---|
1388 | |
---|
1389 | TComPicYuv* pcPicYuvVideoTest = ( iVideoDistMode == 0 ) ? pcPicYuvVideoOrg : pcPicYuvVideoRec; |
---|
1390 | TComPicYuv* pcPicYuvDepthTest = ( iDepthDistMode == 0 ) ? pcPicYuvDepthOrg : pcPicYuvDepthRec; |
---|
1391 | |
---|
1392 | AOT( (iVideoDistMode == 2) != (pcPicYuvVideoRef != NULL) ); |
---|
1393 | AOT( (iDepthDistMode == 2) != (pcPicYuvDepthRef != NULL) ); |
---|
1394 | AOT( pcPicYuvDepthTest == NULL ); |
---|
1395 | AOT( pcPicYuvVideoTest == NULL ); |
---|
1396 | |
---|
1397 | rendererModel->setBaseView( iBaseViewSIdx, pcPicYuvVideoTest, pcPicYuvDepthTest, pcPicYuvVideoRef, pcPicYuvDepthRef ); |
---|
1398 | } |
---|
1399 | |
---|
1400 | rendererModel->setErrorMode( iEncViewSIdx, iEncContent, 0 ); |
---|
1401 | // setup virtual views |
---|
1402 | Int iNumOfSV = m_renderModelParameters->getNumOfModelsForView( iEncViewSIdx, iEncContent ); |
---|
1403 | for (Int iCurView = 0; iCurView < iNumOfSV; iCurView++ ) |
---|
1404 | { |
---|
1405 | Int iOrgRefBaseViewSIdx; |
---|
1406 | Int iLeftBaseViewSIdx; |
---|
1407 | Int iRightBaseViewSIdx; |
---|
1408 | Int iSynthViewRelNum; |
---|
1409 | Int iModelNum; |
---|
1410 | Int iBlendMode; |
---|
1411 | m_renderModelParameters->getSingleModelData(iEncViewSIdx, iEncContent, iCurView, iModelNum, iBlendMode,iLeftBaseViewSIdx, iRightBaseViewSIdx, iOrgRefBaseViewSIdx, iSynthViewRelNum ); |
---|
1412 | |
---|
1413 | Int iLeftBaseViewIdx = -1; |
---|
1414 | Int iRightBaseViewIdx = -1; |
---|
1415 | |
---|
1416 | TComPicYuv* pcPicYuvOrgRef = NULL; |
---|
1417 | Int** ppiShiftLUTLeft = NULL; |
---|
1418 | Int** ppiShiftLUTRight = NULL; |
---|
1419 | Int** ppiBaseShiftLUTLeft = NULL; |
---|
1420 | Int** ppiBaseShiftLUTRight = NULL; |
---|
1421 | |
---|
1422 | |
---|
1423 | Int iDistToLeft = -1; |
---|
1424 | |
---|
1425 | Int iSynthViewIdx = m_cameraParameters->synthRelNum2Idx( iSynthViewRelNum ); |
---|
1426 | |
---|
1427 | if ( iLeftBaseViewSIdx != -1 ) |
---|
1428 | { |
---|
1429 | iLeftBaseViewIdx = m_cameraParameters->getBaseSortedId2Id() [ iLeftBaseViewSIdx ]; |
---|
1430 | ppiShiftLUTLeft = m_cameraParameters->getSynthViewShiftLUTI()[ iLeftBaseViewIdx ][ iSynthViewIdx ]; |
---|
1431 | } |
---|
1432 | |
---|
1433 | if ( iRightBaseViewSIdx != -1 ) |
---|
1434 | { |
---|
1435 | iRightBaseViewIdx = m_cameraParameters->getBaseSortedId2Id() [iRightBaseViewSIdx ]; |
---|
1436 | ppiShiftLUTRight = m_cameraParameters->getSynthViewShiftLUTI()[ iRightBaseViewIdx ][ iSynthViewIdx ]; |
---|
1437 | } |
---|
1438 | |
---|
1439 | if ( iRightBaseViewSIdx != -1 && iLeftBaseViewSIdx != -1 ) |
---|
1440 | { |
---|
1441 | iDistToLeft = m_cameraParameters->getRelDistLeft( iSynthViewIdx , iLeftBaseViewIdx, iRightBaseViewIdx); |
---|
1442 | ppiBaseShiftLUTLeft = m_cameraParameters->getBaseViewShiftLUTI() [ iLeftBaseViewIdx ][ iRightBaseViewIdx ]; |
---|
1443 | ppiBaseShiftLUTRight = m_cameraParameters->getBaseViewShiftLUTI() [ iRightBaseViewIdx ][ iLeftBaseViewIdx ]; |
---|
1444 | |
---|
1445 | } |
---|
1446 | |
---|
1447 | if ( iOrgRefBaseViewSIdx != -1 ) |
---|
1448 | { |
---|
1449 | pcPicYuvOrgRef = m_ivPicLists->getPicYuv( m_cameraParameters->getBaseSortedId2Id()[ iOrgRefBaseViewSIdx ] , false, iPoc, false ); |
---|
1450 | AOF ( pcPicYuvOrgRef ); |
---|
1451 | } |
---|
1452 | |
---|
1453 | rendererModel->setSingleModel( iModelNum, ppiShiftLUTLeft, ppiBaseShiftLUTLeft, ppiShiftLUTRight, ppiBaseShiftLUTRight, iDistToLeft, pcPicYuvOrgRef ); |
---|
1454 | } |
---|
1455 | } |
---|
1456 | #endif |
---|
1457 | //! \} |
---|