1;//
2;// Copyright (C) 2007-2008 ARM Limited
3;//
4;// Licensed under the Apache License, Version 2.0 (the "License");
5;// you may not use this file except in compliance with the License.
6;// You may obtain a copy of the License at
7;//
8;//      http://www.apache.org/licenses/LICENSE-2.0
9;//
10;// Unless required by applicable law or agreed to in writing, software
11;// distributed under the License is distributed on an "AS IS" BASIS,
12;// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13;// See the License for the specific language governing permissions and
14;// limitations under the License.
15;//
16; **********
17; *
18; * File Name:  omxVCM4P2_DecodePadMV_PVOP_s.s
19; * OpenMAX DL: v1.0.2
20; * Revision:   12290
21; * Date:       Wednesday, April 9, 2008
22; *
23; *
24; *
25; *
26; **
27; * Function: omxVCM4P2_DecodePadMV_PVOP
28; *
29; * Description:
30; * Decodes and pads four motion vectors of the non-intra macroblock in P-VOP.
31; * The motion vector padding process is specified in subclause 7.6.1.6 of
32; * ISO/IEC 14496-2.
33; *
34; * Remarks:
35; *
36; *
37; * Parameters:
38; * [in]    ppBitStream        pointer to the pointer to the current byte in
39; *                            the bit stream buffer
40; * [in]    pBitOffset         pointer to the bit position in the byte pointed
41; *                            to by *ppBitStream. *pBitOffset is valid within
42; *                            [0-7].
43; * [in]    pSrcMVLeftMB       pointers to the motion vector buffers of the
44; *                           macroblocks specially at the left side of the current macroblock
45; *                     respectively.
46; * [in]    pSrcMVUpperMB      pointers to the motion vector buffers of the
47; *                     macroblocks specially at the upper side of the current macroblock
48; *                     respectively.
49; * [in]    pSrcMVUpperRightMB pointers to the motion vector buffers of the
50; *                     macroblocks specially at the upper-right side of the current macroblock
51; *                     respectively.
52; * [in]    fcodeForward       a code equal to vop_fcode_forward in MPEG-4
53; *                     bit stream syntax
54; * [in]    MBType         the type of the current macroblock. If MBType
55; *                     is not equal to OMX_VC_INTER4V, the destination
56; *                     motion vector buffer is still filled with the
57; *                     same decoded vector.
58; * [out]   ppBitStream         *ppBitStream is updated after the block is decoded,
59; *                     so that it points to the current byte in the bit
60; *                     stream buffer
61; * [out]   pBitOffset         *pBitOffset is updated so that it points to the
62; *                     current bit position in the byte pointed by
63; *                     *ppBitStream
64; * [out]   pDstMVCurMB         pointer to the motion vector buffer of the current
65; *                     macroblock which contains four decoded motion vectors
66; *
67; * Return Value:
68; * OMX_Sts_NoErr -no error
69; *
70; *
71; * OMX_Sts_Err - status error
72; *
73; *
74
75        INCLUDE omxtypes_s.h
76        INCLUDE armCOMM_s.h
77        INCLUDE armCOMM_BitDec_s.h
78        INCLUDE omxVC_s.h
79
80       M_VARIANTS ARM1136JS
81
82
83
84
85        IF ARM1136JS
86
87;//Input Arguments
88
89ppBitStream           RN 0
90pBitOffset            RN 1
91pSrcMVLeftMB          RN 2
92pSrcMVUpperMB         RN 3
93pSrcMVUpperRightMB    RN 4
94pDstMVCurMB           RN 5
95fcodeForward          RN 6
96MBType                RN 7
97
98;//Local Variables
99
100zero                  RN 4
101one                   RN 4
102scaleFactor           RN 1
103
104
105Return                RN 0
106
107VlcMVD                RN 0
108index                 RN 4
109Count                 RN 7
110
111mvHorData             RN 4
112mvHorResidual         RN 0
113
114mvVerData             RN 4
115mvVerResidual         RN 0
116
117temp                  RN 1
118
119temp1                 RN 3
120High                  RN 4
121Low                   RN 2
122Range                 RN 1
123
124BlkCount              RN 14
125
126diffMVdx              RN 0
127diffMVdy              RN 1
128
129;// Scratch Registers
130
131RBitStream            RN 8
132RBitCount             RN 9
133RBitBuffer            RN 10
134
135T1                    RN 11
136T2                    RN 12
137LR                    RN 14
138
139       IMPORT          armVCM4P2_aVlcMVD
140       IMPORT          omxVCM4P2_FindMVpred
141
142       ;// Allocate stack memory
143
144       M_ALLOC4        ppDstMVCurMB,4
145       M_ALLOC4        pDstMVPredME,4
146       M_ALLOC4        pBlkCount,4
147
148       M_ALLOC4        pppBitStream,4
149       M_ALLOC4        ppBitOffset,4
150       M_ALLOC4        ppSrcMVLeftMB,4
151       M_ALLOC4        ppSrcMVUpperMB,4
152
153       M_ALLOC4        pdiffMVdx,4
154       M_ALLOC4        pdiffMVdy,4
155       M_ALLOC4        pHigh,4
156
157
158
159
160       M_START   omxVCM4P2_DecodePadMV_PVOP,r11
161
162       M_ARG           pSrcMVUpperRightMBonStack,4           ;// pointer to  pSrcMVUpperRightMB on stack
163       M_ARG           pDstMVCurMBonStack,4                  ;// pointer to pDstMVCurMB on stack
164       M_ARG           fcodeForwardonStack,4                 ;// pointer to fcodeForward on stack
165       M_ARG           MBTypeonStack,4                       ;// pointer to MBType on stack
166
167
168
169
170
171       ;// Initializing the BitStream Macro
172
173       M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount
174       M_LDR           MBType,MBTypeonStack                  ;// Load MBType from stack
175       M_LDR           pDstMVCurMB,pDstMVCurMBonStack        ;// Load pDstMVCurMB from stack
176       MOV             zero,#0
177
178       TEQ             MBType,#OMX_VC_INTRA                  ;// Check if MBType=OMX_VC_INTRA
179       TEQNE           MBType,#OMX_VC_INTRA_Q                ;// check if MBType=OMX_VC_INTRA_Q
180       STREQ           zero,[pDstMVCurMB]
181       M_BD_INIT1      T1, T2, T2
182       STREQ           zero,[pDstMVCurMB,#4]
183       M_BD_INIT2      T1, T2, T2
184       STREQ           zero,[pDstMVCurMB,#4]
185       MOVEQ           Return,#OMX_Sts_NoErr
186       MOV             BlkCount,#0
187       STREQ           zero,[pDstMVCurMB,#4]
188
189       BEQ             ExitOK
190
191       TEQ             MBType,#OMX_VC_INTER4V                ;// Check if MBType=OMX_VC_INTER4V
192       TEQNE           MBType,#OMX_VC_INTER4V_Q              ;// Check if MBType=OMX_VC_INTER4V_Q
193       MOVEQ           Count,#4
194
195       TEQ             MBType,#OMX_VC_INTER                  ;// Check if MBType=OMX_VC_INTER
196       TEQNE           MBType,#OMX_VC_INTER_Q                ;// Check if MBType=OMX_VC_INTER_Q
197       MOVEQ           Count,#1
198
199       M_LDR           fcodeForward,fcodeForwardonStack      ;// Load fcodeForward  from stack
200
201       ;// Storing the values temporarily on stack
202
203       M_STR           ppBitStream,pppBitStream
204       M_STR           pBitOffset,ppBitOffset
205
206
207       SUB             temp,fcodeForward,#1                  ;// temp=fcodeForward-1
208       MOV             one,#1
209       M_STR           pSrcMVLeftMB,ppSrcMVLeftMB
210       LSL             scaleFactor,one,temp                  ;// scaleFactor=1<<(fcodeForward-1)
211       M_STR           pSrcMVUpperMB,ppSrcMVUpperMB
212       LSL             scaleFactor,scaleFactor,#5
213       M_STR           scaleFactor,pHigh                     ;// [pHigh]=32*scaleFactor
214
215       ;// VLD Decoding
216
217
218Loop
219
220       LDR             VlcMVD, =armVCM4P2_aVlcMVD        ;// Load the optimized MVD VLC table
221
222       ;// Horizontal Data and Residual calculation
223
224       LDR             temp,=0xFFF
225       M_BD_VLD        index,T1,T2,VlcMVD,3,2                ;// variable lenght decoding using the macro
226
227       TEQ             index,temp
228       BEQ             ExitError                             ;// Exit with an Error Message if the decoded symbol is an invalied symbol
229
230       SUB             mvHorData,index,#32                   ;// mvHorData=index-32
231       MOV             mvHorResidual,#1                      ;// mvHorResidual=1
232       CMP             fcodeForward,#1
233       TEQNE           mvHorData,#0
234       MOVEQ           diffMVdx,mvHorData                    ;// if scaleFactor=1(fcodeForward=1) or mvHorData=0 diffMVdx=mvHorData
235       BEQ             VerticalData
236
237       SUB             temp,fcodeForward,#1
238       M_BD_VREAD8     mvHorResidual,temp,T1,T2              ;// get mvHorResidual from bitstream if fcodeForward>1 and mvHorData!=0
239
240       CMP             mvHorData,#0
241       RSBLT           mvHorData,mvHorData,#0                ;// mvHorData=abs(mvHorData)
242       SUB             mvHorResidual,mvHorResidual,fcodeForward
243       SMLABB          diffMVdx,mvHorData,fcodeForward,mvHorResidual ;// diffMVdx=abs(mvHorData)*fcodeForward+mvHorResidual-fcodeForward
244       ADD             diffMVdx,diffMVdx,#1
245       RSBLT           diffMVdx,diffMVdx,#0
246
247       ;// Vertical Data and Residual calculation
248
249VerticalData
250
251       M_STR           diffMVdx,pdiffMVdx                    ;// Store the diffMVdx on stack
252       LDR             VlcMVD, =armVCM4P2_aVlcMVD        ;// Loading the address of optimized VLC tables
253
254       LDR             temp,=0xFFF
255       M_BD_VLD        index,T1,T2,VlcMVD,3,2                ;// VLC decoding using the macro
256
257       TEQ             index,temp
258       BEQ             ExitError                             ;// Exit with an Error Message if an Invalied Symbol occurs
259
260       SUB             mvVerData,index,#32                   ;// mvVerData=index-32
261       MOV             mvVerResidual,#1
262       CMP             fcodeForward,#1
263       TEQNE           mvVerData,#0
264       MOVEQ           diffMVdy,mvVerData                    ;// diffMVdy = mvVerData if scaleFactor=1(fcodeForward=1) or mvVerData=0
265       BEQ             FindMVPred
266
267       SUB             temp,fcodeForward,#1
268       M_BD_VREAD8     mvVerResidual,temp,T1,T2              ;// Get mvVerResidual from bit stream if fcodeForward>1 and mnVerData!=0
269
270
271       CMP             mvVerData,#0
272       RSBLT           mvVerData,mvVerData,#0
273       SUB             mvVerResidual,mvVerResidual,fcodeForward
274       SMLABB          diffMVdy,mvVerData,fcodeForward,mvVerResidual ;// diffMVdy=abs(mvVerData)*fcodeForward+mvVerResidual-fcodeForward
275       ADD             diffMVdy,diffMVdy,#1
276       RSBLT           diffMVdy,diffMVdy,#0
277
278       ;//Calling the Function omxVCM4P2_FindMVpred
279
280FindMVPred
281
282       M_STR           diffMVdy,pdiffMVdy
283       ADD             temp,pDstMVCurMB,BlkCount,LSL #2      ;// temp=pDstMVCurMB[BlkCount]
284       M_STR           temp,ppDstMVCurMB                     ;// store temp on stack for passing as an argument to FindMVPred
285
286       MOV             temp,#0
287       M_STR           temp,pDstMVPredME                     ;// Pass pDstMVPredME=NULL as an argument
288       M_STR           BlkCount,pBlkCount                    ;// Passs BlkCount as Argument through stack
289
290       MOV             temp,pSrcMVLeftMB                     ;// temp (RN 1)=pSrcMVLeftMB
291       M_LDR           pSrcMVUpperRightMB,pSrcMVUpperRightMBonStack
292       MOV             pSrcMVLeftMB,pSrcMVUpperMB            ;// pSrcMVLeftMB ( RN 2) = pSrcMVUpperMB
293       MOV             ppBitStream,pDstMVCurMB               ;// ppBitStream  ( RN 0) = pDstMVCurMB
294       MOV             pSrcMVUpperMB,pSrcMVUpperRightMB      ;// pSrcMVUpperMB( RN 3) = pSrcMVUpperRightMB
295       BL              omxVCM4P2_FindMVpred              ;// Branch to subroutine omxVCM4P2_FindMVpred
296
297       ;// Store Horizontal Motion Vector
298
299       M_LDR           BlkCount,pBlkCount                    ;// Load BlkCount from stack
300       M_LDR           High,pHigh                            ;// High=32*scaleFactor
301       LSL             temp1,BlkCount,#2                     ;// temp=BlkCount*4
302       M_LDR           diffMVdx,pdiffMVdx                    ;// Laad diffMVdx
303
304       LDRSH           temp,[pDstMVCurMB,temp1]              ;// temp=pDstMVCurMB[BlkCount]
305
306
307       RSB             Low,High,#0                           ;// Low = -32*scaleFactor
308       ADD             diffMVdx,temp,diffMVdx                ;// diffMVdx=pDstMVCurMB[BlkCount]+diffMVdx
309       ADD             Range,High,High                       ;// Range=64*ScaleFactor
310       SUB             High,High,#1                          ;// High= 32*scaleFactor-1
311
312       CMP             diffMVdx,Low                          ;// If diffMVdx<Low
313       ADDLT           diffMVdx,diffMVdx,Range               ;// diffMVdx+=Range
314
315       CMP             diffMVdx,High
316       SUBGT           diffMVdx,diffMVdx,Range               ;// If diffMVdx > High diffMVdx-=Range
317       STRH            diffMVdx,[pDstMVCurMB,temp1]
318
319       ;// Store Vertical
320
321       ADD             temp1,temp1,#2                        ;// temp1=4*BlkCount+2
322       M_LDR           diffMVdx,pdiffMVdy                    ;// Laad diffMVdy
323       LDRSH           temp,[pDstMVCurMB,temp1]              ;// temp=pDstMVCurMB[BlkCount].diffMVdy
324       ADD             BlkCount,BlkCount,#1                  ;// BlkCount=BlkCount+1
325       ADD             diffMVdx,temp,diffMVdx
326       CMP             diffMVdx,Low
327       ADDLT           diffMVdx,diffMVdx,Range               ;// If diffMVdy<Low  diffMVdy+=Range
328       CMP             diffMVdx,High
329       SUBGT           diffMVdx,diffMVdx,Range               ;// If diffMVdy > High diffMVdy-=Range
330       STRH            diffMVdx,[pDstMVCurMB,temp1]
331
332       CMP             BlkCount,Count
333       M_LDR           pSrcMVLeftMB,ppSrcMVLeftMB
334       M_LDR           pSrcMVUpperMB,ppSrcMVUpperMB
335
336       BLT             Loop                                  ;// If BlkCount<Count Continue the Loop
337
338
339       ;// If MBType=OMX_VC_INTER or MBtype=OMX_VC_INTER_Q copy pDstMVCurMB[0] to
340       ;// pDstMVCurMB[1], pDstMVCurMB[2], pDstMVCurMB[3]
341
342       M_LDR           MBType,MBTypeonStack
343
344       TEQ             MBType,#OMX_VC_INTER
345       TEQNE           MBType,#OMX_VC_INTER_Q
346       LDREQ           temp,[pDstMVCurMB]
347       M_LDR           ppBitStream,pppBitStream
348       STREQ           temp,[pDstMVCurMB,#4]
349
350       STREQ           temp,[pDstMVCurMB,#8]
351       STREQ           temp,[pDstMVCurMB,#12]
352
353
354       M_LDR           pBitOffset,ppBitOffset
355       ;//Ending the macro
356       M_BD_FINI       ppBitStream,pBitOffset                 ;// Finishing the Macro
357
358
359       MOV             Return,#OMX_Sts_NoErr
360       B               ExitOK
361
362ExitError
363
364       M_LDR           ppBitStream,pppBitStream
365       M_LDR           pBitOffset,ppBitOffset
366       ;//Ending the macro
367       M_BD_FINI       ppBitStream,pBitOffset
368
369       MOV             Return,#OMX_Sts_Err
370
371ExitOK
372
373       M_END
374       ENDIF
375       END
376
377
378
379