Changeset 56 in 3DVCSoftware for trunk/source/App/TAppEncoder/TAppEncTop.cpp


Ignore:
Timestamp:
11 May 2012, 21:20:17 (12 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/App/TAppEncoder/TAppEncTop.cpp

    r42 r56  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license.
     4 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2011, ISO/IEC
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3232 */
    3333
    34 
    35 
    3634/** \file     TAppEncTop.cpp
    3735    \brief    Encoder application class
     
    3937
    4038#include <list>
     39#include <fstream>
     40#include <stdlib.h>
    4141#include <stdio.h>
    4242#include <fcntl.h>
     
    4444
    4545#include "TAppEncTop.h"
     46#include "TLibEncoder/AnnexBwrite.h"
     47
     48using namespace std;
     49
     50//! \ingroup TAppEncoder
     51//! \{
    4652
    4753// ====================================================================================================================
     
    5157TAppEncTop::TAppEncTop()
    5258{
    53 #if HHI_VSO
    54   m_iLastFramePutInERViewBuffer = -1;
    55 #endif
     59  m_totalBytes = 0;
     60  m_essentialBytes = 0;
    5661}
    5762
     
    6065}
    6166
    62 
    6367Void TAppEncTop::xInitLibCfg()
    6468{
    6569  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
    6670  {
    67     m_iFrameRcvdVector.push_back(0) ;
    68     m_acTEncTopList.push_back(new TEncTop);
    69 
     71    m_frameRcvd.push_back(0);
     72    m_acTEncTopList.push_back(new TEncTop);
    7073    m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv);
    71 
    7274    m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
    73     m_cListPicYuvRecList.push_back(new TComList<TComPicYuv*>) ;
    74     m_aiNextPocToDump.push_back( 0 );
    75     m_cListPicYuvRecMap.push_back( std::map<PicOrderCnt,TComPicYuv*>() );
     75    m_picYuvRec.push_back(new TComList<TComPicYuv*>) ;
     76
    7677    m_acTEncTopList[iViewIdx]->setFrameRate                    ( m_iFrameRate );
    7778    m_acTEncTopList[iViewIdx]->setFrameSkip                    ( m_FrameSkip );
    7879    m_acTEncTopList[iViewIdx]->setSourceWidth                  ( m_iSourceWidth );
    7980    m_acTEncTopList[iViewIdx]->setSourceHeight                 ( m_iSourceHeight );
     81#if PIC_CROPPING
     82    m_acTEncTopList[iViewIdx]->setCroppingMode                 ( m_croppingMode );
     83    m_acTEncTopList[iViewIdx]->setCropLeft                     ( m_cropLeft );
     84    m_acTEncTopList[iViewIdx]->setCropRight                    ( m_cropRight );
     85    m_acTEncTopList[iViewIdx]->setCropTop                      ( m_cropTop );
     86    m_acTEncTopList[iViewIdx]->setCropBottom                   ( m_cropBottom );
     87#endif
    8088    m_acTEncTopList[iViewIdx]->setFrameToBeEncoded             ( m_iFrameToBeEncoded );
     89    m_acTEncTopList[iViewIdx]->setViewId                       ( iViewIdx );
     90    m_acTEncTopList[iViewIdx]->setIsDepth                      ( false );
     91    m_acTEncTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
     92    m_acTEncTopList[iViewIdx]->setCamParPrecision              ( m_cCameraData.getCamParsCodedPrecision  () );
     93    m_acTEncTopList[iViewIdx]->setCamParInSliceHeader          ( m_cCameraData.getVaryingCameraParameters() );
     94    m_acTEncTopList[iViewIdx]->setCodedScale                   ( m_cCameraData.getCodedScale             () );
     95    m_acTEncTopList[iViewIdx]->setCodedOffset                  ( m_cCameraData.getCodedOffset            () );
    8196
    8297  //====== Coding Structure ========
    83 #if DCM_DECODING_REFRESH
     98    m_acTEncTopList[iViewIdx]->setIntraPeriod                  ( m_iIntraPeriod );
    8499    m_acTEncTopList[iViewIdx]->setDecodingRefreshType          ( m_iDecodingRefreshType );
    85 #endif
    86     m_acTEncTopList[iViewIdx]->setCPSSize                      ( m_uiCodedPictureStoreSize );
    87100    m_acTEncTopList[iViewIdx]->setGOPSize                      ( m_iGOPSize );
    88     m_acTEncTopList[iViewIdx]->setRateGOPSize                  ( m_iRateGOPSize );
    89 
    90     m_acTEncTopList[iViewIdx]->setSeqStructure                              ( m_cInputFormatString );
    91 
     101    m_acTEncTopList[iViewIdx]->setGopList                      ( m_GOPListsMvc[iViewIdx] );
     102    m_acTEncTopList[iViewIdx]->setExtraRPSs                    ( m_extraRPSs[iViewIdx] );
     103#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
     104    for(Int i = 0; i < MAX_TLAYER; i++)
     105    {
     106      m_acTEncTopList[iViewIdx]->setNumReorderPics             ( m_numReorderPics[iViewIdx][i], i );
     107      m_acTEncTopList[iViewIdx]->setMaxDecPicBuffering         ( m_maxDecPicBuffering[iViewIdx][i], i );
     108    }
     109#else
     110    m_acTEncTopList[iViewIdx]->setNumReorderFrames             ( m_numReorderFrames );
     111    m_acTEncTopList[iViewIdx]->setMaxNumberOfReferencePictures ( m_maxNumberOfReferencePictures );
     112#endif
     113    for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
     114    {
     115      m_acTEncTopList[iViewIdx]->setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
     116    }
    92117    m_acTEncTopList[iViewIdx]->setQP                           ( m_aiQP[0] );
    93 
     118 
    94119    m_acTEncTopList[iViewIdx]->setTemporalLayerQPOffset        ( m_aiTLayerQPOffset );
    95120    m_acTEncTopList[iViewIdx]->setPad                          ( m_aiPad );
    96 
    97     //===== Slice ========
    98 
    99     //====== Entropy Coding ========
    100     m_acTEncTopList[iViewIdx]->setSymbolMode                   ( m_iSymbolMode );
    101 
    102     //====== Loop/Deblock Filter ========
    103     m_acTEncTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[0]   );
    104     m_acTEncTopList[iViewIdx]->setLoopFilterAlphaC0Offset      ( m_iLoopFilterAlphaC0Offset );
    105     m_acTEncTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_iLoopFilterBetaOffset    );
    106 
    107     //====== Motion search ========
     121   
     122#if H0566_TLA
     123    m_acTEncTopList[iViewIdx]->setMaxTempLayer                 ( m_maxTempLayer[iViewIdx] );
     124#else
     125    m_acTEncTopList[iViewIdx]->setTLayering                    ( m_bTLayering );
     126    m_acTEncTopList[iViewIdx]->setTLayerSwitchingFlag          ( m_abTLayerSwitchingFlag );
     127#endif
     128
     129    m_acTEncTopList[iViewIdx]->setDisInter4x4                  ( m_bDisInter4x4);
     130 
     131    m_acTEncTopList[iViewIdx]->setUseNSQT( m_enableNSQT );
     132    m_acTEncTopList[iViewIdx]->setUseAMP( m_enableAMP );
     133 
     134  //===== Slice ========
     135 
     136  //====== Loop/Deblock Filter ========
     137    m_acTEncTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[0]       );
     138    m_acTEncTopList[iViewIdx]->setLoopFilterOffsetInAPS        ( m_loopFilterOffsetInAPS );
     139    m_acTEncTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
     140    m_acTEncTopList[iViewIdx]->setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
     141#if DBL_CONTROL
     142    m_acTEncTopList[iViewIdx]->setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
     143#endif
     144
     145  //====== Motion search ========
    108146    m_acTEncTopList[iViewIdx]->setFastSearch                   ( m_iFastSearch  );
    109147    m_acTEncTopList[iViewIdx]->setSearchRange                  ( m_iSearchRange );
    110148    m_acTEncTopList[iViewIdx]->setBipredSearchRange            ( m_bipredSearchRange );
     149
     150  //====== Quality control ========
    111151    m_acTEncTopList[iViewIdx]->setMaxDeltaQP                   ( m_iMaxDeltaQP  );
    112 
     152    m_acTEncTopList[iViewIdx]->setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
     153
     154    m_acTEncTopList[iViewIdx]->setChromaQpOffset               ( m_iChromaQpOffset     );
     155    m_acTEncTopList[iViewIdx]->setChromaQpOffset2nd            ( m_iChromaQpOffset2nd  );
     156
     157#if ADAPTIVE_QP_SELECTION
     158    m_acTEncTopList[iViewIdx]->setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
     159#endif
     160
     161#if LOSSLESS_CODING
     162    Int lowestQP;
     163#if H0736_AVC_STYLE_QP_RANGE
     164    lowestQP =  - ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) );
     165#else
     166    lowestQP = 0;
     167#endif
     168    if ((m_iMaxDeltaQP == 0 ) && (m_aiQP[0] == lowestQP) && (m_useLossless == true))
     169    {
     170      m_bUseAdaptiveQP = false;
     171    }
     172#endif
     173
     174    m_acTEncTopList[iViewIdx]->setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
     175    m_acTEncTopList[iViewIdx]->setQPAdaptationRange            ( m_iQPAdaptationRange );
     176 
    113177#if HHI_VSO
    114178    //====== VSO =========
     
    116180    m_acTEncTopList[iViewIdx]->setLambdaScaleVSO               ( 1     );
    117181    m_acTEncTopList[iViewIdx]->setVSOMode                      ( 0     );
    118 #endif
    119 
    120     //====== Tool list ========
     182    m_acTEncTopList[iViewIdx]->setUseVSO                       ( false ); //GT: might be enabled later for VSO Mode 4
     183#endif
     184
     185#if DEPTH_MAP_GENERATION
     186    m_acTEncTopList[iViewIdx]->setPredDepthMapGeneration       ( m_uiPredDepthMapGeneration );
     187    m_acTEncTopList[iViewIdx]->setPdmPrecision                 ( (UInt)m_cCameraData.getPdmPrecision     () );
     188    m_acTEncTopList[iViewIdx]->setPdmScaleNomDelta             (       m_cCameraData.getPdmScaleNomDelta () );
     189    m_acTEncTopList[iViewIdx]->setPdmOffset                    (       m_cCameraData.getPdmOffset        () );
     190#endif
     191#if HHI_INTER_VIEW_MOTION_PRED
     192    m_acTEncTopList[iViewIdx]->setMultiviewMvPredMode          ( m_uiMultiviewMvPredMode );
     193    m_acTEncTopList[iViewIdx]->setMultiviewMvRegMode           ( iViewIdx ? m_uiMultiviewMvRegMode       : 0   );
     194    m_acTEncTopList[iViewIdx]->setMultiviewMvRegLambdaScale    ( iViewIdx ? m_dMultiviewMvRegLambdaScale : 0.0 );
     195#endif
     196#if HHI_INTER_VIEW_RESIDUAL_PRED
     197    m_acTEncTopList[iViewIdx]->setMultiviewResPredMode         ( m_uiMultiviewResPredMode );
     198#endif
     199
     200  //====== Tool list ========
    121201    m_acTEncTopList[iViewIdx]->setUseSBACRD                    ( m_bUseSBACRD   );
    122202    m_acTEncTopList[iViewIdx]->setDeltaQpRD                    ( m_uiDeltaQpRD  );
     
    124204    m_acTEncTopList[iViewIdx]->setUseHADME                     ( m_bUseHADME    );
    125205    m_acTEncTopList[iViewIdx]->setUseALF                       ( m_abUseALF[0]  );
    126 #if MQT_ALF_NPASS
    127206    m_acTEncTopList[iViewIdx]->setALFEncodePassReduction       ( m_iALFEncodePassReduction );
    128 #endif
    129 #if DCM_COMB_LIST
     207#if LOSSLESS_CODING
     208    m_acTEncTopList[iViewIdx]->setUseLossless                  ( m_useLossless );
     209#endif
     210    m_acTEncTopList[iViewIdx]->setALFMaxNumberFilters          ( m_iALFMaxNumberFilters ) ;
     211
    130212    m_acTEncTopList[iViewIdx]->setUseLComb                     ( m_bUseLComb    );
    131213    m_acTEncTopList[iViewIdx]->setLCMod                        ( m_bLCMod         );
    132 #endif
    133214    m_acTEncTopList[iViewIdx]->setdQPs                         ( m_aidQP        );
    134215    m_acTEncTopList[iViewIdx]->setUseRDOQ                      ( m_abUseRDOQ[0] );
    135     m_acTEncTopList[iViewIdx]->setUseLDC                       ( m_bUseLDC      );
     216#if !PIC_CROPPING
    136217    m_acTEncTopList[iViewIdx]->setUsePAD                       ( m_bUsePAD      );
     218#endif
    137219    m_acTEncTopList[iViewIdx]->setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
    138220    m_acTEncTopList[iViewIdx]->setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
     
    140222    m_acTEncTopList[iViewIdx]->setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
    141223    m_acTEncTopList[iViewIdx]->setUseFastEnc                   ( m_bUseFastEnc  );
    142 
    143 #if HHI_VSO
    144     m_acTEncTopList[iViewIdx]->setUseVSO                       ( false ); //GT: might be enabled later for VSO Mode 4
    145 #endif
    146 
    147 #if BITSTREAM_EXTRACTION
    148     m_acTEncTopList[iViewIdx]->setLayerId                      ( ( (UInt)iViewIdx ) << 1 );
    149 #endif
    150     m_acTEncTopList[iViewIdx]->setViewId                       ( (UInt)iViewIdx );
    151     m_acTEncTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
    152     m_acTEncTopList[iViewIdx]->setIsDepth                      ( false );
    153     m_acTEncTopList[iViewIdx]->setCamParPrecision              ( m_cCameraData.getCamParsCodedPrecision  () );
    154     m_acTEncTopList[iViewIdx]->setCamParInSliceHeader          ( m_cCameraData.getVaryingCameraParameters() );
    155     m_acTEncTopList[iViewIdx]->setCodedScale                   ( m_cCameraData.getCodedScale             () );
    156     m_acTEncTopList[iViewIdx]->setCodedOffset                  ( m_cCameraData.getCodedOffset            () );
    157 #if DEPTH_MAP_GENERATION
    158     m_acTEncTopList[iViewIdx]->setPredDepthMapGeneration       ( m_uiPredDepthMapGeneration );
    159     m_acTEncTopList[iViewIdx]->setPdmPrecision                 ( (UInt)m_cCameraData.getPdmPrecision     () );
    160     m_acTEncTopList[iViewIdx]->setPdmScaleNomDelta             (       m_cCameraData.getPdmScaleNomDelta () );
    161     m_acTEncTopList[iViewIdx]->setPdmOffset                    (       m_cCameraData.getPdmOffset        () );
    162 #endif
    163 #if HHI_INTER_VIEW_MOTION_PRED
    164     m_acTEncTopList[iViewIdx]->setMultiviewMvPredMode          ( m_uiMultiviewMvPredMode );
    165     m_acTEncTopList[iViewIdx]->setMultiviewMvRegMode           ( iViewIdx ? m_uiMultiviewMvRegMode       : 0   );
    166     m_acTEncTopList[iViewIdx]->setMultiviewMvRegLambdaScale    ( iViewIdx ? m_dMultiviewMvRegLambdaScale : 0.0 );
    167 #endif
    168 #if HHI_INTER_VIEW_RESIDUAL_PRED
    169     m_acTEncTopList[iViewIdx]->setMultiviewResPredMode         ( m_uiMultiviewResPredMode );
    170 #endif
    171 
    172 
     224    m_acTEncTopList[iViewIdx]->setUseEarlyCU                   ( m_bUseEarlyCU  );
     225#if FAST_DECISION_FOR_MRG_RD_COST
     226    m_acTEncTopList[iViewIdx]->setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
     227#endif
     228    m_acTEncTopList[iViewIdx]->setUseCbfFastMode               ( m_bUseCbfFastMode  );
    173229#if HHI_INTERVIEW_SKIP
    174     m_acTEncTopList[iViewIdx]->setInterViewSkip            ( iViewIdx ? m_uiInterViewSkip : 0 );
     230    m_acTEncTopList[iViewIdx]->setInterViewSkip            ( iViewIdx>0 ? m_bInterViewSkip : false );
    175231#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
    176     m_acTEncTopList[iViewIdx]->setInterViewSkipLambdaScale ( iViewIdx ? (Int)m_dInterViewSkipLambdaScale : 1 );
    177 #endif
    178 #endif
    179     m_acTEncTopList[iViewIdx]->setUseMRG                       ( m_bUseMRG      ); // SOPH:
    180 
    181 #if LM_CHROMA
     232    m_acTEncTopList[iViewIdx]->setInterViewSkipLambdaScale ( iViewIdx>0 ? (UInt)m_dInterViewSkipLambdaScale : 1 );
     233#endif
     234#endif
    182235    m_acTEncTopList[iViewIdx]->setUseLMChroma                  ( m_bUseLMChroma );
    183 #endif
    184 
    185 #if HHI_RMP_SWITCH
    186     m_acTEncTopList[iViewIdx]->setUseRMP                     ( m_bUseRMP );
    187 #endif
    188 #ifdef ROUNDING_CONTROL_BIPRED
    189     m_acTEncTopList[iViewIdx]->setUseRoundingControlBipred(m_useRoundingControlBipred);
    190 #endif
     236    m_acTEncTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
     237    m_acTEncTopList[iViewIdx]->setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
     238    m_acTEncTopList[iViewIdx]->setUsePCM                       ( m_usePCM );
     239    m_acTEncTopList[iViewIdx]->setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
     240
     241  //====== Weighted Prediction ========
     242    m_acTEncTopList[iViewIdx]->setUseWP                        ( m_bUseWeightPred      );
     243    m_acTEncTopList[iViewIdx]->setWPBiPredIdc                  ( m_uiBiPredIdc         );
     244  //====== Slice ========
     245    m_acTEncTopList[iViewIdx]->setSliceMode                    ( m_iSliceMode                );
     246    m_acTEncTopList[iViewIdx]->setSliceArgument                ( m_iSliceArgument            );
     247
     248  //====== Entropy Slice ========
     249    m_acTEncTopList[iViewIdx]->setEntropySliceMode             ( m_iEntropySliceMode         );
     250    m_acTEncTopList[iViewIdx]->setEntropySliceArgument         ( m_iEntropySliceArgument     );
     251    int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
     252    if(m_iEntropySliceMode==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
     253    {
     254      m_acTEncTopList[iViewIdx]->setEntropySliceArgument ( m_iEntropySliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
     255    }
     256    if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)
     257    {
     258      m_acTEncTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
     259    }
     260#if FIXED_NUMBER_OF_TILES_SLICE_MODE
     261    if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE)
     262    {
     263      m_acTEncTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument );
     264    }
     265#endif
     266    m_acTEncTopList[iViewIdx]->setSliceGranularity        ( m_iSliceGranularity         );
     267    if(m_iSliceMode == 0 )
     268    {
     269      m_bLFCrossSliceBoundaryFlag = true;
     270    }
     271    m_acTEncTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
     272    m_acTEncTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[0]     );
     273#if SAO_UNIT_INTERLEAVING
     274    m_acTEncTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
     275    m_acTEncTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
     276#endif
     277    m_acTEncTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
     278    m_acTEncTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
     279
     280    m_acTEncTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
     281
     282    m_acTEncTopList[iViewIdx]->setColumnRowInfoPresent       ( m_iColumnRowInfoPresent );
     283    m_acTEncTopList[iViewIdx]->setUniformSpacingIdr          ( m_iUniformSpacingIdr );
     284#if !REMOVE_TILE_DEPENDENCE
     285    m_acTEncTopList[iViewIdx]->setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr );
     286#endif
     287    m_acTEncTopList[iViewIdx]->setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
     288    m_acTEncTopList[iViewIdx]->setNumRowsMinus1              ( m_iNumRowsMinus1 );
     289    if(m_iUniformSpacingIdr==0)
     290    {
     291      m_acTEncTopList[iViewIdx]->setColumnWidth              ( m_pchColumnWidth );
     292      m_acTEncTopList[iViewIdx]->setRowHeight                ( m_pchRowHeight );
     293    }
     294    m_acTEncTopList[iViewIdx]->xCheckGSParameters();
     295    m_acTEncTopList[iViewIdx]->setTileLocationInSliceHeaderFlag ( m_iTileLocationInSliceHeaderFlag );
     296    m_acTEncTopList[iViewIdx]->setTileMarkerFlag              ( m_iTileMarkerFlag );
     297    m_acTEncTopList[iViewIdx]->setMaxTileMarkerEntryPoints    ( m_iMaxTileMarkerEntryPoints );
     298 
     299    Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
     300    m_dMaxTileMarkerOffset    = ((Double)uiTilesCount) / m_iMaxTileMarkerEntryPoints;
     301    m_acTEncTopList[iViewIdx]->setMaxTileMarkerOffset         ( m_dMaxTileMarkerOffset );
     302    m_acTEncTopList[iViewIdx]->setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag );
     303#if !REMOVE_TILE_DEPENDENCE
     304    if(m_iTileBoundaryIndependenceIdr == 0 || uiTilesCount == 1)
     305#else
     306    if(uiTilesCount == 1)
     307#endif
     308    {
     309      m_bLFCrossTileBoundaryFlag = true;
     310    }
     311    m_acTEncTopList[iViewIdx]->setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
     312    m_acTEncTopList[iViewIdx]->setWaveFrontSynchro           ( m_iWaveFrontSynchro );
     313    m_acTEncTopList[iViewIdx]->setWaveFrontFlush             ( m_iWaveFrontFlush );
     314    m_acTEncTopList[iViewIdx]->setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
     315    m_acTEncTopList[iViewIdx]->setEnableTMVP ( m_enableTMVP );
     316    m_acTEncTopList[iViewIdx]->setUseScalingListId           ( m_useScalingListId  );
     317    m_acTEncTopList[iViewIdx]->setScalingListFile            ( m_scalingListFile   );
     318#if MULTIBITS_DATA_HIDING
     319    m_acTEncTopList[iViewIdx]->setSignHideFlag(m_signHideFlag);
     320    m_acTEncTopList[iViewIdx]->setTSIG(m_signHidingThreshold);
     321#endif
     322
     323#if LCU_SYNTAX_ALF
     324    if(uiTilesCount > 1)
     325    {
     326      m_bALFParamInSlice = false;
     327      m_bALFPicBasedEncode = true;
     328    }
     329    m_acTEncTopList[iViewIdx]->setALFParamInSlice              ( m_bALFParamInSlice);
     330    m_acTEncTopList[iViewIdx]->setALFPicBasedEncode            ( m_bALFPicBasedEncode);
     331#endif
     332
     333    //====== Depth tools ========
    191334#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    192     m_acTEncTopList[iViewIdx]->setUseDMM( false );
    193 #endif
    194 #if CONSTRAINED_INTRA_PRED
    195     m_acTEncTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
    196 #endif
    197 #ifdef WEIGHT_PRED
    198     //====== Weighted Prediction ========
    199     m_acTEncTopList[iViewIdx]->setUseWP                         ( m_bUseWeightPred      );
    200     m_acTEncTopList[iViewIdx]->setWPBiPredIdc                   ( m_uiBiPredIdc         );
    201 #endif
    202     //====== Slice ========
    203     m_acTEncTopList[iViewIdx]->setSliceMode               ( m_iSliceMode                );
    204     m_acTEncTopList[iViewIdx]->setSliceArgument           ( m_iSliceArgument            );
    205 
    206     //====== Entropy Slice ========
    207     m_acTEncTopList[iViewIdx]->setEntropySliceMode        ( m_iEntropySliceMode         );
    208     m_acTEncTopList[iViewIdx]->setEntropySliceArgument    ( m_iEntropySliceArgument     );
    209 #if MTK_NONCROSS_INLOOP_FILTER
    210     if(m_iSliceMode == 0 )
    211     {
    212       m_bLFCrossSliceBoundaryFlag = true;
    213     }
    214     m_acTEncTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
    215 #endif
    216 #if MTK_SAO
    217     m_acTEncTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[0]     );
     335    m_acTEncTopList[iViewIdx]->setUseDMM                     ( false );
    218336#endif
    219337#if HHI_MPI
    220338    m_acTEncTopList[iViewIdx]->setUseMVI( false );
    221339#endif
    222 
    223     m_acTEncTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
    224     m_acTEncTopList[iViewIdx]->setQpChangeFrame( m_iQpChangeFrame );
    225     m_acTEncTopList[iViewIdx]->setQpChangeOffsetVideo( m_iQpChangeOffsetVideo );
    226     m_acTEncTopList[iViewIdx]->setQpChangeOffsetDepth( m_iQpChangeOffsetDepth );
    227340  }
    228341  if( m_bUsingDepthMaps )
    229342  {
    230 
    231 #if HHI_VSO
    232     for (Int iViewIdx=0; iViewIdx<m_iNumberOfExternalRefs; iViewIdx++)
    233     {
    234         m_acTVideoIOYuvERFileList.push_back(new TVideoIOYuv);
    235     }
    236 #endif
    237 
    238343    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
    239344    {
    240 #if FLEX_CODING_ORDER
    241       // Detect whether depth comes before than texture for this view
    242       Bool isDepthFirst = false;
    243       if ( m_b3DVFlexOrder )
    244       {
    245         for ( Int ii=1; ii<12; ii+=2 )
    246         {
    247           Int iViewIdxCfg = (Int)(m_pchMVCJointCodingOrder[ii]-'0');
    248           if ( iViewIdxCfg == iViewIdx )
    249           {
    250             if ( m_pchMVCJointCodingOrder[ii-1]=='D' ) // depth comes first for this view
    251             {
    252               isDepthFirst = true;
    253             }
    254             else
    255             {
    256               assert(m_pchMVCJointCodingOrder[ii-1]=='T');
    257             }
    258             break;
    259           }
    260         }
    261       }
    262 #endif
    263       m_iDepthFrameRcvdVector.push_back(0) ;
    264       m_acTEncDepthTopList.push_back(new TEncTop);
    265 
     345      m_depthFrameRcvd.push_back(0);
     346      m_acTEncDepthTopList.push_back(new TEncTop);
    266347      m_acTVideoIOYuvDepthInputFileList.push_back(new TVideoIOYuv);
    267 
    268348      m_acTVideoIOYuvDepthReconFileList.push_back(new TVideoIOYuv);
    269       m_cListPicYuvDepthRecList.push_back(new TComList<TComPicYuv*>) ;
    270       m_aiNextDepthPocToDump.push_back( 0 );
    271       m_cListPicYuvDepthRecMap.push_back( std::map<PicOrderCnt,TComPicYuv*>() );
     349      m_picYuvDepthRec.push_back(new TComList<TComPicYuv*>) ;
     350
    272351      m_acTEncDepthTopList[iViewIdx]->setFrameRate                    ( m_iFrameRate );
    273352      m_acTEncDepthTopList[iViewIdx]->setFrameSkip                    ( m_FrameSkip );
    274353      m_acTEncDepthTopList[iViewIdx]->setSourceWidth                  ( m_iSourceWidth );
    275354      m_acTEncDepthTopList[iViewIdx]->setSourceHeight                 ( m_iSourceHeight );
     355#if PIC_CROPPING
     356      m_acTEncDepthTopList[iViewIdx]->setCroppingMode                 ( m_croppingMode );
     357      m_acTEncDepthTopList[iViewIdx]->setCropLeft                     ( m_cropLeft );
     358      m_acTEncDepthTopList[iViewIdx]->setCropRight                    ( m_cropRight );
     359      m_acTEncDepthTopList[iViewIdx]->setCropTop                      ( m_cropTop );
     360      m_acTEncDepthTopList[iViewIdx]->setCropBottom                   ( m_cropBottom );
     361#endif
    276362      m_acTEncDepthTopList[iViewIdx]->setFrameToBeEncoded             ( m_iFrameToBeEncoded );
     363      m_acTEncDepthTopList[iViewIdx]->setViewId                       ( iViewIdx );
     364      m_acTEncDepthTopList[iViewIdx]->setIsDepth                      ( true );
     365      m_acTEncDepthTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
     366      m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( 0 );
     367      m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( false );
     368      m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( 0 );
     369      m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( 0 );
    277370
    278371      //====== Coding Structure ========
    279 #if DCM_DECODING_REFRESH
     372      m_acTEncDepthTopList[iViewIdx]->setIntraPeriod                  ( m_iIntraPeriod );
    280373      m_acTEncDepthTopList[iViewIdx]->setDecodingRefreshType          ( m_iDecodingRefreshType );
    281 #endif
    282       m_acTEncDepthTopList[iViewIdx]->setCPSSize                      ( m_uiCodedPictureStoreSize );
    283374      m_acTEncDepthTopList[iViewIdx]->setGOPSize                      ( m_iGOPSize );
    284       m_acTEncDepthTopList[iViewIdx]->setRateGOPSize                  ( m_iRateGOPSize );
    285 
    286       m_acTEncDepthTopList[iViewIdx]->setSeqStructure                              ( m_cInputFormatString );
    287 
     375      m_acTEncDepthTopList[iViewIdx]->setGopList                      ( m_GOPListsMvc[iViewIdx] );
     376      m_acTEncDepthTopList[iViewIdx]->setExtraRPSs                    ( m_extraRPSs[iViewIdx] );
     377#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
     378      for(Int i = 0; i < MAX_TLAYER; i++)
     379      {
     380        m_acTEncDepthTopList[iViewIdx]->setNumReorderPics             ( m_numReorderPics[iViewIdx][i], i );
     381        m_acTEncDepthTopList[iViewIdx]->setMaxDecPicBuffering         ( m_maxDecPicBuffering[iViewIdx][i], i );
     382      }
     383#else
     384      m_acTEncDepthTopList[iViewIdx]->setNumReorderFrames             ( m_numReorderFrames );
     385      m_acTEncDepthTopList[iViewIdx]->setMaxNumberOfReferencePictures ( m_maxNumberOfReferencePictures );
     386#endif
     387      for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
     388      {
     389        m_acTEncDepthTopList[iViewIdx]->setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
     390      }
    288391      m_acTEncDepthTopList[iViewIdx]->setQP                           ( m_aiQP[1] );
    289392
     
    291394      m_acTEncDepthTopList[iViewIdx]->setPad                          ( m_aiPad );
    292395
     396#if H0566_TLA
     397      m_acTEncDepthTopList[iViewIdx]->setMaxTempLayer                 ( m_maxTempLayer[iViewIdx] );
     398#else
     399      m_acTEncDepthTopList[iViewIdx]->setTLayering                    ( m_bTLayering );
     400      m_acTEncDepthTopList[iViewIdx]->setTLayerSwitchingFlag          ( m_abTLayerSwitchingFlag );
     401#endif
     402
     403      m_acTEncDepthTopList[iViewIdx]->setDisInter4x4                  ( m_bDisInter4x4);
     404
     405      m_acTEncDepthTopList[iViewIdx]->setUseNSQT( m_enableNSQT );
     406      m_acTEncDepthTopList[iViewIdx]->setUseAMP( m_enableAMP );
     407
    293408      //===== Slice ========
    294 
    295       //====== Entropy Coding ========
    296       m_acTEncDepthTopList[iViewIdx]->setSymbolMode                   ( m_iSymbolMode );
    297409
    298410      //====== Loop/Deblock Filter ========
    299411      m_acTEncDepthTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[1]   );
    300       m_acTEncDepthTopList[iViewIdx]->setLoopFilterAlphaC0Offset      ( m_iLoopFilterAlphaC0Offset );
    301       m_acTEncDepthTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_iLoopFilterBetaOffset    );
     412      m_acTEncDepthTopList[iViewIdx]->setLoopFilterOffsetInAPS        ( m_loopFilterOffsetInAPS );
     413      m_acTEncDepthTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
     414      m_acTEncDepthTopList[iViewIdx]->setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
     415#if DBL_CONTROL
     416      m_acTEncDepthTopList[iViewIdx]->setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
     417#endif
    302418
    303419      //====== Motion search ========
     
    305421      m_acTEncDepthTopList[iViewIdx]->setSearchRange                  ( m_iSearchRange );
    306422      m_acTEncDepthTopList[iViewIdx]->setBipredSearchRange            ( m_bipredSearchRange );
     423
     424      //====== Quality control ========
    307425      m_acTEncDepthTopList[iViewIdx]->setMaxDeltaQP                   ( m_iMaxDeltaQP  );
     426      m_acTEncDepthTopList[iViewIdx]->setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
     427
     428      m_acTEncDepthTopList[iViewIdx]->setChromaQpOffset               ( m_iChromaQpOffset     );
     429      m_acTEncDepthTopList[iViewIdx]->setChromaQpOffset2nd            ( m_iChromaQpOffset2nd  );
     430
     431#if ADAPTIVE_QP_SELECTION
     432      m_acTEncDepthTopList[iViewIdx]->setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
     433#endif
     434
     435      m_acTEncDepthTopList[iViewIdx]->setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
     436      m_acTEncDepthTopList[iViewIdx]->setQPAdaptationRange            ( m_iQPAdaptationRange );
    308437
    309438      //====== Tool list ========
     
    313442      m_acTEncDepthTopList[iViewIdx]->setUseHADME                     ( m_bUseHADME    );
    314443      m_acTEncDepthTopList[iViewIdx]->setUseALF                       ( m_abUseALF[1]  );
    315 #if MQT_ALF_NPASS
    316444      m_acTEncDepthTopList[iViewIdx]->setALFEncodePassReduction       ( m_iALFEncodePassReduction );
    317 #endif
    318 #if DCM_COMB_LIST
     445#if LOSSLESS_CODING
     446      m_acTEncDepthTopList[iViewIdx]->setUseLossless                  ( m_useLossless );
     447#endif
     448      m_acTEncDepthTopList[iViewIdx]->setALFMaxNumberFilters          ( m_iALFMaxNumberFilters ) ;
     449
    319450      m_acTEncDepthTopList[iViewIdx]->setUseLComb                     ( m_bUseLComb    );
    320       m_acTEncDepthTopList[iViewIdx]->setLCMod                        ( m_bLCMod         );
    321 #endif
    322       m_acTEncDepthTopList[iViewIdx]->setdQPs                         ( m_aidQP        );
     451      m_acTEncDepthTopList[iViewIdx]->setLCMod                        ( m_bLCMod       );
     452      m_acTEncDepthTopList[iViewIdx]->setdQPs                         ( m_aidQPdepth   );
    323453      m_acTEncDepthTopList[iViewIdx]->setUseRDOQ                      ( m_abUseRDOQ[1] );
    324       m_acTEncDepthTopList[iViewIdx]->setUseLDC                       ( m_bUseLDC      );
     454#if !PIC_CROPPING
    325455      m_acTEncDepthTopList[iViewIdx]->setUsePAD                       ( m_bUsePAD      );
     456#endif
    326457      m_acTEncDepthTopList[iViewIdx]->setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
    327458      m_acTEncDepthTopList[iViewIdx]->setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
     
    329460      m_acTEncDepthTopList[iViewIdx]->setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
    330461      m_acTEncDepthTopList[iViewIdx]->setUseFastEnc                   ( m_bUseFastEnc  );
    331 
     462      m_acTEncDepthTopList[iViewIdx]->setUseEarlyCU                   ( m_bUseEarlyCU  );
     463#if FAST_DECISION_FOR_MRG_RD_COST
     464      m_acTEncDepthTopList[iViewIdx]->setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
     465#endif
     466      m_acTEncDepthTopList[iViewIdx]->setUseCbfFastMode               ( m_bUseCbfFastMode  );
     467#if HHI_INTERVIEW_SKIP
     468      m_acTEncDepthTopList[iViewIdx]->setInterViewSkip            ( 0 );
     469#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
     470      m_acTEncDepthTopList[iViewIdx]->setInterViewSkipLambdaScale ( 1 );
     471#endif
     472#endif
     473      m_acTEncDepthTopList[iViewIdx]->setUseLMChroma                  ( m_bUseLMChroma );
     474      m_acTEncDepthTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
     475      m_acTEncDepthTopList[iViewIdx]->setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
     476      m_acTEncDepthTopList[iViewIdx]->setUsePCM                       ( m_usePCM );
     477      m_acTEncDepthTopList[iViewIdx]->setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
     478      //====== VSO ========
    332479#if HHI_VSO
    333480      m_acTEncDepthTopList[iViewIdx]->setUseVSO                       ( m_bUseVSO      ); //GT: might be enabled/disabled later for VSO Mode 4
     
    340487#endif
    341488
    342 #if BITSTREAM_EXTRACTION
    343       m_acTEncDepthTopList[iViewIdx]->setLayerId                      ( ( ( (UInt)iViewIdx ) << 1 ) + 1 );
    344 #endif
    345       m_acTEncDepthTopList[iViewIdx]->setViewId                       ( (UInt)iViewIdx );
    346       m_acTEncDepthTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
    347       m_acTEncDepthTopList[iViewIdx]->setIsDepth                      ( true );
    348       m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( 0 );
    349       m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( false );
    350       m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( 0 );
    351       m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( 0 );
    352489#if DEPTH_MAP_GENERATION
    353490      m_acTEncDepthTopList[iViewIdx]->setPredDepthMapGeneration       ( 0 );
     
    362499#endif
    363500
    364 #if HHI_INTERVIEW_SKIP
    365       m_acTEncDepthTopList[iViewIdx]->setInterViewSkip            ( 0 );
    366 #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
    367       m_acTEncDepthTopList[iViewIdx]->setInterViewSkipLambdaScale ( 1 );
    368 #endif
    369 #endif
    370       m_acTEncDepthTopList[iViewIdx]->setUseMRG                       ( m_bUseMRG      ); // SOPH:
    371 
    372 #if LM_CHROMA
    373       m_acTEncDepthTopList[iViewIdx]->setUseLMChroma                  ( m_bUseLMChroma );
    374 #endif
    375 
    376 #if HHI_RMP_SWITCH
    377       m_acTEncDepthTopList[iViewIdx]->setUseRMP                     ( m_bUseRMP );
    378 #endif
    379 #ifdef ROUNDING_CONTROL_BIPRED
    380       m_acTEncDepthTopList[iViewIdx]->setUseRoundingControlBipred(m_useRoundingControlBipred);
    381 #endif
     501      //====== Weighted Prediction ========
     502      m_acTEncDepthTopList[iViewIdx]->setUseWP                        ( m_bUseWeightPred      );
     503      m_acTEncDepthTopList[iViewIdx]->setWPBiPredIdc                  ( m_uiBiPredIdc         );
     504      //====== Slice ========
     505      m_acTEncDepthTopList[iViewIdx]->setSliceMode                    ( m_iSliceMode                );
     506      m_acTEncDepthTopList[iViewIdx]->setSliceArgument                ( m_iSliceArgument            );
     507
     508      //====== Entropy Slice ========
     509      m_acTEncDepthTopList[iViewIdx]->setEntropySliceMode             ( m_iEntropySliceMode         );
     510      m_acTEncDepthTopList[iViewIdx]->setEntropySliceArgument         ( m_iEntropySliceArgument     );
     511      int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
     512      if(m_iEntropySliceMode==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
     513      {
     514        m_acTEncDepthTopList[iViewIdx]->setEntropySliceArgument ( m_iEntropySliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
     515      }
     516      if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)
     517      {
     518        m_acTEncDepthTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
     519      }
     520#if FIXED_NUMBER_OF_TILES_SLICE_MODE
     521      if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE)
     522      {
     523        m_acTEncDepthTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument );
     524      }
     525#endif
     526      m_acTEncDepthTopList[iViewIdx]->setSliceGranularity        ( m_iSliceGranularity         );
     527      if(m_iSliceMode == 0 )
     528      {
     529        m_bLFCrossSliceBoundaryFlag = true;
     530      }
     531      m_acTEncDepthTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
     532      m_acTEncDepthTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[1]     );
     533#if SAO_UNIT_INTERLEAVING
     534      m_acTEncDepthTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
     535      m_acTEncDepthTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
     536#endif
     537      m_acTEncDepthTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
     538      m_acTEncDepthTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
     539
     540      m_acTEncDepthTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
     541
     542      m_acTEncDepthTopList[iViewIdx]->setColumnRowInfoPresent       ( m_iColumnRowInfoPresent );
     543      m_acTEncDepthTopList[iViewIdx]->setUniformSpacingIdr          ( m_iUniformSpacingIdr );
     544#if !REMOVE_TILE_DEPENDENCE
     545      m_acTEncDepthTopList[iViewIdx]->setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr );
     546#endif
     547      m_acTEncDepthTopList[iViewIdx]->setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
     548      m_acTEncDepthTopList[iViewIdx]->setNumRowsMinus1              ( m_iNumRowsMinus1 );
     549      if(m_iUniformSpacingIdr==0)
     550      {
     551        m_acTEncDepthTopList[iViewIdx]->setColumnWidth              ( m_pchColumnWidth );
     552        m_acTEncDepthTopList[iViewIdx]->setRowHeight                ( m_pchRowHeight );
     553      }
     554      m_acTEncDepthTopList[iViewIdx]->xCheckGSParameters();
     555      m_acTEncDepthTopList[iViewIdx]->setTileLocationInSliceHeaderFlag ( m_iTileLocationInSliceHeaderFlag );
     556      m_acTEncDepthTopList[iViewIdx]->setTileMarkerFlag              ( m_iTileMarkerFlag );
     557      m_acTEncDepthTopList[iViewIdx]->setMaxTileMarkerEntryPoints    ( m_iMaxTileMarkerEntryPoints );
     558
     559      Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
     560      m_dMaxTileMarkerOffset    = ((Double)uiTilesCount) / m_iMaxTileMarkerEntryPoints;
     561      m_acTEncDepthTopList[iViewIdx]->setMaxTileMarkerOffset         ( m_dMaxTileMarkerOffset );
     562      m_acTEncDepthTopList[iViewIdx]->setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag );
     563#if !REMOVE_TILE_DEPENDENCE
     564      if(m_iTileBoundaryIndependenceIdr == 0 || uiTilesCount == 1)
     565#else
     566      if(uiTilesCount == 1)
     567#endif
     568      {
     569        m_bLFCrossTileBoundaryFlag = true;
     570      }
     571      m_acTEncDepthTopList[iViewIdx]->setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
     572      m_acTEncDepthTopList[iViewIdx]->setWaveFrontSynchro           ( m_iWaveFrontSynchro );
     573      m_acTEncDepthTopList[iViewIdx]->setWaveFrontFlush             ( m_iWaveFrontFlush );
     574      m_acTEncDepthTopList[iViewIdx]->setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
     575      m_acTEncDepthTopList[iViewIdx]->setEnableTMVP ( m_enableTMVP );
     576      m_acTEncDepthTopList[iViewIdx]->setUseScalingListId           ( m_useScalingListId  );
     577      m_acTEncDepthTopList[iViewIdx]->setScalingListFile            ( m_scalingListFile   );
     578#if MULTIBITS_DATA_HIDING
     579      m_acTEncDepthTopList[iViewIdx]->setSignHideFlag(m_signHideFlag);
     580      m_acTEncDepthTopList[iViewIdx]->setTSIG(m_signHidingThreshold);
     581#endif
     582
     583#if LCU_SYNTAX_ALF
     584      if(uiTilesCount > 1)
     585      {
     586        m_bALFParamInSlice = false;
     587        m_bALFPicBasedEncode = true;
     588      }
     589      m_acTEncDepthTopList[iViewIdx]->setALFParamInSlice              ( m_bALFParamInSlice);
     590      m_acTEncDepthTopList[iViewIdx]->setALFPicBasedEncode            ( m_bALFPicBasedEncode);
     591#endif
     592
     593  //====== Depth tools ========
    382594#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    383       m_acTEncDepthTopList[iViewIdx]->setUseDMM( m_bUseDMM );
    384 #endif
    385 #if FLEX_CODING_ORDER && HHI_DMM_PRED_TEX
    386       m_acTEncDepthTopList[iViewIdx]->setUseDMM34( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseDMM );
    387 #endif
    388 #if CONSTRAINED_INTRA_PRED
    389       m_acTEncDepthTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
    390 #endif
    391 #ifdef WEIGHT_PRED
    392     //====== Weighted Prediction ========
    393       m_acTEncDepthTopList[iViewIdx]->setUseWP                         ( m_bUseWeightPred      );
    394       m_acTEncDepthTopList[iViewIdx]->setWPBiPredIdc                   ( m_uiBiPredIdc         );
    395 #endif
    396       //====== Slice ========
    397       m_acTEncDepthTopList[iViewIdx]->setSliceMode               ( m_iSliceMode                );
    398       m_acTEncDepthTopList[iViewIdx]->setSliceArgument           ( m_iSliceArgument            );
    399 
    400       //====== Entropy Slice ========
    401       m_acTEncDepthTopList[iViewIdx]->setEntropySliceMode        ( m_iEntropySliceMode         );
    402       m_acTEncDepthTopList[iViewIdx]->setEntropySliceArgument    ( m_iEntropySliceArgument     );
    403 #if MTK_NONCROSS_INLOOP_FILTER
    404       if(m_iSliceMode == 0 )
    405       {
    406         m_bLFCrossSliceBoundaryFlag = true;
    407       }
    408       m_acTEncDepthTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
    409 #endif
    410 #if MTK_SAO
    411       m_acTEncDepthTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[1]     );
     595    m_acTEncDepthTopList[iViewIdx]->setUseDMM                     ( m_bUseDMM );
    412596#endif
    413597#if HHI_MPI
    414 #if FLEX_CODING_ORDER
    415       m_acTEncDepthTopList[iViewIdx]->setUseMVI( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseMVI );
    416 #else
    417       m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
    418 #endif
    419 #endif
    420      
    421       m_acTEncDepthTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
    422 
    423       m_acTEncDepthTopList[iViewIdx]->setQpChangeFrame( m_iQpChangeFrame );
    424       m_acTEncDepthTopList[iViewIdx]->setQpChangeOffsetVideo( m_iQpChangeOffsetVideo );
    425       m_acTEncDepthTopList[iViewIdx]->setQpChangeOffsetDepth( m_iQpChangeOffsetDepth );
    426     }
    427   }
     598     m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
     599#endif
     600    }
     601  }
     602
    428603#if HHI_INTER_VIEW_MOTION_PRED
    429604  else if( m_uiMultiviewMvRegMode )
     
    466641    else
    467642    {
    468       m_cRendererTop.init(m_iSourceWidth, m_iSourceHeight,true,0,0,true, 0,0,0,0,0,0,0,1,0,0 );  //GT: simplest configuration
     643      AOT(true);
    469644    }
    470645  }
     
    474649  m_cUsedPelsRenderer.init(m_iSourceWidth, m_iSourceHeight, true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 4, 1, 0, 6 );
    475650#endif
     651
    476652}
    477653
    478654Void TAppEncTop::xCreateLib()
    479655{
    480   // Video I/O
    481   m_cTVideoIOBitsFile.openBits( m_pchBitstreamFile, true  );  // write mode
    482 
    483656  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
    484657  {
    485658    m_acTVideoIOYuvInputFileList[iViewIdx]->open( m_pchInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
    486     m_acTVideoIOYuvInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth, m_iSourceHeight);
    487     m_acTVideoIOYuvReconFileList[iViewIdx]->open( m_pchReconFileList[iViewIdx],     true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
    488 
    489     // Neo Decoder
     659    m_acTVideoIOYuvInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
     660
     661    if (m_pchReconFileList[iViewIdx])
     662      m_acTVideoIOYuvReconFileList[iViewIdx]->open(m_pchReconFileList[iViewIdx], true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
    490663    m_acTEncTopList[iViewIdx]->create();
    491 
    492664    if( m_bUsingDepthMaps )
     665    {
     666      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->open( m_pchDepthInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
     667      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
     668
     669      if (m_pchDepthReconFileList[iViewIdx])
     670        m_acTVideoIOYuvDepthReconFileList[iViewIdx]->open(m_pchDepthReconFileList[iViewIdx], true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
     671      m_acTEncDepthTopList[iViewIdx]->create();
     672    }
     673#if HHI_INTER_VIEW_MOTION_PRED
     674    else if( m_uiMultiviewMvRegMode )
    493675    {
    494676      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->open( m_pchDepthInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
    495677      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth, m_iSourceHeight);
    496 
    497       m_acTVideoIOYuvDepthReconFileList[iViewIdx]->open( m_pchDepthReconFileList[iViewIdx],     true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
    498 
    499       // Neo Decoder
    500       m_acTEncDepthTopList[iViewIdx]->create();
    501     }
    502 #if HHI_INTER_VIEW_MOTION_PRED
    503     else if( m_uiMultiviewMvRegMode )
    504     {
    505       m_acTVideoIOYuvDepthInputFileList[iViewIdx]->open( m_pchDepthInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
    506       m_acTVideoIOYuvDepthInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth, m_iSourceHeight);
    507     }
    508 #endif
    509   }
    510 
    511 #if HHI_VSO
    512   for(Int iViewIdx=0; iViewIdx < m_iNumberOfExternalRefs; iViewIdx++)
    513   {
    514     m_acTVideoIOYuvERFileList[iViewIdx]->open( m_pchERRefFileList[iViewIdx], false, m_uiInputBitDepth, m_uiInternalBitDepth ); // read mode
    515   }
    516 #endif
     678    }
     679#endif
     680  }
    517681}
    518682
    519683Void TAppEncTop::xDestroyLib()
    520684{
    521 
    522   m_cTVideoIOBitsFile.closeBits();
    523 
    524 #if HHI_VSO
    525   for ( Int iViewIdx = 0; iViewIdx < m_iNumberOfExternalRefs; iViewIdx++ )
    526   {
    527     m_acTVideoIOYuvERFileList[iViewIdx]->close();
    528     delete m_acTVideoIOYuvERFileList[iViewIdx];
    529     m_acTVideoIOYuvERFileList[iViewIdx] = 0;
    530   };
    531 #endif
    532 
     685  // Video I/O
    533686  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
    534687  {
    535688    m_acTVideoIOYuvInputFileList[iViewIdx]->close();
    536689    m_acTVideoIOYuvReconFileList[iViewIdx]->close();
    537 
    538     delete m_acTVideoIOYuvInputFileList[iViewIdx] ; m_acTVideoIOYuvInputFileList[iViewIdx] = NULL;
    539     delete m_acTVideoIOYuvReconFileList[iViewIdx] ; m_acTVideoIOYuvReconFileList[iViewIdx] = NULL;
    540 
    541     delete m_cListPicYuvRecList[iViewIdx] ; m_cListPicYuvRecList[iViewIdx] = NULL;
    542 
     690    delete m_acTVideoIOYuvInputFileList[iViewIdx] ;
     691    m_acTVideoIOYuvInputFileList[iViewIdx] = NULL;
     692    delete m_acTVideoIOYuvReconFileList[iViewIdx] ;
     693    m_acTVideoIOYuvReconFileList[iViewIdx] = NULL;
     694    m_acTEncTopList[iViewIdx]->deletePicBuffer();
    543695    m_acTEncTopList[iViewIdx]->destroy();
    544     delete m_acTEncTopList[iViewIdx] ; m_acTEncTopList[iViewIdx] = NULL;
     696    delete m_acTEncTopList[iViewIdx] ;
     697    m_acTEncTopList[iViewIdx] = NULL;
     698    delete m_picYuvRec[iViewIdx] ;
     699    m_picYuvRec[iViewIdx] = NULL;
    545700
    546701    if( iViewIdx < Int( m_acTVideoIOYuvDepthInputFileList.size() ) && m_acTVideoIOYuvDepthInputFileList[iViewIdx] )
    547702    {
    548703      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->close( );
    549       delete m_acTVideoIOYuvDepthInputFileList[iViewIdx] ;
     704      delete m_acTVideoIOYuvDepthInputFileList[iViewIdx];
     705      m_acTVideoIOYuvDepthInputFileList[iViewIdx] = NULL;
    550706    }
    551707    if( iViewIdx < Int( m_acTVideoIOYuvDepthReconFileList.size() ) && m_acTVideoIOYuvDepthReconFileList[iViewIdx] )
     
    553709      m_acTVideoIOYuvDepthReconFileList[iViewIdx]->close () ;
    554710      delete m_acTVideoIOYuvDepthReconFileList[iViewIdx];
     711      m_acTVideoIOYuvDepthReconFileList[iViewIdx] = NULL;
    555712    }
    556713    if( iViewIdx < Int( m_acTEncDepthTopList.size() ) && m_acTEncDepthTopList[iViewIdx] )
    557714    {
     715      m_acTEncDepthTopList[iViewIdx]->deletePicBuffer();
    558716      m_acTEncDepthTopList[iViewIdx]->destroy();
    559717      delete m_acTEncDepthTopList[iViewIdx];
    560     }
    561     if( iViewIdx < Int( m_cListPicYuvDepthRecList.size() ) && m_cListPicYuvDepthRecList[iViewIdx] )
    562     {
    563       delete m_cListPicYuvDepthRecList[iViewIdx ];
     718      m_acTEncDepthTopList[iViewIdx] = NULL;
     719    }
     720    if( iViewIdx < Int( m_picYuvDepthRec.size() ) && m_picYuvDepthRec[iViewIdx] )
     721    {
     722      delete m_picYuvDepthRec[iViewIdx] ;
     723      m_picYuvDepthRec[iViewIdx] = NULL;
    564724    }
    565725  }
     
    601761 .
    602762 */
    603 //GT PRE LOAD ENC BUFFER
    604763Void TAppEncTop::encode()
    605764{
    606   TComPicYuv*       pcPicYuvOrg      = new TComPicYuv;
     765  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
     766  if (!bitstreamFile)
     767  {
     768    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
     769    exit(EXIT_FAILURE);
     770  }
     771
     772  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
    607773  TComPicYuv*       pcDepthPicYuvOrg = new TComPicYuv;
    608774  TComPicYuv*       pcPdmDepthOrg    = new TComPicYuv;
    609   TComPicYuv*       pcPicYuvRec      = NULL;
    610   //TComPicYuv*       pcDepthPicYuvRec = NULL;
    611 
     775  TComPicYuv*       pcPicYuvRec = NULL;
     776  TComPicYuv*       pcDepthPicYuvRec = NULL;
     777 
    612778  // initialize internal class & member variables
    613779  xInitLibCfg();
    614780  xCreateLib();
    615781  xInitLib();
    616 
     782 
    617783  // main encoder loop
    618 
    619   //GT: setup and init Bools for Eos and Continue Reading
    620   Bool  bAllEos = false;
    621   Bool  bAllContinueReadingPics = false;
    622   std::vector<Bool>  bEos ;
    623   std::vector<Bool>  bContinueReadingPics ;
    624 
    625   Bool  bAllDepthEos = false;
    626   Bool  bAllContinueReadingDepthPics = false;
    627   std::vector<Bool>  bDepthEos ;
    628   std::vector<Bool>  bContinueReadingDepthPics ;
     784  Bool  allEos = false;
     785  std::vector<Bool>  eos ;
     786  std::vector<Bool>  depthEos ;
     787  Int maxGopSize = 0;
     788  Int gopSize = 1;
     789 
     790  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
     791  maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize());   
     792
    629793  for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
    630794  {
    631     bEos.push_back( false ) ;
    632     bContinueReadingPics.push_back( true );
    633     if( m_bUsingDepthMaps)
    634     {
    635       bDepthEos.push_back( false ) ;
    636       bContinueReadingDepthPics.push_back( true ) ;
    637     }
    638   }
     795    eos.push_back( false );
     796    depthEos.push_back( false );
     797  }
     798
    639799  // allocate original YUV buffer
    640800  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    641   if( m_bUsingDepthMaps)
    642   {
    643     pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    644   }
     801  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
     802
    645803#if HHI_INTER_VIEW_MOTION_PRED
    646804  if( m_uiMultiviewMvRegMode )
     
    650808#endif
    651809
    652   TComBitstream*    pcBitstream = new TComBitstream;
    653   pcBitstream->create( (m_iSourceWidth * m_iSourceHeight * 3) >> 1 ) ; //GT: is size reasonable ??
    654 
    655   while ( !(bAllEos&& bAllContinueReadingPics) )
    656   {
    657     bAllContinueReadingPics = false;
    658     bAllContinueReadingDepthPics = false;
    659 
    660     //GT: Read all Buffers
    661     for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ ) //GT; store frames first
    662     {
    663       if (!bEos[iViewIdx] && bContinueReadingPics[iViewIdx] ) //GT: read frames to buffer
     810  while ( !allEos )
     811  {
     812    for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
     813    {
     814      Int frmCnt = 0;
     815      while ( !eos[iViewIdx] && !(frmCnt == gopSize))
    664816      {
    665817        // get buffers
    666         xGetBuffer( pcPicYuvRec, iViewIdx, m_cListPicYuvRecList ); // ringbuffer of size gopsize -> m_cListPicYuvRec, m_cListBitstream
     818        xGetBuffer(pcPicYuvRec, iViewIdx, false);
     819
    667820        // read input YUV file
    668         m_acTVideoIOYuvInputFileList[iViewIdx]->read( pcPicYuvOrg, m_aiPad  ) ;
    669         bEos[iViewIdx] = ( m_acTVideoIOYuvInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );             //GT: End of File
    670         bEos[iViewIdx] = ( m_iFrameRcvdVector[iViewIdx] == (m_iFrameToBeEncoded - 1) ?    true : bEos[iViewIdx]   );   //GT: FramesToBeEncoded Reached
    671         bAllEos = bAllEos|bEos[iViewIdx] ;
    672 
     821        m_acTVideoIOYuvInputFileList[iViewIdx]->read( pcPicYuvOrg, m_aiPad );
     822     
    673823#if HHI_INTER_VIEW_MOTION_PRED
    674824        if( m_uiMultiviewMvRegMode && iViewIdx )
     
    678828#endif
    679829
     830#if HHI_INTER_VIEW_MOTION_PRED
     831        m_acTEncTopList[iViewIdx]->initNewPic( pcPicYuvOrg, ( m_uiMultiviewMvRegMode && iViewIdx ? pcPdmDepthOrg : 0 ) );
     832#else
     833        m_acTEncTopList[iViewIdx]->initNewPic( pcPicYuvOrg );
     834#endif
     835
    680836        // increase number of received frames
    681         m_iFrameRcvdVector[iViewIdx]++ ;
    682       }
    683 
    684 #if HHI_INTER_VIEW_MOTION_PRED
    685       m_acTEncTopList[iViewIdx]->receivePic( bEos[iViewIdx],  pcPicYuvOrg, m_cListPicYuvRecList[iViewIdx]->back(), ( m_uiMultiviewMvRegMode && iViewIdx ? pcPdmDepthOrg : 0 ) );
    686 #else
    687       m_acTEncTopList[iViewIdx]->receivePic( bEos[iViewIdx],  pcPicYuvOrg, m_cListPicYuvRecList[iViewIdx]->back(), 0 );
    688 #endif
    689 
     837        m_frameRcvd[iViewIdx]++;
     838        frmCnt++;
     839        // check end of file
     840        eos[iViewIdx] = ( m_acTVideoIOYuvInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
     841        eos[iViewIdx] = ( m_frameRcvd[iViewIdx] == m_iFrameToBeEncoded ?    true : eos[iViewIdx]   );
     842        allEos = allEos|eos[iViewIdx] ;
     843      }
    690844      if( m_bUsingDepthMaps )
    691845      {
    692         if (!bDepthEos[iViewIdx] && bContinueReadingDepthPics[iViewIdx] )
     846        Int frmCntDepth = 0;
     847        while ( !depthEos[iViewIdx] && !(frmCntDepth == gopSize))
    693848        {
    694849          // get buffers
    695           xGetBuffer( pcPicYuvRec, iViewIdx, m_cListPicYuvDepthRecList ); // ringbuffer of size gopsize -> m_cListPicYuvRec, m_cListBitstream
     850          xGetBuffer(pcDepthPicYuvRec, iViewIdx, true);
     851
    696852          // read input YUV file
    697           m_acTVideoIOYuvDepthInputFileList[iViewIdx]->read( pcDepthPicYuvOrg, m_aiPad  ) ;
    698           bDepthEos[iViewIdx] = ( m_acTVideoIOYuvDepthInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
    699           bDepthEos[iViewIdx] = ( m_iDepthFrameRcvdVector[iViewIdx] == (m_iFrameToBeEncoded - 1) ?    true : bDepthEos[iViewIdx]  );
    700           bAllDepthEos = bAllDepthEos|bDepthEos[iViewIdx] ;
     853          m_acTVideoIOYuvDepthInputFileList[iViewIdx]->read( pcDepthPicYuvOrg, m_aiPad );
     854
     855          m_acTEncDepthTopList[iViewIdx]->initNewPic( pcDepthPicYuvOrg );
     856
    701857          // increase number of received frames
    702           m_iDepthFrameRcvdVector[iViewIdx]++ ;
     858          m_depthFrameRcvd[iViewIdx]++;
     859          frmCntDepth++;
     860          // check end of file
     861          depthEos[iViewIdx] = ( m_acTVideoIOYuvDepthInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
     862          depthEos[iViewIdx] = ( m_depthFrameRcvd[iViewIdx] == m_iFrameToBeEncoded ?    true : depthEos[iViewIdx]   );
     863          allEos = allEos|depthEos[iViewIdx] ;
    703864        }
    704         m_acTEncDepthTopList[iViewIdx]->receivePic( bDepthEos[iViewIdx],  pcDepthPicYuvOrg, m_cListPicYuvDepthRecList[iViewIdx]->back() );
    705       }
    706     }
    707 
    708     //===== store current POC =====
    709     Bool  bCurrPocCoded = m_acTEncTopList[ 0 ]->currentPocWillBeCoded();
    710     Int   iCurrPoc      = m_acTEncTopList[ 0 ]->getNextFrameId();
    711 
    712     //===== update camera parameters =====
    713     if( bCurrPocCoded )
    714     {
    715       m_cCameraData.update( (UInt)iCurrPoc );
    716     }
    717 
    718 #if HHI_VSO   
    719     if ( m_bUseVSO && ( m_uiVSOMode != 4) )
    720     {
    721       //GT: Read external reference pics or render references
    722       xStoreVSORefPicsInBuffer();       //GT;
    723     }
    724 #endif
    725 
    726 #if FLEX_CODING_ORDER
    727     if (m_b3DVFlexOrder)
    728     {
    729       Int i=0;
    730       Int iViewIdx = 0;
    731       bool bThisViewContinueReadingPics = false;
    732       bool bThisViewContinueReadingDepthPics = false;
    733       Int iNumberofDepthViews = m_bUsingDepthMaps?m_iNumberOfViews:0;
    734       for(Int j=0; j < (m_iNumberOfViews+ iNumberofDepthViews); j++ )     // Start encoding
    735       {
    736         if (m_pchMVCJointCodingOrder[i]=='T')
     865      }
     866    }
     867    for ( Int gopId=0; gopId < gopSize; gopId++ )
     868    {
     869      Int  iNumEncoded = 0;
     870      UInt iNextPoc = m_acTEncTopList[0] -> getFrameId( gopId );
     871      if ( iNextPoc < m_iFrameToBeEncoded )
     872      {
     873      m_cCameraData.update( iNextPoc );
     874      }
     875      for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
     876      {
     877        iNumEncoded = 0;
     878        // call encoding function for one frame
     879        m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
     880        xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, iViewIdx, false);
     881        outputAccessUnits.clear();
     882        if( m_bUsingDepthMaps )
    737883        {
    738           i++;
    739           assert(isdigit(m_pchMVCJointCodingOrder[i]));
    740           iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
    741           bThisViewContinueReadingPics = bContinueReadingPics[iViewIdx];
    742           m_acTEncTopList[iViewIdx]->encode( bEos[iViewIdx], m_cListPicYuvRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingPics );
    743           bContinueReadingPics[iViewIdx]=bThisViewContinueReadingPics;
    744           bAllContinueReadingPics = bAllContinueReadingPics||bContinueReadingPics[iViewIdx];
    745 
    746           if(pcBitstream->getNumberOfWrittenBits()!=0)
    747           {
    748             m_cTVideoIOBitsFile.writeBits( pcBitstream );
    749           }
    750           pcBitstream->resetBits(); //GT: also done later in ....
    751           pcBitstream->rewindStreamPacket( );
    752           // write bistream to file if necessary
    753           xWriteOutput( iViewIdx ); //GT: Write Reconfiles (when gop is complete?)
    754           i++;
     884          Int  iNumDepthEncoded = 0;
     885          // call encoding function for one depth frame
     886          m_acTEncDepthTopList[iViewIdx]->encode( depthEos[iViewIdx], pcDepthPicYuvOrg, *m_picYuvDepthRec[iViewIdx], outputAccessUnits, iNumDepthEncoded, gopId );
     887          xWriteOutput(bitstreamFile, iNumDepthEncoded, outputAccessUnits, iViewIdx, true);
     888          outputAccessUnits.clear();
    755889        }
    756         else if ( m_pchMVCJointCodingOrder[i] == 'D')
    757         {
    758           i++;
    759           if( m_bUsingDepthMaps )
    760           {
    761             assert(isdigit(m_pchMVCJointCodingOrder[i]));
    762             iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
    763             bThisViewContinueReadingDepthPics = bContinueReadingDepthPics[iViewIdx];
    764             m_acTEncDepthTopList[iViewIdx]->encode( bDepthEos[iViewIdx], m_cListPicYuvDepthRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingDepthPics );
    765             bContinueReadingDepthPics[iViewIdx]=bThisViewContinueReadingDepthPics;
    766 
    767             bAllContinueReadingDepthPics = bAllContinueReadingDepthPics||bContinueReadingDepthPics[iViewIdx];
    768             if(pcBitstream->getNumberOfWrittenBits()!=0)
    769             {
    770               m_cTVideoIOBitsFile.writeBits( pcBitstream );
    771             }
    772             pcBitstream->resetBits();
    773             pcBitstream->rewindStreamPacket( );
    774             // write bistream to file if necessary
    775             xWriteOutput( iViewIdx, true );
    776             i++;
    777           }
    778         }
    779       }
    780     }
    781     else
    782     {
    783 #endif
    784     //GT: Encode
    785     for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )     // Start encoding
    786     {
    787       bool bThisViewContinueReadingPics = bContinueReadingPics[iViewIdx];
    788       m_acTEncTopList[iViewIdx]->encode( bEos[iViewIdx], m_cListPicYuvRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingPics );
    789       bContinueReadingPics[iViewIdx]=bThisViewContinueReadingPics;
    790       bAllContinueReadingPics = bAllContinueReadingPics||bContinueReadingPics[iViewIdx];
    791 
    792       if(pcBitstream->getNumberOfWrittenBits()!=0)
    793       {
    794         m_cTVideoIOBitsFile.writeBits( pcBitstream );
    795       }
    796       pcBitstream->resetBits(); //GT: also done later in ....
    797       pcBitstream->rewindStreamPacket( );
    798       // write bistream to file if necessary
    799       xWriteOutput( iViewIdx ); //GT: Write Reconfiles (when gop is complete?)
    800 
    801       if( m_bUsingDepthMaps )
    802       {
    803         bool bThisViewContinueReadingDepthPics = bContinueReadingDepthPics[iViewIdx];
    804         m_acTEncDepthTopList[iViewIdx]->encode( bDepthEos[iViewIdx], m_cListPicYuvDepthRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingDepthPics );
    805         bContinueReadingDepthPics[iViewIdx]=bThisViewContinueReadingDepthPics;
    806 
    807         bAllContinueReadingDepthPics = bAllContinueReadingDepthPics||bContinueReadingDepthPics[iViewIdx];
    808         if(pcBitstream->getNumberOfWrittenBits()!=0)
    809         {
    810           m_cTVideoIOBitsFile.writeBits( pcBitstream );
    811         }
    812         pcBitstream->resetBits();
    813         pcBitstream->rewindStreamPacket( );
    814         // write bistream to file if necessary
    815         xWriteOutput( iViewIdx, true );
    816       }
    817     }
    818 #if FLEX_CODING_ORDER
    819         }
    820 #endif
    821     // delete extra picture buffers
    822     if( bCurrPocCoded )
    823     {
     890      }
     891#if HHI_INTERVIEW_SKIP || HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED
    824892      for( Int iViewIdx = 0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
    825893      {
    826894        if( iViewIdx < (Int)m_acTEncTopList.size() && m_acTEncTopList[iViewIdx] )
    827895        {
    828           m_acTEncTopList[iViewIdx]->deleteExtraPicBuffers( iCurrPoc );
     896          m_acTEncTopList[iViewIdx]->deleteExtraPicBuffers( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
    829897        }
    830898        if( iViewIdx < (Int)m_acTEncDepthTopList.size() && m_acTEncDepthTopList[iViewIdx] )
    831899        {
    832           m_acTEncDepthTopList[iViewIdx]->deleteExtraPicBuffers( iCurrPoc );
     900          m_acTEncDepthTopList[iViewIdx]->deleteExtraPicBuffers( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
    833901        }
    834902      }
    835     }
    836 
    837 #if AMVP_BUFFERCOMPRESS
    838     // compress motion for entire access
    839     if( bCurrPocCoded )
    840     {
    841       for( Int iViewIdx = 0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
    842       {
    843         if( iViewIdx < (Int)m_acTEncTopList.size() && m_acTEncTopList[iViewIdx] )
     903#endif
     904      for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
     905      {
     906        m_acTEncTopList[iViewIdx]->compressMotion( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
     907        if( m_bUsingDepthMaps )
    844908        {
    845           m_acTEncTopList[iViewIdx]->compressMotion( iCurrPoc );
     909          m_acTEncDepthTopList[iViewIdx]->compressMotion( m_acTEncDepthTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
    846910        }
    847         if( iViewIdx < (Int)m_acTEncDepthTopList.size() && m_acTEncDepthTopList[iViewIdx] )
    848         {
    849           m_acTEncDepthTopList[iViewIdx]->compressMotion( iCurrPoc );
    850         }
    851       }
    852     }
    853 #endif
    854   }
    855 
    856   // write output
    857   for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
    858   {
    859     m_acTEncTopList[iViewIdx]->printOutSummary(m_acTEncTopList[iViewIdx]->getNumAllPicCoded());
    860     if ( m_bUsingDepthMaps )
    861     {
    862       m_acTEncDepthTopList[iViewIdx]->printOutSummary(m_acTEncDepthTopList[iViewIdx]->getNumAllPicCoded());
    863     }
    864   }
    865 
     911      }
     912    }
     913    gopSize = maxGopSize;
     914  }
    866915  // delete original YUV buffer
    867916  pcPicYuvOrg->destroy();
    868917  delete pcPicYuvOrg;
    869918  pcPicYuvOrg = NULL;
    870 
    871   // valgrind
    872   if( m_bUsingDepthMaps)
    873   {
    874     pcDepthPicYuvOrg->destroy();
    875   }
    876   delete pcDepthPicYuvOrg ;
    877   pcDepthPicYuvOrg = NULL ;
    878 
    879   pcBitstream->destroy();
    880   delete pcBitstream;
    881   pcBitstream = NULL ;
    882 
    883 
    884   // delete used buffers in encoder class
    885   for(Int iViewIdx =0; iViewIdx < m_iNumberOfViews; iViewIdx++)
    886   {
    887     m_acTEncTopList[iViewIdx]->deletePicBuffer() ;
    888   }
    889 
    890   if( m_bUsingDepthMaps)
    891   {
    892     for(Int iViewIdx =0; iViewIdx < m_iNumberOfViews; iViewIdx++)
    893     {
    894       m_acTEncDepthTopList[iViewIdx]->deletePicBuffer() ;
    895     }
    896   }
    897 
    898   if ( pcPdmDepthOrg )
    899   {
    900     pcPdmDepthOrg->destroy();
    901     delete pcPdmDepthOrg;
    902     pcPdmDepthOrg = NULL;
     919  pcDepthPicYuvOrg->destroy();
     920  delete pcDepthPicYuvOrg;
     921  pcDepthPicYuvOrg = NULL;
     922 
     923  for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
     924  {
     925    m_acTEncTopList[iViewIdx]->printOutSummary(m_acTEncTopList[iViewIdx]->getNumAllPicCoded());
     926    if ( m_bUsingDepthMaps )
     927    {
     928      m_acTEncDepthTopList[iViewIdx]->printOutSummary(m_acTEncDepthTopList[iViewIdx]->getNumAllPicCoded());
     929    }
    903930  }
    904931
     
    906933  xDeleteBuffer();
    907934  xDestroyLib();
    908 }
     935
     936  return;
     937}
     938
     939TEncTop*  TAppEncTop::getTEncTop( Int viewId, Bool isDepth )   
     940{
     941  if ( isDepth ) 
     942  {
     943    return m_acTEncDepthTopList[viewId];
     944  }
     945  else
     946  {
     947    return m_acTEncTopList[viewId];
     948  }
     949}
     950
    909951
    910952// ====================================================================================================================
     
    918960 .
    919961 */
    920 Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, Int iViewIdx, std::vector< TComList<TComPicYuv*>*>& racBuffer )
    921 {
    922   if ( m_uiCodedPictureStoreSize   == 0 )
    923     {
    924       if (racBuffer[iViewIdx]->size() == 0)
    925       {
    926         rpcPicYuvRec = new TComPicYuv;
    927         rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    928 
    929         racBuffer[iViewIdx]->pushBack( rpcPicYuvRec );
    930       }
    931       rpcPicYuvRec = racBuffer[iViewIdx]->popFront(); //GT why? only one in list ?? A: only to get rpcPicYuvRec
    932       racBuffer[iViewIdx]->pushBack( rpcPicYuvRec );
    933       return;
    934     }
    935 
    936     // org. buffer
    937   if ( racBuffer[iViewIdx]->size() == (UInt)m_uiCodedPictureStoreSize )
    938     {
    939       rpcPicYuvRec = racBuffer[iViewIdx]->popFront();
     962Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, Int iViewIdx, Bool isDepth)
     963{
     964  assert( m_iGOPSize > 0 );
     965 
     966  if( !isDepth )
     967  {
     968    if ( m_picYuvRec[iViewIdx]->size() == (UInt)m_iGOPSize )
     969    {
     970      rpcPicYuvRec = m_picYuvRec[iViewIdx]->popFront();
    940971    }
    941972    else
    942973    {
    943       rpcPicYuvRec = new TComPicYuv;
     974      rpcPicYuvRec = new TComPicYuv; 
    944975      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    945976    }
    946     racBuffer[iViewIdx]->pushBack( rpcPicYuvRec );
     977    m_picYuvRec[iViewIdx]->pushBack( rpcPicYuvRec );
     978  }
     979  else
     980  {
     981    if ( m_picYuvDepthRec[iViewIdx]->size() == (UInt)m_iGOPSize )
     982    {
     983      rpcPicYuvRec = m_picYuvDepthRec[iViewIdx]->popFront();
     984    }
     985    else
     986    {
     987      rpcPicYuvRec = new TComPicYuv;
     988      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
     989    }
     990    m_picYuvDepthRec[iViewIdx]->pushBack( rpcPicYuvRec );
     991  }
    947992}
    948993
    949994Void TAppEncTop::xDeleteBuffer( )
    950995{
    951   TComList<TComBitstream*>::iterator iterBitstream = m_cListBitstream.begin();
    952 
    953   Int iSize = Int( m_cListBitstream.size() );
    954 
    955   for ( Int i = 0; i < iSize; i++ )
    956   {
    957     TComBitstream* pcBitstream = *(iterBitstream++);
    958 
    959     pcBitstream->destroy();
    960 
    961     delete pcBitstream; pcBitstream = NULL;
    962   }
    963 
    964   for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
    965   {
    966     TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRecList[iViewIdx]->begin();
    967 
    968     iSize = Int( m_cListPicYuvRecList[iViewIdx]->size() );
    969 
    970     for ( Int i = 0; i < iSize; i++ )
    971     {
     996  for(Int iViewIdx=0; iViewIdx<m_picYuvRec.size(); iViewIdx++)
     997  {
     998    if(m_picYuvRec[iViewIdx])
     999    {
     1000      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvRec[iViewIdx]->begin();
     1001      Int iSize = Int( m_picYuvRec[iViewIdx]->size() );
     1002      for ( Int i = 0; i < iSize; i++ )
     1003      {
    9721004        TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
    973         pcPicYuvRec->destroy();
    974         delete pcPicYuvRec; pcPicYuvRec = NULL;
    975     }
    976   }
    977   if( m_bUsingDepthMaps)
    978   {
    979     for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
    980     {
    981       TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvDepthRecList[iViewIdx]->begin();
    982 
    983       iSize = Int( m_cListPicYuvDepthRecList[iViewIdx]->size() );
    984 
     1005        if(pcPicYuvRec)
     1006        {
     1007          pcPicYuvRec->destroy();
     1008          delete pcPicYuvRec;
     1009          pcPicYuvRec = NULL;
     1010        }
     1011      }
     1012    }
     1013  }
     1014  for(Int iViewIdx=0; iViewIdx<m_picYuvDepthRec.size(); iViewIdx++)
     1015  {
     1016    if(m_picYuvDepthRec[iViewIdx])
     1017    {
     1018      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvDepthRec[iViewIdx]->begin();
     1019      Int iSize = Int( m_picYuvDepthRec[iViewIdx]->size() );
    9851020      for ( Int i = 0; i < iSize; i++ )
    9861021      {
    987           TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
     1022        TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
     1023        if(pcPicYuvRec)
     1024        {
    9881025          pcPicYuvRec->destroy();
    989           delete pcPicYuvRec; pcPicYuvRec = NULL;
    990       }
    991     }
    992   }
    993 
    994   // Delete ERFiles
    995 
    996 #if HHI_VSO
    997   std::map< Int,vector<TComPicYuv*> >::iterator iterMapPicExtRefView = m_cMapPicExtRefView.begin();
    998   while ( iterMapPicExtRefView != m_cMapPicExtRefView.end() )
    999   {
    1000     for ( UInt uiViewNumber = 0; uiViewNumber < iterMapPicExtRefView->second.size(); uiViewNumber++ )
    1001     {
    1002       if ( iterMapPicExtRefView->second[uiViewNumber] )
    1003       {
    1004         iterMapPicExtRefView->second[uiViewNumber]->destroy();
    1005         delete iterMapPicExtRefView->second[uiViewNumber];
    1006       }
    1007     }
    1008     iterMapPicExtRefView++;
    1009   }
    1010 #endif
     1026          delete pcPicYuvRec;
     1027          pcPicYuvRec = NULL;
     1028        }
     1029      }
     1030    }
     1031  }
    10111032}
    10121033
    10131034/** \param iNumEncoded  number of encoded frames
    10141035 */
    1015 Void TAppEncTop::xWriteOutput( Int iViewIdx, Bool isDepth )
    1016 {
    1017   std::map<PicOrderCnt, TComPicYuv*> &rcMap = ( isDepth ? m_cListPicYuvDepthRecMap          : m_cListPicYuvRecMap          )[iViewIdx];
    1018   PicOrderCnt  &riNextPocToDump             = ( isDepth ? m_aiNextDepthPocToDump            : m_aiNextPocToDump            )[iViewIdx];
    1019   TVideoIOYuv* &rpcTVideoIOYuvReconFile     = ( isDepth ? m_acTVideoIOYuvDepthReconFileList : m_acTVideoIOYuvReconFileList )[iViewIdx];
    1020   std::map<PicOrderCnt, TComPicYuv*>::iterator i;
    1021 
    1022   while( ! rcMap.empty() && ( i = rcMap.begin() )->first == riNextPocToDump )
    1023   {
    1024     riNextPocToDump++;
    1025     rpcTVideoIOYuvReconFile->write( i->second, m_aiPad );
    1026     rcMap.erase( i );
    1027   }
    1028 }
    1029 
    1030 // GT FIX
    1031 std::vector<TComPic*> TAppEncTop::getSpatialRefPics( Int iViewIdx, Int iPoc, Bool bIsDepthCoder )
    1032 {
    1033   std::vector<TComPic*> apcRefPics( iViewIdx, (TComPic*)NULL );
    1034   for( int iRefViewIdx = 0; iRefViewIdx < iViewIdx; iRefViewIdx++ )
    1035   {
    1036 // GT FIX
    1037     TComPic* pcRefPic = xGetPicFromView(iRefViewIdx, iPoc, bIsDepthCoder);
    1038 
    1039     assert( pcRefPic != NULL );
    1040     apcRefPics[iRefViewIdx] = pcRefPic;
    1041   }
    1042   return apcRefPics;
    1043 }
    1044 
    1045 
    1046 TComPic* TAppEncTop::xGetPicFromView( Int iViewIdx, Int iPoc, bool bDepth )
    1047 {
    1048   assert( ( iViewIdx >= 0) && ( iViewIdx < m_iNumberOfViews ) );
    1049 
    1050   TComPic* pcPic = 0;
    1051   TComList<TComPic*>* apcListPic;
    1052 
    1053   apcListPic = (bDepth ?  m_acTEncDepthTopList[iViewIdx] : m_acTEncTopList[iViewIdx])->getListPic() ;
    1054 
    1055   for(TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++)
    1056   {
    1057     if( (*it)->getPOC() == iPoc )
    1058     {
    1059       pcPic = *it ;
    1060       break ;
    1061     }
    1062   }
    1063 
    1064   return pcPic;
    1065 };
     1036Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, Int iViewIdx, Bool isDepth )
     1037{
     1038  Int i;
     1039 
     1040  if( iNumEncoded > 0 )
     1041  {
     1042    TComList<TComPicYuv*>::iterator iterPicYuvRec = !isDepth ? m_picYuvRec[iViewIdx]->end() : m_picYuvDepthRec[iViewIdx]->end();
     1043 
     1044    for ( i = 0; i < iNumEncoded; i++ )
     1045    {
     1046      --iterPicYuvRec;
     1047    }
     1048 
     1049    for ( i = 0; i < iNumEncoded; i++ )
     1050    {
     1051      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
     1052      if( !isDepth )
     1053      {
     1054        if (m_pchReconFileList[iViewIdx])
     1055        {
     1056#if PIC_CROPPING
     1057          m_acTVideoIOYuvReconFileList[iViewIdx]->write( pcPicYuvRec, m_cropLeft, m_cropRight, m_cropTop, m_cropBottom );
     1058#else
     1059          m_acTVideoIOYuvReconFileList[iViewIdx]->write( pcPicYuvRec, m_aiPad );
     1060#endif
     1061        }
     1062      }
     1063      else
     1064      {
     1065        if (m_pchDepthReconFileList[iViewIdx])
     1066        {
     1067#if PIC_CROPPING
     1068          m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write( pcPicYuvRec, m_cropLeft, m_cropRight, m_cropTop, m_cropBottom );
     1069#else
     1070          m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write( pcPicYuvRec, m_aiPad );
     1071#endif
     1072        }
     1073      }
     1074    }
     1075  }
     1076  if( ! accessUnits.empty() )
     1077  {
     1078    list<AccessUnit>::iterator aUIter;
     1079    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
     1080    {
     1081      const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter);
     1082      rateStatsAccum(*aUIter, stats);
     1083    }
     1084  }
     1085}
     1086
    10661087
    10671088TComPicYuv* TAppEncTop::xGetPicYuvFromView( Int iViewIdx, Int iPoc, Bool bDepth, Bool bRecon )
     
    10881109};
    10891110
    1090 #if HHI_VSO
    1091 Void TAppEncTop::xSetBasePicYuv( Int iViewIdx, Int iPoc, TComMVDRefData* pcRefInfo, InterViewReference eView, bool bDepth )
    1092 {
    1093 
    1094   if ( ( iViewIdx < 0) || ( iViewIdx >= m_iNumberOfViews ) )
    1095     return;
    1096 
    1097   if ( !m_bUsingDepthMaps && bDepth )
    1098     return;
    1099 
    1100   TComPic* pcPic = xGetPicFromView( iViewIdx, iPoc, bDepth);
    1101 
    1102   if (pcPic == 0)
    1103     return;
    1104 
    1105   pcRefInfo->setPicYuvBaseView(eView, bDepth, pcPic->getPicYuvOrg(),  pcPic->getReconMark() ? pcPic->getPicYuvRec() : NULL );
    1106 
    1107 };
    1108 
    1109 Void TAppEncTop::setMVDPic( Int iViewIdx, Int iPoc, TComMVDRefData* pcMVDRefData )
    1110 {
    1111   AOF( iViewIdx >= 0);
    1112   AOF( iViewIdx <  m_iNumberOfViews  );
    1113 
    1114   xSetBasePicYuv(iViewIdx - 1, iPoc, pcMVDRefData, PREVVIEW, false);
    1115   xSetBasePicYuv(iViewIdx    , iPoc, pcMVDRefData, CURRVIEW, false );
    1116   xSetBasePicYuv(iViewIdx + 1, iPoc, pcMVDRefData, NEXTVIEW, false );
    1117 
    1118   if ( m_bUsingDepthMaps )
    1119   {
    1120     xSetBasePicYuv(iViewIdx - 1, iPoc, pcMVDRefData, PREVVIEW, true );
    1121     xSetBasePicYuv(iViewIdx    , iPoc, pcMVDRefData, CURRVIEW, true );
    1122     xSetBasePicYuv(iViewIdx + 1, iPoc, pcMVDRefData, NEXTVIEW, true );
    1123   }
    1124 
    1125 
    1126   xSetBaseLUT       (iViewIdx, iViewIdx-1  , pcMVDRefData, PREVVIEW );
    1127   xSetBaseLUT       (iViewIdx, iViewIdx+1  , pcMVDRefData, NEXTVIEW );
    1128 
    1129 
    1130   if ( m_bUseVSO && m_uiVSOMode != 4)
    1131   {
    1132     xSetERPicYuvs               (iViewIdx, iPoc, pcMVDRefData);
    1133     pcMVDRefData->setShiftLUTsERView(m_cCameraData.getSynthViewShiftLUTD()[iViewIdx],  m_cCameraData.getSynthViewShiftLUTI()[iViewIdx] );
    1134     pcMVDRefData->setRefViewInd     (m_aaiBaseViewRefInd[iViewIdx], m_aaiERViewRefInd[iViewIdx], m_aaiERViewRefLutInd[iViewIdx]);
    1135   }
    1136 };
    1137 
    1138 
    1139 Void TAppEncTop::xSetBaseLUT( Int iViewIdxSource, Int iViewIdxTarget, TComMVDRefData* pcRefInfo, InterViewReference eView )
    1140 {
    1141   if ( ( iViewIdxSource < 0) || ( iViewIdxSource >= m_iNumberOfViews )||( iViewIdxTarget < 0) || ( iViewIdxTarget >= m_iNumberOfViews ) )
    1142     return;
    1143   assert( abs( iViewIdxTarget - iViewIdxSource ) <= 1 );  //GT; Not supported yet
    1144   pcRefInfo->setShiftLUTsBaseView(eView, m_cCameraData.getBaseViewShiftLUTD()[iViewIdxSource][iViewIdxTarget],m_cCameraData.getBaseViewShiftLUTI()[iViewIdxSource][iViewIdxTarget] );
    1145 };
    1146 
    1147 Void TAppEncTop::xSetERPicYuvs( Int iViewIdx, Int iPoc, TComMVDRefData* pcReferenceInfo )
    1148 {
    1149   std::vector<TComPicYuv*> apcExtRefViews;
    1150 
    1151   std::map< Int, vector<TComPicYuv*> >::iterator cMapIt;
    1152   cMapIt = m_cMapPicExtRefView.find(iPoc);
    1153 
    1154   assert(  cMapIt != m_cMapPicExtRefView.end() );
    1155 
    1156   pcReferenceInfo->setPicYuvERViews( cMapIt->second );
    1157 }
    1158 
    1159 Void TAppEncTop::xStoreVSORefPicsInBuffer()
    1160 {
    1161   // X-Check if all Encoders have received the same number of pics
    1162   Int iNumRcvd = m_iFrameRcvdVector[0];
    1163   for ( UInt uiViewNumber = 0; uiViewNumber < m_iNumberOfViews; uiViewNumber ++ )
    1164   {
    1165     assert( ( m_iFrameRcvdVector[uiViewNumber] == iNumRcvd ) && ( m_iDepthFrameRcvdVector[uiViewNumber] == iNumRcvd ) ); //GT; if assert here, the encoder instances are not synchronized any more, re-think this function and the ERView Buffer!!
    1166   };
    1167 
    1168   Int iCurPoc = iNumRcvd - 1;
    1169 
    1170   if ( iCurPoc <= m_iLastFramePutInERViewBuffer )
    1171   {
    1172     return;
    1173   }
    1174 
    1175   std::vector<TComPicYuv*> apcExtRefViewVec;
    1176 
    1177   Int iNumberOfReferenceViews = 0;
    1178   if (m_iNumberOfExternalRefs != 0)
    1179   {
    1180     m_aaiERViewRefLutInd = m_aaiERViewRefInd;
    1181     // Insert Rendered Views form File
    1182 
    1183     iNumberOfReferenceViews = m_iNumberOfExternalRefs;
    1184 
    1185     for ( UInt uiViewNumber = 0; uiViewNumber < iNumberOfReferenceViews; uiViewNumber++ )
    1186     {
    1187       TComPicYuv* pcPicYuvERView = new TComPicYuv;
    1188       pcPicYuvERView->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    1189 
    1190       m_acTVideoIOYuvERFileList[uiViewNumber]->read( pcPicYuvERView, m_aiPad  ) ;
    1191 
    1192       apcExtRefViewVec.push_back( pcPicYuvERView );
    1193     }
    1194   }
    1195   else
    1196   { //Render Views
    1197 
    1198     for ( UInt uiViewNumber = 0; uiViewNumber < m_iNumberOfViews; uiViewNumber++ )
    1199     {
    1200       m_aaiERViewRefInd   [uiViewNumber].clear();
    1201       m_aaiERViewRefLutInd[uiViewNumber].clear();
    1202     }
    1203 
    1204     iNumberOfReferenceViews = 0;
    1205     for ( UInt iSynthViewIdx = 0; iSynthViewIdx < m_cCameraData.getSynthViewNumbers().size(); iSynthViewIdx++ )
    1206     {
    1207       // Get Left and right view
    1208       Int  iLeftViewIdx  = -1;
    1209       Int  iRightViewIdx = -1;
    1210       Bool bIsBaseView;
    1211 
    1212       Int iRelDistToLeft;
    1213       m_cCameraData.getLeftRightBaseView( iSynthViewIdx, iLeftViewIdx, iRightViewIdx, iRelDistToLeft, bIsBaseView );
    1214 
    1215       if  ((iLeftViewIdx == -1) || (iRightViewIdx == -1))
    1216       {
    1217         std::cerr << "Left or right View not given." << endl;
    1218         exit(EXIT_FAILURE);
    1219       }
    1220 
    1221       m_cRendererTop.setShiftLUTs(
    1222         m_cCameraData.getSynthViewShiftLUTD()[iLeftViewIdx] [iSynthViewIdx],
    1223         m_cCameraData.getSynthViewShiftLUTI()[iLeftViewIdx] [iSynthViewIdx],
    1224         m_cCameraData.getBaseViewShiftLUTI ()[iLeftViewIdx] [iRightViewIdx],
    1225         m_cCameraData.getSynthViewShiftLUTD()[iRightViewIdx][iSynthViewIdx],
    1226         m_cCameraData.getSynthViewShiftLUTI()[iRightViewIdx][iSynthViewIdx],
    1227         m_cCameraData.getBaseViewShiftLUTI ()[iRightViewIdx][iLeftViewIdx],
    1228         iRelDistToLeft
    1229       );
    1230       if ( bIsBaseView ) continue;
    1231 
    1232       // Render from left
    1233       TComPicYuv* pcPicYuvERView = new TComPicYuv;
    1234       pcPicYuvERView->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    1235       m_cRendererTop.extrapolateView( xGetPicFromView( iLeftViewIdx, iCurPoc, false )->getPicYuvOrg(), xGetPicFromView( iLeftViewIdx, iCurPoc, true )->getPicYuvOrg(), pcPicYuvERView, true );
    1236 
    1237       apcExtRefViewVec.push_back( pcPicYuvERView );
    1238 
    1239       m_aaiERViewRefInd   [ iLeftViewIdx].push_back( iNumberOfReferenceViews );
    1240       m_aaiERViewRefLutInd[ iLeftViewIdx].push_back( iSynthViewIdx );
    1241       iNumberOfReferenceViews++;
    1242 
    1243       //Render from right
    1244       pcPicYuvERView = new TComPicYuv;
    1245       pcPicYuvERView->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    1246 
    1247       m_cRendererTop.extrapolateView( xGetPicFromView( iRightViewIdx, iCurPoc, false )->getPicYuvOrg(), xGetPicFromView( iRightViewIdx, iCurPoc, true )->getPicYuvOrg(), pcPicYuvERView, false );
    1248       apcExtRefViewVec.push_back( pcPicYuvERView );
    1249 
    1250       m_aaiERViewRefInd   [ iRightViewIdx].push_back( iNumberOfReferenceViews );
    1251       m_aaiERViewRefLutInd[ iRightViewIdx].push_back( iSynthViewIdx );
    1252       iNumberOfReferenceViews++;
    1253     }
    1254   }
    1255 
    1256   m_iLastFramePutInERViewBuffer++;
    1257   m_cMapPicExtRefView.insert( std::make_pair( m_iLastFramePutInERViewBuffer, apcExtRefViewVec ) );
    1258 
    1259   if ( m_cMapPicExtRefView.size() >  (UInt)m_iGOPSize + 1 )
    1260   {
    1261     for ( UInt uiViewNumber = 0; uiViewNumber < (UInt) m_cMapPicExtRefView.begin()->second.size(); uiViewNumber++ )
    1262     {
    1263       if ( m_cMapPicExtRefView.begin()->second[uiViewNumber] )
    1264       {
    1265         m_cMapPicExtRefView.begin()->second[uiViewNumber]->destroy();
    1266         delete m_cMapPicExtRefView.begin()->second[uiViewNumber];
    1267       }
    1268     }
    1269     m_cMapPicExtRefView.erase ( m_cMapPicExtRefView.begin() );
    1270   }
    1271 }
    1272 #endif
     1111/**
     1112 *
     1113 */
     1114void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<unsigned>& annexBsizes)
     1115{
     1116  AccessUnit::const_iterator it_au = au.begin();
     1117  vector<unsigned>::const_iterator it_stats = annexBsizes.begin();
     1118
     1119  for (; it_au != au.end(); it_au++, it_stats++)
     1120  {
     1121    switch ((*it_au)->m_nalUnitType)
     1122    {
     1123    case NAL_UNIT_CODED_SLICE:
     1124#if H0566_TLA
     1125    case NAL_UNIT_CODED_SLICE_IDV:
     1126    case NAL_UNIT_CODED_SLICE_TLA:
     1127    case NAL_UNIT_CODED_SLICE_CRA:
     1128#else
     1129    case NAL_UNIT_CODED_SLICE_DATAPART_A:
     1130    case NAL_UNIT_CODED_SLICE_DATAPART_B:
     1131    case NAL_UNIT_CODED_SLICE_CDR:
     1132#endif
     1133    case NAL_UNIT_CODED_SLICE_IDR:
     1134    case NAL_UNIT_SPS:
     1135    case NAL_UNIT_PPS:
     1136      m_essentialBytes += *it_stats;
     1137      break;
     1138    default:
     1139      break;
     1140    }
     1141
     1142    m_totalBytes += *it_stats;
     1143  }
     1144}
    12731145
    12741146#if HHI_INTERVIEW_SKIP
     
    12771149  AOT( iViewIdx <= 0);
    12781150  AOT( iViewIdx >= m_iNumberOfViews );
    1279   AOF( m_uiInterViewSkip != 0 );
    12801151  AOF( m_cCameraData.getCurFrameId() == iPoc );
    1281 
    12821152  Int iViewSIdx      = m_cCameraData.getBaseId2SortedId()[iViewIdx];
    12831153  Int iFirstViewSIdx = m_cCameraData.getBaseId2SortedId()[0];
     
    12871157  Bool bFirstIsLeft = (iFirstViewSIdx < iViewSIdx);
    12881158
    1289     m_cUsedPelsRenderer.setShiftLUTs(
     1159  m_cUsedPelsRenderer.setShiftLUTs(
    12901160      m_cCameraData.getBaseViewShiftLUTD()[0][iViewIdx],
    12911161      m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
     
    12971167      );
    12981168
    1299 
    13001169  TComPicYuv* pcPicYuvDepth = xGetPicYuvFromView(0, iPoc, true, true );
    13011170  AOF( pcPicYuvDepth);
    13021171
    13031172  m_cUsedPelsRenderer.getUsedSamplesMap( pcPicYuvDepth, pcPicYuvUsedSplsMap, bFirstIsLeft );
    1304 
    1305 }
    1306 #endif
    1307 
     1173}
     1174#endif
    13081175#if HHI_VSO
    13091176Void TAppEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent )
     
    14031270#endif
    14041271
     1272
     1273
     1274/*
     1275void TAppEncTop::printRateSummary()
     1276{
     1277  double time = (double) m_iFrameRcvd / m_iFrameRate;
     1278  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
     1279#if VERBOSE_RATE
     1280  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
     1281#endif
     1282}
     1283*/
     1284
     1285std::vector<TComPic*> TAppEncTop::getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps )
     1286{
     1287  std::vector<TComPic*> apcRefPics( sps->getNumberOfUsableInterViewRefs(), (TComPic*)NULL );
     1288  for( Int k = 0; k < sps->getNumberOfUsableInterViewRefs(); k++ )
     1289  {
     1290    TComPic* pcRefPic = xGetPicFromView( sps->getUsableInterViewRef( k ) + viewId, poc, isDepth );
     1291    assert( pcRefPic != NULL );
     1292    apcRefPics[k] = pcRefPic;
     1293  }
     1294  return apcRefPics;
     1295}
     1296
     1297TComPic* TAppEncTop::xGetPicFromView( Int viewIdx, Int poc, Bool isDepth )
     1298{
     1299  assert( ( viewIdx >= 0 ) && ( viewIdx < m_iNumberOfViews ) );
     1300
     1301  TComList<TComPic*>* apcListPic = (isDepth ?  m_acTEncDepthTopList[viewIdx] : m_acTEncTopList[viewIdx])->getListPic() ;
     1302
     1303  TComPic* pcPic = NULL;
     1304  for(TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++)
     1305  {
     1306    if( (*it)->getPOC() == poc )
     1307    {
     1308      pcPic = *it ;
     1309      break ;
     1310    }
     1311  }
     1312
     1313  return pcPic;
     1314};
     1315
     1316//! \}
Note: See TracChangeset for help on using the changeset viewer.