shithub: openh264

Download patch

ref: 69fe242dc7933a356703b5b4488d169dd717ab63
parent: 9a74427a613999bf5efac9c6b498081beb2d1eb3
parent: 5ed24f216b7848abec4b821cba3548bcab1937a7
author: sijchen <[email protected]>
date: Tue May 6 11:29:56 EDT 2014

Merge pull request #790 from huili2/astyle_all

astyle all files

--- a/codec/api/svc/codec_api.h
+++ b/codec/api/svc/codec_api.h
@@ -75,7 +75,7 @@
   /*
    * return: 0 - success; otherwise - failed;
    */
-  virtual int EXTAPI PauseFrame (const SSourcePicture* kpSrcPic,SFrameBSInfo* pBsInfo) = 0;
+  virtual int EXTAPI PauseFrame (const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo) = 0;
 
   /*
    * return: 0 - success; otherwise - failed;
@@ -99,30 +99,30 @@
   virtual long EXTAPI Uninitialize() = 0;
 
   virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* pSrc,
-                                             const int iSrcLen,
-                                             unsigned char** ppDst,
-                                             int* pStride,
-                                             int& iWidth,
-                                             int& iHeight) = 0;
+      const int iSrcLen,
+      unsigned char** ppDst,
+      int* pStride,
+      int& iWidth,
+      int& iHeight) = 0;
   /*
    * return: 0 - success; otherwise -failed;
    */
   virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* pSrc,
-                                              const int iSrcLen,
-                                              void** ppDst,
-                                              SBufferInfo* pDstInfo) = 0;
+      const int iSrcLen,
+      void** ppDst,
+      SBufferInfo* pDstInfo) = 0;
 
   /*
    *  this API does not work for now!! This is for future use to support non-I420 color format output.
    */
   virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* pSrc,
-                                               const int iSrcLen,
-                                               unsigned char* pDst,
-                                               int iDstStride,
-                                               int& iDstLen,
-                                               int& iWidth,
-                                               int& iHeight,
-                                               int& iColorFormat) = 0;
+      const int iSrcLen,
+      unsigned char* pDst,
+      int iDstStride,
+      int& iDstLen,
+      int& iWidth,
+      int& iHeight,
+      int& iColorFormat) = 0;
 
   /*************************************************************************
    * OutDataFormat, Eos Flag, EC method, ...
@@ -141,62 +141,62 @@
 typedef const ISVCEncoderVtbl* ISVCEncoder;
 struct ISVCEncoderVtbl {
 
-  int (*Initialize) (ISVCEncoder*, const SEncParamBase* pParam);
-  int (*InitializeExt) (ISVCEncoder*, const SEncParamExt* pParam);
+int (*Initialize) (ISVCEncoder*, const SEncParamBase* pParam);
+int (*InitializeExt) (ISVCEncoder*, const SEncParamExt* pParam);
 
-  int (*GetDefaultParams) (ISVCEncoder*, SEncParamExt* pParam);
+int (*GetDefaultParams) (ISVCEncoder*, SEncParamExt* pParam);
 
-  int (*Uninitialize) (ISVCEncoder*);
+int (*Uninitialize) (ISVCEncoder*);
 
-  int (*EncodeFrame) (ISVCEncoder*, const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo);
-  int (*EncodeParameterSets) (ISVCEncoder*, SFrameBSInfo* pBsInfo);
+int (*EncodeFrame) (ISVCEncoder*, const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo);
+int (*EncodeParameterSets) (ISVCEncoder*, SFrameBSInfo* pBsInfo);
 
-  int (*PauseFrame) (ISVCEncoder*, const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo);
+int (*PauseFrame) (ISVCEncoder*, const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo);
 
-  int (*ForceIntraFrame) (ISVCEncoder*, bool bIDR);
+int (*ForceIntraFrame) (ISVCEncoder*, bool bIDR);
 
-  int (*SetOption) (ISVCEncoder*, ENCODER_OPTION eOptionId, void* pOption);
-  int (*GetOption) (ISVCEncoder*, ENCODER_OPTION eOptionId, void* pOption);
+int (*SetOption) (ISVCEncoder*, ENCODER_OPTION eOptionId, void* pOption);
+int (*GetOption) (ISVCEncoder*, ENCODER_OPTION eOptionId, void* pOption);
 };
 
 typedef struct ISVCDecoderVtbl ISVCDecoderVtbl;
 typedef const ISVCDecoderVtbl* ISVCDecoder;
 struct ISVCDecoderVtbl {
-  long (*Initialize) (ISVCDecoder*, const SDecodingParam* pParam);
-  long (*Uninitialize) (ISVCDecoder*);
+long (*Initialize) (ISVCDecoder*, const SDecodingParam* pParam);
+long (*Uninitialize) (ISVCDecoder*);
 
-  DECODING_STATE (*DecodeFrame) (ISVCDecoder*, const unsigned char* pSrc,
+DECODING_STATE (*DecodeFrame) (ISVCDecoder*, const unsigned char* pSrc,
+                               const int iSrcLen,
+                               unsigned char** ppDst,
+                               int* pStride,
+                               int* iWidth,
+                               int* iHeight);
+
+DECODING_STATE (*DecodeFrame2) (ISVCDecoder*, const unsigned char* pSrc,
+                                const int iSrcLen,
+                                void** ppDst,
+                                SBufferInfo* pDstInfo);
+
+DECODING_STATE (*DecodeFrameEx) (ISVCDecoder*, const unsigned char* pSrc,
                                  const int iSrcLen,
-                                 unsigned char** ppDst,
-                                 int* pStride,
+                                 unsigned char* pDst,
+                                 int iDstStride,
+                                 int* iDstLen,
                                  int* iWidth,
-                                 int* iHeight);
+                                 int* iHeight,
+                                 int* iColorFormat);
 
-  DECODING_STATE (*DecodeFrame2) (ISVCDecoder*, const unsigned char* pSrc,
-                                  const int iSrcLen,
-                                  void** ppDst,
-                                  SBufferInfo* pDstInfo);
-
-  DECODING_STATE (*DecodeFrameEx) (ISVCDecoder*, const unsigned char* pSrc,
-                                   const int iSrcLen,
-                                   unsigned char* pDst,
-                                   int iDstStride,
-                                   int* iDstLen,
-                                   int* iWidth,
-                                   int* iHeight,
-                                   int* iColorFormat);
-
-  long (*SetOption) (ISVCDecoder*, DECODER_OPTION eOptionId, void* pOption);
-  long (*GetOption) (ISVCDecoder*, DECODER_OPTION eOptionId, void* pOption);
+long (*SetOption) (ISVCDecoder*, DECODER_OPTION eOptionId, void* pOption);
+long (*GetOption) (ISVCDecoder*, DECODER_OPTION eOptionId, void* pOption);
 };
 #endif
 
 
-  int  WelsCreateSVCEncoder (ISVCEncoder** ppEncoder);
-  void WelsDestroySVCEncoder (ISVCEncoder* pEncoder);
+int  WelsCreateSVCEncoder (ISVCEncoder** ppEncoder);
+void WelsDestroySVCEncoder (ISVCEncoder* pEncoder);
 
-  long WelsCreateDecoder (ISVCDecoder** ppDecoder);
-  void WelsDestroyDecoder (ISVCDecoder* pDecoder);
+long WelsCreateDecoder (ISVCDecoder** ppDecoder);
+void WelsDestroyDecoder (ISVCDecoder* pDecoder);
 
 #ifdef __cplusplus
 }
--- a/codec/api/svc/codec_app_def.h
+++ b/codec/api/svc/codec_app_def.h
@@ -130,11 +130,11 @@
 } LAYER_TYPE;
 
 typedef enum {
-    SPATIAL_LAYER_0 = 0,
-    SPATIAL_LAYER_1 = 1,
-    SPATIAL_LAYER_2 = 2,
-    SPATIAL_LAYER_3 = 3,
-    SPATIAL_LAYER_ALL = 4,
+  SPATIAL_LAYER_0 = 0,
+  SPATIAL_LAYER_1 = 1,
+  SPATIAL_LAYER_2 = 2,
+  SPATIAL_LAYER_3 = 3,
+  SPATIAL_LAYER_ALL = 4,
 } LAYER_NUM;
 
 //enumerate the type of video bitstream which is provided to decoder
@@ -167,11 +167,11 @@
 } SLTRMarkingFeedback;
 
 typedef struct {
-    unsigned int
-    uiSliceMbNum[MAX_SLICES_NUM_TMP];  //here we use a tmp fixed value since MAX_SLICES_NUM is not defined here and its definition may be changed;
-    unsigned int		uiSliceNum;
-    unsigned int		uiSliceSizeConstraint;
-  } SSliceArgument;//not all the elements in this argument will be used, how it will be used depends on uiSliceMode; see below
+  unsigned int
+  uiSliceMbNum[MAX_SLICES_NUM_TMP];  //here we use a tmp fixed value since MAX_SLICES_NUM is not defined here and its definition may be changed;
+  unsigned int		uiSliceNum;
+  unsigned int		uiSliceSizeConstraint;
+} SSliceArgument;//not all the elements in this argument will be used, how it will be used depends on uiSliceMode; see below
 
 typedef enum {
   SM_SINGLE_SLICE         = 0, //	| SliceNum==1
@@ -203,7 +203,7 @@
 
   PRO_SCALABLE_BASELINE	= 83,
   PRO_SCALABLE_HIGH		= 86,
-}EProfileIdc;
+} EProfileIdc;
 
 typedef enum {
   LEVEL_UNKNOWN,
@@ -224,7 +224,7 @@
   LEVEL_5_0,
   LEVEL_5_1,
   LEVEL_5_2
-}ELevelIdc;
+} ELevelIdc;
 
 typedef struct {
   SliceModeEnum uiSliceMode; //by default, uiSliceMode will be SM_SINGLE_SLICE
@@ -247,12 +247,13 @@
 typedef enum {
   CAMERA_VIDEO_REAL_TIME, //camera video signal
   SCREEN_CONTENT_REAL_TIME,//screen content signal
-}EUsageType;
+} EUsageType;
 
 // TODO:  Refine the parameters definition.
 // SVC Encoding Parameters
-typedef struct TagEncParamBase{
-  EUsageType    iUsageType;	//application type;// CAMERA_VIDEO_REAL_TIME: //camera video signal; SCREEN_CONTENT_REAL_TIME: screen content signal;
+typedef struct TagEncParamBase {
+  EUsageType
+  iUsageType;	//application type;// CAMERA_VIDEO_REAL_TIME: //camera video signal; SCREEN_CONTENT_REAL_TIME: screen content signal;
   int		iInputCsp;	// color space of input sequence
 
   int		iPicWidth;			// width of picture in samples
@@ -264,9 +265,9 @@
 } SEncParamBase, *PEncParamBase;
 
 
-typedef struct TagEncParamExt
-{
-  EUsageType    iUsageType;	//application type;// CAMERA_VIDEO_REAL_TIME: //camera video signal; SCREEN_CONTENT_REAL_TIME: screen content signal;
+typedef struct TagEncParamExt {
+  EUsageType
+  iUsageType;	//application type;// CAMERA_VIDEO_REAL_TIME: //camera video signal; SCREEN_CONTENT_REAL_TIME: screen content signal;
   int		iInputCsp;	// color space of input sequence
 
   int		iPicWidth;			// width of picture in samples
@@ -301,9 +302,10 @@
   unsigned int      iLtrMarkPeriod;
 
   /* multi-thread settings*/
-  unsigned short		iMultipleThreadIdc;		// 1	# 0: auto(dynamic imp. internal encoder); 1: multiple threads imp. disabled; > 1: count number of threads;
+  unsigned short
+  iMultipleThreadIdc;		// 1	# 0: auto(dynamic imp. internal encoder); 1: multiple threads imp. disabled; > 1: count number of threads;
 
-   /* Deblocking loop filter */
+  /* Deblocking loop filter */
   int		iLoopFilterDisableIdc;	// 0: on, 1: off, 2: on except for slice boundaries
   int		iLoopFilterAlphaC0Offset;// AlphaOffset: valid range [-6, 6], default 0
   int		iLoopFilterBetaOffset;	// BetaOffset:	valid range [-6, 6], default 0
@@ -313,7 +315,7 @@
   bool    bEnableAdaptiveQuant; // adaptive quantization control
   bool	  bEnableFrameCroppingFlag;// enable frame cropping flag: TRUE always in application
   bool    bEnableSceneChangeDetect;
-}SEncParamExt;
+} SEncParamExt;
 
 //Define a new struct to show the property of video bitstream.
 typedef struct {
@@ -370,13 +372,13 @@
   long long uiTimeStamp;
 } SSourcePicture;
 
-typedef struct Bitrate_Info_s{
+typedef struct Bitrate_Info_s {
   LAYER_NUM iLayer;
   int iBitrate;    //the maximum bitrate
-}SBitrateInfo;
+} SBitrateInfo;
 
-typedef struct Dump_Layer_s{
-	int iLayer;
-	char *pFileName;
-}SDumpLayer;
+typedef struct Dump_Layer_s {
+  int iLayer;
+  char* pFileName;
+} SDumpLayer;
 #endif//WELS_VIDEO_CODEC_APPLICATION_DEFINITION_H__
--- a/codec/common/inc/deblocking_common.h
+++ b/codec/common/inc/deblocking_common.h
@@ -8,11 +8,11 @@
 void DeblockLumaEq4H_c (uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 
 void DeblockChromaLt4V_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta,
-                            int8_t* pTc);
+                          int8_t* pTc);
 void DeblockChromaEq4V_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 
 void DeblockChromaLt4H_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta,
-                            int8_t* pTc);
+                          int8_t* pTc);
 void DeblockChromaEq4H_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 
 #if defined(__cplusplus)
@@ -28,24 +28,26 @@
 void DeblockLumaEq4H_ssse3 (uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 void DeblockChromaEq4V_ssse3 (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 void DeblockChromaLt4V_ssse3 (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta,
-                             int8_t* pTC);
+                              int8_t* pTC);
 void DeblockChromaEq4H_ssse3 (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 void DeblockChromaLt4H_ssse3 (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta,
-                             int8_t* pTC);
+                              int8_t* pTC);
 #endif
 
 #if defined(HAVE_NEON)
-void DeblockLumaLt4V_neon(uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t* pTc);
-void DeblockLumaEq4V_neon(uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
+void DeblockLumaLt4V_neon (uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t* pTc);
+void DeblockLumaEq4V_neon (uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 
-void DeblockLumaLt4H_neon(uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t* pTc);
-void DeblockLumaEq4H_neon(uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
+void DeblockLumaLt4H_neon (uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t* pTc);
+void DeblockLumaEq4H_neon (uint8_t* pPixY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 
-void DeblockChromaLt4V_neon(uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t* pTC);
-void DeblockChromaEq4V_neon(uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta);
+void DeblockChromaLt4V_neon (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta,
+                             int8_t* pTC);
+void DeblockChromaEq4V_neon (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 
-void DeblockChromaLt4H_neon(uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t* pTC);
-void DeblockChromaEq4H_neon(uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta);
+void DeblockChromaLt4H_neon (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta,
+                             int8_t* pTC);
+void DeblockChromaEq4H_neon (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 #endif
 
 #if defined(__cplusplus)
--- a/codec/common/inc/expand_picture_common.h
+++ b/codec/common/inc/expand_picture_common.h
@@ -62,12 +62,13 @@
 #endif//X86_ASM
 
 #if defined(HAVE_NEON)
-void ExpandPictureLuma_neon(uint8_t *pDst, const int32_t kiStride, const int32_t kiPicW, const int32_t kiPicH);
-void ExpandPictureChroma_neon(uint8_t *pDst, const int32_t kiStride, const int32_t kiPicW, const int32_t kiPicH);
+void ExpandPictureLuma_neon (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicW, const int32_t kiPicH);
+void ExpandPictureChroma_neon (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicW, const int32_t kiPicH);
 #endif
 #if defined(HAVE_NEON_AARCH64)
-    void ExpandPictureLuma_AArch64_neon(uint8_t *pDst, const int32_t kiStride, const int32_t kiPicW, const int32_t kiPicH);
-    void ExpandPictureChroma_AArch64_neon(uint8_t *pDst, const int32_t kiStride, const int32_t kiPicW, const int32_t kiPicH);
+void ExpandPictureLuma_AArch64_neon (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicW, const int32_t kiPicH);
+void ExpandPictureChroma_AArch64_neon (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicW,
+                                       const int32_t kiPicH);
 #endif
 #if defined(__cplusplus)
 }
--- a/codec/common/inc/ls_defines.h
+++ b/codec/common/inc/ls_defines.h
@@ -55,12 +55,12 @@
 #define STRUCTA(size, align) struct tagUnaligned_##size##_##align {\
     uint##size##_t l; \
 } __attribute__ ((aligned(align)))
-STRUCTA(16,2);
-STRUCTA(32,2);
-STRUCTA(32,4);
-STRUCTA(64,2);
-STRUCTA(64,4);
-STRUCTA(64,8);
+STRUCTA (16, 2);
+STRUCTA (32, 2);
+STRUCTA (32, 4);
+STRUCTA (64, 2);
+STRUCTA (64, 4);
+STRUCTA (64, 8);
 //#define _USE_STRUCT_INT_CVT
 //	#ifdef _USE_STRUCT_INT_CVT
 #define ST16(a, b) (((struct tagUnaligned_16 *) (a))->l) = (b)
--- a/codec/common/inc/macros.h
+++ b/codec/common/inc/macros.h
@@ -132,41 +132,41 @@
 }
 
 static inline int32_t CeilLog2 (int32_t i) {
-int32_t s = 0;
-i--;
-while (i > 0) {
-  s++;
-  i >>= 1;
+  int32_t s = 0;
+  i--;
+  while (i > 0) {
+    s++;
+    i >>= 1;
+  }
+  return s;
 }
-return s;
-}
 /*
 the second path will degrades the performance
 */
 #if 1
 static inline int32_t WelsMedian (int32_t iX,  int32_t iY, int32_t iZ) {
-int32_t iMin = iX, iMax = iX;
+  int32_t iMin = iX, iMax = iX;
 
-if (iY < iMin)
-  iMin	= iY;
-else
-  iMax = iY;
+  if (iY < iMin)
+    iMin	= iY;
+  else
+    iMax = iY;
 
-if (iZ < iMin)
-  iMin	= iZ;
-else if (iZ > iMax)
-  iMax	= iZ;
+  if (iZ < iMin)
+    iMin	= iZ;
+  else if (iZ > iMax)
+    iMax	= iZ;
 
-return (iX + iY + iZ) - (iMin + iMax);
+  return (iX + iY + iZ) - (iMin + iMax);
 }
 #else
 static inline int32_t WelsMedian (int32_t iX,  int32_t iY, int32_t iZ) {
-int32_t iTmp = (iX - iY) & ((iX - iY) >> 31);
-iX -= iTmp;
-iY += iTmp;
-iY -= (iY - iZ) & ((iY - iZ) >> 31);
-iY += (iX - iY) & ((iX - iY) >> 31);
-return iY;
+  int32_t iTmp = (iX - iY) & ((iX - iY) >> 31);
+  iX -= iTmp;
+  iY += iTmp;
+  iY -= (iY - iZ) & ((iY - iZ) >> 31);
+  iY += (iX - iY) & ((iX - iY) >> 31);
+  return iY;
 }
 
 #endif
@@ -176,8 +176,8 @@
 #define NEG_NUM(iX) (1+(~(iX)))
 #endif// NEG_NUM
 
-static inline uint8_t WelsClip1(int32_t iX) {
-  uint8_t uiTmp = (uint8_t)(((iX) & ~255) ? (-(iX) >> 31) : (iX));
+static inline uint8_t WelsClip1 (int32_t iX) {
+  uint8_t uiTmp = (uint8_t) (((iX) & ~255) ? (- (iX) >> 31) : (iX));
   return uiTmp;
 }
 
@@ -233,11 +233,11 @@
 #endif//#if WELS_VERIFY_RETURN_PROC_IF
 
 static inline int32_t WELS_LOG2 (uint32_t v) {
-int32_t r = 0;
-while (v >>= 1) {
-  ++r;
-}
-return r;
+  int32_t r = 0;
+  while (v >>= 1) {
+    ++r;
+  }
+  return r;
 
 }
 
@@ -260,7 +260,7 @@
 #endif//BUTTERFLY4x8
 
 static inline bool WELS_POWER2_IF (uint32_t v) {
-return (v && ! (v & (v - 1)));
+  return (v && ! (v & (v - 1)));
 }
 
 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
--- a/codec/common/src/WelsThreadLib.cpp
+++ b/codec/common/src/WelsThreadLib.cpp
@@ -175,13 +175,13 @@
 WELS_THREAD_ERROR_CODE    WelsThreadCreate (WELS_THREAD_HANDLE* thread,  LPWELS_THREAD_ROUTINE  routine,
     void* arg, WELS_THREAD_ATTR attr) {
 #ifdef USE_THREADPOOL
-  HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
+  HANDLE h = CreateEvent (NULL, FALSE, FALSE, NULL);
   HANDLE h2;
-  DuplicateHandle(GetCurrentProcess(), h, GetCurrentProcess(), &h2, 0, FALSE, DUPLICATE_SAME_ACCESS);
-  ThreadPool::RunAsync(ref new WorkItemHandler([=](IAsyncAction^) {
-    routine(arg);
-    SetEvent(h2);
-    CloseHandle(h2);
+  DuplicateHandle (GetCurrentProcess(), h, GetCurrentProcess(), &h2, 0, FALSE, DUPLICATE_SAME_ACCESS);
+  ThreadPool::RunAsync (ref new WorkItemHandler ([ = ] (IAsyncAction^) {
+    routine (arg);
+    SetEvent (h2);
+    CloseHandle (h2);
   }, CallbackContext::Any), WorkItemPriority::Normal, WorkItemOptions::TimeSliced);
 #else
   WELS_THREAD_HANDLE   h = CreateThread (NULL, 0, routine, arg, 0, NULL);
@@ -265,15 +265,15 @@
     return WELS_THREAD_ERROR_OK;
   }
 #else
-  WELS_EVENT event = (WELS_EVENT) malloc(sizeof(*event));
+  WELS_EVENT event = (WELS_EVENT) malloc (sizeof (*event));
   if (event == NULL)
     return WELS_THREAD_ERROR_GENERAL;
-  WELS_THREAD_ERROR_CODE err = sem_init(event, 0, 0);
+  WELS_THREAD_ERROR_CODE err = sem_init (event, 0, 0);
   if (!err) {
     *p_event = event;
     return err;
   }
-  free(event);
+  free (event);
   return err;
 #endif
 }
@@ -285,7 +285,7 @@
   return err;
 #else
   WELS_THREAD_ERROR_CODE err = sem_destroy (*event);	// match with sem_init
-  free(*event);
+  free (*event);
   return err;
 #endif
 }
--- a/codec/common/src/cpu.cpp
+++ b/codec/common/src/cpu.cpp
@@ -96,7 +96,7 @@
     uiCPU |= WELS_CPU_CMOV;
   }
   if ((!strcmp ((const char*)chVendorName, CPU_Vendor_INTEL)) ||
-      (!strcmp((const char*)chVendorName, CPU_Vendor_AMD)) ) {	// confirmed_safe_unsafe_usage
+      (!strcmp ((const char*)chVendorName, CPU_Vendor_AMD))) {	// confirmed_safe_unsafe_usage
     if (uiFeatureD & 0x10000000) {
       /* Multi-Threading checking: contains of multiple logic processors */
       uiCPU |= WELS_CPU_HTT;
@@ -136,18 +136,18 @@
     uiCPU |= WELS_CPU_MOVBE;
   }
 
-  if( pNumberOfLogicProcessors != NULL ){
-    if( uiCPU & WELS_CPU_HTT){
+  if (pNumberOfLogicProcessors != NULL) {
+    if (uiCPU & WELS_CPU_HTT) {
       *pNumberOfLogicProcessors = (uiFeatureB & 0x00ff0000) >> 16; // feature bits: 23-16 on returned EBX
     } else {
       *pNumberOfLogicProcessors = 0;
     }
-    if( !strcmp((const char*)chVendorName, CPU_Vendor_INTEL) ){
-      if( uiMaxCpuidLevel >= 4 ){
+    if (!strcmp ((const char*)chVendorName, CPU_Vendor_INTEL)) {
+      if (uiMaxCpuidLevel >= 4) {
         uiFeatureC = 0;
-        WelsCPUId(0x4, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD);
-        if( uiFeatureA != 0 ){
-          *pNumberOfLogicProcessors = ((uiFeatureA&0xfc000000)>>26) + 1;
+        WelsCPUId (0x4, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD);
+        if (uiFeatureA != 0) {
+          *pNumberOfLogicProcessors = ((uiFeatureA & 0xfc000000) >> 26) + 1;
         }
       }
     }
@@ -209,8 +209,7 @@
 
 #elif defined(HAVE_NEON) //For supporting both android platform and iOS platform
 #if defined(ANDROID_NDK)
-uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors)
-{
+uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) {
   uint32_t         uiCPU = 0;
   AndroidCpuFamily cpuFamily = ANDROID_CPU_FAMILY_UNKNOWN;
   uint64_t         uiFeatures = 0;
@@ -217,18 +216,18 @@
   cpuFamily = android_getCpuFamily();
   if (cpuFamily == ANDROID_CPU_FAMILY_ARM)	{
     uiFeatures = android_getCpuFeatures();
-    if (uiFeatures & ANDROID_CPU_ARM_FEATURE_ARMv7){
+    if (uiFeatures & ANDROID_CPU_ARM_FEATURE_ARMv7) {
       uiCPU |= WELS_CPU_ARMv7;
     }
-    if (uiFeatures & ANDROID_CPU_ARM_FEATURE_VFPv3){
+    if (uiFeatures & ANDROID_CPU_ARM_FEATURE_VFPv3) {
       uiCPU |= WELS_CPU_VFPv3;
     }
-    if (uiFeatures & ANDROID_CPU_ARM_FEATURE_NEON){
+    if (uiFeatures & ANDROID_CPU_ARM_FEATURE_NEON) {
       uiCPU |= WELS_CPU_NEON;
     }
   }
 
-  if( pNumberOfLogicProcessors != NULL ){
+  if (pNumberOfLogicProcessors != NULL) {
     *pNumberOfLogicProcessors = android_getCpuCount();
   }
 
@@ -236,22 +235,21 @@
 }
 
 #elif defined(__APPLE__)
-uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors)
-{
-    uint32_t       uiCPU = 0;
+uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) {
+  uint32_t       uiCPU = 0;
 
 #if defined(__ARM_NEON__)
-    uiCPU |= WELS_CPU_ARMv7;
-    uiCPU |= WELS_CPU_VFPv3;
-    uiCPU |= WELS_CPU_NEON;
+  uiCPU |= WELS_CPU_ARMv7;
+  uiCPU |= WELS_CPU_VFPv3;
+  uiCPU |= WELS_CPU_NEON;
 #endif
-    return uiCPU;
+  return uiCPU;
 }
 #elif defined(__linux__)
 
 /* Generic arm/linux cpu feature detection */
 uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) {
-  FILE *f = fopen("/proc/cpuinfo", "r");
+  FILE* f = fopen ("/proc/cpuinfo", "r");
 
   if (!f)
     return 0;
@@ -258,16 +256,16 @@
 
   char buf[200];
   int flags = 0;
-  while (fgets(buf, sizeof(buf), f)) {
-    if (!strncmp(buf, "Features", strlen("Features"))) {
-      if (strstr(buf, " neon "))
+  while (fgets (buf, sizeof (buf), f)) {
+    if (!strncmp (buf, "Features", strlen ("Features"))) {
+      if (strstr (buf, " neon "))
         flags |= WELS_CPU_NEON;
-      if (strstr(buf, " vfpv3 "))
+      if (strstr (buf, " vfpv3 "))
         flags |= WELS_CPU_VFPv3;
       break;
     }
   }
-  fclose(f);
+  fclose (f);
   return flags;
 }
 
--- a/codec/common/src/crt_util_safe_x.cpp
+++ b/codec/common/src/crt_util_safe_x.cpp
@@ -114,7 +114,7 @@
 
   iRc = strftime (pBuffer, iSize, kpFormat, &sTimeNow);
   if (iRc == 0)
-      pBuffer[0] = '\0';
+    pBuffer[0] = '\0';
   return iRc;
 }
 
@@ -175,7 +175,7 @@
 
   iRc = strftime (pBuffer, iSize, kpFormat, pTnow);
   if (iRc == 0)
-      pBuffer[0] = '\0';
+    pBuffer[0] = '\0';
   return iRc;
 }
 
@@ -236,7 +236,7 @@
 
   iRc = strftime (pBuffer, iSize, kpFormat, pTnow);
   if (iRc == 0)
-      pBuffer[0] = '\0';
+    pBuffer[0] = '\0';
   return iRc;
 }
 
@@ -244,8 +244,8 @@
 
 
 char* WelsStrcat (char* pDest, int32_t iSizeInBytes, const char* kpSrc) {
-    int32_t iCurLen = strlen(pDest);
-    return WelsStrncpy(pDest + iCurLen, iSizeInBytes - iCurLen, kpSrc);
+  int32_t iCurLen = strlen (pDest);
+  return WelsStrncpy (pDest + iCurLen, iSizeInBytes - iCurLen, kpSrc);
 }
 
 int32_t WelsFwrite (const void* kpBuffer, int32_t iSize, int32_t iCount, WelsFileHandle* pFp) {
@@ -257,7 +257,7 @@
 }
 
 int32_t WelsFseek (WelsFileHandle* fp, int32_t offset, int32_t origin) {
-  return fseek(fp, offset, origin);
+  return fseek (fp, offset, origin);
 }
 
 int32_t WelsFflush (WelsFileHandle* pFp) {
--- a/codec/common/src/deblocking_common.cpp
+++ b/codec/common/src/deblocking_common.cpp
@@ -2,7 +2,7 @@
 #include "macros.h"
 //  C code only
 void DeblockLumaLt4_c (uint8_t* pPix, int32_t iStrideX, int32_t iStrideY, int32_t iAlpha, int32_t iBeta,
-                         int8_t* pTc) {
+                       int8_t* pTc) {
   for (int32_t i = 0; i < 16; i++) {
     int32_t iTc0 = pTc[i >> 2];
     if (iTc0 >= 0) {
@@ -90,7 +90,7 @@
   DeblockLumaEq4_c (pPix, 1, iStride, iAlpha, iBeta);
 }
 void DeblockChromaLt4_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStrideX, int32_t iStrideY, int32_t iAlpha,
-                           int32_t iBeta, int8_t* pTc) {
+                         int32_t iBeta, int8_t* pTc) {
   int32_t p0, p1, q0, q1, iDeta;
   bool bDetaP0Q0, bDetaP1P0, bDetaQ1Q0;
 
@@ -132,7 +132,7 @@
   }
 }
 void DeblockChromaEq4_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStrideX, int32_t iStrideY, int32_t iAlpha,
-                           int32_t iBeta) {
+                         int32_t iBeta) {
   int32_t p0, p1, q0, q1;
   bool bDetaP0Q0, bDetaP1P0, bDetaQ1Q0;
   for (int32_t i = 0; i < 8; i++) {
@@ -166,11 +166,11 @@
   }
 }
 void DeblockChromaLt4V_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta,
-                            int8_t* tc) {
+                          int8_t* tc) {
   DeblockChromaLt4_c (pPixCb, pPixCr, iStride, 1, iAlpha, iBeta, tc);
 }
 void DeblockChromaLt4H_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta,
-                            int8_t* tc) {
+                          int8_t* tc) {
   DeblockChromaLt4_c (pPixCb, pPixCr, 1, iStride, iAlpha, iBeta, tc);
 }
 void DeblockChromaEq4V_c (uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, int32_t iAlpha, int32_t iBeta) {
--- a/codec/common/src/sad_common.cpp
+++ b/codec/common/src/sad_common.cpp
@@ -107,33 +107,33 @@
 
 void WelsSampleSadFour16x16_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2,
                                int32_t* pSad) {
-    * (pSad)     = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
-    * (pSad + 1) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
-    * (pSad + 2) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 - 1), iStride2);
-    * (pSad + 3) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 + 1), iStride2);
+  * (pSad)     = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
+  * (pSad + 1) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
+  * (pSad + 2) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 - 1), iStride2);
+  * (pSad + 3) = WelsSampleSad16x16_c (iSample1, iStride1, (iSample2 + 1), iStride2);
 }
 void WelsSampleSadFour16x8_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
-    * (pSad)     = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
-    * (pSad + 1) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
-    * (pSad + 2) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 - 1), iStride2);
-    * (pSad + 3) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 + 1), iStride2);
+  * (pSad)     = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
+  * (pSad + 1) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
+  * (pSad + 2) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 - 1), iStride2);
+  * (pSad + 3) = WelsSampleSad16x8_c (iSample1, iStride1, (iSample2 + 1), iStride2);
 }
 void WelsSampleSadFour8x16_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
-    * (pSad)     = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
-    * (pSad + 1) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
-    * (pSad + 2) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 - 1), iStride2);
-    * (pSad + 3) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 + 1), iStride2);
+  * (pSad)     = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
+  * (pSad + 1) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
+  * (pSad + 2) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 - 1), iStride2);
+  * (pSad + 3) = WelsSampleSad8x16_c (iSample1, iStride1, (iSample2 + 1), iStride2);
 
 }
 void WelsSampleSadFour8x8_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
-    * (pSad)     = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
-    * (pSad + 1) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
-    * (pSad + 2) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 - 1), iStride2);
-    * (pSad + 3) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 + 1), iStride2);
+  * (pSad)     = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
+  * (pSad + 1) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
+  * (pSad + 2) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 - 1), iStride2);
+  * (pSad + 3) = WelsSampleSad8x8_c (iSample1, iStride1, (iSample2 + 1), iStride2);
 }
 void WelsSampleSadFour4x4_c (uint8_t* iSample1, int32_t iStride1, uint8_t* iSample2, int32_t iStride2, int32_t* pSad) {
-    * (pSad)     = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
-    * (pSad + 1) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
-    * (pSad + 2) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 - 1), iStride2);
-    * (pSad + 3) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 + 1), iStride2);
+  * (pSad)     = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 - iStride2), iStride2);
+  * (pSad + 1) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 + iStride2), iStride2);
+  * (pSad + 2) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 - 1), iStride2);
+  * (pSad + 3) = WelsSampleSad4x4_c (iSample1, iStride1, (iSample2 + 1), iStride2);
 }
\ No newline at end of file
--- a/codec/console/dec/src/d3d9_utils.cpp
+++ b/codec/console/dec/src/d3d9_utils.cpp
@@ -147,10 +147,10 @@
 HRESULT CD3D9Utils::Render (void* pDst[3], SBufferInfo* pInfo) {
   HRESULT hResult = E_FAIL;
 
-    hResult = InitResource (NULL, pInfo);
-    if (SUCCEEDED (hResult))
-      hResult = Dump2Surface (pDst, m_lpD3D9RawSurfaceShare, pInfo->UsrData.sSystemBuffer.iWidth,
-                              pInfo->UsrData.sSystemBuffer.iHeight, pInfo->UsrData.sSystemBuffer.iStride);
+  hResult = InitResource (NULL, pInfo);
+  if (SUCCEEDED (hResult))
+    hResult = Dump2Surface (pDst, m_lpD3D9RawSurfaceShare, pInfo->UsrData.sSystemBuffer.iWidth,
+                            pInfo->UsrData.sSystemBuffer.iHeight, pInfo->UsrData.sSystemBuffer.iStride);
 
   if (SUCCEEDED (hResult)) {
     IDirect3DSurface9* pBackBuffer = NULL;
@@ -218,10 +218,10 @@
     m_d3dpp.hDeviceWindow = m_hWnd;
     m_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
     hResult = m_lpD3D9->CreateDevice (uiAdapter, D3DDevType, NULL, dwBehaviorFlags, &m_d3dpp, &m_lpD3D9Device);
-      iWidth = pInfo->UsrData.sSystemBuffer.iWidth;
-      iHeight = pInfo->UsrData.sSystemBuffer.iHeight;
-      D3Dformat = (D3DFORMAT)NV12_FORMAT;
-      D3Dpool = (D3DPOOL)D3DPOOL_DEFAULT;
+    iWidth = pInfo->UsrData.sSystemBuffer.iWidth;
+    iHeight = pInfo->UsrData.sSystemBuffer.iHeight;
+    D3Dformat = (D3DFORMAT)NV12_FORMAT;
+    D3Dpool = (D3DPOOL)D3DPOOL_DEFAULT;
 
     hResult = m_lpD3D9Device->CreateOffscreenPlainSurface (iWidth, iHeight, (D3DFORMAT)D3Dformat, (D3DPOOL)D3Dpool,
               &m_lpD3D9RawSurfaceShare, NULL);
@@ -316,10 +316,10 @@
 HRESULT CD3D9ExUtils::Render (void* pDst[3], SBufferInfo* pInfo) {
   HRESULT hResult = E_FAIL;
 
-    hResult = InitResource (NULL, pInfo);
-    if (SUCCEEDED (hResult))
-      hResult = Dump2Surface (pDst, m_lpD3D9RawSurfaceShare, pInfo->UsrData.sSystemBuffer.iWidth,
-                              pInfo->UsrData.sSystemBuffer.iHeight, pInfo->UsrData.sSystemBuffer.iStride);
+  hResult = InitResource (NULL, pInfo);
+  if (SUCCEEDED (hResult))
+    hResult = Dump2Surface (pDst, m_lpD3D9RawSurfaceShare, pInfo->UsrData.sSystemBuffer.iWidth,
+                            pInfo->UsrData.sSystemBuffer.iHeight, pInfo->UsrData.sSystemBuffer.iStride);
 
   if (SUCCEEDED (hResult)) {
     IDirect3DSurface9* pBackBuffer = NULL;
@@ -337,10 +337,10 @@
   int iWidth;
   int iHeight;
 
-    iWidth = pInfo->UsrData.sSystemBuffer.iWidth;
-    iHeight = pInfo->UsrData.sSystemBuffer.iHeight;
-    iStride[0] = pInfo->UsrData.sSystemBuffer.iStride[0];
-    iStride[1] = pInfo->UsrData.sSystemBuffer.iStride[1];
+  iWidth = pInfo->UsrData.sSystemBuffer.iWidth;
+  iHeight = pInfo->UsrData.sSystemBuffer.iHeight;
+  iStride[0] = pInfo->UsrData.sSystemBuffer.iStride[0];
+  iStride[1] = pInfo->UsrData.sSystemBuffer.iStride[1];
 
   if (pDst[0] && pDst[1] && pDst[2])
     Write2File (pFp, (unsigned char**)pDst, iStride, iWidth, iHeight);
@@ -386,10 +386,10 @@
     m_d3dpp.hDeviceWindow = m_hWnd;
     m_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
     hResult = m_lpD3D9->CreateDeviceEx (uiAdapter, D3DDevType, NULL, dwBehaviorFlags, &m_d3dpp, NULL, &m_lpD3D9Device);
-      iWidth = pInfo->UsrData.sSystemBuffer.iWidth;
-      iHeight = pInfo->UsrData.sSystemBuffer.iHeight;
-      D3Dformat = (D3DFORMAT)NV12_FORMAT;
-      D3Dpool = (D3DPOOL)D3DPOOL_DEFAULT;
+    iWidth = pInfo->UsrData.sSystemBuffer.iWidth;
+    iHeight = pInfo->UsrData.sSystemBuffer.iHeight;
+    D3Dformat = (D3DFORMAT)NV12_FORMAT;
+    D3Dpool = (D3DPOOL)D3DPOOL_DEFAULT;
     hResult = m_lpD3D9Device->CreateOffscreenPlainSurface (iWidth, iHeight, (D3DFORMAT)D3Dformat, (D3DPOOL)D3Dpool,
               &m_lpD3D9RawSurfaceShare, &pSharedHandle);
   }
--- a/codec/console/enc/src/welsenc.cpp
+++ b/codec/console/enc/src/welsenc.cpp
@@ -104,8 +104,7 @@
 }
 static int     g_LevelSetting = 0;
 
-int ParseLayerConfig( CReadConfig & cRdLayerCfg, const int iLayer, SEncParamExt& pSvcParam,SFilesSet& sFileSet)
-{
+int ParseLayerConfig (CReadConfig& cRdLayerCfg, const int iLayer, SEncParamExt& pSvcParam, SFilesSet& sFileSet) {
   if (!cRdLayerCfg.ExistFile()) {
     fprintf (stderr, "Unabled to open layer #%d configuration file: %s.\n", iLayer, cRdLayerCfg.GetFileName().c_str());
     return 1;
@@ -112,7 +111,7 @@
   }
 
   SSpatialLayerConfig* pDLayer = &pSvcParam.sSpatialLayers[iLayer];
-  int iLeftTargetBitrate = (pSvcParam.iRCMode!=RC_OFF_MODE)?pSvcParam.iTargetBitrate:0;
+  int iLeftTargetBitrate = (pSvcParam.iRCMode != RC_OFF_MODE) ? pSvcParam.iTargetBitrate : 0;
   SLayerPEncCtx sLayerCtx;
   memset (&sLayerCtx, 0, sizeof (SLayerPEncCtx));
 
@@ -131,9 +130,9 @@
         pDLayer->iVideoHeight	= atoi (strTag[1].c_str());
       } else if (strTag[0].compare ("FrameRateOut") == 0) {
         pDLayer->fFrameRate = (float)atof (strTag[1].c_str());
-      }else if (strTag[0].compare ("ReconFile") == 0) {
+      } else if (strTag[0].compare ("ReconFile") == 0) {
         const unsigned int kiLen = strTag[1].length();
-        if (kiLen >= sizeof(sFileSet.sRecFileName[iLayer]))
+        if (kiLen >= sizeof (sFileSet.sRecFileName[iLayer]))
           return -1;
         sFileSet.sRecFileName[iLayer][kiLen] = '\0';
         strncpy (sFileSet.sRecFileName[iLayer], strTag[1].c_str(), kiLen);	// confirmed_safe_unsafe_usage
@@ -143,7 +142,7 @@
         //					pDLayer->frext_mode	= (bool)atoi(strTag[1].c_str());
       } else if (strTag[0].compare ("SpatialBitrate") == 0) {
         pDLayer->iSpatialBitrate	= 1000 * atoi (strTag[1].c_str());
-        if (pSvcParam.iRCMode!=RC_OFF_MODE) {
+        if (pSvcParam.iRCMode != RC_OFF_MODE) {
           if (pDLayer->iSpatialBitrate <= 0) {
             fprintf (stderr, "Invalid spatial bitrate(%d) in dependency layer #%d.\n", pDLayer->iSpatialBitrate, iLayer);
             return -1;
@@ -150,7 +149,7 @@
           }
           if (pDLayer->iSpatialBitrate > iLeftTargetBitrate) {
             fprintf (stderr, "Invalid spatial(#%d) bitrate(%d) setting due to unavailable left(%d)!\n", iLayer,
-              pDLayer->iSpatialBitrate, iLeftTargetBitrate);
+                     pDLayer->iSpatialBitrate, iLeftTargetBitrate);
             return -1;
           }
           iLeftTargetBitrate -= pDLayer->iSpatialBitrate;
@@ -177,7 +176,7 @@
 
   memcpy (&pDLayer->sSliceCfg, &sLayerCtx.sSliceCfg, sizeof (SSliceConfig));	// confirmed_safe_unsafe_usage
   memcpy (&pDLayer->sSliceCfg.sSliceArgument.uiSliceMbNum[0], &sLayerCtx.sSliceCfg.sSliceArgument.uiSliceMbNum[0],
-    sizeof (sLayerCtx.sSliceCfg.sSliceArgument.uiSliceMbNum));	// confirmed_safe_unsafe_usage
+          sizeof (sLayerCtx.sSliceCfg.sSliceArgument.uiSliceMbNum));	// confirmed_safe_unsafe_usage
 
   return 0;
 }
@@ -194,14 +193,14 @@
       if (strTag[0].empty())
         continue;
 
-      if(strTag[0].compare ("UsageType") == 0){
+      if (strTag[0].compare ("UsageType") == 0) {
         pSvcParam.iUsageType = (EUsageType)atoi (strTag[1].c_str());
-      }else if (strTag[0].compare ("SourceWidth") == 0) {
+      } else if (strTag[0].compare ("SourceWidth") == 0) {
         pSrcPic->iPicWidth = atoi (strTag[1].c_str());
       } else if (strTag[0].compare ("SourceHeight") == 0) {
         pSrcPic->iPicHeight = atoi (strTag[1].c_str());
       } else if (strTag[0].compare ("InputFile") == 0) {
-	    if (strTag[1].length() > 0)
+        if (strTag[1].length() > 0)
           sFileSet.strSeqFile	= strTag[1];
       } else if (strTag[0].compare ("OutputFile") == 0) {
         sFileSet.strBsFile	= strTag[1];
@@ -249,7 +248,7 @@
         pSvcParam.iRCMode	= (RC_MODES) atoi (strTag[1].c_str());
       } else if (strTag[0].compare ("TargetBitrate") == 0) {
         pSvcParam.iTargetBitrate	= 1000 * atoi (strTag[1].c_str());
-        if ((pSvcParam.iRCMode!=RC_OFF_MODE) && pSvcParam.iTargetBitrate <= 0) {
+        if ((pSvcParam.iRCMode != RC_OFF_MODE) && pSvcParam.iTargetBitrate <= 0) {
           fprintf (stderr, "Invalid target bitrate setting due to RC enabled. Check TargetBitrate field please!\n");
           return 1;
         }
@@ -302,8 +301,7 @@
 
   for (int8_t iLayer = 0; iLayer < kiActualLayerNum; ++ iLayer) {
     CReadConfig cRdLayerCfg (sFileSet.strLayerCfgFile[iLayer]);
-    if (-1==ParseLayerConfig( cRdLayerCfg, iLayer, pSvcParam,sFileSet ))
-    {
+    if (-1 == ParseLayerConfig (cRdLayerCfg, iLayer, pSvcParam, sFileSet)) {
       iRet = 1;
       break;
     }
@@ -346,7 +344,7 @@
     else if (!strcmp (pCmd, "-ltr") && (i < argc))
       sParam.bEnableLongTermReference = atoi (argv[i++]) ? true : false;
 
-    else if (!strcmp (pCmd, "-ltrnum") && (i< argc))
+    else if (!strcmp (pCmd, "-ltrnum") && (i < argc))
       sParam.iLTRRefNum = atoi (argv[i++]);
 
     else if (!strcmp (pCmd, "-ltrper") && (i < argc))
@@ -472,7 +470,7 @@
       pSvcParam.iLtrMarkPeriod = atoi (argv[n++]);
 
     else if (!strcmp (pCommand, "-rc") && (n < argc))
-      pSvcParam.iRCMode = static_cast<RC_MODES>(atoi(argv[n++]));
+      pSvcParam.iRCMode = static_cast<RC_MODES> (atoi (argv[n++]));
 
     else if (!strcmp (pCommand, "-trace") && (n < argc))
       g_LevelSetting = atoi (argv[n++]);
@@ -489,21 +487,18 @@
 
       for (int8_t iLayer = 0; iLayer < pSvcParam.iSpatialLayerNum; ++ iLayer) {
         CReadConfig cRdLayerCfg (sFileSet.strLayerCfgFile[iLayer]);
-        if (-1==ParseLayerConfig( cRdLayerCfg, iLayer, pSvcParam,sFileSet ))
-        {
+        if (-1 == ParseLayerConfig (cRdLayerCfg, iLayer, pSvcParam, sFileSet)) {
           return 1;
         }
       }
-    }
-    else if (!strcmp (pCommand, "-drec") && (n + 1 < argc)) {
+    } else if (!strcmp (pCommand, "-drec") && (n + 1 < argc)) {
       unsigned int	iLayer = atoi (argv[n++]);
       const unsigned int iLen = strlen (argv[n]);
-      if (iLen >= sizeof(sFileSet.sRecFileName[iLayer]))
+      if (iLen >= sizeof (sFileSet.sRecFileName[iLayer]))
         return 1;
       sFileSet.sRecFileName[iLayer][iLen] = '\0';
       strncpy (sFileSet.sRecFileName[iLayer], argv[n++], iLen);	// confirmed_safe_unsafe_usage
-    }
-    else if (!strcmp (pCommand, "-dw") && (n + 1 < argc)) {
+    } else if (!strcmp (pCommand, "-dw") && (n + 1 < argc)) {
       unsigned int	iLayer = atoi (argv[n++]);
       SSpatialLayerConfig* pDLayer = &pSvcParam.sSpatialLayers[iLayer];
       pDLayer->iVideoWidth =  atoi (argv[n++]);
@@ -515,10 +510,10 @@
       pDLayer->iVideoHeight =  atoi (argv[n++]);
     }
 
-     else if (!strcmp (pCommand, "-frout") && (n + 1 < argc)) {
+    else if (!strcmp (pCommand, "-frout") && (n + 1 < argc)) {
       unsigned int	iLayer = atoi (argv[n++]);
       SSpatialLayerConfig* pDLayer = &pSvcParam.sSpatialLayers[iLayer];
-	  pDLayer->fFrameRate = (float)atof (argv[n++]);
+      pDLayer->fFrameRate = (float)atof (argv[n++]);
     }
 
     else if (!strcmp (pCommand, "-lqp") && (n + 1 < argc)) {
@@ -687,12 +682,12 @@
     ret = 1;
     goto ERROR_RET;
   }
-  pPtrEnc->SetOption(ENCODER_OPTION_TRACE_LEVEL,&g_LevelSetting);
+  pPtrEnc->SetOption (ENCODER_OPTION_TRACE_LEVEL, &g_LevelSetting);
   if (cmResultSuccess != pPtrEnc->InitializeExt (&sSvcParam)) {
     fprintf (stderr, "Encoder Initialization failed!\n");
-	ret = 1;
+    ret = 1;
     goto ERROR_RET;
-   }
+  }
   iPicLumaSize = sSvcParam.iPicWidth * sSvcParam.iPicHeight;
   switch (sSvcParam.iInputCsp) {
     int iStride;
@@ -731,19 +726,19 @@
 
   pSrcPic = new SSourcePicture;
   if (pSrcPic == NULL) {
-     ret = 1;
-     goto ERROR_RET;
-   }
+    ret = 1;
+    goto ERROR_RET;
+  }
 
   pSrcPic->iColorFormat = sSvcParam.iInputCsp;
   pSrcPic->iPicHeight = sSvcParam.iPicHeight;
   pSrcPic->iPicWidth = sSvcParam.iPicWidth;
   pSrcPic->iStride[0] = sSvcParam.iPicWidth;
-  pSrcPic->iStride[1] = pSrcPic->iStride[2] = sSvcParam.iPicWidth>>1;
+  pSrcPic->iStride[1] = pSrcPic->iStride[2] = sSvcParam.iPicWidth >> 1;
 
   pSrcPic->pData[0] = pPlanes[0];
-  pSrcPic->pData[1] = pSrcPic->pData[0] + (sSvcParam.iPicWidth*sSvcParam.iPicHeight);
-  pSrcPic->pData[2] = pSrcPic->pData[1] + (sSvcParam.iPicWidth*sSvcParam.iPicHeight>>2);
+  pSrcPic->pData[1] = pSrcPic->pData[0] + (sSvcParam.iPicWidth * sSvcParam.iPicHeight);
+  pSrcPic->pData[2] = pSrcPic->pData[1] + (sSvcParam.iPicWidth * sSvcParam.iPicHeight >> 2);
 
   while (true) {
     if (feof (pFpSrc))
@@ -801,9 +796,9 @@
     fclose (pFpSrc);
     pFpSrc = NULL;
   }
-  if(pSrcPic){
-   delete pSrcPic;
-   pSrcPic = NULL;
+  if (pSrcPic) {
+    delete pSrcPic;
+    pSrcPic = NULL;
   }
   return ret;
 }
@@ -824,7 +819,7 @@
   int32_t iActualFrameEncodedCount = 0;
   int32_t iFrameIdx = 0;
   int32_t	iTotalFrameMax = -1;
-  uint8_t* pYUV= NULL;
+  uint8_t* pYUV = NULL;
   SSourcePicture* pSrcPic = NULL;
   uint32_t iSourceWidth, iSourceHeight, kiPicResSize;
   // Inactive with sink with output file handler
@@ -843,7 +838,7 @@
 
   memset (&sFbi, 0, sizeof (SFrameBSInfo));
   memset (&sSvcParam, 0, sizeof (SEncParamExt));
-  memset (&fs.sRecFileName[0][0],0,sizeof(fs.sRecFileName));
+  memset (&fs.sRecFileName[0][0], 0, sizeof (fs.sRecFileName));
   sSvcParam.iInputCsp	= videoFormatI420;	// I420 in default
   sSvcParam.sSpatialLayers[0].uiProfileIdc	= PRO_BASELINE;
 //	svc_cfg->sDependencyLayers[0].frext_mode	= 0;
@@ -859,9 +854,9 @@
 
   pSrcPic = new SSourcePicture;
   if (pSrcPic == NULL) {
-     iRet = 1;
-     goto INSIDE_MEM_FREE;
-   }
+    iRet = 1;
+    goto INSIDE_MEM_FREE;
+  }
   //fill default pSrcPic
   pSrcPic->iColorFormat = videoFormatI420;
   pSrcPic->uiTimeStamp = 0;
@@ -881,31 +876,31 @@
   //finish reading the configurations
   iSourceWidth = pSrcPic->iPicWidth;
   iSourceHeight = pSrcPic->iPicHeight;
-  kiPicResSize = iSourceWidth * iSourceHeight*3>>1;
+  kiPicResSize = iSourceWidth * iSourceHeight * 3 >> 1;
 
   pYUV = new uint8_t [kiPicResSize];
   if (pYUV == NULL) {
-     iRet = 1;
-     goto INSIDE_MEM_FREE;
-   }
+    iRet = 1;
+    goto INSIDE_MEM_FREE;
+  }
 
   //update pSrcPic
   pSrcPic->iStride[0] = iSourceWidth;
-  pSrcPic->iStride[1] = pSrcPic->iStride[2] = pSrcPic->iStride[0]>>1;
+  pSrcPic->iStride[1] = pSrcPic->iStride[2] = pSrcPic->iStride[0] >> 1;
 
   pSrcPic->pData[0] = pYUV;
-  pSrcPic->pData[1] = pSrcPic->pData[0] + (iSourceWidth*iSourceHeight);
-  pSrcPic->pData[2] = pSrcPic->pData[1] + (iSourceWidth*iSourceHeight>>2);
+  pSrcPic->pData[1] = pSrcPic->pData[0] + (iSourceWidth * iSourceHeight);
+  pSrcPic->pData[2] = pSrcPic->pData[1] + (iSourceWidth * iSourceHeight >> 2);
 
   //update sSvcParam
-  for (int iLayer=0; iLayer<sSvcParam.iSpatialLayerNum; iLayer++) {
+  for (int iLayer = 0; iLayer < sSvcParam.iSpatialLayerNum; iLayer++) {
     SSpatialLayerConfig* pDLayer = &sSvcParam.sSpatialLayers[iLayer];
-    sSvcParam.iPicWidth = WELS_MAX(sSvcParam.iPicWidth, pDLayer->iVideoWidth);
-    sSvcParam.iPicHeight = WELS_MAX(sSvcParam.iPicHeight, pDLayer->iVideoHeight);
+    sSvcParam.iPicWidth = WELS_MAX (sSvcParam.iPicWidth, pDLayer->iVideoWidth);
+    sSvcParam.iPicHeight = WELS_MAX (sSvcParam.iPicHeight, pDLayer->iVideoHeight);
   }
   //if target output resolution is not set, use the source size
-  sSvcParam.iPicWidth = (!sSvcParam.iPicWidth)?iSourceWidth:sSvcParam.iPicWidth;
-  sSvcParam.iPicHeight =  (!sSvcParam.iPicHeight)?iSourceHeight:sSvcParam.iPicHeight;
+  sSvcParam.iPicWidth = (!sSvcParam.iPicWidth) ? iSourceWidth : sSvcParam.iPicWidth;
+  sSvcParam.iPicHeight = (!sSvcParam.iPicHeight) ? iSourceHeight : sSvcParam.iPicHeight;
 
   iTotalFrameMax = (int32_t)sSvcParam.uiFrameToBeCoded;
 
@@ -914,12 +909,12 @@
     iRet = 1;
     goto INSIDE_MEM_FREE;
   }
-  for(int iLayer = 0;iLayer<MAX_DEPENDENCY_LAYER;iLayer++){
-    if(fs.sRecFileName[iLayer][0]!=0){
+  for (int iLayer = 0; iLayer < MAX_DEPENDENCY_LAYER; iLayer++) {
+    if (fs.sRecFileName[iLayer][0] != 0) {
       SDumpLayer sDumpLayer;
       sDumpLayer.iLayer = iLayer;
       sDumpLayer.pFileName = fs.sRecFileName[iLayer];
-      if(cmResultSuccess!=pPtrEnc->SetOption(ENCODER_OPTION_DUMP_FILE,&sDumpLayer)){
+      if (cmResultSuccess != pPtrEnc->SetOption (ENCODER_OPTION_DUMP_FILE, &sDumpLayer)) {
         fprintf (stderr, "SetOption ENCODER_OPTION_DUMP_FILE failed!\n");
         iRet = 1;
         goto INSIDE_MEM_FREE;
@@ -946,18 +941,18 @@
 #endif
 
   pFileYUV = fopen (fs.strSeqFile.c_str(), "rb");
-    if (pFileYUV != NULL) {
-      if (!fseek (pFileYUV, 0, SEEK_END)) {
-        int64_t i_size = ftell (pFileYUV);
-        fseek (pFileYUV, 0, SEEK_SET);
-        iTotalFrameMax = WELS_MAX ((int32_t) (i_size / kiPicResSize), iTotalFrameMax);
-      }
-    } else {
-      fprintf (stderr, "Unable to open source sequence file (%s), check corresponding path!\n",
-               fs.strSeqFile.c_str());
-      iRet = 1;
-      goto INSIDE_MEM_FREE;
+  if (pFileYUV != NULL) {
+    if (!fseek (pFileYUV, 0, SEEK_END)) {
+      int64_t i_size = ftell (pFileYUV);
+      fseek (pFileYUV, 0, SEEK_SET);
+      iTotalFrameMax = WELS_MAX ((int32_t) (i_size / kiPicResSize), iTotalFrameMax);
     }
+  } else {
+    fprintf (stderr, "Unable to open source sequence file (%s), check corresponding path!\n",
+             fs.strSeqFile.c_str());
+    iRet = 1;
+    goto INSIDE_MEM_FREE;
+  }
 
   iFrameIdx = 0;
   while (iFrameIdx < iTotalFrameMax && (((int32_t)sSvcParam.uiFrameToBeCoded <= 0)
@@ -969,12 +964,12 @@
       break;
     }
 #endif//ONLY_ENC_FRAMES_NUM
-      bool bCanBeRead = false;
-      bCanBeRead = (fread (pYUV, 1, kiPicResSize, pFileYUV) == kiPicResSize);
+    bool bCanBeRead = false;
+    bCanBeRead = (fread (pYUV, 1, kiPicResSize, pFileYUV) == kiPicResSize);
 
-      if (!bCanBeRead)
-		  break;
-      // To encoder this frame
+    if (!bCanBeRead)
+      break;
+    // To encoder this frame
     iStart	= WelsTime();
     int iEncFrames = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
     iTotal += WelsTime() - iStart;
@@ -1036,39 +1031,39 @@
   if (iActualFrameEncodedCount > 0) {
     double dElapsed = iTotal / 1e6;
     printf ("Width:		%d\nHeight:		%d\nFrames:		%d\nencode time:	%f sec\nFPS:		%f fps\n",
-		sSvcParam.iPicWidth, sSvcParam.iPicHeight,
+            sSvcParam.iPicWidth, sSvcParam.iPicHeight,
             iActualFrameEncodedCount, dElapsed, (iActualFrameEncodedCount * 1.0) / dElapsed);
   }
 INSIDE_MEM_FREE:
-    if (pFpBs) {
-      fclose (pFpBs);
-      pFpBs = NULL;
-    }
+  if (pFpBs) {
+    fclose (pFpBs);
+    pFpBs = NULL;
+  }
 #if defined (STICK_STREAM_SIZE)
-    if (fTrackStream) {
-      fclose (fTrackStream);
-      fTrackStream = NULL;
-    }
+  if (fTrackStream) {
+    fclose (fTrackStream);
+    fTrackStream = NULL;
+  }
 #endif
 #if defined (COMPARE_DATA)
-    if (fpGolden) {
-      fclose (fpGolden);
-      fpGolden = NULL;
-    }
+  if (fpGolden) {
+    fclose (fpGolden);
+    fpGolden = NULL;
+  }
 #endif
-    // Destruction memory introduced in this routine
-      if (pFileYUV!= NULL) {
-        fclose (pFileYUV);
-        pFileYUV = NULL;
-      }
-      if (pYUV) {
-        delete pYUV;
-        pYUV = NULL;
-      }
-	  if(pSrcPic){
-		  delete pSrcPic;
-		  pSrcPic = NULL;
-	  }
+  // Destruction memory introduced in this routine
+  if (pFileYUV != NULL) {
+    fclose (pFileYUV);
+    pFileYUV = NULL;
+  }
+  if (pYUV) {
+    delete pYUV;
+    pYUV = NULL;
+  }
+  if (pSrcPic) {
+    delete pSrcPic;
+    pSrcPic = NULL;
+  }
   return iRet;
 }
 
@@ -1114,7 +1109,7 @@
  * main:
  ****************************************************************************/
 #if defined(ANDROID_NDK) || defined(APPLE_IOS)
-extern "C" int EncMain(int argc, char **argv)
+extern "C" int EncMain (int argc, char** argv)
 #else
 int main (int argc, char** argv)
 #endif
--- a/codec/decoder/core/inc/au_parser.h
+++ b/codec/decoder/core/inc/au_parser.h
@@ -92,7 +92,8 @@
 
 int32_t ParsePrefixNalUnit (PWelsDecoderContext pCtx, PBitStringAux pBs);
 
-bool CheckAccessUnitBoundary (PWelsDecoderContext pCtx, const PNalUnit kpCurNal, const PNalUnit kpLastNal, const PSps kpSps);
+bool CheckAccessUnitBoundary (PWelsDecoderContext pCtx, const PNalUnit kpCurNal, const PNalUnit kpLastNal,
+                              const PSps kpSps);
 bool CheckAccessUnitBoundaryExt (PNalUnitHeaderExt pLastNalHdrExt, PNalUnitHeaderExt pCurNalHeaderExt,
                                  PSliceHeader pLastSliceHeader, PSliceHeader pCurSliceHeader);
 /*!
--- a/codec/decoder/core/inc/bit_stream.h
+++ b/codec/decoder/core/inc/bit_stream.h
@@ -42,14 +42,14 @@
  *	Bit-stream auxiliary reading / writing
  */
 typedef struct TagBitStringAux {
-uint8_t*		pStartBuf;	// buffer to start position
-uint8_t*		pEndBuf;	// buffer + length
-int32_t     iBits;       // count bits of overall bitstreaming input
+  uint8_t*		pStartBuf;	// buffer to start position
+  uint8_t*		pEndBuf;	// buffer + length
+  int32_t     iBits;       // count bits of overall bitstreaming input
 
-int32_t     iIndex;      //only for cavlc usage
-uint8_t*		pCurBuf;	// current reading position
-uint32_t    uiCurBits;
-int32_t		iLeftBits;	// count number of available bits left ([1, 8]),
+  int32_t     iIndex;      //only for cavlc usage
+  uint8_t*		pCurBuf;	// current reading position
+  uint32_t    uiCurBits;
+  int32_t		iLeftBits;	// count number of available bits left ([1, 8]),
 // need pointer to next byte start position in case 0 bit left then 8 instead
 } SBitStringAux, *PBitStringAux;
 
--- a/codec/decoder/core/inc/decode_mb_aux.h
+++ b/codec/decoder/core/inc/decode_mb_aux.h
@@ -51,7 +51,7 @@
 #endif//X86_ASM
 
 #if defined(HAVE_NEON)
-void IdctResAddPred_neon(uint8_t *pred, const int32_t stride, int16_t *rs);
+void IdctResAddPred_neon (uint8_t* pred, const int32_t stride, int16_t* rs);
 #endif
 
 #if defined(__cplusplus)
--- a/codec/decoder/core/inc/decode_slice.h
+++ b/codec/decoder/core/inc/decode_slice.h
@@ -64,7 +64,7 @@
 #endif//__cplusplus
 
 #if defined(HAVE_NEON)
-void SetNonZeroCount_neon(int16_t* pBlock, int8_t* pNonZeroCount);
+void SetNonZeroCount_neon (int16_t* pBlock, int8_t* pNonZeroCount);
 #endif
 
 #ifdef __cplusplus
--- a/codec/decoder/core/inc/decoder_context.h
+++ b/codec/decoder/core/inc/decoder_context.h
@@ -78,7 +78,7 @@
 typedef void (*PGetIntraPredFunc) (uint8_t* pPred, const int32_t kiLumaStride);
 typedef void (*PIdctResAddPredFunc) (uint8_t* pPred, const int32_t kiStride, int16_t* pRs);
 typedef void (*PExpandPictureFunc) (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicWidth,
-                                      const int32_t kiPicHeight);
+                                    const int32_t kiPicHeight);
 
 /**/
 typedef struct TagRefPic {
@@ -92,7 +92,7 @@
 } SRefPic, *PRefPic;
 
 typedef void (*PWelsMcFunc) (const uint8_t* pSrc, int32_t iSrcStride, uint8_t* pDst, int32_t iDstStride,
-                               int16_t iMvX, int16_t iMvY, int32_t iWidth, int32_t iHeight);
+                             int16_t iMvX, int16_t iMvY, int32_t iWidth, int32_t iHeight);
 typedef struct TagMcFunc {
   PWelsMcFunc pMcLumaFunc;
   PWelsMcFunc pMcChromaFunc;
@@ -120,7 +120,7 @@
 
 typedef void (*PDeblockingFilterMbFunc) (PDqLayer pCurDqLayer, PDeblockingFilter  filter, int32_t boundry_flag);
 typedef void (*PLumaDeblockingLT4Func) (uint8_t* iSampleY, int32_t iStride, int32_t iAlpha, int32_t iBeta,
-    int8_t* iTc);
+                                        int8_t* iTc);
 typedef void (*PLumaDeblockingEQ4Func) (uint8_t* iSampleY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
 typedef void (*PChromaDeblockingLT4Func) (uint8_t* iSampleCb, uint8_t* iSampleCr, int32_t iStride, int32_t iAlpha,
     int32_t iBeta, int8_t* iTc);
@@ -330,8 +330,8 @@
 
 } SWelsDecoderContext, *PWelsDecoderContext;
 
-static inline void ResetActiveSPSForEachLayer(PWelsDecoderContext pCtx) {
-  for(int i = 0; i < MAX_LAYER_NUM; i++) {
+static inline void ResetActiveSPSForEachLayer (PWelsDecoderContext pCtx) {
+  for (int i = 0; i < MAX_LAYER_NUM; i++) {
     pCtx->pActiveLayerSps[i] = NULL;
   }
 }
--- a/codec/decoder/core/inc/expand_pic.h
+++ b/codec/decoder/core/inc/expand_pic.h
@@ -48,7 +48,7 @@
 namespace WelsDec {
 
 void ExpandReferencingPicture (PPicture pPic, PExpandPictureFunc pExpandPictureLuma,
-                                 PExpandPictureFunc pExpandPictureChroma[2]);
+                               PExpandPictureFunc pExpandPictureChroma[2]);
 
 void InitExpandPictureFunc (SExpandPicFunc* pExpandPicFunc, const uint32_t kuiCpuFlags);
 
--- a/codec/decoder/core/inc/fmo.h
+++ b/codec/decoder/core/inc/fmo.h
@@ -54,12 +54,12 @@
  * \brief	Wels Flexible Macroblock Ordering (FMO)
  */
 typedef struct TagFmo {
-uint8_t*		pMbAllocMap;
-int32_t		iCountMbNum;
-int32_t		iSliceGroupCount;
-int32_t		iSliceGroupType;
-bool		bActiveFlag;
-uint8_t		uiReserved[3];		// reserved padding bytes
+  uint8_t*		pMbAllocMap;
+  int32_t		iCountMbNum;
+  int32_t		iSliceGroupCount;
+  int32_t		iSliceGroupType;
+  bool		bActiveFlag;
+  uint8_t		uiReserved[3];		// reserved padding bytes
 } SFmo, *PFmo;
 
 
--- a/codec/decoder/core/inc/get_intra_predictor.h
+++ b/codec/decoder/core/inc/get_intra_predictor.h
@@ -98,7 +98,7 @@
 
 
 
-void WelsDecoderI4x4LumaPredH_sse2(uint8_t *pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredH_sse2 (uint8_t* pPred, const int32_t kiStride);
 void WelsDecoderI4x4LumaPredDDR_mmx (uint8_t* pPred, const int32_t kiStride);
 void WelsDecoderI4x4LumaPredHD_mmx (uint8_t* pPred, const int32_t kiStride);
 void WelsDecoderI4x4LumaPredHU_mmx (uint8_t* pPred, const int32_t kiStride);
@@ -108,24 +108,24 @@
 #endif//X86_ASM
 
 #if defined(HAVE_NEON)
-void WelsDecoderI16x16LumaPredV_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI16x16LumaPredH_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI16x16LumaPredDc_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI16x16LumaPredPlane_neon(uint8_t *pPred, const int32_t kiStride);
+void WelsDecoderI16x16LumaPredV_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI16x16LumaPredH_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI16x16LumaPredDc_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI16x16LumaPredPlane_neon (uint8_t* pPred, const int32_t kiStride);
 
-void WelsDecoderI4x4LumaPredV_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI4x4LumaPredH_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI4x4LumaPredDDL_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI4x4LumaPredDDR_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI4x4LumaPredVL_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI4x4LumaPredVR_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI4x4LumaPredHU_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderI4x4LumaPredHD_neon(uint8_t *pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredV_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredH_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredDDL_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredDDR_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredVL_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredVR_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredHU_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderI4x4LumaPredHD_neon (uint8_t* pPred, const int32_t kiStride);
 
-void WelsDecoderIChromaPredV_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderIChromaPredH_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderIChromaPredDc_neon(uint8_t *pPred, const int32_t kiStride);
-void WelsDecoderIChromaPredPlane_neon(uint8_t *pPred, const int32_t kiStride);
+void WelsDecoderIChromaPredV_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderIChromaPredH_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderIChromaPredDc_neon (uint8_t* pPred, const int32_t kiStride);
+void WelsDecoderIChromaPredPlane_neon (uint8_t* pPred, const int32_t kiStride);
 #endif//HAVE_NEON
 
 #if defined(__cplusplus)
--- a/codec/decoder/core/inc/mb_cache.h
+++ b/codec/decoder/core/inc/mb_cache.h
@@ -65,15 +65,15 @@
 extern const uint8_t g_kuiScan4[16];
 
 typedef struct TagNeighborAvail {
-int32_t iTopAvail;
-int32_t iLeftAvail;
-int32_t iRightTopAvail;
-int32_t iLeftTopAvail;  //used for check intra_pred_mode avail or not   //1: avail; 0: unavail
+  int32_t iTopAvail;
+  int32_t iLeftAvail;
+  int32_t iRightTopAvail;
+  int32_t iLeftTopAvail;  //used for check intra_pred_mode avail or not   //1: avail; 0: unavail
 
-int32_t iLeftType;
-int32_t iTopType;
-int32_t iLeftTopType;
-int32_t iRightTopType;
+  int32_t iLeftType;
+  int32_t iTopType;
+  int32_t iLeftTopType;
+  int32_t iRightTopType;
 } SNeighAvail, *PNeighAvail;
 
 } // namespace WelsDec
--- a/codec/decoder/core/inc/mc.h
+++ b/codec/decoder/core/inc/mc.h
@@ -41,7 +41,7 @@
 namespace WelsDec {
 
 typedef void (*PMcChromaWidthExtFunc) (const uint8_t* pSrc, int32_t iSrcStride, uint8_t* pDst, int32_t iDstStride,
-    const uint8_t* kpABCD, int32_t iHeight);
+                                       const uint8_t* kpABCD, int32_t iHeight);
 
 void InitMcFunc (SMcFunc* pMcFunc, int32_t iCpu);
 
--- a/codec/decoder/core/inc/mv_pred.h
+++ b/codec/decoder/core/inc/mv_pred.h
@@ -58,8 +58,8 @@
 * \param
 */
 void UpdateP16x8MotionInfo (PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A],
-                              int8_t iRefIndex[LIST_A][30],
-                              int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]);
+                            int8_t iRefIndex[LIST_A][30],
+                            int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]);
 
 
 /*!
@@ -68,8 +68,8 @@
  * \param
  */
 void UpdateP8x16MotionInfo (PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A],
-                              int8_t iRefIndex[LIST_A][30],
-                              int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]);
+                            int8_t iRefIndex[LIST_A][30],
+                            int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]);
 
 /*!
  * \brief   get the motion predictor for skip mode
@@ -84,7 +84,7 @@
  * \param 	output iMvp[]
  */
 void PredMv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
-               int32_t iPartIdx, int32_t iPartWidth, int8_t iRef, int16_t iMVP[2]);
+             int32_t iPartIdx, int32_t iPartWidth, int8_t iRef, int16_t iMVP[2]);
 
 /*!
  * \brief   get the motion predictor for inter16x8 MB
@@ -92,7 +92,7 @@
  * \param 	output mvp_x and mvp_y
  */
 void PredInter16x8Mv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
-                        int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]);
+                      int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]);
 
 /*!
  * \brief   get the motion predictor for inter8x16 MB
@@ -100,7 +100,7 @@
  * \param 	output mvp_x and mvp_y
  */
 void PredInter8x16Mv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
-                        int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]);
+                      int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]);
 
 } // namespace WelsDec
 
--- a/codec/decoder/core/inc/nalu.h
+++ b/codec/decoder/core/inc/nalu.h
@@ -45,18 +45,18 @@
 
 /* NAL Unit Structure */
 typedef struct TagNalUnit {
-SNalUnitHeaderExt	sNalHeaderExt;
+  SNalUnitHeaderExt	sNalHeaderExt;
 
-union {
-  struct SVclNal {
-    SSliceHeaderExt	sSliceHeaderExt;
-    SBitStringAux	sSliceBitsRead;
-    uint8_t*		 pNalPos;	  // save the address of slice nal for GPU function
-    int32_t 		iNalLength;   // save the nal length for GPU function
-    bool			bSliceHeaderExtFlag;
-  } sVclNal;
-  SPrefixNalUnit	sPrefixNal;
-} sNalData;
+  union {
+    struct SVclNal {
+      SSliceHeaderExt	sSliceHeaderExt;
+      SBitStringAux	sSliceBitsRead;
+      uint8_t*		 pNalPos;	  // save the address of slice nal for GPU function
+      int32_t 		iNalLength;   // save the nal length for GPU function
+      bool			bSliceHeaderExtFlag;
+    } sVclNal;
+    SPrefixNalUnit	sPrefixNal;
+  } sNalData;
 
 } SNalUnit, *PNalUnit;
 
@@ -64,14 +64,14 @@
 
 /* Access Unit structure */
 typedef struct TagAccessUnits {
-PNalUnit*		pNalUnitsList;	// list of NAL Units pointer in this AU
-uint32_t		uiAvailUnitsNum;	// Number of NAL Units available in each AU list based current bitstream,
-uint32_t		uiActualUnitsNum;	// actual number of NAL units belong to current au
+  PNalUnit*		pNalUnitsList;	// list of NAL Units pointer in this AU
+  uint32_t		uiAvailUnitsNum;	// Number of NAL Units available in each AU list based current bitstream,
+  uint32_t		uiActualUnitsNum;	// actual number of NAL units belong to current au
 // While available number exceeds count size below, need realloc extra NAL Units for list space.
-uint32_t		uiCountUnitsNum;	// Count size number of malloced NAL Units in each AU list
-uint32_t		uiStartPos;
-uint32_t		uiEndPos;
-bool			bCompletedAuFlag;	// Indicate whether it is a completed AU
+  uint32_t		uiCountUnitsNum;	// Count size number of malloced NAL Units in each AU list
+  uint32_t		uiStartPos;
+  uint32_t		uiEndPos;
+  bool			bCompletedAuFlag;	// Indicate whether it is a completed AU
 } SAccessUnit, *PAccessUnit;
 
 } // namespace WelsDec
--- a/codec/decoder/core/inc/parameter_sets.h
+++ b/codec/decoder/core/inc/parameter_sets.h
@@ -53,53 +53,53 @@
 
 /* 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 +117,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/inc/parse_mb_syn_cavlc.h
+++ b/codec/decoder/core/inc/parse_mb_syn_cavlc.h
@@ -137,11 +137,11 @@
 void GetNeighborAvailMbType (PNeighAvail pNeighAvail, PDqLayer pCurLayer);
 void WelsFillCacheNonZeroCount (PNeighAvail pNeighAvail, uint8_t* pNonZeroCount, PDqLayer pCurLayer);
 void WelsFillCacheConstrain0Intra4x4 (PNeighAvail pNeighAvail, uint8_t* pNonZeroCount, int8_t* pIntraPredMode,
-                                        PDqLayer pCurLayer);
+                                      PDqLayer pCurLayer);
 void WelsFillCacheConstrain1Intra4x4 (PNeighAvail pNeighAvail, uint8_t* pNonZeroCount, int8_t* pIntraPredMode,
-                                        PDqLayer pCurLayer);
+                                      PDqLayer pCurLayer);
 void WelsFillCacheInter (PNeighAvail pNeighAvail, uint8_t* pNonZeroCount,
-                           int16_t iMvArray[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30], PDqLayer pCurLayer);
+                         int16_t iMvArray[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30], PDqLayer pCurLayer);
 
 
 /*!
--- a/codec/decoder/core/inc/pic_queue.h
+++ b/codec/decoder/core/inc/pic_queue.h
@@ -43,9 +43,9 @@
 
 
 typedef struct TagPicBuff {
-PPicture*      ppPic;
-int32_t        iCapacity;  // capacity size of queue
-int32_t        iCurrentIdx;
+  PPicture*      ppPic;
+  int32_t        iCapacity;  // capacity size of queue
+  int32_t        iCurrentIdx;
 } SPicBuff, *PPicBuff;
 
 /*
--- a/codec/decoder/core/inc/picture.h
+++ b/codec/decoder/core/inc/picture.h
@@ -43,36 +43,36 @@
  *	It is used to express reference picture, also consequent reconstruction picture for output
  */
 typedef struct TagPicture {
-/************************************payload data*********************************/
-uint8_t*		pBuffer[4];		// pointer to the first allocated byte, basical offset of buffer, dimension:
-uint8_t*		pData[4];		// pointer to picture planes respectively
-int32_t		iLinesize[4];// linesize of picture planes respectively used currently
-int32_t		iPlanes;			// How many planes are introduced due to color space format?
+  /************************************payload data*********************************/
+  uint8_t*		pBuffer[4];		// pointer to the first allocated byte, basical offset of buffer, dimension:
+  uint8_t*		pData[4];		// pointer to picture planes respectively
+  int32_t		iLinesize[4];// linesize of picture planes respectively used currently
+  int32_t		iPlanes;			// How many planes are introduced due to color space format?
 // picture information
 
-/*******************************from other standard syntax****************************/
-/*from sps*/
-int32_t		iWidthInPixel;	// picture width in pixel
-int32_t		iHeightInPixel;// picture height in pixel
-/*from slice header*/
-int32_t		iFramePoc;		// frame POC
+  /*******************************from other standard syntax****************************/
+  /*from sps*/
+  int32_t		iWidthInPixel;	// picture width in pixel
+  int32_t		iHeightInPixel;// picture height in pixel
+  /*from slice header*/
+  int32_t		iFramePoc;		// frame POC
 
-/*******************************sef_definition for misc use****************************/
-bool		bUsedAsRef;							//for ref pic management
-bool		bIsLongRef;	// long term reference frame flag	//for ref pic management
-uint8_t		uiRefCount;
-bool		bAvailableFlag;	// indicate whether it is available in this picture memory block.
+  /*******************************sef_definition for misc use****************************/
+  bool		bUsedAsRef;							//for ref pic management
+  bool		bIsLongRef;	// long term reference frame flag	//for ref pic management
+  uint8_t		uiRefCount;
+  bool		bAvailableFlag;	// indicate whether it is available in this picture memory block.
 
-/*******************************for future use****************************/
-uint8_t		uiTemporalId;
-uint8_t		uiSpatialId;
-uint8_t		uiQualityId;
+  /*******************************for future use****************************/
+  uint8_t		uiTemporalId;
+  uint8_t		uiSpatialId;
+  uint8_t		uiQualityId;
 
-int32_t		iFrameNum;		// frame number			//for ref pic management
-int32_t		iLongTermFrameIdx;					//id for long term ref pic
+  int32_t		iFrameNum;		// frame number			//for ref pic management
+  int32_t		iLongTermFrameIdx;					//id for long term ref pic
 
-int32_t     iSpsId; //against mosaic caused by cross-IDR interval reference.
-int32_t     iPpsId;
+  int32_t     iSpsId; //against mosaic caused by cross-IDR interval reference.
+  int32_t     iPpsId;
 } SPicture, *PPicture;	// "Picture" declaration is comflict with Mac system
 
 } // namespace WelsDec
--- a/codec/decoder/core/inc/rec_mb.h
+++ b/codec/decoder/core/inc/rec_mb.h
@@ -64,7 +64,7 @@
 void GetInterPred (uint8_t* pPredY, uint8_t* pPredCb, uint8_t* pPredCr, PWelsDecoderContext pCtx);
 
 void FillBufForMc (uint8_t* pBuf, int32_t iBufStride, uint8_t* pSrc, int32_t iSrcStride, int32_t iSrcOffset,
-                     int32_t iBlockWidth, int32_t iBlockHeight, int32_t iSrcX, int32_t iSrcY, int32_t iPicWidth, int32_t iPicHeight);
+                   int32_t iBlockWidth, int32_t iBlockHeight, int32_t iSrcX, int32_t iSrcY, int32_t iPicWidth, int32_t iPicHeight);
 
 } // namespace WelsDec
 
--- a/codec/decoder/core/inc/vlc_decoder.h
+++ b/codec/decoder/core/inc/vlc_decoder.h
@@ -39,10 +39,10 @@
 namespace WelsDec {
 
 typedef struct TagVlcTable {
-const uint8_t (*kpCoeffTokenVlcTable[4][8])[2];
-const uint8_t (*kpChromaCoeffTokenVlcTable)[2];
-const uint8_t (*kpZeroTable[7])[2];
-const uint8_t (*kpTotalZerosTable[2][15])[2];
+  const uint8_t (*kpCoeffTokenVlcTable[4][8])[2];
+  const uint8_t (*kpChromaCoeffTokenVlcTable)[2];
+  const uint8_t (*kpZeroTable[7])[2];
+  const uint8_t (*kpTotalZerosTable[2][15])[2];
 } SVlcTable;
 
 // for data sharing cross modules and try to reduce size of binary generated
@@ -117,58 +117,58 @@
 #endif
 
 static inline void InitVlcTable (SVlcTable* pVlcTable) {
-pVlcTable->kpChromaCoeffTokenVlcTable = g_kuiVlcChromaTable;
+  pVlcTable->kpChromaCoeffTokenVlcTable = g_kuiVlcChromaTable;
 
-pVlcTable->kpCoeffTokenVlcTable[0][0] = g_kuiVlcTable_0;
-pVlcTable->kpCoeffTokenVlcTable[0][1] = g_kuiVlcTable_1;
-pVlcTable->kpCoeffTokenVlcTable[0][2] = g_kuiVlcTable_2;
-pVlcTable->kpCoeffTokenVlcTable[0][3] = g_kuiVlcTable_3;
+  pVlcTable->kpCoeffTokenVlcTable[0][0] = g_kuiVlcTable_0;
+  pVlcTable->kpCoeffTokenVlcTable[0][1] = g_kuiVlcTable_1;
+  pVlcTable->kpCoeffTokenVlcTable[0][2] = g_kuiVlcTable_2;
+  pVlcTable->kpCoeffTokenVlcTable[0][3] = g_kuiVlcTable_3;
 
-pVlcTable->kpCoeffTokenVlcTable[1][0] = g_kuiVlcTable_0_0;
-pVlcTable->kpCoeffTokenVlcTable[1][1] = g_kuiVlcTable_0_1;
-pVlcTable->kpCoeffTokenVlcTable[1][2] = g_kuiVlcTable_0_2;
-pVlcTable->kpCoeffTokenVlcTable[1][3] = g_kuiVlcTable_0_3;
+  pVlcTable->kpCoeffTokenVlcTable[1][0] = g_kuiVlcTable_0_0;
+  pVlcTable->kpCoeffTokenVlcTable[1][1] = g_kuiVlcTable_0_1;
+  pVlcTable->kpCoeffTokenVlcTable[1][2] = g_kuiVlcTable_0_2;
+  pVlcTable->kpCoeffTokenVlcTable[1][3] = g_kuiVlcTable_0_3;
 
-pVlcTable->kpCoeffTokenVlcTable[2][0] = g_kuiVlcTable_1_0;
-pVlcTable->kpCoeffTokenVlcTable[2][1] = g_kuiVlcTable_1_1;
-pVlcTable->kpCoeffTokenVlcTable[2][2] = g_kuiVlcTable_1_2;
-pVlcTable->kpCoeffTokenVlcTable[2][3] = g_kuiVlcTable_1_3;
+  pVlcTable->kpCoeffTokenVlcTable[2][0] = g_kuiVlcTable_1_0;
+  pVlcTable->kpCoeffTokenVlcTable[2][1] = g_kuiVlcTable_1_1;
+  pVlcTable->kpCoeffTokenVlcTable[2][2] = g_kuiVlcTable_1_2;
+  pVlcTable->kpCoeffTokenVlcTable[2][3] = g_kuiVlcTable_1_3;
 
-pVlcTable->kpCoeffTokenVlcTable[3][0] = g_kuiVlcTable_2_0;
-pVlcTable->kpCoeffTokenVlcTable[3][1] = g_kuiVlcTable_2_1;
-pVlcTable->kpCoeffTokenVlcTable[3][2] = g_kuiVlcTable_2_2;
-pVlcTable->kpCoeffTokenVlcTable[3][3] = g_kuiVlcTable_2_3;
-pVlcTable->kpCoeffTokenVlcTable[3][4] = g_kuiVlcTable_2_4;
-pVlcTable->kpCoeffTokenVlcTable[3][5] = g_kuiVlcTable_2_5;
-pVlcTable->kpCoeffTokenVlcTable[3][6] = g_kuiVlcTable_2_6;
-pVlcTable->kpCoeffTokenVlcTable[3][7] = g_kuiVlcTable_2_7;
+  pVlcTable->kpCoeffTokenVlcTable[3][0] = g_kuiVlcTable_2_0;
+  pVlcTable->kpCoeffTokenVlcTable[3][1] = g_kuiVlcTable_2_1;
+  pVlcTable->kpCoeffTokenVlcTable[3][2] = g_kuiVlcTable_2_2;
+  pVlcTable->kpCoeffTokenVlcTable[3][3] = g_kuiVlcTable_2_3;
+  pVlcTable->kpCoeffTokenVlcTable[3][4] = g_kuiVlcTable_2_4;
+  pVlcTable->kpCoeffTokenVlcTable[3][5] = g_kuiVlcTable_2_5;
+  pVlcTable->kpCoeffTokenVlcTable[3][6] = g_kuiVlcTable_2_6;
+  pVlcTable->kpCoeffTokenVlcTable[3][7] = g_kuiVlcTable_2_7;
 
-pVlcTable->kpZeroTable[0] = g_kuiZeroLeftTable0;
-pVlcTable->kpZeroTable[1] = g_kuiZeroLeftTable1;
-pVlcTable->kpZeroTable[2] = g_kuiZeroLeftTable2;
-pVlcTable->kpZeroTable[3] = g_kuiZeroLeftTable3;
-pVlcTable->kpZeroTable[4] = g_kuiZeroLeftTable4;
-pVlcTable->kpZeroTable[5] = g_kuiZeroLeftTable5;
-pVlcTable->kpZeroTable[6] = g_kuiZeroLeftTable6;
+  pVlcTable->kpZeroTable[0] = g_kuiZeroLeftTable0;
+  pVlcTable->kpZeroTable[1] = g_kuiZeroLeftTable1;
+  pVlcTable->kpZeroTable[2] = g_kuiZeroLeftTable2;
+  pVlcTable->kpZeroTable[3] = g_kuiZeroLeftTable3;
+  pVlcTable->kpZeroTable[4] = g_kuiZeroLeftTable4;
+  pVlcTable->kpZeroTable[5] = g_kuiZeroLeftTable5;
+  pVlcTable->kpZeroTable[6] = g_kuiZeroLeftTable6;
 
-pVlcTable->kpTotalZerosTable[0][0] = g_kuiTotalZerosTable0;
-pVlcTable->kpTotalZerosTable[0][1] = g_kuiTotalZerosTable1;
-pVlcTable->kpTotalZerosTable[0][2] = g_kuiTotalZerosTable2;
-pVlcTable->kpTotalZerosTable[0][3] = g_kuiTotalZerosTable3;
-pVlcTable->kpTotalZerosTable[0][4] = g_kuiTotalZerosTable4;
-pVlcTable->kpTotalZerosTable[0][5] = g_kuiTotalZerosTable5;
-pVlcTable->kpTotalZerosTable[0][6] = g_kuiTotalZerosTable6;
-pVlcTable->kpTotalZerosTable[0][7] = g_kuiTotalZerosTable7;
-pVlcTable->kpTotalZerosTable[0][8] = g_kuiTotalZerosTable8;
-pVlcTable->kpTotalZerosTable[0][9] = g_kuiTotalZerosTable9;
-pVlcTable->kpTotalZerosTable[0][10] = g_kuiTotalZerosTable10;
-pVlcTable->kpTotalZerosTable[0][11] = g_kuiTotalZerosTable11;
-pVlcTable->kpTotalZerosTable[0][12] = g_kuiTotalZerosTable12;
-pVlcTable->kpTotalZerosTable[0][13] = g_kuiTotalZerosTable13;
-pVlcTable->kpTotalZerosTable[0][14] = g_kuiTotalZerosTable14;
-pVlcTable->kpTotalZerosTable[1][0] = g_kuiTotalZerosChromaTable0;
-pVlcTable->kpTotalZerosTable[1][1] = g_kuiTotalZerosChromaTable1;
-pVlcTable->kpTotalZerosTable[1][2] = g_kuiTotalZerosChromaTable2;
+  pVlcTable->kpTotalZerosTable[0][0] = g_kuiTotalZerosTable0;
+  pVlcTable->kpTotalZerosTable[0][1] = g_kuiTotalZerosTable1;
+  pVlcTable->kpTotalZerosTable[0][2] = g_kuiTotalZerosTable2;
+  pVlcTable->kpTotalZerosTable[0][3] = g_kuiTotalZerosTable3;
+  pVlcTable->kpTotalZerosTable[0][4] = g_kuiTotalZerosTable4;
+  pVlcTable->kpTotalZerosTable[0][5] = g_kuiTotalZerosTable5;
+  pVlcTable->kpTotalZerosTable[0][6] = g_kuiTotalZerosTable6;
+  pVlcTable->kpTotalZerosTable[0][7] = g_kuiTotalZerosTable7;
+  pVlcTable->kpTotalZerosTable[0][8] = g_kuiTotalZerosTable8;
+  pVlcTable->kpTotalZerosTable[0][9] = g_kuiTotalZerosTable9;
+  pVlcTable->kpTotalZerosTable[0][10] = g_kuiTotalZerosTable10;
+  pVlcTable->kpTotalZerosTable[0][11] = g_kuiTotalZerosTable11;
+  pVlcTable->kpTotalZerosTable[0][12] = g_kuiTotalZerosTable12;
+  pVlcTable->kpTotalZerosTable[0][13] = g_kuiTotalZerosTable13;
+  pVlcTable->kpTotalZerosTable[0][14] = g_kuiTotalZerosTable14;
+  pVlcTable->kpTotalZerosTable[1][0] = g_kuiTotalZerosChromaTable0;
+  pVlcTable->kpTotalZerosTable[1][1] = g_kuiTotalZerosChromaTable1;
+  pVlcTable->kpTotalZerosTable[1][2] = g_kuiTotalZerosChromaTable2;
 
 }
 
--- a/codec/decoder/core/inc/wels_common_basis.h
+++ b/codec/decoder/core/inc/wels_common_basis.h
@@ -51,17 +51,17 @@
 /* Profile IDC */
 typedef uint8_t		ProfileIdc;
 enum {
-PRO_BASELINE	= 66,
-PRO_MAIN		= 77,
-PRO_EXTENDED	= 88,
-PRO_HIGH		= 100,
-PRO_HIGH10		= 110,
-PRO_HIGH422		= 122,
-PRO_HIGH444		= 144,
-PRO_CAVLC444	= 244,
+  PRO_BASELINE	= 66,
+  PRO_MAIN		= 77,
+  PRO_EXTENDED	= 88,
+  PRO_HIGH		= 100,
+  PRO_HIGH10		= 110,
+  PRO_HIGH422		= 122,
+  PRO_HIGH444		= 144,
+  PRO_CAVLC444	= 244,
 
-PRO_SCALABLE_BASELINE	= 83,
-PRO_SCALABLE_HIGH		= 86,
+  PRO_SCALABLE_BASELINE	= 83,
+  PRO_SCALABLE_HIGH		= 86,
 };
 
 /*
@@ -68,38 +68,38 @@
  *	NAL Unit Type (5 Bits)
  */
 typedef enum TagNalUnitType {
-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
 } ENalUnitType;
 
 static const uint8_t g_kuiEmulationPreventionThreeByte	= 0x03;
@@ -109,10 +109,10 @@
  */
 typedef uint8_t		NalRefIdc;
 enum {
-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
 };
 
 /*
@@ -120,9 +120,9 @@
  */
 typedef uint8_t		VclType;
 enum {
-NON_VCL			= 0,
-VCL				= 1,
-NOT_APP			= 2
+  NON_VCL			= 0,
+  VCL				= 1,
+  NOT_APP			= 2
 };
 
 /*
@@ -147,58 +147,58 @@
  * meaning mapped version after eSliceType minus 4.
  */
 typedef enum TagSliceType {
-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
 } ESliceType;
 
 /* List Index */
 typedef uint8_t		ListIndex;
 enum {
-LIST_0	= 0,
-LIST_1	= 1,
-LIST_A	= 2
+  LIST_0	= 0,
+  LIST_1	= 1,
+  LIST_A	= 2
 };
 
 /* Picture Size */
 typedef struct TagPictureSize {
-int32_t	iWidth;
-int32_t iHeight;
+  int32_t	iWidth;
+  int32_t iHeight;
 } SPictureSize;
 
 /* Motion Vector components */
 typedef uint8_t		MvComp;
 enum {
-MV_X	= 0,
-MV_Y	= 1,
-MV_A	= 2
+  MV_X	= 0,
+  MV_Y	= 1,
+  MV_A	= 2
 };
 
 /* Chroma Components */
 typedef uint8_t		ChromaComp;
 enum {
-CHROMA_CB	= 0,
-CHROMA_CR	= 1,
-CHROMA_A	= 2
+  CHROMA_CB	= 0,
+  CHROMA_CR	= 1,
+  CHROMA_A	= 2
 };
 
 /* Position Offset structure */
 typedef struct TagPosOffset {
-int32_t	iLeftOffset;
-int32_t	iTopOffset;
-int32_t	iRightOffset;
-int32_t	iBottomOffset;
+  int32_t	iLeftOffset;
+  int32_t	iTopOffset;
+  int32_t	iRightOffset;
+  int32_t	iBottomOffset;
 } SPosOffset;
 
 enum EMbPosition { //
-MB_LEFT     = 0x01,	// A
-MB_TOP      = 0x02,	// B
-MB_TOPRIGHT = 0x04,	// C
-MB_TOPLEFT	= 0x08,	// D,
-MB_PRIVATE  = 0x10,
+  MB_LEFT     = 0x01,	// A
+  MB_TOP      = 0x02,	// B
+  MB_TOPRIGHT = 0x04,	// C
+  MB_TOPLEFT	= 0x08,	// D,
+  MB_PRIVATE  = 0x10,
 };
 /* MB Type & Sub-MB Type */
 typedef int32_t MbType;
@@ -237,13 +237,13 @@
  *	Memory Management Control Operation (MMCO) code
  */
 enum {
-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/decoder/core/src/au_parser.cpp
+++ b/codec/decoder/core/src/au_parser.cpp
@@ -399,7 +399,8 @@
 }
 
 
-bool CheckAccessUnitBoundary (PWelsDecoderContext pCtx, const PNalUnit kpCurNal, const PNalUnit kpLastNal, const PSps kpSps) {
+bool CheckAccessUnitBoundary (PWelsDecoderContext pCtx, const PNalUnit kpCurNal, const PNalUnit kpLastNal,
+                              const PSps kpSps) {
   const PNalUnitHeaderExt kpLastNalHeaderExt = &kpLastNal->sNalHeaderExt;
   const PNalUnitHeaderExt kpCurNalHeaderExt = &kpCurNal->sNalHeaderExt;
   const SSliceHeader* kpLastSliceHeader = &kpLastNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader;
@@ -411,7 +412,8 @@
   }
   if (kpLastSliceHeader->iFrameNum != kpCurSliceHeader->iFrameNum)
     return true;
-  if (pCtx->pActiveLayerSps[kpCurNalHeaderExt->uiDependencyId] != NULL && pCtx->pActiveLayerSps[kpCurNalHeaderExt->uiDependencyId] != kpSps) {
+  if (pCtx->pActiveLayerSps[kpCurNalHeaderExt->uiDependencyId] != NULL
+      && pCtx->pActiveLayerSps[kpCurNalHeaderExt->uiDependencyId] != kpSps) {
     pCtx->bNextNewSeqBegin = true;
     return true; // the active sps changed, new sequence begins, so the current au is ready
   }
@@ -423,7 +425,8 @@
   if (kpLastNalHeaderExt->uiDependencyId > kpCurNalHeaderExt->uiDependencyId)
     return true;
   // Subclause 7.4.1.2.4
-  if (kpLastNalHeaderExt->uiDependencyId == kpCurNalHeaderExt->uiDependencyId && kpLastSliceHeader->iPpsId != kpCurSliceHeader->iPpsId)
+  if (kpLastNalHeaderExt->uiDependencyId == kpCurNalHeaderExt->uiDependencyId
+      && kpLastSliceHeader->iPpsId != kpCurSliceHeader->iPpsId)
     return true;
   if (kpLastSliceHeader->bFieldPicFlag != kpCurSliceHeader->bFieldPicFlag)
     return true;
--- a/codec/decoder/core/src/deblocking.cpp
+++ b/codec/decoder/core/src/deblocking.cpp
@@ -185,25 +185,25 @@
   uiNnz32b3 = * (uint32_t*) (pNnzTab + 12);
 
   for (int i = 0; i < 3; i++)
-      uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1];
+    uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1];
   nBS[0][1][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 1, 0);
   nBS[0][2][0] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 2, 1);
   nBS[0][3][0] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 3, 2);
 
   for (int i = 0; i < 3; i++)
-      uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1];
+    uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1];
   nBS[0][1][1] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 5, 4);
   nBS[0][2][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 6, 5);
   nBS[0][3][1] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 7, 6);
 
   for (int i = 0; i < 3; i++)
-      uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1];
+    uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1];
   nBS[0][1][2] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 9, 8);
   nBS[0][2][2] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 10, 9);
   nBS[0][3][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 11, 10);
 
   for (int i = 0; i < 3; i++)
-      uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1];
+    uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1];
   nBS[0][1][3] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 13, 12);
   nBS[0][2][3] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 14, 13);
   nBS[0][3][3] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 15, 14);
@@ -233,8 +233,8 @@
   uint32_t uiBSx4;
   //uint8_t* bS = static_cast<uint8_t*>(&uiBSx4);
   uint8_t* pBS = (uint8_t*) (&uiBSx4);
-  const uint8_t *pBIdx  = &g_kuiTableBIdx[iEdge][0];
-  const uint8_t *pBnIdx = &g_kuiTableBIdx[iEdge][4];
+  const uint8_t* pBIdx  = &g_kuiTableBIdx[iEdge][0];
+  const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4];
 
   for (i = 0; i < 4; i++) {
     if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {
@@ -327,7 +327,7 @@
   return;
 }
 void FilteringEdgeChromaH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,
-                             uint8_t* pBS) {
+                           uint8_t* pBS) {
   int32_t iIndexA;
   int32_t iAlpha;
   int32_t iBeta;
@@ -343,7 +343,7 @@
   return;
 }
 void FilteringEdgeChromaV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,
-                             uint8_t* pBS) {
+                           uint8_t* pBS) {
   int32_t iIndexA;
   int32_t iAlpha;
   int32_t iBeta;
@@ -360,7 +360,7 @@
 }
 
 void FilteringEdgeChromaIntraH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,
-                                  uint8_t* pBS) {
+                                uint8_t* pBS) {
   int32_t iIndexA;
   int32_t iAlpha;
   int32_t iBeta;
@@ -375,7 +375,7 @@
 }
 
 void FilteringEdgeChromaIntraV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,
-                                  uint8_t* pBS) {
+                                uint8_t* pBS) {
   int32_t iIndexA;
   int32_t iAlpha;
   int32_t iBeta;
@@ -391,7 +391,7 @@
 
 
 void DeblockingInterMb (PDqLayer pCurDqLayer, PDeblockingFilter  pFilter, uint8_t nBS[2][4][4],
-                          int32_t iBoundryFlag) {
+                        int32_t iBoundryFlag) {
   int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;
   int32_t iMbX = pCurDqLayer->iMbX;
   int32_t iMbY = pCurDqLayer->iMbY;
@@ -631,7 +631,7 @@
   int32_t iTotalMbCount = pSliceHeaderExt->sSliceHeader.pSps->uiTotalMbCount;
 
   SDeblockingFilter pFilter;
-  memset (&pFilter, 0, sizeof(pFilter));
+  memset (&pFilter, 0, sizeof (pFilter));
   PFmo pFmo = pCtx->pFmo;
   int32_t iNextMbXyIndex = 0;
   int32_t iTotalNumMb = pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice;
@@ -720,18 +720,17 @@
 #endif
 
 #if defined(HAVE_NEON)
-  if ( iCpu & WELS_CPU_NEON )
-	{
-		pFunc->pfLumaDeblockingLT4Ver		= DeblockLumaLt4V_neon;
-		pFunc->pfLumaDeblockingEQ4Ver		= DeblockLumaEq4V_neon;
-		pFunc->pfLumaDeblockingLT4Hor		= DeblockLumaLt4H_neon;
-		pFunc->pfLumaDeblockingEQ4Hor		= DeblockLumaEq4H_neon;
+  if (iCpu & WELS_CPU_NEON) {
+    pFunc->pfLumaDeblockingLT4Ver		= DeblockLumaLt4V_neon;
+    pFunc->pfLumaDeblockingEQ4Ver		= DeblockLumaEq4V_neon;
+    pFunc->pfLumaDeblockingLT4Hor		= DeblockLumaLt4H_neon;
+    pFunc->pfLumaDeblockingEQ4Hor		= DeblockLumaEq4H_neon;
 
-		pFunc->pfChromaDeblockingLT4Ver     = DeblockChromaLt4V_neon;
-		pFunc->pfChromaDeblockingEQ4Ver     = DeblockChromaEq4V_neon;
-		pFunc->pfChromaDeblockingLT4Hor     = DeblockChromaLt4H_neon;
-		pFunc->pfChromaDeblockingEQ4Hor      = DeblockChromaEq4H_neon;
-	}
+    pFunc->pfChromaDeblockingLT4Ver     = DeblockChromaLt4V_neon;
+    pFunc->pfChromaDeblockingEQ4Ver     = DeblockChromaEq4V_neon;
+    pFunc->pfChromaDeblockingLT4Hor     = DeblockChromaLt4H_neon;
+    pFunc->pfChromaDeblockingEQ4Hor      = DeblockChromaEq4H_neon;
+  }
 #endif
 }
 
--- a/codec/decoder/core/src/decode_mb_aux.cpp
+++ b/codec/decoder/core/src/decode_mb_aux.cpp
@@ -92,13 +92,13 @@
     int32_t kT3	= (32 + kT1 + kT2) >> 6;
     int32_t kT4	= (32 + kT1 - kT2) >> 6;
 
-    pDst[i] = WelsClip1( kT3 + pPred[i] );
-    pDst[i + kiStride3] = WelsClip1( kT4 + pPred[i + kiStride3] );
+    pDst[i] = WelsClip1 (kT3 + pPred[i]);
+    pDst[i + kiStride3] = WelsClip1 (kT4 + pPred[i + kiStride3]);
 
     kT1	= iSrc[i] - iSrc[i + 8];
     kT2	= (iSrc[i + 4] >> 1) - iSrc[i + 12];
-    pDst[i + kiStride] = WelsClip1( ((32 + kT1 + kT2) >> 6) + pDst[i + kiStride] );
-    pDst[i + kiStride2] = WelsClip1( ((32 + kT1 - kT2) >> 6) + pDst[i + kiStride2] );
+    pDst[i + kiStride] = WelsClip1 (((32 + kT1 + kT2) >> 6) + pDst[i + kiStride]);
+    pDst[i + kiStride2] = WelsClip1 (((32 + kT1 - kT2) >> 6) + pDst[i + kiStride2]);
   }
 }
 
--- a/codec/decoder/core/src/decode_slice.cpp
+++ b/codec/decoder/core/src/decode_slice.cpp
@@ -441,7 +441,7 @@
   int32_t iMbX = pCurLayer->iMbX;
   int32_t iMbY = pCurLayer->iMbY;
   const int32_t iMbXy = pCurLayer->iMbXyIndex;
-  int8_t *pNzc = pCurLayer->pNzc[iMbXy];
+  int8_t* pNzc = pCurLayer->pNzc[iMbXy];
   int32_t i;
   uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;
   uint32_t uiCode;
@@ -844,7 +844,7 @@
     uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
   }
 
-  memset(pCurLayer->pScaledTCoeff[iMbXy], 0, MB_COEFF_LIST_SIZE * sizeof(int16_t));
+  memset (pCurLayer->pScaledTCoeff[iMbXy], 0, MB_COEFF_LIST_SIZE * sizeof (int16_t));
 
   ST32A4 (&pNzc[0], 0);
   ST32A4 (&pNzc[4], 0);
@@ -975,7 +975,7 @@
   PSliceHeader pSliceHeader		    = &pSlice->sSliceHeaderExt.sSliceHeader;
 
   const int32_t iMbXy = pCurLayer->iMbXyIndex;
-  int8_t *pNzc = pCurLayer->pNzc[iMbXy];
+  int8_t* pNzc = pCurLayer->pNzc[iMbXy];
   int32_t iBaseModeFlag, i;
   int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15
   uint32_t uiCode;
@@ -1048,7 +1048,7 @@
   pFunc->pWelsSetNonZeroCountFunc	    = SetNonZeroCount_c;
 
 #ifdef	HAVE_NEON
-  if ( iCpu & WELS_CPU_NEON ) {
+  if (iCpu & WELS_CPU_NEON) {
     pFunc->pWelsSetNonZeroCountFunc		= SetNonZeroCount_neon;
   }
 #endif
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -970,7 +970,8 @@
     pCtx->sMb.pInterPredictionDoneFlag[i] = (int8_t*) WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (
         int8_t), "pCtx->sMb.pInterPredictionDoneFlag[]");
 
-    pCtx->sMb.pMbCorrectlyDecodedFlag[i] = (bool*) WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (bool), "pCtx->sMb.pMbCorrectlyDecodedFlag[]");
+    pCtx->sMb.pMbCorrectlyDecodedFlag[i] = (bool*) WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (bool),
+                                           "pCtx->sMb.pMbCorrectlyDecodedFlag[]");
 
     // check memory block valid due above allocated..
     WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY,
@@ -1482,39 +1483,41 @@
  * return:
  * true - the AU to be construct is the start of new sequence; false - not
  */
-static bool CheckNewSeqBeginAndUpdateActiveLayerSps(PWelsDecoderContext pCtx) {
+static bool CheckNewSeqBeginAndUpdateActiveLayerSps (PWelsDecoderContext pCtx) {
   bool bNewSeq = false;
   PAccessUnit pCurAu = pCtx->pAccessUnitList;
   PSps pTmpLayerSps[MAX_LAYER_NUM];
-  for(int i = 0; i < MAX_LAYER_NUM; i++) {
+  for (int i = 0; i < MAX_LAYER_NUM; i++) {
     pTmpLayerSps[i] = NULL;
   }
   // track the layer sps for the current au
-  for(unsigned int i = pCurAu->uiStartPos; i <= pCurAu->uiEndPos; i++) {
+  for (unsigned int i = pCurAu->uiStartPos; i <= pCurAu->uiEndPos; i++) {
     uint32_t uiDid = pCurAu->pNalUnitsList[i]->sNalHeaderExt.uiDependencyId;
     pTmpLayerSps[uiDid] = pCurAu->pNalUnitsList[i]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pSps;
-    if ((pCurAu->pNalUnitsList[i]->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR) || (pCurAu->pNalUnitsList[i]->sNalHeaderExt.bIdrFlag))
+    if ((pCurAu->pNalUnitsList[i]->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR)
+        || (pCurAu->pNalUnitsList[i]->sNalHeaderExt.bIdrFlag))
       bNewSeq = true;
   }
   int iMaxActiveLayer = 0, iMaxCurrentLayer = 0;
-  for(int i = MAX_LAYER_NUM - 1; i >= 0; i--) {
+  for (int i = MAX_LAYER_NUM - 1; i >= 0; i--) {
     if (pCtx->pActiveLayerSps[i] != NULL) {
       iMaxActiveLayer = i;
       break;
     }
   }
-  for(int i = MAX_LAYER_NUM - 1; i >= 0; i--) {
+  for (int i = MAX_LAYER_NUM - 1; i >= 0; i--) {
     if (pTmpLayerSps[i] != NULL) {
       iMaxCurrentLayer = i;
       break;
     }
   }
-  if ((iMaxCurrentLayer != iMaxActiveLayer) || (pTmpLayerSps[iMaxCurrentLayer]  != pCtx->pActiveLayerSps[iMaxActiveLayer])) {
+  if ((iMaxCurrentLayer != iMaxActiveLayer)
+      || (pTmpLayerSps[iMaxCurrentLayer]  != pCtx->pActiveLayerSps[iMaxActiveLayer])) {
     bNewSeq = true;
   }
   // fill active sps if the current sps is not null while active layer is null
   if (!bNewSeq) {
-    for(int i = 0; i < MAX_LAYER_NUM; i++) {
+    for (int i = 0; i < MAX_LAYER_NUM; i++) {
       if (pCtx->pActiveLayerSps[i] == NULL && pTmpLayerSps[i] != NULL) {
         pCtx->pActiveLayerSps[i] = pTmpLayerSps[i];
       }
@@ -1521,21 +1524,22 @@
     }
   } else {
     // UpdateActiveLayerSps if new sequence start
-    memcpy(&pCtx->pActiveLayerSps[0], &pTmpLayerSps[0], MAX_LAYER_NUM * sizeof(PSps));
+    memcpy (&pCtx->pActiveLayerSps[0], &pTmpLayerSps[0], MAX_LAYER_NUM * sizeof (PSps));
   }
   return bNewSeq;
 }
 
-static void WriteBackActiveParameters(PWelsDecoderContext pCtx) {
+static void WriteBackActiveParameters (PWelsDecoderContext pCtx) {
   if (pCtx->iOverwriteFlags & OVERWRITE_PPS) {
-    memcpy(&pCtx->sPpsBuffer[pCtx->sPpsBuffer[MAX_PPS_COUNT].iPpsId], &pCtx->sPpsBuffer[MAX_PPS_COUNT], sizeof(SPps));
+    memcpy (&pCtx->sPpsBuffer[pCtx->sPpsBuffer[MAX_PPS_COUNT].iPpsId], &pCtx->sPpsBuffer[MAX_PPS_COUNT], sizeof (SPps));
   }
   if (pCtx->iOverwriteFlags & OVERWRITE_SPS) {
-    memcpy(&pCtx->sSpsBuffer[pCtx->sSpsBuffer[MAX_SPS_COUNT].iSpsId], &pCtx->sSpsBuffer[MAX_SPS_COUNT], sizeof(SSps));
+    memcpy (&pCtx->sSpsBuffer[pCtx->sSpsBuffer[MAX_SPS_COUNT].iSpsId], &pCtx->sSpsBuffer[MAX_SPS_COUNT], sizeof (SSps));
     pCtx->bNewSeqBegin = true;
   }
   if (pCtx->iOverwriteFlags & OVERWRITE_SUBSETSPS) {
-    memcpy(&pCtx->sSubsetSpsBuffer[pCtx->sSubsetSpsBuffer[MAX_SPS_COUNT].sSps.iSpsId], &pCtx->sSubsetSpsBuffer[MAX_SPS_COUNT], sizeof(SSubsetSps));
+    memcpy (&pCtx->sSubsetSpsBuffer[pCtx->sSubsetSpsBuffer[MAX_SPS_COUNT].sSps.iSpsId],
+            &pCtx->sSubsetSpsBuffer[MAX_SPS_COUNT], sizeof (SSubsetSps));
     pCtx->bNewSeqBegin = true;
   }
   pCtx->iOverwriteFlags = OVERWRITE_NONE;
@@ -1561,7 +1565,7 @@
 
   pCtx->bAuReadyFlag = false;
   pCtx->bLastHasMmco5 = false;
-  bool bTmpNewSeqBegin = CheckNewSeqBeginAndUpdateActiveLayerSps(pCtx);
+  bool bTmpNewSeqBegin = CheckNewSeqBeginAndUpdateActiveLayerSps (pCtx);
   pCtx->bNewSeqBegin = pCtx->bNewSeqBegin || bTmpNewSeqBegin;
   iErr = WelsDecodeAccessUnitStart (pCtx);
   GetVclNalTemporalId (pCtx);
@@ -1595,11 +1599,11 @@
   ImplementErrorCon (pCtx);
 
   pCtx->bNewSeqBegin = false;
-  WriteBackActiveParameters(pCtx);
+  WriteBackActiveParameters (pCtx);
   pCtx->bNewSeqBegin = pCtx->bNewSeqBegin || pCtx->bNextNewSeqBegin;
   pCtx->bNextNewSeqBegin = false; // reset it
   if (pCtx->bNewSeqBegin)
-    ResetActiveSPSForEachLayer(pCtx);
+    ResetActiveSPSForEachLayer (pCtx);
   if (ERR_NONE != iErr) {
     WelsLog (pCtx, WELS_LOG_INFO, "returned error from decoding:[0x%x]\n", iErr);
     return iErr;
@@ -1932,7 +1936,7 @@
       }
     }
 
-   // need update frame_num due current frame is well decoded
+    // need update frame_num due current frame is well decoded
     pCtx->iPrevFrameNum	= pSh->iFrameNum;
     if (pCtx->bLastHasMmco5)
       pCtx->iPrevFrameNum = 0;
--- a/codec/decoder/core/src/expand_pic.cpp
+++ b/codec/decoder/core/src/expand_pic.cpp
@@ -38,7 +38,7 @@
 
 // rewrite it (split into luma & chroma) that is helpful for mmx/sse2 optimization perform, 9/27/2009
 static inline void ExpandPictureLuma_c (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicWidth,
-    const int32_t kiPicHeight) {
+                                        const int32_t kiPicHeight) {
   uint8_t* pTmp				= pDst;
   uint8_t* pDstLastLine		= pTmp + (kiPicHeight - 1) * kiStride;
   const int32_t kiPaddingLen	= PADDING_LENGTH;
--- a/codec/decoder/core/src/fmo.cpp
+++ b/codec/decoder/core/src/fmo.cpp
@@ -239,7 +239,7 @@
  * \return	true - changed or not initialized yet; false - not change at all
  */
 bool FmoParamSetsChanged (PFmo pFmo, const int32_t kiCountNumMb, const int32_t kiSliceGroupType,
-                            const int32_t kiSliceGroupCount) {
+                          const int32_t kiSliceGroupCount) {
   WELS_VERIFY_RETURN_IF (false, (NULL == pFmo))
 
   return ((!pFmo->bActiveFlag)
--- a/codec/decoder/core/src/manage_dec_ref.cpp
+++ b/codec/decoder/core/src/manage_dec_ref.cpp
@@ -110,7 +110,8 @@
 int32_t WelsInitRefList (PWelsDecoderContext pCtx, int32_t iPoc) {
   int32_t i, iCount = 0;
 
-  if ((pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] <= 0) && (pCtx->eSliceType != I_SLICE && pCtx->eSliceType != SI_SLICE)) {
+  if ((pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] <= 0) && (pCtx->eSliceType != I_SLICE
+      && pCtx->eSliceType != SI_SLICE)) {
     if (pCtx->iErrorConMethod != ERROR_CON_DISABLE) { //IDR lost!, recover it for future decoding with data all set to 0
       PPicture pRef = PrefetchPic (pCtx->pPicBuff[0]);
       if (pRef != NULL) {
@@ -281,7 +282,7 @@
   }
 
   if (!pCtx->pDec->bIsLongRef) {
-    if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX(1,pCtx->pSps->iNumRefFrames)) {
+    if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) {
       if (pCtx->iErrorConMethod != ERROR_CON_DISABLE) {
         iRet = RemainOneBufferInDpbForEC (pCtx);
       } else {
@@ -372,7 +373,7 @@
       return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX;
     }
     WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);
-    if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX(1,pCtx->pSps->iNumRefFrames)) {
+    if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) {
       return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW;
     }
 #ifdef LONG_TERM_REF
@@ -561,7 +562,8 @@
       uiLongTermFrameIdx++;
     }
   }
-  if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] >= pCtx->pSps->iNumRefFrames) { //fail to remain one empty buffer in DPB
+  if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] >=
+      pCtx->pSps->iNumRefFrames) { //fail to remain one empty buffer in DPB
     WelsLog (pCtx, WELS_LOG_WARNING, "RemainOneBufferInDpbForEC(): empty one DPB failed for EC!\n");
     iRet = ERR_INFO_REF_COUNT_OVERFLOW;
   }
--- a/codec/decoder/core/src/mv_pred.cpp
+++ b/codec/decoder/core/src/mv_pred.cpp
@@ -195,7 +195,7 @@
 
 //basic iMVs prediction unit for iMVs partition width (4, 2, 1)
 void PredMv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
-               int32_t iPartIdx, int32_t iPartWidth, int8_t iRef, int16_t iMVP[2]) {
+             int32_t iPartIdx, int32_t iPartWidth, int8_t iRef, int16_t iMVP[2]) {
   const uint8_t kuiLeftIdx	= g_kuiCache30ScanIdx[iPartIdx] - 1;
   const uint8_t kuiTopIdx		= g_kuiCache30ScanIdx[iPartIdx] - 6;
   const uint8_t kuiRightTopIdx = kuiTopIdx + iPartWidth;
@@ -242,7 +242,7 @@
   }
 }
 void PredInter8x16Mv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
-                        int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]) {
+                      int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]) {
   if (0 == iPartIdx) {
     const int8_t kiLeftRef = iRefIndex[0][6];
     if (iRef == kiLeftRef) {
@@ -265,7 +265,7 @@
   PredMv (iMotionVector, iRefIndex, iPartIdx, 2, iRef, iMVP);
 }
 void PredInter16x8Mv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
-                        int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]) {
+                      int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]) {
   if (0 == iPartIdx) {
     const int8_t kiTopRef = iRefIndex[0][1];
     if (iRef == kiTopRef) {
@@ -309,8 +309,8 @@
 //update iRefIndex and iMVs of Mb, only for P16x8
 /*need further optimization, mb_cache not work */
 void UpdateP16x8MotionInfo (PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A],
-                              int8_t iRefIndex[LIST_A][30],
-                              int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]) {
+                            int8_t iRefIndex[LIST_A][30],
+                            int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]) {
   const int16_t kiRef2 = (iRef << 8) | iRef;
   const int32_t kiMV32 = LD32 (iMVs);
   int32_t i;
@@ -339,8 +339,8 @@
 }
 //update iRefIndex and iMVs of both Mb and Mb_cache, only for P8x16
 void UpdateP8x16MotionInfo (PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A],
-                              int8_t iRefIndex[LIST_A][30],
-                              int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]) {
+                            int8_t iRefIndex[LIST_A][30],
+                            int32_t iPartIdx, int8_t iRef, int16_t iMVs[2]) {
   const int16_t kiRef2 = (iRef << 8) | iRef;
   const int32_t kiMV32 = LD32 (iMVs);
   int32_t i;
--- a/codec/decoder/core/src/parse_mb_syn_cavlc.cpp
+++ b/codec/decoder/core/src/parse_mb_syn_cavlc.cpp
@@ -650,7 +650,7 @@
       }
     } else {
       for (int j = i; j < uiTotalCoeff; j++) {
-	iRun[j] = 0;
+        iRun[j] = 0;
       }
       return iUsedBits;
     }
--- a/codec/decoder/core/src/pic_queue.cpp
+++ b/codec/decoder/core/src/pic_queue.cpp
@@ -81,17 +81,17 @@
 
   iLumaSize	= iPicWidth * iPicHeight;
   iChromaSize	= iPicChromaWidth * iPicChromaHeight;
-    pPic->pBuffer[0]	= static_cast<uint8_t*> (WelsMalloc (iLumaSize /* luma */
-                        + (iChromaSize << 1) /* Cb,Cr */, "_pic->buffer[0]"));
+  pPic->pBuffer[0]	= static_cast<uint8_t*> (WelsMalloc (iLumaSize /* luma */
+                      + (iChromaSize << 1) /* Cb,Cr */, "_pic->buffer[0]"));
 
-    WELS_VERIFY_RETURN_PROC_IF (NULL, NULL == pPic->pBuffer[0], FreePicture (pPic));
-    pPic->iLinesize[0] = iPicWidth;
-    pPic->iLinesize[1] = pPic->iLinesize[2] = iPicChromaWidth;
-    pPic->pBuffer[1]	= pPic->pBuffer[0] + iLumaSize;
-    pPic->pBuffer[2]	= pPic->pBuffer[1] + iChromaSize;
-    pPic->pData[0]	= pPic->pBuffer[0] + (1 + pPic->iLinesize[0]) * PADDING_LENGTH;
-    pPic->pData[1]	= pPic->pBuffer[1] + /*WELS_ALIGN*/ (((1 + pPic->iLinesize[1]) * PADDING_LENGTH) >> 1);
-    pPic->pData[2]	= pPic->pBuffer[2] + /*WELS_ALIGN*/ (((1 + pPic->iLinesize[2]) * PADDING_LENGTH) >> 1);
+  WELS_VERIFY_RETURN_PROC_IF (NULL, NULL == pPic->pBuffer[0], FreePicture (pPic));
+  pPic->iLinesize[0] = iPicWidth;
+  pPic->iLinesize[1] = pPic->iLinesize[2] = iPicChromaWidth;
+  pPic->pBuffer[1]	= pPic->pBuffer[0] + iLumaSize;
+  pPic->pBuffer[2]	= pPic->pBuffer[1] + iChromaSize;
+  pPic->pData[0]	= pPic->pBuffer[0] + (1 + pPic->iLinesize[0]) * PADDING_LENGTH;
+  pPic->pData[1]	= pPic->pBuffer[1] + /*WELS_ALIGN*/ (((1 + pPic->iLinesize[1]) * PADDING_LENGTH) >> 1);
+  pPic->pData[2]	= pPic->pBuffer[2] + /*WELS_ALIGN*/ (((1 + pPic->iLinesize[2]) * PADDING_LENGTH) >> 1);
 
 
 
--- a/codec/decoder/core/src/rec_mb.cpp
+++ b/codec/decoder/core/src/rec_mb.cpp
@@ -184,7 +184,7 @@
 } sMCRefMember;
 //according to current 8*8 block ref_index to gain reference picture
 static inline void GetRefPic (sMCRefMember* pMCRefMem, PWelsDecoderContext pCtx, int8_t* pRefIdxList,
-                                int32_t iIndex) {
+                              int32_t iIndex) {
   PPicture pRefPic;
 
   int8_t iRefIdx = pRefIdxList[iIndex];
@@ -203,7 +203,7 @@
 #define MC_FLOW_SIMPLE_JUDGE 1
 #endif //MC_FLOW_SIMPLE_JUDGE
 static inline void BaseMC (sMCRefMember* pMCRefMem, int32_t iXOffset, int32_t iYOffset, SMcFunc* pMCFunc,
-                             int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) {
+                           int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) {
   int32_t iExpandWidth = PADDING_LENGTH;
   int32_t	iExpandHeight = PADDING_LENGTH;
 
@@ -465,7 +465,7 @@
 }
 
 void FillBufForMc (uint8_t* pBuf, int32_t iBufStride, uint8_t* pSrc, int32_t iSrcStride, int32_t iSrcOffset,
-                     int32_t iBlockWidth, int32_t iBlockHeight, int32_t iSrcX, int32_t iSrcY, int32_t iPicWidth, int32_t iPicHeight) {
+                   int32_t iBlockWidth, int32_t iBlockHeight, int32_t iSrcX, int32_t iSrcY, int32_t iPicWidth, int32_t iPicHeight) {
   int32_t iY;
   int32_t iStartY, iStartX, iEndY, iEndX;
   int32_t iOffsetAdj = 0;
--- a/codec/decoder/plus/inc/welsCodecTrace.h
+++ b/codec/decoder/plus/inc/welsCodecTrace.h
@@ -43,112 +43,112 @@
 
 
 typedef  enum {
-Wels_Trace_Type     = 0,
-Wels_Trace_Type_File    = 1,
-Wels_Trace_Type_WinDgb  = 2,
+  Wels_Trace_Type     = 0,
+  Wels_Trace_Type_File    = 1,
+  Wels_Trace_Type_WinDgb  = 2,
 } EWelsTraceType;
 
 class  IWelsTrace {
  public:
-enum {
-  WELS_LOG_QUIET     = 0,
-  WELS_LOG_ERROR     = 1 << 0,
-  WELS_LOG_WARNING   = 1 << 1,
-  WELS_LOG_INFO      = 1 << 2,
-  WELS_LOG_DEBUG     = 1 << 3,
-  WELS_LOG_RESV      = 1 << 4,
-  WELS_LOG_DEFAULT   = WELS_LOG_ERROR | WELS_LOG_WARNING | WELS_LOG_INFO | WELS_LOG_DEBUG,
+  enum {
+    WELS_LOG_QUIET     = 0,
+    WELS_LOG_ERROR     = 1 << 0,
+    WELS_LOG_WARNING   = 1 << 1,
+    WELS_LOG_INFO      = 1 << 2,
+    WELS_LOG_DEBUG     = 1 << 3,
+    WELS_LOG_RESV      = 1 << 4,
+    WELS_LOG_DEFAULT   = WELS_LOG_ERROR | WELS_LOG_WARNING | WELS_LOG_INFO | WELS_LOG_DEBUG,
 
 
-  MAX_LOG_SIZE       = 1024,
-};
+    MAX_LOG_SIZE       = 1024,
+  };
 
-virtual ~IWelsTrace() {};
+  virtual ~IWelsTrace() {};
 
-virtual int32_t  SetTraceLevel (int32_t iLevel) = 0;
-virtual int32_t  Trace (const int32_t kLevel, const char* kpFormat,  va_list pVl) = 0;
+  virtual int32_t  SetTraceLevel (int32_t iLevel) = 0;
+  virtual int32_t  Trace (const int32_t kLevel, const char* kpFormat,  va_list pVl) = 0;
 
-static void  WelsTrace (void* pObject, const int32_t kLevel, const char* kpFormat, va_list pVl) {
-  IWelsTrace*   pThis = (IWelsTrace*) (pObject);
+  static void  WelsTrace (void* pObject, const int32_t kLevel, const char* kpFormat, va_list pVl) {
+    IWelsTrace*   pThis = (IWelsTrace*) (pObject);
 
-  if (pThis) {
-    pThis->Trace (kLevel, kpFormat, pVl);
+    if (pThis) {
+      pThis->Trace (kLevel, kpFormat, pVl);
+    }
   }
-}
 
-static void WelsVTrace (void* pObject, const int32_t kLevel, const char* kpFormat, ...) {
-  IWelsTrace* pThis = (IWelsTrace*) (pObject);
+  static void WelsVTrace (void* pObject, const int32_t kLevel, const char* kpFormat, ...) {
+    IWelsTrace* pThis = (IWelsTrace*) (pObject);
 
-  va_list  argptr;
+    va_list  argptr;
 
-  va_start (argptr, kpFormat);
+    va_start (argptr, kpFormat);
 
-  if (pThis) {
-    pThis->Trace (kLevel, kpFormat, argptr);
+    if (pThis) {
+      pThis->Trace (kLevel, kpFormat, argptr);
+    }
+
+    va_end (argptr);
   }
 
-  va_end (argptr);
-}
 
-
 };
 
 class CWelsTraceBase : public IWelsTrace {
  public:
-virtual int32_t  SetTraceLevel (int32_t iLevel);
-virtual int32_t  Trace (const int32_t kLevel, const char* kpFormat,  va_list pVl);
+  virtual int32_t  SetTraceLevel (int32_t iLevel);
+  virtual int32_t  Trace (const int32_t kLevel, const char* kpFormat,  va_list pVl);
 
-virtual int32_t  WriteString (int32_t iLevel, const char* pStr) = 0;
+  virtual int32_t  WriteString (int32_t iLevel, const char* pStr) = 0;
  protected:
-CWelsTraceBase() {
-  m_iLevel = WELS_LOG_DEFAULT;
-};
+  CWelsTraceBase() {
+    m_iLevel = WELS_LOG_DEFAULT;
+  };
 
  private:
-int32_t   m_iLevel;
+  int32_t   m_iLevel;
 };
 
 class CWelsTraceFile : public CWelsTraceBase {
  public:
-CWelsTraceFile (const char*   filename = (const char*)"wels_decoder_trace.txt");
-virtual ~CWelsTraceFile();
+  CWelsTraceFile (const char*   filename = (const char*)"wels_decoder_trace.txt");
+  virtual ~CWelsTraceFile();
 
  public:
-virtual int32_t  WriteString (int32_t iLevel, const char* pStr);
+  virtual int32_t  WriteString (int32_t iLevel, const char* pStr);
 
  private:
-WelsFileHandle* m_pTraceFile;
+  WelsFileHandle* m_pTraceFile;
 };
 
 #ifdef  _WIN32
 class CWelsTraceWinDgb : public CWelsTraceBase {
  public:
-CWelsTraceWinDgb() {};
-virtual ~CWelsTraceWinDgb() {};
+  CWelsTraceWinDgb() {};
+  virtual ~CWelsTraceWinDgb() {};
 
  public:
-virtual int32_t  WriteString (int32_t iLevel, const char* pStr);
+  virtual int32_t  WriteString (int32_t iLevel, const char* pStr);
 };
 #endif
 
 class CWelsCodecTrace : public CWelsTraceBase {
  public:
-CWelsCodecTrace() ;
-virtual ~CWelsCodecTrace();
+  CWelsCodecTrace() ;
+  virtual ~CWelsCodecTrace();
 
  public:
-virtual int32_t  WriteString (int32_t iLevel, const char* pStr);
+  virtual int32_t  WriteString (int32_t iLevel, const char* pStr);
 
  protected:
-int32_t  LoadWelsTraceModule();
-int32_t  UnloadWelsTraceModule();
+  int32_t  LoadWelsTraceModule();
+  int32_t  UnloadWelsTraceModule();
 
  private:
 
-CM_WELS_TRACE m_fpDebugTrace;
-CM_WELS_TRACE m_fpInfoTrace;
-CM_WELS_TRACE m_fpWarnTrace;
-CM_WELS_TRACE m_fpErrorTrace;
+  CM_WELS_TRACE m_fpDebugTrace;
+  CM_WELS_TRACE m_fpInfoTrace;
+  CM_WELS_TRACE m_fpWarnTrace;
+  CM_WELS_TRACE m_fpErrorTrace;
 };
 
 
--- a/codec/decoder/plus/inc/welsDecoderExt.h
+++ b/codec/decoder/plus/inc/welsDecoderExt.h
@@ -56,57 +56,57 @@
 
 class CWelsDecoder : public ISVCDecoder {
  public:
-CWelsDecoder (void);
-virtual ~CWelsDecoder();
+  CWelsDecoder (void);
+  virtual ~CWelsDecoder();
 
-virtual long EXTAPI Initialize (const SDecodingParam* pParam);
-virtual long EXTAPI Uninitialize();
+  virtual long EXTAPI Initialize (const SDecodingParam* pParam);
+  virtual long EXTAPI Uninitialize();
 
-/***************************************************************************
-*	Description:
-*		Decompress one frame, and output RGB24 or YV12 decoded stream and its length.
-*	Input parameters:
-*       Parameter		TYPE			       Description
-*       pSrc             unsigned char*         the h264 stream to decode
-*       srcLength       int                    the length of h264 steam
-*       pDst             unsigned char*         buffer pointer of decoded data
-*       pDstInfo        SBufferInfo&           information provided to API including width, height, SW/HW option, etc
-*
-*	return: if decode frame success return 0, otherwise corresponding error returned.
-***************************************************************************/
-virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* kpSrc,
-                                           const int kiSrcLen,
-                                           unsigned char** ppDst,
-                                           int* pStride,
-                                           int& iWidth,
-                                           int& iHeight);
+  /***************************************************************************
+  *	Description:
+  *		Decompress one frame, and output RGB24 or YV12 decoded stream and its length.
+  *	Input parameters:
+  *       Parameter		TYPE			       Description
+  *       pSrc             unsigned char*         the h264 stream to decode
+  *       srcLength       int                    the length of h264 steam
+  *       pDst             unsigned char*         buffer pointer of decoded data
+  *       pDstInfo        SBufferInfo&           information provided to API including width, height, SW/HW option, etc
+  *
+  *	return: if decode frame success return 0, otherwise corresponding error returned.
+  ***************************************************************************/
+  virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* kpSrc,
+      const int kiSrcLen,
+      unsigned char** ppDst,
+      int* pStride,
+      int& iWidth,
+      int& iHeight);
 
-virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* kpSrc,
-                                            const int kiSrcLen,
-                                            void** ppDst,
-                                            SBufferInfo* pDstInfo);
-virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* kpSrc,
-                                             const int kiSrcLen,
-                                             unsigned char* pDst,
-                                             int iDstStride,
-                                             int& iDstLen,
-                                             int& iWidth,
-                                             int& iHeight,
-                                             int& color_format);
+  virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* kpSrc,
+      const int kiSrcLen,
+      void** ppDst,
+      SBufferInfo* pDstInfo);
+  virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* kpSrc,
+      const int kiSrcLen,
+      unsigned char* pDst,
+      int iDstStride,
+      int& iDstLen,
+      int& iWidth,
+      int& iHeight,
+      int& color_format);
 
-virtual long EXTAPI SetOption (DECODER_OPTION eOptID, void* pOption);
-virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption);
+  virtual long EXTAPI SetOption (DECODER_OPTION eOptID, void* pOption);
+  virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption);
 
  private:
-PWelsDecoderContext 				m_pDecContext;
-IWelsTrace*							m_pTrace;
+  PWelsDecoderContext 				m_pDecContext;
+  IWelsTrace*							m_pTrace;
 
-void InitDecoder (void);
-void UninitDecoder (void);
+  void InitDecoder (void);
+  void UninitDecoder (void);
 
 #ifdef OUTPUT_BIT_STREAM
-WelsFileHandle* m_pFBS;
-WelsFileHandle* m_pFBSSize;
+  WelsFileHandle* m_pFBS;
+  WelsFileHandle* m_pFBSSize;
 #endif//OUTPUT_BIT_STREAM
 
 };
--- a/codec/decoder/plus/src/welsDecoderExt.cpp
+++ b/codec/decoder/plus/src/welsDecoderExt.cpp
@@ -325,8 +325,8 @@
   if (kiSrcLen > MAX_ACCESS_UNIT_CAPACITY - MAX_MACROBLOCK_CAPACITY) {//prevent from residual reading overflow
     m_pDecContext->iErrorCode |= dsOutOfMemory;
     IWelsTrace::WelsVTrace (m_pTrace, IWelsTrace::WELS_LOG_INFO,
-      "max AU size exceeded. Allowed size = %d, current size = %d",
-      MAX_ACCESS_UNIT_CAPACITY, kiSrcLen);
+                            "max AU size exceeded. Allowed size = %d, current size = %d",
+                            MAX_ACCESS_UNIT_CAPACITY, kiSrcLen);
     return dsOutOfMemory;
   }
   if (kiSrcLen > 0 && kpSrc != NULL) {
--- a/codec/encoder/core/inc/deblocking.h
+++ b/codec/encoder/core/inc/deblocking.h
@@ -50,15 +50,15 @@
 //struct tagDeblockingFunc;
 
 typedef struct TagDeblockingFilter {
-uint8_t*		pCsData[3];	// pointer to reconstructed picture pData
-int32_t		iCsStride[3];	// Cs iStride
-int16_t     iMbStride;
-int8_t		iSliceAlphaC0Offset;
-int8_t		iSliceBetaOffset;
-uint8_t     uiLumaQP;
-uint8_t     uiChromaQP;
-uint8_t     uiFilterIdc;
-uint8_t     uiReserved;
+  uint8_t*		pCsData[3];	// pointer to reconstructed picture pData
+  int32_t		iCsStride[3];	// Cs iStride
+  int16_t     iMbStride;
+  int8_t		iSliceAlphaC0Offset;
+  int8_t		iSliceBetaOffset;
+  uint8_t     uiLumaQP;
+  uint8_t     uiChromaQP;
+  uint8_t     uiFilterIdc;
+  uint8_t     uiReserved;
 } SDeblockingFilter;
 
 #if defined(__cplusplus)
@@ -65,8 +65,9 @@
 extern "C" {
 #endif//__cplusplus
 #if defined(HAVE_NEON)
-void WelsNonZeroCount_neon(int8_t * pNonZeroCount);
-void DeblockingBSCalcEnc_neon(int8_t *pNzc, SMVUnitXY *pMv, int32_t iBoundryFlag, int32_t iMbStride, uint8_t (*pBS)[4][4]);
+void WelsNonZeroCount_neon (int8_t* pNonZeroCount);
+void DeblockingBSCalcEnc_neon (int8_t* pNzc, SMVUnitXY* pMv, int32_t iBoundryFlag, int32_t iMbStride,
+                               uint8_t (*pBS)[4][4]);
 #endif
 #if defined(__cplusplus)
 }
--- a/codec/encoder/core/inc/decode_mb_aux.h
+++ b/codec/encoder/core/inc/decode_mb_aux.h
@@ -71,13 +71,14 @@
 #endif//X86_ASM
 
 #ifdef	HAVE_NEON
-void WelsDequantFour4x4_neon(int16_t* pDct, const uint16_t* kpMF);
-void WelsDequant4x4_neon(int16_t* pDct, const uint16_t* kpMF);
-void WelsDequantIHadamard4x4_neon(int16_t* pRes, const uint16_t kuiMF);
+void WelsDequantFour4x4_neon (int16_t* pDct, const uint16_t* kpMF);
+void WelsDequant4x4_neon (int16_t* pDct, const uint16_t* kpMF);
+void WelsDequantIHadamard4x4_neon (int16_t* pRes, const uint16_t kuiMF);
 
-void WelsIDctT4Rec_neon(uint8_t* pRec, int32_t iStride, uint8_t* pPrediction, int32_t iPredStride, int16_t* pDct);
-void WelsIDctFourT4Rec_neon(uint8_t* pRec, int32_t iStride, uint8_t* pPrediction, int32_t iPredStride, int16_t* pDct);
-void WelsIDctRecI16x16Dc_neon(uint8_t* pRec, int32_t iStride, uint8_t* pPrediction, int32_t iPredStride, int16_t* pDctDc);
+void WelsIDctT4Rec_neon (uint8_t* pRec, int32_t iStride, uint8_t* pPrediction, int32_t iPredStride, int16_t* pDct);
+void WelsIDctFourT4Rec_neon (uint8_t* pRec, int32_t iStride, uint8_t* pPrediction, int32_t iPredStride, int16_t* pDct);
+void WelsIDctRecI16x16Dc_neon (uint8_t* pRec, int32_t iStride, uint8_t* pPrediction, int32_t iPredStride,
+                               int16_t* pDctDc);
 #endif
 
 #if defined(__cplusplus)
--- a/codec/encoder/core/inc/encode_mb_aux.h
+++ b/codec/encoder/core/inc/encode_mb_aux.h
@@ -106,20 +106,20 @@
 #endif
 
 #ifdef	HAVE_NEON
-void WelsHadamardT4Dc_neon(int16_t* pLumaDc, int16_t* pDct);
-int32_t WelsHadamardQuant2x2_neon(int16_t* pRes, const int16_t kiFF, int16_t iMF, int16_t* pDct, int16_t* pBlock);
-int32_t WelsHadamardQuant2x2Skip_neon(int16_t* pRes, int16_t iFF,  int16_t iMF);
-int32_t WelsHadamardQuant2x2SkipKernel_neon(int16_t *pRes, int16_t iThreshold);// avoid divide operator
+void WelsHadamardT4Dc_neon (int16_t* pLumaDc, int16_t* pDct);
+int32_t WelsHadamardQuant2x2_neon (int16_t* pRes, const int16_t kiFF, int16_t iMF, int16_t* pDct, int16_t* pBlock);
+int32_t WelsHadamardQuant2x2Skip_neon (int16_t* pRes, int16_t iFF,  int16_t iMF);
+int32_t WelsHadamardQuant2x2SkipKernel_neon (int16_t* pRes, int16_t iThreshold); // avoid divide operator
 
-void WelsDctT4_neon(int16_t* pDct,  uint8_t* pPixel1, int32_t iStride1, uint8_t* pPixel2, int32_t iStride2);
-void WelsDctFourT4_neon(int16_t* pDct,  uint8_t* pPixel1, int32_t iStride1, uint8_t* pPixel2, int32_t iStride2);
+void WelsDctT4_neon (int16_t* pDct,  uint8_t* pPixel1, int32_t iStride1, uint8_t* pPixel2, int32_t iStride2);
+void WelsDctFourT4_neon (int16_t* pDct,  uint8_t* pPixel1, int32_t iStride1, uint8_t* pPixel2, int32_t iStride2);
 
-int32_t WelsGetNoneZeroCount_neon(int16_t* pLevel);
+int32_t WelsGetNoneZeroCount_neon (int16_t* pLevel);
 
-void WelsQuant4x4_neon(int16_t* pDct, const int16_t* pFF, const int16_t* pMF);
-void WelsQuant4x4Dc_neon(int16_t* pDct, int16_t iFF, int16_t iMF);
-void WelsQuantFour4x4_neon(int16_t* pDct, const int16_t* pFF, const int16_t* pMF);
-void WelsQuantFour4x4Max_neon(int16_t* pDct, const int16_t* pFF, const int16_t* pMF, int16_t* pMax);
+void WelsQuant4x4_neon (int16_t* pDct, const int16_t* pFF, const int16_t* pMF);
+void WelsQuant4x4Dc_neon (int16_t* pDct, int16_t iFF, int16_t iMF);
+void WelsQuantFour4x4_neon (int16_t* pDct, const int16_t* pFF, const int16_t* pMF);
+void WelsQuantFour4x4Max_neon (int16_t* pDct, const int16_t* pFF, const int16_t* pMF, int16_t* pMax);
 #endif
 
 #if defined(__cplusplus)
--- a/codec/encoder/core/inc/encoder.h
+++ b/codec/encoder/core/inc/encoder.h
@@ -61,7 +61,8 @@
  * \brief	 allocate or reallocate the output bs buffer
  * \return:		successful - 0; otherwise none 0 for failed
  */
-int32_t AllocateBsOutputBuffer(CMemoryAlign*pMa, const int32_t iNeededLen, int32_t iOrigLen, const char* kpTag, uint8_t*& pOutputBuffer );
+int32_t AllocateBsOutputBuffer (CMemoryAlign* pMa, const int32_t iNeededLen, int32_t iOrigLen, const char* kpTag,
+                                uint8_t*& pOutputBuffer);
 //TODO: to finish this function and call it
 
 /*!
@@ -127,7 +128,7 @@
 void WelsSetMemZeroSize8_mmx (void* pDst, int32_t iSize);
 void WelsPrefetchZero_mmx (int8_t const* kpDst);
 #elif defined(HAVE_NEON)
-void WelsSetMemZero_neon(void* pDst, int32_t iSize);
+void WelsSetMemZero_neon (void* pDst, int32_t iSize);
 #endif
 
 #if defined(__cplusplus)
--- a/codec/encoder/core/inc/extern.h
+++ b/codec/encoder/core/inc/extern.h
@@ -64,7 +64,7 @@
  * \pParam	pParam		SWelsSvcCodingParam*
  * \return	successful - 0; otherwise none 0 for failed
  */
-int32_t ParamValidationExt (sWelsEncCtx* pCtx,SWelsSvcCodingParam* pParam);
+int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam);
 
 // GOM based RC related for uiSliceNum decision
 void GomValidCheck (const int32_t kiMbWidth, const int32_t kiMbHeight, int32_t* pSliceNum);
@@ -92,7 +92,7 @@
  * \param	kpSrcPic		Source picture
  * \return	EFrameType (videoFrameTypeIDR/videoFrameTypeI/videoFrameTypeP)
  */
-int32_t WelsEncoderEncodeExt (sWelsEncCtx*, SFrameBSInfo * pFbi, const SSourcePicture* kpSrcPic);
+int32_t WelsEncoderEncodeExt (sWelsEncCtx*, SFrameBSInfo* pFbi, const SSourcePicture* kpSrcPic);
 
 int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst);
 
@@ -107,7 +107,7 @@
  */
 int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNew);
 void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam);
-void WelsEncoderApplyBitRate(SWelsSvcCodingParam* pParam,int32_t iLayer);
+void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int32_t iLayer);
 
 int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest);
 
--- a/codec/encoder/core/inc/get_intra_predictor.h
+++ b/codec/encoder/core/inc/get_intra_predictor.h
@@ -116,24 +116,24 @@
 #endif//X86_ASM
 
 #if defined(HAVE_NEON)
-void WelsI16x16LumaPredV_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI16x16LumaPredH_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI16x16LumaPredDc_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI16x16LumaPredPlane_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI16x16LumaPredV_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI16x16LumaPredH_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI16x16LumaPredDc_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI16x16LumaPredPlane_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
 
-void WelsI4x4LumaPredV_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI4x4LumaPredH_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI4x4LumaPredDDL_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI4x4LumaPredDDR_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI4x4LumaPredVL_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI4x4LumaPredVR_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI4x4LumaPredHU_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsI4x4LumaPredHD_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI4x4LumaPredV_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI4x4LumaPredH_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI4x4LumaPredDDL_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI4x4LumaPredDDR_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI4x4LumaPredVL_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI4x4LumaPredVR_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI4x4LumaPredHU_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsI4x4LumaPredHD_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
 
-void WelsIChromaPredV_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsIChromaPredH_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsIChromaPredDc_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
-void WelsIChromaPredPlane_neon(uint8_t *pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsIChromaPredV_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsIChromaPredH_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsIChromaPredDc_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
+void WelsIChromaPredPlane_neon (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
 #endif//HAVE_NEON
 #if defined(__cplusplus)
 }
--- a/codec/encoder/core/inc/mb_cache.h
+++ b/codec/encoder/core/inc/mb_cache.h
@@ -65,79 +65,79 @@
 
 typedef	struct TagDCTCoeff {
 //ALIGNED_DECLARE( int16_t, residual_ac[16], 16 ); //I_16x16
-int16_t iLumaBlock[16][16]; //based on block4x4 luma DC/AC
+  int16_t iLumaBlock[16][16]; //based on block4x4 luma DC/AC
 //ALIGNED_DECLARE( int16_t, iLumaI16x16Dc[16], 16 ); //I_16x16 DC
-int16_t iLumaI16x16Dc[16];
+  int16_t iLumaI16x16Dc[16];
 //ALIGNED_DECLARE( int16_t, iChromaDc[2][4], 16 ); //chroma DC
-int16_t iChromaBlock[8][16]; //based on block4x4  chroma DC/AC
-int16_t iChromaDc[2][4];
+  int16_t iChromaBlock[8][16]; //based on block4x4  chroma DC/AC
+  int16_t iChromaDc[2][4];
 } SDCTCoeff ;
 
 typedef struct TagMbCache {
 //the followed pData now is promised aligned to 16 bytes
-ALIGNED_DECLARE (SMVComponentUnit, sMvComponents, 16);
+  ALIGNED_DECLARE (SMVComponentUnit, sMvComponents, 16);
 
-ALIGNED_DECLARE_MATRIX_1D (iNonZeroCoeffCount, 48, int8_t, 16);	// Cache line size
+  ALIGNED_DECLARE_MATRIX_1D (iNonZeroCoeffCount, 48, int8_t, 16);	// Cache line size
 // 	int8_t		iNonZeroCoeffCount[6 * 8];	// Right luma, Chroma(Left Top Cb, Left btm Cr); must follow by iIntraPredMode!
-ALIGNED_DECLARE_MATRIX_1D (iIntraPredMode, 48, int8_t, 16);
+  ALIGNED_DECLARE_MATRIX_1D (iIntraPredMode, 48, int8_t, 16);
 //	must follow with iNonZeroCoeffCount!
 
-int32_t     iSadCost[4];			//avail 1; unavail 0
-SMVUnitXY  sMbMvp[MB_BLOCK8x8_NUM];// for write bs
+  int32_t     iSadCost[4];			//avail 1; unavail 0
+  SMVUnitXY  sMbMvp[MB_BLOCK8x8_NUM];// for write bs
 
 //for residual decoding (recovery) at the side of Encoder
-int16_t* pCoeffLevel;		// tmep
+  int16_t* pCoeffLevel;		// tmep
 //malloc memory for prediction
-uint8_t* pSkipMb;
+  uint8_t* pSkipMb;
 
 //ALIGNED_DECLARE(uint8_t, pMemPredMb[2][256],  16);//One: Best I_16x16 Luma and refine frac_pixel pBuffer; another: PingPong I_8x8&&Inter Cb + Cr
-uint8_t* pMemPredMb;
-uint8_t* pMemPredLuma;// inter && intra share same pointer;
+  uint8_t* pMemPredMb;
+  uint8_t* pMemPredLuma;// inter && intra share same pointer;
 //ALIGNED_DECLARE(uint8_t, pMemPredChroma[2][64*2], 16); //another PingPong pBuffer: Best Cb + Cr;
-uint8_t* pMemPredChroma;// inter && intra share same pointer;
-uint8_t* pBestPredIntraChroma; //Cb:0~63;   Cr:64~127
+  uint8_t* pMemPredChroma;// inter && intra share same pointer;
+  uint8_t* pBestPredIntraChroma; //Cb:0~63;   Cr:64~127
 
 //ALIGNED_DECLARE(uint8_t, pMemPredBlk4[2][16], 16); //I_4x4
-uint8_t* pMemPredBlk4;
+  uint8_t* pMemPredBlk4;
 
-uint8_t* pBestPredI4x4Blk4;//I_4x4
+  uint8_t* pBestPredI4x4Blk4;//I_4x4
 
 //ALIGNED_DECLARE(uint8_t, pBufferInterPredMe[4][400], 16);//inter type pBuffer for ME h & v & hv
-uint8_t* pBufferInterPredMe;    // [4][400] is enough because only h&v or v&hv or h&hv. but if both h&v&hv is needed when 8 quart pixel, future we have to use [5][400].
+  uint8_t* pBufferInterPredMe;    // [4][400] is enough because only h&v or v&hv or h&hv. but if both h&v&hv is needed when 8 quart pixel, future we have to use [5][400].
 
 //no scan4[] order, just as memory order to store
 //ALIGNED_DECLARE(bool, pPrevIntra4x4PredModeFlag[16], 16);//if 1, means no rem_intra4x4_pred_mode; if 0, means rem_intra4x4_pred_mode != 0
-bool* pPrevIntra4x4PredModeFlag;
+  bool* pPrevIntra4x4PredModeFlag;
 //ALIGNED_DECLARE(int8_t, pRemIntra4x4PredModeFlag[16], 16);//-1 as default; if pPrevIntra4x4PredModeFlag==0,
 //pRemIntra4x4PredModeFlag or added by 1 is the best pred_mode
-int8_t* pRemIntra4x4PredModeFlag;
+  int8_t* pRemIntra4x4PredModeFlag;
 
-int32_t     iSadCostSkip[4];	     //avail 1; unavail 0
-bool      bMbTypeSkip[4];         //1: skip; 0: non-skip
-int32_t*     pEncSad;
+  int32_t     iSadCostSkip[4];	     //avail 1; unavail 0
+  bool      bMbTypeSkip[4];         //1: skip; 0: non-skip
+  int32_t*     pEncSad;
 
 //for residual encoding at the side of Encoder
-SDCTCoeff* pDct;
+  SDCTCoeff* pDct;
 
-uint8_t      uiNeighborIntra; // LEFT_MB_POS:0x01, TOP_MB_POS:0x02, TOPLEFT_MB_POS = 0x04 ,TOPRIGHT_MB_POS = 0x08;
-uint8_t uiLumaI16x16Mode;
-uint8_t uiChmaI8x8Mode;
+  uint8_t      uiNeighborIntra; // LEFT_MB_POS:0x01, TOP_MB_POS:0x02, TOPLEFT_MB_POS = 0x04 ,TOPRIGHT_MB_POS = 0x08;
+  uint8_t uiLumaI16x16Mode;
+  uint8_t uiChmaI8x8Mode;
 
-bool		bCollocatedPredFlag;//denote if current MB is collocated predicted (MV==0).
-uint32_t	uiRefMbType;
+  bool		bCollocatedPredFlag;//denote if current MB is collocated predicted (MV==0).
+  uint32_t	uiRefMbType;
 
-struct {
-  /* pointer of current mb location in original frame */
-  uint8_t* pEncMb[3];
-  /* pointer of current mb location in recovery frame */
-  uint8_t* pDecMb[3];
-  /* pointer of co-located mb location in reference frame */
-  uint8_t* pRefMb[3];
-  //for SVC
-  uint8_t*	pCsMb[3];//locating current mb's CS in whole frame
+  struct {
+    /* pointer of current mb location in original frame */
+    uint8_t* pEncMb[3];
+    /* pointer of current mb location in recovery frame */
+    uint8_t* pDecMb[3];
+    /* pointer of co-located mb location in reference frame */
+    uint8_t* pRefMb[3];
+    //for SVC
+    uint8_t*	pCsMb[3];//locating current mb's CS in whole frame
 //		int16_t *p_rs[3];//locating current mb's RS	in whole frame
 
-} SPicData;
+  } SPicData;
 } SMbCache;
 
 }//end of namespace
--- a/codec/encoder/core/inc/md.h
+++ b/codec/encoder/core/inc/md.h
@@ -75,43 +75,43 @@
 
 // if we want keep total sizeof(SWelsMD) <= 256, we maybe need to seperate three member of SWelsME.
 typedef struct TagWelsMD {
-int32_t			iLambda;
-uint16_t*		pMvdCost;
+  int32_t			iLambda;
+  uint16_t*		pMvdCost;
 
-int32_t			iCostLuma;
-int32_t			iCostChroma;//satd+lambda(best_pred_mode) //i_sad_chroma;
-int32_t			iSadPredMb;
+  int32_t			iCostLuma;
+  int32_t			iCostChroma;//satd+lambda(best_pred_mode) //i_sad_chroma;
+  int32_t			iSadPredMb;
 
-uint8_t			uiRef; //uiRefIndex appointed by Encoder, used for MC
-bool			bMdUsingSad;
-uint16_t		uiReserved;
+  uint8_t			uiRef; //uiRefIndex appointed by Encoder, used for MC
+  bool			bMdUsingSad;
+  uint16_t		uiReserved;
 
-int32_t			iCostSkipMb;
-int32_t			iSadPredSkip;
+  int32_t			iCostSkipMb;
+  int32_t			iSadPredSkip;
 
-int32_t			iMbPixX;		// pixel position of MB in horizontal axis
-int32_t			iMbPixY;		// pixel position of MB in vertical axis
-int32_t			iBlock8x8StaticIdc[4];
+  int32_t			iMbPixX;		// pixel position of MB in horizontal axis
+  int32_t			iMbPixY;		// pixel position of MB in vertical axis
+  int32_t			iBlock8x8StaticIdc[4];
 
 //NO B frame in our Wels, we can ignore list1
 
-struct {
-  SWelsME			sMe16x16;		//adjust each SWelsME for 8 D-word!
-  SWelsME			sMe8x8[4];
-  SWelsME			sMe16x8[2];
-  SWelsME			sMe8x16[2];
+  struct {
+    SWelsME			sMe16x16;		//adjust each SWelsME for 8 D-word!
+    SWelsME			sMe8x8[4];
+    SWelsME			sMe16x8[2];
+    SWelsME			sMe8x16[2];
 //		SMVUnitXY		i_mvbs[MB_BLOCK8x8_NUM];	//scaled MVB
-} sMe;
+  } sMe;
 
 } SWelsMD;
 
 typedef struct TagMeRefinePointer {
-uint8_t* pHalfPixH;
-uint8_t* pHalfPixV;
-uint8_t* pHalfPixHV;
+  uint8_t* pHalfPixH;
+  uint8_t* pHalfPixV;
+  uint8_t* pHalfPixHV;
 
-uint8_t* pQuarPixBest;
-uint8_t* pQuarPixTmp;
+  uint8_t* pQuarPixBest;
+  uint8_t* pQuarPixTmp;
 
 } SMeRefinePointer;
 
--- a/codec/encoder/core/inc/memory_align.h
+++ b/codec/encoder/core/inc/memory_align.h
@@ -43,30 +43,30 @@
 
 class CMemoryAlign {
  public:
-CMemoryAlign (const uint32_t kuiCacheLineSize);
-virtual ~CMemoryAlign();
+  CMemoryAlign (const uint32_t kuiCacheLineSize);
+  virtual ~CMemoryAlign();
 
-void* WelsMallocz (const uint32_t kuiSize, const char* kpTag);
-void* WelsMalloc (const uint32_t kuiSize, const char* kpTag);
-void WelsFree (void* pPointer, const char* kpTag);
-const uint32_t WelsGetCacheLineSize() const;
-const uint32_t WelsGetMemoryUsage() const;
+  void* WelsMallocz (const uint32_t kuiSize, const char* kpTag);
+  void* WelsMalloc (const uint32_t kuiSize, const char* kpTag);
+  void WelsFree (void* pPointer, const char* kpTag);
+  const uint32_t WelsGetCacheLineSize() const;
+  const uint32_t WelsGetMemoryUsage() const;
 
  private:
 // private copy & assign constructors adding to fix klocwork scan issues
-CMemoryAlign (const CMemoryAlign& kcMa);
-CMemoryAlign& operator= (const CMemoryAlign& kcMa);
+  CMemoryAlign (const CMemoryAlign& kcMa);
+  CMemoryAlign& operator= (const CMemoryAlign& kcMa);
 
  protected:
-uint32_t	m_nCacheLineSize;
+  uint32_t	m_nCacheLineSize;
 
 #ifdef MEMORY_MONITOR
-uint32_t	m_nMemoryUsageInBytes;
+  uint32_t	m_nMemoryUsageInBytes;
 #endif//MEMORY_MONITOR
 
 #ifdef MEMORY_CHECK
-FILE*		m_fpMemChkPoint;
-uint32_t	m_nCountRequestNum;
+  FILE*		m_fpMemChkPoint;
+  uint32_t	m_nCountRequestNum;
 #endif//MEMORY_CHECK
 };
 
--- a/codec/encoder/core/inc/mt_defs.h
+++ b/codec/encoder/core/inc/mt_defs.h
@@ -59,35 +59,36 @@
 #define THRESHOLD_RMSE_CORE2	0.0200f	// v1.1: 0.0200f; v1.0: 0.04f
 
 typedef struct TagSliceThreadPrivateData {
-void*		pWelsPEncCtx;
-SLayerBSInfo*	pLayerBs;
-int32_t		iSliceIndex;	// slice index, zero based
-int32_t		iThreadIndex;	// thread index, zero based
+  void*		pWelsPEncCtx;
+  SLayerBSInfo*	pLayerBs;
+  int32_t		iSliceIndex;	// slice index, zero based
+  int32_t		iThreadIndex;	// thread index, zero based
 
 // for dynamic slicing mode
-int32_t		iStartMbIndex;	// inclusive
-int32_t		iEndMbIndex;	// exclusive
+  int32_t		iStartMbIndex;	// inclusive
+  int32_t		iEndMbIndex;	// exclusive
 } SSliceThreadPrivateData;
 
 typedef struct TagSliceThreading {
-SSliceThreadPrivateData*	pThreadPEncCtx;// thread context, [iThreadIdx]
-char eventNamespace[100];
-WELS_THREAD_HANDLE			pThreadHandles[MAX_THREADS_NUM];// thread handles, [iThreadIdx]
-WELS_EVENT					pSliceCodedEvent[MAX_THREADS_NUM];// events for slice coded state, [iThreadIdx]
-WELS_EVENT					pSliceCodedMasterEvent;	// events for signalling that some event in pSliceCodedEvent has been signalled
-WELS_EVENT					pReadySliceCodingEvent[MAX_THREADS_NUM];	// events for slice coding ready, [iThreadIdx]
-WELS_EVENT					pUpdateMbListEvent[MAX_THREADS_NUM];		// signal to update mb list neighbor for various slices
-WELS_EVENT					pFinUpdateMbListEvent[MAX_THREADS_NUM];	// signal to indicate finish updating mb list
-WELS_EVENT					pExitEncodeEvent[MAX_THREADS_NUM];			// event for exit encoding event
-WELS_EVENT					pThreadMasterEvent[MAX_THREADS_NUM];	// event for indicating that some event has been signalled to the thread
+  SSliceThreadPrivateData*	pThreadPEncCtx;// thread context, [iThreadIdx]
+  char eventNamespace[100];
+  WELS_THREAD_HANDLE			pThreadHandles[MAX_THREADS_NUM];// thread handles, [iThreadIdx]
+  WELS_EVENT					pSliceCodedEvent[MAX_THREADS_NUM];// events for slice coded state, [iThreadIdx]
+  WELS_EVENT					pSliceCodedMasterEvent;	// events for signalling that some event in pSliceCodedEvent has been signalled
+  WELS_EVENT					pReadySliceCodingEvent[MAX_THREADS_NUM];	// events for slice coding ready, [iThreadIdx]
+  WELS_EVENT					pUpdateMbListEvent[MAX_THREADS_NUM];		// signal to update mb list neighbor for various slices
+  WELS_EVENT					pFinUpdateMbListEvent[MAX_THREADS_NUM];	// signal to indicate finish updating mb list
+  WELS_EVENT					pExitEncodeEvent[MAX_THREADS_NUM];			// event for exit encoding event
+  WELS_EVENT
+  pThreadMasterEvent[MAX_THREADS_NUM];	// event for indicating that some event has been signalled to the thread
 
-WELS_MUTEX					mutexSliceNumUpdate;	// for dynamic slicing mode MT
+  WELS_MUTEX					mutexSliceNumUpdate;	// for dynamic slicing mode MT
 
-uint32_t*					pSliceConsumeTime[MAX_DEPENDENCY_LAYER];	// consuming time for each slice, [iSpatialIdx][uiSliceIdx]
-float*						pSliceComplexRatio[MAX_DEPENDENCY_LAYER];
+  uint32_t*					pSliceConsumeTime[MAX_DEPENDENCY_LAYER];	// consuming time for each slice, [iSpatialIdx][uiSliceIdx]
+  float*						pSliceComplexRatio[MAX_DEPENDENCY_LAYER];
 
 #ifdef MT_DEBUG
-FILE*						pFSliceDiff;	// file handle for debug
+  FILE*						pFSliceDiff;	// file handle for debug
 #endif//MT_DEBUG
 
 } SSliceThreading;
--- a/codec/encoder/core/inc/nal_encap.h
+++ b/codec/encoder/core/inc/nal_encap.h
@@ -52,12 +52,12 @@
  *	Raw payload pData for NAL unit, AVC/SVC compatible
  */
 typedef struct TagWelsNalRaw {
-uint8_t*				pRawData;		// pRawNal payload for slice pData
-int32_t				iPayloadSize;		// size of pRawNal pData
+  uint8_t*				pRawData;		// pRawNal payload for slice pData
+  int32_t				iPayloadSize;		// size of pRawNal pData
 
-SNalUnitHeaderExt		sNalExt;		// NAL header information
+  SNalUnitHeaderExt		sNalExt;		// NAL header information
 
-int32_t iStartPos; //NAL start position in buffer
+  int32_t iStartPos; //NAL start position in buffer
 } SWelsNalRaw;
 
 /*
@@ -64,16 +64,16 @@
  *	Encoder majoy output pData
  */
 typedef struct TagWelsEncoderOutput {
-uint8_t*				pBsBuffer;			// overall bitstream pBuffer allocation for a coded picture, recycling use intend.
-uint32_t			uiSize;				// size of allocation pBuffer above
+  uint8_t*				pBsBuffer;			// overall bitstream pBuffer allocation for a coded picture, recycling use intend.
+  uint32_t			uiSize;				// size of allocation pBuffer above
 
-SBitStringAux		sBsWrite;
+  SBitStringAux		sBsWrite;
 
 //	SWelsNalRaw		raw_nals[MAX_DEPENDENCY_LAYER*2+MAX_DEPENDENCY_LAYER*MAX_QUALITY_LEVEL]; // AVC: max up to SPS+PPS+max_slice_idc (2 + 8) for FMO;
-SWelsNalRaw*		sNalList;			// nal list, adaptive for AVC/SVC in case single slice, multiple slices or fmo
-int32_t				iCountNals;			// count number of NAL in list
+  SWelsNalRaw*		sNalList;			// nal list, adaptive for AVC/SVC in case single slice, multiple slices or fmo
+  int32_t				iCountNals;			// count number of NAL in list
 // SVC: num_sps (MAX_D) + num_pps (MAX_D) + num_vcl (MAX_D * MAX_Q)
-int32_t				iNalIndex;			// coding NAL currently, 0 based
+  int32_t				iNalIndex;			// coding NAL currently, 0 based
 
 //	bool				bAnnexBFlag;		// annexeb flag, to figure it pOut the packetization mode whether need 4 bytes (0 0 0 1) of start code prefix
 } SWelsEncoderOutput;
@@ -81,21 +81,21 @@
 //#define MT_DEBUG_BS_WR	0	// for MT debugging if needed
 
 typedef struct TagWelsSliceBs {
-uint8_t*				pBs;				// output bitstream, pBitStringAux not needed for slice 0 due to no dependency of pFrameBs available
-uint32_t			uiBsPos;				// position of output bitstream
-uint8_t*				pBsBuffer;			// overall bitstream pBuffer allocation for a coded slice, recycling use intend.
-uint32_t			uiSize;				// size of allocation pBuffer above
+  uint8_t*				pBs;				// output bitstream, pBitStringAux not needed for slice 0 due to no dependency of pFrameBs available
+  uint32_t			uiBsPos;				// position of output bitstream
+  uint8_t*				pBsBuffer;			// overall bitstream pBuffer allocation for a coded slice, recycling use intend.
+  uint32_t			uiSize;				// size of allocation pBuffer above
 
-SBitStringAux		sBsWrite;
+  SBitStringAux		sBsWrite;
 
-SWelsNalRaw		sNalList[2];		// nal list, PREFIX NAL(if applicable) + SLICE NAL
+  SWelsNalRaw		sNalList[2];		// nal list, PREFIX NAL(if applicable) + SLICE NAL
 //	int32_t				iCountNals;			// count number of NAL in list
-int32_t				iNalLen[2];
-int32_t				iNalIndex;			// coding NAL currently, 0 based
+  int32_t				iNalLen[2];
+  int32_t				iNalIndex;			// coding NAL currently, 0 based
 
 //	bool				bAnnexBFlag;		// annexeb flag, to figure it pOut the packetization mode whether need 4 bytes (0 0 0 1) of start code prefix
 #if MT_DEBUG_BS_WR
-bool				bSliceCodedFlag;
+  bool				bSliceCodedFlag;
 #endif//MT_DEBUG_BS_WR
 } SWelsSliceBs;
 
@@ -129,7 +129,8 @@
  * \param	pRawNal			pRawNal NAL pData
  * \return	ERR_CODE
  */
-int32_t WelsEncodeNal (SWelsNalRaw* pRawNal, void* pNalHeaderExt, const int32_t kiDstBufferLen, void* pDst, int32_t* pDstLen);
+int32_t WelsEncodeNal (SWelsNalRaw* pRawNal, void* pNalHeaderExt, const int32_t kiDstBufferLen, void* pDst,
+                       int32_t* pDstLen);
 
 /*!
  * \brief	write prefix nal
--- a/codec/encoder/core/inc/param_svc.h
+++ b/codec/encoder/core/inc/param_svc.h
@@ -64,45 +64,45 @@
 * \return	2 based scaling factor
 */
 static inline uint32_t GetLogFactor (float base, float upper) {
-const double dLog2factor	= log10 (1.0 * upper / base) / log10 (2.0);
-const double dEpsilon		= 0.0001;
-const double dRound		= floor (dLog2factor + 0.5);
+  const double dLog2factor	= log10 (1.0 * upper / base) / log10 (2.0);
+  const double dEpsilon		= 0.0001;
+  const double dRound		= floor (dLog2factor + 0.5);
 
-if (dLog2factor < dRound + dEpsilon && dRound < dLog2factor + dEpsilon) {
-  return (uint32_t) (dRound);
+  if (dLog2factor < dRound + dEpsilon && dRound < dLog2factor + dEpsilon) {
+    return (uint32_t) (dRound);
+  }
+  return UINT_MAX;
 }
-return UINT_MAX;
-}
 
 /*
  *	Dependency Layer Parameter
  */
 typedef struct TagDLayerParam {
-int32_t		iActualWidth;			// input source picture actual width
-int32_t		iActualHeight;			// input source picture actual height
-int32_t		iFrameWidth;			// frame width
-int32_t		iFrameHeight;			// frame height
+  int32_t		iActualWidth;			// input source picture actual width
+  int32_t		iActualHeight;			// input source picture actual height
+  int32_t		iFrameWidth;			// frame width
+  int32_t		iFrameHeight;			// frame height
 
-int32_t		iSpatialBitrate;
+  int32_t		iSpatialBitrate;
 
-/* temporal settings related */
-int32_t		iTemporalResolution;
-int32_t		iDecompositionStages;
-uint8_t     uiCodingIdx2TemporalId[ (1 << MAX_TEMPORAL_LEVEL) + 1];
+  /* temporal settings related */
+  int32_t		iTemporalResolution;
+  int32_t		iDecompositionStages;
+  uint8_t     uiCodingIdx2TemporalId[ (1 << MAX_TEMPORAL_LEVEL) + 1];
 
-uint8_t		uiProfileIdc;			// value of profile IDC (0 for auto-detection)
-uint8_t		uiLevelIdc;
-int8_t		iHighestTemporalId;
+  uint8_t		uiProfileIdc;			// value of profile IDC (0 for auto-detection)
+  uint8_t		uiLevelIdc;
+  int8_t		iHighestTemporalId;
 //	uint8_t		uiDependencyId;
-int8_t      iDLayerQp;
+  int8_t      iDLayerQp;
 
-SSliceConfig sSliceCfg;	// multiple slice options
+  SSliceConfig sSliceCfg;	// multiple slice options
 
-float		fInputFrameRate;		// input frame rate
-float		fOutputFrameRate;		// output frame rate
+  float		fInputFrameRate;		// input frame rate
+  float		fOutputFrameRate;		// output frame rate
 
 #ifdef ENABLE_FRAME_DUMP
-char		sRecFileName[MAX_FNAME_LEN];	// file to be constructed
+  char		sRecFileName[MAX_FNAME_LEN];	// file to be constructed
 #endif//ENABLE_FRAME_DUMP
 } SDLayerParam;
 
@@ -109,401 +109,405 @@
 /*
  *	Cisco OpenH264 Encoder Parameter Configuration
  */
-typedef struct TagWelsSvcCodingParam: SEncParamExt{
-SDLayerParam	sDependencyLayers[MAX_DEPENDENCY_LAYER];
+typedef struct TagWelsSvcCodingParam: SEncParamExt {
+  SDLayerParam	sDependencyLayers[MAX_DEPENDENCY_LAYER];
 
-/* General */
-uint32_t	uiGopSize;			// GOP size (at maximal frame rate: 16)
-struct {
-  int32_t iLeft;
-  int32_t iTop;
-  int32_t iWidth;
-  int32_t iHeight;
-} SUsedPicRect;	// the rect in input picture that encoder actually used
+  /* General */
+  uint32_t	uiGopSize;			// GOP size (at maximal frame rate: 16)
+  struct {
+    int32_t iLeft;
+    int32_t iTop;
+    int32_t iWidth;
+    int32_t iHeight;
+  } SUsedPicRect;	// the rect in input picture that encoder actually used
 
-char*       pCurPath; // record current lib path such as:/pData/pData/com.wels.enc/lib/
+  char*       pCurPath; // record current lib path such as:/pData/pData/com.wels.enc/lib/
 
-bool		bDeblockingParallelFlag;	// deblocking filter parallelization control flag
+  bool		bDeblockingParallelFlag;	// deblocking filter parallelization control flag
 
-short         iCountThreadsNum;                       //              # derived from disable_multiple_slice_idc (=0 or >1) means;
+  short
+  iCountThreadsNum;                       //              # derived from disable_multiple_slice_idc (=0 or >1) means;
 
-int8_t		iDecompStages;		// GOP size dependency
+  int8_t		iDecompStages;		// GOP size dependency
 
 
  public:
-TagWelsSvcCodingParam () {
-  FillDefault ();
-}
-~TagWelsSvcCodingParam()	{}
+  TagWelsSvcCodingParam() {
+    FillDefault();
+  }
+  ~TagWelsSvcCodingParam()	{}
 
-static void FillDefault (SEncParamExt& param) {
-  memset(&param, 0, sizeof(param));
-  param.uiIntraPeriod		= 0;			// intra period (multiple of GOP size as desired)
-  param.iNumRefFrame		= AUTO_REF_PIC_COUNT;// number of reference frame used
+  static void FillDefault (SEncParamExt& param) {
+    memset (&param, 0, sizeof (param));
+    param.uiIntraPeriod		= 0;			// intra period (multiple of GOP size as desired)
+    param.iNumRefFrame		= AUTO_REF_PIC_COUNT;// number of reference frame used
 
-  param.iPicWidth	= 0;    //   actual input picture width
-  param.iPicHeight	= 0;	//   actual input picture height
+    param.iPicWidth	= 0;    //   actual input picture width
+    param.iPicHeight	= 0;	//   actual input picture height
 
-  param.fMaxFrameRate		= MAX_FRAME_RATE;	// maximal frame rate [Hz / fps]
-  param.iInputCsp			= videoFormatI420;	// input sequence color space in default
-  param.uiFrameToBeCoded	= (uint32_t) - 1;		// frame to be encoded (at input frame rate)
+    param.fMaxFrameRate		= MAX_FRAME_RATE;	// maximal frame rate [Hz / fps]
+    param.iInputCsp			= videoFormatI420;	// input sequence color space in default
+    param.uiFrameToBeCoded	= (uint32_t) - 1;		// frame to be encoded (at input frame rate)
 
-  param.iTargetBitrate			= 0;	// overall target bitrate introduced in RC module
-  param.iMaxBitrate             = MAX_BIT_RATE;
-  param.iMultipleThreadIdc		= 1;
+    param.iTargetBitrate			= 0;	// overall target bitrate introduced in RC module
+    param.iMaxBitrate             = MAX_BIT_RATE;
+    param.iMultipleThreadIdc		= 1;
 
-  param.iLTRRefNum				= 0;
-  param.iLtrMarkPeriod			= 30;	//the min distance of two int32_t references
+    param.iLTRRefNum				= 0;
+    param.iLtrMarkPeriod			= 30;	//the min distance of two int32_t references
 
-  param.bEnableSSEI					= true;
-  param.bEnableFrameCroppingFlag	= true;	// enable frame cropping flag: true alwayse in application
-  // false: Streaming Video Sharing; true: Video Conferencing Meeting;
+    param.bEnableSSEI					= true;
+    param.bEnableFrameCroppingFlag	= true;	// enable frame cropping flag: true alwayse in application
+    // false: Streaming Video Sharing; true: Video Conferencing Meeting;
 
-  /* Deblocking loop filter */
-  param.iLoopFilterDisableIdc		= 0;	// 0: on, 1: off, 2: on except for slice boundaries
-  param.iLoopFilterAlphaC0Offset	= 0;	// AlphaOffset: valid range [-6, 6], default 0
-  param.iLoopFilterBetaOffset		= 0;	// BetaOffset:	valid range [-6, 6], default 0
+    /* Deblocking loop filter */
+    param.iLoopFilterDisableIdc		= 0;	// 0: on, 1: off, 2: on except for slice boundaries
+    param.iLoopFilterAlphaC0Offset	= 0;	// AlphaOffset: valid range [-6, 6], default 0
+    param.iLoopFilterBetaOffset		= 0;	// BetaOffset:	valid range [-6, 6], default 0
 
-  /* Rate Control */
-  param.iRCMode			= RC_QUALITY_MODE;
-  param.iPaddingFlag	= 0;
+    /* Rate Control */
+    param.iRCMode			= RC_QUALITY_MODE;
+    param.iPaddingFlag	= 0;
 
-  param.bEnableDenoise				= false;	// denoise control
-  param.bEnableSceneChangeDetect	= true;		// scene change detection control
-  param.bEnableBackgroundDetection	= true;		// background detection control
-  param.bEnableAdaptiveQuant		= true;		// adaptive quantization control
-  param.bEnableFrameSkip		= true;		// frame skipping
-  param.bEnableLongTermReference	= false;	// long term reference control
-  param.bEnableSpsPpsIdAddition	= true;		// pSps pPps id addition control
-  param.bPrefixNalAddingCtrl		= false;		// prefix NAL adding control
-  param.iSpatialLayerNum		= 1;		// number of dependency(Spatial/CGS) layers used to be encoded
-  param.iTemporalLayerNum			= 1;		// number of temporal layer specified
+    param.bEnableDenoise				= false;	// denoise control
+    param.bEnableSceneChangeDetect	= true;		// scene change detection control
+    param.bEnableBackgroundDetection	= true;		// background detection control
+    param.bEnableAdaptiveQuant		= true;		// adaptive quantization control
+    param.bEnableFrameSkip		= true;		// frame skipping
+    param.bEnableLongTermReference	= false;	// long term reference control
+    param.bEnableSpsPpsIdAddition	= true;		// pSps pPps id addition control
+    param.bPrefixNalAddingCtrl		= false;		// prefix NAL adding control
+    param.iSpatialLayerNum		= 1;		// number of dependency(Spatial/CGS) layers used to be encoded
+    param.iTemporalLayerNum			= 1;		// number of temporal layer specified
 
-  param.iMaxQp = 51;
-  param.iMinQp = 0;
-  param.iUsageType = CAMERA_VIDEO_REAL_TIME;
-  param.uiMaxNalSize = 0;
+    param.iMaxQp = 51;
+    param.iMinQp = 0;
+    param.iUsageType = CAMERA_VIDEO_REAL_TIME;
+    param.uiMaxNalSize = 0;
 
-  for(int32_t iLayer = 0;iLayer< MAX_SPATIAL_LAYER_NUM;iLayer++){
-    param.sSpatialLayers[iLayer].uiProfileIdc = PRO_BASELINE;
-    param.sSpatialLayers[iLayer].uiLevelIdc = LEVEL_5_0;
-    param.sSpatialLayers[iLayer].iDLayerQp = SVC_QUALITY_BASE_QP;
-    param.sSpatialLayers[iLayer].fFrameRate = param.fMaxFrameRate;
-    param.sSpatialLayers[iLayer].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
-    param.sSpatialLayers[iLayer].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1500;
-    param.sSpatialLayers[iLayer].sSliceCfg.sSliceArgument.uiSliceNum = 1;
+    for (int32_t iLayer = 0; iLayer < MAX_SPATIAL_LAYER_NUM; iLayer++) {
+      param.sSpatialLayers[iLayer].uiProfileIdc = PRO_BASELINE;
+      param.sSpatialLayers[iLayer].uiLevelIdc = LEVEL_5_0;
+      param.sSpatialLayers[iLayer].iDLayerQp = SVC_QUALITY_BASE_QP;
+      param.sSpatialLayers[iLayer].fFrameRate = param.fMaxFrameRate;
+      param.sSpatialLayers[iLayer].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
+      param.sSpatialLayers[iLayer].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1500;
+      param.sSpatialLayers[iLayer].sSliceCfg.sSliceArgument.uiSliceNum = 1;
 
-    const int32_t kiLesserSliceNum = ((MAX_SLICES_NUM < MAX_SLICES_NUM_TMP) ? MAX_SLICES_NUM : MAX_SLICES_NUM_TMP);
-    for (int32_t idx = 0; idx < kiLesserSliceNum; idx++)
-      param.sSpatialLayers[iLayer].sSliceCfg.sSliceArgument.uiSliceMbNum[idx] = 960;
+      const int32_t kiLesserSliceNum = ((MAX_SLICES_NUM < MAX_SLICES_NUM_TMP) ? MAX_SLICES_NUM : MAX_SLICES_NUM_TMP);
+      for (int32_t idx = 0; idx < kiLesserSliceNum; idx++)
+        param.sSpatialLayers[iLayer].sSliceCfg.sSliceArgument.uiSliceMbNum[idx] = 960;
+    }
   }
-}
 
-void FillDefault () {
-  FillDefault(*this);
-  uiGopSize			= 1;			// GOP size (at maximal frame rate: 16)
+  void FillDefault() {
+    FillDefault (*this);
+    uiGopSize			= 1;			// GOP size (at maximal frame rate: 16)
 
-  SUsedPicRect.iLeft	=
-    SUsedPicRect.iTop	=
-      SUsedPicRect.iWidth	=
-        SUsedPicRect.iHeight = 0;	// the rect in input picture that encoder actually used
+    SUsedPicRect.iLeft	=
+      SUsedPicRect.iTop	=
+        SUsedPicRect.iWidth	=
+          SUsedPicRect.iHeight = 0;	// the rect in input picture that encoder actually used
 
-  pCurPath			= NULL; // record current lib path such as:/pData/pData/com.wels.enc/lib/
+    pCurPath			= NULL; // record current lib path such as:/pData/pData/com.wels.enc/lib/
 
-  bDeblockingParallelFlag = false;	// deblocking filter parallelization control flag
+    bDeblockingParallelFlag = false;	// deblocking filter parallelization control flag
 
-  iCountThreadsNum		= 1;	//		# derived from disable_multiple_slice_idc (=0 or >1) means;
+    iCountThreadsNum		= 1;	//		# derived from disable_multiple_slice_idc (=0 or >1) means;
 
-  iDecompStages				= 0;	// GOP size dependency, unknown here and be revised later
+    iDecompStages				= 0;	// GOP size dependency, unknown here and be revised later
 
-  memset(sDependencyLayers,0,sizeof(SDLayerParam)*MAX_DEPENDENCY_LAYER);
+    memset (sDependencyLayers, 0, sizeof (SDLayerParam)*MAX_DEPENDENCY_LAYER);
 
 
 
-  //init multi-slice
-   sDependencyLayers[0].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
-   sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint    = 1500;
-   sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum      = 1;
+    //init multi-slice
+    sDependencyLayers[0].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
+    sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint    = 1500;
+    sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceNum      = 1;
 
-   const int32_t kiLesserSliceNum = ((MAX_SLICES_NUM < MAX_SLICES_NUM_TMP) ? MAX_SLICES_NUM : MAX_SLICES_NUM_TMP);
-   for(int32_t idx = 0;idx <kiLesserSliceNum;idx++)
-		sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceMbNum[idx] = 960;
+    const int32_t kiLesserSliceNum = ((MAX_SLICES_NUM < MAX_SLICES_NUM_TMP) ? MAX_SLICES_NUM : MAX_SLICES_NUM_TMP);
+    for (int32_t idx = 0; idx < kiLesserSliceNum; idx++)
+      sDependencyLayers[0].sSliceCfg.sSliceArgument.uiSliceMbNum[idx] = 960;
     sDependencyLayers[0].iDLayerQp = SVC_QUALITY_BASE_QP;
 
 
-}
+  }
 
-int32_t ParamBaseTranscode (const SEncParamBase& pCodingParam) {
+  int32_t ParamBaseTranscode (const SEncParamBase& pCodingParam) {
 
-  iInputCsp		= pCodingParam.iInputCsp;		// color space of input sequence
-  fMaxFrameRate		= WELS_CLIP3 (pCodingParam.fMaxFrameRate, MIN_FRAME_RATE, MAX_FRAME_RATE);
-  iTargetBitrate	= pCodingParam.iTargetBitrate;
-  iUsageType = pCodingParam.iUsageType;
-  iPicWidth   = pCodingParam.iPicWidth;
-  iPicHeight  = pCodingParam.iPicHeight;
+    iInputCsp		= pCodingParam.iInputCsp;		// color space of input sequence
+    fMaxFrameRate		= WELS_CLIP3 (pCodingParam.fMaxFrameRate, MIN_FRAME_RATE, MAX_FRAME_RATE);
+    iTargetBitrate	= pCodingParam.iTargetBitrate;
+    iUsageType = pCodingParam.iUsageType;
+    iPicWidth   = pCodingParam.iPicWidth;
+    iPicHeight  = pCodingParam.iPicHeight;
 
-  SUsedPicRect.iLeft = 0;
-  SUsedPicRect.iTop  = 0;
-  SUsedPicRect.iWidth = ((iPicWidth >> 1) << 1);
-  SUsedPicRect.iHeight = ((iPicHeight >> 1) << 1);
+    SUsedPicRect.iLeft = 0;
+    SUsedPicRect.iTop  = 0;
+    SUsedPicRect.iWidth = ((iPicWidth >> 1) << 1);
+    SUsedPicRect.iHeight = ((iPicHeight >> 1) << 1);
 
-  iRCMode = pCodingParam.iRCMode;    // rc mode
+    iRCMode = pCodingParam.iRCMode;    // rc mode
 
-  int8_t iIdxSpatial	= 0;
-  uint8_t uiProfileIdc		= PRO_BASELINE;
+    int8_t iIdxSpatial	= 0;
+    uint8_t uiProfileIdc		= PRO_BASELINE;
 
-  SDLayerParam* pDlp		= &sDependencyLayers[0];
+    SDLayerParam* pDlp		= &sDependencyLayers[0];
 
-  while (iIdxSpatial < iSpatialLayerNum) {
+    while (iIdxSpatial < iSpatialLayerNum) {
 
-    pDlp->uiProfileIdc		= uiProfileIdc;
-    sSpatialLayers[iIdxSpatial].fFrameRate	= WELS_CLIP3 (pCodingParam.fMaxFrameRate,
-        MIN_FRAME_RATE, MAX_FRAME_RATE);
-    pDlp->fInputFrameRate	=
-      pDlp->fOutputFrameRate	= WELS_CLIP3 (sSpatialLayers[iIdxSpatial].fFrameRate, MIN_FRAME_RATE,
-                                            MAX_FRAME_RATE);
+      pDlp->uiProfileIdc		= uiProfileIdc;
+      sSpatialLayers[iIdxSpatial].fFrameRate	= WELS_CLIP3 (pCodingParam.fMaxFrameRate,
+          MIN_FRAME_RATE, MAX_FRAME_RATE);
+      pDlp->fInputFrameRate	=
+        pDlp->fOutputFrameRate	= WELS_CLIP3 (sSpatialLayers[iIdxSpatial].fFrameRate, MIN_FRAME_RATE,
+                                              MAX_FRAME_RATE);
 #ifdef ENABLE_FRAME_DUMP
-    pDlp->sRecFileName[0]	= '\0';	// file to be constructed
+      pDlp->sRecFileName[0]	= '\0';	// file to be constructed
 #endif//ENABLE_FRAME_DUMP
-   pDlp->iActualWidth = sSpatialLayers[iIdxSpatial].iVideoWidth = iPicWidth;
-   pDlp->iFrameWidth = pDlp->iActualWidth;
+      pDlp->iActualWidth = sSpatialLayers[iIdxSpatial].iVideoWidth = iPicWidth;
+      pDlp->iFrameWidth = pDlp->iActualWidth;
 
-  pDlp->iActualHeight = sSpatialLayers[iIdxSpatial].iVideoHeight = iPicHeight;
-  pDlp->iFrameHeight = pDlp->iActualHeight;
+      pDlp->iActualHeight = sSpatialLayers[iIdxSpatial].iVideoHeight = iPicHeight;
+      pDlp->iFrameHeight = pDlp->iActualHeight;
 
-    pDlp->iSpatialBitrate	=
-		sSpatialLayers[iIdxSpatial].iSpatialBitrate = pCodingParam.iTargetBitrate;	// target bitrate for current spatial layer
+      pDlp->iSpatialBitrate	=
+        sSpatialLayers[iIdxSpatial].iSpatialBitrate = pCodingParam.iTargetBitrate;	// target bitrate for current spatial layer
 
-   pDlp->iDLayerQp = SVC_QUALITY_BASE_QP;
+      pDlp->iDLayerQp = SVC_QUALITY_BASE_QP;
 
-    uiProfileIdc	= PRO_SCALABLE_BASELINE;
-    ++ pDlp;
-    ++ iIdxSpatial;
+      uiProfileIdc	= PRO_SCALABLE_BASELINE;
+      ++ pDlp;
+      ++ iIdxSpatial;
+    }
+    SetActualPicResolution();
+
+    return 0;
   }
-   SetActualPicResolution();
+  void GetBaseParams (SEncParamBase* pCodingParam) {
+    pCodingParam->iUsageType     = iUsageType;
+    pCodingParam->iInputCsp      = iInputCsp;
+    pCodingParam->iPicWidth      = iPicWidth;
+    pCodingParam->iPicHeight     = iPicHeight;
+    pCodingParam->iTargetBitrate = iTargetBitrate;
+    pCodingParam->iRCMode        = iRCMode;
+    pCodingParam->fMaxFrameRate  = fMaxFrameRate;
+  }
+  int32_t ParamTranscode (const SEncParamExt& pCodingParam) {
+    float fParamMaxFrameRate		= WELS_CLIP3 (pCodingParam.fMaxFrameRate, MIN_FRAME_RATE, MAX_FRAME_RATE);
 
-   return 0;
-}
-void GetBaseParams (SEncParamBase* pCodingParam) {
-  pCodingParam->iUsageType     = iUsageType;
-  pCodingParam->iInputCsp      = iInputCsp;
-  pCodingParam->iPicWidth      = iPicWidth;
-  pCodingParam->iPicHeight     = iPicHeight;
-  pCodingParam->iTargetBitrate = iTargetBitrate;
-  pCodingParam->iRCMode        = iRCMode;
-  pCodingParam->fMaxFrameRate  = fMaxFrameRate;
-}
-int32_t ParamTranscode (const SEncParamExt& pCodingParam) {
-  float fParamMaxFrameRate		= WELS_CLIP3 (pCodingParam.fMaxFrameRate, MIN_FRAME_RATE, MAX_FRAME_RATE);
+    iInputCsp		= pCodingParam.iInputCsp;		// color space of input sequence
+    uiFrameToBeCoded	= (uint32_t) -
+                        1;		// frame to be encoded (at input frame rate), -1 dependents on length of input sequence
+    iUsageType = pCodingParam.iUsageType;
+    iPicWidth   = pCodingParam.iPicWidth;
+    iPicHeight  = pCodingParam.iPicHeight;
 
-  iInputCsp		= pCodingParam.iInputCsp;		// color space of input sequence
-  uiFrameToBeCoded	= (uint32_t) -
-                      1;		// frame to be encoded (at input frame rate), -1 dependents on length of input sequence
-  iUsageType = pCodingParam.iUsageType;
-  iPicWidth   = pCodingParam.iPicWidth;
-  iPicHeight  = pCodingParam.iPicHeight;
+    SUsedPicRect.iLeft = 0;
+    SUsedPicRect.iTop  = 0;
+    SUsedPicRect.iWidth = ((iPicWidth >> 1) << 1);
+    SUsedPicRect.iHeight = ((iPicHeight >> 1) << 1);
 
-  SUsedPicRect.iLeft = 0;
-  SUsedPicRect.iTop  = 0;
-  SUsedPicRect.iWidth = ((iPicWidth >> 1) << 1);
-  SUsedPicRect.iHeight = ((iPicHeight >> 1) << 1);
+    /* Deblocking loop filter */
+    iLoopFilterDisableIdc	= pCodingParam.iLoopFilterDisableIdc;	// 0: on, 1: off, 2: on except for slice boundaries,
+    if (iLoopFilterDisableIdc == 0) // Loop filter requested to be enabled
+      iLoopFilterDisableIdc = 2; // Disable loop filter on slice boundaries since that's not allowed with multithreading
+    iLoopFilterAlphaC0Offset = pCodingParam.iLoopFilterAlphaC0Offset;	// AlphaOffset: valid range [-6, 6], default 0
+    iLoopFilterBetaOffset = pCodingParam.iLoopFilterBetaOffset;	// BetaOffset:	valid range [-6, 6], default 0
 
-  /* Deblocking loop filter */
-  iLoopFilterDisableIdc	= pCodingParam.iLoopFilterDisableIdc;	// 0: on, 1: off, 2: on except for slice boundaries,
-  if (iLoopFilterDisableIdc == 0) // Loop filter requested to be enabled
-    iLoopFilterDisableIdc = 2; // Disable loop filter on slice boundaries since that's not allowed with multithreading
-  iLoopFilterAlphaC0Offset = pCodingParam.iLoopFilterAlphaC0Offset;	// AlphaOffset: valid range [-6, 6], default 0
-  iLoopFilterBetaOffset = pCodingParam.iLoopFilterBetaOffset;	// BetaOffset:	valid range [-6, 6], default 0
+    bEnableFrameCroppingFlag	= pCodingParam.bEnableFrameCroppingFlag;
 
-  bEnableFrameCroppingFlag	= pCodingParam.bEnableFrameCroppingFlag;
+    /* Rate Control */
+    iRCMode = pCodingParam.iRCMode;    // rc mode
+    iPaddingFlag = pCodingParam.iPaddingFlag;
 
-  /* Rate Control */
-  iRCMode = pCodingParam.iRCMode;    // rc mode
-  iPaddingFlag = pCodingParam.iPaddingFlag;
+    iTargetBitrate		= pCodingParam.iTargetBitrate;	// target bitrate
+    iMaxBitrate           = pCodingParam.iMaxBitrate;
 
-  iTargetBitrate		= pCodingParam.iTargetBitrate;	// target bitrate
-  iMaxBitrate           = pCodingParam.iMaxBitrate;
+    uiMaxNalSize          = pCodingParam.uiMaxNalSize;
+    /* Denoise Control */
+    bEnableDenoise = pCodingParam.bEnableDenoise ? true : false;    // Denoise Control  // only support 0 or 1 now
 
-  uiMaxNalSize          = pCodingParam.uiMaxNalSize;
-  /* Denoise Control */
-  bEnableDenoise = pCodingParam.bEnableDenoise ? true : false;    // Denoise Control  // only support 0 or 1 now
+    /* Scene change detection control */
+    bEnableSceneChangeDetect	= pCodingParam.bEnableSceneChangeDetect;
 
-  /* Scene change detection control */
-  bEnableSceneChangeDetect	= pCodingParam.bEnableSceneChangeDetect;
+    /* Background detection Control */
+    bEnableBackgroundDetection = pCodingParam.bEnableBackgroundDetection ? true : false;
 
-  /* Background detection Control */
-  bEnableBackgroundDetection = pCodingParam.bEnableBackgroundDetection ? true : false;
+    /* Adaptive quantization control */
+    bEnableAdaptiveQuant	= pCodingParam.bEnableAdaptiveQuant ? true : false;
 
-  /* Adaptive quantization control */
-  bEnableAdaptiveQuant	= pCodingParam.bEnableAdaptiveQuant ? true : false;
+    /* Frame skipping */
+    bEnableFrameSkip	= pCodingParam.bEnableFrameSkip ? true : false;
 
-  /* Frame skipping */
-  bEnableFrameSkip	= pCodingParam.bEnableFrameSkip ? true : false;
+    /* Enable int32_t term reference */
+    bEnableLongTermReference	= pCodingParam.bEnableLongTermReference ? true : false;
+    iLtrMarkPeriod = pCodingParam.iLtrMarkPeriod;
 
-  /* Enable int32_t term reference */
-  bEnableLongTermReference	= pCodingParam.bEnableLongTermReference ? true : false;
-  iLtrMarkPeriod = pCodingParam.iLtrMarkPeriod;
+    iMultipleThreadIdc = pCodingParam.iMultipleThreadIdc;
 
-  iMultipleThreadIdc = pCodingParam.iMultipleThreadIdc;
+    /* For ssei information */
+    bEnableSSEI		= pCodingParam.bEnableSSEI;
 
-  /* For ssei information */
-  bEnableSSEI		= pCodingParam.bEnableSSEI;
+    /* Layer definition */
+    iSpatialLayerNum	= (int8_t)WELS_CLIP3 (pCodingParam.iSpatialLayerNum, 1,
+                                            MAX_DEPENDENCY_LAYER); // number of dependency(Spatial/CGS) layers used to be encoded
+    iTemporalLayerNum		= (int8_t)WELS_CLIP3 (pCodingParam.iTemporalLayerNum, 1,
+                          MAX_TEMPORAL_LEVEL); // number of temporal layer specified
 
-  /* Layer definition */
-  iSpatialLayerNum	= (int8_t)WELS_CLIP3 (pCodingParam.iSpatialLayerNum, 1,
-                        MAX_DEPENDENCY_LAYER); // number of dependency(Spatial/CGS) layers used to be encoded
-  iTemporalLayerNum		= (int8_t)WELS_CLIP3(pCodingParam.iTemporalLayerNum, 1, MAX_TEMPORAL_LEVEL);// number of temporal layer specified
+    uiGopSize			= 1 << (iTemporalLayerNum - 1);	// Override GOP size based temporal layer
+    iDecompStages		= iTemporalLayerNum - 1;	// WELS_LOG2( uiGopSize );// GOP size dependency
+    uiIntraPeriod		= pCodingParam.uiIntraPeriod;// intra period (multiple of GOP size as desired)
+    if (uiIntraPeriod == (uint32_t) (-1))
+      uiIntraPeriod = 0;
+    else if (uiIntraPeriod & (uiGopSize - 1))	// none multiple of GOP size
+      uiIntraPeriod = ((uiIntraPeriod + uiGopSize - 1) / uiGopSize) * uiGopSize;
 
-  uiGopSize			= 1 << (iTemporalLayerNum - 1);	// Override GOP size based temporal layer
-  iDecompStages		= iTemporalLayerNum - 1;	// WELS_LOG2( uiGopSize );// GOP size dependency
-  uiIntraPeriod		= pCodingParam.uiIntraPeriod;// intra period (multiple of GOP size as desired)
-  if (uiIntraPeriod == (uint32_t) (-1))
-    uiIntraPeriod = 0;
-  else if (uiIntraPeriod & (uiGopSize-1))	// none multiple of GOP size
-    uiIntraPeriod = ((uiIntraPeriod + uiGopSize - 1) / uiGopSize) * uiGopSize;
+    if (iUsageType == SCREEN_CONTENT_REAL_TIME) {
+      if (bEnableLongTermReference) {
+        iLTRRefNum = WELS_CLIP3 (pCodingParam.iLTRRefNum, 1, LONG_TERM_REF_NUM_SCREEN);
+        if (iNumRefFrame == AUTO_REF_PIC_COUNT)
+          iNumRefFrame = WELS_MAX (1, WELS_LOG2 (uiGopSize)) + iLTRRefNum;
+      } else {
+        iLTRRefNum = 0;
 
-  if (iUsageType == SCREEN_CONTENT_REAL_TIME) {
-    if (bEnableLongTermReference) {
-      iLTRRefNum = WELS_CLIP3(pCodingParam.iLTRRefNum,1,LONG_TERM_REF_NUM_SCREEN);
-      if( iNumRefFrame == AUTO_REF_PIC_COUNT)
-        iNumRefFrame = WELS_MAX(1, WELS_LOG2 (uiGopSize)) + iLTRRefNum;
+        if (iNumRefFrame == AUTO_REF_PIC_COUNT)
+          iNumRefFrame = WELS_MAX (1, uiGopSize >> 1);
+      }
     } else {
-      iLTRRefNum = 0;
-
-      if( iNumRefFrame == AUTO_REF_PIC_COUNT)
-        iNumRefFrame = WELS_MAX(1, uiGopSize>>1);
+      iLTRRefNum = bEnableLongTermReference ? WELS_CLIP3 (pCodingParam.iLTRRefNum, 1, LONG_TERM_REF_NUM) : 0;
+      if (iNumRefFrame == AUTO_REF_PIC_COUNT) {
+        iNumRefFrame		= ((uiGopSize >> 1) > 1) ? ((uiGopSize >> 1) + iLTRRefNum) : (MIN_REF_PIC_COUNT + iLTRRefNum);
+        iNumRefFrame		= WELS_CLIP3 (iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);
+      }
     }
-  } else {
-    iLTRRefNum = bEnableLongTermReference ? WELS_CLIP3(pCodingParam.iLTRRefNum,1,LONG_TERM_REF_NUM) : 0;
-    if( iNumRefFrame == AUTO_REF_PIC_COUNT){
-      iNumRefFrame		= ((uiGopSize >> 1) > 1) ? ((uiGopSize >> 1) + iLTRRefNum) : (MIN_REF_PIC_COUNT + iLTRRefNum);
-      iNumRefFrame		= WELS_CLIP3 (iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);
-    }
-  }
-  iLtrMarkPeriod  = pCodingParam.iLtrMarkPeriod;
+    iLtrMarkPeriod  = pCodingParam.iLtrMarkPeriod;
 
-  bPrefixNalAddingCtrl	= pCodingParam.bPrefixNalAddingCtrl;
+    bPrefixNalAddingCtrl	= pCodingParam.bPrefixNalAddingCtrl;
 
-  bEnableSpsPpsIdAddition =
-    pCodingParam.bEnableSpsPpsIdAddition;//For SVC meeting application, to avoid mosaic issue caused by cross-IDR reference.
-  //SHOULD enable this feature.
+    bEnableSpsPpsIdAddition =
+      pCodingParam.bEnableSpsPpsIdAddition;//For SVC meeting application, to avoid mosaic issue caused by cross-IDR reference.
+    //SHOULD enable this feature.
 
-  SDLayerParam* pDlp		= &sDependencyLayers[0];
-  float fMaxFr			= .0f;
-  uint8_t uiProfileIdc		= PRO_BASELINE;
-  int8_t iIdxSpatial	= 0;
-  while (iIdxSpatial < iSpatialLayerNum) {
-    pDlp->uiProfileIdc		= (pCodingParam.sSpatialLayers[iIdxSpatial].uiProfileIdc == PRO_UNKNOWN)?uiProfileIdc:pCodingParam.sSpatialLayers[iIdxSpatial].uiProfileIdc;
-    pDlp->uiLevelIdc        = (pCodingParam.sSpatialLayers[iIdxSpatial].uiLevelIdc == LEVEL_UNKNOWN)?LEVEL_5_0:pCodingParam.sSpatialLayers[iIdxSpatial].uiLevelIdc;
+    SDLayerParam* pDlp		= &sDependencyLayers[0];
+    float fMaxFr			= .0f;
+    uint8_t uiProfileIdc		= PRO_BASELINE;
+    int8_t iIdxSpatial	= 0;
+    while (iIdxSpatial < iSpatialLayerNum) {
+      pDlp->uiProfileIdc		= (pCodingParam.sSpatialLayers[iIdxSpatial].uiProfileIdc == PRO_UNKNOWN) ? uiProfileIdc :
+                              pCodingParam.sSpatialLayers[iIdxSpatial].uiProfileIdc;
+      pDlp->uiLevelIdc        = (pCodingParam.sSpatialLayers[iIdxSpatial].uiLevelIdc == LEVEL_UNKNOWN) ? LEVEL_5_0 :
+                                pCodingParam.sSpatialLayers[iIdxSpatial].uiLevelIdc;
 
-    float fLayerFrameRate	= WELS_CLIP3 (pCodingParam.sSpatialLayers[iIdxSpatial].fFrameRate,
-        MIN_FRAME_RATE, fParamMaxFrameRate);
-    pDlp->fInputFrameRate	=
-      pDlp->fOutputFrameRate	= WELS_CLIP3 (fLayerFrameRate, MIN_FRAME_RATE, MAX_FRAME_RATE);
-    if (pDlp->fInputFrameRate > fMaxFr + EPSN)
-      fMaxFr = pDlp->fInputFrameRate;
+      float fLayerFrameRate	= WELS_CLIP3 (pCodingParam.sSpatialLayers[iIdxSpatial].fFrameRate,
+                                          MIN_FRAME_RATE, fParamMaxFrameRate);
+      pDlp->fInputFrameRate	=
+        pDlp->fOutputFrameRate	= WELS_CLIP3 (fLayerFrameRate, MIN_FRAME_RATE, MAX_FRAME_RATE);
+      if (pDlp->fInputFrameRate > fMaxFr + EPSN)
+        fMaxFr = pDlp->fInputFrameRate;
 
 #ifdef ENABLE_FRAME_DUMP
-    pDlp->sRecFileName[0]	= '\0';	// file to be constructed
+      pDlp->sRecFileName[0]	= '\0';	// file to be constructed
 #endif//ENABLE_FRAME_DUMP
-    pDlp->iFrameWidth		= pCodingParam.sSpatialLayers[iIdxSpatial].iVideoWidth;	// frame width
-    pDlp->iFrameHeight		= pCodingParam.sSpatialLayers[iIdxSpatial].iVideoHeight;// frame height
-    pDlp->iSpatialBitrate	=
-      pCodingParam.sSpatialLayers[iIdxSpatial].iSpatialBitrate;	// target bitrate for current spatial layer
+      pDlp->iFrameWidth		= pCodingParam.sSpatialLayers[iIdxSpatial].iVideoWidth;	// frame width
+      pDlp->iFrameHeight		= pCodingParam.sSpatialLayers[iIdxSpatial].iVideoHeight;// frame height
+      pDlp->iSpatialBitrate	=
+        pCodingParam.sSpatialLayers[iIdxSpatial].iSpatialBitrate;	// target bitrate for current spatial layer
 
-    //multi slice
-    pDlp->sSliceCfg.uiSliceMode = pCodingParam.sSpatialLayers[iIdxSpatial].sSliceCfg.uiSliceMode;
-    pDlp->sSliceCfg.sSliceArgument.uiSliceSizeConstraint
-      = (uint32_t) (pCodingParam.sSpatialLayers[iIdxSpatial].sSliceCfg.sSliceArgument.uiSliceSizeConstraint);
-    pDlp->sSliceCfg.sSliceArgument.uiSliceNum
-      = pCodingParam.sSpatialLayers[iIdxSpatial].sSliceCfg.sSliceArgument.uiSliceNum;
-    const int32_t kiLesserSliceNum = ((MAX_SLICES_NUM < MAX_SLICES_NUM_TMP) ? MAX_SLICES_NUM : MAX_SLICES_NUM_TMP);
-    memcpy (pDlp->sSliceCfg.sSliceArgument.uiSliceMbNum,
-            pCodingParam.sSpatialLayers[iIdxSpatial].sSliceCfg.sSliceArgument.uiSliceMbNum,	// confirmed_safe_unsafe_usage
-            kiLesserSliceNum * sizeof (uint32_t)) ;
+      //multi slice
+      pDlp->sSliceCfg.uiSliceMode = pCodingParam.sSpatialLayers[iIdxSpatial].sSliceCfg.uiSliceMode;
+      pDlp->sSliceCfg.sSliceArgument.uiSliceSizeConstraint
+        = (uint32_t) (pCodingParam.sSpatialLayers[iIdxSpatial].sSliceCfg.sSliceArgument.uiSliceSizeConstraint);
+      pDlp->sSliceCfg.sSliceArgument.uiSliceNum
+        = pCodingParam.sSpatialLayers[iIdxSpatial].sSliceCfg.sSliceArgument.uiSliceNum;
+      const int32_t kiLesserSliceNum = ((MAX_SLICES_NUM < MAX_SLICES_NUM_TMP) ? MAX_SLICES_NUM : MAX_SLICES_NUM_TMP);
+      memcpy (pDlp->sSliceCfg.sSliceArgument.uiSliceMbNum,
+              pCodingParam.sSpatialLayers[iIdxSpatial].sSliceCfg.sSliceArgument.uiSliceMbNum,	// confirmed_safe_unsafe_usage
+              kiLesserSliceNum * sizeof (uint32_t)) ;
 
-    pDlp->iDLayerQp = pCodingParam.sSpatialLayers[iIdxSpatial].iDLayerQp;
+      pDlp->iDLayerQp = pCodingParam.sSpatialLayers[iIdxSpatial].iDLayerQp;
 
-    uiProfileIdc	= PRO_SCALABLE_BASELINE;
-    ++ pDlp;
-    ++ iIdxSpatial;
-  }
+      uiProfileIdc	= PRO_SCALABLE_BASELINE;
+      ++ pDlp;
+      ++ iIdxSpatial;
+    }
 
-  fMaxFrameRate	= fMaxFr;
+    fMaxFrameRate	= fMaxFr;
 
-  SetActualPicResolution();
+    SetActualPicResolution();
 
-  return 0;
-}
+    return 0;
+  }
 
 // assuming that the width/height ratio of all spatial layers are the same
 
-void SetActualPicResolution() {
-  int32_t iSpatialIdx			= iSpatialLayerNum - 1;
-  SDLayerParam* pDlayer		= &sDependencyLayers[iSpatialIdx];
+  void SetActualPicResolution() {
+    int32_t iSpatialIdx			= iSpatialLayerNum - 1;
+    SDLayerParam* pDlayer		= &sDependencyLayers[iSpatialIdx];
 
-  for (; iSpatialIdx >= 0; iSpatialIdx --) {
-    pDlayer	= &sDependencyLayers[iSpatialIdx];
+    for (; iSpatialIdx >= 0; iSpatialIdx --) {
+      pDlayer	= &sDependencyLayers[iSpatialIdx];
 
-    pDlayer->iActualWidth = pDlayer->iFrameWidth;
-    pDlayer->iActualHeight = pDlayer->iFrameHeight;
-    pDlayer->iFrameWidth = WELS_ALIGN (pDlayer->iActualWidth, MB_WIDTH_LUMA);
-    pDlayer->iFrameHeight = WELS_ALIGN (pDlayer->iActualHeight, MB_HEIGHT_LUMA);
+      pDlayer->iActualWidth = pDlayer->iFrameWidth;
+      pDlayer->iActualHeight = pDlayer->iFrameHeight;
+      pDlayer->iFrameWidth = WELS_ALIGN (pDlayer->iActualWidth, MB_WIDTH_LUMA);
+      pDlayer->iFrameHeight = WELS_ALIGN (pDlayer->iActualHeight, MB_HEIGHT_LUMA);
+    }
   }
-}
 
-/*!
-* \brief	determined key coding tables for temporal scalability, uiProfileIdc etc for each spatial layer settings
-* \param	SWelsSvcCodingParam, and carried with known GOP size, max, input and output frame rate of each spatial
-* \return	NONE (should ensure valid parameter before this procedure)
-*/
-void DetermineTemporalSettings() {
-  const int32_t iDecStages		= WELS_LOG2 (
-                                  uiGopSize);	// (int8_t)GetLogFactor(1.0f, 1.0f * pcfg->uiGopSize);	//log2(uiGopSize)
-  const uint8_t* pTemporalIdList	= &g_kuiTemporalIdListTable[iDecStages][0];
-  SDLayerParam* pDlp				= &sDependencyLayers[0];
-  uint8_t uiProfileIdc				= PRO_BASELINE;
-  int8_t i						= 0;
+  /*!
+  * \brief	determined key coding tables for temporal scalability, uiProfileIdc etc for each spatial layer settings
+  * \param	SWelsSvcCodingParam, and carried with known GOP size, max, input and output frame rate of each spatial
+  * \return	NONE (should ensure valid parameter before this procedure)
+  */
+  void DetermineTemporalSettings() {
+    const int32_t iDecStages		= WELS_LOG2 (
+                                    uiGopSize);	// (int8_t)GetLogFactor(1.0f, 1.0f * pcfg->uiGopSize);	//log2(uiGopSize)
+    const uint8_t* pTemporalIdList	= &g_kuiTemporalIdListTable[iDecStages][0];
+    SDLayerParam* pDlp				= &sDependencyLayers[0];
+    uint8_t uiProfileIdc				= PRO_BASELINE;
+    int8_t i						= 0;
 
-  while (i < iSpatialLayerNum) {
-    const uint32_t kuiLogFactorInOutRate	= GetLogFactor (pDlp->fOutputFrameRate, pDlp->fInputFrameRate);
-    const uint32_t kuiLogFactorMaxInRate	= GetLogFactor (pDlp->fInputFrameRate, fMaxFrameRate);
-    int32_t iNotCodedMask = 0;
-    int8_t iMaxTemporalId = 0;
+    while (i < iSpatialLayerNum) {
+      const uint32_t kuiLogFactorInOutRate	= GetLogFactor (pDlp->fOutputFrameRate, pDlp->fInputFrameRate);
+      const uint32_t kuiLogFactorMaxInRate	= GetLogFactor (pDlp->fInputFrameRate, fMaxFrameRate);
+      int32_t iNotCodedMask = 0;
+      int8_t iMaxTemporalId = 0;
 
-    memset (pDlp->uiCodingIdx2TemporalId, INVALID_TEMPORAL_ID, sizeof (pDlp->uiCodingIdx2TemporalId));
-    pDlp->uiProfileIdc = uiProfileIdc;	// PRO_BASELINE, PRO_SCALABLE_BASELINE;
+      memset (pDlp->uiCodingIdx2TemporalId, INVALID_TEMPORAL_ID, sizeof (pDlp->uiCodingIdx2TemporalId));
+      pDlp->uiProfileIdc = uiProfileIdc;	// PRO_BASELINE, PRO_SCALABLE_BASELINE;
 
-    iNotCodedMask	= (1 << (kuiLogFactorInOutRate + kuiLogFactorMaxInRate)) - 1;
-    for (uint32_t uiFrameIdx = 0; uiFrameIdx <= uiGopSize; ++ uiFrameIdx) {
-      if (0 == (uiFrameIdx & iNotCodedMask)) {
-        const int8_t kiTemporalId = pTemporalIdList[uiFrameIdx];
-        pDlp->uiCodingIdx2TemporalId[uiFrameIdx] = kiTemporalId;
-        if (kiTemporalId > iMaxTemporalId) {
-          iMaxTemporalId = kiTemporalId;
+      iNotCodedMask	= (1 << (kuiLogFactorInOutRate + kuiLogFactorMaxInRate)) - 1;
+      for (uint32_t uiFrameIdx = 0; uiFrameIdx <= uiGopSize; ++ uiFrameIdx) {
+        if (0 == (uiFrameIdx & iNotCodedMask)) {
+          const int8_t kiTemporalId = pTemporalIdList[uiFrameIdx];
+          pDlp->uiCodingIdx2TemporalId[uiFrameIdx] = kiTemporalId;
+          if (kiTemporalId > iMaxTemporalId) {
+            iMaxTemporalId = kiTemporalId;
+          }
         }
       }
-    }
 
-    pDlp->iHighestTemporalId	= iMaxTemporalId;
-    pDlp->iTemporalResolution	= kuiLogFactorMaxInRate + kuiLogFactorInOutRate;
-    pDlp->iDecompositionStages	= iDecStages - kuiLogFactorMaxInRate - kuiLogFactorInOutRate;
+      pDlp->iHighestTemporalId	= iMaxTemporalId;
+      pDlp->iTemporalResolution	= kuiLogFactorMaxInRate + kuiLogFactorInOutRate;
+      pDlp->iDecompositionStages	= iDecStages - kuiLogFactorMaxInRate - kuiLogFactorInOutRate;
 
-    uiProfileIdc	= PRO_SCALABLE_BASELINE;
-    ++ pDlp;
-    ++ i;
+      uiProfileIdc	= PRO_SCALABLE_BASELINE;
+      ++ pDlp;
+      ++ i;
+    }
+    iDecompStages = (int8_t)iDecStages;
   }
-  iDecompStages = (int8_t)iDecStages;
-}
 
 } SWelsSvcCodingParam;
 
 static inline int32_t FreeCodingParam (SWelsSvcCodingParam** pParam, CMemoryAlign* pMa) {
-if (pParam == NULL || *pParam == NULL || pMa == NULL)
-  return 1;
-pMa->WelsFree (*pParam, "SWelsSvcCodingParam");
-*pParam = NULL;
-return 0;
+  if (pParam == NULL || *pParam == NULL || pMa == NULL)
+    return 1;
+  pMa->WelsFree (*pParam, "SWelsSvcCodingParam");
+  *pParam = NULL;
+  return 0;
 }
 
 static inline int32_t AllocCodingParam (SWelsSvcCodingParam** pParam, CMemoryAlign* pMa) {
@@ -513,7 +517,7 @@
     FreeCodingParam (pParam, pMa);
   }
   SWelsSvcCodingParam* pCodingParam = (SWelsSvcCodingParam*)pMa->WelsMalloc (sizeof (SWelsSvcCodingParam),
-                                    "SWelsSvcCodingParam");
+                                      "SWelsSvcCodingParam");
   if (NULL == pCodingParam)
     return 1;
   *pParam = pCodingParam;
--- a/codec/encoder/core/inc/parameter_sets.h
+++ b/codec/encoder/core/inc/parameter_sets.h
@@ -41,32 +41,32 @@
 
 /* Sequence Parameter Set, refer to Page 57 in JVT X201wcm */
 typedef struct TagWelsSPS {
-uint32_t	uiSpsId;
-int16_t		iMbWidth;
-int16_t		iMbHeight;
-uint32_t	uiLog2MaxFrameNum;
+  uint32_t	uiSpsId;
+  int16_t		iMbWidth;
+  int16_t		iMbHeight;
+  uint32_t	uiLog2MaxFrameNum;
 //	uint32_t	uiPocType;
-/* POC type 0 */
-int32_t		iLog2MaxPocLsb;
-/* POC type 1 */
+  /* POC type 0 */
+  int32_t		iLog2MaxPocLsb;
+  /* POC type 1 */
 //	int32_t		iOffsetForNonRefPic;
 
 //	int32_t		iOffsetForTopToBottomField;
 //	int32_t		iNumRefFramesInPocCycle;
 //	int8_t		iOffsetForRefFrame[256];
-SCropOffset	sFrameCrop;
-int16_t		iNumRefFrames;
+  SCropOffset	sFrameCrop;
+  int16_t		iNumRefFrames;
 //	uint32_t	uiNumUnitsInTick;
 //	uint32_t	uiTimeScale;
 
-uint8_t		uiProfileIdc;
-uint8_t		iLevelIdc;
+  uint8_t		uiProfileIdc;
+  uint8_t		iLevelIdc;
 //	uint8_t		uiChromaFormatIdc;
 //	uint8_t		uiChromaArrayType;		//support =1
 
 //	uint8_t		uiBitDepthLuma;         //=8, only used in decoder, encoder in general_***; it can be removed when removed general up_sample
 //	uint8_t		uiBitDepthChroma;		//=8
-/* TO BE CONTINUE: POC type 1 */
+  /* TO BE CONTINUE: POC type 1 */
 //	bool		bDeltaPicOrderAlwaysZeroFlag;
 //	bool		bGapsInFrameNumValueAllowedFlag;	//=true
 
@@ -73,16 +73,16 @@
 //	bool		bFrameMbsOnlyFlag;
 //	bool		bMbaffFlag;	// MB Adapative Frame Field
 //	bool		bDirect8x8InferenceFlag;
-bool		bFrameCroppingFlag;
+  bool		bFrameCroppingFlag;
 
 //	bool		bVuiParamPresentFlag;
 //	bool		bTimingInfoPresentFlag;
 //	bool		bFixedFrameRateFlag;
 
-bool		bConstraintSet0Flag;
-bool		bConstraintSet1Flag;
-bool		bConstraintSet2Flag;
-bool		bConstraintSet3Flag;
+  bool		bConstraintSet0Flag;
+  bool		bConstraintSet1Flag;
+  bool		bConstraintSet2Flag;
+  bool		bConstraintSet3Flag;
 //	bool		bSeparateColorPlaneFlag;  // =false,: only used in decoder, encoder in general_***; it can be removed when removed general up_sample
 
 } SWelsSPS, *PWelsSPS;
@@ -92,21 +92,21 @@
 typedef struct TagSpsSvcExt {
 //	SCropOffset	sSeqScaledRefLayer;
 
-uint8_t		iExtendedSpatialScalability;	// ESS
+  uint8_t		iExtendedSpatialScalability;	// ESS
 //	uint8_t		uiChromaPhaseXPlus1Flag;
 //	uint8_t		uiChromaPhaseYPlus1;
 //	uint8_t		uiSeqRefLayerChromaPhaseXPlus1Flag;
 //	uint8_t		uiSeqRefLayerChromaPhaseYPlus1;
 //	bool		bInterLayerDeblockingFilterCtrlPresentFlag;
-bool		bSeqTcoeffLevelPredFlag;
-bool		bAdaptiveTcoeffLevelPredFlag;
-bool		bSliceHeaderRestrictionFlag;
+  bool		bSeqTcoeffLevelPredFlag;
+  bool		bAdaptiveTcoeffLevelPredFlag;
+  bool		bSliceHeaderRestrictionFlag;
 } SSpsSvcExt, *PSpsSvcExt;
 
 /* Subset sequence parameter set syntax, refer to Page 391 in JVT X201wcm */
 typedef struct TagSubsetSps {
-SWelsSPS		pSps;
-SSpsSvcExt	sSpsSvcExt;
+  SWelsSPS		pSps;
+  SSpsSvcExt	sSpsSvcExt;
 
 //	bool		bSvcVuiParamPresentFlag;
 //	bool		bAdditionalExtension2Flag;
@@ -115,40 +115,40 @@
 
 /* Picture parameter set syntax, refer to Page 59 in JVT X201wcm */
 typedef struct TagWelsPPS {
-uint32_t	iSpsId;
-uint32_t	iPpsId;
+  uint32_t	iSpsId;
+  uint32_t	iPpsId;
 
 #if !defined(DISABLE_FMO_FEATURE)
-uint32_t	uiNumSliceGroups;
-uint32_t	uiSliceGroupMapType;
-/* uiSliceGroupMapType = 0 */
-uint32_t	uiRunLength[MAX_SLICEGROUP_IDS];
-/* uiSliceGroupMapType = 2 */
-uint32_t	uiTopLeft[MAX_SLICEGROUP_IDS];
-uint32_t	uiBottomRight[MAX_SLICEGROUP_IDS];
-/* uiSliceGroupMapType = 3, 4 or 5 */
-/* uiSliceGroupMapType = 3, 4 or 5 */
-bool		bSliceGroupChangeDirectionFlag;
-uint32_t	uiSliceGroupChangeRate;
-/* uiSliceGroupMapType = 6 */
-uint32_t	uiPicSizeInMapUnits;
-uint32_t	uiSliceGroupId[MAX_SLICEGROUP_IDS];
+  uint32_t	uiNumSliceGroups;
+  uint32_t	uiSliceGroupMapType;
+  /* uiSliceGroupMapType = 0 */
+  uint32_t	uiRunLength[MAX_SLICEGROUP_IDS];
+  /* uiSliceGroupMapType = 2 */
+  uint32_t	uiTopLeft[MAX_SLICEGROUP_IDS];
+  uint32_t	uiBottomRight[MAX_SLICEGROUP_IDS];
+  /* uiSliceGroupMapType = 3, 4 or 5 */
+  /* uiSliceGroupMapType = 3, 4 or 5 */
+  bool		bSliceGroupChangeDirectionFlag;
+  uint32_t	uiSliceGroupChangeRate;
+  /* uiSliceGroupMapType = 6 */
+  uint32_t	uiPicSizeInMapUnits;
+  uint32_t	uiSliceGroupId[MAX_SLICEGROUP_IDS];
 #endif//!DISABLE_FMO_FEATURE
 
 //	uint32_t	uiNumRefIdxL0Active;
 //	uint32_t	uiNumRefIdxL1Active;
 
-int8_t		iPicInitQp;
-int8_t		iPicInitQs;
-uint8_t		uiChromaQpIndexOffset;
+  int8_t		iPicInitQp;
+  int8_t		iPicInitQs;
+  uint8_t		uiChromaQpIndexOffset;
 
-/* potential application for High profile */
+  /* potential application for High profile */
 //	int32_t		iSecondChromaQpIndexOffset;
 //	/* potential application for High profile */
 
 //	bool		bPicOrderPresentFlag;
 
-bool		bDeblockingFilterControlPresentFlag;
+  bool		bDeblockingFilterControlPresentFlag;
 
 //	bool		bConstainedIntraPredFlag;
 //	bool		bRedundantPicCntPresentFlag;
--- a/codec/encoder/core/inc/picture.h
+++ b/codec/encoder/core/inc/picture.h
@@ -40,8 +40,7 @@
 
 namespace WelsSVCEnc {
 #define LIST_SIZE      0x10000    //(256*256)
-typedef struct TagScreenBlockFeatureStorage
-{
+typedef struct TagScreenBlockFeatureStorage {
   //Input
   uint16_t*  pFeatureOfBlockPointer;    // Pointer to pFeatureOfBlock
   int32_t    iIs16x16;      //Feature block size
@@ -49,7 +48,8 @@
 
   //Modify
   uint32_t*  pTimesOfFeatureValue;    // times of every value in Feature
-  uint16_t**  pLocationOfFeature;      // uint16_t *pLocationOfFeature[LIST_SIZE], pLocationOfFeature[i] saves all the location(x,y) whose Feature = i;
+  uint16_t**
+  pLocationOfFeature;      // uint16_t *pLocationOfFeature[LIST_SIZE], pLocationOfFeature[i] saves all the location(x,y) whose Feature = i;
   uint16_t*  pLocationPointer;  // buffer of position array
   int32_t    iActualListSize;      // actual list size
   uint32_t uiSadCostThreshold[BLOCK_SIZE_ALL];
--- a/codec/encoder/core/inc/picture_handle.h
+++ b/codec/encoder/core/inc/picture_handle.h
@@ -52,7 +52,8 @@
  * \pram	iNeedFeatureStorage		need storage for FME
  * \return	successful if effective picture pointer returned, otherwise failed with NULL
  */
-SPicture* AllocPicture (CMemoryAlign* pMa, const int32_t kiWidth, const int32_t kiHeight, bool bNeedMbInfo, int32_t iNeedFeatureStorage);
+SPicture* AllocPicture (CMemoryAlign* pMa, const int32_t kiWidth, const int32_t kiHeight, bool bNeedMbInfo,
+                        int32_t iNeedFeatureStorage);
 
 /*!
  * \brief	free picture pData planes
--- a/codec/encoder/core/inc/rc.h
+++ b/codec/encoder/core/inc/rc.h
@@ -55,7 +55,7 @@
 #define    WELS_RC_DISABLE        0
 #define    WELS_RC_GOM            1
 
-enum{
+enum {
   BITS_NORMAL,
   BITS_LIMITED,
   BITS_EXCEEDED,
--- a/codec/encoder/core/inc/ref_list_mgr_svc.h
+++ b/codec/encoder/core/inc/ref_list_mgr_svc.h
@@ -48,21 +48,21 @@
 
 namespace WelsSVCEnc {
 typedef enum {
-RECIEVE_UNKOWN = 0,
-RECIEVE_SUCCESS = 1,
-RECIEVE_FAILED = 2,
+  RECIEVE_UNKOWN = 0,
+  RECIEVE_SUCCESS = 1,
+  RECIEVE_FAILED = 2,
 } LTR_MARKING_RECEIVE_STATE;
 
 typedef enum {
-LTR_DIRECT_MARK = 0,
-LTR_DELAY_MARK = 1,
+  LTR_DIRECT_MARK = 0,
+  LTR_DELAY_MARK = 1,
 } LTR_MARKING_PROCESS_MODE;
 
 typedef enum {
-FRAME_NUM_EQUAL    = 0x01,
-FRAME_NUM_BIGGER   = 0x02,
-FRAME_NUM_SMALLER  = 0x04,
-FRAME_NUM_OVER_MAX = 0x08,
+  FRAME_NUM_EQUAL    = 0x01,
+  FRAME_NUM_BIGGER   = 0x02,
+  FRAME_NUM_SMALLER  = 0x04,
+  FRAME_NUM_OVER_MAX = 0x08,
 } COMPARE_FRAME_NUM;
 
 /*
@@ -81,7 +81,7 @@
 /*
  *	build reference picture list
  */
-bool WelsBuildRefList (void* pCtx, const int32_t kiPOC,int32_t iBestLtrRefIdx);
+bool WelsBuildRefList (void* pCtx, const int32_t kiPOC, int32_t iBestLtrRefIdx);
 
 /*
  *	update syntax for reference base related
@@ -98,7 +98,7 @@
 */
 void WelsMarkPic (void* pCtx);
 
-void InitRefListMgrFunc(SWelsFuncPtrList* pFuncList,EUsageType eUsageType);
+void InitRefListMgrFunc (SWelsFuncPtrList* pFuncList, EUsageType eUsageType);
 
 #ifdef LONG_TERM_REF_DUMP
 void DumpRef (sWelsEncCtx* ctx);
--- a/codec/encoder/core/inc/sample.h
+++ b/codec/encoder/core/inc/sample.h
@@ -47,11 +47,12 @@
 //int32_t WelsSampleSatd4x8( uint8_t *, int32_t, uint8_t *, int32_t );
 int32_t WelsSampleSatd4x4_c (uint8_t*, int32_t, uint8_t*, int32_t);
 
-int32_t WelsSampleSatdIntra4x4Combined3_c (uint8_t*, int32_t, uint8_t*, int32_t, uint8_t*, int32_t*, int32_t, int32_t, int32_t);
+int32_t WelsSampleSatdIntra4x4Combined3_c (uint8_t*, int32_t, uint8_t*, int32_t, uint8_t*, int32_t*, int32_t, int32_t,
+    int32_t);
 int32_t WelsSampleSatdIntra16x16Combined3_c (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*);
 int32_t WelsSampleSadIntra16x16Combined3_c (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*);
 int32_t WelsSampleSatdIntra8x8Combined3_c (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*,
-                                                   uint8_t*, uint8_t*);
+    uint8_t*, uint8_t*);
 
 #if defined(__cplusplus)
 extern "C" {
@@ -92,9 +93,12 @@
 
 int32_t WelsIntra16x16Combined3Satd_neon (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*);
 int32_t WelsIntra16x16Combined3Sad_neon (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*);
-int32_t WelsIntra8x8Combined3Satd_neon (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*, uint8_t*, uint8_t*);
-int32_t WelsIntra8x8Combined3Sad_neon (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*, uint8_t*, uint8_t*);
-int32_t WelsIntra4x4Combined3Satd_neon (uint8_t*, int32_t, uint8_t*, int32_t, uint8_t*, int32_t*, int32_t, int32_t, int32_t);
+int32_t WelsIntra8x8Combined3Satd_neon (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*, uint8_t*,
+                                        uint8_t*);
+int32_t WelsIntra8x8Combined3Sad_neon (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*, uint8_t*,
+                                       uint8_t*);
+int32_t WelsIntra4x4Combined3Satd_neon (uint8_t*, int32_t, uint8_t*, int32_t, uint8_t*, int32_t*, int32_t, int32_t,
+                                        int32_t);
 
 #endif
 
--- a/codec/encoder/core/inc/set_mb_syn_cavlc.h
+++ b/codec/encoder/core/inc/set_mb_syn_cavlc.h
@@ -49,11 +49,11 @@
 
 
 enum EResidualProperty {
-LUMA_DC     = 0,
-LUMA_AC     = 1,
-LUMA_4x4    = 2,
-CHROMA_DC   = 3,
-CHROMA_AC   = 4
+  LUMA_DC     = 0,
+  LUMA_AC     = 1,
+  LUMA_4x4    = 2,
+  CHROMA_DC   = 3,
+  CHROMA_AC   = 4
 };
 
 
@@ -63,7 +63,7 @@
                                         int32_t iEndIdx);
 
 typedef  struct TagCoeffFunc {
-PCavlcParamCalFunc    pfCavlcParamCal;
+  PCavlcParamCalFunc    pfCavlcParamCal;
 } SCoeffFunc;
 
 /*  For CAVLC   */
@@ -70,9 +70,9 @@
 extern SCoeffFunc    sCoeffFunc;
 
 typedef struct TagCavlcTableItem {
-uint16_t uiBits;
-uint8_t  uiLen;
-uint8_t  uiSuffixLength;
+  uint16_t uiBits;
+  uint8_t  uiLen;
+  uint8_t  uiSuffixLength;
 } SCavlcTableItem;
 
 void  InitCoeffFunc (const uint32_t uiCpuFlag);
--- a/codec/encoder/core/inc/slice_multi_threading.h
+++ b/codec/encoder/core/inc/slice_multi_threading.h
@@ -70,7 +70,8 @@
 void ReleaseMtResource (sWelsEncCtx** ppCtx);
 
 int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t kiSliceCount);
-int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, int32_t& iSliceSize);
+int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx,
+                             int32_t& iSliceSize);
 
 #if !defined(_WIN32)
 WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg);
@@ -80,7 +81,8 @@
 
 int32_t CreateSliceThreads (sWelsEncCtx* pCtx);
 
-int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLayerBsInfo,
+int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList,
+                           SLayerBSInfo* pLayerBsInfo,
                            const uint32_t kuiNumThreads/*, int32_t *iLayerNum*/, SSliceCtx* pSliceCtx, const bool kbIsDynamicSlicingMode);
 
 int32_t DynamicDetectCpuCores();
--- a/codec/encoder/core/inc/svc_base_layer_md.h
+++ b/codec/encoder/core/inc/svc_base_layer_md.h
@@ -75,9 +75,9 @@
 //void wels_md_inter_init ( SWelsMD* pMd, const uint8_t ref_idx, const bool is_highest_dlayer_flag );
 
 bool WelsMdInterJudgeBGDPskip (void* pEnc, void* pMd, SSlice* pSlice, SMB* pCurMb, SMbCache* pMbCache,
-                                 bool* bKeepSkip);
+                               bool* bKeepSkip);
 bool WelsMdInterJudgeBGDPskipFalse (void* pEnc, void* pMd, SSlice* pSlice, SMB* pCurMb, SMbCache* pMbCache,
-                                      bool* bKeepSkip);
+                                    bool* bKeepSkip);
 
 void WelsMdInterUpdateBGDInfo (SDqLayer* pCurLayer,  SMB* pCurMb, const bool kbCollocatedPredFlag,
                                const int32_t kiRefPictureType);
@@ -85,7 +85,7 @@
                                    const int32_t kiRefPictureType);
 
 bool WelsMdInterJudgePskip (sWelsEncCtx* pEncCtx, SWelsMD* pWelsMd, SSlice* pSlice, SMB* pCurMb, SMbCache* pMbCache,
-                              bool bTrySkip);
+                            bool bTrySkip);
 void WelsMdInterUpdatePskip (SDqLayer* pCurDqLayer, SSlice* pSlice, SMB* pCurMb, SMbCache* pMbCache);
 void WelsMdInterDecidedPskip (sWelsEncCtx* pEncCtx, SSlice* pSlice, SMB* pCurMb, SMbCache* pMbCache);
 
--- a/codec/encoder/core/inc/svc_enc_frame.h
+++ b/codec/encoder/core/inc/svc_enc_frame.h
@@ -58,17 +58,17 @@
 typedef struct TagDqLayer	SDqLayer;
 typedef SDqLayer*            pDqLayer;
 
-typedef struct TagFeatureSearchPreparation{
+typedef struct TagFeatureSearchPreparation {
   SScreenBlockFeatureStorage*	pRefBlockFeature;//point the the ref frame storage
 
   uint16_t*	pFeatureOfBlock;		// Feature of every block (8x8), begin with the point
-	uint8_t      uiFeatureStrategyIndex;// index of hash strategy
+  uint8_t      uiFeatureStrategyIndex;// index of hash strategy
 
-	/* for FME frame-level switch */
-	bool bFMESwitchFlag;
-	uint8_t uiFMEGoodFrameCount;
-	int32_t iHighFreMbCount;
-}SFeatureSearchPreparation;//maintain only one
+  /* for FME frame-level switch */
+  bool bFMESwitchFlag;
+  uint8_t uiFMEGoodFrameCount;
+  int32_t iHighFreMbCount;
+} SFeatureSearchPreparation; //maintain only one
 
 typedef struct TagLayerInfo {
   SNalUnitHeaderExt		sNalHeaderExt;
--- a/codec/encoder/core/inc/svc_enc_golomb.h
+++ b/codec/encoder/core/inc/svc_enc_golomb.h
@@ -93,83 +93,83 @@
  *	Get size of unsigned exp golomb codes
  */
 static inline uint32_t BsSizeUE (const uint32_t kiValue) {
-if (256 > kiValue) {
-  return g_uiGolombUELength[kiValue];
-} else {
-  uint32_t n = 0;
-  uint32_t iTmpValue = kiValue + 1;
+  if (256 > kiValue) {
+    return g_uiGolombUELength[kiValue];
+  } else {
+    uint32_t n = 0;
+    uint32_t iTmpValue = kiValue + 1;
 
-  if (iTmpValue & 0xffff0000) {
-    iTmpValue >>= 16;
-    n += 16;
-  }
-  if (iTmpValue & 0xff00) {
-    iTmpValue >>= 8;
-    n += 8;
-  }
+    if (iTmpValue & 0xffff0000) {
+      iTmpValue >>= 16;
+      n += 16;
+    }
+    if (iTmpValue & 0xff00) {
+      iTmpValue >>= 8;
+      n += 8;
+    }
 
-  //n += (g_uiGolombUELength[iTmpValue] >> 1);
-  n += (g_uiGolombUELength[iTmpValue - 1] >> 1);
-  return ((n << 1) + 1);
+    //n += (g_uiGolombUELength[iTmpValue] >> 1);
+    n += (g_uiGolombUELength[iTmpValue - 1] >> 1);
+    return ((n << 1) + 1);
 
+  }
 }
-}
 
 /*
  *	Get size of signed exp golomb codes
  */
 static inline uint32_t BsSizeSE (const int32_t kiValue) {
-uint32_t iTmpValue;
-if (0 == kiValue) {
-  return 1;
-} else if (0 < kiValue) {
-  iTmpValue = (kiValue << 1) - 1;
-  return BsSizeUE (iTmpValue);
-} else {
-  iTmpValue = ((-kiValue) << 1);
-  return BsSizeUE (iTmpValue);
+  uint32_t iTmpValue;
+  if (0 == kiValue) {
+    return 1;
+  } else if (0 < kiValue) {
+    iTmpValue = (kiValue << 1) - 1;
+    return BsSizeUE (iTmpValue);
+  } else {
+    iTmpValue = ((-kiValue) << 1);
+    return BsSizeUE (iTmpValue);
+  }
 }
-}
 
 /*
  *	Get size of truncated exp golomb codes
  */
 static inline int32_t BsSizeTE (const int32_t kiX, const int32_t kiValue) {
-return 0;
+  return 0;
 }
 
 
 
 static inline int32_t BsWriteBits (SBitStringAux* pBs, int32_t n, const uint32_t kuiValue) {
-if (n < pBs->iLeftBits) {
-  pBs->uiCurBits = (pBs->uiCurBits << n) | kuiValue;
-  pBs->iLeftBits -= n;
-} else {
-  n -= pBs->iLeftBits;
-  pBs->uiCurBits = (pBs->uiCurBits << pBs->iLeftBits) | (kuiValue >> n);
-  WRITE_BE_32(pBs->pBufPtr, pBs->uiCurBits);
-  pBs->pBufPtr += 4;
-  pBs->uiCurBits = kuiValue & ((1 << n) - 1);
-  pBs->iLeftBits = 32 - n;
+  if (n < pBs->iLeftBits) {
+    pBs->uiCurBits = (pBs->uiCurBits << n) | kuiValue;
+    pBs->iLeftBits -= n;
+  } else {
+    n -= pBs->iLeftBits;
+    pBs->uiCurBits = (pBs->uiCurBits << pBs->iLeftBits) | (kuiValue >> n);
+    WRITE_BE_32 (pBs->pBufPtr, pBs->uiCurBits);
+    pBs->pBufPtr += 4;
+    pBs->uiCurBits = kuiValue & ((1 << n) - 1);
+    pBs->iLeftBits = 32 - n;
+  }
+  return 0;
 }
-return 0;
-}
 
 /*
  *	Write 1 bit
  */
 static inline int32_t BsWriteOneBit (SBitStringAux* pBs, const uint32_t kuiValue) {
-BsWriteBits (pBs, 1, kuiValue);
+  BsWriteBits (pBs, 1, kuiValue);
 
-return 0;
+  return 0;
 }
 
 
 static inline void BsFlush (SBitStringAux* pBs) {
-WRITE_BE_32(pBs->pBufPtr, pBs->uiCurBits << pBs->iLeftBits);
-pBs->pBufPtr += 4 - pBs->iLeftBits / 8;
-pBs->iLeftBits = 32;
-pBs->uiCurBits = 0;	//  for future writing safe, 5/19/2010
+  WRITE_BE_32 (pBs->pBufPtr, pBs->uiCurBits << pBs->iLeftBits);
+  pBs->pBufPtr += 4 - pBs->iLeftBits / 8;
+  pBs->iLeftBits = 32;
+  pBs->uiCurBits = 0;	//  for future writing safe, 5/19/2010
 }
 
 /*
@@ -176,56 +176,56 @@
  *	Write unsigned exp golomb codes
  */
 static inline void BsWriteUE (SBitStringAux* pBs, const uint32_t kuiValue) {
-uint32_t iTmpValue = kuiValue + 1;
-if (256 > kuiValue)	{
-  BsWriteBits (pBs, g_uiGolombUELength[kuiValue], kuiValue + 1);
-} else {
-  uint32_t n = 0;
+  uint32_t iTmpValue = kuiValue + 1;
+  if (256 > kuiValue)	{
+    BsWriteBits (pBs, g_uiGolombUELength[kuiValue], kuiValue + 1);
+  } else {
+    uint32_t n = 0;
 
-  if (iTmpValue & 0xffff0000) {
-    iTmpValue >>= 16;
-    n += 16;
-  }
-  if (iTmpValue & 0xff00) {
-    iTmpValue >>= 8;
-    n += 8;
-  }
+    if (iTmpValue & 0xffff0000) {
+      iTmpValue >>= 16;
+      n += 16;
+    }
+    if (iTmpValue & 0xff00) {
+      iTmpValue >>= 8;
+      n += 8;
+    }
 
-  //n += (g_uiGolombUELength[iTmpValue] >> 1);
+    //n += (g_uiGolombUELength[iTmpValue] >> 1);
 
-  n += (g_uiGolombUELength[iTmpValue - 1] >> 1);
-  BsWriteBits (pBs, (n << 1) + 1, kuiValue + 1);
+    n += (g_uiGolombUELength[iTmpValue - 1] >> 1);
+    BsWriteBits (pBs, (n << 1) + 1, kuiValue + 1);
+  }
+  return;
 }
-return;
-}
 
 /*
  *	Write signed exp golomb codes
  */
 static inline void BsWriteSE (SBitStringAux* pBs, int32_t iValue) {
-uint32_t iTmpValue;
-if (0 == iValue) {
-  BsWriteOneBit (pBs, 1);
-} else if (0 < iValue) {
-  iTmpValue = (iValue << 1) - 1;
-  BsWriteUE (pBs, iTmpValue);
-} else {
-  iTmpValue = ((-iValue) << 1);
-  BsWriteUE (pBs, iTmpValue);
+  uint32_t iTmpValue;
+  if (0 == iValue) {
+    BsWriteOneBit (pBs, 1);
+  } else if (0 < iValue) {
+    iTmpValue = (iValue << 1) - 1;
+    BsWriteUE (pBs, iTmpValue);
+  } else {
+    iTmpValue = ((-iValue) << 1);
+    BsWriteUE (pBs, iTmpValue);
+  }
+  return;
 }
-return;
-}
 
 /*
  *	Write truncated exp golomb codes
  */
 static inline void BsWriteTE (SBitStringAux* pBs, const int32_t kiX, const uint32_t kuiValue) {
-if (1 == kiX) {
-  BsWriteOneBit (pBs, !kuiValue);
-} else {
-  BsWriteUE (pBs, kuiValue);
+  if (1 == kiX) {
+    BsWriteOneBit (pBs, !kuiValue);
+  } else {
+    BsWriteUE (pBs, kuiValue);
+  }
 }
-}
 
 
 /*
@@ -232,18 +232,18 @@
  *	Write RBSP trailing bits
  */
 static inline void BsRbspTrailingBits (SBitStringAux* pBs) {
-BsWriteOneBit (pBs, 1);
-BsFlush (pBs);
+  BsWriteOneBit (pBs, 1);
+  BsFlush (pBs);
 }
 
 
 static inline bool   BsCheckByteAlign (SBitStringAux* pBs) {
-return ! (pBs->iLeftBits & 0x7);
+  return ! (pBs->iLeftBits & 0x7);
 }
 
 
 static inline int32_t BsGetBitsPos (SBitStringAux* pBs) {
-return (((pBs->pBufPtr - pBs->pBuf) << 3) + 32 - pBs->iLeftBits);
+  return (((pBs->pBufPtr - pBs->pBuf) << 3) + 32 - pBs->iLeftBits);
 }
 
 }
--- a/codec/encoder/core/inc/svc_enc_macroblock.h
+++ b/codec/encoder/core/inc/svc_enc_macroblock.h
@@ -47,29 +47,29 @@
 // keep the most essential level pData structure be 64 Bytes, which matches cache line size; if so, the order with structure maybe negligible.
 // pls take care when modify MB structure size
 typedef struct TagMB {
-/*************************mb_layer() syntax and generated********************************/
-/*mb_layer():*/
-Mb_Type		uiMbType;	// including MB detailed partition type, number and type of reference list
-int16_t		iMbXY;		// offset position of MB top left point based
-int16_t		iMbX;		// position of MB in horizontal axis
-int16_t		iMbY;		// position of MB in vertical axis
+  /*************************mb_layer() syntax and generated********************************/
+  /*mb_layer():*/
+  Mb_Type		uiMbType;	// including MB detailed partition type, number and type of reference list
+  int16_t		iMbXY;		// offset position of MB top left point based
+  int16_t		iMbX;		// position of MB in horizontal axis
+  int16_t		iMbY;		// position of MB in vertical axis
 
-uint8_t		uiNeighborAvail;	// avail && same_slice: LEFT_MB_POS:0x01, TOP_MB_POS:0x02, TOPRIGHT_MB_POS = 0x04 ,TOPLEFT_MB_POS = 0x08;
-uint8_t		uiCbp;
+  uint8_t		uiNeighborAvail;	// avail && same_slice: LEFT_MB_POS:0x01, TOP_MB_POS:0x02, TOPRIGHT_MB_POS = 0x04 ,TOPLEFT_MB_POS = 0x08;
+  uint8_t		uiCbp;
 
-SMVUnitXY*	sMv;
-int8_t*		pRefIndex;
+  SMVUnitXY*	sMv;
+  int8_t*		pRefIndex;
 
-int32_t*     pSadCost;				// mb sad. set to 0 for intra mb
-int8_t*      pIntra4x4PredMode;	// [MB_BLOCK4x4_NUM]
-int8_t*      pNonZeroCount;		// [MB_LUMA_CHROMA_BLOCK4x4_NUM]
+  int32_t*     pSadCost;				// mb sad. set to 0 for intra mb
+  int8_t*      pIntra4x4PredMode;	// [MB_BLOCK4x4_NUM]
+  int8_t*      pNonZeroCount;		// [MB_LUMA_CHROMA_BLOCK4x4_NUM]
 
-SMVUnitXY	sP16x16Mv;
+  SMVUnitXY	sP16x16Mv;
 
-uint8_t		uiLumaQp;		// uiLumaQp: pPps->iInitialQp + sSliceHeader->delta_qp + mb->dquant.
-uint8_t		uiChromaQp;
-uint8_t		uiSliceIdc;	// AVC: pFirstMbInSlice?; SVC: (pFirstMbInSlice << 7) | ((uiDependencyId << 4) | uiQualityId);
-uint8_t		reserved_filling_bytes[1];	// filling bytes reserved to make structure aligned with 4 bytes, higher cache hit on less structure size by 2 cache lines( 2 * 64 bytes) once hit
+  uint8_t		uiLumaQp;		// uiLumaQp: pPps->iInitialQp + sSliceHeader->delta_qp + mb->dquant.
+  uint8_t		uiChromaQp;
+  uint8_t		uiSliceIdc;	// AVC: pFirstMbInSlice?; SVC: (pFirstMbInSlice << 7) | ((uiDependencyId << 4) | uiQualityId);
+  uint8_t		reserved_filling_bytes[1];	// filling bytes reserved to make structure aligned with 4 bytes, higher cache hit on less structure size by 2 cache lines( 2 * 64 bytes) once hit
 } SMB, *PMb;
 
 }
--- a/codec/encoder/core/inc/svc_enc_slice_segment.h
+++ b/codec/encoder/core/inc/svc_enc_slice_segment.h
@@ -73,28 +73,28 @@
  */
 /* Single/multiple slices */
 typedef struct SlicepEncCtx_s {
-SliceModeEnum		uiSliceMode;			/* 0: single slice in frame; 1: multiple slices in frame; */
-int16_t			iMbWidth;			/* width of picture size in mb */
-int16_t			iMbHeight;			/* height of picture size in mb */
-int16_t			iSliceNumInFrame;	/* count number of slices in frame; */
-int32_t			iMbNumInFrame;	/* count number of MBs in frame */
-uint8_t*			pOverallMbMap;	/* overall MB map in frame, store virtual slice idc; */
-int16_t*			pFirstMbInSlice;	/* first MB address top-left based in every slice respectively; */
-int32_t*			pCountMbNumInSlice;	/* count number of MBs in every slice respectively; */
-uint32_t		uiSliceSizeConstraint;/*in byte*/
-int32_t			iMaxSliceNumConstraint;/*maximal number of slices constraint*/
+  SliceModeEnum		uiSliceMode;			/* 0: single slice in frame; 1: multiple slices in frame; */
+  int16_t			iMbWidth;			/* width of picture size in mb */
+  int16_t			iMbHeight;			/* height of picture size in mb */
+  int16_t			iSliceNumInFrame;	/* count number of slices in frame; */
+  int32_t			iMbNumInFrame;	/* count number of MBs in frame */
+  uint8_t*			pOverallMbMap;	/* overall MB map in frame, store virtual slice idc; */
+  int16_t*			pFirstMbInSlice;	/* first MB address top-left based in every slice respectively; */
+  int32_t*			pCountMbNumInSlice;	/* count number of MBs in every slice respectively; */
+  uint32_t		uiSliceSizeConstraint;/*in byte*/
+  int32_t			iMaxSliceNumConstraint;/*maximal number of slices constraint*/
 } SSliceCtx;
 
 
 typedef struct TagDynamicSlicingStack {
-int32_t		iStartPos;
-int32_t		iCurrentPos;
+  int32_t		iStartPos;
+  int32_t		iCurrentPos;
 
-uint8_t*		pBsStackBufPtr;	// current writing position
-uint32_t    uiBsStackCurBits;
-int32_t		iBsStackLeftBits;
+  uint8_t*		pBsStackBufPtr;	// current writing position
+  uint32_t    uiBsStackCurBits;
+  int32_t		iBsStackLeftBits;
 
-int32_t		iMbSkipRunStack;
+  int32_t		iMbSkipRunStack;
 } SDynamicSlicingStack;
 
 /*!
--- a/codec/encoder/core/inc/svc_encode_slice.h
+++ b/codec/encoder/core/inc/svc_encode_slice.h
@@ -83,7 +83,7 @@
 int32_t WelsCodePOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice);
 
 int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx,
-                       const int32_t keNalType);
+                          const int32_t keNalType);
 
 void WelsInitSliceEncodingFuncs (uint32_t uiCpuFlag);
 
@@ -94,12 +94,12 @@
 void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
                        int32_t iNextSliceFirstMbIdx, const int32_t kiLastMbIdxInPartition);
 int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pMd,
-                        const int32_t kiSliceFirstMbXY);	// for inter non-dynamic slice
+                           const int32_t kiSliceFirstMbXY);	// for inter non-dynamic slice
 int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pMd,
-                                        const int32_t kiSliceFirstMbXY);	// for inter dynamic slice
+    const int32_t kiSliceFirstMbXY);	// for inter dynamic slice
 
 
 bool DynSlcJudgeSliceBoundaryStepBack (void* pEncCtx, void* pSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
-    SDynamicSlicingStack* pDss);
+                                       SDynamicSlicingStack* pDss);
 }
 #endif //SVC_ENCODE_SLICE_H__
--- a/codec/encoder/core/inc/svc_motion_estimate.h
+++ b/codec/encoder/core/inc/svc_motion_estimate.h
@@ -61,70 +61,71 @@
   ME_FULL    = 0x10,  // FULL
 
   // derived ME methods combination
-  ME_DIA_CROSS    =  (ME_DIA|ME_CROSS),    // DIA+CROSS
-  ME_DIA_CROSS_FME  =  (ME_DIA_CROSS|ME_FME),  // DIA+CROSS+FME
+  ME_DIA_CROSS    = (ME_DIA | ME_CROSS),   // DIA+CROSS
+  ME_DIA_CROSS_FME  = (ME_DIA_CROSS | ME_FME), // DIA+CROSS+FME
 };
 
 union SadPredISatdUnit {
-uint32_t  uiSadPred;
-uint32_t  uiSatd;    //reuse the sad_pred as a temp satd pData
+  uint32_t  uiSadPred;
+  uint32_t  uiSatd;    //reuse the sad_pred as a temp satd pData
 };
 typedef struct TagWelsME {
-/* input */
-uint16_t*          pMvdCost;
-union SadPredISatdUnit  uSadPredISatd; //reuse the sad_pred as a temp pData
-uint32_t          uiSadCost;  //used by ME and RC //max SAD should be max_delta*size+lambda*mvdsize = 255*256+91*33*2 = 65280 + 6006 = 71286 > (2^16)-1 = 65535
-uint32_t          uiSatdCost; /* satd + lm * nbits */
-uint32_t          uiSadCostThreshold;
-int32_t            iCurMeBlockPixX;
-int32_t            iCurMeBlockPixY;
-uint8_t            uiBlockSize;   /* BLOCK_WxH */
-uint8_t            uiReserved;
+  /* input */
+  uint16_t*          pMvdCost;
+  union SadPredISatdUnit  uSadPredISatd; //reuse the sad_pred as a temp pData
+  uint32_t
+  uiSadCost;  //used by ME and RC //max SAD should be max_delta*size+lambda*mvdsize = 255*256+91*33*2 = 65280 + 6006 = 71286 > (2^16)-1 = 65535
+  uint32_t          uiSatdCost; /* satd + lm * nbits */
+  uint32_t          uiSadCostThreshold;
+  int32_t            iCurMeBlockPixX;
+  int32_t            iCurMeBlockPixY;
+  uint8_t            uiBlockSize;   /* BLOCK_WxH */
+  uint8_t            uiReserved;
 
-uint8_t*            pEncMb;
-uint8_t*            pRefMb;
-uint8_t*            pColoRefMb;
+  uint8_t*            pEncMb;
+  uint8_t*            pRefMb;
+  uint8_t*            pColoRefMb;
 
-SMVUnitXY          sMvp;
-SMVUnitXY          sMvBase;
-SMVUnitXY          sDirectionalMv;
+  SMVUnitXY          sMvp;
+  SMVUnitXY          sMvBase;
+  SMVUnitXY          sDirectionalMv;
 
-/* output */
-SMVUnitXY          sMv;
+  /* output */
+  SMVUnitXY          sMv;
 } SWelsME;
 
-typedef struct TagFeatureSearchIn{
-    PSampleSadSatdCostFunc pSad;
+typedef struct TagFeatureSearchIn {
+  PSampleSadSatdCostFunc pSad;
 
-    uint32_t* pTimesOfFeature;
-    uint16_t** pQpelLocationOfFeature;
-    uint16_t *pMvdCostX;
-    uint16_t *pMvdCostY;
+  uint32_t* pTimesOfFeature;
+  uint16_t** pQpelLocationOfFeature;
+  uint16_t* pMvdCostX;
+  uint16_t* pMvdCostY;
 
-    uint8_t* pEnc;
-    uint8_t* pColoRef;
-    int32_t iEncStride;
-    int32_t iRefStride;
-    uint16_t uiSadCostThresh;
+  uint8_t* pEnc;
+  uint8_t* pColoRef;
+  int32_t iEncStride;
+  int32_t iRefStride;
+  uint16_t uiSadCostThresh;
 
-    int32_t iFeatureOfCurrent;
+  int32_t iFeatureOfCurrent;
 
-    int32_t iCurPixX;
-    int32_t iCurPixY;
-    int32_t iCurPixXQpel;
-    int32_t iCurPixYQpel;
+  int32_t iCurPixX;
+  int32_t iCurPixY;
+  int32_t iCurPixXQpel;
+  int32_t iCurPixYQpel;
 
-    int32_t iMinQpelX;
-    int32_t iMinQpelY;
-    int32_t iMaxQpelX;
-    int32_t iMaxQpelY;
-}SFeatureSearchIn;
+  int32_t iMinQpelX;
+  int32_t iMinQpelY;
+  int32_t iMaxQpelX;
+  int32_t iMaxQpelY;
+} SFeatureSearchIn;
 
-typedef struct TagFeatureSearchOut{
-    SMVUnitXY sBestMv;
-    uint32_t uiBestSadCost;
-    uint8_t* pBestRef;
-}SFeatureSearchOut;
+typedef struct TagFeatureSearchOut {
+  SMVUnitXY sBestMv;
+  uint32_t uiBestSadCost;
+  uint8_t* pBestRef;
+} SFeatureSearchOut;
 
 #define  COST_MVD(table, mx, my)  (table[mx] + table[my])
 extern const int32_t QStepx16ByQp[52];
@@ -131,7 +132,7 @@
 
 // Function definitions below
 
-void WelsInitMeFunc( SWelsFuncPtrList* pFuncList, uint32_t uiCpuFlag, bool bScreenContent );
+void WelsInitMeFunc (SWelsFuncPtrList* pFuncList, uint32_t uiCpuFlag, bool bScreenContent);
 
 /*!
  * \brief  BL mb motion estimate search
@@ -179,45 +180,47 @@
  *
  * \return  NONE
  */
-void WelsDiamondSearch (SWelsFuncPtrList* pFuncList, void* pLpme, void* pLpslice, const int32_t kiEncStride, const int32_t kiRefStride);
+void WelsDiamondSearch (SWelsFuncPtrList* pFuncList, void* pLpme, void* pLpslice, const int32_t kiEncStride,
+                        const int32_t kiRefStride);
 
 bool WelsMeSadCostSelect (int32_t* pSadCost, const uint16_t* kpMvdCost, int32_t* pBestCost, const int32_t kiDx,
-                            const int32_t kiDy, int32_t* pIx, int32_t* pIy);
+                          const int32_t kiDy, int32_t* pIx, int32_t* pIy);
 
-void CalculateSatdCost( PSampleSadSatdCostFunc pSatd, void * vpMe, const int32_t kiEncStride, const int32_t kiRefStride );
-void NotCalculateSatdCost( PSampleSadSatdCostFunc pSatd, void * vpMe, const int32_t kiEncStride, const int32_t kiRefStride );
-bool CheckDirectionalMv(PSampleSadSatdCostFunc pSad, void * vpMe,
-                      const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
-                      int32_t& iBestSadCost);
-bool CheckDirectionalMvFalse(PSampleSadSatdCostFunc pSad, void * vpMe,
-                      const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
-                      int32_t& iBestSadCost);
+void CalculateSatdCost (PSampleSadSatdCostFunc pSatd, void* vpMe, const int32_t kiEncStride, const int32_t kiRefStride);
+void NotCalculateSatdCost (PSampleSadSatdCostFunc pSatd, void* vpMe, const int32_t kiEncStride,
+                           const int32_t kiRefStride);
+bool CheckDirectionalMv (PSampleSadSatdCostFunc pSad, void* vpMe,
+                         const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
+                         int32_t& iBestSadCost);
+bool CheckDirectionalMvFalse (PSampleSadSatdCostFunc pSad, void* vpMe,
+                              const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
+                              int32_t& iBestSadCost);
 
 // Cross Search Basics
-void LineFullSearch_c(  SWelsFuncPtrList *pFuncList, SWelsME *pMe,
-                        uint16_t* pMvdTable, const int32_t kiFixedMvd,
-                        const int32_t kiEncStride, const int32_t kiRefStride,
-                        const int32_t kiMinPos, const int32_t kiMaxPos,
-                        const bool bVerticalSearch );
+void LineFullSearch_c (SWelsFuncPtrList* pFuncList, SWelsME* pMe,
+                       uint16_t* pMvdTable, const int32_t kiFixedMvd,
+                       const int32_t kiEncStride, const int32_t kiRefStride,
+                       const int32_t kiMinPos, const int32_t kiMaxPos,
+                       const bool bVerticalSearch);
 #ifdef X86_ASM
 extern "C"
 {
-uint32_t SampleSad8x8Hor8_sse41 (uint8_t*, int32_t, uint8_t*, int32_t, uint16_t*, int32_t*);
-uint32_t SampleSad16x16Hor8_sse41 (uint8_t*, int32_t, uint8_t*, int32_t, uint16_t*, int32_t*);
+  uint32_t SampleSad8x8Hor8_sse41 (uint8_t*, int32_t, uint8_t*, int32_t, uint16_t*, int32_t*);
+  uint32_t SampleSad16x16Hor8_sse41 (uint8_t*, int32_t, uint8_t*, int32_t, uint16_t*, int32_t*);
 }
 
-void VerticalFullSearchUsingSSE41( SWelsFuncPtrList *pFuncList, SWelsME *pMe,
-                            uint16_t* pMvdTable, const int32_t kiFixedMvd,
-                            const int32_t kiEncStride, const int32_t kiRefStride,
-                          const int32_t kiMinPos, const int32_t kiMaxPos,
-                          const bool bVerticalSearch );
-void HorizontalFullSearchUsingSSE41( SWelsFuncPtrList *pFuncList, SWelsME *pMe,
-                                      uint16_t* pMvdTable, const int32_t kiFixedMvd,
-                                      const int32_t kiEncStride, const int32_t kiRefStride,
-                                      const int32_t kiMinPos, const int32_t kiMaxPos,
-                                      const bool bVerticalSearch );
+void VerticalFullSearchUsingSSE41 (SWelsFuncPtrList* pFuncList, SWelsME* pMe,
+                                   uint16_t* pMvdTable, const int32_t kiFixedMvd,
+                                   const int32_t kiEncStride, const int32_t kiRefStride,
+                                   const int32_t kiMinPos, const int32_t kiMaxPos,
+                                   const bool bVerticalSearch);
+void HorizontalFullSearchUsingSSE41 (SWelsFuncPtrList* pFuncList, SWelsME* pMe,
+                                     uint16_t* pMvdTable, const int32_t kiFixedMvd,
+                                     const int32_t kiEncStride, const int32_t kiRefStride,
+                                     const int32_t kiMinPos, const int32_t kiMaxPos,
+                                     const bool bVerticalSearch);
 #endif
-void WelsMotionCrossSearch(SWelsFuncPtrList *pFuncList,  SDqLayer* pCurLayer, SWelsME * pMe, const SSlice* pSlice);
+void WelsMotionCrossSearch (SWelsFuncPtrList* pFuncList,  SDqLayer* pCurLayer, SWelsME* pMe, const SSlice* pSlice);
 
 // Feature Search Basics
 #define LIST_SIZE_SUM_16x16 0x0FF01  //(256*255+1)
@@ -228,48 +231,53 @@
 #define FMESWITCH_DEFAULT_GOODFRAME_NUM (2)
 #define FMESWITCH_MBSAD_THRESHOLD   30 // empirically set.
 
-int32_t SumOf8x8SingleBlock_c(uint8_t* pRef, const int32_t kiRefStride);
-int32_t SumOf16x16SingleBlock_c(uint8_t* pRef, const int32_t kiRefStride);
-void SumOf8x8BlockOfFrame_c(uint8_t *pRefPicture, const int32_t kiWidth, const int32_t kiHeight, const int32_t kiRefStride,
-                                              uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]);
-void SumOf16x16BlockOfFrame_c(uint8_t *pRefPicture, const int32_t kiWidth, const int32_t kiHeight, const int32_t kiRefStride,
-                                              uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]);
-int32_t RequestScreenBlockFeatureStorage( CMemoryAlign *pMa, const int32_t kiFrameWidth,  const int32_t kiFrameHeight, const int32_t iNeedFeatureStorage,
-                                         SScreenBlockFeatureStorage* pScreenBlockFeatureStorage);
-int32_t ReleaseScreenBlockFeatureStorage( CMemoryAlign *pMa, SScreenBlockFeatureStorage* pScreenBlockFeatureStorage );
-int32_t RequestFeatureSearchPreparation( CMemoryAlign *pMa, const int32_t kiFrameWidth,  const int32_t kiFrameHeight, const int32_t iNeedFeatureStorage,
-                                         SFeatureSearchPreparation* pFeatureSearchPreparation);
-int32_t ReleaseFeatureSearchPreparation( CMemoryAlign *pMa, uint16_t*& pFeatureOfBlock);
+int32_t SumOf8x8SingleBlock_c (uint8_t* pRef, const int32_t kiRefStride);
+int32_t SumOf16x16SingleBlock_c (uint8_t* pRef, const int32_t kiRefStride);
+void SumOf8x8BlockOfFrame_c (uint8_t* pRefPicture, const int32_t kiWidth, const int32_t kiHeight,
+                             const int32_t kiRefStride,
+                             uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]);
+void SumOf16x16BlockOfFrame_c (uint8_t* pRefPicture, const int32_t kiWidth, const int32_t kiHeight,
+                               const int32_t kiRefStride,
+                               uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]);
+int32_t RequestScreenBlockFeatureStorage (CMemoryAlign* pMa, const int32_t kiFrameWidth,  const int32_t kiFrameHeight,
+    const int32_t iNeedFeatureStorage,
+    SScreenBlockFeatureStorage* pScreenBlockFeatureStorage);
+int32_t ReleaseScreenBlockFeatureStorage (CMemoryAlign* pMa, SScreenBlockFeatureStorage* pScreenBlockFeatureStorage);
+int32_t RequestFeatureSearchPreparation (CMemoryAlign* pMa, const int32_t kiFrameWidth,  const int32_t kiFrameHeight,
+    const int32_t iNeedFeatureStorage,
+    SFeatureSearchPreparation* pFeatureSearchPreparation);
+int32_t ReleaseFeatureSearchPreparation (CMemoryAlign* pMa, uint16_t*& pFeatureOfBlock);
 
 #define FMESWITCH_DEFAULT_GOODFRAME_NUM (2)
 #define FME_DEFAULT_FEATURE_INDEX (0)
 
-void PerformFMEPreprocess( SWelsFuncPtrList *pFunc, SPicture* pRef, uint16_t* pFeatureOfBlock,
-                          SScreenBlockFeatureStorage* pScreenBlockFeatureStorage);
-void UpdateFMESwitch(SDqLayer* pCurLayer);
-void UpdateFMESwitchNull(SDqLayer* pCurLayer);
+void PerformFMEPreprocess (SWelsFuncPtrList* pFunc, SPicture* pRef, uint16_t* pFeatureOfBlock,
+                           SScreenBlockFeatureStorage* pScreenBlockFeatureStorage);
+void UpdateFMESwitch (SDqLayer* pCurLayer);
+void UpdateFMESwitchNull (SDqLayer* pCurLayer);
 
 //inline functions
-inline void SetMvWithinIntegerMvRange( const int32_t kiMbWidth, const int32_t kiMbHeight, const int32_t kiMbX, const int32_t kiMbY,
-                        const int32_t kiMaxMvRange,
-                        SMVUnitXY* pMvMin, SMVUnitXY* pMvMax) {
-  pMvMin->iMvX = WELS_MAX(-1*((kiMbX + 1)<<4) + INTPEL_NEEDED_MARGIN, -1*kiMaxMvRange);
-  pMvMin->iMvY = WELS_MAX(-1*((kiMbY + 1)<<4) + INTPEL_NEEDED_MARGIN, -1*kiMaxMvRange);
-  pMvMax->iMvX = WELS_MIN( ((kiMbWidth - kiMbX)<<4) - INTPEL_NEEDED_MARGIN, kiMaxMvRange);
-  pMvMax->iMvY = WELS_MIN( ((kiMbHeight - kiMbY)<<4) - INTPEL_NEEDED_MARGIN, kiMaxMvRange);
+inline void SetMvWithinIntegerMvRange (const int32_t kiMbWidth, const int32_t kiMbHeight, const int32_t kiMbX,
+                                       const int32_t kiMbY,
+                                       const int32_t kiMaxMvRange,
+                                       SMVUnitXY* pMvMin, SMVUnitXY* pMvMax) {
+  pMvMin->iMvX = WELS_MAX (-1 * ((kiMbX + 1) << 4) + INTPEL_NEEDED_MARGIN, -1 * kiMaxMvRange);
+  pMvMin->iMvY = WELS_MAX (-1 * ((kiMbY + 1) << 4) + INTPEL_NEEDED_MARGIN, -1 * kiMaxMvRange);
+  pMvMax->iMvX = WELS_MIN (((kiMbWidth - kiMbX) << 4) - INTPEL_NEEDED_MARGIN, kiMaxMvRange);
+  pMvMax->iMvY = WELS_MIN (((kiMbHeight - kiMbY) << 4) - INTPEL_NEEDED_MARGIN, kiMaxMvRange);
 }
 
-inline bool CheckMvInRange( const int16_t kiCurrentMv, const int16_t kiMinMv, const int16_t kiMaxMv ) {
+inline bool CheckMvInRange (const int16_t kiCurrentMv, const int16_t kiMinMv, const int16_t kiMaxMv) {
   return ((kiCurrentMv >= kiMinMv) && (kiCurrentMv < kiMaxMv));
 }
-inline bool CheckMvInRange( const SMVUnitXY ksCurrentMv, const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv ) {
-  return (CheckMvInRange(ksCurrentMv.iMvX, ksMinMv.iMvX, ksMaxMv.iMvX)
-    && CheckMvInRange(ksCurrentMv.iMvY, ksMinMv.iMvY, ksMaxMv.iMvY));
+inline bool CheckMvInRange (const SMVUnitXY ksCurrentMv, const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv) {
+  return (CheckMvInRange (ksCurrentMv.iMvX, ksMinMv.iMvX, ksMaxMv.iMvX)
+          && CheckMvInRange (ksCurrentMv.iMvY, ksMinMv.iMvY, ksMaxMv.iMvY));
 }
 //FME switch related
-inline bool CalcFMESwitchFlag(const uint8_t uiFMEGoodFrameCount, const int32_t iHighFreMbPrecentage,
-       const int32_t iAvgMbSAD, const bool bScrollingDetected ) {
-  return ( bScrollingDetected ||( uiFMEGoodFrameCount>0 && iAvgMbSAD > FMESWITCH_MBSAD_THRESHOLD ) );
+inline bool CalcFMESwitchFlag (const uint8_t uiFMEGoodFrameCount, const int32_t iHighFreMbPrecentage,
+                               const int32_t iAvgMbSAD, const bool bScrollingDetected) {
+  return (bScrollingDetected || (uiFMEGoodFrameCount > 0 && iAvgMbSAD > FMESWITCH_MBSAD_THRESHOLD));
   //TODO: add the logic of iHighFreMbPrecentage
   //return ( iHighFreMbPrecentage > 2
   //            && ( bScrollingDetected || iHighFreMbPrecentage >15
--- a/codec/encoder/core/inc/utils.h
+++ b/codec/encoder/core/inc/utils.h
@@ -51,14 +51,14 @@
 
 typedef int32_t	iWelsLogLevel;
 enum {
-WELS_LOG_QUIET		= 0x00,		// Quiet mode
-WELS_LOG_ERROR		= 1 << 0,	// Error log iLevel
-WELS_LOG_WARNING	= 1 << 1,	// Warning log iLevel
-WELS_LOG_INFO		= 1 << 2,	// Information log iLevel
-WELS_LOG_DEBUG		= 1 << 3,	// Debug log iLevel
-WELS_LOG_RESV		= 1 << 4,	// Resversed log iLevel
-WELS_LOG_LEVEL_COUNT = 5,
-WELS_LOG_DEFAULT	= WELS_LOG_ERROR | WELS_LOG_WARNING | WELS_LOG_INFO | WELS_LOG_DEBUG	// Default log iLevel in Wels codec
+  WELS_LOG_QUIET		= 0x00,		// Quiet mode
+  WELS_LOG_ERROR		= 1 << 0,	// Error log iLevel
+  WELS_LOG_WARNING	= 1 << 1,	// Warning log iLevel
+  WELS_LOG_INFO		= 1 << 2,	// Information log iLevel
+  WELS_LOG_DEBUG		= 1 << 3,	// Debug log iLevel
+  WELS_LOG_RESV		= 1 << 4,	// Resversed log iLevel
+  WELS_LOG_LEVEL_COUNT = 5,
+  WELS_LOG_DEFAULT	= WELS_LOG_ERROR | WELS_LOG_WARNING | WELS_LOG_INFO | WELS_LOG_DEBUG	// Default log iLevel in Wels codec
 };
 
 /*
--- a/codec/encoder/core/inc/vlc_encoder.h
+++ b/codec/encoder/core/inc/vlc_encoder.h
@@ -58,36 +58,36 @@
 
 static inline int32_t WriteTotalCoeffTrailingones (SBitStringAux* pBs, uint8_t uiNc, uint8_t uiTotalCoeff,
     uint8_t uiTrailingOnes) {
-const uint8_t kuiNcIdx		= g_kuiEncNcMapTable[uiNc];
-const uint8_t* kpCoeffToken	= &g_kuiVlcCoeffToken[kuiNcIdx][uiTotalCoeff][uiTrailingOnes][0];
-return BsWriteBits (pBs,  kpCoeffToken[1], kpCoeffToken[0]);
+  const uint8_t kuiNcIdx		= g_kuiEncNcMapTable[uiNc];
+  const uint8_t* kpCoeffToken	= &g_kuiVlcCoeffToken[kuiNcIdx][uiTotalCoeff][uiTrailingOnes][0];
+  return BsWriteBits (pBs,  kpCoeffToken[1], kpCoeffToken[0]);
 }
 
 static inline int32_t WriteTotalcoeffTrailingonesChroma (SBitStringAux* pBs, uint8_t uiTotalCoeff,
     uint8_t uiTrailingOnes) {
-const uint8_t* kpCoeffToken	= &g_kuiVlcCoeffToken[4][uiTotalCoeff][uiTrailingOnes][0];
-return BsWriteBits (pBs, kpCoeffToken[1], kpCoeffToken[0]);
+  const uint8_t* kpCoeffToken	= &g_kuiVlcCoeffToken[4][uiTotalCoeff][uiTrailingOnes][0];
+  return BsWriteBits (pBs, kpCoeffToken[1], kpCoeffToken[0]);
 }
 
 //kuiZeroCount = level_prefix;
 static inline int32_t WriteLevelPrefix (SBitStringAux* pBs, const uint32_t kuiZeroCount) {
-BsWriteBits (pBs, kuiZeroCount + 1, 1);
-return 0;
+  BsWriteBits (pBs, kuiZeroCount + 1, 1);
+  return 0;
 }
 
 static inline int32_t WriteTotalZeros (SBitStringAux* pBs, uint32_t uiTotalCoeff, uint32_t uiTotalZeros) {
-const uint8_t* kpTotalZeros	= &g_kuiVlcTotalZeros[uiTotalCoeff][uiTotalZeros][0];
-return BsWriteBits (pBs, kpTotalZeros[1], kpTotalZeros[0]);
+  const uint8_t* kpTotalZeros	= &g_kuiVlcTotalZeros[uiTotalCoeff][uiTotalZeros][0];
+  return BsWriteBits (pBs, kpTotalZeros[1], kpTotalZeros[0]);
 }
 
 static inline int32_t WriteTotalZerosChromaDc (SBitStringAux* pBs, uint32_t uiTotalCoeff, uint32_t uiTotalZeros) {
-const uint8_t* kpTotalZerosChromaDc = &g_kuiVlcTotalZerosChromaDc[uiTotalCoeff][uiTotalZeros][0];
-return BsWriteBits (pBs, kpTotalZerosChromaDc[1], kpTotalZerosChromaDc[0]);
+  const uint8_t* kpTotalZerosChromaDc = &g_kuiVlcTotalZerosChromaDc[uiTotalCoeff][uiTotalZeros][0];
+  return BsWriteBits (pBs, kpTotalZerosChromaDc[1], kpTotalZerosChromaDc[0]);
 }
 
 static inline int32_t WriteRunBefore (SBitStringAux* pBs, uint8_t uiZeroLeft, uint8_t uiRunBefore) {
-const uint8_t* kpRunBefore = &g_kuiVlcRunBefore[uiZeroLeft][uiRunBefore][0];
-return BsWriteBits (pBs, kpRunBefore[1], kpRunBefore[0]);
+  const uint8_t* kpRunBefore = &g_kuiVlcRunBefore[uiZeroLeft][uiRunBefore][0];
+  return BsWriteBits (pBs, kpRunBefore[1], kpRunBefore[0]);
 }
 }
 #endif
--- a/codec/encoder/core/inc/wels_common_basis.h
+++ b/codec/encoder/core/inc/wels_common_basis.h
@@ -50,38 +50,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
 };
 
 /*
@@ -89,10 +89,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
 };
 
 /*
@@ -100,9 +100,9 @@
  */
 
 enum EVclType {
-NON_VCL			= 0,
-VCL				= 1,
-NOT_APP			= 2
+  NON_VCL			= 0,
+  VCL				= 1,
+  NOT_APP			= 2
 };
 
 /*
@@ -129,64 +129,64 @@
  */
 
 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
 };
 
 
 struct SMVUnitXY {			// each 4 Bytes
-int16_t		iMvX;
-int16_t		iMvY;
+  int16_t		iMvX;
+  int16_t		iMvY;
  public:
-SMVUnitXY& sDeltaMv (const SMVUnitXY& _v0, const SMVUnitXY& _v1) {
-  iMvX = _v0.iMvX - _v1.iMvX;
-  iMvY = _v0.iMvY - _v1.iMvY;
-  return (*this);
-}
+  SMVUnitXY& sDeltaMv (const SMVUnitXY& _v0, const SMVUnitXY& _v1) {
+    iMvX = _v0.iMvX - _v1.iMvX;
+    iMvY = _v0.iMvY - _v1.iMvY;
+    return (*this);
+  }
 };
 
 typedef struct TagMVComponentUnit {		// each 	LIST_0/LIST_1
-SMVUnitXY	sMotionVectorCache[5 * 6 - 1];			// Luma only: 5 x 6 - 1 = 29 D-Words
-int8_t		iRefIndexCache[5 * 6];			// Luma only: 5 x 6 = 30 bytes
+  SMVUnitXY	sMotionVectorCache[5 * 6 - 1];			// Luma only: 5 x 6 - 1 = 29 D-Words
+  int8_t		iRefIndexCache[5 * 6];			// Luma only: 5 x 6 = 30 bytes
 } SMVComponentUnit, *PMVComponentUnit;
 
 
 typedef struct TagParaSetOffsetVariable {
-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
+  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
 //need not extra +1 due no MGS and FMO case so far
-bool		bUsedParaSetIdInBs[MAX_PPS_COUNT];	//mark the used SPS_ID with 1
-uint32_t	uiNextParaSetIdToUseInBs;					//mark the next SPS_ID_in_bs, for all layers
+  bool		bUsedParaSetIdInBs[MAX_PPS_COUNT];	//mark the used SPS_ID with 1
+  uint32_t	uiNextParaSetIdToUseInBs;					//mark the next SPS_ID_in_bs, for all layers
 } SParaSetOffsetVariable;
 
 typedef struct TagParaSetOffset {
 //in PS0 design, "sParaSetOffsetVariable" record the previous paras before current IDR, AND NEED to be stacked and recover across IDR
-SParaSetOffsetVariable
-sParaSetOffsetVariable[PARA_SET_TYPE]; //PARA_SET_TYPE=3; paraset_type = 0: AVC_SPS; =1: Subset_SPS; =2: PPS
+  SParaSetOffsetVariable
+  sParaSetOffsetVariable[PARA_SET_TYPE]; //PARA_SET_TYPE=3; paraset_type = 0: AVC_SPS; =1: Subset_SPS; =2: PPS
 //in PSO design, "bPpsIdMappingIntoSubsetsps" uses the current para of current IDR period
-bool
-bPpsIdMappingIntoSubsetsps[MAX_DQ_LAYER_NUM/*+1*/];	// need not extra +1 due no MGS and FMO case so far
-uint16_t
-uiIdrPicId;		// IDR picture id: [0, 65535], this one is used for LTR!! Can we just NOT put this into the SParaSetOffset structure?!!
+  bool
+  bPpsIdMappingIntoSubsetsps[MAX_DQ_LAYER_NUM/*+1*/];	// need not extra +1 due no MGS and FMO case so far
+  uint16_t
+  uiIdrPicId;		// IDR picture id: [0, 65535], this one is used for LTR!! Can we just NOT put this into the SParaSetOffset structure?!!
 #if _DEBUG
-bool                  bEnableSpsPpsIdAddition;
+  bool                  bEnableSpsPpsIdAddition;
 #endif
 } SParaSetOffset;
 
@@ -194,25 +194,25 @@
 
 /* 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
 };
 
 /* Position Offset structure */
 typedef struct TagCropOffset {
-int16_t	iCropLeft;
-int16_t	iCropRight;
-int16_t	iCropTop;
-int16_t	iCropBottom;
+  int16_t	iCropLeft;
+  int16_t	iCropRight;
+  int16_t	iCropTop;
+  int16_t	iCropBottom;
 } SCropOffset;
 
 
@@ -219,22 +219,22 @@
 /* Transform Type */
 
 enum ETransType {
-T_4x4	= 0,
-T_8x8	= 1,
-T_16x16	= 2,
-T_PCM	= 3
+  T_4x4	= 0,
+  T_8x8	= 1,
+  T_16x16	= 2,
+  T_PCM	= 3
 };
 
 enum EMbPosition {
-LEFT_MB_POS     = 0x01,	// A
-TOP_MB_POS      = 0x02,	// B
-TOPRIGHT_MB_POS = 0x04,	// C
-TOPLEFT_MB_POS	= 0x08,	// D,
-RIGHT_MB_POS	= 0x10,	//  add followed four case to reuse when intra up-sample
-BOTTOM_MB_POS	= 0x20,	//
-BOTTOMRIGHT_MB_POS = 0x40,	//
-BOTTOMLEFT_MB_POS	= 0x80,	//
-MB_POS_A  = 0x100
+  LEFT_MB_POS     = 0x01,	// A
+  TOP_MB_POS      = 0x02,	// B
+  TOPRIGHT_MB_POS = 0x04,	// C
+  TOPLEFT_MB_POS	= 0x08,	// D,
+  RIGHT_MB_POS	= 0x10,	//  add followed four case to reuse when intra up-sample
+  BOTTOM_MB_POS	= 0x20,	//
+  BOTTOMRIGHT_MB_POS = 0x40,	//
+  BOTTOMLEFT_MB_POS	= 0x80,	//
+  MB_POS_A  = 0x100
 };
 #define MB_ON_PIC_BOUNDRY			(RIGHT_MB_POS|BOTTOM_MB_POS|LEFT_MB_POS|TOP_MB_POS)
 
@@ -301,13 +301,13 @@
 
 
 enum {
-Intra4x4			= 0,
-Intra16x16			= 1,
-Inter16x16			= 2,
-Inter16x8			= 3,
-Inter8x16			= 4,
-Inter8x8			= 5,
-PSkip				= 6
+  Intra4x4			= 0,
+  Intra16x16			= 1,
+  Inter16x16			= 2,
+  Inter16x8			= 3,
+  Inter8x16			= 4,
+  Inter8x8			= 5,
+  PSkip				= 6
 };
 
 
@@ -315,13 +315,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/encoder/core/inc/wels_func_ptr_def.h
+++ b/codec/encoder/core/inc/wels_func_ptr_def.h
@@ -96,7 +96,8 @@
     int32_t iBeta, int8_t* iTc);
 typedef void (*PChromaDeblockingEQ4Func) (uint8_t* iSampleCb, uint8_t* iSampleCr, int32_t iStride, int32_t iAlpha,
     int32_t iBeta);
-typedef void (*PDeblockingBSCalc) (SWelsFuncPtrList* pFunc, SMB* pCurMb, uint8_t uiBS[2][4][4], Mb_Type uiCurMbType, int32_t iMbStride, int32_t iLeftFlag, int32_t iTopFlag);
+typedef void (*PDeblockingBSCalc) (SWelsFuncPtrList* pFunc, SMB* pCurMb, uint8_t uiBS[2][4][4], Mb_Type uiCurMbType,
+                                   int32_t iMbStride, int32_t iLeftFlag, int32_t iTopFlag);
 
 typedef struct tagDeblockingFunc {
   PLumaDeblockingLT4Func    pfLumaDeblockingLT4Ver;
@@ -142,23 +143,26 @@
 typedef int32_t (*PIntraPred8x8Combined3Func) (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*,
     uint8_t*, uint8_t*);
 
-typedef uint32_t (*PSampleSadHor8Func)( uint8_t*, int32_t, uint8_t*, int32_t, uint16_t*, int32_t* );
+typedef uint32_t (*PSampleSadHor8Func) (uint8_t*, int32_t, uint8_t*, int32_t, uint16_t*, int32_t*);
 typedef void (*PMotionSearchFunc) (SWelsFuncPtrList* pFuncList, void* pCurDqLayer, void* pMe,
                                    void* pSlice);
-typedef void (*PSearchMethodFunc) (SWelsFuncPtrList* pFuncList, void* pMe, void* pSlice, const int32_t kiEncStride, const int32_t kiRefStride);
-typedef void (*PCalculateSatdFunc) ( PSampleSadSatdCostFunc pSatd, void * vpMe, const int32_t kiEncStride, const int32_t kiRefStride );
-typedef bool (*PCheckDirectionalMv) (PSampleSadSatdCostFunc pSad, void * vpMe,
-                      const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
-                      int32_t& iBestSadCost);
-typedef void (*PLineFullSearchFunc) (	SWelsFuncPtrList *pFuncList, SWelsME *pMe,
-													uint16_t* pMvdTable, const int32_t kiFixedMvd,
-													const int32_t kiEncStride, const int32_t kiRefStride,
-													const int32_t kiMinPos, const int32_t kiMaxPos,
-                          const bool bVerticalSearch );
-typedef void (*PCalculateBlockFeatureOfFrame)(uint8_t *pRef, const int32_t kiWidth, const int32_t kiHeight, const int32_t kiRefStride,
-                                              uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]);
-typedef int32_t (*PCalculateSingleBlockFeature)(uint8_t *pRef, const int32_t kiRefStride);
-typedef void (*PUpdateFMESwitch)(SDqLayer* pCurLayer);
+typedef void (*PSearchMethodFunc) (SWelsFuncPtrList* pFuncList, void* pMe, void* pSlice, const int32_t kiEncStride,
+                                   const int32_t kiRefStride);
+typedef void (*PCalculateSatdFunc) (PSampleSadSatdCostFunc pSatd, void* vpMe, const int32_t kiEncStride,
+                                    const int32_t kiRefStride);
+typedef bool (*PCheckDirectionalMv) (PSampleSadSatdCostFunc pSad, void* vpMe,
+                                     const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
+                                     int32_t& iBestSadCost);
+typedef void (*PLineFullSearchFunc) (SWelsFuncPtrList* pFuncList, SWelsME* pMe,
+                                     uint16_t* pMvdTable, const int32_t kiFixedMvd,
+                                     const int32_t kiEncStride, const int32_t kiRefStride,
+                                     const int32_t kiMinPos, const int32_t kiMaxPos,
+                                     const bool bVerticalSearch);
+typedef void (*PCalculateBlockFeatureOfFrame) (uint8_t* pRef, const int32_t kiWidth, const int32_t kiHeight,
+    const int32_t kiRefStride,
+    uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]);
+typedef int32_t (*PCalculateSingleBlockFeature) (uint8_t* pRef, const int32_t kiRefStride);
+typedef void (*PUpdateFMESwitch) (SDqLayer* pCurLayer);
 
 #define     MAX_BLOCK_TYPE 5 // prev 7
 typedef struct TagSampleDealingFunc {
@@ -183,8 +187,8 @@
 typedef uint8_t (*PGetMbSignFromInterVaaFunc) (int32_t* pSad8x8);
 typedef void (*PUpdateMbMvFunc) (SMVUnitXY* pMvUnit, const SMVUnitXY ksMv);
 
-typedef bool (*PBuildRefListFunc)(void* pCtx, const int32_t iPOC,int32_t iBestLtrRefIdx);
-typedef void (*PMarkPicFunc)(void* pCtx);
+typedef bool (*PBuildRefListFunc) (void* pCtx, const int32_t iPOC, int32_t iBestLtrRefIdx);
+typedef void (*PMarkPicFunc) (void* pCtx);
 typedef bool (*PUpdateRefListFunc) (void* pCtx);
 
 struct TagWelsFuncPointerList {
--- a/codec/encoder/core/inc/wels_preprocess.h
+++ b/codec/encoder/core/inc/wels_preprocess.h
@@ -62,19 +62,19 @@
 
 
 typedef struct {
-	int32_t iMinFrameComplexity;
+  int32_t iMinFrameComplexity;
   int32_t iMinFrameComplexity08;
   int32_t iMinFrameComplexity11;
 
   int32_t iMinFrameNumGap;
   int32_t iMinFrameQp;
-}SRefJudgement;
+} SRefJudgement;
 
 typedef struct {
-  SPicture   *pRefPicture;
+  SPicture*   pRefPicture;
   int32_t     iSrcListIdx;   //idx in  h->spatial_pic[base_did];
   bool        bSceneLtrFlag;
-}SRefInfoParam;
+} SRefInfoParam;
 
 typedef struct {
   SVAACalcResult		sVaaCalcInfo;
@@ -102,17 +102,16 @@
   bool          bIdrPeriodFlag;
 } SVAAFrameInfo;
 
-typedef struct SVAAFrameInfoExt_t: public SVAAFrameInfo
-{
+typedef struct SVAAFrameInfoExt_t: public SVAAFrameInfo {
   SComplexityAnalysisScreenParam    sComplexityScreenParam;
   SScrollDetectionResult    sScrollDetectInfo;
-    //TOP3_BEST_REF_NO_TID
+  //TOP3_BEST_REF_NO_TID
   SRefInfoParam    sVaaStrBestRefCandidate[MAX_REF_PIC_COUNT];
   int32_t    iNumOfAvailableRef;
 
-  uint8_t    *pVaaBestBlockStaticIdc;//pointer
-  uint8_t    *pVaaBlockStaticIdc[16];//real memory,
-}SVAAFrameInfoExt;
+  uint8_t*    pVaaBestBlockStaticIdc;//pointer
+  uint8_t*    pVaaBlockStaticIdc[16];//real memory,
+} SVAAFrameInfoExt;
 
 class CWelsPreProcess {
  public:
@@ -125,8 +124,9 @@
   void    FreeSpatialPictures (sWelsEncCtx* pCtx);
   int32_t BuildSpatialPicList (sWelsEncCtx* pEncCtx, const SSourcePicture* kpSrcPic);
   int32_t AnalyzeSpatialPic (sWelsEncCtx* pEncCtx, const int32_t kiDIdx);
-  int32_t UpdateSpatialPictures(sWelsEncCtx* pEncCtx, SWelsSvcCodingParam* pParam, const int8_t iCurTid, const int32_t d_idx);
-  int32_t GetRefCandidateLtrIndex(int32_t iRefIdx);
+  int32_t UpdateSpatialPictures (sWelsEncCtx* pEncCtx, SWelsSvcCodingParam* pParam, const int8_t iCurTid,
+                                 const int32_t d_idx);
+  int32_t GetRefCandidateLtrIndex (int32_t iRefIdx);
   void    AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,
                                     const int32_t kiDependencyId, const bool kbCalculateBGD);
 
@@ -156,17 +156,19 @@
   void WelsMoveMemoryWrapper (SWelsSvcCodingParam* pSvcParam, SPicture* pDstPic, const SSourcePicture* kpSrc,
                               const int32_t kiWidth, const int32_t kiHeight);
 
-  ESceneChangeIdc DetectSceneChangeScreen(sWelsEncCtx* pCtx,SPicture* pCurPicture);
-  void InitPixMap( const SPicture *pPicture, SPixMap *pPixMap );
-  void GetAvailableRefList(SPicture ** pSrcPicList,uint8_t iCurTid, const int32_t iClosestLtrFrameNum,
-                           SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum);
-  void InitRefJudgement( SRefJudgement *pRefJudgement );
-  bool JudgeBestRef(SPicture* pRefPic,const SRefJudgement& sRefJudgement, const int32_t iFrameComplexity, const bool bIsClosestLtrFrame);
-  void SaveBestRefToJudgement(const int32_t iRefPictureAvQP, const int32_t iComplexity, SRefJudgement* pRefJudgement);
-  void SaveBestRefToLocal(SRefInfoParam *pRefPicInfo,const SSceneChangeResult& sSceneChangeResult, SRefInfoParam* pRefSaved);
-  void SaveBestRefToVaa(SRefInfoParam& sRefSaved,SRefInfoParam* pVaaBestRef);
+  ESceneChangeIdc DetectSceneChangeScreen (sWelsEncCtx* pCtx, SPicture* pCurPicture);
+  void InitPixMap (const SPicture* pPicture, SPixMap* pPixMap);
+  void GetAvailableRefList (SPicture** pSrcPicList, uint8_t iCurTid, const int32_t iClosestLtrFrameNum,
+                            SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum);
+  void InitRefJudgement (SRefJudgement* pRefJudgement);
+  bool JudgeBestRef (SPicture* pRefPic, const SRefJudgement& sRefJudgement, const int32_t iFrameComplexity,
+                     const bool bIsClosestLtrFrame);
+  void SaveBestRefToJudgement (const int32_t iRefPictureAvQP, const int32_t iComplexity, SRefJudgement* pRefJudgement);
+  void SaveBestRefToLocal (SRefInfoParam* pRefPicInfo, const SSceneChangeResult& sSceneChangeResult,
+                           SRefInfoParam* pRefSaved);
+  void SaveBestRefToVaa (SRefInfoParam& sRefSaved, SRefInfoParam* pVaaBestRef);
 
-private:
+ private:
   Scaled_Picture   m_sScaledPicture;
   SPicture*	   m_pLastSpatialPicture[MAX_DEPENDENCY_LAYER][2];
   IWelsVP*         m_pInterfaceVp;
@@ -174,7 +176,7 @@
   bool             m_bInitDone;
   uint8_t          m_uiSpatialLayersInTemporal[MAX_DEPENDENCY_LAYER];
   uint8_t          m_uiSpatialPicNum[MAX_DEPENDENCY_LAYER];
-public:
+ public:
   /* For Downsampling & VAA I420 based source pictures */
   SPicture*        m_pSpatialPic[MAX_DEPENDENCY_LAYER][MAX_TEMPORAL_LEVEL + 1 +
       LONG_TERM_REF_NUM];	// need memory requirement with total number of (log2(uiGopSize)+1+1+long_term_ref_num)
--- a/codec/encoder/core/inc/wels_transpose_matrix.h
+++ b/codec/encoder/core/inc/wels_transpose_matrix.h
@@ -39,15 +39,19 @@
 #ifdef X86_ASM
 extern "C"
 {
-void TransposeMatrixBlocksx16_sse2( void *pDst, const int32_t kiDstStride, void *pSrc, const int32_t kiSrcStride, const int32_t kiBlocksNum );
-void TransposeMatrixBlock16x16_sse2( void *pDst, const int32_t kiDstStride, void *pSrc, const int32_t kiSrcStride );
-void TransposeMatrixBlocksx8_mmx( void *pDst, const int32_t kiDstStride, void *pSrc, const int32_t kiSrcStride, const int32_t kiBlocksNum );
-void TransposeMatrixBlock8x8_mmx( void *pDst, const int32_t kiDstStride, void *pSrc, const int32_t kiSrcStride );
+  void TransposeMatrixBlocksx16_sse2 (void* pDst, const int32_t kiDstStride, void* pSrc, const int32_t kiSrcStride,
+                                      const int32_t kiBlocksNum);
+  void TransposeMatrixBlock16x16_sse2 (void* pDst, const int32_t kiDstStride, void* pSrc, const int32_t kiSrcStride);
+  void TransposeMatrixBlocksx8_mmx (void* pDst, const int32_t kiDstStride, void* pSrc, const int32_t kiSrcStride,
+                                    const int32_t kiBlocksNum);
+  void TransposeMatrixBlock8x8_mmx (void* pDst, const int32_t kiDstStride, void* pSrc, const int32_t kiSrcStride);
 }
 #endif
 
-typedef void (*PTransposeMatrixBlockFunc)( void *pDst, const int32_t kiDstStride, void *pSrc, const int32_t kiSrcStride );
-typedef void (*PTransposeMatrixBlocksFunc)( void *pDst, const int32_t kiDstStride, void *pSrc, const int32_t kiSrcStride, const int32_t kiBlocksNum );
+typedef void (*PTransposeMatrixBlockFunc) (void* pDst, const int32_t kiDstStride, void* pSrc,
+    const int32_t kiSrcStride);
+typedef void (*PTransposeMatrixBlocksFunc) (void* pDst, const int32_t kiDstStride, void* pSrc,
+    const int32_t kiSrcStride, const int32_t kiBlocksNum);
 
 }// end of namespace declaration
 
--- a/codec/encoder/core/src/au_set.cpp
+++ b/codec/encoder/core/src/au_set.cpp
@@ -404,8 +404,8 @@
 
   //for Scalable Baseline, Scalable High, and Scalable High Intra profiles.If level_idc is equal to 9, the indicated level is level 1b.
   //for the Baseline, Constrained Baseline, Main, and Extended profiles,If level_idc is equal to 11 and constraint_set3_flag is equal to 1, the indicated level is level 1b.
-  if((pSps->iLevelIdc == 9)&&
-    ((pSps->uiProfileIdc == PRO_BASELINE) ||(pSps->uiProfileIdc == PRO_MAIN)||(pSps->uiProfileIdc == PRO_EXTENDED))) {
+  if ((pSps->iLevelIdc == 9) &&
+      ((pSps->uiProfileIdc == PRO_BASELINE) || (pSps->uiProfileIdc == PRO_MAIN) || (pSps->uiProfileIdc == PRO_EXTENDED))) {
     pSps->iLevelIdc = 11;
     pSps->bConstraintSet3Flag = true;
   }
--- a/codec/encoder/core/src/deblocking.cpp
+++ b/codec/encoder/core/src/deblocking.cpp
@@ -193,25 +193,25 @@
   uiNnz32b3 = * (uint32_t*) (pNnzTab + 12);
 
   for (int i = 0; i < 3; i++)
-      uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1];
+    uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1];
   uiBS[0][1][0] = BS_EDGE (uiBsx4[0], iRefIdx, pCurMb->sMv, 1, 0);
   uiBS[0][2][0] = BS_EDGE (uiBsx4[1], iRefIdx, pCurMb->sMv, 2, 1);
   uiBS[0][3][0] = BS_EDGE (uiBsx4[2], iRefIdx, pCurMb->sMv, 3, 2);
 
   for (int i = 0; i < 3; i++)
-      uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1];
+    uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1];
   uiBS[0][1][1] = BS_EDGE (uiBsx4[0], iRefIdx, pCurMb->sMv, 5, 4);
   uiBS[0][2][1] = BS_EDGE (uiBsx4[1], iRefIdx, pCurMb->sMv, 6, 5);
   uiBS[0][3][1] = BS_EDGE (uiBsx4[2], iRefIdx, pCurMb->sMv, 7, 6);
 
   for (int i = 0; i < 3; i++)
-      uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1];
+    uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1];
   uiBS[0][1][2] = BS_EDGE (uiBsx4[0], iRefIdx, pCurMb->sMv, 9, 8);
   uiBS[0][2][2] = BS_EDGE (uiBsx4[1], iRefIdx, pCurMb->sMv, 10, 9);
   uiBS[0][3][2] = BS_EDGE (uiBsx4[2], iRefIdx, pCurMb->sMv, 11, 10);
 
   for (int i = 0; i < 3; i++)
-      uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1];
+    uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1];
   uiBS[0][1][3] = BS_EDGE (uiBsx4[0], iRefIdx, pCurMb->sMv, 13, 12);
   uiBS[0][2][3] = BS_EDGE (uiBsx4[1], iRefIdx, pCurMb->sMv, 14, 13);
   uiBS[0][3][3] = BS_EDGE (uiBsx4[2], iRefIdx, pCurMb->sMv, 15, 14);
@@ -240,8 +240,8 @@
   int32_t i;
   uint32_t uiBSx4;
   uint8_t* pBS = (uint8_t*) (&uiBSx4);
-  const uint8_t *pBIdx  = &g_kuiTableBIdx[iEdge][0];
-  const uint8_t *pBnIdx = &g_kuiTableBIdx[iEdge][4];
+  const uint8_t* pBIdx  = &g_kuiTableBIdx[iEdge][0];
+  const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4];
 
 
   for (i = 0; i < 4; i++) {
@@ -792,7 +792,7 @@
 void WelsBlockFuncInit (PSetNoneZeroCountZeroFunc* pfSetNZCZero,  int32_t iCpu) {
   *pfSetNZCZero = WelsNonZeroCount_c;
 #ifdef	HAVE_NEON
-  if( iCpu & WELS_CPU_NEON ) {
+  if (iCpu & WELS_CPU_NEON) {
     *pfSetNZCZero = WelsNonZeroCount_neon;
   }
 #endif
@@ -826,7 +826,7 @@
 #endif
 
 #if defined(HAVE_NEON)
-  if (iCpu & WELS_CPU_NEON ) {
+  if (iCpu & WELS_CPU_NEON) {
     pFunc->pfLumaDeblockingLT4Ver		= DeblockLumaLt4V_neon;
     pFunc->pfLumaDeblockingEQ4Ver		= DeblockLumaEq4V_neon;
     pFunc->pfLumaDeblockingLT4Hor		= DeblockLumaLt4H_neon;
--- a/codec/encoder/core/src/decode_mb_aux.cpp
+++ b/codec/encoder/core/src/decode_mb_aux.cpp
@@ -259,15 +259,15 @@
 
 #if defined(X86_ASM)
   if (uiCpuFlag & WELS_CPU_MMXEXT) {
-     pFuncList->pfIDctT4		= WelsIDctT4Rec_mmx;
+    pFuncList->pfIDctT4		= WelsIDctT4Rec_mmx;
   }
   if (uiCpuFlag & WELS_CPU_SSE2) {
-     pFuncList->pfDequantization4x4			= WelsDequant4x4_sse2;
-     pFuncList->pfDequantizationFour4x4		= WelsDequantFour4x4_sse2;
-     pFuncList->pfDequantizationIHadamard4x4	= WelsDequantIHadamard4x4_sse2;
+    pFuncList->pfDequantization4x4			= WelsDequant4x4_sse2;
+    pFuncList->pfDequantizationFour4x4		= WelsDequantFour4x4_sse2;
+    pFuncList->pfDequantizationIHadamard4x4	= WelsDequantIHadamard4x4_sse2;
 
-     pFuncList->pfIDctFourT4		= WelsIDctFourT4Rec_sse2;
-     pFuncList->pfIDctI16x16Dc = WelsIDctRecI16x16Dc_sse2;
+    pFuncList->pfIDctFourT4		= WelsIDctFourT4Rec_sse2;
+    pFuncList->pfIDctI16x16Dc = WelsIDctRecI16x16Dc_sse2;
   }
 #endif//X86_ASM
 
--- a/codec/encoder/core/src/encode_mb_aux.cpp
+++ b/codec/encoder/core/src/encode_mb_aux.cpp
@@ -450,9 +450,9 @@
 }
 
 #ifdef	HAVE_NEON
-int32_t WelsHadamardQuant2x2Skip_neon(int16_t* pRes, int16_t iFF,  int16_t iMF) {
-  int16_t iThreshold = ((1<<16)-1)/iMF - iFF;
-  return WelsHadamardQuant2x2SkipKernel_neon(pRes, iThreshold);
+int32_t WelsHadamardQuant2x2Skip_neon (int16_t* pRes, int16_t iFF,  int16_t iMF) {
+  int16_t iThreshold = ((1 << 16) - 1) / iMF - iFF;
+  return WelsHadamardQuant2x2SkipKernel_neon (pRes, iThreshold);
 }
 #endif
 
--- a/codec/encoder/core/src/encoder.cpp
+++ b/codec/encoder/core/src/encoder.cpp
@@ -192,7 +192,7 @@
 
   //
   WelsInitBGDFunc (pFuncList, pParam->bEnableBackgroundDetection);
-  WelsInitScrollingSkipFunc (pFuncList, bScreenContent&&(pParam->bEnableSceneChangeDetect));
+  WelsInitScrollingSkipFunc (pFuncList, bScreenContent && (pParam->bEnableSceneChangeDetect));
 
   // for pfGetVarianceFromIntraVaa function ptr adaptive by CPU features, 6/7/2010
   InitIntraAnalysisVaaInfo (pFuncList, uiCpuFlag);
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -711,8 +711,8 @@
   const int32_t kiFeatureStrategyIndex = FME_DEFAULT_FEATURE_INDEX;
   const int32_t kiMe16x16 = ME_DIA_CROSS;
   const int32_t kiMe8x8 = ME_DIA_CROSS_FME;
-  const int32_t kiNeedFeatureStorage = (pParam->iUsageType != SCREEN_CONTENT_REAL_TIME)?0:
-    ((kiFeatureStrategyIndex<<16) +  ((kiMe16x16 & 0x00FF)<<8) + (kiMe8x8 & 0x00FF));
+  const int32_t kiNeedFeatureStorage = (pParam->iUsageType != SCREEN_CONTENT_REAL_TIME) ? 0 :
+                                       ((kiFeatureStrategyIndex << 16) + ((kiMe16x16 & 0x00FF) << 8) + (kiMe8x8 & 0x00FF));
 
   iDlayerIndex			= 0;
   while (iDlayerIndex < iDlayerCount) {
@@ -733,7 +733,8 @@
     pRefList		= (SRefList*)pMa->WelsMallocz (sizeof (SRefList), "pRefList");
     WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList), FreeMemorySvc (ppCtx))
     do {
-      pRefList->pRef[i]	= AllocPicture (pMa, kiWidth, kiHeight, true, (iDlayerIndex == iDlayerCount-1)?kiNeedFeatureStorage:0);	// to use actual size of current layer
+      pRefList->pRef[i]	= AllocPicture (pMa, kiWidth, kiHeight, true,
+                                        (iDlayerIndex == iDlayerCount - 1) ? kiNeedFeatureStorage : 0);	// to use actual size of current layer
       WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList->pRef[i]), FreeMemorySvc (ppCtx))
       ++ i;
     } while (i < 1 + iNumRef);
@@ -831,13 +832,14 @@
     }
 
     //
-    if (kiNeedFeatureStorage && iDlayerIndex==iDlayerCount-1)
-    {
-      pDqLayer->pFeatureSearchPreparation	= static_cast<SFeatureSearchPreparation*> (pMa->WelsMallocz (sizeof (SFeatureSearchPreparation), "pFeatureSearchPreparation"));
-      WELS_VERIFY_RETURN_PROC_IF (1, NULL==pDqLayer->pFeatureSearchPreparation, FreeMemorySvc (ppCtx));
-      int32_t iReturn = RequestFeatureSearchPreparation(pMa, pDlayer->iFrameWidth, pDlayer->iFrameHeight, kiNeedFeatureStorage,
-        pDqLayer->pFeatureSearchPreparation);
-      WELS_VERIFY_RETURN_PROC_IF (1, ENC_RETURN_SUCCESS!=iReturn, FreeMemorySvc (ppCtx));
+    if (kiNeedFeatureStorage && iDlayerIndex == iDlayerCount - 1) {
+      pDqLayer->pFeatureSearchPreparation	= static_cast<SFeatureSearchPreparation*> (pMa->WelsMallocz (sizeof (
+                                              SFeatureSearchPreparation), "pFeatureSearchPreparation"));
+      WELS_VERIFY_RETURN_PROC_IF (1, NULL == pDqLayer->pFeatureSearchPreparation, FreeMemorySvc (ppCtx));
+      int32_t iReturn = RequestFeatureSearchPreparation (pMa, pDlayer->iFrameWidth, pDlayer->iFrameHeight,
+                        kiNeedFeatureStorage,
+                        pDqLayer->pFeatureSearchPreparation);
+      WELS_VERIFY_RETURN_PROC_IF (1, ENC_RETURN_SUCCESS != iReturn, FreeMemorySvc (ppCtx));
     } else {
       pDqLayer->pFeatureSearchPreparation = NULL;
     }
@@ -1363,19 +1365,19 @@
   WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pWelsSvcRc), FreeMemorySvc (ppCtx))
   //End of Rate control module memory allocation
 
-    //pVaa memory allocation
-    if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
-      (*ppCtx)->pVaa	= (SVAAFrameInfoExt*)pMa->WelsMallocz (sizeof (SVAAFrameInfoExt), "pVaa");
-      WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pVaa), FreeMemorySvc (ppCtx))
-      if(RequestMemoryVaaScreen ((*ppCtx)->pVaa, pMa, (*ppCtx)->pSvcParam->iNumRefFrame, iCountMaxMbNum << 2)){
-        WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMemoryVaaScreen failed!");
-        FreeMemorySvc (ppCtx);
-        return 1;
-      }
-    } else {
-        (*ppCtx)->pVaa	= (SVAAFrameInfo*)pMa->WelsMallocz (sizeof (SVAAFrameInfo), "pVaa");
-        WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pVaa), FreeMemorySvc (ppCtx))
+  //pVaa memory allocation
+  if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
+    (*ppCtx)->pVaa	= (SVAAFrameInfoExt*)pMa->WelsMallocz (sizeof (SVAAFrameInfoExt), "pVaa");
+    WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pVaa), FreeMemorySvc (ppCtx))
+    if (RequestMemoryVaaScreen ((*ppCtx)->pVaa, pMa, (*ppCtx)->pSvcParam->iNumRefFrame, iCountMaxMbNum << 2)) {
+      WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMemoryVaaScreen failed!");
+      FreeMemorySvc (ppCtx);
+      return 1;
     }
+  } else {
+    (*ppCtx)->pVaa	= (SVAAFrameInfo*)pMa->WelsMallocz (sizeof (SVAAFrameInfo), "pVaa");
+    WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pVaa), FreeMemorySvc (ppCtx))
+  }
 
   if ((*ppCtx)->pSvcParam->bEnableAdaptiveQuant) { //malloc mem
     (*ppCtx)->pVaa->sAdaptiveQuantParam.pMotionTextureUnit   = static_cast<SMotionTextureUnit*>
@@ -1585,7 +1587,7 @@
           }
 
           if (pDq->pFeatureSearchPreparation) {
-            ReleaseFeatureSearchPreparation(pMa, pDq->pFeatureSearchPreparation->pFeatureOfBlock);
+            ReleaseFeatureSearchPreparation (pMa, pDq->pFeatureSearchPreparation->pFeatureOfBlock);
             pMa->WelsFree (pDq->pFeatureSearchPreparation, "pFeatureSearchPreparation");
             pDq->pFeatureSearchPreparation = NULL;
           }
@@ -1663,8 +1665,8 @@
         pMa->WelsFree (pCtx->pVaa->sVaaCalcInfo.pMad8x8, "pVaa->sVaaCalcInfo.pMad8x8");
         pCtx->pVaa->sVaaCalcInfo.pMad8x8	= NULL;
       }
-      if(pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
-        ReleaseMemoryVaaScreen(pCtx->pVaa, pMa,pCtx->pSvcParam->iNumRefFrame);
+      if (pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
+        ReleaseMemoryVaaScreen (pCtx->pVaa, pMa, pCtx->pSvcParam->iNumRefFrame);
       pMa->WelsFree (pCtx->pVaa, "pVaa");
       pCtx->pVaa = NULL;
     }
@@ -2456,19 +2458,20 @@
 
       if (P_SLICE == pCtx->eSliceType) {
         //calculate bFMESwitchFlag
-        SVAAFrameInfoExt *pVaaExt		= static_cast<SVAAFrameInfoExt *>(pCtx->pVaa);
-        const int32_t kiMbSize = pCurLayer->iMbHeight*pCurLayer->iMbWidth;
-        pFeatureSearchPreparation->bFMESwitchFlag = CalcFMESwitchFlag( pFeatureSearchPreparation->uiFMEGoodFrameCount,
-          pFeatureSearchPreparation->iHighFreMbCount*100/kiMbSize, pCtx->pVaa->sVaaCalcInfo.iFrameSad/kiMbSize,
-          pVaaExt->sScrollDetectInfo.bScrollDetectFlag);
+        SVAAFrameInfoExt* pVaaExt		= static_cast<SVAAFrameInfoExt*> (pCtx->pVaa);
+        const int32_t kiMbSize = pCurLayer->iMbHeight * pCurLayer->iMbWidth;
+        pFeatureSearchPreparation->bFMESwitchFlag = CalcFMESwitchFlag (pFeatureSearchPreparation->uiFMEGoodFrameCount,
+            pFeatureSearchPreparation->iHighFreMbCount * 100 / kiMbSize, pCtx->pVaa->sVaaCalcInfo.iFrameSad / kiMbSize,
+            pVaaExt->sScrollDetectInfo.bScrollDetectFlag);
 
         //PerformFMEPreprocess
         SScreenBlockFeatureStorage* pScreenBlockFeatureStorage = pCurLayer->pRefPic->pScreenBlockFeatureStorage;
         pFeatureSearchPreparation->pRefBlockFeature = pScreenBlockFeatureStorage;
         if (pFeatureSearchPreparation->bFMESwitchFlag
-          && !pScreenBlockFeatureStorage->bRefBlockFeatureCalculated) {
-            //TODO: use ORIGIN of reference when preprocessing is ready
-            PerformFMEPreprocess( pFuncList, pCurLayer->pRefPic,pFeatureSearchPreparation->pFeatureOfBlock,pScreenBlockFeatureStorage);
+            && !pScreenBlockFeatureStorage->bRefBlockFeatureCalculated) {
+          //TODO: use ORIGIN of reference when preprocessing is ready
+          PerformFMEPreprocess (pFuncList, pCurLayer->pRefPic, pFeatureSearchPreparation->pFeatureOfBlock,
+                                pScreenBlockFeatureStorage);
         }
 
         //assign ME pointer
@@ -3011,9 +3014,10 @@
 #ifdef LONG_TERM_REF_DUMP
     DumpRef (pCtx);
 #endif
-    if((pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)&&(pSvcParam->iRCMode != RC_OFF_MODE))
-      pCtx->pVpp->AnalyzePictureComplexity(pCtx,pCtx->pEncPic,((pCtx->eSliceType == P_SLICE)&&(pCtx->iNumRef0>0))?pCtx->pRefList0[0]:NULL,
-                                           iCurDid,pSvcParam->bEnableBackgroundDetection);
+    if ((pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) && (pSvcParam->iRCMode != RC_OFF_MODE))
+      pCtx->pVpp->AnalyzePictureComplexity (pCtx, pCtx->pEncPic, ((pCtx->eSliceType == P_SLICE)
+                                            && (pCtx->iNumRef0 > 0)) ? pCtx->pRefList0[0] : NULL,
+                                            iCurDid, pSvcParam->bEnableBackgroundDetection);
 
     WelsUpdateRefSyntax (pCtx,  pCtx->iPOC,
                          eFrameType);	//get reordering syntax used for writing slice header and transmit to encoder.
@@ -3093,8 +3097,8 @@
           pCtx->iActiveThreadsNum	= iSliceCount;
           // to fire slice coding threads
           iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
-                                   &pCtx->pSliceThreading->pThreadMasterEvent[0],
-                                   pLayerBsInfo, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false);
+                                    &pCtx->pSliceThreading->pThreadMasterEvent[0],
+                                    pLayerBsInfo, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false);
           if (iRet) {
             WelsLog (pCtx, WELS_LOG_ERROR,
                      "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
@@ -3132,8 +3136,8 @@
           iNumThreadsRunning		= iNumThreadsScheduled;
           // to fire slice coding threads
           iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
-                                   &pCtx->pSliceThreading->pThreadMasterEvent[0],
-                                   pLayerBsInfo, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false);
+                                    &pCtx->pSliceThreading->pThreadMasterEvent[0],
+                                    pLayerBsInfo, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false);
           if (iRet) {
             WelsLog (pCtx, WELS_LOG_ERROR,
                      "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
@@ -3178,8 +3182,8 @@
 
         // to fire slice coding threads
         iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
-                                 &pCtx->pSliceThreading->pThreadMasterEvent[0],
-                                 pLayerBsInfo, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true);
+                                  &pCtx->pSliceThreading->pThreadMasterEvent[0],
+                                  pLayerBsInfo, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true);
         if (iRet) {
           WelsLog (pCtx, WELS_LOG_ERROR,
                    "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
--- a/codec/encoder/core/src/expand_pic.cpp
+++ b/codec/encoder/core/src/expand_pic.cpp
@@ -137,11 +137,11 @@
   }
 #endif//HAVE_NEON
 #if defined(HAVE_NEON_AARCH64)
-    if (kuiCPUFlag & WELS_CPU_NEON) {
-        pFuncList->pfExpandLumaPicture	= ExpandPictureLuma_AArch64_neon;
-        pFuncList->pfExpandChromaPicture[0] = ExpandPictureChroma_AArch64_neon;
-        pFuncList->pfExpandChromaPicture[1] = ExpandPictureChroma_AArch64_neon;
-    }
+  if (kuiCPUFlag & WELS_CPU_NEON) {
+    pFuncList->pfExpandLumaPicture	= ExpandPictureLuma_AArch64_neon;
+    pFuncList->pfExpandChromaPicture[0] = ExpandPictureChroma_AArch64_neon;
+    pFuncList->pfExpandChromaPicture[1] = ExpandPictureChroma_AArch64_neon;
+  }
 #endif//HAVE_NEON_AARCH64
 }
 
--- a/codec/encoder/core/src/get_intra_predictor.cpp
+++ b/codec/encoder/core/src/get_intra_predictor.cpp
@@ -729,7 +729,7 @@
     pFuncList->pfGetChromaPred[C_PRED_V]	= WelsIChromaPredV_neon;
     pFuncList->pfGetChromaPred[C_PRED_P]	= WelsIChromaPredPlane_neon;
     pFuncList->pfGetChromaPred[C_PRED_H]    = WelsIChromaPredH_neon;
-    }
+  }
 #endif
 
 #ifdef X86_ASM
--- a/codec/encoder/core/src/nal_encap.cpp
+++ b/codec/encoder/core/src/nal_encap.cpp
@@ -120,14 +120,15 @@
  */
 //TODO 1: refactor the calling of this func in multi-thread
 //TODO 2: complete the realloc&copy
-int32_t WelsEncodeNal (SWelsNalRaw* pRawNal, void* pNalHeaderExt, const int32_t kiDstBufferLen, void* pDst, int32_t* pDstLen) {
+int32_t WelsEncodeNal (SWelsNalRaw* pRawNal, void* pNalHeaderExt, const int32_t kiDstBufferLen, void* pDst,
+                       int32_t* pDstLen) {
   const bool kbNALExt = pRawNal->sNalExt.sNalHeader.eNalUnitType == NAL_UNIT_PREFIX
-                                        || pRawNal->sNalExt.sNalHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_EXT;
-  int32_t iAssumedNeededLength		= NAL_HEADER_SIZE+(kbNALExt?3:0)+pRawNal->iPayloadSize+1;
-  WELS_VERIFY_RETURN_IF(ENC_RETURN_UNEXPECTED, (iAssumedNeededLength<=0))
+                        || pRawNal->sNalExt.sNalHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_EXT;
+  int32_t iAssumedNeededLength		= NAL_HEADER_SIZE + (kbNALExt ? 3 : 0) + pRawNal->iPayloadSize + 1;
+  WELS_VERIFY_RETURN_IF (ENC_RETURN_UNEXPECTED, (iAssumedNeededLength <= 0))
 
   //since for each 0x000 need a 0x03, so the needed length will not exceed (iAssumeNeedLenth + iAssumeNeedLength/3), here adjust to >>1 to omit division
-  if (kiDstBufferLen < (iAssumedNeededLength + (iAssumedNeededLength>>1)) ) {
+  if (kiDstBufferLen < (iAssumedNeededLength + (iAssumedNeededLength >> 1))) {
     return ENC_RETURN_MEMALLOCERR;
     //TODO: call the realloc&copy instead
   }
@@ -151,14 +152,14 @@
 
     /* NAL UNIT Extension Header */
     *pDstPointer++ =	(0x80) |
-      (sNalExt->bIdrFlag << 6);
+                      (sNalExt->bIdrFlag << 6);
 
     *pDstPointer++ =	(0x80) |
-      (sNalExt->uiDependencyId << 4);
+                      (sNalExt->uiDependencyId << 4);
 
     *pDstPointer++ =	(sNalExt->uiTemporalId << 5) |
-      (sNalExt->bDiscardableFlag << 3) |
-      (0x07);
+                      (sNalExt->bDiscardableFlag << 3) |
+                      (0x07);
   }
 
   while (pSrcPointer < pSrcEnd) {
--- a/codec/encoder/core/src/picture_handle.cpp
+++ b/codec/encoder/core/src/picture_handle.cpp
@@ -110,9 +110,10 @@
   }
 
   if (iNeedFeatureStorage) {
-    pPic->pScreenBlockFeatureStorage = static_cast<SScreenBlockFeatureStorage*> (pMa->WelsMallocz (sizeof (SScreenBlockFeatureStorage), "pScreenBlockFeatureStorage"));
-    int32_t iReturn = RequestScreenBlockFeatureStorage(pMa, kiWidth,  kiHeight, iNeedFeatureStorage,
-      pPic->pScreenBlockFeatureStorage );
+    pPic->pScreenBlockFeatureStorage = static_cast<SScreenBlockFeatureStorage*> (pMa->WelsMallocz (sizeof (
+                                         SScreenBlockFeatureStorage), "pScreenBlockFeatureStorage"));
+    int32_t iReturn = RequestScreenBlockFeatureStorage (pMa, kiWidth,  kiHeight, iNeedFeatureStorage,
+                      pPic->pScreenBlockFeatureStorage);
     WELS_VERIFY_RETURN_PROC_IF (NULL, ENC_RETURN_SUCCESS != iReturn, FreePicture (pMa, &pPic));
   } else {
     pPic->pScreenBlockFeatureStorage = NULL;
@@ -136,10 +137,10 @@
     pPic->pBuffer		= NULL;
     pPic->pData[0]	=
       pPic->pData[1]	=
-      pPic->pData[2]	= NULL;
+        pPic->pData[2]	= NULL;
     pPic->iLineSize[0] =
       pPic->iLineSize[1] =
-      pPic->iLineSize[2] = 0;
+        pPic->iLineSize[2] = 0;
 
     pPic->iWidthInPixel		= 0;
     pPic->iHeightInPixel	= 0;
@@ -169,7 +170,7 @@
     }
 
     if (pPic->pScreenBlockFeatureStorage) {
-      ReleaseScreenBlockFeatureStorage(pMa, pPic->pScreenBlockFeatureStorage);
+      ReleaseScreenBlockFeatureStorage (pMa, pPic->pScreenBlockFeatureStorage);
       pMa->WelsFree (pPic->pScreenBlockFeatureStorage, "pPic->pScreenBlockFeatureStorage");
       pPic->pScreenBlockFeatureStorage = NULL;
     }
--- a/codec/encoder/core/src/ratectl.cpp
+++ b/codec/encoder/core/src/ratectl.cpp
@@ -429,38 +429,35 @@
 
   if (0 == pTOverRc->iPFrameNum) {
     iLumaQp = pWelsSvcRc->iInitialQp;
-  }
-  else if (pWelsSvcRc->iCurrentBitsLevel==BITS_EXCEEDED)
-  {
-	iLumaQp = MAX_LOW_BR_QP;
-	//limit QP
-	int32_t iLastIdxCodecInVGop = pWelsSvcRc->iFrameCodedInVGop - 1;
-	if (iLastIdxCodecInVGop < 0)
-		iLastIdxCodecInVGop += VGOP_SIZE;
-	int32_t iTlLast = pWelsSvcRc->iTlOfFrames[iLastIdxCodecInVGop];
-	int32_t iDeltaQpTemporal = iTl - iTlLast;
-	if (0 == iTlLast && iTl > 0)
-		iDeltaQpTemporal += 3;
-	else if (0 == iTl && iTlLast > 0)
-		iDeltaQpTemporal -= 3;
+  } else if (pWelsSvcRc->iCurrentBitsLevel == BITS_EXCEEDED) {
+    iLumaQp = MAX_LOW_BR_QP;
+    //limit QP
+    int32_t iLastIdxCodecInVGop = pWelsSvcRc->iFrameCodedInVGop - 1;
+    if (iLastIdxCodecInVGop < 0)
+      iLastIdxCodecInVGop += VGOP_SIZE;
+    int32_t iTlLast = pWelsSvcRc->iTlOfFrames[iLastIdxCodecInVGop];
+    int32_t iDeltaQpTemporal = iTl - iTlLast;
+    if (0 == iTlLast && iTl > 0)
+      iDeltaQpTemporal += 3;
+    else if (0 == iTl && iTlLast > 0)
+      iDeltaQpTemporal -= 3;
 
-	iLumaQp = WELS_CLIP3 (iLumaQp,
-		pWelsSvcRc->iLastCalculatedQScale - pWelsSvcRc->iFrameDeltaQpLower + iDeltaQpTemporal,
-		pWelsSvcRc->iLastCalculatedQScale + pWelsSvcRc->iFrameDeltaQpUpper + iDeltaQpTemporal);
-	iLumaQp = WELS_CLIP3 (iLumaQp,  GOM_MIN_QP_MODE, MAX_LOW_BR_QP);
+    iLumaQp = WELS_CLIP3 (iLumaQp,
+                          pWelsSvcRc->iLastCalculatedQScale - pWelsSvcRc->iFrameDeltaQpLower + iDeltaQpTemporal,
+                          pWelsSvcRc->iLastCalculatedQScale + pWelsSvcRc->iFrameDeltaQpUpper + iDeltaQpTemporal);
+    iLumaQp = WELS_CLIP3 (iLumaQp,  GOM_MIN_QP_MODE, MAX_LOW_BR_QP);
 
-	pWelsSvcRc->dQStep = RcConvertQp2QStep (iLumaQp);
-	pWelsSvcRc->iLastCalculatedQScale = iLumaQp;
+    pWelsSvcRc->dQStep = RcConvertQp2QStep (iLumaQp);
+    pWelsSvcRc->iLastCalculatedQScale = iLumaQp;
 
-	if (pEncCtx->pSvcParam->bEnableAdaptiveQuant) {
-		iLumaQp = (int32_t)(iLumaQp - pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp);
-	}
+    if (pEncCtx->pSvcParam->bEnableAdaptiveQuant) {
+      iLumaQp = (int32_t) (iLumaQp - pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp);
+    }
 
-	pEncCtx->iGlobalQp = iLumaQp;
+    pEncCtx->iGlobalQp = iLumaQp;
 
-	return;
-  }
-  else {
+    return;
+  } else {
     double dCmplxRatio = (double)pEncCtx->pVaa->sComplexityAnalysisParam.iFrameComplexity / pTOverRc->iFrameCmplxMean;
     dCmplxRatio = WELS_CLIP3 (dCmplxRatio, 1.0 - FRAME_CMPLX_RATIO_RANGE, 1.0 + FRAME_CMPLX_RATIO_RANGE);
 
@@ -490,10 +487,10 @@
 #ifndef _NOT_USE_AQ_FOR_TEST_
   if (pEncCtx->pSvcParam->bEnableAdaptiveQuant) {
 
-	iLumaQp = (int32_t)(iLumaQp - pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp);
+    iLumaQp = (int32_t) (iLumaQp - pEncCtx->pVaa->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp);
 
-	if (pEncCtx->pSvcParam->iRCMode!=RC_LOW_BW_MODE)
-	  iLumaQp = (int32_t)WELS_CLIP3 (iLumaQp,pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);
+    if (pEncCtx->pSvcParam->iRCMode != RC_LOW_BW_MODE)
+      iLumaQp = (int32_t)WELS_CLIP3 (iLumaQp, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);
 
   }
 #endif
@@ -531,14 +528,11 @@
   } else {
     pWelsSvcRc->iTargetBits = (int32_t) (pWelsSvcRc->iRemainingBits * pTOverRc->dTlayerWeight /
                                          pWelsSvcRc->dRemainingWeights);
-	if ((pWelsSvcRc->iTargetBits <= 0) && (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE))
-	{
-		pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED;
-	}
-	else if ((pWelsSvcRc->iTargetBits <= pTOverRc->iMinBitsTl) && (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE))
-	{
-		pWelsSvcRc->iCurrentBitsLevel = BITS_LIMITED;
-	}
+    if ((pWelsSvcRc->iTargetBits <= 0) && (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE)) {
+      pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED;
+    } else if ((pWelsSvcRc->iTargetBits <= pTOverRc->iMinBitsTl) && (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE)) {
+      pWelsSvcRc->iCurrentBitsLevel = BITS_LIMITED;
+    }
     pWelsSvcRc->iTargetBits = WELS_CLIP3 (pWelsSvcRc->iTargetBits, pTOverRc->iMinBitsTl,	pTOverRc->iMaxBitsTl);
   }
   pWelsSvcRc->dRemainingWeights -= pTOverRc->dTlayerWeight;
@@ -661,8 +655,8 @@
 
   pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice,
                                  pEncCtx->iGlobalQp - pWelsSvcRc->iQpRangeLowerInFrame, pEncCtx->iGlobalQp + pWelsSvcRc->iQpRangeUpperInFrame);
-  if (!(pEncCtx->pSvcParam->iRCMode==RC_LOW_BW_MODE))
-	  pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);
+  if (! (pEncCtx->pSvcParam->iRCMode == RC_LOW_BW_MODE))
+    pSOverRc->iCalculatedQpSlice = WELS_CLIP3 (pSOverRc->iCalculatedQpSlice, pWelsSvcRc->iMinQp, pWelsSvcRc->iMaxQp);
 
   pSOverRc->iGomBitsSlice = 0;
 
--- a/codec/encoder/core/src/ref_list_mgr_svc.cpp
+++ b/codec/encoder/core/src/ref_list_mgr_svc.cpp
@@ -600,7 +600,7 @@
         if (pRef != NULL && pRef->bUsedAsRef && pRef->iFramePoc >= 0 && pRef->uiTemporalId <= kuiTid) {
           pCtx->pRefList0[pCtx->iNumRef0++]	= pRef;
           WelsLog (pCtx, WELS_LOG_INFO, "WelsBuildRefList pCtx->uiTemporalId = %d,pRef->iFrameNum = %d,pRef->uiTemporalId = %d\n",
-                  pCtx->uiTemporalId,pRef->iFrameNum,pRef->uiTemporalId);
+                   pCtx->uiTemporalId, pRef->iFrameNum, pRef->uiTemporalId);
           break;
         }
       }
@@ -640,7 +640,7 @@
     /*syntax for num_ref_idx_l0_active_minus1*/
     pSliceHdr->uiRefCount = pCtx->iNumRef0;
     if (pCtx->iNumRef0 > 0) {
-      if ((!pCtx->pRefList0[0]->bIsLongRef)||(!pCtx->pSvcParam->bEnableLongTermReference)) {
+      if ((!pCtx->pRefList0[0]->bIsLongRef) || (!pCtx->pSvcParam->bEnableLongTermReference)) {
         if (iAbsDiffPicNumMinus1 < 0) {
           WelsLog (pCtx, WELS_LOG_INFO, "WelsUpdateRefSyntax():::uiAbsDiffPicNumMinus1:%d\n", iAbsDiffPicNumMinus1);
           iAbsDiffPicNumMinus1 += (1 << (pCtx->pSps->uiLog2MaxFrameNum));
@@ -662,11 +662,11 @@
       pRefPicMark->bNoOutputOfPriorPicsFlag = false;
       pRefPicMark->bLongTermRefFlag = pCtx->pSvcParam->bEnableLongTermReference;
     } else {
-      if(pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
+      if (pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
         pRefPicMark->bAdaptiveRefPicMarkingModeFlag = pCtx->pSvcParam->bEnableLongTermReference;
       else
         pRefPicMark->bAdaptiveRefPicMarkingModeFlag = (pCtx->pSvcParam->bEnableLongTermReference
-          && pLtr->bLTRMarkingFlag) ? (true) : (false);
+            && pLtr->bLTRMarkingFlag) ? (true) : (false);
     }
   }
 }
@@ -689,17 +689,18 @@
     pCtx->pEncPic->bIsSceneLTR      = pCtx->pDecPic->bIsSceneLTR;
     pCtx->pEncPic->iFrameAverageQp  = pCtx->pDecPic->iFrameAverageQp;
   }
-  PrefetchNextBuffer(pCtx);
+  PrefetchNextBuffer (pCtx);
   for (int32_t i = 0; i < MAX_REF_PIC_COUNT; ++i) {
-    if (NULL == pLongRefSrcList[i + 1] || (NULL != pLongRefList[i] && pLongRefList[i]->bUsedAsRef&& pLongRefList[i]->bIsLongRef)) {
+    if (NULL == pLongRefSrcList[i + 1] || (NULL != pLongRefList[i] && pLongRefList[i]->bUsedAsRef
+                                           && pLongRefList[i]->bIsLongRef)) {
       continue;
-      } else {
-        SetUnref (pLongRefSrcList[i + 1]);
-      }
+    } else {
+      SetUnref (pLongRefSrcList[i + 1]);
     }
-    WelsExchangeSpatialPictures (&pCtx->pVpp->m_pSpatialPic[iDIdx][0],
-                                 &pCtx->pVpp->m_pSpatialPic[iDIdx][1 + pCtx->pVaa->uiMarkLongTermPicIdx]);
-    SetUnref (pCtx->pVpp->m_pSpatialPic[iDIdx][0]);
+  }
+  WelsExchangeSpatialPictures (&pCtx->pVpp->m_pSpatialPic[iDIdx][0],
+                               &pCtx->pVpp->m_pSpatialPic[iDIdx][1 + pCtx->pVaa->uiMarkLongTermPicIdx]);
+  SetUnref (pCtx->pVpp->m_pSpatialPic[iDIdx][0]);
 
   return 0;
 }
@@ -772,8 +773,9 @@
                      "WelsBuildRefListScreen(), ref !current iFrameNum = %d, ref iFrameNum = %d,LTR number = %d,iNumRef = %d ref is Scene LTR = %d\n",
                      pCtx->iFrameNum, pCtx->pRefList0[pCtx->iNumRef0 - 1]->iFrameNum, pRefList->uiLongRefCount, iNumRef,
                      pRefPic->bIsSceneLTR);
-           WelsLog (pCtx, WELS_LOG_INFO, "WelsBuildRefListScreen pCtx->uiTemporalId = %d,pRef->iFrameNum = %d,pRef->uiTemporalId = %d\n",
-                  pCtx->uiTemporalId,pRefPic->iFrameNum,pRefPic->uiTemporalId);
+            WelsLog (pCtx, WELS_LOG_INFO,
+                     "WelsBuildRefListScreen pCtx->uiTemporalId = %d,pRef->iFrameNum = %d,pRef->uiTemporalId = %d\n",
+                     pCtx->uiTemporalId, pRefPic->iFrameNum, pRefPic->uiTemporalId);
           }
         }
       } else {
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -132,8 +132,9 @@
 
   while (iSliceIdx < kiSliceCount) {
     fAvI[iSliceIdx]	= 1.0f * pCountMbInSlice[iSliceIdx] / pSliceTime[iSliceIdx];
-    MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n", iSliceIdx,
-               pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]);
+    MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n",
+                  iSliceIdx,
+                  pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]);
     fSumAv += fAvI[iSliceIdx];
 
     ++ iSliceIdx;
@@ -156,8 +157,9 @@
     iSliceIdx += 2;
   }
   if (uiTotalConsume == 0) {
-    MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n",
-               iSliceNum);
+    MT_TRACE_LOG (NULL, WELS_LOG_DEBUG,
+                  "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n",
+                  iSliceNum);
     return false;
   }
 
@@ -183,8 +185,8 @@
   if (fRmse > fThr)
     iNeedAdj	= true;
   MT_TRACE_LOG (NULL, WELS_LOG_DEBUG,
-             "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n",
-             iNeedAdj, fRmse, fThr, iSliceNum);
+                "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n",
+                iNeedAdj, fRmse, fThr, iSliceNum);
 
   return iNeedAdj;
 }
@@ -256,8 +258,8 @@
     }
     iRunLen[iSliceIdx]	= iNumMbAssigning;
     MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
-             "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n",
-             iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iNumMbAssigning);
+                  "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n",
+                  iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iNumMbAssigning);
     ++ iSliceIdx;
     iMaximalMbNum	= iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum;	// get maximal num_mb in left parts
   }
@@ -313,9 +315,9 @@
 
 #ifdef _WIN32
   // Dummy event namespace, the windows events don't actually use this
-  WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p", (void*) *ppCtx);
+  WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p", (void*) *ppCtx);
 #else
-  WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid());
+  WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid());
 #endif//!_WIN32
 
   iIdx = 0;
@@ -322,7 +324,8 @@
   while (iIdx < iNumSpatialLayers) {
     SSliceConfig* pMso	= &pPara->sDependencyLayers[iIdx].sSliceCfg;
     const int32_t kiSliceNum = pMso->sSliceArgument.uiSliceNum;
-    if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pMso->uiSliceMode == SM_AUTO_SLICE)) && pPara->iMultipleThreadIdc > 1
+    if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE) || (pMso->uiSliceMode == SM_AUTO_SLICE))
+        && pPara->iMultipleThreadIdc > 1
         && pPara->iMultipleThreadIdc >= kiSliceNum) {
       pSmt->pSliceConsumeTime[iIdx]	= (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]");
       WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx))
@@ -371,7 +374,8 @@
     MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
     WelsSnprintf (name, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace);
     err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name);
-    MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
+    MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err,
+                  errno);
     WelsSnprintf (name, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace);
     err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name);
     MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
@@ -415,10 +419,11 @@
   iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate);
   WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
 
-  iReturn = WelsMutexInit (&(*ppCtx)->mutexEncoderError);
+  iReturn = WelsMutexInit (& (*ppCtx)->mutexEncoderError);
   WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
 
-  MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n", pPara->iCountThreadsNum,
+  MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n",
+                pPara->iCountThreadsNum,
                 iMaxSliceNum);
 
   return 0;
@@ -467,7 +472,7 @@
   WelsEventClose (&pSmt->pSliceCodedMasterEvent, ename);
 
   WelsMutexDestroy (&pSmt->mutexSliceNumUpdate);
-  WelsMutexDestroy (&((*ppCtx)->mutexEncoderError));
+  WelsMutexDestroy (& ((*ppCtx)->mutexEncoderError));
 
   if (pSmt->pThreadPEncCtx != NULL) {
     pMa->WelsFree (pSmt->pThreadPEncCtx, "pThreadPEncCtx");
@@ -595,7 +600,8 @@
   return iLayerSize;
 }
 
-int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, int32_t& iSliceSize) {
+int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx,
+                             int32_t& iSliceSize) {
   SWelsSliceBs* pSliceBs			= &pCtx->pSliceBs[iSliceIdx];
   SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt;
   uint8_t* pDst					= pFrameBsBuffer;
@@ -610,8 +616,9 @@
 
   while (iNalIdx < kiNalCnt) {
     iNalSize = 0;
-    iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pCtx->iFrameBsSize-kiWrittenLength-iSliceSize, pDst, &iNalSize);
-    WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
+    iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pCtx->iFrameBsSize - kiWrittenLength - iSliceSize,
+                             pDst, &iNalSize);
+    WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
     iSliceSize += iNalSize;
     pDst += iNalSize;
     pLbi->iNalLengthInByte[iNalBase + iNalIdx]	= iNalSize;
@@ -653,8 +660,9 @@
 
   while (iNalIdx < kiNalCnt) {
     iNalSize = 0;
-    iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize-kiWrittenLength-iSliceSize, pDst, &iNalSize);
-    WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
+    iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize - kiWrittenLength - iSliceSize,
+                             pDst, &iNalSize);
+    WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
     pNalLen[iNalIdx] = iNalSize;
     iSliceSize += iNalSize;
     pDst += iNalSize;
@@ -702,7 +710,8 @@
                   "[MT] CodingSliceThreadProc(), try to call WelsMultipleEventsWaitSingleBlocking(pEventsList= %p %p %p), pEncPEncCtx= %p!\n",
                   pEventsList[0], pEventsList[1], pEventsList[1], (void*)pEncPEncCtx);
     iWaitRet = WelsMultipleEventsWaitSingleBlocking (iEventCount,
-               &pEventsList[0], &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled
+               &pEventsList[0],
+               &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled
     if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) {	// start pSlice coding signal waited
       SLayerBSInfo* pLbi = pPrivateData->pLayerBs;
       const int32_t kiCurDid			= pEncPEncCtx->uiDependencyId;
@@ -722,7 +731,8 @@
         pSlice			= &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
         pSliceBs		= &pEncPEncCtx->pSliceBs[iSliceIdx];
 
-        bDsaFlag	= (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pParamD->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)) &&
+        bDsaFlag	= (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)
+                      || (pParamD->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)) &&
                      pCodingParam->iMultipleThreadIdc > 1 &&
                      pCodingParam->iMultipleThreadIdc >= pParamD->sSliceCfg.sSliceArgument.uiSliceNum);
         if (bDsaFlag)
@@ -752,7 +762,7 @@
         WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc);
 
         iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType);
-        if (ENC_RETURN_SUCCESS!=iReturn) {
+        if (ENC_RETURN_SUCCESS != iReturn) {
           uiThrdRet = iReturn;
           break;
         }
@@ -762,15 +772,14 @@
         if (0 == iSliceIdx) {
           pLbi->pBsBuf	= pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer;
           iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize);
-          if (ENC_RETURN_SUCCESS!=iReturn) {
+          if (ENC_RETURN_SUCCESS != iReturn) {
             uiThrdRet = iReturn;
             break;
           }
           pEncPEncCtx->iPosBsBuffer += iSliceSize;
-        } else
-        {
+        } else {
           iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize);
-          if (ENC_RETURN_SUCCESS!=iReturn) {
+          if (ENC_RETURN_SUCCESS != iReturn) {
             uiThrdRet = iReturn;
             break;
           }
@@ -859,7 +868,7 @@
           WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc);
 
           iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType);
-          if (ENC_RETURN_SUCCESS!=iReturn) {
+          if (ENC_RETURN_SUCCESS != iReturn) {
             uiThrdRet = iReturn;
             break;
           }
@@ -869,16 +878,16 @@
           if (0 == kiPartitionId) {
             if (0 == iSliceIdx)
               pLbi->pBsBuf	= pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer;
-            iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx, iSliceSize);
-            if (ENC_RETURN_SUCCESS!=iReturn) {
+            iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx,
+                                           iSliceSize);
+            if (ENC_RETURN_SUCCESS != iReturn) {
               uiThrdRet = iReturn;
               break;
             }
             pEncPEncCtx->iPosBsBuffer += iSliceSize;
-          } else
-          {
+          } else {
             iSliceSize = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize);
-            if (ENC_RETURN_SUCCESS!=iReturn) {
+            if (ENC_RETURN_SUCCESS != iReturn) {
               uiThrdRet = iReturn;
               break;
             }
@@ -918,12 +927,10 @@
         WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]);	// mean finished coding current pSlice
         WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent);
       }
-    }
-    else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 1 == iWaitRet) {	// exit thread signal
+    } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 1 == iWaitRet) {	// exit thread signal
       uiThrdRet	= 0;
       break;
-    }
-    else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) {	// update pMb list singal
+    } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) {	// update pMb list singal
       iSliceIdx		=
         iEventIdx;	// pPrivateData->iSliceIndex; old threads can not be terminated, pPrivateData is not correct for applicable
       pCurDq			= pEncPEncCtx->pCurDqLayer;
@@ -930,8 +937,7 @@
       UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx);
       WelsEventSignal (
         &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]);	// mean finished update pMb list for this pSlice
-    }
-    else { // WELS_THREAD_ERROR_WAIT_TIMEOUT, or WELS_THREAD_ERROR_WAIT_FAILED
+    } else { // WELS_THREAD_ERROR_WAIT_TIMEOUT, or WELS_THREAD_ERROR_WAIT_FAILED
       WelsLog (pEncPEncCtx, WELS_LOG_WARNING,
                "[MT] CodingSliceThreadProc(), waiting pReadySliceCodingEvent[%d] failed(%d) and thread%d terminated!\n", iEventIdx,
                iWaitRet, iThreadIdx);
@@ -962,9 +968,9 @@
   return 0;
 }
 
-int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLbi,
-                           const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode)
-{
+int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList,
+                           SLayerBSInfo* pLbi,
+                           const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) {
   int32_t iEndMbIdx	= 0;
   int32_t iIdx		= 0;
   const int32_t kiEventCnt = uiNumThreads;
@@ -1044,9 +1050,9 @@
   // if using spatial base layer for complexity estimation
 
   const bool kbModelingFromSpatial =	(pCtx->pCurDqLayer->pRefLayer != NULL && iCurDid > 0)
-                                        && (pCtx->pSvcParam->sDependencyLayers[iCurDid - 1].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
-                                            && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sDependencyLayers[iCurDid -
-                                                1].sSliceCfg.sSliceArgument.uiSliceNum);
+                                      && (pCtx->pSvcParam->sDependencyLayers[iCurDid - 1].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE
+                                          && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sDependencyLayers[iCurDid -
+                                              1].sSliceCfg.sSliceArgument.uiSliceNum);
 
   if (kbModelingFromSpatial) {	// using spatial base layer for complexity estimation
     // do not need adjust due to not different at both slices of consumed time
@@ -1116,7 +1122,7 @@
     const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame;
     if (pCtx->pSliceThreading) {
       if (pCtx->pSliceThreading->pFSliceDiff
-          && ((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pMso->uiSliceMode == SM_AUTO_SLICE))
+          && ((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE) || (pMso->uiSliceMode == SM_AUTO_SLICE))
           && pPara->iMultipleThreadIdc > 1
           && pPara->iMultipleThreadIdc >= kuiCountSliceNum) {
         uint32_t i = 0;
--- a/codec/encoder/core/src/svc_base_layer_md.cpp
+++ b/codec/encoder/core/src/svc_base_layer_md.cpp
@@ -358,7 +358,8 @@
   ST32 (&pCurMb->sP16x16Mv, 0);
   ST32 (&pCurLayer->pDecPic->sMvList[kiMbXY], 0);
 
-  SetMvWithinIntegerMvRange( kiMbWidth, kiMbHeight, kiMbX, kiMbY, CAMERA_STARTMV_RANGE, &(pSlice->sMvStartMin), &(pSlice->sMvStartMax));
+  SetMvWithinIntegerMvRange (kiMbWidth, kiMbHeight, kiMbX, kiMbY, CAMERA_STARTMV_RANGE, & (pSlice->sMvStartMin),
+                             & (pSlice->sMvStartMax));
 }
 
 int32_t WelsMdI16x16 (SWelsFuncPtrList* pFunc, SDqLayer* pCurDqLayer, SMbCache* pMbCache, int32_t iLambda) {
@@ -969,9 +970,8 @@
   WelsMdIntraSecondaryModesEnc (pEncCtx, pWelsMd, pCurMb, pMbCache);
 }
 
-static inline void InitMe(const SWelsMD& sWelsMd, const int32_t iBlockSize, uint8_t* pEnc, uint8_t* pRef,
-                   SWelsME& sWelsMe )
-{
+static inline void InitMe (const SWelsMD& sWelsMd, const int32_t iBlockSize, uint8_t* pEnc, uint8_t* pRef,
+                           SWelsME& sWelsMe) {
   sWelsMe.iCurMeBlockPixX = sWelsMd.iMbPixX;
   sWelsMe.iCurMeBlockPixY = sWelsMd.iMbPixY;
   sWelsMe.uiBlockSize = iBlockSize;
@@ -987,8 +987,8 @@
   uint32_t uiNeighborAvail = pCurMb->uiNeighborAvail;
   const int32_t kiMbWidth	= pCurLayer->iMbWidth;	// for assign once
   const int32_t kiMbHeight	= pCurLayer->iMbHeight;
-  InitMe(*pWelsMd, BLOCK_16x16, pMbCache->SPicData.pEncMb[0], pMbCache->SPicData.pRefMb[0],
-                   *pMe16x16 );
+  InitMe (*pWelsMd, BLOCK_16x16, pMbCache->SPicData.pEncMb[0], pMbCache->SPicData.pRefMb[0],
+          *pMe16x16);
   //not putting the line below into InitMe to avoid judging mode in InitMe
   pMe16x16->uSadPredISatd.uiSadPred = pWelsMd->iSadPredMb;
 
@@ -1035,10 +1035,10 @@
   do {
     sMe16x8 = &pWelsMd->sMe.sMe16x8[i];
     iPixelY = (i << 3);
-    InitMe(*pWelsMd, BLOCK_16x8,
-      pMbCache->SPicData.pEncMb[0] + (iPixelY * iStrideEnc),
-      pMbCache->SPicData.pRefMb[0] + (iPixelY * iStrideRef),
-      *sMe16x8 );
+    InitMe (*pWelsMd, BLOCK_16x8,
+            pMbCache->SPicData.pEncMb[0] + (iPixelY * iStrideEnc),
+            pMbCache->SPicData.pRefMb[0] + (iPixelY * iStrideRef),
+            *sMe16x8);
     //not putting the lines below into InitMe to avoid judging mode in InitMe
     sMe16x8->iCurMeBlockPixY = pWelsMd->iMbPixY + iPixelY;
     sMe16x8->uSadPredISatd.uiSadPred = pWelsMd->iSadPredMb >> 1;
@@ -1062,10 +1062,10 @@
   do {
     iPixelX = (i << 3);
     sMe8x16 = &pWelsMd->sMe.sMe8x16[i];
-    InitMe(*pWelsMd, BLOCK_8x16,
-      pMbCache->SPicData.pEncMb[0] + iPixelX,
-      pMbCache->SPicData.pRefMb[0] + iPixelX,
-      *sMe8x16 );
+    InitMe (*pWelsMd, BLOCK_8x16,
+            pMbCache->SPicData.pEncMb[0] + iPixelX,
+            pMbCache->SPicData.pRefMb[0] + iPixelX,
+            *sMe8x16);
     //not putting the lines below into InitMe to avoid judging mode in InitMe
     sMe8x16->iCurMeBlockPixX = pWelsMd->iMbPixX + iPixelX;
     sMe8x16->uSadPredISatd.uiSadPred = pWelsMd->iSadPredMb >> 1;
@@ -1093,14 +1093,14 @@
     iIdxY = i >> 1;
     iPixelX = (iIdxX << 3);
     iPixelY = (iIdxY << 3);
-    iStrideEnc = iPixelX + ( iPixelY * iLineSizeEnc);
-    iStrideRef = iPixelX + ( iPixelY * iLineSizeRef);
+    iStrideEnc = iPixelX + (iPixelY * iLineSizeEnc);
+    iStrideRef = iPixelX + (iPixelY * iLineSizeRef);
 
     sMe8x8 = &pWelsMd->sMe.sMe8x8[i];
-    InitMe(*pWelsMd, BLOCK_8x8,
-      pMbCache->SPicData.pEncMb[0] + iStrideEnc,
-      pMbCache->SPicData.pRefMb[0] + iStrideRef,
-      *sMe8x8 );
+    InitMe (*pWelsMd, BLOCK_8x8,
+            pMbCache->SPicData.pEncMb[0] + iStrideEnc,
+            pMbCache->SPicData.pRefMb[0] + iStrideRef,
+            *sMe8x8);
     //not putting these three lines below into InitMe to avoid judging mode in InitMe
     sMe8x8->iCurMeBlockPixX = pWelsMd->iMbPixX + iPixelX;
     sMe8x8->iCurMeBlockPixY = pWelsMd->iMbPixY + iPixelY;
@@ -1340,7 +1340,7 @@
   PredSkipMv (pMbCache, &sMvp);
 
   // Special case, need to clip the vector //
-  SMVUnitXY sQpelMvp = { static_cast<int16_t>(sMvp.iMvX >> 2), static_cast<int16_t>(sMvp.iMvY >> 2) };
+  SMVUnitXY sQpelMvp = { static_cast<int16_t> (sMvp.iMvX >> 2), static_cast<int16_t> (sMvp.iMvY >> 2) };
   n = (pCurMb->iMbX << 4) + sQpelMvp.iMvX;
   if (n < -29)
     return false;
@@ -1669,7 +1669,7 @@
 //  try the ordinary Pskip
 //////
 bool WelsMdInterJudgePskip (sWelsEncCtx* pEncCtx, SWelsMD* pWelsMd, SSlice* pSlice, SMB* pCurMb, SMbCache* pMbCache,
-                              bool bTrySkip) {
+                            bool bTrySkip) {
   bool bRet = true;
   if (((pEncCtx->pRefPic->iPictureType == P_SLICE) && (pMbCache->uiRefMbType == MB_TYPE_SKIP
        || pMbCache->uiRefMbType == MB_TYPE_BACKGROUND)) ||
@@ -1751,7 +1751,7 @@
 //  try the BGD Pskip
 //////
 bool WelsMdInterJudgeBGDPskip (void* pCtx, void* pMd, SSlice* pSlice, SMB* pCurMb, SMbCache* pMbCache,
-                                 bool* bKeepSkip) {
+                               bool* bKeepSkip) {
   sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx;
   SWelsMD* pWelsMd = (SWelsMD*)pMd;
 
@@ -1783,7 +1783,7 @@
 }
 
 bool WelsMdInterJudgeBGDPskipFalse (void* pCtx, void* pMd, SSlice* pSlice, SMB* pCurMb, SMbCache* pMbCache,
-                                      bool* bKeepSkip) {
+                                    bool* bKeepSkip) {
   return false;
 }
 
--- a/codec/encoder/core/src/svc_enc_slice_segment.cpp
+++ b/codec/encoder/core/src/svc_enc_slice_segment.cpp
@@ -84,7 +84,7 @@
 
     return 0;
   } else if (SM_RASTER_SLICE  == pSliceSeg->uiSliceMode ||
-             SM_FIXEDSLCNUM_SLICE == pSliceSeg->uiSliceMode||
+             SM_FIXEDSLCNUM_SLICE == pSliceSeg->uiSliceMode ||
              SM_AUTO_SLICE == pSliceSeg->uiSliceMode) {
     const int32_t* kpSlicesAssignList				= (int32_t*) & (kpMso->sSliceArgument.uiSliceMbNum[0]);
     const int32_t kiCountNumMbInFrame		= pSliceSeg->iMbNumInFrame;
@@ -310,7 +310,7 @@
   case SM_FIXEDSLCNUM_SLICE:
   case SM_RASTER_SLICE:
   case SM_ROWMB_SLICE:
-  case SM_AUTO_SLICE:{
+  case SM_AUTO_SLICE: {
     return pMso->sSliceArgument.uiSliceNum;
   }
   case SM_DYN_SLICE: {
@@ -400,7 +400,7 @@
     return AssignMbMapSingleSlice (pSliceSeg->pOverallMbMap, kiCountMbNum, sizeof (pSliceSeg->pOverallMbMap[0]));
   } else { //if ( SM_MULTIPLE_SLICE == uiSliceMode )
     if (uiSliceMode != SM_FIXEDSLCNUM_SLICE && uiSliceMode != SM_ROWMB_SLICE && uiSliceMode != SM_RASTER_SLICE
-        && uiSliceMode != SM_DYN_SLICE&& uiSliceMode != SM_AUTO_SLICE)
+        && uiSliceMode != SM_DYN_SLICE && uiSliceMode != SM_AUTO_SLICE)
       return 1;
 
     pSliceSeg->pOverallMbMap	= (uint8_t*)pMa->WelsMalloc (kiCountMbNum * sizeof (uint8_t), "pSliceSeg->pOverallMbMap");
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -644,7 +644,7 @@
 
   const bool kbBaseAvail		= pCurLayer->bBaseLayerAvailableFlag;
   const bool kbHighestSpatial = pEncCtx->pSvcParam->iSpatialLayerNum ==
-                                  (pCurLayer->sLayerInfo.sNalHeaderExt.uiDependencyId + 1);
+                                (pCurLayer->sLayerInfo.sNalHeaderExt.uiDependencyId + 1);
 
   //MD switch
   if (kbBaseAvail && kbHighestSpatial) {
@@ -663,7 +663,7 @@
 
   const bool kbBaseAvail		= pCurLayer->bBaseLayerAvailableFlag;
   const bool kbHighestSpatial = pEncCtx->pSvcParam->iSpatialLayerNum ==
-                                  (pCurLayer->sLayerInfo.sNalHeaderExt.uiDependencyId + 1);
+                                (pCurLayer->sLayerInfo.sNalHeaderExt.uiDependencyId + 1);
 
   //MD switch
   if (kbBaseAvail && kbHighestSpatial) {
@@ -693,7 +693,8 @@
   SNalUnitHeaderExt* pNalHeadExt	= &pCurLayer->sLayerInfo.sNalHeaderExt;
   SSlice* pCurSlice					= &pCurLayer->sLayerInfo.pSliceInLayer[kiSliceIdx];
   SBitStringAux* pBs					= pCurSlice->pSliceBsa;
-  const int32_t kiDynamicSliceFlag	= (pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId].sSliceCfg.uiSliceMode ==
+  const int32_t kiDynamicSliceFlag	= (pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId].sSliceCfg.uiSliceMode
+                                       ==
                                        SM_DYN_SLICE);
 
   assert (kiSliceIdx == pCurSlice->uiSliceIdx);
@@ -831,7 +832,7 @@
 }
 
 bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
-    SDynamicSlicingStack* pDss) {
+                                       SDynamicSlicingStack* pDss) {
   sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx;
   SSlice* pCurSlice = (SSlice*)pSlice;
   int32_t		   iCurMbIdx  = pCurMb->iMbXY;
@@ -903,13 +904,13 @@
 ///////////////
 //  pMb loop
 ///////////////
-inline void WelsInitInterMDStruc(const SMB* pCurMb, uint16_t *pMvdCostTableInter, const int32_t kiMvdInterTableStride, SWelsMD* pMd )
-{
+inline void WelsInitInterMDStruc (const SMB* pCurMb, uint16_t* pMvdCostTableInter, const int32_t kiMvdInterTableStride,
+                                  SWelsMD* pMd) {
   pMd->iLambda = g_kiQpCostTable[pCurMb->uiLumaQp];
   pMd->pMvdCost = &pMvdCostTableInter[pCurMb->uiLumaQp * kiMvdInterTableStride];
-  pMd->	iMbPixX = (pCurMb->iMbX<<4);
-  pMd->	iMbPixY = (pCurMb->iMbY<<4);
-  memset( &pMd->iBlock8x8StaticIdc[0], 0, sizeof(pMd->iBlock8x8StaticIdc) );
+  pMd->	iMbPixX = (pCurMb->iMbX << 4);
+  pMd->	iMbPixY = (pCurMb->iMbY << 4);
+  memset (&pMd->iBlock8x8StaticIdc[0], 0, sizeof (pMd->iBlock8x8StaticIdc));
 }
 // for inter non-dynamic pSlice
 int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, const int32_t kiSliceFirstMbXY) {
@@ -943,7 +944,7 @@
     //step (2). save some vale for future use, initial pWelsMd
     WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
     WelsMdInterInit (pEncCtx, pSlice, pCurMb, kiSliceFirstMbXY);
-    WelsInitInterMDStruc(pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd );
+    WelsInitInterMDStruc (pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd);
     pEncCtx->pFuncList->pfInterMd (pEncCtx, pMd, pSlice, pCurMb, pMbCache);
     //mb_qp
 
@@ -999,7 +1000,7 @@
 
 // Only for inter dynamic slicing
 int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd,
-                                        const int32_t kiSliceFirstMbXY) {
+    const int32_t kiSliceFirstMbXY) {
   SWelsMD* pMd					= (SWelsMD*)pWelsMd;
   SBitStringAux* pBs			= pSlice->pSliceBsa;
   SDqLayer* pCurLayer			= pEncCtx->pCurDqLayer;
@@ -1041,7 +1042,7 @@
     //step (2). save some vale for future use, initial pWelsMd
     WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
     WelsMdInterInit (pEncCtx, pSlice, pCurMb, kiSliceFirstMbXY);
-    WelsInitInterMDStruc(pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd );
+    WelsInitInterMDStruc (pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd);
     pEncCtx->pFuncList->pfInterMd (pEncCtx, pMd, pSlice, pCurMb, pMbCache);
     //mb_qp
 
--- a/codec/encoder/core/src/svc_mode_decision.cpp
+++ b/codec/encoder/core/src/svc_mode_decision.cpp
@@ -61,7 +61,7 @@
   const bool kbMbTopAvailPskip			= ((kuiNeighborAvail & TOP_MB_POS) ? IS_SKIP (kpTopMb->uiMbType) : false);
   const bool kbMbTopLeftAvailPskip		= ((kuiNeighborAvail & TOPLEFT_MB_POS) ? IS_SKIP ((kpTopMb - 1)->uiMbType) : false);
   const bool kbMbTopRightAvailPskip	= ((kuiNeighborAvail & TOPRIGHT_MB_POS) ? IS_SKIP ((
-      kpTopMb + 1)->uiMbType) : false);
+                                         kpTopMb + 1)->uiMbType) : false);
 
   bool bTrySkip  = kbMbLeftAvailPskip | kbMbTopAvailPskip | kbMbTopLeftAvailPskip | kbMbTopRightAvailPskip;
   bool bKeepSkip = kbMbLeftAvailPskip & kbMbTopAvailPskip & kbMbTopRightAvailPskip;
@@ -162,11 +162,12 @@
 ///////////////////////
 // Scrolling PSkip Decision for screen content
 ////////////////////////
-bool WelsMdInterJudgeScrollingPskip(void* pEncCtx, void* pWelsMd, SSlice* slice, SMB* pCurMb, SMbCache* pMbCache) {
+bool WelsMdInterJudgeScrollingPskip (void* pEncCtx, void* pWelsMd, SSlice* slice, SMB* pCurMb, SMbCache* pMbCache) {
   //TBD
   return false;
 }
-bool WelsMdInterJudgeScrollingPskipFalse(void* pEncCtx, void* pWelsMd, SSlice* slice, SMB* pCurMb, SMbCache* pMbCache) {
+bool WelsMdInterJudgeScrollingPskipFalse (void* pEncCtx, void* pWelsMd, SSlice* slice, SMB* pCurMb,
+    SMbCache* pMbCache) {
   return false;
 }
 
--- a/codec/encoder/core/src/svc_motion_estimate.cpp
+++ b/codec/encoder/core/src/svc_motion_estimate.cpp
@@ -46,30 +46,31 @@
 namespace WelsSVCEnc {
 
 const int32_t QStepx16ByQp[52] = {  /* save QStep<<4 for int32_t */
-    10,  11,  13,  14,  16,  18,  /* 0~5   */
-    20,  22,  26,  28,  32,  36,  /* 6~11  */
-    40,  44,  52,  56,  64,  72,  /* 12~17 */
-    80,  88,  104, 112, 128, 144, /* 18~23 */
-    160, 176, 208, 224, 256, 288, /* 24~29 */
-    320, 352, 416, 448, 512, 576, /* 30~35 */
-    640, 704, 832, 896, 1024, 1152, /* 36~41 */
-    1280, 1408, 1664, 1792, 2048, 2304, /* 42~47 */
-    2560, 2816, 3328, 3584     /* 48~51 */
+  10,  11,  13,  14,  16,  18,  /* 0~5   */
+  20,  22,  26,  28,  32,  36,  /* 6~11  */
+  40,  44,  52,  56,  64,  72,  /* 12~17 */
+  80,  88,  104, 112, 128, 144, /* 18~23 */
+  160, 176, 208, 224, 256, 288, /* 24~29 */
+  320, 352, 416, 448, 512, 576, /* 30~35 */
+  640, 704, 832, 896, 1024, 1152, /* 36~41 */
+  1280, 1408, 1664, 1792, 2048, 2304, /* 42~47 */
+  2560, 2816, 3328, 3584     /* 48~51 */
 };
 
-static inline void UpdateMeResults( const SMVUnitXY ksBestMv, const uint32_t kiBestSadCost, uint8_t* pRef, SWelsME * pMe ) {
+static inline void UpdateMeResults (const SMVUnitXY ksBestMv, const uint32_t kiBestSadCost, uint8_t* pRef,
+                                    SWelsME* pMe) {
   pMe->sMv = ksBestMv;
   pMe->pRefMb = pRef;
   pMe->uiSadCost = kiBestSadCost;
 }
-static inline void MeEndIntepelSearch( SWelsME * pMe ) {
-    /* -> qpel mv */
-    pMe->sMv.iMvX <<= 2;
-    pMe->sMv.iMvY <<= 2;
-    pMe->uiSatdCost = pMe->uiSadCost;
+static inline void MeEndIntepelSearch (SWelsME* pMe) {
+  /* -> qpel mv */
+  pMe->sMv.iMvX <<= 2;
+  pMe->sMv.iMvY <<= 2;
+  pMe->uiSatdCost = pMe->uiSadCost;
 }
 
-void WelsInitMeFunc( SWelsFuncPtrList* pFuncList, uint32_t uiCpuFlag, bool bScreenContent ) {
+void WelsInitMeFunc (SWelsFuncPtrList* pFuncList, uint32_t uiCpuFlag, bool bScreenContent) {
   if (!bScreenContent) {
     pFuncList->pfCheckDirectionalMv = CheckDirectionalMvFalse;
     pFuncList->pfCalculateBlockFeatureOfFrame[0] =
@@ -84,7 +85,7 @@
     pFuncList->pfVerticalFullSearch = LineFullSearch_c;
     pFuncList->pfHorizontalFullSearch = LineFullSearch_c;
 #if defined (X86_ASM)
-    if ( uiCpuFlag & WELS_CPU_SSE41 ) {
+    if (uiCpuFlag & WELS_CPU_SSE41) {
       pFuncList->pfSampleSadHor8[0] = SampleSad8x8Hor8_sse41;
       pFuncList->pfSampleSadHor8[1] = SampleSad16x16Hor8_sse41;
       pFuncList->pfVerticalFullSearch = VerticalFullSearchUsingSSE41;
@@ -119,12 +120,13 @@
   const int32_t kiStrideRef = pCurDqLayer->pRefPic->iLineSize[0];
 
   //  Step 1: Initial point prediction
-  if ( !WelsMotionEstimateInitialPoint (pFuncList, pMe, pSlice, kiStrideEnc, kiStrideRef) ) {
+  if (!WelsMotionEstimateInitialPoint (pFuncList, pMe, pSlice, kiStrideEnc, kiStrideRef)) {
     pFuncList->pfSearchMethod[pMe->uiBlockSize] (pFuncList, pMe, pSlice, kiStrideEnc, kiStrideRef);
-    MeEndIntepelSearch(pMe);
+    MeEndIntepelSearch (pMe);
   }
 
-  pFuncList->pfCalculateSatd( pFuncList->sSampleDealingFuncs.pfSampleSatd[pMe->uiBlockSize], pMe, kiStrideEnc, kiStrideRef );
+  pFuncList->pfCalculateSatd (pFuncList->sSampleDealingFuncs.pfSampleSatd[pMe->uiBlockSize], pMe, kiStrideEnc,
+                              kiStrideRef);
 }
 
 /*!
@@ -185,31 +187,31 @@
     }
   }
 
-  if ( pFuncList->pfCheckDirectionalMv
-    (pSad, pMe, ksMvStartMin, ksMvStartMax, iStrideEnc, iStrideRef, iSadCost) ) {
-      sMv = pMe->sDirectionalMv;
-      pRefMb =  &pMe->pColoRefMb[sMv.iMvY * iStrideRef + sMv.iMvX];
-      iBestSadCost = iSadCost;
+  if (pFuncList->pfCheckDirectionalMv
+      (pSad, pMe, ksMvStartMin, ksMvStartMax, iStrideEnc, iStrideRef, iSadCost)) {
+    sMv = pMe->sDirectionalMv;
+    pRefMb =  &pMe->pColoRefMb[sMv.iMvY * iStrideRef + sMv.iMvX];
+    iBestSadCost = iSadCost;
   }
 
-  UpdateMeResults( sMv, iBestSadCost, pRefMb, pMe );
-  if ( iBestSadCost < static_cast<int32_t>(pMe->uSadPredISatd.uiSadPred) ) {
+  UpdateMeResults (sMv, iBestSadCost, pRefMb, pMe);
+  if (iBestSadCost < static_cast<int32_t> (pMe->uSadPredISatd.uiSadPred)) {
     //Initial point early Stop
-    MeEndIntepelSearch(pMe);
+    MeEndIntepelSearch (pMe);
     return true;
   }
   return false;
 }
 
-void CalculateSatdCost( PSampleSadSatdCostFunc pSatd, void * vpMe,
-                       const int32_t kiEncStride, const int32_t kiRefStride ) {
-  SWelsME* pMe             = static_cast<SWelsME *>(vpMe);
-  pMe->uSadPredISatd.uiSatd = pSatd(pMe->pEncMb, kiEncStride, pMe->pRefMb, kiRefStride);
+void CalculateSatdCost (PSampleSadSatdCostFunc pSatd, void* vpMe,
+                        const int32_t kiEncStride, const int32_t kiRefStride) {
+  SWelsME* pMe             = static_cast<SWelsME*> (vpMe);
+  pMe->uSadPredISatd.uiSatd = pSatd (pMe->pEncMb, kiEncStride, pMe->pRefMb, kiRefStride);
   pMe->uiSatdCost = pMe->uSadPredISatd.uiSatd + COST_MVD (pMe->pMvdCost, pMe->sMv.iMvX - pMe->sMvp.iMvX,
-                                                            pMe->sMv.iMvY - pMe->sMvp.iMvY);
+                    pMe->sMv.iMvY - pMe->sMvp.iMvY);
 }
-void NotCalculateSatdCost( PSampleSadSatdCostFunc pSatd, void * vpMe,
-                          const int32_t kiEncStride, const int32_t kiRefStride ) {
+void NotCalculateSatdCost (PSampleSadSatdCostFunc pSatd, void* vpMe,
+                           const int32_t kiEncStride, const int32_t kiRefStride) {
 }
 
 
@@ -217,7 +219,7 @@
 // Diamond Search Basics
 /////////////////////////
 bool WelsMeSadCostSelect (int32_t* iSadCost, const uint16_t* kpMvdCost, int32_t* pBestCost, const int32_t kiDx,
-                            const int32_t kiDy, int32_t* pIx, int32_t* pIy) {
+                          const int32_t kiDy, int32_t* pIx, int32_t* pIy) {
   int32_t iTempSadCost[4];
   int32_t iInputSadCost = *pBestCost;
   iTempSadCost[0] = iSadCost[0] + COST_MVD (kpMvdCost, kiDx, kiDy - 4);
@@ -286,8 +288,8 @@
   }
 
   /* integer-pel mv */
-  pMe->sMv.iMvX = (iMvDx + pMe->sMvp.iMvX) >>2;
-  pMe->sMv.iMvY = (iMvDy + pMe->sMvp.iMvY) >>2;
+  pMe->sMv.iMvX = (iMvDx + pMe->sMvp.iMvX) >> 2;
+  pMe->sMv.iMvY = (iMvDy + pMe->sMvp.iMvY) >> 2;
   pMe->uiSatdCost = pMe->uiSadCost = (iBestCost);
   pMe->pRefMb = pRefMb;
 }
@@ -295,21 +297,21 @@
 /////////////////////////
 // DirectionalMv Basics
 /////////////////////////
-bool CheckDirectionalMv(PSampleSadSatdCostFunc pSad, void * vpMe,
-                      const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
-                      int32_t& iBestSadCost) {
-  SWelsME* pMe             = static_cast<SWelsME *>(vpMe);
+bool CheckDirectionalMv (PSampleSadSatdCostFunc pSad, void* vpMe,
+                         const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
+                         int32_t& iBestSadCost) {
+  SWelsME* pMe             = static_cast<SWelsME*> (vpMe);
   const int16_t kiMvX = pMe->sDirectionalMv.iMvX;
   const int16_t kiMvY = pMe->sDirectionalMv.iMvY;
 
   //Check MV from scrolling detection
-  if ( (BLOCK_16x16!=pMe->uiBlockSize) //scrolled_MV with P16x16 is checked SKIP checking function
-    && ( kiMvX | kiMvY ) //(0,0) checked in ordinary initial point checking
-    && CheckMvInRange( pMe->sDirectionalMv, ksMinMv, ksMaxMv ) ) {
+  if ((BLOCK_16x16 != pMe->uiBlockSize) //scrolled_MV with P16x16 is checked SKIP checking function
+      && (kiMvX | kiMvY)   //(0,0) checked in ordinary initial point checking
+      && CheckMvInRange (pMe->sDirectionalMv, ksMinMv, ksMaxMv)) {
     uint8_t* pRef = &pMe->pColoRefMb[kiMvY * kiRefStride + kiMvX];
-    uint32_t uiCurrentSadCost = pSad( pMe->pEncMb, kiEncStride,  pRef, kiRefStride ) +
-      COST_MVD(pMe->pMvdCost, (kiMvX<<2) - pMe->sMvp.iMvX, (kiMvY<<2) - pMe->sMvp.iMvY );
-    if( uiCurrentSadCost < pMe->uiSadCost ) {
+    uint32_t uiCurrentSadCost = pSad (pMe->pEncMb, kiEncStride,  pRef, kiRefStride) +
+                                COST_MVD (pMe->pMvdCost, (kiMvX << 2) - pMe->sMvp.iMvX, (kiMvY << 2) - pMe->sMvp.iMvY);
+    if (uiCurrentSadCost < pMe->uiSadCost) {
       iBestSadCost = uiCurrentSadCost;
       return true;
     }
@@ -317,9 +319,9 @@
   return false;
 }
 
-bool CheckDirectionalMvFalse(PSampleSadSatdCostFunc pSad, void * vpMe,
-                      const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
-                      int32_t& iBestSadCost) {
+bool CheckDirectionalMvFalse (PSampleSadSatdCostFunc pSad, void* vpMe,
+                              const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
+                              int32_t& iBestSadCost) {
   return false;
 }
 
@@ -327,44 +329,45 @@
 // Cross Search Basics
 /////////////////////////
 #if defined (X86_ASM)
-void CalcMvdCostx8_c( uint16_t *pMvdCost, const int32_t kiStartMv, uint16_t* pMvdTable, const uint16_t kiFixedCost )
-{
-  uint16_t *pBaseCost  = pMvdCost;
-  const int32_t kiOffset = (kiStartMv<<2);
-  uint16_t *pMvd  = pMvdTable+kiOffset;
+void CalcMvdCostx8_c (uint16_t* pMvdCost, const int32_t kiStartMv, uint16_t* pMvdTable, const uint16_t kiFixedCost) {
+  uint16_t* pBaseCost  = pMvdCost;
+  const int32_t kiOffset = (kiStartMv << 2);
+  uint16_t* pMvd  = pMvdTable + kiOffset;
   for (int32_t i = 0; i < 8; ++ i) {
     pBaseCost[i] = ((*pMvd) + kiFixedCost);
     pMvd += 4;
   }
 }
-void VerticalFullSearchUsingSSE41( SWelsFuncPtrList *pFuncList, SWelsME *pMe,
-                            uint16_t* pMvdTable, const int32_t kiFixedMvd,
-                            const int32_t kiEncStride, const int32_t kiRefStride,
-                          const int32_t kiMinPos, const int32_t kiMaxPos,
-                          const bool bVerticalSearch ) {
+void VerticalFullSearchUsingSSE41 (SWelsFuncPtrList* pFuncList, SWelsME* pMe,
+                                   uint16_t* pMvdTable, const int32_t kiFixedMvd,
+                                   const int32_t kiEncStride, const int32_t kiRefStride,
+                                   const int32_t kiMinPos, const int32_t kiMaxPos,
+                                   const bool bVerticalSearch) {
   uint8_t*  kpEncMb = pMe->pEncMb;
   const int32_t kiCurMeBlockPix = pMe->iCurMeBlockPixY;
-  uint8_t* pRef         = &pMe->pColoRefMb[(kiMinPos - kiCurMeBlockPix)*kiRefStride];
+  uint8_t* pRef         = &pMe->pColoRefMb[ (kiMinPos - kiCurMeBlockPix) * kiRefStride];
   const int32_t kIsBlock16x16 = pMe->uiBlockSize == BLOCK_16x16;
   const int32_t kiEdgeBlocks = kIsBlock16x16 ? 16 : 8;
   PSampleSadHor8Func pSampleSadHor8 = pFuncList->pfSampleSadHor8[kIsBlock16x16];
   PSampleSadSatdCostFunc pSad = pFuncList->sSampleDealingFuncs.pfSampleSad[pMe->uiBlockSize];
-  PTransposeMatrixBlockFunc TransposeMatrixBlock = kIsBlock16x16 ? TransposeMatrixBlock16x16_sse2 : TransposeMatrixBlock8x8_mmx;
-  PTransposeMatrixBlocksFunc TransposeMatrixBlocks= kIsBlock16x16 ? TransposeMatrixBlocksx16_sse2 : TransposeMatrixBlocksx8_mmx;
+  PTransposeMatrixBlockFunc TransposeMatrixBlock = kIsBlock16x16 ? TransposeMatrixBlock16x16_sse2 :
+      TransposeMatrixBlock8x8_mmx;
+  PTransposeMatrixBlocksFunc TransposeMatrixBlocks = kIsBlock16x16 ? TransposeMatrixBlocksx16_sse2 :
+      TransposeMatrixBlocksx8_mmx;
 
   const int32_t kiDiff   = kiMaxPos - kiMinPos;
-  const int32_t kiRowNum  = WELS_ALIGN((kiDiff - kiEdgeBlocks + 1), kiEdgeBlocks);
-  const int32_t kiBlocksNum  = kIsBlock16x16 ? (kiRowNum>>4) : (kiRowNum>>3);
-  int32_t iCountLoop8  = (kiRowNum-kiEdgeBlocks) >> 3;
-  const int32_t kiRemainingVectors  = kiDiff - (iCountLoop8<<3);
+  const int32_t kiRowNum  = WELS_ALIGN ((kiDiff - kiEdgeBlocks + 1), kiEdgeBlocks);
+  const int32_t kiBlocksNum  = kIsBlock16x16 ? (kiRowNum >> 4) : (kiRowNum >> 3);
+  int32_t iCountLoop8  = (kiRowNum - kiEdgeBlocks) >> 3;
+  const int32_t kiRemainingVectors  = kiDiff - (iCountLoop8 << 3);
   const int32_t kiMatrixStride  = MAX_VERTICAL_MV_RANGE;
-  ENFORCE_STACK_ALIGN_2D( uint8_t, uiMatrixRef, 16, kiMatrixStride, 16 ); // transpose matrix result for ref
-  ENFORCE_STACK_ALIGN_2D( uint8_t, uiMatrixEnc, 16, 16, 16 );    // transpose matrix result for enc
-  assert(kiRowNum <= kiMatrixStride); // make sure effective memory
+  ENFORCE_STACK_ALIGN_2D (uint8_t, uiMatrixRef, 16, kiMatrixStride, 16);  // transpose matrix result for ref
+  ENFORCE_STACK_ALIGN_2D (uint8_t, uiMatrixEnc, 16, 16, 16);     // transpose matrix result for enc
+  assert (kiRowNum <= kiMatrixStride); // make sure effective memory
 
-  TransposeMatrixBlock( &uiMatrixEnc[0][0], 16, kpEncMb, kiEncStride );
-  TransposeMatrixBlocks( &uiMatrixRef[0][0], kiMatrixStride, pRef, kiRefStride, kiBlocksNum );
-  ENFORCE_STACK_ALIGN_1D( uint16_t, uiBaseCost, 8, 16 );
+  TransposeMatrixBlock (&uiMatrixEnc[0][0], 16, kpEncMb, kiEncStride);
+  TransposeMatrixBlocks (&uiMatrixRef[0][0], kiMatrixStride, pRef, kiRefStride, kiBlocksNum);
+  ENFORCE_STACK_ALIGN_1D (uint16_t, uiBaseCost, 8, 16);
   int32_t iTargetPos   = kiMinPos;
   int16_t iBestPos    = pMe->sMv.iMvX;
   uint32_t uiBestCost   = pMe->uiSadCost;
@@ -373,12 +376,12 @@
   kpEncMb = &uiMatrixEnc[0][0];
   pRef = &uiMatrixRef[0][0];
 
-  while(iCountLoop8 > 0) {
-    CalcMvdCostx8_c(uiBaseCost, iTargetPos, pMvdTable, kiFixedMvd);
-    uiCostMin = pSampleSadHor8( kpEncMb, 16, pRef, kiMatrixStride, uiBaseCost, &iIndexMinPos );
+  while (iCountLoop8 > 0) {
+    CalcMvdCostx8_c (uiBaseCost, iTargetPos, pMvdTable, kiFixedMvd);
+    uiCostMin = pSampleSadHor8 (kpEncMb, 16, pRef, kiMatrixStride, uiBaseCost, &iIndexMinPos);
     if (uiCostMin < uiBestCost) {
       uiBestCost = uiCostMin;
-      iBestPos  = iTargetPos+iIndexMinPos;
+      iBestPos  = iTargetPos + iIndexMinPos;
     }
     iTargetPos += 8;
     pRef += 8;
@@ -386,10 +389,10 @@
   }
   if (kiRemainingVectors > 0) {
     kpEncMb = pMe->pEncMb;
-    pRef = &pMe->pColoRefMb[(iTargetPos - kiCurMeBlockPix)*kiRefStride];
+    pRef = &pMe->pColoRefMb[ (iTargetPos - kiCurMeBlockPix) * kiRefStride];
     while (iTargetPos < kiMaxPos) {
-      const uint16_t pMvdCost = pMvdTable[iTargetPos<<2];
-      uint32_t uiSadCost = pSad( kpEncMb, kiEncStride, pRef, kiRefStride ) + (kiFixedMvd + pMvdCost);
+      const uint16_t pMvdCost = pMvdTable[iTargetPos << 2];
+      uint32_t uiSadCost = pSad (kpEncMb, kiEncStride, pRef, kiRefStride) + (kiFixedMvd + pMvdCost);
       if (uiSadCost < uiBestCost) {
         uiBestCost = uiSadCost;
         iBestPos = iTargetPos;
@@ -402,23 +405,22 @@
     SMVUnitXY sBestMv;
     sBestMv.iMvX = 0;
     sBestMv.iMvY = iBestPos - kiCurMeBlockPix;
-    UpdateMeResults( sBestMv, uiBestCost, &pMe->pColoRefMb[sBestMv.iMvY*kiRefStride], pMe );
+    UpdateMeResults (sBestMv, uiBestCost, &pMe->pColoRefMb[sBestMv.iMvY * kiRefStride], pMe);
   }
 }
 
-void HorizontalFullSearchUsingSSE41( SWelsFuncPtrList *pFuncList, SWelsME *pMe,
-                                      uint16_t* pMvdTable, const int32_t kiFixedMvd,
-                                      const int32_t kiEncStride, const int32_t kiRefStride,
-                                      const int32_t kiMinPos, const int32_t kiMaxPos,
-                                      const bool bVerticalSearch )
-{
-  uint8_t *kpEncMb = pMe->pEncMb;
+void HorizontalFullSearchUsingSSE41 (SWelsFuncPtrList* pFuncList, SWelsME* pMe,
+                                     uint16_t* pMvdTable, const int32_t kiFixedMvd,
+                                     const int32_t kiEncStride, const int32_t kiRefStride,
+                                     const int32_t kiMinPos, const int32_t kiMaxPos,
+                                     const bool bVerticalSearch) {
+  uint8_t* kpEncMb = pMe->pEncMb;
   const int32_t kiCurMeBlockPix = pMe->iCurMeBlockPixX;
-  uint8_t *pRef         = &pMe->pColoRefMb[kiMinPos - kiCurMeBlockPix];
+  uint8_t* pRef         = &pMe->pColoRefMb[kiMinPos - kiCurMeBlockPix];
   const int32_t kIsBlock16x16 = pMe->uiBlockSize == BLOCK_16x16;
   PSampleSadHor8Func pSampleSadHor8 = pFuncList->pfSampleSadHor8[kIsBlock16x16];
   PSampleSadSatdCostFunc pSad = pFuncList->sSampleDealingFuncs.pfSampleSad[pMe->uiBlockSize];
-  ENFORCE_STACK_ALIGN_1D( uint16_t, uiBaseCost, 8, 16 );
+  ENFORCE_STACK_ALIGN_1D (uint16_t, uiBaseCost, 8, 16);
   const int32_t kiNumVector = kiMaxPos - kiMinPos;
   int32_t iCountLoop8 = kiNumVector >> 3;
   const int32_t kiRemainingLoop8 = kiNumVector & 7;
@@ -428,21 +430,21 @@
   uint32_t uiCostMin;
   int32_t iIndexMinPos;
 
-  while(iCountLoop8 > 0) {
-    CalcMvdCostx8_c(uiBaseCost, iTargetPos, pMvdTable, kiFixedMvd);
-    uiCostMin = pSampleSadHor8( kpEncMb, kiEncStride, pRef, kiRefStride, uiBaseCost, &iIndexMinPos );
+  while (iCountLoop8 > 0) {
+    CalcMvdCostx8_c (uiBaseCost, iTargetPos, pMvdTable, kiFixedMvd);
+    uiCostMin = pSampleSadHor8 (kpEncMb, kiEncStride, pRef, kiRefStride, uiBaseCost, &iIndexMinPos);
     if (uiCostMin < uiBestCost) {
       uiBestCost = uiCostMin;
-      iBestPos  = iTargetPos+iIndexMinPos;
+      iBestPos  = iTargetPos + iIndexMinPos;
     }
     iTargetPos += 8;
     pRef += 8;
     -- iCountLoop8;
   }
-  if ( kiRemainingLoop8 > 0 ) {
+  if (kiRemainingLoop8 > 0) {
     while (iTargetPos < kiMaxPos) {
-      const uint16_t pMvdCost = pMvdTable[iTargetPos<<2];
-      uint32_t uiSadCost = pSad( kpEncMb, kiEncStride, pRef, kiRefStride ) + (kiFixedMvd + pMvdCost);
+      const uint16_t pMvdCost = pMvdTable[iTargetPos << 2];
+      uint32_t uiSadCost = pSad (kpEncMb, kiEncStride, pRef, kiRefStride) + (kiFixedMvd + pMvdCost);
       if (uiSadCost < uiBestCost) {
         uiBestCost = uiSadCost;
         iBestPos = iTargetPos;
@@ -455,69 +457,69 @@
     SMVUnitXY sBestMv;
     sBestMv.iMvX = iBestPos - kiCurMeBlockPix;
     sBestMv.iMvY = 0;
-    UpdateMeResults( sBestMv, uiBestCost, &pMe->pColoRefMb[sBestMv.iMvY], pMe );
+    UpdateMeResults (sBestMv, uiBestCost, &pMe->pColoRefMb[sBestMv.iMvY], pMe);
   }
 }
 #endif
-void LineFullSearch_c( SWelsFuncPtrList *pFuncList, SWelsME *pMe,
-             uint16_t* pMvdTable, const int32_t kiFixedMvd,
-             const int32_t kiEncStride, const int32_t kiRefStride,
-             const int32_t kiMinPos, const int32_t kiMaxPos,
-                          const bool bVerticalSearch ) {
+void LineFullSearch_c (SWelsFuncPtrList* pFuncList, SWelsME* pMe,
+                       uint16_t* pMvdTable, const int32_t kiFixedMvd,
+                       const int32_t kiEncStride, const int32_t kiRefStride,
+                       const int32_t kiMinPos, const int32_t kiMaxPos,
+                       const bool bVerticalSearch) {
   PSampleSadSatdCostFunc pSad = pFuncList->sSampleDealingFuncs.pfSampleSad[pMe->uiBlockSize];
-  const int32_t kiCurMeBlockPix  = bVerticalSearch?pMe->iCurMeBlockPixY:pMe->iCurMeBlockPixX;
-  const int32_t kiStride = bVerticalSearch?kiRefStride:1;
-  uint8_t* pRef            = &pMe->pColoRefMb[(kiMinPos - kiCurMeBlockPix)*kiStride];
-  uint16_t* pMvdCost  = &(pMvdTable[kiMinPos<<2]);
+  const int32_t kiCurMeBlockPix  = bVerticalSearch ? pMe->iCurMeBlockPixY : pMe->iCurMeBlockPixX;
+  const int32_t kiStride = bVerticalSearch ? kiRefStride : 1;
+  uint8_t* pRef            = &pMe->pColoRefMb[ (kiMinPos - kiCurMeBlockPix) * kiStride];
+  uint16_t* pMvdCost  = & (pMvdTable[kiMinPos << 2]);
   uint32_t uiBestCost    = 0xFFFFFFFF;
   int32_t iBestPos       = 0;
 
-  for ( int32_t iTargetPos = kiMinPos; iTargetPos < kiMaxPos; ++ iTargetPos ) {
+  for (int32_t iTargetPos = kiMinPos; iTargetPos < kiMaxPos; ++ iTargetPos) {
     uint8_t* const kpEncMb  = pMe->pEncMb;
-    uint32_t uiSadCost = pSad( kpEncMb, kiEncStride, pRef, kiRefStride ) + (kiFixedMvd + *pMvdCost);
+    uint32_t uiSadCost = pSad (kpEncMb, kiEncStride, pRef, kiRefStride) + (kiFixedMvd + *pMvdCost);
     if (uiSadCost < uiBestCost) {
       uiBestCost  = uiSadCost;
       iBestPos  = iTargetPos;
     }
     pRef += kiStride;
-    pMvdCost+=4;
+    pMvdCost += 4;
   }
 
   if (uiBestCost < pMe->uiSadCost) {
     SMVUnitXY sBestMv;
-    sBestMv.iMvX = bVerticalSearch?0:(iBestPos - kiCurMeBlockPix);
-    sBestMv.iMvY = bVerticalSearch?(iBestPos - kiCurMeBlockPix):0;
-    UpdateMeResults( sBestMv, uiBestCost, &pMe->pColoRefMb[sBestMv.iMvY*kiStride], pMe );
+    sBestMv.iMvX = bVerticalSearch ? 0 : (iBestPos - kiCurMeBlockPix);
+    sBestMv.iMvY = bVerticalSearch ? (iBestPos - kiCurMeBlockPix) : 0;
+    UpdateMeResults (sBestMv, uiBestCost, &pMe->pColoRefMb[sBestMv.iMvY * kiStride], pMe);
   }
 }
 
-void WelsMotionCrossSearch(SWelsFuncPtrList *pFuncList,  SWelsME * pMe,
-           const SSlice* pSlice, const int32_t kiEncStride,  const int32_t kiRefStride) {
+void WelsMotionCrossSearch (SWelsFuncPtrList* pFuncList,  SWelsME* pMe,
+                            const SSlice* pSlice, const int32_t kiEncStride,  const int32_t kiRefStride) {
   PLineFullSearchFunc pfVerticalFullSearchFunc = pFuncList->pfVerticalFullSearch;
   PLineFullSearchFunc pfHorizontalFullSearchFunc = pFuncList->pfHorizontalFullSearch;
 
   const int32_t iCurMeBlockPixX = pMe->iCurMeBlockPixX;
-  const int32_t iCurMeBlockQpelPixX = ((iCurMeBlockPixX)<<2);
+  const int32_t iCurMeBlockQpelPixX = ((iCurMeBlockPixX) << 2);
   const int32_t iCurMeBlockPixY = pMe->iCurMeBlockPixY;
-  const int32_t iCurMeBlockQpelPixY = ((iCurMeBlockPixY)<<2);
+  const int32_t iCurMeBlockQpelPixY = ((iCurMeBlockPixY) << 2);
   uint16_t* pMvdCostX = pMe->pMvdCost - iCurMeBlockQpelPixX - pMe->sMvp.iMvX;//do the offset here instead of in the search
   uint16_t* pMvdCostY = pMe->pMvdCost - iCurMeBlockQpelPixY - pMe->sMvp.iMvY;//do the offset here instead of in the search
 
   //vertical search
-  pfVerticalFullSearchFunc( pFuncList, pMe,
-    pMvdCostY, pMvdCostX[ iCurMeBlockQpelPixX ],
-    kiEncStride, kiRefStride,
-    iCurMeBlockPixY + pSlice->sMvStartMin.iMvY,
-    iCurMeBlockPixY + pSlice->sMvStartMax.iMvY, true );
+  pfVerticalFullSearchFunc (pFuncList, pMe,
+                            pMvdCostY, pMvdCostX[ iCurMeBlockQpelPixX ],
+                            kiEncStride, kiRefStride,
+                            iCurMeBlockPixY + pSlice->sMvStartMin.iMvY,
+                            iCurMeBlockPixY + pSlice->sMvStartMax.iMvY, true);
 
   //horizontal search
   if (pMe->uiSadCost >= pMe->uiSadCostThreshold) {
-    pfHorizontalFullSearchFunc( pFuncList, pMe,
-      pMvdCostX, pMvdCostY[ iCurMeBlockQpelPixY ],
-      kiEncStride, kiRefStride,
-      iCurMeBlockPixX + pSlice->sMvStartMin.iMvX,
-      iCurMeBlockPixX + pSlice->sMvStartMax.iMvX,
-      false );
+    pfHorizontalFullSearchFunc (pFuncList, pMe,
+                                pMvdCostX, pMvdCostY[ iCurMeBlockQpelPixY ],
+                                kiEncStride, kiRefStride,
+                                iCurMeBlockPixX + pSlice->sMvStartMin.iMvX,
+                                iCurMeBlockPixX + pSlice->sMvStartMax.iMvX,
+                                false);
   }
 }
 
@@ -525,23 +527,24 @@
 // Feature Search Basics
 /////////////////////////
 //memory related
-int32_t RequestFeatureSearchPreparation( CMemoryAlign *pMa, const int32_t kiFrameWidth,  const int32_t kiFrameHeight, const int32_t iNeedFeatureStorage,
-                                        SFeatureSearchPreparation* pFeatureSearchPreparation) {
-  const int32_t kiFeatureStrategyIndex = iNeedFeatureStorage>>16;
-  const bool bFme8x8 = ((iNeedFeatureStorage & 0x0000FF & ME_FME)==ME_FME);
-  const int32_t kiMarginSize = bFme8x8?8:16;
-  const int32_t kiFrameSize = (kiFrameWidth-kiMarginSize) * (kiFrameHeight-kiMarginSize);
+int32_t RequestFeatureSearchPreparation (CMemoryAlign* pMa, const int32_t kiFrameWidth,  const int32_t kiFrameHeight,
+    const int32_t iNeedFeatureStorage,
+    SFeatureSearchPreparation* pFeatureSearchPreparation) {
+  const int32_t kiFeatureStrategyIndex = iNeedFeatureStorage >> 16;
+  const bool bFme8x8 = ((iNeedFeatureStorage & 0x0000FF & ME_FME) == ME_FME);
+  const int32_t kiMarginSize = bFme8x8 ? 8 : 16;
+  const int32_t kiFrameSize = (kiFrameWidth - kiMarginSize) * (kiFrameHeight - kiMarginSize);
   int32_t iListOfFeatureOfBlock;
 
-  if (0==kiFeatureStrategyIndex) {
-    iListOfFeatureOfBlock =sizeof(uint16_t) * kiFrameSize;
+  if (0 == kiFeatureStrategyIndex) {
+    iListOfFeatureOfBlock = sizeof (uint16_t) * kiFrameSize;
   } else {
-    iListOfFeatureOfBlock = sizeof(uint16_t) * kiFrameSize +
-      (kiFrameWidth-kiMarginSize) * sizeof(uint32_t) + kiFrameWidth * 8 * sizeof(uint8_t);
+    iListOfFeatureOfBlock = sizeof (uint16_t) * kiFrameSize +
+                            (kiFrameWidth - kiMarginSize) * sizeof (uint32_t) + kiFrameWidth * 8 * sizeof (uint8_t);
   }
   pFeatureSearchPreparation->pFeatureOfBlock =
-    (uint16_t *)pMa->WelsMalloc(iListOfFeatureOfBlock, "pFeatureOfBlock");
-  WELS_VERIFY_RETURN_IF(ENC_RETURN_MEMALLOCERR, NULL == (pFeatureSearchPreparation->pFeatureOfBlock) )
+    (uint16_t*)pMa->WelsMalloc (iListOfFeatureOfBlock, "pFeatureOfBlock");
+  WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == (pFeatureSearchPreparation->pFeatureOfBlock))
 
   pFeatureSearchPreparation->uiFeatureStrategyIndex = kiFeatureStrategyIndex;
   pFeatureSearchPreparation->bFMESwitchFlag = true;
@@ -550,64 +553,69 @@
 
   return ENC_RETURN_SUCCESS;
 }
-int32_t ReleaseFeatureSearchPreparation( CMemoryAlign *pMa, uint16_t*& pFeatureOfBlock) {
-  if ( pMa && pFeatureOfBlock ) {
-    pMa->WelsFree( pFeatureOfBlock, "pFeatureOfBlock");
-    pFeatureOfBlock=NULL;
+int32_t ReleaseFeatureSearchPreparation (CMemoryAlign* pMa, uint16_t*& pFeatureOfBlock) {
+  if (pMa && pFeatureOfBlock) {
+    pMa->WelsFree (pFeatureOfBlock, "pFeatureOfBlock");
+    pFeatureOfBlock = NULL;
     return ENC_RETURN_SUCCESS;
   }
   return ENC_RETURN_UNEXPECTED;
 }
 
-int32_t RequestScreenBlockFeatureStorage( CMemoryAlign *pMa, const int32_t kiFrameWidth,  const int32_t kiFrameHeight, const int32_t iNeedFeatureStorage,
-                                         SScreenBlockFeatureStorage* pScreenBlockFeatureStorage) {
+int32_t RequestScreenBlockFeatureStorage (CMemoryAlign* pMa, const int32_t kiFrameWidth,  const int32_t kiFrameHeight,
+    const int32_t iNeedFeatureStorage,
+    SScreenBlockFeatureStorage* pScreenBlockFeatureStorage) {
 
-  const int32_t kiFeatureStrategyIndex = iNeedFeatureStorage>>16;
+  const int32_t kiFeatureStrategyIndex = iNeedFeatureStorage >> 16;
   const int32_t kiMe8x8FME = iNeedFeatureStorage & 0x0000FF & ME_FME;
-  const int32_t kiMe16x16FME = ((iNeedFeatureStorage & 0x00FF00)>>8) & ME_FME;
-  if ((kiMe8x8FME==ME_FME) && (kiMe16x16FME==ME_FME)) {
+  const int32_t kiMe16x16FME = ((iNeedFeatureStorage & 0x00FF00) >> 8) & ME_FME;
+  if ((kiMe8x8FME == ME_FME) && (kiMe16x16FME == ME_FME)) {
     return ENC_RETURN_UNSUPPORTED_PARA;
     //the following memory allocation cannot support when FME at both size
   }
 
-  const bool bIsBlock8x8 = (kiMe8x8FME==ME_FME);
-  const int32_t kiMarginSize = bIsBlock8x8?8:16;
-  const int32_t kiFrameSize = (kiFrameWidth-kiMarginSize) * (kiFrameHeight-kiMarginSize);
-  const int32_t kiListSize  = (0==kiFeatureStrategyIndex)?(bIsBlock8x8 ? LIST_SIZE_SUM_8x8 : LIST_SIZE_SUM_16x16):256;
+  const bool bIsBlock8x8 = (kiMe8x8FME == ME_FME);
+  const int32_t kiMarginSize = bIsBlock8x8 ? 8 : 16;
+  const int32_t kiFrameSize = (kiFrameWidth - kiMarginSize) * (kiFrameHeight - kiMarginSize);
+  const int32_t kiListSize  = (0 == kiFeatureStrategyIndex) ? (bIsBlock8x8 ? LIST_SIZE_SUM_8x8 : LIST_SIZE_SUM_16x16) :
+                              256;
 
-  pScreenBlockFeatureStorage->pTimesOfFeatureValue = (uint32_t*)pMa->WelsMalloc(kiListSize*sizeof(uint32_t),"pScreenBlockFeatureStorage->pTimesOfFeatureValue");
-  WELS_VERIFY_RETURN_IF(ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pTimesOfFeatureValue)
+  pScreenBlockFeatureStorage->pTimesOfFeatureValue = (uint32_t*)pMa->WelsMalloc (kiListSize * sizeof (uint32_t),
+      "pScreenBlockFeatureStorage->pTimesOfFeatureValue");
+  WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pTimesOfFeatureValue)
 
-  pScreenBlockFeatureStorage->pLocationOfFeature = (uint16_t**)pMa->WelsMalloc(kiListSize*sizeof(uint16_t*),"pScreenBlockFeatureStorage->pLocationOfFeature");
-  WELS_VERIFY_RETURN_IF(ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pLocationOfFeature)
+  pScreenBlockFeatureStorage->pLocationOfFeature = (uint16_t**)pMa->WelsMalloc (kiListSize * sizeof (uint16_t*),
+      "pScreenBlockFeatureStorage->pLocationOfFeature");
+  WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pLocationOfFeature)
 
-  pScreenBlockFeatureStorage->pLocationPointer = (uint16_t*)pMa->WelsMalloc(2*kiFrameSize*sizeof(uint16_t), "pScreenBlockFeatureStorage->pLocationPointer");
-  WELS_VERIFY_RETURN_IF(ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pLocationPointer)
+  pScreenBlockFeatureStorage->pLocationPointer = (uint16_t*)pMa->WelsMalloc (2 * kiFrameSize * sizeof (uint16_t),
+      "pScreenBlockFeatureStorage->pLocationPointer");
+  WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pLocationPointer)
 
   pScreenBlockFeatureStorage->pFeatureOfBlockPointer = NULL;
   pScreenBlockFeatureStorage->iIs16x16 = !bIsBlock8x8;
   pScreenBlockFeatureStorage->uiFeatureStrategyIndex = kiFeatureStrategyIndex;
   pScreenBlockFeatureStorage->iActualListSize = kiListSize;
-  memset(pScreenBlockFeatureStorage->uiSadCostThreshold, UINT_MAX, BLOCK_SIZE_ALL*sizeof(uint32_t));
+  memset (pScreenBlockFeatureStorage->uiSadCostThreshold, UINT_MAX, BLOCK_SIZE_ALL * sizeof (uint32_t));
   pScreenBlockFeatureStorage->bRefBlockFeatureCalculated = false;
 
   return ENC_RETURN_SUCCESS;
 }
-int32_t ReleaseScreenBlockFeatureStorage( CMemoryAlign *pMa, SScreenBlockFeatureStorage* pScreenBlockFeatureStorage ) {
-  if ( pMa && pScreenBlockFeatureStorage ) {
+int32_t ReleaseScreenBlockFeatureStorage (CMemoryAlign* pMa, SScreenBlockFeatureStorage* pScreenBlockFeatureStorage) {
+  if (pMa && pScreenBlockFeatureStorage) {
     if (pScreenBlockFeatureStorage->pTimesOfFeatureValue) {
-      pMa->WelsFree( pScreenBlockFeatureStorage->pTimesOfFeatureValue, "pScreenBlockFeatureStorage->pTimesOfFeatureValue");
-      pScreenBlockFeatureStorage->pTimesOfFeatureValue=NULL;
+      pMa->WelsFree (pScreenBlockFeatureStorage->pTimesOfFeatureValue, "pScreenBlockFeatureStorage->pTimesOfFeatureValue");
+      pScreenBlockFeatureStorage->pTimesOfFeatureValue = NULL;
     }
 
     if (pScreenBlockFeatureStorage->pLocationOfFeature) {
-      pMa->WelsFree( pScreenBlockFeatureStorage->pLocationOfFeature, "pScreenBlockFeatureStorage->pLocationOfFeature");
-      pScreenBlockFeatureStorage->pLocationOfFeature=NULL;
+      pMa->WelsFree (pScreenBlockFeatureStorage->pLocationOfFeature, "pScreenBlockFeatureStorage->pLocationOfFeature");
+      pScreenBlockFeatureStorage->pLocationOfFeature = NULL;
     }
 
     if (pScreenBlockFeatureStorage->pLocationPointer) {
-      pMa->WelsFree( pScreenBlockFeatureStorage->pLocationPointer, "pScreenBlockFeatureStorage->pLocationPointer");
-      pScreenBlockFeatureStorage->pLocationPointer=NULL;
+      pMa->WelsFree (pScreenBlockFeatureStorage->pLocationPointer, "pScreenBlockFeatureStorage->pLocationPointer");
+      pScreenBlockFeatureStorage->pLocationPointer = NULL;
     }
 
     return ENC_RETURN_SUCCESS;
@@ -616,9 +624,9 @@
 }
 
 //preprocess related
-int32_t SumOf8x8SingleBlock_c(uint8_t* pRef, const int32_t kiRefStride) {
+int32_t SumOf8x8SingleBlock_c (uint8_t* pRef, const int32_t kiRefStride) {
   int32_t iSum = 0, i;
-  for(i = 0; i < 8; i++) {
+  for (i = 0; i < 8; i++) {
     iSum +=  pRef[0]    + pRef[1]  + pRef[2]  + pRef[3];
     iSum +=  pRef[4]    + pRef[5]  + pRef[6]  + pRef[7];
     pRef += kiRefStride;
@@ -625,9 +633,9 @@
   }
   return iSum;
 }
-int32_t SumOf16x16SingleBlock_c(uint8_t* pRef, const int32_t kiRefStride) {
+int32_t SumOf16x16SingleBlock_c (uint8_t* pRef, const int32_t kiRefStride) {
   int32_t iSum = 0, i;
-  for(i = 0; i < 16; i++) {
+  for (i = 0; i < 16; i++) {
     iSum +=  pRef[0]    + pRef[1]  + pRef[2]  + pRef[3];
     iSum +=  pRef[4]    + pRef[5]  + pRef[6]  + pRef[7];
     iSum    +=  pRef[8]    + pRef[9]  + pRef[10]  + pRef[11];
@@ -637,18 +645,18 @@
   return iSum;
 }
 
-void SumOf8x8BlockOfFrame_c(uint8_t *pRefPicture, const int32_t kiWidth, const int32_t kiHeight, const int32_t kiRefStride,
-                                              uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[])
-{
+void SumOf8x8BlockOfFrame_c (uint8_t* pRefPicture, const int32_t kiWidth, const int32_t kiHeight,
+                             const int32_t kiRefStride,
+                             uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]) {
   int32_t x, y;
-  uint8_t *pRef;
-  uint16_t *pBuffer;
+  uint8_t* pRef;
+  uint16_t* pBuffer;
   int32_t iSum;
-  for(y = 0; y < kiHeight; y++) {
+  for (y = 0; y < kiHeight; y++) {
     pRef = pRefPicture  + kiRefStride * y;
     pBuffer  = pFeatureOfBlock + kiWidth * y;
-    for(x = 0; x < kiWidth; x++) {
-      iSum = SumOf8x8SingleBlock_c(pRef + x, kiRefStride);
+    for (x = 0; x < kiWidth; x++) {
+      iSum = SumOf8x8SingleBlock_c (pRef + x, kiRefStride);
 
       pBuffer[x] = iSum;
       pTimesOfFeatureValue[iSum]++;
@@ -656,18 +664,19 @@
   }
 }
 
-void SumOf16x16BlockOfFrame_c(uint8_t *pRefPicture, const int32_t kiWidth, const int32_t kiHeight, const int32_t kiRefStride,
-                                              uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[])
-{//TODO: this is similar to SumOf8x8BlockOfFrame_c expect the calling of single block func, refactor-able?
+void SumOf16x16BlockOfFrame_c (uint8_t* pRefPicture, const int32_t kiWidth, const int32_t kiHeight,
+                               const int32_t kiRefStride,
+                               uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]) {
+  //TODO: this is similar to SumOf8x8BlockOfFrame_c expect the calling of single block func, refactor-able?
   int32_t x, y;
-  uint8_t *pRef;
-  uint16_t *pBuffer;
+  uint8_t* pRef;
+  uint16_t* pBuffer;
   int32_t iSum;
-  for(y = 0; y < kiHeight; y++) {
+  for (y = 0; y < kiHeight; y++) {
     pRef = pRefPicture  + kiRefStride * y;
     pBuffer  = pFeatureOfBlock + kiWidth * y;
-    for(x = 0; x < kiWidth; x++) {
-      iSum = SumOf16x16SingleBlock_c(pRef + x, kiRefStride);
+    for (x = 0; x < kiWidth; x++) {
+      iSum = SumOf16x16SingleBlock_c (pRef + x, kiRefStride);
 
       pBuffer[x] = iSum;
       pTimesOfFeatureValue[iSum]++;
@@ -675,25 +684,25 @@
   }
 }
 
-void InitializeHashforFeature_c( uint32_t* pTimesOfFeatureValue, uint16_t* pBuf, const int32_t kiListSize,
-                                uint16_t** pLocationOfFeature, uint16_t** pFeatureValuePointerList ) {
+void InitializeHashforFeature_c (uint32_t* pTimesOfFeatureValue, uint16_t* pBuf, const int32_t kiListSize,
+                                 uint16_t** pLocationOfFeature, uint16_t** pFeatureValuePointerList) {
   //assign location pointer
-  uint16_t *pBufPos  = pBuf;
-  for( int32_t i = 0 ; i < kiListSize; ++i ) {
+  uint16_t* pBufPos  = pBuf;
+  for (int32_t i = 0 ; i < kiListSize; ++i) {
     pLocationOfFeature[i] =
       pFeatureValuePointerList[i] = pBufPos;
-    pBufPos      += (pTimesOfFeatureValue[i]<<1);
+    pBufPos      += (pTimesOfFeatureValue[i] << 1);
   }
 }
-void FillQpelLocationByFeatureValue_c( uint16_t* pFeatureOfBlock, const int32_t kiWidth, const int32_t kiHeight,
-                                       uint16_t** pFeatureValuePointerList ) {
+void FillQpelLocationByFeatureValue_c (uint16_t* pFeatureOfBlock, const int32_t kiWidth, const int32_t kiHeight,
+                                       uint16_t** pFeatureValuePointerList) {
   //assign each pixel's position
   uint16_t* pSrcPointer  =  pFeatureOfBlock;
   int32_t iQpelY = 0;
-  for(int32_t y = 0; y < kiHeight; y++) {
-    for(int32_t x = 0; x < kiWidth; x++) {
+  for (int32_t y = 0; y < kiHeight; y++) {
+    for (int32_t x = 0; x < kiWidth; x++) {
       uint16_t uiFeature = pSrcPointer[x];
-      ST32( &pFeatureValuePointerList[uiFeature][0], ((iQpelY<<16)|(x<<2)) );
+      ST32 (&pFeatureValuePointerList[uiFeature][0], ((iQpelY << 16) | (x << 2)));
       pFeatureValuePointerList[uiFeature] += 2;
     }
     iQpelY += 4;
@@ -701,8 +710,8 @@
   }
 }
 
-void CalculateFeatureOfBlock( SWelsFuncPtrList *pFunc, SPicture* pRef,
-                         SScreenBlockFeatureStorage* pScreenBlockFeatureStorage) {
+void CalculateFeatureOfBlock (SWelsFuncPtrList* pFunc, SPicture* pRef,
+                              SScreenBlockFeatureStorage* pScreenBlockFeatureStorage) {
   uint16_t* pFeatureOfBlock = pScreenBlockFeatureStorage->pFeatureOfBlockPointer;
   uint32_t* pTimesOfFeatureValue = pScreenBlockFeatureStorage->pTimesOfFeatureValue;
   uint16_t** pLocationOfFeature  = pScreenBlockFeatureStorage->pLocationOfFeature;
@@ -711,46 +720,47 @@
   uint8_t* pRefData = pRef->pData[0];
   const int32_t iRefStride = pRef->iLineSize[0];
   int32_t iIs16x16 = pScreenBlockFeatureStorage->iIs16x16;
-  const int32_t iEdgeDiscard = (iIs16x16?16:8);//this is to save complexity of padding on pRef
+  const int32_t iEdgeDiscard = (iIs16x16 ? 16 : 8); //this is to save complexity of padding on pRef
   const int32_t iWidth = pRef->iWidthInPixel - iEdgeDiscard;
   const int32_t kiHeight = pRef->iHeightInPixel - iEdgeDiscard;
   const int32_t kiActualListSize = pScreenBlockFeatureStorage->iActualListSize;
-  uint16_t* pFeatureValuePointerList[WELS_MAX(LIST_SIZE_SUM_16x16,LIST_SIZE_MSE_16x16)] = {0};
+  uint16_t* pFeatureValuePointerList[WELS_MAX (LIST_SIZE_SUM_16x16, LIST_SIZE_MSE_16x16)] = {0};
 
-  memset(pTimesOfFeatureValue, 0, sizeof(int32_t)*kiActualListSize);
-  (pFunc->pfCalculateBlockFeatureOfFrame[iIs16x16])(pRefData,iWidth, kiHeight, iRefStride, pFeatureOfBlock, pTimesOfFeatureValue);
+  memset (pTimesOfFeatureValue, 0, sizeof (int32_t)*kiActualListSize);
+  (pFunc->pfCalculateBlockFeatureOfFrame[iIs16x16]) (pRefData, iWidth, kiHeight, iRefStride, pFeatureOfBlock,
+      pTimesOfFeatureValue);
 
   //assign pLocationOfFeature pointer
-  InitializeHashforFeature_c( pTimesOfFeatureValue, pBuf, kiActualListSize,
-    pLocationOfFeature, pFeatureValuePointerList );
+  InitializeHashforFeature_c (pTimesOfFeatureValue, pBuf, kiActualListSize,
+                              pLocationOfFeature, pFeatureValuePointerList);
 
   //assign each pixel's pLocationOfFeature
-  FillQpelLocationByFeatureValue_c(pFeatureOfBlock, iWidth, kiHeight, pFeatureValuePointerList);
+  FillQpelLocationByFeatureValue_c (pFeatureOfBlock, iWidth, kiHeight, pFeatureValuePointerList);
 }
 
-void PerformFMEPreprocess( SWelsFuncPtrList *pFunc, SPicture* pRef, uint16_t*	pFeatureOfBlock,
-                          SScreenBlockFeatureStorage* pScreenBlockFeatureStorage)
-{
-    pScreenBlockFeatureStorage->pFeatureOfBlockPointer = pFeatureOfBlock;
-    CalculateFeatureOfBlock(pFunc, pRef, pScreenBlockFeatureStorage );
-    pScreenBlockFeatureStorage->bRefBlockFeatureCalculated = true;
+void PerformFMEPreprocess (SWelsFuncPtrList* pFunc, SPicture* pRef, uint16_t*	pFeatureOfBlock,
+                           SScreenBlockFeatureStorage* pScreenBlockFeatureStorage) {
+  pScreenBlockFeatureStorage->pFeatureOfBlockPointer = pFeatureOfBlock;
+  CalculateFeatureOfBlock (pFunc, pRef, pScreenBlockFeatureStorage);
+  pScreenBlockFeatureStorage->bRefBlockFeatureCalculated = true;
 
-    uint32_t uiRefPictureAvgQstepx16 = QStepx16ByQp[WelsMedian(0, pRef->iFrameAverageQp, 51)];
-    uint32_t uiSadCostThreshold16x16 = ((30 * (uiRefPictureAvgQstepx16 + 160))>>3);
-    pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_16x16] = uiSadCostThreshold16x16;
-    pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_8x8] = (uiSadCostThreshold16x16>>2);
-    pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_16x8]
+  uint32_t uiRefPictureAvgQstepx16 = QStepx16ByQp[WelsMedian (0, pRef->iFrameAverageQp, 51)];
+  uint32_t uiSadCostThreshold16x16 = ((30 * (uiRefPictureAvgQstepx16 + 160)) >> 3);
+  pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_16x16] = uiSadCostThreshold16x16;
+  pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_8x8] = (uiSadCostThreshold16x16 >> 2);
+  pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_16x8]
     = pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_8x16]
-    = pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_4x4] = UINT_MAX;
+      = pScreenBlockFeatureStorage->uiSadCostThreshold[BLOCK_4x4] = UINT_MAX;
 }
 
 //search related
-void SetFeatureSearchIn( SWelsFuncPtrList *pFunc,  const SWelsME& sMe,
-                        const SSlice *pSlice, SScreenBlockFeatureStorage* pRefFeatureStorage,
-                        const int32_t kiEncStride, const int32_t kiRefStride,
-                        SFeatureSearchIn* pFeatureSearchIn ) {
+void SetFeatureSearchIn (SWelsFuncPtrList* pFunc,  const SWelsME& sMe,
+                         const SSlice* pSlice, SScreenBlockFeatureStorage* pRefFeatureStorage,
+                         const int32_t kiEncStride, const int32_t kiRefStride,
+                         SFeatureSearchIn* pFeatureSearchIn) {
   pFeatureSearchIn->pSad = pFunc->sSampleDealingFuncs.pfSampleSad[sMe.uiBlockSize];
-  pFeatureSearchIn->iFeatureOfCurrent=pFunc->pfCalculateSingleBlockFeature[BLOCK_16x16==sMe.uiBlockSize](sMe.pEncMb, kiEncStride);
+  pFeatureSearchIn->iFeatureOfCurrent = pFunc->pfCalculateSingleBlockFeature[BLOCK_16x16 == sMe.uiBlockSize] (sMe.pEncMb,
+                                        kiEncStride);
 
   pFeatureSearchIn->pEnc       = sMe.pEncMb;
   pFeatureSearchIn->pColoRef = sMe.pColoRefMb;
@@ -759,9 +769,9 @@
   pFeatureSearchIn->uiSadCostThresh = sMe.uiSadCostThreshold;
 
   pFeatureSearchIn->iCurPixX = sMe.iCurMeBlockPixX;
-  pFeatureSearchIn->iCurPixXQpel = (pFeatureSearchIn->iCurPixX<<2);
+  pFeatureSearchIn->iCurPixXQpel = (pFeatureSearchIn->iCurPixX << 2);
   pFeatureSearchIn->iCurPixY = sMe.iCurMeBlockPixY;
-  pFeatureSearchIn->iCurPixYQpel = (pFeatureSearchIn->iCurPixY<<2);
+  pFeatureSearchIn->iCurPixYQpel = (pFeatureSearchIn->iCurPixY << 2);
 
   pFeatureSearchIn->pTimesOfFeature = pRefFeatureStorage->pTimesOfFeatureValue;
   pFeatureSearchIn->pQpelLocationOfFeature = pRefFeatureStorage->pLocationOfFeature;
@@ -768,27 +778,29 @@
   pFeatureSearchIn->pMvdCostX = sMe.pMvdCost - pFeatureSearchIn->iCurPixXQpel - sMe.sMvp.iMvX;
   pFeatureSearchIn->pMvdCostY = sMe.pMvdCost - pFeatureSearchIn->iCurPixYQpel - sMe.sMvp.iMvY;
 
-  pFeatureSearchIn->iMinQpelX = pFeatureSearchIn->iCurPixXQpel+((pSlice->sMvStartMin.iMvX)<<2);
-  pFeatureSearchIn->iMinQpelY = pFeatureSearchIn->iCurPixYQpel+((pSlice->sMvStartMin.iMvY)<<2);
-  pFeatureSearchIn->iMaxQpelX = pFeatureSearchIn->iCurPixXQpel+((pSlice->sMvStartMax.iMvX)<<2);
-  pFeatureSearchIn->iMaxQpelY = pFeatureSearchIn->iCurPixYQpel+((pSlice->sMvStartMax.iMvY)<<2);
+  pFeatureSearchIn->iMinQpelX = pFeatureSearchIn->iCurPixXQpel + ((pSlice->sMvStartMin.iMvX) << 2);
+  pFeatureSearchIn->iMinQpelY = pFeatureSearchIn->iCurPixYQpel + ((pSlice->sMvStartMin.iMvY) << 2);
+  pFeatureSearchIn->iMaxQpelX = pFeatureSearchIn->iCurPixXQpel + ((pSlice->sMvStartMax.iMvX) << 2);
+  pFeatureSearchIn->iMaxQpelY = pFeatureSearchIn->iCurPixYQpel + ((pSlice->sMvStartMax.iMvY) << 2);
 }
-void SaveFeatureSearchOut( const SMVUnitXY sBestMv, const uint32_t uiBestSadCost, uint8_t* pRef, SFeatureSearchOut* pFeatureSearchOut) {
+void SaveFeatureSearchOut (const SMVUnitXY sBestMv, const uint32_t uiBestSadCost, uint8_t* pRef,
+                           SFeatureSearchOut* pFeatureSearchOut) {
   pFeatureSearchOut->sBestMv = sBestMv;
   pFeatureSearchOut->uiBestSadCost = uiBestSadCost;
   pFeatureSearchOut->pBestRef = pRef;
 }
 
-bool FeatureSearchOne( SFeatureSearchIn &sFeatureSearchIn, const int32_t iFeatureDifference, const uint32_t kuiExpectedSearchTimes,
-                      SFeatureSearchOut* pFeatureSearchOut) {
+bool FeatureSearchOne (SFeatureSearchIn& sFeatureSearchIn, const int32_t iFeatureDifference,
+                       const uint32_t kuiExpectedSearchTimes,
+                       SFeatureSearchOut* pFeatureSearchOut) {
   const int32_t iFeatureOfRef = (sFeatureSearchIn.iFeatureOfCurrent + iFeatureDifference);
-  if(iFeatureOfRef < 0 || iFeatureOfRef >= LIST_SIZE)
+  if (iFeatureOfRef < 0 || iFeatureOfRef >= LIST_SIZE)
     return true;
 
   PSampleSadSatdCostFunc pSad = sFeatureSearchIn.pSad;
   uint8_t* pEnc =  sFeatureSearchIn.pEnc;
   uint8_t* pColoRef = sFeatureSearchIn.pColoRef;
-  const int32_t iEncStride=  sFeatureSearchIn.iEncStride;
+  const int32_t iEncStride =  sFeatureSearchIn.iEncStride;
   const int32_t iRefStride =  sFeatureSearchIn.iRefStride;
   const uint16_t uiSadCostThresh = sFeatureSearchIn.uiSadCostThresh;
 
@@ -802,13 +814,13 @@
   const int32_t iMaxQpelX =  sFeatureSearchIn.iMaxQpelX;
   const int32_t iMaxQpelY =  sFeatureSearchIn.iMaxQpelY;
 
-  const int32_t iSearchTimes = WELS_MIN(sFeatureSearchIn.pTimesOfFeature[iFeatureOfRef], kuiExpectedSearchTimes);
-  const int32_t iSearchTimesx2 = (iSearchTimes<<1);
+  const int32_t iSearchTimes = WELS_MIN (sFeatureSearchIn.pTimesOfFeature[iFeatureOfRef], kuiExpectedSearchTimes);
+  const int32_t iSearchTimesx2 = (iSearchTimes << 1);
   const uint16_t* pQpelPosition = sFeatureSearchIn.pQpelLocationOfFeature[iFeatureOfRef];
 
   SMVUnitXY sBestMv;
   uint32_t uiBestCost, uiTmpCost;
-  uint8_t *pBestRef, *pCurRef;
+  uint8_t* pBestRef, *pCurRef;
   int32_t iQpelX, iQpelY;
   int32_t iIntepelX, iIntepelY;
   int32_t i;
@@ -818,41 +830,41 @@
   uiBestCost = pFeatureSearchOut->uiBestSadCost;
   pBestRef = pFeatureSearchOut->pBestRef;
 
-  for( i = 0; i < iSearchTimesx2; i+=2) {
+  for (i = 0; i < iSearchTimesx2; i += 2) {
     iQpelX = pQpelPosition[i];
-    iQpelY = pQpelPosition[i+1];
+    iQpelY = pQpelPosition[i + 1];
 
-    if((iQpelX > iMaxQpelX) || (iQpelX < iMinQpelX)
-      || (iQpelY > iMaxQpelY) || (iQpelY < iMinQpelY)
-      || (iQpelX == iCurPixXQpel) || (iQpelY == iCurPixYQpel) )
+    if ((iQpelX > iMaxQpelX) || (iQpelX < iMinQpelX)
+        || (iQpelY > iMaxQpelY) || (iQpelY < iMinQpelY)
+        || (iQpelX == iCurPixXQpel) || (iQpelY == iCurPixYQpel))
       continue;
 
     uiTmpCost = sFeatureSearchIn.pMvdCostX[ iQpelX ] + sFeatureSearchIn.pMvdCostY[ iQpelY ];
-    if(uiTmpCost + iFeatureDifference >= uiBestCost)
+    if (uiTmpCost + iFeatureDifference >= uiBestCost)
       continue;
 
-    iIntepelX = (iQpelX>>2) - iCurPixX;
-    iIntepelY = (iQpelY>>2) - iCurPixY;
+    iIntepelX = (iQpelX >> 2) - iCurPixX;
+    iIntepelY = (iQpelY >> 2) - iCurPixY;
     pCurRef = &pColoRef[iIntepelX + iIntepelY * iRefStride];
-    uiTmpCost += pSad( pEnc, iEncStride, pCurRef, iRefStride );
-    if( uiTmpCost < uiBestCost ) {
+    uiTmpCost += pSad (pEnc, iEncStride, pCurRef, iRefStride);
+    if (uiTmpCost < uiBestCost) {
       sBestMv.iMvX = iIntepelX;
       sBestMv.iMvY = iIntepelY;
       uiBestCost = uiTmpCost;
       pBestRef = pCurRef;
 
-      if(uiBestCost < uiSadCostThresh)
+      if (uiBestCost < uiSadCostThresh)
         break;
     }
   }
-  SaveFeatureSearchOut(sBestMv, uiBestCost, pBestRef, pFeatureSearchOut);
+  SaveFeatureSearchOut (sBestMv, uiBestCost, pBestRef, pFeatureSearchOut);
   return (i < iSearchTimesx2);
 }
 
 
-void MotionEstimateFeatureFullSearch( SFeatureSearchIn &sFeatureSearchIn,
-                                        const uint32_t kuiMaxSearchPoint,
-                                        SWelsME* pMe) {
+void MotionEstimateFeatureFullSearch (SFeatureSearchIn& sFeatureSearchIn,
+                                      const uint32_t kuiMaxSearchPoint,
+                                      SWelsME* pMe) {
   SFeatureSearchOut sFeatureSearchOut = { { 0 } };//TODO: this can be refactored and removed
   sFeatureSearchOut.uiBestSadCost = pMe->uiSadCost;
   sFeatureSearchOut.sBestMv = pMe->sMv;
@@ -859,22 +871,22 @@
   sFeatureSearchOut.pBestRef = pMe->pRefMb;
 
   int32_t iFeatureDifference = 0;//TODO: change it according to computational-complexity setting when needed
-  FeatureSearchOne( sFeatureSearchIn, iFeatureDifference, kuiMaxSearchPoint, &sFeatureSearchOut );
-  if ( sFeatureSearchOut.uiBestSadCost < pMe->uiSadCost ) {//TODO: this may be refactored and removed
-    UpdateMeResults(sFeatureSearchOut.sBestMv,
-      sFeatureSearchOut.uiBestSadCost, sFeatureSearchOut.pBestRef,
-      pMe);
+  FeatureSearchOne (sFeatureSearchIn, iFeatureDifference, kuiMaxSearchPoint, &sFeatureSearchOut);
+  if (sFeatureSearchOut.uiBestSadCost < pMe->uiSadCost) {  //TODO: this may be refactored and removed
+    UpdateMeResults (sFeatureSearchOut.sBestMv,
+                     sFeatureSearchOut.uiBestSadCost, sFeatureSearchOut.pBestRef,
+                     pMe);
   }
 }
 
 //switch related
-static uint32_t CountFMECostDown( const SDqLayer* pCurLayer ) {
+static uint32_t CountFMECostDown (const SDqLayer* pCurLayer) {
   uint32_t uiCostDownSum      = 0;
-  const int32_t kiSliceCount  = GetCurrentSliceNum( pCurLayer->pSliceEncCtx );
-  if ( kiSliceCount >= 1 ) {
+  const int32_t kiSliceCount  = GetCurrentSliceNum (pCurLayer->pSliceEncCtx);
+  if (kiSliceCount >= 1) {
     int32_t iSliceIndex  = 0;
-    SSlice *pSlice    = &pCurLayer->sLayerInfo.pSliceInLayer[iSliceIndex];
-    while( iSliceIndex < kiSliceCount ) {
+    SSlice* pSlice    = &pCurLayer->sLayerInfo.pSliceInLayer[iSliceIndex];
+    while (iSliceIndex < kiSliceCount) {
       uiCostDownSum += pSlice->uiSliceFMECostDown;
       ++ pSlice;
       ++ iSliceIndex;
@@ -884,62 +896,64 @@
 }
 #define FMESWITCH_MBAVERCOSTSAVING_THRESHOLD (2) //empirically set.
 #define FMESWITCH_GOODFRAMECOUNT_MAX (5) //empirically set.
-static void UpdateFMEGoodFrameCount(const uint32_t iAvMBNormalizedRDcostDown, uint8_t& uiFMEGoodFrameCount) {
+static void UpdateFMEGoodFrameCount (const uint32_t iAvMBNormalizedRDcostDown, uint8_t& uiFMEGoodFrameCount) {
   //this strategy may be changed, here the number is derived from empirical-numbers
   // uiFMEGoodFrameCount lies in [0,FMESWITCH_GOODFRAMECOUNT_MAX]
-  if ( iAvMBNormalizedRDcostDown > FMESWITCH_MBAVERCOSTSAVING_THRESHOLD ) {
-    if ( uiFMEGoodFrameCount < FMESWITCH_GOODFRAMECOUNT_MAX )
+  if (iAvMBNormalizedRDcostDown > FMESWITCH_MBAVERCOSTSAVING_THRESHOLD) {
+    if (uiFMEGoodFrameCount < FMESWITCH_GOODFRAMECOUNT_MAX)
       ++ uiFMEGoodFrameCount;
   } else {
-    if ( uiFMEGoodFrameCount > 0 )
+    if (uiFMEGoodFrameCount > 0)
       -- uiFMEGoodFrameCount;
   }
 }
-void UpdateFMESwitch(SDqLayer* pCurLayer) {
-  const uint32_t iFMECost = CountFMECostDown( pCurLayer );
-  const uint32_t iAvMBNormalizedRDcostDown  = iFMECost / (pCurLayer->iMbWidth*pCurLayer->iMbHeight);
-  UpdateFMEGoodFrameCount( iAvMBNormalizedRDcostDown, pCurLayer->pFeatureSearchPreparation->uiFMEGoodFrameCount );
+void UpdateFMESwitch (SDqLayer* pCurLayer) {
+  const uint32_t iFMECost = CountFMECostDown (pCurLayer);
+  const uint32_t iAvMBNormalizedRDcostDown  = iFMECost / (pCurLayer->iMbWidth * pCurLayer->iMbHeight);
+  UpdateFMEGoodFrameCount (iAvMBNormalizedRDcostDown, pCurLayer->pFeatureSearchPreparation->uiFMEGoodFrameCount);
 }
-void UpdateFMESwitchNull(SDqLayer* pCurLayer) {
+void UpdateFMESwitchNull (SDqLayer* pCurLayer) {
 }
 /////////////////////////
 // Search function options
 /////////////////////////
-void WelsDiamondCrossSearch(SWelsFuncPtrList *pFunc, void* vpMe, void* vpSlice, const int32_t kiEncStride,  const int32_t kiRefStride) {
-    SWelsME* pMe       = static_cast<SWelsME *>(vpMe);
-    SSlice* pSlice         = static_cast<SSlice *>(vpSlice);
+void WelsDiamondCrossSearch (SWelsFuncPtrList* pFunc, void* vpMe, void* vpSlice, const int32_t kiEncStride,
+                             const int32_t kiRefStride) {
+  SWelsME* pMe       = static_cast<SWelsME*> (vpMe);
+  SSlice* pSlice         = static_cast<SSlice*> (vpSlice);
 
-    //  Step 1: diamond search
-    WelsDiamondSearch(pFunc, vpMe, vpSlice, kiEncStride, kiRefStride);
+  //  Step 1: diamond search
+  WelsDiamondSearch (pFunc, vpMe, vpSlice, kiEncStride, kiRefStride);
 
-    //  Step 2: CROSS search
-    SScreenBlockFeatureStorage pRefBlockFeature; //TODO: use this structure from Ref
-    pMe->uiSadCostThreshold = pRefBlockFeature.uiSadCostThreshold[pMe->uiBlockSize];
-    if (pMe->uiSadCost >= pMe->uiSadCostThreshold) {
-      WelsMotionCrossSearch(pFunc, pMe, pSlice, kiEncStride, kiRefStride);
-    }
+  //  Step 2: CROSS search
+  SScreenBlockFeatureStorage pRefBlockFeature; //TODO: use this structure from Ref
+  pMe->uiSadCostThreshold = pRefBlockFeature.uiSadCostThreshold[pMe->uiBlockSize];
+  if (pMe->uiSadCost >= pMe->uiSadCostThreshold) {
+    WelsMotionCrossSearch (pFunc, pMe, pSlice, kiEncStride, kiRefStride);
+  }
 }
-void WelsDiamondCrossFeatureSearch(SWelsFuncPtrList *pFunc, void* vpMe, void* vpSlice, const int32_t kiEncStride, const int32_t kiRefStride) {
-    SWelsME* pMe       = static_cast<SWelsME *>(vpMe);
-    SSlice* pSlice         = static_cast<SSlice *>(vpSlice);
+void WelsDiamondCrossFeatureSearch (SWelsFuncPtrList* pFunc, void* vpMe, void* vpSlice, const int32_t kiEncStride,
+                                    const int32_t kiRefStride) {
+  SWelsME* pMe       = static_cast<SWelsME*> (vpMe);
+  SSlice* pSlice         = static_cast<SSlice*> (vpSlice);
 
-    //  Step 1: diamond search + cross
-    WelsDiamondCrossSearch(pFunc, pMe, pSlice, kiEncStride, kiRefStride);
+  //  Step 1: diamond search + cross
+  WelsDiamondCrossSearch (pFunc, pMe, pSlice, kiEncStride, kiRefStride);
 
-    // Step 2: FeatureSearch
-    if (pMe->uiSadCost >= pMe->uiSadCostThreshold) {
-        pSlice->uiSliceFMECostDown += pMe->uiSadCost;
+  // Step 2: FeatureSearch
+  if (pMe->uiSadCost >= pMe->uiSadCostThreshold) {
+    pSlice->uiSliceFMECostDown += pMe->uiSadCost;
 
-        SScreenBlockFeatureStorage tmpScreenBlockFeatureStorage; //TODO: use this structure from Ref
-        uint32_t uiMaxSearchPoint = INT_MAX;//TODO: change it according to computational-complexity setting
-        SFeatureSearchIn sFeatureSearchIn = {0};
-        SetFeatureSearchIn(pFunc, *pMe, pSlice, &tmpScreenBlockFeatureStorage,
-          kiEncStride, kiRefStride,
-          &sFeatureSearchIn);
-        MotionEstimateFeatureFullSearch( sFeatureSearchIn, uiMaxSearchPoint, pMe);
+    SScreenBlockFeatureStorage tmpScreenBlockFeatureStorage; //TODO: use this structure from Ref
+    uint32_t uiMaxSearchPoint = INT_MAX;//TODO: change it according to computational-complexity setting
+    SFeatureSearchIn sFeatureSearchIn = {0};
+    SetFeatureSearchIn (pFunc, *pMe, pSlice, &tmpScreenBlockFeatureStorage,
+                        kiEncStride, kiRefStride,
+                        &sFeatureSearchIn);
+    MotionEstimateFeatureFullSearch (sFeatureSearchIn, uiMaxSearchPoint, pMe);
 
-        pSlice->uiSliceFMECostDown -= pMe->uiSadCost;
-    }
+    pSlice->uiSliceFMECostDown -= pMe->uiSadCost;
+  }
 }
 
 } // namespace WelsSVCEnc
--- a/codec/encoder/core/src/svc_set_mb_syn_cavlc.cpp
+++ b/codec/encoder/core/src/svc_set_mb_syn_cavlc.cpp
@@ -208,10 +208,9 @@
   }
 }
 
-int32_t CheckBitstreamBuffer(const uint8_t	kuiSliceIdx, sWelsEncCtx* pEncCtx,  SBitStringAux* pBs)
-{
+int32_t CheckBitstreamBuffer (const uint8_t	kuiSliceIdx, sWelsEncCtx* pEncCtx,  SBitStringAux* pBs) {
   const int32_t iLeftLength = pBs->pBufEnd - pBs->pBufPtr - 1;
-  assert(iLeftLength > 0);
+  assert (iLeftLength > 0);
 
   if (iLeftLength < MAX_MACROBLOCK_SIZE_IN_BYTE) {
     return ENC_RETURN_MEMALLOCERR;
@@ -253,7 +252,7 @@
   }
 
   /* Step 4: Check the left buffer */
-  return CheckBitstreamBuffer(pSlice->uiSliceIdx, pEncCtx, pBs);
+  return CheckBitstreamBuffer (pSlice->uiSliceIdx, pEncCtx, pBs);
 }
 
 void WelsWriteMbResidual (SMbCache* sMbCacheInfo, SMB* pCurMb, SBitStringAux* pBs) {
--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -142,7 +142,7 @@
     if (pEncCtx) {
       SWelsTime tTime;
 
-      WelsGetTimeOfDay(&tTime);
+      WelsGetTimeOfDay (&tTime);
       iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx);	// confirmed_safe_unsafe_usage
       iBufUsed += iCurUsed;
       iBufLeft -= iCurUsed;
--- a/codec/encoder/core/src/wels_preprocess.cpp
+++ b/codec/encoder/core/src/wels_preprocess.cpp
@@ -1,1197 +1,1198 @@
-/*!
- * \copy
- *     Copyright (c)  2013, Cisco Systems
- *     All rights reserved.
- *
- *     Redistribution and use in source and binary forms, with or without
- *     modification, are permitted provided that the following conditions
- *     are met:
- *
- *        * Redistributions of source code must retain the above copyright
- *          notice, this list of conditions and the following disclaimer.
- *
- *        * Redistributions in binary form must reproduce the above copyright
- *          notice, this list of conditions and the following disclaimer in
- *          the documentation and/or other materials provided with the
- *          distribution.
- *
- *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- *     POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "wels_preprocess.h"
-#include "picture_handle.h"
-#include "encoder_context.h"
-#include "utils.h"
-#include "encoder.h"
-
-namespace WelsSVCEnc {
-
-#define WelsSafeDelete(p) if(p){ delete (p); (p) = NULL; }
-
-
-//***** entry API declaration ************************************************************************//
-
-int32_t WelsInitScaledPic (SWelsSvcCodingParam* pParam,  Scaled_Picture*  pScaledPic, CMemoryAlign* pMemoryAlign);
-bool  JudgeNeedOfScaling (SWelsSvcCodingParam* pParam, Scaled_Picture* pScaledPic);
-void    FreeScaledPic (Scaled_Picture*  pScaledPic, CMemoryAlign* pMemoryAlign);
-
-//******* table definition ***********************************************************************//
-const uint8_t g_kuiRefTemporalIdx[MAX_TEMPORAL_LEVEL][MAX_GOP_SIZE] = {
-  {  0, }, // 0
-  {  0,  0, }, // 1
-  {  0,  0,  0,  1, }, // 2
-  {  0,  0,  0,  2,  0,  1,  1,  2, }, // 3
-};
-
-const int32_t g_kiPixMapSizeInBits = sizeof (uint8_t) * 8;
-
-
-inline  void   WelsUpdateSpatialIdxMap (sWelsEncCtx* pEncCtx, int32_t iPos, SPicture* pPic, int32_t iDidx) {
-  pEncCtx->sSpatialIndexMap[iPos].pSrc = pPic;
-  pEncCtx->sSpatialIndexMap[iPos].iDid = iDidx;
-}
-
-
-/***************************************************************************
-*
-*	implement of the interface
-*
-***************************************************************************/
-
-CWelsPreProcess::CWelsPreProcess (sWelsEncCtx* pEncCtx) {
-  m_pInterfaceVp = NULL;
-  m_bInitDone = false;
-  m_pEncCtx = pEncCtx;
-  memset (&m_sScaledPicture, 0, sizeof (m_sScaledPicture));
-  memset (m_pSpatialPic, 0, sizeof (m_pSpatialPic));
-  memset (m_uiSpatialLayersInTemporal, 0, sizeof (m_uiSpatialLayersInTemporal));
-  memset (m_uiSpatialPicNum, 0, sizeof (m_uiSpatialPicNum));
-}
-
-CWelsPreProcess::~CWelsPreProcess() {
-  FreeScaledPic (&m_sScaledPicture,  m_pEncCtx->pMemAlign);
-  WelsPreprocessDestroy();
-}
-
-int32_t CWelsPreProcess::WelsPreprocessCreate() {
-  if (m_pInterfaceVp == NULL) {
-    CreateVpInterface ((void**) &m_pInterfaceVp, WELSVP_INTERFACE_VERION);
-    if (!m_pInterfaceVp)
-      goto exit;
-  } else
-    goto exit;
-
-  return 0;
-
-exit:
-  WelsPreprocessDestroy();
-  return 1;
-}
-
-int32_t CWelsPreProcess::WelsPreprocessDestroy() {
-  DestroyVpInterface (m_pInterfaceVp, WELSVP_INTERFACE_VERION);
-  m_pInterfaceVp = NULL;
-
-  return 0;
-}
-
-int32_t CWelsPreProcess::WelsPreprocessReset (sWelsEncCtx* pCtx) {
-  int32_t iRet = -1;
-
-  if (pCtx) {
-    FreeScaledPic (&m_sScaledPicture, pCtx->pMemAlign);
-    iRet = InitLastSpatialPictures (pCtx);
-    iRet = WelsInitScaledPic (pCtx->pSvcParam, &m_sScaledPicture, pCtx->pMemAlign);
-  }
-
-  return iRet;
-}
-
-int32_t CWelsPreProcess::AllocSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam) {
-  CMemoryAlign* pMa						= pCtx->pMemAlign;
-  const int32_t kiDlayerCount					= pParam->iSpatialLayerNum;
-  int32_t iDlayerIndex							= 0;
-
-  // spatial pictures
-  iDlayerIndex = 0;
-  do {
-    const int32_t kiPicWidth = pParam->sDependencyLayers[iDlayerIndex].iFrameWidth;
-    const int32_t kiPicHeight   = pParam->sDependencyLayers[iDlayerIndex].iFrameHeight;
-    const uint8_t kuiLayerInTemporal = 2 + WELS_MAX (pParam->sDependencyLayers[iDlayerIndex].iHighestTemporalId, 1);
-    const uint8_t kuiRefNumInTemporal = kuiLayerInTemporal + pParam->iLTRRefNum;
-    uint8_t i = 0;
-
-    do {
-      SPicture* pPic = AllocPicture (pMa, kiPicWidth, kiPicHeight, false, 0);
-      WELS_VERIFY_RETURN_IF (1, (NULL == pPic))
-      m_pSpatialPic[iDlayerIndex][i] = pPic;
-      ++ i;
-    } while (i < kuiRefNumInTemporal);
-
-    if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
-      m_uiSpatialLayersInTemporal[iDlayerIndex] = 1;
-    else
-      m_uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
-
-    m_uiSpatialPicNum[iDlayerIndex] = kuiRefNumInTemporal;
-    ++ iDlayerIndex;
-  } while (iDlayerIndex < kiDlayerCount);
-
-  return 0;
-}
-
-void CWelsPreProcess::FreeSpatialPictures (sWelsEncCtx* pCtx) {
-  CMemoryAlign* pMa	= pCtx->pMemAlign;
-  int32_t j = 0;
-  while (j < pCtx->pSvcParam->iSpatialLayerNum) {
-    uint8_t i = 0;
-    uint8_t uiRefNumInTemporal = m_uiSpatialPicNum[j];
-
-    while (i < uiRefNumInTemporal) {
-      if (NULL != m_pSpatialPic[j][i]) {
-        FreePicture (pMa, &m_pSpatialPic[j][i]);
-      }
-      ++ i;
-    }
-    m_uiSpatialLayersInTemporal[j] = 0;
-    ++ j;
-  }
-}
-
-int32_t CWelsPreProcess::BuildSpatialPicList (sWelsEncCtx* pCtx, const SSourcePicture* kpSrcPic) {
-  SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
-  int32_t iSpatialNum = 0;
-
-  if (!m_bInitDone) {
-    if (WelsPreprocessCreate() != 0)
-      return -1;
-    if (WelsPreprocessReset (pCtx) != 0)
-      return -1;
-
-    m_bInitDone = true;
-  }
-
-  if (m_pInterfaceVp == NULL)
-    return -1;
-
-  pCtx->pVaa->bSceneChangeFlag = pCtx->pVaa->bIdrPeriodFlag = false;
-  if (pSvcParam->uiIntraPeriod)
-    pCtx->pVaa->bIdrPeriodFlag = (1 + pCtx->iFrameIndex >= (int32_t)pSvcParam->uiIntraPeriod) ? true : false;
-
-  iSpatialNum = SingleLayerPreprocess (pCtx, kpSrcPic, &m_sScaledPicture);
-
-  return iSpatialNum;
-}
-
-int32_t CWelsPreProcess::AnalyzeSpatialPic (sWelsEncCtx* pCtx, const int32_t kiDidx) {
-  SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
-  bool bNeededMbAq = (pSvcParam->bEnableAdaptiveQuant && (pCtx->eSliceType == P_SLICE));
-  bool bCalculateBGD = (pCtx->eSliceType == P_SLICE && pSvcParam->bEnableBackgroundDetection);
-
-  int32_t iCurTemporalIdx  = m_uiSpatialLayersInTemporal[kiDidx] - 1;
-
-  int32_t iRefTemporalIdx = (int32_t)g_kuiRefTemporalIdx[pSvcParam->iDecompStages][pCtx->iCodingIndex &
-                            (pSvcParam->uiGopSize - 1)];
-  if (pCtx->uiTemporalId == 0 && pCtx->pLtr[pCtx->uiDependencyId].bReceivedT0LostFlag)
-    iRefTemporalIdx = m_uiSpatialLayersInTemporal[kiDidx] + pCtx->pVaa->uiValidLongTermPicIdx;
-
-  SPicture* pCurPic = m_pSpatialPic[kiDidx][iCurTemporalIdx];
-  bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);
-
-  if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
-    SVAAFrameInfoExt* pVaaExt			= static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
-    SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[0]);
-    SPicture* pRefPic = m_pSpatialPic[0][BestRefCandidateParam->iSrcListIdx];
-
-    VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, false, bCalculateVar, bCalculateBGD);
-
-    if (pSvcParam->bEnableBackgroundDetection) {
-      BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
-    }
-
-    if (bNeededMbAq) {
-      AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
-    }
-  } else {
-    SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx];
-    SPicture* pLastPic = m_pLastSpatialPicture[kiDidx][0];
-    bool bCalculateSQDiff = ((pLastPic->pData[0] == pRefPic->pData[0]) && bNeededMbAq);
-    bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);
-
-    VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, bCalculateSQDiff, bCalculateVar, bCalculateBGD);
-
-    if (pSvcParam->bEnableBackgroundDetection) {
-      BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
-    }
-
-    if (bNeededMbAq) {
-      SPicture* pCurPic = m_pLastSpatialPicture[kiDidx][1];
-      SPicture* pRefPic = m_pLastSpatialPicture[kiDidx][0];
-
-      AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
-    }
-    AnalyzePictureComplexity (pCtx, pCurPic, pRefPic, kiDidx, bCalculateBGD);
-    WelsExchangeSpatialPictures (&m_pLastSpatialPicture[kiDidx][1], &m_pLastSpatialPicture[kiDidx][0]);
-  }
-  return 0;
-}
-
-int32_t CWelsPreProcess::UpdateSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam,
-    const int8_t iCurTid, const int32_t d_idx) {
-  if (pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
-    return 0;
-  if (iCurTid < m_uiSpatialLayersInTemporal[d_idx] - 1 || pParam->iDecompStages == 0) {
-    if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (m_uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) {
-      InitLastSpatialPictures (pCtx);
-      return 1;
-    }
-    if (pParam->bEnableLongTermReference && pCtx->bLongTermRefFlag[d_idx][iCurTid]) {
-      SPicture* tmp	= m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx];
-      m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx] =
-        m_pSpatialPic[d_idx][iCurTid];
-      m_pSpatialPic[d_idx][iCurTid] = m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1];
-      m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1] = tmp;
-      pCtx->bLongTermRefFlag[d_idx][iCurTid] = false;
-    } else {
-      WelsExchangeSpatialPictures (&m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1],
-                                   &m_pSpatialPic[d_idx][iCurTid]);
-    }
-  }
-  return 0;
-}
-
-
-/*
-*	SingleLayerPreprocess: down sampling if applicable
-*  @return:	exact number of spatial layers need to encoder indeed
-*/
-int32_t CWelsPreProcess::SingleLayerPreprocess (sWelsEncCtx* pCtx, const SSourcePicture* kpSrc,
-    Scaled_Picture* pScaledPicture) {
-  SWelsSvcCodingParam* pSvcParam    = pCtx->pSvcParam;
-  int8_t  iDependencyId             = pSvcParam->iSpatialLayerNum - 1;
-  int32_t iPicturePos               = m_uiSpatialLayersInTemporal[iDependencyId] - 1;
-
-  SPicture* pSrcPic					= NULL;	// large
-  SPicture* pDstPic					= NULL;	// small
-  SDLayerParam* pDlayerParam					= NULL;
-  int32_t iSpatialNum					= 0;
-  int32_t iSrcWidth					= 0;
-  int32_t iSrcHeight					= 0;
-  int32_t iTargetWidth					= 0;
-  int32_t iTargetHeight					= 0;
-  int32_t iTemporalId = 0;
-  int32_t iActualSpatialLayerNum      = 0;
-
-  pDlayerParam = &pSvcParam->sDependencyLayers[iDependencyId];
-  iTargetWidth	  = pDlayerParam->iFrameWidth;
-  iTargetHeight  = pDlayerParam->iFrameHeight;
-  iTemporalId    = pDlayerParam->uiCodingIdx2TemporalId[pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1)];
-  iSrcWidth   = pSvcParam->SUsedPicRect.iWidth;
-  iSrcHeight  = pSvcParam->SUsedPicRect.iHeight;
-
-  pSrcPic = pScaledPicture->pScaledInputPicture ? pScaledPicture->pScaledInputPicture :
-            m_pSpatialPic[iDependencyId][iPicturePos];
-
-  WelsMoveMemoryWrapper (pSvcParam, pSrcPic, kpSrc, iSrcWidth, iSrcHeight);
-
-  if (pSvcParam->bEnableDenoise)
-    BilateralDenoising (pSrcPic, iSrcWidth, iSrcHeight);
-
-  // different scaling in between input picture and dst highest spatial picture.
-  int32_t iShrinkWidth  = iSrcWidth;
-  int32_t iShrinkHeight = iSrcHeight;
-  pDstPic = pSrcPic;
-  if (pScaledPicture->pScaledInputPicture) {
-    // for highest downsampling
-    pDstPic		= m_pSpatialPic[iDependencyId][iPicturePos];
-    iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];
-    iShrinkHeight = pScaledPicture->iScaledHeight[iDependencyId];
-  }
-  DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight);
-
-  if (pSvcParam->bEnableSceneChangeDetect && !pCtx->pVaa->bIdrPeriodFlag) {
-    if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
-      pCtx->pVaa->eSceneChangeIdc = (pCtx->bEncCurFrmAsIdrFlag ? LARGE_CHANGED_SCENE : DetectSceneChangeScreen (pCtx,
-                                     pDstPic));
-      pCtx->pVaa->bSceneChangeFlag = (LARGE_CHANGED_SCENE == pCtx->pVaa->eSceneChangeIdc);
-    } else {
-      if ((!pCtx->bEncCurFrmAsIdrFlag) && ! (pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1))) {
-        SPicture* pRefPic = pCtx->pLtr[iDependencyId].bReceivedT0LostFlag ?
-                            m_pSpatialPic[iDependencyId][m_uiSpatialLayersInTemporal[iDependencyId] +
-                                pCtx->pVaa->uiValidLongTermPicIdx] : m_pLastSpatialPicture[iDependencyId][0];
-
-        pCtx->pVaa->bSceneChangeFlag = DetectSceneChange (pDstPic, pRefPic);
-      }
-    }
-  }
-
-  for (int32_t i = 0; i < pSvcParam->iSpatialLayerNum; i++) {
-    if (pSvcParam->sDependencyLayers[i].uiCodingIdx2TemporalId[pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1)]
-        != INVALID_TEMPORAL_ID) {
-      ++ iActualSpatialLayerNum;
-    }
-  }
-
-  if (iTemporalId != INVALID_TEMPORAL_ID) {
-    WelsUpdateSpatialIdxMap (pCtx, iActualSpatialLayerNum - 1, pDstPic, iDependencyId);
-    ++ iSpatialNum;
-    -- iActualSpatialLayerNum;
-  }
-
-  m_pLastSpatialPicture[iDependencyId][1]	= m_pSpatialPic[iDependencyId][iPicturePos];
-  -- iDependencyId;
-
-  // generate other spacial layer
-  // pSrc is
-  //	-- padded input pic, if downsample should be applied to generate highest layer, [if] block above
-  //	-- highest layer, if no downsampling, [else] block above
-  if (pSvcParam->iSpatialLayerNum > 1) {
-    while (iDependencyId >= 0) {
-      pDlayerParam			= &pSvcParam->sDependencyLayers[iDependencyId];
-      iTargetWidth	= pDlayerParam->iFrameWidth;
-      iTargetHeight	= pDlayerParam->iFrameHeight;
-      iTemporalId = pDlayerParam->uiCodingIdx2TemporalId[pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1)];
-      iPicturePos		= m_uiSpatialLayersInTemporal[iDependencyId] - 1;
-
-      // NOT work for CGS, FIXME
-      // spatial layer is able to encode indeed
-      if ((iTemporalId != INVALID_TEMPORAL_ID)) {
-        // down sampling performed
-
-        pDstPic	= m_pSpatialPic[iDependencyId][iPicturePos];	// small
-        iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];
-        iShrinkHeight = pScaledPicture->iScaledHeight[iDependencyId];
-        DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight);
-
-        WelsUpdateSpatialIdxMap (pCtx, iActualSpatialLayerNum - 1, pDstPic, iDependencyId);
-
-        -- iActualSpatialLayerNum;
-        ++ iSpatialNum;
-
-        m_pLastSpatialPicture[iDependencyId][1]	= m_pSpatialPic[iDependencyId][iPicturePos];
-      }
-      -- iDependencyId;
-    }
-  }
-
-  return iSpatialNum;
-}
-
-
-/*!
- * \brief	Whether input picture need be scaled?
- */
-bool JudgeNeedOfScaling (SWelsSvcCodingParam* pParam, Scaled_Picture* pScaledPicture) {
-  const int32_t kiInputPicWidth	= pParam->SUsedPicRect.iWidth;
-  const int32_t kiInputPicHeight = pParam->SUsedPicRect.iHeight;
-  const int32_t kiDstPicWidth		= pParam->sDependencyLayers[pParam->iSpatialLayerNum - 1].iActualWidth;
-  const int32_t kiDstPicHeight	= pParam->sDependencyLayers[pParam->iSpatialLayerNum - 1].iActualHeight;
-  bool bNeedDownsampling = true;
-
-  int32_t iSpatialIdx = pParam->iSpatialLayerNum - 1;
-
-  if (kiDstPicWidth >= kiInputPicWidth && kiDstPicHeight >= kiInputPicHeight) {
-    iSpatialIdx --;  // highest D layer do not need downsampling
-    bNeedDownsampling = false;
-  }
-
-  for (; iSpatialIdx >= 0; iSpatialIdx --) {
-    SDLayerParam* pCurLayer = &pParam->sDependencyLayers[iSpatialIdx];
-    int32_t iCurDstWidth			= pCurLayer->iActualWidth;
-    int32_t iCurDstHeight			= pCurLayer->iActualHeight;
-    int32_t iInputWidthXDstHeight	= kiInputPicWidth * iCurDstHeight;
-    int32_t iInputHeightXDstWidth	= kiInputPicHeight * iCurDstWidth;
-
-    if (iInputWidthXDstHeight > iInputHeightXDstWidth) {
-      pScaledPicture->iScaledWidth[iSpatialIdx] = iCurDstWidth;
-      pScaledPicture->iScaledHeight[iSpatialIdx] = iInputHeightXDstWidth / kiInputPicWidth;
-    } else {
-      pScaledPicture->iScaledWidth[iSpatialIdx] = iInputWidthXDstHeight / kiInputPicHeight;
-      pScaledPicture->iScaledHeight[iSpatialIdx] = iCurDstHeight;
-    }
-  }
-
-  return bNeedDownsampling;
-}
-
-int32_t  WelsInitScaledPic (SWelsSvcCodingParam* pParam,  Scaled_Picture*  pScaledPicture, CMemoryAlign* pMemoryAlign) {
-  bool bInputPicNeedScaling = JudgeNeedOfScaling (pParam, pScaledPicture);
-  if (bInputPicNeedScaling) {
-    pScaledPicture->pScaledInputPicture = AllocPicture (pMemoryAlign, pParam->SUsedPicRect.iWidth,
-                                          pParam->SUsedPicRect.iHeight, false, 0);
-    if (pScaledPicture->pScaledInputPicture == NULL)
-      return -1;
-  }
-  return 0;
-}
-
-void  FreeScaledPic (Scaled_Picture*  pScaledPicture, CMemoryAlign* pMemoryAlign) {
-  if (pScaledPicture->pScaledInputPicture) {
-    FreePicture (pMemoryAlign, &pScaledPicture->pScaledInputPicture);
-    pScaledPicture->pScaledInputPicture = NULL;
-  }
-}
-
-int32_t CWelsPreProcess::InitLastSpatialPictures (sWelsEncCtx* pCtx) {
-  SWelsSvcCodingParam* pParam	= pCtx->pSvcParam;
-  const int32_t kiDlayerCount			= pParam->iSpatialLayerNum;
-  int32_t iDlayerIndex					= 0;
-
-  for (; iDlayerIndex < kiDlayerCount; iDlayerIndex++) {
-    const int32_t kiLayerInTemporal = m_uiSpatialLayersInTemporal[iDlayerIndex];
-    m_pLastSpatialPicture[iDlayerIndex][0]	= m_pSpatialPic[iDlayerIndex][kiLayerInTemporal - 2];
-    m_pLastSpatialPicture[iDlayerIndex][1]	= NULL;
-  }
-  for (; iDlayerIndex < MAX_DEPENDENCY_LAYER; iDlayerIndex++) {
-    m_pLastSpatialPicture[iDlayerIndex][0]	= m_pLastSpatialPicture[iDlayerIndex][1] = NULL;
-  }
-
-  return 0;
-}
-//*********************************************************************************************************/
-
-int32_t CWelsPreProcess::ColorspaceConvert (SWelsSvcCodingParam* pSvcParam, SPicture* pDstPic,
-    const SSourcePicture* kpSrc, const int32_t kiWidth, const int32_t kiHeight) {
-  return 1;
-  //not support yet
-}
-
-void CWelsPreProcess::BilateralDenoising (SPicture* pSrc, const int32_t kiWidth, const int32_t kiHeight) {
-  int32_t iMethodIdx = METHOD_DENOISE;
-  SPixMap sSrcPixMap;
-  memset (&sSrcPixMap, 0, sizeof (sSrcPixMap));
-  sSrcPixMap.pPixel[0] = pSrc->pData[0];
-  sSrcPixMap.pPixel[1] = pSrc->pData[1];
-  sSrcPixMap.pPixel[2] = pSrc->pData[2];
-  sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-  sSrcPixMap.sRect.iRectWidth = kiWidth;
-  sSrcPixMap.sRect.iRectHeight = kiHeight;
-  sSrcPixMap.iStride[0] = pSrc->iLineSize[0];
-  sSrcPixMap.iStride[1] = pSrc->iLineSize[1];
-  sSrcPixMap.iStride[2] = pSrc->iLineSize[2];
-  sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
-
-  m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, NULL);
-}
-
-bool CWelsPreProcess::DetectSceneChange (SPicture* pCurPicture, SPicture* pRefPicture) {
-  bool bSceneChangeFlag = false;
-  int32_t iMethodIdx = METHOD_SCENE_CHANGE_DETECTION_VIDEO;
-  SSceneChangeResult sSceneChangeDetectResult = { SIMILAR_SCENE };
-  SPixMap sSrcPixMap;
-  SPixMap sRefPixMap;
-  memset (&sSrcPixMap, 0, sizeof (sSrcPixMap));
-  memset (&sRefPixMap, 0, sizeof (sRefPixMap));
-  sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
-  sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-  sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
-  sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
-  sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
-  sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
-
-
-  sRefPixMap.pPixel[0] = pRefPicture->pData[0];
-  sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-  sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
-  sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
-  sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
-  sRefPixMap.eFormat = VIDEO_FORMAT_I420;
-
-  int32_t iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
-  if (iRet == 0) {
-    m_pInterfaceVp->Get (iMethodIdx, (void*)&sSceneChangeDetectResult);
-    bSceneChangeFlag = (sSceneChangeDetectResult.eSceneChangeIdc == LARGE_CHANGED_SCENE) ? true : false;
-  }
-
-  return bSceneChangeFlag;
-}
-
-int32_t CWelsPreProcess::DownsamplePadding (SPicture* pSrc, SPicture* pDstPic,  int32_t iSrcWidth, int32_t iSrcHeight,
-    int32_t iShrinkWidth, int32_t iShrinkHeight, int32_t iTargetWidth, int32_t iTargetHeight) {
-  int32_t iRet = 0;
-  SPixMap sSrcPixMap;
-  SPixMap sDstPicMap;
-  memset (&sSrcPixMap, 0, sizeof (sSrcPixMap));
-  memset (&sDstPicMap, 0, sizeof (sDstPicMap));
-  sSrcPixMap.pPixel[0]   = pSrc->pData[0];
-  sSrcPixMap.pPixel[1]   = pSrc->pData[1];
-  sSrcPixMap.pPixel[2]   = pSrc->pData[2];
-  sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-  sSrcPixMap.sRect.iRectWidth  = iSrcWidth;
-  sSrcPixMap.sRect.iRectHeight = iSrcHeight;
-  sSrcPixMap.iStride[0]  = pSrc->iLineSize[0];
-  sSrcPixMap.iStride[1]  = pSrc->iLineSize[1];
-  sSrcPixMap.iStride[2]  = pSrc->iLineSize[2];
-  sSrcPixMap.eFormat     = VIDEO_FORMAT_I420;
-
-  if (iSrcWidth != iShrinkWidth || iSrcHeight != iShrinkHeight) {
-    int32_t iMethodIdx = METHOD_DOWNSAMPLE;
-    sDstPicMap.pPixel[0]   = pDstPic->pData[0];
-    sDstPicMap.pPixel[1]   = pDstPic->pData[1];
-    sDstPicMap.pPixel[2]   = pDstPic->pData[2];
-    sDstPicMap.iSizeInBits = g_kiPixMapSizeInBits;
-    sDstPicMap.sRect.iRectWidth  = iShrinkWidth;
-    sDstPicMap.sRect.iRectHeight = iShrinkHeight;
-    sDstPicMap.iStride[0]  = pDstPic->iLineSize[0];
-    sDstPicMap.iStride[1]  = pDstPic->iLineSize[1];
-    sDstPicMap.iStride[2]  = pDstPic->iLineSize[2];
-    sDstPicMap.eFormat     = VIDEO_FORMAT_I420;
-
-    iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sDstPicMap);
-  } else {
-    memcpy (&sDstPicMap, &sSrcPixMap, sizeof (sDstPicMap));	// confirmed_safe_unsafe_usage
-  }
-
-  // get rid of odd line
-  iShrinkWidth -= (iShrinkWidth & 1);
-  iShrinkHeight -= (iShrinkHeight & 1);
-  Padding ((uint8_t*)sDstPicMap.pPixel[0], (uint8_t*)sDstPicMap.pPixel[1], (uint8_t*)sDstPicMap.pPixel[2],
-           sDstPicMap.iStride[0], sDstPicMap.iStride[1],	iShrinkWidth, iTargetWidth, iShrinkHeight, iTargetHeight);
-
-  return iRet;
-}
-
-//*********************************************************************************************************/
-void CWelsPreProcess::VaaCalculation (SVAAFrameInfo* pVaaInfo, SPicture* pCurPicture, SPicture* pRefPicture,
-                                      bool bCalculateSQDiff, bool bCalculateVar, bool bCalculateBGD) {
-  pVaaInfo->sVaaCalcInfo.pCurY = pCurPicture->pData[0];
-  pVaaInfo->sVaaCalcInfo.pRefY = pRefPicture->pData[0];
-  {
-    int32_t iMethodIdx = METHOD_VAA_STATISTICS;
-    SPixMap sCurPixMap;
-    SPixMap sRefPixMap;
-    memset (&sCurPixMap, 0, sizeof (sCurPixMap));
-    memset (&sRefPixMap, 0, sizeof (sRefPixMap));
-    SVAACalcParam calc_param = {0};
-
-    sCurPixMap.pPixel[0] = pCurPicture->pData[0];
-    sCurPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-    sCurPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
-    sCurPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
-    sCurPixMap.iStride[0] = pCurPicture->iLineSize[0];
-    sCurPixMap.eFormat = VIDEO_FORMAT_I420;
-
-    sRefPixMap.pPixel[0] = pRefPicture->pData[0];
-    sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-    sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
-    sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
-    sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
-    sRefPixMap.eFormat = VIDEO_FORMAT_I420;
-
-    calc_param.iCalcVar	= bCalculateVar;
-    calc_param.iCalcBgd	= bCalculateBGD;
-    calc_param.iCalcSsd	= bCalculateSQDiff;
-    calc_param.pCalcResult = &pVaaInfo->sVaaCalcInfo;
-
-    m_pInterfaceVp->Set (iMethodIdx, &calc_param);
-    m_pInterfaceVp->Process (iMethodIdx, &sCurPixMap, &sRefPixMap);
-  }
-}
-
-void CWelsPreProcess::BackgroundDetection (SVAAFrameInfo* pVaaInfo, SPicture* pCurPicture, SPicture* pRefPicture,
-    bool bDetectFlag) {
-  if (bDetectFlag) {
-    pVaaInfo->iPicWidth     = pCurPicture->iWidthInPixel;
-    pVaaInfo->iPicHeight    = pCurPicture->iHeightInPixel;
-
-    pVaaInfo->iPicStride	= pCurPicture->iLineSize[0];
-    pVaaInfo->iPicStrideUV	= pCurPicture->iLineSize[1];
-    pVaaInfo->pCurY			= pCurPicture->pData[0];
-    pVaaInfo->pRefY			= pRefPicture->pData[0];
-    pVaaInfo->pCurU			= pCurPicture->pData[1];
-    pVaaInfo->pRefU			= pRefPicture->pData[1];
-    pVaaInfo->pCurV			= pCurPicture->pData[2];
-    pVaaInfo->pRefV			= pRefPicture->pData[2];
-
-    int32_t iMethodIdx = METHOD_BACKGROUND_DETECTION;
-    SPixMap sSrcPixMap;
-    SPixMap sRefPixMap;
-    memset (&sSrcPixMap, 0, sizeof (sSrcPixMap));
-    memset (&sRefPixMap, 0, sizeof (sRefPixMap));
-    SBGDInterface BGDParam = {0};
-
-    sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
-    sSrcPixMap.pPixel[1] = pCurPicture->pData[1];
-    sSrcPixMap.pPixel[2] = pCurPicture->pData[2];
-    sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-    sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
-    sSrcPixMap.iStride[1] = pCurPicture->iLineSize[1];
-    sSrcPixMap.iStride[2] = pCurPicture->iLineSize[2];
-    sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
-    sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
-    sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
-
-    sRefPixMap.pPixel[0] = pRefPicture->pData[0];
-    sRefPixMap.pPixel[1] = pRefPicture->pData[1];
-    sRefPixMap.pPixel[2] = pRefPicture->pData[2];
-    sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-    sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
-    sRefPixMap.iStride[1] = pRefPicture->iLineSize[1];
-    sRefPixMap.iStride[2] = pRefPicture->iLineSize[2];
-    sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
-    sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
-    sRefPixMap.eFormat = VIDEO_FORMAT_I420;
-
-    BGDParam.pBackgroundMbFlag = pVaaInfo->pVaaBackgroundMbFlag;
-    BGDParam.pCalcRes = & (pVaaInfo->sVaaCalcInfo);
-    m_pInterfaceVp->Set (iMethodIdx, (void*)&BGDParam);
-    m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
-  } else {
-    int32_t	iPicWidthInMb	= (pCurPicture->iWidthInPixel + 15) >> 4;
-    int32_t	iPicHeightInMb = (pCurPicture->iHeightInPixel + 15) >> 4;
-    memset (pVaaInfo->pVaaBackgroundMbFlag, 0, iPicWidthInMb * iPicHeightInMb);
-  }
-}
-
-void CWelsPreProcess::AdaptiveQuantCalculation (SVAAFrameInfo* pVaaInfo, SPicture* pCurPicture, SPicture* pRefPicture) {
-  pVaaInfo->sAdaptiveQuantParam.pCalcResult = & (pVaaInfo->sVaaCalcInfo);
-  pVaaInfo->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp = 0;
-
-  {
-    int32_t iMethodIdx = METHOD_ADAPTIVE_QUANT;
-    SPixMap pSrc;
-    SPixMap pRef;
-    memset (&pSrc, 0, sizeof (pSrc));
-    memset (&pRef, 0, sizeof (pRef));
-    int32_t iRet = 0;
-
-    pSrc.pPixel[0] = pCurPicture->pData[0];
-    pSrc.iSizeInBits = g_kiPixMapSizeInBits;
-    pSrc.iStride[0] = pCurPicture->iLineSize[0];
-    pSrc.sRect.iRectWidth = pCurPicture->iWidthInPixel;
-    pSrc.sRect.iRectHeight = pCurPicture->iHeightInPixel;
-    pSrc.eFormat = VIDEO_FORMAT_I420;
-
-    pRef.pPixel[0] = pRefPicture->pData[0];
-    pRef.iSizeInBits = g_kiPixMapSizeInBits;
-    pRef.iStride[0] = pRefPicture->iLineSize[0];
-    pRef.sRect.iRectWidth = pRefPicture->iWidthInPixel;
-    pRef.sRect.iRectHeight = pRefPicture->iHeightInPixel;
-    pRef.eFormat = VIDEO_FORMAT_I420;
-
-    iRet = m_pInterfaceVp->Set (iMethodIdx, (void*) & (pVaaInfo->sAdaptiveQuantParam));
-    iRet = m_pInterfaceVp->Process (iMethodIdx, &pSrc, &pRef);
-    if (iRet == 0)
-      m_pInterfaceVp->Get (iMethodIdx, (void*) & (pVaaInfo->sAdaptiveQuantParam));
-  }
-}
-
-void CWelsPreProcess::SetRefMbType (sWelsEncCtx* pCtx, uint32_t** pRefMbTypeArray, int32_t iRefPicType) {
-  const uint8_t uiTid	    = pCtx->uiTemporalId;
-  const uint8_t uiDid       = pCtx->uiDependencyId;
-  SRefList* pRefPicLlist    = pCtx->ppRefPicListExt[uiDid];
-  SLTRState* pLtr	    = &pCtx->pLtr[uiDid];
-  uint8_t i							= 0;
-
-  if (pCtx->pSvcParam->bEnableLongTermReference && pLtr->bReceivedT0LostFlag && uiTid == 0) {
-    for (i = 0; i < pRefPicLlist->uiLongRefCount; i++) {
-      SPicture* pRef = pRefPicLlist->pLongRefList[i];
-      if (pRef != NULL && pRef->uiRecieveConfirmed == 1/*RECIEVE_SUCCESS*/) {
-        *pRefMbTypeArray = pRef->uiRefMbType;
-        break;
-      }
-    }
-  } else {
-    for (i = 0; i < pRefPicLlist->uiShortRefCount; i++) {
-      SPicture* pRef = pRefPicLlist->pShortRefList[i];
-      if (pRef != NULL && pRef->bUsedAsRef && pRef->iFramePoc >= 0 && pRef->uiTemporalId <= uiTid) {
-        *pRefMbTypeArray = pRef->uiRefMbType;
-        break;
-      }
-    }
-  }
-}
-
-
-void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,
-    const int32_t kiDependencyId, const bool bCalculateBGD) {
-  SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
-  int32_t iComplexityAnalysisMode = 0;
-
-  if (pSvcParam->iRCMode == RC_OFF_MODE)
-    return;
-  if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
-    SVAAFrameInfoExt* pVaaExt		= static_cast<SVAAFrameInfoExt*> (pCtx->pVaa);
-    SComplexityAnalysisScreenParam* sComplexityAnalysisParam	= &pVaaExt->sComplexityScreenParam;
-    SWelsSvcRc* pWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
-
-    if (pCtx->eSliceType == P_SLICE)
-      iComplexityAnalysisMode = GOM_SAD;
-    else if (pCtx->eSliceType == I_SLICE)
-      iComplexityAnalysisMode = GOM_VAR;
-    else
-      return;
-
-    memset (pWelsSvcRc->pGomForegroundBlockNum, 0, pWelsSvcRc->iGomSize * sizeof (int32_t));
-    memset (pWelsSvcRc->pCurrentFrameGomSad, 0, pWelsSvcRc->iGomSize * sizeof (int32_t));
-
-    sComplexityAnalysisParam->iFrameComplexity = 0;
-    sComplexityAnalysisParam->pGomComplexity = pWelsSvcRc->pCurrentFrameGomSad;
-    sComplexityAnalysisParam->iGomNumInFrame = pWelsSvcRc->iGomSize;
-    sComplexityAnalysisParam->iIdrFlag = (pCtx->eSliceType == I_SLICE);
-    sComplexityAnalysisParam->iMbRowInGom = GOM_H_SCC;
-    sComplexityAnalysisParam->sScrollResult.bScrollDetectFlag = false;
-    sComplexityAnalysisParam->sScrollResult.iScrollMvX = 0;
-    sComplexityAnalysisParam->sScrollResult.iScrollMvY = 0;
-
-    const int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS_SCREEN;
-    SPixMap sSrcPixMap;
-    SPixMap sRefPixMap;
-    memset (&sSrcPixMap, 0, sizeof (SPixMap));
-    memset (&sRefPixMap, 0, sizeof (SPixMap));
-    int32_t iRet = 0;
-
-    sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
-    sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-    sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
-    sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
-    sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
-    sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
-
-    if (pRefPicture != NULL) {
-      sRefPixMap.pPixel[0] = pRefPicture->pData[0];
-      sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-      sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
-      sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
-      sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
-      sRefPixMap.eFormat = VIDEO_FORMAT_I420;
-    }
-
-    iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam);
-    iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
-    if (iRet == 0)
-      m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam);
-
-  } else {
-    SVAAFrameInfo* pVaaInfo	 = pCtx->pVaa;
-    SComplexityAnalysisParam* sComplexityAnalysisParam = & (pVaaInfo->sComplexityAnalysisParam);
-    SWelsSvcRc* SWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
-
-    if (pSvcParam->iRCMode == RC_QUALITY_MODE && pCtx->eSliceType == P_SLICE) {
-      iComplexityAnalysisMode = FRAME_SAD;
-    } else if (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == P_SLICE) {
-      iComplexityAnalysisMode = GOM_SAD;
-    } else if (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE) {
-      iComplexityAnalysisMode = GOM_VAR;
-    } else {
-      return;
-    }
-    sComplexityAnalysisParam->iComplexityAnalysisMode = iComplexityAnalysisMode;
-    sComplexityAnalysisParam->pCalcResult = & (pVaaInfo->sVaaCalcInfo);
-    sComplexityAnalysisParam->pBackgroundMbFlag = pVaaInfo->pVaaBackgroundMbFlag;
-    SetRefMbType (pCtx, & (sComplexityAnalysisParam->uiRefMbType), pRefPicture->iPictureType);
-    sComplexityAnalysisParam->iCalcBgd = bCalculateBGD;
-    sComplexityAnalysisParam->iFrameComplexity = 0;
-
-    memset (SWelsSvcRc->pGomForegroundBlockNum, 0, SWelsSvcRc->iGomSize * sizeof (int32_t));
-    if (iComplexityAnalysisMode != FRAME_SAD)
-      memset (SWelsSvcRc->pCurrentFrameGomSad, 0, SWelsSvcRc->iGomSize * sizeof (int32_t));
-
-    sComplexityAnalysisParam->pGomComplexity = SWelsSvcRc->pCurrentFrameGomSad;
-    sComplexityAnalysisParam->pGomForegroundBlockNum = SWelsSvcRc->pGomForegroundBlockNum;
-    sComplexityAnalysisParam->iMbNumInGom = SWelsSvcRc->iNumberMbGom;
-
-    {
-      int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS;
-      SPixMap sSrcPixMap;
-      SPixMap sRefPixMap;
-      memset (&sSrcPixMap, 0, sizeof (SPixMap));
-      memset (&sRefPixMap, 0, sizeof (SPixMap));
-      int32_t iRet = 0;
-
-      sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
-      sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-      sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
-      sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
-      sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
-      sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
-
-      sRefPixMap.pPixel[0] = pRefPicture->pData[0];
-      sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
-      sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
-      sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
-      sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
-      sRefPixMap.eFormat = VIDEO_FORMAT_I420;
-
-      iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam);
-      iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
-      if (iRet == 0)
-        m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam);
-    }
-  }
-}
-
-
-void CWelsPreProcess::InitPixMap (const SPicture* pPicture, SPixMap* pPixMap) {
-  pPixMap->pPixel[0] = pPicture->pData[0];
-  pPixMap->pPixel[1] = pPicture->pData[1];
-  pPixMap->pPixel[2] = pPicture->pData[2];
-  pPixMap->iSizeInBits = sizeof (uint8_t);
-  pPixMap->iStride[0] = pPicture->iLineSize[0];
-  pPixMap->iStride[1] = pPicture->iLineSize[1];
-  pPixMap->sRect.iRectWidth = pPicture->iWidthInPixel;
-  pPixMap->sRect.iRectHeight = pPicture->iHeightInPixel;
-
-  pPixMap->eFormat = VIDEO_FORMAT_I420;
-}
-void CWelsPreProcess::GetAvailableRefList (SPicture** pSrcPicList, uint8_t iCurTid, const int32_t iClosestLtrFrameNum,
-    SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum) {
-  SWelsSvcCodingParam*		pSvcParam = m_pEncCtx->pSvcParam;
-  const int32_t iSourcePicNum = pSvcParam->iNumRefFrame;
-  if (0 >= iSourcePicNum) {
-    iAvailableRefNum = 0;
-    iAvailableSceneRefNum = 0;
-    return ;
-  }
-  const bool bCurFrameMarkedAsSceneLtr = m_pEncCtx->bCurFrameMarkedAsSceneLtr;
-  SPicture* pRefPic = NULL;
-  uint8_t uiRefTid = 0;
-  bool bRefRealLtr = false;
-
-  iAvailableRefNum = 1; //zero is left for the closest frame
-  iAvailableSceneRefNum = 0;
-
-  //the saving order will be depend on pSrcPicList
-  //TODO: use a frame_idx to find the closer ref in time distance, and correctly sort the ref list
-  for (int32_t i = iSourcePicNum - 1; i >= 0; --i) {
-    pRefPic = pSrcPicList[i];
-    if (NULL == pRefPic || !pRefPic->bUsedAsRef || !pRefPic->bIsLongRef || (bCurFrameMarkedAsSceneLtr
-        && (!pRefPic->bIsSceneLTR))) {
-      continue;
-    }
-    uiRefTid = pRefPic->uiTemporalId;
-    bRefRealLtr = pRefPic->bIsSceneLTR;
-
-    if (bRefRealLtr || (0 == iCurTid && 0 == uiRefTid) || (uiRefTid < iCurTid)) {
-      int32_t idx = (pRefPic->iLongTermPicNum == iClosestLtrFrameNum) ? (0) : (iAvailableRefNum++);
-      pAvailableRefList[idx].pRefPicture = pRefPic;
-      pAvailableRefList[idx].iSrcListIdx = i + 1; //in SrcList, the idx 0 is reserved for CurPic
-      iAvailableSceneRefNum += bRefRealLtr;
-    }
-  }
-
-  if (pAvailableRefList[0].pRefPicture == NULL) {
-    for (int32_t i = 1; i < iAvailableRefNum ; ++i) {
-      pAvailableRefList[i - 1].pRefPicture = pAvailableRefList[i].pRefPicture;
-      pAvailableRefList[i - 1].iSrcListIdx = pAvailableRefList[i].iSrcListIdx;
-    }
-
-    pAvailableRefList[iAvailableRefNum - 1].pRefPicture = NULL;
-    pAvailableRefList[iAvailableRefNum - 1].iSrcListIdx = 0;
-    --iAvailableRefNum;
-  }
-}
-
-
-void CWelsPreProcess::InitRefJudgement (SRefJudgement* pRefJudgement) {
-  pRefJudgement->iMinFrameComplexity = INT_MAX;
-  pRefJudgement->iMinFrameComplexity08 = INT_MAX;
-  pRefJudgement->iMinFrameComplexity11 = INT_MAX;
-
-  pRefJudgement->iMinFrameNumGap = INT_MAX;
-  pRefJudgement->iMinFrameQp = INT_MAX;
-}
-bool CWelsPreProcess::JudgeBestRef (SPicture* pRefPic, const SRefJudgement& sRefJudgement,
-                                    const int32_t iFrameComplexity, const bool bIsClosestLtrFrame) {
-  return (bIsClosestLtrFrame ? (iFrameComplexity < sRefJudgement.iMinFrameComplexity11) :
-          ((iFrameComplexity < sRefJudgement.iMinFrameComplexity08) || ((iFrameComplexity <= sRefJudgement.iMinFrameComplexity11)
-              && (pRefPic->iFrameAverageQp < sRefJudgement.iMinFrameQp))));
-}
-
-void CWelsPreProcess::SaveBestRefToJudgement (const int32_t iRefPictureAvQP, const int32_t iComplexity,
-    SRefJudgement* pRefJudgement) {
-  pRefJudgement->iMinFrameQp = iRefPictureAvQP;
-  pRefJudgement->iMinFrameComplexity =  iComplexity;
-  pRefJudgement->iMinFrameComplexity08 = static_cast<int32_t> (iComplexity * 0.8);
-  pRefJudgement->iMinFrameComplexity11 = static_cast<int32_t> (iComplexity * 1.1);
-}
-void CWelsPreProcess::SaveBestRefToLocal (SRefInfoParam* pRefPicInfo, const SSceneChangeResult& sSceneChangeResult,
-    SRefInfoParam* pRefSaved) {
-  pRefSaved->iSrcListIdx = pRefPicInfo->iSrcListIdx;
-  pRefSaved->bSceneLtrFlag = pRefPicInfo->bSceneLtrFlag;
-}
-
-void CWelsPreProcess::SaveBestRefToVaa (SRefInfoParam& sRefSaved, SRefInfoParam* pVaaBestRef) {
-  (*pVaaBestRef) = sRefSaved;
-}
-
-ESceneChangeIdc CWelsPreProcess::DetectSceneChangeScreen (sWelsEncCtx* pCtx, SPicture* pCurPicture) {
-#define STATIC_SCENE_MOTION_RATIO 0.01f
-  SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
-  SVAAFrameInfoExt* pVaaExt			= static_cast<SVAAFrameInfoExt*> (pCtx->pVaa);
-  if (NULL == pCtx || NULL == pVaaExt || NULL == pCurPicture) {
-    return LARGE_CHANGED_SCENE;
-  }
-
-  const int32_t iTargetDid = pSvcParam->iSpatialLayerNum - 1;
-  if (0 != iTargetDid) {
-    return LARGE_CHANGED_SCENE;
-  }
-
-  ESceneChangeIdc iVaaFrameSceneChangeIdc = LARGE_CHANGED_SCENE;
-  SPicture** pSrcPicList = &m_pSpatialPic[iTargetDid][1];
-  if (NULL == pSrcPicList) {
-    return LARGE_CHANGED_SCENE;
-  }
-
-  SRefInfoParam sAvailableRefList[MAX_REF_PIC_COUNT] = { { 0 } };
-  int32_t iAvailableRefNum = 0;
-  int32_t iAvailableSceneRefNum = 0;
-
-  int32_t iSceneChangeMethodIdx = METHOD_SCENE_CHANGE_DETECTION_SCREEN;
-  SSceneChangeResult sSceneChangeResult = {SIMILAR_SCENE, 0, 0, NULL};
-
-  SPixMap sSrcMap = { { 0 } };
-  SPixMap sRefMap = { { 0 } };
-  SRefJudgement sLtrJudgement;
-  SRefJudgement sSceneLtrJudgement;
-  SRefInfoParam sLtrSaved = {0};
-  SRefInfoParam sSceneLtrSaved = {0};
-
-  int32_t iNumOfLargeChange = 0, iNumOfMediumChangeToLtr = 0;
-
-  bool bBestRefIsLtr = false, bIsClosestLtrFrame = false;
-  int32_t ret = 1, iScdIdx = 0;
-
-  SPicture* pRefPic = NULL;
-  SRefInfoParam* pRefPicInfo = NULL;
-  uint8_t*  pCurBlockStaticPointer = NULL;
-  uint8_t*  pBestStrBlockStaticPointer = NULL;
-  uint8_t*  pBestLtrBlockStaticPointer = NULL;
-
-  const int32_t iNegligibleMotionBlocks = (static_cast<int32_t> ((pCurPicture->iWidthInPixel >> 3) *
-                                          (pCurPicture->iHeightInPixel >> 3) * STATIC_SCENE_MOTION_RATIO));
-  const uint8_t iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[m_pEncCtx->sSpatialIndexMap[0].iDid],
-                          m_pEncCtx->iCodingIndex, pSvcParam->uiGopSize);
-  const int32_t iClosestLtrFrameNum = pCtx->pLtr[iTargetDid].iLastLtrIdx[iCurTid];//TBD
-  GetAvailableRefList (pSrcPicList, iCurTid, iClosestLtrFrameNum, &sAvailableRefList[0], iAvailableRefNum,
-                       iAvailableSceneRefNum);
-  //after this build, pAvailableRefList[idx].iSrcListIdx is the idx of the ref in h->spatial_pic
-  if (0 == iAvailableRefNum) {
-    WelsLog (pCtx, WELS_LOG_ERROR, "SceneChangeDetect() iAvailableRefNum=0 but not I.\n");
-    return LARGE_CHANGED_SCENE;
-  }
-
-  InitPixMap (pCurPicture, &sSrcMap);
-  InitRefJudgement (&sLtrJudgement);
-  InitRefJudgement (&sSceneLtrJudgement);
-
-  for (iScdIdx = 0; iScdIdx < iAvailableRefNum; iScdIdx ++) {
-    pCurBlockStaticPointer = pVaaExt->pVaaBlockStaticIdc[iScdIdx];
-    sSceneChangeResult.eSceneChangeIdc = SIMILAR_SCENE;
-    sSceneChangeResult.pStaticBlockIdc = pCurBlockStaticPointer;//
-
-    pRefPicInfo = & (sAvailableRefList[iScdIdx]);
-    assert (NULL != pRefPicInfo);
-    pRefPic = pRefPicInfo->pRefPicture;
-    InitPixMap (pRefPic, &sRefMap);
-
-    bIsClosestLtrFrame = (pRefPic->iLongTermPicNum == iClosestLtrFrameNum);
-
-    //TBD scrolling detection
-    m_pInterfaceVp->Set (iSceneChangeMethodIdx, (void*) (&sSceneChangeResult));
-    ret = m_pInterfaceVp->Process (iSceneChangeMethodIdx, &sSrcMap, &sRefMap);
-
-    if (ret == 0) {
-      m_pInterfaceVp->Get (iSceneChangeMethodIdx, (void*)&sSceneChangeResult);
-
-      const int32_t iFrameComplexity = sSceneChangeResult.iFrameComplexity;
-      const int32_t iSceneDetectIdc = sSceneChangeResult.eSceneChangeIdc;
-      const int32_t iMotionBlockNum = sSceneChangeResult.iMotionBlockNum;
-
-      const bool bCurRefIsLtr = pRefPic->bIsSceneLTR;
-      const int32_t iRefPicAvQP = pRefPic->iFrameAverageQp;
-
-      //for scene change detection
-      iNumOfLargeChange += (static_cast<int32_t> (LARGE_CHANGED_SCENE == iSceneDetectIdc));
-      iNumOfMediumChangeToLtr += (static_cast<int32_t> ((bCurRefIsLtr) && (iSceneDetectIdc != SIMILAR_SCENE)));
-
-      //for reference selection
-      //this judge can only be saved when iAvailableRefNum==1, which is very limit
-      //when LTR is OFF, it can still judge from all available STR
-      if (JudgeBestRef (pRefPic, sLtrJudgement, iFrameComplexity, bIsClosestLtrFrame)) {
-        SaveBestRefToJudgement (iRefPicAvQP, iFrameComplexity, &sLtrJudgement);
-        SaveBestRefToLocal (pRefPicInfo, sSceneChangeResult, &sLtrSaved);
-        bBestRefIsLtr = bCurRefIsLtr;
-        pBestStrBlockStaticPointer = sSceneChangeResult.pStaticBlockIdc;
-      }
-      if (bCurRefIsLtr && JudgeBestRef (pRefPic, sSceneLtrJudgement, iFrameComplexity, bIsClosestLtrFrame)) {
-        SaveBestRefToJudgement (iRefPicAvQP, iFrameComplexity, &sSceneLtrJudgement);
-        SaveBestRefToLocal (pRefPicInfo, sSceneChangeResult, &sSceneLtrSaved);
-        pBestLtrBlockStaticPointer = sSceneChangeResult.pStaticBlockIdc;
-      }
-
-      if (iMotionBlockNum <= iNegligibleMotionBlocks) {
-        break;
-      }
-    }
-  }
-
-  if (iNumOfLargeChange == iAvailableRefNum) {
-    iVaaFrameSceneChangeIdc = LARGE_CHANGED_SCENE;
-  } else if ((iNumOfMediumChangeToLtr == iAvailableSceneRefNum) && (0 != iAvailableSceneRefNum)) {
-    iVaaFrameSceneChangeIdc = MEDIUM_CHANGED_SCENE;
-  } else {
-    iVaaFrameSceneChangeIdc = SIMILAR_SCENE;
-  }
-
-  WelsLog(pCtx,WELS_LOG_INFO,"iVaaFrameSceneChangeIdc = %d,codingIdx = %d\n",iVaaFrameSceneChangeIdc,pCtx->iCodingIndex);
-
-  SaveBestRefToVaa (sLtrSaved, & (pVaaExt->sVaaStrBestRefCandidate[0]));
-
-  if (0 == iAvailableSceneRefNum) {
-    SaveBestRefToVaa (sSceneLtrSaved, & (pVaaExt->sVaaStrBestRefCandidate[1]));
-  }
-
-  pVaaExt->iNumOfAvailableRef = 1;
-  return static_cast<ESceneChangeIdc> (iVaaFrameSceneChangeIdc);
-}
-
-int32_t CWelsPreProcess::GetRefCandidateLtrIndex (int32_t iRefIdx) {
-  const int32_t iTargetDid = m_pEncCtx->pSvcParam->iSpatialLayerNum - 1;
-  SVAAFrameInfoExt* pVaaExt			= static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
-  SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[iRefIdx]);
-  int32_t iLtrRefIdx = m_pSpatialPic[iTargetDid][BestRefCandidateParam->iSrcListIdx]->iLongTermPicNum;
-  return iLtrRefIdx;
-}
-void  CWelsPreProcess::Padding (uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iStrideY, int32_t iStrideUV,
-                                int32_t iActualWidth, int32_t iPaddingWidth, int32_t iActualHeight, int32_t iPaddingHeight) {
-  int32_t i;
-
-  if (iPaddingHeight > iActualHeight) {
-    for (i = iActualHeight; i < iPaddingHeight; i++) {
-      memset (pSrcY + i * iStrideY, 0, iActualWidth);
-
-      if (! (i & 1)) {
-        memset (pSrcU + i / 2 * iStrideUV, 0x80, iActualWidth / 2);
-        memset (pSrcV + i / 2 * iStrideUV, 0x80, iActualWidth / 2);
-      }
-    }
-  }
-
-  if (iPaddingWidth > iActualWidth) {
-    for (i = 0; i < iPaddingHeight; i++) {
-      memset (pSrcY + i * iStrideY + iActualWidth, 0, iPaddingWidth - iActualWidth);
-      if (! (i & 1)) {
-        memset (pSrcU + i / 2 * iStrideUV + iActualWidth / 2, 0x80, (iPaddingWidth - iActualWidth) / 2);
-        memset (pSrcV + i / 2 * iStrideUV + iActualWidth / 2, 0x80, (iPaddingWidth - iActualWidth) / 2);
-      }
-    }
-  }
-}
-
-
-//TODO: may opti later
-//TODO: not use this func?
-void* WelsMemcpy (void* dst, const void* kpSrc, uint32_t uiSize) {
-  return ::memcpy (dst, kpSrc, uiSize);
-}
-void* WelsMemset (void* p, int32_t val, uint32_t uiSize) {
-  return ::memset (p, val, uiSize);
-}
-
-//i420_to_i420_c
-void  WelsMoveMemory_c (uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV,  int32_t iDstStrideY, int32_t iDstStrideUV,
-                        uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iSrcStrideY, int32_t iSrcStrideUV, int32_t iWidth,
-                        int32_t iHeight) {
-  int32_t   iWidth2 = iWidth >> 1;
-  int32_t   iHeight2 = iHeight >> 1;
-  int32_t   j;
-
-  for (j = iHeight; j; j--) {
-    WelsMemcpy (pDstY, pSrcY, iWidth);
-    pDstY += iDstStrideY;
-    pSrcY += iSrcStrideY;
-  }
-
-  for (j = iHeight2; j; j--) {
-    WelsMemcpy (pDstU, pSrcU, iWidth2);
-    WelsMemcpy (pDstV, pSrcV, iWidth2);
-    pDstU += iDstStrideUV;
-    pDstV += iDstStrideUV;
-    pSrcU += iSrcStrideUV;
-    pSrcV += iSrcStrideUV;
-  }
-}
-
-void  CWelsPreProcess::WelsMoveMemoryWrapper (SWelsSvcCodingParam* pSvcParam, SPicture* pDstPic,
-    const SSourcePicture* kpSrc,
-    const int32_t kiTargetWidth, const int32_t kiTargetHeight) {
-  if (VIDEO_FORMAT_I420 != (kpSrc->iColorFormat & (~VIDEO_FORMAT_VFlip)))
-    return;
-
-  int32_t  iSrcWidth       = kpSrc->iPicWidth;
-  int32_t  iSrcHeight      = kpSrc->iPicHeight;
-
-  if (iSrcHeight > kiTargetHeight) 	iSrcHeight = kiTargetHeight;
-  if (iSrcWidth > kiTargetWidth)		iSrcWidth  = kiTargetWidth;
-
-  // copy from fr26 to fix the odd uiSize failed issue
-  if (iSrcWidth & 0x1)		-- iSrcWidth;
-  if (iSrcHeight & 0x1)		-- iSrcHeight;
-
-  const int32_t kiSrcTopOffsetY = pSvcParam->SUsedPicRect.iTop;
-  const int32_t kiSrcTopOffsetUV = (kiSrcTopOffsetY >> 1);
-  const int32_t kiSrcLeftOffsetY = pSvcParam->SUsedPicRect.iLeft;
-  const int32_t kiSrcLeftOffsetUV = (kiSrcLeftOffsetY >> 1);
-  int32_t  iSrcOffset[3]       = {0, 0, 0};
-  iSrcOffset[0] = kpSrc->iStride[0] * kiSrcTopOffsetY + kiSrcLeftOffsetY;
-  iSrcOffset[1] = kpSrc->iStride[1] * kiSrcTopOffsetUV + kiSrcLeftOffsetUV ;
-  iSrcOffset[2] = kpSrc->iStride[2] * kiSrcTopOffsetUV + kiSrcLeftOffsetUV;
-
-  uint8_t* pSrcY = kpSrc->pData[0] + iSrcOffset[0];
-  uint8_t* pSrcU = kpSrc->pData[1] + iSrcOffset[1];
-  uint8_t* pSrcV = kpSrc->pData[2] + iSrcOffset[2];
-  const int32_t kiSrcStrideY = kpSrc->iStride[0];
-  const int32_t kiSrcStrideUV = kpSrc->iStride[1];
-
-  uint8_t* pDstY = pDstPic->pData[0];
-  uint8_t* pDstU = pDstPic->pData[1];
-  uint8_t* pDstV = pDstPic->pData[2];
-  const int32_t kiDstStrideY = pDstPic->iLineSize[0];
-  const int32_t kiDstStrideUV = pDstPic->iLineSize[1];
-
-#define MAX_WIDTH      (4096)
-#define MAX_HEIGHT     (2304)//MAX_FS_LEVEL51 (36864); MAX_FS_LEVEL51*256/4096 = 2304
-  if (pSrcY) {
-    if (iSrcWidth <= 0 || iSrcWidth > MAX_WIDTH || iSrcHeight <= 0 || iSrcHeight > MAX_HEIGHT)
-      return;
-    if (kiSrcTopOffsetY >= iSrcHeight || kiSrcLeftOffsetY >= iSrcWidth || iSrcWidth > kiSrcStrideY)
-      return;
-  }
-  if (pDstY) {
-    if (kiTargetWidth <= 0 || kiTargetWidth > MAX_WIDTH || kiTargetHeight <= 0 || kiTargetHeight > MAX_HEIGHT)
-      return;
-    if (kiTargetWidth > kiDstStrideY)
-      return;
-  }
-
-  if (pSrcY == NULL || pSrcU == NULL || pSrcV == NULL || pDstY == NULL || pDstU == NULL || pDstV == NULL
-      || (iSrcWidth & 1) || (iSrcHeight & 1)) {
-  } else {
-    //i420_to_i420_c
-    WelsMoveMemory_c (pDstY,  pDstU,  pDstV,  kiDstStrideY, kiDstStrideUV,
-                      pSrcY,  pSrcU,  pSrcV, kiSrcStrideY, kiSrcStrideUV, iSrcWidth, iSrcHeight);
-
-    //in VP Process
-    if (kiTargetWidth > iSrcWidth || kiTargetHeight > iSrcHeight) {
-      Padding (pDstY, pDstU, pDstV, kiDstStrideY, kiDstStrideUV, iSrcWidth, kiTargetWidth, iSrcHeight, kiTargetHeight);
-    }
-  }
-
-}
-
-//*********************************************************************************************************/
-} // namespace WelsSVCEnc
+/*!
+ * \copy
+ *     Copyright (c)  2013, Cisco Systems
+ *     All rights reserved.
+ *
+ *     Redistribution and use in source and binary forms, with or without
+ *     modification, are permitted provided that the following conditions
+ *     are met:
+ *
+ *        * Redistributions of source code must retain the above copyright
+ *          notice, this list of conditions and the following disclaimer.
+ *
+ *        * Redistributions in binary form must reproduce the above copyright
+ *          notice, this list of conditions and the following disclaimer in
+ *          the documentation and/or other materials provided with the
+ *          distribution.
+ *
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *     POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "wels_preprocess.h"
+#include "picture_handle.h"
+#include "encoder_context.h"
+#include "utils.h"
+#include "encoder.h"
+
+namespace WelsSVCEnc {
+
+#define WelsSafeDelete(p) if(p){ delete (p); (p) = NULL; }
+
+
+//***** entry API declaration ************************************************************************//
+
+int32_t WelsInitScaledPic (SWelsSvcCodingParam* pParam,  Scaled_Picture*  pScaledPic, CMemoryAlign* pMemoryAlign);
+bool  JudgeNeedOfScaling (SWelsSvcCodingParam* pParam, Scaled_Picture* pScaledPic);
+void    FreeScaledPic (Scaled_Picture*  pScaledPic, CMemoryAlign* pMemoryAlign);
+
+//******* table definition ***********************************************************************//
+const uint8_t g_kuiRefTemporalIdx[MAX_TEMPORAL_LEVEL][MAX_GOP_SIZE] = {
+  {  0, }, // 0
+  {  0,  0, }, // 1
+  {  0,  0,  0,  1, }, // 2
+  {  0,  0,  0,  2,  0,  1,  1,  2, }, // 3
+};
+
+const int32_t g_kiPixMapSizeInBits = sizeof (uint8_t) * 8;
+
+
+inline  void   WelsUpdateSpatialIdxMap (sWelsEncCtx* pEncCtx, int32_t iPos, SPicture* pPic, int32_t iDidx) {
+  pEncCtx->sSpatialIndexMap[iPos].pSrc = pPic;
+  pEncCtx->sSpatialIndexMap[iPos].iDid = iDidx;
+}
+
+
+/***************************************************************************
+*
+*	implement of the interface
+*
+***************************************************************************/
+
+CWelsPreProcess::CWelsPreProcess (sWelsEncCtx* pEncCtx) {
+  m_pInterfaceVp = NULL;
+  m_bInitDone = false;
+  m_pEncCtx = pEncCtx;
+  memset (&m_sScaledPicture, 0, sizeof (m_sScaledPicture));
+  memset (m_pSpatialPic, 0, sizeof (m_pSpatialPic));
+  memset (m_uiSpatialLayersInTemporal, 0, sizeof (m_uiSpatialLayersInTemporal));
+  memset (m_uiSpatialPicNum, 0, sizeof (m_uiSpatialPicNum));
+}
+
+CWelsPreProcess::~CWelsPreProcess() {
+  FreeScaledPic (&m_sScaledPicture,  m_pEncCtx->pMemAlign);
+  WelsPreprocessDestroy();
+}
+
+int32_t CWelsPreProcess::WelsPreprocessCreate() {
+  if (m_pInterfaceVp == NULL) {
+    CreateVpInterface ((void**) &m_pInterfaceVp, WELSVP_INTERFACE_VERION);
+    if (!m_pInterfaceVp)
+      goto exit;
+  } else
+    goto exit;
+
+  return 0;
+
+exit:
+  WelsPreprocessDestroy();
+  return 1;
+}
+
+int32_t CWelsPreProcess::WelsPreprocessDestroy() {
+  DestroyVpInterface (m_pInterfaceVp, WELSVP_INTERFACE_VERION);
+  m_pInterfaceVp = NULL;
+
+  return 0;
+}
+
+int32_t CWelsPreProcess::WelsPreprocessReset (sWelsEncCtx* pCtx) {
+  int32_t iRet = -1;
+
+  if (pCtx) {
+    FreeScaledPic (&m_sScaledPicture, pCtx->pMemAlign);
+    iRet = InitLastSpatialPictures (pCtx);
+    iRet = WelsInitScaledPic (pCtx->pSvcParam, &m_sScaledPicture, pCtx->pMemAlign);
+  }
+
+  return iRet;
+}
+
+int32_t CWelsPreProcess::AllocSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam) {
+  CMemoryAlign* pMa						= pCtx->pMemAlign;
+  const int32_t kiDlayerCount					= pParam->iSpatialLayerNum;
+  int32_t iDlayerIndex							= 0;
+
+  // spatial pictures
+  iDlayerIndex = 0;
+  do {
+    const int32_t kiPicWidth = pParam->sDependencyLayers[iDlayerIndex].iFrameWidth;
+    const int32_t kiPicHeight   = pParam->sDependencyLayers[iDlayerIndex].iFrameHeight;
+    const uint8_t kuiLayerInTemporal = 2 + WELS_MAX (pParam->sDependencyLayers[iDlayerIndex].iHighestTemporalId, 1);
+    const uint8_t kuiRefNumInTemporal = kuiLayerInTemporal + pParam->iLTRRefNum;
+    uint8_t i = 0;
+
+    do {
+      SPicture* pPic = AllocPicture (pMa, kiPicWidth, kiPicHeight, false, 0);
+      WELS_VERIFY_RETURN_IF (1, (NULL == pPic))
+      m_pSpatialPic[iDlayerIndex][i] = pPic;
+      ++ i;
+    } while (i < kuiRefNumInTemporal);
+
+    if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
+      m_uiSpatialLayersInTemporal[iDlayerIndex] = 1;
+    else
+      m_uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
+
+    m_uiSpatialPicNum[iDlayerIndex] = kuiRefNumInTemporal;
+    ++ iDlayerIndex;
+  } while (iDlayerIndex < kiDlayerCount);
+
+  return 0;
+}
+
+void CWelsPreProcess::FreeSpatialPictures (sWelsEncCtx* pCtx) {
+  CMemoryAlign* pMa	= pCtx->pMemAlign;
+  int32_t j = 0;
+  while (j < pCtx->pSvcParam->iSpatialLayerNum) {
+    uint8_t i = 0;
+    uint8_t uiRefNumInTemporal = m_uiSpatialPicNum[j];
+
+    while (i < uiRefNumInTemporal) {
+      if (NULL != m_pSpatialPic[j][i]) {
+        FreePicture (pMa, &m_pSpatialPic[j][i]);
+      }
+      ++ i;
+    }
+    m_uiSpatialLayersInTemporal[j] = 0;
+    ++ j;
+  }
+}
+
+int32_t CWelsPreProcess::BuildSpatialPicList (sWelsEncCtx* pCtx, const SSourcePicture* kpSrcPic) {
+  SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
+  int32_t iSpatialNum = 0;
+
+  if (!m_bInitDone) {
+    if (WelsPreprocessCreate() != 0)
+      return -1;
+    if (WelsPreprocessReset (pCtx) != 0)
+      return -1;
+
+    m_bInitDone = true;
+  }
+
+  if (m_pInterfaceVp == NULL)
+    return -1;
+
+  pCtx->pVaa->bSceneChangeFlag = pCtx->pVaa->bIdrPeriodFlag = false;
+  if (pSvcParam->uiIntraPeriod)
+    pCtx->pVaa->bIdrPeriodFlag = (1 + pCtx->iFrameIndex >= (int32_t)pSvcParam->uiIntraPeriod) ? true : false;
+
+  iSpatialNum = SingleLayerPreprocess (pCtx, kpSrcPic, &m_sScaledPicture);
+
+  return iSpatialNum;
+}
+
+int32_t CWelsPreProcess::AnalyzeSpatialPic (sWelsEncCtx* pCtx, const int32_t kiDidx) {
+  SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
+  bool bNeededMbAq = (pSvcParam->bEnableAdaptiveQuant && (pCtx->eSliceType == P_SLICE));
+  bool bCalculateBGD = (pCtx->eSliceType == P_SLICE && pSvcParam->bEnableBackgroundDetection);
+
+  int32_t iCurTemporalIdx  = m_uiSpatialLayersInTemporal[kiDidx] - 1;
+
+  int32_t iRefTemporalIdx = (int32_t)g_kuiRefTemporalIdx[pSvcParam->iDecompStages][pCtx->iCodingIndex &
+                            (pSvcParam->uiGopSize - 1)];
+  if (pCtx->uiTemporalId == 0 && pCtx->pLtr[pCtx->uiDependencyId].bReceivedT0LostFlag)
+    iRefTemporalIdx = m_uiSpatialLayersInTemporal[kiDidx] + pCtx->pVaa->uiValidLongTermPicIdx;
+
+  SPicture* pCurPic = m_pSpatialPic[kiDidx][iCurTemporalIdx];
+  bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);
+
+  if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
+    SVAAFrameInfoExt* pVaaExt			= static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
+    SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[0]);
+    SPicture* pRefPic = m_pSpatialPic[0][BestRefCandidateParam->iSrcListIdx];
+
+    VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, false, bCalculateVar, bCalculateBGD);
+
+    if (pSvcParam->bEnableBackgroundDetection) {
+      BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
+    }
+
+    if (bNeededMbAq) {
+      AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
+    }
+  } else {
+    SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx];
+    SPicture* pLastPic = m_pLastSpatialPicture[kiDidx][0];
+    bool bCalculateSQDiff = ((pLastPic->pData[0] == pRefPic->pData[0]) && bNeededMbAq);
+    bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);
+
+    VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, bCalculateSQDiff, bCalculateVar, bCalculateBGD);
+
+    if (pSvcParam->bEnableBackgroundDetection) {
+      BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
+    }
+
+    if (bNeededMbAq) {
+      SPicture* pCurPic = m_pLastSpatialPicture[kiDidx][1];
+      SPicture* pRefPic = m_pLastSpatialPicture[kiDidx][0];
+
+      AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
+    }
+    AnalyzePictureComplexity (pCtx, pCurPic, pRefPic, kiDidx, bCalculateBGD);
+    WelsExchangeSpatialPictures (&m_pLastSpatialPicture[kiDidx][1], &m_pLastSpatialPicture[kiDidx][0]);
+  }
+  return 0;
+}
+
+int32_t CWelsPreProcess::UpdateSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam,
+    const int8_t iCurTid, const int32_t d_idx) {
+  if (pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
+    return 0;
+  if (iCurTid < m_uiSpatialLayersInTemporal[d_idx] - 1 || pParam->iDecompStages == 0) {
+    if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (m_uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) {
+      InitLastSpatialPictures (pCtx);
+      return 1;
+    }
+    if (pParam->bEnableLongTermReference && pCtx->bLongTermRefFlag[d_idx][iCurTid]) {
+      SPicture* tmp	= m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx];
+      m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx] =
+        m_pSpatialPic[d_idx][iCurTid];
+      m_pSpatialPic[d_idx][iCurTid] = m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1];
+      m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1] = tmp;
+      pCtx->bLongTermRefFlag[d_idx][iCurTid] = false;
+    } else {
+      WelsExchangeSpatialPictures (&m_pSpatialPic[d_idx][m_uiSpatialLayersInTemporal[d_idx] - 1],
+                                   &m_pSpatialPic[d_idx][iCurTid]);
+    }
+  }
+  return 0;
+}
+
+
+/*
+*	SingleLayerPreprocess: down sampling if applicable
+*  @return:	exact number of spatial layers need to encoder indeed
+*/
+int32_t CWelsPreProcess::SingleLayerPreprocess (sWelsEncCtx* pCtx, const SSourcePicture* kpSrc,
+    Scaled_Picture* pScaledPicture) {
+  SWelsSvcCodingParam* pSvcParam    = pCtx->pSvcParam;
+  int8_t  iDependencyId             = pSvcParam->iSpatialLayerNum - 1;
+  int32_t iPicturePos               = m_uiSpatialLayersInTemporal[iDependencyId] - 1;
+
+  SPicture* pSrcPic					= NULL;	// large
+  SPicture* pDstPic					= NULL;	// small
+  SDLayerParam* pDlayerParam					= NULL;
+  int32_t iSpatialNum					= 0;
+  int32_t iSrcWidth					= 0;
+  int32_t iSrcHeight					= 0;
+  int32_t iTargetWidth					= 0;
+  int32_t iTargetHeight					= 0;
+  int32_t iTemporalId = 0;
+  int32_t iActualSpatialLayerNum      = 0;
+
+  pDlayerParam = &pSvcParam->sDependencyLayers[iDependencyId];
+  iTargetWidth	  = pDlayerParam->iFrameWidth;
+  iTargetHeight  = pDlayerParam->iFrameHeight;
+  iTemporalId    = pDlayerParam->uiCodingIdx2TemporalId[pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1)];
+  iSrcWidth   = pSvcParam->SUsedPicRect.iWidth;
+  iSrcHeight  = pSvcParam->SUsedPicRect.iHeight;
+
+  pSrcPic = pScaledPicture->pScaledInputPicture ? pScaledPicture->pScaledInputPicture :
+            m_pSpatialPic[iDependencyId][iPicturePos];
+
+  WelsMoveMemoryWrapper (pSvcParam, pSrcPic, kpSrc, iSrcWidth, iSrcHeight);
+
+  if (pSvcParam->bEnableDenoise)
+    BilateralDenoising (pSrcPic, iSrcWidth, iSrcHeight);
+
+  // different scaling in between input picture and dst highest spatial picture.
+  int32_t iShrinkWidth  = iSrcWidth;
+  int32_t iShrinkHeight = iSrcHeight;
+  pDstPic = pSrcPic;
+  if (pScaledPicture->pScaledInputPicture) {
+    // for highest downsampling
+    pDstPic		= m_pSpatialPic[iDependencyId][iPicturePos];
+    iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];
+    iShrinkHeight = pScaledPicture->iScaledHeight[iDependencyId];
+  }
+  DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight);
+
+  if (pSvcParam->bEnableSceneChangeDetect && !pCtx->pVaa->bIdrPeriodFlag) {
+    if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
+      pCtx->pVaa->eSceneChangeIdc = (pCtx->bEncCurFrmAsIdrFlag ? LARGE_CHANGED_SCENE : DetectSceneChangeScreen (pCtx,
+                                     pDstPic));
+      pCtx->pVaa->bSceneChangeFlag = (LARGE_CHANGED_SCENE == pCtx->pVaa->eSceneChangeIdc);
+    } else {
+      if ((!pCtx->bEncCurFrmAsIdrFlag) && ! (pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1))) {
+        SPicture* pRefPic = pCtx->pLtr[iDependencyId].bReceivedT0LostFlag ?
+                            m_pSpatialPic[iDependencyId][m_uiSpatialLayersInTemporal[iDependencyId] +
+                                pCtx->pVaa->uiValidLongTermPicIdx] : m_pLastSpatialPicture[iDependencyId][0];
+
+        pCtx->pVaa->bSceneChangeFlag = DetectSceneChange (pDstPic, pRefPic);
+      }
+    }
+  }
+
+  for (int32_t i = 0; i < pSvcParam->iSpatialLayerNum; i++) {
+    if (pSvcParam->sDependencyLayers[i].uiCodingIdx2TemporalId[pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1)]
+        != INVALID_TEMPORAL_ID) {
+      ++ iActualSpatialLayerNum;
+    }
+  }
+
+  if (iTemporalId != INVALID_TEMPORAL_ID) {
+    WelsUpdateSpatialIdxMap (pCtx, iActualSpatialLayerNum - 1, pDstPic, iDependencyId);
+    ++ iSpatialNum;
+    -- iActualSpatialLayerNum;
+  }
+
+  m_pLastSpatialPicture[iDependencyId][1]	= m_pSpatialPic[iDependencyId][iPicturePos];
+  -- iDependencyId;
+
+  // generate other spacial layer
+  // pSrc is
+  //	-- padded input pic, if downsample should be applied to generate highest layer, [if] block above
+  //	-- highest layer, if no downsampling, [else] block above
+  if (pSvcParam->iSpatialLayerNum > 1) {
+    while (iDependencyId >= 0) {
+      pDlayerParam			= &pSvcParam->sDependencyLayers[iDependencyId];
+      iTargetWidth	= pDlayerParam->iFrameWidth;
+      iTargetHeight	= pDlayerParam->iFrameHeight;
+      iTemporalId = pDlayerParam->uiCodingIdx2TemporalId[pCtx->iCodingIndex & (pSvcParam->uiGopSize - 1)];
+      iPicturePos		= m_uiSpatialLayersInTemporal[iDependencyId] - 1;
+
+      // NOT work for CGS, FIXME
+      // spatial layer is able to encode indeed
+      if ((iTemporalId != INVALID_TEMPORAL_ID)) {
+        // down sampling performed
+
+        pDstPic	= m_pSpatialPic[iDependencyId][iPicturePos];	// small
+        iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];
+        iShrinkHeight = pScaledPicture->iScaledHeight[iDependencyId];
+        DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight);
+
+        WelsUpdateSpatialIdxMap (pCtx, iActualSpatialLayerNum - 1, pDstPic, iDependencyId);
+
+        -- iActualSpatialLayerNum;
+        ++ iSpatialNum;
+
+        m_pLastSpatialPicture[iDependencyId][1]	= m_pSpatialPic[iDependencyId][iPicturePos];
+      }
+      -- iDependencyId;
+    }
+  }
+
+  return iSpatialNum;
+}
+
+
+/*!
+ * \brief	Whether input picture need be scaled?
+ */
+bool JudgeNeedOfScaling (SWelsSvcCodingParam* pParam, Scaled_Picture* pScaledPicture) {
+  const int32_t kiInputPicWidth	= pParam->SUsedPicRect.iWidth;
+  const int32_t kiInputPicHeight = pParam->SUsedPicRect.iHeight;
+  const int32_t kiDstPicWidth		= pParam->sDependencyLayers[pParam->iSpatialLayerNum - 1].iActualWidth;
+  const int32_t kiDstPicHeight	= pParam->sDependencyLayers[pParam->iSpatialLayerNum - 1].iActualHeight;
+  bool bNeedDownsampling = true;
+
+  int32_t iSpatialIdx = pParam->iSpatialLayerNum - 1;
+
+  if (kiDstPicWidth >= kiInputPicWidth && kiDstPicHeight >= kiInputPicHeight) {
+    iSpatialIdx --;  // highest D layer do not need downsampling
+    bNeedDownsampling = false;
+  }
+
+  for (; iSpatialIdx >= 0; iSpatialIdx --) {
+    SDLayerParam* pCurLayer = &pParam->sDependencyLayers[iSpatialIdx];
+    int32_t iCurDstWidth			= pCurLayer->iActualWidth;
+    int32_t iCurDstHeight			= pCurLayer->iActualHeight;
+    int32_t iInputWidthXDstHeight	= kiInputPicWidth * iCurDstHeight;
+    int32_t iInputHeightXDstWidth	= kiInputPicHeight * iCurDstWidth;
+
+    if (iInputWidthXDstHeight > iInputHeightXDstWidth) {
+      pScaledPicture->iScaledWidth[iSpatialIdx] = iCurDstWidth;
+      pScaledPicture->iScaledHeight[iSpatialIdx] = iInputHeightXDstWidth / kiInputPicWidth;
+    } else {
+      pScaledPicture->iScaledWidth[iSpatialIdx] = iInputWidthXDstHeight / kiInputPicHeight;
+      pScaledPicture->iScaledHeight[iSpatialIdx] = iCurDstHeight;
+    }
+  }
+
+  return bNeedDownsampling;
+}
+
+int32_t  WelsInitScaledPic (SWelsSvcCodingParam* pParam,  Scaled_Picture*  pScaledPicture, CMemoryAlign* pMemoryAlign) {
+  bool bInputPicNeedScaling = JudgeNeedOfScaling (pParam, pScaledPicture);
+  if (bInputPicNeedScaling) {
+    pScaledPicture->pScaledInputPicture = AllocPicture (pMemoryAlign, pParam->SUsedPicRect.iWidth,
+                                          pParam->SUsedPicRect.iHeight, false, 0);
+    if (pScaledPicture->pScaledInputPicture == NULL)
+      return -1;
+  }
+  return 0;
+}
+
+void  FreeScaledPic (Scaled_Picture*  pScaledPicture, CMemoryAlign* pMemoryAlign) {
+  if (pScaledPicture->pScaledInputPicture) {
+    FreePicture (pMemoryAlign, &pScaledPicture->pScaledInputPicture);
+    pScaledPicture->pScaledInputPicture = NULL;
+  }
+}
+
+int32_t CWelsPreProcess::InitLastSpatialPictures (sWelsEncCtx* pCtx) {
+  SWelsSvcCodingParam* pParam	= pCtx->pSvcParam;
+  const int32_t kiDlayerCount			= pParam->iSpatialLayerNum;
+  int32_t iDlayerIndex					= 0;
+
+  for (; iDlayerIndex < kiDlayerCount; iDlayerIndex++) {
+    const int32_t kiLayerInTemporal = m_uiSpatialLayersInTemporal[iDlayerIndex];
+    m_pLastSpatialPicture[iDlayerIndex][0]	= m_pSpatialPic[iDlayerIndex][kiLayerInTemporal - 2];
+    m_pLastSpatialPicture[iDlayerIndex][1]	= NULL;
+  }
+  for (; iDlayerIndex < MAX_DEPENDENCY_LAYER; iDlayerIndex++) {
+    m_pLastSpatialPicture[iDlayerIndex][0]	= m_pLastSpatialPicture[iDlayerIndex][1] = NULL;
+  }
+
+  return 0;
+}
+//*********************************************************************************************************/
+
+int32_t CWelsPreProcess::ColorspaceConvert (SWelsSvcCodingParam* pSvcParam, SPicture* pDstPic,
+    const SSourcePicture* kpSrc, const int32_t kiWidth, const int32_t kiHeight) {
+  return 1;
+  //not support yet
+}
+
+void CWelsPreProcess::BilateralDenoising (SPicture* pSrc, const int32_t kiWidth, const int32_t kiHeight) {
+  int32_t iMethodIdx = METHOD_DENOISE;
+  SPixMap sSrcPixMap;
+  memset (&sSrcPixMap, 0, sizeof (sSrcPixMap));
+  sSrcPixMap.pPixel[0] = pSrc->pData[0];
+  sSrcPixMap.pPixel[1] = pSrc->pData[1];
+  sSrcPixMap.pPixel[2] = pSrc->pData[2];
+  sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+  sSrcPixMap.sRect.iRectWidth = kiWidth;
+  sSrcPixMap.sRect.iRectHeight = kiHeight;
+  sSrcPixMap.iStride[0] = pSrc->iLineSize[0];
+  sSrcPixMap.iStride[1] = pSrc->iLineSize[1];
+  sSrcPixMap.iStride[2] = pSrc->iLineSize[2];
+  sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
+
+  m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, NULL);
+}
+
+bool CWelsPreProcess::DetectSceneChange (SPicture* pCurPicture, SPicture* pRefPicture) {
+  bool bSceneChangeFlag = false;
+  int32_t iMethodIdx = METHOD_SCENE_CHANGE_DETECTION_VIDEO;
+  SSceneChangeResult sSceneChangeDetectResult = { SIMILAR_SCENE };
+  SPixMap sSrcPixMap;
+  SPixMap sRefPixMap;
+  memset (&sSrcPixMap, 0, sizeof (sSrcPixMap));
+  memset (&sRefPixMap, 0, sizeof (sRefPixMap));
+  sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
+  sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+  sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
+  sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
+  sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
+  sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
+
+
+  sRefPixMap.pPixel[0] = pRefPicture->pData[0];
+  sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+  sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
+  sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
+  sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
+  sRefPixMap.eFormat = VIDEO_FORMAT_I420;
+
+  int32_t iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
+  if (iRet == 0) {
+    m_pInterfaceVp->Get (iMethodIdx, (void*)&sSceneChangeDetectResult);
+    bSceneChangeFlag = (sSceneChangeDetectResult.eSceneChangeIdc == LARGE_CHANGED_SCENE) ? true : false;
+  }
+
+  return bSceneChangeFlag;
+}
+
+int32_t CWelsPreProcess::DownsamplePadding (SPicture* pSrc, SPicture* pDstPic,  int32_t iSrcWidth, int32_t iSrcHeight,
+    int32_t iShrinkWidth, int32_t iShrinkHeight, int32_t iTargetWidth, int32_t iTargetHeight) {
+  int32_t iRet = 0;
+  SPixMap sSrcPixMap;
+  SPixMap sDstPicMap;
+  memset (&sSrcPixMap, 0, sizeof (sSrcPixMap));
+  memset (&sDstPicMap, 0, sizeof (sDstPicMap));
+  sSrcPixMap.pPixel[0]   = pSrc->pData[0];
+  sSrcPixMap.pPixel[1]   = pSrc->pData[1];
+  sSrcPixMap.pPixel[2]   = pSrc->pData[2];
+  sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+  sSrcPixMap.sRect.iRectWidth  = iSrcWidth;
+  sSrcPixMap.sRect.iRectHeight = iSrcHeight;
+  sSrcPixMap.iStride[0]  = pSrc->iLineSize[0];
+  sSrcPixMap.iStride[1]  = pSrc->iLineSize[1];
+  sSrcPixMap.iStride[2]  = pSrc->iLineSize[2];
+  sSrcPixMap.eFormat     = VIDEO_FORMAT_I420;
+
+  if (iSrcWidth != iShrinkWidth || iSrcHeight != iShrinkHeight) {
+    int32_t iMethodIdx = METHOD_DOWNSAMPLE;
+    sDstPicMap.pPixel[0]   = pDstPic->pData[0];
+    sDstPicMap.pPixel[1]   = pDstPic->pData[1];
+    sDstPicMap.pPixel[2]   = pDstPic->pData[2];
+    sDstPicMap.iSizeInBits = g_kiPixMapSizeInBits;
+    sDstPicMap.sRect.iRectWidth  = iShrinkWidth;
+    sDstPicMap.sRect.iRectHeight = iShrinkHeight;
+    sDstPicMap.iStride[0]  = pDstPic->iLineSize[0];
+    sDstPicMap.iStride[1]  = pDstPic->iLineSize[1];
+    sDstPicMap.iStride[2]  = pDstPic->iLineSize[2];
+    sDstPicMap.eFormat     = VIDEO_FORMAT_I420;
+
+    iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sDstPicMap);
+  } else {
+    memcpy (&sDstPicMap, &sSrcPixMap, sizeof (sDstPicMap));	// confirmed_safe_unsafe_usage
+  }
+
+  // get rid of odd line
+  iShrinkWidth -= (iShrinkWidth & 1);
+  iShrinkHeight -= (iShrinkHeight & 1);
+  Padding ((uint8_t*)sDstPicMap.pPixel[0], (uint8_t*)sDstPicMap.pPixel[1], (uint8_t*)sDstPicMap.pPixel[2],
+           sDstPicMap.iStride[0], sDstPicMap.iStride[1],	iShrinkWidth, iTargetWidth, iShrinkHeight, iTargetHeight);
+
+  return iRet;
+}
+
+//*********************************************************************************************************/
+void CWelsPreProcess::VaaCalculation (SVAAFrameInfo* pVaaInfo, SPicture* pCurPicture, SPicture* pRefPicture,
+                                      bool bCalculateSQDiff, bool bCalculateVar, bool bCalculateBGD) {
+  pVaaInfo->sVaaCalcInfo.pCurY = pCurPicture->pData[0];
+  pVaaInfo->sVaaCalcInfo.pRefY = pRefPicture->pData[0];
+  {
+    int32_t iMethodIdx = METHOD_VAA_STATISTICS;
+    SPixMap sCurPixMap;
+    SPixMap sRefPixMap;
+    memset (&sCurPixMap, 0, sizeof (sCurPixMap));
+    memset (&sRefPixMap, 0, sizeof (sRefPixMap));
+    SVAACalcParam calc_param = {0};
+
+    sCurPixMap.pPixel[0] = pCurPicture->pData[0];
+    sCurPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+    sCurPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
+    sCurPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
+    sCurPixMap.iStride[0] = pCurPicture->iLineSize[0];
+    sCurPixMap.eFormat = VIDEO_FORMAT_I420;
+
+    sRefPixMap.pPixel[0] = pRefPicture->pData[0];
+    sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+    sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
+    sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
+    sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
+    sRefPixMap.eFormat = VIDEO_FORMAT_I420;
+
+    calc_param.iCalcVar	= bCalculateVar;
+    calc_param.iCalcBgd	= bCalculateBGD;
+    calc_param.iCalcSsd	= bCalculateSQDiff;
+    calc_param.pCalcResult = &pVaaInfo->sVaaCalcInfo;
+
+    m_pInterfaceVp->Set (iMethodIdx, &calc_param);
+    m_pInterfaceVp->Process (iMethodIdx, &sCurPixMap, &sRefPixMap);
+  }
+}
+
+void CWelsPreProcess::BackgroundDetection (SVAAFrameInfo* pVaaInfo, SPicture* pCurPicture, SPicture* pRefPicture,
+    bool bDetectFlag) {
+  if (bDetectFlag) {
+    pVaaInfo->iPicWidth     = pCurPicture->iWidthInPixel;
+    pVaaInfo->iPicHeight    = pCurPicture->iHeightInPixel;
+
+    pVaaInfo->iPicStride	= pCurPicture->iLineSize[0];
+    pVaaInfo->iPicStrideUV	= pCurPicture->iLineSize[1];
+    pVaaInfo->pCurY			= pCurPicture->pData[0];
+    pVaaInfo->pRefY			= pRefPicture->pData[0];
+    pVaaInfo->pCurU			= pCurPicture->pData[1];
+    pVaaInfo->pRefU			= pRefPicture->pData[1];
+    pVaaInfo->pCurV			= pCurPicture->pData[2];
+    pVaaInfo->pRefV			= pRefPicture->pData[2];
+
+    int32_t iMethodIdx = METHOD_BACKGROUND_DETECTION;
+    SPixMap sSrcPixMap;
+    SPixMap sRefPixMap;
+    memset (&sSrcPixMap, 0, sizeof (sSrcPixMap));
+    memset (&sRefPixMap, 0, sizeof (sRefPixMap));
+    SBGDInterface BGDParam = {0};
+
+    sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
+    sSrcPixMap.pPixel[1] = pCurPicture->pData[1];
+    sSrcPixMap.pPixel[2] = pCurPicture->pData[2];
+    sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+    sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
+    sSrcPixMap.iStride[1] = pCurPicture->iLineSize[1];
+    sSrcPixMap.iStride[2] = pCurPicture->iLineSize[2];
+    sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
+    sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
+    sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
+
+    sRefPixMap.pPixel[0] = pRefPicture->pData[0];
+    sRefPixMap.pPixel[1] = pRefPicture->pData[1];
+    sRefPixMap.pPixel[2] = pRefPicture->pData[2];
+    sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+    sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
+    sRefPixMap.iStride[1] = pRefPicture->iLineSize[1];
+    sRefPixMap.iStride[2] = pRefPicture->iLineSize[2];
+    sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
+    sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
+    sRefPixMap.eFormat = VIDEO_FORMAT_I420;
+
+    BGDParam.pBackgroundMbFlag = pVaaInfo->pVaaBackgroundMbFlag;
+    BGDParam.pCalcRes = & (pVaaInfo->sVaaCalcInfo);
+    m_pInterfaceVp->Set (iMethodIdx, (void*)&BGDParam);
+    m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
+  } else {
+    int32_t	iPicWidthInMb	= (pCurPicture->iWidthInPixel + 15) >> 4;
+    int32_t	iPicHeightInMb = (pCurPicture->iHeightInPixel + 15) >> 4;
+    memset (pVaaInfo->pVaaBackgroundMbFlag, 0, iPicWidthInMb * iPicHeightInMb);
+  }
+}
+
+void CWelsPreProcess::AdaptiveQuantCalculation (SVAAFrameInfo* pVaaInfo, SPicture* pCurPicture, SPicture* pRefPicture) {
+  pVaaInfo->sAdaptiveQuantParam.pCalcResult = & (pVaaInfo->sVaaCalcInfo);
+  pVaaInfo->sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp = 0;
+
+  {
+    int32_t iMethodIdx = METHOD_ADAPTIVE_QUANT;
+    SPixMap pSrc;
+    SPixMap pRef;
+    memset (&pSrc, 0, sizeof (pSrc));
+    memset (&pRef, 0, sizeof (pRef));
+    int32_t iRet = 0;
+
+    pSrc.pPixel[0] = pCurPicture->pData[0];
+    pSrc.iSizeInBits = g_kiPixMapSizeInBits;
+    pSrc.iStride[0] = pCurPicture->iLineSize[0];
+    pSrc.sRect.iRectWidth = pCurPicture->iWidthInPixel;
+    pSrc.sRect.iRectHeight = pCurPicture->iHeightInPixel;
+    pSrc.eFormat = VIDEO_FORMAT_I420;
+
+    pRef.pPixel[0] = pRefPicture->pData[0];
+    pRef.iSizeInBits = g_kiPixMapSizeInBits;
+    pRef.iStride[0] = pRefPicture->iLineSize[0];
+    pRef.sRect.iRectWidth = pRefPicture->iWidthInPixel;
+    pRef.sRect.iRectHeight = pRefPicture->iHeightInPixel;
+    pRef.eFormat = VIDEO_FORMAT_I420;
+
+    iRet = m_pInterfaceVp->Set (iMethodIdx, (void*) & (pVaaInfo->sAdaptiveQuantParam));
+    iRet = m_pInterfaceVp->Process (iMethodIdx, &pSrc, &pRef);
+    if (iRet == 0)
+      m_pInterfaceVp->Get (iMethodIdx, (void*) & (pVaaInfo->sAdaptiveQuantParam));
+  }
+}
+
+void CWelsPreProcess::SetRefMbType (sWelsEncCtx* pCtx, uint32_t** pRefMbTypeArray, int32_t iRefPicType) {
+  const uint8_t uiTid	    = pCtx->uiTemporalId;
+  const uint8_t uiDid       = pCtx->uiDependencyId;
+  SRefList* pRefPicLlist    = pCtx->ppRefPicListExt[uiDid];
+  SLTRState* pLtr	    = &pCtx->pLtr[uiDid];
+  uint8_t i							= 0;
+
+  if (pCtx->pSvcParam->bEnableLongTermReference && pLtr->bReceivedT0LostFlag && uiTid == 0) {
+    for (i = 0; i < pRefPicLlist->uiLongRefCount; i++) {
+      SPicture* pRef = pRefPicLlist->pLongRefList[i];
+      if (pRef != NULL && pRef->uiRecieveConfirmed == 1/*RECIEVE_SUCCESS*/) {
+        *pRefMbTypeArray = pRef->uiRefMbType;
+        break;
+      }
+    }
+  } else {
+    for (i = 0; i < pRefPicLlist->uiShortRefCount; i++) {
+      SPicture* pRef = pRefPicLlist->pShortRefList[i];
+      if (pRef != NULL && pRef->bUsedAsRef && pRef->iFramePoc >= 0 && pRef->uiTemporalId <= uiTid) {
+        *pRefMbTypeArray = pRef->uiRefMbType;
+        break;
+      }
+    }
+  }
+}
+
+
+void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,
+    const int32_t kiDependencyId, const bool bCalculateBGD) {
+  SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
+  int32_t iComplexityAnalysisMode = 0;
+
+  if (pSvcParam->iRCMode == RC_OFF_MODE)
+    return;
+  if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
+    SVAAFrameInfoExt* pVaaExt		= static_cast<SVAAFrameInfoExt*> (pCtx->pVaa);
+    SComplexityAnalysisScreenParam* sComplexityAnalysisParam	= &pVaaExt->sComplexityScreenParam;
+    SWelsSvcRc* pWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
+
+    if (pCtx->eSliceType == P_SLICE)
+      iComplexityAnalysisMode = GOM_SAD;
+    else if (pCtx->eSliceType == I_SLICE)
+      iComplexityAnalysisMode = GOM_VAR;
+    else
+      return;
+
+    memset (pWelsSvcRc->pGomForegroundBlockNum, 0, pWelsSvcRc->iGomSize * sizeof (int32_t));
+    memset (pWelsSvcRc->pCurrentFrameGomSad, 0, pWelsSvcRc->iGomSize * sizeof (int32_t));
+
+    sComplexityAnalysisParam->iFrameComplexity = 0;
+    sComplexityAnalysisParam->pGomComplexity = pWelsSvcRc->pCurrentFrameGomSad;
+    sComplexityAnalysisParam->iGomNumInFrame = pWelsSvcRc->iGomSize;
+    sComplexityAnalysisParam->iIdrFlag = (pCtx->eSliceType == I_SLICE);
+    sComplexityAnalysisParam->iMbRowInGom = GOM_H_SCC;
+    sComplexityAnalysisParam->sScrollResult.bScrollDetectFlag = false;
+    sComplexityAnalysisParam->sScrollResult.iScrollMvX = 0;
+    sComplexityAnalysisParam->sScrollResult.iScrollMvY = 0;
+
+    const int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS_SCREEN;
+    SPixMap sSrcPixMap;
+    SPixMap sRefPixMap;
+    memset (&sSrcPixMap, 0, sizeof (SPixMap));
+    memset (&sRefPixMap, 0, sizeof (SPixMap));
+    int32_t iRet = 0;
+
+    sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
+    sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+    sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
+    sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
+    sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
+    sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
+
+    if (pRefPicture != NULL) {
+      sRefPixMap.pPixel[0] = pRefPicture->pData[0];
+      sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+      sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
+      sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
+      sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
+      sRefPixMap.eFormat = VIDEO_FORMAT_I420;
+    }
+
+    iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam);
+    iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
+    if (iRet == 0)
+      m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam);
+
+  } else {
+    SVAAFrameInfo* pVaaInfo	 = pCtx->pVaa;
+    SComplexityAnalysisParam* sComplexityAnalysisParam = & (pVaaInfo->sComplexityAnalysisParam);
+    SWelsSvcRc* SWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
+
+    if (pSvcParam->iRCMode == RC_QUALITY_MODE && pCtx->eSliceType == P_SLICE) {
+      iComplexityAnalysisMode = FRAME_SAD;
+    } else if (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == P_SLICE) {
+      iComplexityAnalysisMode = GOM_SAD;
+    } else if (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE) {
+      iComplexityAnalysisMode = GOM_VAR;
+    } else {
+      return;
+    }
+    sComplexityAnalysisParam->iComplexityAnalysisMode = iComplexityAnalysisMode;
+    sComplexityAnalysisParam->pCalcResult = & (pVaaInfo->sVaaCalcInfo);
+    sComplexityAnalysisParam->pBackgroundMbFlag = pVaaInfo->pVaaBackgroundMbFlag;
+    SetRefMbType (pCtx, & (sComplexityAnalysisParam->uiRefMbType), pRefPicture->iPictureType);
+    sComplexityAnalysisParam->iCalcBgd = bCalculateBGD;
+    sComplexityAnalysisParam->iFrameComplexity = 0;
+
+    memset (SWelsSvcRc->pGomForegroundBlockNum, 0, SWelsSvcRc->iGomSize * sizeof (int32_t));
+    if (iComplexityAnalysisMode != FRAME_SAD)
+      memset (SWelsSvcRc->pCurrentFrameGomSad, 0, SWelsSvcRc->iGomSize * sizeof (int32_t));
+
+    sComplexityAnalysisParam->pGomComplexity = SWelsSvcRc->pCurrentFrameGomSad;
+    sComplexityAnalysisParam->pGomForegroundBlockNum = SWelsSvcRc->pGomForegroundBlockNum;
+    sComplexityAnalysisParam->iMbNumInGom = SWelsSvcRc->iNumberMbGom;
+
+    {
+      int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS;
+      SPixMap sSrcPixMap;
+      SPixMap sRefPixMap;
+      memset (&sSrcPixMap, 0, sizeof (SPixMap));
+      memset (&sRefPixMap, 0, sizeof (SPixMap));
+      int32_t iRet = 0;
+
+      sSrcPixMap.pPixel[0] = pCurPicture->pData[0];
+      sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+      sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0];
+      sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel;
+      sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
+      sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
+
+      sRefPixMap.pPixel[0] = pRefPicture->pData[0];
+      sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
+      sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
+      sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
+      sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
+      sRefPixMap.eFormat = VIDEO_FORMAT_I420;
+
+      iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam);
+      iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
+      if (iRet == 0)
+        m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam);
+    }
+  }
+}
+
+
+void CWelsPreProcess::InitPixMap (const SPicture* pPicture, SPixMap* pPixMap) {
+  pPixMap->pPixel[0] = pPicture->pData[0];
+  pPixMap->pPixel[1] = pPicture->pData[1];
+  pPixMap->pPixel[2] = pPicture->pData[2];
+  pPixMap->iSizeInBits = sizeof (uint8_t);
+  pPixMap->iStride[0] = pPicture->iLineSize[0];
+  pPixMap->iStride[1] = pPicture->iLineSize[1];
+  pPixMap->sRect.iRectWidth = pPicture->iWidthInPixel;
+  pPixMap->sRect.iRectHeight = pPicture->iHeightInPixel;
+
+  pPixMap->eFormat = VIDEO_FORMAT_I420;
+}
+void CWelsPreProcess::GetAvailableRefList (SPicture** pSrcPicList, uint8_t iCurTid, const int32_t iClosestLtrFrameNum,
+    SRefInfoParam* pAvailableRefList, int32_t& iAvailableRefNum, int32_t& iAvailableSceneRefNum) {
+  SWelsSvcCodingParam*		pSvcParam = m_pEncCtx->pSvcParam;
+  const int32_t iSourcePicNum = pSvcParam->iNumRefFrame;
+  if (0 >= iSourcePicNum) {
+    iAvailableRefNum = 0;
+    iAvailableSceneRefNum = 0;
+    return ;
+  }
+  const bool bCurFrameMarkedAsSceneLtr = m_pEncCtx->bCurFrameMarkedAsSceneLtr;
+  SPicture* pRefPic = NULL;
+  uint8_t uiRefTid = 0;
+  bool bRefRealLtr = false;
+
+  iAvailableRefNum = 1; //zero is left for the closest frame
+  iAvailableSceneRefNum = 0;
+
+  //the saving order will be depend on pSrcPicList
+  //TODO: use a frame_idx to find the closer ref in time distance, and correctly sort the ref list
+  for (int32_t i = iSourcePicNum - 1; i >= 0; --i) {
+    pRefPic = pSrcPicList[i];
+    if (NULL == pRefPic || !pRefPic->bUsedAsRef || !pRefPic->bIsLongRef || (bCurFrameMarkedAsSceneLtr
+        && (!pRefPic->bIsSceneLTR))) {
+      continue;
+    }
+    uiRefTid = pRefPic->uiTemporalId;
+    bRefRealLtr = pRefPic->bIsSceneLTR;
+
+    if (bRefRealLtr || (0 == iCurTid && 0 == uiRefTid) || (uiRefTid < iCurTid)) {
+      int32_t idx = (pRefPic->iLongTermPicNum == iClosestLtrFrameNum) ? (0) : (iAvailableRefNum++);
+      pAvailableRefList[idx].pRefPicture = pRefPic;
+      pAvailableRefList[idx].iSrcListIdx = i + 1; //in SrcList, the idx 0 is reserved for CurPic
+      iAvailableSceneRefNum += bRefRealLtr;
+    }
+  }
+
+  if (pAvailableRefList[0].pRefPicture == NULL) {
+    for (int32_t i = 1; i < iAvailableRefNum ; ++i) {
+      pAvailableRefList[i - 1].pRefPicture = pAvailableRefList[i].pRefPicture;
+      pAvailableRefList[i - 1].iSrcListIdx = pAvailableRefList[i].iSrcListIdx;
+    }
+
+    pAvailableRefList[iAvailableRefNum - 1].pRefPicture = NULL;
+    pAvailableRefList[iAvailableRefNum - 1].iSrcListIdx = 0;
+    --iAvailableRefNum;
+  }
+}
+
+
+void CWelsPreProcess::InitRefJudgement (SRefJudgement* pRefJudgement) {
+  pRefJudgement->iMinFrameComplexity = INT_MAX;
+  pRefJudgement->iMinFrameComplexity08 = INT_MAX;
+  pRefJudgement->iMinFrameComplexity11 = INT_MAX;
+
+  pRefJudgement->iMinFrameNumGap = INT_MAX;
+  pRefJudgement->iMinFrameQp = INT_MAX;
+}
+bool CWelsPreProcess::JudgeBestRef (SPicture* pRefPic, const SRefJudgement& sRefJudgement,
+                                    const int32_t iFrameComplexity, const bool bIsClosestLtrFrame) {
+  return (bIsClosestLtrFrame ? (iFrameComplexity < sRefJudgement.iMinFrameComplexity11) :
+          ((iFrameComplexity < sRefJudgement.iMinFrameComplexity08) || ((iFrameComplexity <= sRefJudgement.iMinFrameComplexity11)
+              && (pRefPic->iFrameAverageQp < sRefJudgement.iMinFrameQp))));
+}
+
+void CWelsPreProcess::SaveBestRefToJudgement (const int32_t iRefPictureAvQP, const int32_t iComplexity,
+    SRefJudgement* pRefJudgement) {
+  pRefJudgement->iMinFrameQp = iRefPictureAvQP;
+  pRefJudgement->iMinFrameComplexity =  iComplexity;
+  pRefJudgement->iMinFrameComplexity08 = static_cast<int32_t> (iComplexity * 0.8);
+  pRefJudgement->iMinFrameComplexity11 = static_cast<int32_t> (iComplexity * 1.1);
+}
+void CWelsPreProcess::SaveBestRefToLocal (SRefInfoParam* pRefPicInfo, const SSceneChangeResult& sSceneChangeResult,
+    SRefInfoParam* pRefSaved) {
+  pRefSaved->iSrcListIdx = pRefPicInfo->iSrcListIdx;
+  pRefSaved->bSceneLtrFlag = pRefPicInfo->bSceneLtrFlag;
+}
+
+void CWelsPreProcess::SaveBestRefToVaa (SRefInfoParam& sRefSaved, SRefInfoParam* pVaaBestRef) {
+  (*pVaaBestRef) = sRefSaved;
+}
+
+ESceneChangeIdc CWelsPreProcess::DetectSceneChangeScreen (sWelsEncCtx* pCtx, SPicture* pCurPicture) {
+#define STATIC_SCENE_MOTION_RATIO 0.01f
+  SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
+  SVAAFrameInfoExt* pVaaExt			= static_cast<SVAAFrameInfoExt*> (pCtx->pVaa);
+  if (NULL == pCtx || NULL == pVaaExt || NULL == pCurPicture) {
+    return LARGE_CHANGED_SCENE;
+  }
+
+  const int32_t iTargetDid = pSvcParam->iSpatialLayerNum - 1;
+  if (0 != iTargetDid) {
+    return LARGE_CHANGED_SCENE;
+  }
+
+  ESceneChangeIdc iVaaFrameSceneChangeIdc = LARGE_CHANGED_SCENE;
+  SPicture** pSrcPicList = &m_pSpatialPic[iTargetDid][1];
+  if (NULL == pSrcPicList) {
+    return LARGE_CHANGED_SCENE;
+  }
+
+  SRefInfoParam sAvailableRefList[MAX_REF_PIC_COUNT] = { { 0 } };
+  int32_t iAvailableRefNum = 0;
+  int32_t iAvailableSceneRefNum = 0;
+
+  int32_t iSceneChangeMethodIdx = METHOD_SCENE_CHANGE_DETECTION_SCREEN;
+  SSceneChangeResult sSceneChangeResult = {SIMILAR_SCENE, 0, 0, NULL};
+
+  SPixMap sSrcMap = { { 0 } };
+  SPixMap sRefMap = { { 0 } };
+  SRefJudgement sLtrJudgement;
+  SRefJudgement sSceneLtrJudgement;
+  SRefInfoParam sLtrSaved = {0};
+  SRefInfoParam sSceneLtrSaved = {0};
+
+  int32_t iNumOfLargeChange = 0, iNumOfMediumChangeToLtr = 0;
+
+  bool bBestRefIsLtr = false, bIsClosestLtrFrame = false;
+  int32_t ret = 1, iScdIdx = 0;
+
+  SPicture* pRefPic = NULL;
+  SRefInfoParam* pRefPicInfo = NULL;
+  uint8_t*  pCurBlockStaticPointer = NULL;
+  uint8_t*  pBestStrBlockStaticPointer = NULL;
+  uint8_t*  pBestLtrBlockStaticPointer = NULL;
+
+  const int32_t iNegligibleMotionBlocks = (static_cast<int32_t> ((pCurPicture->iWidthInPixel >> 3) *
+                                          (pCurPicture->iHeightInPixel >> 3) * STATIC_SCENE_MOTION_RATIO));
+  const uint8_t iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[m_pEncCtx->sSpatialIndexMap[0].iDid],
+                          m_pEncCtx->iCodingIndex, pSvcParam->uiGopSize);
+  const int32_t iClosestLtrFrameNum = pCtx->pLtr[iTargetDid].iLastLtrIdx[iCurTid];//TBD
+  GetAvailableRefList (pSrcPicList, iCurTid, iClosestLtrFrameNum, &sAvailableRefList[0], iAvailableRefNum,
+                       iAvailableSceneRefNum);
+  //after this build, pAvailableRefList[idx].iSrcListIdx is the idx of the ref in h->spatial_pic
+  if (0 == iAvailableRefNum) {
+    WelsLog (pCtx, WELS_LOG_ERROR, "SceneChangeDetect() iAvailableRefNum=0 but not I.\n");
+    return LARGE_CHANGED_SCENE;
+  }
+
+  InitPixMap (pCurPicture, &sSrcMap);
+  InitRefJudgement (&sLtrJudgement);
+  InitRefJudgement (&sSceneLtrJudgement);
+
+  for (iScdIdx = 0; iScdIdx < iAvailableRefNum; iScdIdx ++) {
+    pCurBlockStaticPointer = pVaaExt->pVaaBlockStaticIdc[iScdIdx];
+    sSceneChangeResult.eSceneChangeIdc = SIMILAR_SCENE;
+    sSceneChangeResult.pStaticBlockIdc = pCurBlockStaticPointer;//
+
+    pRefPicInfo = & (sAvailableRefList[iScdIdx]);
+    assert (NULL != pRefPicInfo);
+    pRefPic = pRefPicInfo->pRefPicture;
+    InitPixMap (pRefPic, &sRefMap);
+
+    bIsClosestLtrFrame = (pRefPic->iLongTermPicNum == iClosestLtrFrameNum);
+
+    //TBD scrolling detection
+    m_pInterfaceVp->Set (iSceneChangeMethodIdx, (void*) (&sSceneChangeResult));
+    ret = m_pInterfaceVp->Process (iSceneChangeMethodIdx, &sSrcMap, &sRefMap);
+
+    if (ret == 0) {
+      m_pInterfaceVp->Get (iSceneChangeMethodIdx, (void*)&sSceneChangeResult);
+
+      const int32_t iFrameComplexity = sSceneChangeResult.iFrameComplexity;
+      const int32_t iSceneDetectIdc = sSceneChangeResult.eSceneChangeIdc;
+      const int32_t iMotionBlockNum = sSceneChangeResult.iMotionBlockNum;
+
+      const bool bCurRefIsLtr = pRefPic->bIsSceneLTR;
+      const int32_t iRefPicAvQP = pRefPic->iFrameAverageQp;
+
+      //for scene change detection
+      iNumOfLargeChange += (static_cast<int32_t> (LARGE_CHANGED_SCENE == iSceneDetectIdc));
+      iNumOfMediumChangeToLtr += (static_cast<int32_t> ((bCurRefIsLtr) && (iSceneDetectIdc != SIMILAR_SCENE)));
+
+      //for reference selection
+      //this judge can only be saved when iAvailableRefNum==1, which is very limit
+      //when LTR is OFF, it can still judge from all available STR
+      if (JudgeBestRef (pRefPic, sLtrJudgement, iFrameComplexity, bIsClosestLtrFrame)) {
+        SaveBestRefToJudgement (iRefPicAvQP, iFrameComplexity, &sLtrJudgement);
+        SaveBestRefToLocal (pRefPicInfo, sSceneChangeResult, &sLtrSaved);
+        bBestRefIsLtr = bCurRefIsLtr;
+        pBestStrBlockStaticPointer = sSceneChangeResult.pStaticBlockIdc;
+      }
+      if (bCurRefIsLtr && JudgeBestRef (pRefPic, sSceneLtrJudgement, iFrameComplexity, bIsClosestLtrFrame)) {
+        SaveBestRefToJudgement (iRefPicAvQP, iFrameComplexity, &sSceneLtrJudgement);
+        SaveBestRefToLocal (pRefPicInfo, sSceneChangeResult, &sSceneLtrSaved);
+        pBestLtrBlockStaticPointer = sSceneChangeResult.pStaticBlockIdc;
+      }
+
+      if (iMotionBlockNum <= iNegligibleMotionBlocks) {
+        break;
+      }
+    }
+  }
+
+  if (iNumOfLargeChange == iAvailableRefNum) {
+    iVaaFrameSceneChangeIdc = LARGE_CHANGED_SCENE;
+  } else if ((iNumOfMediumChangeToLtr == iAvailableSceneRefNum) && (0 != iAvailableSceneRefNum)) {
+    iVaaFrameSceneChangeIdc = MEDIUM_CHANGED_SCENE;
+  } else {
+    iVaaFrameSceneChangeIdc = SIMILAR_SCENE;
+  }
+
+  WelsLog (pCtx, WELS_LOG_INFO, "iVaaFrameSceneChangeIdc = %d,codingIdx = %d\n", iVaaFrameSceneChangeIdc,
+           pCtx->iCodingIndex);
+
+  SaveBestRefToVaa (sLtrSaved, & (pVaaExt->sVaaStrBestRefCandidate[0]));
+
+  if (0 == iAvailableSceneRefNum) {
+    SaveBestRefToVaa (sSceneLtrSaved, & (pVaaExt->sVaaStrBestRefCandidate[1]));
+  }
+
+  pVaaExt->iNumOfAvailableRef = 1;
+  return static_cast<ESceneChangeIdc> (iVaaFrameSceneChangeIdc);
+}
+
+int32_t CWelsPreProcess::GetRefCandidateLtrIndex (int32_t iRefIdx) {
+  const int32_t iTargetDid = m_pEncCtx->pSvcParam->iSpatialLayerNum - 1;
+  SVAAFrameInfoExt* pVaaExt			= static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
+  SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[iRefIdx]);
+  int32_t iLtrRefIdx = m_pSpatialPic[iTargetDid][BestRefCandidateParam->iSrcListIdx]->iLongTermPicNum;
+  return iLtrRefIdx;
+}
+void  CWelsPreProcess::Padding (uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iStrideY, int32_t iStrideUV,
+                                int32_t iActualWidth, int32_t iPaddingWidth, int32_t iActualHeight, int32_t iPaddingHeight) {
+  int32_t i;
+
+  if (iPaddingHeight > iActualHeight) {
+    for (i = iActualHeight; i < iPaddingHeight; i++) {
+      memset (pSrcY + i * iStrideY, 0, iActualWidth);
+
+      if (! (i & 1)) {
+        memset (pSrcU + i / 2 * iStrideUV, 0x80, iActualWidth / 2);
+        memset (pSrcV + i / 2 * iStrideUV, 0x80, iActualWidth / 2);
+      }
+    }
+  }
+
+  if (iPaddingWidth > iActualWidth) {
+    for (i = 0; i < iPaddingHeight; i++) {
+      memset (pSrcY + i * iStrideY + iActualWidth, 0, iPaddingWidth - iActualWidth);
+      if (! (i & 1)) {
+        memset (pSrcU + i / 2 * iStrideUV + iActualWidth / 2, 0x80, (iPaddingWidth - iActualWidth) / 2);
+        memset (pSrcV + i / 2 * iStrideUV + iActualWidth / 2, 0x80, (iPaddingWidth - iActualWidth) / 2);
+      }
+    }
+  }
+}
+
+
+//TODO: may opti later
+//TODO: not use this func?
+void* WelsMemcpy (void* dst, const void* kpSrc, uint32_t uiSize) {
+  return ::memcpy (dst, kpSrc, uiSize);
+}
+void* WelsMemset (void* p, int32_t val, uint32_t uiSize) {
+  return ::memset (p, val, uiSize);
+}
+
+//i420_to_i420_c
+void  WelsMoveMemory_c (uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV,  int32_t iDstStrideY, int32_t iDstStrideUV,
+                        uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iSrcStrideY, int32_t iSrcStrideUV, int32_t iWidth,
+                        int32_t iHeight) {
+  int32_t   iWidth2 = iWidth >> 1;
+  int32_t   iHeight2 = iHeight >> 1;
+  int32_t   j;
+
+  for (j = iHeight; j; j--) {
+    WelsMemcpy (pDstY, pSrcY, iWidth);
+    pDstY += iDstStrideY;
+    pSrcY += iSrcStrideY;
+  }
+
+  for (j = iHeight2; j; j--) {
+    WelsMemcpy (pDstU, pSrcU, iWidth2);
+    WelsMemcpy (pDstV, pSrcV, iWidth2);
+    pDstU += iDstStrideUV;
+    pDstV += iDstStrideUV;
+    pSrcU += iSrcStrideUV;
+    pSrcV += iSrcStrideUV;
+  }
+}
+
+void  CWelsPreProcess::WelsMoveMemoryWrapper (SWelsSvcCodingParam* pSvcParam, SPicture* pDstPic,
+    const SSourcePicture* kpSrc,
+    const int32_t kiTargetWidth, const int32_t kiTargetHeight) {
+  if (VIDEO_FORMAT_I420 != (kpSrc->iColorFormat & (~VIDEO_FORMAT_VFlip)))
+    return;
+
+  int32_t  iSrcWidth       = kpSrc->iPicWidth;
+  int32_t  iSrcHeight      = kpSrc->iPicHeight;
+
+  if (iSrcHeight > kiTargetHeight) 	iSrcHeight = kiTargetHeight;
+  if (iSrcWidth > kiTargetWidth)		iSrcWidth  = kiTargetWidth;
+
+  // copy from fr26 to fix the odd uiSize failed issue
+  if (iSrcWidth & 0x1)		-- iSrcWidth;
+  if (iSrcHeight & 0x1)		-- iSrcHeight;
+
+  const int32_t kiSrcTopOffsetY = pSvcParam->SUsedPicRect.iTop;
+  const int32_t kiSrcTopOffsetUV = (kiSrcTopOffsetY >> 1);
+  const int32_t kiSrcLeftOffsetY = pSvcParam->SUsedPicRect.iLeft;
+  const int32_t kiSrcLeftOffsetUV = (kiSrcLeftOffsetY >> 1);
+  int32_t  iSrcOffset[3]       = {0, 0, 0};
+  iSrcOffset[0] = kpSrc->iStride[0] * kiSrcTopOffsetY + kiSrcLeftOffsetY;
+  iSrcOffset[1] = kpSrc->iStride[1] * kiSrcTopOffsetUV + kiSrcLeftOffsetUV ;
+  iSrcOffset[2] = kpSrc->iStride[2] * kiSrcTopOffsetUV + kiSrcLeftOffsetUV;
+
+  uint8_t* pSrcY = kpSrc->pData[0] + iSrcOffset[0];
+  uint8_t* pSrcU = kpSrc->pData[1] + iSrcOffset[1];
+  uint8_t* pSrcV = kpSrc->pData[2] + iSrcOffset[2];
+  const int32_t kiSrcStrideY = kpSrc->iStride[0];
+  const int32_t kiSrcStrideUV = kpSrc->iStride[1];
+
+  uint8_t* pDstY = pDstPic->pData[0];
+  uint8_t* pDstU = pDstPic->pData[1];
+  uint8_t* pDstV = pDstPic->pData[2];
+  const int32_t kiDstStrideY = pDstPic->iLineSize[0];
+  const int32_t kiDstStrideUV = pDstPic->iLineSize[1];
+
+#define MAX_WIDTH      (4096)
+#define MAX_HEIGHT     (2304)//MAX_FS_LEVEL51 (36864); MAX_FS_LEVEL51*256/4096 = 2304
+  if (pSrcY) {
+    if (iSrcWidth <= 0 || iSrcWidth > MAX_WIDTH || iSrcHeight <= 0 || iSrcHeight > MAX_HEIGHT)
+      return;
+    if (kiSrcTopOffsetY >= iSrcHeight || kiSrcLeftOffsetY >= iSrcWidth || iSrcWidth > kiSrcStrideY)
+      return;
+  }
+  if (pDstY) {
+    if (kiTargetWidth <= 0 || kiTargetWidth > MAX_WIDTH || kiTargetHeight <= 0 || kiTargetHeight > MAX_HEIGHT)
+      return;
+    if (kiTargetWidth > kiDstStrideY)
+      return;
+  }
+
+  if (pSrcY == NULL || pSrcU == NULL || pSrcV == NULL || pDstY == NULL || pDstU == NULL || pDstV == NULL
+      || (iSrcWidth & 1) || (iSrcHeight & 1)) {
+  } else {
+    //i420_to_i420_c
+    WelsMoveMemory_c (pDstY,  pDstU,  pDstV,  kiDstStrideY, kiDstStrideUV,
+                      pSrcY,  pSrcU,  pSrcV, kiSrcStrideY, kiSrcStrideUV, iSrcWidth, iSrcHeight);
+
+    //in VP Process
+    if (kiTargetWidth > iSrcWidth || kiTargetHeight > iSrcHeight) {
+      Padding (pDstY, pDstU, pDstV, kiDstStrideY, kiDstStrideUV, iSrcWidth, kiTargetWidth, iSrcHeight, kiTargetHeight);
+    }
+  }
+
+}
+
+//*********************************************************************************************************/
+} // namespace WelsSVCEnc
--- a/codec/encoder/plus/src/welsCodecTrace.cpp
+++ b/codec/encoder/plus/src/welsCodecTrace.cpp
@@ -133,7 +133,7 @@
 void welsCodecTrace::SetTraceLevel (const int32_t iLevel) {
   if (iLevel >= 0)
     m_iTraceLevel	= iLevel;
-  WelsStderrSetTraceLevel(iLevel);
+  WelsStderrSetTraceLevel (iLevel);
 }
 
 
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -84,7 +84,7 @@
 #ifdef OUTPUT_BIT_STREAM
   SWelsTime tTime;
 
-  WelsGetTimeOfDay(&tTime);
+  WelsGetTimeOfDay (&tTime);
 
   iCurUsed      = WelsSnprintf (strStreamFileName, iBufferLeft, "enc_bs_0x%p_", (void*)this);
   iCurUsedSize  = WelsSnprintf (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
@@ -108,7 +108,7 @@
 
   if (iBufferLeft > 0) {
     iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264",
-                             WelsGetMillisecond(&tTime));
+                             WelsGetMillisecond (&tTime));
     iBufferUsed += iCurUsed;
     iBufferLeft -= iCurUsed;
   }
@@ -115,7 +115,7 @@
 
   if (iBufferLeftSize > 0) {
     iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len",
-                                 WelsGetMillisecond(&tTime));
+                                 WelsGetMillisecond (&tTime));
     iBufferUsedSize += iCurUsedSize;
     iBufferLeftSize -= iCurUsedSize;
   }
@@ -186,7 +186,7 @@
 /* Interfaces override from ISVCEncoder */
 
 int CWelsH264SVCEncoder::GetDefaultParams (SEncParamExt* argv) {
-  SWelsSvcCodingParam::FillDefault(*argv);
+  SWelsSvcCodingParam::FillDefault (*argv);
   return cmResultSuccess;
 }
 
@@ -209,7 +209,7 @@
     return cmInitParaError;
   }
 
-  return InitializeInternal(&sConfig);
+  return InitializeInternal (&sConfig);
 }
 
 int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) {
@@ -228,10 +228,10 @@
     return cmInitParaError;
   }
 
-  return InitializeInternal(&sConfig);
+  return InitializeInternal (&sConfig);
 }
 
-int CWelsH264SVCEncoder::InitializeInternal(SWelsSvcCodingParam* pCfg) {
+int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
   if (NULL == pCfg) {
     WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p.\n",
              pCfg);
@@ -245,7 +245,7 @@
   }
 
 #ifdef REC_FRAME_COUNT
-  SWelsSvcCodingParam &sEncodingParam = *pCfg;
+  SWelsSvcCodingParam& sEncodingParam = *pCfg;
   WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
            m_uiCountFrameNum, m_iCspInternal);
   WelsLog (m_pEncContext, WELS_LOG_INFO,
@@ -346,17 +346,17 @@
   }
   if (pCfg->iUsageType == SCREEN_CONTENT_REAL_TIME) {
     if (pCfg->bEnableLongTermReference) {
-      pCfg->iLTRRefNum = WELS_CLIP3(pCfg->iLTRRefNum,1,LONG_TERM_REF_NUM_SCREEN);
-      pCfg->iNumRefFrame = WELS_MAX(1,WELS_LOG2 (pCfg->uiGopSize)) + pCfg->iLTRRefNum;
+      pCfg->iLTRRefNum = WELS_CLIP3 (pCfg->iLTRRefNum, 1, LONG_TERM_REF_NUM_SCREEN);
+      pCfg->iNumRefFrame = WELS_MAX (1, WELS_LOG2 (pCfg->uiGopSize)) + pCfg->iLTRRefNum;
     } else {
       pCfg->iLTRRefNum = 0;
-      pCfg->iNumRefFrame = WELS_MAX(1, pCfg->uiGopSize>>1);
+      pCfg->iNumRefFrame = WELS_MAX (1, pCfg->uiGopSize >> 1);
     }
-   } else {
-     pCfg->iLTRRefNum = pCfg->bEnableLongTermReference ? WELS_CLIP3(pCfg->iLTRRefNum,1,LONG_TERM_REF_NUM) : 0;
-     pCfg->iNumRefFrame		= ((pCfg->uiGopSize >> 1) > 1) ? ((pCfg->uiGopSize >> 1) + pCfg->iLTRRefNum) :
-                                  (MIN_REF_PIC_COUNT + pCfg->iLTRRefNum);
-     pCfg->iNumRefFrame		= WELS_CLIP3 (pCfg->iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);
+  } else {
+    pCfg->iLTRRefNum = pCfg->bEnableLongTermReference ? WELS_CLIP3 (pCfg->iLTRRefNum, 1, LONG_TERM_REF_NUM) : 0;
+    pCfg->iNumRefFrame		= ((pCfg->uiGopSize >> 1) > 1) ? ((pCfg->uiGopSize >> 1) + pCfg->iLTRRefNum) :
+                            (MIN_REF_PIC_COUNT + pCfg->iLTRRefNum);
+    pCfg->iNumRefFrame		= WELS_CLIP3 (pCfg->iNumRefFrame, MIN_REF_PIC_COUNT, MAX_REFERENCE_PICTURE_COUNT_NUM);
   }
 
   if (pCfg->iLtrMarkPeriod == 0) {
@@ -419,9 +419,9 @@
     return cmInitParaError;
   }
 
-  const int32_t kiEncoderReturn = EncodeFrameInternal(kpSrcPic, pBsInfo);
+  const int32_t kiEncoderReturn = EncodeFrameInternal (kpSrcPic, pBsInfo);
 
-  if(kiEncoderReturn != cmResultSuccess)
+  if (kiEncoderReturn != cmResultSuccess)
     return kiEncoderReturn;
 
 #ifdef REC_FRAME_COUNT
@@ -437,14 +437,13 @@
 }
 
 
-int CWelsH264SVCEncoder::EncodeFrameInternal(const SSourcePicture*  pSrcPic, SFrameBSInfo* pBsInfo) {
+int CWelsH264SVCEncoder::EncodeFrameInternal (const SSourcePicture*  pSrcPic, SFrameBSInfo* pBsInfo) {
   const int32_t kiEncoderReturn = WelsEncoderEncodeExt (m_pEncContext, pBsInfo, pSrcPic);
 
-  if(kiEncoderReturn == ENC_RETURN_MEMALLOCERR) {
+  if (kiEncoderReturn == ENC_RETURN_MEMALLOCERR) {
     WelsUninitEncoderExt (&m_pEncContext);
     return cmMallocMemeError;
-  }
-  else if((kiEncoderReturn != ENC_RETURN_SUCCESS)&&(kiEncoderReturn == ENC_RETURN_CORRECTED)){
+  } else if ((kiEncoderReturn != ENC_RETURN_SUCCESS) && (kiEncoderReturn == ENC_RETURN_CORRECTED)) {
     WelsLog (m_pEncContext, WELS_LOG_ERROR, "unexpected return(%d) from EncodeFrameInternal()!\n", kiEncoderReturn);
     return cmUnkonwReason;
   }
@@ -500,7 +499,7 @@
 }
 
 int CWelsH264SVCEncoder::EncodeParameterSets (SFrameBSInfo* pBsInfo) {
-    return WelsEncoderEncodeParameterSets (m_pEncContext, pBsInfo);
+  return WelsEncoderEncodeParameterSets (m_pEncContext, pBsInfo);
 }
 
 /*
@@ -512,7 +511,7 @@
   ForceIntraFrame (true);
 
   if (EncodeFrameInternal (kpSrcPic, pBsInfo) != videoFrameTypeInvalid) {
-	iReturn = 0;
+    iReturn = 0;
   }
 
 
@@ -692,7 +691,7 @@
              "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_FRAME_RATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %f\n",
              m_uiCountFrameNum, m_iCspInternal, iValue);
 #endif//REC_FRAME_COUNT
-    if (iValue<=0) {
+    if (iValue <= 0) {
       return cmInitParaError;
     }
     //adjust to valid range
@@ -701,80 +700,84 @@
   }
   break;
   case ENCODER_OPTION_BITRATE: {	// Target bit-rate
-    SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption));
+    SBitrateInfo* pInfo = (static_cast<SBitrateInfo*> (pOption));
     int32_t iBitrate = pInfo->iBitrate;
 #ifdef REC_FRAME_COUNT
     WelsLog (m_pEncContext, WELS_LOG_INFO,
-      "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n",
-      m_uiCountFrameNum, m_iCspInternal, iValue);
+             "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n",
+             m_uiCountFrameNum, m_iCspInternal, iValue);
 #endif//REC_FRAME_COUNT
-    if (iBitrate<=0) {
-	  WelsLog (m_pEncContext, WELS_LOG_ERROR,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iBitrate = %d\n",iBitrate);
+    if (iBitrate <= 0) {
+      WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iBitrate = %d\n",
+               iBitrate);
       return cmInitParaError;
     }
     iBitrate	= WELS_CLIP3 (iBitrate, MIN_BIT_RATE, MAX_BIT_RATE);
-	switch(pInfo->iLayer){
-	case SPATIAL_LAYER_ALL:
-	  m_pEncContext->pSvcParam->iTargetBitrate = iBitrate;
-	break;
-	case SPATIAL_LAYER_0:
-	  m_pEncContext->pSvcParam->sSpatialLayers[0].iSpatialBitrate = iBitrate;
-	break;
-	case SPATIAL_LAYER_1:
-	  m_pEncContext->pSvcParam->sSpatialLayers[1].iSpatialBitrate = iBitrate;
-	break;
-	case SPATIAL_LAYER_2:
-	  m_pEncContext->pSvcParam->sSpatialLayers[2].iSpatialBitrate = iBitrate;
-	break;
-	case SPATIAL_LAYER_3:
-	  m_pEncContext->pSvcParam->sSpatialLayers[3].iSpatialBitrate = iBitrate;
-	break;
-	default:
-	   WelsLog (m_pEncContext, WELS_LOG_ERROR,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iLayer = %d\n",pInfo->iLayer);
-	return cmInitParaError;
-	break;
-	}
+    switch (pInfo->iLayer) {
+    case SPATIAL_LAYER_ALL:
+      m_pEncContext->pSvcParam->iTargetBitrate = iBitrate;
+      break;
+    case SPATIAL_LAYER_0:
+      m_pEncContext->pSvcParam->sSpatialLayers[0].iSpatialBitrate = iBitrate;
+      break;
+    case SPATIAL_LAYER_1:
+      m_pEncContext->pSvcParam->sSpatialLayers[1].iSpatialBitrate = iBitrate;
+      break;
+    case SPATIAL_LAYER_2:
+      m_pEncContext->pSvcParam->sSpatialLayers[2].iSpatialBitrate = iBitrate;
+      break;
+    case SPATIAL_LAYER_3:
+      m_pEncContext->pSvcParam->sSpatialLayers[3].iSpatialBitrate = iBitrate;
+      break;
+    default:
+      WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iLayer = %d\n",
+               pInfo->iLayer);
+      return cmInitParaError;
+      break;
+    }
     //adjust to valid range
-    WelsEncoderApplyBitRate (m_pEncContext->pSvcParam,pInfo->iLayer);
+    WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer);
   }
   break;
   case ENCODER_OPTION_MAX_BITRATE: {	// Target bit-rate
-    SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption));
+    SBitrateInfo* pInfo = (static_cast<SBitrateInfo*> (pOption));
     int32_t iBitrate = pInfo->iBitrate;
 
 #ifdef REC_FRAME_COUNT
     WelsLog (m_pEncContext, WELS_LOG_INFO,
-      "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n",
-      m_uiCountFrameNum, m_iCspInternal, iValue);
+             "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n",
+             m_uiCountFrameNum, m_iCspInternal, iValue);
 #endif//REC_FRAME_COUNT
-	if (iBitrate<=0) {
-	  WelsLog (m_pEncContext, WELS_LOG_ERROR,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_MAX_BITRATE,iBitrate = %d\n",iBitrate);
-	   return cmInitParaError;
-	}
-	iBitrate	= WELS_CLIP3 (iBitrate, MIN_BIT_RATE, MAX_BIT_RATE);
-	switch(pInfo->iLayer){
-	case SPATIAL_LAYER_ALL:
-	  m_pEncContext->pSvcParam->iMaxBitrate = iBitrate;
-	break;
-	case SPATIAL_LAYER_0:
-	  m_pEncContext->pSvcParam->sSpatialLayers[0].iMaxSpatialBitrate = iBitrate;
-	break;
-	case SPATIAL_LAYER_1:
-	  m_pEncContext->pSvcParam->sSpatialLayers[1].iMaxSpatialBitrate = iBitrate;
-	break;
-	case SPATIAL_LAYER_2:
-	  m_pEncContext->pSvcParam->sSpatialLayers[2].iMaxSpatialBitrate = iBitrate;
-	break;
-	case SPATIAL_LAYER_3:
-	  m_pEncContext->pSvcParam->sSpatialLayers[3].iMaxSpatialBitrate = iBitrate;
-	break;
-	default:
-	  WelsLog (m_pEncContext, WELS_LOG_ERROR,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_MAX_BITRATE,iLayer = %d\n",pInfo->iLayer);
-			return cmInitParaError;
-	break;
-	}
-	  //adjust to valid range
-	WelsEncoderApplyBitRate (m_pEncContext->pSvcParam,pInfo->iLayer);
+    if (iBitrate <= 0) {
+      WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_MAX_BITRATE,iBitrate = %d\n",
+               iBitrate);
+      return cmInitParaError;
+    }
+    iBitrate	= WELS_CLIP3 (iBitrate, MIN_BIT_RATE, MAX_BIT_RATE);
+    switch (pInfo->iLayer) {
+    case SPATIAL_LAYER_ALL:
+      m_pEncContext->pSvcParam->iMaxBitrate = iBitrate;
+      break;
+    case SPATIAL_LAYER_0:
+      m_pEncContext->pSvcParam->sSpatialLayers[0].iMaxSpatialBitrate = iBitrate;
+      break;
+    case SPATIAL_LAYER_1:
+      m_pEncContext->pSvcParam->sSpatialLayers[1].iMaxSpatialBitrate = iBitrate;
+      break;
+    case SPATIAL_LAYER_2:
+      m_pEncContext->pSvcParam->sSpatialLayers[2].iMaxSpatialBitrate = iBitrate;
+      break;
+    case SPATIAL_LAYER_3:
+      m_pEncContext->pSvcParam->sSpatialLayers[3].iMaxSpatialBitrate = iBitrate;
+      break;
+    default:
+      WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_MAX_BITRATE,iLayer = %d\n",
+               pInfo->iLayer);
+      return cmInitParaError;
+      break;
+    }
+    //adjust to valid range
+    WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer);
   }
   break;
   case ENCODER_OPTION_RC_MODE: {	// 0:quality mode;1:bit-rate mode;2:bitrate limited mode
@@ -838,20 +841,21 @@
     }
   }
   break;
-  case ENCODER_OPTION_DUMP_FILE:{
+  case ENCODER_OPTION_DUMP_FILE: {
 #ifdef ENABLE_FRAME_DUMP
-    if(m_pEncContext->pSvcParam!=NULL){
-      SDumpLayer*pDump = (static_cast<SDumpLayer *>(pOption));
-      WelsStrncpy(m_pEncContext->pSvcParam->sDependencyLayers[pDump->iLayer].sRecFileName, sizeof(m_pEncContext->pSvcParam->sDependencyLayers[pDump->iLayer].sRecFileName),pDump->pFileName);
+    if (m_pEncContext->pSvcParam != NULL) {
+      SDumpLayer* pDump = (static_cast<SDumpLayer*> (pOption));
+      WelsStrncpy (m_pEncContext->pSvcParam->sDependencyLayers[pDump->iLayer].sRecFileName,
+                   sizeof (m_pEncContext->pSvcParam->sDependencyLayers[pDump->iLayer].sRecFileName), pDump->pFileName);
     }
 #endif
   }
   break;
-  case ENCODER_OPTION_TRACE_LEVEL:{
-    if(m_pWelsTrace){
-	  uint32_t level = *((uint32_t*)pOption);
-	  m_pWelsTrace->SetTraceLevel(level);
-	}
+  case ENCODER_OPTION_TRACE_LEVEL: {
+    if (m_pWelsTrace) {
+      uint32_t level = * ((uint32_t*)pOption);
+      m_pWelsTrace->SetTraceLevel (level);
+    }
   }
   break;
   default:
@@ -908,7 +912,7 @@
              "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_SVC_ENCODE_PARAM_BASE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
              m_uiCountFrameNum, m_iCspInternal);
 #endif//REC_FRAME_COUNT
-    m_pEncContext->pSvcParam->GetBaseParams((SEncParamBase*) pOption);
+    m_pEncContext->pSvcParam->GetBaseParams ((SEncParamBase*) pOption);
   }
   break;
 
@@ -927,29 +931,32 @@
              "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
              m_uiCountFrameNum, m_iCspInternal);
 #endif//REC_FRAME_COUNT
-    SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption));
-    if((pInfo->iLayer!=SPATIAL_LAYER_ALL)&&(pInfo->iLayer!=SPATIAL_LAYER_0)&&(pInfo->iLayer!=SPATIAL_LAYER_1)&&(pInfo->iLayer!=SPATIAL_LAYER_2)&&(pInfo->iLayer!=SPATIAL_LAYER_3))
-        return cmInitParaError;
-    if(pInfo->iLayer == SPATIAL_LAYER_ALL){
+    SBitrateInfo* pInfo = (static_cast<SBitrateInfo*> (pOption));
+    if ((pInfo->iLayer != SPATIAL_LAYER_ALL) && (pInfo->iLayer != SPATIAL_LAYER_0) && (pInfo->iLayer != SPATIAL_LAYER_1)
+        && (pInfo->iLayer != SPATIAL_LAYER_2) && (pInfo->iLayer != SPATIAL_LAYER_3))
+      return cmInitParaError;
+    if (pInfo->iLayer == SPATIAL_LAYER_ALL) {
       pInfo->iBitrate = m_pEncContext->pSvcParam->iTargetBitrate;
-    }else{
+    } else {
       pInfo->iBitrate = m_pEncContext->pSvcParam->sSpatialLayers[pInfo->iLayer].iSpatialBitrate;
-	}
+    }
   }
   break;
   case ENCODER_OPTION_MAX_BITRATE: {	// Target bit-rate
 #ifdef REC_FRAME_COUNT
-    WelsLog (m_pEncContext, WELS_LOG_INFO,"CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_MAX_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
-	          m_uiCountFrameNum, m_iCspInternal);
+    WelsLog (m_pEncContext, WELS_LOG_INFO,
+             "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_MAX_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
+             m_uiCountFrameNum, m_iCspInternal);
 #endif//REC_FRAME_COUNT
-    SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption));
-	if((pInfo->iLayer!=SPATIAL_LAYER_ALL)&&(pInfo->iLayer!=SPATIAL_LAYER_0)&&(pInfo->iLayer!=SPATIAL_LAYER_1)&&(pInfo->iLayer!=SPATIAL_LAYER_2)&&(pInfo->iLayer!=SPATIAL_LAYER_3))
-	  return cmInitParaError;
-	if(pInfo->iLayer == SPATIAL_LAYER_ALL){
+    SBitrateInfo* pInfo = (static_cast<SBitrateInfo*> (pOption));
+    if ((pInfo->iLayer != SPATIAL_LAYER_ALL) && (pInfo->iLayer != SPATIAL_LAYER_0) && (pInfo->iLayer != SPATIAL_LAYER_1)
+        && (pInfo->iLayer != SPATIAL_LAYER_2) && (pInfo->iLayer != SPATIAL_LAYER_3))
+      return cmInitParaError;
+    if (pInfo->iLayer == SPATIAL_LAYER_ALL) {
       pInfo->iBitrate = m_pEncContext->pSvcParam->iMaxBitrate;
-	}else{
-	  pInfo->iBitrate = m_pEncContext->pSvcParam->sSpatialLayers[pInfo->iLayer].iMaxSpatialBitrate;
-	}
+    } else {
+      pInfo->iBitrate = m_pEncContext->pSvcParam->sSpatialLayers[pInfo->iLayer].iMaxSpatialBitrate;
+    }
   }
   break;
   default:
--- a/codec/processing/interface/IWelsVP.h
+++ b/codec/processing/interface/IWelsVP.h
@@ -138,7 +138,7 @@
 //-----------------------------------------------------------------//
 //  Algorithm parameters define
 //-----------------------------------------------------------------//
-typedef struct{
+typedef struct {
   SRect sMaskRect;
   bool bMaskInfoAvailable;
   int iScrollMvX;
@@ -163,7 +163,7 @@
   ESceneChangeIdc eSceneChangeIdc; // SIMILAR_SCENE, MEDIUM_CHANGED_SCENE, LARGE_CHANGED_SCENE
   int             iMotionBlockNum; // Number of motion blocks
   int             iFrameComplexity; // frame complexity
-  unsigned char * pStaticBlockIdc;  // static block idc
+  unsigned char* pStaticBlockIdc;   // static block idc
 } SSceneChangeResult;
 
 typedef struct {
@@ -216,8 +216,7 @@
   GOM_VAR       = -2
 } EComplexityAnalysisMode;
 
-typedef struct
-{
+typedef struct {
   int iScrollMvX;
   int iScrollMvY;
   bool bScrollDetectFlag; // 0:false ; 1:ltr; 2: scene change
@@ -235,10 +234,9 @@
   SVAACalcResult*  pCalcResult;
 } SComplexityAnalysisParam;
 
-typedef struct
-{
+typedef struct {
   int  iMbRowInGom;
-  int  *pGomComplexity;
+  int*  pGomComplexity;
   int  iGomNumInFrame;
   int  iFrameComplexity;
   int  iIdrFlag;
--- a/codec/processing/src/backgrounddetection/BackgroundDetection.h
+++ b/codec/processing/src/backgrounddetection/BackgroundDetection.h
@@ -84,7 +84,7 @@
   inline void     FreeOUArrayMemory();
   inline int32_t  CalculateAsdChromaEdge (uint8_t* pOriRef, uint8_t* pOriCur, int32_t iStride);
   inline bool   ForegroundDilation23Luma (SBackgroundOU* pBackgroundOU,
-      SBackgroundOU* pOUNeighbours[]); //Foreground_Dilation_2_3_Luma
+                                          SBackgroundOU* pOUNeighbours[]); //Foreground_Dilation_2_3_Luma
   inline bool   ForegroundDilation23Chroma (int8_t iNeighbourForegroundFlags, int32_t iStartSamplePos,
       int32_t iPicStrideUV, vBGDParam* pBgdParam);//Foreground_Dilation_2_3_Chroma
   inline void     ForegroundDilation (SBackgroundOU* pBackgroundOU, SBackgroundOU* pOUNeighbours[], vBGDParam* pBgdParam,
--- a/codec/processing/src/common/WelsFrameWork.cpp
+++ b/codec/processing/src/common/WelsFrameWork.cpp
@@ -267,11 +267,11 @@
     pStrategy = WelsDynamicCast (IStrategy*, new CDenoiser (iCpuFlag));
     break;
   case METHOD_SCROLL_DETECTION:
-	pStrategy = WelsDynamicCast (IStrategy*, new CScrollDetection(iCpuFlag));
-	break;
+    pStrategy = WelsDynamicCast (IStrategy*, new CScrollDetection (iCpuFlag));
+    break;
   case METHOD_SCENE_CHANGE_DETECTION_VIDEO:
   case METHOD_SCENE_CHANGE_DETECTION_SCREEN:
-    pStrategy = BuildSceneChangeDetection(m_eMethod, iCpuFlag);
+    pStrategy = BuildSceneChangeDetection (m_eMethod, iCpuFlag);
     break;
   case METHOD_DOWNSAMPLE:
     pStrategy = WelsDynamicCast (IStrategy*, new CDownsampling (iCpuFlag));
--- a/codec/processing/src/common/common.cpp
+++ b/codec/processing/src/common/common.cpp
@@ -44,8 +44,8 @@
 
   do {
     ST64 (pDst  , kuiT1);
-	ST64 (pDst + 8, kuiT2);
-	pDst += 16;
+    ST64 (pDst + 8, kuiT2);
+    pDst += 16;
   } while (i-- > 0);
 }
 
@@ -58,15 +58,15 @@
   do {
     const uint8_t kuiSrc8	= pRef[iStridex15 - 1];
 #ifdef _MSC_VER
-	const uint64_t kuiV64	= (uint64_t) (0x0101010101010101U * kuiSrc8);
+    const uint64_t kuiV64	= (uint64_t) (0x0101010101010101U * kuiSrc8);
 #else
-	const uint64_t kuiV64	= (uint64_t) (0x0101010101010101LL * kuiSrc8);
+    const uint64_t kuiV64	= (uint64_t) (0x0101010101010101LL * kuiSrc8);
 #endif
-	ST64 (&pPred[iPredStridex15], kuiV64);
-	ST64 (&pPred[iPredStridex15 + 8], kuiV64);
+    ST64 (&pPred[iPredStridex15], kuiV64);
+    ST64 (&pPred[iPredStridex15 + 8], kuiV64);
 
-	iStridex15 -= kiStride;
-	iPredStridex15 -= iPredStride;
+    iStridex15 -= kiStride;
+    iPredStridex15 -= iPredStride;
   } while (i-- > 0);
 }
 
--- a/codec/processing/src/common/common.h
+++ b/codec/processing/src/common/common.h
@@ -53,12 +53,12 @@
 
 typedef SadFunc*   SadFuncPtr;
 
-typedef int32_t (Sad16x16Func) ( uint8_t * pSrcY, int32_t iSrcStrideY, uint8_t *pRefY, int32_t iRefStrideY );
-typedef Sad16x16Func      *PSad16x16Func;
+typedef int32_t (Sad16x16Func) (uint8_t* pSrcY, int32_t iSrcStrideY, uint8_t* pRefY, int32_t iRefStrideY);
+typedef Sad16x16Func*      PSad16x16Func;
 
-typedef void (GetIntraPred)(uint8_t *pPred, uint8_t *pRef, const int32_t kiStride);
+typedef void (GetIntraPred) (uint8_t* pPred, uint8_t* pRef, const int32_t kiStride);
 
-typedef GetIntraPred  *GetIntraPredPtr;
+typedef GetIntraPred*  GetIntraPredPtr;
 
 GetIntraPred     WelsI16x16LumaPredV_c;
 GetIntraPred     WelsI16x16LumaPredH_c;
--- a/codec/processing/src/complexityanalysis/ComplexityAnalysis.h
+++ b/codec/processing/src/complexityanalysis/ComplexityAnalysis.h
@@ -82,21 +82,20 @@
 
 //for screen content
 
-class CComplexityAnalysisScreen : public IStrategy
-{
-public:
-  CComplexityAnalysisScreen(int32_t cpu_flag);
+class CComplexityAnalysisScreen : public IStrategy {
+ public:
+  CComplexityAnalysisScreen (int32_t cpu_flag);
   ~CComplexityAnalysisScreen();
 
-  EResult Process(int32_t nType, SPixMap *src, SPixMap *ref);
-  EResult Set(int32_t nType, void *pParam);
-  EResult Get(int32_t nType, void *pParam);
+  EResult Process (int32_t nType, SPixMap* src, SPixMap* ref);
+  EResult Set (int32_t nType, void* pParam);
+  EResult Get (int32_t nType, void* pParam);
 
-private:
-  void GomComplexityAnalysisIntra( SPixMap *pSrc );
-  void GomComplexityAnalysisInter( SPixMap *pSrc, SPixMap *pRef,bool bScrollFlag);
+ private:
+  void GomComplexityAnalysisIntra (SPixMap* pSrc);
+  void GomComplexityAnalysisInter (SPixMap* pSrc, SPixMap* pRef, bool bScrollFlag);
 
-private:
+ private:
   PSad16x16Func m_pSadFunc;
   GetIntraPredPtr m_pIntraFunc[2];
   SComplexityAnalysisScreenParam m_ComplexityAnalysisParam;
--- a/codec/processing/src/downsample/downsample.h
+++ b/codec/processing/src/downsample/downsample.h
@@ -112,8 +112,9 @@
 
 GeneralDownsampleFunc   GeneralBilinearAccurateDownsamplerWrap_neon;
 
-void GeneralBilinearAccurateDownsampler_neon( uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, const int32_t kiDstHeight,
-									   uint8_t* pSrc, const int32_t kiSrcStride, const uint32_t kuiScaleX, const uint32_t kuiScaleY);
+void GeneralBilinearAccurateDownsampler_neon (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth,
+    const int32_t kiDstHeight,
+    uint8_t* pSrc, const int32_t kiSrcStride, const uint32_t kuiScaleX, const uint32_t kuiScaleY);
 
 WELSVP_EXTERN_C_END
 #endif
--- a/codec/processing/src/downsample/downsamplefuncs.cpp
+++ b/codec/processing/src/downsample/downsamplefuncs.cpp
@@ -230,13 +230,15 @@
 #endif //X86_ASM
 
 #ifdef HAVE_NEON
-void GeneralBilinearAccurateDownsamplerWrap_neon(uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, const int32_t kiDstHeight,
-                        uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight) {
+void GeneralBilinearAccurateDownsamplerWrap_neon (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth,
+    const int32_t kiDstHeight,
+    uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight) {
   const int32_t kiScaleBit = 15;
   const uint32_t kuiScale = (1 << kiScaleBit);
-  uint32_t uiScalex = (uint32_t)((float)kiSrcWidth / (float)kiDstWidth * kuiScale);
-  uint32_t uiScaley = (uint32_t)((float)kiSrcHeight / (float)kiDstHeight * kuiScale);
-  GeneralBilinearAccurateDownsampler_neon(pDst, kiDstStride, kiDstWidth, kiDstHeight, pSrc, kiSrcStride, uiScalex, uiScaley);
+  uint32_t uiScalex = (uint32_t) ((float)kiSrcWidth / (float)kiDstWidth * kuiScale);
+  uint32_t uiScaley = (uint32_t) ((float)kiSrcHeight / (float)kiDstHeight * kuiScale);
+  GeneralBilinearAccurateDownsampler_neon (pDst, kiDstStride, kiDstWidth, kiDstHeight, pSrc, kiSrcStride, uiScalex,
+      uiScaley);
 }
 #endif
 WELSVP_NAMESPACE_END
--- a/codec/processing/src/scenechangedetection/SceneChangeDetection.cpp
+++ b/codec/processing/src/scenechangedetection/SceneChangeDetection.cpp
@@ -35,13 +35,13 @@
 
 WELSVP_NAMESPACE_BEGIN
 
-IStrategy * BuildSceneChangeDetection(EMethods eMethod, int32_t iCpuFlag){
-  switch(eMethod){
+IStrategy* BuildSceneChangeDetection (EMethods eMethod, int32_t iCpuFlag) {
+  switch (eMethod) {
   case METHOD_SCENE_CHANGE_DETECTION_VIDEO:
-    return new CSceneChangeDetection<CSceneChangeDetectorVideo>(eMethod, iCpuFlag);
+    return new CSceneChangeDetection<CSceneChangeDetectorVideo> (eMethod, iCpuFlag);
     break;
   case METHOD_SCENE_CHANGE_DETECTION_SCREEN:
-    return new CSceneChangeDetection<CSceneChangeDetectorScreen>(eMethod, iCpuFlag);
+    return new CSceneChangeDetection<CSceneChangeDetectorScreen> (eMethod, iCpuFlag);
     break;
   default:
     // not support yet
--- a/codec/processing/src/scenechangedetection/SceneChangeDetection.h
+++ b/codec/processing/src/scenechangedetection/SceneChangeDetection.h
@@ -56,16 +56,16 @@
 WELSVP_NAMESPACE_BEGIN
 
 class CSceneChangeDetectorVideo {
-public:
-  CSceneChangeDetectorVideo(SSceneChangeResult & sParam, int32_t iCpuFlag) : m_sParam(sParam) {
+ public:
+  CSceneChangeDetectorVideo (SSceneChangeResult& sParam, int32_t iCpuFlag) : m_sParam (sParam) {
     m_pfSad = WelsSampleSad8x8_c;
 #ifdef X86_ASM
-    if (iCpuFlag & WELS_CPU_SSE2){
+    if (iCpuFlag & WELS_CPU_SSE2) {
       m_pfSad = WelsSampleSad8x8_sse21;
     }
 #endif
 #ifdef HAVE_NEON
-    if (iCpuFlag & WELS_CPU_NEON){
+    if (iCpuFlag & WELS_CPU_NEON) {
       m_pfSad = WelsProcessingSampleSad8x8_neon;
     }
 #endif
@@ -72,24 +72,25 @@
   }
   virtual ~CSceneChangeDetectorVideo() {
   }
-  void operator () (uint8_t* pSrcY, int32_t iSrcStrideY, uint8_t* pRefY, int32_t iRefStrideY, uint8_t *& pStaticBlockIdc) {
-    int32_t iSad = m_pfSad(pSrcY, iSrcStrideY, pRefY, iSrcStrideY);
+  void operator() (uint8_t* pSrcY, int32_t iSrcStrideY, uint8_t* pRefY, int32_t iRefStrideY, uint8_t*& pStaticBlockIdc) {
+    int32_t iSad = m_pfSad (pSrcY, iSrcStrideY, pRefY, iSrcStrideY);
     m_sParam.iMotionBlockNum += iSad > HIGH_MOTION_BLOCK_THRESHOLD;
   }
-protected:
+ protected:
   SadFuncPtr m_pfSad;
-  SSceneChangeResult &m_sParam;
+  SSceneChangeResult& m_sParam;
 };
 
-class CSceneChangeDetectorScreen : public CSceneChangeDetectorVideo{
-public:
-  CSceneChangeDetectorScreen(SSceneChangeResult & sParam, int32_t iCpuFlag) : CSceneChangeDetectorVideo(sParam, iCpuFlag) {
+class CSceneChangeDetectorScreen : public CSceneChangeDetectorVideo {
+ public:
+  CSceneChangeDetectorScreen (SSceneChangeResult& sParam, int32_t iCpuFlag) : CSceneChangeDetectorVideo (sParam,
+        iCpuFlag) {
   }
   virtual ~CSceneChangeDetectorScreen() {
   }
-  void operator() (uint8_t* pSrcY, int32_t iSrcStrideY, uint8_t* pRefY, int32_t iRefStrideY, uint8_t *& pStaticBlockIdc) {
-    int32_t iSad = m_pfSad(pSrcY, iSrcStrideY, pRefY, iSrcStrideY);
-    if( iSad == 0 ){
+  void operator() (uint8_t* pSrcY, int32_t iSrcStrideY, uint8_t* pRefY, int32_t iRefStrideY, uint8_t*& pStaticBlockIdc) {
+    int32_t iSad = m_pfSad (pSrcY, iSrcStrideY, pRefY, iSrcStrideY);
+    if (iSad == 0) {
       *pStaticBlockIdc ++ = COLLOCATED_STATIC;
     } else {
       m_sParam.iFrameComplexity += iSad;
@@ -102,15 +103,15 @@
 template<typename T>
 class CSceneChangeDetection : public IStrategy {
  public:
-  CSceneChangeDetection (EMethods eMethod, int32_t iCpuFlag): m_cDetector(m_sSceneChangeParam, iCpuFlag) {
+  CSceneChangeDetection (EMethods eMethod, int32_t iCpuFlag): m_cDetector (m_sSceneChangeParam, iCpuFlag) {
     m_eMethod   = eMethod;
     WelsMemset (&m_sSceneChangeParam, 0, sizeof (m_sSceneChangeParam));
   }
 
-  ~CSceneChangeDetection(){
+  ~CSceneChangeDetection() {
   }
 
-  EResult Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap){
+  EResult Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
     EResult eReturn = RET_INVALIDPARAM;
     int32_t iWidth                  = pSrcPixMap->sRect.iRectWidth;
     int32_t iHeight                 = pSrcPixMap->sRect.iRectHeight;
@@ -117,13 +118,15 @@
     int32_t iBlock8x8Width      = iWidth  >> 3;
     int32_t iBlock8x8Height	 = iHeight >> 3;
     int32_t iBlock8x8Num       = iBlock8x8Width * iBlock8x8Height;
-    int32_t iSceneChangeThresholdLarge = WelsStaticCast (int32_t, SCENE_CHANGE_MOTION_RATIO_LARGE * iBlock8x8Num + 0.5f + PESN);
-    int32_t iSceneChangeThresholdMedium	= WelsStaticCast(int32_t, SCENE_CHANGE_MOTION_RATIO_MEDIUM * iBlock8x8Num + 0.5f + PESN);
+    int32_t iSceneChangeThresholdLarge = WelsStaticCast (int32_t,
+                                         SCENE_CHANGE_MOTION_RATIO_LARGE * iBlock8x8Num + 0.5f + PESN);
+    int32_t iSceneChangeThresholdMedium	= WelsStaticCast (int32_t,
+                                          SCENE_CHANGE_MOTION_RATIO_MEDIUM * iBlock8x8Num + 0.5f + PESN);
     uint8_t* pRefY = NULL, *pCurY = NULL;
     int32_t iRefStride = 0, iCurStride = 0;
     int32_t iRefRowStride = 0, iCurRowStride = 0;
     uint8_t* pRefTmp = NULL, *pCurTmp = NULL;
-    uint8_t * pStaticBlockIdc = m_sSceneChangeParam.pStaticBlockIdc;
+    uint8_t* pStaticBlockIdc = m_sSceneChangeParam.pStaticBlockIdc;
 
     pRefY = (uint8_t*)pRefPixMap->pPixel[0];
     pCurY = (uint8_t*)pSrcPixMap->pPixel[0];
@@ -143,7 +146,7 @@
       pCurTmp   = pCurY;
 
       for (int32_t i = 0; i < iBlock8x8Width; i++) {
-        m_cDetector(pRefTmp, iRefStride, pCurTmp, iCurStride, pStaticBlockIdc);
+        m_cDetector (pRefTmp, iRefStride, pCurTmp, iCurStride, pStaticBlockIdc);
         pRefTmp += 8;
         pCurTmp += 8;
       }
@@ -154,7 +157,7 @@
 
     if (m_sSceneChangeParam.iMotionBlockNum >= iSceneChangeThresholdLarge) {
       m_sSceneChangeParam.eSceneChangeIdc = LARGE_CHANGED_SCENE;
-    } else if( m_sSceneChangeParam.iMotionBlockNum >= iSceneChangeThresholdMedium ){
+    } else if (m_sSceneChangeParam.iMotionBlockNum >= iSceneChangeThresholdMedium) {
       m_sSceneChangeParam.eSceneChangeIdc = MEDIUM_CHANGED_SCENE;
     }
 
@@ -171,11 +174,11 @@
     return RET_SUCCESS;
   }
 
-  EResult Set(int32_t iType, void * pParam) {
-    if( pParam == NULL ){
+  EResult Set (int32_t iType, void* pParam) {
+    if (pParam == NULL) {
       return RET_INVALIDPARAM;
     }
-    m_sSceneChangeParam = *(SSceneChangeResult*)pParam;
+    m_sSceneChangeParam = * (SSceneChangeResult*)pParam;
     return RET_SUCCESS;
   }
  private:
@@ -183,7 +186,7 @@
   T          m_cDetector;
 };
 
-IStrategy * BuildSceneChangeDetection(EMethods eMethod, int32_t iCpuFlag);
+IStrategy* BuildSceneChangeDetection (EMethods eMethod, int32_t iCpuFlag);
 
 WELSVP_NAMESPACE_END
 
--- a/codec/processing/src/scrolldetection/ScrollDetection.cpp
+++ b/codec/processing/src/scrolldetection/ScrollDetection.cpp
@@ -37,37 +37,38 @@
 
 WELSVP_NAMESPACE_BEGIN
 
-EResult CScrollDetection::Process(int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap){
+EResult CScrollDetection::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
   if (pRefPixMap->pPixel[0] == NULL || pSrcPixMap->pPixel[0] == NULL ||
-    pRefPixMap->sRect.iRectWidth != pSrcPixMap->sRect.iRectWidth || pRefPixMap->sRect.iRectHeight != pSrcPixMap->sRect.iRectHeight){
-  return RET_INVALIDPARAM;
+      pRefPixMap->sRect.iRectWidth != pSrcPixMap->sRect.iRectWidth
+      || pRefPixMap->sRect.iRectHeight != pSrcPixMap->sRect.iRectHeight) {
+    return RET_INVALIDPARAM;
   }
 
   if (!m_sScrollDetectionParam.bMaskInfoAvailable)
-    ScrollDetectionWithoutMask(pSrcPixMap, pRefPixMap);
+    ScrollDetectionWithoutMask (pSrcPixMap, pRefPixMap);
   else
-    ScrollDetectionWithMask(pSrcPixMap, pRefPixMap);
+    ScrollDetectionWithMask (pSrcPixMap, pRefPixMap);
 
   return RET_SUCCESS;
 }
 
-EResult CScrollDetection::Set(int32_t iType, void *pParam){
-  if( pParam == NULL ){
+EResult CScrollDetection::Set (int32_t iType, void* pParam) {
+  if (pParam == NULL) {
     return RET_INVALIDPARAM;
   }
-  m_sScrollDetectionParam = *((SScrollDetectionParam*)pParam);
+  m_sScrollDetectionParam = * ((SScrollDetectionParam*)pParam);
   return RET_SUCCESS;
 }
 
-EResult CScrollDetection::Get(int32_t iType, void *pParam){
-  if( pParam == NULL ){
+EResult CScrollDetection::Get (int32_t iType, void* pParam) {
+  if (pParam == NULL) {
     return RET_INVALIDPARAM;
   }
-  *((SScrollDetectionParam*)pParam) = m_sScrollDetectionParam;
+  * ((SScrollDetectionParam*)pParam) = m_sScrollDetectionParam;
   return RET_SUCCESS;
 }
 
-void CScrollDetection::ScrollDetectionWithMask(SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
+void CScrollDetection::ScrollDetectionWithMask (SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
   int32_t iStartX, iStartY, iWidth, iHeight;
 
   iStartX = m_sScrollDetectionParam.sMaskRect.iRectLeft;
@@ -76,39 +77,39 @@
   iHeight = m_sScrollDetectionParam.sMaskRect.iRectHeight;
 
   iWidth /= 2;
-  iStartX += iWidth/2;
+  iStartX += iWidth / 2;
 
   m_sScrollDetectionParam.iScrollMvX = 0;
   m_sScrollDetectionParam.iScrollMvY = 0;
   m_sScrollDetectionParam.bScrollDetectFlag = false;
 
-  if(iStartX >= 0 && iWidth > MINIMUM_DETECT_WIDTH && iHeight > 2 * CHECK_OFFSET){
-    ScrollDetectionCore(pSrcPixMap, pRefPixMap,iWidth, iHeight, iStartX, iStartY, m_sScrollDetectionParam);
+  if (iStartX >= 0 && iWidth > MINIMUM_DETECT_WIDTH && iHeight > 2 * CHECK_OFFSET) {
+    ScrollDetectionCore (pSrcPixMap, pRefPixMap, iWidth, iHeight, iStartX, iStartY, m_sScrollDetectionParam);
   }
 }
 
-void CScrollDetection::ScrollDetectionWithoutMask(SPixMap* pSrcPixMap, SPixMap* pRefPixMap){
+void CScrollDetection::ScrollDetectionWithoutMask (SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
   int32_t iStartX, iStartY, iWidth, iHeight;
 
-  const int32_t kiPicBorderWidth= pSrcPixMap->sRect.iRectHeight>>4;
-  const int32_t kiRegionWidth = (int) (pSrcPixMap->sRect.iRectWidth-(kiPicBorderWidth<<1))/3;
-  const int32_t kiRegionHeight = (pSrcPixMap->sRect.iRectHeight*7)>>3;
-  const int32_t kiHieghtStride = (int) pSrcPixMap->sRect.iRectHeight*5/24;
+  const int32_t kiPicBorderWidth = pSrcPixMap->sRect.iRectHeight >> 4;
+  const int32_t kiRegionWidth = (int) (pSrcPixMap->sRect.iRectWidth - (kiPicBorderWidth << 1)) / 3;
+  const int32_t kiRegionHeight = (pSrcPixMap->sRect.iRectHeight * 7) >> 3;
+  const int32_t kiHieghtStride = (int) pSrcPixMap->sRect.iRectHeight * 5 / 24;
 
-  for (int32_t i=0; i< REGION_NUMBER;i++){
-    iStartX = kiPicBorderWidth+(i%3)*kiRegionWidth;
-    iStartY = -pSrcPixMap->sRect.iRectHeight*7/48+ (int)(i/3)*(kiHieghtStride);
+  for (int32_t i = 0; i < REGION_NUMBER; i++) {
+    iStartX = kiPicBorderWidth + (i % 3) * kiRegionWidth;
+    iStartY = -pSrcPixMap->sRect.iRectHeight * 7 / 48 + (int) (i / 3) * (kiHieghtStride);
     iWidth = kiRegionWidth;
     iHeight = kiRegionHeight;
 
     iWidth /= 2;
-    iStartX += iWidth/2;
+    iStartX += iWidth / 2;
 
     m_sScrollDetectionParam.iScrollMvX = 0;
     m_sScrollDetectionParam.iScrollMvY = 0;
     m_sScrollDetectionParam.bScrollDetectFlag = false;
 
-    ScrollDetectionCore(pSrcPixMap, pRefPixMap, iWidth, iHeight, iStartX, iStartY, m_sScrollDetectionParam);
+    ScrollDetectionCore (pSrcPixMap, pRefPixMap, iWidth, iHeight, iStartX, iStartY, m_sScrollDetectionParam);
 
     if (m_sScrollDetectionParam.bScrollDetectFlag && m_sScrollDetectionParam.iScrollMvY)
       break;
--- a/codec/processing/src/scrolldetection/ScrollDetection.h
+++ b/codec/processing/src/scrolldetection/ScrollDetection.h
@@ -51,22 +51,22 @@
 WELSVP_EXTERN_C_END
 #endif
 
-class CScrollDetection : public IStrategy{
-public:
-  CScrollDetection(int32_t iCpuFlag){
+class CScrollDetection : public IStrategy {
+ public:
+  CScrollDetection (int32_t iCpuFlag) {
     m_eMethod = METHOD_SCROLL_DETECTION;
     WelsMemset (&m_sScrollDetectionParam, 0, sizeof (m_sScrollDetectionParam));
   };
-  ~CScrollDetection(){
+  ~CScrollDetection() {
   }
-  EResult Process(int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap);
-  EResult Set(int32_t iType, void *pParam);
-  EResult Get(int32_t iType, void *pParam);
+  EResult Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap);
+  EResult Set (int32_t iType, void* pParam);
+  EResult Get (int32_t iType, void* pParam);
 
-private:
-  void ScrollDetectionWithMask(SPixMap* pSrcPixMap, SPixMap* pRefPixMap);
-  void ScrollDetectionWithoutMask(SPixMap* pSrcPixMap, SPixMap* pRefPixMap);
-private:
+ private:
+  void ScrollDetectionWithMask (SPixMap* pSrcPixMap, SPixMap* pRefPixMap);
+  void ScrollDetectionWithoutMask (SPixMap* pSrcPixMap, SPixMap* pRefPixMap);
+ private:
   SScrollDetectionParam m_sScrollDetectionParam;
 };
 
--- a/codec/processing/src/scrolldetection/ScrollDetectionFuncs.cpp
+++ b/codec/processing/src/scrolldetection/ScrollDetectionFuncs.cpp
@@ -35,23 +35,23 @@
 
 WELSVP_NAMESPACE_BEGIN
 
-int32_t CheckLine(uint8_t* pData, int32_t iWidth){
+int32_t CheckLine (uint8_t* pData, int32_t iWidth) {
   int32_t iQualified = 0;
   int32_t iColorMap[8] = {0};
   int32_t iChangedTimes = 0;
   int32_t iColorCounts = 0;
 
-  RECORD_COLOR(pData[0], iColorMap);
+  RECORD_COLOR (pData[0], iColorMap);
 
-  for (int32_t i=1; i<iWidth; i++){
-    RECORD_COLOR(pData[i], iColorMap);
-    iChangedTimes += (pData[i] != pData[i-1]);
+  for (int32_t i = 1; i < iWidth; i++) {
+    RECORD_COLOR (pData[i], iColorMap);
+    iChangedTimes += (pData[i] != pData[i - 1]);
   }
-  for (int32_t i=0; i<8; i++)
-    for (int32_t j=0; j<32; j++)
-      iColorCounts += ((iColorMap[i] >> j)&1);
+  for (int32_t i = 0; i < 8; i++)
+    for (int32_t j = 0; j < 32; j++)
+      iColorCounts += ((iColorMap[i] >> j) & 1);
 
-  switch(iColorCounts){
+  switch (iColorCounts) {
   case 1:
     iQualified = 0;
     break;
@@ -66,8 +66,8 @@
   return iQualified;
 }
 
-int32_t SelectTestLine(uint8_t* pY, int32_t iWidth, int32_t iHeight, int32_t iPicHeight,
-                       int32_t iStride, int32_t iOffsetX, int32_t iOffsetY){
+int32_t SelectTestLine (uint8_t* pY, int32_t iWidth, int32_t iHeight, int32_t iPicHeight,
+                        int32_t iStride, int32_t iOffsetX, int32_t iOffsetY) {
   const int32_t kiHalfHeight	= iHeight >> 1;
   const int32_t kiMidPos		= iOffsetY + kiHalfHeight;
   int32_t TestPos			= kiMidPos;
@@ -74,16 +74,16 @@
   int32_t iOffsetAbs;
   uint8_t* pTmp;
 
-  for (iOffsetAbs = 0; iOffsetAbs < kiHalfHeight; iOffsetAbs++){
+  for (iOffsetAbs = 0; iOffsetAbs < kiHalfHeight; iOffsetAbs++) {
     TestPos = kiMidPos + iOffsetAbs;
-    if (TestPos < iPicHeight){
+    if (TestPos < iPicHeight) {
       pTmp = pY + TestPos * iStride + iOffsetX;
-      if (CheckLine(pTmp, iWidth)) break;
+      if (CheckLine (pTmp, iWidth)) break;
     }
     TestPos = kiMidPos - iOffsetAbs;
-    if(TestPos >=0){
+    if (TestPos >= 0) {
       pTmp = pY + TestPos * iStride + iOffsetX;
-      if (CheckLine(pTmp, iWidth)) break;
+      if (CheckLine (pTmp, iWidth)) break;
     }
   }
   if (iOffsetAbs == kiHalfHeight)
@@ -95,27 +95,26 @@
  * compare pixel line between previous and current one
  * return: 0 for totally equal, otherwise 1
  */
-int32_t CompareLine(uint8_t *pYSrc, uint8_t *pYRef, const int32_t kiWidth)
-{
+int32_t CompareLine (uint8_t* pYSrc, uint8_t* pYRef, const int32_t kiWidth) {
   int32_t iCmp = 1;
 
-  if ( *((int32_t*)pYSrc) != *((int32_t*)pYRef)) return 1;
-  if ( *((int32_t*)(pYSrc + 4)) != *((int32_t*)(pYRef + 4))) return 1;
-  if ( *((int32_t*)(pYSrc + 8)) != *((int32_t*)(pYRef + 8))) return 1;
-  if ( kiWidth > 12 )
-    iCmp = WelsMemcmp(pYSrc+12, pYRef+12, kiWidth-12);
+  if (* ((int32_t*)pYSrc) != * ((int32_t*)pYRef)) return 1;
+  if (* ((int32_t*) (pYSrc + 4)) != * ((int32_t*) (pYRef + 4))) return 1;
+  if (* ((int32_t*) (pYSrc + 8)) != * ((int32_t*) (pYRef + 8))) return 1;
+  if (kiWidth > 12)
+    iCmp = WelsMemcmp (pYSrc + 12, pYRef + 12, kiWidth - 12);
   return iCmp;
 }
 
-void ScrollDetectionCore(SPixMap* pSrcPixMap, SPixMap* pRefPixMap, int32_t iWidth, int32_t iHeight,
-                         int32_t iOffsetX, int32_t iOffsetY, SScrollDetectionParam &sScrollDetectionParam){
+void ScrollDetectionCore (SPixMap* pSrcPixMap, SPixMap* pRefPixMap, int32_t iWidth, int32_t iHeight,
+                          int32_t iOffsetX, int32_t iOffsetY, SScrollDetectionParam& sScrollDetectionParam) {
   bool bScrollDetected = 0;
   uint8_t* pYLine;
   uint8_t* pYTmp;
   int32_t iTestPos, iSearchPos = 0, iOffsetAbs, iMaxAbs;
   int32_t iPicHeight = pRefPixMap->sRect.iRectHeight;
-  int32_t iMinHeight = WELS_MAX(iOffsetY,0);
-  int32_t iMaxHeight = WELS_MIN(iOffsetY + iHeight - 1, iPicHeight-1) ;//offset_y + height - 1;//
+  int32_t iMinHeight = WELS_MAX (iOffsetY, 0);
+  int32_t iMaxHeight = WELS_MIN (iOffsetY + iHeight - 1, iPicHeight - 1) ; //offset_y + height - 1;//
   uint8_t* pYRef, *pYSrc;
   int32_t iYStride;
 
@@ -123,66 +122,65 @@
   pYSrc = (uint8_t*)pSrcPixMap->pPixel[0];
   iYStride = pRefPixMap->iStride[0];
 
-  iTestPos = SelectTestLine(pYSrc, iWidth, iHeight, iPicHeight, iYStride, iOffsetX, iOffsetY);
+  iTestPos = SelectTestLine (pYSrc, iWidth, iHeight, iPicHeight, iYStride, iOffsetX, iOffsetY);
 
-  if (iTestPos == -1){
+  if (iTestPos == -1) {
     sScrollDetectionParam.bScrollDetectFlag = 0;
     return;
   }
   pYLine = pYSrc + iYStride * iTestPos + iOffsetX;
-  iMaxAbs = WELS_MIN(WELS_MAX(iTestPos-iMinHeight-1, iMaxHeight-iTestPos),MAX_SCROLL_MV_Y);
+  iMaxAbs = WELS_MIN (WELS_MAX (iTestPos - iMinHeight - 1, iMaxHeight - iTestPos), MAX_SCROLL_MV_Y);
   iSearchPos = iTestPos;
-  for (iOffsetAbs = 0; iOffsetAbs <= iMaxAbs; iOffsetAbs++){
+  for (iOffsetAbs = 0; iOffsetAbs <= iMaxAbs; iOffsetAbs++) {
     iSearchPos = iTestPos + iOffsetAbs;
-    if (iSearchPos <= iMaxHeight){
+    if (iSearchPos <= iMaxHeight) {
       pYTmp = pYRef + iSearchPos * iYStride + iOffsetX;
-      if (!CompareLine(pYLine, pYTmp, iWidth)){
-        uint8_t *pYUpper, *pYLineUpper;
+      if (!CompareLine (pYLine, pYTmp, iWidth)) {
+        uint8_t* pYUpper, *pYLineUpper;
         int32_t iCheckedLines;
-        int32_t iLowOffset = WELS_MIN(iMaxHeight - iSearchPos, CHECK_OFFSET);
+        int32_t iLowOffset = WELS_MIN (iMaxHeight - iSearchPos, CHECK_OFFSET);
         int32_t i;
 
-        iCheckedLines = WELS_MIN(iTestPos - iMinHeight + iLowOffset, 2 * CHECK_OFFSET);
+        iCheckedLines = WELS_MIN (iTestPos - iMinHeight + iLowOffset, 2 * CHECK_OFFSET);
         pYUpper = pYTmp - (iCheckedLines - iLowOffset) * iYStride;
         pYLineUpper = pYLine - (iCheckedLines - iLowOffset) * iYStride;
 
-        for(i = 0; i < iCheckedLines; i ++){
-          if (CompareLine(pYLineUpper, pYUpper, iWidth)){
+        for (i = 0; i < iCheckedLines; i ++) {
+          if (CompareLine (pYLineUpper, pYUpper, iWidth)) {
             break;
           }
           pYUpper += iYStride;
           pYLineUpper += iYStride;
         }
-        if (i == iCheckedLines){
-          bScrollDetected=1;
+        if (i == iCheckedLines) {
+          bScrollDetected = 1;
           break;
         }
       }
     }
 
-    iSearchPos = iTestPos - iOffsetAbs-1;
-    if (iSearchPos >= iMinHeight){
+    iSearchPos = iTestPos - iOffsetAbs - 1;
+    if (iSearchPos >= iMinHeight) {
       pYTmp = pYRef + iSearchPos * iYStride + iOffsetX;
-      if (!CompareLine(pYLine, pYTmp, iWidth))
-      {
-        uint8_t *pYUpper, *pYLineUpper;
+      if (!CompareLine (pYLine, pYTmp, iWidth)) {
+        uint8_t* pYUpper, *pYLineUpper;
         int32_t iCheckedLines;
-        int32_t iUpOffset = WELS_MIN(iSearchPos - iMinHeight, CHECK_OFFSET);
+        int32_t iUpOffset = WELS_MIN (iSearchPos - iMinHeight, CHECK_OFFSET);
         int32_t i;
 
         pYUpper = pYTmp - iUpOffset * iYStride;
         pYLineUpper = pYLine - iUpOffset * iYStride;
-        iCheckedLines = WELS_MIN(iMaxHeight - iTestPos + iUpOffset, 2 * CHECK_OFFSET);
+        iCheckedLines = WELS_MIN (iMaxHeight - iTestPos + iUpOffset, 2 * CHECK_OFFSET);
 
-        for(i = 0; i < iCheckedLines; i ++){
-          if (CompareLine(pYLineUpper,pYUpper, iWidth)){
+        for (i = 0; i < iCheckedLines; i ++) {
+          if (CompareLine (pYLineUpper, pYUpper, iWidth)) {
             break;
           }
           pYUpper += iYStride;
           pYLineUpper += iYStride;
         }
-        if (i == iCheckedLines){
-          bScrollDetected=1;
+        if (i == iCheckedLines) {
+          bScrollDetected = 1;
           break;
         }
       }
@@ -189,10 +187,9 @@
     }
   }
 
-  if (!bScrollDetected){
+  if (!bScrollDetected) {
     sScrollDetectionParam.bScrollDetectFlag = 0;
-  }
-  else{
+  } else {
     sScrollDetectionParam.bScrollDetectFlag = 1;
     sScrollDetectionParam.iScrollMvY = iSearchPos - iTestPos; // pre_pos - cur_pos, change to mv
     sScrollDetectionParam.iScrollMvX = 0;
--- a/codec/processing/src/scrolldetection/ScrollDetectionFuncs.h
+++ b/codec/processing/src/scrolldetection/ScrollDetectionFuncs.h
@@ -51,11 +51,11 @@
   x[_t>>5] |= (1 << (_t&31)); \
 }
 
-int32_t CheckLine(uint8_t* pData, int32_t iWidth);
-int32_t SelectTestLine(uint8_t* pY, int32_t iWidth, int32_t iHeight, int32_t iPicHeight,
-                       int32_t iStride, int32_t iOffsetX, int32_t iOffsetY);
-int32_t CompareLine(uint8_t *pYSrc, uint8_t *pYRef, const int32_t kiWidth);
-void ScrollDetectionCore(SPixMap* pSrcPixMap, SPixMap* pRefPixMap, int32_t iWidth, int32_t iHeight,
-                         int32_t iOffsetX, int32_t iOffsetY, SScrollDetectionParam &sScrollDetectionParam);
+int32_t CheckLine (uint8_t* pData, int32_t iWidth);
+int32_t SelectTestLine (uint8_t* pY, int32_t iWidth, int32_t iHeight, int32_t iPicHeight,
+                        int32_t iStride, int32_t iOffsetX, int32_t iOffsetY);
+int32_t CompareLine (uint8_t* pYSrc, uint8_t* pYRef, const int32_t kiWidth);
+void ScrollDetectionCore (SPixMap* pSrcPixMap, SPixMap* pRefPixMap, int32_t iWidth, int32_t iHeight,
+                          int32_t iOffsetX, int32_t iOffsetY, SScrollDetectionParam& sScrollDetectionParam);
 
 WELSVP_NAMESPACE_END
\ No newline at end of file
--- a/codec/processing/src/vaacalc/vaacalcfuncs.cpp
+++ b/codec/processing/src/vaacalc/vaacalcfuncs.cpp
@@ -34,7 +34,8 @@
 
 WELSVP_NAMESPACE_BEGIN
 
-void VAACalcSadSsd_c (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight, int32_t iPicStride,
+void VAACalcSadSsd_c (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight,
+                      int32_t iPicStride,
                       int32_t* pFrameSad, int32_t* pSad8x8, int32_t* pSum16x16, int32_t* psqsum16x16, int32_t* psqdiff16x16) {
   const uint8_t* tmp_ref = pRefData;
   const uint8_t* tmp_cur = pCurData;
@@ -145,7 +146,8 @@
     tmp_cur += step;
   }
 }
-void VAACalcSadVar_c (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight, int32_t iPicStride,
+void VAACalcSadVar_c (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight,
+                      int32_t iPicStride,
                       int32_t* pFrameSad, int32_t* pSad8x8, int32_t* pSum16x16, int32_t* psqsum16x16) {
   const uint8_t* tmp_ref = pRefData;
   const uint8_t* tmp_cur = pCurData;
@@ -249,7 +251,8 @@
 }
 
 
-void VAACalcSad_c (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight, int32_t iPicStride,
+void VAACalcSad_c (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight,
+                   int32_t iPicStride,
                    int32_t* pFrameSad, int32_t* pSad8x8) {
   const uint8_t* tmp_ref = pRefData;
   const uint8_t* tmp_cur = pCurData;
@@ -480,7 +483,8 @@
   }
 }
 
-void VAACalcSadBgd_c (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight, int32_t iPicStride,
+void VAACalcSadBgd_c (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight,
+                      int32_t iPicStride,
                       int32_t* pFrameSad, int32_t* pSad8x8, int32_t* pSd8x8, uint8_t* pMad8x8) {
   const uint8_t* tmp_ref = pRefData;
   const uint8_t* tmp_cur = pCurData;
--- a/codec/processing/src/vaacalc/vaacalculation.cpp
+++ b/codec/processing/src/vaacalc/vaacalculation.cpp
@@ -72,7 +72,7 @@
     sVaaFuncs.pfVAACalcSadSsd		= VAACalcSadSsd_neon;
     sVaaFuncs.pfVAACalcSadSsdBgd = VAACalcSadSsdBgd_neon;
     sVaaFuncs.pfVAACalcSadVar		= VAACalcSadVar_neon;
-    }
+  }
 #endif//HAVE_NEON
 }
 
--- a/codec/processing/src/vaacalc/vaacalculation.h
+++ b/codec/processing/src/vaacalc/vaacalculation.h
@@ -49,11 +49,13 @@
 
 WELSVP_NAMESPACE_BEGIN
 
-typedef void (VAACalcSadBgdFunc) (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight,
+typedef void (VAACalcSadBgdFunc) (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth,
+                                  int32_t iPicHeight,
                                   int32_t iPicStride,
                                   int32_t* pFrameSad, int32_t* pSad8x8, int32_t* pSd8x8, uint8_t* pMad8x8);
 
-typedef void (VAACalcSadSsdBgdFunc) (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight,
+typedef void (VAACalcSadSsdBgdFunc) (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth,
+                                     int32_t iPicHeight,
                                      int32_t iPicStride,
                                      int32_t* pFrameSad, int32_t* pSad8x8, int32_t* pSum16x16, int32_t* pSumSquare16x16,
                                      int32_t* pSsd16x16, int32_t* pSd8x8, uint8_t* pMad8x8);
@@ -62,11 +64,13 @@
                                int32_t iPicStride,
                                int32_t* pFrameSad, int32_t* pSad8x8);
 
-typedef void (VAACalcSadVarFunc) (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight,
+typedef void (VAACalcSadVarFunc) (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth,
+                                  int32_t iPicHeight,
                                   int32_t iPicStride,
                                   int32_t* pFrameSad, int32_t* pSad8x8, int32_t* pSum16x16, int32_t* pSumSquare16x16);
 
-typedef void (VAACalcSadSsdFunc) (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth, int32_t iPicHeight,
+typedef void (VAACalcSadSsdFunc) (const uint8_t* pCurData, const uint8_t* pRefData, int32_t iPicWidth,
+                                  int32_t iPicHeight,
                                   int32_t iPicStride,
                                   int32_t* pFrameSad, int32_t* pSad8x8, int32_t* pSum16x16, int32_t* pSumSquare16x16, int32_t* pSsd16x16);