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