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.pfVAACalcSadBgd = VAACalcSadBgd_lsx;
110 }
111 #endif//HAVE_LSX
112 }
113
Process(int32_t iType,SPixMap * pSrcPixMap,SPixMap * pRefPixMap)114 EResult CVAACalculation::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
115 uint8_t* pCurData = (uint8_t*)pSrcPixMap->pPixel[0];
116 uint8_t* pRefData = (uint8_t*)pRefPixMap->pPixel[0];
117 int32_t iPicWidth = pSrcPixMap->sRect.iRectWidth;
118 int32_t iPicHeight = pSrcPixMap->sRect.iRectHeight;
119 int32_t iPicStride = pSrcPixMap->iStride[0];
120
121 SVAACalcResult* pResult = m_sCalcParam.pCalcResult;
122
123 if (pCurData == NULL || pRefData == NULL) {
124 return RET_INVALIDPARAM;
125 }
126
127 pResult->pCurY = pCurData;
128 pResult->pRefY = pRefData;
129 if (m_sCalcParam.iCalcBgd) {
130 if (m_sCalcParam.iCalcSsd) {
131 m_sVaaFuncs.pfVAACalcSadSsdBgd (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
132 (int32_t*)pResult->pSad8x8, pResult->pSum16x16, pResult->pSumOfSquare16x16, pResult->pSsd16x16,
133 (int32_t*)pResult->pSumOfDiff8x8, (uint8_t*)pResult->pMad8x8);
134 } else {
135 m_sVaaFuncs.pfVAACalcSadBgd (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
136 (int32_t*) (pResult->pSad8x8), (int32_t*) (pResult->pSumOfDiff8x8), (uint8_t*)pResult->pMad8x8);
137 }
138 } else {
139 if (m_sCalcParam.iCalcSsd) {
140 m_sVaaFuncs.pfVAACalcSadSsd (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
141 (int32_t*)pResult->pSad8x8, pResult->pSum16x16, pResult->pSumOfSquare16x16, pResult->pSsd16x16);
142 } else {
143 if (m_sCalcParam.iCalcVar) {
144 m_sVaaFuncs.pfVAACalcSadVar (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
145 (int32_t*)pResult->pSad8x8, pResult->pSum16x16, pResult->pSumOfSquare16x16);
146 } else {
147 m_sVaaFuncs.pfVAACalcSad (pCurData, pRefData, iPicWidth, iPicHeight, iPicStride, &pResult->iFrameSad,
148 (int32_t*)pResult->pSad8x8);
149 }
150 }
151 }
152
153 return RET_SUCCESS;
154 }
155
Set(int32_t iType,void * pParam)156 EResult CVAACalculation::Set (int32_t iType, void* pParam) {
157 if (pParam == NULL || ((SVAACalcParam*)pParam)->pCalcResult == NULL) {
158 return RET_INVALIDPARAM;
159 }
160
161 m_sCalcParam = * (SVAACalcParam*)pParam;
162
163 return RET_SUCCESS;
164 }
165
166
167 WELSVP_NAMESPACE_END
168