shithub: openh264

Download patch

ref: 2356eb1ff6126916cca782ebd68ac7f478ab901e
parent: 869870e670f1934258edfd59c39041bc2e46e380
author: Martin Storsjö <[email protected]>
date: Fri Jan 30 05:44:04 EST 2015

Move the memory allocation/deallocation routines to the common library

They are still used slightly differently in the encoder and decoder;
the decoder uses plain functions while the encoder uses one object
keeping track of the number of allocated bytes, and keeping track
of the requested alignment.

--- a/codec/build/iOS/common/common.xcodeproj/project.pbxproj
+++ b/codec/build/iOS/common/common.xcodeproj/project.pbxproj
@@ -19,6 +19,7 @@
 		4CE443D918B722CD0017DF25 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CE443D818B722CD0017DF25 /* Foundation.framework */; };
 		53C1C9BC193F0FB000404D8F /* expand_pic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53C1C9BB193F0FB000404D8F /* expand_pic.cpp */; };
 		5BA8F2C019603F5F00011CE4 /* common_tables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5BA8F2BF19603F5F00011CE4 /* common_tables.cpp */; };
+		5BD896BA1A7B839B00D32B7D /* memory_align.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5BD896B91A7B839B00D32B7D /* memory_align.cpp */; };
 		5BDD15ED1A79027600B6CA2E /* mc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5BDD15EC1A79027600B6CA2E /* mc.cpp */; };
 		F0B204F918FD23BF005DA23F /* copy_mb.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F0B204F818FD23BF005DA23F /* copy_mb.cpp */; };
 		F556A8241906673900E156A8 /* arm_arch64_common_macro.S in Sources */ = {isa = PBXBuildFile; fileRef = F556A8221906673900E156A8 /* arm_arch64_common_macro.S */; };
@@ -70,6 +71,8 @@
 		53C1C9BB193F0FB000404D8F /* expand_pic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = expand_pic.cpp; sourceTree = "<group>"; };
 		5BA8F2BE19603F3500011CE4 /* wels_common_defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wels_common_defs.h; sourceTree = "<group>"; };
 		5BA8F2BF19603F5F00011CE4 /* common_tables.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = common_tables.cpp; sourceTree = "<group>"; };
+		5BD896B81A7B837700D32B7D /* memory_align.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = memory_align.h; sourceTree = "<group>"; };
+		5BD896B91A7B839B00D32B7D /* memory_align.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = memory_align.cpp; sourceTree = "<group>"; };
 		5BDD15EB1A79026A00B6CA2E /* mc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mc.h; sourceTree = "<group>"; };
 		5BDD15EC1A79027600B6CA2E /* mc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mc.cpp; sourceTree = "<group>"; };
 		F0B204F718FD23B6005DA23F /* copy_mb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = copy_mb.h; sourceTree = "<group>"; };
@@ -127,6 +130,7 @@
 				4C3406BE18D96EA600DFA14A /* macros.h */,
 				5BDD15EB1A79026A00B6CA2E /* mc.h */,
 				4C3406C018D96EA600DFA14A /* measure_time.h */,
+				5BD896B81A7B837700D32B7D /* memory_align.h */,
 				4C3406C118D96EA600DFA14A /* typedefs.h */,
 				5BA8F2BE19603F3500011CE4 /* wels_common_defs.h */,
 				4C3406C218D96EA600DFA14A /* WelsThreadLib.h */,
@@ -146,6 +150,7 @@
 				53C1C9BB193F0FB000404D8F /* expand_pic.cpp */,
 				4C3406C618D96EA600DFA14A /* deblocking_common.cpp */,
 				5BDD15EC1A79027600B6CA2E /* mc.cpp */,
+				5BD896B91A7B839B00D32B7D /* memory_align.cpp */,
 				4C3406C818D96EA600DFA14A /* WelsThreadLib.cpp */,
 			);
 			path = src;
@@ -260,6 +265,7 @@
 				F5AC94FF193EB7D800F58154 /* deblocking_aarch64_neon.S in Sources */,
 				4C3406CE18D96EA600DFA14A /* crt_util_safe_x.cpp in Sources */,
 				F791965919D3BE2200F60C6B /* intra_pred_common.cpp in Sources */,
+				5BD896BA1A7B839B00D32B7D /* memory_align.cpp in Sources */,
 				4C3406CF18D96EA600DFA14A /* deblocking_common.cpp in Sources */,
 				5BA8F2C019603F5F00011CE4 /* common_tables.cpp in Sources */,
 				F791965419D3B89D00F60C6B /* intra_pred_common_aarch64_neon.S in Sources */,
--- a/codec/build/iOS/dec/welsdec/welsdec.xcodeproj/project.pbxproj
+++ b/codec/build/iOS/dec/welsdec/welsdec.xcodeproj/project.pbxproj
@@ -20,7 +20,6 @@
 		4CE4469318BC5EAB0017DF25 /* fmo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4467018BC5EAA0017DF25 /* fmo.cpp */; };
 		4CE4469418BC5EAB0017DF25 /* get_intra_predictor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4467118BC5EAA0017DF25 /* get_intra_predictor.cpp */; };
 		4CE4469518BC5EAB0017DF25 /* manage_dec_ref.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4467218BC5EAA0017DF25 /* manage_dec_ref.cpp */; };
-		4CE4469718BC5EAB0017DF25 /* mem_align.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4467418BC5EAA0017DF25 /* mem_align.cpp */; };
 		4CE4469818BC5EAB0017DF25 /* memmgr_nal_unit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4467518BC5EAA0017DF25 /* memmgr_nal_unit.cpp */; };
 		4CE4469918BC5EAB0017DF25 /* mv_pred.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4467618BC5EAA0017DF25 /* mv_pred.cpp */; };
 		4CE4469A18BC5EAB0017DF25 /* parse_mb_syn_cavlc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4467718BC5EAA0017DF25 /* parse_mb_syn_cavlc.cpp */; };
