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