?? vlc.c
字號:
/*COPYRIGHT, LICENSE AND WARRANTY INFORMATIONThis software module has been originally developed by Nokia Corporation. Provided that a person, entity or a company willing to use the Software (hereinafter Licensee) comply with all the terms and conditions of this Statement and subject to the limitations set forth in this Statement Nokia grants to such Licensee a non-exclusive, sub-licensable, worldwide, limited license under copyrights owned by Nokia to use the Software for the sole purpose of creating, manufacturing, selling, marketing, or distributing (including the right to make modifications to the Software) a fully compliant decoder implementation (hereinafter "Decoder") of ITU-T Recommendation H.264 / ISO/IEC International Standard 14496-10 and an encoder implementation producing output that is decodable with the Decoder.Nokia retains the ownership of copyrights to the Software. There is no patent nor other intellectual property right of Nokia licensed under this Statement (except the copyright license above). Licensee hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if patent licenses are required, it is their responsibility to acquire the license before utilizing the Software.The license by Nokia is subject to that the Licensee grants to Nokia the non-exclusive, worldwide, royalty-free, perpetual and irrevocable covenant that the Licensee(s) shall not bring a suit before any court or administrative agency or otherwise assert a claim for infringement under the Licensee intellectual property rights that, but for a license, would be infringed by the Software against (a) Nokia or Nokia's Affiliate; or (b) other recipient of a license and covenant not to sue with respect to the Software from Nokia; or (c) contractor, customer or distributor of a party listed above in a or b, which suit or claim is related to the Software or use thereof.The Licensee(s) further agrees to grant a reciprocal license to Nokia (as granted by Nokia to the Licensee(s) on the modifications made by Licensee(s) to the Software. THE SOFTWARE IS PROVIDED "AS IS" AND THE ORIGINAL DEVELOPER DISCLAIMS ANY AND ALL WARRANTIES WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. THOSE INTENDING TO USE THE SOFTWARE ARE EXPRESSLY ADVISED THAT ITS USE MAY INFRINGE EXISTING PATENTS AND BE SUBJECT TO ROYALTY PAYMENTS TO PATENT OWNERS. ANYONE USING THE SOFTWARE ON THE BASIS OF THIS LICENSE AGREES TO OBTAIN THE NECESSARY PERMISSIONS FROM ANY AND ALL APPLICABLE PATENT OWNERS FOR SUCH USE.IN NO EVENT SHALL THE ORIGINAL DEVELOPER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.This copyright, license and warranty information notice must be retained in all copies and derivative works of the Software or substantial portions thereof.*/#include "vlcutility.h"#include "vlc.h"static const vlcCode_s numCoefsTrailTabChroma[4][5] = { {{1,2},{7,6},{4,6},{3,6},{2,6}}, {{0,0},{1,1},{6,6},{3,7},{3,8}}, {{0,0},{0,0},{1,3},{2,7},{2,8}}, {{0,0},{0,0},{0,0},{5,6},{0,7}},};static const vlcCode_s totZerosTab[15][16] = { {{1,1},{3,3},{2,3},{3,4},{2,4},{3,5},{2,5},{3,6},{2,6},{3,7},{2,7},{3,8},{2,8},{3,9},{2,9},{1, 9}}, {{7,3},{6,3},{5,3},{4,3},{3,3},{5,4},{4,4},{3,4},{2,4},{3,5},{2,5},{3,6},{2,6},{1,6},{0,6}}, {{5,4},{7,3},{6,3},{5,3},{4,4},{3,4},{4,3},{3,3},{2,4},{3,5},{2,5},{1,6},{1,5},{0,6}}, {{3,5},{7,3},{5,4},{4,4},{6,3},{5,3},{4,3},{3,4},{3,3},{2,4},{2,5},{1,5},{0,5}}, {{5,4},{4,4},{3,4},{7,3},{6,3},{5,3},{4,3},{3,3},{2,4},{1,5},{1,4},{0,5}}, {{1,6},{1,5},{7,3},{6,3},{5,3},{4,3},{3,3},{2,3},{1,4},{1,3},{0,6}}, {{1,6},{1,5},{5,3},{4,3},{3,3},{3,2},{2,3},{1,4},{1,3},{0,6}}, {{1,6},{1,4},{1,5},{3,3},{3,2},{2,2},{2,3},{1,3},{0,6}}, {{1,6},{0,6},{1,4},{3,2},{2,2},{1,3},{1,2},{1,5}}, {{1,5},{0,5},{1,3},{3,2},{2,2},{1,2},{1,4}}, {{0,4},{1,4},{1,3},{2,3},{1,1},{3,3}}, {{0,4},{1,4},{1,2},{1,1},{1,3}}, {{0,3},{1,3},{1,1},{1,2}}, {{0,2},{1,2},{1,1}}, {{0,1},{1,1}},};static const vlcCode_s totZerosTabChroma[3][4] = { {{1, 1}, {1, 2}, {1, 3}, {0, 3},}, {{1, 1}, {1, 2}, {0, 2}, {0, 0},}, {{1, 1}, {0, 1}, {0, 0}, {0, 0},}};static const vlcCode_s runTab[6][7] = { {{1,1}, {0,1}}, {{1,1}, {1,2}, {0,2}}, {{3,2}, {2,2}, {1,2}, {0,2}}, {{3,2}, {2,2}, {1,2}, {1,3}, {0,3}}, {{3,2}, {2,2}, {3,3}, {2,3}, {1,3}, {0,3}}, {{3,2}, {0,3}, {1,3}, {3,3}, {2,3}, {5,3}, {4,3}},};static const vlcCode_s runTabLong[15] = { {7,3}, {6,3}, {5,3}, {4,3}, {3,3}, {2,3}, {1,3}, {1,4}, {1,5}, {1,6}, {1,7}, {1,8}, {1,9}, {1,10}, {1,11},};static const int incVlc[7] = { 0,3,6,12,24,48,32768 /* maximum vlc = 6 */};static const int8 vlcNumTab[8] = { 0, 0, 1, 1, 2, 2, 2, 2};static const int8 numCoefsTrailTab[3][4][17] = { { { 1, 5, 7, 7, 7, 7,15,11, 8,15,11,15,11,15,11, 7,4}, { 0, 1, 4, 6, 6, 6, 6,14,10,14,10,14,10, 1,14,10,6}, { 0, 0, 1, 5, 5, 5, 5, 5,13, 9,13, 9,13, 9,13, 9,5}, { 0, 0, 0, 3, 3, 4, 4, 4, 4, 4,12,12, 8,12, 8,12,8} }, { { 3,11, 7, 7, 7, 4, 7,15,11,15,11, 8,15,11, 7, 9,7}, { 0, 2, 7,10, 6, 6, 6, 6,14,10,14,10,14,10,11, 8,6}, { 0, 0, 3, 9, 5, 5, 5, 5,13, 9,13, 9,13, 9, 6,10,5}, { 0, 0, 0, 5, 4, 6, 8, 4, 4, 4,12, 8,12,12, 8, 1,4} }, { {15,15,11, 8,15,11, 9, 8,15,11,15,11, 8,13, 9, 5,1}, { 0,14,15,12,10, 8,14,10,14,14,10,14,10, 7,12, 8,4}, { 0, 0,13,14,11, 9,13, 9,13,10,13, 9,13, 9,11, 7,3}, { 0, 0, 0,12,11,10, 9, 8,13,12,12,12, 8,12,10, 6,2} }};static const int8 numCoefsTrailLenTab[3][4][17] = { { { 1, 6, 8, 9,10,11,13,13,13,14,14,15,15,16,16,16,16}, { 0, 2, 6, 8, 9,10,11,13,13,14,14,15,15,15,16,16,16}, { 0, 0, 3, 7, 8, 9,10,11,13,13,14,14,15,15,16,16,16}, { 0, 0, 0, 5, 6, 7, 8, 9,10,11,13,14,14,15,15,16,16} }, { { 2, 6, 6, 7, 8, 8, 9,11,11,12,12,12,13,13,13,14,14}, { 0, 2, 5, 6, 6, 7, 8, 9,11,11,12,12,13,13,14,14,14}, { 0, 0, 3, 6, 6, 7, 8, 9,11,11,12,12,13,13,13,14,14}, { 0, 0, 0, 4, 4, 5, 6, 6, 7, 9,11,11,12,13,13,13,14} }, { { 4, 6, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9,10,10,10,10}, { 0, 4, 5, 5, 5, 5, 6, 6, 7, 8, 8, 9, 9, 9,10,10,10}, { 0, 0, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10}, { 0, 0, 0, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 9,10,10,10} }};/* * Codes for Coded Block Patterns for intra and inter */const int8 cbpCode[48][2] = { { 3, 0},{29, 2},{30, 3},{17, 7},{31, 4},{18, 8},{37,17},{ 8,13},{32, 5},{38,18},{19, 9},{ 9,14}, {20,10},{10,15},{11,16},{ 2,11},{16, 1},{33,32},{34,33},{21,36},{35,34},{22,37},{39,44},{ 4,40}, {36,35},{40,45},{23,38},{ 5,41},{24,39},{ 6,42},{ 7,43},{ 1,19},{41, 6},{42,24},{43,25},{25,20}, {44,26},{26,21},{46,46},{12,28},{45,27},{47,47},{27,22},{13,29},{28,23},{14,30},{15,31},{ 0,12},}; /* * vlcSendMbSkipFlag: * * Parameters: * bitbuf Bitbuffer handle * mb Macroblock object * stat Statistics * * Function: * Send the MB skipping count. * * Returns: * 1, MB skipped, 0, MB not skipped. */int vlcSendMbSkipFlag(bitbuffer_s *bitbuf, macroblock_s *mb, int skipFlag){ int bitsSkipLen; int sendSkipCount; sendSkipCount = 1; if (skipFlag) { mb->numSkipped += 1; if (! mb->isLastMb) sendSkipCount = 0; } bitsSkipLen = 0; if (sendSkipCount) { bitsSkipLen = vlcuSendUVLC(bitbuf, mb->numSkipped); mb->headerBits = bitsSkipLen; mb->numSkipped = 0; } return bitsSkipLen;}/* * vlcSendMotVecs * * Parameters: * bitbuf Bitbuffer * interMode Mode for inter MB (16x16, 8x16, 16x8 or 8x8) * numRefFrames Number of reference frames scanned * diffVecs Differential motion vectors * numVecs Number of motion vectors * refIndices Reference frame indices * * Function: * Send motion vectors. * * Returns: * Number of bits for prediction modes. */int vlcSendMotVecs(bitbuffer_s *bitbuf, int interMode, int numRefFrames, int16 diffVecs[16][2], int numVecs, u_int8 refIndices[4]){ int i, j; int bits = 0; /* Send reference frame indices if there are more than one reference frames */ /* and all indices are not zero for inter mode >= 4 */ if (numRefFrames > 1 && !(interMode == MOT_8x8 && ((refIndices[0] | refIndices[1] | refIndices[2] | refIndices[3]) == 0))) { /* If there are only two ref. frames we just send one bit flag for each index */ if (numRefFrames == 2) { for (i = 0; i < numOfRefPar[interMode - 1]; i ++) bibPutBits(bitbuf, 1 - refIndices[i], 1); bits += numOfRefPar[interMode-1]; } /* Otherwise we send UVLC code for each index */ else { for (i = 0; i < numOfRefPar[interMode-1]; i++) bits += vlcuSendUVLC(bitbuf, refIndices[i]); } } for(j = 0; j < numVecs; j++) { for(i = 0; i < 2; i++) { bits += vlcuSendUVLC(bitbuf, vlcuMapSigned(diffVecs[j][i])); } } return bits;}/* * vlcuSendIntraPred * * Parameters: * bitbuf Bitbuffer * ipTab Intra predicition modes * * Function: * Send 4x4 intra prediction modes. * * Returns: * Number of bits for prediction modes. */int vlcSendIntraPred(bitbuffer_s *bitbuf, int8 *ipTab){ int i; int numNonPredicted; numNonPredicted = 0; for (i = 0; i < 16; i ++) { if (ipTab[i] < 0) bibPutBits(bitbuf, 1, 1); else { numNonPredicted ++; bibPutBits(bitbuf, ipTab[i], 4); } } return (16 + numNonPredicted * 3);}/* * vlcSendCbp * * Parameters: * bitbuf Bitbuffer * type Type of the macroblock * cbp Combined coded Block Pattern for luma and chroma * * Function: * Send Coded Block Pattern. * * Returns: * Number of bits for Coded Block Pattern. */int vlcSendCbp(bitbuffer_s *bitbuf, int mbType, int cbp){ int code; if (mbType == MBK_INTRA) code = cbpCode[cbp][0]; else
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -