shithub: openh264

Download patch

ref: 493d254a4a6bdd7fa7080ac23cd1d6110288544b
parent: 49f8fe8c5c55766e6445b922855e9adbefa6fe8a
author: ruil2 <[email protected]>
date: Tue Aug 12 05:28:40 EDT 2014

merge level table

--- a/codec/common/inc/wels_common_defs.h
+++ b/codec/common/inc/wels_common_defs.h
@@ -42,6 +42,21 @@
 namespace WelsCommon {
 /*common use table*/
 
+#define LEVEL_NUMBER 17
+typedef struct TagLevelLimits {
+  uint8_t uiLevelIdc;  // level idc
+  uint32_t uiMaxMBPS; // Max macroblock processing rate(MB/s)
+  uint32_t uiMaxFS;   // Max frame sizea(MBs)
+  uint32_t uiMaxDPBMbs;// Max decoded picture buffer size(MBs)
+  uint32_t uiMaxBR; // Max video bit rate
+  uint32_t uiMaxCPB; // Max CPB size
+  int16_t iMinVmv; // Vertical MV component range upper bound
+  int16_t iMaxVmv; // Vertical MV component range lower bound
+  uint16_t uiMinCR;  // Min compression ration
+  int16_t iMaxMvsPer2Mb; // Max number of motion vectors per two consecutive MBs
+} SLevelLimits;
+
+extern const SLevelLimits g_ksLevelLimits[LEVEL_NUMBER];
 extern const uint8_t g_kuiMbCountScan4Idx[24];
 extern const uint8_t g_kuiCache30ScanIdx[16];
 extern const uint8_t g_kuiCache48CountScan4Idx[24];
@@ -53,38 +68,38 @@
  *	NAL Unit Type (5 Bits)
  */
 enum EWelsNalUnitType {
-NAL_UNIT_UNSPEC_0			= 0,
-NAL_UNIT_CODED_SLICE		= 1,
-NAL_UNIT_CODED_SLICE_DPA	= 2,
-NAL_UNIT_CODED_SLICE_DPB	= 3,
-NAL_UNIT_CODED_SLICE_DPC	= 4,
-NAL_UNIT_CODED_SLICE_IDR	= 5,
-NAL_UNIT_SEI				= 6,
-NAL_UNIT_SPS				= 7,
-NAL_UNIT_PPS				= 8,
-NAL_UNIT_AU_DELIMITER		= 9,
-NAL_UNIT_END_OF_SEQ			= 10,
-NAL_UNIT_END_OF_STR			= 11,
-NAL_UNIT_FILLER_DATA		= 12,
-NAL_UNIT_SPS_EXT			= 13,
-NAL_UNIT_PREFIX				= 14,
-NAL_UNIT_SUBSET_SPS			= 15,
-NAL_UNIT_RESV_16			= 16,
-NAL_UNIT_RESV_17			= 17,
-NAL_UNIT_RESV_18			= 18,
-NAL_UNIT_AUX_CODED_SLICE	= 19,
-NAL_UNIT_CODED_SLICE_EXT	= 20,
-NAL_UNIT_RESV_21			= 21,
-NAL_UNIT_RESV_22			= 22,
-NAL_UNIT_RESV_23			= 23,
-NAL_UNIT_UNSPEC_24			= 24,
-NAL_UNIT_UNSPEC_25			= 25,
-NAL_UNIT_UNSPEC_26			= 26,
-NAL_UNIT_UNSPEC_27			= 27,
-NAL_UNIT_UNSPEC_28			= 28,
-NAL_UNIT_UNSPEC_29			= 29,
-NAL_UNIT_UNSPEC_30			= 30,
-NAL_UNIT_UNSPEC_31			= 31
+  NAL_UNIT_UNSPEC_0			= 0,
+  NAL_UNIT_CODED_SLICE		= 1,
+  NAL_UNIT_CODED_SLICE_DPA	= 2,
+  NAL_UNIT_CODED_SLICE_DPB	= 3,
+  NAL_UNIT_CODED_SLICE_DPC	= 4,
+  NAL_UNIT_CODED_SLICE_IDR	= 5,
+  NAL_UNIT_SEI				= 6,
+  NAL_UNIT_SPS				= 7,
+  NAL_UNIT_PPS				= 8,
+  NAL_UNIT_AU_DELIMITER		= 9,
+  NAL_UNIT_END_OF_SEQ			= 10,
+  NAL_UNIT_END_OF_STR			= 11,
+  NAL_UNIT_FILLER_DATA		= 12,
+  NAL_UNIT_SPS_EXT			= 13,
+  NAL_UNIT_PREFIX				= 14,
+  NAL_UNIT_SUBSET_SPS			= 15,
+  NAL_UNIT_RESV_16			= 16,
+  NAL_UNIT_RESV_17			= 17,
+  NAL_UNIT_RESV_18			= 18,
+  NAL_UNIT_AUX_CODED_SLICE	= 19,
+  NAL_UNIT_CODED_SLICE_EXT	= 20,
+  NAL_UNIT_RESV_21			= 21,
+  NAL_UNIT_RESV_22			= 22,
+  NAL_UNIT_RESV_23			= 23,
+  NAL_UNIT_UNSPEC_24			= 24,
+  NAL_UNIT_UNSPEC_25			= 25,
+  NAL_UNIT_UNSPEC_26			= 26,
+  NAL_UNIT_UNSPEC_27			= 27,
+  NAL_UNIT_UNSPEC_28			= 28,
+  NAL_UNIT_UNSPEC_29			= 29,
+  NAL_UNIT_UNSPEC_30			= 30,
+  NAL_UNIT_UNSPEC_31			= 31
 };
 
 /*
@@ -92,10 +107,10 @@
  */
 
 enum EWelsNalRefIdc {
-NRI_PRI_LOWEST	= 0,
-NRI_PRI_LOW		= 1,
-NRI_PRI_HIGH	= 2,
-NRI_PRI_HIGHEST	= 3
+  NRI_PRI_LOWEST	= 0,
+  NRI_PRI_LOW		= 1,
+  NRI_PRI_HIGH	= 2,
+  NRI_PRI_HIGHEST	= 3
 };
 
 /*
@@ -103,9 +118,9 @@
  */
 
 enum EVclType {
-NON_VCL			= 0,
-VCL				= 1,
-NOT_APP			= 2
+  NON_VCL			= 0,
+  VCL				= 1,
+  NOT_APP			= 2
 };
 
 /*
@@ -132,26 +147,26 @@
  */
 
 enum EWelsSliceType {
-P_SLICE	= 0,
-B_SLICE	= 1,
-I_SLICE	= 2,
-SP_SLICE = 3,
-SI_SLICE = 4,
-UNKNOWN_SLICE = 5
+  P_SLICE	= 0,
+  B_SLICE	= 1,
+  I_SLICE	= 2,
+  SP_SLICE = 3,
+  SI_SLICE = 4,
+  UNKNOWN_SLICE = 5
 };
 
 /* SSlice Types in scalable extension */		;
 enum ESliceTypeExt {
-EP_SLICE = 0,	// EP_SLICE: 0, 5
-EB_SLICE = 1,	// EB_SLICE: 1, 6
-EI_SLICE = 2	// EI_SLICE: 2, 7
+  EP_SLICE = 0,	// EP_SLICE: 0, 5
+  EB_SLICE = 1,	// EB_SLICE: 1, 6
+  EI_SLICE = 2	// EI_SLICE: 2, 7
 };
 
 /* List Index */
 enum EListIndex {
-LIST_0	= 0,
-LIST_1	= 1,
-LIST_A	= 2
+  LIST_0	= 0,
+  LIST_1	= 1,
+  LIST_A	= 2
 };
 
 
@@ -158,17 +173,17 @@
 
 /* Motion Vector components */
 enum EMvComp {
-MV_X	= 0,
-MV_Y	= 1,
-MV_A	= 2
+  MV_X	= 0,
+  MV_Y	= 1,
+  MV_A	= 2
 };
 
 /* Chroma Components */
 
 enum EChromaComp {
-CHROMA_CB	= 0,
-CHROMA_CR	= 1,
-CHROMA_A	= 2
+  CHROMA_CB	= 0,
+  CHROMA_CR	= 1,
+  CHROMA_A	= 2
 };
 
 
@@ -177,13 +192,13 @@
  *	Memory Management Control Operation (MMCO) code
  */
 enum EMmcoCode {
-MMCO_END			= 0,
-MMCO_SHORT2UNUSED	= 1,
-MMCO_LONG2UNUSED	= 2,
-MMCO_SHORT2LONG		= 3,
-MMCO_SET_MAX_LONG	= 4,
-MMCO_RESET			= 5,
-MMCO_LONG			= 6
+  MMCO_END			= 0,
+  MMCO_SHORT2UNUSED	= 1,
+  MMCO_LONG2UNUSED	= 2,
+  MMCO_SHORT2LONG		= 3,
+  MMCO_SET_MAX_LONG	= 4,
+  MMCO_RESET			= 5,
+  MMCO_LONG			= 6
 };
 
 /////////intra16x16  Luma
--- a/codec/common/src/common_tables.cpp
+++ b/codec/common/src/common_tables.cpp
@@ -149,5 +149,29 @@
   /*50*/{ 3328, 4096, 3328, 4096, 4096, 5120, 4096, 5120 },	/*51*/{ 3584, 4608, 3584, 4608, 4608, 5888, 4608, 5888 },
 };
 