@@ -71,7 +70,6 @@
 		4CE4465318BC5EAA0017DF25 /* get_intra_predictor.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = get_intra_predictor.h; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
 		4CE4465418BC5EAA0017DF25 /* manage_dec_ref.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = manage_dec_ref.h; sourceTree = "<group>"; };
 		4CE4465518BC5EAA0017DF25 /* mb_cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mb_cache.h; sourceTree = "<group>"; };
-		4CE4465718BC5EAA0017DF25 /* mem_align.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mem_align.h; sourceTree = "<group>"; };
 		4CE4465818BC5EAA0017DF25 /* memmgr_nal_unit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = memmgr_nal_unit.h; sourceTree = "<group>"; };
 		4CE4465918BC5EAA0017DF25 /* mv_pred.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mv_pred.h; sourceTree = "<group>"; };
 		4CE4465A18BC5EAA0017DF25 /* nal_prefix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nal_prefix.h; sourceTree = "<group>"; };
@@ -96,7 +94,6 @@
 		4CE4467018BC5EAA0017DF25 /* fmo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fmo.cpp; sourceTree = "<group>"; };
 		4CE4467118BC5EAA0017DF25 /* get_intra_predictor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = get_intra_predictor.cpp; sourceTree = "<group>"; };
 		4CE4467218BC5EAA0017DF25 /* manage_dec_ref.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = manage_dec_ref.cpp; sourceTree = "<group>"; };
-		4CE4467418BC5EAA0017DF25 /* mem_align.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mem_align.cpp; sourceTree = "<group>"; };
 		4CE4467518BC5EAA0017DF25 /* memmgr_nal_unit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = memmgr_nal_unit.cpp; sourceTree = "<group>"; };
 		4CE4467618BC5EAA0017DF25 /* mv_pred.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mv_pred.cpp; sourceTree = "<group>"; };
 		4CE4467718BC5EAA0017DF25 /* parse_mb_syn_cavlc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parse_mb_syn_cavlc.cpp; sourceTree = "<group>"; };
@@ -211,7 +208,6 @@
 				4CE4465318BC5EAA0017DF25 /* get_intra_predictor.h */,
 				4CE4465418BC5EAA0017DF25 /* manage_dec_ref.h */,
 				4CE4465518BC5EAA0017DF25 /* mb_cache.h */,
-				4CE4465718BC5EAA0017DF25 /* mem_align.h */,
 				4CE4465818BC5EAA0017DF25 /* memmgr_nal_unit.h */,
 				4CE4465918BC5EAA0017DF25 /* mv_pred.h */,
 				4CE4465A18BC5EAA0017DF25 /* nal_prefix.h */,
@@ -247,7 +243,6 @@
 				4CE4467018BC5EAA0017DF25 /* fmo.cpp */,
 				4CE4467118BC5EAA0017DF25 /* get_intra_predictor.cpp */,
 				4CE4467218BC5EAA0017DF25 /* manage_dec_ref.cpp */,
-				4CE4467418BC5EAA0017DF25 /* mem_align.cpp */,
 				4CE4467518BC5EAA0017DF25 /* memmgr_nal_unit.cpp */,
 				4CE4467618BC5EAA0017DF25 /* mv_pred.cpp */,
 				4CE4467718BC5EAA0017DF25 /* parse_mb_syn_cavlc.cpp */,
@@ -351,7 +346,6 @@
 				4CE4469F18BC5EAB0017DF25 /* welsDecoderExt.cpp in Sources */,
 				4CE4469318BC5EAB0017DF25 /* fmo.cpp in Sources */,
 				4CE4469118BC5EAB0017DF25 /* decoder_data_tables.cpp in Sources */,
-				4CE4469718BC5EAB0017DF25 /* mem_align.cpp in Sources */,
 				4CE4469518BC5EAB0017DF25 /* manage_dec_ref.cpp in Sources */,
 				4CE4468A18BC5EAB0017DF25 /* au_parser.cpp in Sources */,
 				4CE4469918BC5EAB0017DF25 /* mv_pred.cpp in Sources */,
--- a/codec/build/iOS/enc/welsenc/welsenc.xcodeproj/project.pbxproj
+++ b/codec/build/iOS/enc/welsenc/welsenc.xcodeproj/project.pbxproj
@@ -25,7 +25,6 @@
 		4CE4471418BC605C0017DF25 /* encoder_ext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE446E318BC605C0017DF25 /* encoder_ext.cpp */; };
 		4CE4471618BC605C0017DF25 /* get_intra_predictor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE446E518BC605C0017DF25 /* get_intra_predictor.cpp */; };
 		4CE4471818BC605C0017DF25 /* md.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE446E718BC605C0017DF25 /* md.cpp */; };
-		4CE4471918BC605C0017DF25 /* memory_align.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE446E818BC605C0017DF25 /* memory_align.cpp */; };
 		4CE4471A18BC605C0017DF25 /* mv_pred.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE446E918BC605C0017DF25 /* mv_pred.cpp */; };
 		4CE4471B18BC605C0017DF25 /* nal_encap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE446EA18BC605C0017DF25 /* nal_encap.cpp */; };
 		4CE4471C18BC605C0017DF25 /* picture_handle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CE446EB18BC605C0017DF25 /* picture_handle.cpp */; };
