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-2013, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncTop.cpp |
---|
35 | \brief encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TLibCommon/CommonDef.h" |
---|
39 | #include "TEncTop.h" |
---|
40 | #include "TEncPic.h" |
---|
41 | #if FAST_BIT_EST |
---|
42 | #include "TLibCommon/ContextModel.h" |
---|
43 | #endif |
---|
44 | |
---|
45 | //! \ingroup TLibEncoder |
---|
46 | //! \{ |
---|
47 | #if SVC_EXTENSION |
---|
48 | Int TEncTop::m_iSPSIdCnt = 0; |
---|
49 | Int TEncTop::m_iPPSIdCnt = 0; |
---|
50 | #endif |
---|
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 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
66 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
67 | g_nSymbolCounter = 0; |
---|
68 | #endif |
---|
69 | |
---|
70 | m_iMaxRefPicNum = 0; |
---|
71 | |
---|
72 | #if FAST_BIT_EST |
---|
73 | ContextModel::buildNextStateTable(); |
---|
74 | #endif |
---|
75 | |
---|
76 | m_pcSbacCoders = NULL; |
---|
77 | m_pcBinCoderCABACs = NULL; |
---|
78 | m_ppppcRDSbacCoders = NULL; |
---|
79 | m_ppppcBinCodersCABAC = NULL; |
---|
80 | m_pcRDGoOnSbacCoders = NULL; |
---|
81 | m_pcRDGoOnBinCodersCABAC = NULL; |
---|
82 | m_pcBitCounters = NULL; |
---|
83 | m_pcRdCosts = NULL; |
---|
84 | #if REF_IDX_FRAMEWORK |
---|
85 | memset(m_cIlpPic, 0, sizeof(m_cIlpPic)); |
---|
86 | #endif |
---|
87 | #if REF_IDX_MFM |
---|
88 | m_bMFMEnabledFlag = false; |
---|
89 | #endif |
---|
90 | } |
---|
91 | |
---|
92 | TEncTop::~TEncTop() |
---|
93 | { |
---|
94 | #if ENC_DEC_TRACE |
---|
95 | fclose( g_hTrace ); |
---|
96 | #endif |
---|
97 | } |
---|
98 | |
---|
99 | Void TEncTop::create () |
---|
100 | { |
---|
101 | #if !SVC_EXTENSION |
---|
102 | // initialize global variables |
---|
103 | initROM(); |
---|
104 | #endif |
---|
105 | |
---|
106 | // create processing unit classes |
---|
107 | #if SVC_EXTENSION |
---|
108 | m_cGOPEncoder. create( m_layerId ); |
---|
109 | #else |
---|
110 | m_cGOPEncoder. create(); |
---|
111 | #endif |
---|
112 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
113 | m_cCuEncoder. create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
114 | if (m_bUseSAO) |
---|
115 | { |
---|
116 | m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary()); |
---|
117 | m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization()); |
---|
118 | m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic()); |
---|
119 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
120 | m_cEncSAO.createEncBuffer(); |
---|
121 | } |
---|
122 | #if ADAPTIVE_QP_SELECTION |
---|
123 | if (m_bUseAdaptQpSelect) |
---|
124 | { |
---|
125 | m_cTrQuant.initSliceQpDelta(); |
---|
126 | } |
---|
127 | #endif |
---|
128 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
129 | |
---|
130 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
131 | if ( m_RCEnableRateControl ) |
---|
132 | { |
---|
133 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
134 | g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
---|
135 | } |
---|
136 | #else |
---|
137 | m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight); |
---|
138 | #endif |
---|
139 | // if SBAC-based RD optimization is used |
---|
140 | if( m_bUseSBACRD ) |
---|
141 | { |
---|
142 | m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
143 | #if FAST_BIT_EST |
---|
144 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1]; |
---|
145 | #else |
---|
146 | m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
147 | #endif |
---|
148 | |
---|
149 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
150 | { |
---|
151 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
152 | #if FAST_BIT_EST |
---|
153 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
154 | #else |
---|
155 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
156 | #endif |
---|
157 | |
---|
158 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
159 | { |
---|
160 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
161 | #if FAST_BIT_EST |
---|
162 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
163 | #else |
---|
164 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
165 | #endif |
---|
166 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | /** |
---|
173 | - Allocate coders required for wavefront for the nominated number of substreams. |
---|
174 | . |
---|
175 | \param iNumSubstreams Determines how much information to allocate. |
---|
176 | */ |
---|
177 | Void TEncTop::createWPPCoders(Int iNumSubstreams) |
---|
178 | { |
---|
179 | if (m_pcSbacCoders != NULL) |
---|
180 | { |
---|
181 | return; // already generated. |
---|
182 | } |
---|
183 | |
---|
184 | m_iNumSubstreams = iNumSubstreams; |
---|
185 | m_pcSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
186 | m_pcBinCoderCABACs = new TEncBinCABAC [iNumSubstreams]; |
---|
187 | m_pcRDGoOnSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
188 | m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC [iNumSubstreams]; |
---|
189 | m_pcBitCounters = new TComBitCounter [iNumSubstreams]; |
---|
190 | m_pcRdCosts = new TComRdCost [iNumSubstreams]; |
---|
191 | |
---|
192 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
193 | { |
---|
194 | m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] ); |
---|
195 | m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] ); |
---|
196 | } |
---|
197 | if( m_bUseSBACRD ) |
---|
198 | { |
---|
199 | m_ppppcRDSbacCoders = new TEncSbac*** [iNumSubstreams]; |
---|
200 | m_ppppcBinCodersCABAC = new TEncBinCABAC***[iNumSubstreams]; |
---|
201 | for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) |
---|
202 | { |
---|
203 | m_ppppcRDSbacCoders[ui] = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
204 | m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
205 | |
---|
206 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
207 | { |
---|
208 | m_ppppcRDSbacCoders[ui][iDepth] = new TEncSbac* [CI_NUM]; |
---|
209 | m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM]; |
---|
210 | |
---|
211 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
212 | { |
---|
213 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx] = new TEncSbac; |
---|
214 | m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC; |
---|
215 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] ); |
---|
216 | } |
---|
217 | } |
---|
218 | } |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | Void TEncTop::destroy () |
---|
223 | { |
---|
224 | // destroy processing unit classes |
---|
225 | m_cGOPEncoder. destroy(); |
---|
226 | m_cSliceEncoder. destroy(); |
---|
227 | m_cCuEncoder. destroy(); |
---|
228 | if (m_cSPS.getUseSAO()) |
---|
229 | { |
---|
230 | m_cEncSAO.destroy(); |
---|
231 | m_cEncSAO.destroyEncBuffer(); |
---|
232 | } |
---|
233 | m_cLoopFilter. destroy(); |
---|
234 | m_cRateCtrl. destroy(); |
---|
235 | // SBAC RD |
---|
236 | if( m_bUseSBACRD ) |
---|
237 | { |
---|
238 | Int iDepth; |
---|
239 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
240 | { |
---|
241 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
242 | { |
---|
243 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
244 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
249 | { |
---|
250 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
251 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
252 | } |
---|
253 | |
---|
254 | delete [] m_pppcRDSbacCoder; |
---|
255 | delete [] m_pppcBinCoderCABAC; |
---|
256 | |
---|
257 | for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ ) |
---|
258 | { |
---|
259 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
260 | { |
---|
261 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
262 | { |
---|
263 | delete m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]; |
---|
264 | delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx]; |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
269 | { |
---|
270 | delete [] m_ppppcRDSbacCoders [ui][iDepth]; |
---|
271 | delete [] m_ppppcBinCodersCABAC[ui][iDepth]; |
---|
272 | } |
---|
273 | delete[] m_ppppcRDSbacCoders [ui]; |
---|
274 | delete[] m_ppppcBinCodersCABAC[ui]; |
---|
275 | } |
---|
276 | delete[] m_ppppcRDSbacCoders; |
---|
277 | delete[] m_ppppcBinCodersCABAC; |
---|
278 | } |
---|
279 | delete[] m_pcSbacCoders; |
---|
280 | delete[] m_pcBinCoderCABACs; |
---|
281 | delete[] m_pcRDGoOnSbacCoders; |
---|
282 | delete[] m_pcRDGoOnBinCodersCABAC; |
---|
283 | delete[] m_pcBitCounters; |
---|
284 | delete[] m_pcRdCosts; |
---|
285 | |
---|
286 | #if !SVC_EXTENSION |
---|
287 | // destroy ROM |
---|
288 | destroyROM(); |
---|
289 | #endif |
---|
290 | #if REF_IDX_FRAMEWORK |
---|
291 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
292 | { |
---|
293 | if(m_cIlpPic[i]) |
---|
294 | { |
---|
295 | //m_cIlpPic[i]->setPicYuvRec(NULL); |
---|
296 | m_cIlpPic[i]->destroy(); |
---|
297 | delete m_cIlpPic[i]; |
---|
298 | m_cIlpPic[i] = NULL; |
---|
299 | } |
---|
300 | } |
---|
301 | #endif |
---|
302 | return; |
---|
303 | } |
---|
304 | |
---|
305 | Void TEncTop::init() |
---|
306 | { |
---|
307 | // initialize SPS |
---|
308 | xInitSPS(); |
---|
309 | |
---|
310 | /* set the VPS profile information */ |
---|
311 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
---|
312 | #if L0043_TIMING_INFO |
---|
313 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
314 | #endif |
---|
315 | // initialize PPS |
---|
316 | m_cPPS.setSPS(&m_cSPS); |
---|
317 | xInitPPS(); |
---|
318 | xInitRPS(); |
---|
319 | |
---|
320 | xInitPPSforTiles(); |
---|
321 | |
---|
322 | // initialize processing unit classes |
---|
323 | m_cGOPEncoder. init( this ); |
---|
324 | m_cSliceEncoder.init( this ); |
---|
325 | m_cCuEncoder. init( this ); |
---|
326 | |
---|
327 | // initialize transform & quantization class |
---|
328 | m_pcCavlcCoder = getCavlcCoder(); |
---|
329 | |
---|
330 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
---|
331 | m_useRDOQ, |
---|
332 | m_useRDOQTS, |
---|
333 | true |
---|
334 | ,m_useTransformSkipFast |
---|
335 | #if ADAPTIVE_QP_SELECTION |
---|
336 | , m_bUseAdaptQpSelect |
---|
337 | #endif |
---|
338 | ); |
---|
339 | |
---|
340 | // initialize encoder search class |
---|
341 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
342 | |
---|
343 | m_iMaxRefPicNum = 0; |
---|
344 | #if SVC_EXTENSION |
---|
345 | m_iSPSIdCnt ++; |
---|
346 | m_iPPSIdCnt ++; |
---|
347 | #endif |
---|
348 | #if REF_IDX_FRAMEWORK |
---|
349 | xInitILRP(); |
---|
350 | #endif |
---|
351 | } |
---|
352 | |
---|
353 | // ==================================================================================================================== |
---|
354 | // Public member functions |
---|
355 | // ==================================================================================================================== |
---|
356 | |
---|
357 | Void TEncTop::deletePicBuffer() |
---|
358 | { |
---|
359 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
360 | Int iSize = Int( m_cListPic.size() ); |
---|
361 | |
---|
362 | for ( Int i = 0; i < iSize; i++ ) |
---|
363 | { |
---|
364 | TComPic* pcPic = *(iterPic++); |
---|
365 | |
---|
366 | pcPic->destroy(); |
---|
367 | delete pcPic; |
---|
368 | pcPic = NULL; |
---|
369 | } |
---|
370 | } |
---|
371 | |
---|
372 | /** |
---|
373 | - Application has picture buffer list with size of GOP + 1 |
---|
374 | - Picture buffer list acts like as ring buffer |
---|
375 | - End of the list has the latest picture |
---|
376 | . |
---|
377 | \param flush cause encoder to encode a partial GOP |
---|
378 | \param pcPicYuvOrg original YUV picture |
---|
379 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
380 | \retval rcListBitstreamOut list of output bitstreams |
---|
381 | \retval iNumEncoded number of encoded pictures |
---|
382 | */ |
---|
383 | #if SVC_EXTENSION |
---|
384 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ) |
---|
385 | { |
---|
386 | // compress GOP |
---|
387 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
388 | if ( m_RCEnableRateControl ) |
---|
389 | { |
---|
390 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
391 | } |
---|
392 | #endif |
---|
393 | |
---|
394 | // compress GOP |
---|
395 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
396 | |
---|
397 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
398 | if ( m_RCEnableRateControl ) |
---|
399 | { |
---|
400 | m_cRateCtrl.destroyRCGOP(); |
---|
401 | } |
---|
402 | #endif |
---|
403 | |
---|
404 | m_uiNumAllPicCoded ++; |
---|
405 | } |
---|
406 | |
---|
407 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg ) |
---|
408 | { |
---|
409 | if (pcPicYuvOrg) { |
---|
410 | // get original YUV |
---|
411 | TComPic* pcPicCurr = NULL; |
---|
412 | xGetNewPicBuffer( pcPicCurr ); |
---|
413 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
414 | |
---|
415 | // compute image characteristics |
---|
416 | if ( getUseAdaptiveQP() ) |
---|
417 | { |
---|
418 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
419 | } |
---|
420 | } |
---|
421 | } |
---|
422 | #else |
---|
423 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
424 | { |
---|
425 | if (pcPicYuvOrg) { |
---|
426 | // get original YUV |
---|
427 | TComPic* pcPicCurr = NULL; |
---|
428 | xGetNewPicBuffer( pcPicCurr ); |
---|
429 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
430 | |
---|
431 | // compute image characteristics |
---|
432 | if ( getUseAdaptiveQP() ) |
---|
433 | { |
---|
434 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) |
---|
439 | { |
---|
440 | iNumEncoded = 0; |
---|
441 | return; |
---|
442 | } |
---|
443 | |
---|
444 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
445 | if ( m_RCEnableRateControl ) |
---|
446 | { |
---|
447 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
448 | } |
---|
449 | #endif |
---|
450 | |
---|
451 | // compress GOP |
---|
452 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); |
---|
453 | |
---|
454 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
455 | if ( m_RCEnableRateControl ) |
---|
456 | { |
---|
457 | m_cRateCtrl.destroyRCGOP(); |
---|
458 | } |
---|
459 | #endif |
---|
460 | |
---|
461 | iNumEncoded = m_iNumPicRcvd; |
---|
462 | m_iNumPicRcvd = 0; |
---|
463 | m_uiNumAllPicCoded += iNumEncoded; |
---|
464 | } |
---|
465 | #endif |
---|
466 | |
---|
467 | // ==================================================================================================================== |
---|
468 | // Protected member functions |
---|
469 | // ==================================================================================================================== |
---|
470 | |
---|
471 | /** |
---|
472 | - Application has picture buffer list with size of GOP + 1 |
---|
473 | - Picture buffer list acts like as ring buffer |
---|
474 | - End of the list has the latest picture |
---|
475 | . |
---|
476 | \retval rpcPic obtained picture buffer |
---|
477 | */ |
---|
478 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
479 | { |
---|
480 | TComSlice::sortPicList(m_cListPic); |
---|
481 | |
---|
482 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
483 | { |
---|
484 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
485 | Int iSize = Int( m_cListPic.size() ); |
---|
486 | for ( Int i = 0; i < iSize; i++ ) |
---|
487 | { |
---|
488 | rpcPic = *(iterPic++); |
---|
489 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
490 | { |
---|
491 | break; |
---|
492 | } |
---|
493 | } |
---|
494 | } |
---|
495 | else |
---|
496 | { |
---|
497 | if ( getUseAdaptiveQP() ) |
---|
498 | { |
---|
499 | TEncPic* pcEPic = new TEncPic; |
---|
500 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
501 | if(m_layerId > 0) |
---|
502 | { |
---|
503 | TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 ); |
---|
504 | if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() ) |
---|
505 | { |
---|
506 | pcEPic->setSpatialEnhLayerFlag( true ); |
---|
507 | } |
---|
508 | } |
---|
509 | #endif |
---|
510 | |
---|
511 | #if SVC_UPSAMPLING |
---|
512 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
513 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
514 | #else |
---|
515 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
516 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
517 | #endif |
---|
518 | rpcPic = pcEPic; |
---|
519 | } |
---|
520 | else |
---|
521 | { |
---|
522 | rpcPic = new TComPic; |
---|
523 | |
---|
524 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
525 | if(m_layerId > 0) |
---|
526 | { |
---|
527 | TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 ); |
---|
528 | if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() ) |
---|
529 | { |
---|
530 | rpcPic->setSpatialEnhLayerFlag( true ); |
---|
531 | } |
---|
532 | } |
---|
533 | #endif |
---|
534 | |
---|
535 | #if SVC_UPSAMPLING |
---|
536 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
537 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
538 | #else |
---|
539 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
540 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
541 | #endif |
---|
542 | } |
---|
543 | if (getUseSAO()) |
---|
544 | { |
---|
545 | rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO); |
---|
546 | } |
---|
547 | m_cListPic.pushBack( rpcPic ); |
---|
548 | } |
---|
549 | rpcPic->setReconMark (false); |
---|
550 | |
---|
551 | m_iPOCLast++; |
---|
552 | m_iNumPicRcvd++; |
---|
553 | |
---|
554 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
555 | // mark it should be extended |
---|
556 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
557 | } |
---|
558 | |
---|
559 | Void TEncTop::xInitSPS() |
---|
560 | { |
---|
561 | #if SVC_EXTENSION |
---|
562 | m_cSPS.setLayerId(m_layerId); |
---|
563 | #endif |
---|
564 | #if REF_IDX_MFM |
---|
565 | m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag); |
---|
566 | #endif |
---|
567 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
---|
568 | profileTierLevel.setLevelIdc(m_level); |
---|
569 | profileTierLevel.setTierFlag(m_levelTier); |
---|
570 | profileTierLevel.setProfileIdc(m_profile); |
---|
571 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
---|
572 | #if L0046_CONSTRAINT_FLAGS |
---|
573 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
574 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
575 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
576 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
577 | #endif |
---|
578 | |
---|
579 | if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8) |
---|
580 | { |
---|
581 | /* The above constraint is equal to Profile::MAIN */ |
---|
582 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
---|
583 | } |
---|
584 | if (m_profile == Profile::MAIN) |
---|
585 | { |
---|
586 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
---|
587 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
---|
588 | } |
---|
589 | /* XXX: should Main be marked as compatible with still picture? */ |
---|
590 | /* XXX: may be a good idea to refactor the above into a function |
---|
591 | * that chooses the actual compatibility based upon options */ |
---|
592 | |
---|
593 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
594 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
595 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
---|
596 | m_cSPS.setMaxCUWidth ( g_uiMaxCUWidth ); |
---|
597 | m_cSPS.setMaxCUHeight ( g_uiMaxCUHeight ); |
---|
598 | m_cSPS.setMaxCUDepth ( g_uiMaxCUDepth ); |
---|
599 | m_cSPS.setMinTrDepth ( 0 ); |
---|
600 | m_cSPS.setMaxTrDepth ( 1 ); |
---|
601 | #if SVC_EXTENSION |
---|
602 | m_cSPS.setSPSId ( m_iSPSIdCnt ); |
---|
603 | #endif |
---|
604 | |
---|
605 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
606 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
607 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
608 | |
---|
609 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
610 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
611 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
612 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
613 | |
---|
614 | m_cSPS.setTMVPFlagsPresent(false); |
---|
615 | m_cSPS.setUseLossless ( m_useLossless ); |
---|
616 | |
---|
617 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
618 | |
---|
619 | m_cSPS.setUseLComb ( m_bUseLComb ); |
---|
620 | |
---|
621 | Int i; |
---|
622 | |
---|
623 | for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ ) |
---|
624 | { |
---|
625 | m_cSPS.setAMPAcc( i, m_useAMP ); |
---|
626 | //m_cSPS.setAMPAcc( i, 1 ); |
---|
627 | } |
---|
628 | |
---|
629 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
630 | |
---|
631 | for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ ) |
---|
632 | { |
---|
633 | m_cSPS.setAMPAcc(i, 0); |
---|
634 | } |
---|
635 | |
---|
636 | m_cSPS.setBitDepthY( g_bitDepthY ); |
---|
637 | m_cSPS.setBitDepthC( g_bitDepthC ); |
---|
638 | |
---|
639 | m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) ); |
---|
640 | m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) ); |
---|
641 | |
---|
642 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
643 | |
---|
644 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
645 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
---|
646 | for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ ) |
---|
647 | { |
---|
648 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
649 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
650 | } |
---|
651 | m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma); |
---|
652 | m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma); |
---|
653 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
654 | |
---|
655 | m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 ); |
---|
656 | |
---|
657 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
658 | |
---|
659 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
660 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
661 | { |
---|
662 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
663 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1); |
---|
664 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
665 | pcVUI->setSarWidth(getSarWidth()); |
---|
666 | pcVUI->setSarHeight(getSarHeight()); |
---|
667 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
668 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
669 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
670 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
671 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
672 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
673 | pcVUI->setColourPrimaries(getColourPrimaries()); |
---|
674 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
675 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
676 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
677 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
678 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
679 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
680 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
---|
681 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
---|
682 | pcVUI->setFieldSeqFlag(false); |
---|
683 | pcVUI->setHrdParametersPresentFlag(false); |
---|
684 | #if L0043_TIMING_INFO |
---|
685 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
686 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
687 | #else |
---|
688 | pcVUI->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
689 | pcVUI->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
690 | #endif |
---|
691 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
692 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
693 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
694 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
---|
695 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
696 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
697 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
698 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
699 | } |
---|
700 | } |
---|
701 | |
---|
702 | Void TEncTop::xInitPPS() |
---|
703 | { |
---|
704 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
705 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
706 | |
---|
707 | Int lowestQP = - m_cSPS.getQpBDOffsetY(); |
---|
708 | |
---|
709 | if(getUseLossless()) |
---|
710 | { |
---|
711 | if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) ) |
---|
712 | { |
---|
713 | bUseDQP = false; |
---|
714 | } |
---|
715 | else |
---|
716 | { |
---|
717 | bUseDQP = true; |
---|
718 | } |
---|
719 | } |
---|
720 | else |
---|
721 | { |
---|
722 | if(bUseDQP == false) |
---|
723 | { |
---|
724 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
725 | { |
---|
726 | bUseDQP = true; |
---|
727 | } |
---|
728 | } |
---|
729 | } |
---|
730 | |
---|
731 | if(bUseDQP) |
---|
732 | { |
---|
733 | m_cPPS.setUseDQP(true); |
---|
734 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
735 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
736 | } |
---|
737 | else |
---|
738 | { |
---|
739 | m_cPPS.setUseDQP(false); |
---|
740 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
741 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
742 | } |
---|
743 | |
---|
744 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
745 | if ( m_RCEnableRateControl ) |
---|
746 | { |
---|
747 | m_cPPS.setUseDQP(true); |
---|
748 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
749 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
750 | } |
---|
751 | #endif |
---|
752 | |
---|
753 | m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset ); |
---|
754 | m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset ); |
---|
755 | |
---|
756 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
757 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
---|
758 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
759 | m_cPPS.setUseWP( m_useWeightedPred ); |
---|
760 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
761 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
762 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
763 | m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent ); |
---|
764 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
765 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
766 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
767 | Int histogram[MAX_NUM_REF + 1]; |
---|
768 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
769 | { |
---|
770 | histogram[i]=0; |
---|
771 | } |
---|
772 | for( Int i = 0; i < getGOPSize(); i++ ) |
---|
773 | { |
---|
774 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
---|
775 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
776 | } |
---|
777 | Int maxHist=-1; |
---|
778 | Int bestPos=0; |
---|
779 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
780 | { |
---|
781 | if(histogram[i]>maxHist) |
---|
782 | { |
---|
783 | maxHist=histogram[i]; |
---|
784 | bestPos=i; |
---|
785 | } |
---|
786 | } |
---|
787 | #if L0323_LIMIT_DEFAULT_LIST_SIZE |
---|
788 | assert(bestPos <= 15); |
---|
789 | #endif |
---|
790 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
791 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
792 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
793 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
794 | if (m_sliceSegmentMode) |
---|
795 | { |
---|
796 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
---|
797 | } |
---|
798 | if( m_cPPS.getDependentSliceSegmentsEnabledFlag() ) |
---|
799 | { |
---|
800 | Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1; |
---|
801 | m_cSliceEncoder.initCtxMem( NumCtx ); |
---|
802 | for ( UInt st = 0; st < NumCtx; st++ ) |
---|
803 | { |
---|
804 | TEncSbac* ctx = NULL; |
---|
805 | ctx = new TEncSbac; |
---|
806 | ctx->init( &m_cBinCoderCABAC ); |
---|
807 | m_cSliceEncoder.setCtxMem( ctx, st ); |
---|
808 | } |
---|
809 | } |
---|
810 | #if SVC_EXTENSION |
---|
811 | m_cPPS.setPPSId ( m_iPPSIdCnt ); |
---|
812 | m_cPPS.setSPSId ( m_iSPSIdCnt ); |
---|
813 | #endif |
---|
814 | } |
---|
815 | |
---|
816 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
817 | Void TEncTop::xInitRPS() |
---|
818 | { |
---|
819 | TComReferencePictureSet* rps; |
---|
820 | |
---|
821 | m_cSPS.createRPSList(getGOPSize()+m_extraRPSs); |
---|
822 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
823 | |
---|
824 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
825 | { |
---|
826 | GOPEntry ge = getGOPEntry(i); |
---|
827 | rps = rpsList->getReferencePictureSet(i); |
---|
828 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
829 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
830 | Int numNeg = 0; |
---|
831 | Int numPos = 0; |
---|
832 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
833 | { |
---|
834 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
835 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
836 | if(ge.m_referencePics[j]>0) |
---|
837 | { |
---|
838 | numPos++; |
---|
839 | } |
---|
840 | else |
---|
841 | { |
---|
842 | numNeg++; |
---|
843 | } |
---|
844 | } |
---|
845 | rps->setNumberOfNegativePictures(numNeg); |
---|
846 | rps->setNumberOfPositivePictures(numPos); |
---|
847 | |
---|
848 | // handle inter RPS intialization from the config file. |
---|
849 | #if AUTO_INTER_RPS |
---|
850 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
851 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
852 | TComReferencePictureSet* RPSRef = rpsList->getReferencePictureSet(i-1); // get the reference RPS |
---|
853 | |
---|
854 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
855 | { |
---|
856 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
857 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
858 | |
---|
859 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
860 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
861 | Int count=0; |
---|
862 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
863 | { |
---|
864 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
865 | rps->setRefIdc(j, 0); |
---|
866 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
867 | { |
---|
868 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
869 | { |
---|
870 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
871 | count++; |
---|
872 | break; |
---|
873 | } |
---|
874 | } |
---|
875 | } |
---|
876 | if (count != rps->getNumberOfPictures()) |
---|
877 | { |
---|
878 | 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"); |
---|
879 | rps->setInterRPSPrediction(0); |
---|
880 | } |
---|
881 | } |
---|
882 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
883 | { |
---|
884 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
885 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
886 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
887 | { |
---|
888 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
889 | } |
---|
890 | #if WRITE_BACK |
---|
891 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
892 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
893 | numNeg = 0; |
---|
894 | numPos = 0; |
---|
895 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
896 | |
---|
897 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
898 | { |
---|
899 | if (ge.m_refIdc[j]) |
---|
900 | { |
---|
901 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
902 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
903 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
904 | if (deltaPOC<0) |
---|
905 | { |
---|
906 | numNeg++; |
---|
907 | } |
---|
908 | else |
---|
909 | { |
---|
910 | numPos++; |
---|
911 | } |
---|
912 | } |
---|
913 | } |
---|
914 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
915 | { |
---|
916 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
917 | rps->setNumberOfNegativePictures(numNeg); |
---|
918 | rps->setNumberOfPositivePictures(numNeg+numPos); |
---|
919 | } |
---|
920 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
921 | { |
---|
922 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
923 | rps->setNumberOfPositivePictures(numPos); |
---|
924 | rps->setNumberOfPositivePictures(numNeg+numPos); |
---|
925 | } |
---|
926 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
927 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
928 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
929 | // check if Delta POC and Used are the same |
---|
930 | // print warning if they are not. |
---|
931 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
932 | { |
---|
933 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
934 | { |
---|
935 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
936 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
937 | } |
---|
938 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
939 | { |
---|
940 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
941 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
942 | } |
---|
943 | } |
---|
944 | #endif |
---|
945 | } |
---|
946 | #else |
---|
947 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
948 | if (ge.m_interRPSPrediction) |
---|
949 | { |
---|
950 | rps->setDeltaRIdxMinus1(0); |
---|
951 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
952 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
953 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
954 | { |
---|
955 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
956 | } |
---|
957 | #if WRITE_BACK |
---|
958 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
959 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
960 | numNeg = 0; |
---|
961 | numPos = 0; |
---|
962 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-1); |
---|
963 | |
---|
964 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
965 | { |
---|
966 | if (ge.m_refIdc[j]) |
---|
967 | { |
---|
968 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
969 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
970 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
971 | if (deltaPOC<0) |
---|
972 | { |
---|
973 | numNeg++; |
---|
974 | } |
---|
975 | else |
---|
976 | { |
---|
977 | numPos++; |
---|
978 | } |
---|
979 | } |
---|
980 | } |
---|
981 | rps->setNumberOfNegativePictures(numNeg); |
---|
982 | rps->setNumberOfPositivePictures(numPos); |
---|
983 | rps->sortDeltaPOC(); |
---|
984 | #endif |
---|
985 | } |
---|
986 | #endif //INTER_RPS_AUTO |
---|
987 | } |
---|
988 | |
---|
989 | } |
---|
990 | |
---|
991 | // This is a function that |
---|
992 | // determines what Reference Picture Set to use |
---|
993 | // for a specific slice (with POC = POCCurr) |
---|
994 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
995 | { |
---|
996 | slice->setRPSidx(GOPid); |
---|
997 | |
---|
998 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
999 | { |
---|
1000 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
1001 | { |
---|
1002 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
1003 | if(POCIndex == 0) |
---|
1004 | { |
---|
1005 | POCIndex = m_uiIntraPeriod; |
---|
1006 | } |
---|
1007 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
1008 | { |
---|
1009 | slice->setRPSidx(extraNum); |
---|
1010 | } |
---|
1011 | } |
---|
1012 | else |
---|
1013 | { |
---|
1014 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
1015 | { |
---|
1016 | slice->setRPSidx(extraNum); |
---|
1017 | } |
---|
1018 | } |
---|
1019 | } |
---|
1020 | |
---|
1021 | slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
1022 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
1023 | |
---|
1024 | } |
---|
1025 | |
---|
1026 | Void TEncTop::xInitPPSforTiles() |
---|
1027 | { |
---|
1028 | m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr ); |
---|
1029 | m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
1030 | m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
1031 | if( m_iUniformSpacingIdr == 0 ) |
---|
1032 | { |
---|
1033 | m_cPPS.setColumnWidth( m_puiColumnWidth ); |
---|
1034 | m_cPPS.setRowHeight( m_puiRowHeight ); |
---|
1035 | } |
---|
1036 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
1037 | |
---|
1038 | // # substreams is "per tile" when tiles are independent. |
---|
1039 | if (m_iWaveFrontSynchro |
---|
1040 | ) |
---|
1041 | { |
---|
1042 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)); |
---|
1043 | } |
---|
1044 | } |
---|
1045 | |
---|
1046 | Void TEncCfg::xCheckGSParameters() |
---|
1047 | { |
---|
1048 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
1049 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
1050 | UInt uiCummulativeColumnWidth = 0; |
---|
1051 | UInt uiCummulativeRowHeight = 0; |
---|
1052 | |
---|
1053 | //check the column relative parameters |
---|
1054 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
1055 | { |
---|
1056 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
1057 | exit( EXIT_FAILURE ); |
---|
1058 | } |
---|
1059 | |
---|
1060 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
1061 | { |
---|
1062 | printf( "The current picture can not have so many columns.\n" ); |
---|
1063 | exit( EXIT_FAILURE ); |
---|
1064 | } |
---|
1065 | |
---|
1066 | if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1067 | { |
---|
1068 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
1069 | { |
---|
1070 | uiCummulativeColumnWidth += m_puiColumnWidth[i]; |
---|
1071 | } |
---|
1072 | |
---|
1073 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
1074 | { |
---|
1075 | printf( "The width of the column is too large.\n" ); |
---|
1076 | exit( EXIT_FAILURE ); |
---|
1077 | } |
---|
1078 | } |
---|
1079 | |
---|
1080 | //check the row relative parameters |
---|
1081 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
1082 | { |
---|
1083 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
1084 | exit( EXIT_FAILURE ); |
---|
1085 | } |
---|
1086 | |
---|
1087 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
1088 | { |
---|
1089 | printf( "The current picture can not have so many rows.\n" ); |
---|
1090 | exit( EXIT_FAILURE ); |
---|
1091 | } |
---|
1092 | |
---|
1093 | if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
1094 | { |
---|
1095 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
1096 | uiCummulativeRowHeight += m_puiRowHeight[i]; |
---|
1097 | |
---|
1098 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
1099 | { |
---|
1100 | printf( "The height of the row is too large.\n" ); |
---|
1101 | exit( EXIT_FAILURE ); |
---|
1102 | } |
---|
1103 | } |
---|
1104 | } |
---|
1105 | |
---|
1106 | #if REF_IDX_FRAMEWORK |
---|
1107 | Void TEncTop::xInitILRP() |
---|
1108 | { |
---|
1109 | if(m_layerId>0) |
---|
1110 | { |
---|
1111 | Int numReorderPics[MAX_TLAYER]; |
---|
1112 | Window &conformanceWindow = m_cSPS.getConformanceWindow(); |
---|
1113 | Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window(); |
---|
1114 | |
---|
1115 | if (m_cIlpPic[0] == NULL) |
---|
1116 | { |
---|
1117 | for (Int j=0; j<1/*MAX_NUM_REF*/; j++) |
---|
1118 | { |
---|
1119 | m_cIlpPic[j] = new TComPic; |
---|
1120 | //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true); |
---|
1121 | #if SVC_UPSAMPLING |
---|
1122 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
1123 | #else |
---|
1124 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true); |
---|
1125 | #endif |
---|
1126 | #if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM |
---|
1127 | m_cIlpPic[j]->setIsILR(true); |
---|
1128 | #endif |
---|
1129 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
---|
1130 | { |
---|
1131 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
---|
1132 | } |
---|
1133 | } |
---|
1134 | } |
---|
1135 | } |
---|
1136 | } |
---|
1137 | |
---|
1138 | Void TEncTop::setILRPic(TComPic *pcPic) |
---|
1139 | { |
---|
1140 | if(m_cIlpPic[0]) |
---|
1141 | { |
---|
1142 | //m_cIlpPic[0]->setPicYuvRec(pcPic->getFullPelBaseRec()); |
---|
1143 | m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec()); |
---|
1144 | m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC()); |
---|
1145 | m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false); |
---|
1146 | m_cIlpPic[0]->getPicYuvRec()->extendPicBorder(); |
---|
1147 | } |
---|
1148 | } |
---|
1149 | #endif |
---|
1150 | //! \} |
---|