History

merge bit_stream.h for encoder&decoder

huili2 committed 11 years ago

Commit ed1140b1 parent 585855b29 files · +350 −482Browse files

Showing the changes to codec/decoder/core/src/bit_stream.cpp (1 of 29 files). Show all

Unified · Split

codec/decoder/core/src/bit_stream.cpp+1−110
@@ -67,7 +67,7 @@ int32_t InitReadBits (PBitStringAux pBitString, intX_t iEndOffset) { · 66 unmodified lines
6767 *
6868 * \return 0: success, other: fail
6969 */
70−int32_t InitBits (PBitStringAux pBitString, const uint8_t* kpBuf, const int32_t kiSize) {
70+int32_t DecInitBits (PBitStringAux pBitString, const uint8_t* kpBuf, const int32_t kiSize) {
7171 const int32_t kiSizeBuf = (kiSize + 7) >> 3;
7272 uint8_t* pTmp = (uint8_t*)kpBuf;
7373
@@ -85,115 +85,6 @@ int32_t InitBits (PBitStringAux pBitString, const uint8_t* kpBuf, const int32_t · 11 unmodified lines
8585 return ERR_NONE;
8686 }
8787
88−//Following for write bs in decoder
89−void DecInitBitsForEncoding (PBitStringAux pBitString, uint8_t* pBuf, const int32_t kiSize) {
90− uint8_t* pPtr = pBuf;
91− pBitString->pStartBuf = pPtr;
92− pBitString->pCurBuf = pPtr;
93− pBitString->pEndBuf = pPtr + kiSize;
94− pBitString->iLeftBits = 32;
95− pBitString->uiCurBits = 0;
96−}
97−
98−#define WRITE_BE_32(ptr, val) do { \
99− (ptr)[0] = (val) >> 24; \
100− (ptr)[1] = (val) >> 16; \
101− (ptr)[2] = (val) >> 8; \
102− (ptr)[3] = (val) >> 0; \
103− } while (0);
104−
105−int32_t DecBsWriteBits (PBitStringAux pBitString, int32_t iLen, const uint32_t kuiValue) {
106− if (iLen < pBitString->iLeftBits) {
107− pBitString->uiCurBits = (pBitString->uiCurBits << iLen) | kuiValue;
108− pBitString->iLeftBits -= iLen;
109− } else {
110− iLen -= pBitString->iLeftBits;
111− pBitString->uiCurBits = (pBitString->uiCurBits << pBitString->iLeftBits) | (kuiValue >> iLen);
112− WRITE_BE_32 (pBitString->pCurBuf, pBitString->uiCurBits);
113− pBitString->pCurBuf += 4;
114− pBitString->uiCurBits = kuiValue & ((1 << iLen) - 1);
115− pBitString->iLeftBits = 32 - iLen;
116− }
117− return 0;
118−}
119−
120−int32_t DecBsWriteOneBit (PBitStringAux pBitString, const uint32_t kuiValue) {
121− DecBsWriteBits (pBitString, 1, kuiValue);
122− return 0;
123−}
124−
125−int32_t DecBsFlush (PBitStringAux pBitString) {
126− WRITE_BE_32 (pBitString->pCurBuf, pBitString->uiCurBits << pBitString->iLeftBits);
127− pBitString->pCurBuf += 4 - pBitString->iLeftBits / 8;
128− pBitString->iLeftBits = 32;
129− pBitString->uiCurBits = 0;
130− return 0;
131−}
132−
133−const uint32_t g_kuiDecGolombUELength[256] = {
134− 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, //14
135− 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, //30
136− 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,//46
137− 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,//62
138− 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,//
139− 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
140− 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
141− 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
142− 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
143− 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
144− 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
145− 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
146− 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
147− 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
148− 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
149− 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
150− 17
151−};
152−
153−int32_t DecBsWriteUe (PBitStringAux pBitString, const uint32_t kuiValue) {
154− uint32_t iTmpValue = kuiValue + 1;
155− if (256 > kuiValue) {
156− DecBsWriteBits (pBitString, g_kuiDecGolombUELength[kuiValue], kuiValue + 1);
157− } else {
158− uint32_t n = 0;
159− if (iTmpValue & 0xffff0000) {
160− iTmpValue >>= 16;
161− n += 16;
162− }
163− if (iTmpValue & 0xff) {
164− iTmpValue >>= 8;
165− n += 8;
166− }
167−
168− //n += (g_kuiDecGolombUELength[iTmpValue] >> 1);
169−
170− n += (g_kuiDecGolombUELength[iTmpValue - 1] >> 1);
171− DecBsWriteBits (pBitString, (n << 1) + 1, kuiValue + 1);
172− }
173− return 0;
174−}
175−
176−int32_t DecBsWriteSe (PBitStringAux pBitString, const int32_t kiValue) {
177− uint32_t iTmpValue;
178− if (0 == kiValue) {
179− DecBsWriteOneBit (pBitString, 1);
180− } else if (0 < kiValue) {
181− iTmpValue = (kiValue << 1) - 1;
182− DecBsWriteUe (pBitString, iTmpValue);
183− } else {
184− iTmpValue = ((-kiValue) << 1);
185− DecBsWriteUe (pBitString, iTmpValue);
186− }
187− return 0;
188−}
189−
190−int32_t DecBsRbspTrailingBits (PBitStringAux pBitString) {
191− DecBsWriteOneBit (pBitString, 1);
192− DecBsFlush (pBitString);
193−
194− return 0;
195−}
196−
19788 void RBSP2EBSP (uint8_t* pDstBuf, uint8_t* pSrcBuf, const int32_t kiSize) {
19889 uint8_t* pSrcPointer = pSrcBuf;
19990 uint8_t* pDstPointer = pDstBuf;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t