Use Int instead of Double in Rate Control and Modify anchor SHA1 value
Showing the changes to codec/processing (3 of 12 files). Show all
Unified · Split
| @@ -209,7 +209,7 @@ typedef struct { · 208 unmodified lines | ||
| 209 | 209 | SMotionTextureUnit* pMotionTextureUnit; |
| 210 | 210 | |
| 211 | 211 | signed char* pMotionTextureIndexToDeltaQp; |
| 212 | − double dAverMotionTextureIndexToDeltaQp; | |
| 212 | + int iAverMotionTextureIndexToDeltaQp; // *AQ_STEP_INT_MULTIPLY | |
| 213 | 213 | } SAdaptiveQuantizationParam; |
| 214 | 214 | |
| 215 | 215 | typedef enum { |
| @@ -30,16 +30,16 @@ · 29 unmodified lines | ||
| 30 | 30 | * |
| 31 | 31 | */ |
| 32 | 32 | #include "AdaptiveQuantization.h" |
| 33 | − | |
| 33 | +#include "macros.h" | |
| 34 | 34 | WELSVP_NAMESPACE_BEGIN |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | |
| 38 | −#define AVERAGE_TIME_MOTION (0.3) //0.3046875 // 1/4 + 1/16 - 1/128 ~ 0.3 | |
| 39 | −#define AVERAGE_TIME_TEXTURE_QUALITYMODE (1.0) //0.5 // 1/2 | |
| 40 | −#define AVERAGE_TIME_TEXTURE_BITRATEMODE (0.875) //0.5 // 1/2 | |
| 41 | −#define MODEL_ALPHA (0.9910) //1.5 //1.1102 | |
| 42 | −#define MODEL_TIME (5.8185) //9.0 //5.9842 | |
| 38 | +#define AVERAGE_TIME_MOTION (3000) //0.3046875 // 1/4 + 1/16 - 1/128 ~ 0.3 *AQ_TIME_INT_MULTIPLY | |
| 39 | +#define AVERAGE_TIME_TEXTURE_QUALITYMODE (10000) //0.5 // 1/2 *AQ_TIME_INT_MULTIPLY | |
| 40 | +#define AVERAGE_TIME_TEXTURE_BITRATEMODE (8750) //0.5 // 1/2 *AQ_TIME_INT_MULTIPLY | |
| 41 | +#define MODEL_ALPHA (9910) //1.5 //1.1102 *AQ_TIME_INT_MULTIPLY | |
| 42 | +#define MODEL_TIME (58185) //9.0 //5.9842 *AQ_TIME_INT_MULTIPLY | |
| 43 | 43 | |
| 44 | 44 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 45 | 45 | |
| @@ -65,14 +65,14 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 19 unmodified lines | ||
| 65 | 65 | |
| 66 | 66 | SMotionTextureUnit* pMotionTexture = NULL; |
| 67 | 67 | SVAACalcResult* pVaaCalcResults = NULL; |
| 68 | − int8_t iMotionTextureIndexToDeltaQp = 0; | |
| 68 | + int32_t iMotionTextureIndexToDeltaQp = 0; | |
| 69 | 69 | int32_t iAverMotionTextureIndexToDeltaQp = 0; // double to uint32 |
| 70 | − double dAverageMotionIndex = 0.0; // double to float | |
| 71 | − double dAverageTextureIndex = 0.0; | |
| 70 | + int64_t iAverageMotionIndex = 0; // double to float | |
| 71 | + int64_t iAverageTextureIndex = 0; | |
| 72 | 72 | |
| 73 | − double dQStep = 0.0; | |
| 74 | − double dLumaMotionDeltaQp = 0; | |
| 75 | − double dLumaTextureDeltaQp = 0; | |
| 73 | + int64_t iQStep = 0; | |
| 74 | + int64_t iLumaMotionDeltaQp = 0; | |
| 75 | + int64_t iLumaTextureDeltaQp = 0; | |
| 76 | 76 | |
| 77 | 77 | uint8_t* pRefFrameY = NULL, *pCurFrameY = NULL; |
| 78 | 78 | int32_t iRefStride = 0, iCurStride = 0; |
| @@ -88,8 +88,8 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 9 unmodified lines | ||
| 88 | 88 | |
| 89 | 89 | /////////////////////////////////////// motion ////////////////////////////////// |
| 90 | 90 | // motion MB residual variance |
| 91 | − dAverageMotionIndex = 0.0; | |
| 92 | − dAverageTextureIndex = 0.0; | |
| 91 | + iAverageMotionIndex = 0; | |
| 92 | + iAverageTextureIndex = 0; | |
| 93 | 93 | pMotionTexture = m_sAdaptiveQuantParam.pMotionTextureUnit; |
| 94 | 94 | pVaaCalcResults = m_sAdaptiveQuantParam.pCalcResult; |
| 95 | 95 | |
| @@ -115,8 +115,8 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 19 unmodified lines | ||
| 115 | 115 | uiSum = uiSum >> 8; |
| 116 | 116 | pMotionTexture->uiTextureIndex = (iSQSum >> 8) - (uiSum * uiSum); |
| 117 | 117 | |
| 118 | − dAverageMotionIndex += pMotionTexture->uiMotionIndex; | |
| 119 | − dAverageTextureIndex += pMotionTexture->uiTextureIndex; | |
| 118 | + iAverageMotionIndex += pMotionTexture->uiMotionIndex; | |
| 119 | + iAverageTextureIndex += pMotionTexture->uiTextureIndex; | |
| 120 | 120 | pMotionTexture++; |
| 121 | 121 | ++iMbIndex; |
| 122 | 122 | pRefFrameTmp += MB_WIDTH_LUMA; |
| @@ -131,8 +131,8 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 8 unmodified lines | ||
| 131 | 131 | pCurFrameTmp = pCurFrameY; |
| 132 | 132 | for (i = 0; i < iMbWidth; i++) { |
| 133 | 133 | m_pfVar (pRefFrameTmp, iRefStride, pCurFrameTmp, iCurStride, pMotionTexture); |
| 134 | − dAverageMotionIndex += pMotionTexture->uiMotionIndex; | |
| 135 | − dAverageTextureIndex += pMotionTexture->uiTextureIndex; | |
| 134 | + iAverageMotionIndex += pMotionTexture->uiMotionIndex; | |
| 135 | + iAverageTextureIndex += pMotionTexture->uiTextureIndex; | |
| 136 | 136 | pMotionTexture++; |
| 137 | 137 | pRefFrameTmp += MB_WIDTH_LUMA; |
| 138 | 138 | pCurFrameTmp += MB_WIDTH_LUMA; |
| @@ -142,49 +142,51 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 3 unmodified lines | ||
| 142 | 142 | pCurFrameY += (iCurStride) << 4; |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | − dAverageMotionIndex = dAverageMotionIndex / iMbTotalNum; | |
| 146 | − dAverageTextureIndex = dAverageTextureIndex / iMbTotalNum; | |
| 147 | − if ((dAverageMotionIndex <= PESN) && (dAverageMotionIndex >= -PESN)) { | |
| 148 | − dAverageMotionIndex = 1.0; | |
| 145 | + iAverageMotionIndex = WELS_DIV_ROUND64(iAverageMotionIndex * AQ_INT_MULTIPLY,iMbTotalNum); | |
| 146 | + iAverageTextureIndex = WELS_DIV_ROUND64(iAverageTextureIndex * AQ_INT_MULTIPLY, iMbTotalNum); | |
| 147 | + if ((iAverageMotionIndex <= AQ_PESN) && (iAverageMotionIndex >= -AQ_PESN)) { | |
| 148 | + iAverageMotionIndex = AQ_INT_MULTIPLY; | |
| 149 | 149 | } |
| 150 | − if ((dAverageTextureIndex <= PESN) && (dAverageTextureIndex >= -PESN)) { | |
| 151 | − dAverageTextureIndex = 1.0; | |
| 150 | + if ((iAverageTextureIndex <= AQ_PESN) && (iAverageTextureIndex >= -AQ_PESN)) { | |
| 151 | + iAverageTextureIndex = AQ_INT_MULTIPLY; | |
| 152 | 152 | } |
| 153 | 153 | // motion mb residual map to QP |
| 154 | 154 | // texture mb original map to QP |
| 155 | 155 | iAverMotionTextureIndexToDeltaQp = 0; |
| 156 | − dAverageMotionIndex = AVERAGE_TIME_MOTION * dAverageMotionIndex; | |
| 156 | + iAverageMotionIndex = WELS_DIV_ROUND64(AVERAGE_TIME_MOTION * iAverageMotionIndex, AQ_TIME_INT_MULTIPLY); | |
| 157 | 157 | |
| 158 | 158 | if (m_sAdaptiveQuantParam.iAdaptiveQuantMode == AQ_QUALITY_MODE) { |
| 159 | − dAverageTextureIndex = AVERAGE_TIME_TEXTURE_QUALITYMODE * dAverageTextureIndex; | |
| 159 | + iAverageTextureIndex = WELS_DIV_ROUND64(AVERAGE_TIME_TEXTURE_QUALITYMODE * iAverageTextureIndex, AQ_TIME_INT_MULTIPLY); | |
| 160 | 160 | } else { |
| 161 | − dAverageTextureIndex = AVERAGE_TIME_TEXTURE_BITRATEMODE * dAverageTextureIndex; | |
| 161 | + iAverageTextureIndex = WELS_DIV_ROUND64(AVERAGE_TIME_TEXTURE_BITRATEMODE * iAverageTextureIndex, AQ_TIME_INT_MULTIPLY); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | + int64_t iAQ_EPSN = -((int64_t)AQ_PESN*AQ_TIME_INT_MULTIPLY*AQ_QSTEP_INT_MULTIPLY/AQ_INT_MULTIPLY); | |
| 164 | 165 | pMotionTexture = m_sAdaptiveQuantParam.pMotionTextureUnit; |
| 165 | 166 | for (j = 0; j < iMbHeight; j ++) { |
| 166 | 167 | for (i = 0; i < iMbWidth; i++) { |
| 167 | − double a = pMotionTexture->uiTextureIndex / dAverageTextureIndex; | |
| 168 | − dQStep = (a - 1) / (a + MODEL_ALPHA); | |
| 169 | − dLumaTextureDeltaQp = MODEL_TIME * dQStep;// range +- 6 | |
| 168 | + int64_t a = WELS_DIV_ROUND64((int64_t)(pMotionTexture->uiTextureIndex) *AQ_INT_MULTIPLY * AQ_TIME_INT_MULTIPLY, iAverageTextureIndex); | |
| 169 | + iQStep = WELS_DIV_ROUND64((a - AQ_TIME_INT_MULTIPLY) * AQ_QSTEP_INT_MULTIPLY, (a + MODEL_ALPHA)); | |
| 170 | + iLumaTextureDeltaQp = MODEL_TIME * iQStep;// range +- 6 | |
| 170 | 171 | |
| 171 | − iMotionTextureIndexToDeltaQp = (int8_t)dLumaTextureDeltaQp; | |
| 172 | + iMotionTextureIndexToDeltaQp = ((int32_t)(iLumaTextureDeltaQp/(AQ_TIME_INT_MULTIPLY))); | |
| 172 | 173 | |
| 173 | − a = pMotionTexture->uiMotionIndex / dAverageMotionIndex; | |
| 174 | − dQStep = (a - 1) / (a + MODEL_ALPHA); | |
| 175 | − dLumaMotionDeltaQp = MODEL_TIME * dQStep;// range +- 6 | |
| 174 | + a = WELS_DIV_ROUND64(((int64_t)pMotionTexture->uiMotionIndex)*AQ_INT_MULTIPLY * AQ_TIME_INT_MULTIPLY, iAverageMotionIndex); | |
| 175 | + iQStep = WELS_DIV_ROUND64((a - AQ_TIME_INT_MULTIPLY) * AQ_QSTEP_INT_MULTIPLY, (a + MODEL_ALPHA)); | |
| 176 | + iLumaMotionDeltaQp = MODEL_TIME * iQStep;// range +- 6 | |
| 176 | 177 | |
| 177 | − if ((m_sAdaptiveQuantParam.iAdaptiveQuantMode == AQ_QUALITY_MODE && dLumaMotionDeltaQp < -PESN) | |
| 178 | + if ((m_sAdaptiveQuantParam.iAdaptiveQuantMode == AQ_QUALITY_MODE && iLumaMotionDeltaQp < iAQ_EPSN) | |
| 178 | 179 | || (m_sAdaptiveQuantParam.iAdaptiveQuantMode == AQ_BITRATE_MODE)) { |
| 179 | − iMotionTextureIndexToDeltaQp += (int8_t)dLumaMotionDeltaQp; | |
| 180 | + iMotionTextureIndexToDeltaQp += ((int32_t)(iLumaMotionDeltaQp/(AQ_TIME_INT_MULTIPLY))); | |
| 180 | 181 | } |
| 181 | 182 | |
| 182 | − m_sAdaptiveQuantParam.pMotionTextureIndexToDeltaQp[j * iMbWidth + i] = iMotionTextureIndexToDeltaQp; | |
| 183 | + m_sAdaptiveQuantParam.pMotionTextureIndexToDeltaQp[j * iMbWidth + i] = (int8_t)(iMotionTextureIndexToDeltaQp/AQ_QSTEP_INT_MULTIPLY); | |
| 183 | 184 | iAverMotionTextureIndexToDeltaQp += iMotionTextureIndexToDeltaQp; |
| 184 | 185 | pMotionTexture++; |
| 185 | 186 | } |
| 186 | 187 | } |
| 187 | − m_sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp = (1.0 * iAverMotionTextureIndexToDeltaQp) / iMbTotalNum; | |
| 188 | + | |
| 189 | + m_sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp = iAverMotionTextureIndexToDeltaQp / iMbTotalNum; | |
| 188 | 190 | |
| 189 | 191 | eReturn = RET_SUCCESS; |
| 190 | 192 | |
| @@ -210,7 +212,7 @@ EResult CAdaptiveQuantization::Get (int32_t iType, void* pParam) { · 19 unmodified lines | ||
| 210 | 212 | |
| 211 | 213 | SAdaptiveQuantizationParam* sAdaptiveQuantParam = (SAdaptiveQuantizationParam*)pParam; |
| 212 | 214 | |
| 213 | − sAdaptiveQuantParam->dAverMotionTextureIndexToDeltaQp = m_sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp; | |
| 215 | + sAdaptiveQuantParam->iAverMotionTextureIndexToDeltaQp = m_sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp; | |
| 214 | 216 | |
| 215 | 217 | return RET_SUCCESS; |
| 216 | 218 | } |
| @@ -58,6 +58,10 @@ WELSVP_NAMESPACE_BEGIN · 57 unmodified lines | ||
| 58 | 58 | #define MAX_HEIGHT (2304)//MAX_FS_LEVEL51 (36864); MAX_FS_LEVEL51*256/4096 = 2304 |
| 59 | 59 | #define MB_WIDTH_LUMA (16) |
| 60 | 60 | #define PESN (1e-6) // desired float precision |
| 61 | +#define AQ_INT_MULTIPLY 10000000 | |
| 62 | +#define AQ_TIME_INT_MULTIPLY 10000 | |
| 63 | +#define AQ_QSTEP_INT_MULTIPLY 100 | |
| 64 | +#define AQ_PESN 10 // (1e-6)*AQ_INT_MULTIPLY | |
| 61 | 65 | |
| 62 | 66 | #define MB_TYPE_INTRA4x4 0x00000001 |
| 63 | 67 | #define MB_TYPE_INTRA16x16 0x00000002 |