@@ -93,7 +92,6 @@
 		4CE446B618BC605C0017DF25 /* get_intra_predictor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = get_intra_predictor.h; sourceTree = "<group>"; };
 		4CE446B718BC605C0017DF25 /* mb_cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mb_cache.h; sourceTree = "<group>"; };
 		4CE446B918BC605C0017DF25 /* md.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md.h; sourceTree = "<group>"; };
-		4CE446BA18BC605C0017DF25 /* memory_align.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = memory_align.h; sourceTree = "<group>"; };
 		4CE446BB18BC605C0017DF25 /* mt_defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mt_defs.h; sourceTree = "<group>"; };
 		4CE446BC18BC605C0017DF25 /* mv_pred.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mv_pred.h; sourceTree = "<group>"; };
 		4CE446BD18BC605C0017DF25 /* nal_encap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nal_encap.h; sourceTree = "<group>"; };
@@ -134,7 +132,6 @@
 		4CE446E318BC605C0017DF25 /* encoder_ext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = encoder_ext.cpp; sourceTree = "<group>"; };
 		4CE446E518BC605C0017DF25 /* get_intra_predictor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = get_intra_predictor.cpp; sourceTree = "<group>"; };
 		4CE446E718BC605C0017DF25 /* md.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = md.cpp; sourceTree = "<group>"; };
-		4CE446E818BC605C0017DF25 /* memory_align.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = memory_align.cpp; sourceTree = "<group>"; };
 		4CE446E918BC605C0017DF25 /* mv_pred.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mv_pred.cpp; sourceTree = "<group>"; };
 		4CE446EA18BC605C0017DF25 /* nal_encap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = nal_encap.cpp; sourceTree = "<group>"; };
 		4CE446EB18BC605C0017DF25 /* picture_handle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = picture_handle.cpp; sourceTree = "<group>"; };
@@ -274,7 +271,6 @@
 				4CE446B618BC605C0017DF25 /* get_intra_predictor.h */,
 				4CE446B718BC605C0017DF25 /* mb_cache.h */,
 				4CE446B918BC605C0017DF25 /* md.h */,
-				4CE446BA18BC605C0017DF25 /* memory_align.h */,
 				4CE446BB18BC605C0017DF25 /* mt_defs.h */,
 				4CE446BC18BC605C0017DF25 /* mv_pred.h */,
 				4CE446BD18BC605C0017DF25 /* nal_encap.h */,
@@ -325,7 +321,6 @@
 				4CE446E318BC605C0017DF25 /* encoder_ext.cpp */,
 				4CE446E518BC605C0017DF25 /* get_intra_predictor.cpp */,
 				4CE446E718BC605C0017DF25 /* md.cpp */,
-				4CE446E818BC605C0017DF25 /* memory_align.cpp */,
 				4CE446E918BC605C0017DF25 /* mv_pred.cpp */,
 				4CE446EA18BC605C0017DF25 /* nal_encap.cpp */,
 				4CE446EB18BC605C0017DF25 /* picture_handle.cpp */,
@@ -455,7 +450,6 @@
 				4CE4472918BC605C0017DF25 /* svc_set_mb_syn_cavlc.cpp in Sources */,
 				4CE4471818BC605C0017DF25 /* md.cpp in Sources */,
 				4CE4471B18BC605C0017DF25 /* nal_encap.cpp in Sources */,
-				4CE4471918BC605C0017DF25 /* memory_align.cpp in Sources */,
 				4CE4472418BC605C0017DF25 /* svc_enc_slice_segment.cpp in Sources */,
 				4CE4472318BC605C0017DF25 /* svc_base_layer_md.cpp in Sources */,
 				4CB8F2B419235FC5005D6386 /* pixel_aarch64_neon.S in Sources */,
--- a/codec/build/win32/dec/WelsDecCore.vcproj
+++ b/codec/build/win32/dec/WelsDecCore.vcproj
@@ -752,7 +752,7 @@
 					>
 				</File>
 				<File
-					RelativePath="..\..\..\decoder\core\inc\mem_align.h"
+					RelativePath="..\..\..\common\inc\memory_align.h"
 					>
 				</File>
 				<File
@@ -909,7 +909,7 @@
 					>
 				</File>
 				<File
-					RelativePath="..\..\..\decoder\core\src\mem_align.cpp"
+					RelativePath="..\..\..\common\src\memory_align.cpp"
 					>
 				</File>
 				<File
--- a/codec/build/win32/dec/WelsDecPlus.vcproj
+++ b/codec/build/win32/dec/WelsDecPlus.vcproj
@@ -384,7 +384,7 @@
 				Filter="h;hpp;hxx;hm;inl"
 				>
 				<File
-					RelativePath="..\..\..\decoder\core\inc\mem_align.h"
+					RelativePath="..\..\..\common\inc\mem_align.h"
 					>
 				</File>
 				<File
--- a/codec/build/win32/enc/WelsEncCore.vcproj
+++ b/codec/build/win32/enc/WelsEncCore.vcproj
@@ -394,7 +394,7 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\..\encoder\core\src\memory_align.cpp"
+				RelativePath="..\..\..\common\src\memory_align.cpp"
 				>
 			</File>
 			<File
@@ -575,7 +575,7 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\..\encoder\core\inc\memory_align.h"
+				RelativePath="..\..\..\common\inc\memory_align.h"
 				>
 			</File>
 			<File
