source: SHVCSoftware/branches/SHM-4.0-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 1497

Last change on this file since 1497 was 497, checked in by seregin, 11 years ago

fix for auxiliary pictures dimension length, provided by Antti Hallapuro <antti.hallapuro@…>

  • Property svn:eol-style set to native
File size: 82.3 KB
RevLine 
[313]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
[466]4 * granted under this license.
[313]5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     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
45#include "TAppEncTop.h"
46#include "TLibEncoder/AnnexBwrite.h"
47
48using namespace std;
49
50//! \ingroup TAppEncoder
51//! \{
52
53// ====================================================================================================================
54// Constructor / destructor / initialization / destroy
55// ====================================================================================================================
56
57TAppEncTop::TAppEncTop()
58{
59  m_iFrameRcvd = 0;
60  m_totalBytes = 0;
61  m_essentialBytes = 0;
62#if SVC_EXTENSION
63  for(UInt layer=0; layer < MAX_LAYERS; layer++)
64  {
65    m_apcTEncTop[layer] = &m_acTEncTop[layer];
66  }
67#endif
68}
69
70TAppEncTop::~TAppEncTop()
71{
72}
73
74#if SVC_EXTENSION
75Void TAppEncTop::xInitLibCfg()
76{
77  TComVPS* vps = m_acTEncTop[0].getVPS();
78
79  vps->setMaxTLayers                       ( m_maxTempLayer );
80  if (m_maxTempLayer == 1)
81  {
82    vps->setTemporalNestingFlag(true);
83  }
84#if !VPS_RENAME
85  vps.setMaxLayers                        ( 1 );
86#endif
87  for(Int i = 0; i < MAX_TLAYER; i++)
88  {
89    vps->setNumReorderPics                 ( m_numReorderPics[i], i );
90    vps->setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
91  }
[442]92#if REPN_FORMAT_IN_VPS
93  vps->setRepFormatIdxPresentFlag( true );   // Could be disabled to optimize in some cases.
94  Int maxRepFormatIdx = -1;
95  Int formatIdx = -1;
96  for(UInt layer=0; layer < m_numLayers; layer++)
97  {
98    // Auto generation of the format index
99    if( m_acLayerCfg[layer].getRepFormatIdx() == -1 )
[481]100    {     
[442]101      Bool found = false;
102      for( UInt idx = 0; idx < layer; idx++ )
103      {
[481]104        if( m_acLayerCfg[layer].getSourceWidth() == m_acLayerCfg[idx].getSourceWidth() && m_acLayerCfg[layer].getSourceHeight() == m_acLayerCfg[idx].getSourceHeight()
[475]105#if AUXILIARY_PICTURES
[481]106          && m_acLayerCfg[layer].getChromaFormatIDC() == m_acLayerCfg[idx].getChromaFormatIDC()
[475]107#endif
[483]108#if O0194_DIFFERENT_BITDEPTH_EL_BL
[481]109          && m_acLayerCfg[layer].m_internalBitDepthY == m_acLayerCfg[idx].m_internalBitDepthY && m_acLayerCfg[layer].m_internalBitDepthC == m_acLayerCfg[idx].m_internalBitDepthC
110#endif
111          )
[442]112        {
113          found = true;
114          break;
115        }
116      }
117      if( !found )
118      {
119        formatIdx++;
120      }
[313]121
[442]122      m_acLayerCfg[layer].setRepFormatIdx( formatIdx );
123    }
124
[466]125    assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );
[442]126    vps->setVpsRepFormatIdx( layer, m_acLayerCfg[layer].getRepFormatIdx() );
127    maxRepFormatIdx = std::max( m_acLayerCfg[layer].getRepFormatIdx(), maxRepFormatIdx );
128  }
129  assert( vps->getVpsRepFormatIdx( 0 ) == 0 );  // Base layer should point to the first one.
130  Int* mapIdxToLayer = new Int[maxRepFormatIdx + 1];
131  // Check that all the indices from 0 to maxRepFormatIdx are used in the VPS
132  for(Int i = 0; i <= maxRepFormatIdx; i++)
133  {
134    mapIdxToLayer[i] = -1;
135    UInt layer;
136    for(layer=0; layer < m_numLayers; layer++)
137    {
138      if( vps->getVpsRepFormatIdx(layer) == i )
139      {
140        mapIdxToLayer[i] = layer;
141        break;
142      }
143    }
144    assert( layer != m_numLayers );   // One of the VPS Rep format indices not set
145  }
146  vps->setVpsNumRepFormats( maxRepFormatIdx + 1 );
147  for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
148  {
[466]149    RepFormat *repFormat = vps->getVpsRepFormat( idx );
[442]150    repFormat->setPicWidthVpsInLumaSamples  ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceWidth()   );
151    repFormat->setPicHeightVpsInLumaSamples ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceHeight()  );
[475]152#if AUXILIARY_PICTURES
153    repFormat->setChromaFormatVpsIdc        ( m_acLayerCfg[mapIdxToLayer[idx]].getChromaFormatIDC() );
154#else
[442]155    repFormat->setChromaFormatVpsIdc        ( 1                                             );  // Need modification to change for each layer - corresponds to 420
[475]156#endif
[442]157    repFormat->setSeparateColourPlaneVpsFlag( 0                                             );  // Need modification to change for each layer
[468]158#if O0194_DIFFERENT_BITDEPTH_EL_BL
[466]159    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY(mapIdxToLayer[idx])      );  // Need modification to change for each layer
160    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC(mapIdxToLayer[idx])      );  // Need modification to change for each layer
161#else
[442]162    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY()                        );  // Need modification to change for each layer
163    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC()                        );  // Need modification to change for each layer
[466]164#endif
[442]165  }
166  delete [] mapIdxToLayer;
167#endif
[313]168  for(UInt layer=0; layer<m_numLayers; layer++)
169  {
[466]170#if O0194_DIFFERENT_BITDEPTH_EL_BL
171    //1
172    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
173    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
174
175    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
176    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
177
178    // Set this to be used in Upsampling filter in function "TComUpsampleFilter::upsampleBasePic"
179    g_bitDepthYLayer[layer] = g_bitDepthY;
180    g_bitDepthCLayer[layer] = g_bitDepthC;
181#endif
[313]182    //m_acTEncTop[layer].setVPS(&vps);
183    m_acTEncTop[layer].setFrameRate                    ( m_acLayerCfg[layer].getFrameRate() );
184    m_acTEncTop[layer].setFrameSkip                    ( m_FrameSkip );
185    m_acTEncTop[layer].setSourceWidth                  ( m_acLayerCfg[layer].getSourceWidth() );
186    m_acTEncTop[layer].setSourceHeight                 ( m_acLayerCfg[layer].getSourceHeight() );
187    m_acTEncTop[layer].setConformanceMode              ( m_acLayerCfg[layer].getConformanceMode() );
188    m_acTEncTop[layer].setConformanceWindow            ( m_acLayerCfg[layer].m_confLeft, m_acLayerCfg[layer].m_confRight, m_acLayerCfg[layer].m_confTop, m_acLayerCfg[layer].m_confBottom );
189    m_acTEncTop[layer].setFramesToBeEncoded            ( m_framesToBeEncoded );
190
191    m_acTEncTop[layer].setProfile(m_profile);
192    m_acTEncTop[layer].setLevel(m_levelTier, m_level);
193    m_acTEncTop[layer].setProgressiveSourceFlag(m_progressiveSourceFlag);
194    m_acTEncTop[layer].setInterlacedSourceFlag(m_interlacedSourceFlag);
195    m_acTEncTop[layer].setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
196    m_acTEncTop[layer].setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
197
198#if REF_IDX_MFM
199#if AVC_BASE
200#if M0457_PREDICTION_INDICATIONS
201    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_avcBaseLayerFlag ? AVC_SYNTAX : true ) && m_acLayerCfg[layer].getNumMotionPredRefLayers());
202#else
203    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_avcBaseLayerFlag ? AVC_SYNTAX : true ));
204#endif
205#else
206#if M0457_PREDICTION_INDICATIONS
207    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : ( m_acLayerCfg[layer].getNumMotionPredRefLayers() > 0 ) );
208#else
209    m_acTEncTop[layer].setMFMEnabledFlag(layer == 0 ? false : true);
210#endif
211#endif
212#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
213    m_acTEncTop[layer].setIlSampleOnlyPred( layer == 0 ? 0 : m_ilSampleOnlyPred[layer] );
214#endif
215#endif
[466]216    // set layer ID
217    m_acTEncTop[layer].setLayerId ( layer );
[313]218    m_acTEncTop[layer].setNumLayer ( m_numLayers );
219    m_acTEncTop[layer].setLayerEnc(m_apcTEncTop);
220
221    //====== Coding Structure ========
222    m_acTEncTop[layer].setIntraPeriod                  ( m_acLayerCfg[layer].m_iIntraPeriod );
223    m_acTEncTop[layer].setDecodingRefreshType          ( m_iDecodingRefreshType );
224    m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
225    m_acTEncTop[layer].setGopList                      ( m_GOPList );
[471]226
[313]227    m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs );
228    for(Int i = 0; i < MAX_TLAYER; i++)
229    {
230      m_acTEncTop[layer].setNumReorderPics             ( m_numReorderPics[i], i );
231      m_acTEncTop[layer].setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
232    }
233    for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
234    {
235      m_acTEncTop[layer].setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
236    }
237    m_acTEncTop[layer].setQP                           ( m_acLayerCfg[layer].getIntQP() );
238
239    m_acTEncTop[layer].setPad                          ( m_acLayerCfg[layer].getPad() );
240
241    m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
242    m_acTEncTop[layer].setUseAMP( m_enableAMP );
[442]243#if N0120_MAX_TID_REF_CFG
244    if (layer<m_numLayers-1)
245    {
[466]246       m_acTEncTop[layer].setMaxTidIlRefPicsPlus1 ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1());
[442]247    }
[466]248#endif
[313]249#if VPS_EXTN_DIRECT_REF_LAYERS
250    if(layer)
251    {
252#if M0457_PREDICTION_INDICATIONS
253      for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
254      {
255        m_acTEncTop[layer].setSamplePredEnabledFlag(i, false);
256        m_acTEncTop[layer].setMotionPredEnabledFlag(i, false);
257      }
258      if(m_acLayerCfg[layer].getNumSamplePredRefLayers() == -1)
259      {
260        // Not included in the configuration file; assume that each layer depends on previous layer
261        m_acTEncTop[layer].setNumSamplePredRefLayers   (1);      // One sample pred ref. layer
262        m_acTEncTop[layer].setSamplePredRefLayerId     (0, layer - 1);   // Previous layer
263        m_acTEncTop[layer].setSamplePredEnabledFlag    (layer - 1, true);
264      }
265      else
266      {
[466]267        m_acTEncTop[layer].setNumSamplePredRefLayers   ( m_acLayerCfg[layer].getNumSamplePredRefLayers() );
[313]268        for(Int i = 0; i < m_acTEncTop[layer].getNumSamplePredRefLayers(); i++)
269        {
270          m_acTEncTop[layer].setSamplePredRefLayerId   ( i, m_acLayerCfg[layer].getSamplePredRefLayerId(i));
271          m_acTEncTop[layer].setSamplePredEnabledFlag  (m_acLayerCfg[layer].getSamplePredRefLayerId(i), true);
[466]272        }
[313]273      }
274      if(m_acLayerCfg[layer].getNumMotionPredRefLayers() == -1)
275      {
276        // Not included in the configuration file; assume that each layer depends on previous layer
277        m_acTEncTop[layer].setNumMotionPredRefLayers   (1);      // One motion pred ref. layer
278        m_acTEncTop[layer].setMotionPredRefLayerId     (0, layer - 1);   // Previous layer
279        m_acTEncTop[layer].setMotionPredEnabledFlag    (layer - 1, true);
280      }
281      else
282      {
[466]283        m_acTEncTop[layer].setNumMotionPredRefLayers   ( m_acLayerCfg[layer].getNumMotionPredRefLayers() );
[313]284        for(Int i = 0; i < m_acTEncTop[layer].getNumMotionPredRefLayers(); i++)
285        {
286          m_acTEncTop[layer].setMotionPredRefLayerId   ( i, m_acLayerCfg[layer].getMotionPredRefLayerId(i));
[442]287          m_acTEncTop[layer].setMotionPredEnabledFlag  (m_acLayerCfg[layer].getMotionPredRefLayerId(i), true);
[466]288        }
[313]289      }
290      Int numDirectRefLayers = 0;
291      for (Int i = 0; i < layer; i++)
292      {
293        if (m_acTEncTop[layer].getSamplePredEnabledFlag(i) || m_acTEncTop[layer].getMotionPredEnabledFlag(i))
294        {
295          m_acTEncTop[layer].setRefLayerId(numDirectRefLayers, i);
296          numDirectRefLayers++;
297        }
298      }
299      m_acTEncTop[layer].setNumDirectRefLayers(numDirectRefLayers);
300#else
301      if(m_acLayerCfg[layer].getNumDirectRefLayers() == -1)
302      {
303        // Not included in the configuration file; assume that each layer depends on previous layer
304        m_acTEncTop[layer].setNumDirectRefLayers       (1);      // One ref. layer
305        m_acTEncTop[layer].setRefLayerId               (0, layer - 1);   // Previous layer
306      }
307      else
308      {
[466]309        m_acTEncTop[layer].setNumDirectRefLayers       ( m_acLayerCfg[layer].getNumDirectRefLayers() );
[313]310        for(Int i = 0; i < m_acTEncTop[layer].getNumDirectRefLayers(); i++)
311        {
312          m_acTEncTop[layer].setRefLayerId             ( i, m_acLayerCfg[layer].getRefLayerId(i));
313        }
314      }
315#endif
316      if(m_acLayerCfg[layer].getNumActiveRefLayers() == -1)
317      {
318#if M0457_PREDICTION_INDICATIONS
319        m_acTEncTop[layer].setNumActiveRefLayers( m_acTEncTop[layer].getNumDirectRefLayers() );
320#else
321        m_acTEncTop[layer].setNumActiveRefLayers( m_acLayerCfg[layer].getNumDirectRefLayers() );
322#endif
323        for( Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++ )
324        {
325          m_acTEncTop[layer].setPredLayerId(i, i);
326        }
327      }
328      else
329      {
[466]330        m_acTEncTop[layer].setNumActiveRefLayers       ( m_acLayerCfg[layer].getNumActiveRefLayers() );
[313]331        for(Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++)
332        {
333          m_acTEncTop[layer].setPredLayerId             ( i, m_acLayerCfg[layer].getPredLayerId(i));
334        }
335      }
336    }
337#endif
338    //===== Slice ========
339
340    //====== Loop/Deblock Filter ========
341    m_acTEncTop[layer].setLoopFilterDisable            ( m_bLoopFilterDisable       );
342    m_acTEncTop[layer].setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
343    m_acTEncTop[layer].setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
344    m_acTEncTop[layer].setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
345    m_acTEncTop[layer].setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
346    m_acTEncTop[layer].setDeblockingFilterMetric       ( m_DeblockingFilterMetric );
347
348    //====== Motion search ========
349    m_acTEncTop[layer].setFastSearch                   ( m_iFastSearch  );
350    m_acTEncTop[layer].setSearchRange                  ( m_iSearchRange );
351    m_acTEncTop[layer].setBipredSearchRange            ( m_bipredSearchRange );
352
353    //====== Quality control ========
354    m_acTEncTop[layer].setMaxDeltaQP                   ( m_iMaxDeltaQP  );
355    m_acTEncTop[layer].setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
356
357    m_acTEncTop[layer].setChromaCbQpOffset             ( m_cbQpOffset     );
358    m_acTEncTop[layer].setChromaCrQpOffset             ( m_crQpOffset  );
359
360#if ADAPTIVE_QP_SELECTION
361    m_acTEncTop[layer].setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
362#endif
363
364    Int lowestQP;
365    lowestQP =  - 6*(g_bitDepthY - 8); // XXX: check
366
367    if ((m_iMaxDeltaQP == 0 ) && (m_acLayerCfg[layer].getIntQP() == lowestQP) && (m_useLossless == true))
368    {
369      m_bUseAdaptiveQP = false;
370    }
371    m_acTEncTop[layer].setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
372    m_acTEncTop[layer].setQPAdaptationRange            ( m_iQPAdaptationRange );
373
374    //====== Tool list ========
375    m_acTEncTop[layer].setUseSBACRD                    ( m_bUseSBACRD   );
376    m_acTEncTop[layer].setDeltaQpRD                    ( m_uiDeltaQpRD  );
377    m_acTEncTop[layer].setUseASR                       ( m_bUseASR      );
378    m_acTEncTop[layer].setUseHADME                     ( m_bUseHADME    );
379    m_acTEncTop[layer].setUseLossless                  ( m_useLossless );
380    m_acTEncTop[layer].setdQPs                         ( m_acLayerCfg[layer].getdQPs() );
381    m_acTEncTop[layer].setUseRDOQ                      ( m_useRDOQ     );
382    m_acTEncTop[layer].setUseRDOQTS                    ( m_useRDOQTS   );
383    m_acTEncTop[layer].setRDpenalty                    ( m_rdPenalty );
[467]384#if LAYER_CTB
385    m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize );
386    m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize );
387    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter );
388    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra );
389#else
[313]390    m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
391    m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
392    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
393    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
[467]394#endif
[313]395    m_acTEncTop[layer].setUseFastEnc                   ( m_bUseFastEnc  );
[466]396    m_acTEncTop[layer].setUseEarlyCU                   ( m_bUseEarlyCU  );
[313]397    m_acTEncTop[layer].setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
398    m_acTEncTop[layer].setUseCbfFastMode               ( m_bUseCbfFastMode  );
399    m_acTEncTop[layer].setUseEarlySkipDetection        ( m_useEarlySkipDetection );
400#if FAST_INTRA_SHVC
401    m_acTEncTop[layer].setUseFastIntraScalable         ( m_useFastIntraScalable );
402#endif
403
404    m_acTEncTop[layer].setUseTransformSkip             ( m_useTransformSkip      );
405    m_acTEncTop[layer].setUseTransformSkipFast         ( m_useTransformSkipFast  );
406    m_acTEncTop[layer].setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
407    m_acTEncTop[layer].setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
408    m_acTEncTop[layer].setUsePCM                       ( m_usePCM );
409    m_acTEncTop[layer].setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
410    m_acTEncTop[layer].setMaxNumMergeCand              ( m_maxNumMergeCand );
411
412
413    //====== Weighted Prediction ========
414    m_acTEncTop[layer].setUseWP                   ( m_useWeightedPred      );
415    m_acTEncTop[layer].setWPBiPred                ( m_useWeightedBiPred   );
[466]416#if O0194_WEIGHTED_PREDICTION_CGS
[468]417    if (layer!=0)
418    {
[466]419      // Enable weighted prediction for enhancement layer
420      m_acTEncTop[layer].setUseWP                 ( true   );
421      m_acTEncTop[layer].setWPBiPred              ( true   );
422    }
423#endif
[313]424    //====== Parallel Merge Estimation ========
425    m_acTEncTop[layer].setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
426
427    //====== Slice ========
428    m_acTEncTop[layer].setSliceMode               ( m_sliceMode                );
429    m_acTEncTop[layer].setSliceArgument           ( m_sliceArgument            );
430
431    //====== Dependent Slice ========
432    m_acTEncTop[layer].setSliceSegmentMode        ( m_sliceSegmentMode         );
433    m_acTEncTop[layer].setSliceSegmentArgument    ( m_sliceSegmentArgument     );
[467]434#if LAYER_CTB
435    Int iNumPartInCU = 1<<(m_acLayerCfg[layer].m_uiMaxCUDepth<<1);
436#else
[313]437    Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
[467]438#endif
[313]439    if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
440    {
441      m_acTEncTop[layer].setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU );
442    }
443    if(m_sliceMode==FIXED_NUMBER_OF_LCU)
444    {
445      m_acTEncTop[layer].setSliceArgument ( m_sliceArgument * iNumPartInCU );
446    }
447    if(m_sliceMode==FIXED_NUMBER_OF_TILES)
448    {
449      m_acTEncTop[layer].setSliceArgument ( m_sliceArgument );
450    }
451
452    if(m_sliceMode == 0 )
453    {
454      m_bLFCrossSliceBoundaryFlag = true;
455    }
456    m_acTEncTop[layer].setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
457    m_acTEncTop[layer].setUseSAO ( m_bUseSAO );
458    m_acTEncTop[layer].setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
459
460    m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary);
461    m_acTEncTop[layer].setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
[466]462    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
463    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
[313]464
465    m_acTEncTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
466    m_acTEncTop[layer].setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
467    m_acTEncTop[layer].setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
468    m_acTEncTop[layer].setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
469    m_acTEncTop[layer].setToneMappingInfoSEIEnabled                 ( m_toneMappingInfoSEIEnabled );
470    m_acTEncTop[layer].setTMISEIToneMapId                           ( m_toneMapId );
471    m_acTEncTop[layer].setTMISEIToneMapCancelFlag                   ( m_toneMapCancelFlag );
472    m_acTEncTop[layer].setTMISEIToneMapPersistenceFlag              ( m_toneMapPersistenceFlag );
473    m_acTEncTop[layer].setTMISEICodedDataBitDepth                   ( m_toneMapCodedDataBitDepth );
474    m_acTEncTop[layer].setTMISEITargetBitDepth                      ( m_toneMapTargetBitDepth );
475    m_acTEncTop[layer].setTMISEIModelID                             ( m_toneMapModelId );
476    m_acTEncTop[layer].setTMISEIMinValue                            ( m_toneMapMinValue );
477    m_acTEncTop[layer].setTMISEIMaxValue                            ( m_toneMapMaxValue );
478    m_acTEncTop[layer].setTMISEISigmoidMidpoint                     ( m_sigmoidMidpoint );
479    m_acTEncTop[layer].setTMISEISigmoidWidth                        ( m_sigmoidWidth );
480    m_acTEncTop[layer].setTMISEIStartOfCodedInterva                 ( m_startOfCodedInterval );
481    m_acTEncTop[layer].setTMISEINumPivots                           ( m_numPivots );
482    m_acTEncTop[layer].setTMISEICodedPivotValue                     ( m_codedPivotValue );
483    m_acTEncTop[layer].setTMISEITargetPivotValue                    ( m_targetPivotValue );
484    m_acTEncTop[layer].setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
485    m_acTEncTop[layer].setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
486    m_acTEncTop[layer].setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
487    m_acTEncTop[layer].setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
488    m_acTEncTop[layer].setTMISEIExposureCompensationValueDenomIdc   ( m_exposureCompensationValueDenomIdc );
489    m_acTEncTop[layer].setTMISEIRefScreenLuminanceWhite             ( m_refScreenLuminanceWhite );
490    m_acTEncTop[layer].setTMISEIExtendedRangeWhiteLevel             ( m_extendedRangeWhiteLevel );
491    m_acTEncTop[layer].setTMISEINominalBlackLevelLumaCodeValue      ( m_nominalBlackLevelLumaCodeValue );
492    m_acTEncTop[layer].setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
493    m_acTEncTop[layer].setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
494    m_acTEncTop[layer].setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
495    m_acTEncTop[layer].setFramePackingArrangementSEIType( m_framePackingSEIType );
496    m_acTEncTop[layer].setFramePackingArrangementSEIId( m_framePackingSEIId );
497    m_acTEncTop[layer].setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx );
498    m_acTEncTop[layer].setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation );
499    m_acTEncTop[layer].setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle );
500    m_acTEncTop[layer].setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled );
501    m_acTEncTop[layer].setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
502    m_acTEncTop[layer].setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
503#if M0043_LAYERS_PRESENT_SEI
504    m_acTEncTop[layer].setLayersPresentSEIEnabled( m_layersPresentSEIEnabled );
505#endif
506    m_acTEncTop[layer].setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
507    m_acTEncTop[layer].setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
[442]508#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
509    m_acTEncTop[layer].setInterLayerConstrainedTileSetsSEIEnabled( m_interLayerConstrainedTileSetsSEIEnabled );
510    m_acTEncTop[layer].setIlNumSetsInMessage( m_ilNumSetsInMessage );
511    m_acTEncTop[layer].setSkippedTileSetPresentFlag( m_skippedTileSetPresentFlag );
512    m_acTEncTop[layer].setTopLeftTileIndex( m_topLeftTileIndex );
513    m_acTEncTop[layer].setBottomRightTileIndex( m_bottomRightTileIndex );
514    m_acTEncTop[layer].setIlcIdc( m_ilcIdc );
515#endif
[313]516    m_acTEncTop[layer].setUniformSpacingIdr          ( m_iUniformSpacingIdr );
517    m_acTEncTop[layer].setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
518    m_acTEncTop[layer].setNumRowsMinus1              ( m_iNumRowsMinus1 );
519    if(m_iUniformSpacingIdr==0)
520    {
521      m_acTEncTop[layer].setColumnWidth              ( m_pColumnWidth );
522      m_acTEncTop[layer].setRowHeight                ( m_pRowHeight );
523    }
524    m_acTEncTop[layer].xCheckGSParameters();
525    Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
526    if(uiTilesCount == 1)
527    {
[466]528      m_bLFCrossTileBoundaryFlag = true;
[313]529    }
530    m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
531    m_acTEncTop[layer].setWaveFrontSynchro           ( m_iWaveFrontSynchro );
532    m_acTEncTop[layer].setWaveFrontSubstreams        ( m_acLayerCfg[layer].m_iWaveFrontSubstreams );
533    m_acTEncTop[layer].setTMVPModeId ( m_TMVPModeId );
534    m_acTEncTop[layer].setUseScalingListId           ( m_useScalingListId  );
535    m_acTEncTop[layer].setScalingListFile            ( m_scalingListFile   );
536    m_acTEncTop[layer].setSignHideFlag(m_signHideFlag);
537#if RATE_CONTROL_LAMBDA_DOMAIN
538#if RC_SHVC_HARMONIZATION
539    m_acTEncTop[layer].setUseRateCtrl     (m_acLayerCfg[layer].getRCEnableRateControl());
540    m_acTEncTop[layer].setTargetBitrate   (m_acLayerCfg[layer].getRCTargetBitrate());
541    m_acTEncTop[layer].setKeepHierBit     (m_acLayerCfg[layer].getRCKeepHierarchicalBit());
542    m_acTEncTop[layer].setLCULevelRC      (m_acLayerCfg[layer].getRCLCULevelRC());
543    m_acTEncTop[layer].setUseLCUSeparateModel (m_acLayerCfg[layer].getRCUseLCUSeparateModel());
544    m_acTEncTop[layer].setInitialQP           (m_acLayerCfg[layer].getRCInitialQP());
545    m_acTEncTop[layer].setForceIntraQP        (m_acLayerCfg[layer].getRCForceIntraQP());
546#else
547    m_acTEncTop[layer].setUseRateCtrl         ( m_RCEnableRateControl );
548    m_acTEncTop[layer].setTargetBitrate       ( m_RCTargetBitrate );
549    m_acTEncTop[layer].setKeepHierBit         ( m_RCKeepHierarchicalBit );
550    m_acTEncTop[layer].setLCULevelRC          ( m_RCLCULevelRC );
551    m_acTEncTop[layer].setUseLCUSeparateModel ( m_RCUseLCUSeparateModel );
552    m_acTEncTop[layer].setInitialQP           ( m_RCInitialQP );
553    m_acTEncTop[layer].setForceIntraQP        ( m_RCForceIntraQP );
554#endif
555#else
556    m_acTEncTop[layer].setUseRateCtrl     ( m_enableRateCtrl);
557    m_acTEncTop[layer].setTargetBitrate   ( m_targetBitrate);
558    m_acTEncTop[layer].setNumLCUInUnit    ( m_numLCUInUnit);
559#endif
560    m_acTEncTop[layer].setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
561    m_acTEncTop[layer].setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue);
562    m_acTEncTop[layer].setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
563    m_acTEncTop[layer].setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
[466]564    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
[313]565    m_acTEncTop[layer].setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
566    m_acTEncTop[layer].setAspectRatioIdc( m_aspectRatioIdc );
567    m_acTEncTop[layer].setSarWidth( m_sarWidth );
568    m_acTEncTop[layer].setSarHeight( m_sarHeight );
569    m_acTEncTop[layer].setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
570    m_acTEncTop[layer].setOverscanAppropriateFlag( m_overscanAppropriateFlag );
571    m_acTEncTop[layer].setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
572    m_acTEncTop[layer].setVideoFormat( m_videoFormat );
573    m_acTEncTop[layer].setVideoFullRangeFlag( m_videoFullRangeFlag );
574    m_acTEncTop[layer].setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
575    m_acTEncTop[layer].setColourPrimaries( m_colourPrimaries );
576    m_acTEncTop[layer].setTransferCharacteristics( m_transferCharacteristics );
577    m_acTEncTop[layer].setMatrixCoefficients( m_matrixCoefficients );
578    m_acTEncTop[layer].setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
579    m_acTEncTop[layer].setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
580    m_acTEncTop[layer].setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
581    m_acTEncTop[layer].setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
582    m_acTEncTop[layer].setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
583    m_acTEncTop[layer].setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag );
584    m_acTEncTop[layer].setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag );
585    m_acTEncTop[layer].setNumTicksPocDiffOneMinus1   ( m_numTicksPocDiffOneMinus1    );
586    m_acTEncTop[layer].setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
587    m_acTEncTop[layer].setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
588    m_acTEncTop[layer].setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
589    m_acTEncTop[layer].setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc );
590    m_acTEncTop[layer].setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
591    m_acTEncTop[layer].setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
592    m_acTEncTop[layer].setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
593    m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
594    m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled);
595    if( layer > 0 )
596    {
597      m_acTEncTop[layer].setNumScaledRefLayerOffsets( m_acLayerCfg[layer].m_numScaledRefLayerOffsets );
598      for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
599      {
600        m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
[466]601                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
[313]602      }
603    }
604#if M0040_ADAPTIVE_RESOLUTION_CHANGE
605    m_acTEncTop[layer].setAdaptiveResolutionChange( m_adaptiveResolutionChange );
606#endif
[475]607#if AUXILIARY_PICTURES
608    m_acTEncTop[layer].setChromaFormatIDC( m_acLayerCfg[layer].m_chromaFormatIDC );
609#endif
[313]610  }
611}
[467]612#else //SVC_EXTENSION
[313]613Void TAppEncTop::xInitLibCfg()
614{
615  TComVPS vps;
616
617  vps.setMaxTLayers                       ( m_maxTempLayer );
618  if (m_maxTempLayer == 1)
619  {
620    vps.setTemporalNestingFlag(true);
621  }
622  vps.setMaxLayers                        ( 1 );
623  for(Int i = 0; i < MAX_TLAYER; i++)
624  {
625    vps.setNumReorderPics                 ( m_numReorderPics[i], i );
626    vps.setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
627  }
628  m_cTEncTop.setVPS(&vps);
629
630  m_cTEncTop.setProfile(m_profile);
631  m_cTEncTop.setLevel(m_levelTier, m_level);
632  m_cTEncTop.setProgressiveSourceFlag(m_progressiveSourceFlag);
633  m_cTEncTop.setInterlacedSourceFlag(m_interlacedSourceFlag);
634  m_cTEncTop.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
635  m_cTEncTop.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
636
637  m_cTEncTop.setFrameRate                    ( m_iFrameRate );
638  m_cTEncTop.setFrameSkip                    ( m_FrameSkip );
639  m_cTEncTop.setSourceWidth                  ( m_iSourceWidth );
640  m_cTEncTop.setSourceHeight                 ( m_iSourceHeight );
641  m_cTEncTop.setConformanceWindow            ( m_confLeft, m_confRight, m_confTop, m_confBottom );
642  m_cTEncTop.setFramesToBeEncoded            ( m_framesToBeEncoded );
643
644  //====== Coding Structure ========
645  m_cTEncTop.setIntraPeriod                  ( m_iIntraPeriod );
646  m_cTEncTop.setDecodingRefreshType          ( m_iDecodingRefreshType );
647  m_cTEncTop.setGOPSize                      ( m_iGOPSize );
648  m_cTEncTop.setGopList                      ( m_GOPList );
649  m_cTEncTop.setExtraRPSs                    ( m_extraRPSs );
650  for(Int i = 0; i < MAX_TLAYER; i++)
651  {
652    m_cTEncTop.setNumReorderPics             ( m_numReorderPics[i], i );
653    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
654  }
655  for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
656  {
657    m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
658  }
659  m_cTEncTop.setQP                           ( m_iQP );
660
661  m_cTEncTop.setPad                          ( m_aiPad );
662
663  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
664  m_cTEncTop.setUseAMP( m_enableAMP );
665
666  //===== Slice ========
667
668  //====== Loop/Deblock Filter ========
669  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
670  m_cTEncTop.setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
671  m_cTEncTop.setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
672  m_cTEncTop.setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
673  m_cTEncTop.setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
674  m_cTEncTop.setDeblockingFilterMetric       ( m_DeblockingFilterMetric );
675
676  //====== Motion search ========
677  m_cTEncTop.setFastSearch                   ( m_iFastSearch  );
678  m_cTEncTop.setSearchRange                  ( m_iSearchRange );
679  m_cTEncTop.setBipredSearchRange            ( m_bipredSearchRange );
680
681  //====== Quality control ========
682  m_cTEncTop.setMaxDeltaQP                   ( m_iMaxDeltaQP  );
683  m_cTEncTop.setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
684
685  m_cTEncTop.setChromaCbQpOffset               ( m_cbQpOffset     );
686  m_cTEncTop.setChromaCrQpOffset            ( m_crQpOffset  );
687
688#if ADAPTIVE_QP_SELECTION
689  m_cTEncTop.setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
690#endif
691
692  Int lowestQP;
693  lowestQP =  - 6*(g_bitDepthY - 8); // XXX: check
694
695  if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))
696  {
697    m_bUseAdaptiveQP = false;
698  }
699  m_cTEncTop.setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
700  m_cTEncTop.setQPAdaptationRange            ( m_iQPAdaptationRange );
701
702  //====== Tool list ========
703  m_cTEncTop.setUseSBACRD                    ( m_bUseSBACRD   );
704  m_cTEncTop.setDeltaQpRD                    ( m_uiDeltaQpRD  );
705  m_cTEncTop.setUseASR                       ( m_bUseASR      );
706  m_cTEncTop.setUseHADME                     ( m_bUseHADME    );
707  m_cTEncTop.setUseLossless                  ( m_useLossless );
708  m_cTEncTop.setdQPs                         ( m_aidQP        );
709  m_cTEncTop.setUseRDOQ                      ( m_useRDOQ     );
710  m_cTEncTop.setUseRDOQTS                    ( m_useRDOQTS   );
711  m_cTEncTop.setRDpenalty                 ( m_rdPenalty );
712  m_cTEncTop.setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
713  m_cTEncTop.setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
714  m_cTEncTop.setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
715  m_cTEncTop.setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
716  m_cTEncTop.setUseFastEnc                   ( m_bUseFastEnc  );
[466]717  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  );
[313]718  m_cTEncTop.setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
719  m_cTEncTop.setUseCbfFastMode            ( m_bUseCbfFastMode  );
720  m_cTEncTop.setUseEarlySkipDetection            ( m_useEarlySkipDetection );
721#if FAST_INTRA_SHVC
722  m_cTEncTop.setUseFastIntraScalable            ( m_useFastIntraScalable );
723#endif
724
725  m_cTEncTop.setUseTransformSkip             ( m_useTransformSkip      );
726  m_cTEncTop.setUseTransformSkipFast         ( m_useTransformSkipFast  );
727  m_cTEncTop.setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
728  m_cTEncTop.setPCMLog2MinSize          ( m_uiPCMLog2MinSize);
729  m_cTEncTop.setUsePCM                       ( m_usePCM );
730  m_cTEncTop.setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
731  m_cTEncTop.setMaxNumMergeCand              ( m_maxNumMergeCand );
732
733
734  //====== Weighted Prediction ========
735  m_cTEncTop.setUseWP                   ( m_useWeightedPred      );
736  m_cTEncTop.setWPBiPred                ( m_useWeightedBiPred   );
737  //====== Parallel Merge Estimation ========
738  m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
739
740  //====== Slice ========
741  m_cTEncTop.setSliceMode               ( m_sliceMode                );
742  m_cTEncTop.setSliceArgument           ( m_sliceArgument            );
743
744  //====== Dependent Slice ========
745  m_cTEncTop.setSliceSegmentMode        ( m_sliceSegmentMode         );
746  m_cTEncTop.setSliceSegmentArgument    ( m_sliceSegmentArgument     );
747  Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
748  if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
749  {
750    m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument * iNumPartInCU );
751  }
752  if(m_sliceMode==FIXED_NUMBER_OF_LCU)
753  {
754    m_cTEncTop.setSliceArgument ( m_sliceArgument * iNumPartInCU );
755  }
756  if(m_sliceMode==FIXED_NUMBER_OF_TILES)
757  {
758    m_cTEncTop.setSliceArgument ( m_sliceArgument );
759  }
760
761  if(m_sliceMode == 0 )
762  {
763    m_bLFCrossSliceBoundaryFlag = true;
764  }
765  m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
766  m_cTEncTop.setUseSAO ( m_bUseSAO );
767  m_cTEncTop.setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
768
769  m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
770  m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
[466]771  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
772  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
[313]773
774  m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
775  m_cTEncTop.setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
776  m_cTEncTop.setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
777  m_cTEncTop.setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
778  m_cTEncTop.setToneMappingInfoSEIEnabled                 ( m_toneMappingInfoSEIEnabled );
779  m_cTEncTop.setTMISEIToneMapId                           ( m_toneMapId );
780  m_cTEncTop.setTMISEIToneMapCancelFlag                   ( m_toneMapCancelFlag );
781  m_cTEncTop.setTMISEIToneMapPersistenceFlag              ( m_toneMapPersistenceFlag );
782  m_cTEncTop.setTMISEICodedDataBitDepth                   ( m_toneMapCodedDataBitDepth );
783  m_cTEncTop.setTMISEITargetBitDepth                      ( m_toneMapTargetBitDepth );
784  m_cTEncTop.setTMISEIModelID                             ( m_toneMapModelId );
785  m_cTEncTop.setTMISEIMinValue                            ( m_toneMapMinValue );
786  m_cTEncTop.setTMISEIMaxValue                            ( m_toneMapMaxValue );
787  m_cTEncTop.setTMISEISigmoidMidpoint                     ( m_sigmoidMidpoint );
788  m_cTEncTop.setTMISEISigmoidWidth                        ( m_sigmoidWidth );
789  m_cTEncTop.setTMISEIStartOfCodedInterva                 ( m_startOfCodedInterval );
790  m_cTEncTop.setTMISEINumPivots                           ( m_numPivots );
791  m_cTEncTop.setTMISEICodedPivotValue                     ( m_codedPivotValue );
792  m_cTEncTop.setTMISEITargetPivotValue                    ( m_targetPivotValue );
793  m_cTEncTop.setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
794  m_cTEncTop.setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
795  m_cTEncTop.setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
796  m_cTEncTop.setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
797  m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc   ( m_exposureCompensationValueDenomIdc );
798  m_cTEncTop.setTMISEIRefScreenLuminanceWhite             ( m_refScreenLuminanceWhite );
799  m_cTEncTop.setTMISEIExtendedRangeWhiteLevel             ( m_extendedRangeWhiteLevel );
800  m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue      ( m_nominalBlackLevelLumaCodeValue );
801  m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue      ( m_nominalWhiteLevelLumaCodeValue );
802  m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue     ( m_extendedWhiteLevelLumaCodeValue );
803  m_cTEncTop.setFramePackingArrangementSEIEnabled( m_framePackingSEIEnabled );
804  m_cTEncTop.setFramePackingArrangementSEIType( m_framePackingSEIType );
805  m_cTEncTop.setFramePackingArrangementSEIId( m_framePackingSEIId );
806  m_cTEncTop.setFramePackingArrangementSEIQuincunx( m_framePackingSEIQuincunx );
807  m_cTEncTop.setFramePackingArrangementSEIInterpretation( m_framePackingSEIInterpretation );
808  m_cTEncTop.setDisplayOrientationSEIAngle( m_displayOrientationSEIAngle );
809  m_cTEncTop.setTemporalLevel0IndexSEIEnabled( m_temporalLevel0IndexSEIEnabled );
810  m_cTEncTop.setGradualDecodingRefreshInfoEnabled( m_gradualDecodingRefreshInfoEnabled );
811  m_cTEncTop.setDecodingUnitInfoSEIEnabled( m_decodingUnitInfoSEIEnabled );
812#if M0043_LAYERS_PRESENT_SEI
813  m_cTEncTop.setLayersPresentSEIEnabled( m_layersPresentSEIEnabled );
814#endif
815  m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
816  m_cTEncTop.setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
817  m_cTEncTop.setUniformSpacingIdr          ( m_iUniformSpacingIdr );
818  m_cTEncTop.setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
819  m_cTEncTop.setNumRowsMinus1              ( m_iNumRowsMinus1 );
820  if(m_iUniformSpacingIdr==0)
821  {
822    m_cTEncTop.setColumnWidth              ( m_pColumnWidth );
823    m_cTEncTop.setRowHeight                ( m_pRowHeight );
824  }
825  m_cTEncTop.xCheckGSParameters();
826  Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
827  if(uiTilesCount == 1)
828  {
[466]829    m_bLFCrossTileBoundaryFlag = true;
[313]830  }
831  m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
832  m_cTEncTop.setWaveFrontSynchro           ( m_iWaveFrontSynchro );
833  m_cTEncTop.setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
834  m_cTEncTop.setTMVPModeId ( m_TMVPModeId );
835  m_cTEncTop.setUseScalingListId           ( m_useScalingListId  );
836  m_cTEncTop.setScalingListFile            ( m_scalingListFile   );
837  m_cTEncTop.setSignHideFlag(m_signHideFlag);
838#if RATE_CONTROL_LAMBDA_DOMAIN
839  m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
840  m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
841  m_cTEncTop.setKeepHierBit         ( m_RCKeepHierarchicalBit );
842  m_cTEncTop.setLCULevelRC          ( m_RCLCULevelRC );
843  m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel );
844  m_cTEncTop.setInitialQP           ( m_RCInitialQP );
845  m_cTEncTop.setForceIntraQP        ( m_RCForceIntraQP );
846#else
847  m_cTEncTop.setUseRateCtrl     ( m_enableRateCtrl);
848  m_cTEncTop.setTargetBitrate   ( m_targetBitrate);
849  m_cTEncTop.setNumLCUInUnit    ( m_numLCUInUnit);
850#endif
851  m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
852  m_cTEncTop.setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue);
853  m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
854  m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
[466]855  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
[313]856  m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
857  m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc );
858  m_cTEncTop.setSarWidth( m_sarWidth );
859  m_cTEncTop.setSarHeight( m_sarHeight );
860  m_cTEncTop.setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
861  m_cTEncTop.setOverscanAppropriateFlag( m_overscanAppropriateFlag );
862  m_cTEncTop.setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
863  m_cTEncTop.setVideoFormat( m_videoFormat );
864  m_cTEncTop.setVideoFullRangeFlag( m_videoFullRangeFlag );
865  m_cTEncTop.setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
866  m_cTEncTop.setColourPrimaries( m_colourPrimaries );
867  m_cTEncTop.setTransferCharacteristics( m_transferCharacteristics );
868  m_cTEncTop.setMatrixCoefficients( m_matrixCoefficients );
869  m_cTEncTop.setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
870  m_cTEncTop.setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
871  m_cTEncTop.setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
872  m_cTEncTop.setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
873  m_cTEncTop.setDefaultDisplayWindow( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
874  m_cTEncTop.setFrameFieldInfoPresentFlag( m_frameFieldInfoPresentFlag );
875  m_cTEncTop.setPocProportionalToTimingFlag( m_pocProportionalToTimingFlag );
876  m_cTEncTop.setNumTicksPocDiffOneMinus1   ( m_numTicksPocDiffOneMinus1    );
877  m_cTEncTop.setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
878  m_cTEncTop.setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
879  m_cTEncTop.setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
880  m_cTEncTop.setMinSpatialSegmentationIdc( m_minSpatialSegmentationIdc );
881  m_cTEncTop.setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
882  m_cTEncTop.setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
883  m_cTEncTop.setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
884  m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
885}
[467]886#endif //SVC_EXTENSION
[313]887
888Void TAppEncTop::xCreateLib()
889{
890  // Video I/O
891#if SVC_EXTENSION
892  // initialize global variables
893  initROM();
894
895  for(UInt layer=0; layer<m_numLayers; layer++)
896  {
[466]897#if O0194_DIFFERENT_BITDEPTH_EL_BL
898    //2
899    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
900    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
901
902    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
903    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
[445]904#endif
[468]905#if LAYER_CTB
906    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
907    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
908    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
909    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
910#endif
[466]911#if O0194_DIFFERENT_BITDEPTH_EL_BL
912    m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_acLayerCfg[layer].m_inputBitDepthY, m_acLayerCfg[layer].m_inputBitDepthC, m_acLayerCfg[layer].m_internalBitDepthY, m_acLayerCfg[layer].m_internalBitDepthC );  // read  mode
913#else
[313]914    m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
[466]915#endif
[313]916    m_acTVideoIOYuvInputFile[layer].skipFrames(m_FrameSkip, m_acLayerCfg[layer].getSourceWidth() - m_acLayerCfg[layer].getPad()[0], m_acLayerCfg[layer].getSourceHeight() - m_acLayerCfg[layer].getPad()[1]);
917
918    if (!m_acLayerCfg[layer].getReconFile().empty())
919    {
[466]920#if O0194_DIFFERENT_BITDEPTH_EL_BL
921      m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_acLayerCfg[layer].m_outputBitDepthY, m_acLayerCfg[layer].m_outputBitDepthC, m_acLayerCfg[layer].m_internalBitDepthY, m_acLayerCfg[layer].m_internalBitDepthC );  // write mode
922#else
[313]923      m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // write mode
[466]924#endif
[313]925    }
926
927    m_acTEncTop[layer].create();
928  }
[467]929#else //SVC_EXTENSION
[313]930  m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
931  m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
932
933  if (m_pchReconFile)
934    m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC);  // write mode
935
936  // Neo Decoder
937  m_cTEncTop.create();
[467]938#endif //SVC_EXTENSION
[313]939}
940
941Void TAppEncTop::xDestroyLib()
942{
943  // Video I/O
944#if SVC_EXTENSION
945  // destroy ROM
946  destroyROM();
947
948  for(UInt layer=0; layer<m_numLayers; layer++)
949  {
[467]950#if LAYER_CTB
951    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
952    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
953    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
954    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
955#endif
956
[313]957    m_acTVideoIOYuvInputFile[layer].close();
958    m_acTVideoIOYuvReconFile[layer].close();
959
960    m_acTEncTop[layer].destroy();
961  }
[467]962#else //SVC_EXTENSION
[313]963  m_cTVideoIOYuvInputFile.close();
964  m_cTVideoIOYuvReconFile.close();
965
966  // Neo Decoder
967  m_cTEncTop.destroy();
[467]968#endif //SVC_EXTENSION
[313]969}
970
[442]971Void TAppEncTop::xInitLib(Bool isFieldCoding)
[313]972{
973#if SVC_EXTENSION
974  for(UInt layer=0; layer<m_numLayers; layer++)
975  {
[468]976#if O0194_DIFFERENT_BITDEPTH_EL_BL
977    //3
978    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
979    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
980
981    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
982    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
983#endif
[467]984#if LAYER_CTB
985    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
986    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
987    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
988    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
[468]989
[467]990    memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) );
991    memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) );
992    memcpy( g_auiRasterToPelX,  g_auiLayerRasterToPelX[layer],  sizeof( g_auiRasterToPelX ) );
993    memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
994#endif
[442]995    m_acTEncTop[layer].init(isFieldCoding);
[313]996  }
997#if VPS_RENAME
998  m_acTEncTop[0].getVPS()->setMaxLayers( m_numLayers );
999#endif
1000#if VPS_EXTN_OP_LAYER_SETS
1001  TComVPS* vps = m_acTEncTop[0].getVPS();
1002  vps->setMaxLayerId(m_numLayers - 1);    // Set max-layer ID
1003
1004  vps->setNumLayerSets(m_numLayers);
1005  for(Int setId = 1; setId < vps->getNumLayerSets(); setId++)
1006  {
1007    for(Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++)
1008    {
[466]1009#if O0194_DIFFERENT_BITDEPTH_EL_BL
1010      //4
1011      g_bitDepthY = m_acLayerCfg[layerId].m_internalBitDepthY;
1012      g_bitDepthC = m_acLayerCfg[layerId].m_internalBitDepthC;
1013
1014      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthY : m_acLayerCfg[layerId].m_internalBitDepthY;
1015      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthC : m_acLayerCfg[layerId].m_internalBitDepthC;
1016#endif
[313]1017      vps->setLayerIdIncludedFlag(true, setId, layerId);
1018    }
1019  }
1020#if VPS_EXTN_MASK_AND_DIM_INFO
1021  UInt i = 0, dimIdLen = 0;
1022#if AVC_BASE
1023  vps->setAvcBaseLayerFlag(m_avcBaseLayerFlag);
1024#else
1025  vps->setAvcBaseLayerFlag(false);
1026#endif
1027  vps->setSplittingFlag(false);
1028  for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
1029  {
1030    vps->setScalabilityMask(i, false);
1031  }
[466]1032  if(m_numLayers > 1)
[313]1033  {
1034    Int scalabilityTypes = 0;
1035    for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
1036    {
1037      vps->setScalabilityMask(i, m_scalabilityMask[i]);
1038      scalabilityTypes += m_scalabilityMask[i];
1039    }
[475]1040#if AUXILIARY_PICTURES
1041    assert( scalabilityTypes <= 2 );
1042#else
[313]1043    assert( scalabilityTypes == 1 );
[475]1044#endif
[313]1045    vps->setNumScalabilityTypes(scalabilityTypes);
1046  }
1047  else
1048  {
1049    vps->setNumScalabilityTypes(0);
1050  }
1051  while((1 << dimIdLen) < m_numLayers)
1052  {
1053    dimIdLen++;
1054  }
1055  vps->setDimensionIdLen(0, dimIdLen);
1056  vps->setNuhLayerIdPresentFlag(false);
1057  vps->setLayerIdInNuh(0, 0);
1058  vps->setLayerIdInVps(0, 0);
1059  for(i = 1; i < vps->getMaxLayers(); i++)
1060  {
1061    vps->setLayerIdInNuh(i, i);
1062    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
1063    vps->setDimensionId(i, 0, i);
1064  }
[475]1065#if AUXILIARY_PICTURES
1066  if (m_scalabilityMask[3])
1067  {
1068    UInt maxAuxId = 0;
[497]1069    UInt auxDimIdLen = 1;
[475]1070    for(i = 1; i < vps->getMaxLayers(); i++)
1071    {
1072      if (m_acLayerCfg[i].getAuxId() > maxAuxId)
1073      {
1074        maxAuxId = m_acLayerCfg[i].getAuxId();
1075      }
1076    }
1077    while((1 << auxDimIdLen) < (maxAuxId + 1))
1078    {
1079      auxDimIdLen++;
1080    }
1081    vps->setDimensionIdLen(1, auxDimIdLen);
1082    for(i = 1; i < vps->getMaxLayers(); i++)
1083    {
1084      vps->setDimensionId(i, 1, m_acLayerCfg[i].getAuxId());
1085    }
1086  }
[313]1087#endif
[475]1088#endif
[345]1089#if N0120_MAX_TID_REF_PRESENT_FLAG
[442]1090#if N0120_MAX_TID_REF_CFG
1091  vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag);
[466]1092#else
[442]1093  vps->setMaxTidRefPresentFlag(true);
[466]1094#endif
[442]1095  if (vps->getMaxTidRefPresentFlag())
[345]1096  {
1097    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
1098    {
[442]1099#if N0120_MAX_TID_REF_CFG
[484]1100#if O0225_MAX_TID_FOR_REF_LAYERS
1101      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
1102      {
1103        vps->setMaxTidIlRefPicsPlus1(i, j, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
1104      }
1105#else
[466]1106      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
[484]1107#endif
[466]1108#else
[484]1109#if O0225_MAX_TID_FOR_REF_LAYERS
1110      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
1111      {
1112        vps->setMaxTidIlRefPicsPlus1(i, j, vps->getMaxTLayers()+1);
1113      }
1114#else
[442]1115      vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
[466]1116#endif
[484]1117#endif
[345]1118    }
1119  }
1120  else
1121  {
1122    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
1123    {
[484]1124#if O0225_MAX_TID_FOR_REF_LAYERS
1125      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
1126      {
1127        vps->setMaxTidIlRefPicsPlus1(i, j, 7);
1128      }
1129#else
[442]1130      vps->setMaxTidIlRefPicsPlus1(i, 7);
[484]1131#endif
[345]1132    }
1133  }
[466]1134#endif
[345]1135#if ILP_SSH_SIG
[458]1136#if ILP_SSH_SIG_FIX
1137    vps->setIlpSshSignalingEnabledFlag(false);
1138#else
[345]1139    vps->setIlpSshSignalingEnabledFlag(true);
1140#endif
[458]1141#endif
[313]1142#if VPS_EXTN_PROFILE_INFO
1143  vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets());
1144  for(Int setId = 1; setId < vps->getNumLayerSets(); setId++)
1145  {
1146    vps->setProfilePresentFlag(setId, true);
1147    // Note - may need to be changed for other layer structures.
1148    *(vps->getPTLForExtn(setId)) = *(m_acTEncTop[setId].getSPS()->getPTL());
1149  }
1150#endif
1151  // Target output layer
[466]1152  vps->setNumOutputLayerSets(vps->getNumLayerSets());
1153  vps->setNumProfileTierLevel(vps->getNumLayerSets());
[313]1154  vps->setDefaultOneTargetOutputLayerFlag(true);
1155  for(i = 1; i < vps->getNumLayerSets(); i++)
1156  {
1157    vps->setProfileLevelTierIdx(i, i);
[466]1158    vps->setOutputLayerSetIdx(i, i);
[313]1159  }
[467]1160
[313]1161  for(Int lsIdx = 1; lsIdx < vps->getNumLayerSets(); lsIdx++)
1162  {
[466]1163    // Include the highest layer as output layer
[313]1164    for(UInt layer=0; layer <= vps->getMaxLayerId() ; layer++)
1165    {
1166      if(vps->getLayerIdIncludedFlag(lsIdx, layer))
1167      {
1168        vps->setOutputLayerFlag(lsIdx, layer, layer == (vps->getMaxLayerId()));
1169      }
1170    }
1171  }
1172#endif
1173#if VPS_EXTN_DIRECT_REF_LAYERS
1174  // Direct reference layers
1175  UInt maxDirectRefLayers = 0;
1176  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1177  {
1178    vps->setNumDirectRefLayers( layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers() );
1179    maxDirectRefLayers = max<UInt>( maxDirectRefLayers, vps->getNumDirectRefLayers( layerCtr ) );
1180
1181    for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
1182    {
1183      vps->setRefLayerId( layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i) );
1184    }
1185    // Set direct dependency flag
1186    // Initialize flag to 0
1187    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1188    {
1189      vps->setDirectDependencyFlag( layerCtr, refLayerCtr, false );
1190    }
1191    for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
1192    {
1193      vps->setDirectDependencyFlag( layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
1194    }
1195#if M0457_PREDICTION_INDICATIONS
1196    vps->setDirectDepTypeLen(2); // sample and motion types are encoded
1197    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1198    {
1199      if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
1200      {
1201        assert(m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) || m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr));
1202        vps->setDirectDependencyType( layerCtr, refLayerCtr, ((m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) ? 1 : 0) |
1203                                                              (m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr) ? 2 : 0)) - 1);
1204      }
1205      else
1206      {
1207        vps->setDirectDependencyType( layerCtr, refLayerCtr, 0 );
1208      }
1209    }
1210#endif
1211  }
[442]1212#if IL_SL_SIGNALLING_N0371
1213  for(i = 1; i < vps->getMaxLayers(); i++)
1214  {
1215    for(Int j = 0; j < i; j++)
1216    {
1217      vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
1218    }
1219  }
[313]1220#endif
[442]1221#endif
[466]1222#if JCTVC_M0458_INTERLAYER_RPS_SIG
1223    vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true);
1224#endif
[479]1225#if O0062_POC_LSB_NOT_PRESENT_FLAG
1226    for(i = 1; i< vps->getMaxLayers(); i++)
1227    {
1228      if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
1229      {
1230        vps->setPocLsbNotPresentFlag(i, false);
1231      }
1232    }
1233#endif
[466]1234#if N0147_IRAP_ALIGN_FLAG
1235    vps->setCrossLayerIrapAlignFlag(true);
[442]1236    for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1237    {
1238      for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1239      {
1240        if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
[466]1241        {
[442]1242          if(m_acTEncTop[layerCtr].getIntraPeriod() !=  m_acTEncTop[refLayerCtr].getIntraPeriod())
1243          {
1244            vps->setCrossLayerIrapAlignFlag(false);
1245            break;
1246          }
1247        }
1248      }
1249    }
1250
1251    if( vps->getAvcBaseLayerFlag() )
1252    {
1253      vps->setCrossLayerIrapAlignFlag(false);
1254    }
[466]1255#endif
[313]1256#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1257  vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false);
1258#endif
[461]1259#if !VPS_EXTN_OFFSET_CALC
[442]1260#if VPS_EXTN_OFFSET
1261  // to be updated according to the current semantics
1262  vps->setExtensionOffset( 0xffff );
[313]1263#endif
[461]1264#endif
[464]1265
1266#if O0215_PHASE_ALIGNMENT
1267  vps->setPhaseAlignFlag( m_phaseAlignFlag );
1268#endif
1269
[442]1270#else //SVC_EXTENSION
1271  m_cTEncTop.init(isFieldCoding);
1272#endif //SVC_EXTENSION
[313]1273}
1274
1275// ====================================================================================================================
1276// Public member functions
1277// ====================================================================================================================
1278
1279/**
1280 - create internal class
1281 - initialize internal variable
1282 - until the end of input YUV file, call encoding function in TEncTop class
1283 - delete allocated buffers
1284 - destroy internal class
1285 .
1286 */
1287#if SVC_EXTENSION
1288Void TAppEncTop::encode()
1289{
1290  fstream bitstreamFile(m_pBitstreamFile, fstream::binary | fstream::out);
1291  if (!bitstreamFile)
1292  {
1293    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pBitstreamFile);
1294    exit(EXIT_FAILURE);
1295  }
1296
1297  TComPicYuv*       pcPicYuvOrg [MAX_LAYERS];
1298  TComPicYuv*       pcPicYuvRec = NULL;
1299
1300  // initialize internal class & member variables
1301  xInitLibCfg();
1302  xCreateLib();
[442]1303  xInitLib(m_isField);
[313]1304
1305  // main encoder loop
1306  Int   iNumEncoded = 0, iTotalNumEncoded = 0;
1307  Bool  bEos = false;
1308
1309  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
1310
1311  for(UInt layer=0; layer<m_numLayers; layer++)
1312  {
[466]1313#if O0194_DIFFERENT_BITDEPTH_EL_BL
1314    //5
1315    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
1316    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
1317
1318    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
1319    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
1320#endif
[313]1321    // allocate original YUV buffer
1322    pcPicYuvOrg[layer] = new TComPicYuv;
[442]1323    if( m_isField )
1324    {
[313]1325#if SVC_UPSAMPLING
[467]1326#if LAYER_CTB
[475]1327#if AUXILIARY_PICTURES
1328      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1329#else
[467]1330      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
[475]1331#endif
[467]1332#else
[475]1333#if AUXILIARY_PICTURES
1334      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1335#else
[442]1336      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
[467]1337#endif
[475]1338#endif
[313]1339#else
[442]1340      pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
[313]1341#endif
[442]1342    }
1343    else
1344    {
1345#if SVC_UPSAMPLING
[467]1346#if LAYER_CTB
[475]1347#if AUXILIARY_PICTURES
1348      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1349#else
[467]1350      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
[475]1351#endif
[467]1352#else
[475]1353#if AUXILIARY_PICTURES
1354      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1355#else
[442]1356      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
[467]1357#endif
[475]1358#endif
[442]1359#else
1360      pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1361#endif
1362    }
[313]1363  }
1364
1365#if AVC_SYNTAX
1366  fstream streamSyntaxFile;
1367  if( m_acTEncTop[0].getVPS()->getAvcBaseLayerFlag() )
1368  {
1369    if( !m_BLSyntaxFile )
1370    {
1371      printf( "Wrong base layer syntax input file\n" );
1372      exit(EXIT_FAILURE);
1373    }
1374    streamSyntaxFile.open( m_BLSyntaxFile, fstream::in | fstream::binary );
1375    if( !streamSyntaxFile.good() )
1376    {
1377      printf( "Base layer syntax input reading error\n" );
1378      exit(EXIT_FAILURE);
1379    }
1380    m_acTEncTop[0].setBLSyntaxFile( &streamSyntaxFile );
1381  }
1382#endif
1383
1384  Bool bFirstFrame = true;
1385  while ( !bEos )
1386  {
[466]1387    // Read enough frames
[313]1388    Bool bFramesReadyToCode = false;
1389    while(!bFramesReadyToCode)
1390    {
1391      for(UInt layer=0; layer<m_numLayers; layer++)
1392      {
[466]1393#if O0194_DIFFERENT_BITDEPTH_EL_BL
1394        //6
1395        g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
1396        g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
1397
1398        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
1399        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
[445]1400#endif
[468]1401#if LAYER_CTB
1402        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
1403        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
1404        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
1405        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
1406#endif
1407
[313]1408        // get buffers
1409        xGetBuffer(pcPicYuvRec, layer);
1410
1411        // read input YUV file
1412        m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], m_acLayerCfg[layer].getPad() );
1413
[475]1414#if AUXILIARY_PICTURES
1415        if (m_acLayerCfg[layer].getChromaFormatIDC() == CHROMA_400)
1416        {
1417          pcPicYuvOrg[layer]->convertToMonochrome();
1418        }
1419#endif
1420
[313]1421        if(layer == m_numLayers-1)
1422        {
1423          // increase number of received frames
1424          m_iFrameRcvd++;
1425          // check end of file
[442]1426          bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
[313]1427        }
1428
[442]1429        if ( m_isField )
1430        {
1431          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer], m_isTopFieldFirst );
1432        }
1433        else
1434        {
1435          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer] );
1436        }
[313]1437      }
1438
1439      bFramesReadyToCode = !(!bFirstFrame && ( m_acTEncTop[m_numLayers-1].getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos );
1440    }
1441    Bool flush = 0;
1442    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
1443    if (m_acTVideoIOYuvInputFile[m_numLayers-1].isEof())
1444    {
1445      flush = true;
1446      bEos = true;
1447      m_iFrameRcvd--;
1448      m_acTEncTop[m_numLayers-1].setFramesToBeEncoded(m_iFrameRcvd);
1449    }
1450
1451#if RC_SHVC_HARMONIZATION
1452    for(UInt layer=0; layer<m_numLayers; layer++)
1453    {
1454      if ( m_acTEncTop[layer].getUseRateCtrl() )
1455      {
1456        (m_acTEncTop[layer].getRateCtrl())->initRCGOP(m_acTEncTop[layer].getNumPicRcvd());
1457      }
1458    }
1459#endif
1460
1461#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1462    if (m_adaptiveResolutionChange)
1463    {
1464      for(UInt layer = 0; layer < m_numLayers; layer++)
1465      {
1466        TComList<TComPicYuv*>::iterator iterPicYuvRec;
1467        for (iterPicYuvRec = m_acListPicYuvRec[layer].begin(); iterPicYuvRec != m_acListPicYuvRec[layer].end(); iterPicYuvRec++)
1468        {
1469          TComPicYuv* recPic = *(iterPicYuvRec);
1470          recPic->setReconstructed(false);
1471        }
1472      }
1473    }
1474#endif
1475
[466]1476    // loop through frames in one GOP
[313]1477    for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ )
1478    {
1479      // layer by layer for each frame
1480      for(UInt layer=0; layer<m_numLayers; layer++)
1481      {
[468]1482#if O0194_DIFFERENT_BITDEPTH_EL_BL
1483        //7
1484        g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
1485        g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
1486
1487        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
1488        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
1489#endif
[467]1490#if LAYER_CTB
1491        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
1492        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
1493        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
1494        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
1495
1496        memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) );
1497        memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) );
1498        memcpy( g_auiRasterToPelX,  g_auiLayerRasterToPelX[layer],  sizeof( g_auiRasterToPelX ) );
1499        memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
1500#endif
[313]1501        // call encoding function for one frame
[442]1502        if ( m_isField )
1503        {
1504          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP, m_isTopFieldFirst );
1505        }
1506        else
1507        {
1508          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
1509        }
[313]1510      }
1511    }
1512
1513#if RC_SHVC_HARMONIZATION
1514    for(UInt layer=0; layer<m_numLayers; layer++)
1515    {
1516      if ( m_acTEncTop[layer].getUseRateCtrl() )
1517      {
1518        (m_acTEncTop[layer].getRateCtrl())->destroyRCGOP();
1519      }
1520    }
1521#endif
1522
1523    iTotalNumEncoded = 0;
1524    for(UInt layer=0; layer<m_numLayers; layer++)
1525    {
[466]1526#if O0194_DIFFERENT_BITDEPTH_EL_BL
1527      //8
1528      g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
1529      g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
1530
1531      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
1532      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
1533#endif
[313]1534      // write bistream to file if necessary
1535      iNumEncoded = m_acTEncTop[layer].getNumPicRcvd();
1536      if ( iNumEncoded > 0 )
1537      {
1538        xWriteRecon(layer, iNumEncoded);
1539        iTotalNumEncoded += iNumEncoded;
1540      }
1541      m_acTEncTop[layer].setNumPicRcvd( 0 );
1542    }
1543
1544    // write bitstream out
1545    if(iTotalNumEncoded)
1546    {
1547      xWriteStream(bitstreamFile, iTotalNumEncoded, outputAccessUnits);
1548      outputAccessUnits.clear();
1549    }
1550
1551    // print out summary
1552    if (bEos)
1553    {
[442]1554      printOutSummary(m_isTopFieldFirst);
[313]1555    }
1556
1557    bFirstFrame = false;
1558  }
1559  // delete original YUV buffer
1560  for(UInt layer=0; layer<m_numLayers; layer++)
1561  {
1562    pcPicYuvOrg[layer]->destroy();
1563    delete pcPicYuvOrg[layer];
1564    pcPicYuvOrg[layer] = NULL;
1565
1566    // delete used buffers in encoder class
1567    m_acTEncTop[layer].deletePicBuffer();
1568  }
1569
1570#if AVC_SYNTAX
1571  if( streamSyntaxFile.is_open() )
1572  {
1573    streamSyntaxFile.close();
1574  }
1575#endif
1576
1577  // delete buffers & classes
1578  xDeleteBuffer();
1579  xDestroyLib();
1580
1581  printRateSummary();
1582
1583  return;
1584}
1585
[442]1586Void TAppEncTop::printOutSummary(Bool isField)
[313]1587{
1588  UInt layer;
1589
1590  // set frame rate
1591  for(layer = 0; layer < m_numLayers; layer++)
1592  {
[442]1593    if(isField)
1594    {
1595      m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2);
1596      m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
1597      m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
1598      m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
1599    }
1600    else
1601    {
1602      m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
1603      m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
1604      m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
1605      m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
1606    }
[313]1607  }
1608
1609  //-- all
1610  printf( "\n\nSUMMARY --------------------------------------------------------\n" );
1611  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
1612  for(layer = 0; layer < m_numLayers; layer++)
1613  {
1614    m_gcAnalyzeAll[layer].printOut('a', layer);
1615  }
1616
1617  printf( "\n\nI Slices--------------------------------------------------------\n" );
1618  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
1619  for(layer = 0; layer < m_numLayers; layer++)
1620  {
1621    m_gcAnalyzeI[layer].printOut('i', layer);
1622  }
1623
1624  printf( "\n\nP Slices--------------------------------------------------------\n" );
1625  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
1626  for(layer = 0; layer < m_numLayers; layer++)
1627  {
1628    m_gcAnalyzeP[layer].printOut('p', layer);
1629  }
1630
1631  printf( "\n\nB Slices--------------------------------------------------------\n" );
1632  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
1633  for(layer = 0; layer < m_numLayers; layer++)
1634  {
1635    m_gcAnalyzeB[layer].printOut('b', layer);
1636  }
[442]1637
1638  if(isField)
1639  {
1640    for(layer = 0; layer < m_numLayers; layer++)
1641    {
1642      //-- interlaced summary
1643      m_gcAnalyzeAll_in.setFrmRate( m_acLayerCfg[layer].getFrameRate());
1644      printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
1645      m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll[layer].getBits());
1646
1647#if _SUMMARY_OUT_
1648      m_gcAnalyzeAll_in.printSummaryOutInterlaced();
1649#endif
1650    }
1651  }
[313]1652}
1653
1654#else
1655Void TAppEncTop::encode()
1656{
1657  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
1658  if (!bitstreamFile)
1659  {
1660    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
1661    exit(EXIT_FAILURE);
1662  }
1663
1664  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
1665  TComPicYuv*       pcPicYuvRec = NULL;
1666
1667  // initialize internal class & member variables
1668  xInitLibCfg();
1669  xCreateLib();
[442]1670  xInitLib(m_isField);
[313]1671
1672  // main encoder loop
1673  Int   iNumEncoded = 0;
1674  Bool  bEos = false;
1675
1676  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
1677
1678  // allocate original YUV buffer
[442]1679  if( m_isField )
1680  {
1681    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1682  }
1683  else
1684  {
1685    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1686  }
[313]1687
1688  while ( !bEos )
1689  {
1690    // get buffers
1691    xGetBuffer(pcPicYuvRec);
1692
1693    // read input YUV file
1694    m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad );
1695
1696    // increase number of received frames
1697    m_iFrameRcvd++;
1698
[442]1699    bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
[313]1700    Bool flush = 0;
1701    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
1702    if (m_cTVideoIOYuvInputFile.isEof())
1703    {
1704      flush = true;
1705      bEos = true;
1706      m_iFrameRcvd--;
1707      m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd);
1708    }
1709
1710    // call encoding function for one frame
[442]1711    if ( m_isField )
1712    {
1713      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst);
1714    }
1715    else
1716    {
[313]1717    m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
[442]1718    }
[313]1719
1720    // write bistream to file if necessary
1721    if ( iNumEncoded > 0 )
1722    {
1723      xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
1724      outputAccessUnits.clear();
1725    }
1726  }
1727
[442]1728  m_cTEncTop.printSummary(m_isField);
[313]1729
1730  // delete original YUV buffer
1731  pcPicYuvOrg->destroy();
1732  delete pcPicYuvOrg;
1733  pcPicYuvOrg = NULL;
1734
1735  // delete used buffers in encoder class
1736  m_cTEncTop.deletePicBuffer();
1737
1738  // delete buffers & classes
1739  xDeleteBuffer();
1740  xDestroyLib();
1741
1742  printRateSummary();
1743
1744  return;
1745}
1746#endif
1747
1748// ====================================================================================================================
1749// Protected member functions
1750// ====================================================================================================================
1751
1752/**
1753 - application has picture buffer list with size of GOP
1754 - picture buffer list acts as ring buffer
1755 - end of the list has the latest picture
1756 .
1757 */
1758#if SVC_EXTENSION
1759Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
1760{
1761  assert( m_iGOPSize > 0 );
1762
1763  // org. buffer
1764  if ( m_acListPicYuvRec[layer].size() == (UInt)m_iGOPSize )
1765  {
1766    rpcPicYuvRec = m_acListPicYuvRec[layer].popFront();
1767
1768  }
1769  else
1770  {
1771    rpcPicYuvRec = new TComPicYuv;
1772
1773#if SVC_UPSAMPLING
[467]1774#if LAYER_CTB
[475]1775#if AUXILIARY_PICTURES
1776    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
1777#else
[467]1778    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
[475]1779#endif
[467]1780#else
[475]1781#if AUXILIARY_PICTURES
1782    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
1783#else
[313]1784    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
[467]1785#endif
[475]1786#endif
[313]1787#else
1788    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1789#endif
1790
1791  }
1792  m_acListPicYuvRec[layer].pushBack( rpcPicYuvRec );
1793}
1794
1795Void TAppEncTop::xDeleteBuffer( )
1796{
1797  for(UInt layer=0; layer<m_numLayers; layer++)
1798  {
1799    TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_acListPicYuvRec[layer].begin();
1800
1801    Int iSize = Int( m_acListPicYuvRec[layer].size() );
1802
1803    for ( Int i = 0; i < iSize; i++ )
1804    {
1805      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1806      pcPicYuvRec->destroy();
1807      delete pcPicYuvRec; pcPicYuvRec = NULL;
1808    }
[466]1809  }
[313]1810}
1811
1812Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
1813{
[442]1814  if (m_isField)
1815  {
1816    //Reinterlace fields
1817    Int i;
1818    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
[313]1819
[442]1820    for ( i = 0; i < iNumEncoded; i++ )
1821    {
1822      --iterPicYuvRec;
1823    }
[313]1824
[442]1825    for ( i = 0; i < iNumEncoded/2; i++ )
1826    {
1827      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
1828      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
[313]1829
1830#if M0040_ADAPTIVE_RESOLUTION_CHANGE
[442]1831      if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRecTop->isReconstructed() && pcPicYuvRecBottom->isReconstructed())
[313]1832#else
[442]1833      if (!m_acLayerCfg[layer].getReconFile().empty())
[313]1834#endif
[442]1835      {
1836        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom(), m_isTopFieldFirst );
1837      }
1838    }
1839  }
1840  else
1841  {
1842    Int i;
1843
1844    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
1845
1846    for ( i = 0; i < iNumEncoded; i++ )
[313]1847    {
[442]1848      --iterPicYuvRec;
[313]1849    }
[442]1850
1851    for ( i = 0; i < iNumEncoded; i++ )
1852    {
1853      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1854#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1855      if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRec->isReconstructed())
1856#else
1857      if (!m_acLayerCfg[layer].getReconFile().empty())
1858#endif
1859      {
[466]1860        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(),
[442]1861          m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
1862      }
1863    }
[313]1864  }
1865}
1866
1867Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
1868{
[442]1869  if (m_isField)
1870  {
1871    //Reinterlace fields
1872    Int i;
1873    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
[313]1874
[442]1875#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1876    for ( i = 0; i < iNumEncoded/2 && iterBitstream != accessUnits.end(); i++ )
1877#else
1878    for ( i = 0; i < iNumEncoded/2; i++ )
1879#endif
[466]1880    {
[442]1881      const AccessUnit& auTop = *(iterBitstream++);
1882      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
1883      rateStatsAccum(auTop, statsTop);
[313]1884
[442]1885      const AccessUnit& auBottom = *(iterBitstream++);
1886      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
1887      rateStatsAccum(auBottom, statsBottom);
1888    }
1889  }
1890  else
1891  {
1892    Int i;
1893
1894    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
1895
[313]1896#if M0040_ADAPTIVE_RESOLUTION_CHANGE
[442]1897    for ( i = 0; i < iNumEncoded && iterBitstream != accessUnits.end(); i++ )
[313]1898#else
[442]1899    for ( i = 0; i < iNumEncoded; i++ )
[313]1900#endif
[442]1901    {
1902      const AccessUnit& au = *(iterBitstream++);
1903      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
1904      rateStatsAccum(au, stats);
1905    }
[313]1906  }
1907}
1908
1909#else // SVC_EXTENSION
1910Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
1911{
1912  assert( m_iGOPSize > 0 );
1913
1914  // org. buffer
1915  if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize )
1916  {
1917    rpcPicYuvRec = m_cListPicYuvRec.popFront();
1918
1919  }
1920  else
1921  {
1922    rpcPicYuvRec = new TComPicYuv;
1923
1924    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1925
1926  }
1927  m_cListPicYuvRec.pushBack( rpcPicYuvRec );
1928}
1929
1930Void TAppEncTop::xDeleteBuffer( )
1931{
1932  TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
1933
1934  Int iSize = Int( m_cListPicYuvRec.size() );
1935
1936  for ( Int i = 0; i < iSize; i++ )
1937  {
1938    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1939    pcPicYuvRec->destroy();
1940    delete pcPicYuvRec; pcPicYuvRec = NULL;
1941  }
1942
1943}
1944
1945/** \param iNumEncoded  number of encoded frames
1946 */
1947Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
1948{
[442]1949  if (m_isField)
1950  {
1951    //Reinterlace fields
1952    Int i;
1953    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
1954    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
[313]1955
[442]1956    for ( i = 0; i < iNumEncoded; i++ )
1957    {
1958      --iterPicYuvRec;
1959    }
[313]1960
[442]1961    for ( i = 0; i < iNumEncoded/2; i++ )
1962    {
1963      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
1964      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
1965
1966      if (m_pchReconFile)
1967      {
1968        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
1969      }
1970
1971      const AccessUnit& auTop = *(iterBitstream++);
1972      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
1973      rateStatsAccum(auTop, statsTop);
1974
1975      const AccessUnit& auBottom = *(iterBitstream++);
1976      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
1977      rateStatsAccum(auBottom, statsBottom);
1978    }
1979  }
1980  else
[313]1981  {
[442]1982    Int i;
[313]1983
[442]1984    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
1985    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
1986
1987    for ( i = 0; i < iNumEncoded; i++ )
[313]1988    {
[442]1989      --iterPicYuvRec;
1990    }
1991
1992    for ( i = 0; i < iNumEncoded; i++ )
1993    {
1994      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1995      if (m_pchReconFile)
1996      {
1997#if SYNTAX_OUTPUT
1998        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
[313]1999#endif
[442]2000      }
2001
2002      const AccessUnit& au = *(iterBitstream++);
2003      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
2004      rateStatsAccum(au, stats);
[313]2005    }
2006  }
2007}
2008#endif
2009
2010/**
2011 *
2012 */
2013void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes)
2014{
2015  AccessUnit::const_iterator it_au = au.begin();
2016  vector<UInt>::const_iterator it_stats = annexBsizes.begin();
2017
2018  for (; it_au != au.end(); it_au++, it_stats++)
2019  {
2020    switch ((*it_au)->m_nalUnitType)
2021    {
2022    case NAL_UNIT_CODED_SLICE_TRAIL_R:
2023    case NAL_UNIT_CODED_SLICE_TRAIL_N:
2024    case NAL_UNIT_CODED_SLICE_TLA_R:
2025    case NAL_UNIT_CODED_SLICE_TSA_N:
2026    case NAL_UNIT_CODED_SLICE_STSA_R:
2027    case NAL_UNIT_CODED_SLICE_STSA_N:
2028    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
2029    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
2030    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
2031    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
2032    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
2033    case NAL_UNIT_CODED_SLICE_CRA:
2034    case NAL_UNIT_CODED_SLICE_RADL_N:
2035    case NAL_UNIT_CODED_SLICE_RADL_R:
2036    case NAL_UNIT_CODED_SLICE_RASL_N:
2037    case NAL_UNIT_CODED_SLICE_RASL_R:
2038    case NAL_UNIT_VPS:
2039    case NAL_UNIT_SPS:
2040    case NAL_UNIT_PPS:
2041      m_essentialBytes += *it_stats;
2042      break;
2043    default:
2044      break;
2045    }
2046
2047    m_totalBytes += *it_stats;
2048  }
2049}
2050
2051void TAppEncTop::printRateSummary()
2052{
2053#if SVC_EXTENSION
2054  Double time = (Double) m_iFrameRcvd / m_acLayerCfg[m_numLayers-1].getFrameRate();
2055#else
2056  Double time = (Double) m_iFrameRcvd / m_iFrameRate;
2057#endif
2058  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
2059#if VERBOSE_RATE
2060  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
2061#endif
2062}
2063
2064//! \}
Note: See TracBrowser for help on using the repository browser.