Line data Source code
1 : #include <assert.h>
2 : #include <stdint.h>
3 : #include "options.h"
4 : #include "stat_com.h"
5 : #include "prot_fx.h"
6 : #include "wmc_auto.h"
7 :
8 :
9 : /** Put nBits long encoded value from *pStream into bitstream. Using the function EncodeValue for encoding. */
10 410 : static Word16 PutIntoBitstream_fx(
11 : const Word16 **pStream,
12 : TEncodeValue EncodeValue,
13 : Word16 index,
14 : BSTR_ENC_HANDLE hBstr,
15 : const Word16 nBits )
16 : {
17 : Word16 value;
18 : Word16 codedValue;
19 :
20 410 : move16();
21 410 : value = *( *pStream )++;
22 410 : codedValue = EncodeValue( value, index );
23 :
24 410 : push_next_indice( hBstr, codedValue, nBits );
25 :
26 410 : return value;
27 : }
28 1643871 : static Word16 PutIntoBitstream_ivas_fx(
29 : const Word16 **pStream,
30 : TEncodeValue EncodeValue,
31 : Word16 index,
32 : BSTR_ENC_HANDLE hBstr,
33 : const Word16 nBits )
34 : {
35 : Word16 value;
36 : Word16 codedValue;
37 :
38 1643871 : move16();
39 1643871 : value = *( *pStream )++;
40 1643871 : codedValue = EncodeValue( value, index );
41 :
42 1643871 : push_next_indice( hBstr, codedValue, nBits );
43 :
44 1643871 : return value;
45 : }
46 :
47 933231 : static Word16 FixedWidthEncoding( Word16 value, Word16 index )
48 : {
49 : (void) index; /* suppress compiler warnings */
50 :
51 933231 : return value;
52 : }
53 :
54 :
55 : /********************************/
56 : /* Interface functions */
57 : /********************************/
58 :
59 222089 : void GetParameters(
60 : ParamsBitMap const *paramsBitMap,
61 : const Word16 nArrayLength,
62 : void const *pParameter,
63 : Word16 **pStream,
64 : Word16 *pnSize,
65 : Word16 *pnBits )
66 : {
67 : Word16 index;
68 : Word16 iParam, nParams;
69 : Word16 value;
70 : void const *pSubStruct;
71 :
72 222089 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
73 :
74 222089 : nParams = paramsBitMap->nParams;
75 562466 : for ( index = 0; index < nArrayLength; index++ )
76 : {
77 680754 : for ( iParam = 0; iParam < nParams; iParam++ )
78 : {
79 340377 : ParamBitMap const *const param = ¶msBitMap->params[iParam];
80 :
81 : #define WMC_TOOL_SKIP
82 340377 : pSubStruct = param->GetParamValue( pParameter, index, &value );
83 : #undef WMC_TOOL_SKIP
84 : /* If a function for encoding/decoding value is defined than it should take care of 0 */
85 340377 : if ( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
86 : {
87 323135 : *( *pStream )++ = value;
88 : }
89 : else
90 : {
91 17242 : *( *pStream )++ = value - 1;
92 : }
93 340377 : ++*pnSize;
94 : #define WMC_TOOL_SKIP
95 340377 : *pnBits += ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( value, index );
96 : #undef WMC_TOOL_SKIP
97 340377 : if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
98 : {
99 60202 : GetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
100 : }
101 : }
102 : }
103 :
104 222089 : return;
105 : }
106 :
107 1466405 : void GetParameters_fx(
108 : ParamsBitMap const *paramsBitMap,
109 : const Word16 nArrayLength, // Q0
110 : void const *pParameter, // Q0
111 : Word16 **pStream, // Q0
112 : Word16 *pnSize, // Q0
113 : Word16 *pnBits ) // Q0
114 : {
115 : Word16 index;
116 : Word16 iParam, nParams;
117 : Word16 value;
118 : void const *pSubStruct;
119 :
120 1466405 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
121 :
122 1466405 : nParams = paramsBitMap->nParams;
123 1466405 : move16();
124 3343860 : FOR( index = 0; index < nArrayLength; index++ )
125 : {
126 3823544 : FOR( iParam = 0; iParam < nParams; iParam++ )
127 : {
128 1946089 : ParamBitMap const *const param = ¶msBitMap->params[iParam];
129 :
130 : #define WMC_TOOL_SKIP
131 1946089 : pSubStruct = param->GetParamValue( pParameter, index, &value );
132 : #undef WMC_TOOL_SKIP
133 : /* If a function for encoding/decoding value is defined than it should take care of 0 */
134 1946089 : test();
135 1946089 : IF( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
136 : {
137 1877455 : *( *pStream )++ = value;
138 1877455 : move16();
139 : }
140 : ELSE
141 : {
142 68634 : *( *pStream )++ = sub( value, 1 );
143 68634 : move16();
144 : }
145 1946089 : ++*pnSize;
146 : #define WMC_TOOL_SKIP
147 1946089 : IF( ( param->nBits != 0 ) )
148 : {
149 1378928 : *pnBits = add( *pnBits, param->nBits );
150 : }
151 : ELSE
152 : {
153 567161 : *pnBits = add( *pnBits, param->GetNumberOfBits( value, index ) );
154 : }
155 1946089 : move16();
156 : #undef WMC_TOOL_SKIP
157 :
158 1946089 : test();
159 1946089 : IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
160 : {
161 224745 : GetParameters_fx( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
162 : }
163 : }
164 : }
165 :
166 1466405 : return;
167 : }
168 :
169 264875 : void SetParameters(
170 : ParamsBitMap const *paramsBitMap,
171 : const Word16 nArrayLength,
172 : void *pParameter,
173 : const Word16 **pStream,
174 : Word16 *pnSize )
175 : {
176 : Word16 index;
177 : Word16 iParam, nParams;
178 : Word16 value;
179 : void *pSubStruct;
180 :
181 264875 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) );
182 :
183 264875 : nParams = paramsBitMap->nParams;
184 1020489 : for ( index = 0; index < nArrayLength; index++ )
185 : {
186 1574729 : for ( iParam = 0; iParam < nParams; iParam++ )
187 : {
188 819115 : ParamBitMap const *const param = ¶msBitMap->params[iParam];
189 : /* If a function for encoding/decoding value is defined than it should take care of 0 */
190 :
191 819115 : value = *( *pStream )++ + ( param->fZeroAllowed || ( param->EncodeValue != NULL ) ? 0 : 1 );
192 : #define WMC_TOOL_SKIP
193 819115 : pSubStruct = param->SetParamValue( pParameter, index, value );
194 : #undef WMC_TOOL_SKIP
195 819115 : ++*pnSize;
196 819115 : if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
197 : {
198 183492 : SetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize );
199 : }
200 : }
201 : }
202 :
203 264875 : return;
204 : }
205 :
206 721991 : void SetParameters_fx(
207 : ParamsBitMap const *paramsBitMap,
208 : const Word16 nArrayLength,
209 : void *pParameter,
210 : const Word16 **pStream,
211 : Word16 *pnSize )
212 : {
213 : Word16 index;
214 : Word16 iParam, nParams;
215 : Word16 value;
216 : void *pSubStruct;
217 : void *pTmp;
218 721991 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) );
219 721991 : nParams = paramsBitMap->nParams;
220 :
221 1443982 : FOR( index = 0; index < nArrayLength; index++ )
222 : {
223 1443982 : FOR( iParam = 0; iParam < nParams; iParam++ )
224 : {
225 : ParamBitMap const *param;
226 : /* If a function for encoding/decoding value is defined than it should take care of 0 */
227 :
228 721991 : move16();
229 721991 : param = ¶msBitMap->params[iParam];
230 :
231 721991 : move16();
232 721991 : value = 1;
233 721991 : if ( s_or( param->fZeroAllowed != 0, param->EncodeValue != NULL ) )
234 : {
235 721991 : move16();
236 721991 : value = 0;
237 : }
238 721991 : value = add( value, *( *pStream )++ );
239 :
240 : #define WMC_TOOL_SKIP
241 721991 : pSubStruct = param->SetParamValue( pParameter, index, value );
242 : #undef WMC_TOOL_SKIP
243 721991 : move16();
244 721991 : *pnSize = add( *pnSize, 1 );
245 :
246 721991 : IF( s_and( param->pSubParamBitMap != NULL, value > 0 ) )
247 : {
248 81009 : pTmp = pParameter;
249 81009 : if ( pSubStruct != NULL )
250 1288 : pTmp = pSubStruct;
251 81009 : SetParameters( param->pSubParamBitMap, value, pTmp, pStream, pnSize );
252 : }
253 : }
254 : }
255 721991 : }
256 :
257 :
258 384 : void WriteToBitstream_fx(
259 : ParamsBitMap const *paramsBitMap,
260 : const Word16 nArrayLength,
261 : const Word16 **pStream,
262 : Word16 *pnSize,
263 : BSTR_ENC_HANDLE hBstr,
264 : Word16 *pnBits )
265 : {
266 : Word16 index;
267 : Word16 iParam, nParams;
268 :
269 :
270 384 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
271 384 : nParams = paramsBitMap->nParams;
272 :
273 794 : FOR( index = 0; index < nArrayLength; index++ )
274 : {
275 :
276 820 : FOR( iParam = 0; iParam < nParams; iParam++ )
277 : {
278 : ParamBitMap const *param;
279 : Word16 nBits;
280 : /* If a function for encoding/decoding value is defined than it should take care of 0 */
281 : Word16 fShiftValue;
282 : TEncodeValue EncodeValue;
283 : Word16 value;
284 :
285 410 : move16();
286 410 : param = ¶msBitMap->params[iParam];
287 :
288 410 : move16();
289 410 : nBits = param->nBits;
290 410 : IF( param->nBits == 0 )
291 : {
292 : #define WMC_TOOL_SKIP
293 34 : nBits = param->GetNumberOfBits( **pStream, index );
294 : #undef WMC_TOOL_SKIP
295 : }
296 :
297 410 : test();
298 410 : test();
299 410 : fShiftValue = s_and( param->fZeroAllowed == 0, param->EncodeValue == NULL );
300 410 : move16();
301 410 : EncodeValue = param->EncodeValue;
302 410 : if ( param->EncodeValue == NULL )
303 : {
304 376 : move16();
305 376 : EncodeValue = &FixedWidthEncoding;
306 : }
307 410 : value = PutIntoBitstream_fx( pStream, EncodeValue, index, hBstr, nBits );
308 410 : if ( fShiftValue )
309 : {
310 0 : value = add( value, 1 );
311 : }
312 :
313 410 : move16();
314 410 : *pnSize = add( *pnSize, 1 );
315 410 : move16();
316 410 : *pnBits = add( *pnBits, nBits );
317 :
318 410 : IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
319 : {
320 8 : WriteToBitstream_fx( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
321 : }
322 : }
323 : }
324 384 : }
325 1060398 : void WriteToBitstream_ivas_fx(
326 : ParamsBitMap const *paramsBitMap,
327 : const Word16 nArrayLength,
328 : const Word16 **pStream,
329 : Word16 *pnSize,
330 : BSTR_ENC_HANDLE hBstr,
331 : Word16 *pnBits )
332 : {
333 : Word16 index;
334 : Word16 iParam, nParams;
335 :
336 :
337 1060398 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
338 1060398 : nParams = paramsBitMap->nParams;
339 1060398 : move16();
340 :
341 2638121 : FOR( index = 0; index < nArrayLength; index++ )
342 : {
343 :
344 3221594 : FOR( iParam = 0; iParam < nParams; iParam++ )
345 : {
346 : ParamBitMap const *param;
347 : Word16 nBits;
348 : /* If a function for encoding/decoding value is defined than it should take care of 0 */
349 : Word16 fShiftValue;
350 : TEncodeValue EncodeValue;
351 : Word16 value;
352 :
353 1643871 : move16();
354 1643871 : param = ¶msBitMap->params[iParam];
355 :
356 1643871 : move16();
357 1643871 : nBits = param->nBits;
358 1643871 : IF( param->nBits == 0 )
359 : {
360 : #define WMC_TOOL_SKIP
361 711016 : nBits = param->GetNumberOfBits( **pStream, index );
362 : #undef WMC_TOOL_SKIP
363 : }
364 :
365 1643871 : fShiftValue = s_and( param->fZeroAllowed == 0, param->EncodeValue == NULL );
366 :
367 1643871 : EncodeValue = param->EncodeValue;
368 1643871 : if ( param->EncodeValue == NULL )
369 : {
370 932855 : move16();
371 932855 : EncodeValue = &FixedWidthEncoding;
372 : }
373 1643871 : value = PutIntoBitstream_ivas_fx( pStream, EncodeValue, index, hBstr, nBits );
374 1643871 : IF( fShiftValue )
375 : {
376 83390 : value = add( value, 1 );
377 : }
378 :
379 1643871 : move16();
380 1643871 : *pnSize = add( *pnSize, 1 );
381 1643871 : move16();
382 1643871 : *pnBits = add( *pnBits, nBits );
383 :
384 1643871 : test();
385 1643871 : IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
386 : {
387 277081 : WriteToBitstream_ivas_fx( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
388 : }
389 : }
390 : }
391 1060398 : }
392 :
393 : /** Get nBits long value from bitstream into *pStream. */
394 1517518 : static Word16 GetFromBitstream(
395 : Decoder_State *st,
396 : TDecodeValue DecodeValue,
397 : UWord16 index,
398 : Word16 nFixedBits,
399 : Word16 **pStream )
400 : {
401 1517518 : Word16 value = 0;
402 1517518 : move16();
403 1517518 : move16();
404 1517518 : value = 0;
405 1517518 : IF( DecodeValue != NULL )
406 : {
407 658993 : DecodeValue( st, index, &value );
408 : }
409 : ELSE
410 : {
411 : // value = get_next_indice_fx(st, nFixedBits);
412 858525 : value = get_next_indice_fx( st, nFixedBits );
413 : }
414 1517518 : move16();
415 1517518 : *( *pStream )++ = value;
416 :
417 1517518 : return value;
418 : }
419 :
420 976989 : void ReadFromBitstream_fx(
421 : ParamsBitMap const *paramsBitMap,
422 : const Word16 nArrayLength,
423 : Decoder_State *st,
424 : Word16 **pStream,
425 : Word16 *pnSize )
426 : {
427 : Word16 index;
428 : Word16 iParam, nParams;
429 : Word16 fShiftValue;
430 : Word16 value;
431 :
432 976989 : assert( ( paramsBitMap != NULL ) && GT_16( nArrayLength, 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( st != NULL ) );
433 976989 : move16();
434 976989 : nParams = paramsBitMap->nParams;
435 2433340 : FOR( index = 0; index < nArrayLength; index++ )
436 : {
437 2973869 : FOR( iParam = 0; iParam < nParams; iParam++ )
438 : {
439 : ParamBitMap const *param;
440 : /* If a function for encoding/decoding value is defined than it should take care of 0 */
441 1517518 : move16();
442 1517518 : param = ¶msBitMap->params[iParam];
443 1517518 : test();
444 1517518 : test();
445 1517518 : fShiftValue = s_and( (Word16) param->fZeroAllowed == 0, param->EncodeValue == NULL );
446 1517518 : value = GetFromBitstream( st, param->DecodeValue, index, param->nBits, pStream );
447 1517518 : IF( fShiftValue )
448 : {
449 77387 : move16();
450 77387 : value = add( value, 1 );
451 : }
452 :
453 1517518 : test();
454 1517518 : IF( ( param->pSubParamBitMap != NULL ) && value > 0 )
455 : {
456 257018 : ReadFromBitstream_fx( param->pSubParamBitMap, value, st, pStream, pnSize );
457 : }
458 : }
459 : }
460 976989 : move16();
461 976989 : *pnSize = add( *pnSize, i_mult( nParams, nArrayLength ) );
462 976989 : }
|