Home | History | Annotate | Download | only in src
      1 /**
      2  *
      3  * File Name:  armVCM4P2_FillVLCBuffer.c
      4  * OpenMAX DL: v1.0.2
      5  * Revision:   9641
      6  * Date:       Thursday, February 7, 2008
      7  *
      8  * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
      9  *
     10  *
     11  *
     12  * Description:
     13  * Contains module for putting VLC bits
     14  *
     15  */
     16 
     17 #include "omxtypes.h"
     18 #include "armOMX.h"
     19 
     20 #include "armVC.h"
     21 #include "armCOMM.h"
     22 #include "armCOMM_Bitstream.h"
     23 
     24 /**
     25  * Function: armVCM4P2_FillVLCBuffer
     26  *
     27  * Description:
     28  * Performs calculating the VLC bits depending on the escape type and insert
     29  * the same in the bitstream
     30  *
     31  * Remarks:
     32  *
     33  * Parameters:
     34  * [in]	 ppBitStream		pointer to the pointer to the current byte in
     35  *	                        the bit stream
     36  * [in]	 pBitOffset         pointer to the bit position in the byte pointed
     37  *                          by *ppBitStream. Valid within 0 to 7
     38  * [in]  run                Run value (count of zeros) to be encoded
     39  * [in]  level              Level value (non-zero value) to be encoded
     40  * [in]  runPlus            Calculated as runPlus = run - (RMAX + 1)
     41  * [in]  levelPlus          Calculated as
     42  *                          levelPlus = sign(level)*[abs(level) - LMAX]
     43  * [in]  fMode              Flag indicating the escape modes
     44  * [in]  last               status of the last flag
     45  * [in]  maxRunForMultipleEntries
     46  *                          The run value after which level will be equal to 1:
     47  *                          (considering last and inter/intra status)
     48  * [in]  pRunIndexTable     Run Index table defined in
     49  *                          armVCM4P2_Huff_Tables_VLC.h
     50  * [in]  pVlcTable          VLC table defined in armVCM4P2_Huff_Tables_VLC.h
     51  * [out] ppBitStream		*ppBitStream is updated after the block is encoded
     52  *                          so that it points to the current byte in the bit
     53  *                          stream buffer.
     54  * [out] pBitOffset         *pBitOffset is updated so that it points to the
     55  *                          current bit position in the byte pointed by
     56  *                          *ppBitStream.
     57  *
     58  * Return Value:
     59  * Standard OMXResult result. See enumeration for possible result codes.
     60  *
     61  */
     62 
     63 OMXResult armVCM4P2_FillVLCBuffer (
     64               OMX_U8 **ppBitStream,
     65               OMX_INT * pBitOffset,
     66               OMX_U32 run,
     67               OMX_S16 level,
     68 			  OMX_U32 runPlus,
     69               OMX_S16 levelPlus,
     70               OMX_U8  fMode,
     71 			  OMX_U8  last,
     72               OMX_U8  maxRunForMultipleEntries,
     73               const OMX_U8  *pRunIndexTable,
     74               const ARM_VLC32 *pVlcTable
     75 )
     76 {
     77     OMX_INT tempIndex;
     78 	OMX_U32 tempRun = run, sign = 0;
     79     OMX_S16 tempLevel = level;
     80 
     81     /* Escape sequence addition */
     82     if (fMode == 1)
     83     {
     84         armPackBits(ppBitStream, pBitOffset, 3, 7);
     85         armPackBits(ppBitStream, pBitOffset, 0, 1);
     86 		tempLevel = levelPlus;
     87 
     88     }
     89     else if(fMode == 2)
     90     {
     91         armPackBits(ppBitStream, pBitOffset, 3, 7);
     92         armPackBits(ppBitStream, pBitOffset, 2, 2);
     93 		tempRun = runPlus;
     94     }
     95     else if (fMode == 3)
     96     {
     97         armPackBits(ppBitStream, pBitOffset, 3, 7);
     98         armPackBits(ppBitStream, pBitOffset, 3, 2);
     99     }
    100     else if (fMode == 4)
    101     {
    102         armPackBits(ppBitStream, pBitOffset, 3, 7);
    103         armPackBits(ppBitStream, pBitOffset, (OMX_U32)last, 1);
    104 		armPackBits(ppBitStream, pBitOffset, tempRun, 6);
    105 		if((tempLevel != 0) && (tempLevel != -128))
    106 		{
    107 		    armPackBits(ppBitStream, pBitOffset,
    108 			   (OMX_U32) tempLevel, 8);
    109 		}
    110 		return OMX_Sts_NoErr;
    111     }
    112 
    113     if (tempLevel < 0)
    114     {
    115         sign = 1;
    116         tempLevel = armAbs(tempLevel);
    117     }
    118     /* Putting VLC bits in the stream */
    119 	if (fMode < 3)
    120 	{
    121 		if (tempRun > maxRunForMultipleEntries)
    122 		{
    123 			tempIndex = pRunIndexTable [maxRunForMultipleEntries + 1] +
    124 						(tempRun - maxRunForMultipleEntries - 1);
    125 		}
    126 		else
    127 		{
    128 			tempIndex = pRunIndexTable [tempRun] + (tempLevel -1);
    129 		}
    130 
    131 		armPackVLC32 (ppBitStream, pBitOffset,
    132 					  pVlcTable [tempIndex]);
    133 		armPackBits(ppBitStream, pBitOffset, (OMX_U32)sign, 1);
    134 	}
    135     else
    136 	{
    137 		if (sign)
    138 		{
    139 			tempLevel = -tempLevel;
    140 		}
    141 		tempRun  = run;
    142 		armPackBits(ppBitStream, pBitOffset, (OMX_U32)last, 1);
    143 		armPackBits(ppBitStream, pBitOffset, tempRun, 6);
    144 		armPackBits(ppBitStream, pBitOffset, 1, 1);
    145 		armPackBits(ppBitStream, pBitOffset,
    146 			   (OMX_U32) tempLevel, 12);
    147 		armPackBits(ppBitStream, pBitOffset, 1, 1);
    148 	}
    149     return OMX_Sts_NoErr;
    150 }
    151 
    152 /*End of File*/
    153 
    154