--- /dev/null
+++ b/codec/common/inc/memory_align.h
@@ -1,0 +1,110 @@
+/*!
+ * \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.
+ *
+ */
+
+#if !defined(WELS_COMMON_MEMORY_ALIGN_H__)
+#define WELS_COMMON_MEMORY_ALIGN_H__
+
+#include "typedefs.h"
+
+// NOTE: please do not clean below lines even comment, turn on for potential memory leak verify and memory usage monitor etc.
+//#define MEMORY_CHECK
+#define MEMORY_MONITOR
+#ifdef MEMORY_CHECK
+#ifndef MEMORY_MONITOR
+#define MEMORY_MONITOR
+#endif//MEMORY_MONITOR
+#endif//MEMORY_CHECK
+
+
+#ifdef MEMORY_CHECK
+#include <stdio.h>
+#endif//MEMORY_CHECK
+
+namespace WelsCommon {
+
+class CMemoryAlign {
+ public:
+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;
+
+ private:
+// private copy & assign constructors adding to fix klocwork scan issues
+CMemoryAlign (const CMemoryAlign& kcMa);
+CMemoryAlign& operator= (const CMemoryAlign& kcMa);
+
+ protected:
+uint32_t	m_nCacheLineSize;
+
+#ifdef MEMORY_MONITOR
+uint32_t	m_nMemoryUsageInBytes;
+#endif//MEMORY_MONITOR
+};
+
+/*!
+*************************************************************************************
+* \brief        malloc with zero filled utilization in Wels
+*
+* \param        kuiSize     size of memory block required
+*
+* \return       allocated memory pointer exactly, failed in case of NULL return
+*
+* \note N/A
+*************************************************************************************
+*/
+void* WelsMallocz (const uint32_t kuiSize, const char* kpTag);
+
+/*!
+*************************************************************************************
+* \brief        free utilization in Wels
+*
+* \param        pPtr    data pointer to be free.
+*                       i.e, uint8_t *pPtr = actual data to be free, argv = &pPtr.
+*
+* \return       NONE
+*
+* \note N/A
+*************************************************************************************
+*/
+void WelsFree (void* pPtr, const char* kpTag);
+
+#define WELS_SAFE_FREE(pPtr, pTag)              if (pPtr) { WelsFree(pPtr, pTag); pPtr = NULL; }
+
+
+}
+
+#endif//WELS_COMMON_MEMORY_ALIGN_H__
--- /dev/null
+++ b/codec/common/src/memory_align.cpp
@@ -1,0 +1,168 @@
+/*!
+ * \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 <stdlib.h>
+#include <string.h>
+#include "memory_align.h"
+#include "macros.h"
+
+namespace WelsCommon {
+
+#ifdef MEMORY_CHECK
+static FILE*    fpMemChkPoint;
+static uint32_t nCountRequestNum;
+#endif
+
+
+CMemoryAlign::CMemoryAlign (const uint32_t kuiCacheLineSize)
+#ifdef MEMORY_MONITOR
+  :	m_nMemoryUsageInBytes (0)
+#endif//MEMORY_MONITOR
+{
+  if ((kuiCacheLineSize == 0) || (kuiCacheLineSize & 0x0f))
+    m_nCacheLineSize	= 0x10;
+  else
+    m_nCacheLineSize	= kuiCacheLineSize;
+}
+
+CMemoryAlign::~CMemoryAlign() {
+#ifdef MEMORY_MONITOR
+  assert (m_nMemoryUsageInBytes == 0);
+#endif//MEMORY_MONITOR
+}
+
+void* WelsMalloc (const uint32_t kuiSize, const char* kpTag, const uint32_t kiAlign) {
+  const int32_t kiSizeOfVoidPointer	= sizeof (void**);
+  const int32_t kiSizeOfInt				= sizeof (int32_t);
+  const int32_t kiAlignedBytes		= kiAlign - 1;
+  const int32_t kiTrialRequestedSize	= kuiSize + kiAlignedBytes + kiSizeOfVoidPointer + kiSizeOfInt;
+  const int32_t kiActualRequestedSize	= kiTrialRequestedSize;
+  const uint32_t kiPayloadSize			= kuiSize;
+
+  uint8_t* pBuf		= (uint8_t*) malloc (kiActualRequestedSize);
+#ifdef MEMORY_CHECK
+  if (fpMemChkPoint == NULL) {
+    m_fpMemChkPoint    = fopen ("./enc_mem_check_point.txt",  "at+");
+    m_nCountRequestNum = 0;
+  }
+
+  if (fpMemChkPoint != NULL) {
+    if (kpTag != NULL)
+      fprintf (fpMemChkPoint, "WelsMalloc(), 0x%x : actual uiSize:\t%d\tbytes, input uiSize: %d bytes, %d - %s\n",
+               (void*)pBuf, kiActualRequestedSize, kuiSize, nCountRequestNum++, kpTag);
+    else
+      fprintf (fpMemChkPoint, "WelsMalloc(), 0x%x : actual uiSize:\t%d\tbytes, input uiSize: %d bytes, %d \n", (void*)pBuf,
+               kiActualRequestedSize, kuiSize, nCountRequestNum++);
+    fflush (fpMemChkPoint);
+  }
+#endif
+  uint8_t* pAlignedBuffer;
+
+  if (NULL == pBuf)
+    return NULL;
+
+  pAlignedBuffer = pBuf + kiAlignedBytes + kiSizeOfVoidPointer + kiSizeOfInt;
+  pAlignedBuffer -= ((uintptr_t) pAlignedBuffer & kiAlignedBytes);
+  * ((void**) (pAlignedBuffer - kiSizeOfVoidPointer)) = pBuf;
+  * ((int32_t*) (pAlignedBuffer - (kiSizeOfVoidPointer + kiSizeOfInt))) = kiPayloadSize;
+
+  return pAlignedBuffer;
+}
+
+void WelsFree (void* pPointer, const char* kpTag) {
+  if (pPointer) {
+#ifdef MEMORY_CHECK
+    if (m_fpMemChkPoint != NULL) {
+      if (kpTag != NULL)
+        fprintf (fpMemChkPoint, "WelsFree(), 0x%x - %s: \t%d\t bytes \n", (void*) (* (((void**) pPointer) - 1)), kpTag,
+                 kiMemoryLength);
+      else
+        fprintf (fpMemChkPoint, "WelsFree(), 0x%x \n", (void*) (* (((void**) pPointer) - 1)));
+      fflush (fpMemChkPoint);
+    }
+#endif
+    free (* (((void**) pPointer) - 1));
+  }
+}
+
+void* CMemoryAlign::WelsMallocz (const uint32_t kuiSize, const char* kpTag) {
+  void* pPointer = WelsMalloc (kuiSize, kpTag);
+  if (NULL == pPointer) {
+    return NULL;
+  }
+  // zero memory
+  memset (pPointer, 0, kuiSize);
+
+  return pPointer;
+}
+
+void* CMemoryAlign::WelsMalloc (const uint32_t kuiSize, const char* kpTag) {
+  void* pPointer = WelsCommon::WelsMalloc (kuiSize, kpTag, m_nCacheLineSize);
+#ifdef MEMORY_MONITOR
+  if (pPointer != NULL) {
+    const int32_t kiMemoryLength = * ((int32_t*) ((uint8_t*)pPointer - sizeof (void**) - sizeof (
+                                        int32_t))) + m_nCacheLineSize - 1 + sizeof (void**) + sizeof (int32_t);
+    m_nMemoryUsageInBytes += kiMemoryLength;
+  }
+#endif//MEMORY_MONITOR
+  return pPointer;
+}
+
+void CMemoryAlign::WelsFree (void* pPointer, const char* kpTag) {
+  if (pPointer) {
+#ifdef MEMORY_MONITOR
+    const int32_t kiMemoryLength = * ((int32_t*) ((uint8_t*)pPointer - sizeof (void**) - sizeof (
+                                        int32_t))) + m_nCacheLineSize - 1 + sizeof (void**) + sizeof (int32_t);
+    m_nMemoryUsageInBytes -= kiMemoryLength;
+#endif//MEMORY_MONITOR
+  }
+  WelsCommon::WelsFree (pPointer, kpTag);
+}
+
+void* WelsMallocz (const uint32_t kuiSize, const char* kpTag) {
+  void* pPointer = WelsMalloc (kuiSize, kpTag, 16);
+  if (NULL == pPointer) {
+    return NULL;
+  }
+  memset (pPointer, 0, kuiSize);
+  return pPointer;
+}
+
+const uint32_t CMemoryAlign::WelsGetCacheLineSize() const {
+  return m_nCacheLineSize;
+}
+
+const uint32_t CMemoryAlign::WelsGetMemoryUsage() const {
+  return m_nMemoryUsageInBytes;
+}
+
+} // end of namespace WelsCommon
--- a/codec/common/targets.mk
+++ b/codec/common/targets.mk
@@ -8,6 +8,7 @@
 	$(COMMON_SRCDIR)/src/expand_pic.cpp\
 	$(COMMON_SRCDIR)/src/intra_pred_common.cpp\
 	$(COMMON_SRCDIR)/src/mc.cpp\
+	$(COMMON_SRCDIR)/src/memory_align.cpp\
 	$(COMMON_SRCDIR)/src/sad_common.cpp\
 	$(COMMON_SRCDIR)/src/utils.cpp\
 	$(COMMON_SRCDIR)/src/welsCodecTrace.cpp\
--- a/codec/decoder/core/inc/mem_align.h
+++ /dev/null
@@ -1,90 +1,0 @@
-/*!
- * \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.
- *
- *	memory alignment utilization
- */
-
-#ifndef WELS_MEM_ALIGN_H__
-#define WELS_MEM_ALIGN_H__
-
-
-
-#include <stdlib.h>
-#include <string.h>
-#include "utils.h"
-
-namespace WelsDec {
-
-#ifdef __cplusplus
-extern "C" {
-#endif//__cplusplus
-
-
-
-/*!
-*************************************************************************************
-* \brief	malloc with zero filled utilization in Wels
-*
-* \param 	kuiSize	    size of memory block required
-*
-* \return	allocated memory pointer exactly, failed in case of NULL return
-*
-* \note	N/A
-*************************************************************************************
-*/
-void* WelsMallocz (const uint32_t kuiSize, const char* kpTag);
-
-/*!
-*************************************************************************************
-* \brief	free utilization in Wels
-*
-* \param 	pPtr	data pointer to be free.
-*			i.e, uint8_t *pPtr = actual data to be free, argv = &pPtr.
-*
-* \return	NONE
-*
-* \note	N/A
-*************************************************************************************
-*/
-void WelsFree (void* pPtr, const char* kpTag);
-
-#define WELS_SAFE_FREE(pPtr, pTag)		if (pPtr) { WelsFree(pPtr, pTag); pPtr = NULL; }
-
-/*
- *	memory operation routines
- */
-
-#ifdef __cplusplus
-}
-#endif//__cplusplus
-
-} // namespace WelsDec
-
-#endif //WELS_MEM_ALIGN_H__
--- a/codec/decoder/core/src/au_parser.cpp
+++ b/codec/decoder/core/src/au_parser.cpp
@@ -44,7 +44,7 @@
 #include "memmgr_nal_unit.h"
 #include "decoder_core.h"
 #include "bit_stream.h"
