source: SHVCSoftware/branches/SHM-1.1-dev/source/App/TAppEncoder/TAppEncTop.cpp @ 854

Last change on this file since 854 was 38, checked in by seregin, 12 years ago

AVC_SYNTAX: initial porting of the AVC metadata file reading

File size: 43.4 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#if AVC_SYNTAX
709  if( !m_BLSyntaxFile )
710  {
711    printf( "Wrong base layer syntax input file\n" );
712    exit(EXIT_FAILURE);
713  }
714  fstream streamSyntaxFile( m_BLSyntaxFile, fstream::in | fstream::binary );
715  if( !streamSyntaxFile.good() )
716  {
717    printf( "Base layer syntax input reading error\n" );
718    exit(EXIT_FAILURE);
719  }
720  m_acTEncTop[0].setBLSyntaxFile( &streamSyntaxFile );
721#endif
722
723  Bool bFirstFrame = true;
724  while ( !bEos )
725  {
726    // Read enough frames
727    Bool bFramesReadyToCode = false;
728    while(!bFramesReadyToCode)
729    {
730      for(UInt layer=0; layer<m_numLayers; layer++)
731      {
732        // get buffers
733        xGetBuffer(pcPicYuvRec, layer);
734
735        m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], m_acLayerCfg[layer].getPad() );
736   
737        if(layer == m_numLayers-1)
738        {
739          // increase number of received frames
740          m_iFrameRcvd++;
741          // check end of file
742          bEos = ( m_acTVideoIOYuvInputFile[layer].isEof() == 1 ?   true : bBaseEos? true : bEos  );
743          bEos = ( m_iFrameRcvd == m_iFrameToBeEncoded ?    true : bEos   );
744        }
745        else
746        {
747          // check end of file of base layers
748          bBaseEos = ( m_acTVideoIOYuvInputFile[layer].isEof() == 1 ?   true : bBaseEos  );
749        }
750        m_acTEncTop[layer].encodePrep( bEos, pcPicYuvOrg[layer] );
751      }
752
753      bFramesReadyToCode = !(!bFirstFrame && ( m_acTEncTop[m_numLayers-1].getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos );
754    }
755
756    // loop through frames in one GOP
757    for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ )
758    {
759      // layer by layer for each frame
760      for(UInt layer=0; layer<m_numLayers; layer++)
761      {
762        // call encoding function for one frame
763        m_acTEncTop[layer].encode( pcPicYuvOrg[layer], m_acListPicYuvRec[layer], 
764          outputAccessUnits, iPicIdInGOP );
765      }
766    }
767
768    iTotalNumEncoded = 0;
769    for(UInt layer=0; layer<m_numLayers; layer++)
770    {
771      // write bistream to file if necessary
772      iNumEncoded = m_acTEncTop[layer].getNumPicRcvd();
773      if ( iNumEncoded > 0 ) 
774      {
775        xWriteRecon(layer, iNumEncoded);
776        iTotalNumEncoded += iNumEncoded;
777      }
778      m_acTEncTop[layer].setNumPicRcvd( 0 );
779    }
780
781    // write bitstream out
782    if(iTotalNumEncoded)
783    {
784      xWriteStream(bitstreamFile, iTotalNumEncoded, outputAccessUnits);
785      outputAccessUnits.clear();
786    }
787
788    // print out summary
789    if (bEos)
790    {
791      printOutSummary();
792    }
793
794    bFirstFrame = false;
795  }
796
797  // delete original YUV buffer
798  for(UInt layer=0; layer<m_numLayers; layer++)
799  {
800    pcPicYuvOrg[layer]->destroy();
801    delete pcPicYuvOrg[layer];
802    pcPicYuvOrg[layer] = NULL;
803
804    // delete used buffers in encoder class
805    m_acTEncTop[layer].deletePicBuffer();
806  }
807 
808#if AVC_SYNTAX
809  if( streamSyntaxFile.is_open() )
810  {
811    streamSyntaxFile.close();
812  }
813#endif
814
815  // delete buffers & classes
816  xDeleteBuffer();
817  xDestroyLib();
818 
819  printRateSummary();
820
821  return;
822}
823
824
825Void TAppEncTop::printOutSummary()
826{
827  UInt layer;
828
829  // set frame rate
830  for(layer = 0; layer < m_numLayers; layer++)
831  {
832    m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
833    m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
834    m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
835    m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
836  }
837
838  //-- all
839  printf( "\n\nSUMMARY --------------------------------------------------------\n" );
840  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
841  for(layer = 0; layer < m_numLayers; layer++)
842  {
843    m_gcAnalyzeAll[layer].printOut('a', layer);
844  }
845   
846  printf( "\n\nI Slices--------------------------------------------------------\n" );
847  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
848  for(layer = 0; layer < m_numLayers; layer++)
849  {
850    m_gcAnalyzeI[layer].printOut('i', layer);
851  }
852   
853  printf( "\n\nP Slices--------------------------------------------------------\n" );
854  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
855  for(layer = 0; layer < m_numLayers; layer++)
856  {
857    m_gcAnalyzeP[layer].printOut('p', layer);
858  }
859   
860  printf( "\n\nB Slices--------------------------------------------------------\n" );
861  printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
862  for(layer = 0; layer < m_numLayers; layer++)
863  {
864    m_gcAnalyzeB[layer].printOut('b', layer);
865  }
866}
867
868#else
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*       pcPicYuvRec = NULL;
880 
881  // initialize internal class & member variables
882  xInitLibCfg();
883  xCreateLib();
884  xInitLib();
885 
886  // main encoder loop
887  Int   iNumEncoded = 0;
888  Bool  bEos = false;
889 
890  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
891
892  // allocate original YUV buffer
893  pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
894 
895  while ( !bEos )
896  {
897    // get buffers
898    xGetBuffer(pcPicYuvRec);
899
900    // read input YUV file
901    m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, m_aiPad );
902   
903    // increase number of received frames
904    m_iFrameRcvd++;
905   
906    // check end of file
907    bEos = ( m_cTVideoIOYuvInputFile.isEof() == 1 ?   true : false  );
908    bEos = ( m_iFrameRcvd == m_iFrameToBeEncoded ?    true : bEos   );
909   
910    // call encoding function for one frame
911    m_cTEncTop.encode( bEos, pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
912   
913    // write bistream to file if necessary
914    if ( iNumEncoded > 0 )
915    {
916      xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits);
917      outputAccessUnits.clear();
918    }
919  }
920  // delete original YUV buffer
921  pcPicYuvOrg->destroy();
922  delete pcPicYuvOrg;
923  pcPicYuvOrg = NULL;
924 
925  // delete used buffers in encoder class
926  m_cTEncTop.deletePicBuffer();
927 
928  // delete buffers & classes
929  xDeleteBuffer();
930  xDestroyLib();
931 
932  printRateSummary();
933
934  return;
935}
936#endif
937
938// ====================================================================================================================
939// Protected member functions
940// ====================================================================================================================
941
942/**
943 - application has picture buffer list with size of GOP
944 - picture buffer list acts as ring buffer
945 - end of the list has the latest picture
946 .
947 */
948#if SVC_EXTENSION
949Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
950{
951  assert( m_iGOPSize > 0 );
952 
953  // org. buffer
954  if ( m_acListPicYuvRec[layer].size() == (UInt)m_iGOPSize )
955  {
956    rpcPicYuvRec = m_acListPicYuvRec[layer].popFront();
957
958  }
959  else
960  {
961    rpcPicYuvRec = new TComPicYuv;
962   
963#if SVC_UPSAMPLING
964    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
965#else
966    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
967#endif
968
969  }
970  m_acListPicYuvRec[layer].pushBack( rpcPicYuvRec );
971}
972
973Void TAppEncTop::xDeleteBuffer( )
974{
975  for(UInt layer=0; layer<m_numLayers; layer++)
976  {
977    TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_acListPicYuvRec[layer].begin();
978   
979    Int iSize = Int( m_acListPicYuvRec[layer].size() );
980   
981    for ( Int i = 0; i < iSize; i++ )
982    {
983      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
984      pcPicYuvRec->destroy();
985      delete pcPicYuvRec; pcPicYuvRec = NULL;
986    }
987  } 
988}
989
990
991
992Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
993{
994  Int i;
995 
996  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
997 
998  for ( i = 0; i < iNumEncoded; i++ )
999  {
1000    --iterPicYuvRec;
1001  }
1002 
1003  for ( i = 0; i < iNumEncoded; i++ )
1004  {
1005    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1006    if (!m_acLayerCfg[layer].getReconFile().empty())
1007    {
1008      m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getCropLeft(), m_acLayerCfg[layer].getCropRight(), 
1009        m_acLayerCfg[layer].getCropTop(), m_acLayerCfg[layer].getCropBottom() );
1010    }
1011  }
1012}
1013
1014
1015Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
1016{
1017  Int i;
1018 
1019  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
1020 
1021  for ( i = 0; i < iNumEncoded; i++ )
1022  {
1023    const AccessUnit& au = *(iterBitstream++);
1024    const vector<unsigned>& stats = writeAnnexB(bitstreamFile, au);
1025    rateStatsAccum(au, stats);
1026  }
1027}
1028
1029#else // SVC_EXTENSION
1030Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
1031{
1032  assert( m_iGOPSize > 0 );
1033 
1034  // org. buffer
1035  if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize )
1036  {
1037    rpcPicYuvRec = m_cListPicYuvRec.popFront();
1038
1039  }
1040  else
1041  {
1042    rpcPicYuvRec = new TComPicYuv;
1043   
1044    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
1045
1046  }
1047  m_cListPicYuvRec.pushBack( rpcPicYuvRec );
1048}
1049
1050Void TAppEncTop::xDeleteBuffer( )
1051{
1052  TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
1053 
1054  Int iSize = Int( m_cListPicYuvRec.size() );
1055 
1056  for ( Int i = 0; i < iSize; i++ )
1057  {
1058    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1059    pcPicYuvRec->destroy();
1060    delete pcPicYuvRec; pcPicYuvRec = NULL;
1061  }
1062 
1063}
1064
1065/** \param iNumEncoded  number of encoded frames
1066 */
1067Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
1068{
1069  Int i;
1070 
1071  TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
1072  list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
1073 
1074  for ( i = 0; i < iNumEncoded; i++ )
1075  {
1076    --iterPicYuvRec;
1077  }
1078 
1079  for ( i = 0; i < iNumEncoded; i++ )
1080  {
1081    TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
1082    if (m_pchReconFile)
1083    {
1084      m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_cropLeft, m_cropRight, m_cropTop, m_cropBottom );
1085    }
1086
1087    const AccessUnit& au = *(iterBitstream++);
1088    const vector<unsigned>& stats = writeAnnexB(bitstreamFile, au);
1089    rateStatsAccum(au, stats);
1090  }
1091}
1092#endif
1093
1094/**
1095 *
1096 */
1097void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<unsigned>& annexBsizes)
1098{
1099  AccessUnit::const_iterator it_au = au.begin();
1100  vector<unsigned>::const_iterator it_stats = annexBsizes.begin();
1101
1102  for (; it_au != au.end(); it_au++, it_stats++)
1103  {
1104    switch ((*it_au)->m_nalUnitType)
1105    {
1106#if NAL_UNIT_TYPES_J1003_D7
1107    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1108    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1109    case NAL_UNIT_CODED_SLICE_TLA:
1110    case NAL_UNIT_CODED_SLICE_TSA_N:
1111    case NAL_UNIT_CODED_SLICE_STSA_R:
1112    case NAL_UNIT_CODED_SLICE_STSA_N:
1113    case NAL_UNIT_CODED_SLICE_BLA:
1114    case NAL_UNIT_CODED_SLICE_BLANT:
1115    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1116    case NAL_UNIT_CODED_SLICE_IDR:
1117    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1118    case NAL_UNIT_CODED_SLICE_CRA:
1119    case NAL_UNIT_CODED_SLICE_DLP:
1120    case NAL_UNIT_CODED_SLICE_TFD:
1121#else
1122    case NAL_UNIT_CODED_SLICE:
1123    case NAL_UNIT_CODED_SLICE_TFD:
1124    case NAL_UNIT_CODED_SLICE_TLA:
1125    case NAL_UNIT_CODED_SLICE_CRA:
1126    case NAL_UNIT_CODED_SLICE_CRANT:
1127    case NAL_UNIT_CODED_SLICE_BLA:
1128    case NAL_UNIT_CODED_SLICE_BLANT:
1129    case NAL_UNIT_CODED_SLICE_IDR:
1130#endif
1131    case NAL_UNIT_VPS:
1132    case NAL_UNIT_SPS:
1133    case NAL_UNIT_PPS:
1134      m_essentialBytes += *it_stats;
1135      break;
1136    default:
1137      break;
1138    }
1139
1140    m_totalBytes += *it_stats;
1141  }
1142}
1143
1144void TAppEncTop::printRateSummary()
1145{
1146#if SVC_EXTENSION
1147  double time = (double) m_iFrameRcvd / m_acLayerCfg[m_numLayers-1].getFrameRate();
1148#else
1149  double time = (double) m_iFrameRcvd / m_iFrameRate;
1150#endif
1151  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
1152#if VERBOSE_RATE
1153  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
1154#endif
1155}
1156
1157//! \}
Note: See TracBrowser for help on using the repository browser.