source: SHVCSoftware/branches/0.1.1-bugfix/source/App/TAppEncoder/TAppEncTop.cpp @ 1263

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

Initial import by Vadim Seregin <vseregin@…>

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