shithub: openh264

Download patch

ref: e8d8bdc48e6e858ab8773a9391191ed11aa0e674
parent: cab66c93a7a34958897f1a9e426e34c99119bcd9
parent: 4ab8c88e98020363b45884599eef2539a530969e
author: Licai Guo <[email protected]>
date: Tue Apr 15 12:20:08 EDT 2014

Merge pull request #689 from huili2/add_file_CopyMB_EC

divide copy_mb functions into new file for decoder use from encoder and ...

--- a/codec/build/win32/dec/WelsDecCore.vcproj
+++ b/codec/build/win32/dec/WelsDecCore.vcproj
@@ -685,6 +685,10 @@
 					RelativePath="..\..\..\decoder\core\inc\bit_stream.h"
 					>
 				</File>
+                                <File
+                                        RelativePath="..\..\..\common\inc\copy_mb.h"
+                                        >
+                                </File>
 				<File
 					RelativePath="..\..\..\common\inc\cpu.h"
 					>
@@ -733,6 +737,10 @@
 					RelativePath="..\..\..\decoder\core\inc\error_code.h"
 					>
 				</File>
+                                <File
+                                        RelativePath="..\..\..\decoder\core\inc\error_concealment.h"
+                                        >
+                                </File>
 				<File
 					RelativePath="..\..\..\decoder\core\inc\expand_pic.h"
 					>
@@ -854,6 +862,10 @@
 					RelativePath="..\..\..\decoder\core\src\bit_stream.cpp"
 					>
 				</File>
+                                <File
+                                        RelativePath="..\..\..\common\src\copy_mb.cpp"
+                                        >
+                                </File>
 				<File
 					RelativePath="..\..\..\common\src\cpu.cpp"
 					>
@@ -890,6 +902,10 @@
 					RelativePath="..\..\..\decoder\core\src\decoder_data_tables.cpp"
 					>
 				</File>
+                                <File
+                                        RelativePath="..\..\..\decoder\core\src\error_concealment.cpp"
+                                        >
+                                </File>
 				<File
 					RelativePath="..\..\..\decoder\core\src\expand_pic.cpp"
 					>
--- a/codec/build/win32/enc/WelsEncCore.vcproj
+++ b/codec/build/win32/enc/WelsEncCore.vcproj
@@ -395,6 +395,10 @@
 					/>
 				</FileConfiguration>
 			</File>
+                        <File
+                                RelativePath="..\..\..\common\src\copy_mb.cpp"
+                                >
+                        </File>
 			<File
 				RelativePath="..\..\..\common\src\cpu.cpp"
 				>
@@ -1448,6 +1452,10 @@
 				RelativePath="..\..\..\encoder\core\inc\bit_stream.h"
 				>
 			</File>
+                        <File
+                                RelativePath="..\..\..\common\inc\copy_mb.h"
+                                >
+                        </File>
 			<File
 				RelativePath="..\..\..\common\inc\cpu.h"
 				>
