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 "vaacalculation.h"
34 #include "cpu.h"
35
36 WELSVP_NAMESPACE_BEGIN
37
38
39 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
40
CVAACalculation(int32_t iCpuFlag)41 CVAACalculation::CVAACalculation (int32_t iCpuFlag) {
42 m_iCPUFlag = iCpuFlag;
43 m_eMethod = METHOD_VAA_STATISTICS;
44
45 WelsMemset (&m_sCalcParam, 0, sizeof (m_sCalcParam));
46 WelsMemset (&m_sVaaFuncs, 0, sizeof (m_sVaaFuncs));
47 InitVaaFuncs (m_sVaaFuncs, m_iCPUFlag);
48 }
49
~CVAACalculation()50 CVAACalculation::~CVAACalculation() {
51 }
52
InitVaaFuncs(SVaaFuncs & sVaaFuncs,int32_t iCpuFlag)53 void CVAACalculation::InitVaaFuncs (SVaaFuncs& sVaaFuncs, int32_t iCpuFlag) {
54 sVaaFuncs.pfVAACalcSad = VAACalcSad_c;
55 sVaaFuncs.pfVAACalcSadBgd = VAACalcSadBgd_c;
56 sVaaFuncs.pfVAACalcSadSsd = VAACalcSadSsd_c;
57 sVaaFuncs.pfVAACalcSadSsdBgd = VAACalcSadSsdBgd_c;
58 sVaaFuncs.pfVAACalcSadVar = VAACalcSadVar_c;
59 #ifdef X86_ASM
60 if ((iCpuFlag & WELS_CPU_SSE2) == WELS_CPU_SSE2) {
61 sVaaFuncs.pfVAACalcSad = VAACalcSad_sse2;
62 sVaaFuncs.pfVAACalcSadBgd = VAACalcSadBgd_sse2;
63 sVaaFuncs.pfVAACalcSadSsd = VAACalcSadSsd_sse2;
64 sVaaFuncs.pfVAACalcSadSsdBgd = VAACalcSadSsdBgd_sse2;
65 sVaaFuncs.pfVAACalcSadVar = VAACalcSadVar_sse2;
66 }
67 #ifdef HAVE_AVX2
68 if (iCpuFlag & WELS_CPU_AVX2) {
69 sVaaFuncs.pfVAACalcSad = VAACalcSad_avx2;
70 sVaaFuncs.pfVAACalcSadBgd = VAACalcSadBgd_avx2;
71 sVaaFuncs.pfVAACalcSadSsd = VAACalcSadSsd_avx2;
72 sVaaFuncs.pfVAACalcSadSsdBgd = VAACalcSadSsdBgd_avx2;
73 sVaaFuncs.pfVAACalcSadVar = VAACalcSadVar_avx2;
74 }
75 #endif
76 #endif//X86_ASM
77 #ifdef HAVE_NEON
78 if ((iCpuFlag & WELS_CPU_NEON) == WELS_CPU_NEON) {
79 sVaaFuncs.pfVAACalcSad = VAACalcSad_neon;
80 sVaaFuncs.pfVAACalcSadBgd = VAACalcSadBgd_neon;
81 sVaaFuncs.pfVAACalcSadSsd = VAACalcSadSsd_neon;
82 sVaaFuncs.pfVAACalcSadSsdBgd = VAACalcSadSsdBgd_neon;
83 sVaaFuncs.pfVAACalcSadVar = VAACalcSadVar_neon;
84 }
85 #endif//HAVE_NEON
86
87 #ifdef HAVE_NEON_AARCH64
88 if ((iCpuFlag & WELS_CPU_NEON) == WELS_CPU_NEON) {
89 sVaaFuncs.pfVAACalcSad = VAACalcSad_AArch64_neon;
90 sVaaFuncs.pfVAACalcSadBgd = VAACalcSadBgd_AArch64_neon;
91 sVaaFuncs.pfVAACalcSadSsd = VAACalcSadSsd_AArch64_neon;
92 sVaaFuncs.pfVAACalcSadSsdBgd = VAACalcSadSsdBgd_AArch64_neon;
93 sVaaFuncs.pfVAACalcSadVar = VAACalcSadVar_AArch64_neon;
94 }
95 #endif//HAVE_NEON_AARCH64
96
97 #ifdef HAVE_MMI
98 if ((iCpuFlag & WELS_CPU_MMI) == WELS_CPU_MMI) {
99 sVaaFuncs.pfVAACalcSad = VAACalcSad_mmi;
100 sVaaFuncs.pfVAACalcSadBgd = VAACalcSadBgd_mmi;
101 sVaaFuncs.pfVAACalcSadSsd = VAACalcSadSsd_mmi;
102 sVaaFuncs.pfVAACalcSadSsdBgd = VAACalcSadSsdBgd_mmi;
103 sVaaFuncs.pfVAACalcSadVar = VAACalcSadVar_mmi;
104 }
105 #endif//HAVE_MMI
106
107 #ifdef HAVE_LSX
108 if ((iCpuFlag & WELS_CPU_LSX) == WELS_CPU_LSX) {
109 sVaaFuncs.pfVAACalcSad = VAACalcSad_lsx;
110 sVaaFuncs.pfVAACalcSadBgd = VAACalcSadBgd_lsx;
111 }
112 #endif//HAVE_LSX
113 #ifdef HAVE_LASX
114 if ((iCpuFlag & WELS_CPU_LASX) == WELS_CPU_LASX) {
115 sVaaFuncs.pfVAACalcSadBgd = VAACalcSadBgd_lasx;
116 }
117 #endif//HAVE_LASX
118 }
119
Process(int32_t iType,SPixMap * pSrcPixMap,SPixMap * pRefPixMap)120 EResult CVAACalculation::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
121 uint8_t* pCurData = (uint8_t*)pSrcPixMap->pPixel[0];
122 uint8_t* pRefData = (uint8_t*)pRefPixMap->pPixel[0];
123 int32_t iPicWidth = pSrcPixMap->sRect.iRectWidth;
124 int32_t iPicHeight = pSrcPixMap->sRect.iRectHeight;
125 int32_t iPicStride = pSrcPixMap->iStride[0];
126
127 SVAACalcResult* pResult = m_sCalcParam.pCalcResult;
128
129 if (pCurData == NULL || pRefData == NULL) {
130 return RET_INVALIDPARAM;
131 }
132
133 pResult->pCurY = pCurData;
134 pResult->pRefY = pRefData;
135 if (m_sCalcParam.iCalcBgd) {
136 if (m_sCalcParam.iCalcSsd) {
137 m_sVaaFuncs.pfVAACalcSadSsdBgd (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
138 (int32_t*)pResult->pSad8x8, pResult->pSum16x16, pResult->pSumOfSquare16x16, pResult->pSsd16x16,
139 (int32_t*)pResult->pSumOfDiff8x8, (uint8_t*)pResult->pMad8x8);
140 } else {
141 m_sVaaFuncs.pfVAACalcSadBgd (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
142 (int32_t*) (pResult->pSad8x8), (int32_t*) (pResult->pSumOfDiff8x8), (uint8_t*)pResult->pMad8x8);
143 }
144 } else {
145 if (m_sCalcParam.iCalcSsd) {
146 m_sVaaFuncs.pfVAACalcSadSsd (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
147 (int32_t*)pResult->pSad8x8, pResult->pSum16x16, pResult->pSumOfSquare16x16, pResult->pSsd16x16);
148 } else {
149 if (m_sCalcParam.iCalcVar) {
150 m_sVaaFuncs.pfVAACalcSadVar (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
151 (int32_t*)pResult->pSad8x8, pResult->pSum16x16, pResult->pSumOfSquare16x16);
152 } else {
153 m_sVaaFuncs.pfVAACalcSad (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
154 (int32_t*)pResult->pSad8x8);
155 }
156 }
157 }
158
159 return RET_SUCCESS;
160 }
161
Set(int32_t iType,void * pParam)162 EResult CVAACalculation::Set (int32_t iType, void* pParam) {
163 if (pParam == NULL || ((SVAACalcParam*)pParam)->pCalcResult == NULL) {
164 return RET_INVALIDPARAM;
165 }
166
167 m_sCalcParam = * (SVAACalcParam*)pParam;
168
169 return RET_SUCCESS;
170 }
171
172
173 WELSVP_NAMESPACE_END
174