• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 #ifndef WELS_VLC_DECODER_H__
34 #define WELS_VLC_DECODER_H__
35 
36 #include "bit_stream.h"
37 #include "dec_golomb.h"
38 
39 namespace WelsDec {
40 
41 typedef struct TagVlcTable {
42 const uint8_t (*kpCoeffTokenVlcTable[4][8])[2];
43 const uint8_t (*kpChromaCoeffTokenVlcTable)[2];
44 const uint8_t (*kpZeroTable[7])[2];
45 const uint8_t (*kpTotalZerosTable[2][15])[2];
46 } SVlcTable;
47 
48 // for data sharing cross modules and try to reduce size of binary generated
49 extern const uint8_t g_kuiVlcChromaTable[256][2];
50 extern const uint8_t g_kuiVlcTable_0[256][2];
51 extern const uint8_t g_kuiVlcTable_0_0[256][2];
52 extern const uint8_t g_kuiVlcTable_0_1[4][2];
53 extern const uint8_t g_kuiVlcTable_0_2[2][2];
54 extern const uint8_t g_kuiVlcTable_0_3[2][2];
55 extern const uint8_t g_kuiVlcTable_1[256][2];
56 extern const uint8_t g_kuiVlcTable_1_0[64][2];
57 extern const uint8_t g_kuiVlcTable_1_1[8][2];
58 extern const uint8_t g_kuiVlcTable_1_2[2][2];
59 extern const uint8_t g_kuiVlcTable_1_3[2][2];
60 extern const uint8_t g_kuiVlcTable_2[256][2];
61 extern const uint8_t g_kuiVlcTable_2_0[4][2];
62 extern const uint8_t g_kuiVlcTable_2_1[4][2];
63 extern const uint8_t g_kuiVlcTable_2_2[4][2];
64 extern const uint8_t g_kuiVlcTable_2_3[4][2];
65 extern const uint8_t g_kuiVlcTable_2_4[2][2];
66 extern const uint8_t g_kuiVlcTable_2_5[2][2];
67 extern const uint8_t g_kuiVlcTable_2_6[2][2];
68 extern const uint8_t g_kuiVlcTable_2_7[2][2];
69 extern const uint8_t g_kuiVlcTable_3[64][2];
70 extern const uint8_t g_kuiVlcTableNeedMoreBitsThread[3];
71 extern const uint8_t g_kuiVlcTableMoreBitsCount0[4];
72 extern const uint8_t g_kuiVlcTableMoreBitsCount1[4];
73 extern const uint8_t g_kuiVlcTableMoreBitsCount2[8];
74 extern const uint8_t g_kuiNcMapTable[17];
75 extern const uint8_t g_kuiVlcTrailingOneTotalCoeffTable[62][2];
76 extern const uint8_t g_kuiTotalZerosTable0[512][2];
77 extern const uint8_t g_kuiTotalZerosTable1[64][2];
78 extern const uint8_t g_kuiTotalZerosTable2[64][2];
79 extern const uint8_t g_kuiTotalZerosTable3[32][2];
80 extern const uint8_t g_kuiTotalZerosTable4[32][2];
81 extern const uint8_t g_kuiTotalZerosTable5[64][2];
82 extern const uint8_t g_kuiTotalZerosTable6[64][2];
83 extern const uint8_t g_kuiTotalZerosTable7[64][2];
84 extern const uint8_t g_kuiTotalZerosTable8[64][2];
85 extern const uint8_t g_kuiTotalZerosTable9[32][2];
86 extern const uint8_t g_kuiTotalZerosTable10[16][2];
87 extern const uint8_t g_kuiTotalZerosTable11[16][2];
88 extern const uint8_t g_kuiTotalZerosTable12[8][2];
89 extern const uint8_t g_kuiTotalZerosTable13[4][2];
90 extern const uint8_t g_kuiTotalZerosTable14[2][2];
91 extern const uint8_t g_kuiTotalZerosBitNumMap[15];
92 extern const uint8_t g_kuiTotalZerosChromaTable0[8][2];
93 extern const uint8_t g_kuiTotalZerosChromaTable1[4][2];
94 extern const uint8_t g_kuiTotalZerosChromaTable2[2][2];
95 extern const uint8_t g_kuiTotalZerosBitNumChromaMap[3];
96 extern const uint8_t g_kuiZeroLeftTable0[2][2];
97 extern const uint8_t g_kuiZeroLeftTable1[4][2];
98 extern const uint8_t g_kuiZeroLeftTable2[4][2];
99 extern const uint8_t g_kuiZeroLeftTable3[8][2];
100 extern const uint8_t g_kuiZeroLeftTable4[8][2];
101 extern const uint8_t g_kuiZeroLeftTable5[8][2];
102 extern const uint8_t g_kuiZeroLeftTable6[8][2];
103 extern const uint8_t g_kuiZeroLeftBitNumMap[16];
104 
105 #if defined(_MSC_VER) && defined(_M_IX86)
106 //TODO need linux version
107 #define WELS_GET_PREFIX_BITS(inval,outval){\
108   uint32_t local = inval;\
109   __asm xor       eax,    eax\
110   __asm bsr       eax,    local\
111   __asm sub       eax,    32\
112   __asm neg       eax\
113   __asm mov       outval, eax\
114 }
115 #else
116 #define WELS_GET_PREFIX_BITS(inval, outval) outval = GetPrefixBits(inval)
117 #endif
118 
InitVlcTable(SVlcTable * pVlcTable)119 static inline void InitVlcTable (SVlcTable* pVlcTable) {
120 pVlcTable->kpChromaCoeffTokenVlcTable = g_kuiVlcChromaTable;
121 
122 pVlcTable->kpCoeffTokenVlcTable[0][0] = g_kuiVlcTable_0;
123 pVlcTable->kpCoeffTokenVlcTable[0][1] = g_kuiVlcTable_1;
124 pVlcTable->kpCoeffTokenVlcTable[0][2] = g_kuiVlcTable_2;
125 pVlcTable->kpCoeffTokenVlcTable[0][3] = g_kuiVlcTable_3;
126 
127 pVlcTable->kpCoeffTokenVlcTable[1][0] = g_kuiVlcTable_0_0;
128 pVlcTable->kpCoeffTokenVlcTable[1][1] = g_kuiVlcTable_0_1;
129 pVlcTable->kpCoeffTokenVlcTable[1][2] = g_kuiVlcTable_0_2;
130 pVlcTable->kpCoeffTokenVlcTable[1][3] = g_kuiVlcTable_0_3;
131 
132 pVlcTable->kpCoeffTokenVlcTable[2][0] = g_kuiVlcTable_1_0;
133 pVlcTable->kpCoeffTokenVlcTable[2][1] = g_kuiVlcTable_1_1;
134 pVlcTable->kpCoeffTokenVlcTable[2][2] = g_kuiVlcTable_1_2;
135 pVlcTable->kpCoeffTokenVlcTable[2][3] = g_kuiVlcTable_1_3;
136 
137 pVlcTable->kpCoeffTokenVlcTable[3][0] = g_kuiVlcTable_2_0;
138 pVlcTable->kpCoeffTokenVlcTable[3][1] = g_kuiVlcTable_2_1;
139 pVlcTable->kpCoeffTokenVlcTable[3][2] = g_kuiVlcTable_2_2;
140 pVlcTable->kpCoeffTokenVlcTable[3][3] = g_kuiVlcTable_2_3;
141 pVlcTable->kpCoeffTokenVlcTable[3][4] = g_kuiVlcTable_2_4;
142 pVlcTable->kpCoeffTokenVlcTable[3][5] = g_kuiVlcTable_2_5;
143 pVlcTable->kpCoeffTokenVlcTable[3][6] = g_kuiVlcTable_2_6;
144 pVlcTable->kpCoeffTokenVlcTable[3][7] = g_kuiVlcTable_2_7;
145 
146 pVlcTable->kpZeroTable[0] = g_kuiZeroLeftTable0;
147 pVlcTable->kpZeroTable[1] = g_kuiZeroLeftTable1;
148 pVlcTable->kpZeroTable[2] = g_kuiZeroLeftTable2;
149 pVlcTable->kpZeroTable[3] = g_kuiZeroLeftTable3;
150 pVlcTable->kpZeroTable[4] = g_kuiZeroLeftTable4;
151 pVlcTable->kpZeroTable[5] = g_kuiZeroLeftTable5;
152 pVlcTable->kpZeroTable[6] = g_kuiZeroLeftTable6;
153 
154 pVlcTable->kpTotalZerosTable[0][0] = g_kuiTotalZerosTable0;
155 pVlcTable->kpTotalZerosTable[0][1] = g_kuiTotalZerosTable1;
156 pVlcTable->kpTotalZerosTable[0][2] = g_kuiTotalZerosTable2;
157 pVlcTable->kpTotalZerosTable[0][3] = g_kuiTotalZerosTable3;
158 pVlcTable->kpTotalZerosTable[0][4] = g_kuiTotalZerosTable4;
159 pVlcTable->kpTotalZerosTable[0][5] = g_kuiTotalZerosTable5;
160 pVlcTable->kpTotalZerosTable[0][6] = g_kuiTotalZerosTable6;
161 pVlcTable->kpTotalZerosTable[0][7] = g_kuiTotalZerosTable7;
162 pVlcTable->kpTotalZerosTable[0][8] = g_kuiTotalZerosTable8;
163 pVlcTable->kpTotalZerosTable[0][9] = g_kuiTotalZerosTable9;
164 pVlcTable->kpTotalZerosTable[0][10] = g_kuiTotalZerosTable10;
165 pVlcTable->kpTotalZerosTable[0][11] = g_kuiTotalZerosTable11;
166 pVlcTable->kpTotalZerosTable[0][12] = g_kuiTotalZerosTable12;
167 pVlcTable->kpTotalZerosTable[0][13] = g_kuiTotalZerosTable13;
168 pVlcTable->kpTotalZerosTable[0][14] = g_kuiTotalZerosTable14;
169 pVlcTable->kpTotalZerosTable[1][0] = g_kuiTotalZerosChromaTable0;
170 pVlcTable->kpTotalZerosTable[1][1] = g_kuiTotalZerosChromaTable1;
171 pVlcTable->kpTotalZerosTable[1][2] = g_kuiTotalZerosChromaTable2;
172 
173 }
174 
175 } // namespace WelsDec
176 
177 #endif//WELS_VLC_DECODER_H__
178