--- /dev/null
+++ b/codec/common/inc/copy_mb.h
@@ -1,0 +1,72 @@
+/*!
+ * \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.
+ *
+ */
+
+#ifndef WELS_COPY_MB_H_
+#define WELS_COPY_MB_H_
+
+#include "typedefs.h"
+
+/****************************************************************************
+ * Copy functions
+ ****************************************************************************/
+void WelsCopy4x4 (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+void WelsCopy8x8_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+void WelsCopy8x16_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);	//
+void WelsCopy16x8_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);	//
+void WelsCopy16x16_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+
+#if defined(__cplusplus)
+extern "C" {
+#endif//__cplusplus
+
+#if defined (X86_ASM)
+
+void WelsCopy8x8_mmx (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+void WelsCopy8x16_mmx (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+void WelsCopy16x8NotAligned_sse2 (uint8_t* Dst, int32_t  iStrideD, uint8_t* Src, int32_t  iStrideS);
+void WelsCopy16x16_sse2 (uint8_t* Dst, int32_t  iStrideD, uint8_t* Src, int32_t  iStrideS);
+void WelsCopy16x16NotAligned_sse2 (uint8_t* Dst, int32_t  iStrideD, uint8_t* Src, int32_t  iStrideS);
+#endif//X86_ASM
+
+#if defined (HAVE_NEON)
+void WelsCopy8x8_neon (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+void WelsCopy16x16_neon (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+void WelsCopy16x16NotAligned_neon (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+void WelsCopy16x8NotAligned_neon (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+void WelsCopy8x16_neon (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+#endif
+
+#if defined(__cplusplus)
+}
+#endif//__cplusplus
+
+#endif //SAMPLE_H_
--- /dev/null
+++ b/codec/common/src/copy_mb.cpp
@@ -1,0 +1,103 @@
+/*!
+ * \copy
+ *     Copyright (c)  2009-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.
+ *
+ *
+ * \file	copy_mb.cpp
+ *
+ * \brief	copy MB YUV data
+ *
+ * \date	2014.04.14 Created
+ *
+ *************************************************************************************
+ */
+
+#include "copy_mb.h"
+#include "macros.h"
+#include "ls_defines.h"
+
+/****************************************************************************
+ * Copy functions
+ ****************************************************************************/
+void WelsCopy4x4 (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
+  const int32_t kiSrcStride2 = iStrideS << 1;
+  const int32_t kiSrcStride3 = iStrideS + kiSrcStride2;
+  const int32_t kiDstStride2 = iStrideD << 1;
+  const int32_t kiDstStride3 = iStrideD + kiDstStride2;
+
+  ST32 (pDst,				LD32 (pSrc));
+  ST32 (pDst + iStrideD,	LD32 (pSrc + iStrideS));
+  ST32 (pDst + kiDstStride2, LD32 (pSrc + kiSrcStride2));
+  ST32 (pDst + kiDstStride3, LD32 (pSrc + kiSrcStride3));
+}
+void WelsCopy8x8_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
+  int32_t i;
+  for (i = 0; i < 4; i++) {
+    ST32 (pDst,				LD32 (pSrc));
+    ST32 (pDst + 4 ,			LD32 (pSrc + 4));
+    ST32 (pDst + iStrideD,	LD32 (pSrc + iStrideS));
+    ST32 (pDst + iStrideD + 4 ,	LD32 (pSrc + iStrideS + 4));
+    pDst += iStrideD << 1;
+    pSrc += iStrideS << 1;
+  }
+}
+void WelsCopy8x16_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
+  int32_t i;
+  for (i = 0; i < 8; ++i) {
+    ST32 (pDst,				LD32 (pSrc));
+    ST32 (pDst + 4 ,			LD32 (pSrc + 4));
+    ST32 (pDst + iStrideD,	LD32 (pSrc + iStrideS));
+    ST32 (pDst + iStrideD + 4 ,	LD32 (pSrc + iStrideS + 4));
+    pDst += iStrideD << 1;
+    pSrc += iStrideS << 1;
+  }
+}
+void WelsCopy16x8_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
+  int32_t i;
+  for (i = 0; i < 8; i++) {
+    ST32 (pDst,		LD32 (pSrc));
+    ST32 (pDst + 4 ,	LD32 (pSrc + 4));
+    ST32 (pDst + 8 , LD32 (pSrc + 8));
+    ST32 (pDst + 12 ,	LD32 (pSrc + 12));
+    pDst += iStrideD ;
+    pSrc += iStrideS;
+  }
+}
+void WelsCopy16x16_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
+  int32_t i;
+  for (i = 0; i < 16; i++) {
+    ST32 (pDst,		LD32 (pSrc));
+    ST32 (pDst + 4 ,	LD32 (pSrc + 4));
+    ST32 (pDst + 8 , LD32 (pSrc + 8));
+    ST32 (pDst + 12 ,	LD32 (pSrc + 12));
+    pDst += iStrideD ;
+    pSrc += iStrideS;
+  }
+}
+
--- a/codec/common/targets.mk
+++ b/codec/common/targets.mk
@@ -1,5 +1,6 @@
 COMMON_SRCDIR=codec/common
 COMMON_CPP_SRCS=\
+        $(COMMON_SRCDIR)/src/copy_mb.cpp\
 	$(COMMON_SRCDIR)/src/cpu.cpp\
 	$(COMMON_SRCDIR)/src/crt_util_safe_x.cpp\
 	$(COMMON_SRCDIR)/src/deblocking_common.cpp\
--- a/codec/decoder/core/inc/decoder_context.h
+++ b/codec/decoder/core/inc/decoder_context.h
@@ -98,6 +98,12 @@
   PWelsMcFunc pMcChromaFunc;
 } SMcFunc;
 
+typedef void (*PCopyFunc) (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
+typedef struct TagCopyFunc {
+  PCopyFunc pCopyLumaFunc;
+  PCopyFunc pCopyChromaFunc;
+} SCopyFunc;
+
 //deblock module defination
 struct TagDeblockingFunc;
 
@@ -278,6 +284,9 @@
   PGetIntraPredFunc pGetIChromaPredFunc[7];		// h264_predict_8x8_t
   PIdctResAddPredFunc	pIdctResAddPredFunc;
   SMcFunc				sMcFunc;
+
+  //For error concealment
+  SCopyFunc sCopyFunc;
   /* For Deblocking */
   SDeblockingFunc     sDeblockingFunc;
   SExpandPicFunc	    sExpandPicFunc;
--- /dev/null
+++ b/codec/decoder/core/inc/error_concealment.h
@@ -1,0 +1,62 @@
+/*!
+ * \copy
+ *     Copyright (c)  2009-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.
+ *
+ * \file	error_concealment.h
+ *
+ * \brief	Interfaces introduced for error concealment
+ *
+ * \date	04/14/2014 Created
+ *
+ *************************************************************************************
+ */
+#ifndef WELS_ERROR_CONCEALMENT_H__
+#define WELS_ERROR_CONCEALMENT_H__
+#include "typedefs.h"
+#include "decoder_context.h"
+
+namespace WelsDec {
+//Initialize error concealment
+void InitErrorCon (PWelsDecoderContext pCtx);
+//Do error concealment using frame copy method
+void DoErrorConFrameCopy (PWelsDecoderContext pCtx);
+//Do error concealment using slice copy method
+void DoErrorConSliceCopy (PWelsDecoderContext pCtx);
+//Mark erroneous frame as Ref Pic into DPB
+int32_t MarkECFrameAsRef (PWelsDecoderContext pCtx);
+//Judge if EC is needed to current frame
+bool NeedErrorCon (PWelsDecoderContext pCtx);
+// ImplementErrorConceal
+// Do actual error concealment
+int32_t ImplementErrorCon (PWelsDecoderContext pCtx);
+
+} // namespace WelsDec
+
+#endif//WELS_ERROR_CONCEALMENT_H__
+
--- a/codec/decoder/core/src/decoder.cpp
+++ b/codec/decoder/core/src/decoder.cpp
@@ -50,6 +50,7 @@
 #include "deblocking.h"
 #include "expand_pic.h"
 #include "decode_slice.h"
+#include "error_concealment.h"
 #include "mem_align.h"
 #include "ls_defines.h"
 
@@ -476,6 +477,8 @@
                 return pCtx->iErrorCode;
               }
             }
+            //Do error concealment here
+            ImplementErrorCon (pCtx);
           }
 
           if ((IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL (pCtx->sCurNalHead.eNalUnitType)) &&
@@ -530,10 +533,10 @@
         ResetParameterSetsState (pCtx);
         return pCtx->iErrorCode;
       }
