History

Initial Commit

Ethan Hugg committed 12 years ago

Commit 70e5e621 parent bd509b2308 files · +97095 −-5Browse files

Showing the changes to codec/decoder/core/src/mv_pred.cpp (1 of 308 files). Show all

Unified · Split

codec/decoder/core/src/mv_pred.cpp+251−0
@@ -0,0 +1,251 @@
1+/*!
2+ * \copy
3+ * Copyright (c) 2009-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+ * \file mv_pred.c
33+ *
34+ * \brief Get MV predictor and update motion vector of mb cache
35+ *
36+ * \date 05/22/2009 Created
37+ *
38+ *************************************************************************************
39+ */
40+
41+#include "mv_pred.h"
42+#include "ls_defines.h"
43+#include "mb_cache.h"
44+
45+namespace WelsDec {
46+
47+//basic iMVs prediction unit for iMVs partition width (4, 2, 1)
48+void_t PredMv(int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
49+ int32_t iPartIdx, int32_t iPartWidth, int8_t iRef, int16_t iMVP[2])
50+{
51+ const uint8_t kuiLeftIdx = g_kuiCache30ScanIdx[iPartIdx] - 1;
52+ const uint8_t kuiTopIdx = g_kuiCache30ScanIdx[iPartIdx] - 6;
53+ const uint8_t kuiRightTopIdx= kuiTopIdx + iPartWidth;
54+ const uint8_t kuiLeftTopIdx = kuiTopIdx - 1;
55+
56+ const int8_t kiLeftRef = iRefIndex[0][kuiLeftIdx];
57+ const int8_t kiTopRef = iRefIndex[0][ kuiTopIdx];
58+ const int8_t kiRightTopRef = iRefIndex[0][kuiRightTopIdx];
59+ const int8_t kiLeftTopRef = iRefIndex[0][ kuiLeftTopIdx];
60+ int8_t iDiagonalRef = kiRightTopRef;
61+
62+ int8_t iMatchRef = 0;
63+
64+
65+ int16_t iAMV[2], iBMV[2], iCMV[2];
66+
67+ *(int32_t*)iAMV = INTD32(iMotionVector[0][ kuiLeftIdx]);
68+ *(int32_t*)iBMV = INTD32(iMotionVector[0][ kuiTopIdx]);
69+ *(int32_t*)iCMV = INTD32(iMotionVector[0][kuiRightTopIdx]);
70+
71+ if (REF_NOT_AVAIL == iDiagonalRef)
72+ {
73+ iDiagonalRef = kiLeftTopRef;
74+ *(int32_t*)iCMV = INTD32(iMotionVector[0][kuiLeftTopIdx]);
75+ }
76+
77+ iMatchRef = (iRef == kiLeftRef) + (iRef == kiTopRef) + (iRef == iDiagonalRef);
78+
79+ if (REF_NOT_AVAIL == kiTopRef && REF_NOT_AVAIL == iDiagonalRef && kiLeftRef >= REF_NOT_IN_LIST)
80+ {
81+ ST32(iMVP, LD32(iAMV));
82+ return;
83+ }
84+
85+ if (1 == iMatchRef)
86+ {
87+ if (iRef == kiLeftRef)
88+ {
89+ ST32(iMVP, LD32(iAMV));
90+ }
91+ else if (iRef == kiTopRef)
92+ {
93+ ST32(iMVP, LD32(iBMV));
94+ }
95+ else
96+ {
97+ ST32(iMVP, LD32(iCMV));
98+ }
99+ }
100+ else
101+ {
102+ iMVP[0] = WelsMedian(iAMV[0], iBMV[0], iCMV[0]);
103+ iMVP[1] = WelsMedian(iAMV[1], iBMV[1], iCMV[1]);
104+ }
105+}
106+void_t PredInter8x16Mv(int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
107+ int32_t iPartIdx, int8_t iRef, int16_t iMVP[2])
108+{
109+ if (0 == iPartIdx)
110+ {
111+ const int8_t kiLeftRef = iRefIndex[0][6];
112+ if (iRef == kiLeftRef)
113+ {
114+ ST32( iMVP, LD32(&iMotionVector[0][6][0]) );
115+ return;
116+ }
117+ }
118+ else // 1 == iPartIdx
119+ {
120+ int8_t iDiagonalRef = iRefIndex[0][5]; //top-right
121+ int8_t index = 5;
122+ if (REF_NOT_AVAIL == iDiagonalRef)
123+ {
124+ iDiagonalRef = iRefIndex[0][2]; //top-left for 8*8 block(index 1)
125+ index = 2;
126+ }
127+ if (iRef == iDiagonalRef)
128+ {
129+ ST32( iMVP, LD32(&iMotionVector[0][index][0]) );
130+ return;
131+ }
132+ }
133+
134+ PredMv(iMotionVector, iRefIndex, iPartIdx, 2, iRef, iMVP);
135+}
136+void_t PredInter16x8Mv(int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
137+ int32_t iPartIdx, int8_t iRef, int16_t iMVP[2])
138+{
139+ if (0 == iPartIdx)
140+ {
141+ const int8_t kiTopRef = iRefIndex[0][1];
142+ if (iRef == kiTopRef)
143+ {
144+ ST32(iMVP, LD32(&iMotionVector[0][1][0]));
145+ return;
146+ }
147+ }
148+ else // 8 == iPartIdx
149+ {
150+ const int8_t kiLeftRef = iRefIndex[0][18];
151+ if (iRef == kiLeftRef)
152+ {
153+ ST32(iMVP, LD32(&iMotionVector[0][18][0]));
154+ return;
155+ }
156+ }
157+
158+ PredMv(iMotionVector, iRefIndex, iPartIdx, 4, iRef, iMVP);
159+}
160+
161+//update iMVs and iRefIndex cache for current MB, only for P_16*16 (SKIP inclusive)
162+/* can be further optimized */
163+void_t UpdateP16x16MotionInfo( PDqLayer pCurDqLayer, int8_t iRef, int16_t iMVs[2])
164+{
165+ const int16_t kiRef2 = (iRef << 8) | iRef;
166+ const int32_t kiMV32 = LD32(iMVs);
167+ int32_t i;
168+ int32_t iMbXy = pCurDqLayer->iMbXyIndex;
169+
170+ for (i = 0; i < 16; i+=4)
171+ {
172+ //mb
173+ const uint8_t kuiScan4Idx = g_kuiScan4[i];
174+ const uint8_t kuiScan4IdxPlus4= 4 + kuiScan4Idx;
175+
176+ ST16( &pCurDqLayer->pRefIndex[0][iMbXy][kuiScan4Idx ], kiRef2 );
177+ ST16( &pCurDqLayer->pRefIndex[0][iMbXy][kuiScan4IdxPlus4], kiRef2 );
178+
179+ ST32( pCurDqLayer->pMv[0][iMbXy][ kuiScan4Idx ], kiMV32 );
180+ ST32( pCurDqLayer->pMv[0][iMbXy][1+kuiScan4Idx ], kiMV32 );
181+ ST32( pCurDqLayer->pMv[0][iMbXy][ kuiScan4IdxPlus4], kiMV32 );
182+ ST32( pCurDqLayer->pMv[0][iMbXy][1+kuiScan4IdxPlus4], kiMV32 );
183+ }
184+}
185+
186+//update iRefIndex and iMVs of Mb, only for P16x8
187+/*need further optimization, mb_cache not work */
188+void_t UpdateP16x8MotionInfo(PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
189+ int32_t iPartIdx, int8_t iRef, int16_t iMVs[2])
190+{
191+ const int16_t kiRef2 = (iRef << 8) | iRef;
192+ const int32_t kiMV32 = LD32(iMVs);
193+ int32_t i;
194+ int32_t iMbXy = pCurDqLayer->iMbXyIndex;
195+ for (i = 0; i < 2; i++, iPartIdx+=4)
196+ {
197+ const uint8_t kuiScan4Idx = g_kuiScan4[iPartIdx];
198+ const uint8_t kuiScan4IdxPlus4 = 4 + kuiScan4Idx;
199+ const uint8_t kuiCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
200+ const uint8_t kuiCacheIdxPlus6 = 6 + kuiCacheIdx;
201+
202+ //mb
203+ ST16( &pCurDqLayer->pRefIndex[0][iMbXy][kuiScan4Idx ], kiRef2 );
204+ ST16( &pCurDqLayer->pRefIndex[0][iMbXy][kuiScan4IdxPlus4], kiRef2 );
205+ ST32( pCurDqLayer->pMv[0][iMbXy][ kuiScan4Idx ], kiMV32 );
206+ ST32( pCurDqLayer->pMv[0][iMbXy][1+kuiScan4Idx ], kiMV32 );
207+ ST32( pCurDqLayer->pMv[0][iMbXy][ kuiScan4IdxPlus4], kiMV32 );
208+ ST32( pCurDqLayer->pMv[0][iMbXy][1+kuiScan4IdxPlus4], kiMV32 );
209+ //cache
210+ ST16( &iRefIndex[0][kuiCacheIdx ], kiRef2 );
211+ ST16( &iRefIndex[0][kuiCacheIdxPlus6], kiRef2 );
212+ ST32( iMotionVector[0][ kuiCacheIdx ], kiMV32 );
213+ ST32( iMotionVector[0][1+kuiCacheIdx ], kiMV32 );
214+ ST32( iMotionVector[0][ kuiCacheIdxPlus6], kiMV32 );
215+ ST32( iMotionVector[0][1+kuiCacheIdxPlus6], kiMV32 );
216+ }
217+}
218+//update iRefIndex and iMVs of both Mb and Mb_cache, only for P8x16
219+void_t UpdateP8x16MotionInfo(PDqLayer pCurDqLayer, int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30],
220+ int32_t iPartIdx, int8_t iRef, int16_t iMVs[2])
221+{
222+ const int16_t kiRef2 = (iRef << 8) | iRef;
223+ const int32_t kiMV32 = LD32(iMVs);
224+ int32_t i;
225+ int32_t iMbXy = pCurDqLayer->iMbXyIndex;
226+
227+ for (i = 0; i < 2; i++, iPartIdx+=8)
228+ {
229+ const uint8_t kuiScan4Idx = g_kuiScan4[iPartIdx];
230+ const uint8_t kuiCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
231+ const uint8_t kuiScan4IdxPlus4= 4 + kuiScan4Idx;
232+ const uint8_t kuiCacheIdxPlus6= 6 + kuiCacheIdx;
233+
234+ //mb
235+ ST16( &pCurDqLayer->pRefIndex[0][iMbXy][kuiScan4Idx ], kiRef2 );
236+ ST16( &pCurDqLayer->pRefIndex[0][iMbXy][kuiScan4IdxPlus4], kiRef2 );
237+ ST32( pCurDqLayer->pMv[0][iMbXy][ kuiScan4Idx ], kiMV32 );
238+ ST32( pCurDqLayer->pMv[0][iMbXy][1+kuiScan4Idx ], kiMV32 );
239+ ST32( pCurDqLayer->pMv[0][iMbXy][ kuiScan4IdxPlus4], kiMV32 );
240+ ST32( pCurDqLayer->pMv[0][iMbXy][1+kuiScan4IdxPlus4], kiMV32 );
241+ //cache
242+ ST16( &iRefIndex[0][kuiCacheIdx ], kiRef2 );
243+ ST16( &iRefIndex[0][kuiCacheIdxPlus6], kiRef2 );
244+ ST32( iMotionVector[0][ kuiCacheIdx ], kiMV32 );
245+ ST32( iMotionVector[0][1+kuiCacheIdx ], kiMV32 );
246+ ST32( iMotionVector[0][ kuiCacheIdxPlus6], kiMV32 );
247+ ST32( iMotionVector[0][1+kuiCacheIdxPlus6], kiMV32 );
248+ }
249+}
250+
251+} // namespace WelsDec

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