178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar/*
278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Copyright (C) 2007-2008 ARM Limited
378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Licensed under the Apache License, Version 2.0 (the "License");
578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * you may not use this file except in compliance with the License.
678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * You may obtain a copy of the License at
778e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
878e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *      http://www.apache.org/licenses/LICENSE-2.0
978e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1078e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Unless required by applicable law or agreed to in writing, software
1178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * distributed under the License is distributed on an "AS IS" BASIS,
1278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * See the License for the specific language governing permissions and
1478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * limitations under the License.
1578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar */
170c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
180c1bc742181ded4930842b46e9507372f0b1b963James Dong *
190c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name:  armVCM4P2_CheckVLCEscapeMode.c
200c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2
210c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision:   9641
220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date:       Thursday, February 7, 2008
230c1bc742181ded4930842b46e9507372f0b1b963James Dong *
240c1bc742181ded4930842b46e9507372f0b1b963James Dong *
250c1bc742181ded4930842b46e9507372f0b1b963James Dong *
260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
270c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
280c1bc742181ded4930842b46e9507372f0b1b963James Dong * Contains module for VLC escape mode check
290c1bc742181ded4930842b46e9507372f0b1b963James Dong *
300c1bc742181ded4930842b46e9507372f0b1b963James Dong */
310c1bc742181ded4930842b46e9507372f0b1b963James Dong
320c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
330c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h"
340c1bc742181ded4930842b46e9507372f0b1b963James Dong
350c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h"
360c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h"
370c1bc742181ded4930842b46e9507372f0b1b963James Dong
380c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
390c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armVCM4P2_CheckVLCEscapeMode
400c1bc742181ded4930842b46e9507372f0b1b963James Dong *
410c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
420c1bc742181ded4930842b46e9507372f0b1b963James Dong * Performs escape mode decision based on the run, run+, level, level+ and
430c1bc742181ded4930842b46e9507372f0b1b963James Dong * last combinations.
440c1bc742181ded4930842b46e9507372f0b1b963James Dong *
450c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
460c1bc742181ded4930842b46e9507372f0b1b963James Dong *
470c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
480c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] run             Run value (count of zeros) to be encoded
490c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] level           Level value (non-zero value) to be encoded
500c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] runPlus         Calculated as runPlus = run - (RMAX + 1)
510c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] levelPlus       Calculated as
520c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      levelPlus = sign(level)*[abs(level) - LMAX]
530c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] maxStoreRun     Max store possible (considering last and inter/intra)
540c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] maxRunForMultipleEntries
550c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      The run value after which level
560c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      will be equal to 1:
570c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      (considering last and inter/intra status)
580c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pRunIndexTable  Run Index table defined in
590c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      armVCM4P2_Huff_Tables_VLC.c
600c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      (considering last and inter/intra status)
610c1bc742181ded4930842b46e9507372f0b1b963James Dong *
620c1bc742181ded4930842b46e9507372f0b1b963James Dong *
630c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
640c1bc742181ded4930842b46e9507372f0b1b963James Dong * Returns an Escape mode which can take values from 0 to 3
650c1bc742181ded4930842b46e9507372f0b1b963James Dong * 0 --> no escape mode, 1 --> escape type 1,
660c1bc742181ded4930842b46e9507372f0b1b963James Dong * 1 --> escape type 2, 3 --> escape type 3, check section 7.4.1.3
670c1bc742181ded4930842b46e9507372f0b1b963James Dong * in the MPEG ISO standard.
680c1bc742181ded4930842b46e9507372f0b1b963James Dong *
690c1bc742181ded4930842b46e9507372f0b1b963James Dong */
700c1bc742181ded4930842b46e9507372f0b1b963James Dong
710c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_U8 armVCM4P2_CheckVLCEscapeMode(
720c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U32 run,
730c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U32 runPlus,
740c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S16 level,
750c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S16 levelPlus,
760c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U8  maxStoreRun,
770c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U8  maxRunForMultipleEntries,
780c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT shortVideoHeader,
790c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_U8  *pRunIndexTable
800c1bc742181ded4930842b46e9507372f0b1b963James Dong)
810c1bc742181ded4930842b46e9507372f0b1b963James Dong{
820c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U8 escape = 0, fMode = 0, entries;
830c1bc742181ded4930842b46e9507372f0b1b963James Dong
840c1bc742181ded4930842b46e9507372f0b1b963James Dong    level = armAbs (level);
850c1bc742181ded4930842b46e9507372f0b1b963James Dong    levelPlus = armAbs (levelPlus);
860c1bc742181ded4930842b46e9507372f0b1b963James Dong
870c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Check for a valid entry with run, level and Last combination
880c1bc742181ded4930842b46e9507372f0b1b963James Dong       Mode 0 check */
890c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (run <= maxStoreRun)
900c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
910c1bc742181ded4930842b46e9507372f0b1b963James Dong        entries = pRunIndexTable[run + 1]
920c1bc742181ded4930842b46e9507372f0b1b963James Dong                  - pRunIndexTable[run];
930c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (run > maxRunForMultipleEntries)
940c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
950c1bc742181ded4930842b46e9507372f0b1b963James Dong            entries = 1;
960c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
970c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (level > entries)
980c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
990c1bc742181ded4930842b46e9507372f0b1b963James Dong            escape = 1;
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong        escape = 1;
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong    if(escape && shortVideoHeader)
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong        escape = 0;
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong        fMode = 4;
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Check for a valid entry with run, levelPlus and Last combination
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong       Mode 1 check */
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (escape)
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong        escape = 0;
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong        fMode = 1;
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (run <= maxStoreRun)
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong            entries = pRunIndexTable[run + 1]
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong                      - pRunIndexTable[run];
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (run > maxRunForMultipleEntries)
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong                entries = 1;
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (levelPlus > entries)
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong                escape = 1;
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong            escape = 1;
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Check for a valid entry with runPlus, level and Last combination
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong       Mode 2 check */
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (escape)
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong        escape = 0;
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong        fMode = 2;
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (runPlus <= maxStoreRun)
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong            entries = pRunIndexTable[runPlus + 1]
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong                      - pRunIndexTable[runPlus];
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (runPlus > maxRunForMultipleEntries)
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong                entries = 1;
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (level > entries)
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong                escape = 1;
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong            escape = 1;
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* select mode 3 --> FLC */
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (escape)
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong        fMode = 3;
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong    return fMode;
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong/*End of File*/
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong
172