+      //Do error concealment here
+      ImplementErrorCon (pCtx);
     }
 
-    //TODO error concealment here
-
     if ((IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL (pCtx->sCurNalHead.eNalUnitType))
         && pNalPayload) {
       if (ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes)) {
@@ -571,7 +574,8 @@
         ResetParameterSetsState (pCtx);
         return pCtx->iErrorCode;
       }
-
+      //Do error concealment here
+      ImplementErrorCon (pCtx);
     }
   }
 
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -41,6 +41,7 @@
 #include "decoder.h"
 #include "decode_mb_aux.h"
 #include "mem_align.h"
+#include "error_concealment.h"
 
 namespace WelsDec {
 
@@ -1549,6 +1550,7 @@
       WelsLog (pCtx, WELS_LOG_WARNING, "sync picture resolution ext failed,  the error is %d", iErr);
       return iErr;
     }
+    InitErrorCon (pCtx); //Do EC initialization here, for sequence start
   }
 
 
--- /dev/null
+++ b/codec/decoder/core/src/error_concealment.cpp
@@ -1,0 +1,98 @@
+/*!
+ * \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.
+ *
+ *	error_concealment.cpp:	Wels decoder error concealment implementation
+ */
+
+#include "error_code.h"
+#include "expand_pic.h"
+#include "manage_dec_ref.h"
+#include "copy_mb.h"
+#include "error_concealment.h"
+#include "cpu_core.h"
+
+namespace WelsDec {
+//Init
+void InitErrorCon (PWelsDecoderContext pCtx) {
+  if (pCtx->iErrorConMethod == ERROR_CON_SLICE_COPY) {
+    pCtx->sCopyFunc.pCopyLumaFunc = WelsCopy16x16_c;
+    pCtx->sCopyFunc.pCopyChromaFunc = WelsCopy8x8_c;
+
+#if defined(X86_ASM)
+    if (pCtx->uiCpuFlag & WELS_CPU_MMXEXT) {
+      pCtx->sCopyFunc.pCopyChromaFunc = WelsCopy8x8_mmx; //aligned
+    }
+
+    if (pCtx->uiCpuFlag & WELS_CPU_SSE2) {
+      pCtx->sCopyFunc.pCopyLumaFunc = WelsCopy16x16_sse2; //this is aligned copy;
+    }
+#endif //X86_ASM
+
+#if defined(HAVE_NEON)
+    if (pCtx->uiCpuFlag & WELS_CPU_NEON) {
+      pCtx->sCopyFunc.pCopyChromaFunc		= WelsCopy8x8_neon; //aligned
+    }
+#endif //HAVE_NEON
+  } //TODO add more methods here
+  return;
+}
+
+//Do error concealment using frame copy method
+void DoErrorConFrameCopy (PWelsDecoderContext pCtx) {
+  //TODO
+}
+
+
+//Do error concealment using slice copy method
+void DoErrorConSliceCopy (PWelsDecoderContext pCtx) {
+  //TODO
+}
+
+//Mark erroneous frame as Ref Pic into DPB
+int32_t MarkECFrameAsRef (PWelsDecoderContext pCtx) {
+  //TODO
+  return ERR_NONE;
+}
+
+bool NeedErrorCon (PWelsDecoderContext pCtx) {
+  bool bNeedEC = false;
+  //TODO
+  return bNeedEC;
+}
+
+// ImplementErrorConceal
+// Do actual error concealment
+int32_t ImplementErrorCon (PWelsDecoderContext pCtx) {
+  int32_t iRet = ERR_NONE;
+  //TODO
+  return iRet;
+}
+
+} // namespace WelsDec
--- a/codec/decoder/targets.mk
+++ b/codec/decoder/targets.mk
@@ -8,6 +8,7 @@
 	$(DECODER_SRCDIR)/core/src/decoder.cpp\
 	$(DECODER_SRCDIR)/core/src/decoder_core.cpp\
 	$(DECODER_SRCDIR)/core/src/decoder_data_tables.cpp\
