blob: d538a4efaa45588d0530e054ae12d12d7c441a65 [file] [log] [blame]
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301/******************************************************************************
2 *
3 * Copyright (C) 2015 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*/
20/*!
21 ***************************************************************************
22 * \file ih264d_parse_cavlc.c
23 *
24 * \brief
25 * This file contains UVLC related functions.
26 *
27 * \date
28 * 20/11/2002
29 *
30 * \author NS
31 ***************************************************************************
32 */
33
34#include <string.h>
35#include <stdio.h>
36
37#include "ih264d_bitstrm.h"
38#include "ih264d_parse_cavlc.h"
39#include "ih264d_error_handler.h"
40#include "ih264d_defs.h"
41#include "ih264d_debug.h"
42#include "ih264d_cabac.h"
43#include "ih264d_structs.h"
44#include "ih264d_tables.h"
45#include "ih264d_tables.h"
46#include "ih264d_mb_utils.h"
47
48void ih264d_unpack_coeff4x4_dc_4x4blk(tu_sblk4x4_coeff_data_t *ps_tu_4x4,
49 WORD16 *pi2_out_coeff_data,
50 UWORD8 *pu1_inv_scan);
51
52/*****************************************************************************/
53/* */
54/* Function Name : ih264d_uev */
55/* */
56/* Description : Reads the unsigned Exp Golomb codec syntax from the */
57/* ps_bitstrm as specified in section 9.1 of H264 standard */
58/* It also increases bitstream u4_ofst by the number of bits */
59/* parsed for UEV decode operation */
60/* */
61/* Inputs : bitstream base pointer and bitsream u4_ofst in bits */
62/* Globals : None */
63/* Processing : */
64/* Outputs : UEV decoded syntax element and incremented ps_bitstrm u4_ofst */
65/* Returns : UEV decoded syntax element */
66/* */
67/* Issues : Does not check if ps_bitstrm u4_ofst exceeds max ps_bitstrm i4_size */
68/* for performamce. Caller might have to do error resilence */
69/* check for bitstream overflow */
70/* */
71/* Revision History: */
72/* */
73/* DD MM YYYY Author(s) Changes (Describe the changes made) */
74/* 19 09 2008 Jay Draft */
75/* */
76/*****************************************************************************/
77UWORD32 ih264d_uev(UWORD32 *pu4_bitstrm_ofst, UWORD32 *pu4_bitstrm_buf)
78{
79 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
80 UWORD32 u4_word, u4_ldz;
81
82 /***************************************************************/
83 /* Find leading zeros in next 32 bits */
84 /***************************************************************/
85 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
86 u4_ldz = CLZ(u4_word);
87 /* Flush the ps_bitstrm */
88 u4_bitstream_offset += (u4_ldz + 1);
89 /* Read the suffix from the ps_bitstrm */
90 u4_word = 0;
91 if(u4_ldz)
92 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
93 *pu4_bitstrm_ofst = u4_bitstream_offset;
94 return ((1 << u4_ldz) + u4_word - 1);
95}
96
97/*****************************************************************************/
98/* */
99/* Function Name : ih264d_sev */
100/* */
101/* Description : Reads the signed Exp Golomb codec syntax from the ps_bitstrm */
102/* as specified in section 9.1 of H264 standard. */
103/* It also increases bitstream u4_ofst by the number of bits */
104/* parsed for SEV decode operation */
105/* */
106/* Inputs : bitstream base pointer and bitsream u4_ofst in bits */
107/* Globals : None */
108/* Processing : */
109/* Outputs : SEV decoded syntax element and incremented ps_bitstrm u4_ofst */
110/* Returns : SEV decoded syntax element */
111/* */
112/* Issues : Does not check if ps_bitstrm u4_ofst exceeds max ps_bitstrm i4_size */
113/* for performamce. Caller might have to do error resilence */
114/* check for bitstream overflow */
115/* */
116/* Revision History: */
117/* */
118/* DD MM YYYY Author(s) Changes (Describe the changes made) */
119/* 19 09 2008 Jay Draft */
120/* */
121/*****************************************************************************/
122WORD32 ih264d_sev(UWORD32 *pu4_bitstrm_ofst, UWORD32 *pu4_bitstrm_buf)
123{
124 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
125 UWORD32 u4_word, u4_ldz, u4_abs_val;
126
127 /***************************************************************/
128 /* Find leading zeros in next 32 bits */
129 /***************************************************************/
130 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
131 u4_ldz = CLZ(u4_word);
132
133 /* Flush the ps_bitstrm */
134 u4_bitstream_offset += (u4_ldz + 1);
135
136 /* Read the suffix from the ps_bitstrm */
137 u4_word = 0;
138 if(u4_ldz)
139 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
140
141 *pu4_bitstrm_ofst = u4_bitstream_offset;
142 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
143
144 if(u4_word & 0x1)
145 return (-(WORD32)u4_abs_val);
146 else
147 return (u4_abs_val);
148}
149
150/*****************************************************************************/
151/* */
152/* Function Name : get_tev_range_1 */
153/* */
154/* Description : Reads the TEV Exp Golomb codec syntax from the ps_bitstrm */
155/* as specified in section 9.1 of H264 standard. This will */
156/* called only when the input range is 1 for TEV decode. */
157/* If range is more than 1, then UEV decode is done */
158/* */
159/* Inputs : bitstream base pointer and bitsream u4_ofst in bits */
160/* Globals : None */
161/* Processing : */
162/* Outputs : TEV decoded syntax element and incremented ps_bitstrm u4_ofst */
163/* Returns : TEV decoded syntax element */
164/* */
165/* Issues : Does not check if ps_bitstrm u4_ofst exceeds max ps_bitstrm i4_size */
166/* for performamce. Caller might have to do error resilence */
167/* check for bitstream overflow */
168/* */
169/* Revision History: */
170/* */
171/* DD MM YYYY Author(s) Changes (Describe the changes made) */
172/* 19 09 2008 Jay Draft */
173/* */
174/*****************************************************************************/
175UWORD32 ih264d_tev_range1(UWORD32 *pu4_bitstrm_ofst, UWORD32 *pu4_bitstrm_buf)
176{
177 UWORD32 u4_code;
178 GETBIT(u4_code, *pu4_bitstrm_ofst, pu4_bitstrm_buf);
179 return (!u4_code);
180}
181
182/*!
183 **************************************************************************
184 * \if Function name : ih264d_uvlc \endif
185 *
186 * \brief
187 *
188 * Reads the unsigned/signed/truncated integer Exp-Golomb-coded syntax element
189 * with the left bit first. The parsing process for this descriptor is specified
190 * in subclause 9.1.
191 *
192 * \param ps_bitstrm : Pointer to Bitstream Structure .
193 * \param u4_range : Range value in case of Truncated Exp-Golomb-code
194 * \param pi_bitstrm_ofst : Pointer to the local copy of Bitstream u4_ofst
195 * \param u1_flag : Flag indicating the case of UEV,SEV or TEV
196 * \param u4_bitstrm_ofst : Local copy of Bitstream u4_ofst
197 * \param pu4_bitstrm_buf : Pointer to the Bitstream buffer
198 *
199 * \return
200 * Returns Code Value.
201 *
202 **************************************************************************
203 */
204
205WORD32 ih264d_uvlc(dec_bit_stream_t *ps_bitstrm,
206 UWORD32 u4_range,
207 UWORD32 *pi_bitstrm_ofst,
208 UWORD8 u1_flag,
209 UWORD32 u4_bitstrm_ofst,
210 UWORD32 *pu4_bitstrm_buf)
211{
212 UWORD32 word, word2, cur_bit, cur_word, code_val, code_num, clz;
213
214 SWITCHOFFTRACE;
215 cur_bit = u4_bitstrm_ofst & 0x1F;
216 cur_word = u4_bitstrm_ofst >> 5;
217 word = pu4_bitstrm_buf[cur_word];
218 word2 = pu4_bitstrm_buf[cur_word + 1];
219
220 if(cur_bit != 0)
221 {
222 word <<= cur_bit;
223 word2 >>= (32 - cur_bit);
224 word |= word2;
225 }
226
227 if(u1_flag == TEV && u4_range == 1)
228 {
229 word >>= 31;
230 word = 1 - word;
231 (*pi_bitstrm_ofst)++;
232 ps_bitstrm->u4_ofst = *pi_bitstrm_ofst;
233 return (WORD32)word;
234 }
235
236 //finding clz
237 {
238 UWORD32 ui32_code, ui32_mask;
239
240 ui32_code = word;
241 ui32_mask = 0x80000000;
242 clz = 0;
243
244 /* DSP implements this with LMBD instruction */
245 /* so there we don't need to break the loop */
246 while(!(ui32_code & ui32_mask))
247 {
248 clz++;
249 ui32_mask >>= 1;
250 if(0 == ui32_mask)
251 break;
252 }
253 }
254
255 if(clz == 0)
256 {
257 *pi_bitstrm_ofst = *pi_bitstrm_ofst + (2 * clz) + 1;
258 ps_bitstrm->u4_ofst = *pi_bitstrm_ofst;
259 return 0;
260 }
261
262 word <<= (clz + 1);
263 word >>= (32 - clz);
264 code_num = (1 << clz) + word - 1;
265 *pi_bitstrm_ofst = *pi_bitstrm_ofst + (2 * clz) + 1;
266 ps_bitstrm->u4_ofst = *pi_bitstrm_ofst;
267
268 if(u1_flag == TEV || u1_flag == UEV)
269 return (WORD32)code_num;
270
271 code_val = (code_num + 1) >> 1;
272 if(!(code_num & 0x01))
273 return -((WORD32)code_val);
274 return (WORD32)code_val;
275
276}
277
278/*****************************************************************************/
279/* */
280/* Function Name : ih264d_cavlc_4x4res_block_totalcoeff_1 */
281/* */
282/* Description : This function does cavlc decoding of 4x4 block residual */
283/* coefficient when total coeff is equal to 1. The parsing */
284/* is done as defined in section 9.2.2 and 9.2.3 of the */
285/* H264 standard. */
286/* */
287/* Inputs : <What inputs does the function take?> */
288/* Globals : <Does it use any global variables?> */
289/* Processing : <Describe how the function operates - include algorithm */
290/* description> */
291/* Outputs : <What does the function produce?> */
292/* Returns : <What does the function return?> */
293/* */
294/* Issues : <List any issues or problems with this function> */
295/* */
296/* Revision History: */
297/* */
298/* DD MM YYYY Author(s) Changes (Describe the changes made) */
299/* 25 09 2008 Jay Draft */
300/* */
301/*****************************************************************************/
302WORD32 ih264d_cavlc_4x4res_block_totalcoeff_1(UWORD32 u4_isdc,
303 UWORD32 u4_total_coeff_trail_one,
304 dec_bit_stream_t *ps_bitstrm)
305{
306
307 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
308 UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
309 UWORD32 u4_trailing_ones = u4_total_coeff_trail_one & 0xFFFF;
310 WORD32 i2_level;
311 UWORD32 u4_tot_zero, u4_ldz, u4_scan_pos;
312
313 tu_sblk4x4_coeff_data_t *ps_tu_4x4;
314 WORD16 *pi2_coeff_data;
315 dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
316
317 ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
318 ps_tu_4x4->u2_sig_coeff_map = 0;
319 pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
320
321
322 if(u4_trailing_ones)
323 {
324 UWORD32 u4_sign;
325 /****************************************************************/
326 /* Decode Trailing One as in section 9.2.2 */
327 /****************************************************************/
328 GETBIT(u4_sign, u4_bitstream_offset, pu4_bitstrm_buf);
329 i2_level = u4_sign ? -1 : 1;
330 }
331 else
332 {
333 /****************************************************************/
334 /* Decoding Level based on prefix and suffix as in 9.2.2 */
335 /****************************************************************/
336 UWORD32 u4_lev_suffix, u4_lev_suffix_size;
337 WORD32 u2_lev_code, u2_abs_value;
338 UWORD32 u4_lev_prefix;
339 /***************************************************************/
340 /* Find leading zeros in next 32 bits */
341 /***************************************************************/
342 FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
343 pu4_bitstrm_buf);
344 u2_lev_code = (2 + MIN(u4_lev_prefix, 15));
345
346 if(14 == u4_lev_prefix)
347 u4_lev_suffix_size = 4;
348 else if(15 <= u4_lev_prefix)
349 {
350 u2_lev_code += 15;
351 u4_lev_suffix_size = u4_lev_prefix - 3;
352 }
353 else
354 u4_lev_suffix_size = 0;
355
356 //HP_LEVEL_PREFIX
357 if(16 <= u4_lev_prefix)
358 {
359 u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
360 }
361 if(u4_lev_suffix_size)
362 {
363 GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
364 u4_lev_suffix_size);
365 u2_lev_code += u4_lev_suffix;
366 }
367
368 u2_abs_value = (u2_lev_code + 2) >> 1;
369 /*********************************************************/
370 /* If Level code is odd, level is negative else positive */
371 /*********************************************************/
372 i2_level = (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
373
374 }
375
376 /****************************************************************/
377 /* Decoding total zeros as in section 9.2.3, table 9.7 */
378 /****************************************************************/
379 FIND_ONE_IN_STREAM_LEN(u4_ldz, u4_bitstream_offset, pu4_bitstrm_buf, 8);
380
381 if(u4_ldz)
382 {
383 GETBIT(u4_tot_zero, u4_bitstream_offset, pu4_bitstrm_buf);
384 u4_tot_zero = (u4_ldz << 1) - u4_tot_zero;
385 }
386 else
387 u4_tot_zero = 0;
388
389 /***********************************************************************/
390 /* Inverse scan and store residual coeff. Update the bitstream u4_ofst */
391 /***********************************************************************/
392 u4_scan_pos = u4_tot_zero + u4_isdc;
393 if(u4_scan_pos > 15)
394 return -1;
395
396 SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
397 *pi2_coeff_data++ = i2_level;
398
399
400 {
401 WORD32 offset;
402 offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
403 offset = ALIGN4(offset);
404 ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
405 }
406
407 ps_bitstrm->u4_ofst = u4_bitstream_offset;
408 return 0;
409}
410
411/*****************************************************************************/
412/* */
413/* Function Name : ih264d_cavlc_4x4res_block_totalcoeff_2to10 */
414/* */
415/* Description : This function does cavlc decoding of 4x4 block residual */
416/* coefficient when total coeffs are between two and ten */
417/* inclusive. Parsing is done as defined in section 9.2.2 */
418/* and 9.2.3 the H264 standard. */
419/* */
420/* Inputs : <What inputs does the function take?> */
421/* Globals : <Does it use any global variables?> */
422/* Processing : <Describe how the function operates - include algorithm */
423/* description> */
424/* Outputs : <What does the function produce?> */
425/* Returns : <What does the function return?> */
426/* */
427/* Issues : <List any issues or problems with this function> */
428/* */
429/* Revision History: */
430/* */
431/* DD MM YYYY Author(s) Changes (Describe the changes made) */
432/* 25 09 2008 Jay Draft */
433/* */
434/*****************************************************************************/
435
436WORD32 ih264d_cavlc_4x4res_block_totalcoeff_2to10(UWORD32 u4_isdc,
437 UWORD32 u4_total_coeff_trail_one, /*!<TotalCoefficients<<16+trailingones*/
438 dec_bit_stream_t *ps_bitstrm)
439{
440 UWORD32 u4_total_zeroes;
441 WORD32 i;
442 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
443 UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
444 UWORD32 u4_trailing_ones = u4_total_coeff_trail_one & 0xFFFF;
445 UWORD32 u4_total_coeff = u4_total_coeff_trail_one >> 16;
Harish Mahendrakaref3da4e2016-02-17 18:06:36 +0530446 // To avoid error check at 4x4 level, allocating for 3 extra levels(16+3)
447 // since u4_trailing_ones can at the max be 3. This will be required when
448 // u4_total_coeff is less than u4_trailing_ones
449 WORD16 ai2_level_arr[19];
450 WORD16 *i2_level_arr = &ai2_level_arr[3];
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530451
452 tu_sblk4x4_coeff_data_t *ps_tu_4x4;
453 WORD16 *pi2_coeff_data;
454 dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
455
456 ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
457 ps_tu_4x4->u2_sig_coeff_map = 0;
458 pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
459
460 i = u4_total_coeff - 1;
461
462 if(u4_trailing_ones)
463 {
464 /*********************************************************************/
465 /* Decode Trailing Ones */
466 /* read the sign of T1's and put them in level array */
467 /*********************************************************************/
468 UWORD32 u4_signs, u4_cnt = u4_trailing_ones;
469 WORD16 (*ppi2_trlone_lkup)[3] =
470 (WORD16 (*)[3])gai2_ih264d_trailing_one_level;
471 WORD16 *pi2_trlone_lkup;
472
473 GETBITS(u4_signs, u4_bitstream_offset, pu4_bitstrm_buf, u4_cnt);
474
475 pi2_trlone_lkup = ppi2_trlone_lkup[(1 << u4_cnt) - 2 + u4_signs];
476
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530477 while(u4_cnt)
478 {
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530479 i2_level_arr[i--] = *pi2_trlone_lkup++;
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530480 u4_cnt--;
481 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530482 }
483
484 /****************************************************************/
485 /* Decoding Levels Begins */
486 /****************************************************************/
487 if(i >= 0)
488 {
489 /****************************************************************/
490 /* First level is decoded outside the loop as it has lot of */
491 /* special cases. */
492 /****************************************************************/
493 UWORD32 u4_lev_suffix, u4_suffix_len, u4_lev_suffix_size;
494 WORD32 u2_lev_code, u2_abs_value;
495 UWORD32 u4_lev_prefix;
496
497 /***************************************************************/
498 /* u4_suffix_len = 0, Find leading zeros in next 32 bits */
499 /***************************************************************/
500 FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
501 pu4_bitstrm_buf);
502
503 /*********************************************************/
504 /* Special decoding case when trailing ones are 3 */
505 /*********************************************************/
506 u2_lev_code = MIN(15, u4_lev_prefix);
507
508 u2_lev_code += (3 == u4_trailing_ones) ? 0 : 2;
509
510 if(14 == u4_lev_prefix)
511 u4_lev_suffix_size = 4;
512 else if(15 <= u4_lev_prefix)
513 {
514 u2_lev_code += 15;
515 u4_lev_suffix_size = u4_lev_prefix - 3;
516 }
517 else
518 u4_lev_suffix_size = 0;
519
520 //HP_LEVEL_PREFIX
521 if(16 <= u4_lev_prefix)
522 {
523 u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
524 }
525 if(u4_lev_suffix_size)
526 {
527 GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
528 u4_lev_suffix_size);
529 u2_lev_code += u4_lev_suffix;
530 }
531
532 u2_abs_value = (u2_lev_code + 2) >> 1;
533 /*********************************************************/
534 /* If Level code is odd, level is negative else positive */
535 /*********************************************************/
536 i2_level_arr[i--] = (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
537
538 u4_suffix_len = (u2_abs_value > 3) ? 2 : 1;
539
540 /*********************************************************/
541 /* Now loop over the remaining levels */
542 /*********************************************************/
543 while(i >= 0)
544 {
545
546 /***************************************************************/
547 /* Find leading zeros in next 32 bits */
548 /***************************************************************/
549 FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
550 pu4_bitstrm_buf);
551
552 u4_lev_suffix_size =
553 (15 <= u4_lev_prefix) ?
554 (u4_lev_prefix - 3) : u4_suffix_len;
555
556 /*********************************************************/
557 /* Compute level code using prefix and suffix */
558 /*********************************************************/
559 GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
560 u4_lev_suffix_size);
561 u2_lev_code = (MIN(15,u4_lev_prefix) << u4_suffix_len)
562 + u4_lev_suffix;
563
564 //HP_LEVEL_PREFIX
565 if(16 <= u4_lev_prefix)
566 {
567 u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
568 }
569 u2_abs_value = (u2_lev_code + 2) >> 1;
570
571 /*********************************************************/
572 /* If Level code is odd, level is negative else positive */
573 /*********************************************************/
574 i2_level_arr[i--] =
575 (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
576
577 /*********************************************************/
578 /* Increment suffix length if required */
579 /*********************************************************/
580 u4_suffix_len +=
581 (u4_suffix_len < 6) ?
582 (u2_abs_value
583 > (3
584 << (u4_suffix_len
585 - 1))) :
586 0;
587 }
588
589 /****************************************************************/
590 /* Decoding Levels Ends */
591 /****************************************************************/
592 }
593
594 /****************************************************************/
595 /* Decoding total zeros as in section 9.2.3, table 9.7 */
596 /****************************************************************/
597 {
598 UWORD32 u4_index;
599 const UWORD8 (*ppu1_total_zero_lkup)[64] =
600 (const UWORD8 (*)[64])gau1_ih264d_table_total_zero_2to10;
601
602 NEXTBITS(u4_index, u4_bitstream_offset, pu4_bitstrm_buf, 6);
603 u4_total_zeroes = ppu1_total_zero_lkup[u4_total_coeff - 2][u4_index];
604
605 FLUSHBITS(u4_bitstream_offset, (u4_total_zeroes >> 4));
606 u4_total_zeroes &= 0xf;
607 }
608
609 /**************************************************************/
610 /* Decode the runs and form the coefficient buffer */
611 /**************************************************************/
612 {
613 const UWORD8 *pu1_table_runbefore;
614 UWORD32 u4_run;
615 WORD32 k;
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530616 WORD32 u4_scan_pos = u4_total_coeff + u4_total_zeroes - 1 + u4_isdc;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530617 WORD32 u4_zeroes_left = u4_total_zeroes;
618 k = u4_total_coeff - 1;
619
620 /**************************************************************/
621 /* Decoding Runs Begin for zeros left > 6 */
622 /**************************************************************/
623 while((u4_zeroes_left > 6) && k)
624 {
625 UWORD32 u4_code;
626
627 NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 3);
628
629 if(u4_code != 0)
630 {
631 FLUSHBITS(u4_bitstream_offset, 3);
632 u4_run = (7 - u4_code);
633 }
634 else
635 {
636
637 FIND_ONE_IN_STREAM_LEN(u4_code, u4_bitstream_offset,
638 pu4_bitstrm_buf, 11);
639 u4_run = (4 + u4_code);
640 }
641
642 SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
643 *pi2_coeff_data++ = i2_level_arr[k--];
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530644 u4_zeroes_left -= (WORD32)u4_run;
645 u4_scan_pos -= (WORD32)(u4_run + 1);
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530646 }
647
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530648 if (u4_zeroes_left < 0 || u4_scan_pos < 0)
649 return -1;
650
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530651 /**************************************************************/
652 /* Decoding Runs for 0 < zeros left <=6 */
653 /**************************************************************/
654 pu1_table_runbefore = (UWORD8 *)gau1_ih264d_table_run_before;
655 while((u4_zeroes_left > 0) && k)
656 {
657 UWORD32 u4_code;
658 NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 3);
659
660 u4_code = pu1_table_runbefore[u4_code + (u4_zeroes_left << 3)];
661 u4_run = u4_code >> 2;
662
663 FLUSHBITS(u4_bitstream_offset, (u4_code & 0x03));
664
665 SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
666 *pi2_coeff_data++ = i2_level_arr[k--];
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530667 u4_zeroes_left -= (WORD32)u4_run;
668 u4_scan_pos -= (WORD32)(u4_run + 1);
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530669 }
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530670 if (u4_zeroes_left < 0 || u4_scan_pos < 0)
671 return -1;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530672 /**************************************************************/
673 /* Decoding Runs End */
674 /**************************************************************/
675
676 /**************************************************************/
677 /* Copy the remaining coefficients */
678 /**************************************************************/
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530679 while(k >= 0)
680 {
681
682 SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
683 *pi2_coeff_data++ = i2_level_arr[k--];
684 u4_scan_pos--;
685 }
686 }
687
688 {
689 WORD32 offset;
690 offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
691 offset = ALIGN4(offset);
692 ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
693 }
694
695 ps_bitstrm->u4_ofst = u4_bitstream_offset;
696 return 0;
697}
698
699/*****************************************************************************/
700/* */
701/* Function Name : ih264d_cavlc_4x4res_block_totalcoeff_11to16 */
702/* */
703/* Description : This function does cavlc decoding of 4x4 block residual */
704/* coefficient when total coeffs are greater than ten. */
705/* Parsing is done as defined in section 9.2.2 and 9.2.3 of */
706/* the H264 standard. */
707/* */
708/* Inputs : <What inputs does the function take?> */
709/* Globals : <Does it use any global variables?> */
710/* Processing : <Describe how the function operates - include algorithm */
711/* description> */
712/* Outputs : <What does the function produce?> */
713/* Returns : <What does the function return?> */
714/* */
715/* Issues : <List any issues or problems with this function> */
716/* */
717/* Revision History: */
718/* */
719/* DD MM YYYY Author(s) Changes (Describe the changes made) */
720/* 25 09 2008 Jay Draft */
721/* */
722/*****************************************************************************/
723
724WORD32 ih264d_cavlc_4x4res_block_totalcoeff_11to16(UWORD32 u4_isdc,
725 UWORD32 u4_total_coeff_trail_one, /*!<TotalCoefficients<<16+trailingones*/
726 dec_bit_stream_t *ps_bitstrm )
727{
728 UWORD32 u4_total_zeroes;
729 WORD32 i;
730 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
731 UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
732 UWORD32 u4_trailing_ones = u4_total_coeff_trail_one & 0xFFFF;
733 UWORD32 u4_total_coeff = u4_total_coeff_trail_one >> 16;
Harish Mahendrakaref3da4e2016-02-17 18:06:36 +0530734 // To avoid error check at 4x4 level, allocating for 3 extra levels(16+3)
735 // since u4_trailing_ones can at the max be 3. This will be required when
736 // u4_total_coeff is less than u4_trailing_ones
737 WORD16 ai2_level_arr[19];//
738 WORD16 *i2_level_arr = &ai2_level_arr[3];
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530739
740 tu_sblk4x4_coeff_data_t *ps_tu_4x4;
741 WORD16 *pi2_coeff_data;
742 dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
743
744 ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
745 ps_tu_4x4->u2_sig_coeff_map = 0;
746 pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
747
748 i = u4_total_coeff - 1;
749 if(u4_trailing_ones)
750 {
751 /*********************************************************************/
752 /* Decode Trailing Ones */
753 /* read the sign of T1's and put them in level array */
754 /*********************************************************************/
755 UWORD32 u4_signs, u4_cnt = u4_trailing_ones;
756 WORD16 (*ppi2_trlone_lkup)[3] =
757 (WORD16 (*)[3])gai2_ih264d_trailing_one_level;
758 WORD16 *pi2_trlone_lkup;
759
760 GETBITS(u4_signs, u4_bitstream_offset, pu4_bitstrm_buf, u4_cnt);
761
762 pi2_trlone_lkup = ppi2_trlone_lkup[(1 << u4_cnt) - 2 + u4_signs];
763
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530764 while(u4_cnt)
765 {
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530766 i2_level_arr[i--] = *pi2_trlone_lkup++;
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530767 u4_cnt--;
768 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530769 }
770
771 /****************************************************************/
772 /* Decoding Levels Begins */
773 /****************************************************************/
774 if(i >= 0)
775 {
776 /****************************************************************/
777 /* First level is decoded outside the loop as it has lot of */
778 /* special cases. */
779 /****************************************************************/
780 UWORD32 u4_lev_suffix, u4_suffix_len, u4_lev_suffix_size;
781 UWORD16 u2_lev_code, u2_abs_value;
782 UWORD32 u4_lev_prefix;
783
784 if(u4_trailing_ones < 3)
785 {
786 /*********************************************************/
787 /* u4_suffix_len = 1 */
788 /*********************************************************/
789 /***************************************************************/
790 /* Find leading zeros in next 32 bits */
791 /***************************************************************/
792 FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
793 pu4_bitstrm_buf);
794
795 u4_lev_suffix_size =
796 (15 <= u4_lev_prefix) ? (u4_lev_prefix - 3) : 1;
797
798 GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
799 u4_lev_suffix_size);
800 u2_lev_code = 2 + (MIN(u4_lev_prefix,15) << 1) + u4_lev_suffix;
801
802 //HP_LEVEL_PREFIX
803 if(16 <= u4_lev_prefix)
804 {
805 u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
806 }
807 }
808 else
809 {
810 /*********************************************************/
811 /*u4_suffix_len = 0 */
812 /*********************************************************/
813 /***************************************************************/
814 /* Find leading zeros in next 32 bits */
815 /***************************************************************/
816 FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
817 pu4_bitstrm_buf);
818
819 /*********************************************************/
820 /* Special decoding case when trailing ones are 3 */
821 /*********************************************************/
822 u2_lev_code = MIN(15, u4_lev_prefix);
823
824 u2_lev_code += (3 == u4_trailing_ones) ? 0 : (2);
825
826 if(14 == u4_lev_prefix)
827 u4_lev_suffix_size = 4;
828 else if(15 <= u4_lev_prefix)
829 {
830 u2_lev_code += 15;
831 u4_lev_suffix_size = (u4_lev_prefix - 3);
832 }
833 else
834 u4_lev_suffix_size = 0;
835
836 //HP_LEVEL_PREFIX
837 if(16 <= u4_lev_prefix)
838 {
839 u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
840 }
841 if(u4_lev_suffix_size)
842 {
843 GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
844 u4_lev_suffix_size);
845 u2_lev_code += u4_lev_suffix;
846 }
847 }
848
849 u2_abs_value = (u2_lev_code + 2) >> 1;
850 /*********************************************************/
851 /* If Level code is odd, level is negative else positive */
852 /*********************************************************/
853 i2_level_arr[i--] = (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
854
855 u4_suffix_len = (u2_abs_value > 3) ? 2 : 1;
856
857 /*********************************************************/
858 /* Now loop over the remaining levels */
859 /*********************************************************/
860 while(i >= 0)
861 {
862
863 /***************************************************************/
864 /* Find leading zeros in next 32 bits */
865 /***************************************************************/
866 FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
867 pu4_bitstrm_buf);
868
869 u4_lev_suffix_size =
870 (15 <= u4_lev_prefix) ?
871 (u4_lev_prefix - 3) : u4_suffix_len;
872
873 /*********************************************************/
874 /* Compute level code using prefix and suffix */
875 /*********************************************************/
876 GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
877 u4_lev_suffix_size);
878 u2_lev_code = (MIN(15,u4_lev_prefix) << u4_suffix_len)
879 + u4_lev_suffix;
880
881 //HP_LEVEL_PREFIX
882 if(16 <= u4_lev_prefix)
883 {
884 u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
885 }
886 u2_abs_value = (u2_lev_code + 2) >> 1;
887
888 /*********************************************************/
889 /* If Level code is odd, level is negative else positive */
890 /*********************************************************/
891 i2_level_arr[i--] =
892 (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
893
894 /*********************************************************/
895 /* Increment suffix length if required */
896 /*********************************************************/
897 u4_suffix_len +=
898 (u4_suffix_len < 6) ?
899 (u2_abs_value
900 > (3
901 << (u4_suffix_len
902 - 1))) :
903 0;
904 }
905
906 /****************************************************************/
907 /* Decoding Levels Ends */
908 /****************************************************************/
909 }
910
911 if(u4_total_coeff < (16 - u4_isdc))
912 {
913 UWORD32 u4_index;
914 const UWORD8 (*ppu1_total_zero_lkup)[16] =
915 (const UWORD8 (*)[16])gau1_ih264d_table_total_zero_11to15;
916
917 NEXTBITS(u4_index, u4_bitstream_offset, pu4_bitstrm_buf, 4);
918 u4_total_zeroes = ppu1_total_zero_lkup[u4_total_coeff - 11][u4_index];
919
920 FLUSHBITS(u4_bitstream_offset, (u4_total_zeroes >> 4));
921 u4_total_zeroes &= 0xf;
922 }
923 else
924 u4_total_zeroes = 0;
925
926 /**************************************************************/
927 /* Decode the runs and form the coefficient buffer */
928 /**************************************************************/
929 {
930 const UWORD8 *pu1_table_runbefore;
931 UWORD32 u4_run;
932 WORD32 k;
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530933 WORD32 u4_scan_pos = u4_total_coeff + u4_total_zeroes - 1 + u4_isdc;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530934 WORD32 u4_zeroes_left = u4_total_zeroes;
935 k = u4_total_coeff - 1;
936
937 /**************************************************************/
938 /* Decoding Runs for 0 < zeros left <=6 */
939 /**************************************************************/
940 pu1_table_runbefore = (UWORD8 *)gau1_ih264d_table_run_before;
941 while((u4_zeroes_left > 0) && k)
942 {
943 UWORD32 u4_code;
944 NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 3);
945
946 u4_code = pu1_table_runbefore[u4_code + (u4_zeroes_left << 3)];
947 u4_run = u4_code >> 2;
948
949 FLUSHBITS(u4_bitstream_offset, (u4_code & 0x03));
950 SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
951 *pi2_coeff_data++ = i2_level_arr[k--];
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530952 u4_zeroes_left -= (WORD32)u4_run;
953 u4_scan_pos -= (WORD32)(u4_run + 1);
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530954 }
Isha Kulkarni43dc60e2019-01-11 16:48:08 +0530955 if (u4_zeroes_left < 0 || u4_scan_pos < 0)
956 return -1;
957
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530958 /**************************************************************/
959 /* Decoding Runs End */
960 /**************************************************************/
961
962 /**************************************************************/
963 /* Copy the remaining coefficients */
964 /**************************************************************/
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530965 while(k >= 0)
966 {
967 SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
968 *pi2_coeff_data++ = i2_level_arr[k--];
969 u4_scan_pos--;
970 }
971 }
972
973 {
974 WORD32 offset;
975 offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
976 offset = ALIGN4(offset);
977 ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
978 }
979
980 ps_bitstrm->u4_ofst = u4_bitstream_offset;
981 return 0;
982}
983
984/*****************************************************************************/
985/* */
986/* Function Name : ih264d_rest_of_residual_cav_chroma_dc_block */
987/* */
988/* Description : This function does the Cavlc parsing of the bitstream */
989/* for chroma dc coefficients */
990/* Inputs : <What inputs does the function take?> */
991/* Globals : <Does it use any global variables?> */
992/* Processing : <Describe how the function operates - include algorithm */
993/* description> */
994/* Outputs : <What does the function produce?> */
995/* Returns : <What does the function return?> */
996/* */
997/* Issues : <List any issues or problems with this function> */
998/* */
999/* Revision History: */
1000/* */
1001/* DD MM YYYY Author(s) Changes (Describe the changes made) */
1002/* 15 09 2008 Jay Draft */
1003/* */
1004/*****************************************************************************/
1005void ih264d_rest_of_residual_cav_chroma_dc_block(UWORD32 u4_total_coeff_trail_one,
1006 dec_bit_stream_t *ps_bitstrm)
1007{
1008 UWORD32 u4_total_zeroes;
1009 WORD16 i;
1010 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1011 UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1012 UWORD32 u4_trailing_ones = u4_total_coeff_trail_one & 0xFFFF;
1013 UWORD32 u4_total_coeff = u4_total_coeff_trail_one >> 16;
Harish Mahendrakaref3da4e2016-02-17 18:06:36 +05301014 // To avoid error check at 4x4 level, allocating for 3 extra levels(4+3)
1015 // since u4_trailing_ones can at the max be 3. This will be required when
1016 // u4_total_coeff is less than u4_trailing_ones
1017 WORD16 ai2_level_arr[7];//
1018 WORD16 *i2_level_arr = &ai2_level_arr[3];
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301019
1020 tu_sblk4x4_coeff_data_t *ps_tu_4x4;
1021 WORD16 *pi2_coeff_data;
1022 dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
1023
1024 ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
1025 ps_tu_4x4->u2_sig_coeff_map = 0;
1026 pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
1027
1028 i = u4_total_coeff - 1;
1029 if(u4_trailing_ones)
1030 {
1031 /*********************************************************************/
1032 /* Decode Trailing Ones */
1033 /* read the sign of T1's and put them in level array */
1034 /*********************************************************************/
1035 UWORD32 u4_signs, u4_cnt = u4_trailing_ones;
1036 WORD16 (*ppi2_trlone_lkup)[3] =
1037 (WORD16 (*)[3])gai2_ih264d_trailing_one_level;
1038 WORD16 *pi2_trlone_lkup;
1039
1040 GETBITS(u4_signs, u4_bitstream_offset, pu4_bitstrm_buf, u4_cnt);
1041
1042 pi2_trlone_lkup = ppi2_trlone_lkup[(1 << u4_cnt) - 2 + u4_signs];
1043
Isha Kulkarni43dc60e2019-01-11 16:48:08 +05301044 while(u4_cnt)
1045 {
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301046 i2_level_arr[i--] = *pi2_trlone_lkup++;
Isha Kulkarni43dc60e2019-01-11 16:48:08 +05301047 u4_cnt--;
1048 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301049 }
1050
1051 /****************************************************************/
1052 /* Decoding Levels Begins */
1053 /****************************************************************/
1054 if(i >= 0)
1055 {
1056 /****************************************************************/
1057 /* First level is decoded outside the loop as it has lot of */
1058 /* special cases. */
1059 /****************************************************************/
1060 UWORD32 u4_lev_suffix, u4_suffix_len, u4_lev_suffix_size;
1061 UWORD16 u2_lev_code, u2_abs_value;
1062 UWORD32 u4_lev_prefix;
1063
1064 /***************************************************************/
1065 /* u4_suffix_len = 0, Find leading zeros in next 32 bits */
1066 /***************************************************************/
1067 FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
1068 pu4_bitstrm_buf);
1069
1070 /*********************************************************/
1071 /* Special decoding case when trailing ones are 3 */
1072 /*********************************************************/
1073 u2_lev_code = MIN(15, u4_lev_prefix);
1074
1075 u2_lev_code += (3 == u4_trailing_ones) ? 0 : (2);
1076
1077 if(14 == u4_lev_prefix)
1078 u4_lev_suffix_size = 4;
1079 else if(15 <= u4_lev_prefix)
1080 {
1081 u2_lev_code += 15;
1082 u4_lev_suffix_size = u4_lev_prefix - 3;
1083 }
1084 else
1085 u4_lev_suffix_size = 0;
1086
1087 //HP_LEVEL_PREFIX
1088 if(16 <= u4_lev_prefix)
1089 {
1090 u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
1091 }
1092 if(u4_lev_suffix_size)
1093 {
1094 GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
1095 u4_lev_suffix_size);
1096 u2_lev_code += u4_lev_suffix;
1097 }
1098
1099 u2_abs_value = (u2_lev_code + 2) >> 1;
1100 /*********************************************************/
1101 /* If Level code is odd, level is negative else positive */
1102 /*********************************************************/
1103 i2_level_arr[i--] = (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
1104
1105 u4_suffix_len = (u2_abs_value > 3) ? 2 : 1;
1106
1107 /*********************************************************/
1108 /* Now loop over the remaining levels */
1109 /*********************************************************/
1110 while(i >= 0)
1111 {
1112
1113 /***************************************************************/
1114 /* Find leading zeros in next 32 bits */
1115 /***************************************************************/
1116 FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
1117 pu4_bitstrm_buf);
1118
1119 u4_lev_suffix_size =
1120 (15 <= u4_lev_prefix) ?
1121 (u4_lev_prefix - 3) : u4_suffix_len;
1122
1123 /*********************************************************/
1124 /* Compute level code using prefix and suffix */
1125 /*********************************************************/
1126 GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
1127 u4_lev_suffix_size);
1128 u2_lev_code = (MIN(u4_lev_prefix,15) << u4_suffix_len)
1129 + u4_lev_suffix;
1130
1131 //HP_LEVEL_PREFIX
1132 if(16 <= u4_lev_prefix)
1133 {
1134 u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
1135 }
1136 u2_abs_value = (u2_lev_code + 2) >> 1;
1137
1138 /*********************************************************/
1139 /* If Level code is odd, level is negative else positive */
1140 /*********************************************************/
1141 i2_level_arr[i--] =
1142 (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
1143
1144 /*********************************************************/
1145 /* Increment suffix length if required */
1146 /*********************************************************/
1147 u4_suffix_len += (u2_abs_value > (3 << (u4_suffix_len - 1)));
1148 }
1149
1150 /****************************************************************/
1151 /* Decoding Levels Ends */
1152 /****************************************************************/
1153 }
1154
1155 if(u4_total_coeff < 4)
1156 {
1157 UWORD32 u4_max_ldz = (4 - u4_total_coeff);
1158 FIND_ONE_IN_STREAM_LEN(u4_total_zeroes, u4_bitstream_offset,
1159 pu4_bitstrm_buf, u4_max_ldz);
1160 }
1161 else
1162 u4_total_zeroes = 0;
1163
1164 /**************************************************************/
1165 /* Decode the runs and form the coefficient buffer */
1166 /**************************************************************/
1167 {
1168 const UWORD8 *pu1_table_runbefore;
1169 UWORD32 u4_run;
Isha Kulkarni43dc60e2019-01-11 16:48:08 +05301170 WORD32 u4_scan_pos = (u4_total_coeff + u4_total_zeroes - 1);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301171 UWORD32 u4_zeroes_left = u4_total_zeroes;
1172 i = u4_total_coeff - 1;
1173
1174 /**************************************************************/
1175 /* Decoding Runs for 0 < zeros left <=6 */
1176 /**************************************************************/
1177 pu1_table_runbefore = (UWORD8 *)gau1_ih264d_table_run_before;
1178 while(u4_zeroes_left && i)
1179 {
1180 UWORD32 u4_code;
1181 NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 3);
1182
1183 u4_code = pu1_table_runbefore[u4_code + (u4_zeroes_left << 3)];
1184 u4_run = u4_code >> 2;
1185
1186 FLUSHBITS(u4_bitstream_offset, (u4_code & 0x03));
1187 SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
1188 *pi2_coeff_data++ = i2_level_arr[i--];
Isha Kulkarni43dc60e2019-01-11 16:48:08 +05301189 u4_zeroes_left -= (WORD32)u4_run;
1190 u4_scan_pos -= (WORD32)(u4_run + 1);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301191 }
1192 /**************************************************************/
1193 /* Decoding Runs End */
1194 /**************************************************************/
1195
1196 /**************************************************************/
1197 /* Copy the remaining coefficients */
1198 /**************************************************************/
1199 while(i >= 0)
1200 {
1201 SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
1202 *pi2_coeff_data++ = i2_level_arr[i--];
1203 u4_scan_pos--;
1204 }
1205 }
1206
1207 {
1208 WORD32 offset;
1209 offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
1210 offset = ALIGN4(offset);
1211 ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
1212 }
1213
1214 ps_bitstrm->u4_ofst = u4_bitstream_offset;
1215}
1216
1217/*!
1218 **************************************************************************
1219 * \if Function name : CavlcParsingInvScanInvQuant \endif
1220 *
1221 * \brief
1222 * This function do cavlc parsing of coefficient tokens for any block
1223 * type except chromDc and depending
1224 * on whenther any coefficients to be parsed calls module
1225 * RestOfResidualBlockCavlc.
1226 *
1227 * \return
1228 * Returns total number of non-zero coefficients.
1229 *
1230 **************************************************************************
1231 */
1232
1233WORD32 ih264d_cavlc_parse4x4coeff_n0to7(WORD16 *pi2_coeff_block,
1234 UWORD32 u4_isdc, /* is it a DC block */
1235 WORD32 u4_n,
1236 dec_struct_t *ps_dec,
1237 UWORD32 *pu4_total_coeff)
1238{
1239 dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm;
1240 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1241 UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1242 UWORD32 u4_code, u4_index, u4_ldz;
1243 const UWORD16 *pu2_code = (const UWORD16*)gau2_ih264d_code_gx;
1244 const UWORD16 *pu2_offset_num_vlc =
1245 (const UWORD16 *)gau2_ih264d_offset_num_vlc_tab;
1246 UWORD32 u4_offset_num_vlc = pu2_offset_num_vlc[u4_n];
1247
1248
1249 UNUSED(pi2_coeff_block);
1250 *pu4_total_coeff = 0;
1251 FIND_ONE_IN_STREAM_32(u4_ldz, u4_bitstream_offset, pu4_bitstrm_buf);
1252 NEXTBITS(u4_index, u4_bitstream_offset, pu4_bitstrm_buf, 3);
1253 u4_index += (u4_ldz << 3);
1254 u4_index += u4_offset_num_vlc;
1255
1256 u4_index = MIN(u4_index, 303);
1257 u4_code = pu2_code[u4_index];
1258
1259 FLUSHBITS(u4_bitstream_offset, (u4_code & 0x03));
1260 ps_bitstrm->u4_ofst = u4_bitstream_offset;
1261 *pu4_total_coeff = (u4_code >> 4);
1262
1263 if(*pu4_total_coeff)
1264 {
1265 UWORD32 u4_trailing_ones, u4_offset, u4_total_coeff_tone;
1266 const UWORD8 *pu1_offset =
1267 (UWORD8 *)gau1_ih264d_total_coeff_fn_ptr_offset;
1268 WORD32 ret;
1269 u4_trailing_ones = ((u4_code >> 2) & 0x03);
1270 u4_offset = pu1_offset[*pu4_total_coeff - 1];
1271 u4_total_coeff_tone = (*pu4_total_coeff << 16) | u4_trailing_ones;
1272
1273 ret = ps_dec->pf_cavlc_4x4res_block[u4_offset](u4_isdc,
1274 u4_total_coeff_tone,
1275 ps_bitstrm);
1276 if(ret != 0)
1277 return ERROR_CAVLC_NUM_COEFF_T;
1278 }
1279
1280 return OK;
1281}
1282
1283WORD32 ih264d_cavlc_parse4x4coeff_n8(WORD16 *pi2_coeff_block,
1284 UWORD32 u4_isdc, /* is it a DC block */
1285 WORD32 u4_n,
1286 dec_struct_t *ps_dec,
1287 UWORD32 *pu4_total_coeff)
1288{
1289
1290 dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm;
1291 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1292 UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1293 UWORD32 u4_code;
1294 UNUSED(u4_n);
1295 UNUSED(pi2_coeff_block);
1296 GETBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 6);
1297 ps_bitstrm->u4_ofst = u4_bitstream_offset;
1298 *pu4_total_coeff = 0;
1299
1300 if(u4_code != 3)
1301 {
1302 UWORD8 *pu1_offset = (UWORD8 *)gau1_ih264d_total_coeff_fn_ptr_offset;
1303 UWORD32 u4_trailing_ones, u4_offset, u4_total_coeff_tone;
1304
1305 *pu4_total_coeff = (u4_code >> 2) + 1;
1306 u4_trailing_ones = u4_code & 0x03;
1307 u4_offset = pu1_offset[*pu4_total_coeff - 1];
1308 u4_total_coeff_tone = (*pu4_total_coeff << 16) | u4_trailing_ones;
1309
1310 ps_dec->pf_cavlc_4x4res_block[u4_offset](u4_isdc,
1311 u4_total_coeff_tone,
1312 ps_bitstrm);
1313 }
1314
1315 return OK;
1316}
1317
1318/*!
1319 **************************************************************************
1320 * \if Function name : ih264d_cavlc_parse_chroma_dc \endif
1321 *
1322 * \brief
1323 * This function do cavlc parsing of coefficient tokens chromDc block
1324 * and depending on whenther any coefficients to be parsed calls module
1325 * ih264d_rest_of_residual_cav_chroma_dc_block.
1326 *
1327 * \return
1328 * Returns total number of non-zero coefficients.
1329 *
1330 **************************************************************************
1331 */
1332
1333void ih264d_cavlc_parse_chroma_dc(dec_mb_info_t *ps_cur_mb_info,
1334 WORD16 *pi2_coeff_block,
1335 dec_bit_stream_t *ps_bitstrm,
1336 UWORD32 u4_scale_u,
1337 UWORD32 u4_scale_v,
1338 WORD32 i4_mb_inter_inc)
1339{
1340 UWORD32 u4_total_coeff, u4_trailing_ones, u4_total_coeff_tone, u4_code;
1341 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1342 UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1343 const UWORD8 *pu1_cav_chromdc = (const UWORD8*)gau1_ih264d_cav_chromdc_vld;
1344 UNUSED(i4_mb_inter_inc);
1345 /******************************************************************/
1346 /* Chroma DC Block for U component */
1347 /******************************************************************/
1348 NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 8);
1349
1350 u4_code = pu1_cav_chromdc[u4_code];
1351
1352 FLUSHBITS(u4_bitstream_offset, ((u4_code & 0x7) + 1));
1353 ps_bitstrm->u4_ofst = u4_bitstream_offset;
1354
1355 u4_total_coeff = (u4_code >> 5);
1356
1357 if(u4_total_coeff)
1358 {
1359 WORD32 i_z0, i_z1, i_z2, i_z3;
1360 tu_sblk4x4_coeff_data_t *ps_tu_4x4;
1361 dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
1362 WORD16 ai2_dc_coef[4];
1363 UWORD8 pu1_inv_scan[4] =
1364 { 0, 1, 2, 3 };
1365 WORD16 *pi2_coeff_data =
1366 (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
1367
1368 ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
1369
1370 u4_trailing_ones = ((u4_code >> 3) & 0x3);
1371 u4_total_coeff_tone = (u4_total_coeff << 16) | u4_trailing_ones;
1372 ih264d_rest_of_residual_cav_chroma_dc_block(u4_total_coeff_tone,
1373 ps_bitstrm);
1374
1375 ai2_dc_coef[0] = 0;
1376 ai2_dc_coef[1] = 0;
1377 ai2_dc_coef[2] = 0;
1378 ai2_dc_coef[3] = 0;
1379
1380 ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
1381 ai2_dc_coef,
1382 pu1_inv_scan);
1383 /*-------------------------------------------------------------------*/
1384 /* Inverse 2x2 transform and scaling of chroma DC */
1385 /*-------------------------------------------------------------------*/
1386 i_z0 = (ai2_dc_coef[0] + ai2_dc_coef[2]);
1387 i_z1 = (ai2_dc_coef[0] - ai2_dc_coef[2]);
1388 i_z2 = (ai2_dc_coef[1] - ai2_dc_coef[3]);
1389 i_z3 = (ai2_dc_coef[1] + ai2_dc_coef[3]);
1390
1391 /*-----------------------------------------------------------*/
1392 /* Scaling and storing the values back */
1393 /*-----------------------------------------------------------*/
Isha Kulkarni43dc60e2019-01-11 16:48:08 +05301394 *pi2_coeff_data++ = (WORD16)(((i_z0 + i_z3) * (WORD32)u4_scale_u) >> 5);
1395 *pi2_coeff_data++ = (WORD16)(((i_z0 - i_z3) * (WORD32)u4_scale_u) >> 5);
1396 *pi2_coeff_data++ = (WORD16)(((i_z1 + i_z2) * (WORD32)u4_scale_u) >> 5);
1397 *pi2_coeff_data++ = (WORD16)(((i_z1 - i_z2) * (WORD32)u4_scale_u) >> 5);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301398
1399 ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_data;
1400
1401 SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,1);
1402 }
1403
1404 /******************************************************************/
1405 /* Chroma DC Block for V component */
1406 /******************************************************************/
1407 pi2_coeff_block += 64;
1408 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1409
1410 NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 8);
1411
1412 u4_code = pu1_cav_chromdc[u4_code];
1413
1414 FLUSHBITS(u4_bitstream_offset, ((u4_code & 0x7) + 1));
1415 ps_bitstrm->u4_ofst = u4_bitstream_offset;
1416
1417 u4_total_coeff = (u4_code >> 5);
1418
1419 if(u4_total_coeff)
1420 {
1421 WORD32 i_z0, i_z1, i_z2, i_z3;
1422 tu_sblk4x4_coeff_data_t *ps_tu_4x4;
1423 dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
1424 WORD16 ai2_dc_coef[4];
1425 UWORD8 pu1_inv_scan[4] =
1426 { 0, 1, 2, 3 };
1427 WORD16 *pi2_coeff_data =
1428 (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
1429
1430 ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
1431
1432 u4_trailing_ones = ((u4_code >> 3) & 0x3);
1433 u4_total_coeff_tone = (u4_total_coeff << 16) | u4_trailing_ones;
1434 ih264d_rest_of_residual_cav_chroma_dc_block(u4_total_coeff_tone,
1435 ps_bitstrm);
1436
1437 ai2_dc_coef[0] = 0;
1438 ai2_dc_coef[1] = 0;
1439 ai2_dc_coef[2] = 0;
1440 ai2_dc_coef[3] = 0;
1441
1442 ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
1443 ai2_dc_coef,
1444 pu1_inv_scan);
1445
1446 /*-------------------------------------------------------------------*/
1447 /* Inverse 2x2 transform and scaling of chroma DC */
1448 /*-------------------------------------------------------------------*/
1449 i_z0 = (ai2_dc_coef[0] + ai2_dc_coef[2]);
1450 i_z1 = (ai2_dc_coef[0] - ai2_dc_coef[2]);
1451 i_z2 = (ai2_dc_coef[1] - ai2_dc_coef[3]);
1452 i_z3 = (ai2_dc_coef[1] + ai2_dc_coef[3]);
1453
1454 /*-----------------------------------------------------------*/
1455 /* Scaling and storing the values back */
1456 /*-----------------------------------------------------------*/
Isha Kulkarni43dc60e2019-01-11 16:48:08 +05301457 *pi2_coeff_data++ = (WORD16)(((i_z0 + i_z3) * (WORD32)u4_scale_v) >> 5);
1458 *pi2_coeff_data++ = (WORD16)(((i_z0 - i_z3) * (WORD32)u4_scale_v) >> 5);
1459 *pi2_coeff_data++ = (WORD16)(((i_z1 + i_z2) * (WORD32)u4_scale_v) >> 5);
1460 *pi2_coeff_data++ = (WORD16)(((i_z1 - i_z2) * (WORD32)u4_scale_v) >> 5);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301461
1462 ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_data;
1463
1464 SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,2);
1465 }
1466}
1467
1468/*****************************************************************************/
1469/* */
1470/* Function Name : ih264d_parse_pmb_ref_index_cavlc_range1 */
1471/* */
1472/* Description : This function does the Cavlc TEV range =1 parsing of */
1473/* reference index for a P MB. Range is 1 when */
1474/* num_ref_idx_active_minus1 is 0 */
1475/* */
1476/* Inputs : <What inputs does the function take?> */
1477/* Globals : <Does it use any global variables?> */
1478/* Processing : <Describe how the function operates - include algorithm */
1479/* description> */
1480/* Outputs : <What does the function produce?> */
1481/* Returns : <What does the function return?> */
1482/* */
1483/* Issues : <List any issues or problems with this function> */
1484/* */
1485/* Revision History: */
1486/* */
1487/* DD MM YYYY Author(s) Changes (Describe the changes made) */
1488/* 19 09 2008 Jay Draft */
1489/* */
1490/*****************************************************************************/
1491void ih264d_parse_pmb_ref_index_cavlc_range1(UWORD32 u4_num_part, /* Number of partitions in MB */
1492 dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */
1493 WORD8 *pi1_ref_idx, /* pointer to reference index array */
1494 UWORD32 u4_num_ref_idx_active_minus1 /* Not used for range 1 */
1495 )
1496{
1497 UWORD32 u4_i;
1498 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1499 UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst;
1500 UNUSED(u4_num_ref_idx_active_minus1);
1501 for(u4_i = 0; u4_i < u4_num_part; u4_i++)
1502 {
1503 UWORD32 u4_ref_idx;
1504 u4_ref_idx = ih264d_tev_range1(pu4_bitstream_off, pu4_bitstrm_buf);
1505
1506 /* Storing Reference Idx Information */
1507 pi1_ref_idx[u4_i] = (WORD8)u4_ref_idx;
1508 }
1509}
1510
1511/*****************************************************************************/
1512/* */
1513/* Function Name : ih264d_parse_pmb_ref_index_cavlc */
1514/* */
1515/* Description : This function does the Cavlc TEV range > 1 parsing of */
1516/* reference index for a P MB. */
1517/* Range > 1 when num_ref_idx_active_minus1 > 0 */
1518/* */
1519/* Inputs : <What inputs does the function take?> */
1520/* Globals : <Does it use any global variables?> */
1521/* Processing : <Describe how the function operates - include algorithm */
1522/* description> */
1523/* Outputs : <What does the function produce?> */
1524/* Returns : <What does the function return?> */
1525/* */
1526/* Issues : <List any issues or problems with this function> */
1527/* */
1528/* Revision History: */
1529/* */
1530/* DD MM YYYY Author(s) Changes (Describe the changes made) */
1531/* 19 09 2008 Jay Draft */
1532/* */
1533/*****************************************************************************/
1534
1535WORD32 ih264d_parse_pmb_ref_index_cavlc(UWORD32 u4_num_part, /* Number of partitions in MB */
1536 dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */
1537 WORD8 *pi1_ref_idx, /* pointer to reference index array */
1538 UWORD32 u4_num_ref_idx_active_minus1 /* Number of active references - 1 */
1539 )
1540{
1541 UWORD32 u4_i;
1542 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1543 UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst;
1544
1545 for(u4_i = 0; u4_i < u4_num_part; u4_i++)
1546 {
1547 UWORD32 u4_ref_idx;
1548//Inlined ih264d_uev
1549 UWORD32 u4_bitstream_offset = *pu4_bitstream_off;
1550 UWORD32 u4_word, u4_ldz;
1551
1552 /***************************************************************/
1553 /* Find leading zeros in next 32 bits */
1554 /***************************************************************/
1555 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
1556 u4_ldz = CLZ(u4_word);
1557 /* Flush the ps_bitstrm */
1558 u4_bitstream_offset += (u4_ldz + 1);
1559 /* Read the suffix from the ps_bitstrm */
1560 u4_word = 0;
1561 if(u4_ldz)
1562 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
1563 *pu4_bitstream_off = u4_bitstream_offset;
1564 u4_ref_idx = ((1 << u4_ldz) + u4_word - 1);
1565//Inlined ih264d_uev
1566
1567 if(u4_ref_idx > u4_num_ref_idx_active_minus1)
1568 return ERROR_REF_IDX;
1569
1570 /* Storing Reference Idx Information */
1571 pi1_ref_idx[u4_i] = (WORD8)u4_ref_idx;
1572 }
1573 return OK;
1574}
1575
1576/*****************************************************************************/
1577/* */
1578/* Function Name : ih264d_parse_bmb_ref_index_cavlc_range1 */
1579/* */
1580/* Description : This function does the Cavlc TEV range =1 parsing of */
1581/* reference index for a B MB. Range is 1 when */
1582/* num_ref_idx_active_minus1 is 0 */
1583/* */
1584/* Inputs : <What inputs does the function take?> */
1585/* Globals : <Does it use any global variables?> */
1586/* Processing : <Describe how the function operates - include algorithm */
1587/* description> */
1588/* Outputs : <What does the function produce?> */
1589/* Returns : <What does the function return?> */
1590/* */
1591/* Issues : <List any issues or problems with this function> */
1592/* */
1593/* Revision History: */
1594/* */
1595/* DD MM YYYY Author(s) Changes (Describe the changes made) */
1596/* 19 09 2008 Jay Draft */
1597/* */
1598/*****************************************************************************/
1599void ih264d_parse_bmb_ref_index_cavlc_range1(UWORD32 u4_num_part, /* Number of partitions in MB */
1600 dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */
1601 WORD8 *pi1_ref_idx, /* pointer to reference index array */
1602 UWORD32 u4_num_ref_idx_active_minus1 /* Not used for range 1 */
1603 )
1604{
1605 UWORD32 u4_i;
1606 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1607 UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst;
1608 UNUSED(u4_num_ref_idx_active_minus1);
1609 for(u4_i = 0; u4_i < u4_num_part; u4_i++)
1610 {
1611 if(pi1_ref_idx[u4_i] > -1)
1612 {
1613 UWORD32 u4_ref_idx;
1614
1615 u4_ref_idx = ih264d_tev_range1(pu4_bitstream_off, pu4_bitstrm_buf);
1616
1617 /* Storing Reference Idx Information */
1618 pi1_ref_idx[u4_i] = (WORD8)u4_ref_idx;
1619 }
1620 }
1621}
1622
1623/*****************************************************************************/
1624/* */
1625/* Function Name : ih264d_parse_bmb_ref_index_cavlc */
1626/* */
1627/* Description : This function does the Cavlc TEV range > 1 parsing of */
1628/* reference index for a B MB. */
1629/* Range > 1 when num_ref_idx_active_minus1 > 0 */
1630/* */
1631/* Inputs : <What inputs does the function take?> */
1632/* Globals : <Does it use any global variables?> */
1633/* Processing : <Describe how the function operates - include algorithm */
1634/* description> */
1635/* Outputs : <What does the function produce?> */
1636/* Returns : <What does the function return?> */
1637/* */
1638/* Issues : <List any issues or problems with this function> */
1639/* */
1640/* Revision History: */
1641/* */
1642/* DD MM YYYY Author(s) Changes (Describe the changes made) */
1643/* 19 09 2008 Jay Draft */
1644/* */
1645/*****************************************************************************/
1646WORD32 ih264d_parse_bmb_ref_index_cavlc(UWORD32 u4_num_part, /* Number of partitions in MB */
1647 dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */
1648 WORD8 *pi1_ref_idx, /* pointer to reference index array */
1649 UWORD32 u4_num_ref_idx_active_minus1 /* Number of active references - 1 */
1650 )
1651{
1652 UWORD32 u4_i;
1653 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1654 UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst;
1655
1656 for(u4_i = 0; u4_i < u4_num_part; u4_i++)
1657 {
1658 if(pi1_ref_idx[u4_i] > -1)
1659 {
1660 UWORD32 u4_ref_idx;
1661//inlining ih264d_uev
1662 UWORD32 u4_bitstream_offset = *pu4_bitstream_off;
1663 UWORD32 u4_word, u4_ldz;
1664
1665 /***************************************************************/
1666 /* Find leading zeros in next 32 bits */
1667 /***************************************************************/
1668 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
1669 u4_ldz = CLZ(u4_word);
1670 /* Flush the ps_bitstrm */
1671 u4_bitstream_offset += (u4_ldz + 1);
1672 /* Read the suffix from the ps_bitstrm */
1673 u4_word = 0;
1674 if(u4_ldz)
1675 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
1676 *pu4_bitstream_off = u4_bitstream_offset;
1677 u4_ref_idx = ((1 << u4_ldz) + u4_word - 1);
1678//inlining ih264d_uev
1679 if(u4_ref_idx > u4_num_ref_idx_active_minus1)
1680 return ERROR_REF_IDX;
1681
1682 /* Storing Reference Idx Information */
1683 pi1_ref_idx[u4_i] = (WORD8)u4_ref_idx;
1684 }
1685 }
1686 return OK;
1687}
1688/*****************************************************************************/
1689/* */
1690/* Function Name : ih264d_cavlc_parse_8x8block_both_available */
1691/* */
1692/* Description : This function does the residual parsing of 4 subblocks */
1693/* in a 8x8 block when both top and left are available */
1694/* */
1695/* Inputs : pi2_coeff_block : pointer to residual block where */
1696/* decoded and inverse scan coefficients are updated */
1697/* */
1698/* u4_sub_block_strd : indicates the number of sublocks */
1699/* in a row. It is 4 for luma and 2 for chroma. */
1700/* */
1701/* u4_isdc : required to indicate 4x4 parse modules if the */
1702/* current Mb is I_16x16/chroma DC coded. */
1703/* */
1704/* ps_dec : pointer to Decstruct (decoder context) */
1705/* */
1706/* pu1_top_nnz : top nnz pointer */
1707/* */
1708/* pu1_left_nnz : left nnz pointer */
1709/* */
1710/* Globals : No */
1711/* Processing : Parsing for four subblocks in unrolled, top and left nnz */
1712/* are updated on the fly. csbp is set in accordance to */
1713/* decoded numcoeff for the subblock index in raster order */
1714/* */
1715/* Outputs : The updated residue buffer, nnzs and csbp current block */
1716/* */
1717/* Returns : Returns the coded sub block pattern csbp for the block */
1718/* */
1719/* Issues : <List any issues or problems with this function> */
1720/* */
1721/* Revision History: */
1722/* */
1723/* DD MM YYYY Author(s) Changes (Describe the changes made) */
1724/* 09 10 2008 Jay Draft */
1725/* */
1726/*****************************************************************************/
1727WORD32 ih264d_cavlc_parse_8x8block_both_available(WORD16 *pi2_coeff_block,
1728 UWORD32 u4_sub_block_strd,
1729 UWORD32 u4_isdc,
1730 dec_struct_t * ps_dec,
1731 UWORD8 *pu1_top_nnz,
1732 UWORD8 *pu1_left_nnz,
1733 UWORD8 u1_tran_form8x8,
1734 UWORD8 u1_mb_field_decodingflag,
1735 UWORD32 *pu4_csbp)
1736{
1737 UWORD32 u4_num_coeff, u4_n, u4_subblock_coded;
1738 UWORD32 u4_top0, u4_top1;
1739 UWORD32 *pu4_dummy;
1740 WORD32 (**pf_cavlc_parse4x4coeff)(WORD16 *pi2_coeff_block,
1741 UWORD32 u4_isdc,
1742 WORD32 u4_n,
1743 struct _DecStruct *ps_dec,
1744 UWORD32 *pu4_dummy) =
1745 ps_dec->pf_cavlc_parse4x4coeff;
1746 UWORD32 u4_idx = 0;
1747 UWORD8 *puc_temp;
1748 WORD32 ret;
1749
1750 *pu4_csbp = 0;
1751 /* need to change the inverse scan matrices here */
1752 puc_temp = ps_dec->pu1_inv_scan;
1753
1754 /*------------------------------------------------------*/
1755 /* Residual 4x4 decoding: SubBlock 0 */
1756 /*------------------------------------------------------*/
1757 if(u1_tran_form8x8)
1758 {
1759 if(!u1_mb_field_decodingflag)
1760 {
1761 ps_dec->pu1_inv_scan =
1762 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
1763 }
1764 else
1765 {
1766 ps_dec->pu1_inv_scan =
1767 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
1768 }
1769 }
1770 u4_n = (pu1_top_nnz[0] + pu1_left_nnz[0] + 1) >> 1;
1771 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1772 u4_n, ps_dec, &u4_num_coeff);
1773 if(ret != OK)
1774 return ret;
1775
1776 u4_top0 = u4_num_coeff;
1777 u4_subblock_coded = (u4_num_coeff != 0);
1778 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1779
1780 /*------------------------------------------------------*/
1781 /* Residual 4x4 decoding: SubBlock 1 */
1782 /*------------------------------------------------------*/
1783 u4_idx++;
1784 if(u1_tran_form8x8)
1785 {
1786 if(!u1_mb_field_decodingflag)
1787 {
1788 ps_dec->pu1_inv_scan =
1789 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
1790 }
1791 else
1792 {
1793 ps_dec->pu1_inv_scan =
1794 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
1795 }
1796 }
1797 else
1798 {
1799 pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1800 }
1801 u4_n = (pu1_top_nnz[1] + u4_num_coeff + 1) >> 1;
1802 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1803 u4_n, ps_dec, &u4_num_coeff);
1804 if(ret != OK)
1805 return ret;
1806
1807 u4_top1 = pu1_left_nnz[0] = u4_num_coeff;
1808 u4_subblock_coded = (u4_num_coeff != 0);
1809 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1810
1811 /*------------------------------------------------------*/
1812 /* Residual 4x4 decoding: SubBlock 2 */
1813 /*------------------------------------------------------*/
1814 u4_idx += (u4_sub_block_strd - 1);
1815 if(u1_tran_form8x8)
1816 {
1817 if(!u1_mb_field_decodingflag)
1818 {
1819 ps_dec->pu1_inv_scan =
1820 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
1821 }
1822 else
1823 {
1824 ps_dec->pu1_inv_scan =
1825 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
1826 }
1827 }
1828 else
1829 {
1830 pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
1831 }
1832 u4_n = (u4_top0 + pu1_left_nnz[1] + 1) >> 1;
1833 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1834 u4_n, ps_dec, &u4_num_coeff);
1835 if(ret != OK)
1836 return ret;
1837
1838 pu1_top_nnz[0] = u4_num_coeff;
1839 u4_subblock_coded = (u4_num_coeff != 0);
1840 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1841
1842 /*------------------------------------------------------*/
1843 /* Residual 4x4 decoding: SubBlock 3 */
1844 /*------------------------------------------------------*/
1845 u4_idx++;
1846 if(u1_tran_form8x8)
1847 {
1848 if(!u1_mb_field_decodingflag)
1849 {
1850 ps_dec->pu1_inv_scan =
1851 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
1852 }
1853 else
1854 {
1855 ps_dec->pu1_inv_scan =
1856 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
1857 }
1858 }
1859 else
1860 {
1861 pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1862 }
1863 u4_n = (u4_top1 + u4_num_coeff + 1) >> 1;
1864 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1865 u4_n, ps_dec, &u4_num_coeff);
1866 if(ret != OK)
1867 return ret;
1868
1869 pu1_top_nnz[1] = pu1_left_nnz[1] = u4_num_coeff;
1870 u4_subblock_coded = (u4_num_coeff != 0);
1871 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1872
1873 ps_dec->pu1_inv_scan = puc_temp;
1874
1875 return OK;
1876}
1877
1878/*****************************************************************************/
1879/* */
1880/* Function Name : ih264d_cavlc_parse_8x8block_left_available */
1881/* */
1882/* Description : This function does the residual parsing of 4 subblocks */
1883/* in a 8x8 block when only left is available for block */
1884/* */
1885/* Inputs : pi2_coeff_block : pointer to residual block where */
1886/* decoded and inverse scan coefficients are updated */
1887/* */
1888/* u4_sub_block_strd : indicates the number of sublocks */
1889/* in a row. It is 4 for luma and 2 for chroma. */
1890/* */
1891/* u4_isdc : required to indicate 4x4 parse modules if the */
1892/* current Mb is I_16x16/chroma DC coded. */
1893/* */
1894/* ps_dec : pointer to Decstruct (decoder context) */
1895/* */
1896/* pu1_top_nnz : top nnz pointer */
1897/* */
1898/* pu1_left_nnz : left nnz pointer */
1899/* */
1900/* Globals : No */
1901/* Processing : Parsing for four subblocks in unrolled, top and left nnz */
1902/* are updated on the fly. csbp is set in accordance to */
1903/* decoded numcoeff for the subblock index in raster order */
1904/* */
1905/* Outputs : The updated residue buffer, nnzs and csbp current block */
1906/* */
1907/* Returns : Returns the coded sub block pattern csbp for the block */
1908/* */
1909/* Issues : <List any issues or problems with this function> */
1910/* */
1911/* Revision History: */
1912/* */
1913/* DD MM YYYY Author(s) Changes (Describe the changes made) */
1914/* 09 10 2008 Jay Draft */
1915/* */
1916/*****************************************************************************/
1917WORD32 ih264d_cavlc_parse_8x8block_left_available(WORD16 *pi2_coeff_block,
1918 UWORD32 u4_sub_block_strd,
1919 UWORD32 u4_isdc,
1920 dec_struct_t * ps_dec,
1921 UWORD8 *pu1_top_nnz,
1922 UWORD8 *pu1_left_nnz,
1923 UWORD8 u1_tran_form8x8,
1924 UWORD8 u1_mb_field_decodingflag,
1925 UWORD32 *pu4_csbp)
1926{
1927 UWORD32 u4_num_coeff, u4_n, u4_subblock_coded;
1928 UWORD32 u4_top0, u4_top1;
1929 UWORD32 *pu4_dummy;
1930 WORD32 (**pf_cavlc_parse4x4coeff)(WORD16 *pi2_coeff_block,
1931 UWORD32 u4_isdc,
1932 WORD32 u4_n,
1933 struct _DecStruct *ps_dec,
1934 UWORD32 *pu4_dummy) =
1935 ps_dec->pf_cavlc_parse4x4coeff;
1936 UWORD32 u4_idx = 0;
1937 UWORD8 *puc_temp;
1938 WORD32 ret;
1939
1940 *pu4_csbp = 0;
1941 puc_temp = ps_dec->pu1_inv_scan;
1942
1943 /*------------------------------------------------------*/
1944 /* Residual 4x4 decoding: SubBlock 0 */
1945 /*------------------------------------------------------*/
1946 if(u1_tran_form8x8)
1947 {
1948 if(!u1_mb_field_decodingflag)
1949 {
1950 ps_dec->pu1_inv_scan =
1951 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
1952 }
1953 else
1954 {
1955 ps_dec->pu1_inv_scan =
1956 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
1957 }
1958 }
1959 u4_n = pu1_left_nnz[0];
1960 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1961 u4_n, ps_dec, &u4_num_coeff);
1962 if(ret != OK)
1963 return ret;
1964
1965 u4_top0 = u4_num_coeff;
1966 u4_subblock_coded = (u4_num_coeff != 0);
1967 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1968
1969 /*------------------------------------------------------*/
1970 /* Residual 4x4 decoding: SubBlock 1 */
1971 /*------------------------------------------------------*/
1972 u4_idx++;
1973 if(u1_tran_form8x8)
1974 {
1975 if(!u1_mb_field_decodingflag)
1976 {
1977 ps_dec->pu1_inv_scan =
1978 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
1979 }
1980 else
1981 {
1982 ps_dec->pu1_inv_scan =
1983 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
1984 }
1985 }
1986 else
1987 {
1988 pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1989 }
1990 u4_n = u4_num_coeff;
1991 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1992 u4_n, ps_dec, &u4_num_coeff);
1993 if(ret != OK)
1994 return ret;
1995
1996 u4_top1 = pu1_left_nnz[0] = u4_num_coeff;
1997 u4_subblock_coded = (u4_num_coeff != 0);
1998 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1999
2000 /*------------------------------------------------------*/
2001 /* Residual 4x4 decoding: SubBlock 2 */
2002 /*------------------------------------------------------*/
2003 u4_idx += (u4_sub_block_strd - 1);
2004 if(u1_tran_form8x8)
2005 {
2006 if(!u1_mb_field_decodingflag)
2007 {
2008 ps_dec->pu1_inv_scan =
2009 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
2010 }
2011 else
2012 {
2013 ps_dec->pu1_inv_scan =
2014 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
2015 }
2016 }
2017 else
2018 {
2019 pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
2020 }
2021 u4_n = (u4_top0 + pu1_left_nnz[1] + 1) >> 1;
2022 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2023 u4_n, ps_dec, &u4_num_coeff);
2024 if(ret != OK)
2025 return ret;
2026
2027 pu1_top_nnz[0] = u4_num_coeff;
2028 u4_subblock_coded = (u4_num_coeff != 0);
2029 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2030
2031 /*------------------------------------------------------*/
2032 /* Residual 4x4 decoding: SubBlock 3 */
2033 /*------------------------------------------------------*/
2034 u4_idx++;
2035 if(u1_tran_form8x8)
2036 {
2037 if(!u1_mb_field_decodingflag)
2038 {
2039 ps_dec->pu1_inv_scan =
2040 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
2041 }
2042 else
2043 {
2044 ps_dec->pu1_inv_scan =
2045 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
2046 }
2047 }
2048 else
2049 {
2050 pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2051 }
2052 u4_n = (u4_top1 + u4_num_coeff + 1) >> 1;
2053 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2054 u4_n, ps_dec, &u4_num_coeff);
2055 if(ret != OK)
2056 return ret;
2057
2058 pu1_top_nnz[1] = pu1_left_nnz[1] = u4_num_coeff;
2059 u4_subblock_coded = (u4_num_coeff != 0);
2060 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2061
2062 ps_dec->pu1_inv_scan = puc_temp;
2063
2064 return OK;
2065}
2066
2067/*****************************************************************************/
2068/* */
2069/* Function Name : ih264d_cavlc_parse_8x8block_top_available */
2070/* */
2071/* Description : This function does the residual parsing of 4 subblocks */
2072/* in a 8x8 block when only top is available for block */
2073/* */
2074/* Inputs : pi2_coeff_block : pointer to residual block where */
2075/* decoded and inverse scan coefficients are updated */
2076/* */
2077/* u4_sub_block_strd : indicates the number of sublocks */
2078/* in a row. It is 4 for luma and 2 for chroma. */
2079/* */
2080/* u4_isdc : required to indicate 4x4 parse modules if the */
2081/* current Mb is I_16x16/chroma DC coded. */
2082/* */
2083/* ps_dec : pointer to Decstruct (decoder context) */
2084/* */
2085/* pu1_top_nnz : top nnz pointer */
2086/* */
2087/* pu1_left_nnz : left nnz pointer */
2088/* */
2089/* Globals : No */
2090/* Processing : Parsing for four subblocks in unrolled, top and left nnz */
2091/* are updated on the fly. csbp is set in accordance to */
2092/* decoded numcoeff for the subblock index in raster order */
2093/* */
2094/* Outputs : The updated residue buffer, nnzs and csbp current block */
2095/* */
2096/* Returns : Returns the coded sub block pattern csbp for the block */
2097/* */
2098/* Issues : <List any issues or problems with this function> */
2099/* */
2100/* Revision History: */
2101/* */
2102/* DD MM YYYY Author(s) Changes (Describe the changes made) */
2103/* 09 10 2008 Jay Draft */
2104/* */
2105/*****************************************************************************/
2106WORD32 ih264d_cavlc_parse_8x8block_top_available(WORD16 *pi2_coeff_block,
2107 UWORD32 u4_sub_block_strd,
2108 UWORD32 u4_isdc,
2109 dec_struct_t * ps_dec,
2110 UWORD8 *pu1_top_nnz,
2111 UWORD8 *pu1_left_nnz,
2112 UWORD8 u1_tran_form8x8,
2113 UWORD8 u1_mb_field_decodingflag,
2114 UWORD32 *pu4_csbp)
2115{
2116 UWORD32 u4_num_coeff, u4_n, u4_subblock_coded;
2117 UWORD32 u4_top0, u4_top1;
2118 UWORD32 *pu4_dummy;
2119 WORD32 (**pf_cavlc_parse4x4coeff)(WORD16 *pi2_coeff_block,
2120 UWORD32 u4_isdc,
2121 WORD32 u4_n,
2122 struct _DecStruct *ps_dec,
2123 UWORD32 *pu4_dummy) =
2124 ps_dec->pf_cavlc_parse4x4coeff;
2125 UWORD32 u4_idx = 0;
2126 UWORD8 *puc_temp;
2127 WORD32 ret;
2128
2129 *pu4_csbp = 0;
2130 puc_temp = ps_dec->pu1_inv_scan;
2131
2132 /*------------------------------------------------------*/
2133 /* Residual 4x4 decoding: SubBlock 0 */
2134 /*------------------------------------------------------*/
2135 if(u1_tran_form8x8)
2136 {
2137 if(!u1_mb_field_decodingflag)
2138 {
2139 ps_dec->pu1_inv_scan =
2140 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
2141 }
2142 else
2143 {
2144 ps_dec->pu1_inv_scan =
2145 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
2146 }
2147 }
2148 u4_n = pu1_top_nnz[0];
2149 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2150 u4_n, ps_dec, &u4_num_coeff);
2151 if(ret != OK)
2152 return ret;
2153
2154 u4_top0 = u4_num_coeff;
2155 u4_subblock_coded = (u4_num_coeff != 0);
2156 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2157
2158 /*------------------------------------------------------*/
2159 /* Residual 4x4 decoding: SubBlock 1 */
2160 /*------------------------------------------------------*/
2161 u4_idx++;
2162 if(u1_tran_form8x8)
2163 {
2164 if(!u1_mb_field_decodingflag)
2165 {
2166 ps_dec->pu1_inv_scan =
2167 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
2168 }
2169 else
2170 {
2171 ps_dec->pu1_inv_scan =
2172 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
2173 }
2174 }
2175 else
2176 {
2177 pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2178 }
2179 u4_n = (pu1_top_nnz[1] + u4_num_coeff + 1) >> 1;
2180 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2181 u4_n, ps_dec, &u4_num_coeff);
2182 if(ret != OK)
2183 return ret;
2184
2185 u4_top1 = pu1_left_nnz[0] = u4_num_coeff;
2186 u4_subblock_coded = (u4_num_coeff != 0);
2187 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2188
2189 /*------------------------------------------------------*/
2190 /* Residual 4x4 decoding: SubBlock 2 */
2191 /*------------------------------------------------------*/
2192 u4_idx += (u4_sub_block_strd - 1);
2193 if(u1_tran_form8x8)
2194 {
2195 if(!u1_mb_field_decodingflag)
2196 {
2197 ps_dec->pu1_inv_scan =
2198 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
2199 }
2200 else
2201 {
2202 ps_dec->pu1_inv_scan =
2203 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
2204 }
2205 }
2206 else
2207 {
2208 pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
2209 }
2210 u4_n = u4_top0;
2211 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2212 u4_n, ps_dec, &u4_num_coeff);
2213 if(ret != OK)
2214 return ret;
2215
2216 pu1_top_nnz[0] = u4_num_coeff;
2217 u4_subblock_coded = (u4_num_coeff != 0);
2218 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2219
2220 /*------------------------------------------------------*/
2221 /* Residual 4x4 decoding: SubBlock 3 */
2222 /*------------------------------------------------------*/
2223 u4_idx++;
2224 if(u1_tran_form8x8)
2225 {
2226 if(!u1_mb_field_decodingflag)
2227 {
2228 ps_dec->pu1_inv_scan =
2229 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
2230 }
2231 else
2232 {
2233 ps_dec->pu1_inv_scan =
2234 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
2235 }
2236 }
2237 else
2238 {
2239 pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2240 }
2241 u4_n = (u4_top1 + u4_num_coeff + 1) >> 1;
2242 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2243 u4_n, ps_dec, &u4_num_coeff);
2244 if(ret != OK)
2245 return ret;
2246
2247 pu1_top_nnz[1] = pu1_left_nnz[1] = u4_num_coeff;
2248 u4_subblock_coded = (u4_num_coeff != 0);
2249 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2250
2251 ps_dec->pu1_inv_scan = puc_temp;
2252
2253 return OK;
2254}
2255
2256/*****************************************************************************/
2257/* */
2258/* Function Name : ih264d_cavlc_parse_8x8block_none_available */
2259/* */
2260/* Description : This function does the residual parsing of 4 subblocks */
2261/* in a 8x8 block when none of the neigbours are available */
2262/* */
2263/* Inputs : pi2_coeff_block : pointer to residual block where */
2264/* decoded and inverse scan coefficients are updated */
2265/* */
2266/* u4_sub_block_strd : indicates the number of sublocks */
2267/* in a row. It is 4 for luma and 2 for chroma. */
2268/* */
2269/* u4_isdc : required to indicate 4x4 parse modules if the */
2270/* current Mb is I_16x16/chroma DC coded. */
2271/* */
2272/* ps_dec : pointer to Decstruct (decoder context) */
2273/* */
2274/* pu1_top_nnz : top nnz pointer */
2275/* */
2276/* pu1_left_nnz : left nnz pointer */
2277/* */
2278/* Globals : No */
2279/* Processing : Parsing for four subblocks in unrolled, top and left nnz */
2280/* are updated on the fly. csbp is set in accordance to */
2281/* decoded numcoeff for the subblock index in raster order */
2282/* */
2283/* Outputs : The updated residue buffer, nnzs and csbp current block */
2284/* */
2285/* Returns : Returns the coded sub block pattern csbp for the block */
2286/* */
2287/* Issues : <List any issues or problems with this function> */
2288/* */
2289/* Revision History: */
2290/* */
2291/* DD MM YYYY Author(s) Changes (Describe the changes made) */
2292/* 09 10 2008 Jay Draft */
2293/* */
2294/*****************************************************************************/
2295WORD32 ih264d_cavlc_parse_8x8block_none_available(WORD16 *pi2_coeff_block,
2296 UWORD32 u4_sub_block_strd,
2297 UWORD32 u4_isdc,
2298 dec_struct_t * ps_dec,
2299 UWORD8 *pu1_top_nnz,
2300 UWORD8 *pu1_left_nnz,
2301 UWORD8 u1_tran_form8x8,
2302 UWORD8 u1_mb_field_decodingflag,
2303 UWORD32 *pu4_csbp)
2304{
2305 UWORD32 u4_num_coeff, u4_n, u4_subblock_coded;
2306 UWORD32 u4_top0, u4_top1;
2307 UWORD32 *pu4_dummy;
2308 WORD32 (**pf_cavlc_parse4x4coeff)(WORD16 *pi2_coeff_block,
2309 UWORD32 u4_isdc,
2310 WORD32 u4_n,
2311 struct _DecStruct *ps_dec,
2312 UWORD32 *pu4_dummy) =
2313 ps_dec->pf_cavlc_parse4x4coeff;
2314 UWORD32 u4_idx = 0;
2315 UWORD8 *puc_temp;
2316 WORD32 ret;
2317
2318 *pu4_csbp = 0;
2319 puc_temp = ps_dec->pu1_inv_scan;
2320
2321 /*------------------------------------------------------*/
2322 /* Residual 4x4 decoding: SubBlock 0 */
2323 /*------------------------------------------------------*/
2324 if(u1_tran_form8x8)
2325 {
2326 if(!u1_mb_field_decodingflag)
2327 {
2328 ps_dec->pu1_inv_scan =
2329 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
2330 }
2331 else
2332 {
2333 ps_dec->pu1_inv_scan =
2334 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
2335 }
2336 }
2337 ret = pf_cavlc_parse4x4coeff[0](pi2_coeff_block, u4_isdc, 0,
2338 ps_dec, &u4_num_coeff);
2339 if(ret != OK)
2340 return ret;
2341
2342 u4_top0 = u4_num_coeff;
2343 u4_subblock_coded = (u4_num_coeff != 0);
2344 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2345
2346 /*------------------------------------------------------*/
2347 /* Residual 4x4 decoding: SubBlock 1 */
2348 /*------------------------------------------------------*/
2349 u4_idx++;
2350 if(u1_tran_form8x8)
2351 {
2352 if(!u1_mb_field_decodingflag)
2353 {
2354 ps_dec->pu1_inv_scan =
2355 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
2356 }
2357 else
2358 {
2359 ps_dec->pu1_inv_scan =
2360 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
2361 }
2362 }
2363 else
2364 {
2365 pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2366 }
2367 u4_n = u4_num_coeff;
2368 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2369 u4_n, ps_dec, &u4_num_coeff);
2370 if(ret != OK)
2371 return ret;
2372
2373 u4_top1 = pu1_left_nnz[0] = u4_num_coeff;
2374 u4_subblock_coded = (u4_num_coeff != 0);
2375 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2376
2377 /*------------------------------------------------------*/
2378 /* Residual 4x4 decoding: SubBlock 2 */
2379 /*------------------------------------------------------*/
2380 u4_idx += (u4_sub_block_strd - 1);
2381 if(u1_tran_form8x8)
2382 {
2383 if(!u1_mb_field_decodingflag)
2384 {
2385 ps_dec->pu1_inv_scan =
2386 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
2387 }
2388 else
2389 {
2390 ps_dec->pu1_inv_scan =
2391 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
2392 }
2393 }
2394 else
2395 {
2396 pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
2397 }
2398 u4_n = u4_top0;
2399 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2400 u4_n, ps_dec, &u4_num_coeff);
2401 if(ret != OK)
2402 return ret;
2403
2404 pu1_top_nnz[0] = u4_num_coeff;
2405 u4_subblock_coded = (u4_num_coeff != 0);
2406 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2407
2408 /*------------------------------------------------------*/
2409 /* Residual 4x4 decoding: SubBlock 3 */
2410 /*------------------------------------------------------*/
2411 u4_idx++;
2412 if(u1_tran_form8x8)
2413 {
2414 if(!u1_mb_field_decodingflag)
2415 {
2416 ps_dec->pu1_inv_scan =
2417 (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
2418 }
2419 else
2420 {
2421 ps_dec->pu1_inv_scan =
2422 (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
2423 }
2424 }
2425 else
2426 {
2427 pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2428 }
2429 u4_n = (u4_top1 + u4_num_coeff + 1) >> 1;
2430 ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2431 u4_n, ps_dec, &u4_num_coeff);
2432 if(ret != OK)
2433 return ret;
2434
2435 pu1_top_nnz[1] = pu1_left_nnz[1] = u4_num_coeff;
2436 u4_subblock_coded = (u4_num_coeff != 0);
2437 INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2438
2439 ps_dec->pu1_inv_scan = puc_temp;
2440
2441 return OK;
2442}
2443
2444/*!
2445 **************************************************************************
2446 * \if Function name : ih264d_parse_residual4x4_cavlc \endif
2447 *
2448 * \brief
2449 * This function parses CAVLC syntax of a Luma and Chroma AC Residuals.
2450 *
2451 * \return
2452 * 0 on Success and Error code otherwise
2453 **************************************************************************
2454 */
2455
2456WORD32 ih264d_parse_residual4x4_cavlc(dec_struct_t * ps_dec,
2457 dec_mb_info_t *ps_cur_mb_info,
2458 UWORD8 u1_offset)
2459{
2460 UWORD8 u1_cbp = ps_cur_mb_info->u1_cbp;
2461 UWORD16 ui16_csbp = 0;
2462 UWORD32 u4_nbr_avl;
2463 WORD16 *pi2_residual_buf;
2464
2465 UWORD8 u1_is_top_mb_avail;
2466 UWORD8 u1_is_left_mb_avail;
2467
2468 UWORD8 *pu1_top_nnz = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
2469 UWORD8 *pu1_left_nnz = ps_dec->pu1_left_nnz_y;
2470 WORD16 *pi2_coeff_block = NULL;
2471 UWORD32 *pu4_dummy;
2472 WORD32 ret;
2473
2474 WORD32 (**pf_cavlc_parse_8x8block)(WORD16 *pi2_coeff_block,
2475 UWORD32 u4_sub_block_strd,
2476 UWORD32 u4_isdc,
2477 struct _DecStruct *ps_dec,
2478 UWORD8 *pu1_top_nnz,
2479 UWORD8 *pu1_left_nnz,
2480 UWORD8 u1_tran_form8x8,
2481 UWORD8 u1_mb_field_decodingflag,
2482 UWORD32 *pu4_dummy) = ps_dec->pf_cavlc_parse_8x8block;
2483
2484
2485 {
2486 UWORD8 uc_temp = ps_dec->u1_mb_ngbr_availablity;
2487 u1_is_top_mb_avail = BOOLEAN(uc_temp & TOP_MB_AVAILABLE_MASK);
2488 u1_is_left_mb_avail = BOOLEAN(uc_temp & LEFT_MB_AVAILABLE_MASK);
2489 u4_nbr_avl = (u1_is_top_mb_avail << 1) | u1_is_left_mb_avail;
2490 }
2491
2492 ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6;
2493 ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6;
2494 ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6;
2495 ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6;
2496 ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6;
2497 ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6;
2498
2499 if(u1_cbp & 0xf)
2500 {
2501 pu1_top_nnz[0] = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0];
2502 pu1_top_nnz[1] = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[1];
2503 pu1_top_nnz[2] = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[2];
2504 pu1_top_nnz[3] = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[3];
2505
2506 /*******************************************************************/
2507 /* Block 0 residual decoding, check cbp and proceed (subblock = 0) */
2508 /*******************************************************************/
2509 if(!(u1_cbp & 0x1))
2510 {
2511 *(UWORD16 *)(pu1_top_nnz) = 0;
2512 *(UWORD16 *)(pu1_left_nnz) = 0;
2513
2514 }
2515 else
2516 {
2517 UWORD32 u4_temp;
2518 ret = pf_cavlc_parse_8x8block[u4_nbr_avl](
2519 pi2_coeff_block, 4, u1_offset, ps_dec, pu1_top_nnz,
2520 pu1_left_nnz, ps_cur_mb_info->u1_tran_form8x8,
2521 ps_cur_mb_info->u1_mb_field_decodingflag, &u4_temp);
2522 if(ret != OK)
2523 return ret;
2524 ui16_csbp = u4_temp;
2525 }
2526
2527 /*******************************************************************/
2528 /* Block 1 residual decoding, check cbp and proceed (subblock = 2) */
2529 /*******************************************************************/
2530 if(ps_cur_mb_info->u1_tran_form8x8)
2531 {
2532 pi2_coeff_block += 64;
2533 }
2534 else
2535 {
2536 pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK);
2537 }
2538
2539 if(!(u1_cbp & 0x2))
2540 {
2541 *(UWORD16 *)(pu1_top_nnz + 2) = 0;
2542 *(UWORD16 *)(pu1_left_nnz) = 0;
2543 }
2544 else
2545 {
2546 UWORD32 u4_temp = (u4_nbr_avl | 0x1);
2547 ret = pf_cavlc_parse_8x8block[u4_temp](
2548 pi2_coeff_block, 4, u1_offset, ps_dec,
2549 (pu1_top_nnz + 2), pu1_left_nnz,
2550 ps_cur_mb_info->u1_tran_form8x8,
2551 ps_cur_mb_info->u1_mb_field_decodingflag, &u4_temp);
2552 if(ret != OK)
2553 return ret;
2554 ui16_csbp |= (u4_temp << 2);
2555 }
2556
2557 /*******************************************************************/
2558 /* Block 2 residual decoding, check cbp and proceed (subblock = 8) */
2559 /*******************************************************************/
2560 if(ps_cur_mb_info->u1_tran_form8x8)
2561 {
2562 pi2_coeff_block += 64;
2563 }
2564 else
2565 {
2566 pi2_coeff_block += (6 * NUM_COEFFS_IN_4x4BLK);
2567 }
2568
2569 if(!(u1_cbp & 0x4))
2570 {
2571 *(UWORD16 *)(pu1_top_nnz) = 0;
2572 *(UWORD16 *)(pu1_left_nnz + 2) = 0;
2573 }
2574 else
2575 {
2576 UWORD32 u4_temp = (u4_nbr_avl | 0x2);
2577 ret = pf_cavlc_parse_8x8block[u4_temp](
2578 pi2_coeff_block, 4, u1_offset, ps_dec, pu1_top_nnz,
2579 (pu1_left_nnz + 2), ps_cur_mb_info->u1_tran_form8x8,
2580 ps_cur_mb_info->u1_mb_field_decodingflag, &u4_temp);
2581 if(ret != OK)
2582 return ret;
2583 ui16_csbp |= (u4_temp << 8);
2584 }
2585
2586 /*******************************************************************/
2587 /* Block 3 residual decoding, check cbp and proceed (subblock = 10)*/
2588 /*******************************************************************/
2589 if(ps_cur_mb_info->u1_tran_form8x8)
2590 {
2591 pi2_coeff_block += 64;
2592 }
2593 else
2594 {
2595 pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK);
2596 }
2597
2598 if(!(u1_cbp & 0x8))
2599 {
2600 *(UWORD16 *)(pu1_top_nnz + 2) = 0;
2601 *(UWORD16 *)(pu1_left_nnz + 2) = 0;
2602 }
2603 else
2604 {
2605 UWORD32 u4_temp;
2606 ret = pf_cavlc_parse_8x8block[0x3](
2607 pi2_coeff_block, 4, u1_offset, ps_dec,
2608 (pu1_top_nnz + 2), (pu1_left_nnz + 2),
2609 ps_cur_mb_info->u1_tran_form8x8,
2610 ps_cur_mb_info->u1_mb_field_decodingflag, &u4_temp);
2611 if(ret != OK)
2612 return ret;
2613 ui16_csbp |= (u4_temp << 10);
2614 }
2615 }
2616 else
2617 {
2618 *(UWORD32 *)(pu1_top_nnz) = 0;
2619 *(UWORD32 *)(pu1_left_nnz) = 0;
2620 }
2621
2622 ps_cur_mb_info->u2_luma_csbp = ui16_csbp;
2623 ps_cur_mb_info->ps_curmb->u2_luma_csbp = ui16_csbp;
2624
2625 {
2626 UWORD16 u2_chroma_csbp = 0;
2627 ps_cur_mb_info->u2_chroma_csbp = 0;
2628 pu1_top_nnz = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
2629 pu1_left_nnz = ps_dec->pu1_left_nnz_uv;
2630
2631 u1_cbp >>= 4;
2632 /*--------------------------------------------------------------------*/
2633 /* if Chroma Component not present OR no ac values present */
2634 /* Set the values of N to zero */
2635 /*--------------------------------------------------------------------*/
2636 if(u1_cbp == CBPC_ALLZERO || u1_cbp == CBPC_ACZERO)
2637 {
2638 *(UWORD32 *)(pu1_top_nnz) = 0;
2639 *(UWORD32 *)(pu1_left_nnz) = 0;
2640 }
2641
2642 if(u1_cbp == CBPC_ALLZERO)
2643 {
2644 return (0);
2645 }
2646 /*--------------------------------------------------------------------*/
2647 /* Decode Chroma DC values */
2648 /*--------------------------------------------------------------------*/
2649 {
2650 WORD32 u4_scale_u;
2651 WORD32 u4_scale_v;
2652 WORD32 i4_mb_inter_inc;
2653 u4_scale_u = ps_dec->pu2_quant_scale_u[0] << ps_dec->u1_qp_u_div6;
2654 u4_scale_v = ps_dec->pu2_quant_scale_v[0] << ps_dec->u1_qp_v_div6;
2655 i4_mb_inter_inc = (!((ps_cur_mb_info->ps_curmb->u1_mb_type == I_4x4_MB)
2656 || (ps_cur_mb_info->ps_curmb->u1_mb_type == I_16x16_MB)))
2657 * 3;
2658
2659 if(ps_dec->s_high_profile.u1_scaling_present)
2660 {
2661 u4_scale_u *=
2662 ps_dec->s_high_profile.i2_scalinglist4x4[i4_mb_inter_inc
2663 + 1][0];
2664 u4_scale_v *=
2665 ps_dec->s_high_profile.i2_scalinglist4x4[i4_mb_inter_inc
2666 + 2][0];
2667
2668 }
2669 else
2670 {
2671 u4_scale_u <<= 4;
2672 u4_scale_v <<= 4;
2673 }
2674
2675 ih264d_cavlc_parse_chroma_dc(ps_cur_mb_info,pi2_coeff_block, ps_dec->ps_bitstrm,
2676 u4_scale_u, u4_scale_v,
2677 i4_mb_inter_inc);
2678 }
2679
2680 if(u1_cbp == CBPC_ACZERO)
2681 return (0);
2682
2683 pu1_top_nnz[0] = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv[0];
2684 pu1_top_nnz[1] = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv[1];
2685 pu1_top_nnz[2] = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv[2];
2686 pu1_top_nnz[3] = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv[3];
2687 /*--------------------------------------------------------------------*/
2688 /* Decode Chroma AC values */
2689 /*--------------------------------------------------------------------*/
2690 {
2691 UWORD32 u4_temp;
2692 /*****************************************************************/
2693 /* U Block residual decoding, check cbp and proceed (subblock=0)*/
2694 /*****************************************************************/
2695 ret = pf_cavlc_parse_8x8block[u4_nbr_avl](
2696 pi2_coeff_block, 2, 1, ps_dec, pu1_top_nnz,
2697 pu1_left_nnz, 0, 0, &u4_temp);
2698 if(ret != OK)
2699 return ret;
2700 u2_chroma_csbp = u4_temp;
2701
2702 pi2_coeff_block += MB_CHROM_SIZE;
2703 /*****************************************************************/
2704 /* V Block residual decoding, check cbp and proceed (subblock=1)*/
2705 /*****************************************************************/
2706 ret = pf_cavlc_parse_8x8block[u4_nbr_avl](pi2_coeff_block, 2, 1,
2707 ps_dec,
2708 (pu1_top_nnz + 2),
2709 (pu1_left_nnz + 2), 0,
2710 0, &u4_temp);
2711 if(ret != OK)
2712 return ret;
2713 u2_chroma_csbp |= (u4_temp << 4);
2714 }
2715
2716 ps_cur_mb_info->u2_chroma_csbp = u2_chroma_csbp;
2717 }
2718 return OK;
2719}