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-2015, 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 | #include "TLibCommon/TComChromaFormat.h" |
---|
42 | #if FAST_BIT_EST |
---|
43 | #include "TLibCommon/ContextModel.h" |
---|
44 | #endif |
---|
45 | #if NH_MV |
---|
46 | #include "../../App/TAppEncoder/TAppEncTop.h" |
---|
47 | #endif |
---|
48 | |
---|
49 | //! \ingroup TLibEncoder |
---|
50 | //! \{ |
---|
51 | |
---|
52 | // ==================================================================================================================== |
---|
53 | // Constructor / destructor / create / destroy |
---|
54 | // ==================================================================================================================== |
---|
55 | |
---|
56 | TEncTop::TEncTop() |
---|
57 | { |
---|
58 | m_iPOCLast = -1; |
---|
59 | m_iNumPicRcvd = 0; |
---|
60 | m_uiNumAllPicCoded = 0; |
---|
61 | m_pppcRDSbacCoder = NULL; |
---|
62 | m_pppcBinCoderCABAC = NULL; |
---|
63 | m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC ); |
---|
64 | #if ENC_DEC_TRACE |
---|
65 | if (g_hTrace == NULL) |
---|
66 | { |
---|
67 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
68 | } |
---|
69 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
70 | g_nSymbolCounter = 0; |
---|
71 | #endif |
---|
72 | |
---|
73 | m_iMaxRefPicNum = 0; |
---|
74 | |
---|
75 | #if FAST_BIT_EST |
---|
76 | ContextModel::buildNextStateTable(); |
---|
77 | #endif |
---|
78 | #if NH_MV |
---|
79 | m_ivPicLists = NULL; |
---|
80 | #endif |
---|
81 | #if H_3D_IC |
---|
82 | m_aICEnableCandidate = NULL; |
---|
83 | m_aICEnableNum = NULL; |
---|
84 | #endif |
---|
85 | #if NH_3D |
---|
86 | m_cCavlcCoder.setEncTop(this); |
---|
87 | #endif |
---|
88 | |
---|
89 | } |
---|
90 | |
---|
91 | TEncTop::~TEncTop() |
---|
92 | { |
---|
93 | #if ENC_DEC_TRACE |
---|
94 | if (g_hTrace != stdout) |
---|
95 | { |
---|
96 | fclose( g_hTrace ); |
---|
97 | } |
---|
98 | #endif |
---|
99 | } |
---|
100 | |
---|
101 | Void TEncTop::create () |
---|
102 | { |
---|
103 | #if !NH_MV |
---|
104 | // initialize global variables |
---|
105 | initROM(); |
---|
106 | #endif |
---|
107 | |
---|
108 | // create processing unit classes |
---|
109 | m_cGOPEncoder. create( ); |
---|
110 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth ); |
---|
111 | m_cCuEncoder. create( m_maxTotalCUDepth, m_maxCUWidth, m_maxCUHeight, m_chromaFormatIDC ); |
---|
112 | if (m_bUseSAO) |
---|
113 | { |
---|
114 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA], m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] ); |
---|
115 | m_cEncSAO.createEncData(getSaoCtuBoundary()); |
---|
116 | } |
---|
117 | #if ADAPTIVE_QP_SELECTION |
---|
118 | if (m_bUseAdaptQpSelect) |
---|
119 | { |
---|
120 | m_cTrQuant.initSliceQpDelta(); |
---|
121 | } |
---|
122 | #endif |
---|
123 | |
---|
124 | m_cLoopFilter.create( m_maxTotalCUDepth ); |
---|
125 | |
---|
126 | if ( m_RCEnableRateControl ) |
---|
127 | { |
---|
128 | #if KWU_RC_MADPRED_E0227 |
---|
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, getLayerId() ); |
---|
131 | #else |
---|
132 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
133 | m_maxCUWidth, m_maxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
---|
134 | #endif |
---|
135 | } |
---|
136 | |
---|
137 | m_pppcRDSbacCoder = new TEncSbac** [m_maxTotalCUDepth+1]; |
---|
138 | #if FAST_BIT_EST |
---|
139 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [m_maxTotalCUDepth+1]; |
---|
140 | #else |
---|
141 | m_pppcBinCoderCABAC = new TEncBinCABAC** [m_maxTotalCUDepth+1]; |
---|
142 | #endif |
---|
143 | |
---|
144 | for ( Int iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
145 | { |
---|
146 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
147 | #if FAST_BIT_EST |
---|
148 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
149 | #else |
---|
150 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
151 | #endif |
---|
152 | |
---|
153 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
154 | { |
---|
155 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
156 | #if FAST_BIT_EST |
---|
157 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
158 | #else |
---|
159 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
160 | #endif |
---|
161 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | Void TEncTop::destroy () |
---|
167 | { |
---|
168 | // destroy processing unit classes |
---|
169 | m_cGOPEncoder. destroy(); |
---|
170 | m_cSliceEncoder. destroy(); |
---|
171 | m_cCuEncoder. destroy(); |
---|
172 | m_cEncSAO. destroyEncData(); |
---|
173 | m_cEncSAO. destroy(); |
---|
174 | m_cLoopFilter. destroy(); |
---|
175 | m_cRateCtrl. destroy(); |
---|
176 | Int iDepth; |
---|
177 | for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
178 | { |
---|
179 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
180 | { |
---|
181 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
182 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
187 | { |
---|
188 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
189 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
190 | } |
---|
191 | |
---|
192 | delete [] m_pppcRDSbacCoder; |
---|
193 | delete [] m_pppcBinCoderCABAC; |
---|
194 | |
---|
195 | #if !NH_MV |
---|
196 | // destroy ROM |
---|
197 | destroyROM(); |
---|
198 | #endif |
---|
199 | |
---|
200 | return; |
---|
201 | } |
---|
202 | |
---|
203 | #if KWU_RC_MADPRED_E0227 |
---|
204 | Void TEncTop::init(TAppEncTop* pcTAppEncTop, Bool isFieldCoding) |
---|
205 | #else |
---|
206 | Void TEncTop::init(Bool isFieldCoding) |
---|
207 | #endif |
---|
208 | { |
---|
209 | // initialize SPS |
---|
210 | #if H_3D |
---|
211 | // Assuming that all PPS indirectly refer to the same VPS via different SPS |
---|
212 | m_cSPS.setVPS(m_cVPS); |
---|
213 | #endif |
---|
214 | xInitSPS(); |
---|
215 | xInitVPS(); |
---|
216 | |
---|
217 | m_cRdCost.setCostMode(m_costMode); |
---|
218 | |
---|
219 | #if NH_MV |
---|
220 | // This seems to be incorrect, but irrelevant for the MV-HEVC |
---|
221 | *(m_cVPS->getPTL()) = *m_cSPS.getPTL(); |
---|
222 | m_cVPS->getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
223 | #endif |
---|
224 | // initialize PPS |
---|
225 | xInitPPS(); |
---|
226 | xInitRPS(isFieldCoding); |
---|
227 | |
---|
228 | xInitPPSforTiles(); |
---|
229 | #if H_3D_IC |
---|
230 | m_aICEnableCandidate = new Int[ 10 ]; |
---|
231 | m_aICEnableNum = new Int[ 10 ]; |
---|
232 | |
---|
233 | for(int i=0;i<10;i++) |
---|
234 | { |
---|
235 | m_aICEnableCandidate[i]=0; |
---|
236 | m_aICEnableNum[i]=0; |
---|
237 | } |
---|
238 | #endif |
---|
239 | |
---|
240 | // initialize processing unit classes |
---|
241 | m_cGOPEncoder. init( this ); |
---|
242 | m_cSliceEncoder.init( this ); |
---|
243 | m_cCuEncoder. init( this ); |
---|
244 | |
---|
245 | #if KWU_RC_MADPRED_E0227 |
---|
246 | m_pcTAppEncTop = pcTAppEncTop; |
---|
247 | #endif |
---|
248 | // initialize transform & quantization class |
---|
249 | m_pcCavlcCoder = getCavlcCoder(); |
---|
250 | |
---|
251 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
---|
252 | m_useRDOQ, |
---|
253 | m_useRDOQTS, |
---|
254 | #if T0196_SELECTIVE_RDOQ |
---|
255 | m_useSelectiveRDOQ, |
---|
256 | #endif |
---|
257 | true |
---|
258 | ,m_useTransformSkipFast |
---|
259 | #if ADAPTIVE_QP_SELECTION |
---|
260 | ,m_bUseAdaptQpSelect |
---|
261 | #endif |
---|
262 | ); |
---|
263 | |
---|
264 | // initialize encoder search class |
---|
265 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
266 | |
---|
267 | m_iMaxRefPicNum = 0; |
---|
268 | |
---|
269 | xInitScalingLists(); |
---|
270 | } |
---|
271 | |
---|
272 | Void TEncTop::xInitScalingLists() |
---|
273 | { |
---|
274 | // Initialise scaling lists |
---|
275 | // The encoder will only use the SPS scaling lists. The PPS will never be marked present. |
---|
276 | const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] = |
---|
277 | { |
---|
278 | m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA), |
---|
279 | m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA) |
---|
280 | }; |
---|
281 | if(getUseScalingListId() == SCALING_LIST_OFF) |
---|
282 | { |
---|
283 | getTrQuant()->setFlatScalingList(maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
284 | getTrQuant()->setUseScalingList(false); |
---|
285 | m_cSPS.setScalingListPresentFlag(false); |
---|
286 | m_cPPS.setScalingListPresentFlag(false); |
---|
287 | } |
---|
288 | else if(getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
289 | { |
---|
290 | m_cSPS.getScalingList().setDefaultScalingList (); |
---|
291 | m_cSPS.setScalingListPresentFlag(false); |
---|
292 | m_cPPS.setScalingListPresentFlag(false); |
---|
293 | |
---|
294 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
295 | getTrQuant()->setUseScalingList(true); |
---|
296 | } |
---|
297 | else if(getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
298 | { |
---|
299 | m_cSPS.getScalingList().setDefaultScalingList (); |
---|
300 | if(m_cSPS.getScalingList().xParseScalingList(getScalingListFile())) |
---|
301 | { |
---|
302 | Bool bParsedScalingList=false; // Use of boolean so that assertion outputs useful string |
---|
303 | assert(bParsedScalingList); |
---|
304 | exit(1); |
---|
305 | } |
---|
306 | m_cSPS.getScalingList().checkDcOfMatrix(); |
---|
307 | m_cSPS.setScalingListPresentFlag(m_cSPS.getScalingList().checkDefaultScalingList()); |
---|
308 | m_cPPS.setScalingListPresentFlag(false); |
---|
309 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
310 | getTrQuant()->setUseScalingList(true); |
---|
311 | } |
---|
312 | else |
---|
313 | { |
---|
314 | printf("error : ScalingList == %d not supported\n",getUseScalingListId()); |
---|
315 | assert(0); |
---|
316 | } |
---|
317 | |
---|
318 | if (getUseScalingListId() != SCALING_LIST_OFF) |
---|
319 | { |
---|
320 | // Prepare delta's: |
---|
321 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
322 | { |
---|
323 | const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries. |
---|
324 | |
---|
325 | for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep) |
---|
326 | { |
---|
327 | m_cSPS.getScalingList().checkPredMode( sizeId, listId ); |
---|
328 | } |
---|
329 | } |
---|
330 | } |
---|
331 | } |
---|
332 | |
---|
333 | // ==================================================================================================================== |
---|
334 | // Public member functions |
---|
335 | // ==================================================================================================================== |
---|
336 | |
---|
337 | #if NH_MV |
---|
338 | Void TEncTop::initNewPic( TComPicYuv* pcPicYuvOrg ) |
---|
339 | { |
---|
340 | TComPic* pcPicCurr = NULL; |
---|
341 | |
---|
342 | // get original YUV |
---|
343 | xGetNewPicBuffer( pcPicCurr ); |
---|
344 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
345 | |
---|
346 | // compute image characteristics |
---|
347 | if ( getUseAdaptiveQP() ) |
---|
348 | { |
---|
349 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
350 | } |
---|
351 | #if NH_MV |
---|
352 | pcPicCurr->setLayerId( getLayerId()); |
---|
353 | #endif |
---|
354 | #if NH_3D |
---|
355 | pcPicCurr->setScaleOffset( m_cameraParameters->getCodedScale(), m_cameraParameters->getCodedOffset() ); |
---|
356 | #endif |
---|
357 | } |
---|
358 | #endif |
---|
359 | |
---|
360 | Void TEncTop::deletePicBuffer() |
---|
361 | { |
---|
362 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
363 | Int iSize = Int( m_cListPic.size() ); |
---|
364 | |
---|
365 | for ( Int i = 0; i < iSize; i++ ) |
---|
366 | { |
---|
367 | TComPic* pcPic = *(iterPic++); |
---|
368 | |
---|
369 | pcPic->destroy(); |
---|
370 | delete pcPic; |
---|
371 | pcPic = NULL; |
---|
372 | } |
---|
373 | } |
---|
374 | |
---|
375 | /** |
---|
376 | - Application has picture buffer list with size of GOP + 1 |
---|
377 | - Picture buffer list acts like as ring buffer |
---|
378 | - End of the list has the latest picture |
---|
379 | . |
---|
380 | \param flush cause encoder to encode a partial GOP |
---|
381 | \param pcPicYuvOrg original YUV picture |
---|
382 | \param pcPicYuvTrueOrg |
---|
383 | \param snrCSC |
---|
384 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
385 | \retval accessUnitsOut list of output access units |
---|
386 | \retval iNumEncoded number of encoded pictures |
---|
387 | */ |
---|
388 | #if NH_MV |
---|
389 | Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Int gopId ) |
---|
390 | { |
---|
391 | #else |
---|
392 | Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
393 | { |
---|
394 | #endif |
---|
395 | #if NH_3D |
---|
396 | TComPic* picLastCoded = getPic( getGOPEncoder()->getPocLastCoded() ); |
---|
397 | if( picLastCoded ) |
---|
398 | { |
---|
399 | picLastCoded->compressMotion(1); |
---|
400 | } |
---|
401 | #endif |
---|
402 | #if NH_MV |
---|
403 | if( gopId == 0) |
---|
404 | { |
---|
405 | m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
406 | #else |
---|
407 | if (pcPicYuvOrg != NULL) |
---|
408 | { |
---|
409 | // get original YUV |
---|
410 | TComPic* pcPicCurr = NULL; |
---|
411 | |
---|
412 | xGetNewPicBuffer( pcPicCurr ); |
---|
413 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
414 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
---|
415 | |
---|
416 | // compute image characteristics |
---|
417 | if ( getUseAdaptiveQP() ) |
---|
418 | { |
---|
419 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
420 | } |
---|
421 | } |
---|
422 | |
---|
423 | if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0))) |
---|
424 | { |
---|
425 | iNumEncoded = 0; |
---|
426 | return; |
---|
427 | } |
---|
428 | #endif |
---|
429 | if ( m_RCEnableRateControl ) |
---|
430 | { |
---|
431 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
432 | } |
---|
433 | #if NH_MV |
---|
434 | } |
---|
435 | m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE, gopId); |
---|
436 | |
---|
437 | if( gopId + 1 == m_cGOPEncoder.getGOPSize() ) |
---|
438 | { |
---|
439 | #else |
---|
440 | // compress GOP |
---|
441 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
---|
442 | #endif |
---|
443 | if ( m_RCEnableRateControl ) |
---|
444 | { |
---|
445 | m_cRateCtrl.destroyRCGOP(); |
---|
446 | } |
---|
447 | |
---|
448 | iNumEncoded = m_iNumPicRcvd; |
---|
449 | m_iNumPicRcvd = 0; |
---|
450 | m_uiNumAllPicCoded += iNumEncoded; |
---|
451 | #if NH_MV |
---|
452 | } |
---|
453 | #endif |
---|
454 | } |
---|
455 | |
---|
456 | /**------------------------------------------------ |
---|
457 | Separate interlaced frame into two fields |
---|
458 | -------------------------------------------------**/ |
---|
459 | Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop) |
---|
460 | { |
---|
461 | if (!isTop) |
---|
462 | { |
---|
463 | org += stride; |
---|
464 | } |
---|
465 | for (Int y = 0; y < height>>1; y++) |
---|
466 | { |
---|
467 | for (Int x = 0; x < width; x++) |
---|
468 | { |
---|
469 | dstField[x] = org[x]; |
---|
470 | } |
---|
471 | |
---|
472 | dstField += stride; |
---|
473 | org += stride*2; |
---|
474 | } |
---|
475 | |
---|
476 | } |
---|
477 | #if NH_MV |
---|
478 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff, Int gopId ) |
---|
479 | { |
---|
480 | assert( 0 ); // Field coding and multiview need to be further harmonized. |
---|
481 | } |
---|
482 | #else |
---|
483 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff) |
---|
484 | { |
---|
485 | iNumEncoded = 0; |
---|
486 | |
---|
487 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
488 | { |
---|
489 | if (pcPicYuvOrg) |
---|
490 | { |
---|
491 | |
---|
492 | /* -- field initialization -- */ |
---|
493 | const Bool isTopField=isTff==(fieldNum==0); |
---|
494 | |
---|
495 | TComPic *pcField; |
---|
496 | xGetNewPicBuffer( pcField ); |
---|
497 | pcField->setReconMark (false); // where is this normally? |
---|
498 | |
---|
499 | if (fieldNum==1) // where is this normally? |
---|
500 | { |
---|
501 | TComPicYuv* rpcPicYuvRec; |
---|
502 | |
---|
503 | // org. buffer |
---|
504 | if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize. |
---|
505 | { |
---|
506 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
507 | } |
---|
508 | else |
---|
509 | { |
---|
510 | rpcPicYuvRec = new TComPicYuv; |
---|
511 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true); |
---|
512 | } |
---|
513 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
514 | } |
---|
515 | |
---|
516 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
---|
517 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
---|
518 | |
---|
519 | pcField->setTopField(isTopField); // interlaced requirement |
---|
520 | |
---|
521 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
---|
522 | { |
---|
523 | const ComponentID component = ComponentID(componentIndex); |
---|
524 | const UInt stride = pcPicYuvOrg->getStride(component); |
---|
525 | |
---|
526 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
---|
527 | pcField->getPicYuvOrg()->getAddr(component), |
---|
528 | pcPicYuvOrg->getStride(component), |
---|
529 | pcPicYuvOrg->getWidth(component), |
---|
530 | pcPicYuvOrg->getHeight(component), |
---|
531 | isTopField); |
---|
532 | |
---|
533 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
---|
534 | pcField->getPicYuvTrueOrg()->getAddr(component), |
---|
535 | pcPicYuvTrueOrg->getStride(component), |
---|
536 | pcPicYuvTrueOrg->getWidth(component), |
---|
537 | pcPicYuvTrueOrg->getHeight(component), |
---|
538 | isTopField); |
---|
539 | } |
---|
540 | |
---|
541 | // compute image characteristics |
---|
542 | if ( getUseAdaptiveQP() ) |
---|
543 | { |
---|
544 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
---|
545 | } |
---|
546 | } |
---|
547 | |
---|
548 | if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) ) |
---|
549 | { |
---|
550 | // compress GOP |
---|
551 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
---|
552 | |
---|
553 | iNumEncoded += m_iNumPicRcvd; |
---|
554 | m_uiNumAllPicCoded += m_iNumPicRcvd; |
---|
555 | m_iNumPicRcvd = 0; |
---|
556 | } |
---|
557 | } |
---|
558 | } |
---|
559 | #endif |
---|
560 | // ==================================================================================================================== |
---|
561 | // Protected member functions |
---|
562 | // ==================================================================================================================== |
---|
563 | |
---|
564 | /** |
---|
565 | - Application has picture buffer list with size of GOP + 1 |
---|
566 | - Picture buffer list acts like as ring buffer |
---|
567 | - End of the list has the latest picture |
---|
568 | . |
---|
569 | \retval rpcPic obtained picture buffer |
---|
570 | */ |
---|
571 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
572 | { |
---|
573 | // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic. |
---|
574 | |
---|
575 | TComSlice::sortPicList(m_cListPic); |
---|
576 | |
---|
577 | |
---|
578 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
579 | { |
---|
580 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
581 | Int iSize = Int( m_cListPic.size() ); |
---|
582 | for ( Int i = 0; i < iSize; i++ ) |
---|
583 | { |
---|
584 | rpcPic = *(iterPic++); |
---|
585 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
586 | { |
---|
587 | break; |
---|
588 | } |
---|
589 | } |
---|
590 | } |
---|
591 | else |
---|
592 | { |
---|
593 | if ( getUseAdaptiveQP() ) |
---|
594 | { |
---|
595 | TEncPic* pcEPic = new TEncPic; |
---|
596 | pcEPic->create( m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false); |
---|
597 | rpcPic = pcEPic; |
---|
598 | } |
---|
599 | else |
---|
600 | { |
---|
601 | rpcPic = new TComPic; |
---|
602 | rpcPic->create( m_cSPS, m_cPPS, false ); |
---|
603 | } |
---|
604 | |
---|
605 | m_cListPic.pushBack( rpcPic ); |
---|
606 | } |
---|
607 | rpcPic->setReconMark (false); |
---|
608 | |
---|
609 | m_iPOCLast++; |
---|
610 | m_iNumPicRcvd++; |
---|
611 | |
---|
612 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
613 | // mark it should be extended |
---|
614 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
615 | #if NH_MV |
---|
616 | rpcPic->getPicYuvOrg()->setBorderExtension(false); |
---|
617 | #endif |
---|
618 | |
---|
619 | } |
---|
620 | |
---|
621 | Void TEncTop::xInitVPS() |
---|
622 | { |
---|
623 | // The SPS must have already been set up. |
---|
624 | // set the VPS profile information. |
---|
625 | #if NH_MV |
---|
626 | // Do initialization in TAppEncTop |
---|
627 | #else |
---|
628 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
---|
629 | m_cVPS.setMaxOpSets(1); |
---|
630 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
631 | m_cVPS.setNumHrdParameters( 0 ); |
---|
632 | |
---|
633 | m_cVPS.createHrdParamBuffer(); |
---|
634 | for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ ) |
---|
635 | { |
---|
636 | m_cVPS.setHrdOpSetIdx( 0, i ); |
---|
637 | m_cVPS.setCprmsPresentFlag( false, i ); |
---|
638 | // Set up HrdParameters here. |
---|
639 | } |
---|
640 | #endif |
---|
641 | } |
---|
642 | |
---|
643 | Void TEncTop::xInitSPS() |
---|
644 | { |
---|
645 | #if NH_MV |
---|
646 | m_cSPS.setSPSId( getLayerIdInVps() ); |
---|
647 | m_cSPS.setLayerId( getLayerId() ); |
---|
648 | // Code below needs to be moved to VPS |
---|
649 | #endif |
---|
650 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
---|
651 | profileTierLevel.setLevelIdc(m_level); |
---|
652 | profileTierLevel.setTierFlag(m_levelTier); |
---|
653 | profileTierLevel.setProfileIdc(m_profile); |
---|
654 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
---|
655 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
656 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
657 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
658 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
659 | profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue); |
---|
660 | profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue); |
---|
661 | profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag); |
---|
662 | profileTierLevel.setOnePictureOnlyConstraintFlag(m_onePictureOnlyConstraintFlag); |
---|
663 | profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag); |
---|
664 | |
---|
665 | if ((m_profile == Profile::MAIN10) && (m_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (m_bitDepth[CHANNEL_TYPE_CHROMA] == 8)) |
---|
666 | { |
---|
667 | /* The above constraint is equal to Profile::MAIN */ |
---|
668 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
---|
669 | } |
---|
670 | if (m_profile == Profile::MAIN) |
---|
671 | { |
---|
672 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
---|
673 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
---|
674 | } |
---|
675 | /* XXX: should Main be marked as compatible with still picture? */ |
---|
676 | /* XXX: may be a good idea to refactor the above into a function |
---|
677 | * that chooses the actual compatibility based upon options */ |
---|
678 | #if NH_MV |
---|
679 | m_cSPS.setUpdateRepFormatFlag ( false ); |
---|
680 | Bool multiLayerExtensionFlag = ( getLayerId() > 0 ) && ( m_cVPS->getNumRefLayers( getLayerId() ) > 0 ); |
---|
681 | |
---|
682 | m_cSPS.setSpsExtOrMaxSubLayersMinus1( multiLayerExtensionFlag ? 7 : m_maxTempLayer - 1 ); |
---|
683 | if ( multiLayerExtensionFlag ) |
---|
684 | { |
---|
685 | m_cSPS.setSpsInferScalingListFlag ( true ); |
---|
686 | m_cSPS.setSpsScalingListRefLayerId( m_cVPS->getIdRefLayer( getLayerId(), 0 ) ); |
---|
687 | #if NH_MV |
---|
688 | if ( m_bUseDisparitySearchRangeRestriction ) |
---|
689 | { |
---|
690 | m_cSPS.setInterViewMvVertConstraintFlag ( true ) ; |
---|
691 | } |
---|
692 | #endif |
---|
693 | } |
---|
694 | m_cSPS.setSpsExtensionPresentFlag ( true ); |
---|
695 | m_cSPS.setSpsMultilayerExtensionFlag ( true ); |
---|
696 | #if NH_3D |
---|
697 | m_cSPS.setSps3dExtensionFlag ( true ); |
---|
698 | #endif |
---|
699 | #endif |
---|
700 | |
---|
701 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
702 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
703 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
---|
704 | m_cSPS.setMaxCUWidth ( m_maxCUWidth ); |
---|
705 | m_cSPS.setMaxCUHeight ( m_maxCUHeight ); |
---|
706 | m_cSPS.setMaxTotalCUDepth ( m_maxTotalCUDepth ); |
---|
707 | #if NH_3D |
---|
708 | assert( !getIsDepth() || m_chromaFormatIDC == CHROMA_400 ); |
---|
709 | #endif |
---|
710 | m_cSPS.setChromaFormatIdc( m_chromaFormatIDC); |
---|
711 | m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_log2DiffMaxMinCodingBlockSize); |
---|
712 | |
---|
713 | Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getLog2DiffMaxMinCodingBlockSize() ); |
---|
714 | Int log2MinCUSize = 0; |
---|
715 | while(minCUSize > 1) |
---|
716 | { |
---|
717 | minCUSize >>= 1; |
---|
718 | log2MinCUSize++; |
---|
719 | } |
---|
720 | |
---|
721 | m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize); |
---|
722 | |
---|
723 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
724 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
725 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
726 | |
---|
727 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
728 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
729 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
730 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
731 | |
---|
732 | m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1)); |
---|
733 | |
---|
734 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
735 | |
---|
736 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
737 | |
---|
738 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
---|
739 | { |
---|
740 | m_cSPS.setBitDepth (ChannelType(channelType), m_bitDepth[channelType] ); |
---|
741 | #if O0043_BEST_EFFORT_DECODING |
---|
742 | m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] ); |
---|
743 | #endif |
---|
744 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (m_bitDepth[channelType] - 8))); |
---|
745 | m_cSPS.setPCMBitDepth (ChannelType(channelType), m_PCMBitDepth[channelType] ); |
---|
746 | } |
---|
747 | #if NH_MV |
---|
748 | m_cSPS.inferRepFormat( m_cVPS, getLayerId(), true ); |
---|
749 | #endif |
---|
750 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
751 | |
---|
752 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
753 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
---|
754 | |
---|
755 | for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) |
---|
756 | { |
---|
757 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
758 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
759 | } |
---|
760 | #if NH_MV |
---|
761 | for ( Int ols = 0; ols < m_cVPS->getNumOutputLayerSets(); ols++) |
---|
762 | { |
---|
763 | // Check MaxDecPicBuffering |
---|
764 | const std::vector<Int>& targetDecLayerIdList = m_cVPS->getTargetDecLayerIdList( m_cVPS->olsIdxToLsIdx( ols )); |
---|
765 | for( Int is = 0; is < targetDecLayerIdList.size(); is++ ) |
---|
766 | { |
---|
767 | if ( m_cVPS->getNecessaryLayerFlag( ols, is ) ) |
---|
768 | { |
---|
769 | m_cSPS.inferSpsMaxDecPicBufferingMinus1( m_cVPS, ols, targetDecLayerIdList[is], true ); |
---|
770 | } |
---|
771 | } |
---|
772 | } |
---|
773 | #endif |
---|
774 | |
---|
775 | |
---|
776 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
777 | m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 ); |
---|
778 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
779 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
780 | |
---|
781 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
782 | { |
---|
783 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
784 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag()); |
---|
785 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
786 | pcVUI->setSarWidth(getSarWidth()); |
---|
787 | pcVUI->setSarHeight(getSarHeight()); |
---|
788 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
789 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
790 | #if NH_MV |
---|
791 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag() && getLayerId() == 0 ); |
---|
792 | #else |
---|
793 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
794 | #endif |
---|
795 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
796 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
797 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
798 | pcVUI->setColourPrimaries(getColourPrimaries()); |
---|
799 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
800 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
801 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
802 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
803 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
804 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
805 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
---|
806 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
---|
807 | pcVUI->setFieldSeqFlag(false); |
---|
808 | pcVUI->setHrdParametersPresentFlag(false); |
---|
809 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
810 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
811 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
812 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
813 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
814 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
---|
815 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
816 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
817 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
818 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
819 | } |
---|
820 | m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS); |
---|
821 | assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS); |
---|
822 | for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++) |
---|
823 | { |
---|
824 | m_cSPS.setLtRefPicPocLsbSps(k, 0); |
---|
825 | m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0); |
---|
826 | } |
---|
827 | if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) |
---|
828 | { |
---|
829 | xInitHrdParameters(); |
---|
830 | } |
---|
831 | if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) |
---|
832 | { |
---|
833 | m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true ); |
---|
834 | } |
---|
835 | |
---|
836 | // Set up SPS range extension settings |
---|
837 | m_cSPS.getSpsRangeExtension().setTransformSkipRotationEnabledFlag(m_transformSkipRotationEnabledFlag); |
---|
838 | m_cSPS.getSpsRangeExtension().setTransformSkipContextEnabledFlag(m_transformSkipContextEnabledFlag); |
---|
839 | for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++) |
---|
840 | { |
---|
841 | m_cSPS.getSpsRangeExtension().setRdpcmEnabledFlag(RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]); |
---|
842 | } |
---|
843 | m_cSPS.getSpsRangeExtension().setExtendedPrecisionProcessingFlag(m_extendedPrecisionProcessingFlag); |
---|
844 | m_cSPS.getSpsRangeExtension().setIntraSmoothingDisabledFlag( m_intraSmoothingDisabledFlag ); |
---|
845 | m_cSPS.getSpsRangeExtension().setHighPrecisionOffsetsEnabledFlag(m_highPrecisionOffsetsEnabledFlag); |
---|
846 | m_cSPS.getSpsRangeExtension().setPersistentRiceAdaptationEnabledFlag(m_persistentRiceAdaptationEnabledFlag); |
---|
847 | m_cSPS.getSpsRangeExtension().setCabacBypassAlignmentEnabledFlag(m_cabacBypassAlignmentEnabledFlag); |
---|
848 | #if NH_MV |
---|
849 | m_cSPS.setSpsRangeExtensionsFlag( m_cSPS.getSpsRangeExtension().settingsDifferFromDefaults() ); |
---|
850 | #endif |
---|
851 | |
---|
852 | } |
---|
853 | |
---|
854 | Void TEncTop::xInitHrdParameters() |
---|
855 | { |
---|
856 | Bool useSubCpbParams = (getSliceMode() > 0) || (getSliceSegmentMode() > 0); |
---|
857 | Int bitRate = getTargetBitrate(); |
---|
858 | Bool isRandomAccess = getIntraPeriod() > 0; |
---|
859 | |
---|
860 | if( !getVuiParametersPresentFlag() ) |
---|
861 | { |
---|
862 | return; |
---|
863 | } |
---|
864 | |
---|
865 | TComVUI *vui = m_cSPS.getVuiParameters(); |
---|
866 | TComHRD *hrd = vui->getHrdParameters(); |
---|
867 | |
---|
868 | TimingInfo *timingInfo = vui->getTimingInfo(); |
---|
869 | timingInfo->setTimingInfoPresentFlag( true ); |
---|
870 | switch( getFrameRate() ) |
---|
871 | { |
---|
872 | case 24: |
---|
873 | timingInfo->setNumUnitsInTick( 1125000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
874 | break; |
---|
875 | case 25: |
---|
876 | timingInfo->setNumUnitsInTick( 1080000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
877 | break; |
---|
878 | case 30: |
---|
879 | timingInfo->setNumUnitsInTick( 900900 ); timingInfo->setTimeScale ( 27000000 ); |
---|
880 | break; |
---|
881 | case 50: |
---|
882 | timingInfo->setNumUnitsInTick( 540000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
883 | break; |
---|
884 | case 60: |
---|
885 | timingInfo->setNumUnitsInTick( 450450 ); timingInfo->setTimeScale ( 27000000 ); |
---|
886 | break; |
---|
887 | default: |
---|
888 | timingInfo->setNumUnitsInTick( 1001 ); timingInfo->setTimeScale ( 60000 ); |
---|
889 | break; |
---|
890 | } |
---|
891 | |
---|
892 | Bool rateCnt = ( bitRate > 0 ); |
---|
893 | hrd->setNalHrdParametersPresentFlag( rateCnt ); |
---|
894 | hrd->setVclHrdParametersPresentFlag( rateCnt ); |
---|
895 | |
---|
896 | hrd->setSubPicCpbParamsPresentFlag( useSubCpbParams ); |
---|
897 | |
---|
898 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
899 | { |
---|
900 | hrd->setTickDivisorMinus2( 100 - 2 ); // |
---|
901 | hrd->setDuCpbRemovalDelayLengthMinus1( 7 ); // 8-bit precision ( plus 1 for last DU in AU ) |
---|
902 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( true ); |
---|
903 | hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 ); // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay |
---|
904 | } |
---|
905 | else |
---|
906 | { |
---|
907 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); |
---|
908 | } |
---|
909 | |
---|
910 | hrd->setBitRateScale( 4 ); // in units of 2^( 6 + 4 ) = 1,024 bps |
---|
911 | hrd->setCpbSizeScale( 6 ); // in units of 2^( 4 + 6 ) = 1,024 bit |
---|
912 | hrd->setDuCpbSizeScale( 6 ); // in units of 2^( 4 + 6 ) = 1,024 bit |
---|
913 | |
---|
914 | hrd->setInitialCpbRemovalDelayLengthMinus1(15); // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit |
---|
915 | if( isRandomAccess ) |
---|
916 | { |
---|
917 | hrd->setCpbRemovalDelayLengthMinus1(5); // 32 = 2^5 (plus 1) |
---|
918 | hrd->setDpbOutputDelayLengthMinus1 (5); // 32 + 3 = 2^6 |
---|
919 | } |
---|
920 | else |
---|
921 | { |
---|
922 | hrd->setCpbRemovalDelayLengthMinus1(9); // max. 2^10 |
---|
923 | hrd->setDpbOutputDelayLengthMinus1 (9); // max. 2^10 |
---|
924 | } |
---|
925 | |
---|
926 | // Note: parameters for all temporal layers are initialized with the same values |
---|
927 | Int i, j; |
---|
928 | UInt bitrateValue, cpbSizeValue; |
---|
929 | UInt duCpbSizeValue; |
---|
930 | UInt duBitRateValue = 0; |
---|
931 | |
---|
932 | for( i = 0; i < MAX_TLAYER; i ++ ) |
---|
933 | { |
---|
934 | hrd->setFixedPicRateFlag( i, 1 ); |
---|
935 | hrd->setPicDurationInTcMinus1( i, 0 ); |
---|
936 | hrd->setLowDelayHrdFlag( i, 0 ); |
---|
937 | hrd->setCpbCntMinus1( i, 0 ); |
---|
938 | |
---|
939 | //! \todo check for possible PTL violations |
---|
940 | // BitRate[ i ] = ( bit_rate_value_minus1[ i ] + 1 ) * 2^( 6 + bit_rate_scale ) |
---|
941 | bitrateValue = bitRate / (1 << (6 + hrd->getBitRateScale()) ); // bitRate is in bits, so it needs to be scaled down |
---|
942 | // CpbSize[ i ] = ( cpb_size_value_minus1[ i ] + 1 ) * 2^( 4 + cpb_size_scale ) |
---|
943 | cpbSizeValue = bitRate / (1 << (4 + hrd->getCpbSizeScale()) ); // using bitRate results in 1 second CPB size |
---|
944 | |
---|
945 | // DU CPB size could be smaller (i.e. bitrateValue / number of DUs), but we don't know |
---|
946 | // in how many DUs the slice segment settings will result |
---|
947 | duCpbSizeValue = bitrateValue; |
---|
948 | duBitRateValue = cpbSizeValue; |
---|
949 | |
---|
950 | for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ ) |
---|
951 | { |
---|
952 | hrd->setBitRateValueMinus1( i, j, 0, ( bitrateValue - 1 ) ); |
---|
953 | hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) ); |
---|
954 | hrd->setDuCpbSizeValueMinus1( i, j, 0, ( duCpbSizeValue - 1 ) ); |
---|
955 | hrd->setCbrFlag( i, j, 0, false ); |
---|
956 | |
---|
957 | hrd->setBitRateValueMinus1( i, j, 1, ( bitrateValue - 1) ); |
---|
958 | hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) ); |
---|
959 | hrd->setDuCpbSizeValueMinus1( i, j, 1, ( duCpbSizeValue - 1 ) ); |
---|
960 | hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) ); |
---|
961 | hrd->setCbrFlag( i, j, 1, false ); |
---|
962 | } |
---|
963 | } |
---|
964 | } |
---|
965 | |
---|
966 | |
---|
967 | Void TEncTop::xInitPPS() |
---|
968 | { |
---|
969 | #if NH_MV |
---|
970 | m_cPPS.setLayerId( getLayerId() ); |
---|
971 | #if NH_3D |
---|
972 | // Check if this condition is still correct |
---|
973 | if( getVPS()->getNumRefListLayers( getLayerId() ) > 0 ) |
---|
974 | #else |
---|
975 | if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 ) |
---|
976 | #endif |
---|
977 | { |
---|
978 | m_cPPS.setListsModificationPresentFlag( true ); |
---|
979 | } |
---|
980 | m_cPPS.setPPSId( getLayerIdInVps() ); |
---|
981 | m_cPPS.setSPSId( getLayerIdInVps() ); |
---|
982 | m_cPPS.setPpsMultilayerExtensionFlag ( true ); |
---|
983 | #if NH_3D |
---|
984 | // Might be used for DLT |
---|
985 | m_cPPS.setPps3dExtensionFlag ( getIsDepth() ); |
---|
986 | #endif |
---|
987 | #endif |
---|
988 | |
---|
989 | #if NH_3D_DLT |
---|
990 | // create mapping from depth layer indexes to layer ids |
---|
991 | Int j=0; |
---|
992 | for( Int i=0; i<=getVPS()->getMaxLayersMinus1(); i++ ) |
---|
993 | { |
---|
994 | Int layerId = getVPS()->getLayerIdInNuh(i); |
---|
995 | if( getVPS()->getDepthId(layerId) ) |
---|
996 | m_cDLT.setDepthIdxToLayerId(j++, layerId); |
---|
997 | } |
---|
998 | m_cPPS.setDLT( m_cDLT ); |
---|
999 | #endif |
---|
1000 | |
---|
1001 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
1002 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
1003 | |
---|
1004 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
1005 | { |
---|
1006 | bUseDQP = true; |
---|
1007 | } |
---|
1008 | |
---|
1009 | if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING) |
---|
1010 | { |
---|
1011 | bUseDQP=false; |
---|
1012 | } |
---|
1013 | |
---|
1014 | |
---|
1015 | if ( m_RCEnableRateControl ) |
---|
1016 | { |
---|
1017 | m_cPPS.setUseDQP(true); |
---|
1018 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
1019 | } |
---|
1020 | else if(bUseDQP) |
---|
1021 | { |
---|
1022 | m_cPPS.setUseDQP(true); |
---|
1023 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
1024 | } |
---|
1025 | else |
---|
1026 | { |
---|
1027 | m_cPPS.setUseDQP(false); |
---|
1028 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
1029 | } |
---|
1030 | |
---|
1031 | if ( m_diffCuChromaQpOffsetDepth >= 0 ) |
---|
1032 | { |
---|
1033 | m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(m_diffCuChromaQpOffsetDepth); |
---|
1034 | m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList(); |
---|
1035 | m_cPPS.getPpsRangeExtension().setChromaQpOffsetListEntry(1, 6, 6); |
---|
1036 | /* todo, insert table entries from command line (NB, 0 should not be touched) */ |
---|
1037 | } |
---|
1038 | else |
---|
1039 | { |
---|
1040 | m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(0); |
---|
1041 | m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList(); |
---|
1042 | } |
---|
1043 | m_cPPS.getPpsRangeExtension().setCrossComponentPredictionEnabledFlag(m_crossComponentPredictionEnabledFlag); |
---|
1044 | m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA, m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA ]); |
---|
1045 | m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA]); |
---|
1046 | |
---|
1047 | m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset ); |
---|
1048 | m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset ); |
---|
1049 | |
---|
1050 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
---|
1051 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
1052 | m_cPPS.setUseWP( m_useWeightedPred ); |
---|
1053 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
1054 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
1055 | #if NH_MV |
---|
1056 | m_cPPS.setNumExtraSliceHeaderBits( 3 ); |
---|
1057 | #endif |
---|
1058 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
1059 | if ( getDeblockingFilterMetric() ) |
---|
1060 | { |
---|
1061 | m_cPPS.setDeblockingFilterOverrideEnabledFlag(true); |
---|
1062 | m_cPPS.setPicDisableDeblockingFilterFlag(false); |
---|
1063 | } |
---|
1064 | else |
---|
1065 | { |
---|
1066 | m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() ); |
---|
1067 | m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() ); |
---|
1068 | } |
---|
1069 | |
---|
1070 | if (! m_cPPS.getPicDisableDeblockingFilterFlag()) |
---|
1071 | { |
---|
1072 | m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() ); |
---|
1073 | m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() ); |
---|
1074 | } |
---|
1075 | else |
---|
1076 | { |
---|
1077 | m_cPPS.setDeblockingFilterBetaOffsetDiv2(0); |
---|
1078 | m_cPPS.setDeblockingFilterTcOffsetDiv2(0); |
---|
1079 | } |
---|
1080 | |
---|
1081 | // deblockingFilterControlPresentFlag is true if any of the settings differ from the inferred values: |
---|
1082 | const Bool deblockingFilterControlPresentFlag = m_cPPS.getDeblockingFilterOverrideEnabledFlag() || |
---|
1083 | m_cPPS.getPicDisableDeblockingFilterFlag() || |
---|
1084 | m_cPPS.getDeblockingFilterBetaOffsetDiv2() != 0 || |
---|
1085 | m_cPPS.getDeblockingFilterTcOffsetDiv2() != 0; |
---|
1086 | |
---|
1087 | m_cPPS.setDeblockingFilterControlPresentFlag(deblockingFilterControlPresentFlag); |
---|
1088 | |
---|
1089 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
1090 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
1091 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
1092 | |
---|
1093 | |
---|
1094 | Int histogram[MAX_NUM_REF + 1]; |
---|
1095 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
1096 | { |
---|
1097 | histogram[i]=0; |
---|
1098 | } |
---|
1099 | for( Int i = 0; i < getGOPSize(); i++) |
---|
1100 | { |
---|
1101 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
---|
1102 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
1103 | } |
---|
1104 | |
---|
1105 | Int maxHist=-1; |
---|
1106 | Int bestPos=0; |
---|
1107 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
1108 | { |
---|
1109 | if(histogram[i]>maxHist) |
---|
1110 | { |
---|
1111 | maxHist=histogram[i]; |
---|
1112 | bestPos=i; |
---|
1113 | } |
---|
1114 | } |
---|
1115 | assert(bestPos <= 15); |
---|
1116 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
1117 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
1118 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
1119 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
1120 | m_cPPS.getPpsRangeExtension().setLog2MaxTransformSkipBlockSize( m_log2MaxTransformSkipBlockSize ); |
---|
1121 | |
---|
1122 | if (m_sliceSegmentMode != NO_SLICES) |
---|
1123 | { |
---|
1124 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
---|
1125 | } |
---|
1126 | } |
---|
1127 | |
---|
1128 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
1129 | Void TEncTop::xInitRPS(Bool isFieldCoding) |
---|
1130 | { |
---|
1131 | TComReferencePictureSet* rps; |
---|
1132 | |
---|
1133 | m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1); |
---|
1134 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
1135 | |
---|
1136 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
1137 | { |
---|
1138 | GOPEntry ge = getGOPEntry(i); |
---|
1139 | rps = rpsList->getReferencePictureSet(i); |
---|
1140 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
1141 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1142 | Int numNeg = 0; |
---|
1143 | Int numPos = 0; |
---|
1144 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
1145 | { |
---|
1146 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
1147 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
1148 | if(ge.m_referencePics[j]>0) |
---|
1149 | { |
---|
1150 | numPos++; |
---|
1151 | } |
---|
1152 | else |
---|
1153 | { |
---|
1154 | numNeg++; |
---|
1155 | } |
---|
1156 | } |
---|
1157 | rps->setNumberOfNegativePictures(numNeg); |
---|
1158 | rps->setNumberOfPositivePictures(numPos); |
---|
1159 | |
---|
1160 | // handle inter RPS intialization from the config file. |
---|
1161 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
1162 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
1163 | TComReferencePictureSet* RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL; // get the reference RPS |
---|
1164 | |
---|
1165 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
1166 | { |
---|
1167 | assert (RPSRef!=NULL); |
---|
1168 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
1169 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
1170 | |
---|
1171 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
1172 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
1173 | Int count=0; |
---|
1174 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
1175 | { |
---|
1176 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
1177 | rps->setRefIdc(j, 0); |
---|
1178 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
1179 | { |
---|
1180 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
1181 | { |
---|
1182 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
1183 | count++; |
---|
1184 | break; |
---|
1185 | } |
---|
1186 | } |
---|
1187 | } |
---|
1188 | if (count != rps->getNumberOfPictures()) |
---|
1189 | { |
---|
1190 | 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"); |
---|
1191 | rps->setInterRPSPrediction(0); |
---|
1192 | } |
---|
1193 | } |
---|
1194 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
1195 | { |
---|
1196 | assert (RPSRef!=NULL); |
---|
1197 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
1198 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
1199 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1200 | { |
---|
1201 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
1202 | } |
---|
1203 | // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
1204 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
1205 | numNeg = 0; |
---|
1206 | numPos = 0; |
---|
1207 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
1208 | |
---|
1209 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1210 | { |
---|
1211 | if (ge.m_refIdc[j]) |
---|
1212 | { |
---|
1213 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
1214 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
1215 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
1216 | if (deltaPOC<0) |
---|
1217 | { |
---|
1218 | numNeg++; |
---|
1219 | } |
---|
1220 | else |
---|
1221 | { |
---|
1222 | numPos++; |
---|
1223 | } |
---|
1224 | } |
---|
1225 | } |
---|
1226 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
1227 | { |
---|
1228 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1229 | rps->setNumberOfNegativePictures(numNeg); |
---|
1230 | rps->setNumberOfPictures(numNeg+numPos); |
---|
1231 | } |
---|
1232 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
1233 | { |
---|
1234 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1235 | rps->setNumberOfPositivePictures(numPos); |
---|
1236 | rps->setNumberOfPictures(numNeg+numPos); |
---|
1237 | } |
---|
1238 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
1239 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
1240 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
1241 | // check if Delta POC and Used are the same |
---|
1242 | // print warning if they are not. |
---|
1243 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
1244 | { |
---|
1245 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
1246 | { |
---|
1247 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
1248 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
1249 | } |
---|
1250 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
1251 | { |
---|
1252 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
1253 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
1254 | } |
---|
1255 | } |
---|
1256 | } |
---|
1257 | } |
---|
1258 | //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. |
---|
1259 | //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. |
---|
1260 | if (isFieldCoding) |
---|
1261 | { |
---|
1262 | rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs); |
---|
1263 | rps->setNumberOfPictures(1); |
---|
1264 | rps->setNumberOfNegativePictures(1); |
---|
1265 | rps->setNumberOfPositivePictures(0); |
---|
1266 | rps->setNumberOfLongtermPictures(0); |
---|
1267 | rps->setDeltaPOC(0,-1); |
---|
1268 | rps->setPOC(0,0); |
---|
1269 | rps->setUsed(0,true); |
---|
1270 | rps->setInterRPSPrediction(false); |
---|
1271 | rps->setDeltaRIdxMinus1(0); |
---|
1272 | rps->setDeltaRPS(0); |
---|
1273 | rps->setNumRefIdc(0); |
---|
1274 | } |
---|
1275 | } |
---|
1276 | |
---|
1277 | // This is a function that |
---|
1278 | // determines what Reference Picture Set to use |
---|
1279 | // for a specific slice (with POC = POCCurr) |
---|
1280 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
1281 | { |
---|
1282 | #if NH_MV |
---|
1283 | if( slice->getRapPicFlag() == true && getLayerId() > 0 && POCCurr == 0 ) |
---|
1284 | { |
---|
1285 | TComReferencePictureSet* rps = slice->getLocalRPS(); |
---|
1286 | rps->setNumberOfNegativePictures(0); |
---|
1287 | rps->setNumberOfPositivePictures(0); |
---|
1288 | rps->setNumberOfLongtermPictures(0); |
---|
1289 | rps->setNumberOfPictures(0); |
---|
1290 | slice->setRPS(rps); |
---|
1291 | } |
---|
1292 | else |
---|
1293 | { |
---|
1294 | #endif |
---|
1295 | slice->setRPSidx(GOPid); |
---|
1296 | |
---|
1297 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1298 | { |
---|
1299 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1300 | { |
---|
1301 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1302 | if(POCIndex == 0) |
---|
1303 | { |
---|
1304 | POCIndex = m_uiIntraPeriod; |
---|
1305 | } |
---|
1306 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1307 | { |
---|
1308 | slice->setRPSidx(extraNum); |
---|
1309 | } |
---|
1310 | } |
---|
1311 | else |
---|
1312 | { |
---|
1313 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1314 | { |
---|
1315 | slice->setRPSidx(extraNum); |
---|
1316 | } |
---|
1317 | } |
---|
1318 | } |
---|
1319 | |
---|
1320 | if(POCCurr == 1 && slice->getPic()->isField()) |
---|
1321 | { |
---|
1322 | slice->setRPSidx(m_iGOPSize+m_extraRPSs); |
---|
1323 | } |
---|
1324 | |
---|
1325 | TComReferencePictureSet *rps=slice->getLocalRPS(); |
---|
1326 | (*rps) = *(slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1327 | slice->setRPS(rps); |
---|
1328 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1329 | #if NH_MV |
---|
1330 | } |
---|
1331 | #endif |
---|
1332 | |
---|
1333 | } |
---|
1334 | |
---|
1335 | Int TEncTop::getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid ) |
---|
1336 | { |
---|
1337 | Int rpsIdx = GOPid; |
---|
1338 | |
---|
1339 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
1340 | { |
---|
1341 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1342 | { |
---|
1343 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1344 | if(POCIndex == 0) |
---|
1345 | { |
---|
1346 | POCIndex = m_uiIntraPeriod; |
---|
1347 | } |
---|
1348 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1349 | { |
---|
1350 | rpsIdx = extraNum; |
---|
1351 | } |
---|
1352 | } |
---|
1353 | else |
---|
1354 | { |
---|
1355 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1356 | { |
---|
1357 | rpsIdx = extraNum; |
---|
1358 | } |
---|
1359 | } |
---|
1360 | } |
---|
1361 | |
---|
1362 | return rpsIdx; |
---|
1363 | } |
---|
1364 | |
---|
1365 | Void TEncTop::xInitPPSforTiles() |
---|
1366 | { |
---|
1367 | m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag ); |
---|
1368 | m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1369 | m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 ); |
---|
1370 | if( !m_tileUniformSpacingFlag ) |
---|
1371 | { |
---|
1372 | m_cPPS.setTileColumnWidth( m_tileColumnWidth ); |
---|
1373 | m_cPPS.setTileRowHeight( m_tileRowHeight ); |
---|
1374 | } |
---|
1375 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
1376 | |
---|
1377 | // # substreams is "per tile" when tiles are independent. |
---|
1378 | } |
---|
1379 | |
---|
1380 | Void TEncCfg::xCheckGSParameters() |
---|
1381 | { |
---|
1382 | Int iWidthInCU = ( m_iSourceWidth%m_maxCUWidth ) ? m_iSourceWidth/m_maxCUWidth + 1 : m_iSourceWidth/m_maxCUWidth; |
---|
1383 | Int iHeightInCU = ( m_iSourceHeight%m_maxCUHeight ) ? m_iSourceHeight/m_maxCUHeight + 1 : m_iSourceHeight/m_maxCUHeight; |
---|
1384 | UInt uiCummulativeColumnWidth = 0; |
---|
1385 | UInt uiCummulativeRowHeight = 0; |
---|
1386 | |
---|
1387 | //check the column relative parameters |
---|
1388 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1389 | { |
---|
1390 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1391 | exit( EXIT_FAILURE ); |
---|
1392 | } |
---|
1393 | |
---|
1394 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1395 | { |
---|
1396 | printf( "The current picture can not have so many columns.\n" ); |
---|
1397 | exit( EXIT_FAILURE ); |
---|
1398 | } |
---|
1399 | |
---|
1400 | if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag ) |
---|
1401 | { |
---|
1402 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1403 | { |
---|
1404 | uiCummulativeColumnWidth += m_tileColumnWidth[i]; |
---|
1405 | } |
---|
1406 | |
---|
1407 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1408 | { |
---|
1409 | printf( "The width of the column is too large.\n" ); |
---|
1410 | exit( EXIT_FAILURE ); |
---|
1411 | } |
---|
1412 | } |
---|
1413 | |
---|
1414 | //check the row relative parameters |
---|
1415 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1416 | { |
---|
1417 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1418 | exit( EXIT_FAILURE ); |
---|
1419 | } |
---|
1420 | |
---|
1421 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1422 | { |
---|
1423 | printf( "The current picture can not have so many rows.\n" ); |
---|
1424 | exit( EXIT_FAILURE ); |
---|
1425 | } |
---|
1426 | |
---|
1427 | if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag ) |
---|
1428 | { |
---|
1429 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1430 | { |
---|
1431 | uiCummulativeRowHeight += m_tileRowHeight[i]; |
---|
1432 | } |
---|
1433 | |
---|
1434 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1435 | { |
---|
1436 | printf( "The height of the row is too large.\n" ); |
---|
1437 | exit( EXIT_FAILURE ); |
---|
1438 | } |
---|
1439 | } |
---|
1440 | } |
---|
1441 | |
---|
1442 | #if NH_MV |
---|
1443 | Int TEncTop::getFrameId(Int iGOPid) |
---|
1444 | { |
---|
1445 | if(m_iPOCLast == 0) |
---|
1446 | { |
---|
1447 | return(0 ); |
---|
1448 | } |
---|
1449 | else |
---|
1450 | { |
---|
1451 | return m_iPOCLast -m_iNumPicRcvd+ getGOPEntry(iGOPid).m_POC ; |
---|
1452 | } |
---|
1453 | } |
---|
1454 | |
---|
1455 | TComPic* TEncTop::getPic( Int poc ) |
---|
1456 | { |
---|
1457 | TComList<TComPic*>* listPic = getListPic(); |
---|
1458 | TComPic* pcPic = NULL; |
---|
1459 | for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++) |
---|
1460 | { |
---|
1461 | if( (*it)->getPOC() == poc ) |
---|
1462 | { |
---|
1463 | pcPic = *it ; |
---|
1464 | break ; |
---|
1465 | } |
---|
1466 | } |
---|
1467 | return pcPic; |
---|
1468 | } |
---|
1469 | |
---|
1470 | #endif |
---|
1471 | |
---|
1472 | #if NH_3D_VSO |
---|
1473 | Void TEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset, Int maxCuHeight ) |
---|
1474 | { |
---|
1475 | TRenModel* rendererModel = m_cRdCost.getRenModel(); |
---|
1476 | rendererModel->setupPart( iHorOffset, std::min( maxCuHeight, (Int) ( m_iSourceHeight - iHorOffset ) )) ; |
---|
1477 | |
---|
1478 | Int iEncViewSIdx = m_cameraParameters->getBaseId2SortedId()[ iEncViewIdx ]; |
---|
1479 | |
---|
1480 | // setup base views |
---|
1481 | Int iNumOfBV = m_renderModelParameters->getNumOfBaseViewsForView( iEncViewSIdx, iEncContent ); |
---|
1482 | |
---|
1483 | for (Int iCurView = 0; iCurView < iNumOfBV; iCurView++ ) |
---|
1484 | { |
---|
1485 | Int iBaseViewSIdx; |
---|
1486 | Int iVideoDistMode; |
---|
1487 | Int iDepthDistMode; |
---|
1488 | |
---|
1489 | m_renderModelParameters->getBaseViewData( iEncViewSIdx, iEncContent, iCurView, iBaseViewSIdx, iVideoDistMode, iDepthDistMode ); |
---|
1490 | |
---|
1491 | AOT( iVideoDistMode < 0 || iVideoDistMode > 2 ); |
---|
1492 | |
---|
1493 | Int iBaseViewIdx = m_cameraParameters->getBaseSortedId2Id()[ iBaseViewSIdx ]; |
---|
1494 | |
---|
1495 | TComPicYuv* pcPicYuvVideoRec = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, true ); |
---|
1496 | TComPicYuv* pcPicYuvDepthRec = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, true ); |
---|
1497 | TComPicYuv* pcPicYuvVideoOrg = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, false ); |
---|
1498 | TComPicYuv* pcPicYuvDepthOrg = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, false ); |
---|
1499 | |
---|
1500 | TComPicYuv* pcPicYuvVideoRef = ( iVideoDistMode == 2 ) ? pcPicYuvVideoOrg : NULL; |
---|
1501 | TComPicYuv* pcPicYuvDepthRef = ( iDepthDistMode == 2 ) ? pcPicYuvDepthOrg : NULL; |
---|
1502 | |
---|
1503 | TComPicYuv* pcPicYuvVideoTest = ( iVideoDistMode == 0 ) ? pcPicYuvVideoOrg : pcPicYuvVideoRec; |
---|
1504 | TComPicYuv* pcPicYuvDepthTest = ( iDepthDistMode == 0 ) ? pcPicYuvDepthOrg : pcPicYuvDepthRec; |
---|
1505 | |
---|
1506 | AOT( (iVideoDistMode == 2) != (pcPicYuvVideoRef != NULL) ); |
---|
1507 | AOT( (iDepthDistMode == 2) != (pcPicYuvDepthRef != NULL) ); |
---|
1508 | AOT( pcPicYuvDepthTest == NULL ); |
---|
1509 | AOT( pcPicYuvVideoTest == NULL ); |
---|
1510 | |
---|
1511 | rendererModel->setBaseView( iBaseViewSIdx, pcPicYuvVideoTest, pcPicYuvDepthTest, pcPicYuvVideoRef, pcPicYuvDepthRef ); |
---|
1512 | } |
---|
1513 | |
---|
1514 | rendererModel->setErrorMode( iEncViewSIdx, iEncContent, 0 ); |
---|
1515 | // setup virtual views |
---|
1516 | Int iNumOfSV = m_renderModelParameters->getNumOfModelsForView( iEncViewSIdx, iEncContent ); |
---|
1517 | for (Int iCurView = 0; iCurView < iNumOfSV; iCurView++ ) |
---|
1518 | { |
---|
1519 | Int iOrgRefBaseViewSIdx; |
---|
1520 | Int iLeftBaseViewSIdx; |
---|
1521 | Int iRightBaseViewSIdx; |
---|
1522 | Int iSynthViewRelNum; |
---|
1523 | Int iModelNum; |
---|
1524 | Int iBlendMode; |
---|
1525 | m_renderModelParameters->getSingleModelData(iEncViewSIdx, iEncContent, iCurView, iModelNum, iBlendMode,iLeftBaseViewSIdx, iRightBaseViewSIdx, iOrgRefBaseViewSIdx, iSynthViewRelNum ); |
---|
1526 | |
---|
1527 | Int iLeftBaseViewIdx = -1; |
---|
1528 | Int iRightBaseViewIdx = -1; |
---|
1529 | |
---|
1530 | TComPicYuv* pcPicYuvOrgRef = NULL; |
---|
1531 | Int** ppiShiftLUTLeft = NULL; |
---|
1532 | Int** ppiShiftLUTRight = NULL; |
---|
1533 | Int** ppiBaseShiftLUTLeft = NULL; |
---|
1534 | Int** ppiBaseShiftLUTRight = NULL; |
---|
1535 | |
---|
1536 | |
---|
1537 | Int iDistToLeft = -1; |
---|
1538 | |
---|
1539 | Int iSynthViewIdx = m_cameraParameters->synthRelNum2Idx( iSynthViewRelNum ); |
---|
1540 | |
---|
1541 | if ( iLeftBaseViewSIdx != -1 ) |
---|
1542 | { |
---|
1543 | iLeftBaseViewIdx = m_cameraParameters->getBaseSortedId2Id() [ iLeftBaseViewSIdx ]; |
---|
1544 | ppiShiftLUTLeft = m_cameraParameters->getSynthViewShiftLUTI()[ iLeftBaseViewIdx ][ iSynthViewIdx ]; |
---|
1545 | } |
---|
1546 | |
---|
1547 | if ( iRightBaseViewSIdx != -1 ) |
---|
1548 | { |
---|
1549 | iRightBaseViewIdx = m_cameraParameters->getBaseSortedId2Id() [iRightBaseViewSIdx ]; |
---|
1550 | ppiShiftLUTRight = m_cameraParameters->getSynthViewShiftLUTI()[ iRightBaseViewIdx ][ iSynthViewIdx ]; |
---|
1551 | } |
---|
1552 | |
---|
1553 | if ( iRightBaseViewSIdx != -1 && iLeftBaseViewSIdx != -1 ) |
---|
1554 | { |
---|
1555 | iDistToLeft = m_cameraParameters->getRelDistLeft( iSynthViewIdx , iLeftBaseViewIdx, iRightBaseViewIdx); |
---|
1556 | ppiBaseShiftLUTLeft = m_cameraParameters->getBaseViewShiftLUTI() [ iLeftBaseViewIdx ][ iRightBaseViewIdx ]; |
---|
1557 | ppiBaseShiftLUTRight = m_cameraParameters->getBaseViewShiftLUTI() [ iRightBaseViewIdx ][ iLeftBaseViewIdx ]; |
---|
1558 | |
---|
1559 | } |
---|
1560 | |
---|
1561 | if ( iOrgRefBaseViewSIdx != -1 ) |
---|
1562 | { |
---|
1563 | pcPicYuvOrgRef = m_ivPicLists->getPicYuv( m_cameraParameters->getBaseSortedId2Id()[ iOrgRefBaseViewSIdx ] , false, iPoc, false ); |
---|
1564 | AOF ( pcPicYuvOrgRef ); |
---|
1565 | } |
---|
1566 | |
---|
1567 | rendererModel->setSingleModel( iModelNum, ppiShiftLUTLeft, ppiBaseShiftLUTLeft, ppiShiftLUTRight, ppiBaseShiftLUTRight, iDistToLeft, pcPicYuvOrgRef ); |
---|
1568 | } |
---|
1569 | } |
---|
1570 | #endif |
---|
1571 | |
---|
1572 | //! \} |
---|