1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Header file for Bit Buffer module. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef _BIBLIN_H_ |
|
22 #define _BIBLIN_H_ |
|
23 |
|
24 #include "epoclib.h" |
|
25 |
|
26 /* |
|
27 * Defines |
|
28 */ |
|
29 |
|
30 /* Error codes */ |
|
31 /* Obsolete error codes are not used anymore and are defined only to maintain |
|
32 backwards compatibility with older versions of the file. */ |
|
33 #define ERR_BIB_STRUCT_ALLOC 1000 /* If a structure allocation failed */ |
|
34 #define ERR_BIB_BUFFER_ALLOC 1001 /* Obsolete */ |
|
35 #define ERR_BIB_FILE_READ 1002 /* Obsolete */ |
|
36 #define ERR_BIB_NOT_ENOUGH_DATA 1003 /* If the number of bits requested from |
|
37 the buffer is greater than the number |
|
38 of bits available in the buffer */ |
|
39 #define ERR_BIB_ALREADY_OPENED 1004 /* Obsolete */ |
|
40 #define ERR_BIB_FILE_OPEN 1005 /* Obsolete */ |
|
41 #define ERR_BIB_ALREADY_CLOSED 1006 /* Obsolete */ |
|
42 #define ERR_BIB_FILE_CLOSE 1007 /* Obsolete */ |
|
43 #define ERR_BIB_NUM_BITS 1008 /* Obsolete */ |
|
44 #define ERR_BIB_FILE_NOT_OPEN 1009 /* Obsolete */ |
|
45 #define ERR_BIB_ILLEGAL_SIZE 1010 /* Obsolete */ |
|
46 #define ERR_BIB_CANNOT_REWIND 1011 /* If the number of bits requested to be |
|
47 rewinded is greater than the number |
|
48 of bits available in the buffer */ |
|
49 #define ERR_BIB_BUFLIST 1012 /* If the internal buffer list has |
|
50 been corrupted */ |
|
51 #define ERR_BIB_TOO_SMALL_BUFFER 1013 /* Obsolete */ |
|
52 #define ERR_BIB_FEC_RELOCK 1050 /* Obsolete */ |
|
53 #define ERR_BIB_PSC_FOUND 1060 /* Obsolete */ |
|
54 |
|
55 |
|
56 /* |
|
57 * Structs and typedefs |
|
58 */ |
|
59 |
|
60 |
|
61 |
|
62 /* {{-output"bibBuffer_t_info.txt" -ignore"*" -noCR}} |
|
63 * The bibBuffer_t data type is a structure containing all the necessary data |
|
64 * for a bit buffer instance (except for the actual data buffer). This |
|
65 * structure is passed to all of the bit buffer functions. |
|
66 * {{-output"bibBuffer_t_info.txt"}} |
|
67 */ |
|
68 |
|
69 /* {{-output"bibBuffer_t.txt"}} */ |
|
70 |
|
71 |
|
72 |
|
73 enum CopyMode { |
|
74 CopyNone = 0, |
|
75 CopyWhole = 1, |
|
76 CopyWithEdit = 2, |
|
77 EditOnly = 3 |
|
78 }; |
|
79 |
|
80 typedef struct bibEditParams_s { |
|
81 |
|
82 int StartByteIndex; // start byte position where data is to be written |
|
83 int StartBitIndex; // start bit position where data is to be written |
|
84 int curNumBits; // number of bits that need to be replaced |
|
85 int newNumBits; // number of bits to be written |
|
86 int newValue; // the value to be written |
|
87 |
|
88 } bibEditParams_t; |
|
89 |
|
90 typedef struct bibBufferEdit_s { |
|
91 |
|
92 CopyMode copyMode; |
|
93 int numChanges; |
|
94 bibEditParams_t *editParams; |
|
95 |
|
96 } bibBufferEdit_t; |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 typedef struct bibBuffer_s { |
|
102 u_char *baseAddr; /* the start address of the buffer */ |
|
103 |
|
104 unsigned size; /* the size of the buffer in bytes */ |
|
105 |
|
106 unsigned getIndex; /* an index to the buffer where data was last got */ |
|
107 |
|
108 int bitIndex; /* an index to the byte pointed by getIndex + 1 */ |
|
109 |
|
110 u_int32 bitsLeft; /* the number of bits currently in the buffer */ |
|
111 |
|
112 u_int32 numBytesRead; /* the total number of bytes read */ |
|
113 |
|
114 int error; /* stores possible error code */ |
|
115 |
|
116 } bibBuffer_t; |
|
117 /* {{-output"bibBuffer_t.txt"}} */ |
|
118 |
|
119 #ifdef DEBUG_OUTPUT |
|
120 extern bibBuffer_t * buffer_global; |
|
121 #endif |
|
122 |
|
123 /* typedefs for bibFlushBits, bibGetBits, and bibShowBits function types */ |
|
124 typedef void (*bibFlushBits_t) (int, bibBuffer_t *, int *, int *, int16 *); |
|
125 typedef u_int32 (*bibGetBits_t) (int, bibBuffer_t *, int *, int *, int16 *); |
|
126 typedef u_int32 (*bibShowBits_t) (int, bibBuffer_t *, int *, int *, int16 *); |
|
127 |
|
128 /* |
|
129 * External macros |
|
130 */ |
|
131 |
|
132 /* |
|
133 * bibNumberOfBitsLeft |
|
134 * |
|
135 * Parameters: |
|
136 * bibBuffer_t *buffer input bit buffer instance |
|
137 * |
|
138 * Function: |
|
139 * This macro returns the number of bits which are left to be read |
|
140 * from the current position. |
|
141 * |
|
142 * Returns: |
|
143 * See above. |
|
144 */ |
|
145 |
|
146 #define bibNumberOfBitsLeft(buffer) \ |
|
147 ((buffer)->bitsLeft) |
|
148 |
|
149 /* |
|
150 * External function prototypes |
|
151 */ |
|
152 |
|
153 bibBuffer_t *bibCreate(void *srcBuffer, unsigned srcBufferLength, |
|
154 int16 *errorCode); |
|
155 |
|
156 void bibDelete(bibBuffer_t *buffer, int16 *errorCode); |
|
157 |
|
158 u_int32 bibNumberOfFlushedBits(bibBuffer_t *buffer); |
|
159 |
|
160 u_int32 bibNumberOfFlushedBytes(bibBuffer_t *buffer); |
|
161 |
|
162 u_int32 bibNumberOfRewBits(bibBuffer_t *buffer); |
|
163 |
|
164 void bibRewindBits(u_int32 numberOfBits, bibBuffer_t *buffer, int16 *errorCode); |
|
165 |
|
166 |
|
167 /* |
|
168 * Prototypes for bibFlushBits/bibGetBits/bibShowBits |
|
169 */ |
|
170 |
|
171 void bibFlushBits(int numberOfBits, bibBuffer_t *buffer); |
|
172 u_int32 bibGetBits(int numberOfBits, bibBuffer_t *buffer); |
|
173 u_int32 bibShowBits(int numberOfBits, bibBuffer_t *buffer); |
|
174 |
|
175 inline void bibFlushBits(int numberOfBits, bibBuffer_t *buffer, int *numberOfBitsGot, int * /*bitErrorIndication*/, int16 * /*errorCode*/) |
|
176 { |
|
177 *numberOfBitsGot = numberOfBits; |
|
178 bibFlushBits(numberOfBits, buffer); |
|
179 } |
|
180 |
|
181 inline u_int32 bibGetBits(int numberOfBits, bibBuffer_t *buffer, int *numberOfBitsGot, int * /*bitErrorIndication*/, int16 * /*errorCode*/) |
|
182 { |
|
183 *numberOfBitsGot = numberOfBits; |
|
184 return bibGetBits(numberOfBits, buffer); |
|
185 } |
|
186 |
|
187 inline u_int32 bibShowBits(int numberOfBits, bibBuffer_t *buffer, int *numberOfBitsGot, int * /*bitErrorIndication*/, int16 * /*errorCode*/) |
|
188 { |
|
189 *numberOfBitsGot = numberOfBits; |
|
190 return bibShowBits(numberOfBits, buffer); |
|
191 } |
|
192 |
|
193 #define bibFlushBitsFromBuffer bibFlushBits |
|
194 #define bibGetBitsFromBuffer bibGetBits |
|
195 #define bibShowBitsFromBuffer bibShowBits |
|
196 |
|
197 |
|
198 bibBufferEdit_t *bibBufferEditCreate(int16 *errorCode); |
|
199 void bibBufEditDelete(bibBufferEdit_t *bufEdit, int16 *errorCode); |
|
200 |
|
201 // copy from input buffer to output buffer in various copy modes (with or without editing) |
|
202 void CopyStream(bibBuffer_t *SrcBuffer,bibBuffer_t *DestBuffer,bibBufferEdit_t *bufEdit, |
|
203 int ByteStart,int BitStart); |
|
204 // copy from input buffer to output buffer (without editing) |
|
205 void CopyBuffer(bibBuffer_t *SrcBuffer,bibBuffer_t *DestBuffer, |
|
206 int ByteStart,int BitStart, int ByteEnd, int BitEnd); |
|
207 // copy from BufferEdit to output buffer (no copying; rather, inserting code into output buffer) |
|
208 void CopyBufferEdit(bibBuffer_t *SrcBuffer, bibBuffer_t *DestBuffer, |
|
209 bibEditParams_t *edParam, int updateSrcBufferStats=1); |
|
210 // insert correct IntraDC values for H.263 chrominance blocks in output buffer |
|
211 void ResetH263IntraDcUV(bibBuffer_t *DestBuffer, int uValue, int vValue); |
|
212 // insert correct IntraDC values for MPEG-4 chrominance blocks in output buffer |
|
213 void ResetMPEG4IntraDcUV(bibBuffer_t *DestBuffer, int IntraDC_size); |
|
214 |
|
215 /* |
|
216 SrcValue the source value from which bits are to be extacted |
|
217 MaxNumBits the length in bits of the source value |
|
218 StartBit the index of the starting bit form where data is to be retrieved |
|
219 getBits the number of bits to be retrieved |
|
220 */ |
|
221 u_int32 bibGetBitsFromWord(u_int32 SrcValue, u_int32 getBits, u_int32 *StartBit, |
|
222 u_int32 MaxNumBits); |
|
223 void bibForwardBits(u_int32 numberOfBits, bibBuffer_t *buffer); |
|
224 void bibStuffBits(bibBuffer_t *buffer); |
|
225 void bibStuffBitsMPEG4(bibBuffer_t *inBuffer, bibBuffer_t *outBuffer, bibBufferEdit_t *bufEdit, |
|
226 int *StartByteIndex, int *StartBitIndex, int updateSrcBufferStats); |
|
227 |
|
228 |
|
229 #endif |
|
230 // End of File |
|