Home | History | Annotate | Download | only in src
      1 /**
      2  *
      3  * File Name:  armVCM4P2_PutVLCBits.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 VLC put bits to bitstream
     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 #include "armVCM4P2_ZigZag_Tables.h"
     24 #include "armVCM4P2_Huff_Tables_VLC.h"
     25 
     26 
     27 /**
     28  * Function: armVCM4P2_PutVLCBits
     29  *
     30  * Description:
     31  * Checks the type of Escape Mode and put encoded bits for
     32  * quantized DCT coefficients.
     33  *
     34  * Remarks:
     35  *
     36  * Parameters:
     37  * [in]	 ppBitStream      pointer to the pointer to the current byte in
     38  *						  the bit stream
     39  * [in]	 pBitOffset       pointer to the bit position in the byte pointed
     40  *                        by *ppBitStream. Valid within 0 to 7
     41  * [in] shortVideoHeader binary flag indicating presence of short_video_header; escape modes 0-3 are used if shortVideoHeader==0,
     42  *                           and escape mode 4 is used when shortVideoHeader==1.
     43  * [in]  start            start indicates whether the encoding begins with
     44  *                        0th element or 1st.
     45  * [in]  maxStoreRunL0    Max store possible (considering last and inter/intra)
     46  *                        for last = 0
     47  * [in]  maxStoreRunL1    Max store possible (considering last and inter/intra)
     48  *                        for last = 1
     49  * [in]  maxRunForMultipleEntriesL0
     50  *                        The run value after which level
     51  *                        will be equal to 1:
     52  *                        (considering last and inter/intra status) for last = 0
     53  * [in]  maxRunForMultipleEntriesL1
     54  *                        The run value after which level
     55  *                        will be equal to 1:
     56  *                        (considering last and inter/intra status) for last = 1
     57  * [in]  pRunIndexTableL0 Run Index table defined in
     58  *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
     59  * [in]  pVlcTableL0      VLC table for last == 0
     60  * [in]  pRunIndexTableL1 Run Index table defined in
     61  *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
     62  * [in]  pVlcTableL1      VLC table for last == 1
     63  * [in]  pLMAXTableL0     Level MAX table defined in
     64  *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
     65  * [in]  pLMAXTableL1     Level MAX table defined in
     66  *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
     67  * [in]  pRMAXTableL0     Run MAX table defined in
     68  *                        armVCM4P2_Huff_Tables_VLC.c for last == 0
     69  * [in]  pRMAXTableL1     Run MAX table defined in
     70  *                        armVCM4P2_Huff_Tables_VLC.c for last == 1
     71  * [out] pQDctBlkCoef     pointer to the quantized DCT coefficient
     72  * [out] ppBitStream      *ppBitStream is updated after the block is encoded
     73  *                        so that it points to the current byte in the bit
     74  *                        stream buffer.
     75  * [out] pBitOffset       *pBitOffset is updated so that it points to the
     76  *                        current bit position in the byte pointed by
     77  *                        *ppBitStream.
     78  *
     79  * Return Value:
     80  * Standard OMXResult result. See enumeration for possible result codes.
     81  *
     82  */
     83 
     84 
     85 OMXResult armVCM4P2_PutVLCBits (
     86               OMX_U8 **ppBitStream,
     87               OMX_INT * pBitOffset,
     88               const OMX_S16 *pQDctBlkCoef,
     89               OMX_INT shortVideoHeader,
     90               OMX_U8 start,
     91               OMX_U8 maxStoreRunL0,
     92               OMX_U8 maxStoreRunL1,
     93               OMX_U8  maxRunForMultipleEntriesL0,
     94               OMX_U8  maxRunForMultipleEntriesL1,
     95               const OMX_U8  * pRunIndexTableL0,
     96               const ARM_VLC32 *pVlcTableL0,
     97 			  const OMX_U8  * pRunIndexTableL1,
     98               const ARM_VLC32 *pVlcTableL1,
     99               const OMX_U8  * pLMAXTableL0,
    100               const OMX_U8  * pLMAXTableL1,
    101               const OMX_U8  * pRMAXTableL0,
    102               const OMX_U8  * pRMAXTableL1,
    103               const OMX_U8  * pZigzagTable
    104 )
    105 {
    106 
    107     OMX_U32 storeRun = 0, run, storeRunPlus;
    108     OMX_U8  last = 0, first = 1, fMode;
    109     OMX_S16 level, storeLevel = 0, storeLevelPlus;
    110     OMX_INT i;
    111 
    112         /* RLE encoding and packing the bits into the streams */
    113         for (i = start, run=0; i < 64; i++)
    114         {
    115             level   = pQDctBlkCoef[pZigzagTable[i]];
    116 
    117             /* Counting the run */
    118             if (level == 0)
    119             {
    120                 run++;
    121             }
    122 
    123             /* Found a non-zero coeff */
    124             else
    125             {
    126                 if (first == 0)
    127                 {
    128                     last = 0;
    129 
    130                     /* Check for a valid entry in the VLC table */
    131                     storeLevelPlus = armSignCheck(storeLevel) *
    132                       (armAbs(storeLevel) - pLMAXTableL0[storeRun]);
    133                     storeRunPlus = storeRun -
    134                                   (pRMAXTableL0[armAbs(storeLevel) - 1] + 1);
    135 
    136                     fMode = armVCM4P2_CheckVLCEscapeMode(
    137                                              storeRun,
    138                                              storeRunPlus,
    139                                              storeLevel,
    140                                              storeLevelPlus,
    141                                              maxStoreRunL0,
    142                                              maxRunForMultipleEntriesL0,
    143                                              shortVideoHeader,
    144                                              pRunIndexTableL0);
    145 
    146                     armVCM4P2_FillVLCBuffer (
    147                                       ppBitStream,
    148                                       pBitOffset,
    149                                       storeRun,
    150                                       storeLevel,
    151 									  storeRunPlus,
    152                                       storeLevelPlus,
    153                                       fMode,
    154 									  last,
    155                                       maxRunForMultipleEntriesL0,
    156                                       pRunIndexTableL0,
    157                                       pVlcTableL0);
    158                 }
    159                 storeLevel = level;
    160                 storeRun   = run;
    161                 first = 0;
    162                 run = 0;
    163             }
    164 
    165         } /* end of for loop for 64 elements */
    166 
    167         /* writing the last element */
    168         last = 1;
    169 
    170         /* Check for a valid entry in the VLC table */
    171         storeLevelPlus = armSignCheck(storeLevel) *
    172                         (armAbs(storeLevel) - pLMAXTableL1[run]);
    173         storeRunPlus = storeRun -
    174                       (pRMAXTableL1[armAbs(storeLevel) - 1] + 1);
    175         fMode = armVCM4P2_CheckVLCEscapeMode(
    176                                  storeRun,
    177                                  storeRunPlus,
    178                                  storeLevel,
    179                                  storeLevelPlus,
    180                                  maxStoreRunL1,
    181                                  maxRunForMultipleEntriesL1,
    182                                  shortVideoHeader,
    183                                  pRunIndexTableL1);
    184 
    185         armVCM4P2_FillVLCBuffer (
    186                           ppBitStream,
    187                           pBitOffset,
    188                           storeRun,
    189                           storeLevel,
    190 						  storeRunPlus,
    191                           storeLevelPlus,
    192                           fMode,
    193 						  last,
    194                           maxRunForMultipleEntriesL1,
    195                           pRunIndexTableL1,
    196                           pVlcTableL1);
    197 	return OMX_Sts_NoErr;
    198 }
    199 
    200 /* End of File */
    201