| 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-2014, 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 | #if Q0048_CGS_3D_ASYMLUT |
|---|
| 57 | #include "TEnc3DAsymLUT.h" |
|---|
| 58 | #endif |
|---|
| 59 | |
|---|
| 60 | #include "TEncAnalyze.h" |
|---|
| 61 | #include "TEncRateCtrl.h" |
|---|
| 62 | #include <vector> |
|---|
| 63 | |
|---|
| 64 | //! \ingroup TLibEncoder |
|---|
| 65 | //! \{ |
|---|
| 66 | |
|---|
| 67 | class TEncTop; |
|---|
| 68 | |
|---|
| 69 | // ==================================================================================================================== |
|---|
| 70 | // Class definition |
|---|
| 71 | // ==================================================================================================================== |
|---|
| 72 | |
|---|
| 73 | class TEncGOP |
|---|
| 74 | { |
|---|
| 75 | private: |
|---|
| 76 | // Data |
|---|
| 77 | Bool m_bLongtermTestPictureHasBeenCoded; |
|---|
| 78 | Bool m_bLongtermTestPictureHasBeenCoded2; |
|---|
| 79 | UInt m_numLongTermRefPicSPS; |
|---|
| 80 | UInt m_ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS]; |
|---|
| 81 | Bool m_ltRefPicUsedByCurrPicFlag[MAX_NUM_LONG_TERM_REF_PICS]; |
|---|
| 82 | Int m_iLastIDR; |
|---|
| 83 | Int m_iGopSize; |
|---|
| 84 | Int m_iNumPicCoded; |
|---|
| 85 | Bool m_bFirst; |
|---|
| 86 | #if ALLOW_RECOVERY_POINT_AS_RAP |
|---|
| 87 | Int m_iLastRecoveryPicPOC; |
|---|
| 88 | #endif |
|---|
| 89 | |
|---|
| 90 | #if Q0074_COLOUR_REMAPPING_SEI |
|---|
| 91 | string m_colourRemapSEIFile; |
|---|
| 92 | Int m_colourRemapSEIId; |
|---|
| 93 | Bool m_colourRemapSEICancelFlag; |
|---|
| 94 | Bool m_colourRemapSEIPersistenceFlag; |
|---|
| 95 | Bool m_colourRemapSEIVideoSignalInfoPresentFlag; |
|---|
| 96 | Bool m_colourRemapSEIFullRangeFlag; |
|---|
| 97 | Int m_colourRemapSEIPrimaries; |
|---|
| 98 | Int m_colourRemapSEITransferFunction; |
|---|
| 99 | Int m_colourRemapSEIMatrixCoefficients; |
|---|
| 100 | Int m_colourRemapSEIInputBitDepth; |
|---|
| 101 | Int m_colourRemapSEIBitDepth; |
|---|
| 102 | Int m_colourRemapSEIPreLutNumValMinus1[3]; |
|---|
| 103 | Int* m_colourRemapSEIPreLutCodedValue[3]; |
|---|
| 104 | Int* m_colourRemapSEIPreLutTargetValue[3]; |
|---|
| 105 | Bool m_colourRemapSEIMatrixPresentFlag; |
|---|
| 106 | Int m_colourRemapSEILog2MatrixDenom; |
|---|
| 107 | Int m_colourRemapSEICoeffs[3][3]; |
|---|
| 108 | Int m_colourRemapSEIPostLutNumValMinus1[3]; |
|---|
| 109 | Int* m_colourRemapSEIPostLutCodedValue[3]; |
|---|
| 110 | Int* m_colourRemapSEIPostLutTargetValue[3]; |
|---|
| 111 | #endif |
|---|
| 112 | // Access channel |
|---|
| 113 | TEncTop* m_pcEncTop; |
|---|
| 114 | TEncCfg* m_pcCfg; |
|---|
| 115 | TEncSlice* m_pcSliceEncoder; |
|---|
| 116 | TComList<TComPic*>* m_pcListPic; |
|---|
| 117 | |
|---|
| 118 | TEncEntropy* m_pcEntropyCoder; |
|---|
| 119 | TEncCavlc* m_pcCavlcCoder; |
|---|
| 120 | TEncSbac* m_pcSbacCoder; |
|---|
| 121 | TEncBinCABAC* m_pcBinCABAC; |
|---|
| 122 | TComLoopFilter* m_pcLoopFilter; |
|---|
| 123 | |
|---|
| 124 | SEIWriter m_seiWriter; |
|---|
| 125 | |
|---|
| 126 | //--Adaptive Loop filter |
|---|
| 127 | TEncSampleAdaptiveOffset* m_pcSAO; |
|---|
| 128 | TEncRateCtrl* m_pcRateCtrl; |
|---|
| 129 | // indicate sequence first |
|---|
| 130 | Bool m_bSeqFirst; |
|---|
| 131 | |
|---|
| 132 | // clean decoding refresh |
|---|
| 133 | Bool m_bRefreshPending; |
|---|
| 134 | Int m_pocCRA; |
|---|
| 135 | NalUnitType m_associatedIRAPType; |
|---|
| 136 | Int m_associatedIRAPPOC; |
|---|
| 137 | |
|---|
| 138 | std::vector<Int> m_vRVM_RP; |
|---|
| 139 | UInt m_lastBPSEI; |
|---|
| 140 | UInt m_totalCoded; |
|---|
| 141 | UInt m_cpbRemovalDelay; |
|---|
| 142 | UInt m_tl0Idx; |
|---|
| 143 | UInt m_rapIdx; |
|---|
| 144 | Bool m_activeParameterSetSEIPresentInAU; |
|---|
| 145 | Bool m_bufferingPeriodSEIPresentInAU; |
|---|
| 146 | Bool m_pictureTimingSEIPresentInAU; |
|---|
| 147 | Bool m_nestedBufferingPeriodSEIPresentInAU; |
|---|
| 148 | Bool m_nestedPictureTimingSEIPresentInAU; |
|---|
| 149 | |
|---|
| 150 | #if POC_RESET_IDC_ENCODER |
|---|
| 151 | Int m_pocCraWithoutReset; |
|---|
| 152 | Int m_associatedIrapPocBeforeReset; |
|---|
| 153 | #endif |
|---|
| 154 | #if SVC_EXTENSION |
|---|
| 155 | UInt m_layerId; |
|---|
| 156 | TEncTop** m_ppcTEncTop; |
|---|
| 157 | TEncSearch* m_pcPredSearch; ///< encoder search class |
|---|
| 158 | #if Q0048_CGS_3D_ASYMLUT |
|---|
| 159 | TEnc3DAsymLUT m_Enc3DAsymLUTPicUpdate; |
|---|
| 160 | TEnc3DAsymLUT m_Enc3DAsymLUTPPS; |
|---|
| 161 | TComPicYuv* m_pColorMappedPic; |
|---|
| 162 | |
|---|
| 163 | Int m_iTap; |
|---|
| 164 | const Int (*m_phase_filter)[13]; |
|---|
| 165 | const Int (*m_phase_filter_luma)[13]; |
|---|
| 166 | const Int (*m_phase_filter_chroma)[13]; |
|---|
| 167 | Int m_iM, m_iN; |
|---|
| 168 | static const Int m_phase_filter_0_t0[4][13]; |
|---|
| 169 | static const Int m_phase_filter_0_t1[4][13]; |
|---|
| 170 | static const Int m_phase_filter_0_t1_chroma[4][13]; |
|---|
| 171 | static const Int m_phase_filter_1[8][13]; |
|---|
| 172 | Int **m_temp; |
|---|
| 173 | #endif |
|---|
| 174 | #if POC_RESET_IDC_ENCODER |
|---|
| 175 | Int m_lastPocPeriodId; |
|---|
| 176 | #endif |
|---|
| 177 | #if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS |
|---|
| 178 | Bool m_noRaslOutputFlag; |
|---|
| 179 | Bool m_prevPicHasEos; |
|---|
| 180 | #endif |
|---|
| 181 | #endif |
|---|
| 182 | |
|---|
| 183 | public: |
|---|
| 184 | TEncGOP(); |
|---|
| 185 | virtual ~TEncGOP(); |
|---|
| 186 | |
|---|
| 187 | #if SVC_EXTENSION |
|---|
| 188 | Void create ( UInt layerId ); |
|---|
| 189 | #else |
|---|
| 190 | Void create (); |
|---|
| 191 | #endif |
|---|
| 192 | Void destroy (); |
|---|
| 193 | |
|---|
| 194 | Void init ( TEncTop* pcTEncTop ); |
|---|
| 195 | #if SVC_EXTENSION |
|---|
| 196 | Void compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
|---|
| 197 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
|---|
| 198 | #else |
|---|
| 199 | Void compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
|---|
| 200 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
|---|
| 201 | #endif |
|---|
| 202 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect); |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | Int getGOPSize() { return m_iGopSize; } |
|---|
| 206 | |
|---|
| 207 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
|---|
| 208 | |
|---|
| 209 | #if !SVC_EXTENSION |
|---|
| 210 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE ); |
|---|
| 211 | #endif |
|---|
| 212 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist ); |
|---|
| 213 | |
|---|
| 214 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
|---|
| 215 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
|---|
| 216 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
|---|
| 217 | |
|---|
| 218 | #if POC_RESET_IDC_ENCODER |
|---|
| 219 | Void determinePocResetIdc( Int const pocCurr, TComSlice *const slice); |
|---|
| 220 | Int getIntraRefreshInterval() { return m_pcCfg->getIntraPeriod(); } |
|---|
| 221 | Int getIntraRefreshType() { return m_pcCfg->getDecodingRefreshType(); } |
|---|
| 222 | Int getLastPocPeriodId() { return m_lastPocPeriodId; } |
|---|
| 223 | Void setLastPocPeriodId(Int x) { m_lastPocPeriodId = x; } |
|---|
| 224 | Void updatePocValuesOfPics( Int const pocCurr, TComSlice *const slice); |
|---|
| 225 | #endif |
|---|
| 226 | |
|---|
| 227 | protected: |
|---|
| 228 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
|---|
| 229 | |
|---|
| 230 | protected: |
|---|
| 231 | |
|---|
| 232 | Void xInitGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField ); |
|---|
| 233 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField ); |
|---|
| 234 | |
|---|
| 235 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
|---|
| 236 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
|---|
| 237 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
|---|
| 238 | const AccessUnit& accessUnit, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
|---|
| 239 | |
|---|
| 240 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1); |
|---|
| 241 | |
|---|
| 242 | Double xCalculateRVM(); |
|---|
| 243 | |
|---|
| 244 | SEIActiveParameterSets* xCreateSEIActiveParameterSets (TComSPS *sps); |
|---|
| 245 | SEIFramePacking* xCreateSEIFramePacking(); |
|---|
| 246 | SEISegmentedRectFramePacking* xCreateSEISegmentedRectFramePacking(); |
|---|
| 247 | SEIDisplayOrientation* xCreateSEIDisplayOrientation(); |
|---|
| 248 | SEIToneMappingInfo* xCreateSEIToneMappingInfo(); |
|---|
| 249 | SEITempMotionConstrainedTileSets* xCreateSEITempMotionConstrainedTileSets (); |
|---|
| 250 | SEIKneeFunctionInfo* xCreateSEIKneeFunctionInfo(); |
|---|
| 251 | SEIChromaSamplingFilterHint* xCreateSEIChromaSamplingFilterHint(Bool bChromaLocInfoPresent, Int iHorFilterIndex, Int iVerFilterIdc); |
|---|
| 252 | |
|---|
| 253 | Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps); |
|---|
| 254 | Int xGetFirstSeiLocation (AccessUnit &accessUnit); |
|---|
| 255 | Void xResetNonNestedSEIPresentFlags() |
|---|
| 256 | { |
|---|
| 257 | m_activeParameterSetSEIPresentInAU = false; |
|---|
| 258 | m_bufferingPeriodSEIPresentInAU = false; |
|---|
| 259 | m_pictureTimingSEIPresentInAU = false; |
|---|
| 260 | } |
|---|
| 261 | Void xResetNestedSEIPresentFlags() |
|---|
| 262 | { |
|---|
| 263 | m_nestedBufferingPeriodSEIPresentInAU = false; |
|---|
| 264 | m_nestedPictureTimingSEIPresentInAU = false; |
|---|
| 265 | } |
|---|
| 266 | Void dblMetric( TComPic* pcPic, UInt uiNumSlices ); |
|---|
| 267 | |
|---|
| 268 | #if Q0074_COLOUR_REMAPPING_SEI |
|---|
| 269 | Void setCRISEIFile( Char* pch ) { m_colourRemapSEIFile = pch; } |
|---|
| 270 | |
|---|
| 271 | Void freeColourCRI(); |
|---|
| 272 | Int readingCRIparameters(); |
|---|
| 273 | Void xCheckParameter(); |
|---|
| 274 | |
|---|
| 275 | SEIColourRemappingInfo* xCreateSEIColourRemappingInfo(); |
|---|
| 276 | #endif |
|---|
| 277 | #if SVC_EXTENSION |
|---|
| 278 | #if LAYERS_NOT_PRESENT_SEI |
|---|
| 279 | SEILayersNotPresent* xCreateSEILayersNotPresent (); |
|---|
| 280 | #endif |
|---|
| 281 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
|---|
| 282 | Void xBuildTileSetsMap(TComPicSym* picSym); |
|---|
| 283 | SEIInterLayerConstrainedTileSets* xCreateSEIInterLayerConstrainedTileSets(); |
|---|
| 284 | #endif |
|---|
| 285 | #if O0164_MULTI_LAYER_HRD |
|---|
| 286 | #if VPS_VUI_BSP_HRD_PARAMS |
|---|
| 287 | SEIScalableNesting* xCreateBspNestingSEI(TComSlice *pcSlice, Int olsIdx, Int partitioningSchemeIdx, Int bspIdx); |
|---|
| 288 | #else |
|---|
| 289 | SEIScalableNesting* xCreateBspNestingSEI(TComSlice *pcSlice); |
|---|
| 290 | #endif |
|---|
| 291 | #endif |
|---|
| 292 | #if P0123_ALPHA_CHANNEL_SEI |
|---|
| 293 | SEIAlphaChannelInfo* xCreateSEIAlphaChannelInfo(); |
|---|
| 294 | #endif |
|---|
| 295 | #if Q0096_OVERLAY_SEI |
|---|
| 296 | SEIOverlayInfo* xCreateSEIOverlayInfo(); |
|---|
| 297 | #endif |
|---|
| 298 | #if Q0048_CGS_3D_ASYMLUT |
|---|
| 299 | Void xDetermin3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS ); |
|---|
| 300 | Void downScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest); |
|---|
| 301 | 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 ); |
|---|
| 302 | inline Short xClip( Short x , Int bitdepth ); |
|---|
| 303 | Void initDs(Int iWidth, Int iHeight, Int iType); |
|---|
| 304 | Void filterImg( |
|---|
| 305 | Pel *src, |
|---|
| 306 | Int iSrcStride, |
|---|
| 307 | Pel *dst, |
|---|
| 308 | Int iDstStride, |
|---|
| 309 | Int height1, |
|---|
| 310 | Int width1, |
|---|
| 311 | Int shift, |
|---|
| 312 | Int plane); |
|---|
| 313 | |
|---|
| 314 | Int get_mem2DintWithPad(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX); |
|---|
| 315 | Void free_mem2DintWithPad(Int **array2D, Int iPadY, Int iPadX); |
|---|
| 316 | #endif |
|---|
| 317 | #if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS |
|---|
| 318 | Void xCheckLayerReset(TComSlice *slice); |
|---|
| 319 | Void xSetNoRaslOutputFlag(TComSlice *slice); |
|---|
| 320 | Void xSetLayerInitializedFlag(TComSlice *slice); |
|---|
| 321 | #endif |
|---|
| 322 | #endif //SVC_EXTENSION |
|---|
| 323 | };// END CLASS DEFINITION TEncGOP |
|---|
| 324 | |
|---|
| 325 | //! \} |
|---|
| 326 | |
|---|
| 327 | #endif // __TENCGOP__ |
|---|
| 328 | |
|---|