armVCM4P2_CheckVLCEscapeMode.c revision 78e52bfac041d71ce53b5b13c2abf78af742b09d
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 *
19 * File Name:  armVCM4P2_CheckVLCEscapeMode.c
20 * OpenMAX DL: v1.0.2
21 * Revision:   9641
22 * Date:       Thursday, February 7, 2008
23 *
24 *
25 *
26 *
27 * Description:
28 * Contains module for VLC escape mode check
29 *
30 */
31
32#include "omxtypes.h"
33#include "armOMX.h"
34
35#include "armVC.h"
36#include "armCOMM.h"
37
38/**
39 * Function: armVCM4P2_CheckVLCEscapeMode
40 *
41 * Description:
42 * Performs escape mode decision based on the run, run+, level, level+ and
43 * last combinations.
44 *
45 * Remarks:
46 *
47 * Parameters:
48 * [in] run             Run value (count of zeros) to be encoded
49 * [in] level           Level value (non-zero value) to be encoded
50 * [in] runPlus         Calculated as runPlus = run - (RMAX + 1)
51 * [in] levelPlus       Calculated as
52 *                      levelPlus = sign(level)*[abs(level) - LMAX]
53 * [in] maxStoreRun     Max store possible (considering last and inter/intra)
54 * [in] maxRunForMultipleEntries
55 *                      The run value after which level
56 *                      will be equal to 1:
57 *                      (considering last and inter/intra status)
58 * [in] pRunIndexTable  Run Index table defined in
59 *                      armVCM4P2_Huff_Tables_VLC.c
60 *                      (considering last and inter/intra status)
61 *
62 *
63 * Return Value:
64 * Returns an Escape mode which can take values from 0 to 3
65 * 0 --> no escape mode, 1 --> escape type 1,
66 * 1 --> escape type 2, 3 --> escape type 3, check section 7.4.1.3
67 * in the MPEG ISO standard.
68 *
69 */
70
71OMX_U8 armVCM4P2_CheckVLCEscapeMode(
72     OMX_U32 run,
73     OMX_U32 runPlus,
74     OMX_S16 level,
75     OMX_S16 levelPlus,
76     OMX_U8  maxStoreRun,
77     OMX_U8  maxRunForMultipleEntries,
78     OMX_INT shortVideoHeader,
79     const OMX_U8  *pRunIndexTable
80)
81{
82    OMX_U8 escape = 0, fMode = 0, entries;
83
84    level = armAbs (level);
85    levelPlus = armAbs (levelPlus);
86
87    /* Check for a valid entry with run, level and Last combination
88       Mode 0 check */
89    if (run <= maxStoreRun)
90    {
91        entries = pRunIndexTable[run + 1]
92                  - pRunIndexTable[run];
93        if (run > maxRunForMultipleEntries)
94        {
95            entries = 1;
96        }
97        if (level > entries)
98        {
99            escape = 1;
100        }
101    }
102    else
103    {
104        escape = 1;
105    }
106    if(escape && shortVideoHeader)
107    {
108        escape = 0;
109        fMode = 4;
110    }
111    /* Check for a valid entry with run, levelPlus and Last combination
112       Mode 1 check */
113    if (escape)
114    {
115        escape = 0;
116        fMode = 1;
117        if (run <= maxStoreRun)
118        {
119            entries = pRunIndexTable[run + 1]
120                      - pRunIndexTable[run];
121            if (run > maxRunForMultipleEntries)
122            {
123                entries = 1;
124            }
125            if (levelPlus > entries)
126            {
127                escape = 1;
128            }
129        }
130        else
131        {
132            escape = 1;
133        }
134    }
135
136    /* Check for a valid entry with runPlus, level and Last combination
137       Mode 2 check */
138    if (escape)
139    {
140        escape = 0;
141        fMode = 2;
142        if (runPlus <= maxStoreRun)
143        {
144            entries = pRunIndexTable[runPlus + 1]
145                      - pRunIndexTable[runPlus];
146            if (runPlus > maxRunForMultipleEntries)
147            {
148                entries = 1;
149            }
150            if (level > entries)
151            {
152                escape = 1;
153            }
154        }
155        else
156        {
157            escape = 1;
158        }
159    }
160
161    /* select mode 3 --> FLC */
162    if (escape)
163    {
164        fMode = 3;
165    }
166
167    return fMode;
168}
169
170/*End of File*/
171
172