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