1 /*! 2 * \copy 3 * Copyright (c) 2013, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 */ 32 33 #ifndef WELS_PARASET_STRATEGY_H 34 #define WELS_PARASET_STRATEGY_H 35 36 #include "param_svc.h" 37 #include "utils.h" 38 39 namespace WelsEnc { 40 41 class IWelsParametersetStrategy { 42 public: ~IWelsParametersetStrategy()43 virtual ~IWelsParametersetStrategy() { } 44 45 static IWelsParametersetStrategy* CreateParametersetStrategy (EParameterSetStrategy eSpsPpsIdStrategy, 46 const bool bSimulcastAVC, const int32_t kiSpatialLayerNum); 47 48 //virtual SParaSetOffset* GetParaSetOffset() = 0; 49 50 virtual int32_t GetPpsIdOffset (const int32_t iPpsId) = 0; 51 virtual int32_t GetSpsIdOffset (const int32_t iPpsId, const int32_t iSpsId) = 0; 52 virtual int32_t* GetSpsIdOffsetList (const int iParasetType) = 0; 53 54 virtual uint32_t GetAllNeededParasetNum() = 0; 55 56 virtual uint32_t GetNeededSpsNum() = 0; 57 virtual uint32_t GetNeededSubsetSpsNum() = 0; 58 virtual uint32_t GetNeededPpsNum() = 0; 59 60 virtual void LoadPrevious (SExistingParasetList* pExistingParasetList, SWelsSPS* pSpsArray, 61 SSubsetSps* pSubsetArray, 62 SWelsPPS* pPpsArray) = 0; 63 64 virtual void Update (const uint32_t kuiId, const int iParasetType) = 0; 65 virtual void UpdatePpsList (sWelsEncCtx* pCtx) = 0; 66 67 virtual bool CheckParamCompatibility (SWelsSvcCodingParam* pCodingParam, SLogContext* pLogCtx) = 0; 68 69 virtual uint32_t GenerateNewSps (sWelsEncCtx* pCtx, const bool kbUseSubsetSps, const int32_t iDlayerIndex, 70 const int32_t iDlayerCount, 71 uint32_t kuiSpsId, 72 SWelsSPS*& pSps, SSubsetSps*& pSubsetSps, bool bSVCBaselayer) = 0; 73 74 virtual uint32_t InitPps (sWelsEncCtx* pCtx, uint32_t kiSpsId, 75 SWelsSPS* pSps, 76 SSubsetSps* pSubsetSps, 77 uint32_t kuiPpsId, 78 const bool kbDeblockingFilterPresentFlag, 79 const bool kbUsingSubsetSps, 80 const bool kbEntropyCodingModeFlag) = 0; 81 82 virtual void SetUseSubsetFlag (const uint32_t iPpsId, const bool bUseSubsetSps) = 0; 83 84 virtual void UpdateParaSetNum (sWelsEncCtx* pCtx) = 0; 85 86 virtual int32_t GetCurrentPpsId (const int32_t iPpsId, const int32_t iIdrLoop) = 0; 87 88 virtual void OutputCurrentStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList, 89 sWelsEncCtx* pCtx, SExistingParasetList* pExistingParasetList) = 0; 90 virtual void LoadPreviousStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList) = 0; 91 92 virtual int32_t GetSpsIdx (const int32_t iIdx) = 0; 93 }; 94 95 96 class CWelsParametersetIdConstant : public IWelsParametersetStrategy { 97 public: 98 99 CWelsParametersetIdConstant (const bool bSimulcastAVC, const int32_t kiSpatialLayerNum); 100 virtual ~ CWelsParametersetIdConstant(); 101 102 virtual int32_t GetPpsIdOffset (const int32_t iPpsId); 103 virtual int32_t GetSpsIdOffset (const int32_t iPpsId, const int32_t iSpsId); 104 int32_t* GetSpsIdOffsetList (const int iParasetType); 105 106 uint32_t GetAllNeededParasetNum(); 107 108 virtual uint32_t GetNeededSpsNum(); 109 virtual uint32_t GetNeededSubsetSpsNum(); 110 virtual uint32_t GetNeededPpsNum(); 111 112 virtual void LoadPrevious (SExistingParasetList* pExistingParasetList, SWelsSPS* pSpsArray, 113 SSubsetSps* pSubsetArray, 114 SWelsPPS* pPpsArray); 115 116 virtual void Update (const uint32_t kuiId, const int iParasetType); UpdatePpsList(sWelsEncCtx * pCtx)117 virtual void UpdatePpsList (sWelsEncCtx* pCtx) {}; 118 CheckParamCompatibility(SWelsSvcCodingParam * pCodingParam,SLogContext * pLogCtx)119 bool CheckParamCompatibility (SWelsSvcCodingParam* pCodingParam, SLogContext* pLogCtx) { 120 return true; 121 }; 122 123 virtual uint32_t GenerateNewSps (sWelsEncCtx* pCtx, const bool kbUseSubsetSps, const int32_t iDlayerIndex, 124 const int32_t iDlayerCount, uint32_t kuiSpsId, 125 SWelsSPS*& pSps, SSubsetSps*& pSubsetSps, bool bSVCBaselayer); 126 127 virtual uint32_t InitPps (sWelsEncCtx* pCtx, uint32_t kiSpsId, 128 SWelsSPS* pSps, 129 SSubsetSps* pSubsetSps, 130 uint32_t kuiPpsId, 131 const bool kbDeblockingFilterPresentFlag, 132 const bool kbUsingSubsetSps, 133 const bool kbEntropyCodingModeFlag); 134 135 virtual void SetUseSubsetFlag (const uint32_t iPpsId, const bool bUseSubsetSps); 136 UpdateParaSetNum(sWelsEncCtx * pCtx)137 virtual void UpdateParaSetNum (sWelsEncCtx* pCtx) {}; 138 GetCurrentPpsId(const int32_t iPpsId,const int32_t iIdrLoop)139 virtual int32_t GetCurrentPpsId (const int32_t iPpsId, const int32_t iIdrLoop) { 140 return iPpsId; 141 }; 142 OutputCurrentStructure(SParaSetOffsetVariable * pParaSetOffsetVariable,int32_t * pPpsIdList,sWelsEncCtx * pCtx,SExistingParasetList * pExistingParasetList)143 virtual void OutputCurrentStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList, 144 sWelsEncCtx* pCtx, 145 SExistingParasetList* pExistingParasetList) {}; LoadPreviousStructure(SParaSetOffsetVariable * pParaSetOffsetVariable,int32_t * pPpsIdList)146 virtual void LoadPreviousStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList) {}; 147 GetSpsIdx(const int32_t iIdx)148 virtual int32_t GetSpsIdx (const int32_t iIdx) { 149 return 0; 150 }; 151 protected: 152 LoadPreviousSps(SExistingParasetList * pExistingParasetList,SWelsSPS * pSpsArray,SSubsetSps * pSubsetArray)153 virtual void LoadPreviousSps (SExistingParasetList* pExistingParasetList, SWelsSPS* pSpsArray, 154 SSubsetSps* pSubsetArray) {}; LoadPreviousPps(SExistingParasetList * pExistingParasetList,SWelsPPS * pPpsArray)155 virtual void LoadPreviousPps (SExistingParasetList* pExistingParasetList, SWelsPPS* pPpsArray) {}; 156 157 protected: 158 SParaSetOffset m_sParaSetOffset; 159 bool m_bSimulcastAVC; 160 int32_t m_iSpatialLayerNum; 161 162 uint32_t m_iBasicNeededSpsNum; 163 uint32_t m_iBasicNeededPpsNum; 164 }; 165 166 /* 167 typedef struct TagParaSetOffsetVariable { 168 int32_t iParaSetIdDelta[MAX_DQ_LAYER_NUM+1];//mark delta between SPS_ID_in_bs and sps_id_in_encoder, can be minus, for each dq-layer 169 //need not extra +1 due no MGS and FMO case so far 170 bool bUsedParaSetIdInBs[MAX_PPS_COUNT]; //mark the used SPS_ID with 1 171 uint32_t uiNextParaSetIdToUseInBs; //mark the next SPS_ID_in_bs, for all layers 172 } SParaSetOffsetVariable; 173 174 typedef struct TagParaSetOffset { 175 //in PS0 design, "sParaSetOffsetVariable" record the previous paras before current IDR, AND NEED to be stacked and recover across IDR 176 SParaSetOffsetVariable 177 sParaSetOffsetVariable[PARA_SET_TYPE]; //PARA_SET_TYPE=3; paraset_type = 0: AVC_SPS; =1: Subset_SPS; =2: PPS 178 //in PSO design, "bPpsIdMappingIntoSubsetsps" uses the current para of current IDR period 179 bool 180 bPpsIdMappingIntoSubsetsps[MAX_DQ_LAYER_NUM+1]; // need not extra +1 due no MGS and FMO case so far 181 182 int32_t iPpsIdList[MAX_DQ_LAYER_NUM][MAX_PPS_COUNT]; //index0: max pps types; index1: for differnt IDRs, if only index0=1, index1 can reach MAX_PPS_COUNT 183 184 //#if _DEBUG 185 int32_t eSpsPpsIdStrategy; 186 //#endif 187 188 uint32_t uiNeededSpsNum; 189 uint32_t uiNeededSubsetSpsNum; 190 uint32_t uiNeededPpsNum; 191 192 uint32_t uiInUseSpsNum; 193 uint32_t uiInUseSubsetSpsNum; 194 uint32_t uiInUsePpsNum; 195 } SParaSetOffset; 196 */ 197 198 class CWelsParametersetIdNonConstant : public CWelsParametersetIdConstant { 199 public: CWelsParametersetIdNonConstant(const bool bSimulcastAVC,const int32_t kiSpatialLayerNum)200 CWelsParametersetIdNonConstant (const bool bSimulcastAVC, 201 const int32_t kiSpatialLayerNum): CWelsParametersetIdConstant (bSimulcastAVC, kiSpatialLayerNum) {}; 202 203 virtual void OutputCurrentStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList, 204 sWelsEncCtx* pCtx, 205 SExistingParasetList* pExistingParasetList); 206 virtual void LoadPreviousStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList); 207 }; 208 209 class CWelsParametersetIdIncreasing : public CWelsParametersetIdNonConstant { 210 public: CWelsParametersetIdIncreasing(const bool bSimulcastAVC,const int32_t kiSpatialLayerNum)211 CWelsParametersetIdIncreasing (const bool bSimulcastAVC, 212 const int32_t kiSpatialLayerNum): CWelsParametersetIdNonConstant (bSimulcastAVC, kiSpatialLayerNum) {}; 213 214 215 virtual int32_t GetPpsIdOffset (const int32_t iPpsId); 216 virtual int32_t GetSpsIdOffset (const int32_t iPpsId, const int32_t iSpsId); 217 218 virtual void Update (const uint32_t kuiId, const int iParasetType); 219 220 protected: 221 222 //void ParasetIdAdditionIdAdjust (SParaSetOffsetVariable* sParaSetOffsetVariable, const int32_t kiCurEncoderParaSetId, 223 // const uint32_t kuiMaxIdInBs); 224 225 private: 226 void DebugPps (const int32_t kiPpsId); 227 void DebugSpsPps (const int32_t iPpsId, const int32_t iSpsId); 228 }; 229 230 231 class CWelsParametersetSpsListing : public CWelsParametersetIdNonConstant { 232 public: 233 CWelsParametersetSpsListing (const bool bSimulcastAVC, const int32_t kiSpatialLayerNum); 234 235 virtual uint32_t GetNeededSubsetSpsNum(); 236 237 virtual void LoadPrevious (SExistingParasetList* pExistingParasetList, SWelsSPS* pSpsArray, 238 SSubsetSps* pSubsetArray, 239 SWelsPPS* pPpsArray); 240 241 bool CheckParamCompatibility (SWelsSvcCodingParam* pCodingParam, SLogContext* pLogCtx); 242 243 virtual uint32_t GenerateNewSps (sWelsEncCtx* pCtx, const bool kbUseSubsetSps, const int32_t iDlayerIndex, 244 const int32_t iDlayerCount, uint32_t kuiSpsId, 245 SWelsSPS*& pSps, SSubsetSps*& pSubsetSps, bool bSVCBaselayer); 246 247 virtual void UpdateParaSetNum (sWelsEncCtx* pCtx); 248 GetSpsIdx(const int32_t iIdx)249 int32_t GetSpsIdx (const int32_t iIdx) { 250 return iIdx; 251 }; 252 253 virtual void OutputCurrentStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList, 254 sWelsEncCtx* pCtx, 255 SExistingParasetList* pExistingParasetList); 256 protected: 257 virtual void LoadPreviousSps (SExistingParasetList* pExistingParasetList, SWelsSPS* pSpsArray, 258 SSubsetSps* pSubsetArray); 259 virtual bool CheckPpsGenerating(); 260 virtual int32_t SpsReset (sWelsEncCtx* pCtx, bool kbUseSubsetSps); 261 }; 262 263 class CWelsParametersetSpsPpsListing : public CWelsParametersetSpsListing { 264 public: 265 CWelsParametersetSpsPpsListing (const bool bSimulcastAVC, const int32_t kiSpatialLayerNum); 266 267 //uint32_t GetNeededPpsNum(); 268 269 virtual void UpdatePpsList (sWelsEncCtx* pCtx); 270 271 virtual uint32_t InitPps (sWelsEncCtx* pCtx, uint32_t kiSpsId, 272 SWelsSPS* pSps, 273 SSubsetSps* pSubsetSps, 274 uint32_t kuiPpsId, 275 const bool kbDeblockingFilterPresentFlag, 276 const bool kbUsingSubsetSps, 277 const bool kbEntropyCodingModeFlag); 278 279 virtual void UpdateParaSetNum (sWelsEncCtx* pCtx); 280 281 virtual int32_t GetCurrentPpsId (const int32_t iPpsId, const int32_t iIdrLoop); 282 283 virtual void OutputCurrentStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList, 284 sWelsEncCtx* pCtx, 285 SExistingParasetList* pExistingParasetList); 286 virtual void LoadPreviousStructure (SParaSetOffsetVariable* pParaSetOffsetVariable, int32_t* pPpsIdList); 287 protected: 288 virtual void LoadPreviousPps (SExistingParasetList* pExistingParasetList, SWelsPPS* pPpsArray); 289 290 virtual bool CheckPpsGenerating(); 291 virtual int32_t SpsReset (sWelsEncCtx* pCtx, bool kbUseSubsetSps); 292 }; 293 294 class CWelsParametersetSpsListingPpsIncreasing : public CWelsParametersetSpsListing { 295 public: CWelsParametersetSpsListingPpsIncreasing(const bool bSimulcastAVC,const int32_t kiSpatialLayerNum)296 CWelsParametersetSpsListingPpsIncreasing (const bool bSimulcastAVC, 297 const int32_t kiSpatialLayerNum): CWelsParametersetSpsListing (bSimulcastAVC, kiSpatialLayerNum) {}; 298 299 virtual int32_t GetPpsIdOffset (const int32_t kiPpsId); 300 virtual void Update (const uint32_t kuiId, const int iParasetType); 301 }; 302 303 int32_t FindExistingSps (SWelsSvcCodingParam* pParam, const bool kbUseSubsetSps, const int32_t iDlayerIndex, 304 const int32_t iDlayerCount, const int32_t iSpsNumInUse, 305 SWelsSPS* pSpsArray, 306 SSubsetSps* pSubsetArray, bool bSVCBaseLayer); 307 308 } 309 310 #endif 311