+// table A-1 - Level limits
+const SLevelLimits g_ksLevelLimits[LEVEL_NUMBER] = {
+  {10, 1485, 99, 396, 64, 175, -256, 255, 2, 0x7fff}, /* level 1 */
+  {9, 1485, 99, 396, 128, 350, -256, 255, 2, 0x7fff}, /* level 1.b */
+  {11, 3000, 396, 900, 192, 500, -512, 511, 2, 0x7fff}, /* level 1.1 */
+  {12, 6000, 396, 2376, 384, 1000, -512, 511, 2, 0x7fff}, /* level 1.2 */
+  {13, 11880, 396, 2376, 768, 2000, -512, 511, 2, 0x7fff}, /* level 1.3 */
+
+  {20, 11880, 396, 2376, 2000, 2000, -512, 511, 2, 0x7fff}, /* level 2 */
+  {21, 19800, 792, 4752, 4000, 4000, -1024, 1023, 2, 0x7fff}, /* level 2.1 */
+  {22, 20250, 1620, 8100, 4000, 4000, -1024, 1023, 2, 0x7fff}, /* level 2.2 */
+
+  {30, 40500, 1620, 8100, 10000, 10000, -1024, 1023, 2, 32 }, /* level 3 */
+  {31, 108000, 3600, 18000, 14000, 14000, -2048, 2047, 4, 16}, /* level 3.1 */
+  {32, 216000, 5120, 20480, 20000, 20000, -2048, 2047, 4, 16}, /* level 3.2 */
+
+  {40, 245760, 8192, 32768, 20000, 25000, -2048, 2047, 4, 16}, /* level 4 */
+  {41, 245760, 8192, 32768, 50000, 62500, -2048, 2047, 2, 16}, /* level 4.1 */
+  {42, 522240, 8704, 34816, 50000, 62500, -2048, 2047, 2, 16}, /* level 4.2 */
+
+  {50, 589824, 22080, 110400, 135000, 135000, -2048, 2047, 2, 16}, /* level 5 */
+  {51, 983040, 36864, 184320, 240000, 240000, -2048, 2047, 2, 16}, /* level 5.1 */
+  {52, 2073600, 36864, 184320, 240000, 240000, -2048, 2047, 2, 16} /* level 5.2 */
+};
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 }
--- a/codec/decoder/core/inc/parameter_sets.h
+++ b/codec/decoder/core/inc/parameter_sets.h
@@ -39,67 +39,56 @@
 
 namespace WelsDec {
 
-typedef struct TagLevelLimits {
-int32_t iMaxMBPS; // Max macroblock processing rate(MB/s)
-int32_t iMaxFS;   // Max frame sizea(MBs)
-int32_t iMaxDPBMbs;// Max decoded picture buffer size(MBs)
-int32_t iMaxBR; // Max video bit rate
-int32_t iMaxCPB; // Max CPB size
-int16_t iMinVmv; // Vertical MV component range upper bound
-int16_t iMaxVmv; // Vertical MV component range lower bound
-int16_t iMinCR;  // Min compression ration
-int16_t iMaxMvsPer2Mb; // Max number of motion vectors per two consecutive MBs
-} SLevelLimits;
 
 /* Sequence Parameter Set, refer to Page 57 in JVT X201wcm */
 typedef struct TagSps {
-int32_t	    iSpsId;
-uint32_t	iMbWidth;
-uint32_t	iMbHeight;
-uint32_t	uiTotalMbCount;	//used in decode_slice_data()
+  int32_t	    iSpsId;
+  uint32_t	iMbWidth;
+  uint32_t	iMbHeight;
+  uint32_t	uiTotalMbCount;	//used in decode_slice_data()
 
-uint32_t	uiLog2MaxFrameNum;
-uint32_t	uiPocType;
-/* POC type 0 */
-int32_t		iLog2MaxPocLsb;
-/* POC type 1 */
-int32_t		iOffsetForNonRefPic;
+  uint32_t	uiLog2MaxFrameNum;
+  uint32_t	uiPocType;
+  /* POC type 0 */
+  int32_t		iLog2MaxPocLsb;
+  /* POC type 1 */
+  int32_t		iOffsetForNonRefPic;
 
-int32_t		iOffsetForTopToBottomField;
-int32_t		iNumRefFramesInPocCycle;
-int8_t		iOffsetForRefFrame[256];
-int32_t		iNumRefFrames;
+  int32_t		iOffsetForTopToBottomField;
+  int32_t		iNumRefFramesInPocCycle;
+  int8_t		iOffsetForRefFrame[256];
+  int32_t		iNumRefFrames;
 
-SPosOffset	sFrameCrop;
+  SPosOffset	sFrameCrop;
 
-ProfileIdc	uiProfileIdc;
-uint8_t		uiLevelIdc;
-uint8_t		uiChromaFormatIdc;
-uint8_t		uiChromaArrayType;
+  ProfileIdc	uiProfileIdc;
+  uint8_t		uiLevelIdc;
+  uint8_t		uiChromaFormatIdc;
+  uint8_t		uiChromaArrayType;
 
-uint8_t		uiBitDepthLuma;
-uint8_t		uiBitDepthChroma;
-/* TO BE CONTINUE: POC type 1 */
-bool		bDeltaPicOrderAlwaysZeroFlag;
-bool		bGapsInFrameNumValueAllowedFlag;
+  uint8_t		uiBitDepthLuma;
+  uint8_t		uiBitDepthChroma;
+  /* TO BE CONTINUE: POC type 1 */
+  bool		bDeltaPicOrderAlwaysZeroFlag;
+  bool		bGapsInFrameNumValueAllowedFlag;
 
-bool		bFrameMbsOnlyFlag;
-bool		bMbaffFlag;	// MB Adapative Frame Field
-bool		bDirect8x8InferenceFlag;
-bool		bFrameCroppingFlag;
+  bool		bFrameMbsOnlyFlag;
+  bool		bMbaffFlag;	// MB Adapative Frame Field
+  bool		bDirect8x8InferenceFlag;
+  bool		bFrameCroppingFlag;
 
-bool		bVuiParamPresentFlag;
+  bool		bVuiParamPresentFlag;
 //	bool		bTimingInfoPresentFlag;
 //	bool		bFixedFrameRateFlag;
-bool		bConstraintSet0Flag;
-bool		bConstraintSet1Flag;
-bool		bConstraintSet2Flag;
-bool		bConstraintSet3Flag;
-bool		bSeparateColorPlaneFlag;
-bool		bQpPrimeYZeroTransfBypassFlag;
-bool		bSeqScalingMatrixPresentFlag;
-bool		bSeqScalingListPresentFlag[12];
-const SLevelLimits* pSLevelLimits;
+  bool		bConstraintSet0Flag;
+  bool		bConstraintSet1Flag;
+  bool		bConstraintSet2Flag;
+  bool		bConstraintSet3Flag;
+  bool		bSeparateColorPlaneFlag;
+  bool		bQpPrimeYZeroTransfBypassFlag;
+  bool		bSeqScalingMatrixPresentFlag;
+  bool		bSeqScalingListPresentFlag[12];
+  const SLevelLimits* pSLevelLimits;
 } SSps, *PSps;
 
 
@@ -117,63 +106,63 @@
 
 /* Sequence Parameter Set extension syntax, refer to Page 391 in JVT X201wcm */
 typedef struct TagSpsSvcExt {
-SPosOffset	sSeqScaledRefLayer;
+  SPosOffset	sSeqScaledRefLayer;
 
-uint8_t		uiExtendedSpatialScalability;	// ESS
-uint8_t		uiChromaPhaseXPlus1Flag;
-uint8_t		uiChromaPhaseYPlus1;
-uint8_t		uiSeqRefLayerChromaPhaseXPlus1Flag;
-uint8_t		uiSeqRefLayerChromaPhaseYPlus1;
-bool		bInterLayerDeblockingFilterCtrlPresentFlag;
-bool		bSeqTCoeffLevelPredFlag;
-bool		bAdaptiveTCoeffLevelPredFlag;
-bool		bSliceHeaderRestrictionFlag;
+  uint8_t		uiExtendedSpatialScalability;	// ESS
+  uint8_t		uiChromaPhaseXPlus1Flag;
+  uint8_t		uiChromaPhaseYPlus1;
+  uint8_t		uiSeqRefLayerChromaPhaseXPlus1Flag;
+  uint8_t		uiSeqRefLayerChromaPhaseYPlus1;
+  bool		bInterLayerDeblockingFilterCtrlPresentFlag;
+  bool		bSeqTCoeffLevelPredFlag;
+  bool		bAdaptiveTCoeffLevelPredFlag;
+  bool		bSliceHeaderRestrictionFlag;
 } SSpsSvcExt, *PSpsSvcExt;
 
 /* Subset sequence parameter set syntax, refer to Page 391 in JVT X201wcm */
 typedef struct TagSubsetSps {
-SSps		sSps;
-SSpsSvcExt	sSpsSvcExt;
-bool		bSvcVuiParamPresentFlag;
-bool		bAdditionalExtension2Flag;
-bool		bAdditionalExtension2DataFlag;
+  SSps		sSps;
+  SSpsSvcExt	sSpsSvcExt;
+  bool		bSvcVuiParamPresentFlag;
+  bool		bAdditionalExtension2Flag;
+  bool		bAdditionalExtension2DataFlag;
 } SSubsetSps, *PSubsetSps;
 
 /* Picture parameter set syntax, refer to Page 59 in JVT X201wcm */
 typedef struct TagPps {
-int32_t	iSpsId;
-int32_t	iPpsId;
+  int32_t	iSpsId;
+  int32_t	iPpsId;
 
-uint32_t	uiNumSliceGroups;
-uint32_t	uiSliceGroupMapType;
-/* slice_group_map_type = 0 */
-uint32_t	uiRunLength[MAX_SLICEGROUP_IDS];
-/* slice_group_map_type = 2 */
-uint32_t	uiTopLeft[MAX_SLICEGROUP_IDS];
-uint32_t	uiBottomRight[MAX_SLICEGROUP_IDS];
-/* slice_group_map_type = 3, 4 or 5 */
-uint32_t	uiSliceGroupChangeRate;
-/* slice_group_map_type = 6 */
-uint32_t	uiPicSizeInMapUnits;
-uint32_t	uiSliceGroupId[MAX_SLICEGROUP_IDS];
+  uint32_t	uiNumSliceGroups;
+  uint32_t	uiSliceGroupMapType;
+  /* slice_group_map_type = 0 */
+  uint32_t	uiRunLength[MAX_SLICEGROUP_IDS];
+  /* slice_group_map_type = 2 */
+  uint32_t	uiTopLeft[MAX_SLICEGROUP_IDS];
+  uint32_t	uiBottomRight[MAX_SLICEGROUP_IDS];
+  /* slice_group_map_type = 3, 4 or 5 */
+  uint32_t	uiSliceGroupChangeRate;
+  /* slice_group_map_type = 6 */
+  uint32_t	uiPicSizeInMapUnits;
+  uint32_t	uiSliceGroupId[MAX_SLICEGROUP_IDS];
 
-uint32_t	uiNumRefIdxL0Active;
-uint32_t	uiNumRefIdxL1Active;
+  uint32_t	uiNumRefIdxL0Active;
+  uint32_t	uiNumRefIdxL1Active;
 
-int32_t		iPicInitQp;
-int32_t		iPicInitQs;
-int32_t		iChromaQpIndexOffset;
+  int32_t		iPicInitQp;
+  int32_t		iPicInitQs;
+  int32_t		iChromaQpIndexOffset;
 
-bool		bEntropyCodingModeFlag;
-bool		bPicOrderPresentFlag;
-/* slice_group_map_type = 3, 4 or 5 */
-bool		bSliceGroupChangeDirectionFlag;
-bool		bDeblockingFilterControlPresentFlag;
+  bool		bEntropyCodingModeFlag;
+  bool		bPicOrderPresentFlag;
+  /* slice_group_map_type = 3, 4 or 5 */
+  bool		bSliceGroupChangeDirectionFlag;
+  bool		bDeblockingFilterControlPresentFlag;
 
-bool		bConstainedIntraPredFlag;
-bool		bRedundantPicCntPresentFlag;
-bool		bWeightedPredFlag;
-uint8_t		uiWeightedBipredIdc;
+  bool		bConstainedIntraPredFlag;
+  bool		bRedundantPicCntPresentFlag;
+  bool		bWeightedPredFlag;
+  uint8_t		uiWeightedBipredIdc;
 
 } SPps, *PPps;
 
--- a/codec/decoder/core/src/au_parser.cpp
+++ b/codec/decoder/core/src/au_parser.cpp
@@ -688,64 +688,43 @@
   return 0;
 }
 
