1 /*! 2 * \copy 3 * Copyright (c) 2009-2013, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 * 32 * \file md.h 33 * 34 * \brief mode decision 35 * 36 * \date 2009.5.14 Created 37 * 38 ************************************************************************************* 39 */ 40 #ifndef WELS_MACROBLOCK_MODE_DECISION_H__ 41 #define WELS_MACROBLOCK_MODE_DECISION_H__ 42 43 #include "svc_motion_estimate.h" 44 #include "svc_enc_macroblock.h" 45 #include "encode_mb_aux.h" 46 #include "wels_func_ptr_def.h" 47 48 namespace WelsEnc { 49 #define ME_REFINE_BUF_STRIDE 32 50 #define ME_REFINE_BUF_WIDTH_BLK4 8 51 #define ME_REFINE_BUF_WIDTH_BLK8 16 52 #define ME_REFINE_BUF_STRIDE_BLK4 160 53 #define ME_REFINE_BUF_STRIDE_BLK8 320 54 55 #define REFINE_ME_NO_BEST_HALF_PIXEL 0 //( 0, 0) 56 #define REFINE_ME_HALF_PIXEL_LEFT 3 //(-2, 0) 57 #define REFINE_ME_HALF_PIXEL_RIGHT 4 //( 2, 0) 58 #define REFINE_ME_HALF_PIXEL_TOP 1 //( 0, -2) 59 #define REFINE_ME_HALF_PIXEL_BOTTOM 2 //( 0, 2) 60 61 #define ME_NO_BEST_QUAR_PIXEL 1 //( 0, 0) or best half pixel 62 #define ME_QUAR_PIXEL_LEFT 2 //(-1, 0) 63 #define ME_QUAR_PIXEL_RIGHT 3 //( 1, 0) 64 #define ME_QUAR_PIXEL_TOP 4 //( 0, -1) 65 #define ME_QUAR_PIXEL_BOTTOM 5 //( 0, 1) 66 67 #define NO_BEST_FRAC_PIX 1 // REFINE_ME_NO_BEST_HALF_PIXEL + ME_NO_BEST_QUAR_PIXEL 68 69 //for vaa constants 70 #define MBVAASIGN_FLAT 15 71 #define MBVAASIGN_HOR1 3 72 #define MBVAASIGN_HOR2 12 73 #define MBVAASIGN_VER1 5 74 #define MBVAASIGN_VER2 10 75 #define MBVAASIGN_CMPX1 6 76 #define MBVAASIGN_CMPX2 9 77 78 extern const int32_t g_kiQpCostTable[52]; 79 extern const int8_t g_kiMapModeI16x16[7]; 80 //extern const int8_t g_kiMapModeI4x4[14]; 81 extern const int8_t g_kiMapModeIntraChroma[7]; 82 83 ///////////////////////////// 84 85 // if we want keep total sizeof(SWelsMD) <= 256, we maybe need to seperate three member of SWelsME. 86 typedef struct TagWelsMD { 87 int32_t iLambda; 88 uint16_t* pMvdCost; 89 90 int32_t iCostLuma; 91 int32_t iCostChroma;//satd+lambda(best_pred_mode) //i_sad_chroma; 92 int32_t iSadPredMb; 93 94 uint8_t uiRef; //uiRefIndex appointed by Encoder, used for MC 95 bool bMdUsingSad; 96 uint16_t uiReserved; 97 98 int32_t iCostSkipMb; 99 int32_t iSadPredSkip; 100 101 int32_t iMbPixX; // pixel position of MB in horizontal axis 102 int32_t iMbPixY; // pixel position of MB in vertical axis 103 int32_t iBlock8x8StaticIdc[4]; 104 105 //NO B frame in our Wels, we can ignore list1 106 107 struct { 108 SWelsME sMe16x16; //adjust each SWelsME for 8 D-word! 109 SWelsME sMe8x8[4]; 110 SWelsME sMe16x8[2]; 111 SWelsME sMe8x16[2]; 112 SWelsME sMe4x4[4][4]; 113 SWelsME sMe8x4[4][2]; 114 SWelsME sMe4x8[4][2]; 115 // SMVUnitXY i_mvbs[MB_BLOCK8x8_NUM]; //scaled MVB 116 } sMe; 117 118 } SWelsMD; 119 120 typedef struct TagMeRefinePointer { 121 uint8_t* pHalfPixH; 122 uint8_t* pHalfPixV; 123 uint8_t* pHalfPixHV; 124 125 uint8_t* pQuarPixBest; 126 uint8_t* pQuarPixTmp; 127 128 PCopyFunc pfCopyBlockByMode; 129 } SMeRefinePointer; 130 131 void FillNeighborCacheIntra (SMbCache* pMbCache, SMB* pCurMb, int32_t iMbWidth/*, bool constrained_intra_pred_flag*/); 132 void FillNeighborCacheInterWithoutBGD (SMbCache* pMbCache, SMB* pCurMb, int32_t iMbWidth, 133 int8_t* pVaaBgMbFlag); //BGD spatial func 134 void FillNeighborCacheInterWithBGD (SMbCache* pMbCache, SMB* pCurMb, int32_t iMbWidth, int8_t* pVaaBgMbFlag); 135 void InitFillNeighborCacheInterFunc (SWelsFuncPtrList* pFuncList, const int32_t kiFlag); 136 137 void MvdCostInit (uint16_t* pMvdCostInter, const int32_t kiMvdSz); 138 139 void PredictSad (int8_t* pRefIndexCache, int32_t* pSadCostCache, int32_t uiRef, int32_t* pSadPred); 140 141 142 void PredictSadSkip (int8_t* pRefIndexCache, bool* pMbSkipCache, int32_t* pSadCostCache, int32_t uiRef, 143 int32_t* iSadPredSkip); 144 145 // for pfGetVarianceFromIntraVaa function ptr adaptive by CPU features, 6/7/2010 146 void InitIntraAnalysisVaaInfo (SWelsFuncPtrList* pFuncList, const uint32_t kuiCpuFlag); 147 bool MdIntraAnalysisVaaInfo (sWelsEncCtx* pEncCtx, uint8_t* pEncMb); 148 149 uint8_t MdInterAnalysisVaaInfo_c (int32_t* pSad8x8); 150 151 152 void InitMeRefinePointer (SMeRefinePointer* pMeRefine, SMbCache* pMbCache, int32_t iStride); 153 void MeRefineFracPixel (sWelsEncCtx* pEncCtx, uint8_t* pMemPredInterMb, SWelsME* pMe, 154 SMeRefinePointer* pMeRefine, int32_t iWidth, int32_t iHeight); 155 156 void InitBlkStrideWithRef (int32_t* pBlkStride, const int32_t kiStrideRef); 157 158 void UpdateMbMv_c (SMVUnitXY* pMvBuffer, const SMVUnitXY ksMv); 159 160 #if defined(__cplusplus) 161 extern "C" { 162 #endif//__cplusplus 163 164 #if defined(X86_ASM) 165 166 // for pfGetVarianceFromIntraVaa SIMD optimization, 6/7/2010 167 int32_t AnalysisVaaInfoIntra_sse2 (uint8_t* pDataY, const int32_t kiLineSize); 168 int32_t AnalysisVaaInfoIntra_ssse3 (uint8_t* pDataY, const int32_t kiLineSize); 169 uint8_t MdInterAnalysisVaaInfo_sse2 (int32_t* pSad8x8); 170 uint8_t MdInterAnalysisVaaInfo_sse41 (int32_t* pSad8x8); 171 void UpdateMbMv_sse2 (SMVUnitXY* pMvBuffer, const SMVUnitXY ksMv); 172 173 #endif//X86_ASM 174 175 #if defined(__cplusplus) 176 } 177 #endif//__cplusplus 178 179 } 180 #endif//WELS_MACROBLOCK_MODE_DECISION_H__ 181 182