-#include "mem_align.h"
+#include "memory_align.h"
 
 namespace WelsDec {
 /*!
--- a/codec/decoder/core/src/decoder.cpp
+++ b/codec/decoder/core/src/decoder.cpp
@@ -51,7 +51,7 @@
 #include "expand_pic.h"
 #include "decode_slice.h"
 #include "error_concealment.h"
-#include "mem_align.h"
+#include "memory_align.h"
 
 namespace WelsDec {
 
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -40,7 +40,7 @@
 #include "expand_pic.h"
 #include "decoder.h"
 #include "decode_mb_aux.h"
-#include "mem_align.h"
+#include "memory_align.h"
 #include "error_concealment.h"
 
 namespace WelsDec {
--- a/codec/decoder/core/src/fmo.cpp
+++ b/codec/decoder/core/src/fmo.cpp
@@ -39,7 +39,7 @@
  */
 
 #include "fmo.h"
-#include "mem_align.h"
+#include "memory_align.h"
 
 namespace WelsDec {
 
--- a/codec/decoder/core/src/mem_align.cpp
+++ /dev/null
@@ -1,100 +1,0 @@
-/*!
- * \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 "mem_align.h"
-
-namespace WelsDec {
-
-//#define MEMORY_CHECK
-#ifdef MEMORY_CHECK
-
-WelsFileHandle* pMemCheckMalloc = NULL;
-WelsFileHandle* pMemCheckFree = NULL;
-
-int32_t iCountMalloc = 0;
-#endif
-//
-
-void* WelsMallocz (const uint32_t kuiSize, const char* kpTag) {
-  const int32_t kiSizeVoidPtr	= sizeof (void**);
-  const int32_t kiSizeInt		= sizeof (int32_t);
-  const int32_t kiAlignBytes	= 15;
-  uint8_t* pBuf		= (uint8_t*) malloc (kuiSize + kiAlignBytes + kiSizeVoidPtr + kiSizeInt);
-  uint8_t* pAlignBuf;
-
-#ifdef MEMORY_CHECK
-  if (pMemCheckMalloc == NULL) {
-    pMemCheckMalloc = WelsFopen ("mem_check_malloc.txt", "at+");
-    pMemCheckFree   = WelsFopen ("mem_check_free.txt", "at+");
-  }
-
-  if (kpTag != NULL) {
-    if (pMemCheckMalloc != NULL) {
-      fprintf (pMemCheckMalloc, "0x%x, size: %d       , malloc %s\n", (void*)pBuf,
-               (kuiSize + kiAlignBytes + kiSizeVoidPtr + kiSizeInt), kpTag);
-    }
-    if (pMemCheckMalloc != NULL) {
-      fflush (pMemCheckMalloc);
-    }
-  }
-#endif
-
-  if (NULL == pBuf)
-    return NULL;
-
-  // to fill zero values
-  memset (pBuf, 0, kuiSize + kiAlignBytes + kiSizeVoidPtr + kiSizeInt);
-
-  pAlignBuf = pBuf + kiAlignBytes + kiSizeVoidPtr + kiSizeInt;
-  pAlignBuf -= (uintptr_t) pAlignBuf & kiAlignBytes;
-  * ((void**) (pAlignBuf - kiSizeVoidPtr)) = pBuf;
-  * ((int32_t*) (pAlignBuf - (kiSizeVoidPtr + kiSizeInt))) = kuiSize;
-
-  return (pAlignBuf);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-
-void WelsFree (void* pPtr, const char* kpTag) {
-  if (pPtr) {
-#ifdef MEMORY_CHECK
-    if (NULL != pMemCheckFree && kpTag != NULL) {
-      fprintf (pMemCheckFree, "0x%x, free %s\n", (void*) (* (((void**) pPtr) - 1)), kpTag);
-      fflush (pMemCheckFree);
-    }
-#endif
-    free (* (((void**) pPtr) - 1));
-  }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-} // namespace WelsDec
--- a/codec/decoder/core/src/memmgr_nal_unit.cpp
+++ b/codec/decoder/core/src/memmgr_nal_unit.cpp
@@ -39,7 +39,7 @@
  *
  *****************************************************************************/
 #include "memmgr_nal_unit.h"
-#include "mem_align.h"
+#include "memory_align.h"
 
 namespace WelsDec {
 
--- a/codec/decoder/core/src/pic_queue.cpp
+++ b/codec/decoder/core/src/pic_queue.cpp
@@ -40,7 +40,7 @@
 #include "pic_queue.h"
 #include "decoder_context.h"
 #include "codec_def.h"
-#include "mem_align.h"
+#include "memory_align.h"
 
 namespace WelsDec {
 
--- a/codec/decoder/plus/src/welsDecoderExt.cpp
+++ b/codec/decoder/plus/src/welsDecoderExt.cpp
@@ -44,7 +44,7 @@
 #include "welsCodecTrace.h"
 #include "codec_def.h"
 #include "typedefs.h"
-#include "mem_align.h"
+#include "memory_align.h"
 #include "utils.h"
 #include "version.h"
 
--- a/codec/decoder/targets.mk
+++ b/codec/decoder/targets.mk
@@ -13,7 +13,6 @@
 	$(DECODER_SRCDIR)/core/src/fmo.cpp\
 	$(DECODER_SRCDIR)/core/src/get_intra_predictor.cpp\
 	$(DECODER_SRCDIR)/core/src/manage_dec_ref.cpp\
-	$(DECODER_SRCDIR)/core/src/mem_align.cpp\
 	$(DECODER_SRCDIR)/core/src/memmgr_nal_unit.cpp\
 	$(DECODER_SRCDIR)/core/src/mv_pred.cpp\
 	$(DECODER_SRCDIR)/core/src/parse_mb_syn_cabac.cpp\
--- a/codec/encoder/core/inc/as264_common.h
+++ b/codec/encoder/core/inc/as264_common.h
@@ -139,16 +139,5 @@
 #endif//MB_TYPES_CHECK
 #endif//MB_TYPES_INFO_OUTPUT
 
-// NOTE: please do not clean below lines even comment, turn on for potential memory leak verify and memory usage monitor etc.
-//#define MEMORY_CHECK
-#define MEMORY_MONITOR
-#ifdef MEMORY_CHECK
-#ifndef MEMORY_MONITOR
-#define MEMORY_MONITOR
-#endif//MEMORY_MONITOR
-#endif//MEMORY_CHECK
-
-
-
 #endif // AS264_COMMON_H_
 
--- a/codec/encoder/core/inc/memory_align.h
+++ /dev/null
@@ -1,75 +1,0 @@
-/*!
- * \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.
- *
- */
-
-#if !defined(WELS_ENCODER_MEMORY_ALIGN_H__)
-#define WELS_ENCODER_MEMORY_ALIGN_H__
-
-#include "typedefs.h"
-#include "as264_common.h"
-#ifdef MEMORY_CHECK
-#include <stdio.h>
-#endif//MEMORY_CHECK
-
-namespace WelsEnc {
-
-class CMemoryAlign {
- public:
-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;
-
- private:
-// private copy & assign constructors adding to fix klocwork scan issues
-CMemoryAlign (const CMemoryAlign& kcMa);
-CMemoryAlign& operator= (const CMemoryAlign& kcMa);
-
- protected:
-uint32_t	m_nCacheLineSize;
-
-#ifdef MEMORY_MONITOR
-uint32_t	m_nMemoryUsageInBytes;
-#endif//MEMORY_MONITOR
-
-#ifdef MEMORY_CHECK
-FILE*		m_fpMemChkPoint;
-uint32_t	m_nCountRequestNum;
-#endif//MEMORY_CHECK
-};
-
-}
-
-#endif//WELS_ENCODER_MEMORY_ALIGN_H__
--- a/codec/encoder/core/inc/svc_enc_slice_segment.h
+++ b/codec/encoder/core/inc/svc_enc_slice_segment.h
@@ -48,6 +48,8 @@
 #include "codec_app_def.h"
 #include "set_mb_syn_cabac.h"
 
+using namespace WelsCommon;
+
 namespace WelsEnc {
 
 
--- a/codec/encoder/core/src/memory_align.cpp
+++ /dev/null
@@ -1,146 +1,0 @@
-/*!
- * \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 <stdlib.h>
-#include <string.h>
-#include "memory_align.h"
-#include "macros.h"
-
-namespace WelsEnc {
-
-CMemoryAlign::CMemoryAlign (const uint32_t kuiCacheLineSize)
-#ifdef MEMORY_MONITOR
-  :	m_nMemoryUsageInBytes (0)
-#endif//MEMORY_MONITOR
-{
-  if ((kuiCacheLineSize == 0) || (kuiCacheLineSize & 0x0f))
-    m_nCacheLineSize	= 0x10;
-  else
-    m_nCacheLineSize	= kuiCacheLineSize;
-
-#ifdef MEMORY_CHECK
-  m_fpMemChkPoint		= fopen ("./enc_mem_check_point.txt",  "wt+");
-  m_nCountRequestNum	= 0;
-#endif//MEMORY_CHECK
-}
-
-CMemoryAlign::~CMemoryAlign() {
-#ifdef MEMORY_MONITOR
-  assert (m_nMemoryUsageInBytes == 0);
-#endif//MEMORY_MONITOR
-
-#ifdef MEMORY_CHECK
-  fclose (m_fpMemChkPoint);
-  m_fpMemChkPoint = NULL;
-
-  m_nCountRequestNum	= 0;
-#endif//MEMORY_CHECK
-}
-
-void* CMemoryAlign::WelsMallocz (const uint32_t kuiSize, const char* kpTag) {
-  void* pPointer = WelsMalloc (kuiSize, kpTag);
-  if (NULL == pPointer) {
-    return NULL;
-  }
-  // zero memory
-  memset (pPointer, 0, kuiSize);
-
-  return pPointer;
-}
-
-void* CMemoryAlign::WelsMalloc (const uint32_t kuiSize, const char* kpTag) {
-  const int32_t kiSizeOfVoidPointer	= sizeof (void**);
-  const int32_t kiSizeOfInt				= sizeof (int32_t);
-  const int32_t kiAlignedBytes		= m_nCacheLineSize - 1;
-  const int32_t kiTrialRequestedSize	= kuiSize + kiAlignedBytes + kiSizeOfVoidPointer + kiSizeOfInt;
-  const int32_t kiActualRequestedSize	= kiTrialRequestedSize;
-  const uint32_t kiPayloadSize			= kuiSize;
-
-  uint8_t* pBuf		= (uint8_t*) malloc (kiActualRequestedSize);
-#ifdef MEMORY_CHECK
-  if (m_fpMemChkPoint != NULL) {
-    if (kpTag != NULL)
-      fprintf (m_fpMemChkPoint, "WelsMalloc(), 0x%x : actual uiSize:\t%d\tbytes, input uiSize: %d bytes, %d - %s\n",
-               (void*)pBuf, kiActualRequestedSize, kuiSize, m_nCountRequestNum++, kpTag);
-    else
-      fprintf (m_fpMemChkPoint, "WelsMalloc(), 0x%x : actual uiSize:\t%d\tbytes, input uiSize: %d bytes, %d \n", (void*)pBuf,
-               kiActualRequestedSize, kuiSize, m_nCountRequestNum++);
-    fflush (m_fpMemChkPoint);
-  }
-#endif
-  uint8_t* pAlignedBuffer;
-
-  if (NULL == pBuf)
-    return NULL;
-
-  pAlignedBuffer = pBuf + kiAlignedBytes + kiSizeOfVoidPointer + kiSizeOfInt;
-  pAlignedBuffer -= ((uintptr_t) pAlignedBuffer & kiAlignedBytes);
-  * ((void**) (pAlignedBuffer - kiSizeOfVoidPointer)) = pBuf;
-  * ((int32_t*) (pAlignedBuffer - (kiSizeOfVoidPointer + kiSizeOfInt))) = kiPayloadSize;
-
-#ifdef MEMORY_MONITOR
-  m_nMemoryUsageInBytes += kiActualRequestedSize;
-#endif//MEMORY_MONITOR
-
-  return pAlignedBuffer;
-}
-
-void CMemoryAlign::WelsFree (void* pPointer, const char* kpTag) {
-  if (pPointer) {
-#ifdef MEMORY_MONITOR
-    const int32_t kiMemoryLength = * ((int32_t*) ((uint8_t*)pPointer - sizeof (void**) - sizeof (
-                                        int32_t))) + m_nCacheLineSize - 1 + sizeof (void**) + sizeof (int32_t);
-    m_nMemoryUsageInBytes -= kiMemoryLength;
-#endif//MEMORY_MONITOR
-#ifdef MEMORY_CHECK
-    if (m_fpMemChkPoint != NULL) {
-      if (kpTag != NULL)
-        fprintf (m_fpMemChkPoint, "WelsFree(), 0x%x - %s: \t%d\t bytes \n", (void*) (* (((void**) pPointer) - 1)), kpTag,
-                 kiMemoryLength);
-      else
-        fprintf (m_fpMemChkPoint, "WelsFree(), 0x%x \n", (void*) (* (((void**) pPointer) - 1)));
-      fflush (m_fpMemChkPoint);
-    }
-#endif
-    free (* (((void**) pPointer) - 1));
-  }
-}
-
-const uint32_t CMemoryAlign::WelsGetCacheLineSize() const {
-  return m_nCacheLineSize;
-}
-
-const uint32_t CMemoryAlign::WelsGetMemoryUsage() const {
-  return m_nMemoryUsageInBytes;
-}
-
-} // end of namespace WelsEnc
--- a/codec/encoder/targets.mk
+++ b/codec/encoder/targets.mk
@@ -9,7 +9,6 @@
 	$(ENCODER_SRCDIR)/core/src/encoder_ext.cpp\
 	$(ENCODER_SRCDIR)/core/src/get_intra_predictor.cpp\
 	$(ENCODER_SRCDIR)/core/src/md.cpp\
-	$(ENCODER_SRCDIR)/core/src/memory_align.cpp\
 	$(ENCODER_SRCDIR)/core/src/mv_pred.cpp\
 	$(ENCODER_SRCDIR)/core/src/nal_encap.cpp\
 	$(ENCODER_SRCDIR)/core/src/picture_handle.cpp\
--- a/test/common/ExpandPicture.cpp
+++ b/test/common/ExpandPicture.cpp
@@ -1,7 +1,7 @@
 #include <gtest/gtest.h>
 #include "codec_def.h"
 #include "expand_pic.h"
-#include "mem_align.h"
+#include "memory_align.h"
 #include "decoder_context.h"
 #include "cpu.h"
 #include "cpu_core.h"
--- a/test/decoder/DecUT_DecExt.cpp
+++ b/test/decoder/DecUT_DecExt.cpp
@@ -4,7 +4,7 @@
 #include "codec_app_def.h"
 #include "codec_api.h"
 #include "wels_common_basis.h"
-#include "mem_align.h"
+#include "memory_align.h"
 #include "ls_defines.h"
 
 using namespace WelsDec;
--- a/test/decoder/DecUT_ErrorConcealment.cpp
+++ b/test/decoder/DecUT_ErrorConcealment.cpp
@@ -1,7 +1,7 @@
 #include <gtest/gtest.h>
 
 #include "wels_common_basis.h"
-#include "mem_align.h"
+#include "memory_align.h"
 #include "error_concealment.h"
 #include "ls_defines.h"
 #include "cpu.h"
--- a/test/decoder/DecUT_PredMv.cpp
+++ b/test/decoder/DecUT_PredMv.cpp
@@ -1,7 +1,7 @@
 #include <gtest/gtest.h>
 
 #include "wels_common_basis.h"
-#include "mem_align.h"
+#include "memory_align.h"
 #include "mv_pred.h"
 #include "ls_defines.h"
 
--- a/test/encoder/EncUT_EncoderMb.cpp
+++ b/test/encoder/EncUT_EncoderMb.cpp
@@ -3,8 +3,8 @@
 #include "memory_align.h"
 #include "utils/DataGenerator.h"
 
-using namespace WelsEnc;
 #include "encode_mb_aux.h"
+using namespace WelsEnc;
 
 ALIGNED_DECLARE (const int16_t, g_kiQuantInterFFCompare[104][8], 16) = {
   /* 0*/	{   0,     1,     0,     1,     1,     1,     1,     1 },
--- a/test/encoder/EncUT_MemoryAlloc.cpp
+++ b/test/encoder/EncUT_MemoryAlloc.cpp
@@ -1,7 +1,7 @@
 #include "gtest/gtest.h"
 #include "memory_align.h"
 
-using namespace WelsEnc;
+using namespace WelsCommon;
 
 //Tests of WelsGetCacheLineSize Begin
 TEST (MemoryAlignTest, GetCacheLineSize_LoopWithin16K) {