-// table A-1 - Level limits
-static const SLevelLimits g_kSLevelLimits[17] = {
-  {1485, 99, 396, 64, 175, -256, 255, 2, 0x7fff}, /* level 1 */
-  {1485, 99, 396, 128, 350, -256, 255, 2, 0x7fff}, /* level 1.b */
-  {3000, 396, 900, 192, 500, -512, 511, 2, 0x7fff}, /* level 1.1 */
-  {6000, 396, 2376, 384, 1000, -512, 511, 2, 0x7fff}, /* level 1.2 */
-  {11880, 396, 2376, 768, 2000, -512, 511, 2, 0x7fff}, /* level 1.3 */
-  {11880, 396, 2376, 2000, 2000, -512, 511, 2, 0x7fff}, /* level 2 */
-  {19800, 792, 4752, 4000, 4000, -1024, 1023, 2, 0x7fff}, /* level 2.1 */
-  {20250, 1620, 8100, 4000, 4000, -1024, 1023, 2, 0x7fff}, /* level 2.2 */
-  {40500, 1620, 8100, 10000, 10000, -1024, 1023, 2, 32 }, /* level 3 */
-  {108000, 3600, 18000, 14000, 14000, -2048, 2047, 4, 16}, /* level 3.1 */
-  {216000, 5120, 20480, 20000, 20000, -2048, 2047, 4, 16}, /* level 3.2 */
-  {245760, 8192, 32768, 20000, 25000, -2048, 2047, 4, 16}, /* level 4 */
-  {245760, 8192, 32768, 50000, 62500, -2048, 2047, 2, 16}, /* level 4.1 */
-  {522240, 8704, 34816, 50000, 62500, -2048, 2047, 2, 16}, /* level 4.2 */
-  {589824, 22080, 110400, 135000, 135000, -2048, 2047, 2, 16}, /* level 5 */
-  {983040, 36864, 184320, 240000, 240000, -2048, 2047, 2, 16}, /* level 5.1 */
-  {2073600, 36864, 184320, 240000, 240000, -2048, 2047, 2, 16} /* level 5.2 */
-};
-
 const SLevelLimits* GetLevelLimits (int32_t iLevelIdx, bool bConstraint3) {
   switch (iLevelIdx) {
   case 10:
-    return &g_kSLevelLimits[0];
+    return &g_ksLevelLimits[0];
   case 11:
     if (bConstraint3)
-      return &g_kSLevelLimits[1];
+      return &g_ksLevelLimits[1];
     else
-      return &g_kSLevelLimits[2];
+      return &g_ksLevelLimits[2];
   case 12:
-    return &g_kSLevelLimits[3];
+    return &g_ksLevelLimits[3];
   case 13:
-    return &g_kSLevelLimits[4];
+    return &g_ksLevelLimits[4];
   case 20:
-    return &g_kSLevelLimits[5];
+    return &g_ksLevelLimits[5];
   case 21:
-    return &g_kSLevelLimits[6];
+    return &g_ksLevelLimits[6];
   case 22:
-    return &g_kSLevelLimits[7];
+    return &g_ksLevelLimits[7];
   case 30:
-    return &g_kSLevelLimits[8];
+    return &g_ksLevelLimits[8];
   case 31:
-    return &g_kSLevelLimits[9];
+    return &g_ksLevelLimits[9];
   case 32:
-    return &g_kSLevelLimits[10];
+    return &g_ksLevelLimits[10];
   case 40:
-    return &g_kSLevelLimits[11];
+    return &g_ksLevelLimits[11];
   case 41:
-    return &g_kSLevelLimits[12];
+    return &g_ksLevelLimits[12];
   case 42:
-    return &g_kSLevelLimits[13];
+    return &g_ksLevelLimits[13];
   case 50:
-    return &g_kSLevelLimits[14];
+    return &g_ksLevelLimits[14];
   case 51:
-    return &g_kSLevelLimits[15];
+    return &g_ksLevelLimits[15];
   case 52:
-    return &g_kSLevelLimits[16];
+    return &g_ksLevelLimits[16];
   default:
     return NULL;
   }
@@ -923,7 +902,7 @@
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "pic_width_in_mbs(%d) exceeds the maximum allowed!\n", pSps->iMbWidth);
     return  GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_MAX_MB_SIZE);
   }