+        $(DECODER_SRCDIR)/core/src/error_concealment.cpp\
 	$(DECODER_SRCDIR)/core/src/expand_pic.cpp\
 	$(DECODER_SRCDIR)/core/src/fmo.cpp\
 	$(DECODER_SRCDIR)/core/src/get_intra_predictor.cpp\
--- a/codec/encoder/core/inc/encode_mb_aux.h
+++ b/codec/encoder/core/inc/encode_mb_aux.h
@@ -35,6 +35,7 @@
 
 #include "typedefs.h"
 #include "wels_func_ptr_def.h"
+#include "copy_mb.h"
 
 namespace WelsSVCEnc {
 void WelsInitEncodingFuncs (SWelsFuncPtrList* pFuncList, uint32_t  uiCpuFlag);
@@ -68,15 +69,6 @@
 // dct_data is no-use here, just for the same interface with dct_save functions
 void WelsDctFourT4_c (int16_t* pDct, uint8_t* pPixel1, int32_t iStride1, uint8_t* pPixel2, int32_t iStride2);
 
-/****************************************************************************
- * Copy functions
- ****************************************************************************/
-void WelsCopy4x4 (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
-void WelsCopy8x8_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
-void WelsCopy8x16_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);	//
-void WelsCopy16x8_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);	//
-void WelsCopy16x16_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
-
 #if defined(__cplusplus)
 extern "C" {
 #endif//__cplusplus
@@ -111,24 +103,9 @@
 void WelsQuantFour4x4_sse2 (int16_t* pDct, const int16_t* pFF, const int16_t* pMF);
 void WelsQuantFour4x4Max_sse2 (int16_t* pDct, const int16_t* pFF, const int16_t* pMF, int16_t* pMax);
 
-
-/****************************************************************************
- * Copy functions for rec
- ****************************************************************************/
-void WelsCopy8x8_mmx (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
-void WelsCopy8x16_mmx (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
-void WelsCopy16x8NotAligned_sse2 (uint8_t* Dst, int32_t  iStrideD, uint8_t* Src, int32_t  iStrideS);
-void WelsCopy16x16_sse2 (uint8_t* Dst, int32_t  iStrideD, uint8_t* Src, int32_t  iStrideS);
-void WelsCopy16x16NotAligned_sse2 (uint8_t* Dst, int32_t  iStrideD, uint8_t* Src, int32_t  iStrideS);
 #endif
 
 #ifdef	HAVE_NEON
-void WelsCopy8x8_neon( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS );
-void WelsCopy16x16_neon( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS );
-void WelsCopy16x16NotAligned_neon( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS );
-void WelsCopy16x8NotAligned_neon( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS );
-void WelsCopy8x16_neon( uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS );
-
 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);
--- a/codec/encoder/core/src/encode_mb_aux.cpp
+++ b/codec/encoder/core/src/encode_mb_aux.cpp
@@ -434,65 +434,6 @@
   return iSingleCtr;
 }
 
-/****************************************************************************
- * Copy functions
- ****************************************************************************/
-void WelsCopy4x4 (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
-  const int32_t kiSrcStride2 = iStrideS << 1;
-  const int32_t kiSrcStride3 = iStrideS + kiSrcStride2;
-  const int32_t kiDstStride2 = iStrideD << 1;
-  const int32_t kiDstStride3 = iStrideD + kiDstStride2;
-
-  ST32 (pDst,				LD32 (pSrc));
-  ST32 (pDst + iStrideD,	LD32 (pSrc + iStrideS));
-  ST32 (pDst + kiDstStride2, LD32 (pSrc + kiSrcStride2));
-  ST32 (pDst + kiDstStride3, LD32 (pSrc + kiSrcStride3));
-}
-void WelsCopy8x8_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
-  int32_t i;
-  for (i = 0; i < 4; i++) {
-    ST32 (pDst,				LD32 (pSrc));
-    ST32 (pDst + 4 ,			LD32 (pSrc + 4));
-    ST32 (pDst + iStrideD,	LD32 (pSrc + iStrideS));
-    ST32 (pDst + iStrideD + 4 ,	LD32 (pSrc + iStrideS + 4));
-    pDst += iStrideD << 1;
-    pSrc += iStrideS << 1;
-  }
-}
-void WelsCopy8x16_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
-  int32_t i;
-  for (i = 0; i < 8; ++i) {
-    ST32 (pDst,				LD32 (pSrc));
-    ST32 (pDst + 4 ,			LD32 (pSrc + 4));
-    ST32 (pDst + iStrideD,	LD32 (pSrc + iStrideS));
-    ST32 (pDst + iStrideD + 4 ,	LD32 (pSrc + iStrideS + 4));
-    pDst += iStrideD << 1;
-    pSrc += iStrideS << 1;
-  }
-}
-void WelsCopy16x8_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
-  int32_t i;
-  for (i = 0; i < 8; i++) {
-    ST32 (pDst,		LD32 (pSrc));
-    ST32 (pDst + 4 ,	LD32 (pSrc + 4));
-    ST32 (pDst + 8 , LD32 (pSrc + 8));
-    ST32 (pDst + 12 ,	LD32 (pSrc + 12));
-    pDst += iStrideD ;
-    pSrc += iStrideS;
-  }
-}
-void WelsCopy16x16_c (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS) {
-  int32_t i;
-  for (i = 0; i < 16; i++) {
-    ST32 (pDst,		LD32 (pSrc));
-    ST32 (pDst + 4 ,	LD32 (pSrc + 4));
-    ST32 (pDst + 8 , LD32 (pSrc + 8));
-    ST32 (pDst + 12 ,	LD32 (pSrc + 12));
-    pDst += iStrideD ;
-    pSrc += iStrideS;
-  }
-}
-
 int32_t WelsGetNoneZeroCount_c (int16_t* pLevel) {
   int32_t iCnt = 0;
   int32_t iIdx = 0;