source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h @ 1311

Last change on this file since 1311 was 1310, checked in by seregin, 9 years ago

port rev 4381

  • Property svn:eol-style set to native
File size: 14.3 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-2015, 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     TEncGOP.h
35    \brief    GOP encoder class (header)
36*/
37
38#ifndef __TENCGOP__
39#define __TENCGOP__
40
41#include <list>
42
43#include <stdlib.h>
44
45#include "TLibCommon/TComList.h"
46#include "TLibCommon/TComPic.h"
47#include "TLibCommon/TComBitCounter.h"
48#include "TLibCommon/TComLoopFilter.h"
49#include "TLibCommon/AccessUnit.h"
50#include "TEncSampleAdaptiveOffset.h"
51#include "TEncSlice.h"
52#include "TEncEntropy.h"
53#include "TEncCavlc.h"
54#include "TEncSbac.h"
55#include "SEIwrite.h"
56#include "SEIEncoder.h"
57#if CGS_3D_ASYMLUT
58#include "TEnc3DAsymLUT.h"
59#endif
60
61#include "TEncAnalyze.h"
62#include "TEncRateCtrl.h"
63#include <vector>
64
65//! \ingroup TLibEncoder
66//! \{
67
68class TEncTop;
69
70// ====================================================================================================================
71// Class definition
72// ====================================================================================================================
73
74class TEncGOP
75{
76  class DUData
77  {
78  public:
79    DUData()
80    :accumBitsDU(0)
81    ,accumNalsDU(0) {};
82
83    Int accumBitsDU;
84    Int accumNalsDU;
85  };
86
87private:
88
89  TEncAnalyze             m_gcAnalyzeAll;
90  TEncAnalyze             m_gcAnalyzeI;
91  TEncAnalyze             m_gcAnalyzeP;
92  TEncAnalyze             m_gcAnalyzeB;
93
94  TEncAnalyze             m_gcAnalyzeAll_in;
95  //  Data
96  Bool                    m_bLongtermTestPictureHasBeenCoded;
97  Bool                    m_bLongtermTestPictureHasBeenCoded2;
98  UInt                    m_numLongTermRefPicSPS;
99  UInt                    m_ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS];
100  Bool                    m_ltRefPicUsedByCurrPicFlag[MAX_NUM_LONG_TERM_REF_PICS];
101  Int                     m_iLastIDR;
102  Int                     m_iGopSize;
103  Int                     m_iNumPicCoded;
104  Bool                    m_bFirst;
105#if ALLOW_RECOVERY_POINT_AS_RAP
106  Int                     m_iLastRecoveryPicPOC;
107#endif
108
109  //  Access channel
110  TEncTop*                m_pcEncTop;
111  TEncCfg*                m_pcCfg;
112  TEncSlice*              m_pcSliceEncoder;
113  TComList<TComPic*>*     m_pcListPic;
114
115  TEncEntropy*            m_pcEntropyCoder;
116  TEncCavlc*              m_pcCavlcCoder;
117  TEncSbac*               m_pcSbacCoder;
118  TEncBinCABAC*           m_pcBinCABAC;
119  TComLoopFilter*         m_pcLoopFilter;
120
121  SEIWriter               m_seiWriter;
122
123  //--Adaptive Loop filter
124  TEncSampleAdaptiveOffset*  m_pcSAO;
125  TEncRateCtrl*           m_pcRateCtrl;
126  // indicate sequence first
127  Bool                    m_bSeqFirst;
128
129  // clean decoding refresh
130  Bool                    m_bRefreshPending;
131  Int                     m_pocCRA;
132  NalUnitType             m_associatedIRAPType;
133  Int                     m_associatedIRAPPOC;
134
135  std::vector<Int> m_vRVM_RP;
136  UInt                    m_lastBPSEI;
137  UInt                    m_totalCoded;
138  Bool                    m_bufferingPeriodSEIPresentInAU;
139  SEIEncoder              m_seiEncoder;
140
141#if Q0074_COLOUR_REMAPPING_SEI
142  TComSEIColourRemappingInfo m_seiColourRemappingInfo; 
143#endif
144#if SVC_EXTENSION
145  Int                     m_pocCraWithoutReset;
146  Int                     m_associatedIrapPocBeforeReset;
147  UInt                    m_layerId;     
148  TEncTop**               m_ppcTEncTop;
149  TEncSearch*             m_pcPredSearch;                       ///< encoder search class
150#if CGS_3D_ASYMLUT
151  TEnc3DAsymLUT           m_Enc3DAsymLUTPicUpdate;
152  TEnc3DAsymLUT           m_Enc3DAsymLUTPPS;
153  TComPicYuv*             m_pColorMappedPic;
154
155  Int m_iTap;
156  const Int (*m_phase_filter)[13];
157  const Int (*m_phase_filter_luma)[13];
158  const Int (*m_phase_filter_chroma)[13];
159  Int m_iM, m_iN;
160  static const Int m_phase_filter_0_t0[4][13];
161  static const Int m_phase_filter_0_t1[4][13];
162  static const Int m_phase_filter_0_t1_chroma[4][13];
163  static const Int m_phase_filter_1[8][13];
164  Int   **m_temp;
165#endif
166  Int   m_lastPocPeriodId;
167  Bool  m_noRaslOutputFlag;
168  Bool  m_prevPicHasEos;
169  static Bool m_signalledVPS;
170#endif
171 
172public:
173  TEncGOP();
174  virtual ~TEncGOP();
175 
176#if SVC_EXTENSION
177  Void  create      ( UInt layerId );
178#else
179  Void  create      ();
180#endif
181  Void  destroy     ();
182
183  Void  init        ( TEncTop* pcTEncTop );
184#if SVC_EXTENSION 
185  Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec,
186                      std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE );
187#else
188  Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec,
189                      std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE );
190#endif
191  Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect);
192
193
194  Int   getGOPSize()          { return  m_iGopSize;  }
195
196  TComList<TComPic*>*   getListPic()      { return m_pcListPic; }
197
198  Void  printOutSummary      ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths );
199  Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist );
200
201  TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
202  NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField );
203  Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& );
204
205#if SVC_EXTENSION
206  Void  determinePocResetIdc( Int const pocCurr, TComSlice *const slice);
207  Int   getIntraRefreshInterval()   { return m_pcCfg->getIntraPeriod(); }
208  Int   getIntraRefreshType()       { return m_pcCfg->getDecodingRefreshType(); } 
209  Int   getLastPocPeriodId()        { return m_lastPocPeriodId; }
210  Void  setLastPocPeriodId(Int x)   { m_lastPocPeriodId = x;    }
211  Void  updatePocValuesOfPics( Int const pocCurr, TComSlice *const slice);
212
213  TEncAnalyze* getAnalyzeAll()      { return &m_gcAnalyzeAll;  }
214  TEncAnalyze* getAnalyzeI()        { return &m_gcAnalyzeI;    }
215  TEncAnalyze* getAnalyzeP()        { return &m_gcAnalyzeP;    }
216  TEncAnalyze* getAnalyzeB()        { return &m_gcAnalyzeB;    }
217  TEncAnalyze* getAnalyzeAllin()    { return &m_gcAnalyzeAll_in; }
218  Double       calculateRVM()       { return xCalculateRVM();    }
219#endif
220
221protected:
222  TEncRateCtrl* getRateCtrl()       { return m_pcRateCtrl;  }
223
224protected:
225
226  Void  xInitGOP          ( Int iPOCLast, Int iNumPicRcvd, Bool isField );
227  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField );
228
229  Void  xCalculateAddPSNRs         ( const Bool isField, const Bool isFieldTopFieldFirst, const Int iGOPid, TComPic* pcPic, const AccessUnit&accessUnit, TComList<TComPic*> &rcListPic, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE );
230  Void  xCalculateAddPSNR          ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE );
231  Void  xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField,
232                                     TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField,
233                                     const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE );
234
235  UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths);
236
237  Double xCalculateRVM();
238
239  Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps);
240  Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice);
241  Void xCreatePictureTimingSEI  (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData);
242  Void xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData);
243  Void xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps);
244  Void xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI);
245
246  Void xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages);
247#if O0164_MULTI_LAYER_HRD
248  Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
249  Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
250#else
251  Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps);
252  Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps);
253#endif
254  Void xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages);
255#if O0164_MULTI_LAYER_HRD
256  Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *vps, const TComSPS *sps, Bool testWrite, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
257  Void xWriteLeadingSEIMessages  (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *vps, const TComSPS *sps, std::deque<DUData> &duData, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
258  Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
259  Void xWriteDuSEIMessages       (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *sps, const TComSPS *vps, std::deque<DUData> &duData, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
260#else
261  Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite);
262  Void xWriteLeadingSEIMessages  (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData);
263  Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps);
264  Void xWriteDuSEIMessages       (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData);
265#endif
266
267  Int xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps);
268  Int xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps);
269  Int xWritePPS (AccessUnit &accessUnit, const TComPPS *pps);
270  Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice);
271
272  Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices );
273
274#if Q0074_COLOUR_REMAPPING_SEI
275  TComSEIColourRemappingInfo* xGetSEIColourRemappingInfo()  { return &m_seiColourRemappingInfo; }
276  Void  setCRISEIFile( Char* pch )       { m_seiColourRemappingInfo.m_colourRemapSEIFile = pch; }
277
278  Void freeColourCRI();
279  Int  readingCRIparameters();
280  Void xCheckParameter();
281#endif
282#if SVC_EXTENSION
283#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
284  Void xBuildTileSetsMap(TComPicSym* picSym);
285#endif
286#if CGS_3D_ASYMLUT
287  Void xDetermin3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS );
288  Void downScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest, BitDepths& bitDepth);
289  Void downScaleComponent2x2( const Pel* pSrc, Pel* pDest, const Int iSrcStride, const Int iDestStride, const Int iSrcWidth, const Int iSrcHeight, const Int inputBitDepth, const Int outputBitDepth );
290  inline Short xClip( Short x , Int bitdepth );
291  Void initDs(Int iWidth, Int iHeight, Int iType);
292  Void filterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height1, Int width1, BitDepths& bitDepth, Int plane );
293
294  Int get_mem2DintWithPad(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX);
295  Void free_mem2DintWithPad(Int **array2D, Int iPadY, Int iPadX);
296#endif
297  Void xCheckLayerReset(TComSlice *slice);
298  Void xSetNoRaslOutputFlag(TComSlice *slice);
299  Void xSetLayerInitializedFlag(TComSlice *slice);
300#endif //SVC_EXTENSION
301};// END CLASS DEFINITION TEncGOP
302
303//! \}
304
305#endif // __TENCGOP__
306
Note: See TracBrowser for help on using the repository browser.