source: 3DVCSoftware/trunk/source/App/TAppEncoder/TAppEncTop.cpp @ 332

Last change on this file since 332 was 332, checked in by tech, 11 years ago

Merged branch 6.1-Cleanup@329.

  • Property svn:eol-style set to native
File size: 68.2 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2012, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TAppEncTop.cpp
35    \brief    Encoder application class
36*/
37
38#include <list>
39#include <fstream>
40#include <stdlib.h>
41#include <stdio.h>
42#include <fcntl.h>
43#include <assert.h>
44
45#include "TAppEncTop.h"
46#include "TLibEncoder/AnnexBwrite.h"
47
48using namespace std;
49
50//! \ingroup TAppEncoder
51//! \{
52
53// ====================================================================================================================
54// Constructor / destructor / initialization / destroy
55// ====================================================================================================================
56
57TAppEncTop::TAppEncTop()
58{
59  m_totalBytes = 0;
60  m_essentialBytes = 0;
61}
62
63TAppEncTop::~TAppEncTop()
64{
65}
66
67Void TAppEncTop::xInitLibCfg()
68{
69#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
70#if !QC_MVHEVC_B0046
71  UInt layerId = 0;
72#endif
73  // TODO: fix the assumption here that the temporal structures are all equal across all layers???
74  m_cVPS.setMaxTLayers( m_maxTempLayer[0] );
75#if QC_MVHEVC_B0046
76  m_cVPS.setMaxLayers( m_iNumberOfViews );
77#else
78  m_cVPS.setMaxLayers( m_iNumberOfViews * (m_bUsingDepthMaps ? 2:1) );
79#endif
80  for(Int i = 0; i < MAX_TLAYER; i++)
81  {
82    m_cVPS.setNumReorderPics( m_numReorderPics[0][i], i );
83    m_cVPS.setMaxDecPicBuffering( m_maxDecPicBuffering[0][i], i );
84  }
85#endif
86 
87  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
88  {
89    m_frameRcvd.push_back(0);
90    m_acTEncTopList.push_back(new TEncTop); 
91    m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv);
92    m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
93    m_picYuvRec.push_back(new TComList<TComPicYuv*>) ;
94
95    m_acTEncTopList[iViewIdx]->setFrameRate                    ( m_iFrameRate );
96    m_acTEncTopList[iViewIdx]->setFrameSkip                    ( m_FrameSkip );
97    m_acTEncTopList[iViewIdx]->setSourceWidth                  ( m_iSourceWidth );
98    m_acTEncTopList[iViewIdx]->setSourceHeight                 ( m_iSourceHeight );
99    m_acTEncTopList[iViewIdx]->setCroppingMode                 ( m_croppingMode );
100    m_acTEncTopList[iViewIdx]->setCropLeft                     ( m_cropLeft );
101    m_acTEncTopList[iViewIdx]->setCropRight                    ( m_cropRight );
102    m_acTEncTopList[iViewIdx]->setCropTop                      ( m_cropTop );
103    m_acTEncTopList[iViewIdx]->setCropBottom                   ( m_cropBottom );
104    m_acTEncTopList[iViewIdx]->setFrameToBeEncoded             ( m_iFrameToBeEncoded );
105    m_acTEncTopList[iViewIdx]->setViewId                       ( iViewIdx );
106    m_acTEncTopList[iViewIdx]->setIsDepth                      ( false );
107#if QC_MVHEVC_B0046
108    m_acTEncTopList[iViewIdx]->setLayerId                      ( iViewIdx );
109    m_cVPS.setViewId                                           ( m_aiVId[ iViewIdx ], iViewIdx );
110#else
111    m_acTEncTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
112#if VIDYO_VPS_INTEGRATION
113    layerId = iViewIdx * (m_bUsingDepthMaps ? 2:1);
114    m_acTEncTopList[iViewIdx]->setLayerId                      ( layerId );
115    m_cVPS.setDepthFlag                                        ( false, layerId );
116    m_cVPS.setViewId                                           ( iViewIdx, layerId );
117    m_cVPS.setViewOrderIdx                                     ( m_cCameraData.getViewOrderIndex()[ iViewIdx ], layerId );
118    // TODO: set correct dependentFlag and dependentLayer
119    m_cVPS.setDependentFlag                                    ( iViewIdx ? true:false, layerId );
120    m_cVPS.setDependentLayer                                   ( layerId - (m_bUsingDepthMaps ? 2:1), layerId );
121#if INTER_VIEW_VECTOR_SCALING_C0115
122    m_cVPS.setIVScalingFlag                                    ( m_bUseIVS );
123#endif
124#endif
125   
126    m_acTEncTopList[iViewIdx]->setCamParPrecision              ( m_cCameraData.getCamParsCodedPrecision  () );
127    m_acTEncTopList[iViewIdx]->setCamParInSliceHeader          ( m_cCameraData.getVaryingCameraParameters() );
128    m_acTEncTopList[iViewIdx]->setCodedScale                   ( m_cCameraData.getCodedScale             () );
129    m_acTEncTopList[iViewIdx]->setCodedOffset                  ( m_cCameraData.getCodedOffset            () );
130#endif   
131
132  //====== Coding Structure ========
133    m_acTEncTopList[iViewIdx]->setIntraPeriod                  ( m_iIntraPeriod );
134    m_acTEncTopList[iViewIdx]->setDecodingRefreshType          ( m_iDecodingRefreshType );
135    m_acTEncTopList[iViewIdx]->setGOPSize                      ( m_iGOPSize );
136    m_acTEncTopList[iViewIdx]->setGopList                      ( m_GOPListsMvc[iViewIdx] );
137    m_acTEncTopList[iViewIdx]->setExtraRPSs                    ( m_extraRPSs[iViewIdx] );
138    for(Int i = 0; i < MAX_TLAYER; i++)
139    {
140      m_acTEncTopList[iViewIdx]->setNumReorderPics             ( m_numReorderPics[iViewIdx][i], i );
141      m_acTEncTopList[iViewIdx]->setMaxDecPicBuffering         ( m_maxDecPicBuffering[iViewIdx][i], i );
142    }
143    for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
144    {
145      m_acTEncTopList[iViewIdx]->setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
146    }
147    m_acTEncTopList[iViewIdx]->setQP                           ( m_aiQP[0] );
148 
149    m_acTEncTopList[iViewIdx]->setTemporalLayerQPOffset        ( m_aiTLayerQPOffset );
150    m_acTEncTopList[iViewIdx]->setPad                          ( m_aiPad );
151   
152    m_acTEncTopList[iViewIdx]->setMaxTempLayer                 ( m_maxTempLayer[iViewIdx] );
153
154    m_acTEncTopList[iViewIdx]->setDisInter4x4                  ( m_bDisInter4x4);
155 
156    m_acTEncTopList[iViewIdx]->setUseNSQT( m_enableNSQT );
157    m_acTEncTopList[iViewIdx]->setUseAMP( m_enableAMP );
158 
159  //===== Slice ========
160 
161  //====== Loop/Deblock Filter ========
162    m_acTEncTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[0]       );
163    m_acTEncTopList[iViewIdx]->setLoopFilterOffsetInAPS        ( m_loopFilterOffsetInAPS );
164    m_acTEncTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
165    m_acTEncTopList[iViewIdx]->setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
166    m_acTEncTopList[iViewIdx]->setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
167
168  //====== Motion search ========
169    m_acTEncTopList[iViewIdx]->setFastSearch                   ( m_iFastSearch  );
170    m_acTEncTopList[iViewIdx]->setSearchRange                  ( m_iSearchRange );
171    m_acTEncTopList[iViewIdx]->setBipredSearchRange            ( m_bipredSearchRange );
172#if DV_V_RESTRICTION_B0037
173    m_acTEncTopList[iViewIdx]->setUseDisparitySearchRangeRestriction ( m_bUseDisparitySearchRangeRestriction );
174    m_acTEncTopList[iViewIdx]->setVerticalDisparitySearchRange( m_iVerticalDisparitySearchRange );
175#endif
176  //====== Quality control ========
177    m_acTEncTopList[iViewIdx]->setMaxDeltaQP                   ( m_iMaxDeltaQP  );
178    m_acTEncTopList[iViewIdx]->setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
179
180    m_acTEncTopList[iViewIdx]->setChromaQpOffset               ( m_iChromaQpOffset     );
181    m_acTEncTopList[iViewIdx]->setChromaQpOffset2nd            ( m_iChromaQpOffset2nd  );
182
183#if ADAPTIVE_QP_SELECTION
184    m_acTEncTopList[iViewIdx]->setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
185#endif
186
187#if LOSSLESS_CODING
188    Int lowestQP;
189    lowestQP =  - ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) );
190    if ((m_iMaxDeltaQP == 0 ) && (m_aiQP[0] == lowestQP) && (m_useLossless == true))
191    {
192      m_bUseAdaptiveQP = false;
193    }
194#endif
195
196    m_acTEncTopList[iViewIdx]->setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
197    m_acTEncTopList[iViewIdx]->setQPAdaptationRange            ( m_iQPAdaptationRange );
198 
199#if HHI_VSO
200    //====== VSO =========
201    m_acTEncTopList[iViewIdx]->setForceLambdaScaleVSO          ( false );
202    m_acTEncTopList[iViewIdx]->setLambdaScaleVSO               ( 1     );
203    m_acTEncTopList[iViewIdx]->setVSOMode                      ( 0     );
204    m_acTEncTopList[iViewIdx]->setUseVSO                       ( false ); 
205#if SAIT_VSO_EST_A0033
206    m_acTEncTopList[iViewIdx]->setUseEstimatedVSD              ( false );
207#endif
208#if LGE_WVSO_A0119
209    m_acTEncTopList[iViewIdx]->setUseWVSO                      ( false ); 
210#endif
211#endif
212
213#if DEPTH_MAP_GENERATION
214    m_acTEncTopList[iViewIdx]->setPredDepthMapGeneration       ( m_uiPredDepthMapGeneration );
215    m_acTEncTopList[iViewIdx]->setPdmPrecision                 ( (UInt)m_cCameraData.getPdmPrecision     () );
216    m_acTEncTopList[iViewIdx]->setPdmScaleNomDelta             (       m_cCameraData.getPdmScaleNomDelta () );
217    m_acTEncTopList[iViewIdx]->setPdmOffset                    (       m_cCameraData.getPdmOffset        () );
218#endif
219#if H3D_IVMP
220    m_acTEncTopList[iViewIdx]->setMultiviewMvPredMode          ( m_uiMultiviewMvPredMode );
221    m_acTEncTopList[iViewIdx]->setMultiviewMvRegMode           ( iViewIdx ? m_uiMultiviewMvRegMode       : 0   );
222    m_acTEncTopList[iViewIdx]->setMultiviewMvRegLambdaScale    ( iViewIdx ? m_dMultiviewMvRegLambdaScale : 0.0 );
223#endif
224#if H3D_IVRP
225    m_acTEncTopList[iViewIdx]->setMultiviewResPredMode         ( m_uiMultiviewResPredMode );
226#endif
227
228  //====== Tool list ========
229    m_acTEncTopList[iViewIdx]->setUseSBACRD                    ( m_bUseSBACRD   );
230    m_acTEncTopList[iViewIdx]->setDeltaQpRD                    ( m_uiDeltaQpRD  );
231    m_acTEncTopList[iViewIdx]->setUseASR                       ( m_bUseASR      );
232    m_acTEncTopList[iViewIdx]->setUseHADME                     ( m_bUseHADME    );
233    m_acTEncTopList[iViewIdx]->setUseALF                       ( m_abUseALF[0]  );
234    m_acTEncTopList[iViewIdx]->setALFEncodePassReduction       ( m_iALFEncodePassReduction );
235#if LOSSLESS_CODING
236    m_acTEncTopList[iViewIdx]->setUseLossless                  ( m_useLossless );
237#endif
238    m_acTEncTopList[iViewIdx]->setALFMaxNumberFilters          ( m_iALFMaxNumberFilters ) ;
239
240    m_acTEncTopList[iViewIdx]->setUseLComb                     ( m_bUseLComb    );
241    m_acTEncTopList[iViewIdx]->setLCMod                        ( m_bLCMod         );
242    m_acTEncTopList[iViewIdx]->setdQPs                         ( m_aidQP        );
243    m_acTEncTopList[iViewIdx]->setUseRDOQ                      ( m_abUseRDOQ[0] );
244    m_acTEncTopList[iViewIdx]->setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
245    m_acTEncTopList[iViewIdx]->setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
246    m_acTEncTopList[iViewIdx]->setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
247    m_acTEncTopList[iViewIdx]->setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
248    m_acTEncTopList[iViewIdx]->setUseFastEnc                   ( m_bUseFastEnc  );
249    m_acTEncTopList[iViewIdx]->setUseEarlyCU                   ( m_bUseEarlyCU  ); 
250    m_acTEncTopList[iViewIdx]->setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
251    m_acTEncTopList[iViewIdx]->setUseCbfFastMode               ( m_bUseCbfFastMode  );
252#if HHI_INTERVIEW_SKIP
253    m_acTEncTopList[iViewIdx]->setInterViewSkip            ( iViewIdx>0 ? m_bInterViewSkip : false );
254#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
255    m_acTEncTopList[iViewIdx]->setInterViewSkipLambdaScale ( iViewIdx>0 ? (UInt)m_dInterViewSkipLambdaScale : 1 );
256#endif
257#endif
258    m_acTEncTopList[iViewIdx]->setUseLMChroma                  ( m_bUseLMChroma );
259    m_acTEncTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
260    m_acTEncTopList[iViewIdx]->setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
261    m_acTEncTopList[iViewIdx]->setUsePCM                       ( m_usePCM );
262    m_acTEncTopList[iViewIdx]->setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
263
264  //====== Weighted Prediction ========
265    m_acTEncTopList[iViewIdx]->setUseWP                        ( m_bUseWeightPred      );
266    m_acTEncTopList[iViewIdx]->setWPBiPredIdc                  ( m_uiBiPredIdc         );
267  //====== Slice ========
268    m_acTEncTopList[iViewIdx]->setSliceMode                    ( m_iSliceMode                );
269    m_acTEncTopList[iViewIdx]->setSliceArgument                ( m_iSliceArgument            );
270
271  //====== Entropy Slice ========
272    m_acTEncTopList[iViewIdx]->setEntropySliceMode             ( m_iEntropySliceMode         );
273    m_acTEncTopList[iViewIdx]->setEntropySliceArgument         ( m_iEntropySliceArgument     );
274    int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
275    if(m_iEntropySliceMode==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
276    {
277      m_acTEncTopList[iViewIdx]->setEntropySliceArgument ( m_iEntropySliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
278    }
279    if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)
280    {
281      m_acTEncTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
282    }
283    if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE)
284    {
285      m_acTEncTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument );
286    }
287    m_acTEncTopList[iViewIdx]->setSliceGranularity        ( m_iSliceGranularity         );
288    if(m_iSliceMode == 0 )
289    {
290      m_bLFCrossSliceBoundaryFlag = true;
291    }
292    m_acTEncTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
293    m_acTEncTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[0]     );
294#if LGE_ILLUCOMP_B0045
295#if LGE_ILLUCOMP_DEPTH_C0046
296    m_acTEncTopList[iViewIdx]->setUseIC                ( m_abUseIC[0]      );
297#else
298    m_acTEncTopList[iViewIdx]->setUseIC                ( m_bUseIC          );
299#endif
300#endif
301#if INTER_VIEW_VECTOR_SCALING_C0115
302    m_acTEncTopList[iViewIdx]->setUseIVS               ( m_bUseIVS          );
303#endif
304    m_acTEncTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
305    m_acTEncTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
306    m_acTEncTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
307    m_acTEncTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
308
309    m_acTEncTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
310
311    m_acTEncTopList[iViewIdx]->setColumnRowInfoPresent       ( m_iColumnRowInfoPresent );
312    m_acTEncTopList[iViewIdx]->setUniformSpacingIdr          ( m_iUniformSpacingIdr );
313    m_acTEncTopList[iViewIdx]->setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
314    m_acTEncTopList[iViewIdx]->setNumRowsMinus1              ( m_iNumRowsMinus1 );
315    if(m_iUniformSpacingIdr==0)
316    {
317      m_acTEncTopList[iViewIdx]->setColumnWidth              ( m_pchColumnWidth );
318      m_acTEncTopList[iViewIdx]->setRowHeight                ( m_pchRowHeight );
319    }
320    m_acTEncTopList[iViewIdx]->xCheckGSParameters();
321    m_acTEncTopList[iViewIdx]->setTileLocationInSliceHeaderFlag ( m_iTileLocationInSliceHeaderFlag );
322    m_acTEncTopList[iViewIdx]->setTileMarkerFlag              ( m_iTileMarkerFlag );
323    m_acTEncTopList[iViewIdx]->setMaxTileMarkerEntryPoints    ( m_iMaxTileMarkerEntryPoints );
324 
325    Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
326    m_dMaxTileMarkerOffset    = ((Double)uiTilesCount) / m_iMaxTileMarkerEntryPoints;
327    m_acTEncTopList[iViewIdx]->setMaxTileMarkerOffset         ( m_dMaxTileMarkerOffset );
328    m_acTEncTopList[iViewIdx]->setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag );
329    if(uiTilesCount == 1)
330    {
331      m_bLFCrossTileBoundaryFlag = true; 
332    }
333    m_acTEncTopList[iViewIdx]->setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
334    m_acTEncTopList[iViewIdx]->setWaveFrontSynchro           ( m_iWaveFrontSynchro );
335    m_acTEncTopList[iViewIdx]->setWaveFrontFlush             ( m_iWaveFrontFlush );
336    m_acTEncTopList[iViewIdx]->setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
337#if TMVP_DEPTH_SWITCH
338    m_acTEncTopList[iViewIdx]->setEnableTMVP                 ( m_enableTMVP[0] );
339#else
340    m_acTEncTopList[iViewIdx]->setEnableTMVP ( m_enableTMVP );
341#endif
342    m_acTEncTopList[iViewIdx]->setUseScalingListId           ( m_useScalingListId  );
343    m_acTEncTopList[iViewIdx]->setScalingListFile            ( m_scalingListFile   );
344    m_acTEncTopList[iViewIdx]->setSignHideFlag(m_signHideFlag);
345    m_acTEncTopList[iViewIdx]->setTSIG(m_signHidingThreshold);
346
347    if(uiTilesCount > 1)
348    {
349      m_bALFParamInSlice = false;
350      m_bALFPicBasedEncode = true;
351    }
352    m_acTEncTopList[iViewIdx]->setALFParamInSlice              ( m_bALFParamInSlice);
353    m_acTEncTopList[iViewIdx]->setALFPicBasedEncode            ( m_bALFPicBasedEncode);
354
355    //====== Depth tools ========
356#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
357    m_acTEncTopList[iViewIdx]->setUseDMM                     ( false );
358#endif
359#if H3D_QTL
360    m_acTEncTopList[iViewIdx]->setUseQTLPC                   ( false );
361#endif
362#if HHI_MPI
363    m_acTEncTopList[iViewIdx]->setUseMVI( false );
364#endif
365#if RWTH_SDC_DLT_B0036
366    m_acTEncTopList[iViewIdx]->setUseDLT                      ( false );
367    m_acTEncTopList[iViewIdx]->setUseSDC                      ( false );
368#endif
369  }
370  if( m_bUsingDepthMaps )
371  {
372    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
373    {
374
375#if FLEX_CODING_ORDER_M23723
376      // Detect whether depth comes before than texture for this view
377      Bool isDepthFirst = false;
378      if ( m_b3DVFlexOrder )
379      {
380        for ( Int ii=1; ii<12; ii+=2 )
381        {
382          Int iViewIdxCfg = (Int)(m_pchMVCJointCodingOrder[ii]-'0');
383          if ( iViewIdxCfg == iViewIdx )
384          {
385            if ( m_pchMVCJointCodingOrder[ii-1]=='D' ) // depth comes first for this view
386            {
387              isDepthFirst = true;
388            }
389            else
390            {
391              assert(m_pchMVCJointCodingOrder[ii-1]=='T');
392            }
393            break;
394          }
395        }
396      }
397#endif
398
399      m_depthFrameRcvd.push_back(0);
400      m_acTEncDepthTopList.push_back(new TEncTop); 
401      m_acTVideoIOYuvDepthInputFileList.push_back(new TVideoIOYuv);
402      m_acTVideoIOYuvDepthReconFileList.push_back(new TVideoIOYuv);
403      m_picYuvDepthRec.push_back(new TComList<TComPicYuv*>) ;
404
405      m_acTEncDepthTopList[iViewIdx]->setFrameRate                    ( m_iFrameRate );
406      m_acTEncDepthTopList[iViewIdx]->setFrameSkip                    ( m_FrameSkip );
407      m_acTEncDepthTopList[iViewIdx]->setSourceWidth                  ( m_iSourceWidth );
408      m_acTEncDepthTopList[iViewIdx]->setSourceHeight                 ( m_iSourceHeight );
409      m_acTEncDepthTopList[iViewIdx]->setCroppingMode                 ( m_croppingMode );
410      m_acTEncDepthTopList[iViewIdx]->setCropLeft                     ( m_cropLeft );
411      m_acTEncDepthTopList[iViewIdx]->setCropRight                    ( m_cropRight );
412      m_acTEncDepthTopList[iViewIdx]->setCropTop                      ( m_cropTop );
413      m_acTEncDepthTopList[iViewIdx]->setCropBottom                   ( m_cropBottom );
414      m_acTEncDepthTopList[iViewIdx]->setFrameToBeEncoded             ( m_iFrameToBeEncoded );
415      m_acTEncDepthTopList[iViewIdx]->setViewId                       ( iViewIdx );
416      m_acTEncDepthTopList[iViewIdx]->setIsDepth                      ( true );
417#if QC_MVHEVC_B0046
418      m_acTEncDepthTopList[iViewIdx]->setLayerId                      ( iViewIdx );
419#else
420      m_acTEncDepthTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
421#endif
422#if VIDYO_VPS_INTEGRATION
423      layerId = iViewIdx * 2 + 1;
424      m_acTEncDepthTopList[iViewIdx]->setLayerId                      ( layerId );
425      m_cVPS.setDepthFlag                                             ( true, layerId );
426      m_cVPS.setViewId                                                ( iViewIdx, layerId );
427      m_cVPS.setViewOrderIdx                                          ( m_cCameraData.getViewOrderIndex()[ iViewIdx ], layerId );
428      m_cVPS.setDependentFlag                                         ( true, layerId );
429      m_cVPS.setDependentLayer                                        ( layerId-1, layerId);
430#endif
431#if FCO_FIX_SPS_CHANGE
432      m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( m_cCameraData.getCamParsCodedPrecision  () );
433      m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( m_cCameraData.getVaryingCameraParameters() );
434      m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( m_cCameraData.getCodedScale             () );
435      m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( m_cCameraData.getCodedOffset            () );
436#else
437      m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( 0 );
438      m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( false );
439      m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( 0 );
440      m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( 0 );
441#endif
442
443      //====== Coding Structure ========
444      m_acTEncDepthTopList[iViewIdx]->setIntraPeriod                  ( m_iIntraPeriod );
445      m_acTEncDepthTopList[iViewIdx]->setDecodingRefreshType          ( m_iDecodingRefreshType );
446      m_acTEncDepthTopList[iViewIdx]->setGOPSize                      ( m_iGOPSize );
447      m_acTEncDepthTopList[iViewIdx]->setGopList                      ( m_GOPListsMvc[iViewIdx] );
448      m_acTEncDepthTopList[iViewIdx]->setExtraRPSs                    ( m_extraRPSs[iViewIdx] );
449      for(Int i = 0; i < MAX_TLAYER; i++)
450      {
451        m_acTEncDepthTopList[iViewIdx]->setNumReorderPics             ( m_numReorderPics[iViewIdx][i], i );
452        m_acTEncDepthTopList[iViewIdx]->setMaxDecPicBuffering         ( m_maxDecPicBuffering[iViewIdx][i], i );
453      }
454      for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
455      {
456        m_acTEncDepthTopList[iViewIdx]->setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
457      }
458      m_acTEncDepthTopList[iViewIdx]->setQP                           ( m_aiQP[1] );
459
460      m_acTEncDepthTopList[iViewIdx]->setTemporalLayerQPOffset        ( m_aiTLayerQPOffset );
461      m_acTEncDepthTopList[iViewIdx]->setPad                          ( m_aiPad );
462
463      m_acTEncDepthTopList[iViewIdx]->setMaxTempLayer                 ( m_maxTempLayer[iViewIdx] );
464
465      m_acTEncDepthTopList[iViewIdx]->setDisInter4x4                  ( m_bDisInter4x4);
466
467      m_acTEncDepthTopList[iViewIdx]->setUseNSQT( m_enableNSQT );
468      m_acTEncDepthTopList[iViewIdx]->setUseAMP( m_enableAMP );
469
470      //===== Slice ========
471
472      //====== Loop/Deblock Filter ========
473      m_acTEncDepthTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[1]   );
474      m_acTEncDepthTopList[iViewIdx]->setLoopFilterOffsetInAPS        ( m_loopFilterOffsetInAPS );
475      m_acTEncDepthTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
476      m_acTEncDepthTopList[iViewIdx]->setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
477      m_acTEncDepthTopList[iViewIdx]->setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
478
479      //====== Motion search ========
480      m_acTEncDepthTopList[iViewIdx]->setFastSearch                   ( m_iFastSearch  );
481      m_acTEncDepthTopList[iViewIdx]->setSearchRange                  ( m_iSearchRange );
482      m_acTEncDepthTopList[iViewIdx]->setBipredSearchRange            ( m_bipredSearchRange );
483#if DV_V_RESTRICTION_B0037
484      m_acTEncDepthTopList[iViewIdx]->setUseDisparitySearchRangeRestriction ( m_bUseDisparitySearchRangeRestriction );
485      m_acTEncDepthTopList[iViewIdx]->setVerticalDisparitySearchRange( m_iVerticalDisparitySearchRange );
486#endif
487      //====== Quality control ========
488      m_acTEncDepthTopList[iViewIdx]->setMaxDeltaQP                   ( m_iMaxDeltaQP  );
489      m_acTEncDepthTopList[iViewIdx]->setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
490
491      m_acTEncDepthTopList[iViewIdx]->setChromaQpOffset               ( m_iChromaQpOffset     );
492      m_acTEncDepthTopList[iViewIdx]->setChromaQpOffset2nd            ( m_iChromaQpOffset2nd  );
493
494#if ADAPTIVE_QP_SELECTION
495      m_acTEncDepthTopList[iViewIdx]->setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
496#endif
497
498      m_acTEncDepthTopList[iViewIdx]->setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
499      m_acTEncDepthTopList[iViewIdx]->setQPAdaptationRange            ( m_iQPAdaptationRange );
500
501      //====== Tool list ========
502      m_acTEncDepthTopList[iViewIdx]->setUseSBACRD                    ( m_bUseSBACRD   );
503      m_acTEncDepthTopList[iViewIdx]->setDeltaQpRD                    ( m_uiDeltaQpRD  );
504      m_acTEncDepthTopList[iViewIdx]->setUseASR                       ( m_bUseASR      );
505      m_acTEncDepthTopList[iViewIdx]->setUseHADME                     ( m_bUseHADME    );
506      m_acTEncDepthTopList[iViewIdx]->setUseALF                       ( m_abUseALF[1]  );
507      m_acTEncDepthTopList[iViewIdx]->setALFEncodePassReduction       ( m_iALFEncodePassReduction );
508#if LOSSLESS_CODING
509      m_acTEncDepthTopList[iViewIdx]->setUseLossless                  ( m_useLossless );
510#endif
511      m_acTEncDepthTopList[iViewIdx]->setALFMaxNumberFilters          ( m_iALFMaxNumberFilters ) ;
512
513      m_acTEncDepthTopList[iViewIdx]->setUseLComb                     ( m_bUseLComb    );
514      m_acTEncDepthTopList[iViewIdx]->setLCMod                        ( m_bLCMod       );
515      m_acTEncDepthTopList[iViewIdx]->setdQPs                         ( m_aidQPdepth   );
516      m_acTEncDepthTopList[iViewIdx]->setUseRDOQ                      ( m_abUseRDOQ[1] );
517      m_acTEncDepthTopList[iViewIdx]->setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
518      m_acTEncDepthTopList[iViewIdx]->setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
519      m_acTEncDepthTopList[iViewIdx]->setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
520      m_acTEncDepthTopList[iViewIdx]->setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
521      m_acTEncDepthTopList[iViewIdx]->setUseFastEnc                   ( m_bUseFastEnc  );
522      m_acTEncDepthTopList[iViewIdx]->setUseEarlyCU                   ( m_bUseEarlyCU  ); 
523      m_acTEncDepthTopList[iViewIdx]->setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
524      m_acTEncDepthTopList[iViewIdx]->setUseCbfFastMode               ( m_bUseCbfFastMode  );
525#if HHI_INTERVIEW_SKIP
526      m_acTEncDepthTopList[iViewIdx]->setInterViewSkip            ( 0 );
527#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
528      m_acTEncDepthTopList[iViewIdx]->setInterViewSkipLambdaScale ( 1 );
529#endif
530#endif
531      m_acTEncDepthTopList[iViewIdx]->setUseLMChroma                  ( m_bUseLMChroma );
532      m_acTEncDepthTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
533      m_acTEncDepthTopList[iViewIdx]->setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
534      m_acTEncDepthTopList[iViewIdx]->setUsePCM                       ( m_usePCM );
535      m_acTEncDepthTopList[iViewIdx]->setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
536      //====== VSO ========
537#if HHI_VSO
538      m_acTEncDepthTopList[iViewIdx]->setUseVSO                       ( m_bUseVSO      ); //GT: might be enabled/disabled later for VSO Mode 4
539      m_acTEncDepthTopList[iViewIdx]->setForceLambdaScaleVSO          ( m_bForceLambdaScaleVSO );
540      m_acTEncDepthTopList[iViewIdx]->setLambdaScaleVSO               ( m_dLambdaScaleVSO );
541#if HHI_VSO_DIST_INT
542      m_acTEncDepthTopList[iViewIdx]->setAllowNegDist                 ( m_bAllowNegDist );
543#endif
544      m_acTEncDepthTopList[iViewIdx]->setVSOMode                      ( m_uiVSOMode );
545
546#if SAIT_VSO_EST_A0033
547      m_acTEncDepthTopList[iViewIdx]->setUseEstimatedVSD              ( m_bUseEstimatedVSD );
548#endif
549#if LGE_WVSO_A0119
550      m_acTEncDepthTopList[iViewIdx]->setUseWVSO                      ( m_bUseWVSO         );
551#endif
552#endif
553
554#if DEPTH_MAP_GENERATION
555      m_acTEncDepthTopList[iViewIdx]->setPredDepthMapGeneration       ( 0 );
556#endif
557#if H3D_IVMP
558      m_acTEncDepthTopList[iViewIdx]->setMultiviewMvPredMode          ( 0 );
559      m_acTEncDepthTopList[iViewIdx]->setMultiviewMvRegMode           ( 0 );
560      m_acTEncDepthTopList[iViewIdx]->setMultiviewMvRegLambdaScale    ( 0.0 );
561#endif
562#if H3D_IVRP
563      m_acTEncDepthTopList[iViewIdx]->setMultiviewResPredMode         ( 0 );
564#endif
565
566      //====== Weighted Prediction ========
567      m_acTEncDepthTopList[iViewIdx]->setUseWP                        ( m_bUseWeightPred      );
568      m_acTEncDepthTopList[iViewIdx]->setWPBiPredIdc                  ( m_uiBiPredIdc         );
569      //====== Slice ========
570      m_acTEncDepthTopList[iViewIdx]->setSliceMode                    ( m_iSliceMode                );
571      m_acTEncDepthTopList[iViewIdx]->setSliceArgument                ( m_iSliceArgument            );
572
573      //====== Entropy Slice ========
574      m_acTEncDepthTopList[iViewIdx]->setEntropySliceMode             ( m_iEntropySliceMode         );
575      m_acTEncDepthTopList[iViewIdx]->setEntropySliceArgument         ( m_iEntropySliceArgument     );
576      int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
577      if(m_iEntropySliceMode==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
578      {
579        m_acTEncDepthTopList[iViewIdx]->setEntropySliceArgument ( m_iEntropySliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
580      }
581      if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)
582      {
583        m_acTEncDepthTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
584      }
585      if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE)
586      {
587        m_acTEncDepthTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument );
588      }
589      m_acTEncDepthTopList[iViewIdx]->setSliceGranularity        ( m_iSliceGranularity         );
590      if(m_iSliceMode == 0 )
591      {
592        m_bLFCrossSliceBoundaryFlag = true;
593      }
594      m_acTEncDepthTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
595      m_acTEncDepthTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[1]     );
596#if LGE_ILLUCOMP_B0045
597#if LGE_ILLUCOMP_DEPTH_C0046
598      m_acTEncDepthTopList[iViewIdx]->setUseIC                ( m_abUseIC[1] );
599#else
600      m_acTEncDepthTopList[iViewIdx]->setUseIC                ( false     );
601#endif
602#endif
603#if INTER_VIEW_VECTOR_SCALING_C0115
604     m_acTEncDepthTopList[iViewIdx]->setUseIVS                ( m_bUseIVS );
605#endif
606      m_acTEncDepthTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
607      m_acTEncDepthTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
608      m_acTEncDepthTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
609      m_acTEncDepthTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
610
611      m_acTEncDepthTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
612
613      m_acTEncDepthTopList[iViewIdx]->setColumnRowInfoPresent       ( m_iColumnRowInfoPresent );
614      m_acTEncDepthTopList[iViewIdx]->setUniformSpacingIdr          ( m_iUniformSpacingIdr );
615      m_acTEncDepthTopList[iViewIdx]->setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
616      m_acTEncDepthTopList[iViewIdx]->setNumRowsMinus1              ( m_iNumRowsMinus1 );
617      if(m_iUniformSpacingIdr==0)
618      {
619        m_acTEncDepthTopList[iViewIdx]->setColumnWidth              ( m_pchColumnWidth );
620        m_acTEncDepthTopList[iViewIdx]->setRowHeight                ( m_pchRowHeight );
621      }
622      m_acTEncDepthTopList[iViewIdx]->xCheckGSParameters();
623      m_acTEncDepthTopList[iViewIdx]->setTileLocationInSliceHeaderFlag ( m_iTileLocationInSliceHeaderFlag );
624      m_acTEncDepthTopList[iViewIdx]->setTileMarkerFlag              ( m_iTileMarkerFlag );
625      m_acTEncDepthTopList[iViewIdx]->setMaxTileMarkerEntryPoints    ( m_iMaxTileMarkerEntryPoints );
626
627      Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
628      m_dMaxTileMarkerOffset    = ((Double)uiTilesCount) / m_iMaxTileMarkerEntryPoints;
629      m_acTEncDepthTopList[iViewIdx]->setMaxTileMarkerOffset         ( m_dMaxTileMarkerOffset );
630      m_acTEncDepthTopList[iViewIdx]->setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag );
631      if(uiTilesCount == 1)
632      {
633        m_bLFCrossTileBoundaryFlag = true; 
634      }
635      m_acTEncDepthTopList[iViewIdx]->setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
636      m_acTEncDepthTopList[iViewIdx]->setWaveFrontSynchro           ( m_iWaveFrontSynchro );
637      m_acTEncDepthTopList[iViewIdx]->setWaveFrontFlush             ( m_iWaveFrontFlush );
638      m_acTEncDepthTopList[iViewIdx]->setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
639#if TMVP_DEPTH_SWITCH
640      m_acTEncDepthTopList[iViewIdx]->setEnableTMVP                 ( m_enableTMVP[1] );
641#else
642      m_acTEncDepthTopList[iViewIdx]->setEnableTMVP ( m_enableTMVP );
643#endif
644      m_acTEncDepthTopList[iViewIdx]->setUseScalingListId           ( m_useScalingListId  );
645      m_acTEncDepthTopList[iViewIdx]->setScalingListFile            ( m_scalingListFile   );
646      m_acTEncDepthTopList[iViewIdx]->setSignHideFlag(m_signHideFlag);
647      m_acTEncDepthTopList[iViewIdx]->setTSIG(m_signHidingThreshold);
648
649      if(uiTilesCount > 1)
650      {
651        m_bALFParamInSlice = false;
652        m_bALFPicBasedEncode = true;
653      }
654      m_acTEncDepthTopList[iViewIdx]->setALFParamInSlice              ( m_bALFParamInSlice);
655      m_acTEncDepthTopList[iViewIdx]->setALFPicBasedEncode            ( m_bALFPicBasedEncode);
656
657  //====== Depth tools ========
658#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
659    m_acTEncDepthTopList[iViewIdx]->setUseDMM                     ( m_bUseDMM );
660#endif
661#if FLEX_CODING_ORDER_M23723 && HHI_DMM_PRED_TEX
662    m_acTEncDepthTopList[iViewIdx]->setUseDMM34( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseDMM );
663#endif
664
665#if H3D_QTL
666    m_acTEncDepthTopList[iViewIdx]->setUseQTLPC                   (m_bUseQTLPC);
667#endif
668#if HHI_MPI
669#if FLEX_CODING_ORDER_M23723
670    m_acTEncDepthTopList[iViewIdx]->setUseMVI( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseMVI );
671#else
672     m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
673#endif
674#endif
675#if RWTH_SDC_DLT_B0036
676      m_acTEncDepthTopList[iViewIdx]->setUseDLT                   ( m_bUseDLT );
677      m_acTEncDepthTopList[iViewIdx]->setUseSDC                   ( m_bUseSDC );
678#endif
679    }
680  }
681
682#if H3D_IVMP
683  else if( m_uiMultiviewMvRegMode )
684  {
685    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
686    {
687      m_acTVideoIOYuvDepthInputFileList.push_back( new TVideoIOYuv );
688    }
689  }
690#endif
691
692#if HHI_VSO
693  if ( m_bUseVSO )
694  {
695    if ( m_uiVSOMode == 4 )
696    {
697#if LGE_VSO_EARLY_SKIP_A0093
698      m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, g_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0, m_bVSOEarlySkip );
699#else
700      m_cRendererModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, g_uiMaxCUHeight , LOG2_DISP_PREC_LUT, 0 );
701#endif
702
703      for ( Int iViewNum = 0; iViewNum < m_iNumberOfViews; iViewNum++ )
704      {
705        for (Int iContent = 0; iContent < 2; iContent++ )
706        {
707          Int iNumOfModels   = m_cRenModStrParser.getNumOfModelsForView(iViewNum, iContent);
708          Bool bUseVSO = (iNumOfModels != 0);
709
710          TEncTop* pcEncTop = ( iContent == 0 ) ? m_acTEncTopList[iViewNum] : m_acTEncDepthTopList[iViewNum];
711          pcEncTop->setUseVSO( bUseVSO );
712          pcEncTop->getRdCost()->setRenModel( bUseVSO ? &m_cRendererModel : NULL );
713
714          for (Int iCurModel = 0; iCurModel < iNumOfModels; iCurModel++ )
715          {
716            Int iModelNum; Int iLeftViewNum; Int iRightViewNum; Int iDump; Int iOrgRefNum; Int iBlendMode;
717
718            m_cRenModStrParser.getSingleModelData  ( iViewNum, iContent, iCurModel, iModelNum, iBlendMode, iLeftViewNum, iRightViewNum, iOrgRefNum, iDump ) ;
719            m_cRendererModel  .createSingleModel   ( iViewNum, iContent, iModelNum, iLeftViewNum, iRightViewNum, (iOrgRefNum != -1), iBlendMode );
720          }
721        }
722      }
723    }
724    else
725    {
726      AOT(true);
727    }
728#if LGE_WVSO_A0119
729    for ( Int iViewNum = 0; iViewNum < m_iNumberOfViews; iViewNum++ )
730    {
731      for (Int iContent = 0; iContent < 2; iContent++ )
732      {
733        TEncTop* pcEncTop = ( iContent == 0 ) ? m_acTEncTopList[iViewNum] : m_acTEncDepthTopList[iViewNum]; 
734        pcEncTop->setUseWVSO  ( m_bUseWVSO );
735        pcEncTop->setVSOWeight( m_iVSOWeight );
736        pcEncTop->setVSDWeight( m_iVSDWeight );
737        pcEncTop->setDWeight  ( m_iDWeight );
738      }
739    }
740#endif
741  }
742#endif
743
744#if HHI_INTERVIEW_SKIP
745  m_cUsedPelsRenderer.init(m_iSourceWidth, m_iSourceHeight, true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 4, 1, 0, 6 );
746#endif
747
748}
749
750Void TAppEncTop::xCreateLib()
751{
752  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
753  {
754    m_acTVideoIOYuvInputFileList[iViewIdx]->open( m_pchInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
755    m_acTVideoIOYuvInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
756
757    if (m_pchReconFileList[iViewIdx])
758      m_acTVideoIOYuvReconFileList[iViewIdx]->open(m_pchReconFileList[iViewIdx], true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
759    m_acTEncTopList[iViewIdx]->create();
760    if( m_bUsingDepthMaps )
761    {
762      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->open( m_pchDepthInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
763      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
764
765      if (m_pchDepthReconFileList[iViewIdx])
766        m_acTVideoIOYuvDepthReconFileList[iViewIdx]->open(m_pchDepthReconFileList[iViewIdx], true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
767      m_acTEncDepthTopList[iViewIdx]->create();
768    }
769#if H3D_IVMP
770    else if( m_uiMultiviewMvRegMode )
771    {
772      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->open( m_pchDepthInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
773      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth, m_iSourceHeight);
774    }
775#endif
776  }
777}
778
779Void TAppEncTop::xDestroyLib()
780{
781  // Video I/O
782  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
783  {
784    m_acTVideoIOYuvInputFileList[iViewIdx]->close();
785    m_acTVideoIOYuvReconFileList[iViewIdx]->close();
786    delete m_acTVideoIOYuvInputFileList[iViewIdx] ; 
787    m_acTVideoIOYuvInputFileList[iViewIdx] = NULL;
788    delete m_acTVideoIOYuvReconFileList[iViewIdx] ; 
789    m_acTVideoIOYuvReconFileList[iViewIdx] = NULL;
790    m_acTEncTopList[iViewIdx]->deletePicBuffer();
791    m_acTEncTopList[iViewIdx]->destroy();
792    delete m_acTEncTopList[iViewIdx] ; 
793    m_acTEncTopList[iViewIdx] = NULL;
794    delete m_picYuvRec[iViewIdx] ; 
795    m_picYuvRec[iViewIdx] = NULL;
796
797    if( iViewIdx < Int( m_acTVideoIOYuvDepthInputFileList.size() ) && m_acTVideoIOYuvDepthInputFileList[iViewIdx] )
798    {
799      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->close( );
800      delete m_acTVideoIOYuvDepthInputFileList[iViewIdx];
801      m_acTVideoIOYuvDepthInputFileList[iViewIdx] = NULL;
802    }
803    if( iViewIdx < Int( m_acTVideoIOYuvDepthReconFileList.size() ) && m_acTVideoIOYuvDepthReconFileList[iViewIdx] )
804    {
805      m_acTVideoIOYuvDepthReconFileList[iViewIdx]->close () ;
806      delete m_acTVideoIOYuvDepthReconFileList[iViewIdx];
807      m_acTVideoIOYuvDepthReconFileList[iViewIdx] = NULL;
808    }
809    if( iViewIdx < Int( m_acTEncDepthTopList.size() ) && m_acTEncDepthTopList[iViewIdx] )
810    {
811      m_acTEncDepthTopList[iViewIdx]->deletePicBuffer();
812      m_acTEncDepthTopList[iViewIdx]->destroy();
813      delete m_acTEncDepthTopList[iViewIdx];
814      m_acTEncDepthTopList[iViewIdx] = NULL;
815    }
816    if( iViewIdx < Int( m_picYuvDepthRec.size() ) && m_picYuvDepthRec[iViewIdx] )
817    {
818      delete m_picYuvDepthRec[iViewIdx] ; 
819      m_picYuvDepthRec[iViewIdx] = NULL;
820    }
821  }
822}
823
824Void TAppEncTop::xInitLib()
825{
826  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
827  {
828    m_acTEncTopList[iViewIdx]->init( this );
829#if QC_MVHEVC_B0046
830  //set setNumDirectRefLayer
831  Int iNumDirectRef = m_acTEncTopList[iViewIdx]->getSPS()->getNumberOfUsableInterViewRefs();
832  m_acTEncTopList[iViewIdx]->getEncTop()->getVPS()->setNumDirectRefLayer(iNumDirectRef, iViewIdx);
833  for(Int iNumIvRef = 0; iNumIvRef < iNumDirectRef; iNumIvRef ++)
834  {
835    Int iLayerId = m_acTEncTopList[iViewIdx]->getSPS()->getUsableInterViewRef(iNumIvRef);
836    m_acTEncTopList[iViewIdx]->getEncTop()->getVPS()->setDirectRefLayerId( iLayerId + iViewIdx, iViewIdx, iNumIvRef);
837  }
838#endif
839  }
840  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
841  {
842    m_acTEncTopList[iViewIdx]->setTEncTopList( &m_acTEncTopList  );
843  }
844  if ( m_bUsingDepthMaps )
845  {
846    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
847    {
848      m_acTEncDepthTopList[iViewIdx]->init( this );
849    }
850    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
851    {
852      m_acTEncDepthTopList[iViewIdx]->setTEncTopList( &m_acTEncDepthTopList  );
853    }
854  }
855}
856
857// ====================================================================================================================
858// Public member functions
859// ====================================================================================================================
860
861/**
862 - create internal class
863 - initialize internal variable
864 - until the end of input YUV file, call encoding function in TEncTop class
865 - delete allocated buffers
866 - destroy internal class
867 .
868 */
869Void TAppEncTop::encode()
870{
871  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
872  if (!bitstreamFile)
873  {
874    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
875    exit(EXIT_FAILURE);
876  }
877
878  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
879  TComPicYuv*       pcDepthPicYuvOrg = new TComPicYuv;
880#if !QC_MVHEVC_B0046
881  TComPicYuv*       pcPdmDepthOrg    = new TComPicYuv;
882#endif
883  TComPicYuv*       pcPicYuvRec = NULL;
884  TComPicYuv*       pcDepthPicYuvRec = NULL;
885
886  // initialize internal class & member variables
887  xInitLibCfg();
888  xCreateLib();
889  xInitLib();
890 
891  // main encoder loop
892  Bool  allEos = false;
893  std::vector<Bool>  eos ;
894  std::vector<Bool>  depthEos ;
895  Int maxGopSize = 0;
896  Int gopSize = 1;
897 
898  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
899  maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize());   
900
901  for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
902  {
903    eos.push_back( false );
904    depthEos.push_back( false );
905   
906#if RWTH_SDC_DLT_B0036
907    if( m_bUsingDepthMaps && m_bUseDLT )
908      xAnalyzeInputBaseDepth(iViewIdx, m_iIntraPeriod);
909#endif
910  }
911
912  // allocate original YUV buffer
913  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
914  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
915
916#if H3D_IVMP
917  if( m_uiMultiviewMvRegMode )
918  {
919    pcPdmDepthOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
920  }
921#endif
922
923  while ( !allEos )
924  {
925    for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
926    {
927      Int frmCnt = 0;
928      while ( !eos[iViewIdx] && !(frmCnt == gopSize))
929      {
930        // get buffers
931        xGetBuffer(pcPicYuvRec, iViewIdx, false);
932
933        // read input YUV file
934        m_acTVideoIOYuvInputFileList[iViewIdx]->read( pcPicYuvOrg, m_aiPad );
935     
936#if H3D_IVMP
937        if( m_uiMultiviewMvRegMode && iViewIdx )
938        {
939          m_acTVideoIOYuvDepthInputFileList[iViewIdx]->read( pcPdmDepthOrg, m_aiPad, m_bUsingDepthMaps );
940        }
941#endif
942
943#if H3D_IVMP
944        m_acTEncTopList[iViewIdx]->initNewPic( pcPicYuvOrg, ( m_uiMultiviewMvRegMode && iViewIdx ? pcPdmDepthOrg : 0 ) );
945#else
946        m_acTEncTopList[iViewIdx]->initNewPic( pcPicYuvOrg );
947#endif
948
949        // increase number of received frames
950        m_frameRcvd[iViewIdx]++;
951        frmCnt++;
952        // check end of file
953        eos[iViewIdx] = ( m_acTVideoIOYuvInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
954        eos[iViewIdx] = ( m_frameRcvd[iViewIdx] == m_iFrameToBeEncoded ?    true : eos[iViewIdx]   );
955        allEos = allEos|eos[iViewIdx] ; 
956      }
957      if( m_bUsingDepthMaps )
958      {
959        Int frmCntDepth = 0;
960        while ( !depthEos[iViewIdx] && !(frmCntDepth == gopSize))
961        {
962          // get buffers
963          xGetBuffer(pcDepthPicYuvRec, iViewIdx, true);
964
965          // read input YUV file
966          m_acTVideoIOYuvDepthInputFileList[iViewIdx]->read( pcDepthPicYuvOrg, m_aiPad );
967
968          m_acTEncDepthTopList[iViewIdx]->initNewPic( pcDepthPicYuvOrg );
969
970          // increase number of received frames
971          m_depthFrameRcvd[iViewIdx]++;
972          frmCntDepth++;
973          // check end of file
974          depthEos[iViewIdx] = ( m_acTVideoIOYuvDepthInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
975          depthEos[iViewIdx] = ( m_depthFrameRcvd[iViewIdx] == m_iFrameToBeEncoded ?    true : depthEos[iViewIdx]   );
976          allEos = allEos|depthEos[iViewIdx] ; 
977        }
978      }
979    }
980    for ( Int gopId=0; gopId < gopSize; gopId++ )
981    {
982      Int  iNumEncoded = 0;
983
984#if !QC_MVHEVC_B0046
985      UInt iNextPoc = m_acTEncTopList[0] -> getFrameId( gopId );
986      if ( iNextPoc < m_iFrameToBeEncoded )
987      {
988        m_cCameraData.update( iNextPoc );
989      }
990#endif
991
992
993#if FLEX_CODING_ORDER_M23723
994      if (m_b3DVFlexOrder)
995      {
996        Int  iNumDepthEncoded = 0;
997        iNumEncoded = 0;
998        Int i=0;
999        Int iViewIdx=0;
1000        Int iNumberofDepthViews = m_bUsingDepthMaps?m_iNumberOfViews:0;
1001        for (Int j=0; j < (m_iNumberOfViews+ iNumberofDepthViews); j++ )
1002        {
1003          if (m_pchMVCJointCodingOrder[i]=='T')
1004          {
1005
1006            i++;
1007            assert(isdigit(m_pchMVCJointCodingOrder[i]));
1008            iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
1009#if (FCO_FIX && MERL_VSP_C0152)
1010            Int iCurPoc = m_acTEncTopList[iViewIdx]->getFrameId(gopId);
1011            if( iCurPoc < m_acTEncTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
1012            {
1013              TComPic* pcBaseTxtPic   = getPicFromView(  0, m_acTEncTopList[iViewIdx]->getFrameId(gopId), false ); //get base view reconstructed texture
1014              TComPic* pcBaseDepthPic = getPicFromView(  0, m_acTEncTopList[iViewIdx]->getFrameId(gopId), true );  //get base view reconstructed depth
1015              TEncSlice* pEncSlice = m_acTEncTopList[iViewIdx]->getSliceEncoder();
1016              pEncSlice->setRefPicBaseTxt(pcBaseTxtPic);
1017              pEncSlice->setRefPicBaseDepth(pcBaseDepthPic);
1018            }
1019            setBWVSPLUT( iViewIdx, gopId, false);           
1020#endif
1021
1022            m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
1023            xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, iViewIdx, false);
1024            outputAccessUnits.clear();
1025            i++;
1026          }
1027          else if ( m_pchMVCJointCodingOrder[i] == 'D')
1028          {
1029
1030            i++;
1031            if( m_bUsingDepthMaps )
1032            {
1033              assert(isdigit(m_pchMVCJointCodingOrder[i]));
1034              iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
1035
1036#if SAIT_VSO_EST_A0033
1037              if( m_bUseVSO && iNextPoc < m_iFrameToBeEncoded )
1038              {
1039                m_cCameraData.xSetDispCoeff( iNextPoc, iViewIdx );
1040                m_acTEncDepthTopList[iViewIdx]->setDispCoeff( m_cCameraData.getDispCoeff() );
1041              }
1042#endif
1043#if (FCO_FIX && MERL_VSP_C0152)
1044              Int iCurPocDepth = m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId);
1045              if( iCurPocDepth < m_acTEncDepthTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
1046              {
1047                TComPic* pcBaseDepthPic = getPicFromView(  0, m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId), true );
1048                TEncSlice* pcSlice = (TEncSlice*) m_acTEncDepthTopList[iViewIdx]->getSliceEncoder();
1049                pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
1050              }
1051              setBWVSPLUT( iViewIdx, gopId, true);
1052#endif
1053              m_acTEncDepthTopList[iViewIdx]->encode( depthEos[iViewIdx], pcDepthPicYuvOrg, *m_picYuvDepthRec[iViewIdx], outputAccessUnits, iNumDepthEncoded, gopId );
1054              xWriteOutput(bitstreamFile, iNumDepthEncoded, outputAccessUnits, iViewIdx, true);
1055              outputAccessUnits.clear();
1056              i++;
1057            }
1058          }
1059        }
1060      }
1061      else
1062      {
1063
1064#endif
1065      for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
1066      {
1067#if SAIT_VSO_EST_A0033
1068        if( m_bUseVSO && iNextPoc < m_iFrameToBeEncoded )
1069        {
1070          m_cCameraData.xSetDispCoeff( iNextPoc, iViewIdx );
1071          m_acTEncDepthTopList[iViewIdx]->setDispCoeff( m_cCameraData.getDispCoeff() );
1072        }
1073#endif
1074        iNumEncoded = 0;
1075
1076#if MERL_VSP_C0152
1077#if MERL_VSP_C0152_BugFix_ForNoDepthCase
1078        if(m_bUsingDepthMaps) //VSP can be used only when depth is available as input
1079        {
1080#endif
1081        Int iCurPoc = m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId);
1082        if( iCurPoc < m_acTEncDepthTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
1083        {
1084          TComPic* pcBaseTxtPic   = getPicFromView(  0, m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId), false ); //get base view reconstructed texture
1085          TComPic* pcBaseDepthPic = getPicFromView(  0, m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId), true );  //get base view reconstructed depth
1086          TEncSlice* pEncSlice = m_acTEncTopList[iViewIdx]->getSliceEncoder();
1087          pEncSlice->setRefPicBaseTxt(pcBaseTxtPic);
1088          pEncSlice->setRefPicBaseDepth(pcBaseDepthPic);
1089        }
1090        setBWVSPLUT( iViewIdx, gopId, false);
1091#if MERL_VSP_C0152_BugFix_ForNoDepthCase
1092        }
1093        else
1094        {
1095          Int iCurPoc = m_acTEncTopList[iViewIdx]->getFrameId(gopId);
1096          if( iCurPoc < m_acTEncTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
1097          {
1098            TEncSlice* pEncSlice = m_acTEncTopList[iViewIdx]->getSliceEncoder();
1099            pEncSlice->setRefPicBaseTxt(NULL);//Initialize the base view reconstructed texture buffer
1100            pEncSlice->setRefPicBaseDepth(NULL);//Initialize the base view reconstructed depth buffer
1101          }
1102        }
1103#endif
1104
1105#endif
1106        // call encoding function for one frame
1107        m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
1108        xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, iViewIdx, false);
1109        outputAccessUnits.clear();
1110        if( m_bUsingDepthMaps )
1111        {
1112          Int  iNumDepthEncoded = 0;
1113#if MERL_VSP_C0152
1114        Int iCurPocDepth = m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId);
1115        if( iCurPocDepth < m_acTEncDepthTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
1116        {
1117          TComPic* pcBaseDepthPic = getPicFromView(  0, m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId), true );
1118          TEncSlice* pcSlice = (TEncSlice*) m_acTEncDepthTopList[iViewIdx]->getSliceEncoder();
1119          pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
1120        }
1121        setBWVSPLUT( iViewIdx, gopId, true);
1122#endif
1123
1124          // call encoding function for one depth frame
1125          m_acTEncDepthTopList[iViewIdx]->encode( depthEos[iViewIdx], pcDepthPicYuvOrg, *m_picYuvDepthRec[iViewIdx], outputAccessUnits, iNumDepthEncoded, gopId );
1126          xWriteOutput(bitstreamFile, iNumDepthEncoded, outputAccessUnits, iViewIdx, true);
1127          outputAccessUnits.clear();
1128        }
1129      }
1130 
1131#if FLEX_CODING_ORDER_M23723
1132      }
1133#endif
1134
1135#if HHI_INTERVIEW_SKIP || H3D_IVMP || H3D_IVRP
1136      for( Int iViewIdx = 0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
1137      {
1138        if( iViewIdx < (Int)m_acTEncTopList.size() && m_acTEncTopList[iViewIdx] )
1139        {
1140          m_acTEncTopList[iViewIdx]->deleteExtraPicBuffers( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
1141        }
1142        if( iViewIdx < (Int)m_acTEncDepthTopList.size() && m_acTEncDepthTopList[iViewIdx] )
1143        {
1144          m_acTEncDepthTopList[iViewIdx]->deleteExtraPicBuffers( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
1145        }
1146      }
1147#endif
1148      for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
1149      {
1150        m_acTEncTopList[iViewIdx]->compressMotion( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
1151        if( m_bUsingDepthMaps )
1152        {
1153          m_acTEncDepthTopList[iViewIdx]->compressMotion( m_acTEncDepthTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
1154        }
1155      }
1156    }
1157    gopSize = maxGopSize;
1158  }
1159  // delete original YUV buffer
1160  pcPicYuvOrg->destroy();
1161  delete pcPicYuvOrg;
1162  pcPicYuvOrg = NULL;
1163  pcDepthPicYuvOrg->destroy();
1164  delete pcDepthPicYuvOrg;
1165  pcDepthPicYuvOrg = NULL;
1166 
1167#if !QC_MVHEVC_B0046
1168  if ( pcPdmDepthOrg != NULL && m_uiMultiviewMvRegMode )
1169  {
1170    pcPdmDepthOrg->destroy();
1171    delete pcPdmDepthOrg;     
1172    pcPdmDepthOrg = NULL; 
1173  };
1174#endif
1175 
1176  for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
1177  {
1178    m_acTEncTopList[iViewIdx]->printOutSummary(m_acTEncTopList[iViewIdx]->getNumAllPicCoded());
1179    if ( m_bUsingDepthMaps )
1180    {
1181      m_acTEncDepthTopList[iViewIdx]->printOutSummary(m_acTEncDepthTopList[iViewIdx]->getNumAllPicCoded());
1182    }
1183  }
1184
1185  // delete buffers & classes
1186  xDeleteBuffer();
1187  xDestroyLib();
1188
1189  return;
1190}
1191
1192TEncTop*  TAppEncTop::getTEncTop( Int viewId, Bool isDepth )   
1193{ 
1194  if ( isDepth ) 
1195  {
1196    return m_acTEncDepthTopList[viewId]; 
1197  } 
1198  else
1199  { 
1200    return m_acTEncTopList[viewId]; 
1201  } 
1202}
1203
1204
1205// ====================================================================================================================
1206// Protected member functions
1207// ====================================================================================================================
1208
1209/**
1210 - application has picture buffer list with size of GOP
1211 - picture buffer list acts as ring buffer
1212 - end of the list has the latest picture
1213 .
1214 */
1215Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, Int iViewIdx, Bool isDepth)
1216{
1217  assert( m_iGOPSize > 0 );
1218 
1219  if( !isDepth )
1220  {
1221    if ( m_picYuvRec[iViewIdx]->size() == (UInt)m_iGOPSize )
1222    {
1223      rpcPicYuvRec = m_picYuvRec[iViewIdx]->popFront();
1224    }
1225    else
1226    {
1227      rpcPicYuvRec = new TComPicYuv; 
1228      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1229    }
1230    m_picYuvRec[iViewIdx]->pushBack( rpcPicYuvRec );
1231  }
1232  else
1233  {
1234    if ( m_picYuvDepthRec[iViewIdx]->size() == (UInt)m_iGOPSize )
1235    {
1236      rpcPicYuvRec = m_picYuvDepthRec[iViewIdx]->popFront();
1237    }
1238    else
1239    {
1240      rpcPicYuvRec = new TComPicYuv; 
1241      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1242    }
1243    m_picYuvDepthRec[iViewIdx]->pushBack( rpcPicYuvRec );
1244  }
1245}
1246
1247Void TAppEncTop::xDeleteBuffer( )
1248{
1249  for(Int iViewIdx=0; iViewIdx<m_picYuvRec.size(); iViewIdx++)
1250  {
1251    if(m_picYuvRec[iViewIdx])
1252    {
1253      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvRec[iViewIdx]->begin();
1254      Int iSize = Int( m_picYuvRec[iViewIdx]->size() );
1255      for ( Int i = 0; i < iSize; i++ )
1256      {
1257        TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1258        if(pcPicYuvRec)
1259        {
1260          pcPicYuvRec->destroy();
1261          delete pcPicYuvRec; 
1262          pcPicYuvRec = NULL;
1263        }
1264      }
1265    } 
1266  }
1267  for(Int iViewIdx=0; iViewIdx<m_picYuvDepthRec.size(); iViewIdx++)
1268  {
1269    if(m_picYuvDepthRec[iViewIdx])
1270    {
1271      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvDepthRec[iViewIdx]->begin();
1272      Int iSize = Int( m_picYuvDepthRec[iViewIdx]->size() );
1273      for ( Int i = 0; i < iSize; i++ )
1274      {
1275        TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1276        if(pcPicYuvRec)
1277        {
1278          pcPicYuvRec->destroy();
1279          delete pcPicYuvRec; 
1280          pcPicYuvRec = NULL;
1281        }
1282      } 
1283    }
1284  }
1285}
1286
1287/** \param iNumEncoded  number of encoded frames
1288 */
1289Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, Int iViewIdx, Bool isDepth )
1290{
1291  Int i;
1292 
1293  if( iNumEncoded > 0 )
1294  {
1295    TComList<TComPicYuv*>::iterator iterPicYuvRec = !isDepth ? m_picYuvRec[iViewIdx]->end() : m_picYuvDepthRec[iViewIdx]->end();
1296 
1297    for ( i = 0; i < iNumEncoded; i++ )
1298    {
1299      --iterPicYuvRec;
1300    }
1301 
1302    for ( i = 0; i < iNumEncoded; i++ )
1303    {
1304      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1305      if( !isDepth )
1306      {
1307        if (m_pchReconFileList[iViewIdx])
1308        {
1309          m_acTVideoIOYuvReconFileList[iViewIdx]->write( pcPicYuvRec, m_cropLeft, m_cropRight, m_cropTop, m_cropBottom );
1310        }
1311      }
1312      else
1313      {
1314        if (m_pchDepthReconFileList[iViewIdx])
1315        {
1316          m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write( pcPicYuvRec, m_cropLeft, m_cropRight, m_cropTop, m_cropBottom );
1317        }
1318      }
1319    }
1320  }
1321  if( ! accessUnits.empty() )
1322  {
1323    list<AccessUnit>::iterator aUIter;
1324    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
1325    {
1326      const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter);
1327      rateStatsAccum(*aUIter, stats);
1328    }
1329  }
1330}
1331
1332
1333TComPicYuv* TAppEncTop::xGetPicYuvFromView( Int iViewIdx, Int iPoc, Bool bDepth, Bool bRecon )
1334{
1335  TComPic*    pcPic = xGetPicFromView( iViewIdx, iPoc, bDepth);
1336  TComPicYuv* pcPicYuv = NULL;
1337
1338  if (pcPic != NULL)
1339  {
1340    if( bRecon )
1341    {
1342      if ( pcPic->getReconMark() )
1343      {
1344        pcPicYuv = pcPic->getPicYuvRec();
1345      }
1346    }
1347    else
1348    {
1349      pcPicYuv = pcPic->getPicYuvOrg();
1350    }
1351  };
1352
1353  return pcPicYuv;
1354};
1355
1356/**
1357 *
1358 */
1359void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<unsigned>& annexBsizes)
1360{
1361  AccessUnit::const_iterator it_au = au.begin();
1362  vector<unsigned>::const_iterator it_stats = annexBsizes.begin();
1363
1364  for (; it_au != au.end(); it_au++, it_stats++)
1365  {
1366    switch ((*it_au)->m_nalUnitType)
1367    {
1368    case NAL_UNIT_CODED_SLICE:
1369#if !QC_REM_IDV_B0046
1370    case NAL_UNIT_CODED_SLICE_IDV:
1371#endif
1372    case NAL_UNIT_CODED_SLICE_TLA:
1373    case NAL_UNIT_CODED_SLICE_CRA:
1374    case NAL_UNIT_CODED_SLICE_IDR:
1375    case NAL_UNIT_SPS:
1376    case NAL_UNIT_PPS:
1377#if VIDYO_VPS_INTEGRATION
1378    case NAL_UNIT_VPS:
1379#endif
1380      m_essentialBytes += *it_stats;
1381      break;
1382    default:
1383      break;
1384    }
1385
1386    m_totalBytes += *it_stats;
1387  }
1388}
1389
1390#if HHI_INTERVIEW_SKIP
1391Void TAppEncTop::getUsedPelsMap( Int iViewIdx, Int iPoc, TComPicYuv* pcPicYuvUsedSplsMap )
1392{
1393  AOT( iViewIdx <= 0);
1394  AOT( iViewIdx >= m_iNumberOfViews );
1395  AOF( m_cCameraData.getCurFrameId() == iPoc );
1396  Int iViewSIdx      = m_cCameraData.getBaseId2SortedId()[iViewIdx];
1397  Int iFirstViewSIdx = m_cCameraData.getBaseId2SortedId()[0];
1398
1399  AOT( iViewSIdx == iFirstViewSIdx );
1400
1401  Bool bFirstIsLeft = (iFirstViewSIdx < iViewSIdx);
1402
1403  m_cUsedPelsRenderer.setShiftLUTs(
1404      m_cCameraData.getBaseViewShiftLUTD()[0][iViewIdx],
1405      m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
1406      m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
1407      m_cCameraData.getBaseViewShiftLUTD()[0][iViewIdx],
1408      m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
1409      m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
1410      -1
1411      );
1412
1413  TComPicYuv* pcPicYuvDepth = xGetPicYuvFromView(0, iPoc, true, true );
1414  AOF( pcPicYuvDepth);
1415
1416  m_cUsedPelsRenderer.getUsedSamplesMap( pcPicYuvDepth, pcPicYuvUsedSplsMap, bFirstIsLeft );
1417}
1418#endif
1419#if HHI_VSO
1420Void TAppEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset )
1421{
1422  m_cRendererModel.setupPart( iHorOffset, Min( g_uiMaxCUHeight, m_iSourceHeight - iHorOffset ) ); 
1423  Int iEncViewSIdx = m_cCameraData.getBaseId2SortedId()[ iEncViewIdx ];
1424
1425  // setup base views
1426  Int iNumOfBV = m_cRenModStrParser.getNumOfBaseViewsForView( iEncViewSIdx, iEncContent );
1427
1428  for (Int iCurView = 0; iCurView < iNumOfBV; iCurView++ )
1429  {
1430    Int iBaseViewSIdx;
1431    Int iVideoDistMode;
1432    Int iDepthDistMode;
1433
1434    m_cRenModStrParser.getBaseViewData( iEncViewSIdx, iEncContent, iCurView, iBaseViewSIdx, iVideoDistMode, iDepthDistMode );
1435
1436    AOT( iVideoDistMode < 0 || iVideoDistMode > 2 );
1437
1438    Int iBaseViewIdx = m_cCameraData.getBaseSortedId2Id()[ iBaseViewSIdx ];
1439
1440    TComPicYuv* pcPicYuvVideoRec  = xGetPicYuvFromView( iBaseViewIdx, iPoc, false, true  );
1441    TComPicYuv* pcPicYuvDepthRec  = xGetPicYuvFromView( iBaseViewIdx, iPoc, true , true  );
1442    TComPicYuv* pcPicYuvVideoOrg  = xGetPicYuvFromView( iBaseViewIdx, iPoc, false, false );
1443    TComPicYuv* pcPicYuvDepthOrg  = xGetPicYuvFromView( iBaseViewIdx, iPoc, true , false );
1444
1445    TComPicYuv* pcPicYuvVideoRef  = ( iVideoDistMode == 2 ) ? pcPicYuvVideoOrg  : NULL;
1446    TComPicYuv* pcPicYuvDepthRef  = ( iDepthDistMode == 2 ) ? pcPicYuvDepthOrg  : NULL;
1447
1448    TComPicYuv* pcPicYuvVideoTest = ( iVideoDistMode == 0 ) ? pcPicYuvVideoOrg  : pcPicYuvVideoRec;
1449    TComPicYuv* pcPicYuvDepthTest = ( iDepthDistMode == 0 ) ? pcPicYuvDepthOrg  : pcPicYuvDepthRec;
1450
1451    AOT( (iVideoDistMode == 2) != (pcPicYuvVideoRef != NULL) );
1452    AOT( (iDepthDistMode == 2) != (pcPicYuvDepthRef != NULL) );
1453    AOT( pcPicYuvDepthTest == NULL );
1454    AOT( pcPicYuvVideoTest == NULL );
1455
1456    m_cRendererModel.setBaseView( iBaseViewSIdx, pcPicYuvVideoTest, pcPicYuvDepthTest, pcPicYuvVideoRef, pcPicYuvDepthRef );
1457  }
1458
1459  m_cRendererModel.setErrorMode( iEncViewSIdx, iEncContent, 0 );
1460  // setup virtual views
1461  Int iNumOfSV  = m_cRenModStrParser.getNumOfModelsForView( iEncViewSIdx, iEncContent );
1462  for (Int iCurView = 0; iCurView < iNumOfSV; iCurView++ )
1463  {
1464    Int iOrgRefBaseViewSIdx;
1465    Int iLeftBaseViewSIdx;
1466    Int iRightBaseViewSIdx;
1467    Int iSynthViewRelNum;
1468    Int iModelNum;
1469    Int iBlendMode;
1470    m_cRenModStrParser.getSingleModelData(iEncViewSIdx, iEncContent, iCurView, iModelNum, iBlendMode,iLeftBaseViewSIdx, iRightBaseViewSIdx, iOrgRefBaseViewSIdx, iSynthViewRelNum );
1471
1472    Int iLeftBaseViewIdx    = -1;
1473    Int iRightBaseViewIdx   = -1;
1474
1475    TComPicYuv* pcPicYuvOrgRef  = NULL;
1476    Int**      ppiShiftLUTLeft  = NULL;
1477    Int**      ppiShiftLUTRight = NULL;
1478    Int**      ppiBaseShiftLUTLeft  = NULL;
1479    Int**      ppiBaseShiftLUTRight = NULL;
1480
1481
1482    Int        iDistToLeft      = -1;
1483
1484    Int iSynthViewIdx = m_cCameraData.synthRelNum2Idx( iSynthViewRelNum );
1485
1486    if ( iLeftBaseViewSIdx != -1 )
1487    {
1488      iLeftBaseViewIdx   = m_cCameraData.getBaseSortedId2Id()   [ iLeftBaseViewSIdx ];
1489      ppiShiftLUTLeft    = m_cCameraData.getSynthViewShiftLUTI()[ iLeftBaseViewIdx  ][ iSynthViewIdx  ];
1490    }
1491
1492    if ( iRightBaseViewSIdx != -1 )
1493    {
1494      iRightBaseViewIdx  = m_cCameraData.getBaseSortedId2Id()   [iRightBaseViewSIdx ];
1495      ppiShiftLUTRight   = m_cCameraData.getSynthViewShiftLUTI()[ iRightBaseViewIdx ][ iSynthViewIdx ];
1496    }
1497
1498    if ( iRightBaseViewSIdx != -1 && iLeftBaseViewSIdx != -1 )
1499    {
1500      iDistToLeft    = m_cCameraData.getRelDistLeft(  iSynthViewIdx , iLeftBaseViewIdx, iRightBaseViewIdx);
1501      ppiBaseShiftLUTLeft  = m_cCameraData.getBaseViewShiftLUTI() [ iLeftBaseViewIdx  ][ iRightBaseViewIdx ];
1502      ppiBaseShiftLUTRight = m_cCameraData.getBaseViewShiftLUTI() [ iRightBaseViewIdx ][ iLeftBaseViewIdx  ];
1503
1504    }
1505
1506    if ( iOrgRefBaseViewSIdx != -1 )
1507    {
1508      pcPicYuvOrgRef = xGetPicYuvFromView( m_cCameraData.getBaseSortedId2Id()[ iOrgRefBaseViewSIdx ] , iPoc, false, false );
1509      AOF ( pcPicYuvOrgRef );
1510    }
1511
1512    m_cRendererModel.setSingleModel( iModelNum, ppiShiftLUTLeft, ppiBaseShiftLUTLeft, ppiShiftLUTRight, ppiBaseShiftLUTRight, iDistToLeft, pcPicYuvOrgRef );
1513  }
1514}
1515#endif
1516
1517
1518
1519/*
1520void TAppEncTop::printRateSummary()
1521{
1522  double time = (double) m_iFrameRcvd / m_iFrameRate;
1523  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
1524#if VERBOSE_RATE
1525  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
1526#endif
1527}
1528*/
1529
1530std::vector<TComPic*> TAppEncTop::getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps )
1531{
1532  std::vector<TComPic*> apcRefPics( sps->getNumberOfUsableInterViewRefs(), (TComPic*)NULL );
1533  for( Int k = 0; k < sps->getNumberOfUsableInterViewRefs(); k++ )
1534  {
1535    TComPic* pcRefPic = xGetPicFromView( sps->getUsableInterViewRef( k ) + viewId, poc, isDepth );
1536    assert( pcRefPic != NULL );
1537    apcRefPics[k] = pcRefPic;
1538  }
1539  return apcRefPics;
1540}
1541
1542TComPic* TAppEncTop::xGetPicFromView( Int viewIdx, Int poc, Bool isDepth )
1543{
1544  assert( ( viewIdx >= 0 ) && ( viewIdx < m_iNumberOfViews ) );
1545
1546  TComList<TComPic*>* apcListPic = (isDepth ?  m_acTEncDepthTopList[viewIdx] : m_acTEncTopList[viewIdx])->getListPic() ;
1547
1548  TComPic* pcPic = NULL;
1549  for(TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++)
1550  {
1551    if( (*it)->getPOC() == poc )
1552    {
1553      pcPic = *it ;
1554      break ;
1555    }
1556  }
1557
1558  return pcPic;
1559};
1560 
1561#if RWTH_SDC_DLT_B0036
1562Void TAppEncTop::xAnalyzeInputBaseDepth(Int iViewIdx, UInt uiNumFrames)
1563{
1564  TComPicYuv*       pcDepthPicYuvOrg = new TComPicYuv;
1565  // allocate original YUV buffer
1566  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1567 
1568  TVideoIOYuv* depthVideoFile = new TVideoIOYuv;
1569 
1570  UInt uiMaxDepthValue = g_uiIBDI_MAX;
1571 
1572  Bool abValidDepths[256];
1573 
1574  depthVideoFile->open( m_pchDepthInputFileList[iViewIdx], false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
1575 
1576  // initialize boolean array
1577  for(Int p=0; p<=uiMaxDepthValue; p++)
1578    abValidDepths[p] = false;
1579 
1580  Int iHeight   = pcDepthPicYuvOrg->getHeight();
1581  Int iWidth    = pcDepthPicYuvOrg->getWidth();
1582  Int iStride   = pcDepthPicYuvOrg->getStride();
1583 
1584  Pel* pInDM    = pcDepthPicYuvOrg->getLumaAddr();
1585 
1586  for(Int uiFrame=0; uiFrame < uiNumFrames; uiFrame++ )
1587  {
1588    depthVideoFile->read( pcDepthPicYuvOrg, m_aiPad, false );
1589   
1590    // check all pixel values
1591    for (Int i=0; i<iHeight; i++)
1592    {
1593      Int rowOffset = i*iStride;
1594     
1595      for (Int j=0; j<iWidth; j++)
1596      {
1597        Pel depthValue = pInDM[rowOffset+j];
1598        abValidDepths[depthValue] = true;
1599      }
1600    }
1601  }
1602 
1603  depthVideoFile->close();
1604 
1605  pcDepthPicYuvOrg->destroy();
1606  delete pcDepthPicYuvOrg;
1607 
1608  // convert boolean array to idx2Depth LUT
1609  UInt* auiIdx2DepthValue = (UInt*) calloc(uiMaxDepthValue, sizeof(UInt));
1610  UInt uiNumDepthValues = 0;
1611  for(UInt p=0; p<=uiMaxDepthValue; p++)
1612  {
1613    if( abValidDepths[p] == true)
1614    {
1615      auiIdx2DepthValue[uiNumDepthValues++] = p;
1616    }
1617  }
1618 
1619  if( uiNumFrames == 0 || ceil(Log2(uiNumDepthValues)) == ceil(Log2(g_uiIBDI_MAX)) )
1620  {
1621    // don't use DLT
1622    m_acTEncDepthTopList[iViewIdx]->setUseDLT(false);
1623    m_acTEncDepthTopList[iViewIdx]->getSPS()->setUseDLT(false);
1624  }
1625 
1626  // assign LUT
1627  if( m_acTEncDepthTopList[iViewIdx]->getUseDLT() )
1628    m_acTEncDepthTopList[iViewIdx]->getSPS()->setDepthLUTs(auiIdx2DepthValue, uiNumDepthValues);
1629  else
1630    m_acTEncDepthTopList[iViewIdx]->getSPS()->setDepthLUTs();
1631 
1632  // free temporary memory
1633  free(auiIdx2DepthValue);
1634}
1635#endif
1636
1637#if MERL_VSP_C0152
1638Void TAppEncTop::setBWVSPLUT(Int iCodedViewIdx, Int gopId, Bool isDepth)
1639{
1640  //first view does not have VSP
1641  if((iCodedViewIdx == 0)) return;
1642
1643  AOT( iCodedViewIdx <= 0);
1644  AOT( iCodedViewIdx >= m_iNumberOfViews );
1645
1646  Int iNeighborViewId = 0;
1647  //setting look-up table
1648  Int* piShiftLUT = m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
1649
1650  if(isDepth)
1651  {
1652    TEncSlice* pcEncSlice = (TEncSlice*) m_acTEncDepthTopList[iCodedViewIdx]->getSliceEncoder();
1653    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT );
1654  }
1655  else
1656  {
1657    TEncSlice* pcEncSlice = (TEncSlice*) m_acTEncTopList[iCodedViewIdx]->getSliceEncoder();
1658    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT );
1659  }
1660
1661}
1662#endif
1663
1664//! \}
Note: See TracBrowser for help on using the repository browser.