History

resolve conflict

volvet committed 12 years ago

Commit ec84f4b1 parent 3958118124 files · +15352 −15696Browse files

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

Unified · Split

2 files
  1. codec/processing/src/complexityanalysis/ComplexityAnalysis.cpp +304 −0
  2. codec/processing/src/complexityanalysis/ComplexityAnalysis.h +83 −0
codec/processing/src/complexityanalysis/ComplexityAnalysis.cpp+304−0
@@ -0,0 +1,304 @@
1/*!
2 * \copy
3 * Copyright (c) 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
33#include "ComplexityAnalysis.h"
34#include "../common/cpu.h"
35
36WELSVP_NAMESPACE_BEGIN
37
38
39///////////////////////////////////////////////////////////////////////////////////////////////////////////////
40
41CComplexityAnalysis::CComplexityAnalysis (int32_t iCpuFlag) {
42 m_eMethod = METHOD_COMPLEXITY_ANALYSIS;
43 m_pfGomSad = NULL;
44 WelsMemset (&m_sComplexityAnalysisParam, 0, sizeof (m_sComplexityAnalysisParam));
45}
46
47CComplexityAnalysis::~CComplexityAnalysis() {
48}
49
50EResult CComplexityAnalysis::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
51 EResult eReturn = RET_SUCCESS;
52
53 switch (m_sComplexityAnalysisParam.iComplexityAnalysisMode) {
54 case FRAME_SAD:
55 AnalyzeFrameComplexityViaSad (pSrcPixMap, pRefPixMap);
56 break;
57 case GOM_SAD:
58 AnalyzeGomComplexityViaSad (pSrcPixMap, pRefPixMap);
59 break;
60 case GOM_VAR:
61 AnalyzeGomComplexityViaVar (pSrcPixMap, pRefPixMap);
62 break;
63 default:
64 eReturn = RET_INVALIDPARAM;
65 break;
66 }
67
68 return eReturn;
69}
70
71
72EResult CComplexityAnalysis::Set (int32_t iType, void* pParam) {
73 if (pParam == NULL) {
74 return RET_INVALIDPARAM;
75 }
76
77 m_sComplexityAnalysisParam = * (SComplexityAnalysisParam*)pParam;
78
79 return RET_SUCCESS;
80}
81
82EResult CComplexityAnalysis::Get (int32_t iType, void* pParam) {
83 if (pParam == NULL) {
84 return RET_INVALIDPARAM;
85 }
86
87 SComplexityAnalysisParam* sComplexityAnalysisParam = (SComplexityAnalysisParam*)pParam;
88
89 sComplexityAnalysisParam->iFrameComplexity = m_sComplexityAnalysisParam.iFrameComplexity;
90
91 return RET_SUCCESS;
92}
93
94
95///////////////////////////////////////////////////////////////////////////////////////////////
96void CComplexityAnalysis::AnalyzeFrameComplexityViaSad (SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
97 SVAACalcResult* pVaaCalcResults = NULL;
98 pVaaCalcResults = m_sComplexityAnalysisParam.pCalcResult;
99
100 m_sComplexityAnalysisParam.iFrameComplexity = pVaaCalcResults->iFrameSad;
101
102 if (m_sComplexityAnalysisParam.iCalcBgd) { //BGD control
103 m_sComplexityAnalysisParam.iFrameComplexity = (int32_t)GetFrameSadExcludeBackground (pSrcPixMap, pRefPixMap);
104 }
105}
106
107int32_t CComplexityAnalysis::GetFrameSadExcludeBackground (SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
108 int32_t iWidth = pSrcPixMap->sRect.iRectWidth;
109 int32_t iHeight = pSrcPixMap->sRect.iRectHeight;
110 int32_t iMbWidth = iWidth >> 4;
111 int32_t iMbHeight = iHeight >> 4;
112 int32_t iMbNum = iMbWidth * iMbHeight;
113
114 int32_t iMbNumInGom = m_sComplexityAnalysisParam.iMbNumInGom;
115 int32_t iGomMbNum = (iMbNum + iMbNumInGom - 1) / iMbNumInGom;
116 int32_t iGomMbStartIndex = 0, iGomMbEndIndex = 0;
117
118 uint8_t* pBackgroundMbFlag = (uint8_t*)m_sComplexityAnalysisParam.pBackgroundMbFlag;
119 uint32_t* uiRefMbType = (uint32_t*)m_sComplexityAnalysisParam.uiRefMbType;
120 SVAACalcResult* pVaaCalcResults = m_sComplexityAnalysisParam.pCalcResult;
121 int32_t* pGomForegroundBlockNum = m_sComplexityAnalysisParam.pGomForegroundBlockNum;
122
123 uint32_t uiFrameSad = 0;
124 for (int32_t j = 0; j < iGomMbNum; j ++) {
125 iGomMbStartIndex = j * iMbNumInGom;
126 iGomMbEndIndex = WELS_MIN ((j + 1) * iMbNumInGom, iMbNum);
127
128 for (int32_t i = iGomMbStartIndex; i < iGomMbEndIndex; i ++) {
129 if (pBackgroundMbFlag[i] == 0 || IS_INTRA (uiRefMbType[i])) {
130 pGomForegroundBlockNum[j]++;
131 uiFrameSad += pVaaCalcResults->pSad8x8[i][0];
132 uiFrameSad += pVaaCalcResults->pSad8x8[i][1];
133 uiFrameSad += pVaaCalcResults->pSad8x8[i][2];
134 uiFrameSad += pVaaCalcResults->pSad8x8[i][3];
135 }
136 }
137 }
138
139 return (uiFrameSad);
140}
141
142
143void InitGomSadFunc (PGOMSadFunc& pfGomSad, uint8_t iCalcBgd) {
144 pfGomSad = GomSampleSad;
145
146 if (iCalcBgd) {
147 pfGomSad = GomSampleSadExceptBackground;
148 }
149}
150
151void GomSampleSad (uint32_t* pGomSad, int32_t* pGomForegroundBlockNum, int32_t* pSad8x8, uint8_t pBackgroundMbFlag) {
152 (*pGomForegroundBlockNum) ++;
153 *pGomSad += pSad8x8[0];
154 *pGomSad += pSad8x8[1];
155 *pGomSad += pSad8x8[2];
156 *pGomSad += pSad8x8[3];
157}
158
159void GomSampleSadExceptBackground (uint32_t* pGomSad, int32_t* pGomForegroundBlockNum, int32_t* pSad8x8,
160 uint8_t pBackgroundMbFlag) {
161 if (pBackgroundMbFlag == 0) {
162 (*pGomForegroundBlockNum) ++;
163 *pGomSad += pSad8x8[0];
164 *pGomSad += pSad8x8[1];
165 *pGomSad += pSad8x8[2];
166 *pGomSad += pSad8x8[3];
167 }
168}
169
170void CComplexityAnalysis::AnalyzeGomComplexityViaSad (SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
171 int32_t iWidth = pSrcPixMap->sRect.iRectWidth;
172 int32_t iHeight = pSrcPixMap->sRect.iRectHeight;
173 int32_t iMbWidth = iWidth >> 4;
174 int32_t iMbHeight = iHeight >> 4;
175 int32_t iMbNum = iMbWidth * iMbHeight;
176
177 int32_t iMbNumInGom = m_sComplexityAnalysisParam.iMbNumInGom;
178 int32_t iGomMbNum = (iMbNum + iMbNumInGom - 1) / iMbNumInGom;
179
180 int32_t iGomMbStartIndex = 0, iGomMbEndIndex = 0, iGomMbRowNum = 0;
181 int32_t iMbStartIndex = 0, iMbEndIndex = 0;
182 int32_t iStartSampleIndex = 0;
183
184 uint8_t* pBackgroundMbFlag = (uint8_t*)m_sComplexityAnalysisParam.pBackgroundMbFlag;
185 uint32_t* uiRefMbType = (uint32_t*)m_sComplexityAnalysisParam.uiRefMbType;
186 SVAACalcResult* pVaaCalcResults = m_sComplexityAnalysisParam.pCalcResult;
187 int32_t* pGomForegroundBlockNum = (int32_t*)m_sComplexityAnalysisParam.pGomForegroundBlockNum;
188 int32_t* pGomComplexity = (int32_t*)m_sComplexityAnalysisParam.pGomComplexity;
189
190 uint8_t* pRefY = NULL, *pSrcY = NULL;
191 int32_t iRefStride = 0, iCurStride = 0;
192
193 uint8_t* pRefTmp = NULL, *pCurTmp = NULL;
194 uint32_t uiGomSad = 0, uiFrameSad = 0;
195
196 pRefY = (uint8_t*)pRefPixMap->pPixel[0];
197 pSrcY = (uint8_t*)pSrcPixMap->pPixel[0];
198
199 iRefStride = pRefPixMap->iStride[0];
200 iCurStride = pSrcPixMap->iStride[0];
201
202 InitGomSadFunc (m_pfGomSad, m_sComplexityAnalysisParam.iCalcBgd);
203
204 for (int32_t j = 0; j < iGomMbNum; j ++) {
205 uiGomSad = 0;
206
207 iGomMbStartIndex = j * iMbNumInGom;
208 iGomMbEndIndex = WELS_MIN ((j + 1) * iMbNumInGom, iMbNum);
209 iGomMbRowNum = (iGomMbEndIndex + iMbWidth - 1) / iMbWidth - iGomMbStartIndex / iMbWidth;
210
211 iMbStartIndex = iGomMbStartIndex;
212 iMbEndIndex = WELS_MIN ((iMbStartIndex / iMbWidth + 1) * iMbWidth, iGomMbEndIndex);
213
214 iStartSampleIndex = (iMbStartIndex / iMbWidth) * MB_WIDTH_LUMA * iRefStride + (iMbStartIndex % iMbWidth) *
215 MB_WIDTH_LUMA;
216
217 do {
218 pRefTmp = pRefY + iStartSampleIndex;
219 pCurTmp = pSrcY + iStartSampleIndex;
220
221 for (int32_t i = iMbStartIndex; i < iMbEndIndex; i ++) {
222 m_pfGomSad (&uiGomSad, pGomForegroundBlockNum + j, pVaaCalcResults->pSad8x8[i], pBackgroundMbFlag[i]
223 && !IS_INTRA (uiRefMbType[i]));
224 }
225
226 iMbStartIndex = iMbEndIndex;
227 iMbEndIndex = WELS_MIN (iMbEndIndex + iMbWidth , iGomMbEndIndex);
228
229 iStartSampleIndex = (iMbStartIndex / iMbWidth) * MB_WIDTH_LUMA * iRefStride + (iMbStartIndex % iMbWidth) *
230 MB_WIDTH_LUMA;
231
232 } while (--iGomMbRowNum);
233
234 pGomComplexity[j] = uiGomSad;
235 uiFrameSad += pGomComplexity[j];
236 }
237
238 m_sComplexityAnalysisParam.iFrameComplexity = uiFrameSad;
239}
240
241
242void CComplexityAnalysis::AnalyzeGomComplexityViaVar (SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
243 int32_t iWidth = pSrcPixMap->sRect.iRectWidth;
244 int32_t iHeight = pSrcPixMap->sRect.iRectHeight;
245 int32_t iMbWidth = iWidth >> 4;
246 int32_t iMbHeight = iHeight >> 4;
247 int32_t iMbNum = iMbWidth * iMbHeight;
248
249 int32_t iMbNumInGom = m_sComplexityAnalysisParam.iMbNumInGom;
250 int32_t iGomMbNum = (iMbNum + iMbNumInGom - 1) / iMbNumInGom;
251 int32_t iGomSampleNum = 0;
252
253 int32_t iGomMbStartIndex = 0, iGomMbEndIndex = 0, iGomMbRowNum = 0;
254 int32_t iMbStartIndex = 0, iMbEndIndex = 0;
255 int32_t iStartSampleIndex = 0;
256
257 SVAACalcResult* pVaaCalcResults = m_sComplexityAnalysisParam.pCalcResult;
258 int32_t* pGomComplexity = (int32_t*)m_sComplexityAnalysisParam.pGomComplexity;
259
260 uint8_t* pSrcY = NULL;
261 int32_t iCurStride = 0;
262
263 uint8_t* pCurTmp = NULL;
264 uint32_t uiSampleSum = 0, uiSquareSum = 0;
265
266 pSrcY = (uint8_t*)pSrcPixMap->pPixel[0];
267 iCurStride = pSrcPixMap->iStride[0];
268
269 for (int32_t j = 0; j < iGomMbNum; j ++) {
270 uiSampleSum = 0;
271 uiSquareSum = 0;
272
273 iGomMbStartIndex = j * iMbNumInGom;
274 iGomMbEndIndex = WELS_MIN ((j + 1) * iMbNumInGom, iMbNum);
275 iGomMbRowNum = (iGomMbEndIndex + iMbWidth - 1) / iMbWidth - iGomMbStartIndex / iMbWidth;
276
277 iMbStartIndex = iGomMbStartIndex;
278 iMbEndIndex = WELS_MIN ((iMbStartIndex / iMbWidth + 1) * iMbWidth, iGomMbEndIndex);
279
280 iStartSampleIndex = (iMbStartIndex / iMbWidth) * MB_WIDTH_LUMA * iCurStride + (iMbStartIndex % iMbWidth) *
281 MB_WIDTH_LUMA;
282 iGomSampleNum = (iMbEndIndex - iMbStartIndex) * MB_WIDTH_LUMA * MB_WIDTH_LUMA;
283
284 do {
285 pCurTmp = pSrcY + iStartSampleIndex;
286
287 for (int32_t i = iMbStartIndex; i < iMbEndIndex; i ++) {
288 uiSampleSum += pVaaCalcResults->pSum16x16[i];
289 uiSquareSum += pVaaCalcResults->pSumOfSquare16x16[i];
290 }
291
292 iMbStartIndex = iMbEndIndex;
293 iMbEndIndex = WELS_MIN (iMbEndIndex + iMbWidth, iGomMbEndIndex);
294
295 iStartSampleIndex = (iMbStartIndex / iMbWidth) * MB_WIDTH_LUMA * iCurStride + (iMbStartIndex % iMbWidth) *
296 MB_WIDTH_LUMA;
297 } while (--iGomMbRowNum);
298
299 pGomComplexity[j] = uiSquareSum - (uiSampleSum * uiSampleSum / iGomSampleNum);
300 }
301}
302
303
304WELSVP_NAMESPACE_END
codec/processing/src/complexityanalysis/ComplexityAnalysis.h+83−0
@@ -0,0 +1,83 @@
1/*!
2 * \copy
3 * Copyright (c) 2011-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* \file : ComplexityAnalysis.h
32*
33* \brief : complexity analysis class of wels video processor class
34*
35* \date : 2011/03/28
36*
37* \description : 1. rewrite the package code of complexity analysis class
38*
39*************************************************************************************
40*/
41
42#ifndef WELSVP_COMPLEXITYANALYSIS_H
43#define WELSVP_COMPLEXITYANALYSIS_H
44
45#include "../common/util.h"
46#include "../common/memory.h"
47#include "../common/WelsFrameWork.h"
48#include "../../interface/IWelsVP.h"
49
50WELSVP_NAMESPACE_BEGIN
51
52typedef void (GOMSadFunc) (uint32_t* pGomSad, int32_t* pGomForegroundBlockNum, int32_t* pSad8x8,
53 uint8_t pBackgroundMbFlag);
54
55typedef GOMSadFunc* PGOMSadFunc;
56
57GOMSadFunc GomSampleSad;
58GOMSadFunc GomSampleSadExceptBackground;
59
60class CComplexityAnalysis : public IStrategy {
61 public:
62 CComplexityAnalysis (int32_t iCpuFlag);
63 ~CComplexityAnalysis();
64
65 EResult Process (int32_t iType, SPixMap* pSrc, SPixMap* pRef);
66 EResult Set (int32_t iType, void* pParam);
67 EResult Get (int32_t iType, void* pParam);
68
69 private:
70 void AnalyzeFrameComplexityViaSad (SPixMap* pSrc, SPixMap* pRef);
71 int32_t GetFrameSadExcludeBackground (SPixMap* pSrc, SPixMap* pRef);
72
73 void AnalyzeGomComplexityViaSad (SPixMap* pSrc, SPixMap* pRef);
74 void AnalyzeGomComplexityViaVar (SPixMap* pSrc, SPixMap* pRef);
75
76 private:
77 PGOMSadFunc m_pfGomSad;
78 SComplexityAnalysisParam m_sComplexityAnalysisParam;
79};
80
81WELSVP_NAMESPACE_END
82
83#endif

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