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-2016, 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 TAppEncTop.cpp |
---|
35 | \brief Encoder application class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <list> |
---|
39 | #include <fstream> |
---|
40 | #include <stdlib.h> |
---|
41 | #include <stdio.h> |
---|
42 | #include <fcntl.h> |
---|
43 | #include <assert.h> |
---|
44 | #if !SVC_EXTENSION |
---|
45 | #include <iomanip> |
---|
46 | #endif |
---|
47 | |
---|
48 | #include "TAppEncTop.h" |
---|
49 | #include "TLibEncoder/AnnexBwrite.h" |
---|
50 | |
---|
51 | using namespace std; |
---|
52 | |
---|
53 | //! \ingroup TAppEncoder |
---|
54 | //! \{ |
---|
55 | |
---|
56 | // ==================================================================================================================== |
---|
57 | // Constructor / destructor / initialization / destroy |
---|
58 | // ==================================================================================================================== |
---|
59 | |
---|
60 | TAppEncTop::TAppEncTop() |
---|
61 | { |
---|
62 | m_iFrameRcvd = 0; |
---|
63 | m_totalBytes = 0; |
---|
64 | m_essentialBytes = 0; |
---|
65 | #if SVC_EXTENSION |
---|
66 | memset( m_apcTVideoIOYuvInputFile, 0, sizeof(m_apcTVideoIOYuvInputFile) ); |
---|
67 | memset( m_apcTVideoIOYuvReconFile, 0, sizeof(m_apcTVideoIOYuvReconFile) ); |
---|
68 | memset( m_apcTEncTop, 0, sizeof(m_apcTEncTop) ); |
---|
69 | #endif |
---|
70 | } |
---|
71 | |
---|
72 | TAppEncTop::~TAppEncTop() |
---|
73 | { |
---|
74 | } |
---|
75 | |
---|
76 | Void TAppEncTop::xInitLibCfg() |
---|
77 | { |
---|
78 | #if SVC_EXTENSION |
---|
79 | TComVPS& vps = *m_apcTEncTop[0]->getVPS(); |
---|
80 | |
---|
81 | vps.setMaxTLayers ( m_apcLayerCfg[0]->m_maxTempLayer ); |
---|
82 | if (m_apcLayerCfg[0]->m_maxTempLayer == 1) |
---|
83 | #else |
---|
84 | TComVPS vps; |
---|
85 | |
---|
86 | vps.setMaxTLayers ( m_maxTempLayer ); |
---|
87 | if (m_maxTempLayer == 1) |
---|
88 | #endif |
---|
89 | { |
---|
90 | vps.setTemporalNestingFlag(true); |
---|
91 | } |
---|
92 | vps.setMaxLayers ( 1 ); |
---|
93 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
94 | { |
---|
95 | vps.setNumReorderPics ( m_numReorderPics[i], i ); |
---|
96 | vps.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
97 | } |
---|
98 | |
---|
99 | #if !SVC_EXTENSION |
---|
100 | m_cTEncTop.setVPS(&vps); |
---|
101 | #endif |
---|
102 | |
---|
103 | #if SVC_EXTENSION |
---|
104 | vps.setVpsPocLsbAlignedFlag(false); |
---|
105 | |
---|
106 | Int maxRepFormatIdx = -1; |
---|
107 | Int formatIdx = -1; |
---|
108 | for(UInt layer=0; layer < m_numLayers; layer++) |
---|
109 | { |
---|
110 | // Auto generation of the format index |
---|
111 | if( m_apcLayerCfg[layer]->getRepFormatIdx() == -1 ) |
---|
112 | { |
---|
113 | Bool found = false; |
---|
114 | for( UInt idx = 0; idx < layer; idx++ ) |
---|
115 | { |
---|
116 | if( m_apcLayerCfg[layer]->m_iSourceWidth == m_apcLayerCfg[idx]->m_iSourceWidth && m_apcLayerCfg[layer]->m_iSourceHeight == m_apcLayerCfg[idx]->m_iSourceHeight |
---|
117 | #if AUXILIARY_PICTURES |
---|
118 | && m_apcLayerCfg[layer]->m_chromaFormatIDC == m_apcLayerCfg[idx]->m_chromaFormatIDC |
---|
119 | #endif |
---|
120 | && m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA] == m_apcLayerCfg[idx]->m_internalBitDepth[CHANNEL_TYPE_LUMA] && m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA] == m_apcLayerCfg[idx]->m_internalBitDepth[CHANNEL_TYPE_CHROMA] |
---|
121 | ) |
---|
122 | { |
---|
123 | found = true; |
---|
124 | break; |
---|
125 | } |
---|
126 | } |
---|
127 | if( !found ) |
---|
128 | { |
---|
129 | formatIdx++; |
---|
130 | } |
---|
131 | |
---|
132 | m_apcLayerCfg[layer]->setRepFormatIdx( formatIdx ); |
---|
133 | } |
---|
134 | |
---|
135 | assert( m_apcLayerCfg[layer]->getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" ); |
---|
136 | |
---|
137 | vps.setVpsRepFormatIdx( layer, m_apcLayerCfg[layer]->getRepFormatIdx() ); |
---|
138 | |
---|
139 | maxRepFormatIdx = std::max( m_apcLayerCfg[layer]->getRepFormatIdx(), maxRepFormatIdx ); |
---|
140 | |
---|
141 | for(Int compareLayer = 0; compareLayer < layer; compareLayer++ ) |
---|
142 | { |
---|
143 | if(m_apcLayerCfg[layer]->m_repFormatIdx == m_apcLayerCfg[compareLayer]->m_repFormatIdx && ( |
---|
144 | m_apcLayerCfg[layer]->m_chromaFormatIDC != m_apcLayerCfg[compareLayer]->m_chromaFormatIDC |
---|
145 | // separate_colour_plane_flag not supported yet but if supported insert check here |
---|
146 | || m_apcLayerCfg[layer]->m_iSourceWidth != m_apcLayerCfg[compareLayer]->m_iSourceWidth |
---|
147 | || m_apcLayerCfg[layer]->m_iSourceHeight != m_apcLayerCfg[compareLayer]->m_iSourceHeight |
---|
148 | || m_apcLayerCfg[layer]->m_internalBitDepth[0] != m_apcLayerCfg[compareLayer]->m_internalBitDepth[0] |
---|
149 | || m_apcLayerCfg[layer]->m_internalBitDepth[1] != m_apcLayerCfg[compareLayer]->m_internalBitDepth[1] |
---|
150 | || m_apcLayerCfg[layer]->m_confWinLeft != m_apcLayerCfg[compareLayer]->m_confWinLeft |
---|
151 | || m_apcLayerCfg[layer]->m_confWinRight != m_apcLayerCfg[compareLayer]->m_confWinRight |
---|
152 | || m_apcLayerCfg[layer]->m_confWinTop != m_apcLayerCfg[compareLayer]->m_confWinTop |
---|
153 | || m_apcLayerCfg[layer]->m_confWinBottom != m_apcLayerCfg[compareLayer]->m_confWinBottom |
---|
154 | )) |
---|
155 | { |
---|
156 | fprintf(stderr, "Error: Two layers using the same FormatIdx value must share the same values of the related parameters\n"); |
---|
157 | exit(EXIT_FAILURE); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | assert( vps.getVpsRepFormatIdx( 0 ) == 0 ); // Base layer should point to the first one. |
---|
163 | |
---|
164 | Int* mapIdxToLayer = new Int[maxRepFormatIdx + 1]; |
---|
165 | |
---|
166 | // Check that all the indices from 0 to maxRepFormatIdx are used in the VPS |
---|
167 | for(Int i = 0; i <= maxRepFormatIdx; i++) |
---|
168 | { |
---|
169 | mapIdxToLayer[i] = -1; |
---|
170 | UInt layer; |
---|
171 | for(layer=0; layer < m_numLayers; layer++) |
---|
172 | { |
---|
173 | if( vps.getVpsRepFormatIdx(layer) == i ) |
---|
174 | { |
---|
175 | mapIdxToLayer[i] = layer; |
---|
176 | break; |
---|
177 | } |
---|
178 | } |
---|
179 | assert( layer != m_numLayers ); // One of the VPS Rep format indices not set |
---|
180 | } |
---|
181 | |
---|
182 | vps.setVpsNumRepFormats ( maxRepFormatIdx + 1 ); |
---|
183 | |
---|
184 | // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0 |
---|
185 | vps.setRepFormatIdxPresentFlag ( vps.getVpsNumRepFormats() > 1 ? true : false ); |
---|
186 | |
---|
187 | for(UInt idx=0; idx < vps.getVpsNumRepFormats(); idx++) |
---|
188 | { |
---|
189 | RepFormat *repFormat = vps.getVpsRepFormat( idx ); |
---|
190 | repFormat->setChromaAndBitDepthVpsPresentFlag ( true ); |
---|
191 | if (idx==0) |
---|
192 | { |
---|
193 | assert(repFormat->getChromaAndBitDepthVpsPresentFlag() == true); |
---|
194 | } |
---|
195 | |
---|
196 | repFormat->setPicWidthVpsInLumaSamples ( m_apcLayerCfg[mapIdxToLayer[idx]]->m_iSourceWidth ); |
---|
197 | repFormat->setPicHeightVpsInLumaSamples ( m_apcLayerCfg[mapIdxToLayer[idx]]->m_iSourceHeight ); |
---|
198 | #if AUXILIARY_PICTURES |
---|
199 | repFormat->setChromaFormatVpsIdc ( m_apcLayerCfg[mapIdxToLayer[idx]]->m_chromaFormatIDC ); |
---|
200 | #else |
---|
201 | repFormat->setChromaFormatVpsIdc ( 1 ); // Need modification to change for each layer - corresponds to 420 |
---|
202 | #endif |
---|
203 | repFormat->setSeparateColourPlaneVpsFlag ( 0 ); // Need modification to change for each layer |
---|
204 | |
---|
205 | repFormat->setBitDepthVpsLuma ( getInternalBitDepth(mapIdxToLayer[idx], CHANNEL_TYPE_LUMA) ); // Need modification to change for each layer |
---|
206 | repFormat->setBitDepthVpsChroma ( getInternalBitDepth(mapIdxToLayer[idx], CHANNEL_TYPE_CHROMA) ); // Need modification to change for each layer |
---|
207 | |
---|
208 | repFormat->getConformanceWindowVps().setWindow ( m_apcLayerCfg[mapIdxToLayer[idx]]->m_confWinLeft, |
---|
209 | m_apcLayerCfg[mapIdxToLayer[idx]]->m_confWinRight, |
---|
210 | m_apcLayerCfg[mapIdxToLayer[idx]]->m_confWinTop, |
---|
211 | m_apcLayerCfg[mapIdxToLayer[idx]]->m_confWinBottom ); |
---|
212 | |
---|
213 | m_apcTEncTop[mapIdxToLayer[idx]]->setSkipPictureAtArcSwitch ( m_skipPictureAtArcSwitch ); |
---|
214 | } |
---|
215 | |
---|
216 | delete [] mapIdxToLayer; |
---|
217 | |
---|
218 | //Populate PTL in VPS |
---|
219 | for( Int ii = 0; ii < m_numPTLInfo; ii++ ) |
---|
220 | { |
---|
221 | vps.getPTL(ii)->getGeneralPTL()->setLevelIdc(m_levelList[ii]); |
---|
222 | vps.getPTL(ii)->getGeneralPTL()->setTierFlag(m_levelTierList[ii]); |
---|
223 | vps.getPTL(ii)->getGeneralPTL()->setProfileIdc(m_profileList[ii]); |
---|
224 | vps.getPTL(ii)->getGeneralPTL()->setProfileCompatibilityFlag(m_profileCompatibility[ii], 1); |
---|
225 | vps.getPTL(ii)->getGeneralPTL()->setProgressiveSourceFlag(m_progressiveSourceFlagList[ii]); |
---|
226 | vps.getPTL(ii)->getGeneralPTL()->setInterlacedSourceFlag(m_interlacedSourceFlagList[ii]); |
---|
227 | vps.getPTL(ii)->getGeneralPTL()->setNonPackedConstraintFlag(m_nonPackedConstraintFlagList[ii]); |
---|
228 | vps.getPTL(ii)->getGeneralPTL()->setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlagList[ii]); |
---|
229 | } |
---|
230 | vps.setNumProfileTierLevel(m_numPTLInfo); |
---|
231 | |
---|
232 | std::vector<Int> myvector; |
---|
233 | vps.getProfileLevelTierIdx()->resize(m_numOutputLayerSets); |
---|
234 | for( Int ii = 0; ii < m_numOutputLayerSets; ii++ ) |
---|
235 | { |
---|
236 | myvector = m_listOfLayerPTLofOlss[ii]; |
---|
237 | |
---|
238 | for( std::vector<Int>::iterator it = myvector.begin() ; it != myvector.end(); ++it ) |
---|
239 | { |
---|
240 | vps.addProfileLevelTierIdx(ii, it[0]); |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | assert( m_numLayers <= MAX_LAYERS ); |
---|
245 | |
---|
246 | for( UInt layer=0; layer < m_numLayers; layer++ ) |
---|
247 | { |
---|
248 | TEncTop& m_cTEncTop = *m_apcTEncTop[layer]; |
---|
249 | //1 |
---|
250 | m_cTEncTop.setInterLayerWeightedPredFlag ( m_useInterLayerWeightedPred ); |
---|
251 | #if AVC_BASE |
---|
252 | m_cTEncTop.setMFMEnabledFlag ( layer == 0 ? false : ( m_nonHEVCBaseLayerFlag ? false : true ) && m_apcLayerCfg[layer]->getNumMotionPredRefLayers()); |
---|
253 | #else |
---|
254 | m_cTEncTop.setMFMEnabledFlag ( layer == 0 ? false : m_apcLayerCfg[layer]->getNumMotionPredRefLayers()); |
---|
255 | #endif |
---|
256 | |
---|
257 | // set layer ID |
---|
258 | m_cTEncTop.setLayerId ( m_apcLayerCfg[layer]->m_layerId ); |
---|
259 | m_cTEncTop.setNumLayer ( m_numLayers ); |
---|
260 | m_cTEncTop.setLayerEnc ( m_apcTEncTop ); |
---|
261 | |
---|
262 | if( layer < m_numLayers - 1 ) |
---|
263 | { |
---|
264 | m_cTEncTop.setMaxTidIlRefPicsPlus1 ( m_apcLayerCfg[layer]->getMaxTidIlRefPicsPlus1()); |
---|
265 | } |
---|
266 | |
---|
267 | if( layer ) |
---|
268 | { |
---|
269 | UInt prevLayerIdx = 0; |
---|
270 | UInt prevLayerId = 0; |
---|
271 | if (m_apcLayerCfg[layer]->getNumActiveRefLayers() > 0) |
---|
272 | { |
---|
273 | prevLayerIdx = m_apcLayerCfg[layer]->getPredLayerIdx(m_apcLayerCfg[layer]->getNumActiveRefLayers() - 1); |
---|
274 | prevLayerId = m_cTEncTop.getRefLayerId(prevLayerIdx); |
---|
275 | } |
---|
276 | for(Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++) |
---|
277 | { |
---|
278 | m_cTEncTop.setSamplePredEnabledFlag (i, false); |
---|
279 | m_cTEncTop.setMotionPredEnabledFlag (i, false); |
---|
280 | } |
---|
281 | if(m_apcLayerCfg[layer]->getNumSamplePredRefLayers() == -1) |
---|
282 | { |
---|
283 | // Not included in the configuration file; assume that each layer depends on previous layer |
---|
284 | m_cTEncTop.setNumSamplePredRefLayers (1); // One sample pred ref. layer |
---|
285 | m_cTEncTop.setSamplePredRefLayerId (prevLayerIdx, prevLayerId); // Previous layer |
---|
286 | m_cTEncTop.setSamplePredEnabledFlag (prevLayerIdx, true); |
---|
287 | } |
---|
288 | else |
---|
289 | { |
---|
290 | m_cTEncTop.setNumSamplePredRefLayers ( m_apcLayerCfg[layer]->getNumSamplePredRefLayers() ); |
---|
291 | for( Int i = 0; i < m_cTEncTop.getNumSamplePredRefLayers(); i++ ) |
---|
292 | { |
---|
293 | m_cTEncTop.setSamplePredRefLayerId ( i, m_apcLayerCfg[layer]->getSamplePredRefLayerId(i)); |
---|
294 | } |
---|
295 | } |
---|
296 | if( m_apcLayerCfg[layer]->getNumMotionPredRefLayers() == -1) |
---|
297 | { |
---|
298 | // Not included in the configuration file; assume that each layer depends on previous layer |
---|
299 | m_cTEncTop.setNumMotionPredRefLayers (1); // One motion pred ref. layer |
---|
300 | m_cTEncTop.setMotionPredRefLayerId (prevLayerIdx, prevLayerId); // Previous layer |
---|
301 | m_cTEncTop.setMotionPredEnabledFlag (prevLayerIdx, true); |
---|
302 | } |
---|
303 | else |
---|
304 | { |
---|
305 | m_cTEncTop.setNumMotionPredRefLayers ( m_apcLayerCfg[layer]->getNumMotionPredRefLayers() ); |
---|
306 | for( Int i = 0; i < m_cTEncTop.getNumMotionPredRefLayers(); i++ ) |
---|
307 | { |
---|
308 | m_cTEncTop.setMotionPredRefLayerId ( i, m_apcLayerCfg[layer]->getMotionPredRefLayerId(i)); |
---|
309 | } |
---|
310 | } |
---|
311 | Int numDirectRefLayers = 0; |
---|
312 | |
---|
313 | assert( layer < MAX_LAYERS ); |
---|
314 | |
---|
315 | for (Int i = 0; i < m_apcLayerCfg[layer]->m_layerId; i++) |
---|
316 | { |
---|
317 | Int refLayerId = -1; |
---|
318 | |
---|
319 | for( Int layerIdc = 0; layerIdc < m_cTEncTop.getNumSamplePredRefLayers(); layerIdc++ ) |
---|
320 | { |
---|
321 | if( m_apcLayerCfg[layer]->getSamplePredRefLayerId(layerIdc) == i ) |
---|
322 | { |
---|
323 | refLayerId = i; |
---|
324 | m_cTEncTop.setSamplePredEnabledFlag( numDirectRefLayers, true ); |
---|
325 | break; |
---|
326 | } |
---|
327 | } |
---|
328 | |
---|
329 | for( Int layerIdc = 0; layerIdc < m_cTEncTop.getNumMotionPredRefLayers(); layerIdc++ ) |
---|
330 | { |
---|
331 | if( m_apcLayerCfg[layer]->getMotionPredRefLayerId(layerIdc) == i ) |
---|
332 | { |
---|
333 | refLayerId = i; |
---|
334 | m_cTEncTop.setMotionPredEnabledFlag( numDirectRefLayers, true ); |
---|
335 | break; |
---|
336 | } |
---|
337 | } |
---|
338 | |
---|
339 | if( refLayerId >= 0 ) |
---|
340 | { |
---|
341 | m_cTEncTop.setRefLayerId ( numDirectRefLayers, refLayerId ); |
---|
342 | numDirectRefLayers++; |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | m_cTEncTop.setNumDirectRefLayers ( numDirectRefLayers ); |
---|
347 | |
---|
348 | if(m_apcLayerCfg[layer]->getNumActiveRefLayers() == -1) |
---|
349 | { |
---|
350 | m_cTEncTop.setNumActiveRefLayers ( m_cTEncTop.getNumDirectRefLayers() ); |
---|
351 | for( Int i = 0; i < m_cTEncTop.getNumActiveRefLayers(); i++ ) |
---|
352 | { |
---|
353 | m_cTEncTop.setPredLayerIdx(i, i); |
---|
354 | } |
---|
355 | } |
---|
356 | else |
---|
357 | { |
---|
358 | m_cTEncTop.setNumActiveRefLayers ( m_apcLayerCfg[layer]->getNumActiveRefLayers() ); |
---|
359 | for(Int i = 0; i < m_cTEncTop.getNumActiveRefLayers(); i++) |
---|
360 | { |
---|
361 | m_cTEncTop.setPredLayerIdx ( i, m_apcLayerCfg[layer]->getPredLayerIdx(i)); |
---|
362 | } |
---|
363 | } |
---|
364 | } |
---|
365 | else |
---|
366 | { |
---|
367 | assert( layer == 0 ); |
---|
368 | m_cTEncTop.setNumDirectRefLayers(0); |
---|
369 | } |
---|
370 | |
---|
371 | if( layer > 0 ) |
---|
372 | { |
---|
373 | #if AUXILIARY_PICTURES |
---|
374 | Int subWidthC = ( m_apcLayerCfg[layer]->m_chromaFormatIDC == CHROMA_420 || m_apcLayerCfg[layer]->m_chromaFormatIDC == CHROMA_422 ) ? 2 : 1; |
---|
375 | Int subHeightC = ( m_apcLayerCfg[layer]->m_chromaFormatIDC == CHROMA_420 ) ? 2 : 1; |
---|
376 | #else |
---|
377 | Int subWidthC = 2; |
---|
378 | Int subHeightC = 2; |
---|
379 | #endif |
---|
380 | m_cTEncTop.setNumRefLayerLocationOffsets ( m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets ); |
---|
381 | for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++) |
---|
382 | { |
---|
383 | m_cTEncTop.setRefLocationOffsetLayerId ( i, m_apcLayerCfg[layer]->m_refLocationOffsetLayerId[i]); |
---|
384 | m_cTEncTop.setScaledRefLayerOffsetPresentFlag ( i, m_apcLayerCfg[layer]->m_scaledRefLayerOffsetPresentFlag[i] ); |
---|
385 | m_cTEncTop.getScaledRefLayerWindow(i).setWindow ( subWidthC * m_apcLayerCfg[layer]->m_scaledRefLayerLeftOffset[i], subWidthC * m_apcLayerCfg[layer]->m_scaledRefLayerRightOffset[i], |
---|
386 | subHeightC * m_apcLayerCfg[layer]->m_scaledRefLayerTopOffset[i], subHeightC * m_apcLayerCfg[layer]->m_scaledRefLayerBottomOffset[i]); |
---|
387 | |
---|
388 | Int rlSubWidthC = ( m_apcLayerCfg[i]->m_chromaFormatIDC == CHROMA_420 || m_apcLayerCfg[i]->m_chromaFormatIDC == CHROMA_422 ) ? 2 : 1; |
---|
389 | Int rlSubHeightC = ( m_apcLayerCfg[i]->m_chromaFormatIDC == CHROMA_420 ) ? 2 : 1; |
---|
390 | |
---|
391 | m_cTEncTop.setRefRegionOffsetPresentFlag ( i, m_apcLayerCfg[layer]->m_refRegionOffsetPresentFlag[i] ); |
---|
392 | m_cTEncTop.getRefLayerWindow(i).setWindow ( rlSubWidthC * m_apcLayerCfg[layer]->m_refRegionLeftOffset[i], rlSubWidthC * m_apcLayerCfg[layer]->m_refRegionRightOffset[i], |
---|
393 | rlSubHeightC * m_apcLayerCfg[layer]->m_refRegionTopOffset[i], rlSubHeightC * m_apcLayerCfg[layer]->m_refRegionBottomOffset[i]); |
---|
394 | m_cTEncTop.setResamplePhaseSetPresentFlag ( i, m_apcLayerCfg[layer]->m_resamplePhaseSetPresentFlag[i] ); |
---|
395 | m_cTEncTop.setPhaseHorLuma ( i, m_apcLayerCfg[layer]->m_phaseHorLuma[i] ); |
---|
396 | m_cTEncTop.setPhaseVerLuma ( i, m_apcLayerCfg[layer]->m_phaseVerLuma[i] ); |
---|
397 | m_cTEncTop.setPhaseHorChroma ( i, m_apcLayerCfg[layer]->m_phaseHorChroma[i] ); |
---|
398 | m_cTEncTop.setPhaseVerChroma ( i, m_apcLayerCfg[layer]->m_phaseVerChroma[i] ); |
---|
399 | } |
---|
400 | } |
---|
401 | |
---|
402 | m_cTEncTop.setElRapSliceTypeB ( m_elRapSliceBEnabled ); |
---|
403 | |
---|
404 | m_cTEncTop.setAdaptiveResolutionChange ( m_adaptiveResolutionChange ); |
---|
405 | m_cTEncTop.setLayerSwitchOffBegin ( m_apcLayerCfg[layer]->m_layerSwitchOffBegin ); |
---|
406 | m_cTEncTop.setLayerSwitchOffEnd ( m_apcLayerCfg[layer]->m_layerSwitchOffEnd ); |
---|
407 | m_cTEncTop.setChromaFormatIDC ( m_apcLayerCfg[layer]->m_chromaFormatIDC ); |
---|
408 | m_cTEncTop.setAltOuputLayerFlag ( m_altOutputLayerFlag ); |
---|
409 | m_cTEncTop.setCrossLayerBLAFlag ( m_crossLayerBLAFlag ); |
---|
410 | #if CGS_3D_ASYMLUT |
---|
411 | m_cTEncTop.setCGSFlag ( layer == 0 ? 0 : m_nCGSFlag ); |
---|
412 | m_cTEncTop.setCGSMaxOctantDepth ( m_nCGSMaxOctantDepth ); |
---|
413 | m_cTEncTop.setCGSMaxYPartNumLog2 ( m_nCGSMaxYPartNumLog2 ); |
---|
414 | m_cTEncTop.setCGSLUTBit ( m_nCGSLUTBit ); |
---|
415 | m_cTEncTop.setCGSAdaptChroma ( m_nCGSAdaptiveChroma ); |
---|
416 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
417 | m_cTEncTop.setCGSLutSizeRDO ( m_nCGSLutSizeRDO ); |
---|
418 | #endif |
---|
419 | #endif |
---|
420 | m_cTEncTop.setNumAddLayerSets ( m_numAddLayerSets ); |
---|
421 | |
---|
422 | #if FAST_INTRA_SHVC |
---|
423 | m_cTEncTop.setUseFastIntraScalable ( m_useFastIntraScalable ); |
---|
424 | #endif |
---|
425 | |
---|
426 | #if P0123_ALPHA_CHANNEL_SEI |
---|
427 | m_cTEncTop.setAlphaSEIEnabled ( m_alphaSEIEnabled ); |
---|
428 | m_cTEncTop.setAlphaCancelFlag ( m_alphaCancelFlag ); |
---|
429 | m_cTEncTop.setAlphaUseIdc ( m_alphaUseIdc ); |
---|
430 | m_cTEncTop.setAlphaBitDepthMinus8 ( m_alphaBitDepthMinus8 ); |
---|
431 | m_cTEncTop.setAlphaTransparentValue ( m_alphaTransparentValue ); |
---|
432 | m_cTEncTop.setAlphaOpaqueValue ( m_alphaOpaqueValue ); |
---|
433 | m_cTEncTop.setAlphaIncrementFlag ( m_alphaIncrementFlag ); |
---|
434 | m_cTEncTop.setAlphaClipFlag ( m_alphaClipFlag ); |
---|
435 | m_cTEncTop.setAlphaClipTypeFlag ( m_alphaClipTypeFlag ); |
---|
436 | #endif |
---|
437 | #if Q0096_OVERLAY_SEI |
---|
438 | m_cTEncTop.setOverlaySEIEnabled ( m_overlaySEIEnabled ); |
---|
439 | m_cTEncTop.setOverlaySEICancelFlag ( m_overlayInfoCancelFlag ); |
---|
440 | m_cTEncTop.setOverlaySEIContentAuxIdMinus128 ( m_overlayContentAuxIdMinus128 ); |
---|
441 | m_cTEncTop.setOverlaySEILabelAuxIdMinus128 ( m_overlayLabelAuxIdMinus128 ); |
---|
442 | m_cTEncTop.setOverlaySEIAlphaAuxIdMinus128 ( m_overlayAlphaAuxIdMinus128 ); |
---|
443 | m_cTEncTop.setOverlaySEIElementLabelValueLengthMinus8 ( m_overlayElementLabelValueLengthMinus8 ); |
---|
444 | m_cTEncTop.setOverlaySEINumOverlaysMinus1 ( m_numOverlaysMinus1 ); |
---|
445 | m_cTEncTop.setOverlaySEIIdx ( m_overlayIdx ); |
---|
446 | m_cTEncTop.setOverlaySEILanguagePresentFlag ( m_overlayLanguagePresentFlag ); |
---|
447 | m_cTEncTop.setOverlaySEIContentLayerId ( m_overlayContentLayerId ); |
---|
448 | m_cTEncTop.setOverlaySEILabelPresentFlag ( m_overlayLabelPresentFlag ); |
---|
449 | m_cTEncTop.setOverlaySEILabelLayerId ( m_overlayLabelLayerId ); |
---|
450 | m_cTEncTop.setOverlaySEIAlphaPresentFlag ( m_overlayAlphaPresentFlag ); |
---|
451 | m_cTEncTop.setOverlaySEIAlphaLayerId ( m_overlayAlphaLayerId ); |
---|
452 | m_cTEncTop.setOverlaySEINumElementsMinus1 ( m_numOverlayElementsMinus1 ); |
---|
453 | m_cTEncTop.setOverlaySEIElementLabelMin ( m_overlayElementLabelMin ); |
---|
454 | m_cTEncTop.setOverlaySEIElementLabelMax ( m_overlayElementLabelMax ); |
---|
455 | m_cTEncTop.setOverlaySEILanguage ( m_overlayLanguage ); |
---|
456 | m_cTEncTop.setOverlaySEIName ( m_overlayName ); |
---|
457 | m_cTEncTop.setOverlaySEIElementName ( m_overlayElementName ); |
---|
458 | m_cTEncTop.setOverlaySEIPersistenceFlag ( m_overlayInfoPersistenceFlag ); |
---|
459 | #endif |
---|
460 | #if Q0189_TMVP_CONSTRAINTS |
---|
461 | m_cTEncTop.setTMVPConstraintsSEIEnabled ( m_TMVPConstraintsSEIEnabled); |
---|
462 | #endif |
---|
463 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
464 | m_cTEncTop.setInterLayerConstrainedTileSetsSEIEnabled ( m_interLayerConstrainedTileSetsSEIEnabled ); |
---|
465 | m_cTEncTop.setIlNumSetsInMessage ( m_ilNumSetsInMessage ); |
---|
466 | m_cTEncTop.setSkippedTileSetPresentFlag ( m_skippedTileSetPresentFlag ); |
---|
467 | m_cTEncTop.setTopLeftTileIndex ( m_topLeftTileIndex ); |
---|
468 | m_cTEncTop.setBottomRightTileIndex ( m_bottomRightTileIndex ); |
---|
469 | m_cTEncTop.setIlcIdc ( m_ilcIdc ); |
---|
470 | #endif |
---|
471 | #if VIEW_SCALABILITY |
---|
472 | m_cTEncTop.setUseDisparitySearchRangeRestriction ( m_scalabilityMask[VIEW_ORDER_INDEX] ); |
---|
473 | #endif |
---|
474 | |
---|
475 | Int& layerPTLIdx = m_apcLayerCfg[layer]->m_layerPTLIdx; |
---|
476 | |
---|
477 | Profile::Name& m_profile = m_profileList[layerPTLIdx]; |
---|
478 | Level::Tier& m_levelTier = m_levelTierList[layerPTLIdx]; |
---|
479 | Level::Name& m_level = m_levelList[layerPTLIdx]; |
---|
480 | UInt& m_bitDepthConstraint = m_apcLayerCfg[layer]->m_bitDepthConstraint; |
---|
481 | ChromaFormat& m_chromaFormatConstraint = m_apcLayerCfg[layer]->m_chromaFormatConstraint; |
---|
482 | Bool& m_intraConstraintFlag = m_apcLayerCfg[layer]->m_intraConstraintFlag; |
---|
483 | Bool& m_onePictureOnlyConstraintFlag = m_apcLayerCfg[layer]->m_onePictureOnlyConstraintFlag; |
---|
484 | Bool& m_lowerBitRateConstraintFlag = m_apcLayerCfg[layer]->m_lowerBitRateConstraintFlag; |
---|
485 | Bool& m_progressiveSourceFlag = m_progressiveSourceFlagList[layerPTLIdx]; |
---|
486 | Bool& m_interlacedSourceFlag = m_interlacedSourceFlagList[layerPTLIdx]; |
---|
487 | Bool& m_nonPackedConstraintFlag = m_nonPackedConstraintFlagList[layerPTLIdx]; |
---|
488 | Bool& m_frameOnlyConstraintFlag = m_frameOnlyConstraintFlagList[layerPTLIdx]; |
---|
489 | |
---|
490 | Int& m_iFrameRate = m_apcLayerCfg[layer]->m_iFrameRate; |
---|
491 | Int& m_iSourceWidth = m_apcLayerCfg[layer]->m_iSourceWidth; |
---|
492 | Int& m_iSourceHeight = m_apcLayerCfg[layer]->m_iSourceHeight; |
---|
493 | Int& m_confWinLeft = m_apcLayerCfg[layer]->m_confWinLeft; |
---|
494 | Int& m_confWinRight = m_apcLayerCfg[layer]->m_confWinRight; |
---|
495 | Int& m_confWinTop = m_apcLayerCfg[layer]->m_confWinTop; |
---|
496 | Int& m_confWinBottom = m_apcLayerCfg[layer]->m_confWinBottom; |
---|
497 | |
---|
498 | Int& m_iIntraPeriod = m_apcLayerCfg[layer]->m_iIntraPeriod; |
---|
499 | Int& m_iQP = m_apcLayerCfg[layer]->m_iQP; |
---|
500 | Int *m_aiPad = m_apcLayerCfg[layer]->m_aiPad; |
---|
501 | |
---|
502 | Int& m_iMaxCuDQPDepth = m_apcLayerCfg[layer]->m_iMaxCuDQPDepth; |
---|
503 | ChromaFormat& m_chromaFormatIDC = m_apcLayerCfg[layer]->m_chromaFormatIDC; |
---|
504 | Int *m_aidQP = m_apcLayerCfg[layer]->m_aidQP; |
---|
505 | |
---|
506 | UInt& m_uiMaxCUWidth = m_apcLayerCfg[layer]->m_uiMaxCUWidth; |
---|
507 | UInt& m_uiMaxCUHeight = m_apcLayerCfg[layer]->m_uiMaxCUHeight; |
---|
508 | UInt& m_uiMaxTotalCUDepth = m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth; |
---|
509 | UInt& m_uiLog2DiffMaxMinCodingBlockSize = m_apcLayerCfg[layer]->m_uiLog2DiffMaxMinCodingBlockSize; |
---|
510 | UInt& m_uiQuadtreeTULog2MaxSize = m_apcLayerCfg[layer]->m_uiQuadtreeTULog2MaxSize; |
---|
511 | UInt& m_uiQuadtreeTULog2MinSize = m_apcLayerCfg[layer]->m_uiQuadtreeTULog2MinSize; |
---|
512 | UInt& m_uiQuadtreeTUMaxDepthInter = m_apcLayerCfg[layer]->m_uiQuadtreeTUMaxDepthInter; |
---|
513 | UInt& m_uiQuadtreeTUMaxDepthIntra = m_apcLayerCfg[layer]->m_uiQuadtreeTUMaxDepthIntra; |
---|
514 | |
---|
515 | Bool& m_entropyCodingSyncEnabledFlag = m_apcLayerCfg[layer]->m_entropyCodingSyncEnabledFlag; |
---|
516 | Bool& m_RCEnableRateControl = m_apcLayerCfg[layer]->m_RCEnableRateControl; |
---|
517 | Int& m_RCTargetBitrate = m_apcLayerCfg[layer]->m_RCTargetBitrate; |
---|
518 | Bool& m_RCKeepHierarchicalBit = m_apcLayerCfg[layer]->m_RCKeepHierarchicalBit; |
---|
519 | Bool& m_RCLCULevelRC = m_apcLayerCfg[layer]->m_RCLCULevelRC; |
---|
520 | Bool& m_RCUseLCUSeparateModel = m_apcLayerCfg[layer]->m_RCUseLCUSeparateModel; |
---|
521 | Int& m_RCInitialQP = m_apcLayerCfg[layer]->m_RCInitialQP; |
---|
522 | Bool& m_RCForceIntraQP = m_apcLayerCfg[layer]->m_RCForceIntraQP; |
---|
523 | |
---|
524 | #if U0132_TARGET_BITS_SATURATION |
---|
525 | Bool& m_RCCpbSaturationEnabled = m_apcLayerCfg[layer]->m_RCCpbSaturationEnabled; |
---|
526 | UInt& m_RCCpbSize = m_apcLayerCfg[layer]->m_RCCpbSize; |
---|
527 | Double& m_RCInitialCpbFullness = m_apcLayerCfg[layer]->m_RCInitialCpbFullness; |
---|
528 | #endif |
---|
529 | |
---|
530 | ScalingListMode& m_useScalingListId = m_apcLayerCfg[layer]->m_useScalingListId; |
---|
531 | string& m_scalingListFileName = m_apcLayerCfg[layer]->m_scalingListFileName; |
---|
532 | Bool& m_bUseSAO = m_apcLayerCfg[layer]->m_bUseSAO; |
---|
533 | |
---|
534 | GOPEntry* m_GOPList = m_apcLayerCfg[layer]->m_GOPList; |
---|
535 | Int& m_extraRPSs = m_apcLayerCfg[layer]->m_extraRPSs; |
---|
536 | Int& m_maxTempLayer = m_apcLayerCfg[layer]->m_maxTempLayer; |
---|
537 | |
---|
538 | string& m_colourRemapSEIFileRoot = m_apcLayerCfg[layer]->m_colourRemapSEIFileRoot; |
---|
539 | #if PER_LAYER_LOSSLESS |
---|
540 | Bool& m_TransquantBypassEnabledFlag = m_apcLayerCfg[layer]->m_TransquantBypassEnabledFlag; |
---|
541 | Bool& m_CUTransquantBypassFlagForce = m_apcLayerCfg[layer]->m_CUTransquantBypassFlagForce; |
---|
542 | CostMode& m_costMode = m_apcLayerCfg[layer]->m_costMode; |
---|
543 | #endif |
---|
544 | #endif |
---|
545 | |
---|
546 | m_cTEncTop.setProfile ( m_profile); |
---|
547 | m_cTEncTop.setLevel ( m_levelTier, m_level); |
---|
548 | m_cTEncTop.setProgressiveSourceFlag ( m_progressiveSourceFlag); |
---|
549 | m_cTEncTop.setInterlacedSourceFlag ( m_interlacedSourceFlag); |
---|
550 | m_cTEncTop.setNonPackedConstraintFlag ( m_nonPackedConstraintFlag); |
---|
551 | m_cTEncTop.setFrameOnlyConstraintFlag ( m_frameOnlyConstraintFlag); |
---|
552 | m_cTEncTop.setBitDepthConstraintValue ( m_bitDepthConstraint ); |
---|
553 | m_cTEncTop.setChromaFormatConstraintValue ( m_chromaFormatConstraint ); |
---|
554 | m_cTEncTop.setIntraConstraintFlag ( m_intraConstraintFlag ); |
---|
555 | m_cTEncTop.setOnePictureOnlyConstraintFlag ( m_onePictureOnlyConstraintFlag ); |
---|
556 | m_cTEncTop.setLowerBitRateConstraintFlag ( m_lowerBitRateConstraintFlag ); |
---|
557 | |
---|
558 | m_cTEncTop.setPrintMSEBasedSequencePSNR ( m_printMSEBasedSequencePSNR); |
---|
559 | m_cTEncTop.setPrintFrameMSE ( m_printFrameMSE); |
---|
560 | m_cTEncTop.setPrintSequenceMSE ( m_printSequenceMSE); |
---|
561 | m_cTEncTop.setCabacZeroWordPaddingEnabled ( m_cabacZeroWordPaddingEnabled ); |
---|
562 | |
---|
563 | m_cTEncTop.setFrameRate ( m_iFrameRate ); |
---|
564 | m_cTEncTop.setFrameSkip ( m_FrameSkip ); |
---|
565 | m_cTEncTop.setTemporalSubsampleRatio ( m_temporalSubsampleRatio ); |
---|
566 | m_cTEncTop.setSourceWidth ( m_iSourceWidth ); |
---|
567 | m_cTEncTop.setSourceHeight ( m_iSourceHeight ); |
---|
568 | m_cTEncTop.setConformanceWindow ( m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom ); |
---|
569 | m_cTEncTop.setFramesToBeEncoded ( m_framesToBeEncoded ); |
---|
570 | |
---|
571 | //====== Coding Structure ======== |
---|
572 | m_cTEncTop.setIntraPeriod ( m_iIntraPeriod ); |
---|
573 | m_cTEncTop.setDecodingRefreshType ( m_iDecodingRefreshType ); |
---|
574 | m_cTEncTop.setGOPSize ( m_iGOPSize ); |
---|
575 | m_cTEncTop.setGopList ( m_GOPList ); |
---|
576 | m_cTEncTop.setExtraRPSs ( m_extraRPSs ); |
---|
577 | for(Int i = 0; i < MAX_TLAYER; i++) |
---|
578 | { |
---|
579 | m_cTEncTop.setNumReorderPics ( m_numReorderPics[i], i ); |
---|
580 | m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
---|
581 | } |
---|
582 | for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop ) |
---|
583 | { |
---|
584 | m_cTEncTop.setLambdaModifier ( uiLoop, m_adLambdaModifier[ uiLoop ] ); |
---|
585 | } |
---|
586 | m_cTEncTop.setIntraLambdaModifier ( m_adIntraLambdaModifier ); |
---|
587 | m_cTEncTop.setIntraQpFactor ( m_dIntraQpFactor ); |
---|
588 | |
---|
589 | m_cTEncTop.setQP ( m_iQP ); |
---|
590 | |
---|
591 | m_cTEncTop.setPad ( m_aiPad ); |
---|
592 | |
---|
593 | m_cTEncTop.setAccessUnitDelimiter ( m_AccessUnitDelimiter ); |
---|
594 | |
---|
595 | m_cTEncTop.setMaxTempLayer ( m_maxTempLayer ); |
---|
596 | m_cTEncTop.setUseAMP( m_enableAMP ); |
---|
597 | |
---|
598 | //===== Slice ======== |
---|
599 | |
---|
600 | //====== Loop/Deblock Filter ======== |
---|
601 | m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable ); |
---|
602 | m_cTEncTop.setLoopFilterOffsetInPPS ( m_loopFilterOffsetInPPS ); |
---|
603 | m_cTEncTop.setLoopFilterBetaOffset ( m_loopFilterBetaOffsetDiv2 ); |
---|
604 | m_cTEncTop.setLoopFilterTcOffset ( m_loopFilterTcOffsetDiv2 ); |
---|
605 | #if W0038_DB_OPT |
---|
606 | m_cTEncTop.setDeblockingFilterMetric ( m_deblockingFilterMetric ); |
---|
607 | #else |
---|
608 | m_cTEncTop.setDeblockingFilterMetric ( m_DeblockingFilterMetric ); |
---|
609 | #endif |
---|
610 | |
---|
611 | //====== Motion search ======== |
---|
612 | m_cTEncTop.setDisableIntraPUsInInterSlices ( m_bDisableIntraPUsInInterSlices ); |
---|
613 | m_cTEncTop.setMotionEstimationSearchMethod ( m_motionEstimationSearchMethod ); |
---|
614 | m_cTEncTop.setSearchRange ( m_iSearchRange ); |
---|
615 | m_cTEncTop.setBipredSearchRange ( m_bipredSearchRange ); |
---|
616 | m_cTEncTop.setClipForBiPredMeEnabled ( m_bClipForBiPredMeEnabled ); |
---|
617 | m_cTEncTop.setFastMEAssumingSmootherMVEnabled ( m_bFastMEAssumingSmootherMVEnabled ); |
---|
618 | m_cTEncTop.setMinSearchWindow ( m_minSearchWindow ); |
---|
619 | m_cTEncTop.setRestrictMESampling ( m_bRestrictMESampling ); |
---|
620 | |
---|
621 | //====== Quality control ======== |
---|
622 | m_cTEncTop.setMaxDeltaQP ( m_iMaxDeltaQP ); |
---|
623 | m_cTEncTop.setMaxCuDQPDepth ( m_iMaxCuDQPDepth ); |
---|
624 | m_cTEncTop.setDiffCuChromaQpOffsetDepth ( m_diffCuChromaQpOffsetDepth ); |
---|
625 | m_cTEncTop.setChromaCbQpOffset ( m_cbQpOffset ); |
---|
626 | m_cTEncTop.setChromaCrQpOffset ( m_crQpOffset ); |
---|
627 | #if W0038_CQP_ADJ |
---|
628 | m_cTEncTop.setSliceChromaOffsetQpIntraOrPeriodic ( m_sliceChromaQpOffsetPeriodicity, m_sliceChromaQpOffsetIntraOrPeriodic ); |
---|
629 | #endif |
---|
630 | m_cTEncTop.setChromaFormatIdc ( m_chromaFormatIDC ); |
---|
631 | |
---|
632 | #if ADAPTIVE_QP_SELECTION |
---|
633 | m_cTEncTop.setUseAdaptQpSelect ( m_bUseAdaptQpSelect ); |
---|
634 | #endif |
---|
635 | |
---|
636 | m_cTEncTop.setUseAdaptiveQP ( m_bUseAdaptiveQP ); |
---|
637 | m_cTEncTop.setQPAdaptationRange ( m_iQPAdaptationRange ); |
---|
638 | m_cTEncTop.setExtendedPrecisionProcessingFlag ( m_extendedPrecisionProcessingFlag ); |
---|
639 | m_cTEncTop.setHighPrecisionOffsetsEnabledFlag ( m_highPrecisionOffsetsEnabledFlag ); |
---|
640 | |
---|
641 | m_cTEncTop.setWeightedPredictionMethod( m_weightedPredictionMethod ); |
---|
642 | |
---|
643 | //====== Tool list ======== |
---|
644 | m_cTEncTop.setDeltaQpRD ( m_uiDeltaQpRD ); |
---|
645 | m_cTEncTop.setFastDeltaQp ( m_bFastDeltaQP ); |
---|
646 | m_cTEncTop.setUseASR ( m_bUseASR ); |
---|
647 | m_cTEncTop.setUseHADME ( m_bUseHADME ); |
---|
648 | m_cTEncTop.setdQPs ( m_aidQP ); |
---|
649 | m_cTEncTop.setUseRDOQ ( m_useRDOQ ); |
---|
650 | m_cTEncTop.setUseRDOQTS ( m_useRDOQTS ); |
---|
651 | #if T0196_SELECTIVE_RDOQ |
---|
652 | m_cTEncTop.setUseSelectiveRDOQ ( m_useSelectiveRDOQ ); |
---|
653 | #endif |
---|
654 | m_cTEncTop.setRDpenalty ( m_rdPenalty ); |
---|
655 | m_cTEncTop.setMaxCUWidth ( m_uiMaxCUWidth ); |
---|
656 | m_cTEncTop.setMaxCUHeight ( m_uiMaxCUHeight ); |
---|
657 | m_cTEncTop.setMaxTotalCUDepth ( m_uiMaxTotalCUDepth ); |
---|
658 | m_cTEncTop.setLog2DiffMaxMinCodingBlockSize ( m_uiLog2DiffMaxMinCodingBlockSize ); |
---|
659 | m_cTEncTop.setQuadtreeTULog2MaxSize ( m_uiQuadtreeTULog2MaxSize ); |
---|
660 | m_cTEncTop.setQuadtreeTULog2MinSize ( m_uiQuadtreeTULog2MinSize ); |
---|
661 | m_cTEncTop.setQuadtreeTUMaxDepthInter ( m_uiQuadtreeTUMaxDepthInter ); |
---|
662 | m_cTEncTop.setQuadtreeTUMaxDepthIntra ( m_uiQuadtreeTUMaxDepthIntra ); |
---|
663 | m_cTEncTop.setFastInterSearchMode ( m_fastInterSearchMode ); |
---|
664 | m_cTEncTop.setUseEarlyCU ( m_bUseEarlyCU ); |
---|
665 | m_cTEncTop.setUseFastDecisionForMerge ( m_useFastDecisionForMerge ); |
---|
666 | m_cTEncTop.setUseCbfFastMode ( m_bUseCbfFastMode ); |
---|
667 | m_cTEncTop.setUseEarlySkipDetection ( m_useEarlySkipDetection ); |
---|
668 | m_cTEncTop.setCrossComponentPredictionEnabledFlag ( m_crossComponentPredictionEnabledFlag ); |
---|
669 | m_cTEncTop.setUseReconBasedCrossCPredictionEstimate ( m_reconBasedCrossCPredictionEstimate ); |
---|
670 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_LUMA , m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA] ); |
---|
671 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] ); |
---|
672 | m_cTEncTop.setUseTransformSkip ( m_useTransformSkip ); |
---|
673 | m_cTEncTop.setUseTransformSkipFast ( m_useTransformSkipFast ); |
---|
674 | m_cTEncTop.setTransformSkipRotationEnabledFlag ( m_transformSkipRotationEnabledFlag ); |
---|
675 | m_cTEncTop.setTransformSkipContextEnabledFlag ( m_transformSkipContextEnabledFlag ); |
---|
676 | m_cTEncTop.setPersistentRiceAdaptationEnabledFlag ( m_persistentRiceAdaptationEnabledFlag ); |
---|
677 | m_cTEncTop.setCabacBypassAlignmentEnabledFlag ( m_cabacBypassAlignmentEnabledFlag ); |
---|
678 | m_cTEncTop.setLog2MaxTransformSkipBlockSize ( m_log2MaxTransformSkipBlockSize ); |
---|
679 | for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++) |
---|
680 | { |
---|
681 | m_cTEncTop.setRdpcmEnabledFlag ( RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]); |
---|
682 | } |
---|
683 | m_cTEncTop.setUseConstrainedIntraPred ( m_bUseConstrainedIntraPred ); |
---|
684 | m_cTEncTop.setFastUDIUseMPMEnabled ( m_bFastUDIUseMPMEnabled ); |
---|
685 | m_cTEncTop.setFastMEForGenBLowDelayEnabled ( m_bFastMEForGenBLowDelayEnabled ); |
---|
686 | m_cTEncTop.setUseBLambdaForNonKeyLowDelayPictures ( m_bUseBLambdaForNonKeyLowDelayPictures ); |
---|
687 | m_cTEncTop.setPCMLog2MinSize ( m_uiPCMLog2MinSize); |
---|
688 | m_cTEncTop.setUsePCM ( m_usePCM ); |
---|
689 | |
---|
690 | // set internal bit-depth and constants |
---|
691 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
---|
692 | { |
---|
693 | #if SVC_EXTENSION |
---|
694 | m_cTEncTop.setBitDepth((ChannelType)channelType, m_apcLayerCfg[layer]->m_internalBitDepth[channelType]); |
---|
695 | m_cTEncTop.setPCMBitDepth((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[channelType] : m_apcLayerCfg[layer]->m_internalBitDepth[channelType]); |
---|
696 | #else |
---|
697 | m_cTEncTop.setBitDepth((ChannelType)channelType, m_internalBitDepth[channelType]); |
---|
698 | m_cTEncTop.setPCMBitDepth((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_MSBExtendedBitDepth[channelType] : m_internalBitDepth[channelType]); |
---|
699 | #endif |
---|
700 | } |
---|
701 | |
---|
702 | m_cTEncTop.setPCMLog2MaxSize ( m_pcmLog2MaxSize); |
---|
703 | m_cTEncTop.setMaxNumMergeCand ( m_maxNumMergeCand ); |
---|
704 | |
---|
705 | |
---|
706 | //====== Weighted Prediction ======== |
---|
707 | m_cTEncTop.setUseWP ( m_useWeightedPred ); |
---|
708 | m_cTEncTop.setWPBiPred ( m_useWeightedBiPred ); |
---|
709 | |
---|
710 | //====== Parallel Merge Estimation ======== |
---|
711 | m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 ); |
---|
712 | |
---|
713 | //====== Slice ======== |
---|
714 | m_cTEncTop.setSliceMode ( m_sliceMode ); |
---|
715 | m_cTEncTop.setSliceArgument ( m_sliceArgument ); |
---|
716 | |
---|
717 | //====== Dependent Slice ======== |
---|
718 | m_cTEncTop.setSliceSegmentMode ( m_sliceSegmentMode ); |
---|
719 | m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument ); |
---|
720 | |
---|
721 | if(m_sliceMode == NO_SLICES ) |
---|
722 | { |
---|
723 | m_bLFCrossSliceBoundaryFlag = true; |
---|
724 | } |
---|
725 | m_cTEncTop.setLFCrossSliceBoundaryFlag ( m_bLFCrossSliceBoundaryFlag ); |
---|
726 | m_cTEncTop.setUseSAO ( m_bUseSAO ); |
---|
727 | m_cTEncTop.setTestSAODisableAtPictureLevel ( m_bTestSAODisableAtPictureLevel ); |
---|
728 | m_cTEncTop.setSaoEncodingRate ( m_saoEncodingRate ); |
---|
729 | m_cTEncTop.setSaoEncodingRateChroma ( m_saoEncodingRateChroma ); |
---|
730 | m_cTEncTop.setMaxNumOffsetsPerPic ( m_maxNumOffsetsPerPic); |
---|
731 | |
---|
732 | m_cTEncTop.setSaoCtuBoundary ( m_saoCtuBoundary); |
---|
733 | #if OPTIONAL_RESET_SAO_ENCODING_AFTER_IRAP |
---|
734 | m_cTEncTop.setSaoResetEncoderStateAfterIRAP ( m_saoResetEncoderStateAfterIRAP); |
---|
735 | #endif |
---|
736 | m_cTEncTop.setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); |
---|
737 | m_cTEncTop.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); |
---|
738 | |
---|
739 | m_cTEncTop.setIntraSmoothingDisabledFlag (!m_enableIntraReferenceSmoothing ); |
---|
740 | m_cTEncTop.setDecodedPictureHashSEIType ( m_decodedPictureHashSEIType ); |
---|
741 | m_cTEncTop.setRecoveryPointSEIEnabled ( m_recoveryPointSEIEnabled ); |
---|
742 | m_cTEncTop.setBufferingPeriodSEIEnabled ( m_bufferingPeriodSEIEnabled ); |
---|
743 | m_cTEncTop.setPictureTimingSEIEnabled ( m_pictureTimingSEIEnabled ); |
---|
744 | m_cTEncTop.setToneMappingInfoSEIEnabled ( m_toneMappingInfoSEIEnabled ); |
---|
745 | m_cTEncTop.setTMISEIToneMapId ( m_toneMapId ); |
---|
746 | m_cTEncTop.setTMISEIToneMapCancelFlag ( m_toneMapCancelFlag ); |
---|
747 | m_cTEncTop.setTMISEIToneMapPersistenceFlag ( m_toneMapPersistenceFlag ); |
---|
748 | m_cTEncTop.setTMISEICodedDataBitDepth ( m_toneMapCodedDataBitDepth ); |
---|
749 | m_cTEncTop.setTMISEITargetBitDepth ( m_toneMapTargetBitDepth ); |
---|
750 | m_cTEncTop.setTMISEIModelID ( m_toneMapModelId ); |
---|
751 | m_cTEncTop.setTMISEIMinValue ( m_toneMapMinValue ); |
---|
752 | m_cTEncTop.setTMISEIMaxValue ( m_toneMapMaxValue ); |
---|
753 | m_cTEncTop.setTMISEISigmoidMidpoint ( m_sigmoidMidpoint ); |
---|
754 | m_cTEncTop.setTMISEISigmoidWidth ( m_sigmoidWidth ); |
---|
755 | m_cTEncTop.setTMISEIStartOfCodedInterva ( m_startOfCodedInterval ); |
---|
756 | m_cTEncTop.setTMISEINumPivots ( m_numPivots ); |
---|
757 | m_cTEncTop.setTMISEICodedPivotValue ( m_codedPivotValue ); |
---|
758 | m_cTEncTop.setTMISEITargetPivotValue ( m_targetPivotValue ); |
---|
759 | m_cTEncTop.setTMISEICameraIsoSpeedIdc ( m_cameraIsoSpeedIdc ); |
---|
760 | m_cTEncTop.setTMISEICameraIsoSpeedValue ( m_cameraIsoSpeedValue ); |
---|
761 | m_cTEncTop.setTMISEIExposureIndexIdc ( m_exposureIndexIdc ); |
---|
762 | m_cTEncTop.setTMISEIExposureIndexValue ( m_exposureIndexValue ); |
---|
763 | m_cTEncTop.setTMISEIExposureCompensationValueSignFlag ( m_exposureCompensationValueSignFlag ); |
---|
764 | m_cTEncTop.setTMISEIExposureCompensationValueNumerator ( m_exposureCompensationValueNumerator ); |
---|
765 | m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc ( m_exposureCompensationValueDenomIdc ); |
---|
766 | m_cTEncTop.setTMISEIRefScreenLuminanceWhite ( m_refScreenLuminanceWhite ); |
---|
767 | m_cTEncTop.setTMISEIExtendedRangeWhiteLevel ( m_extendedRangeWhiteLevel ); |
---|
768 | m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue ( m_nominalBlackLevelLumaCodeValue ); |
---|
769 | m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue ( m_nominalWhiteLevelLumaCodeValue ); |
---|
770 | m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue ( m_extendedWhiteLevelLumaCodeValue ); |
---|
771 | m_cTEncTop.setChromaResamplingFilterHintEnabled ( m_chromaResamplingFilterSEIenabled ); |
---|
772 | m_cTEncTop.setChromaResamplingHorFilterIdc ( m_chromaResamplingHorFilterIdc ); |
---|
773 | m_cTEncTop.setChromaResamplingVerFilterIdc ( m_chromaResamplingVerFilterIdc ); |
---|
774 | m_cTEncTop.setFramePackingArrangementSEIEnabled ( m_framePackingSEIEnabled ); |
---|
775 | m_cTEncTop.setFramePackingArrangementSEIType ( m_framePackingSEIType ); |
---|
776 | m_cTEncTop.setFramePackingArrangementSEIId ( m_framePackingSEIId ); |
---|
777 | m_cTEncTop.setFramePackingArrangementSEIQuincunx ( m_framePackingSEIQuincunx ); |
---|
778 | m_cTEncTop.setFramePackingArrangementSEIInterpretation ( m_framePackingSEIInterpretation ); |
---|
779 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIEnabled ( m_segmentedRectFramePackingSEIEnabled ); |
---|
780 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEICancel ( m_segmentedRectFramePackingSEICancel ); |
---|
781 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIType ( m_segmentedRectFramePackingSEIType ); |
---|
782 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIPersistence( m_segmentedRectFramePackingSEIPersistence ); |
---|
783 | m_cTEncTop.setDisplayOrientationSEIAngle ( m_displayOrientationSEIAngle ); |
---|
784 | m_cTEncTop.setTemporalLevel0IndexSEIEnabled ( m_temporalLevel0IndexSEIEnabled ); |
---|
785 | m_cTEncTop.setGradualDecodingRefreshInfoEnabled ( m_gradualDecodingRefreshInfoEnabled ); |
---|
786 | m_cTEncTop.setNoDisplaySEITLayer ( m_noDisplaySEITLayer ); |
---|
787 | m_cTEncTop.setDecodingUnitInfoSEIEnabled ( m_decodingUnitInfoSEIEnabled ); |
---|
788 | m_cTEncTop.setSOPDescriptionSEIEnabled ( m_SOPDescriptionSEIEnabled ); |
---|
789 | m_cTEncTop.setScalableNestingSEIEnabled ( m_scalableNestingSEIEnabled ); |
---|
790 | m_cTEncTop.setTMCTSSEIEnabled ( m_tmctsSEIEnabled ); |
---|
791 | m_cTEncTop.setTimeCodeSEIEnabled ( m_timeCodeSEIEnabled ); |
---|
792 | m_cTEncTop.setNumberOfTimeSets ( m_timeCodeSEINumTs ); |
---|
793 | for(Int i = 0; i < m_timeCodeSEINumTs; i++) |
---|
794 | { |
---|
795 | m_cTEncTop.setTimeSet(m_timeSetArray[i], i); |
---|
796 | } |
---|
797 | m_cTEncTop.setKneeSEIEnabled ( m_kneeSEIEnabled ); |
---|
798 | m_cTEncTop.setKneeSEIId ( m_kneeSEIId ); |
---|
799 | m_cTEncTop.setKneeSEICancelFlag ( m_kneeSEICancelFlag ); |
---|
800 | m_cTEncTop.setKneeSEIPersistenceFlag ( m_kneeSEIPersistenceFlag ); |
---|
801 | m_cTEncTop.setKneeSEIInputDrange ( m_kneeSEIInputDrange ); |
---|
802 | m_cTEncTop.setKneeSEIInputDispLuminance ( m_kneeSEIInputDispLuminance ); |
---|
803 | m_cTEncTop.setKneeSEIOutputDrange ( m_kneeSEIOutputDrange ); |
---|
804 | m_cTEncTop.setKneeSEIOutputDispLuminance ( m_kneeSEIOutputDispLuminance ); |
---|
805 | m_cTEncTop.setKneeSEINumKneePointsMinus1 ( m_kneeSEINumKneePointsMinus1 ); |
---|
806 | m_cTEncTop.setKneeSEIInputKneePoint ( m_kneeSEIInputKneePoint ); |
---|
807 | m_cTEncTop.setKneeSEIOutputKneePoint ( m_kneeSEIOutputKneePoint ); |
---|
808 | m_cTEncTop.setColourRemapInfoSEIFileRoot ( m_colourRemapSEIFileRoot ); |
---|
809 | m_cTEncTop.setMasteringDisplaySEI ( m_masteringDisplay ); |
---|
810 | #if U0033_ALTERNATIVE_TRANSFER_CHARACTERISTICS_SEI |
---|
811 | m_cTEncTop.setSEIAlternativeTransferCharacteristicsSEIEnable ( m_preferredTransferCharacteristics>=0 ); |
---|
812 | m_cTEncTop.setSEIPreferredTransferCharacteristics ( UChar(m_preferredTransferCharacteristics) ); |
---|
813 | #endif |
---|
814 | m_cTEncTop.setSEIGreenMetadataInfoSEIEnable ( m_greenMetadataType > 0 ); |
---|
815 | m_cTEncTop.setSEIGreenMetadataType ( UChar(m_greenMetadataType) ); |
---|
816 | m_cTEncTop.setSEIXSDMetricType ( UChar(m_xsdMetricType) ); |
---|
817 | |
---|
818 | m_cTEncTop.setTileUniformSpacingFlag ( m_tileUniformSpacingFlag ); |
---|
819 | m_cTEncTop.setNumColumnsMinus1 ( m_numTileColumnsMinus1 ); |
---|
820 | m_cTEncTop.setNumRowsMinus1 ( m_numTileRowsMinus1 ); |
---|
821 | if(!m_tileUniformSpacingFlag) |
---|
822 | { |
---|
823 | m_cTEncTop.setColumnWidth ( m_tileColumnWidth ); |
---|
824 | m_cTEncTop.setRowHeight ( m_tileRowHeight ); |
---|
825 | } |
---|
826 | m_cTEncTop.xCheckGSParameters(); |
---|
827 | Int uiTilesCount = (m_numTileRowsMinus1+1) * (m_numTileColumnsMinus1+1); |
---|
828 | if(uiTilesCount == 1) |
---|
829 | { |
---|
830 | m_bLFCrossTileBoundaryFlag = true; |
---|
831 | } |
---|
832 | m_cTEncTop.setLFCrossTileBoundaryFlag ( m_bLFCrossTileBoundaryFlag ); |
---|
833 | m_cTEncTop.setEntropyCodingSyncEnabledFlag ( m_entropyCodingSyncEnabledFlag ); |
---|
834 | m_cTEncTop.setTMVPModeId ( m_TMVPModeId ); |
---|
835 | m_cTEncTop.setUseScalingListId ( m_useScalingListId ); |
---|
836 | m_cTEncTop.setScalingListFileName ( m_scalingListFileName ); |
---|
837 | m_cTEncTop.setSignDataHidingEnabledFlag ( m_signDataHidingEnabledFlag); |
---|
838 | m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl ); |
---|
839 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
---|
840 | m_cTEncTop.setKeepHierBit ( m_RCKeepHierarchicalBit ); |
---|
841 | m_cTEncTop.setLCULevelRC ( m_RCLCULevelRC ); |
---|
842 | m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel ); |
---|
843 | m_cTEncTop.setInitialQP ( m_RCInitialQP ); |
---|
844 | m_cTEncTop.setForceIntraQP ( m_RCForceIntraQP ); |
---|
845 | #if U0132_TARGET_BITS_SATURATION |
---|
846 | m_cTEncTop.setCpbSaturationEnabled ( m_RCCpbSaturationEnabled ); |
---|
847 | m_cTEncTop.setCpbSize ( m_RCCpbSize ); |
---|
848 | m_cTEncTop.setInitialCpbFullness ( m_RCInitialCpbFullness ); |
---|
849 | #endif |
---|
850 | m_cTEncTop.setTransquantBypassEnabledFlag ( m_TransquantBypassEnabledFlag ); |
---|
851 | m_cTEncTop.setCUTransquantBypassFlagForceValue ( m_CUTransquantBypassFlagForce ); |
---|
852 | m_cTEncTop.setCostMode ( m_costMode ); |
---|
853 | m_cTEncTop.setUseRecalculateQPAccordingToLambda ( m_recalculateQPAccordingToLambda ); |
---|
854 | m_cTEncTop.setUseStrongIntraSmoothing ( m_useStrongIntraSmoothing ); |
---|
855 | m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); |
---|
856 | m_cTEncTop.setVuiParametersPresentFlag ( m_vuiParametersPresentFlag ); |
---|
857 | m_cTEncTop.setAspectRatioInfoPresentFlag ( m_aspectRatioInfoPresentFlag); |
---|
858 | m_cTEncTop.setAspectRatioIdc ( m_aspectRatioIdc ); |
---|
859 | m_cTEncTop.setSarWidth ( m_sarWidth ); |
---|
860 | m_cTEncTop.setSarHeight ( m_sarHeight ); |
---|
861 | m_cTEncTop.setOverscanInfoPresentFlag ( m_overscanInfoPresentFlag ); |
---|
862 | m_cTEncTop.setOverscanAppropriateFlag ( m_overscanAppropriateFlag ); |
---|
863 | m_cTEncTop.setVideoSignalTypePresentFlag ( m_videoSignalTypePresentFlag ); |
---|
864 | m_cTEncTop.setVideoFormat ( m_videoFormat ); |
---|
865 | m_cTEncTop.setVideoFullRangeFlag ( m_videoFullRangeFlag ); |
---|
866 | m_cTEncTop.setColourDescriptionPresentFlag ( m_colourDescriptionPresentFlag ); |
---|
867 | m_cTEncTop.setColourPrimaries ( m_colourPrimaries ); |
---|
868 | m_cTEncTop.setTransferCharacteristics ( m_transferCharacteristics ); |
---|
869 | m_cTEncTop.setMatrixCoefficients ( m_matrixCoefficients ); |
---|
870 | m_cTEncTop.setChromaLocInfoPresentFlag ( m_chromaLocInfoPresentFlag ); |
---|
871 | m_cTEncTop.setChromaSampleLocTypeTopField ( m_chromaSampleLocTypeTopField ); |
---|
872 | m_cTEncTop.setChromaSampleLocTypeBottomField ( m_chromaSampleLocTypeBottomField ); |
---|
873 | m_cTEncTop.setNeutralChromaIndicationFlag ( m_neutralChromaIndicationFlag ); |
---|
874 | m_cTEncTop.setDefaultDisplayWindow ( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset ); |
---|
875 | m_cTEncTop.setFrameFieldInfoPresentFlag ( m_frameFieldInfoPresentFlag ); |
---|
876 | m_cTEncTop.setPocProportionalToTimingFlag ( m_pocProportionalToTimingFlag ); |
---|
877 | m_cTEncTop.setNumTicksPocDiffOneMinus1 ( m_numTicksPocDiffOneMinus1 ); |
---|
878 | m_cTEncTop.setBitstreamRestrictionFlag ( m_bitstreamRestrictionFlag ); |
---|
879 | m_cTEncTop.setTilesFixedStructureFlag ( m_tilesFixedStructureFlag ); |
---|
880 | m_cTEncTop.setMotionVectorsOverPicBoundariesFlag ( m_motionVectorsOverPicBoundariesFlag ); |
---|
881 | m_cTEncTop.setMinSpatialSegmentationIdc ( m_minSpatialSegmentationIdc ); |
---|
882 | m_cTEncTop.setMaxBytesPerPicDenom ( m_maxBytesPerPicDenom ); |
---|
883 | m_cTEncTop.setMaxBitsPerMinCuDenom ( m_maxBitsPerMinCuDenom ); |
---|
884 | m_cTEncTop.setLog2MaxMvLengthHorizontal ( m_log2MaxMvLengthHorizontal ); |
---|
885 | m_cTEncTop.setLog2MaxMvLengthVertical ( m_log2MaxMvLengthVertical ); |
---|
886 | m_cTEncTop.setEfficientFieldIRAPEnabled ( m_bEfficientFieldIRAPEnabled ); |
---|
887 | m_cTEncTop.setHarmonizeGopFirstFieldCoupleEnabled ( m_bHarmonizeGopFirstFieldCoupleEnabled ); |
---|
888 | |
---|
889 | m_cTEncTop.setSummaryOutFilename ( m_summaryOutFilename ); |
---|
890 | m_cTEncTop.setSummaryPicFilenameBase ( m_summaryPicFilenameBase ); |
---|
891 | m_cTEncTop.setSummaryVerboseness ( m_summaryVerboseness ); |
---|
892 | |
---|
893 | #if LAYERS_NOT_PRESENT_SEI |
---|
894 | m_cTEncTop.setLayersNotPresentSEIEnabled ( m_layersNotPresentSEIEnabled ); |
---|
895 | #endif |
---|
896 | |
---|
897 | |
---|
898 | #if SVC_EXTENSION |
---|
899 | if( layer != 0 && m_useInterLayerWeightedPred ) |
---|
900 | { |
---|
901 | // Enable weighted prediction for enhancement layer |
---|
902 | m_cTEncTop.setUseWP ( true ); |
---|
903 | m_cTEncTop.setWPBiPred ( true ); |
---|
904 | } |
---|
905 | |
---|
906 | } |
---|
907 | #endif |
---|
908 | } |
---|
909 | |
---|
910 | Void TAppEncTop::xCreateLib() |
---|
911 | { |
---|
912 | // Video I/O |
---|
913 | #if SVC_EXTENSION |
---|
914 | // initialize global variables |
---|
915 | initROM(); |
---|
916 | |
---|
917 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
918 | { |
---|
919 | //2 |
---|
920 | // Video I/O |
---|
921 | m_apcTVideoIOYuvInputFile[layer]->open( m_apcLayerCfg[layer]->getInputFileName(), false, m_apcLayerCfg[layer]->m_inputBitDepth, m_apcLayerCfg[layer]->m_MSBExtendedBitDepth, m_apcLayerCfg[layer]->m_internalBitDepth ); // read mode |
---|
922 | m_apcTVideoIOYuvInputFile[layer]->skipFrames(m_FrameSkip, m_apcLayerCfg[layer]->m_iSourceWidth - m_apcLayerCfg[layer]->m_aiPad[0], m_apcLayerCfg[layer]->m_iSourceHeight - m_apcLayerCfg[layer]->m_aiPad[1], m_apcLayerCfg[layer]->m_InputChromaFormatIDC); |
---|
923 | |
---|
924 | if( !m_apcLayerCfg[layer]->getReconFileName().empty() ) |
---|
925 | { |
---|
926 | m_apcTVideoIOYuvReconFile[layer]->open( m_apcLayerCfg[layer]->getReconFileName(), true, m_apcLayerCfg[layer]->m_outputBitDepth, m_apcLayerCfg[layer]->m_MSBExtendedBitDepth, m_apcLayerCfg[layer]->m_internalBitDepth ); // write mode |
---|
927 | } |
---|
928 | |
---|
929 | // Neo Decoder |
---|
930 | m_apcTEncTop[layer]->create(); |
---|
931 | } |
---|
932 | #else //SVC_EXTENSION |
---|
933 | // Video I/O |
---|
934 | m_cTVideoIOYuvInputFile.open( m_inputFileName, false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth ); // read mode |
---|
935 | m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC); |
---|
936 | |
---|
937 | if (!m_reconFileName.empty()) |
---|
938 | { |
---|
939 | m_cTVideoIOYuvReconFile.open(m_reconFileName, true, m_outputBitDepth, m_outputBitDepth, m_internalBitDepth); // write mode |
---|
940 | } |
---|
941 | |
---|
942 | // Neo Decoder |
---|
943 | m_cTEncTop.create(); |
---|
944 | #endif //SVC_EXTENSION |
---|
945 | } |
---|
946 | |
---|
947 | Void TAppEncTop::xDestroyLib() |
---|
948 | { |
---|
949 | // Video I/O |
---|
950 | #if SVC_EXTENSION |
---|
951 | // destroy ROM |
---|
952 | destroyROM(); |
---|
953 | |
---|
954 | for( UInt layer=0; layer < m_numLayers; layer++ ) |
---|
955 | { |
---|
956 | if( m_apcTVideoIOYuvInputFile[layer] ) |
---|
957 | { |
---|
958 | m_apcTVideoIOYuvInputFile[layer]->close(); |
---|
959 | delete m_apcTVideoIOYuvInputFile[layer]; |
---|
960 | m_apcTVideoIOYuvInputFile[layer] = NULL; |
---|
961 | } |
---|
962 | |
---|
963 | if( m_apcTVideoIOYuvReconFile[layer] ) |
---|
964 | { |
---|
965 | m_apcTVideoIOYuvReconFile[layer]->close(); |
---|
966 | delete m_apcTVideoIOYuvReconFile[layer]; |
---|
967 | m_apcTVideoIOYuvReconFile[layer] = NULL; |
---|
968 | } |
---|
969 | |
---|
970 | if( m_apcTEncTop[layer] ) |
---|
971 | { |
---|
972 | m_apcTEncTop[layer]->destroy(); |
---|
973 | delete m_apcTEncTop[layer]; |
---|
974 | m_apcTEncTop[layer] = NULL; |
---|
975 | } |
---|
976 | } |
---|
977 | #else //SVC_EXTENSION |
---|
978 | m_cTVideoIOYuvInputFile.close(); |
---|
979 | m_cTVideoIOYuvReconFile.close(); |
---|
980 | |
---|
981 | // Neo Decoder |
---|
982 | m_cTEncTop.destroy(); |
---|
983 | #endif //SVC_EXTENSION |
---|
984 | } |
---|
985 | |
---|
986 | Void TAppEncTop::xInitLib(Bool isFieldCoding) |
---|
987 | { |
---|
988 | #if SVC_EXTENSION |
---|
989 | TComVPS* vps = m_apcTEncTop[0]->getVPS(); |
---|
990 | m_apcTEncTop[0]->getVPS()->setMaxLayers( m_numLayers ); |
---|
991 | |
---|
992 | UInt i = 0, dimIdLen = 0; |
---|
993 | #if VIEW_SCALABILITY |
---|
994 | Int curDimId=0; |
---|
995 | |
---|
996 | if( m_scalabilityMask[VIEW_ORDER_INDEX] ) |
---|
997 | { |
---|
998 | UInt maxViewOrderIndex = 0,maxViewId=0; |
---|
999 | UInt voiLen = 1,vidLen=1; |
---|
1000 | |
---|
1001 | for( i = 0; i < vps->getMaxLayers(); i++ ) |
---|
1002 | { |
---|
1003 | if( m_apcLayerCfg[i]->getViewOrderIndex() > maxViewOrderIndex ) |
---|
1004 | { |
---|
1005 | maxViewOrderIndex = m_apcLayerCfg[i]->getViewOrderIndex(); |
---|
1006 | } |
---|
1007 | |
---|
1008 | if( m_apcLayerCfg[i]->getViewId() > maxViewId ) |
---|
1009 | { |
---|
1010 | maxViewId = m_apcLayerCfg[i]->getViewId(); |
---|
1011 | } |
---|
1012 | |
---|
1013 | } |
---|
1014 | while((1 << voiLen) < (maxViewOrderIndex + 1)) |
---|
1015 | { |
---|
1016 | voiLen++; |
---|
1017 | } |
---|
1018 | |
---|
1019 | while((1 << vidLen) < (maxViewId + 1)) |
---|
1020 | { |
---|
1021 | vidLen++; |
---|
1022 | } |
---|
1023 | |
---|
1024 | vps->setDimensionIdLen(0, voiLen); |
---|
1025 | vps->setViewIdLen(vidLen); |
---|
1026 | |
---|
1027 | for( i = 0; i < vps->getMaxLayers(); i++ ) |
---|
1028 | { |
---|
1029 | vps->setDimensionId(i, 0, m_apcLayerCfg[i]->getViewOrderIndex()); |
---|
1030 | } |
---|
1031 | |
---|
1032 | for( i = 0; i < m_iNumberOfViews; i++ ) |
---|
1033 | { |
---|
1034 | vps->setViewIdVal(i, m_ViewIdVal[i]); |
---|
1035 | } |
---|
1036 | |
---|
1037 | curDimId++; |
---|
1038 | } |
---|
1039 | #endif |
---|
1040 | |
---|
1041 | while((1 << dimIdLen) < m_numLayers) |
---|
1042 | { |
---|
1043 | dimIdLen++; |
---|
1044 | } |
---|
1045 | #if VIEW_SCALABILITY |
---|
1046 | vps->setDimensionIdLen(curDimId, dimIdLen); |
---|
1047 | #else |
---|
1048 | vps->setDimensionIdLen(0, dimIdLen); |
---|
1049 | #endif |
---|
1050 | vps->setNuhLayerIdPresentFlag(false); |
---|
1051 | vps->setLayerIdInNuh(0, 0); |
---|
1052 | vps->setLayerIdxInVps(0, 0); |
---|
1053 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
1054 | { |
---|
1055 | vps->setLayerIdInNuh(i, m_apcLayerCfg[i]->m_layerId); |
---|
1056 | vps->setLayerIdxInVps(vps->getLayerIdInNuh(i), i); |
---|
1057 | #if VIEW_SCALABILITY |
---|
1058 | vps->setDimensionId(i, curDimId, i); |
---|
1059 | #else |
---|
1060 | vps->setDimensionId(i, 0, i); |
---|
1061 | #endif |
---|
1062 | if( m_apcLayerCfg[i]->m_layerId != i ) |
---|
1063 | { |
---|
1064 | vps->setNuhLayerIdPresentFlag(true); |
---|
1065 | } |
---|
1066 | } |
---|
1067 | |
---|
1068 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
1069 | { |
---|
1070 | //3 |
---|
1071 | #if LAYER_CTB |
---|
1072 | memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) ); |
---|
1073 | memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) ); |
---|
1074 | memcpy( g_auiRasterToPelX, g_auiLayerRasterToPelX[layer], sizeof( g_auiRasterToPelX ) ); |
---|
1075 | memcpy( g_auiRasterToPelY, g_auiLayerRasterToPelY[layer], sizeof( g_auiRasterToPelY ) ); |
---|
1076 | #endif |
---|
1077 | m_apcTEncTop[layer]->init(isFieldCoding); |
---|
1078 | } |
---|
1079 | |
---|
1080 | // Set max-layer ID |
---|
1081 | vps->setMaxLayerId( m_apcLayerCfg[m_numLayers - 1]->m_layerId ); |
---|
1082 | vps->setVpsExtensionFlag( m_numLayers > 1 ? true : false ); |
---|
1083 | |
---|
1084 | if( m_numLayerSets > 1 ) |
---|
1085 | { |
---|
1086 | vps->setNumLayerSets(m_numLayerSets); |
---|
1087 | |
---|
1088 | for (Int setId = 1; setId < vps->getNumLayerSets(); setId++) |
---|
1089 | { |
---|
1090 | for (Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++) |
---|
1091 | { |
---|
1092 | vps->setLayerIdIncludedFlag(false, setId, layerId); |
---|
1093 | } |
---|
1094 | } |
---|
1095 | for (Int setId = 1; setId < vps->getNumLayerSets(); setId++) |
---|
1096 | { |
---|
1097 | for( i = 0; i < m_numLayerInIdList[setId]; i++ ) |
---|
1098 | { |
---|
1099 | //4 |
---|
1100 | vps->setLayerIdIncludedFlag(true, setId, m_layerSetLayerIdList[setId][i]); |
---|
1101 | } |
---|
1102 | } |
---|
1103 | } |
---|
1104 | else |
---|
1105 | { |
---|
1106 | // Default layer sets |
---|
1107 | vps->setNumLayerSets(m_numLayers); |
---|
1108 | for (Int setId = 1; setId < vps->getNumLayerSets(); setId++) |
---|
1109 | { |
---|
1110 | for (Int layerIdx = 0; layerIdx <= vps->getMaxLayers(); layerIdx++) |
---|
1111 | { |
---|
1112 | //4 |
---|
1113 | UInt layerId = vps->getLayerIdInNuh(layerIdx); |
---|
1114 | |
---|
1115 | if (layerId <= setId) |
---|
1116 | { |
---|
1117 | vps->setLayerIdIncludedFlag(true, setId, layerId); |
---|
1118 | } |
---|
1119 | else |
---|
1120 | { |
---|
1121 | vps->setLayerIdIncludedFlag(false, setId, layerId); |
---|
1122 | } |
---|
1123 | } |
---|
1124 | } |
---|
1125 | } |
---|
1126 | |
---|
1127 | vps->setVpsNumLayerSetsMinus1(vps->getNumLayerSets() - 1); |
---|
1128 | vps->setNumAddLayerSets(m_numAddLayerSets); |
---|
1129 | vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets()); |
---|
1130 | |
---|
1131 | if( m_numAddLayerSets > 0 ) |
---|
1132 | { |
---|
1133 | for (Int setId = 0; setId < m_numAddLayerSets; setId++) |
---|
1134 | { |
---|
1135 | for (Int j = 0; j < m_numHighestLayerIdx[setId]; j++) |
---|
1136 | { |
---|
1137 | vps->setHighestLayerIdxPlus1(setId, j + 1, m_highestLayerIdx[setId][j] + 1); |
---|
1138 | } |
---|
1139 | } |
---|
1140 | } |
---|
1141 | |
---|
1142 | #if AVC_BASE |
---|
1143 | vps->setNonHEVCBaseLayerFlag( m_nonHEVCBaseLayerFlag ); |
---|
1144 | if( m_nonHEVCBaseLayerFlag ) |
---|
1145 | { |
---|
1146 | vps->setBaseLayerInternalFlag(false); |
---|
1147 | } |
---|
1148 | #endif |
---|
1149 | |
---|
1150 | for( Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx < vps->getNumProfileTierLevel(); idx++ ) |
---|
1151 | { |
---|
1152 | vps->setProfilePresentFlag(idx, true); |
---|
1153 | } |
---|
1154 | |
---|
1155 | vps->setSplittingFlag(false); |
---|
1156 | |
---|
1157 | for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++) |
---|
1158 | { |
---|
1159 | vps->setScalabilityMask(i, false); |
---|
1160 | } |
---|
1161 | if(m_numLayers > 1) |
---|
1162 | { |
---|
1163 | Int scalabilityTypes = 0; |
---|
1164 | for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++) |
---|
1165 | { |
---|
1166 | vps->setScalabilityMask(i, m_scalabilityMask[i]); |
---|
1167 | scalabilityTypes += m_scalabilityMask[i]; |
---|
1168 | } |
---|
1169 | #if VIEW_SCALABILITY |
---|
1170 | assert( scalabilityTypes <= 3 ); |
---|
1171 | #else |
---|
1172 | #if AUXILIARY_PICTURES |
---|
1173 | assert( scalabilityTypes <= 2 ); |
---|
1174 | #else |
---|
1175 | assert( scalabilityTypes == 1 ); |
---|
1176 | #endif |
---|
1177 | #endif |
---|
1178 | vps->setNumScalabilityTypes(scalabilityTypes); |
---|
1179 | } |
---|
1180 | else |
---|
1181 | { |
---|
1182 | vps->setNumScalabilityTypes(0); |
---|
1183 | } |
---|
1184 | |
---|
1185 | #if AUXILIARY_PICTURES |
---|
1186 | if (m_scalabilityMask[AUX_ID]) |
---|
1187 | { |
---|
1188 | UInt maxAuxId = 0; |
---|
1189 | UInt auxDimIdLen = 1; |
---|
1190 | Int auxId = vps->getNumScalabilityTypes() - 1; |
---|
1191 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
1192 | { |
---|
1193 | if (m_apcLayerCfg[i]->m_auxId > maxAuxId) |
---|
1194 | { |
---|
1195 | maxAuxId = m_apcLayerCfg[i]->m_auxId; |
---|
1196 | } |
---|
1197 | } |
---|
1198 | while((1 << auxDimIdLen) < (maxAuxId + 1)) |
---|
1199 | { |
---|
1200 | auxDimIdLen++; |
---|
1201 | } |
---|
1202 | vps->setDimensionIdLen(auxId, auxDimIdLen); |
---|
1203 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
1204 | { |
---|
1205 | vps->setDimensionId(i, auxId, m_apcLayerCfg[i]->m_auxId); |
---|
1206 | } |
---|
1207 | } |
---|
1208 | #endif |
---|
1209 | |
---|
1210 | vps->setMaxTSLayersPresentFlag(true); |
---|
1211 | |
---|
1212 | for( i = 0; i < vps->getMaxLayers(); i++ ) |
---|
1213 | { |
---|
1214 | vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1); |
---|
1215 | } |
---|
1216 | |
---|
1217 | vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag); |
---|
1218 | if (vps->getMaxTidRefPresentFlag()) |
---|
1219 | { |
---|
1220 | for( i = 0; i < vps->getMaxLayers() - 1; i++ ) |
---|
1221 | { |
---|
1222 | for( Int j = i+1; j < vps->getMaxLayers(); j++) |
---|
1223 | { |
---|
1224 | vps->setMaxTidIlRefPicsPlus1(i, j, m_apcTEncTop[i]->getMaxTidIlRefPicsPlus1()); |
---|
1225 | } |
---|
1226 | } |
---|
1227 | } |
---|
1228 | else |
---|
1229 | { |
---|
1230 | for( i = 0; i < vps->getMaxLayers() - 1; i++ ) |
---|
1231 | { |
---|
1232 | for( Int j = i+1; j < vps->getMaxLayers(); j++) |
---|
1233 | { |
---|
1234 | vps->setMaxTidIlRefPicsPlus1(i, j, 7); |
---|
1235 | } |
---|
1236 | } |
---|
1237 | } |
---|
1238 | |
---|
1239 | vps->setDefaultRefLayersActiveFlag(false); |
---|
1240 | |
---|
1241 | // Direct reference layers |
---|
1242 | UInt maxDirectRefLayers = 0; |
---|
1243 | Bool isDefaultDirectDependencyTypeSet = false; |
---|
1244 | for (UInt layerCtr = 1; layerCtr < vps->getMaxLayers(); layerCtr++) |
---|
1245 | { |
---|
1246 | UInt layerId = vps->getLayerIdInNuh(layerCtr); |
---|
1247 | Int numDirectRefLayers = 0; |
---|
1248 | |
---|
1249 | vps->setNumDirectRefLayers(layerId, m_apcTEncTop[layerCtr]->getNumDirectRefLayers()); |
---|
1250 | maxDirectRefLayers = max<UInt>(maxDirectRefLayers, vps->getNumDirectRefLayers(layerId)); |
---|
1251 | |
---|
1252 | for (i = 0; i < vps->getNumDirectRefLayers(layerId); i++) |
---|
1253 | { |
---|
1254 | vps->setRefLayerId(layerId, i, m_apcTEncTop[layerCtr]->getRefLayerId(i)); |
---|
1255 | } |
---|
1256 | // Set direct dependency flag |
---|
1257 | // Initialize flag to 0 |
---|
1258 | for (Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++) |
---|
1259 | { |
---|
1260 | vps->setDirectDependencyFlag(layerCtr, refLayerCtr, false); |
---|
1261 | } |
---|
1262 | for (i = 0; i < vps->getNumDirectRefLayers(layerId); i++) |
---|
1263 | { |
---|
1264 | vps->setDirectDependencyFlag(layerCtr, vps->getLayerIdxInVps(m_apcTEncTop[layerCtr]->getRefLayerId(i)), true); |
---|
1265 | } |
---|
1266 | // prediction indications |
---|
1267 | vps->setDirectDepTypeLen(2); // sample and motion types are encoded |
---|
1268 | for (Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++) |
---|
1269 | { |
---|
1270 | if (vps->getDirectDependencyFlag(layerCtr, refLayerCtr)) |
---|
1271 | { |
---|
1272 | assert(m_apcTEncTop[layerCtr]->getSamplePredEnabledFlag(numDirectRefLayers) || m_apcTEncTop[layerCtr]->getMotionPredEnabledFlag(numDirectRefLayers)); |
---|
1273 | vps->setDirectDependencyType(layerCtr, refLayerCtr, ((m_apcTEncTop[layerCtr]->getSamplePredEnabledFlag(numDirectRefLayers) ? 1 : 0) | |
---|
1274 | (m_apcTEncTop[layerCtr]->getMotionPredEnabledFlag(numDirectRefLayers) ? 2 : 0)) - 1); |
---|
1275 | |
---|
1276 | if (!isDefaultDirectDependencyTypeSet) |
---|
1277 | { |
---|
1278 | vps->setDefaultDirectDependecyTypeFlag(1); |
---|
1279 | vps->setDefaultDirectDependecyType(vps->getDirectDependencyType(layerCtr, refLayerCtr)); |
---|
1280 | isDefaultDirectDependencyTypeSet = true; |
---|
1281 | } |
---|
1282 | else if (vps->getDirectDependencyType(layerCtr, refLayerCtr) != vps->getDefaultDirectDependencyType()) |
---|
1283 | { |
---|
1284 | vps->setDefaultDirectDependecyTypeFlag(0); |
---|
1285 | } |
---|
1286 | |
---|
1287 | numDirectRefLayers ++; |
---|
1288 | } |
---|
1289 | else |
---|
1290 | { |
---|
1291 | vps->setDirectDependencyType(layerCtr, refLayerCtr, 0); |
---|
1292 | } |
---|
1293 | } |
---|
1294 | } |
---|
1295 | |
---|
1296 | // dependency constraint |
---|
1297 | vps->setNumRefLayers(); |
---|
1298 | |
---|
1299 | if( vps->getMaxLayers() > MAX_REF_LAYERS ) |
---|
1300 | { |
---|
1301 | for( UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++ ) |
---|
1302 | { |
---|
1303 | assert(vps->getNumRefLayers(vps->getLayerIdInNuh(layerCtr)) <= MAX_REF_LAYERS); |
---|
1304 | } |
---|
1305 | } |
---|
1306 | |
---|
1307 | // The Layer ID List variables should be derived here. |
---|
1308 | vps->deriveLayerIdListVariables(); |
---|
1309 | vps->setPredictedLayerIds(); |
---|
1310 | vps->setTreePartitionLayerIdList(); |
---|
1311 | vps->deriveLayerIdListVariablesForAddLayerSets(); |
---|
1312 | |
---|
1313 | vps->setDefaultTargetOutputLayerIdc( m_defaultTargetOutputLayerIdc ); // As per configuration file |
---|
1314 | |
---|
1315 | if( m_numOutputLayerSets == -1 ) // # of output layer sets not specified in the configuration file |
---|
1316 | { |
---|
1317 | vps->setNumOutputLayerSets(vps->getNumLayerSets()); |
---|
1318 | |
---|
1319 | for(i = 1; i < vps->getNumLayerSets(); i++) |
---|
1320 | { |
---|
1321 | vps->setOutputLayerSetIdx(i, i); |
---|
1322 | } |
---|
1323 | } |
---|
1324 | else |
---|
1325 | { |
---|
1326 | vps->setNumOutputLayerSets( m_numOutputLayerSets ); |
---|
1327 | for( Int olsCtr = 0; olsCtr < vps->getNumLayerSets(); olsCtr ++ ) // Default output layer sets |
---|
1328 | { |
---|
1329 | vps->setOutputLayerSetIdx(olsCtr, olsCtr); |
---|
1330 | } |
---|
1331 | for( Int olsCtr = vps->getNumLayerSets(); olsCtr < vps->getNumOutputLayerSets(); olsCtr ++ ) // Non-default output layer sets |
---|
1332 | { |
---|
1333 | vps->setOutputLayerSetIdx(olsCtr, m_outputLayerSetIdx[olsCtr - vps->getNumLayerSets()]); |
---|
1334 | } |
---|
1335 | } |
---|
1336 | |
---|
1337 | // Target output layer |
---|
1338 | vps->deriveNumberOfSubDpbs(); |
---|
1339 | vps->setOutputLayerFlag( 0, 0, 1 ); |
---|
1340 | |
---|
1341 | // derive OutputLayerFlag[i][j] |
---|
1342 | // default_output_layer_idc equal to 1 specifies that only the layer with the highest value of nuh_layer_id such that nuh_layer_id equal to nuhLayerIdA and |
---|
1343 | // AuxId[ nuhLayerIdA ] equal to 0 in each of the output layer sets with index in the range of 1 to vps_num_layer_sets_minus1, inclusive, is an output layer of its output layer set. |
---|
1344 | |
---|
1345 | // Include the highest layer as output layer for each layer set |
---|
1346 | for(Int lsIdx = 1; lsIdx <= vps->getVpsNumLayerSetsMinus1(); lsIdx++) |
---|
1347 | { |
---|
1348 | for( UInt layer = 0; layer < vps->getNumLayersInIdList(lsIdx); layer++ ) |
---|
1349 | { |
---|
1350 | switch( vps->getDefaultTargetOutputLayerIdc() ) |
---|
1351 | { |
---|
1352 | case 0: vps->setOutputLayerFlag( lsIdx, layer, 1 ); |
---|
1353 | break; |
---|
1354 | case 1: vps->setOutputLayerFlag( lsIdx, layer, layer == vps->getNumLayersInIdList(lsIdx) - 1 ); |
---|
1355 | break; |
---|
1356 | case 2: |
---|
1357 | case 3: vps->setOutputLayerFlag( lsIdx, layer, (layer != vps->getNumLayersInIdList(lsIdx) - 1) ? std::find( m_listOfOutputLayers[lsIdx].begin(), m_listOfOutputLayers[lsIdx].end(), m_layerSetLayerIdList[lsIdx][layer]) != m_listOfOutputLayers[lsIdx].end() |
---|
1358 | : m_listOfOutputLayers[lsIdx][m_listOfOutputLayers[lsIdx].size()-1] == m_layerSetLayerIdList[lsIdx][layer] ); |
---|
1359 | break; |
---|
1360 | } |
---|
1361 | } |
---|
1362 | } |
---|
1363 | |
---|
1364 | for( Int olsIdx = vps->getVpsNumLayerSetsMinus1() + 1; olsIdx < vps->getNumOutputLayerSets(); olsIdx++ ) |
---|
1365 | { |
---|
1366 | for( UInt layer = 0; layer < vps->getNumLayersInIdList(vps->getOutputLayerSetIdx(olsIdx)); layer++ ) |
---|
1367 | { |
---|
1368 | vps->setOutputLayerFlag( olsIdx, layer, (layer != vps->getNumLayersInIdList(vps->getOutputLayerSetIdx(olsIdx)) - 1) ? std::find( m_listOfOutputLayers[olsIdx].begin(), m_listOfOutputLayers[olsIdx].end(), vps->getLayerSetLayerIdList(vps->getOutputLayerSetIdx(olsIdx), layer)) != m_listOfOutputLayers[olsIdx].end() |
---|
1369 | : m_listOfOutputLayers[olsIdx][m_listOfOutputLayers[olsIdx].size()-1] == vps->getLayerSetLayerIdList(vps->getOutputLayerSetIdx(olsIdx), layer) ); |
---|
1370 | } |
---|
1371 | } |
---|
1372 | |
---|
1373 | vps->deriveNecessaryLayerFlag(); |
---|
1374 | vps->checkNecessaryLayerFlagCondition(); |
---|
1375 | vps->calculateMaxSLInLayerSets(); |
---|
1376 | |
---|
1377 | // Initialize dpb_size_table() for all ouput layer sets in the VPS extension |
---|
1378 | for( i = 1; i < vps->getNumOutputLayerSets(); i++ ) |
---|
1379 | { |
---|
1380 | Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i ); |
---|
1381 | Int layerSetId = vps->getOutputLayerSetIdx(i); |
---|
1382 | |
---|
1383 | for(Int j = 0; j < vps->getMaxTLayers(); j++) |
---|
1384 | { |
---|
1385 | |
---|
1386 | Int maxNumReorderPics = -1; |
---|
1387 | for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++) |
---|
1388 | { |
---|
1389 | Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set |
---|
1390 | vps->setMaxVpsDecPicBufferingMinus1( i, k, j, m_apcTEncTop[vps->getLayerIdxInVps(layerId)]->getMaxDecPicBuffering(j) - 1 ); |
---|
1391 | maxNumReorderPics = std::max( maxNumReorderPics, m_apcTEncTop[vps->getLayerIdxInVps(layerId)]->getNumReorderPics(j)); |
---|
1392 | } |
---|
1393 | vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics); |
---|
1394 | vps->determineSubDpbInfoFlags(); |
---|
1395 | } |
---|
1396 | } |
---|
1397 | |
---|
1398 | vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true); |
---|
1399 | |
---|
1400 | // POC LSB not present flag |
---|
1401 | for( i = 1; i< vps->getMaxLayers(); i++ ) |
---|
1402 | { |
---|
1403 | if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0 ) |
---|
1404 | { |
---|
1405 | // make independedent layers base-layer compliant |
---|
1406 | vps->setPocLsbNotPresentFlag(i, true); |
---|
1407 | } |
---|
1408 | } |
---|
1409 | |
---|
1410 | vps->setCrossLayerPictureTypeAlignFlag( m_crossLayerPictureTypeAlignFlag ); |
---|
1411 | vps->setCrossLayerAlignedIdrOnlyFlag( m_crossLayerAlignedIdrOnlyFlag ); |
---|
1412 | vps->setCrossLayerIrapAlignFlag( m_crossLayerIrapAlignFlag ); |
---|
1413 | |
---|
1414 | if( vps->getCrossLayerPictureTypeAlignFlag() ) |
---|
1415 | { |
---|
1416 | // When not present, the value of cross_layer_irap_aligned_flag is inferred to be equal to vps_vui_present_flag, |
---|
1417 | assert( m_crossLayerIrapAlignFlag == true ); |
---|
1418 | vps->setCrossLayerIrapAlignFlag( true ); |
---|
1419 | } |
---|
1420 | |
---|
1421 | for(UInt layerCtr = 1;layerCtr < vps->getMaxLayers(); layerCtr++) |
---|
1422 | { |
---|
1423 | for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++) |
---|
1424 | { |
---|
1425 | if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr)) |
---|
1426 | { |
---|
1427 | assert( layerCtr < MAX_LAYERS ); |
---|
1428 | |
---|
1429 | if(m_apcTEncTop[layerCtr]->getIntraPeriod() != m_apcTEncTop[refLayerCtr]->getIntraPeriod()) |
---|
1430 | { |
---|
1431 | vps->setCrossLayerIrapAlignFlag(false); |
---|
1432 | break; |
---|
1433 | } |
---|
1434 | } |
---|
1435 | } |
---|
1436 | } |
---|
1437 | vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false); |
---|
1438 | vps->setHigherLayerIrapSkipFlag(m_skipPictureAtArcSwitch); |
---|
1439 | |
---|
1440 | for( Int k = 0; k < MAX_VPS_LAYER_SETS_PLUS1; k++ ) |
---|
1441 | { |
---|
1442 | vps->setAltOuputLayerFlag( k, m_altOutputLayerFlag ); |
---|
1443 | } |
---|
1444 | |
---|
1445 | // VPS VUI BSP HRD parameters |
---|
1446 | vps->setVpsVuiBspHrdPresentFlag(false); |
---|
1447 | TEncTop *pcCfg = m_apcTEncTop[0]; |
---|
1448 | if( pcCfg->getBufferingPeriodSEIEnabled() ) |
---|
1449 | { |
---|
1450 | Int j; |
---|
1451 | vps->setVpsVuiBspHrdPresentFlag(true); |
---|
1452 | vps->setVpsNumAddHrdParams( vps->getMaxLayers() ); |
---|
1453 | vps->createBspHrdParamBuffer(vps->getVpsNumAddHrdParams() + 1); |
---|
1454 | for( i = vps->getNumHrdParameters(), j = 0; i < vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams(); i++, j++ ) |
---|
1455 | { |
---|
1456 | vps->setCprmsAddPresentFlag( j, true ); |
---|
1457 | vps->setNumSubLayerHrdMinus1( j, vps->getMaxTLayers() - 1 ); |
---|
1458 | |
---|
1459 | UInt layerIdx = j; |
---|
1460 | TEncTop *pcCfgLayer = m_apcTEncTop[layerIdx]; |
---|
1461 | |
---|
1462 | Int iPicWidth = pcCfgLayer->getSourceWidth(); |
---|
1463 | Int iPicHeight = pcCfgLayer->getSourceHeight(); |
---|
1464 | |
---|
1465 | UInt uiWidthInCU = ( iPicWidth % m_apcLayerCfg[layerIdx]->m_uiMaxCUWidth ) ? iPicWidth / m_apcLayerCfg[layerIdx]->m_uiMaxCUWidth + 1 : iPicWidth / m_apcLayerCfg[layerIdx]->m_uiMaxCUWidth; |
---|
1466 | UInt uiHeightInCU = ( iPicHeight % m_apcLayerCfg[layerIdx]->m_uiMaxCUHeight ) ? iPicHeight / m_apcLayerCfg[layerIdx]->m_uiMaxCUHeight + 1 : iPicHeight / m_apcLayerCfg[layerIdx]->m_uiMaxCUHeight; |
---|
1467 | UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_apcLayerCfg[layerIdx]->m_uiMaxCUDepth << 1); |
---|
1468 | |
---|
1469 | UInt uiNumCUsInFrame = uiWidthInCU * uiHeightInCU; |
---|
1470 | |
---|
1471 | UInt numDU = ( pcCfgLayer->getSliceMode() == 1 ) ? ( uiNumCUsInFrame / maxCU ) : ( 0 ); |
---|
1472 | if( uiNumCUsInFrame % maxCU != 0 || numDU == 0 ) |
---|
1473 | { |
---|
1474 | numDU ++; |
---|
1475 | } |
---|
1476 | //vps->getBspHrd(i)->setNumDU( numDU ); |
---|
1477 | vps->setBspHrdParameters( i, pcCfgLayer->getFrameRate(), numDU, pcCfgLayer->getTargetBitrate(), ( pcCfgLayer->getIntraPeriod() > 0 ) ); |
---|
1478 | } |
---|
1479 | |
---|
1480 | // Signalling of additional partitioning schemes |
---|
1481 | for( Int h = 1; h < vps->getNumOutputLayerSets(); h++ ) |
---|
1482 | { |
---|
1483 | Int lsIdx = vps->getOutputLayerSetIdx( h ); |
---|
1484 | vps->setNumSignalledPartitioningSchemes(h, 1); // Only the default per-layer partitioning scheme |
---|
1485 | for( j = 1; j < vps->getNumSignalledPartitioningSchemes(h); j++ ) |
---|
1486 | { |
---|
1487 | // ToDo: Add code for additional partitioning schemes here |
---|
1488 | // ToDo: Initialize num_partitions_in_scheme_minus1 and layer_included_in_partition_flag |
---|
1489 | } |
---|
1490 | |
---|
1491 | for( i = 0; i < vps->getNumSignalledPartitioningSchemes(h); i++ ) |
---|
1492 | { |
---|
1493 | if( i == 0 ) |
---|
1494 | { |
---|
1495 | for(Int t = 0; t <= vps->getMaxSLayersInLayerSetMinus1( lsIdx ); t++) |
---|
1496 | { |
---|
1497 | vps->setNumBspSchedulesMinus1( h, i, t, 0 ); |
---|
1498 | for( j = 0; j <= vps->getNumBspSchedulesMinus1(h, i, t); j++ ) |
---|
1499 | { |
---|
1500 | for( Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, i); k++ ) |
---|
1501 | { |
---|
1502 | // Only for the default partition |
---|
1503 | Int nuhlayerId = vps->getLayerSetLayerIdList( lsIdx, k); |
---|
1504 | Int layerIdxInVps = vps->getLayerIdxInVps( nuhlayerId ); |
---|
1505 | vps->setBspHrdIdx(h, i, t, j, k, layerIdxInVps + vps->getNumHrdParameters()); |
---|
1506 | |
---|
1507 | vps->setBspSchedIdx(h, i, t, j, k, 0); |
---|
1508 | } |
---|
1509 | } |
---|
1510 | } |
---|
1511 | } |
---|
1512 | else |
---|
1513 | { |
---|
1514 | assert(0); // Need to add support for additional partitioning schemes. |
---|
1515 | } |
---|
1516 | } |
---|
1517 | } |
---|
1518 | } |
---|
1519 | #else //SVC_EXTENSION |
---|
1520 | m_cTEncTop.init(isFieldCoding); |
---|
1521 | #endif //SVC_EXTENSION |
---|
1522 | } |
---|
1523 | |
---|
1524 | // ==================================================================================================================== |
---|
1525 | // Public member functions |
---|
1526 | // ==================================================================================================================== |
---|
1527 | |
---|
1528 | /** |
---|
1529 | - create internal class |
---|
1530 | - initialize internal variable |
---|
1531 | - until the end of input YUV file, call encoding function in TEncTop class |
---|
1532 | - delete allocated buffers |
---|
1533 | - destroy internal class |
---|
1534 | . |
---|
1535 | */ |
---|
1536 | #if SVC_EXTENSION |
---|
1537 | Void TAppEncTop::encode() |
---|
1538 | { |
---|
1539 | fstream bitstreamFile(m_bitstreamFileName.c_str(), fstream::binary | fstream::out); |
---|
1540 | if (!bitstreamFile) |
---|
1541 | { |
---|
1542 | fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_bitstreamFileName.c_str()); |
---|
1543 | exit(EXIT_FAILURE); |
---|
1544 | } |
---|
1545 | |
---|
1546 | // allocated memory |
---|
1547 | for( Int layer = 0; layer < m_numLayers; layer++ ) |
---|
1548 | { |
---|
1549 | m_apcTVideoIOYuvInputFile[layer] = new TVideoIOYuv; |
---|
1550 | m_apcTVideoIOYuvReconFile[layer] = new TVideoIOYuv; |
---|
1551 | m_apcTEncTop[layer] = new TEncTop; |
---|
1552 | } |
---|
1553 | |
---|
1554 | TComPicYuv* pcPicYuvOrg [MAX_LAYERS]; |
---|
1555 | TComPicYuv* pcPicYuvRec = NULL; |
---|
1556 | |
---|
1557 | // initialize internal class & member variables |
---|
1558 | xInitLibCfg(); |
---|
1559 | xCreateLib(); |
---|
1560 | xInitLib(m_isField); |
---|
1561 | |
---|
1562 | // main encoder loop |
---|
1563 | Int iNumEncoded = 0, iTotalNumEncoded = 0; |
---|
1564 | Bool bEos = false; |
---|
1565 | |
---|
1566 | const InputColourSpaceConversion ipCSC = m_inputColourSpaceConvert; |
---|
1567 | const InputColourSpaceConversion snrCSC = (!m_snrInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED; |
---|
1568 | |
---|
1569 | list<AccessUnit> outputAccessUnits; ///< list of access units to write out. is populated by the encoding process |
---|
1570 | |
---|
1571 | TComPicYuv acPicYuvTrueOrg[MAX_LAYERS]; |
---|
1572 | |
---|
1573 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
1574 | { |
---|
1575 | //5 |
---|
1576 | // allocate original YUV buffer |
---|
1577 | pcPicYuvOrg[layer] = new TComPicYuv; |
---|
1578 | if( m_isField ) |
---|
1579 | { |
---|
1580 | pcPicYuvOrg[layer]->create( m_apcLayerCfg[layer]->m_iSourceWidth, m_apcLayerCfg[layer]->m_iSourceHeightOrg, m_apcLayerCfg[layer]->m_chromaFormatIDC, m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL ); |
---|
1581 | acPicYuvTrueOrg[layer].create( m_apcLayerCfg[layer]->m_iSourceWidth, m_apcLayerCfg[layer]->m_iSourceHeightOrg, m_apcLayerCfg[layer]->m_chromaFormatIDC, m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL ); |
---|
1582 | } |
---|
1583 | else |
---|
1584 | { |
---|
1585 | pcPicYuvOrg[layer]->create( m_apcLayerCfg[layer]->m_iSourceWidth, m_apcLayerCfg[layer]->m_iSourceHeight, m_apcLayerCfg[layer]->m_chromaFormatIDC, m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL ); |
---|
1586 | acPicYuvTrueOrg[layer].create( m_apcLayerCfg[layer]->m_iSourceWidth, m_apcLayerCfg[layer]->m_iSourceHeight, m_apcLayerCfg[layer]->m_chromaFormatIDC, m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL ); |
---|
1587 | } |
---|
1588 | } |
---|
1589 | |
---|
1590 | Bool bFirstFrame = true; |
---|
1591 | while ( !bEos ) |
---|
1592 | { |
---|
1593 | // Read enough frames |
---|
1594 | Bool bFramesReadyToCode = false; |
---|
1595 | while(!bFramesReadyToCode) |
---|
1596 | { |
---|
1597 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
1598 | { |
---|
1599 | //6 |
---|
1600 | // get buffers |
---|
1601 | xGetBuffer(pcPicYuvRec, layer); |
---|
1602 | |
---|
1603 | // read input YUV file |
---|
1604 | m_apcTVideoIOYuvInputFile[layer]->read( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer], ipCSC, m_apcLayerCfg[layer]->m_aiPad, m_apcLayerCfg[layer]->m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range ); |
---|
1605 | |
---|
1606 | #if AUXILIARY_PICTURES |
---|
1607 | if( m_apcLayerCfg[layer]->m_chromaFormatIDC == CHROMA_400 || (m_apcTEncTop[0]->getVPS()->getScalabilityMask(AUX_ID) && (m_apcLayerCfg[layer]->m_auxId == AUX_ALPHA || m_apcLayerCfg[layer]->m_auxId == AUX_DEPTH)) ) |
---|
1608 | { |
---|
1609 | pcPicYuvOrg[layer]->convertToMonochrome(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]); |
---|
1610 | } |
---|
1611 | #endif |
---|
1612 | |
---|
1613 | if(layer == m_numLayers-1) |
---|
1614 | { |
---|
1615 | // increase number of received frames |
---|
1616 | m_iFrameRcvd++; |
---|
1617 | // check end of file |
---|
1618 | bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) ); |
---|
1619 | } |
---|
1620 | |
---|
1621 | if ( m_isField ) |
---|
1622 | { |
---|
1623 | m_apcTEncTop[layer]->encodePrep( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer], m_isTopFieldFirst ); |
---|
1624 | } |
---|
1625 | else |
---|
1626 | { |
---|
1627 | m_apcTEncTop[layer]->encodePrep( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer] ); |
---|
1628 | } |
---|
1629 | } |
---|
1630 | |
---|
1631 | bFramesReadyToCode = !(!bFirstFrame && ( m_apcTEncTop[m_numLayers-1]->getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos ); |
---|
1632 | } |
---|
1633 | Bool flush = 0; |
---|
1634 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
---|
1635 | if (m_apcTVideoIOYuvInputFile[m_numLayers-1]->isEof()) |
---|
1636 | { |
---|
1637 | flush = true; |
---|
1638 | bEos = true; |
---|
1639 | m_iFrameRcvd--; |
---|
1640 | m_apcTEncTop[m_numLayers-1]->setFramesToBeEncoded(m_iFrameRcvd); |
---|
1641 | } |
---|
1642 | |
---|
1643 | #if RC_SHVC_HARMONIZATION |
---|
1644 | for( UInt layer=0; layer<m_numLayers; layer++ ) |
---|
1645 | { |
---|
1646 | if( m_apcTEncTop[layer]->getUseRateCtrl() ) |
---|
1647 | { |
---|
1648 | m_apcTEncTop[layer]->getRateCtrl()->initRCGOP(m_apcTEncTop[layer]->getNumPicRcvd()); |
---|
1649 | } |
---|
1650 | } |
---|
1651 | #endif |
---|
1652 | |
---|
1653 | if( m_adaptiveResolutionChange ) |
---|
1654 | { |
---|
1655 | for(UInt layer = 0; layer < m_numLayers; layer++) |
---|
1656 | { |
---|
1657 | TComList<TComPicYuv*>::iterator iterPicYuvRec; |
---|
1658 | for (iterPicYuvRec = m_acListPicYuvRec[layer].begin(); iterPicYuvRec != m_acListPicYuvRec[layer].end(); iterPicYuvRec++) |
---|
1659 | { |
---|
1660 | TComPicYuv* recPic = *(iterPicYuvRec); |
---|
1661 | recPic->setReconstructed(false); |
---|
1662 | } |
---|
1663 | } |
---|
1664 | } |
---|
1665 | |
---|
1666 | // loop through frames in one GOP |
---|
1667 | for( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ ) |
---|
1668 | { |
---|
1669 | // layer by layer for each frame |
---|
1670 | for( UInt layer=0; layer<m_numLayers; layer++ ) |
---|
1671 | { |
---|
1672 | //7 |
---|
1673 | #if LAYER_CTB |
---|
1674 | memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) ); |
---|
1675 | memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) ); |
---|
1676 | memcpy( g_auiRasterToPelX, g_auiLayerRasterToPelX[layer], sizeof( g_auiRasterToPelX ) ); |
---|
1677 | memcpy( g_auiRasterToPelY, g_auiLayerRasterToPelY[layer], sizeof( g_auiRasterToPelY ) ); |
---|
1678 | #endif |
---|
1679 | // call encoding function for one frame |
---|
1680 | if ( m_isField ) |
---|
1681 | { |
---|
1682 | m_apcTEncTop[layer]->encode( flush ? 0 : pcPicYuvOrg[layer], snrCSC, m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP, m_isTopFieldFirst ); |
---|
1683 | } |
---|
1684 | else |
---|
1685 | { |
---|
1686 | m_apcTEncTop[layer]->encode( flush ? 0 : pcPicYuvOrg[layer], snrCSC, m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP ); |
---|
1687 | } |
---|
1688 | } |
---|
1689 | } |
---|
1690 | #if R0247_SEI_ACTIVE |
---|
1691 | if(bFirstFrame) |
---|
1692 | { |
---|
1693 | list<AccessUnit>::iterator first_au = outputAccessUnits.begin(); |
---|
1694 | #if AVC_BASE |
---|
1695 | if( m_nonHEVCBaseLayerFlag ) |
---|
1696 | { |
---|
1697 | first_au++; |
---|
1698 | } |
---|
1699 | #endif |
---|
1700 | AccessUnit::iterator it_sps; |
---|
1701 | for (it_sps = first_au->begin(); it_sps != first_au->end(); it_sps++) |
---|
1702 | { |
---|
1703 | if( (*it_sps)->m_nalUnitType == NAL_UNIT_SPS ) |
---|
1704 | { |
---|
1705 | break; |
---|
1706 | } |
---|
1707 | } |
---|
1708 | |
---|
1709 | for (list<AccessUnit>::iterator it_au = ++outputAccessUnits.begin(); it_au != outputAccessUnits.end(); it_au++) |
---|
1710 | { |
---|
1711 | for (AccessUnit::iterator it_nalu = it_au->begin(); it_nalu != it_au->end(); it_nalu++) |
---|
1712 | { |
---|
1713 | if( (*it_nalu)->m_nalUnitType == NAL_UNIT_SPS ) |
---|
1714 | { |
---|
1715 | it_sps = first_au->insert(++it_sps, *it_nalu); |
---|
1716 | it_nalu = it_au->erase(it_nalu); |
---|
1717 | } |
---|
1718 | } |
---|
1719 | } |
---|
1720 | } |
---|
1721 | #endif |
---|
1722 | |
---|
1723 | #if RC_SHVC_HARMONIZATION |
---|
1724 | for( UInt layer = 0; layer < m_numLayers; layer++ ) |
---|
1725 | { |
---|
1726 | if( m_apcTEncTop[layer]->getUseRateCtrl() ) |
---|
1727 | { |
---|
1728 | m_apcTEncTop[layer]->getRateCtrl()->destroyRCGOP(); |
---|
1729 | } |
---|
1730 | } |
---|
1731 | #endif |
---|
1732 | |
---|
1733 | iTotalNumEncoded = 0; |
---|
1734 | for( UInt layer=0; layer<m_numLayers; layer++ ) |
---|
1735 | { |
---|
1736 | //8 |
---|
1737 | // write bistream to file if necessary |
---|
1738 | iNumEncoded = m_apcTEncTop[layer]->getNumPicRcvd(); |
---|
1739 | if ( iNumEncoded > 0 ) |
---|
1740 | { |
---|
1741 | xWriteRecon(layer, iNumEncoded); |
---|
1742 | iTotalNumEncoded += iNumEncoded; |
---|
1743 | } |
---|
1744 | m_apcTEncTop[layer]->setNumPicRcvd( 0 ); |
---|
1745 | |
---|
1746 | // temporally skip frames |
---|
1747 | if( m_temporalSubsampleRatio > 1 ) |
---|
1748 | { |
---|
1749 | m_apcTVideoIOYuvInputFile[layer]->skipFrames(m_temporalSubsampleRatio-1, m_apcTEncTop[layer]->getSourceWidth() - m_apcTEncTop[layer]->getPad(0), m_apcTEncTop[layer]->getSourceHeight() - m_apcTEncTop[layer]->getPad(1), m_apcLayerCfg[layer]->m_InputChromaFormatIDC); |
---|
1750 | } |
---|
1751 | } |
---|
1752 | |
---|
1753 | // write bitstream out |
---|
1754 | if( iTotalNumEncoded ) |
---|
1755 | { |
---|
1756 | if( bEos ) |
---|
1757 | { |
---|
1758 | OutputNALUnit nalu(NAL_UNIT_EOB); |
---|
1759 | nalu.m_nuhLayerId = 0; |
---|
1760 | |
---|
1761 | AccessUnit& accessUnit = outputAccessUnits.back(); |
---|
1762 | nalu.m_temporalId = 0; |
---|
1763 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1764 | } |
---|
1765 | |
---|
1766 | xWriteStream(bitstreamFile, iTotalNumEncoded, outputAccessUnits); |
---|
1767 | outputAccessUnits.clear(); |
---|
1768 | } |
---|
1769 | |
---|
1770 | // print out summary |
---|
1771 | if (bEos) |
---|
1772 | { |
---|
1773 | printOutSummary(m_isTopFieldFirst, m_printMSEBasedSequencePSNR, m_printSequenceMSE); |
---|
1774 | } |
---|
1775 | |
---|
1776 | bFirstFrame = false; |
---|
1777 | } |
---|
1778 | // delete original YUV buffer |
---|
1779 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
1780 | { |
---|
1781 | pcPicYuvOrg[layer]->destroy(); |
---|
1782 | delete pcPicYuvOrg[layer]; |
---|
1783 | pcPicYuvOrg[layer] = NULL; |
---|
1784 | |
---|
1785 | // delete used buffers in encoder class |
---|
1786 | m_apcTEncTop[layer]->deletePicBuffer(); |
---|
1787 | acPicYuvTrueOrg[layer].destroy(); |
---|
1788 | } |
---|
1789 | |
---|
1790 | // delete buffers & classes |
---|
1791 | xDeleteBuffer(); |
---|
1792 | xDestroyLib(); |
---|
1793 | |
---|
1794 | printRateSummary(); |
---|
1795 | |
---|
1796 | return; |
---|
1797 | } |
---|
1798 | |
---|
1799 | Void TAppEncTop::printOutSummary(Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE) |
---|
1800 | { |
---|
1801 | UInt layer; |
---|
1802 | const Int rateMultiplier = isField ? 2 : 1; |
---|
1803 | |
---|
1804 | // set frame rate |
---|
1805 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1806 | { |
---|
1807 | m_apcTEncTop[layer]->getAnalyzeAll()->setFrmRate( m_apcLayerCfg[layer]->m_iFrameRate * rateMultiplier ); |
---|
1808 | m_apcTEncTop[layer]->getAnalyzeI()->setFrmRate( m_apcLayerCfg[layer]->m_iFrameRate * rateMultiplier ); |
---|
1809 | m_apcTEncTop[layer]->getAnalyzeP()->setFrmRate( m_apcLayerCfg[layer]->m_iFrameRate * rateMultiplier ); |
---|
1810 | m_apcTEncTop[layer]->getAnalyzeB()->setFrmRate( m_apcLayerCfg[layer]->m_iFrameRate * rateMultiplier ); |
---|
1811 | } |
---|
1812 | |
---|
1813 | //-- all |
---|
1814 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
1815 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1816 | { |
---|
1817 | const UInt layerId = m_apcTEncTop[layer]->getVPS()->getLayerIdInNuh(layer); |
---|
1818 | const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]); |
---|
1819 | m_apcTEncTop[layer]->getAnalyzeAll()->printOut('a', m_apcLayerCfg[layer]->m_chromaFormatIDC, printMSEBasedSNR, printSequenceMSE, bitDepths, layerId); |
---|
1820 | } |
---|
1821 | |
---|
1822 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
1823 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1824 | { |
---|
1825 | const UInt layerId = m_apcTEncTop[layer]->getVPS()->getLayerIdInNuh(layer); |
---|
1826 | const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]); |
---|
1827 | m_apcTEncTop[layer]->getAnalyzeI()->printOut('i', m_apcLayerCfg[layer]->m_chromaFormatIDC, printMSEBasedSNR, printSequenceMSE, bitDepths, layerId); |
---|
1828 | } |
---|
1829 | |
---|
1830 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
1831 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1832 | { |
---|
1833 | const UInt layerId = m_apcTEncTop[layer]->getVPS()->getLayerIdInNuh(layer); |
---|
1834 | const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]); |
---|
1835 | m_apcTEncTop[layer]->getAnalyzeP()->printOut('p', m_apcLayerCfg[layer]->m_chromaFormatIDC, printMSEBasedSNR, printSequenceMSE, bitDepths, layerId); |
---|
1836 | } |
---|
1837 | |
---|
1838 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
1839 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1840 | { |
---|
1841 | const UInt layerId = m_apcTEncTop[layer]->getVPS()->getLayerIdInNuh(layer); |
---|
1842 | const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]); |
---|
1843 | m_apcTEncTop[layer]->getAnalyzeB()->printOut('b', m_apcLayerCfg[layer]->m_chromaFormatIDC, printMSEBasedSNR, printSequenceMSE, bitDepths, layerId); |
---|
1844 | } |
---|
1845 | |
---|
1846 | for( layer = 0; layer < m_numLayers; layer++ ) |
---|
1847 | { |
---|
1848 | if (!m_apcTEncTop[layer]->getSummaryOutFilename().empty()) |
---|
1849 | { |
---|
1850 | const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]); |
---|
1851 | |
---|
1852 | m_apcTEncTop[layer]->getAnalyzeAll()->printSummary(m_apcLayerCfg[layer]->m_chromaFormatIDC, printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryOutFilename()); |
---|
1853 | } |
---|
1854 | } |
---|
1855 | |
---|
1856 | for( layer = 0; layer < m_numLayers; layer++ ) |
---|
1857 | { |
---|
1858 | if (!m_apcTEncTop[layer]->getSummaryPicFilenameBase().empty()) |
---|
1859 | { |
---|
1860 | const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]); |
---|
1861 | |
---|
1862 | m_apcTEncTop[layer]->getAnalyzeI()->printSummary(m_apcLayerCfg[layer]->m_chromaFormatIDC, printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"I.txt"); |
---|
1863 | m_apcTEncTop[layer]->getAnalyzeP()->printSummary(m_apcLayerCfg[layer]->m_chromaFormatIDC, printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"P.txt"); |
---|
1864 | m_apcTEncTop[layer]->getAnalyzeB()->printSummary(m_apcLayerCfg[layer]->m_chromaFormatIDC, printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"B.txt"); |
---|
1865 | } |
---|
1866 | } |
---|
1867 | |
---|
1868 | if(isField) |
---|
1869 | { |
---|
1870 | for(layer = 0; layer < m_numLayers; layer++) |
---|
1871 | { |
---|
1872 | const UInt layerId = m_apcTEncTop[layer]->getVPS()->getLayerIdInNuh(layer); |
---|
1873 | const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]); |
---|
1874 | TEncAnalyze *analyze = m_apcTEncTop[layer]->getAnalyzeAllin(); |
---|
1875 | |
---|
1876 | //-- interlaced summary |
---|
1877 | analyze->setFrmRate( m_apcLayerCfg[layer]->m_iFrameRate); |
---|
1878 | analyze->setBits(m_apcTEncTop[layer]->getAnalyzeB()->getBits()); |
---|
1879 | // prior to the above statement, the interlace analyser does not contain the correct total number of bits. |
---|
1880 | |
---|
1881 | printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" ); |
---|
1882 | analyze->printOut('a', m_apcLayerCfg[layer]->m_chromaFormatIDC, printMSEBasedSNR, printSequenceMSE, bitDepths, layerId); |
---|
1883 | |
---|
1884 | if (!m_apcTEncTop[layer]->getSummaryOutFilename().empty()) |
---|
1885 | { |
---|
1886 | analyze->printSummary(m_apcLayerCfg[layer]->m_chromaFormatIDC, printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryOutFilename()); |
---|
1887 | } |
---|
1888 | } |
---|
1889 | } |
---|
1890 | |
---|
1891 | printf("\n"); |
---|
1892 | for( layer = 0; layer < m_numLayers; layer++ ) |
---|
1893 | { |
---|
1894 | const UInt layerId = m_apcTEncTop[layer]->getVPS()->getLayerIdInNuh(layer); |
---|
1895 | printf("RVM[L%d]: %.3lf\n", layerId, m_apcTEncTop[layer]->calculateRVM()); |
---|
1896 | } |
---|
1897 | printf("\n"); |
---|
1898 | } |
---|
1899 | #else |
---|
1900 | // ==================================================================================================================== |
---|
1901 | // Public member functions |
---|
1902 | // ==================================================================================================================== |
---|
1903 | |
---|
1904 | /** |
---|
1905 | - create internal class |
---|
1906 | - initialize internal variable |
---|
1907 | - until the end of input YUV file, call encoding function in TEncTop class |
---|
1908 | - delete allocated buffers |
---|
1909 | - destroy internal class |
---|
1910 | . |
---|
1911 | */ |
---|
1912 | Void TAppEncTop::encode() |
---|
1913 | { |
---|
1914 | fstream bitstreamFile(m_bitstreamFileName.c_str(), fstream::binary | fstream::out); |
---|
1915 | if (!bitstreamFile) |
---|
1916 | { |
---|
1917 | fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_bitstreamFileName.c_str()); |
---|
1918 | exit(EXIT_FAILURE); |
---|
1919 | } |
---|
1920 | |
---|
1921 | TComPicYuv* pcPicYuvOrg = new TComPicYuv; |
---|
1922 | TComPicYuv* pcPicYuvRec = NULL; |
---|
1923 | |
---|
1924 | // initialize internal class & member variables |
---|
1925 | xInitLibCfg(); |
---|
1926 | xCreateLib(); |
---|
1927 | xInitLib(m_isField); |
---|
1928 | |
---|
1929 | printChromaFormat(); |
---|
1930 | |
---|
1931 | // main encoder loop |
---|
1932 | Int iNumEncoded = 0; |
---|
1933 | Bool bEos = false; |
---|
1934 | |
---|
1935 | const InputColourSpaceConversion ipCSC = m_inputColourSpaceConvert; |
---|
1936 | const InputColourSpaceConversion snrCSC = (!m_snrInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED; |
---|
1937 | |
---|
1938 | list<AccessUnit> outputAccessUnits; ///< list of access units to write out. is populated by the encoding process |
---|
1939 | |
---|
1940 | TComPicYuv cPicYuvTrueOrg; |
---|
1941 | |
---|
1942 | // allocate original YUV buffer |
---|
1943 | if( m_isField ) |
---|
1944 | { |
---|
1945 | pcPicYuvOrg->create ( m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
1946 | cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true); |
---|
1947 | } |
---|
1948 | else |
---|
1949 | { |
---|
1950 | pcPicYuvOrg->create ( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
1951 | cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
1952 | } |
---|
1953 | |
---|
1954 | while ( !bEos ) |
---|
1955 | { |
---|
1956 | // get buffers |
---|
1957 | xGetBuffer(pcPicYuvRec); |
---|
1958 | |
---|
1959 | // read input YUV file |
---|
1960 | m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, &cPicYuvTrueOrg, ipCSC, m_aiPad, m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range ); |
---|
1961 | |
---|
1962 | // increase number of received frames |
---|
1963 | m_iFrameRcvd++; |
---|
1964 | |
---|
1965 | bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) ); |
---|
1966 | |
---|
1967 | Bool flush = 0; |
---|
1968 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
---|
1969 | if (m_cTVideoIOYuvInputFile.isEof()) |
---|
1970 | { |
---|
1971 | flush = true; |
---|
1972 | bEos = true; |
---|
1973 | m_iFrameRcvd--; |
---|
1974 | m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd); |
---|
1975 | } |
---|
1976 | |
---|
1977 | // call encoding function for one frame |
---|
1978 | if ( m_isField ) |
---|
1979 | { |
---|
1980 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst ); |
---|
1981 | } |
---|
1982 | else |
---|
1983 | { |
---|
1984 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded ); |
---|
1985 | } |
---|
1986 | |
---|
1987 | // write bistream to file if necessary |
---|
1988 | if ( iNumEncoded > 0 ) |
---|
1989 | { |
---|
1990 | xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits); |
---|
1991 | outputAccessUnits.clear(); |
---|
1992 | } |
---|
1993 | // temporally skip frames |
---|
1994 | if( m_temporalSubsampleRatio > 1 ) |
---|
1995 | { |
---|
1996 | m_cTVideoIOYuvInputFile.skipFrames(m_temporalSubsampleRatio-1, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC); |
---|
1997 | } |
---|
1998 | } |
---|
1999 | |
---|
2000 | m_cTEncTop.printSummary(m_isField); |
---|
2001 | |
---|
2002 | // delete original YUV buffer |
---|
2003 | pcPicYuvOrg->destroy(); |
---|
2004 | delete pcPicYuvOrg; |
---|
2005 | pcPicYuvOrg = NULL; |
---|
2006 | |
---|
2007 | // delete used buffers in encoder class |
---|
2008 | m_cTEncTop.deletePicBuffer(); |
---|
2009 | cPicYuvTrueOrg.destroy(); |
---|
2010 | |
---|
2011 | // delete buffers & classes |
---|
2012 | xDeleteBuffer(); |
---|
2013 | xDestroyLib(); |
---|
2014 | |
---|
2015 | printRateSummary(); |
---|
2016 | |
---|
2017 | return; |
---|
2018 | } |
---|
2019 | #endif //SVC_EXTENSION |
---|
2020 | |
---|
2021 | // ==================================================================================================================== |
---|
2022 | // Protected member functions |
---|
2023 | // ==================================================================================================================== |
---|
2024 | |
---|
2025 | /** |
---|
2026 | - application has picture buffer list with size of GOP |
---|
2027 | - picture buffer list acts as ring buffer |
---|
2028 | - end of the list has the latest picture |
---|
2029 | . |
---|
2030 | */ |
---|
2031 | #if SVC_EXTENSION |
---|
2032 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer) |
---|
2033 | { |
---|
2034 | assert( m_iGOPSize > 0 ); |
---|
2035 | |
---|
2036 | // org. buffer |
---|
2037 | if ( m_acListPicYuvRec[layer].size() >= (UInt)m_iGOPSize ) // buffer will be 1 element longer when using field coding, to maintain first field whilst processing second. |
---|
2038 | { |
---|
2039 | rpcPicYuvRec = m_acListPicYuvRec[layer].popFront(); |
---|
2040 | } |
---|
2041 | else |
---|
2042 | { |
---|
2043 | rpcPicYuvRec = new TComPicYuv; |
---|
2044 | |
---|
2045 | rpcPicYuvRec->create( m_apcLayerCfg[layer]->m_iSourceWidth, m_apcLayerCfg[layer]->m_iSourceHeight, m_apcLayerCfg[layer]->m_chromaFormatIDC, m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL ); |
---|
2046 | } |
---|
2047 | m_acListPicYuvRec[layer].pushBack( rpcPicYuvRec ); |
---|
2048 | } |
---|
2049 | |
---|
2050 | Void TAppEncTop::xDeleteBuffer( ) |
---|
2051 | { |
---|
2052 | for(UInt layer=0; layer<m_numLayers; layer++) |
---|
2053 | { |
---|
2054 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].begin(); |
---|
2055 | |
---|
2056 | Int iSize = Int( m_acListPicYuvRec[layer].size() ); |
---|
2057 | |
---|
2058 | for ( Int i = 0; i < iSize; i++ ) |
---|
2059 | { |
---|
2060 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
2061 | pcPicYuvRec->destroy(); |
---|
2062 | delete pcPicYuvRec; pcPicYuvRec = NULL; |
---|
2063 | } |
---|
2064 | } |
---|
2065 | } |
---|
2066 | |
---|
2067 | Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded) |
---|
2068 | { |
---|
2069 | ChromaFormat& chromaFormatIdc = m_apcLayerCfg[layer]->m_chromaFormatIDC; |
---|
2070 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ); |
---|
2071 | Int yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
2072 | |
---|
2073 | const InputColourSpaceConversion ipCSC = (!m_outputInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED; |
---|
2074 | |
---|
2075 | if (m_isField) |
---|
2076 | { |
---|
2077 | //Reinterlace fields |
---|
2078 | Int i; |
---|
2079 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end(); |
---|
2080 | |
---|
2081 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
2082 | { |
---|
2083 | --iterPicYuvRec; |
---|
2084 | } |
---|
2085 | |
---|
2086 | for ( i = 0; i < iNumEncoded/2; i++ ) |
---|
2087 | { |
---|
2088 | TComPicYuv* pcPicYuvRecTop = *(iterPicYuvRec++); |
---|
2089 | TComPicYuv* pcPicYuvRecBottom = *(iterPicYuvRec++); |
---|
2090 | |
---|
2091 | if( !m_apcLayerCfg[layer]->getReconFileName().empty() && pcPicYuvRecTop->isReconstructed() && pcPicYuvRecBottom->isReconstructed() ) |
---|
2092 | { |
---|
2093 | m_apcTVideoIOYuvReconFile[layer]->write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_apcLayerCfg[layer]->getConfWinLeft() * xScal, m_apcLayerCfg[layer]->getConfWinRight() * xScal, |
---|
2094 | m_apcLayerCfg[layer]->getConfWinTop() * yScal, m_apcLayerCfg[layer]->getConfWinBottom() * yScal, NUM_CHROMA_FORMAT, m_isTopFieldFirst ); |
---|
2095 | } |
---|
2096 | } |
---|
2097 | } |
---|
2098 | else |
---|
2099 | { |
---|
2100 | Int i; |
---|
2101 | |
---|
2102 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end(); |
---|
2103 | |
---|
2104 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
2105 | { |
---|
2106 | --iterPicYuvRec; |
---|
2107 | } |
---|
2108 | |
---|
2109 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
2110 | { |
---|
2111 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
2112 | if( !m_apcLayerCfg[layer]->getReconFileName().empty() && pcPicYuvRec->isReconstructed() ) |
---|
2113 | { |
---|
2114 | m_apcTVideoIOYuvReconFile[layer]->write( pcPicYuvRec, ipCSC, m_apcLayerCfg[layer]->getConfWinLeft() * xScal, m_apcLayerCfg[layer]->getConfWinRight() * xScal, |
---|
2115 | m_apcLayerCfg[layer]->getConfWinTop() * yScal, m_apcLayerCfg[layer]->getConfWinBottom() * yScal, |
---|
2116 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
---|
2117 | } |
---|
2118 | } |
---|
2119 | } |
---|
2120 | } |
---|
2121 | |
---|
2122 | Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits) |
---|
2123 | { |
---|
2124 | if (m_isField) |
---|
2125 | { |
---|
2126 | //Reinterlace fields |
---|
2127 | Int i; |
---|
2128 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
2129 | |
---|
2130 | for( i = 0; i < iNumEncoded/2 && iterBitstream != accessUnits.end(); i++ ) |
---|
2131 | { |
---|
2132 | const AccessUnit& auTop = *(iterBitstream++); |
---|
2133 | const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop); |
---|
2134 | rateStatsAccum(auTop, statsTop); |
---|
2135 | |
---|
2136 | const AccessUnit& auBottom = *(iterBitstream++); |
---|
2137 | const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom); |
---|
2138 | rateStatsAccum(auBottom, statsBottom); |
---|
2139 | } |
---|
2140 | } |
---|
2141 | else |
---|
2142 | { |
---|
2143 | Int i; |
---|
2144 | |
---|
2145 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
2146 | |
---|
2147 | for( i = 0; i < iNumEncoded && iterBitstream != accessUnits.end(); i++ ) |
---|
2148 | { |
---|
2149 | const AccessUnit& au = *(iterBitstream++); |
---|
2150 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, au); |
---|
2151 | rateStatsAccum(au, stats); |
---|
2152 | } |
---|
2153 | } |
---|
2154 | } |
---|
2155 | |
---|
2156 | #else // SVC_EXTENSION |
---|
2157 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec) |
---|
2158 | { |
---|
2159 | assert( m_iGOPSize > 0 ); |
---|
2160 | |
---|
2161 | // org. buffer |
---|
2162 | if ( m_cListPicYuvRec.size() >= (UInt)m_iGOPSize ) // buffer will be 1 element longer when using field coding, to maintain first field whilst processing second. |
---|
2163 | { |
---|
2164 | rpcPicYuvRec = m_cListPicYuvRec.popFront(); |
---|
2165 | |
---|
2166 | } |
---|
2167 | else |
---|
2168 | { |
---|
2169 | rpcPicYuvRec = new TComPicYuv; |
---|
2170 | |
---|
2171 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
---|
2172 | |
---|
2173 | } |
---|
2174 | m_cListPicYuvRec.pushBack( rpcPicYuvRec ); |
---|
2175 | } |
---|
2176 | |
---|
2177 | Void TAppEncTop::xDeleteBuffer( ) |
---|
2178 | { |
---|
2179 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.begin(); |
---|
2180 | |
---|
2181 | Int iSize = Int( m_cListPicYuvRec.size() ); |
---|
2182 | |
---|
2183 | for ( Int i = 0; i < iSize; i++ ) |
---|
2184 | { |
---|
2185 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
2186 | pcPicYuvRec->destroy(); |
---|
2187 | delete pcPicYuvRec; pcPicYuvRec = NULL; |
---|
2188 | } |
---|
2189 | |
---|
2190 | } |
---|
2191 | |
---|
2192 | /** |
---|
2193 | Write access units to output file. |
---|
2194 | \param bitstreamFile target bitstream file |
---|
2195 | \param iNumEncoded number of encoded frames |
---|
2196 | \param accessUnits list of access units to be written |
---|
2197 | */ |
---|
2198 | Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits) |
---|
2199 | { |
---|
2200 | const InputColourSpaceConversion ipCSC = (!m_outputInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED; |
---|
2201 | |
---|
2202 | if (m_isField) |
---|
2203 | { |
---|
2204 | //Reinterlace fields |
---|
2205 | Int i; |
---|
2206 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
---|
2207 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
2208 | |
---|
2209 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
2210 | { |
---|
2211 | --iterPicYuvRec; |
---|
2212 | } |
---|
2213 | |
---|
2214 | for ( i = 0; i < iNumEncoded/2; i++ ) |
---|
2215 | { |
---|
2216 | TComPicYuv* pcPicYuvRecTop = *(iterPicYuvRec++); |
---|
2217 | TComPicYuv* pcPicYuvRecBottom = *(iterPicYuvRec++); |
---|
2218 | |
---|
2219 | if (!m_reconFileName.empty()) |
---|
2220 | { |
---|
2221 | m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, NUM_CHROMA_FORMAT, m_isTopFieldFirst ); |
---|
2222 | } |
---|
2223 | |
---|
2224 | const AccessUnit& auTop = *(iterBitstream++); |
---|
2225 | const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop); |
---|
2226 | rateStatsAccum(auTop, statsTop); |
---|
2227 | |
---|
2228 | const AccessUnit& auBottom = *(iterBitstream++); |
---|
2229 | const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom); |
---|
2230 | rateStatsAccum(auBottom, statsBottom); |
---|
2231 | } |
---|
2232 | } |
---|
2233 | else |
---|
2234 | { |
---|
2235 | Int i; |
---|
2236 | |
---|
2237 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
---|
2238 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
---|
2239 | |
---|
2240 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
2241 | { |
---|
2242 | --iterPicYuvRec; |
---|
2243 | } |
---|
2244 | |
---|
2245 | for ( i = 0; i < iNumEncoded; i++ ) |
---|
2246 | { |
---|
2247 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
---|
2248 | if (!m_reconFileName.empty()) |
---|
2249 | { |
---|
2250 | m_cTVideoIOYuvReconFile.write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, |
---|
2251 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
---|
2252 | } |
---|
2253 | |
---|
2254 | const AccessUnit& au = *(iterBitstream++); |
---|
2255 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, au); |
---|
2256 | rateStatsAccum(au, stats); |
---|
2257 | } |
---|
2258 | } |
---|
2259 | } |
---|
2260 | #endif |
---|
2261 | |
---|
2262 | /** |
---|
2263 | * |
---|
2264 | */ |
---|
2265 | Void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes) |
---|
2266 | { |
---|
2267 | AccessUnit::const_iterator it_au = au.begin(); |
---|
2268 | vector<UInt>::const_iterator it_stats = annexBsizes.begin(); |
---|
2269 | |
---|
2270 | for (; it_au != au.end(); it_au++, it_stats++) |
---|
2271 | { |
---|
2272 | switch ((*it_au)->m_nalUnitType) |
---|
2273 | { |
---|
2274 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
---|
2275 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
---|
2276 | case NAL_UNIT_CODED_SLICE_TSA_R: |
---|
2277 | case NAL_UNIT_CODED_SLICE_TSA_N: |
---|
2278 | case NAL_UNIT_CODED_SLICE_STSA_R: |
---|
2279 | case NAL_UNIT_CODED_SLICE_STSA_N: |
---|
2280 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
---|
2281 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
---|
2282 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
---|
2283 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
---|
2284 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
---|
2285 | case NAL_UNIT_CODED_SLICE_CRA: |
---|
2286 | case NAL_UNIT_CODED_SLICE_RADL_N: |
---|
2287 | case NAL_UNIT_CODED_SLICE_RADL_R: |
---|
2288 | case NAL_UNIT_CODED_SLICE_RASL_N: |
---|
2289 | case NAL_UNIT_CODED_SLICE_RASL_R: |
---|
2290 | case NAL_UNIT_VPS: |
---|
2291 | case NAL_UNIT_SPS: |
---|
2292 | case NAL_UNIT_PPS: |
---|
2293 | m_essentialBytes += *it_stats; |
---|
2294 | break; |
---|
2295 | default: |
---|
2296 | break; |
---|
2297 | } |
---|
2298 | |
---|
2299 | m_totalBytes += *it_stats; |
---|
2300 | } |
---|
2301 | } |
---|
2302 | |
---|
2303 | Void TAppEncTop::printRateSummary() |
---|
2304 | { |
---|
2305 | #if SVC_EXTENSION |
---|
2306 | Double time = (Double) m_iFrameRcvd / m_apcLayerCfg[m_numLayers-1]->m_iFrameRate * m_temporalSubsampleRatio; |
---|
2307 | #else |
---|
2308 | Double time = (Double) m_iFrameRcvd / m_iFrameRate * m_temporalSubsampleRatio; |
---|
2309 | #endif |
---|
2310 | printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time); |
---|
2311 | if (m_summaryVerboseness > 0) |
---|
2312 | { |
---|
2313 | printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time); |
---|
2314 | } |
---|
2315 | } |
---|
2316 | |
---|
2317 | #if !SVC_EXTENSION |
---|
2318 | Void TAppEncTop::printChromaFormat() |
---|
2319 | { |
---|
2320 | std::cout << std::setw(43) << "Input ChromaFormatIDC = "; |
---|
2321 | switch (m_InputChromaFormatIDC) |
---|
2322 | { |
---|
2323 | case CHROMA_400: std::cout << " 4:0:0"; break; |
---|
2324 | case CHROMA_420: std::cout << " 4:2:0"; break; |
---|
2325 | case CHROMA_422: std::cout << " 4:2:2"; break; |
---|
2326 | case CHROMA_444: std::cout << " 4:4:4"; break; |
---|
2327 | default: |
---|
2328 | std::cerr << "Invalid"; |
---|
2329 | exit(1); |
---|
2330 | } |
---|
2331 | std::cout << std::endl; |
---|
2332 | |
---|
2333 | std::cout << std::setw(43) << "Output (internal) ChromaFormatIDC = "; |
---|
2334 | switch (m_cTEncTop.getChromaFormatIdc()) |
---|
2335 | { |
---|
2336 | case CHROMA_400: std::cout << " 4:0:0"; break; |
---|
2337 | case CHROMA_420: std::cout << " 4:2:0"; break; |
---|
2338 | case CHROMA_422: std::cout << " 4:2:2"; break; |
---|
2339 | case CHROMA_444: std::cout << " 4:4:4"; break; |
---|
2340 | default: |
---|
2341 | std::cerr << "Invalid"; |
---|
2342 | exit(1); |
---|
2343 | } |
---|
2344 | std::cout << "\n" << std::endl; |
---|
2345 | } |
---|
2346 | #endif |
---|
2347 | |
---|
2348 | //! \} |
---|