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