History

resolve conflict

volvet committed 12 years ago

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

Showing the changes to codec/processing/src/common/WelsFrameWork.cpp (1 of 124 files). Show all

Unified · Split

codec/processing/src/common/WelsFrameWork.cpp+301−0
@@ -0,0 +1,301 @@
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 "WelsFrameWork.h"
34#include "cpu.h"
35#include "../denoise/denoise.h"
36#include "../downsample/downsample.h"
37#include "../scenechangedetection/SceneChangeDetection.h"
38#include "../vaacalc/vaacalculation.h"
39#include "../backgounddetection/BackgroundDetection.h"
40#include "../adaptivequantization/AdaptiveQuantization.h"
41#include "../complexityanalysis/ComplexityAnalysis.h"
42#include "../imagerotate/imagerotate.h"
43
44
45/* interface API implement */
46
47EResult WELSAPI CreateVpInterface (void** ppCtx, int iVersion) {
48 if (iVersion & 0x8000)
49 return nsWelsVP::CreateSpecificVpInterface ((IWelsVP**)ppCtx);
50 else if (iVersion & 0x7fff)
51 return nsWelsVP::CreateSpecificVpInterface ((IWelsVPc**)ppCtx);
52 else
53 return RET_INVALIDPARAM;
54}
55
56EResult WELSAPI DestroyVpInterface (void* pCtx, int iVersion) {
57 if (iVersion & 0x8000)
58 return nsWelsVP::DestroySpecificVpInterface ((IWelsVP*)pCtx);
59 else if (iVersion & 0x7fff)
60 return nsWelsVP::DestroySpecificVpInterface ((IWelsVPc*)pCtx);
61 else
62 return RET_INVALIDPARAM;
63}
64
65WELSVP_NAMESPACE_BEGIN
66
67///////////////////////////////////////////////////////////////////////
68
69EResult CreateSpecificVpInterface (IWelsVP** ppCtx) {
70 EResult eReturn = RET_FAILED;
71
72 CVpFrameWork* pFr = new CVpFrameWork (1, eReturn);
73 if (pFr) {
74 *ppCtx = (IWelsVP*)pFr;
75 eReturn = RET_SUCCESS;
76 }
77
78 return eReturn;
79}
80
81EResult DestroySpecificVpInterface (IWelsVP* pCtx) {
82 _SafeDelete (pCtx);
83
84 return RET_SUCCESS;
85}
86
87///////////////////////////////////////////////////////////////////////////////
88
89CVpFrameWork::CVpFrameWork (uint32_t uiThreadsNum, EResult& eReturn) {
90 int32_t iCoreNum = 1;
91#ifndef X86_ASM
92 uint32_t uiCPUFlag = 0;
93#else
94 uint32_t uiCPUFlag = WelsCPUFeatureDetect (&iCoreNum);
95#endif
96
97 for (int32_t i = 0; i < MAX_STRATEGY_NUM; i++) {
98 IStrategy* pStrategy = m_pStgChain[i];
99 pStrategy = CreateStrategy (WelsStaticCast (EMethods, i + 1), uiCPUFlag);
100 m_pStgChain[i] = pStrategy;
101 }
102
103 WelsMutexInit (&m_mutes);
104
105 eReturn = RET_SUCCESS;
106}
107
108CVpFrameWork::~CVpFrameWork() {
109 for (int32_t i = 0; i < MAX_STRATEGY_NUM; i++) {
110 if (m_pStgChain[i]) {
111 Uninit (m_pStgChain[i]->m_eMethod);
112 _SafeDelete (m_pStgChain[i]);
113 }
114 }
115
116 WelsMutexDestroy (&m_mutes);
117}
118
119EResult CVpFrameWork::Init (int32_t iType, void* pCfg) {
120 EResult eReturn = RET_SUCCESS;
121 int32_t iCurIdx = WelsStaticCast (int32_t, WelsVpGetValidMethod (iType)) - 1;
122
123 Uninit (iType);
124
125 WelsMutexLock (&m_mutes);
126
127 IStrategy* pStrategy = m_pStgChain[iCurIdx];
128 if (pStrategy)
129 eReturn = pStrategy->Init (0, pCfg);
130
131 WelsMutexUnlock (&m_mutes);
132
133 return eReturn;
134}
135
136EResult CVpFrameWork::Uninit (int32_t iType) {
137 EResult eReturn = RET_SUCCESS;
138 int32_t iCurIdx = WelsStaticCast (int32_t, WelsVpGetValidMethod (iType)) - 1;
139
140 WelsMutexLock (&m_mutes);
141
142 IStrategy* pStrategy = m_pStgChain[iCurIdx];
143 if (pStrategy)
144 eReturn = pStrategy->Uninit (0);
145
146 WelsMutexUnlock (&m_mutes);
147
148 return eReturn;
149}
150
151EResult CVpFrameWork::Flush (int32_t iType) {
152 EResult eReturn = RET_SUCCESS;
153
154 return eReturn;
155}
156
157EResult CVpFrameWork::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pDstPixMap) {
158 EResult eReturn = RET_NOTSUPPORTED;
159 EMethods eMethod = WelsVpGetValidMethod (iType);
160 int32_t iCurIdx = WelsStaticCast (int32_t, eMethod) - 1;
161 SPixMap sSrcPic;
162 SPixMap sDstPic;
163 memset (&sSrcPic, 0, sizeof (sSrcPic)); // confirmed_safe_unsafe_usage
164 memset (&sDstPic, 0, sizeof (sDstPic)); // confirmed_safe_unsafe_usage
165
166 if (pSrcPixMap) sSrcPic = *pSrcPixMap;
167 if (pDstPixMap) sDstPic = *pDstPixMap;
168 if (!CheckValid (eMethod, sSrcPic, sDstPic))
169 return RET_INVALIDPARAM;
170
171 WelsMutexLock (&m_mutes);
172
173 IStrategy* pStrategy = m_pStgChain[iCurIdx];
174 if (pStrategy)
175 eReturn = pStrategy->Process (0, &sSrcPic, &sDstPic);
176
177 WelsMutexUnlock (&m_mutes);
178
179 return eReturn;
180}
181
182EResult CVpFrameWork::Get (int32_t iType, void* pParam) {
183 EResult eReturn = RET_SUCCESS;
184 int32_t iCurIdx = WelsStaticCast (int32_t, WelsVpGetValidMethod (iType)) - 1;
185
186 if (!pParam)
187 return RET_INVALIDPARAM;
188
189 WelsMutexLock (&m_mutes);
190
191 IStrategy* pStrategy = m_pStgChain[iCurIdx];
192 if (pStrategy)
193 eReturn = pStrategy->Get (0, pParam);
194
195 WelsMutexUnlock (&m_mutes);
196
197 return eReturn;
198}
199
200EResult CVpFrameWork::Set (int32_t iType, void* pParam) {
201 EResult eReturn = RET_SUCCESS;
202 int32_t iCurIdx = WelsStaticCast (int32_t, WelsVpGetValidMethod (iType)) - 1;
203
204 if (!pParam)
205 return RET_INVALIDPARAM;
206
207 WelsMutexLock (&m_mutes);
208
209 IStrategy* pStrategy = m_pStgChain[iCurIdx];
210 if (pStrategy)
211 eReturn = pStrategy->Set (0, pParam);
212
213 WelsMutexUnlock (&m_mutes);
214
215 return eReturn;
216}
217
218EResult CVpFrameWork::SpecialFeature (int32_t iType, void* pIn, void* pOut) {
219 EResult eReturn = RET_SUCCESS;
220
221 return eReturn;
222}
223
224bool_t CVpFrameWork::CheckValid (EMethods eMethod, SPixMap& pSrcPixMap, SPixMap& pDstPixMap) {
225 bool_t eReturn = FALSE;
226
227 if (eMethod == METHOD_NULL)
228 goto exit;
229
230 if (eMethod != METHOD_COLORSPACE_CONVERT) {
231 if (pSrcPixMap.pPixel[0]) {
232 if (pSrcPixMap.eFormat != VIDEO_FORMAT_I420 && pSrcPixMap.eFormat != VIDEO_FORMAT_YV12)
233 goto exit;
234 }
235 if (pSrcPixMap.pPixel[0] && pDstPixMap.pPixel[0]) {
236 if (pDstPixMap.eFormat != pSrcPixMap.eFormat)
237 goto exit;
238 }
239 }
240
241 if (pSrcPixMap.pPixel[0]) {
242 if (pSrcPixMap.sRect.iRectWidth <= 0 || pSrcPixMap.sRect.iRectWidth > MAX_WIDTH || pSrcPixMap.sRect.iRectHeight <= 0
243 || pSrcPixMap.sRect.iRectHeight > MAX_HEIGHT)
244 goto exit;
245 if (pSrcPixMap.sRect.iRectTop >= pSrcPixMap.sRect.iRectHeight
246 || pSrcPixMap.sRect.iRectLeft >= pSrcPixMap.sRect.iRectWidth || pSrcPixMap.sRect.iRectWidth > pSrcPixMap.iStride[0])
247 goto exit;
248 }
249 if (pDstPixMap.pPixel[0]) {
250 if (pDstPixMap.sRect.iRectWidth <= 0 || pDstPixMap.sRect.iRectWidth > MAX_WIDTH || pDstPixMap.sRect.iRectHeight <= 0
251 || pDstPixMap.sRect.iRectHeight > MAX_HEIGHT)
252 goto exit;
253 if (pDstPixMap.sRect.iRectTop >= pDstPixMap.sRect.iRectHeight
254 || pDstPixMap.sRect.iRectLeft >= pDstPixMap.sRect.iRectWidth || pDstPixMap.sRect.iRectWidth > pDstPixMap.iStride[0])
255 goto exit;
256 }
257 eReturn = TRUE;
258
259exit:
260 return eReturn;
261}
262
263IStrategy* CVpFrameWork::CreateStrategy (EMethods m_eMethod, int32_t iCpuFlag) {
264 IStrategy* pStrategy = NULL;
265
266 switch (m_eMethod) {
267 case METHOD_COLORSPACE_CONVERT:
268 //not support yet
269 break;
270 case METHOD_DENOISE:
271 pStrategy = WelsDynamicCast (IStrategy*, new CDenoiser (iCpuFlag));
272 break;
273 case METHOD_SCENE_CHANGE_DETECTION:
274 pStrategy = WelsDynamicCast (IStrategy*, new CSceneChangeDetection (iCpuFlag));
275 break;
276 case METHOD_DOWNSAMPLE:
277 pStrategy = WelsDynamicCast (IStrategy*, new CDownsampling (iCpuFlag));
278 break;
279 case METHOD_VAA_STATISTICS:
280 pStrategy = WelsDynamicCast (IStrategy*, new CVAACalculation (iCpuFlag));
281 break;
282 case METHOD_BACKGROUND_DETECTION:
283 pStrategy = WelsDynamicCast (IStrategy*, new CBackgroundDetection (iCpuFlag));
284 break;
285 case METHOD_ADAPTIVE_QUANT:
286 pStrategy = WelsDynamicCast (IStrategy*, new CAdaptiveQuantization (iCpuFlag));
287 break;
288 case METHOD_COMPLEXITY_ANALYSIS:
289 pStrategy = WelsDynamicCast (IStrategy*, new CComplexityAnalysis (iCpuFlag));
290 break;
291 case METHOD_IMAGE_ROTATE:
292 pStrategy = WelsDynamicCast (IStrategy*, new CImageRotating (iCpuFlag));
293 break;
294 default:
295 break;
296 }
297
298 return pStrategy;
299}
300
301WELSVP_NAMESPACE_END

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