History

Use Int instead of Double in Rate Control and Modify anchor SHA1 value

dongzha committed 12 years ago

Commit f6ce43f1 parent 08377f312 files · +187 −163Browse files

Showing the changes to codec/processing/src (2 of 12 files). Show all

Unified · Split

2 files
  1. codec/processing/src/adaptivequantization/AdaptiveQuantization.cpp +41 −39
  2. codec/processing/src/common/util.h +4 −0
codec/processing/src/adaptivequantization/AdaptiveQuantization.cpp+41−39
@@ -30,16 +30,16 @@ · 29 unmodified lines
3030 *
3131 */
3232 #include "AdaptiveQuantization.h"
33−
33+#include "macros.h"
3434 WELSVP_NAMESPACE_BEGIN
3535
3636
3737
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
4343
4444 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
4545
@@ -65,14 +65,14 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 19 unmodified lines
6565
6666 SMotionTextureUnit* pMotionTexture = NULL;
6767 SVAACalcResult* pVaaCalcResults = NULL;
68− int8_t iMotionTextureIndexToDeltaQp = 0;
68+ int32_t iMotionTextureIndexToDeltaQp = 0;
6969 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;
7272
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;
7676
7777 uint8_t* pRefFrameY = NULL, *pCurFrameY = NULL;
7878 int32_t iRefStride = 0, iCurStride = 0;
@@ -88,8 +88,8 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 9 unmodified lines
8888
8989 /////////////////////////////////////// motion //////////////////////////////////
9090 // motion MB residual variance
91− dAverageMotionIndex = 0.0;
92− dAverageTextureIndex = 0.0;
91+ iAverageMotionIndex = 0;
92+ iAverageTextureIndex = 0;
9393 pMotionTexture = m_sAdaptiveQuantParam.pMotionTextureUnit;
9494 pVaaCalcResults = m_sAdaptiveQuantParam.pCalcResult;
9595
@@ -115,8 +115,8 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 19 unmodified lines
115115 uiSum = uiSum >> 8;
116116 pMotionTexture->uiTextureIndex = (iSQSum >> 8) - (uiSum * uiSum);
117117
118− dAverageMotionIndex += pMotionTexture->uiMotionIndex;
119− dAverageTextureIndex += pMotionTexture->uiTextureIndex;
118+ iAverageMotionIndex += pMotionTexture->uiMotionIndex;
119+ iAverageTextureIndex += pMotionTexture->uiTextureIndex;
120120 pMotionTexture++;
121121 ++iMbIndex;
122122 pRefFrameTmp += MB_WIDTH_LUMA;
@@ -131,8 +131,8 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 8 unmodified lines
131131 pCurFrameTmp = pCurFrameY;
132132 for (i = 0; i < iMbWidth; i++) {
133133 m_pfVar (pRefFrameTmp, iRefStride, pCurFrameTmp, iCurStride, pMotionTexture);
134− dAverageMotionIndex += pMotionTexture->uiMotionIndex;
135− dAverageTextureIndex += pMotionTexture->uiTextureIndex;
134+ iAverageMotionIndex += pMotionTexture->uiMotionIndex;
135+ iAverageTextureIndex += pMotionTexture->uiTextureIndex;
136136 pMotionTexture++;
137137 pRefFrameTmp += MB_WIDTH_LUMA;
138138 pCurFrameTmp += MB_WIDTH_LUMA;
@@ -142,49 +142,51 @@ EResult CAdaptiveQuantization::Process (int32_t iType, SPixMap* pSrcPixMap, SPix · 3 unmodified lines
142142 pCurFrameY += (iCurStride) << 4;
143143 }
144144 }
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;
149149 }
150− if ((dAverageTextureIndex <= PESN) && (dAverageTextureIndex >= -PESN)) {
151− dAverageTextureIndex = 1.0;
150+ if ((iAverageTextureIndex <= AQ_PESN) && (iAverageTextureIndex >= -AQ_PESN)) {
151+ iAverageTextureIndex = AQ_INT_MULTIPLY;
152152 }
153153 // motion mb residual map to QP
154154 // texture mb original map to QP
155155 iAverMotionTextureIndexToDeltaQp = 0;
156− dAverageMotionIndex = AVERAGE_TIME_MOTION * dAverageMotionIndex;
156+ iAverageMotionIndex = WELS_DIV_ROUND64(AVERAGE_TIME_MOTION * iAverageMotionIndex, AQ_TIME_INT_MULTIPLY);
157157
158158 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);
160160 } else {
161− dAverageTextureIndex = AVERAGE_TIME_TEXTURE_BITRATEMODE * dAverageTextureIndex;
161+ iAverageTextureIndex = WELS_DIV_ROUND64(AVERAGE_TIME_TEXTURE_BITRATEMODE * iAverageTextureIndex, AQ_TIME_INT_MULTIPLY);
162162 }
163163
164+ int64_t iAQ_EPSN = -((int64_t)AQ_PESN*AQ_TIME_INT_MULTIPLY*AQ_QSTEP_INT_MULTIPLY/AQ_INT_MULTIPLY);
164165 pMotionTexture = m_sAdaptiveQuantParam.pMotionTextureUnit;
165166 for (j = 0; j < iMbHeight; j ++) {
166167 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
170171
171− iMotionTextureIndexToDeltaQp = (int8_t)dLumaTextureDeltaQp;
172+ iMotionTextureIndexToDeltaQp = ((int32_t)(iLumaTextureDeltaQp/(AQ_TIME_INT_MULTIPLY)));
172173
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
176177
177− if ((m_sAdaptiveQuantParam.iAdaptiveQuantMode == AQ_QUALITY_MODE && dLumaMotionDeltaQp < -PESN)
178+ if ((m_sAdaptiveQuantParam.iAdaptiveQuantMode == AQ_QUALITY_MODE && iLumaMotionDeltaQp < iAQ_EPSN)
178179 || (m_sAdaptiveQuantParam.iAdaptiveQuantMode == AQ_BITRATE_MODE)) {
179− iMotionTextureIndexToDeltaQp += (int8_t)dLumaMotionDeltaQp;
180+ iMotionTextureIndexToDeltaQp += ((int32_t)(iLumaMotionDeltaQp/(AQ_TIME_INT_MULTIPLY)));
180181 }
181182
182− m_sAdaptiveQuantParam.pMotionTextureIndexToDeltaQp[j * iMbWidth + i] = iMotionTextureIndexToDeltaQp;
183+ m_sAdaptiveQuantParam.pMotionTextureIndexToDeltaQp[j * iMbWidth + i] = (int8_t)(iMotionTextureIndexToDeltaQp/AQ_QSTEP_INT_MULTIPLY);
183184 iAverMotionTextureIndexToDeltaQp += iMotionTextureIndexToDeltaQp;
184185 pMotionTexture++;
185186 }
186187 }
187− m_sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp = (1.0 * iAverMotionTextureIndexToDeltaQp) / iMbTotalNum;
188+
189+ m_sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp = iAverMotionTextureIndexToDeltaQp / iMbTotalNum;
188190
189191 eReturn = RET_SUCCESS;
190192
@@ -210,7 +212,7 @@ EResult CAdaptiveQuantization::Get (int32_t iType, void* pParam) { · 19 unmodified lines
210212
211213 SAdaptiveQuantizationParam* sAdaptiveQuantParam = (SAdaptiveQuantizationParam*)pParam;
212214
213− sAdaptiveQuantParam->dAverMotionTextureIndexToDeltaQp = m_sAdaptiveQuantParam.dAverMotionTextureIndexToDeltaQp;
215+ sAdaptiveQuantParam->iAverMotionTextureIndexToDeltaQp = m_sAdaptiveQuantParam.iAverMotionTextureIndexToDeltaQp;
214216
215217 return RET_SUCCESS;
216218 }
codec/processing/src/common/util.h+4−0
@@ -58,6 +58,10 @@ WELSVP_NAMESPACE_BEGIN · 57 unmodified lines
5858 #define MAX_HEIGHT (2304)//MAX_FS_LEVEL51 (36864); MAX_FS_LEVEL51*256/4096 = 2304
5959 #define MB_WIDTH_LUMA (16)
6060 #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
6165
6266 #define MB_TYPE_INTRA4x4 0x00000001
6367 #define MB_TYPE_INTRA16x16 0x00000002

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t