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 0 : 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 0 : move16();
21 0 : value = *( *pStream )++;
22 0 : codedValue = EncodeValue( value, index );
23 :
24 0 : push_next_indice( hBstr, codedValue, nBits );
25 :
26 0 : return value;
27 : }
28 0 : 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 0 : move16();
39 0 : value = *( *pStream )++;
40 0 : codedValue = EncodeValue( value, index );
41 :
42 0 : push_next_indice( hBstr, codedValue, nBits );
43 :
44 0 : return value;
45 : }
46 :
47 0 : static Word16 FixedWidthEncoding( Word16 value, Word16 index )
48 : {
49 : (void) index; /* suppress compiler warnings */
50 :
51 0 : return value;
52 : }
53 :
54 :
55 : /********************************/
56 : /* Interface functions */
57 : /********************************/
58 :
59 0 : 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 0 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
73 :
74 0 : nParams = paramsBitMap->nParams;
75 0 : for ( index = 0; index < nArrayLength; index++ )
76 : {
77 0 : for ( iParam = 0; iParam < nParams; iParam++ )
78 : {
79 0 : ParamBitMap const *const param = ¶msBitMap->params[iParam];
80 :
81 : #define WMC_TOOL_SKIP
82 0 : 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 0 : if ( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
86 : {
87 0 : *( *pStream )++ = value;
88 : }
89 : else
90 : {
91 0 : *( *pStream )++ = value - 1;
92 : }
93 0 : ++*pnSize;
94 : #define WMC_TOOL_SKIP
95 0 : *pnBits += ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( value, index );
96 : #undef WMC_TOOL_SKIP
97 0 : if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
98 : {
99 0 : GetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
100 : }
101 : }
102 : }
103 :
104 0 : return;
105 : }
106 :
107 0 : 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 0 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
121 :
122 0 : nParams = paramsBitMap->nParams;
123 0 : move16();
124 0 : FOR( index = 0; index < nArrayLength; index++ )
125 : {
126 0 : FOR( iParam = 0; iParam < nParams; iParam++ )
127 : {
128 0 : ParamBitMap const *const param = ¶msBitMap->params[iParam];
129 :
130 : #define WMC_TOOL_SKIP
131 0 : 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 0 : test();
135 0 : IF( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
136 : {
137 0 : *( *pStream )++ = value;
138 0 : move16();
139 : }
140 : ELSE
141 : {
142 0 : *( *pStream )++ = sub( value, 1 );
143 0 : move16();
144 : }
145 0 : ++*pnSize;
146 : #define WMC_TOOL_SKIP
147 0 : IF( ( param->nBits != 0 ) )
148 : {
149 0 : *pnBits = add( *pnBits, param->nBits );
150 : }
151 : ELSE
152 : {
153 0 : *pnBits = add( *pnBits, param->GetNumberOfBits( value, index ) );
154 : }
155 0 : move16();
156 : #undef WMC_TOOL_SKIP
157 :
158 0 : test();
159 0 : IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
160 : {
161 0 : GetParameters_fx( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
162 : }
163 : }
164 : }
165 :
166 0 : 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 0 : 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 0 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
271 0 : nParams = paramsBitMap->nParams;
272 :
273 0 : FOR( index = 0; index < nArrayLength; index++ )
274 : {
275 :
276 0 : 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 0 : move16();
286 0 : param = ¶msBitMap->params[iParam];
287 :
288 0 : move16();
289 0 : nBits = param->nBits;
290 0 : IF( param->nBits == 0 )
291 : {
292 : #define WMC_TOOL_SKIP
293 0 : nBits = param->GetNumberOfBits( **pStream, index );
294 : #undef WMC_TOOL_SKIP
295 : }
296 :
297 0 : test();
298 0 : test();
299 0 : fShiftValue = s_and( param->fZeroAllowed == 0, param->EncodeValue == NULL );
300 0 : move16();
301 0 : EncodeValue = param->EncodeValue;
302 0 : if ( param->EncodeValue == NULL )
303 : {
304 0 : move16();
305 0 : EncodeValue = &FixedWidthEncoding;
306 : }
307 0 : value = PutIntoBitstream_fx( pStream, EncodeValue, index, hBstr, nBits );
308 0 : if ( fShiftValue )
309 : {
310 0 : value = add( value, 1 );
311 : }
312 :
313 0 : move16();
314 0 : *pnSize = add( *pnSize, 1 );
315 0 : move16();
316 0 : *pnBits = add( *pnBits, nBits );
317 :
318 0 : IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
319 : {
320 0 : WriteToBitstream_fx( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
321 : }
322 : }
323 : }
324 0 : }
325 0 : 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 0 : assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
338 0 : nParams = paramsBitMap->nParams;
339 0 : move16();
340 :
341 0 : FOR( index = 0; index < nArrayLength; index++ )
342 : {
343 :
344 0 : 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 0 : move16();
354 0 : param = ¶msBitMap->params[iParam];
355 :
356 0 : move16();
357 0 : nBits = param->nBits;
358 0 : IF( param->nBits == 0 )
359 : {
360 : #define WMC_TOOL_SKIP
361 0 : nBits = param->GetNumberOfBits( **pStream, index );
362 : #undef WMC_TOOL_SKIP
363 : }
364 :
365 0 : fShiftValue = s_and( param->fZeroAllowed == 0, param->EncodeValue == NULL );
366 :
367 0 : EncodeValue = param->EncodeValue;
368 0 : if ( param->EncodeValue == NULL )
369 : {
370 0 : move16();
371 0 : EncodeValue = &FixedWidthEncoding;
372 : }
373 0 : value = PutIntoBitstream_ivas_fx( pStream, EncodeValue, index, hBstr, nBits );
374 0 : IF( fShiftValue )
375 : {
376 0 : value = add( value, 1 );
377 : }
378 :
379 0 : move16();
380 0 : *pnSize = add( *pnSize, 1 );
381 0 : move16();
382 0 : *pnBits = add( *pnBits, nBits );
383 :
384 0 : test();
385 0 : IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
386 : {
387 0 : WriteToBitstream_ivas_fx( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
388 : }
389 : }
390 : }
391 0 : }
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 : }
|