[5] | 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 |
---|
[1313] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1401] | 6 | * Copyright (c) 2010-2016, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 33 | |
---|
[56] | 34 | /** \file TEncGOP.h |
---|
[2] | 35 | \brief GOP encoder class (header) |
---|
| 36 | */ |
---|
| 37 | |
---|
[56] | 38 | #ifndef __TENCGOP__ |
---|
| 39 | #define __TENCGOP__ |
---|
[2] | 40 | |
---|
[56] | 41 | #include <list> |
---|
| 42 | |
---|
[2] | 43 | #include <stdlib.h> |
---|
| 44 | |
---|
[56] | 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" |
---|
[2] | 51 | #include "TEncSlice.h" |
---|
| 52 | #include "TEncEntropy.h" |
---|
| 53 | #include "TEncCavlc.h" |
---|
| 54 | #include "TEncSbac.h" |
---|
[608] | 55 | #include "SEIwrite.h" |
---|
[1313] | 56 | #include "SEIEncoder.h" |
---|
[2] | 57 | |
---|
| 58 | #include "TEncAnalyze.h" |
---|
[608] | 59 | #include "TEncRateCtrl.h" |
---|
[655] | 60 | #if KWU_RC_MADPRED_E0227 |
---|
| 61 | #include "../App/TAppEncoder/TAppEncTop.h" |
---|
| 62 | #endif |
---|
[2] | 63 | #include <vector> |
---|
| 64 | |
---|
[56] | 65 | //! \ingroup TLibEncoder |
---|
| 66 | //! \{ |
---|
| 67 | |
---|
[2] | 68 | class TEncTop; |
---|
| 69 | |
---|
| 70 | // ==================================================================================================================== |
---|
| 71 | // Class definition |
---|
| 72 | // ==================================================================================================================== |
---|
| 73 | |
---|
[56] | 74 | class TEncGOP |
---|
[2] | 75 | { |
---|
[1313] | 76 | class DUData |
---|
| 77 | { |
---|
| 78 | public: |
---|
| 79 | DUData() |
---|
| 80 | :accumBitsDU(0) |
---|
| 81 | ,accumNalsDU(0) {}; |
---|
| 82 | |
---|
| 83 | Int accumBitsDU; |
---|
| 84 | Int accumNalsDU; |
---|
| 85 | }; |
---|
| 86 | |
---|
[2] | 87 | private: |
---|
[1313] | 88 | |
---|
| 89 | TEncAnalyze m_gcAnalyzeAll; |
---|
| 90 | TEncAnalyze m_gcAnalyzeI; |
---|
| 91 | TEncAnalyze m_gcAnalyzeP; |
---|
| 92 | TEncAnalyze m_gcAnalyzeB; |
---|
| 93 | |
---|
| 94 | TEncAnalyze m_gcAnalyzeAll_in; |
---|
[2] | 95 | // Data |
---|
[56] | 96 | Bool m_bLongtermTestPictureHasBeenCoded; |
---|
| 97 | Bool m_bLongtermTestPictureHasBeenCoded2; |
---|
[1313] | 98 | UInt m_numLongTermRefPicSPS; |
---|
| 99 | UInt m_ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS]; |
---|
| 100 | Bool m_ltRefPicUsedByCurrPicFlag[MAX_NUM_LONG_TERM_REF_PICS]; |
---|
[56] | 101 | Int m_iLastIDR; |
---|
| 102 | Int m_iGopSize; |
---|
| 103 | Int m_iNumPicCoded; |
---|
| 104 | Bool m_bFirst; |
---|
[964] | 105 | Int m_iLastRecoveryPicPOC; |
---|
[1313] | 106 | |
---|
[2] | 107 | // Access channel |
---|
| 108 | TEncTop* m_pcEncTop; |
---|
| 109 | TEncCfg* m_pcCfg; |
---|
| 110 | TEncSlice* m_pcSliceEncoder; |
---|
| 111 | TComList<TComPic*>* m_pcListPic; |
---|
[1313] | 112 | |
---|
[2] | 113 | TEncEntropy* m_pcEntropyCoder; |
---|
| 114 | TEncCavlc* m_pcCavlcCoder; |
---|
| 115 | TEncSbac* m_pcSbacCoder; |
---|
| 116 | TEncBinCABAC* m_pcBinCABAC; |
---|
| 117 | TComLoopFilter* m_pcLoopFilter; |
---|
[608] | 118 | |
---|
| 119 | SEIWriter m_seiWriter; |
---|
[1313] | 120 | |
---|
| 121 | #if NH_MV |
---|
[608] | 122 | TComPicLists* m_ivPicLists; |
---|
[622] | 123 | std::vector<TComPic*> m_refPicSetInterLayer0; |
---|
| 124 | std::vector<TComPic*> m_refPicSetInterLayer1; |
---|
[608] | 125 | |
---|
| 126 | Int m_pocLastCoded; |
---|
| 127 | Int m_layerId; |
---|
| 128 | Int m_viewId; |
---|
[1313] | 129 | #if NH_3D |
---|
[608] | 130 | Int m_viewIndex; |
---|
| 131 | Bool m_isDepth; |
---|
[5] | 132 | #endif |
---|
| 133 | #endif |
---|
[1313] | 134 | #if NH_3D_IC |
---|
[1084] | 135 | Int* m_aICEnableCandidate; |
---|
| 136 | Int* m_aICEnableNum; |
---|
[1066] | 137 | #endif |
---|
[2] | 138 | //--Adaptive Loop filter |
---|
| 139 | TEncSampleAdaptiveOffset* m_pcSAO; |
---|
[608] | 140 | TEncRateCtrl* m_pcRateCtrl; |
---|
[56] | 141 | // indicate sequence first |
---|
| 142 | Bool m_bSeqFirst; |
---|
[1313] | 143 | |
---|
[2] | 144 | // clean decoding refresh |
---|
| 145 | Bool m_bRefreshPending; |
---|
[56] | 146 | Int m_pocCRA; |
---|
[872] | 147 | NalUnitType m_associatedIRAPType; |
---|
| 148 | Int m_associatedIRAPPOC; |
---|
[2] | 149 | |
---|
| 150 | std::vector<Int> m_vRVM_RP; |
---|
[608] | 151 | UInt m_lastBPSEI; |
---|
| 152 | UInt m_totalCoded; |
---|
| 153 | Bool m_bufferingPeriodSEIPresentInAU; |
---|
[1313] | 154 | SEIEncoder m_seiEncoder; |
---|
[1402] | 155 | #if W0038_DB_OPT |
---|
| 156 | TComPicYuv* m_pcDeblockingTempPicYuv; |
---|
| 157 | Int m_DBParam[MAX_ENCODER_DEBLOCKING_QUALITY_LAYERS][4]; //[layer_id][0: available; 1: bDBDisabled; 2: Beta Offset Div2; 3: Tc Offset Div2;] |
---|
| 158 | #endif |
---|
[1313] | 159 | |
---|
[2] | 160 | public: |
---|
[56] | 161 | TEncGOP(); |
---|
| 162 | virtual ~TEncGOP(); |
---|
[1313] | 163 | |
---|
[608] | 164 | Void create (); |
---|
[2] | 165 | Void destroy (); |
---|
[1313] | 166 | |
---|
[2] | 167 | Void init ( TEncTop* pcTEncTop ); |
---|
[1313] | 168 | #if NH_MV |
---|
| 169 | Void initGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP); |
---|
| 170 | Void compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
| 171 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Int iGOPid ); |
---|
[608] | 172 | #else |
---|
[1313] | 173 | Void compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
| 174 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
[608] | 175 | #endif |
---|
[1313] | 176 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect); |
---|
[56] | 177 | |
---|
[1313] | 178 | #if NH_MV |
---|
[608] | 179 | Int getPocLastCoded () { return m_pocLastCoded; } |
---|
| 180 | Int getLayerId () { return m_layerId; } |
---|
| 181 | Int getViewId () { return m_viewId; } |
---|
[1313] | 182 | #if NH_3D |
---|
[608] | 183 | Int getViewIndex () { return m_viewIndex; } |
---|
| 184 | Bool getIsDepth () { return m_isDepth; } |
---|
| 185 | #endif |
---|
| 186 | #endif |
---|
| 187 | |
---|
[56] | 188 | Int getGOPSize() { return m_iGopSize; } |
---|
[1313] | 189 | |
---|
[2] | 190 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
---|
[1313] | 191 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths ); |
---|
| 192 | #if NH_3D_VSO |
---|
| 193 | Void preLoopFilterPicAll ( TComPic* pcPic, Dist64& ruiDist); |
---|
[608] | 194 | #else |
---|
[1313] | 195 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist ); |
---|
[608] | 196 | #endif |
---|
[655] | 197 | |
---|
| 198 | #if KWU_RC_MADPRED_E0227 |
---|
| 199 | TEncTop* getEncTop() { return m_pcEncTop; } |
---|
| 200 | #endif |
---|
| 201 | |
---|
[56] | 202 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
---|
[872] | 203 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
---|
[608] | 204 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
---|
[1313] | 205 | |
---|
[2] | 206 | protected: |
---|
[608] | 207 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
---|
[2] | 208 | |
---|
[56] | 209 | protected: |
---|
[872] | 210 | |
---|
[1313] | 211 | Void xInitGOP ( Int iPOCLast, Int iNumPicRcvd, Bool isField ); |
---|
| 212 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField ); |
---|
[655] | 213 | |
---|
[1313] | 214 | 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 ); |
---|
| 215 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
| 216 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
| 217 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
| 218 | const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
| 219 | #if NH_3D_VSO |
---|
| 220 | Dist64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
[608] | 221 | #else |
---|
[1313] | 222 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
[608] | 223 | #endif |
---|
[2] | 224 | Double xCalculateRVM(); |
---|
| 225 | |
---|
[1386] | 226 | Void xWriteAccessUnitDelimiter (AccessUnit &accessUnit, TComSlice *slice); |
---|
| 227 | |
---|
[1313] | 228 | Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps); |
---|
| 229 | Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice); |
---|
| 230 | Void xCreatePictureTimingSEI (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData); |
---|
| 231 | Void xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData); |
---|
| 232 | Void xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps); |
---|
| 233 | Void xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI); |
---|
[608] | 234 | |
---|
[1313] | 235 | Void xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages); |
---|
| 236 | Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
| 237 | Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
| 238 | Void xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages); |
---|
| 239 | Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite); |
---|
| 240 | Void xWriteLeadingSEIMessages (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
| 241 | Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps); |
---|
| 242 | Void xWriteDuSEIMessages (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
[608] | 243 | |
---|
[1313] | 244 | Int xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps); |
---|
| 245 | Int xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps); |
---|
| 246 | Int xWritePPS (AccessUnit &accessUnit, const TComPPS *pps); |
---|
| 247 | Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice); |
---|
| 248 | |
---|
| 249 | #if NH_MV |
---|
[622] | 250 | Void xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid ); |
---|
[608] | 251 | #endif |
---|
[2] | 252 | |
---|
| 253 | |
---|
[1313] | 254 | Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices ); |
---|
[1402] | 255 | #if W0038_DB_OPT |
---|
| 256 | Void applyDeblockingFilterParameterSelection( TComPic* pcPic, const UInt numSlices, const Int gopID ); |
---|
| 257 | #endif |
---|
[1313] | 258 | };// END CLASS DEFINITION TEncGOP |
---|
[56] | 259 | |
---|
| 260 | //! \} |
---|
| 261 | |
---|
| 262 | #endif // __TENCGOP__ |
---|
| 263 | |
---|