-  if (((uint64_t)pSps->iMbWidth * (uint64_t)pSps->iMbWidth) > (uint64_t) (8 * pSLevelLimits->iMaxFS)) {
+  if (((uint64_t)pSps->iMbWidth * (uint64_t)pSps->iMbWidth) > (uint64_t) (8 * pSLevelLimits->uiMaxFS)) {
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, " the pic_width_in_mbs exceeds the level limits!\n");
   }
   WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //pic_height_in_map_units_minus1
@@ -932,11 +911,11 @@
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "pic_height_in_mbs(%d) exceeds the maximum allowed!\n", pSps->iMbHeight);
     return  GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_MAX_MB_SIZE);
   }
-  if (((uint64_t)pSps->iMbHeight * (uint64_t)pSps->iMbHeight) > (uint64_t) (8 * pSLevelLimits->iMaxFS)) {
+  if (((uint64_t)pSps->iMbHeight * (uint64_t)pSps->iMbHeight) > (uint64_t) (8 * pSLevelLimits->uiMaxFS)) {
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, " the pic_height_in_mbs exceeds the level limits!\n");
   }
   uint32_t uiTmp32 = pSps->iMbWidth * pSps->iMbHeight;
-  if (uiTmp32 > (uint32_t)pSLevelLimits->iMaxFS) {
+  if (uiTmp32 > (uint32_t)pSLevelLimits->uiMaxFS) {
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, " the total count of mb exceeds the level limits!\n");
   }
   pSps->uiTotalMbCount	= uiTmp32;
