source: SHVCSoftware/branches/SHM-1.0-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 1263

Last change on this file since 1263 was 34, checked in by seregin, 12 years ago

Merge with trunk

File size: 42.9 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_iFrameRcvd = 0;
60  m_totalBytes = 0;
61  m_essentialBytes = 0;
62#if SVC_EXTENSION
63  for(UInt layer=0; layer < MAX_LAYERS; layer++)
64  {
65    m_apcTEncTop[layer] = &m_acTEncTop[layer];
66  }
67#endif
68}
69
70TAppEncTop::~TAppEncTop()
71{
72}
73
74#if SVC_EXTENSION
75Void TAppEncTop::xInitLibCfg()
76{
77  for(UInt layer=0; layer<m_numLayers; layer++)
78  {
79    TComVPS vps;
80
81    vps.setMaxTLayers                       ( m_maxTempLayer );
82    vps.setMaxLayers                        ( 1 );
83    for(Int i = 0; i < MAX_TLAYER; i++)
84    {
85      vps.setNumReorderPics                 ( m_numReorderPics[i], i );
86      vps.setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
87    }
88    m_acTEncTop[layer].setVPS(&vps);
89    m_acTEncTop[layer].setFrameRate                    ( m_acLayerCfg[layer].getFrameRate() );
90    m_acTEncTop[layer].setFrameSkip                    ( m_FrameSkip );
91    m_acTEncTop[layer].setSourceWidth                  ( m_acLayerCfg[layer].getSourceWidth() );
92    m_acTEncTop[layer].setSourceHeight                 ( m_acLayerCfg[layer].getSourceHeight() );
93    m_acTEncTop[layer].setCroppingMode                 ( m_acLayerCfg[layer].getCroppingMode() );
94    m_acTEncTop[layer].setCropLeft                     ( m_acLayerCfg[layer].getCropLeft() );
95    m_acTEncTop[layer].setCropRight                    ( m_acLayerCfg[layer].getCropRight() );
96    m_acTEncTop[layer].setCropTop                      ( m_acLayerCfg[layer].getCropTop() );
97    m_acTEncTop[layer].setCropBottom                   ( m_acLayerCfg[layer].getCropBottom() );
98    m_acTEncTop[layer].setFrameToBeEncoded             ( m_iFrameToBeEncoded );
99
100#if REF_IDX_MFM
101    if(layer == 0)
102    {
103      m_acTEncTop[layer].setMFMEnabledFlag(false);
104    }
105    else
106    {
107      m_acTEncTop[layer].setMFMEnabledFlag(true);
108    }
109#endif
110    // set layer ID
111    m_acTEncTop[layer].setLayerId ( layer ); 
112    m_acTEncTop[layer].setNumLayer ( m_numLayers );
113    m_acTEncTop[layer].setLayerEnc(m_apcTEncTop);
114
115
116    //====== Coding Structure ========
117    m_acTEncTop[layer].setIntraPeriod                  ( m_acLayerCfg[layer].m_iIntraPeriod );
118    m_acTEncTop[layer].setDecodingRefreshType          ( m_iDecodingRefreshType );
119    m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
120    m_acTEncTop[layer].setGopList                      ( m_GOPList );
121    m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs );
122    for(Int i = 0; i < MAX_TLAYER; i++)
123    {
124      m_acTEncTop[layer].setNumReorderPics             ( m_numReorderPics[i], i );
125      m_acTEncTop[layer].setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
126    }
127    for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
128    {
129      m_acTEncTop[layer].setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
130    }
131    m_acTEncTop[layer].setQP                           ( m_acLayerCfg[layer].getIntQP() );
132
133    m_acTEncTop[layer].setPad                          ( m_acLayerCfg[layer].getPad() );
134
135    m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
136#if !REMOVE_NSQT
137    m_acTEncTop[layer].setUseNSQT( m_enableNSQT );
138#endif
139    m_acTEncTop[layer].setUseAMP( m_enableAMP );
140
141    //===== Slice ========
142
143    //====== Loop/Deblock Filter ========
144    m_acTEncTop[layer].setLoopFilterDisable            ( m_bLoopFilterDisable       );
145    m_acTEncTop[layer].setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
146    m_acTEncTop[layer].setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
147    m_acTEncTop[layer].setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
148    m_acTEncTop[layer].setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
149
150    //====== Motion search ========
151    m_acTEncTop[layer].setFastSearch                   ( m_iFastSearch  );
152    m_acTEncTop[layer].setSearchRange                  ( m_iSearchRange );
153    m_acTEncTop[layer].setBipredSearchRange            ( m_bipredSearchRange );
154
155    //====== Quality control ========
156    m_acTEncTop[layer].setMaxDeltaQP                   ( m_iMaxDeltaQP  );
157    m_acTEncTop[layer].setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
158
159    m_acTEncTop[layer].setChromaCbQpOffset               ( m_cbQpOffset     );
160    m_acTEncTop[layer].setChromaCrQpOffset            ( m_crQpOffset  );
161
162#if ADAPTIVE_QP_SELECTION
163    m_acTEncTop[layer].setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
164#endif
165
166    Int lowestQP;
167    lowestQP =  - ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) );
168
169    if ((m_iMaxDeltaQP == 0 ) && (m_acLayerCfg[layer].getIntQP() == lowestQP) && (m_useLossless == true))
170    {
171      m_bUseAdaptiveQP = false;
172    }
173    m_acTEncTop[layer].setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
174    m_acTEncTop[layer].setQPAdaptationRange            ( m_iQPAdaptationRange );
175
176    //====== Tool list ========
177    m_acTEncTop[layer].setUseSBACRD                    ( m_bUseSBACRD   );
178    m_acTEncTop[layer].setDeltaQpRD                    ( m_uiDeltaQpRD  );
179    m_acTEncTop[layer].setUseASR                       ( m_bUseASR      );
180    m_acTEncTop[layer].setUseHADME                     ( m_bUseHADME    );
181#if !REMOVE_ALF
182    m_acTEncTop[layer].setUseALF                       ( m_bUseALF      );
183#endif
184    m_acTEncTop[layer].setUseLossless                  ( m_useLossless );
185    m_acTEncTop[layer].setUseLComb                     ( m_bUseLComb    );
186    m_acTEncTop[layer].setdQPs                         ( m_acLayerCfg[layer].getdQPs()        );
187    m_acTEncTop[layer].setUseRDOQ                      ( m_bUseRDOQ     );
188    m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
189    m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
190    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
191    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
192    m_acTEncTop[layer].setUseFastEnc                   ( m_bUseFastEnc  );
193    m_acTEncTop[layer].setUseEarlyCU                   ( m_bUseEarlyCU  ); 
194    m_acTEncTop[layer].setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
195    m_acTEncTop[layer].setUseCbfFastMode            ( m_bUseCbfFastMode  );
196    m_acTEncTop[layer].setUseEarlySkipDetection            ( m_useEarlySkipDetection );
197
198#if !REMOVE_LMCHROMA
199    m_acTEncTop[layer].setUseLMChroma                  ( m_bUseLMChroma );
200#endif
201    m_acTEncTop[layer].setUseTransformSkip             ( m_useTransformSkip      );
202    m_acTEncTop[layer].setUseTransformSkipFast         ( m_useTransformSkipFast  );
203    m_acTEncTop[layer].setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
204    m_acTEncTop[layer].setPCMLog2MinSize          ( m_uiPCMLog2MinSize);
205    m_acTEncTop[layer].setUsePCM                       ( m_usePCM );
206    m_acTEncTop[layer].setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
207    m_acTEncTop[layer].setMaxNumMergeCand              ( m_maxNumMergeCand );
208
209
210    //====== Weighted Prediction ========
211    m_acTEncTop[layer].setUseWP                   ( m_bUseWeightPred      );
212    m_acTEncTop[layer].setWPBiPred                ( m_useWeightedBiPred   );
213    //====== Parallel Merge Estimation ========
214    m_acTEncTop[layer].setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
215
216    //====== Slice ========
217    m_acTEncTop[layer].setSliceMode               ( m_iSliceMode                );
218    m_acTEncTop[layer].setSliceArgument           ( m_iSliceArgument            );
219
220    //====== Dependent Slice ========
221    m_acTEncTop[layer].setDependentSliceMode        ( m_iDependentSliceMode         );
222    m_acTEncTop[layer].setDependentSliceArgument    ( m_iDependentSliceArgument     );
223#if DEPENDENT_SLICES
224#if TILES_WPP_ENTROPYSLICES_FLAGS
225    m_acTEncTop[layer].setEntropySliceEnabledFlag   ( m_entropySliceEnabledFlag );
226#else
227    m_acTEncTop[layer].setCabacIndependentFlag      ( m_bCabacIndependentFlag   );
228#endif
229#endif
230    int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
231    if(m_iDependentSliceMode==SHARP_FIXED_NUMBER_OF_LCU_IN_DEPENDENT_SLICE)
232    {
233#if REMOVE_FGS
234      m_acTEncTop[layer].setDependentSliceArgument ( m_iDependentSliceArgument * iNumPartInCU );
235#else
236      m_acTEncTop[layer].setDependentSliceArgument ( m_iDependentSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
237#endif
238    }
239    if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)
240    {
241#if REMOVE_FGS
242      m_acTEncTop[layer].setSliceArgument ( m_iSliceArgument * iNumPartInCU );
243#else
244      m_acTEncTop[layer].setSliceArgument ( m_iSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
245#endif
246    }
247    if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE)
248    {
249      m_acTEncTop[layer].setSliceArgument ( m_iSliceArgument );
250    }
251
252#if !REMOVE_FGS
253    m_acTEncTop[layer].setSliceGranularity        ( m_iSliceGranularity         );
254#endif
255    if(m_iSliceMode == 0 )
256    {
257      m_bLFCrossSliceBoundaryFlag = true;
258    }
259    m_acTEncTop[layer].setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
260    m_acTEncTop[layer].setUseSAO ( m_bUseSAO );
261    m_acTEncTop[layer].setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
262
263#if SAO_LCU_BOUNDARY
264    m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary);
265#endif
266    m_acTEncTop[layer].setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
267    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
268    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
269
270    m_acTEncTop[layer].setDecodedPictureHashSEIEnabled(m_decodePictureHashSEIEnabled);
271#if RECOVERY_POINT_SEI
272    m_acTEncTop[layer].setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
273#endif
274#if BUFFERING_PERIOD_AND_TIMING_SEI
275    m_acTEncTop[layer].setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
276    m_acTEncTop[layer].setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
277#endif
278    m_acTEncTop[layer].setUniformSpacingIdr          ( m_iUniformSpacingIdr );
279    m_acTEncTop[layer].setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
280    m_acTEncTop[layer].setNumRowsMinus1              ( m_iNumRowsMinus1 );
281    if(m_iUniformSpacingIdr==0)
282    {
283      m_acTEncTop[layer].setColumnWidth              ( m_pchColumnWidth );
284      m_acTEncTop[layer].setRowHeight                ( m_pchRowHeight );
285    }
286    m_acTEncTop[layer].xCheckGSParameters();
287    Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
288    if(uiTilesCount == 1)
289    {
290      m_bLFCrossTileBoundaryFlag = true; 
291    }
292    m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
293    m_acTEncTop[layer].setWaveFrontSynchro           ( m_iWaveFrontSynchro );
294    m_acTEncTop[layer].setWaveFrontSubstreams        ( m_acLayerCfg[layer].m_iWaveFrontSubstreams );
295    m_acTEncTop[layer].setTMVPModeId ( m_TMVPModeId );
296    m_acTEncTop[layer].setUseScalingListId           ( m_useScalingListId  );
297    m_acTEncTop[layer].setScalingListFile            ( m_scalingListFile   );
298    m_acTEncTop[layer].setSignHideFlag(m_signHideFlag);
299#if !REMOVE_ALF
300    m_acTEncTop[layer].setALFLowLatencyEncoding( m_alfLowLatencyEncoding );
301#endif
302    m_acTEncTop[layer].setUseRateCtrl     ( m_enableRateCtrl);
303    m_acTEncTop[layer].setTargetBitrate   ( m_targetBitrate);
304    m_acTEncTop[layer].setNumLCUInUnit    ( m_numLCUInUnit);
305    m_acTEncTop[layer].setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
306    m_acTEncTop[layer].setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue);
307#if RECALCULATE_QP_ACCORDING_LAMBDA
308    m_acTEncTop[layer].setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
309#endif
310#if ACTIVE_PARAMETER_SETS_SEI_MESSAGE
311    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
312#endif
313#if SUPPORT_FOR_VUI
314    m_acTEncTop[layer].setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
315    m_acTEncTop[layer].setAspectRatioIdc( m_aspectRatioIdc );
316    m_acTEncTop[layer].setSarWidth( m_sarWidth );
317    m_acTEncTop[layer].setSarHeight( m_sarHeight );
318    m_acTEncTop[layer].setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
319    m_acTEncTop[layer].setOverscanAppropriateFlag( m_overscanAppropriateFlag );
320    m_acTEncTop[layer].setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
321    m_acTEncTop[layer].setVideoFormat( m_videoFormat );
322    m_acTEncTop[layer].setVideoFullRangeFlag( m_videoFullRangeFlag );
323    m_acTEncTop[layer].setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
324    m_acTEncTop[layer].setColourPrimaries( m_colourPrimaries );
325    m_acTEncTop[layer].setTransferCharacteristics( m_transferCharacteristics );
326    m_acTEncTop[layer].setMatrixCoefficients( m_matrixCoefficients );
327    m_acTEncTop[layer].setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
328    m_acTEncTop[layer].setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
329    m_acTEncTop[layer].setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
330    m_acTEncTop[layer].setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
331    m_acTEncTop[layer].setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
332    m_acTEncTop[layer].setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
333    m_acTEncTop[layer].setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
334    m_acTEncTop[layer].setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
335    m_acTEncTop[layer].setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
336    m_acTEncTop[layer].setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
337    m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
338#endif
339#if REF_IDX_FRAMEWORK
340    m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled);
341#endif
342  }
343}
344#else
345Void TAppEncTop::xInitLibCfg()
346{
347  TComVPS vps;
348 
349  vps.setMaxTLayers                       ( m_maxTempLayer );
350  vps.setMaxLayers                        ( 1 );
351  for(Int i = 0; i < MAX_TLAYER; i++)
352  {
353    vps.setNumReorderPics                 ( m_numReorderPics[i], i );
354    vps.setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
355  }
356  m_cTEncTop.setVPS(&vps);
357  m_cTEncTop.setFrameRate                    ( m_iFrameRate );
358  m_cTEncTop.setFrameSkip                    ( m_FrameSkip );
359  m_cTEncTop.setSourceWidth                  ( m_iSourceWidth );
360  m_cTEncTop.setSourceHeight                 ( m_iSourceHeight );
361  m_cTEncTop.setCroppingMode                 ( m_croppingMode );
362  m_cTEncTop.setCropLeft                     ( m_cropLeft );
363  m_cTEncTop.setCropRight                    ( m_cropRight );
364  m_cTEncTop.setCropTop                      ( m_cropTop );
365  m_cTEncTop.setCropBottom                   ( m_cropBottom );
366  m_cTEncTop.setFrameToBeEncoded             ( m_iFrameToBeEncoded );
367 
368  //====== Coding Structure ========
369  m_cTEncTop.setIntraPeriod                  ( m_iIntraPeriod );
370  m_cTEncTop.setDecodingRefreshType          ( m_iDecodingRefreshType );
371  m_cTEncTop.setGOPSize                      ( m_iGOPSize );
372  m_cTEncTop.setGopList                      ( m_GOPList );
373  m_cTEncTop.setExtraRPSs                    ( m_extraRPSs );
374  for(Int i = 0; i < MAX_TLAYER; i++)
375  {
376    m_cTEncTop.setNumReorderPics             ( m_numReorderPics[i], i );
377    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
378  }
379  for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
380  {
381    m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
382  }
383  m_cTEncTop.setQP                           ( m_iQP );
384 
385  m_cTEncTop.setPad                          ( m_aiPad );
386   
387  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
388#if !REMOVE_NSQT
389  m_cTEncTop.setUseNSQT( m_enableNSQT );
390#endif
391  m_cTEncTop.setUseAMP( m_enableAMP );
392 
393  //===== Slice ========
394 
395  //====== Loop/Deblock Filter ========
396  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
397  m_cTEncTop.setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
398  m_cTEncTop.setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
399  m_cTEncTop.setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
400  m_cTEncTop.setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
401
402  //====== Motion search ========
403  m_cTEncTop.setFastSearch                   ( m_iFastSearch  );
404  m_cTEncTop.setSearchRange                  ( m_iSearchRange );
405  m_cTEncTop.setBipredSearchRange            ( m_bipredSearchRange );
406
407  //====== Quality control ========
408  m_cTEncTop.setMaxDeltaQP                   ( m_iMaxDeltaQP  );
409  m_cTEncTop.setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
410
411  m_cTEncTop.setChromaCbQpOffset               ( m_cbQpOffset     );
412  m_cTEncTop.setChromaCrQpOffset            ( m_crQpOffset  );
413
414#if ADAPTIVE_QP_SELECTION
415  m_cTEncTop.setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
416#endif
417
418  Int lowestQP;
419  lowestQP =  - ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) );
420
421  if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))
422  {
423    m_bUseAdaptiveQP = false;
424  }
425  m_cTEncTop.setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
426  m_cTEncTop.setQPAdaptationRange            ( m_iQPAdaptationRange );
427 
428  //====== Tool list ========
429  m_cTEncTop.setUseSBACRD                    ( m_bUseSBACRD   );
430  m_cTEncTop.setDeltaQpRD                    ( m_uiDeltaQpRD  );
431  m_cTEncTop.setUseASR                       ( m_bUseASR      );
432  m_cTEncTop.setUseHADME                     ( m_bUseHADME    );
433#if !REMOVE_ALF
434  m_cTEncTop.setUseALF                       ( m_bUseALF      );
435#endif
436  m_cTEncTop.setUseLossless                  ( m_useLossless );
437  m_cTEncTop.setUseLComb                     ( m_bUseLComb    );
438  m_cTEncTop.setdQPs                         ( m_aidQP        );
439  m_cTEncTop.setUseRDOQ                      ( m_bUseRDOQ     );
440  m_cTEncTop.setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
441  m_cTEncTop.setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
442  m_cTEncTop.setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
443  m_cTEncTop.setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
444  m_cTEncTop.setUseFastEnc                   ( m_bUseFastEnc  );
445  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  ); 
446  m_cTEncTop.setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
447  m_cTEncTop.setUseCbfFastMode            ( m_bUseCbfFastMode  );
448  m_cTEncTop.setUseEarlySkipDetection            ( m_useEarlySkipDetection );
449
450#if !REMOVE_LMCHROMA
451  m_cTEncTop.setUseLMChroma                  ( m_bUseLMChroma );
452#endif
453  m_cTEncTop.setUseTransformSkip             ( m_useTransformSkip      );
454  m_cTEncTop.setUseTransformSkipFast         ( m_useTransformSkipFast  );
455  m_cTEncTop.setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
456  m_cTEncTop.setPCMLog2MinSize          ( m_uiPCMLog2MinSize);
457  m_cTEncTop.setUsePCM                       ( m_usePCM );
458  m_cTEncTop.setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
459  m_cTEncTop.setMaxNumMergeCand              ( m_maxNumMergeCand );
460 
461
462  //====== Weighted Prediction ========
463  m_cTEncTop.setUseWP                   ( m_bUseWeightPred      );
464  m_cTEncTop.setWPBiPred                ( m_useWeightedBiPred   );
465  //====== Parallel Merge Estimation ========
466  m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
467
468  //====== Slice ========
469  m_cTEncTop.setSliceMode               ( m_iSliceMode                );
470  m_cTEncTop.setSliceArgument           ( m_iSliceArgument            );
471
472  //====== Dependent Slice ========
473  m_cTEncTop.setDependentSliceMode        ( m_iDependentSliceMode         );
474  m_cTEncTop.setDependentSliceArgument    ( m_iDependentSliceArgument     );
475#if DEPENDENT_SLICES
476#if TILES_WPP_ENTROPYSLICES_FLAGS
477  m_cTEncTop.setEntropySliceEnabledFlag   ( m_entropySliceEnabledFlag );
478#else
479  m_cTEncTop.setCabacIndependentFlag      ( m_bCabacIndependentFlag   );
480#endif
481#endif
482  int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
483  if(m_iDependentSliceMode==SHARP_FIXED_NUMBER_OF_LCU_IN_DEPENDENT_SLICE)
484  {
485#if REMOVE_FGS
486    m_cTEncTop.setDependentSliceArgument ( m_iDependentSliceArgument * iNumPartInCU );
487#else
488    m_cTEncTop.setDependentSliceArgument ( m_iDependentSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
489#endif
490  }
491  if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)
492  {
493#if REMOVE_FGS
494    m_cTEncTop.setSliceArgument ( m_iSliceArgument * iNumPartInCU );
495#else
496    m_cTEncTop.setSliceArgument ( m_iSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
497#endif
498  }
499  if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE)
500  {
501    m_cTEncTop.setSliceArgument ( m_iSliceArgument );
502  }
503 
504#if !REMOVE_FGS
505  m_cTEncTop.setSliceGranularity        ( m_iSliceGranularity         );
506#endif
507  if(m_iSliceMode == 0 )
508  {
509    m_bLFCrossSliceBoundaryFlag = true;
510  }
511  m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
512  m_cTEncTop.setUseSAO ( m_bUseSAO );
513  m_cTEncTop.setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
514
515#if SAO_LCU_BOUNDARY
516  m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
517#endif
518  m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
519  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
520  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
521
522  m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodePictureHashSEIEnabled);
523#if RECOVERY_POINT_SEI
524  m_cTEncTop.setRecoveryPointSEIEnabled( m_recoveryPointSEIEnabled );
525#endif
526#if BUFFERING_PERIOD_AND_TIMING_SEI
527  m_cTEncTop.setBufferingPeriodSEIEnabled( m_bufferingPeriodSEIEnabled );
528  m_cTEncTop.setPictureTimingSEIEnabled( m_pictureTimingSEIEnabled );
529#endif
530  m_cTEncTop.setUniformSpacingIdr          ( m_iUniformSpacingIdr );
531  m_cTEncTop.setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
532  m_cTEncTop.setNumRowsMinus1              ( m_iNumRowsMinus1 );
533  if(m_iUniformSpacingIdr==0)
534  {
535    m_cTEncTop.setColumnWidth              ( m_pchColumnWidth );
536    m_cTEncTop.setRowHeight                ( m_pchRowHeight );
537  }
538  m_cTEncTop.xCheckGSParameters();
539  Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
540  if(uiTilesCount == 1)
541  {
542    m_bLFCrossTileBoundaryFlag = true; 
543  }
544  m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
545  m_cTEncTop.setWaveFrontSynchro           ( m_iWaveFrontSynchro );
546  m_cTEncTop.setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
547  m_cTEncTop.setTMVPModeId ( m_TMVPModeId );
548  m_cTEncTop.setUseScalingListId           ( m_useScalingListId  );
549  m_cTEncTop.setScalingListFile            ( m_scalingListFile   );
550  m_cTEncTop.setSignHideFlag(m_signHideFlag);
551#if !REMOVE_ALF
552  m_cTEncTop.setALFLowLatencyEncoding( m_alfLowLatencyEncoding );
553#endif
554  m_cTEncTop.setUseRateCtrl     ( m_enableRateCtrl);
555  m_cTEncTop.setTargetBitrate   ( m_targetBitrate);
556  m_cTEncTop.setNumLCUInUnit    ( m_numLCUInUnit);
557  m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
558  m_cTEncTop.setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue);
559#if RECALCULATE_QP_ACCORDING_LAMBDA
560  m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
561#endif
562#if ACTIVE_PARAMETER_SETS_SEI_MESSAGE
563  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
564#endif
565#if SUPPORT_FOR_VUI
566  m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
567  m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc );
568  m_cTEncTop.setSarWidth( m_sarWidth );
569  m_cTEncTop.setSarHeight( m_sarHeight );
570  m_cTEncTop.setOverscanInfoPresentFlag( m_overscanInfoPresentFlag );
571  m_cTEncTop.setOverscanAppropriateFlag( m_overscanAppropriateFlag );
572  m_cTEncTop.setVideoSignalTypePresentFlag( m_videoSignalTypePresentFlag );
573  m_cTEncTop.setVideoFormat( m_videoFormat );
574  m_cTEncTop.setVideoFullRangeFlag( m_videoFullRangeFlag );
575  m_cTEncTop.setColourDescriptionPresentFlag( m_colourDescriptionPresentFlag );
576  m_cTEncTop.setColourPrimaries( m_colourPrimaries );
577  m_cTEncTop.setTransferCharacteristics( m_transferCharacteristics );
578  m_cTEncTop.setMatrixCoefficients( m_matrixCoefficients );
579  m_cTEncTop.setChromaLocInfoPresentFlag( m_chromaLocInfoPresentFlag );
580  m_cTEncTop.setChromaSampleLocTypeTopField( m_chromaSampleLocTypeTopField );
581  m_cTEncTop.setChromaSampleLocTypeBottomField( m_chromaSampleLocTypeBottomField );
582  m_cTEncTop.setNeutralChromaIndicationFlag( m_neutralChromaIndicationFlag );
583  m_cTEncTop.setBitstreamRestrictionFlag( m_bitstreamRestrictionFlag );
584  m_cTEncTop.setTilesFixedStructureFlag( m_tilesFixedStructureFlag );
585  m_cTEncTop.setMotionVectorsOverPicBoundariesFlag( m_motionVectorsOverPicBoundariesFlag );
586  m_cTEncTop.setMaxBytesPerPicDenom( m_maxBytesPerPicDenom );
587  m_cTEncTop.setMaxBitsPerMinCuDenom( m_maxBitsPerMinCuDenom );
588  m_cTEncTop.setLog2MaxMvLengthHorizontal( m_log2MaxMvLengthHorizontal );
589  m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
590#endif
591}
592#endif
593
594Void TAppEncTop::xCreateLib()
595{
596  // Video I/O
597#if SVC_EXTENSION
598  // initialize global variables
599  initROM();
600
601  for(UInt layer=0; layer<m_numLayers; layer++)
602  {
603    m_acTVideoIOYuvInputFile[layer].open( (char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
604    m_acTVideoIOYuvInputFile[layer].skipFrames(m_FrameSkip, m_acLayerCfg[layer].getSourceWidth() - m_acLayerCfg[layer].getPad()[0], m_acLayerCfg[layer].getSourceHeight() - m_acLayerCfg[layer].getPad()[1]);
605
606    if (!m_acLayerCfg[layer].getReconFile().empty())
607    {
608      m_acTVideoIOYuvReconFile[layer].open((char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
609    }
610
611    m_acTEncTop[layer].create();
612  }
613#else
614  m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
615  m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
616
617  if (m_pchReconFile)
618    m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
619 
620  // Neo Decoder
621  m_cTEncTop.create();
622#endif
623}
624
625Void TAppEncTop::xDestroyLib()
626{
627  // Video I/O
628#if SVC_EXTENSION
629  // destroy ROM
630  destroyROM();
631
632  for(UInt layer=0; layer<m_numLayers; layer++)
633  {
634    m_acTVideoIOYuvInputFile[layer].close();
635    m_acTVideoIOYuvReconFile[layer].close();
636
637    m_acTEncTop[layer].destroy();
638  }
639#else
640  m_cTVideoIOYuvInputFile.close();
641  m_cTVideoIOYuvReconFile.close();
642 
643  // Neo Decoder
644  m_cTEncTop.destroy();
645#endif
646}
647
648Void TAppEncTop::xInitLib()
649{
650#if SVC_EXTENSION
651  for(UInt layer=0; layer<m_numLayers; layer++)
652  {
653    m_acTEncTop[layer].init();
654  }
655#else
656  m_cTEncTop.init();
657#endif
658}
659
660// ====================================================================================================================
661// Public member functions
662// ====================================================================================================================
663
664/**
665 - create internal class
666 - initialize internal variable
667 - until the end of input YUV file, call encoding function in TEncTop class
668 - delete allocated buffers
669 - destroy internal class
670 .
671 */
672#if SVC_EXTENSION
673Void TAppEncTop::encode()
674{
675  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
676  if (!bitstreamFile)
677  {
678    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
679    exit(EXIT_FAILURE);
680  }
681
682  TComPicYuv*       pcPicYuvOrg [MAX_LAYERS];
683  TComPicYuv*       pcPicYuvRec = NULL;
684 
685  // initialize internal class & member variables
686
687  xInitLibCfg();
688  xCreateLib();
689  xInitLib();
690
691  // main encoder loop
692  Int   iNumEncoded, iTotalNumEncoded;
693  Bool  bEos = false, bBaseEos = false;
694 
695  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
696
697  for(UInt layer=0; layer<m_numLayers; layer++)
698  {
699    // allocate original YUV buffer
700    pcPicYuvOrg[layer] = new TComPicYuv;
701#if SVC_UPSAMPLING
702    pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
703#else
704    pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
705#endif
706  }
707
708  Bool bFirstFrame = true;
709  while ( !bEos )
710  {
711    // Read enough frames
712    Bool bFramesReadyToCode = false;
713    while(!bFramesReadyToCode)
714    {
715      for(UInt layer=0; layer<m_numLayers; layer++)
716      {
717        // get buffers
718        xGetBuffer(pcPicYuvRec, layer);
719
720        m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], m_acLayerCfg[layer].getPad() );
721   
722        if(layer == m_numLayers-1)
723        {
724          // increase number of received frames
725          m_iFrameRcvd++;
726          // check end of file
727          bEos = ( m_acTVideoIOYuvInputFile[layer].isEof() == 1 ?   true : bBaseEos? true : bEos  );
728          bEos = ( m_iFrameRcvd == m_iFrameToBeEncoded ?    true : bEos   );
729        }
730        else
731        {
732          // check end of file of base layers
733          bBaseEos = ( m_acTVideoIOYuvInputFile[layer].isEof() == 1 ?   true : bBaseEos  );
734        }
735        m_acTEncTop[layer].encodePrep( bEos, pcPicYuvOrg[layer] );
736      }
737
738      bFramesReadyToCode = !(!bFirstFrame && ( m_acTEncTop[m_numLayers-1].getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos );
739    }
740
741    // loop through frames in one GOP
742    for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ )
743    {
744      // layer by layer for each frame
745      for(UInt layer=0; layer<m_numLayers; layer++)
746      {
747        // call encoding function for one frame
748        m_acTEncTop[layer].encode( pcPicYuvOrg[layer], m_acListPicYuvRec[layer], 
749          outputAccessUnits, iPicIdInGOP );
750      }
751    }
752
753    iTotalNumEncoded = 0;
754    for(UInt layer=0; layer<m_numLayers; layer++)
755    {
756      // write bistream to file if necessary
757      iNumEncoded = m_acTEncTop[layer].getNumPicRcvd();
758      if ( iNumEncoded > 0 ) 
759      {
760        xWriteRecon(layer, iNumEncoded);
761        iTotalNumEncoded += iNumEncoded;
762      }
763      m_acTEncTop[layer].setNumPicRcvd( 0 );
764    }
765
766    // write bitstream out
767    if(iTotalNumEncoded)
768    {
769      xWriteStream(bitstreamFile, iTotalNumEncoded, outputAccessUnits);
770      outputAccessUnits.clear();
771    }
772
773    // print out summary
774    if (bEos)
775    {
776      printOutSummary();
777    }
778
779    bFirstFrame = false;
780  }
781
782  // delete original YUV buffer
783  for(UInt layer=0; layer<m_numLayers; layer++)
784  {
785    pcPicYuvOrg[layer]->destroy();
786    delete pcPicYuvOrg[layer];
787    pcPicYuvOrg[layer] = NULL;
788
789    // delete used buffers in encoder class
790    m_acTEncTop[layer].deletePicBuffer();
791  }
792 
793  // delete buffers & classes
794  xDeleteBuffer();
795  xDestroyLib();
796 
797  printRateSummary();
798
799  return;
800}
801
802
803Void TAppEncTop::printOutSummary()
804{
805  UInt layer;
806
807  // set frame rate
808  for(layer = 0; layer < m_numLayers; layer++)
809  {
810    m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
811    m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
812    m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
813    m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
814  }
815
816  //-- all
817  printf( "\n\nSUMMARY --------------------------------------------------------\n" );
818  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
819  for(layer = 0; layer < m_numLayers; layer++)
820  {
821    m_gcAnalyzeAll[layer].printOut('a', layer);
822  }
823   
824  printf( "\n\nI Slices--------------------------------------------------------\n" );
825  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
826  for(layer = 0; layer < m_numLayers; layer++)
827  {
828    m_gcAnalyzeI[layer].printOut('i', layer);
829  }
830   
831  printf( "\n\nP Slices--------------------------------------------------------\n" );
832  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
833  for(layer = 0; layer < m_numLayers; layer++)
834  {
835    m_gcAnalyzeP[layer].printOut('p', layer);
836  }
837   
838  printf( "\n\nB Slices--------------------------------------------------------\n" );
839  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
840  for(layer = 0; layer < m_numLayers; layer++)
841  {
842    m_gcAnalyzeB[layer].printOut('b', layer);
843  }
844}
845
846#else
847Void TAppEncTop::encode()
848{
849  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
850  if (!bitstreamFile)
851  {
852    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
853    exit(EXIT_FAILURE);
854  }
855
856  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
857  TComPicYuv*       pcPicYuvRec = NULL;
858 
859  // initialize internal class & member variables
860  xInitLibCfg();
861  xCreateLib();
862  xInitLib();
863 
864  // main encoder loop
865  Int   iNumEncoded = 0;
866  Bool  bEos = false;
867 
868  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
869
870  // allocate original YUV buffer
871  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
872 
873  while ( !bEos )
874  {
875    // get buffers
876    xGetBuffer(pcPicYuvRec);
877
878    // read input YUV file
879    m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad );
880   
881    // increase number of received frames
882    m_iFrameRcvd++;
883   
884    // check end of file
885    bEos = ( m_cTVideoIOYuvInputFile.isEof() == 1 ?   true : false  );
886    bEos = ( m_iFrameRcvd == m_iFrameToBeEncoded ?    true : bEos   );
887   
888    // call encoding function for one frame
889    m_cTEncTop.encode( bEos, pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
890   
891    // write bistream to file if necessary
892    if ( iNumEncoded > 0 )
893    {
894      xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
895      outputAccessUnits.clear();
896    }
897  }
898  // delete original YUV buffer
899  pcPicYuvOrg->destroy();
900  delete pcPicYuvOrg;
901  pcPicYuvOrg = NULL;
902 
903  // delete used buffers in encoder class
904  m_cTEncTop.deletePicBuffer();
905 
906  // delete buffers & classes
907  xDeleteBuffer();
908  xDestroyLib();
909 
910  printRateSummary();
911
912  return;
913}
914#endif
915
916// ====================================================================================================================
917// Protected member functions
918// ====================================================================================================================
919
920/**
921 - application has picture buffer list with size of GOP
922 - picture buffer list acts as ring buffer
923 - end of the list has the latest picture
924 .
925 */
926#if SVC_EXTENSION
927Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
928{
929  assert( m_iGOPSize > 0 );
930 
931  // org. buffer
932  if ( m_acListPicYuvRec[layer].size() == (UInt)m_iGOPSize )
933  {
934    rpcPicYuvRec = m_acListPicYuvRec[layer].popFront();
935
936  }
937  else
938  {
939    rpcPicYuvRec = new TComPicYuv;
940   
941#if SVC_UPSAMPLING
942    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
943#else
944    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
945#endif
946
947  }
948  m_acListPicYuvRec[layer].pushBack( rpcPicYuvRec );
949}
950
951Void TAppEncTop::xDeleteBuffer( )
952{
953  for(UInt layer=0; layer<m_numLayers; layer++)
954  {
955    TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_acListPicYuvRec[layer].begin();
956   
957    Int iSize = Int( m_acListPicYuvRec[layer].size() );
958   
959    for ( Int i = 0; i < iSize; i++ )
960    {
961      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
962      pcPicYuvRec->destroy();
963      delete pcPicYuvRec; pcPicYuvRec = NULL;
964    }
965  } 
966}
967
968
969
970Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
971{
972  Int i;
973 
974  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
975 
976  for ( i = 0; i < iNumEncoded; i++ )
977  {
978    --iterPicYuvRec;
979  }
980 
981  for ( i = 0; i < iNumEncoded; i++ )
982  {
983    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
984    if (!m_acLayerCfg[layer].getReconFile().empty())
985    {
986      m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getCropLeft(), m_acLayerCfg[layer].getCropRight(), 
987        m_acLayerCfg[layer].getCropTop(), m_acLayerCfg[layer].getCropBottom() );
988    }
989  }
990}
991
992
993Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
994{
995  Int i;
996 
997  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
998 
999  for ( i = 0; i < iNumEncoded; i++ )
1000  {
1001    const AccessUnit& au = *(iterBitstream++);
1002    const vector<unsigned>& stats = writeAnnexB(bitstreamFile, au);
1003    rateStatsAccum(au, stats);
1004  }
1005}
1006
1007#else // SVC_EXTENSION
1008Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
1009{
1010  assert( m_iGOPSize > 0 );
1011 
1012  // org. buffer
1013  if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize )
1014  {
1015    rpcPicYuvRec = m_cListPicYuvRec.popFront();
1016
1017  }
1018  else
1019  {
1020    rpcPicYuvRec = new TComPicYuv;
1021   
1022    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1023
1024  }
1025  m_cListPicYuvRec.pushBack( rpcPicYuvRec );
1026}
1027
1028Void TAppEncTop::xDeleteBuffer( )
1029{
1030  TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
1031 
1032  Int iSize = Int( m_cListPicYuvRec.size() );
1033 
1034  for ( Int i = 0; i < iSize; i++ )
1035  {
1036    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1037    pcPicYuvRec->destroy();
1038    delete pcPicYuvRec; pcPicYuvRec = NULL;
1039  }
1040 
1041}
1042
1043/** \param iNumEncoded  number of encoded frames
1044 */
1045Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
1046{
1047  Int i;
1048 
1049  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
1050  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
1051 
1052  for ( i = 0; i < iNumEncoded; i++ )
1053  {
1054    --iterPicYuvRec;
1055  }
1056 
1057  for ( i = 0; i < iNumEncoded; i++ )
1058  {
1059    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1060    if (m_pchReconFile)
1061    {
1062      m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_cropLeft, m_cropRight, m_cropTop, m_cropBottom );
1063    }
1064
1065    const AccessUnit& au = *(iterBitstream++);
1066    const vector<unsigned>& stats = writeAnnexB(bitstreamFile, au);
1067    rateStatsAccum(au, stats);
1068  }
1069}
1070#endif
1071
1072/**
1073 *
1074 */
1075void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<unsigned>& annexBsizes)
1076{
1077  AccessUnit::const_iterator it_au = au.begin();
1078  vector<unsigned>::const_iterator it_stats = annexBsizes.begin();
1079
1080  for (; it_au != au.end(); it_au++, it_stats++)
1081  {
1082    switch ((*it_au)->m_nalUnitType)
1083    {
1084#if NAL_UNIT_TYPES_J1003_D7
1085    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1086    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1087    case NAL_UNIT_CODED_SLICE_TLA:
1088    case NAL_UNIT_CODED_SLICE_TSA_N:
1089    case NAL_UNIT_CODED_SLICE_STSA_R:
1090    case NAL_UNIT_CODED_SLICE_STSA_N:
1091    case NAL_UNIT_CODED_SLICE_BLA:
1092    case NAL_UNIT_CODED_SLICE_BLANT:
1093    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1094    case NAL_UNIT_CODED_SLICE_IDR:
1095    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1096    case NAL_UNIT_CODED_SLICE_CRA:
1097    case NAL_UNIT_CODED_SLICE_DLP:
1098    case NAL_UNIT_CODED_SLICE_TFD:
1099#else
1100    case NAL_UNIT_CODED_SLICE:
1101    case NAL_UNIT_CODED_SLICE_TFD:
1102    case NAL_UNIT_CODED_SLICE_TLA:
1103    case NAL_UNIT_CODED_SLICE_CRA:
1104    case NAL_UNIT_CODED_SLICE_CRANT:
1105    case NAL_UNIT_CODED_SLICE_BLA:
1106    case NAL_UNIT_CODED_SLICE_BLANT:
1107    case NAL_UNIT_CODED_SLICE_IDR:
1108#endif
1109    case NAL_UNIT_VPS:
1110    case NAL_UNIT_SPS:
1111    case NAL_UNIT_PPS:
1112      m_essentialBytes += *it_stats;
1113      break;
1114    default:
1115      break;
1116    }
1117
1118    m_totalBytes += *it_stats;
1119  }
1120}
1121
1122void TAppEncTop::printRateSummary()
1123{
1124#if SVC_EXTENSION
1125  double time = (double) m_iFrameRcvd / m_acLayerCfg[m_numLayers-1].getFrameRate();
1126#else
1127  double time = (double) m_iFrameRcvd / m_iFrameRate;
1128#endif
1129  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
1130#if VERBOSE_RATE
1131  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
1132#endif
1133}
1134
1135//! \}
Note: See TracBrowser for help on using the repository browser.