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_GetVLCBits.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 get bits from the stream
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#include "armCOMM_Bitstream.h"
380c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVCM4P2_ZigZag_Tables.h"
390c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVCM4P2_Huff_Tables_VLC.h"
400c1bc742181ded4930842b46e9507372f0b1b963James Dong
410c1bc742181ded4930842b46e9507372f0b1b963James Dong
420c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
430c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armVCM4P2_GetVLCBits
440c1bc742181ded4930842b46e9507372f0b1b963James Dong *
450c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
460c1bc742181ded4930842b46e9507372f0b1b963James Dong * Performs escape mode decision based on the run, run+, level, level+ and
470c1bc742181ded4930842b46e9507372f0b1b963James Dong * last combinations.
480c1bc742181ded4930842b46e9507372f0b1b963James Dong *
490c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks:
500c1bc742181ded4930842b46e9507372f0b1b963James Dong *
510c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters:
520c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	ppBitStream		pointer to the pointer to the current byte in
530c1bc742181ded4930842b46e9507372f0b1b963James Dong *								the bit stream
540c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in]	pBitOffset		pointer to the bit position in the byte pointed
550c1bc742181ded4930842b46e9507372f0b1b963James Dong *								by *ppBitStream. Valid within 0 to 7
560c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] start           start indicates whether the encoding begins with
570c1bc742181ded4930842b46e9507372f0b1b963James Dong *                      0th element or 1st.
580c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in/out] pLast       pointer to last status flag
590c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] runBeginSingleLevelEntriesL0      The run value from which level
600c1bc742181ded4930842b46e9507372f0b1b963James Dong *                                        will be equal to 1: last == 0
610c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] IndexBeginSingleLevelEntriesL0    Array index in the VLC table
620c1bc742181ded4930842b46e9507372f0b1b963James Dong *                                        pointing to the
630c1bc742181ded4930842b46e9507372f0b1b963James Dong *                                        runBeginSingleLevelEntriesL0
640c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] runBeginSingleLevelEntriesL1      The run value from which level
650c1bc742181ded4930842b46e9507372f0b1b963James Dong *                                        will be equal to 1: last == 1
660c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] IndexBeginSingleLevelEntriesL1    Array index in the VLC table
670c1bc742181ded4930842b46e9507372f0b1b963James Dong *                                        pointing to the
680c1bc742181ded4930842b46e9507372f0b1b963James Dong *                                        runBeginSingleLevelEntriesL0
690c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pRunIndexTableL0    Run Index table defined in
700c1bc742181ded4930842b46e9507372f0b1b963James Dong *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
710c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pVlcTableL0         VLC table for last == 0
720c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pRunIndexTableL1    Run Index table defined in
730c1bc742181ded4930842b46e9507372f0b1b963James Dong *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
740c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pVlcTableL1         VLC table for last == 1
750c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pLMAXTableL0        Level MAX table defined in
760c1bc742181ded4930842b46e9507372f0b1b963James Dong *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
770c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pLMAXTableL1        Level MAX table defined in
780c1bc742181ded4930842b46e9507372f0b1b963James Dong *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
790c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pRMAXTableL0        Run MAX table defined in
800c1bc742181ded4930842b46e9507372f0b1b963James Dong *                          armVCM4P2_Huff_Tables_VLC.c for last == 0
810c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pRMAXTableL1        Run MAX table defined in
820c1bc742181ded4930842b46e9507372f0b1b963James Dong *                          armVCM4P2_Huff_Tables_VLC.c for last == 1
830c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out]pDst			    pointer to the coefficient buffer of current
840c1bc742181ded4930842b46e9507372f0b1b963James Dong *							block. Should be 32-bit aligned
850c1bc742181ded4930842b46e9507372f0b1b963James Dong *
860c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
870c1bc742181ded4930842b46e9507372f0b1b963James Dong * Standard OMXResult result. See enumeration for possible result codes.
880c1bc742181ded4930842b46e9507372f0b1b963James Dong *
890c1bc742181ded4930842b46e9507372f0b1b963James Dong */
900c1bc742181ded4930842b46e9507372f0b1b963James Dong
910c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult armVCM4P2_GetVLCBits (
920c1bc742181ded4930842b46e9507372f0b1b963James Dong              const OMX_U8 **ppBitStream,
930c1bc742181ded4930842b46e9507372f0b1b963James Dong              OMX_INT * pBitOffset,
940c1bc742181ded4930842b46e9507372f0b1b963James Dong			  OMX_S16 * pDst,
950c1bc742181ded4930842b46e9507372f0b1b963James Dong			  OMX_INT shortVideoHeader,
960c1bc742181ded4930842b46e9507372f0b1b963James Dong			  OMX_U8    start,
970c1bc742181ded4930842b46e9507372f0b1b963James Dong			  OMX_U8  * pLast,
980c1bc742181ded4930842b46e9507372f0b1b963James Dong			  OMX_U8    runBeginSingleLevelEntriesL0,
990c1bc742181ded4930842b46e9507372f0b1b963James Dong			  OMX_U8    maxIndexForMultipleEntriesL0,
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong			  OMX_U8    maxRunForMultipleEntriesL1,
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong			  OMX_U8    maxIndexForMultipleEntriesL1,
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong              const OMX_U8  * pRunIndexTableL0,
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong              const ARM_VLC32 *pVlcTableL0,
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong			  const OMX_U8  * pRunIndexTableL1,
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong              const ARM_VLC32 *pVlcTableL1,
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong              const OMX_U8  * pLMAXTableL0,
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong              const OMX_U8  * pLMAXTableL1,
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong              const OMX_U8  * pRMAXTableL0,
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong              const OMX_U8  * pRMAXTableL1,
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong              const OMX_U8  * pZigzagTable
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong)
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong{
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U32 storeRun;
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U8  tabIndex, markerBit;
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S16 storeLevel;
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_U16 unpackRetIndex;
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong	OMX_U8  i, fType, escape;
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong	OMX_U8  sign = 0;
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong	/* Unpacking the bitstream and RLD */
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = start; i < 64;)
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong		escape = armLookAheadBits(ppBitStream, pBitOffset, 7);
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong		if (escape != 3)
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong		{
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong			fType = 0; /* Not in escape mode */
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong		}
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong		else
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong		{
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong			armSkipBits (ppBitStream, pBitOffset, 7);
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong			if(shortVideoHeader)
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong			{
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong			  *pLast = armGetBits(ppBitStream, pBitOffset, 1);
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong			  storeRun = armGetBits(ppBitStream, pBitOffset, 6);
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong			  storeLevel = armGetBits(ppBitStream, pBitOffset, 8);
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong			  /* Ref to Table B-18 (c) in MPEG4 Standard- FLC code for  */
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong			  /* LEVEL when short_video_header is 1, the storeLevel is  */
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong			  /* a signed value and the sign and the unsigned value for */
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong			  /* storeLevel need to be extracted and passed to arm      */
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong			  /* FillVLDBuffer function                                 */
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong			  sign = (storeLevel & 0x80);
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong			  if(sign==0x80)
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong			  {
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong			  	storeLevel=(storeLevel^0xff)+1;
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong			  	sign=1;
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong			  }
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong			  armRetDataErrIf( storeLevel == 0 || sign*storeLevel == 128 , OMX_Sts_Err); /* Invalid FLC */
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong			  armRetDataErrIf((i + storeRun) >= 64, OMX_Sts_Err);
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong			  armVCM4P2_FillVLDBuffer(
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong			    storeRun,
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong			    pDst,
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong			    storeLevel,
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong			    sign,
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong			    *pLast,
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong			    &i,
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong			    pZigzagTable);
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong			    return OMX_Sts_NoErr;
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong			}
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong			if (armGetBits(ppBitStream, pBitOffset, 1))
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong			{
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong				if (armGetBits(ppBitStream, pBitOffset, 1))
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong				{
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong					fType = 3;
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong				}
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong				else
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong				{
1720c1bc742181ded4930842b46e9507372f0b1b963James Dong					fType = 2;
1730c1bc742181ded4930842b46e9507372f0b1b963James Dong				}
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong			}
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong			else
1760c1bc742181ded4930842b46e9507372f0b1b963James Dong			{
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong				fType = 1;
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong			}
1790c1bc742181ded4930842b46e9507372f0b1b963James Dong		}
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong
1810c1bc742181ded4930842b46e9507372f0b1b963James Dong	    if (fType < 3)
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong	    {
1830c1bc742181ded4930842b46e9507372f0b1b963James Dong	        unpackRetIndex = armUnPackVLC32(ppBitStream, pBitOffset,
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong										pVlcTableL0);
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong			if (unpackRetIndex != ARM_NO_CODEBOOK_INDEX)
1860c1bc742181ded4930842b46e9507372f0b1b963James Dong		    {
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong			    /* Decode run and level from the index */
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong			    /* last = 0 */
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong			    *pLast = 0;
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong			    if (unpackRetIndex > maxIndexForMultipleEntriesL0)
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong			    {
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeLevel = 1;
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeRun = (unpackRetIndex - maxIndexForMultipleEntriesL0)
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong							+ runBeginSingleLevelEntriesL0;
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong			    }
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong			    else
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong			    {
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong				    tabIndex = 1;
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong				    while (pRunIndexTableL0[tabIndex] <= unpackRetIndex)
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong				    {
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong					    tabIndex++;
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong				    }
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeRun = tabIndex - 1;
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeLevel = unpackRetIndex - pRunIndexTableL0[tabIndex - 1] + 1;
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong			    }
2060c1bc742181ded4930842b46e9507372f0b1b963James Dong			    sign = (OMX_U8) armGetBits(ppBitStream, pBitOffset, 1);
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong			    if (fType == 1)
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong			    {
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeLevel = (armAbs(storeLevel) + pLMAXTableL0[storeRun]);
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong			    }
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong			    else if (fType == 2)
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong			    {
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeRun = storeRun + pRMAXTableL0[storeLevel-1] + 1;
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong			    }
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong		    }
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong		    else
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong		    {
2190c1bc742181ded4930842b46e9507372f0b1b963James Dong			    unpackRetIndex = armUnPackVLC32(ppBitStream, pBitOffset,
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong											pVlcTableL1);
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong			    armRetDataErrIf(unpackRetIndex == ARM_NO_CODEBOOK_INDEX, OMX_Sts_Err);
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong			    /* Decode run and level from the index */
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong			    /* last = 1 */
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong			    *pLast = 1;
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong			    if (unpackRetIndex > maxIndexForMultipleEntriesL1)
2280c1bc742181ded4930842b46e9507372f0b1b963James Dong			    {
2290c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeLevel = 1;
2300c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeRun = (unpackRetIndex - maxIndexForMultipleEntriesL1)
2310c1bc742181ded4930842b46e9507372f0b1b963James Dong							+ maxRunForMultipleEntriesL1;
2320c1bc742181ded4930842b46e9507372f0b1b963James Dong		        }
2330c1bc742181ded4930842b46e9507372f0b1b963James Dong		        else
2340c1bc742181ded4930842b46e9507372f0b1b963James Dong			    {
2350c1bc742181ded4930842b46e9507372f0b1b963James Dong				    tabIndex = 1;
2360c1bc742181ded4930842b46e9507372f0b1b963James Dong				    while (pRunIndexTableL1[tabIndex] <= unpackRetIndex)
2370c1bc742181ded4930842b46e9507372f0b1b963James Dong				    {
2380c1bc742181ded4930842b46e9507372f0b1b963James Dong					    tabIndex++;
2390c1bc742181ded4930842b46e9507372f0b1b963James Dong				    }
2400c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeRun = tabIndex - 1;
2410c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeLevel = unpackRetIndex - pRunIndexTableL1[tabIndex - 1] + 1;
2420c1bc742181ded4930842b46e9507372f0b1b963James Dong			    }
2430c1bc742181ded4930842b46e9507372f0b1b963James Dong			    sign = (OMX_U8) armGetBits(ppBitStream, pBitOffset, 1);
2440c1bc742181ded4930842b46e9507372f0b1b963James Dong
2450c1bc742181ded4930842b46e9507372f0b1b963James Dong			    if (fType == 1)
2460c1bc742181ded4930842b46e9507372f0b1b963James Dong			    {
2470c1bc742181ded4930842b46e9507372f0b1b963James Dong			        storeLevel = (armAbs(storeLevel) + pLMAXTableL1[storeRun]);
2480c1bc742181ded4930842b46e9507372f0b1b963James Dong			    }
2490c1bc742181ded4930842b46e9507372f0b1b963James Dong			    else if (fType == 2)
2500c1bc742181ded4930842b46e9507372f0b1b963James Dong			    {
2510c1bc742181ded4930842b46e9507372f0b1b963James Dong				    storeRun = storeRun + pRMAXTableL1[storeLevel-1] + 1;
2520c1bc742181ded4930842b46e9507372f0b1b963James Dong			    }
2530c1bc742181ded4930842b46e9507372f0b1b963James Dong		    }
2540c1bc742181ded4930842b46e9507372f0b1b963James Dong            armRetDataErrIf((i + storeRun) >= 64, OMX_Sts_Err);
2550c1bc742181ded4930842b46e9507372f0b1b963James Dong		    armVCM4P2_FillVLDBuffer(
2560c1bc742181ded4930842b46e9507372f0b1b963James Dong			    storeRun,
2570c1bc742181ded4930842b46e9507372f0b1b963James Dong			    pDst,
2580c1bc742181ded4930842b46e9507372f0b1b963James Dong			    storeLevel,
2590c1bc742181ded4930842b46e9507372f0b1b963James Dong			    sign,
2600c1bc742181ded4930842b46e9507372f0b1b963James Dong			    *pLast,
2610c1bc742181ded4930842b46e9507372f0b1b963James Dong			    &i,
2620c1bc742181ded4930842b46e9507372f0b1b963James Dong			    pZigzagTable);
2630c1bc742181ded4930842b46e9507372f0b1b963James Dong	    }
2640c1bc742181ded4930842b46e9507372f0b1b963James Dong	    else
2650c1bc742181ded4930842b46e9507372f0b1b963James Dong	    {
2660c1bc742181ded4930842b46e9507372f0b1b963James Dong		    *pLast = armGetBits(ppBitStream, pBitOffset, 1);
2670c1bc742181ded4930842b46e9507372f0b1b963James Dong		    storeRun  = armGetBits(ppBitStream, pBitOffset, 6);
2680c1bc742181ded4930842b46e9507372f0b1b963James Dong		    armRetDataErrIf((i + storeRun) >= 64, OMX_Sts_Err);
2690c1bc742181ded4930842b46e9507372f0b1b963James Dong		    markerBit = armGetBits(ppBitStream, pBitOffset, 1);
2700c1bc742181ded4930842b46e9507372f0b1b963James Dong		    armRetDataErrIf( markerBit == 0, OMX_Sts_Err);
2710c1bc742181ded4930842b46e9507372f0b1b963James Dong		    storeLevel  = armGetBits(ppBitStream, pBitOffset, 12);
2720c1bc742181ded4930842b46e9507372f0b1b963James Dong		    if (storeLevel & 0x800)
2730c1bc742181ded4930842b46e9507372f0b1b963James Dong		    {
2740c1bc742181ded4930842b46e9507372f0b1b963James Dong			    storeLevel -= 4096;
2750c1bc742181ded4930842b46e9507372f0b1b963James Dong		    }
2760c1bc742181ded4930842b46e9507372f0b1b963James Dong		    armRetDataErrIf( storeLevel == 0 || storeLevel == -2048 , OMX_Sts_Err); /* Invalid FLC */
2770c1bc742181ded4930842b46e9507372f0b1b963James Dong		    armGetBits(ppBitStream, pBitOffset, 1);
2780c1bc742181ded4930842b46e9507372f0b1b963James Dong		    armVCM4P2_FillVLDBuffer(
2790c1bc742181ded4930842b46e9507372f0b1b963James Dong			    storeRun,
2800c1bc742181ded4930842b46e9507372f0b1b963James Dong			    pDst,
2810c1bc742181ded4930842b46e9507372f0b1b963James Dong			    storeLevel,
2820c1bc742181ded4930842b46e9507372f0b1b963James Dong			    0, /* Sign is not used, preprocessing done */
2830c1bc742181ded4930842b46e9507372f0b1b963James Dong			    *pLast,
2840c1bc742181ded4930842b46e9507372f0b1b963James Dong			    &i,
2850c1bc742181ded4930842b46e9507372f0b1b963James Dong			    pZigzagTable);
2860c1bc742181ded4930842b46e9507372f0b1b963James Dong
2870c1bc742181ded4930842b46e9507372f0b1b963James Dong	    }
2880c1bc742181ded4930842b46e9507372f0b1b963James Dong    } /* End of forloop for i */
2890c1bc742181ded4930842b46e9507372f0b1b963James Dong	return OMX_Sts_NoErr;
2900c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2910c1bc742181ded4930842b46e9507372f0b1b963James Dong
2920c1bc742181ded4930842b46e9507372f0b1b963James Dong/* End of File */
2930c1bc742181ded4930842b46e9507372f0b1b963James Dong
294