@@ -943,7 +922,7 @@
   WELS_CHECK_SE_UPPER_ERROR (pSps->iNumRefFrames, SPS_MAX_NUM_REF_FRAMES_MAX, "max_num_ref_frames",
                              GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_MAX_NUM_REF_FRAMES));
   // here we check max_num_ref_frames
-  uint32_t uiMaxDpbMbs = pSLevelLimits->iMaxDPBMbs;
+  uint32_t uiMaxDpbMbs = pSLevelLimits->uiMaxDPBMbs;
   uint32_t uiMaxDpbFrames = uiMaxDpbMbs / pSps->uiTotalMbCount;
   if (uiMaxDpbFrames > SPS_MAX_NUM_REF_FRAMES_MAX)
     uiMaxDpbFrames = SPS_MAX_NUM_REF_FRAMES_MAX;
--- a/codec/encoder/core/src/au_set.cpp
+++ b/codec/encoder/core/src/au_set.cpp
@@ -41,43 +41,14 @@
 #include "au_set.h"
 #include "svc_enc_golomb.h"
 #include "macros.h"
-namespace WelsEnc {
 
+#include "wels_common_defs.h"
 
-#define LEVEL_NUMBER 16
+using namespace WelsCommon;
 
-typedef struct TagLevelLimit {
-  uint8_t iLevelIdc;
-  uint32_t uiMaxMbPS; // Max MBs processing speed
-  uint32_t uiMaxFS; // Max Frame size
-  uint32_t uiMaxDPBMB; //Max DPB MB Size
-  uint32_t uiMaxBR; //Max Bitrate
-} SLevelLimit;
+namespace WelsEnc {
 
-const SLevelLimit g_ksLevelLimit[LEVEL_NUMBER] = {
-  { 10,   1485,    99,	  396,     64 },                 //10
-  { 9,    1485,    99,	  396,    128 },                 //9 (1b)
-  { 11,   3000,   396,	  900,    192 },                 //11
-  { 12,   6000,   396,	 2376,    384 },                 //12
-  { 13,  11880,   396,	 2376,    768 },                 //13
-
-  { 20,  11880,   396,    2376,   2000 },                 //20
-  { 21,  19800,   792,    4752,   4000 },                 //21
-  { 22,  20250,  1620,    8100,   4000 },                 //22
-
-  { 30,  40500,  1620,    8100,  10000 },                 //30
-  { 31, 108000,  3600,   18000,  14000 },                 //31
-  { 32, 216000,  5120,   20480,  20000 },                 //32
-
-  { 40, 245760,  8192,   32768,  20000 },                 //40
-  { 41, 245760,  8192,   32768,  50000 },                 //41
-  { 42, 491520,  8192,   34816,  50000 },                 //42
-
-  { 50, 589824, 22080,  110400, 135000 },                 //50
-  { 51, 983040, 36864,  184320, 240000 }                  //51
-};
-
-static inline int32_t WelsCheckLevelLimitation (const SWelsSPS* kpSps, const SLevelLimit* kpLevelLimit,
+static inline int32_t WelsCheckLevelLimitation (const SWelsSPS* kpSps, const SLevelLimits* kpLevelLimit,
     float fFrameRate, int32_t iTargetBitRate) {
   uint32_t uiPicWidthInMBs = kpSps->iMbWidth;
   uint32_t uiPicHeightInMBs = kpSps->iMbHeight;
@@ -84,7 +55,7 @@
   uint32_t uiPicInMBs = uiPicWidthInMBs * uiPicHeightInMBs;
   uint32_t uiNumRefFrames = kpSps->iNumRefFrames;
 
-  if (kpLevelLimit->uiMaxMbPS < (uint32_t) (uiPicInMBs * fFrameRate))
+  if (kpLevelLimit->uiMaxMBPS < (uint32_t) (uiPicInMBs * fFrameRate))
     return 0;
   if (kpLevelLimit->uiMaxFS < uiPicInMBs)
     return 0;
@@ -92,7 +63,7 @@
     return 0;
   if ((kpLevelLimit->uiMaxFS << 3) < (uiPicHeightInMBs * uiPicHeightInMBs))
     return 0;
-  if (kpLevelLimit->uiMaxDPBMB < uiNumRefFrames * uiPicInMBs)
+  if (kpLevelLimit->uiMaxDPBMbs < uiNumRefFrames * uiPicInMBs)
     return 0;
   if (iTargetBitRate
       && ((int32_t) kpLevelLimit->uiMaxBR  * 1200) < iTargetBitRate)    //RC enabled, considering bitrate constraint
@@ -114,7 +85,7 @@
       pSpatialLayer->uiLevelIdc = LEVEL_5_0;
       WelsLog (pLogCtx, WELS_LOG_WARNING, "change level to level5.0\n");
     }
-    iRefFrame = g_ksLevelLimit[pSpatialLayer->uiLevelIdc - 1].uiMaxDPBMB / uiPicInMBs;
+    iRefFrame = g_ksLevelLimits[pSpatialLayer->uiLevelIdc - 1].uiMaxDPBMbs / uiPicInMBs;
     if (iRefFrame < pParam->iMaxNumRefFrame)
       pParam->iMaxNumRefFrame = iRefFrame;
     if (pParam->iMaxNumRefFrame < 1) {
@@ -129,8 +100,8 @@
 static inline int32_t WelsGetLevelIdc (const SWelsSPS* kpSps, float fFrameRate, int32_t iTargetBitRate) {
   int32_t iOrder;
   for (iOrder = 0; iOrder < LEVEL_NUMBER; iOrder++) {
-    if (WelsCheckLevelLimitation (kpSps, & (g_ksLevelLimit[iOrder]), fFrameRate, iTargetBitRate)) {
-      return (int32_t) (g_ksLevelLimit[iOrder].iLevelIdc);
+    if (WelsCheckLevelLimitation (kpSps, & (g_ksLevelLimits[iOrder]), fFrameRate, iTargetBitRate)) {
+      return (int32_t) (g_ksLevelLimits[iOrder].uiLevelIdc);
     }
   }
   return 51; //final decision: select the biggest level