xref: /aosp_15_r20/external/libavc/decoder/ih264d_parse_islice.c (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1*495ae853SAndroid Build Coastguard Worker /******************************************************************************
2*495ae853SAndroid Build Coastguard Worker  *
3*495ae853SAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
4*495ae853SAndroid Build Coastguard Worker  *
5*495ae853SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*495ae853SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*495ae853SAndroid Build Coastguard Worker  * You may obtain a copy of the License at:
8*495ae853SAndroid Build Coastguard Worker  *
9*495ae853SAndroid Build Coastguard Worker  * http://www.apache.org/licenses/LICENSE-2.0
10*495ae853SAndroid Build Coastguard Worker  *
11*495ae853SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*495ae853SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*495ae853SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*495ae853SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*495ae853SAndroid Build Coastguard Worker  * limitations under the License.
16*495ae853SAndroid Build Coastguard Worker  *
17*495ae853SAndroid Build Coastguard Worker  *****************************************************************************
18*495ae853SAndroid Build Coastguard Worker  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*495ae853SAndroid Build Coastguard Worker */
20*495ae853SAndroid Build Coastguard Worker 
21*495ae853SAndroid Build Coastguard Worker /*!
22*495ae853SAndroid Build Coastguard Worker  **************************************************************************
23*495ae853SAndroid Build Coastguard Worker  * \file ih264d_parse_islice.c
24*495ae853SAndroid Build Coastguard Worker  *
25*495ae853SAndroid Build Coastguard Worker  * \brief
26*495ae853SAndroid Build Coastguard Worker  *    Contains routines that decode a I slice type
27*495ae853SAndroid Build Coastguard Worker  *
28*495ae853SAndroid Build Coastguard Worker  * Detailed_description
29*495ae853SAndroid Build Coastguard Worker  *
30*495ae853SAndroid Build Coastguard Worker  * \date
31*495ae853SAndroid Build Coastguard Worker  *    07/07/2003
32*495ae853SAndroid Build Coastguard Worker  *
33*495ae853SAndroid Build Coastguard Worker  * \author  NS
34*495ae853SAndroid Build Coastguard Worker  **************************************************************************
35*495ae853SAndroid Build Coastguard Worker  */
36*495ae853SAndroid Build Coastguard Worker #include <string.h>
37*495ae853SAndroid Build Coastguard Worker #include "ih264_defs.h"
38*495ae853SAndroid Build Coastguard Worker #include "ih264d_error_handler.h"
39*495ae853SAndroid Build Coastguard Worker #include "ih264d_debug.h"
40*495ae853SAndroid Build Coastguard Worker #include "ih264d_bitstrm.h"
41*495ae853SAndroid Build Coastguard Worker #include "ih264d_defs.h"
42*495ae853SAndroid Build Coastguard Worker #include "ih264d_debug.h"
43*495ae853SAndroid Build Coastguard Worker #include "ih264d_tables.h"
44*495ae853SAndroid Build Coastguard Worker #include "ih264d_structs.h"
45*495ae853SAndroid Build Coastguard Worker #include "ih264d_defs.h"
46*495ae853SAndroid Build Coastguard Worker #include "ih264d_parse_cavlc.h"
47*495ae853SAndroid Build Coastguard Worker #include "ih264d_mb_utils.h"
48*495ae853SAndroid Build Coastguard Worker #include "ih264d_deblocking.h"
49*495ae853SAndroid Build Coastguard Worker #include "ih264d_cabac.h"
50*495ae853SAndroid Build Coastguard Worker #include "ih264d_parse_cabac.h"
51*495ae853SAndroid Build Coastguard Worker #include "ih264d_parse_mb_header.h"
52*495ae853SAndroid Build Coastguard Worker #include "ih264d_parse_slice.h"
53*495ae853SAndroid Build Coastguard Worker #include "ih264d_process_pslice.h"
54*495ae853SAndroid Build Coastguard Worker #include "ih264d_process_intra_mb.h"
55*495ae853SAndroid Build Coastguard Worker #include "ih264d_parse_islice.h"
56*495ae853SAndroid Build Coastguard Worker #include "ih264d_error_handler.h"
57*495ae853SAndroid Build Coastguard Worker #include "ih264d_mvpred.h"
58*495ae853SAndroid Build Coastguard Worker #include "ih264d_defs.h"
59*495ae853SAndroid Build Coastguard Worker #include "ih264d_thread_parse_decode.h"
60*495ae853SAndroid Build Coastguard Worker #include "ithread.h"
61*495ae853SAndroid Build Coastguard Worker #include "ih264d_parse_mb_header.h"
62*495ae853SAndroid Build Coastguard Worker #include "assert.h"
63*495ae853SAndroid Build Coastguard Worker #include "ih264d_utils.h"
64*495ae853SAndroid Build Coastguard Worker #include "ih264d_format_conv.h"
65*495ae853SAndroid Build Coastguard Worker 
66*495ae853SAndroid Build Coastguard Worker void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
67*495ae853SAndroid Build Coastguard Worker 
68*495ae853SAndroid Build Coastguard Worker void ih264d_itrans_recon_luma_dc(dec_struct_t *ps_dec,
69*495ae853SAndroid Build Coastguard Worker                                  WORD16* pi2_src,
70*495ae853SAndroid Build Coastguard Worker                                  WORD16* pi2_coeff_block,
71*495ae853SAndroid Build Coastguard Worker                                  const UWORD16 *pu2_weigh_mat);
72*495ae853SAndroid Build Coastguard Worker 
73*495ae853SAndroid Build Coastguard Worker 
74*495ae853SAndroid Build Coastguard Worker 
75*495ae853SAndroid Build Coastguard Worker /*!
76*495ae853SAndroid Build Coastguard Worker  **************************************************************************
77*495ae853SAndroid Build Coastguard Worker  * \if Function name : ParseIMb \endif
78*495ae853SAndroid Build Coastguard Worker  *
79*495ae853SAndroid Build Coastguard Worker  * \brief
80*495ae853SAndroid Build Coastguard Worker  *    This function parses CAVLC syntax of a I MB. If 16x16 Luma DC transform
81*495ae853SAndroid Build Coastguard Worker  *    is also done here. Transformed Luma DC values are copied in their
82*495ae853SAndroid Build Coastguard Worker  *    0th pixel location of corrosponding CoeffBlock.
83*495ae853SAndroid Build Coastguard Worker  *
84*495ae853SAndroid Build Coastguard Worker  * \return
85*495ae853SAndroid Build Coastguard Worker  *    0 on Success and Error code otherwise
86*495ae853SAndroid Build Coastguard Worker  **************************************************************************
87*495ae853SAndroid Build Coastguard Worker  */
ih264d_parse_imb_cavlc(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mb_num,UWORD8 u1_mb_type)88*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_imb_cavlc(dec_struct_t * ps_dec,
89*495ae853SAndroid Build Coastguard Worker                               dec_mb_info_t * ps_cur_mb_info,
90*495ae853SAndroid Build Coastguard Worker                               UWORD8 u1_mb_num,
91*495ae853SAndroid Build Coastguard Worker                               UWORD8 u1_mb_type)
92*495ae853SAndroid Build Coastguard Worker {
93*495ae853SAndroid Build Coastguard Worker     WORD32 i4_delta_qp;
94*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_temp;
95*495ae853SAndroid Build Coastguard Worker     UWORD32 ui_is_top_mb_available;
96*495ae853SAndroid Build Coastguard Worker     UWORD32 ui_is_left_mb_available;
97*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_cbp;
98*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_offset;
99*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_buf;
100*495ae853SAndroid Build Coastguard Worker     WORD32 ret;
101*495ae853SAndroid Build Coastguard Worker 
102*495ae853SAndroid Build Coastguard Worker     dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
103*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
104*495ae853SAndroid Build Coastguard Worker     UNUSED(u1_mb_num);
105*495ae853SAndroid Build Coastguard Worker     ps_cur_mb_info->u1_tran_form8x8 = 0;
106*495ae853SAndroid Build Coastguard Worker     ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
107*495ae853SAndroid Build Coastguard Worker 
108*495ae853SAndroid Build Coastguard Worker     ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
109*495ae853SAndroid Build Coastguard Worker 
110*495ae853SAndroid Build Coastguard Worker     u4_temp = ps_dec->u1_mb_ngbr_availablity;
111*495ae853SAndroid Build Coastguard Worker     ui_is_top_mb_available = BOOLEAN(u4_temp & TOP_MB_AVAILABLE_MASK);
112*495ae853SAndroid Build Coastguard Worker     ui_is_left_mb_available = BOOLEAN(u4_temp & LEFT_MB_AVAILABLE_MASK);
113*495ae853SAndroid Build Coastguard Worker 
114*495ae853SAndroid Build Coastguard Worker     pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
115*495ae853SAndroid Build Coastguard Worker 
116*495ae853SAndroid Build Coastguard Worker     if(u1_mb_type == I_4x4_MB)
117*495ae853SAndroid Build Coastguard Worker     {
118*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
119*495ae853SAndroid Build Coastguard Worker         u4_offset = 0;
120*495ae853SAndroid Build Coastguard Worker 
121*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
122*495ae853SAndroid Build Coastguard Worker         /* Read transform_size_8x8_flag if present                            */
123*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
124*495ae853SAndroid Build Coastguard Worker         if(ps_dec->s_high_profile.u1_transform8x8_present)
125*495ae853SAndroid Build Coastguard Worker         {
126*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm);
127*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
128*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
129*495ae853SAndroid Build Coastguard Worker         }
130*495ae853SAndroid Build Coastguard Worker 
131*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
132*495ae853SAndroid Build Coastguard Worker         /* Read the IntraPrediction modes for LUMA                            */
133*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
134*495ae853SAndroid Build Coastguard Worker         if (!ps_cur_mb_info->u1_tran_form8x8)
135*495ae853SAndroid Build Coastguard Worker         {
136*495ae853SAndroid Build Coastguard Worker             UWORD8 *pu1_temp;
137*495ae853SAndroid Build Coastguard Worker             ih264d_read_intra_pred_modes(ps_dec,
138*495ae853SAndroid Build Coastguard Worker                                           ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
139*495ae853SAndroid Build Coastguard Worker                                           ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16),
140*495ae853SAndroid Build Coastguard Worker                                           ps_cur_mb_info->u1_tran_form8x8);
141*495ae853SAndroid Build Coastguard Worker             pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
142*495ae853SAndroid Build Coastguard Worker             pu1_temp += 32;
143*495ae853SAndroid Build Coastguard Worker             ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
144*495ae853SAndroid Build Coastguard Worker         }
145*495ae853SAndroid Build Coastguard Worker         else
146*495ae853SAndroid Build Coastguard Worker         {
147*495ae853SAndroid Build Coastguard Worker             UWORD8 *pu1_temp;
148*495ae853SAndroid Build Coastguard Worker             ih264d_read_intra_pred_modes(ps_dec,
149*495ae853SAndroid Build Coastguard Worker                                           ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
150*495ae853SAndroid Build Coastguard Worker                                           ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4),
151*495ae853SAndroid Build Coastguard Worker                                           ps_cur_mb_info->u1_tran_form8x8);
152*495ae853SAndroid Build Coastguard Worker             pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
153*495ae853SAndroid Build Coastguard Worker             pu1_temp += 8;
154*495ae853SAndroid Build Coastguard Worker             ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
155*495ae853SAndroid Build Coastguard Worker         }
156*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
157*495ae853SAndroid Build Coastguard Worker         /* Read the IntraPrediction mode for CHROMA                           */
158*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
159*495ae853SAndroid Build Coastguard Worker //Inlined ih264d_uev
160*495ae853SAndroid Build Coastguard Worker         {
161*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
162*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_word, u4_ldz, u4_temp;
163*495ae853SAndroid Build Coastguard Worker 
164*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
165*495ae853SAndroid Build Coastguard Worker             /* Find leading zeros in next 32 bits                          */
166*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
167*495ae853SAndroid Build Coastguard Worker             NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
168*495ae853SAndroid Build Coastguard Worker             u4_ldz = CLZ(u4_word);
169*495ae853SAndroid Build Coastguard Worker             /* Flush the ps_bitstrm */
170*495ae853SAndroid Build Coastguard Worker             u4_bitstream_offset += (u4_ldz + 1);
171*495ae853SAndroid Build Coastguard Worker             /* Read the suffix from the ps_bitstrm */
172*495ae853SAndroid Build Coastguard Worker             u4_word = 0;
173*495ae853SAndroid Build Coastguard Worker             if(u4_ldz)
174*495ae853SAndroid Build Coastguard Worker             {
175*495ae853SAndroid Build Coastguard Worker                 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
176*495ae853SAndroid Build Coastguard Worker                         u4_ldz);
177*495ae853SAndroid Build Coastguard Worker             }
178*495ae853SAndroid Build Coastguard Worker             *pu4_bitstrm_ofst = u4_bitstream_offset;
179*495ae853SAndroid Build Coastguard Worker             u4_temp = ((1 << u4_ldz) + u4_word - 1);
180*495ae853SAndroid Build Coastguard Worker             if(u4_temp > 3)
181*495ae853SAndroid Build Coastguard Worker             {
182*495ae853SAndroid Build Coastguard Worker                 return ERROR_CHROMA_PRED_MODE;
183*495ae853SAndroid Build Coastguard Worker             }
184*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->u1_chroma_pred_mode = u4_temp;
185*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode);
186*495ae853SAndroid Build Coastguard Worker         }
187*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
188*495ae853SAndroid Build Coastguard Worker         /* Read the Coded block pattern                                       */
189*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
190*495ae853SAndroid Build Coastguard Worker         {
191*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
192*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_word, u4_ldz;
193*495ae853SAndroid Build Coastguard Worker 
194*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
195*495ae853SAndroid Build Coastguard Worker             /* Find leading zeros in next 32 bits                          */
196*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
197*495ae853SAndroid Build Coastguard Worker             NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
198*495ae853SAndroid Build Coastguard Worker             u4_ldz = CLZ(u4_word);
199*495ae853SAndroid Build Coastguard Worker             /* Flush the ps_bitstrm */
200*495ae853SAndroid Build Coastguard Worker             u4_bitstream_offset += (u4_ldz + 1);
201*495ae853SAndroid Build Coastguard Worker             /* Read the suffix from the ps_bitstrm */
202*495ae853SAndroid Build Coastguard Worker             u4_word = 0;
203*495ae853SAndroid Build Coastguard Worker             if(u4_ldz)
204*495ae853SAndroid Build Coastguard Worker             {
205*495ae853SAndroid Build Coastguard Worker                 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
206*495ae853SAndroid Build Coastguard Worker                         u4_ldz);
207*495ae853SAndroid Build Coastguard Worker             }
208*495ae853SAndroid Build Coastguard Worker             *pu4_bitstrm_ofst = u4_bitstream_offset;
209*495ae853SAndroid Build Coastguard Worker             u4_cbp = ((1 << u4_ldz) + u4_word - 1);
210*495ae853SAndroid Build Coastguard Worker         }
211*495ae853SAndroid Build Coastguard Worker         if(u4_cbp > 47)
212*495ae853SAndroid Build Coastguard Worker         {
213*495ae853SAndroid Build Coastguard Worker             return ERROR_CBP;
214*495ae853SAndroid Build Coastguard Worker         }
215*495ae853SAndroid Build Coastguard Worker 
216*495ae853SAndroid Build Coastguard Worker         u4_cbp = gau1_ih264d_cbp_table[u4_cbp][0];
217*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("coded_block_pattern", u1_cbp);
218*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_cbp = u4_cbp;
219*495ae853SAndroid Build Coastguard Worker 
220*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
221*495ae853SAndroid Build Coastguard Worker         /* Read mb_qp_delta                                                   */
222*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
223*495ae853SAndroid Build Coastguard Worker         if(ps_cur_mb_info->u1_cbp)
224*495ae853SAndroid Build Coastguard Worker         {
225*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
226*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_word, u4_ldz, u4_abs_val;
227*495ae853SAndroid Build Coastguard Worker 
228*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
229*495ae853SAndroid Build Coastguard Worker             /* Find leading zeros in next 32 bits                          */
230*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
231*495ae853SAndroid Build Coastguard Worker             NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
232*495ae853SAndroid Build Coastguard Worker             u4_ldz = CLZ(u4_word);
233*495ae853SAndroid Build Coastguard Worker 
234*495ae853SAndroid Build Coastguard Worker             /* Flush the ps_bitstrm */
235*495ae853SAndroid Build Coastguard Worker             u4_bitstream_offset += (u4_ldz + 1);
236*495ae853SAndroid Build Coastguard Worker 
237*495ae853SAndroid Build Coastguard Worker             /* Read the suffix from the ps_bitstrm */
238*495ae853SAndroid Build Coastguard Worker             u4_word = 0;
239*495ae853SAndroid Build Coastguard Worker             if(u4_ldz)
240*495ae853SAndroid Build Coastguard Worker             {
241*495ae853SAndroid Build Coastguard Worker                 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
242*495ae853SAndroid Build Coastguard Worker                         u4_ldz);
243*495ae853SAndroid Build Coastguard Worker             }
244*495ae853SAndroid Build Coastguard Worker 
245*495ae853SAndroid Build Coastguard Worker             *pu4_bitstrm_ofst = u4_bitstream_offset;
246*495ae853SAndroid Build Coastguard Worker             u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
247*495ae853SAndroid Build Coastguard Worker 
248*495ae853SAndroid Build Coastguard Worker             if(u4_word & 0x1)
249*495ae853SAndroid Build Coastguard Worker             {
250*495ae853SAndroid Build Coastguard Worker                 i4_delta_qp = (-(WORD32)u4_abs_val);
251*495ae853SAndroid Build Coastguard Worker             }
252*495ae853SAndroid Build Coastguard Worker             else
253*495ae853SAndroid Build Coastguard Worker             {
254*495ae853SAndroid Build Coastguard Worker                 i4_delta_qp = (u4_abs_val);
255*495ae853SAndroid Build Coastguard Worker             }
256*495ae853SAndroid Build Coastguard Worker 
257*495ae853SAndroid Build Coastguard Worker             if((i4_delta_qp < -26) || (i4_delta_qp > 25))
258*495ae853SAndroid Build Coastguard Worker             {
259*495ae853SAndroid Build Coastguard Worker                 return ERROR_INV_RANGE_QP_T;
260*495ae853SAndroid Build Coastguard Worker             }
261*495ae853SAndroid Build Coastguard Worker 
262*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
263*495ae853SAndroid Build Coastguard Worker             if(i4_delta_qp != 0)
264*495ae853SAndroid Build Coastguard Worker             {
265*495ae853SAndroid Build Coastguard Worker                 ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp);
266*495ae853SAndroid Build Coastguard Worker                 if(ret != OK)
267*495ae853SAndroid Build Coastguard Worker                     return ret;
268*495ae853SAndroid Build Coastguard Worker             }
269*495ae853SAndroid Build Coastguard Worker         }
270*495ae853SAndroid Build Coastguard Worker 
271*495ae853SAndroid Build Coastguard Worker     }
272*495ae853SAndroid Build Coastguard Worker     else
273*495ae853SAndroid Build Coastguard Worker     {
274*495ae853SAndroid Build Coastguard Worker         u4_offset = 1;
275*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
276*495ae853SAndroid Build Coastguard Worker         /*-------------------------------------------------------------------*/
277*495ae853SAndroid Build Coastguard Worker         /* Read the IntraPrediction mode for CHROMA                          */
278*495ae853SAndroid Build Coastguard Worker         /*-------------------------------------------------------------------*/
279*495ae853SAndroid Build Coastguard Worker         {
280*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
281*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_word, u4_ldz;
282*495ae853SAndroid Build Coastguard Worker 
283*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
284*495ae853SAndroid Build Coastguard Worker             /* Find leading zeros in next 32 bits                          */
285*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
286*495ae853SAndroid Build Coastguard Worker             NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
287*495ae853SAndroid Build Coastguard Worker             u4_ldz = CLZ(u4_word);
288*495ae853SAndroid Build Coastguard Worker             /* Flush the ps_bitstrm */
289*495ae853SAndroid Build Coastguard Worker             u4_bitstream_offset += (u4_ldz + 1);
290*495ae853SAndroid Build Coastguard Worker             /* Read the suffix from the ps_bitstrm */
291*495ae853SAndroid Build Coastguard Worker             u4_word = 0;
292*495ae853SAndroid Build Coastguard Worker             if(u4_ldz)
293*495ae853SAndroid Build Coastguard Worker             {
294*495ae853SAndroid Build Coastguard Worker                 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
295*495ae853SAndroid Build Coastguard Worker                         u4_ldz);
296*495ae853SAndroid Build Coastguard Worker             }
297*495ae853SAndroid Build Coastguard Worker             *pu4_bitstrm_ofst = u4_bitstream_offset;
298*495ae853SAndroid Build Coastguard Worker             u4_temp = ((1 << u4_ldz) + u4_word - 1);
299*495ae853SAndroid Build Coastguard Worker 
300*495ae853SAndroid Build Coastguard Worker //Inlined ih264d_uev
301*495ae853SAndroid Build Coastguard Worker 
302*495ae853SAndroid Build Coastguard Worker             if(u4_temp > 3)
303*495ae853SAndroid Build Coastguard Worker             {
304*495ae853SAndroid Build Coastguard Worker                 return ERROR_CHROMA_PRED_MODE;
305*495ae853SAndroid Build Coastguard Worker             }
306*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->u1_chroma_pred_mode = u4_temp;
307*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode);
308*495ae853SAndroid Build Coastguard Worker         }
309*495ae853SAndroid Build Coastguard Worker         /*-------------------------------------------------------------------*/
310*495ae853SAndroid Build Coastguard Worker         /* Read the Coded block pattern                                      */
311*495ae853SAndroid Build Coastguard Worker         /*-------------------------------------------------------------------*/
312*495ae853SAndroid Build Coastguard Worker         u4_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2];
313*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_cbp = u4_cbp;
314*495ae853SAndroid Build Coastguard Worker 
315*495ae853SAndroid Build Coastguard Worker         /*-------------------------------------------------------------------*/
316*495ae853SAndroid Build Coastguard Worker         /* Read mb_qp_delta                                                  */
317*495ae853SAndroid Build Coastguard Worker         /*-------------------------------------------------------------------*/
318*495ae853SAndroid Build Coastguard Worker         {
319*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
320*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_word, u4_ldz, u4_abs_val;
321*495ae853SAndroid Build Coastguard Worker 
322*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
323*495ae853SAndroid Build Coastguard Worker             /* Find leading zeros in next 32 bits                          */
324*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
325*495ae853SAndroid Build Coastguard Worker             NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
326*495ae853SAndroid Build Coastguard Worker             u4_ldz = CLZ(u4_word);
327*495ae853SAndroid Build Coastguard Worker 
328*495ae853SAndroid Build Coastguard Worker             /* Flush the ps_bitstrm */
329*495ae853SAndroid Build Coastguard Worker             u4_bitstream_offset += (u4_ldz + 1);
330*495ae853SAndroid Build Coastguard Worker 
331*495ae853SAndroid Build Coastguard Worker             /* Read the suffix from the ps_bitstrm */
332*495ae853SAndroid Build Coastguard Worker             u4_word = 0;
333*495ae853SAndroid Build Coastguard Worker             if(u4_ldz)
334*495ae853SAndroid Build Coastguard Worker                 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
335*495ae853SAndroid Build Coastguard Worker                         u4_ldz);
336*495ae853SAndroid Build Coastguard Worker 
337*495ae853SAndroid Build Coastguard Worker             *pu4_bitstrm_ofst = u4_bitstream_offset;
338*495ae853SAndroid Build Coastguard Worker             u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
339*495ae853SAndroid Build Coastguard Worker 
340*495ae853SAndroid Build Coastguard Worker             if(u4_word & 0x1)
341*495ae853SAndroid Build Coastguard Worker                 i4_delta_qp = (-(WORD32)u4_abs_val);
342*495ae853SAndroid Build Coastguard Worker             else
343*495ae853SAndroid Build Coastguard Worker                 i4_delta_qp = (u4_abs_val);
344*495ae853SAndroid Build Coastguard Worker 
345*495ae853SAndroid Build Coastguard Worker             if((i4_delta_qp < -26) || (i4_delta_qp > 25))
346*495ae853SAndroid Build Coastguard Worker                 return ERROR_INV_RANGE_QP_T;
347*495ae853SAndroid Build Coastguard Worker 
348*495ae853SAndroid Build Coastguard Worker         }
349*495ae853SAndroid Build Coastguard Worker //inlinined ih264d_sev
350*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("Delta quant", i1_delta_qp);
351*495ae853SAndroid Build Coastguard Worker 
352*495ae853SAndroid Build Coastguard Worker         if(i4_delta_qp != 0)
353*495ae853SAndroid Build Coastguard Worker         {
354*495ae853SAndroid Build Coastguard Worker             ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp);
355*495ae853SAndroid Build Coastguard Worker             if(ret != OK)
356*495ae853SAndroid Build Coastguard Worker                 return ret;
357*495ae853SAndroid Build Coastguard Worker         }
358*495ae853SAndroid Build Coastguard Worker 
359*495ae853SAndroid Build Coastguard Worker         {
360*495ae853SAndroid Build Coastguard Worker             WORD16 i_scaleFactor;
361*495ae853SAndroid Build Coastguard Worker             UWORD32 ui_N = 0;
362*495ae853SAndroid Build Coastguard Worker             WORD16 *pi2_scale_matrix_ptr;
363*495ae853SAndroid Build Coastguard Worker             /*******************************************************************/
364*495ae853SAndroid Build Coastguard Worker             /* for luma DC coefficients the scaling is done during the parsing */
365*495ae853SAndroid Build Coastguard Worker             /* to preserve the precision                                       */
366*495ae853SAndroid Build Coastguard Worker             /*******************************************************************/
367*495ae853SAndroid Build Coastguard Worker             if(ps_dec->s_high_profile.u1_scaling_present)
368*495ae853SAndroid Build Coastguard Worker             {
369*495ae853SAndroid Build Coastguard Worker                 pi2_scale_matrix_ptr =
370*495ae853SAndroid Build Coastguard Worker                                 ps_dec->s_high_profile.i2_scalinglist4x4[0];
371*495ae853SAndroid Build Coastguard Worker             }
372*495ae853SAndroid Build Coastguard Worker             else
373*495ae853SAndroid Build Coastguard Worker             {
374*495ae853SAndroid Build Coastguard Worker                 i_scaleFactor = 16;
375*495ae853SAndroid Build Coastguard Worker                 pi2_scale_matrix_ptr = &i_scaleFactor;
376*495ae853SAndroid Build Coastguard Worker             }
377*495ae853SAndroid Build Coastguard Worker 
378*495ae853SAndroid Build Coastguard Worker             /*---------------------------------------------------------------*/
379*495ae853SAndroid Build Coastguard Worker             /* Decode DC coefficients                                        */
380*495ae853SAndroid Build Coastguard Worker             /*---------------------------------------------------------------*/
381*495ae853SAndroid Build Coastguard Worker             /*---------------------------------------------------------------*/
382*495ae853SAndroid Build Coastguard Worker             /* Calculation of N                                              */
383*495ae853SAndroid Build Coastguard Worker             /*---------------------------------------------------------------*/
384*495ae853SAndroid Build Coastguard Worker             if(ui_is_left_mb_available)
385*495ae853SAndroid Build Coastguard Worker             {
386*495ae853SAndroid Build Coastguard Worker 
387*495ae853SAndroid Build Coastguard Worker                 if(ui_is_top_mb_available)
388*495ae853SAndroid Build Coastguard Worker                 {
389*495ae853SAndroid Build Coastguard Worker                     ui_N = ((ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0]
390*495ae853SAndroid Build Coastguard Worker                                     + ps_dec->pu1_left_nnz_y[0] + 1) >> 1);
391*495ae853SAndroid Build Coastguard Worker                 }
392*495ae853SAndroid Build Coastguard Worker                 else
393*495ae853SAndroid Build Coastguard Worker                 {
394*495ae853SAndroid Build Coastguard Worker                     ui_N = ps_dec->pu1_left_nnz_y[0];
395*495ae853SAndroid Build Coastguard Worker                 }
396*495ae853SAndroid Build Coastguard Worker             }
397*495ae853SAndroid Build Coastguard Worker             else if(ui_is_top_mb_available)
398*495ae853SAndroid Build Coastguard Worker             {
399*495ae853SAndroid Build Coastguard Worker                 ui_N = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0];
400*495ae853SAndroid Build Coastguard Worker             }
401*495ae853SAndroid Build Coastguard Worker 
402*495ae853SAndroid Build Coastguard Worker             {
403*495ae853SAndroid Build Coastguard Worker                 WORD16 pi2_dc_coef[16];
404*495ae853SAndroid Build Coastguard Worker                 WORD32 pi4_tmp[16];
405*495ae853SAndroid Build Coastguard Worker                 tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
406*495ae853SAndroid Build Coastguard Worker                                 (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
407*495ae853SAndroid Build Coastguard Worker                 WORD16 *pi2_coeff_block =
408*495ae853SAndroid Build Coastguard Worker                                 (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
409*495ae853SAndroid Build Coastguard Worker                 UWORD32 u4_num_coeff;
410*495ae853SAndroid Build Coastguard Worker                 ps_tu_4x4->u2_sig_coeff_map = 0;
411*495ae853SAndroid Build Coastguard Worker 
412*495ae853SAndroid Build Coastguard Worker                 ret = ps_dec->pf_cavlc_parse4x4coeff[(ui_N > 7)](pi2_dc_coef, 0, ui_N,
413*495ae853SAndroid Build Coastguard Worker                                                                  ps_dec, &u4_num_coeff);
414*495ae853SAndroid Build Coastguard Worker                 if(ret != OK)
415*495ae853SAndroid Build Coastguard Worker                     return ret;
416*495ae853SAndroid Build Coastguard Worker 
417*495ae853SAndroid Build Coastguard Worker                 if(EXCEED_OFFSET(ps_bitstrm))
418*495ae853SAndroid Build Coastguard Worker                     return ERROR_EOB_TERMINATE_T;
419*495ae853SAndroid Build Coastguard Worker                 if(ps_tu_4x4->u2_sig_coeff_map)
420*495ae853SAndroid Build Coastguard Worker                 {
421*495ae853SAndroid Build Coastguard Worker                     memset(pi2_dc_coef,0,sizeof(pi2_dc_coef));
422*495ae853SAndroid Build Coastguard Worker                     ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
423*495ae853SAndroid Build Coastguard Worker                                                      pi2_dc_coef,
424*495ae853SAndroid Build Coastguard Worker                                                      ps_dec->pu1_inv_scan);
425*495ae853SAndroid Build Coastguard Worker 
426*495ae853SAndroid Build Coastguard Worker                     PROFILE_DISABLE_IQ_IT_RECON()
427*495ae853SAndroid Build Coastguard Worker                     ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef,
428*495ae853SAndroid Build Coastguard Worker                                                      pi2_coeff_block,
429*495ae853SAndroid Build Coastguard Worker                                                      ps_dec->pu2_quant_scale_y,
430*495ae853SAndroid Build Coastguard Worker                                                      (UWORD16 *)pi2_scale_matrix_ptr,
431*495ae853SAndroid Build Coastguard Worker                                                      ps_dec->u1_qp_y_div6,
432*495ae853SAndroid Build Coastguard Worker                                                      pi4_tmp);
433*495ae853SAndroid Build Coastguard Worker                     pi2_coeff_block += 16;
434*495ae853SAndroid Build Coastguard Worker                     ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block;
435*495ae853SAndroid Build Coastguard Worker                     SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0);
436*495ae853SAndroid Build Coastguard Worker                 }
437*495ae853SAndroid Build Coastguard Worker 
438*495ae853SAndroid Build Coastguard Worker             }
439*495ae853SAndroid Build Coastguard Worker         }
440*495ae853SAndroid Build Coastguard Worker     }
441*495ae853SAndroid Build Coastguard Worker 
442*495ae853SAndroid Build Coastguard Worker 
443*495ae853SAndroid Build Coastguard Worker     if(u4_cbp)
444*495ae853SAndroid Build Coastguard Worker     {
445*495ae853SAndroid Build Coastguard Worker 
446*495ae853SAndroid Build Coastguard Worker         ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info,
447*495ae853SAndroid Build Coastguard Worker                                        (UWORD8)u4_offset);
448*495ae853SAndroid Build Coastguard Worker         if(ret != OK)
449*495ae853SAndroid Build Coastguard Worker             return ret;
450*495ae853SAndroid Build Coastguard Worker         if(EXCEED_OFFSET(ps_bitstrm))
451*495ae853SAndroid Build Coastguard Worker             return ERROR_EOB_TERMINATE_T;
452*495ae853SAndroid Build Coastguard Worker 
453*495ae853SAndroid Build Coastguard Worker         /* Store Left Mb NNZ and TOP chroma NNZ */
454*495ae853SAndroid Build Coastguard Worker     }
455*495ae853SAndroid Build Coastguard Worker     else
456*495ae853SAndroid Build Coastguard Worker     {
457*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6;
458*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6;
459*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6;
460*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6;
461*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6;
462*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6;
463*495ae853SAndroid Build Coastguard Worker         ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
464*495ae853SAndroid Build Coastguard Worker     }
465*495ae853SAndroid Build Coastguard Worker 
466*495ae853SAndroid Build Coastguard Worker     return OK;
467*495ae853SAndroid Build Coastguard Worker }
468*495ae853SAndroid Build Coastguard Worker 
469*495ae853SAndroid Build Coastguard Worker /*!
470*495ae853SAndroid Build Coastguard Worker  **************************************************************************
471*495ae853SAndroid Build Coastguard Worker  * \if Function name : ParseIMbCab \endif
472*495ae853SAndroid Build Coastguard Worker  *
473*495ae853SAndroid Build Coastguard Worker  * \brief
474*495ae853SAndroid Build Coastguard Worker  *    This function parses CABAC syntax of a I MB. If 16x16 Luma DC transform
475*495ae853SAndroid Build Coastguard Worker  *    is also done here. Transformed Luma DC values are copied in their
476*495ae853SAndroid Build Coastguard Worker  *    0th pixel location of corrosponding CoeffBlock.
477*495ae853SAndroid Build Coastguard Worker  *
478*495ae853SAndroid Build Coastguard Worker  * \return
479*495ae853SAndroid Build Coastguard Worker  *    0 on Success and Error code otherwise
480*495ae853SAndroid Build Coastguard Worker  **************************************************************************
481*495ae853SAndroid Build Coastguard Worker  */
ih264d_parse_imb_cabac(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mb_type)482*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_imb_cabac(dec_struct_t * ps_dec,
483*495ae853SAndroid Build Coastguard Worker                               dec_mb_info_t * ps_cur_mb_info,
484*495ae853SAndroid Build Coastguard Worker                               UWORD8 u1_mb_type)
485*495ae853SAndroid Build Coastguard Worker {
486*495ae853SAndroid Build Coastguard Worker     WORD8 i1_delta_qp;
487*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_cbp;
488*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_offset;
489*495ae853SAndroid Build Coastguard Worker     /* Variables for handling Cabac contexts */
490*495ae853SAndroid Build Coastguard Worker     ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
491*495ae853SAndroid Build Coastguard Worker     ctxt_inc_mb_info_t *ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
492*495ae853SAndroid Build Coastguard Worker     dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
493*495ae853SAndroid Build Coastguard Worker     bin_ctxt_model_t *p_bin_ctxt;
494*495ae853SAndroid Build Coastguard Worker 
495*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_intra_chrom_pred_mode;
496*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_dc_block_flag = 0;
497*495ae853SAndroid Build Coastguard Worker     WORD32 ret;
498*495ae853SAndroid Build Coastguard Worker 
499*495ae853SAndroid Build Coastguard Worker     ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
500*495ae853SAndroid Build Coastguard Worker 
501*495ae853SAndroid Build Coastguard Worker     if(ps_left_ctxt == ps_dec->ps_def_ctxt_mb_info)
502*495ae853SAndroid Build Coastguard Worker     {
503*495ae853SAndroid Build Coastguard Worker         ps_dec->pu1_left_yuv_dc_csbp[0] = 0xf;
504*495ae853SAndroid Build Coastguard Worker     }
505*495ae853SAndroid Build Coastguard Worker 
506*495ae853SAndroid Build Coastguard Worker     if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE)
507*495ae853SAndroid Build Coastguard Worker     {
508*495ae853SAndroid Build Coastguard Worker         WORD32 *pi4_buf;
509*495ae853SAndroid Build Coastguard Worker         WORD8 *pi1_buf;
510*495ae853SAndroid Build Coastguard Worker         MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
511*495ae853SAndroid Build Coastguard Worker         *((UWORD32 *)ps_dec->pi1_left_ref_idx_ctxt_inc) = 0;
512*495ae853SAndroid Build Coastguard Worker         MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
513*495ae853SAndroid Build Coastguard Worker         memset(p_curr_ctxt->i1_ref_idx, 0, 4);
514*495ae853SAndroid Build Coastguard Worker     }
515*495ae853SAndroid Build Coastguard Worker 
516*495ae853SAndroid Build Coastguard Worker     if(u1_mb_type == I_4x4_MB)
517*495ae853SAndroid Build Coastguard Worker     {
518*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
519*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_mb_type = CAB_I4x4;
520*495ae853SAndroid Build Coastguard Worker         u1_offset = 0;
521*495ae853SAndroid Build Coastguard Worker 
522*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_tran_form8x8 = 0;
523*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
524*495ae853SAndroid Build Coastguard Worker 
525*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
526*495ae853SAndroid Build Coastguard Worker         /* Read transform_size_8x8_flag if present                            */
527*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
528*495ae853SAndroid Build Coastguard Worker         if(ps_dec->s_high_profile.u1_transform8x8_present)
529*495ae853SAndroid Build Coastguard Worker         {
530*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac(
531*495ae853SAndroid Build Coastguard Worker                             ps_dec, ps_cur_mb_info);
532*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
533*495ae853SAndroid Build Coastguard Worker             p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8;
534*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
535*495ae853SAndroid Build Coastguard Worker         }
536*495ae853SAndroid Build Coastguard Worker         else
537*495ae853SAndroid Build Coastguard Worker         {
538*495ae853SAndroid Build Coastguard Worker             p_curr_ctxt->u1_transform8x8_ctxt = 0;
539*495ae853SAndroid Build Coastguard Worker         }
540*495ae853SAndroid Build Coastguard Worker 
541*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
542*495ae853SAndroid Build Coastguard Worker         /* Read the IntraPrediction modes for LUMA                            */
543*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
544*495ae853SAndroid Build Coastguard Worker         if (!ps_cur_mb_info->u1_tran_form8x8)
545*495ae853SAndroid Build Coastguard Worker         {
546*495ae853SAndroid Build Coastguard Worker             UWORD8 *pu1_temp;
547*495ae853SAndroid Build Coastguard Worker             ih264d_read_intra_pred_modes_cabac(
548*495ae853SAndroid Build Coastguard Worker                             ps_dec,
549*495ae853SAndroid Build Coastguard Worker                             ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
550*495ae853SAndroid Build Coastguard Worker                             ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16),
551*495ae853SAndroid Build Coastguard Worker                             ps_cur_mb_info->u1_tran_form8x8);
552*495ae853SAndroid Build Coastguard Worker             pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
553*495ae853SAndroid Build Coastguard Worker             pu1_temp += 32;
554*495ae853SAndroid Build Coastguard Worker             ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
555*495ae853SAndroid Build Coastguard Worker         }
556*495ae853SAndroid Build Coastguard Worker         else
557*495ae853SAndroid Build Coastguard Worker         {
558*495ae853SAndroid Build Coastguard Worker             UWORD8 *pu1_temp;
559*495ae853SAndroid Build Coastguard Worker             ih264d_read_intra_pred_modes_cabac(
560*495ae853SAndroid Build Coastguard Worker                             ps_dec,
561*495ae853SAndroid Build Coastguard Worker                             ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
562*495ae853SAndroid Build Coastguard Worker                             ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4),
563*495ae853SAndroid Build Coastguard Worker                             ps_cur_mb_info->u1_tran_form8x8);
564*495ae853SAndroid Build Coastguard Worker             pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
565*495ae853SAndroid Build Coastguard Worker             pu1_temp += 8;
566*495ae853SAndroid Build Coastguard Worker             ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
567*495ae853SAndroid Build Coastguard Worker         }
568*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
569*495ae853SAndroid Build Coastguard Worker         /* Read the IntraPrediction mode for CHROMA                           */
570*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
571*495ae853SAndroid Build Coastguard Worker         u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec);
572*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("intra_chroma_pred_mode", u1_intra_chrom_pred_mode);
573*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode =
574*495ae853SAndroid Build Coastguard Worker                         u1_intra_chrom_pred_mode;
575*495ae853SAndroid Build Coastguard Worker 
576*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
577*495ae853SAndroid Build Coastguard Worker         /* Read the Coded block pattern                                       */
578*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
579*495ae853SAndroid Build Coastguard Worker         u1_cbp = ih264d_parse_ctx_cbp_cabac(ps_dec);
580*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("coded_block_pattern", u1_cbp);
581*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_cbp = u1_cbp;
582*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_cbp = u1_cbp;
583*495ae853SAndroid Build Coastguard Worker 
584*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
585*495ae853SAndroid Build Coastguard Worker         /* Read mb_qp_delta                                                   */
586*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
587*495ae853SAndroid Build Coastguard Worker         if(ps_cur_mb_info->u1_cbp)
588*495ae853SAndroid Build Coastguard Worker         {
589*495ae853SAndroid Build Coastguard Worker             ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp);
590*495ae853SAndroid Build Coastguard Worker             if(ret != OK)
591*495ae853SAndroid Build Coastguard Worker                 return ret;
592*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
593*495ae853SAndroid Build Coastguard Worker             if(i1_delta_qp != 0)
594*495ae853SAndroid Build Coastguard Worker             {
595*495ae853SAndroid Build Coastguard Worker                 ret = ih264d_update_qp(ps_dec, i1_delta_qp);
596*495ae853SAndroid Build Coastguard Worker                 if(ret != OK)
597*495ae853SAndroid Build Coastguard Worker                     return ret;
598*495ae853SAndroid Build Coastguard Worker             }
599*495ae853SAndroid Build Coastguard Worker         }
600*495ae853SAndroid Build Coastguard Worker         else
601*495ae853SAndroid Build Coastguard Worker             ps_dec->i1_prev_mb_qp_delta = 0;
602*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
603*495ae853SAndroid Build Coastguard Worker     }
604*495ae853SAndroid Build Coastguard Worker     else
605*495ae853SAndroid Build Coastguard Worker     {
606*495ae853SAndroid Build Coastguard Worker         u1_offset = 1;
607*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
608*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_mb_type = CAB_I16x16;
609*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_tran_form8x8 = 0;
610*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_transform8x8_ctxt = 0;
611*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
612*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
613*495ae853SAndroid Build Coastguard Worker         /* Read the IntraPrediction mode for CHROMA                           */
614*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
615*495ae853SAndroid Build Coastguard Worker         u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec);
616*495ae853SAndroid Build Coastguard Worker         if(u1_intra_chrom_pred_mode > 3)
617*495ae853SAndroid Build Coastguard Worker             return ERROR_CHROMA_PRED_MODE;
618*495ae853SAndroid Build Coastguard Worker 
619*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("Chroma intra_chroma_pred_mode pred mode", u1_intra_chrom_pred_mode);
620*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode =
621*495ae853SAndroid Build Coastguard Worker                         u1_intra_chrom_pred_mode;
622*495ae853SAndroid Build Coastguard Worker 
623*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
624*495ae853SAndroid Build Coastguard Worker         /* Read the Coded block pattern                                       */
625*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
626*495ae853SAndroid Build Coastguard Worker         u1_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2];
627*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_cbp = u1_cbp;
628*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_cbp = u1_cbp;
629*495ae853SAndroid Build Coastguard Worker 
630*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
631*495ae853SAndroid Build Coastguard Worker         /* Read mb_qp_delta                                                   */
632*495ae853SAndroid Build Coastguard Worker         /*--------------------------------------------------------------------*/
633*495ae853SAndroid Build Coastguard Worker         ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp);
634*495ae853SAndroid Build Coastguard Worker         if(ret != OK)
635*495ae853SAndroid Build Coastguard Worker             return ret;
636*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
637*495ae853SAndroid Build Coastguard Worker         if(i1_delta_qp != 0)
638*495ae853SAndroid Build Coastguard Worker         {
639*495ae853SAndroid Build Coastguard Worker             ret = ih264d_update_qp(ps_dec, i1_delta_qp);
640*495ae853SAndroid Build Coastguard Worker             if(ret != OK)
641*495ae853SAndroid Build Coastguard Worker                 return ret;
642*495ae853SAndroid Build Coastguard Worker         }
643*495ae853SAndroid Build Coastguard Worker 
644*495ae853SAndroid Build Coastguard Worker         {
645*495ae853SAndroid Build Coastguard Worker             WORD16 i_scaleFactor;
646*495ae853SAndroid Build Coastguard Worker             WORD16* pi2_scale_matrix_ptr;
647*495ae853SAndroid Build Coastguard Worker             /*******************************************************************/
648*495ae853SAndroid Build Coastguard Worker             /* for luma DC coefficients the scaling is done during the parsing */
649*495ae853SAndroid Build Coastguard Worker             /* to preserve the precision                                       */
650*495ae853SAndroid Build Coastguard Worker             /*******************************************************************/
651*495ae853SAndroid Build Coastguard Worker             if(ps_dec->s_high_profile.u1_scaling_present)
652*495ae853SAndroid Build Coastguard Worker             {
653*495ae853SAndroid Build Coastguard Worker                 pi2_scale_matrix_ptr =
654*495ae853SAndroid Build Coastguard Worker                                 ps_dec->s_high_profile.i2_scalinglist4x4[0];
655*495ae853SAndroid Build Coastguard Worker 
656*495ae853SAndroid Build Coastguard Worker             }
657*495ae853SAndroid Build Coastguard Worker             else
658*495ae853SAndroid Build Coastguard Worker             {
659*495ae853SAndroid Build Coastguard Worker                 i_scaleFactor = 16;
660*495ae853SAndroid Build Coastguard Worker                 pi2_scale_matrix_ptr = &i_scaleFactor;
661*495ae853SAndroid Build Coastguard Worker             }
662*495ae853SAndroid Build Coastguard Worker             {
663*495ae853SAndroid Build Coastguard Worker                 ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
664*495ae853SAndroid Build Coastguard Worker                 UWORD8 uc_a, uc_b;
665*495ae853SAndroid Build Coastguard Worker                 UWORD32 u4_ctx_inc;
666*495ae853SAndroid Build Coastguard Worker 
667*495ae853SAndroid Build Coastguard Worker                 INC_SYM_COUNT(&(ps_dec->s_cab_dec_env));
668*495ae853SAndroid Build Coastguard Worker 
669*495ae853SAndroid Build Coastguard Worker                 /* if MbAddrN not available then CondTermN = 1 */
670*495ae853SAndroid Build Coastguard Worker                 uc_b = ((ps_top_ctxt->u1_yuv_dc_csbp) & 0x01);
671*495ae853SAndroid Build Coastguard Worker 
672*495ae853SAndroid Build Coastguard Worker                 /* if MbAddrN not available then CondTermN = 1 */
673*495ae853SAndroid Build Coastguard Worker                 uc_a = ((ps_dec->pu1_left_yuv_dc_csbp[0]) & 0x01);
674*495ae853SAndroid Build Coastguard Worker 
675*495ae853SAndroid Build Coastguard Worker                 u4_ctx_inc = (uc_a + (uc_b << 1));
676*495ae853SAndroid Build Coastguard Worker 
677*495ae853SAndroid Build Coastguard Worker                 {
678*495ae853SAndroid Build Coastguard Worker                     WORD16 pi2_dc_coef[16];
679*495ae853SAndroid Build Coastguard Worker                     tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
680*495ae853SAndroid Build Coastguard Worker                                     (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
681*495ae853SAndroid Build Coastguard Worker                     WORD16 *pi2_coeff_block =
682*495ae853SAndroid Build Coastguard Worker                                     (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
683*495ae853SAndroid Build Coastguard Worker 
684*495ae853SAndroid Build Coastguard Worker                     p_bin_ctxt = (ps_dec->p_cbf_t[LUMA_DC_CTXCAT]) + u4_ctx_inc;
685*495ae853SAndroid Build Coastguard Worker 
686*495ae853SAndroid Build Coastguard Worker                     u1_dc_block_flag =
687*495ae853SAndroid Build Coastguard Worker                                     ih264d_read_coeff4x4_cabac(ps_bitstrm,
688*495ae853SAndroid Build Coastguard Worker                                                     LUMA_DC_CTXCAT,
689*495ae853SAndroid Build Coastguard Worker                                                     ps_dec->p_significant_coeff_flag_t[LUMA_DC_CTXCAT],
690*495ae853SAndroid Build Coastguard Worker                                                     ps_dec, p_bin_ctxt);
691*495ae853SAndroid Build Coastguard Worker 
692*495ae853SAndroid Build Coastguard Worker                     /* Store coded_block_flag */
693*495ae853SAndroid Build Coastguard Worker                     p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
694*495ae853SAndroid Build Coastguard Worker                     p_curr_ctxt->u1_yuv_dc_csbp |= u1_dc_block_flag;
695*495ae853SAndroid Build Coastguard Worker                     if(u1_dc_block_flag)
696*495ae853SAndroid Build Coastguard Worker                     {
697*495ae853SAndroid Build Coastguard Worker                         WORD32 pi4_tmp[16];
698*495ae853SAndroid Build Coastguard Worker                         memset(pi2_dc_coef,0,sizeof(pi2_dc_coef));
699*495ae853SAndroid Build Coastguard Worker                         ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
700*495ae853SAndroid Build Coastguard Worker                                                          pi2_dc_coef,
701*495ae853SAndroid Build Coastguard Worker                                                          ps_dec->pu1_inv_scan);
702*495ae853SAndroid Build Coastguard Worker 
703*495ae853SAndroid Build Coastguard Worker                         PROFILE_DISABLE_IQ_IT_RECON()
704*495ae853SAndroid Build Coastguard Worker                         ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef,
705*495ae853SAndroid Build Coastguard Worker                                                          pi2_coeff_block,
706*495ae853SAndroid Build Coastguard Worker                                                          ps_dec->pu2_quant_scale_y,
707*495ae853SAndroid Build Coastguard Worker                                                          (UWORD16 *)pi2_scale_matrix_ptr,
708*495ae853SAndroid Build Coastguard Worker                                                          ps_dec->u1_qp_y_div6,
709*495ae853SAndroid Build Coastguard Worker                                                          pi4_tmp);
710*495ae853SAndroid Build Coastguard Worker                         pi2_coeff_block += 16;
711*495ae853SAndroid Build Coastguard Worker                         ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block;
712*495ae853SAndroid Build Coastguard Worker                         SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0);
713*495ae853SAndroid Build Coastguard Worker                     }
714*495ae853SAndroid Build Coastguard Worker 
715*495ae853SAndroid Build Coastguard Worker                 }
716*495ae853SAndroid Build Coastguard Worker 
717*495ae853SAndroid Build Coastguard Worker             }
718*495ae853SAndroid Build Coastguard Worker         }
719*495ae853SAndroid Build Coastguard Worker     }
720*495ae853SAndroid Build Coastguard Worker 
721*495ae853SAndroid Build Coastguard Worker     ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6;
722*495ae853SAndroid Build Coastguard Worker     ps_dec->pu1_left_yuv_dc_csbp[0] |= u1_dc_block_flag;
723*495ae853SAndroid Build Coastguard Worker 
724*495ae853SAndroid Build Coastguard Worker     ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, u1_offset);
725*495ae853SAndroid Build Coastguard Worker     if(EXCEED_OFFSET(ps_bitstrm))
726*495ae853SAndroid Build Coastguard Worker         return ERROR_EOB_TERMINATE_T;
727*495ae853SAndroid Build Coastguard Worker     return OK;
728*495ae853SAndroid Build Coastguard Worker }
729*495ae853SAndroid Build Coastguard Worker 
730*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
731*495ae853SAndroid Build Coastguard Worker /*                                                                           */
732*495ae853SAndroid Build Coastguard Worker /*  Function Name : ih264d_parse_islice_data_cavlc                                  */
733*495ae853SAndroid Build Coastguard Worker /*                                                                           */
734*495ae853SAndroid Build Coastguard Worker /*  Description   : This function parses cabac syntax of a inter slice on    */
735*495ae853SAndroid Build Coastguard Worker /*                  N MB basis.                                              */
736*495ae853SAndroid Build Coastguard Worker /*                                                                           */
737*495ae853SAndroid Build Coastguard Worker /*  Inputs        : ps_dec                                                   */
738*495ae853SAndroid Build Coastguard Worker /*                  sliceparams                                              */
739*495ae853SAndroid Build Coastguard Worker /*                  firstMbInSlice                                           */
740*495ae853SAndroid Build Coastguard Worker /*                                                                           */
741*495ae853SAndroid Build Coastguard Worker /*  Processing    : 1. After parsing syntax for N MBs those N MBs are        */
742*495ae853SAndroid Build Coastguard Worker /*                     decoded till the end of slice.                        */
743*495ae853SAndroid Build Coastguard Worker /*                                                                           */
744*495ae853SAndroid Build Coastguard Worker /*  Returns       : 0                                                        */
745*495ae853SAndroid Build Coastguard Worker /*                                                                           */
746*495ae853SAndroid Build Coastguard Worker /*  Issues        : <List any issues or problems with this function>         */
747*495ae853SAndroid Build Coastguard Worker /*                                                                           */
748*495ae853SAndroid Build Coastguard Worker /*  Revision History:                                                        */
749*495ae853SAndroid Build Coastguard Worker /*                                                                           */
750*495ae853SAndroid Build Coastguard Worker /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
751*495ae853SAndroid Build Coastguard Worker /*         24 06 2005   ARNY            Draft                                */
752*495ae853SAndroid Build Coastguard Worker /*                                                                           */
753*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
ih264d_parse_islice_data_cavlc(dec_struct_t * ps_dec,dec_slice_params_t * ps_slice,UWORD16 u2_first_mb_in_slice)754*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_islice_data_cavlc(dec_struct_t * ps_dec,
755*495ae853SAndroid Build Coastguard Worker                                       dec_slice_params_t * ps_slice,
756*495ae853SAndroid Build Coastguard Worker                                       UWORD16 u2_first_mb_in_slice)
757*495ae853SAndroid Build Coastguard Worker {
758*495ae853SAndroid Build Coastguard Worker     UWORD8 uc_more_data_flag;
759*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_num_mbs, u1_mb_idx;
760*495ae853SAndroid Build Coastguard Worker     dec_mb_info_t *ps_cur_mb_info;
761*495ae853SAndroid Build Coastguard Worker     deblk_mb_t *ps_cur_deblk_mb;
762*495ae853SAndroid Build Coastguard Worker     dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
763*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
764*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
765*495ae853SAndroid Build Coastguard Worker     UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
766*495ae853SAndroid Build Coastguard Worker     WORD16 i2_cur_mb_addr;
767*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_mbaff;
768*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_num_mbs_next, u1_end_of_row, u1_tfr_n_mb;
769*495ae853SAndroid Build Coastguard Worker     WORD32 ret = OK;
770*495ae853SAndroid Build Coastguard Worker 
771*495ae853SAndroid Build Coastguard Worker     ps_dec->u1_qp = ps_slice->u1_slice_qp;
772*495ae853SAndroid Build Coastguard Worker     ih264d_update_qp(ps_dec, 0);
773*495ae853SAndroid Build Coastguard Worker     u1_mbaff = ps_slice->u1_mbaff_frame_flag;
774*495ae853SAndroid Build Coastguard Worker 
775*495ae853SAndroid Build Coastguard Worker     /* initializations */
776*495ae853SAndroid Build Coastguard Worker     u1_mb_idx = ps_dec->u1_mb_idx;
777*495ae853SAndroid Build Coastguard Worker     u1_num_mbs = u1_mb_idx;
778*495ae853SAndroid Build Coastguard Worker 
779*495ae853SAndroid Build Coastguard Worker     uc_more_data_flag = 1;
780*495ae853SAndroid Build Coastguard Worker     i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
781*495ae853SAndroid Build Coastguard Worker 
782*495ae853SAndroid Build Coastguard Worker     do
783*495ae853SAndroid Build Coastguard Worker     {
784*495ae853SAndroid Build Coastguard Worker         UWORD8 u1_mb_type;
785*495ae853SAndroid Build Coastguard Worker 
786*495ae853SAndroid Build Coastguard Worker         ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
787*495ae853SAndroid Build Coastguard Worker 
788*495ae853SAndroid Build Coastguard Worker         if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
789*495ae853SAndroid Build Coastguard Worker         {
790*495ae853SAndroid Build Coastguard Worker             break;
791*495ae853SAndroid Build Coastguard Worker         }
792*495ae853SAndroid Build Coastguard Worker 
793*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
794*495ae853SAndroid Build Coastguard Worker         ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
795*495ae853SAndroid Build Coastguard Worker         ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
796*495ae853SAndroid Build Coastguard Worker 
797*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_end_of_slice = 0;
798*495ae853SAndroid Build Coastguard Worker 
799*495ae853SAndroid Build Coastguard Worker         /***************************************************************/
800*495ae853SAndroid Build Coastguard Worker         /* Get the required information for decoding of MB             */
801*495ae853SAndroid Build Coastguard Worker         /* mb_x, mb_y , neighbour availablity,                         */
802*495ae853SAndroid Build Coastguard Worker         /***************************************************************/
803*495ae853SAndroid Build Coastguard Worker         ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 0);
804*495ae853SAndroid Build Coastguard Worker 
805*495ae853SAndroid Build Coastguard Worker         /***************************************************************/
806*495ae853SAndroid Build Coastguard Worker         /* Set the deblocking parameters for this MB                   */
807*495ae853SAndroid Build Coastguard Worker         /***************************************************************/
808*495ae853SAndroid Build Coastguard Worker         ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
809*495ae853SAndroid Build Coastguard Worker 
810*495ae853SAndroid Build Coastguard Worker         if(ps_dec->u4_app_disable_deblk_frm == 0)
811*495ae853SAndroid Build Coastguard Worker             ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
812*495ae853SAndroid Build Coastguard Worker                                              ps_dec->u1_mb_ngbr_availablity,
813*495ae853SAndroid Build Coastguard Worker                                              ps_dec->u1_cur_mb_fld_dec_flag);
814*495ae853SAndroid Build Coastguard Worker 
815*495ae853SAndroid Build Coastguard Worker         ps_cur_deblk_mb->u1_mb_type = ps_cur_deblk_mb->u1_mb_type | D_INTRA_MB;
816*495ae853SAndroid Build Coastguard Worker 
817*495ae853SAndroid Build Coastguard Worker         /**************************************************************/
818*495ae853SAndroid Build Coastguard Worker         /* Macroblock Layer Begins, Decode the u1_mb_type                */
819*495ae853SAndroid Build Coastguard Worker         /**************************************************************/
820*495ae853SAndroid Build Coastguard Worker //Inlined ih264d_uev
821*495ae853SAndroid Build Coastguard Worker         {
822*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
823*495ae853SAndroid Build Coastguard Worker             UWORD32 u4_word, u4_ldz, u4_temp;
824*495ae853SAndroid Build Coastguard Worker 
825*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
826*495ae853SAndroid Build Coastguard Worker             /* Find leading zeros in next 32 bits                          */
827*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
828*495ae853SAndroid Build Coastguard Worker             NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
829*495ae853SAndroid Build Coastguard Worker             u4_ldz = CLZ(u4_word);
830*495ae853SAndroid Build Coastguard Worker             /* Flush the ps_bitstrm */
831*495ae853SAndroid Build Coastguard Worker             u4_bitstream_offset += (u4_ldz + 1);
832*495ae853SAndroid Build Coastguard Worker             /* Read the suffix from the ps_bitstrm */
833*495ae853SAndroid Build Coastguard Worker             u4_word = 0;
834*495ae853SAndroid Build Coastguard Worker             if(u4_ldz)
835*495ae853SAndroid Build Coastguard Worker                 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
836*495ae853SAndroid Build Coastguard Worker                         u4_ldz);
837*495ae853SAndroid Build Coastguard Worker             *pu4_bitstrm_ofst = u4_bitstream_offset;
838*495ae853SAndroid Build Coastguard Worker             u4_temp = ((1 << u4_ldz) + u4_word - 1);
839*495ae853SAndroid Build Coastguard Worker             if(u4_temp > 25)
840*495ae853SAndroid Build Coastguard Worker                 return ERROR_MB_TYPE;
841*495ae853SAndroid Build Coastguard Worker             u1_mb_type = u4_temp;
842*495ae853SAndroid Build Coastguard Worker 
843*495ae853SAndroid Build Coastguard Worker         }
844*495ae853SAndroid Build Coastguard Worker //Inlined ih264d_uev
845*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_mb_type = u1_mb_type;
846*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("u1_mb_type", u1_mb_type);
847*495ae853SAndroid Build Coastguard Worker 
848*495ae853SAndroid Build Coastguard Worker         /**************************************************************/
849*495ae853SAndroid Build Coastguard Worker         /* Parse Macroblock data                                      */
850*495ae853SAndroid Build Coastguard Worker         /**************************************************************/
851*495ae853SAndroid Build Coastguard Worker         if(25 == u1_mb_type)
852*495ae853SAndroid Build Coastguard Worker         {
853*495ae853SAndroid Build Coastguard Worker             /* I_PCM_MB */
854*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
855*495ae853SAndroid Build Coastguard Worker             ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
856*495ae853SAndroid Build Coastguard Worker             if(ret != OK)
857*495ae853SAndroid Build Coastguard Worker                 return ret;
858*495ae853SAndroid Build Coastguard Worker             ps_cur_deblk_mb->u1_mb_qp = 0;
859*495ae853SAndroid Build Coastguard Worker         }
860*495ae853SAndroid Build Coastguard Worker         else
861*495ae853SAndroid Build Coastguard Worker         {
862*495ae853SAndroid Build Coastguard Worker             ret = ih264d_parse_imb_cavlc(ps_dec, ps_cur_mb_info, u1_num_mbs, u1_mb_type);
863*495ae853SAndroid Build Coastguard Worker             if(ret != OK)
864*495ae853SAndroid Build Coastguard Worker                 return ret;
865*495ae853SAndroid Build Coastguard Worker             ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
866*495ae853SAndroid Build Coastguard Worker         }
867*495ae853SAndroid Build Coastguard Worker 
868*495ae853SAndroid Build Coastguard Worker         if(ps_dec->u1_enable_mb_info)
869*495ae853SAndroid Build Coastguard Worker         {
870*495ae853SAndroid Build Coastguard Worker             ih264d_populate_mb_info_map(ps_dec, ps_cur_mb_info, ps_cur_mb_info->u2_mbx << 1,
871*495ae853SAndroid Build Coastguard Worker                                         ps_cur_mb_info->u2_mby << 1, ps_cur_deblk_mb->u1_mb_qp);
872*495ae853SAndroid Build Coastguard Worker         }
873*495ae853SAndroid Build Coastguard Worker 
874*495ae853SAndroid Build Coastguard Worker         uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
875*495ae853SAndroid Build Coastguard Worker 
876*495ae853SAndroid Build Coastguard Worker         if(u1_mbaff)
877*495ae853SAndroid Build Coastguard Worker         {
878*495ae853SAndroid Build Coastguard Worker             ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
879*495ae853SAndroid Build Coastguard Worker             if(!uc_more_data_flag && (0 == (i2_cur_mb_addr & 1)))
880*495ae853SAndroid Build Coastguard Worker             {
881*495ae853SAndroid Build Coastguard Worker                 return ERROR_EOB_FLUSHBITS_T;
882*495ae853SAndroid Build Coastguard Worker             }
883*495ae853SAndroid Build Coastguard Worker         }
884*495ae853SAndroid Build Coastguard Worker         /**************************************************************/
885*495ae853SAndroid Build Coastguard Worker         /* Get next Macroblock address                                */
886*495ae853SAndroid Build Coastguard Worker         /**************************************************************/
887*495ae853SAndroid Build Coastguard Worker 
888*495ae853SAndroid Build Coastguard Worker         i2_cur_mb_addr++;
889*495ae853SAndroid Build Coastguard Worker 
890*495ae853SAndroid Build Coastguard Worker 
891*495ae853SAndroid Build Coastguard Worker         /* Store the colocated information */
892*495ae853SAndroid Build Coastguard Worker         {
893*495ae853SAndroid Build Coastguard Worker             mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_num_mbs << 4);
894*495ae853SAndroid Build Coastguard Worker 
895*495ae853SAndroid Build Coastguard Worker             mv_pred_t s_mvPred =
896*495ae853SAndroid Build Coastguard Worker                 {
897*495ae853SAndroid Build Coastguard Worker                     { 0, 0, 0, 0 },
898*495ae853SAndroid Build Coastguard Worker                       { -1, -1 }, 0, 0};
899*495ae853SAndroid Build Coastguard Worker             ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
900*495ae853SAndroid Build Coastguard Worker                                (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1), 4,
901*495ae853SAndroid Build Coastguard Worker                                4);
902*495ae853SAndroid Build Coastguard Worker         }
903*495ae853SAndroid Build Coastguard Worker 
904*495ae853SAndroid Build Coastguard Worker         /*if num _cores is set to 3,compute bs will be done in another thread*/
905*495ae853SAndroid Build Coastguard Worker         if(ps_dec->u4_num_cores < 3)
906*495ae853SAndroid Build Coastguard Worker         {
907*495ae853SAndroid Build Coastguard Worker             if(ps_dec->u4_app_disable_deblk_frm == 0)
908*495ae853SAndroid Build Coastguard Worker                 ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
909*495ae853SAndroid Build Coastguard Worker                                      (UWORD16)(u1_num_mbs >> u1_mbaff));
910*495ae853SAndroid Build Coastguard Worker         }
911*495ae853SAndroid Build Coastguard Worker         u1_num_mbs++;
912*495ae853SAndroid Build Coastguard Worker 
913*495ae853SAndroid Build Coastguard Worker         /****************************************************************/
914*495ae853SAndroid Build Coastguard Worker         /* Check for End Of Row                                         */
915*495ae853SAndroid Build Coastguard Worker         /****************************************************************/
916*495ae853SAndroid Build Coastguard Worker         u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
917*495ae853SAndroid Build Coastguard Worker         u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
918*495ae853SAndroid Build Coastguard Worker         u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
919*495ae853SAndroid Build Coastguard Worker                         || (!uc_more_data_flag);
920*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_end_of_slice = (!uc_more_data_flag);
921*495ae853SAndroid Build Coastguard Worker 
922*495ae853SAndroid Build Coastguard Worker         /*H264_DEC_DEBUG_PRINT("Pic: %d Mb_X=%d Mb_Y=%d",
923*495ae853SAndroid Build Coastguard Worker          ps_slice->i4_poc >> ps_slice->u1_field_pic_flag,
924*495ae853SAndroid Build Coastguard Worker          ps_dec->u2_mbx,ps_dec->u2_mby + (1 - ps_cur_mb_info->u1_topmb));
925*495ae853SAndroid Build Coastguard Worker          H264_DEC_DEBUG_PRINT("u1_tfr_n_mb || (!uc_more_data_flag): %d", u1_tfr_n_mb || (!uc_more_data_flag));*/
926*495ae853SAndroid Build Coastguard Worker         if(u1_tfr_n_mb || (!uc_more_data_flag))
927*495ae853SAndroid Build Coastguard Worker         {
928*495ae853SAndroid Build Coastguard Worker 
929*495ae853SAndroid Build Coastguard Worker             if(ps_dec->u1_separate_parse)
930*495ae853SAndroid Build Coastguard Worker             {
931*495ae853SAndroid Build Coastguard Worker                 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
932*495ae853SAndroid Build Coastguard Worker                                      u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
933*495ae853SAndroid Build Coastguard Worker                 ps_dec->ps_nmb_info +=  u1_num_mbs;
934*495ae853SAndroid Build Coastguard Worker             }
935*495ae853SAndroid Build Coastguard Worker             else
936*495ae853SAndroid Build Coastguard Worker             {
937*495ae853SAndroid Build Coastguard Worker                 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
938*495ae853SAndroid Build Coastguard Worker                                             u1_num_mbs_next, u1_tfr_n_mb,
939*495ae853SAndroid Build Coastguard Worker                                             u1_end_of_row);
940*495ae853SAndroid Build Coastguard Worker             }
941*495ae853SAndroid Build Coastguard Worker             ps_dec->u2_total_mbs_coded += u1_num_mbs;
942*495ae853SAndroid Build Coastguard Worker             if(u1_tfr_n_mb)
943*495ae853SAndroid Build Coastguard Worker                 u1_num_mbs = 0;
944*495ae853SAndroid Build Coastguard Worker             u1_mb_idx = u1_num_mbs;
945*495ae853SAndroid Build Coastguard Worker             ps_dec->u1_mb_idx = u1_num_mbs;
946*495ae853SAndroid Build Coastguard Worker 
947*495ae853SAndroid Build Coastguard Worker         }
948*495ae853SAndroid Build Coastguard Worker     }
949*495ae853SAndroid Build Coastguard Worker     while(uc_more_data_flag);
950*495ae853SAndroid Build Coastguard Worker 
951*495ae853SAndroid Build Coastguard Worker     ps_dec->u4_num_mbs_cur_nmb = 0;
952*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
953*495ae853SAndroid Build Coastguard Worker 
954*495ae853SAndroid Build Coastguard Worker                         - (u2_first_mb_in_slice << u1_mbaff);
955*495ae853SAndroid Build Coastguard Worker 
956*495ae853SAndroid Build Coastguard Worker     return ret;
957*495ae853SAndroid Build Coastguard Worker }
958*495ae853SAndroid Build Coastguard Worker 
959*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
960*495ae853SAndroid Build Coastguard Worker /*                                                                           */
961*495ae853SAndroid Build Coastguard Worker /*  Function Name : ih264d_parse_islice_data_cabac                                  */
962*495ae853SAndroid Build Coastguard Worker /*                                                                           */
963*495ae853SAndroid Build Coastguard Worker /*  Description   : This function parses cabac syntax of a inter slice on    */
964*495ae853SAndroid Build Coastguard Worker /*                  N MB basis.                                              */
965*495ae853SAndroid Build Coastguard Worker /*                                                                           */
966*495ae853SAndroid Build Coastguard Worker /*  Inputs        : ps_dec                                                   */
967*495ae853SAndroid Build Coastguard Worker /*                  sliceparams                                              */
968*495ae853SAndroid Build Coastguard Worker /*                  firstMbInSlice                                           */
969*495ae853SAndroid Build Coastguard Worker /*                                                                           */
970*495ae853SAndroid Build Coastguard Worker /*  Processing    : 1. After parsing syntax for N MBs those N MBs are        */
971*495ae853SAndroid Build Coastguard Worker /*                     decoded till the end of slice.                        */
972*495ae853SAndroid Build Coastguard Worker /*                                                                           */
973*495ae853SAndroid Build Coastguard Worker /*  Returns       : 0                                                        */
974*495ae853SAndroid Build Coastguard Worker /*                                                                           */
975*495ae853SAndroid Build Coastguard Worker /*  Issues        : <List any issues or problems with this function>         */
976*495ae853SAndroid Build Coastguard Worker /*                                                                           */
977*495ae853SAndroid Build Coastguard Worker /*  Revision History:                                                        */
978*495ae853SAndroid Build Coastguard Worker /*                                                                           */
979*495ae853SAndroid Build Coastguard Worker /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
980*495ae853SAndroid Build Coastguard Worker /*         24 06 2005   ARNY            Draft                                */
981*495ae853SAndroid Build Coastguard Worker /*                                                                           */
982*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
ih264d_parse_islice_data_cabac(dec_struct_t * ps_dec,dec_slice_params_t * ps_slice,UWORD16 u2_first_mb_in_slice)983*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_islice_data_cabac(dec_struct_t * ps_dec,
984*495ae853SAndroid Build Coastguard Worker                                       dec_slice_params_t * ps_slice,
985*495ae853SAndroid Build Coastguard Worker                                       UWORD16 u2_first_mb_in_slice)
986*495ae853SAndroid Build Coastguard Worker {
987*495ae853SAndroid Build Coastguard Worker     UWORD8 uc_more_data_flag;
988*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_num_mbs, u1_mb_idx;
989*495ae853SAndroid Build Coastguard Worker     dec_mb_info_t *ps_cur_mb_info;
990*495ae853SAndroid Build Coastguard Worker     deblk_mb_t *ps_cur_deblk_mb;
991*495ae853SAndroid Build Coastguard Worker 
992*495ae853SAndroid Build Coastguard Worker     dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
993*495ae853SAndroid Build Coastguard Worker     UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
994*495ae853SAndroid Build Coastguard Worker     WORD16 i2_cur_mb_addr;
995*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_mbaff;
996*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_num_mbs_next, u1_end_of_row, u1_tfr_n_mb;
997*495ae853SAndroid Build Coastguard Worker     WORD32 ret = OK;
998*495ae853SAndroid Build Coastguard Worker 
999*495ae853SAndroid Build Coastguard Worker     ps_dec->u1_qp = ps_slice->u1_slice_qp;
1000*495ae853SAndroid Build Coastguard Worker     ih264d_update_qp(ps_dec, 0);
1001*495ae853SAndroid Build Coastguard Worker     u1_mbaff = ps_slice->u1_mbaff_frame_flag;
1002*495ae853SAndroid Build Coastguard Worker 
1003*495ae853SAndroid Build Coastguard Worker     if(ps_bitstrm->u4_ofst & 0x07)
1004*495ae853SAndroid Build Coastguard Worker     {
1005*495ae853SAndroid Build Coastguard Worker         ps_bitstrm->u4_ofst += 8;
1006*495ae853SAndroid Build Coastguard Worker         ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
1007*495ae853SAndroid Build Coastguard Worker     }
1008*495ae853SAndroid Build Coastguard Worker     ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
1009*495ae853SAndroid Build Coastguard Worker     if(ret != OK)
1010*495ae853SAndroid Build Coastguard Worker         return ret;
1011*495ae853SAndroid Build Coastguard Worker     ih264d_init_cabac_contexts(I_SLICE, ps_dec);
1012*495ae853SAndroid Build Coastguard Worker 
1013*495ae853SAndroid Build Coastguard Worker     ps_dec->i1_prev_mb_qp_delta = 0;
1014*495ae853SAndroid Build Coastguard Worker 
1015*495ae853SAndroid Build Coastguard Worker     /* initializations */
1016*495ae853SAndroid Build Coastguard Worker     u1_mb_idx = ps_dec->u1_mb_idx;
1017*495ae853SAndroid Build Coastguard Worker     u1_num_mbs = u1_mb_idx;
1018*495ae853SAndroid Build Coastguard Worker 
1019*495ae853SAndroid Build Coastguard Worker     uc_more_data_flag = 1;
1020*495ae853SAndroid Build Coastguard Worker     i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
1021*495ae853SAndroid Build Coastguard Worker     do
1022*495ae853SAndroid Build Coastguard Worker     {
1023*495ae853SAndroid Build Coastguard Worker         UWORD16 u2_mbx;
1024*495ae853SAndroid Build Coastguard Worker 
1025*495ae853SAndroid Build Coastguard Worker         ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1026*495ae853SAndroid Build Coastguard Worker 
1027*495ae853SAndroid Build Coastguard Worker         if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
1028*495ae853SAndroid Build Coastguard Worker         {
1029*495ae853SAndroid Build Coastguard Worker             break;
1030*495ae853SAndroid Build Coastguard Worker         }
1031*495ae853SAndroid Build Coastguard Worker 
1032*495ae853SAndroid Build Coastguard Worker         {
1033*495ae853SAndroid Build Coastguard Worker             UWORD8 u1_mb_type;
1034*495ae853SAndroid Build Coastguard Worker 
1035*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
1036*495ae853SAndroid Build Coastguard Worker             ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
1037*495ae853SAndroid Build Coastguard Worker             ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
1038*495ae853SAndroid Build Coastguard Worker 
1039*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->u1_end_of_slice = 0;
1040*495ae853SAndroid Build Coastguard Worker 
1041*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
1042*495ae853SAndroid Build Coastguard Worker             /* Get the required information for decoding of MB                  */
1043*495ae853SAndroid Build Coastguard Worker             /* mb_x, mb_y , neighbour availablity,                              */
1044*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
1045*495ae853SAndroid Build Coastguard Worker             ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 0);
1046*495ae853SAndroid Build Coastguard Worker             u2_mbx = ps_dec->u2_mbx;
1047*495ae853SAndroid Build Coastguard Worker 
1048*495ae853SAndroid Build Coastguard Worker             /*********************************************************************/
1049*495ae853SAndroid Build Coastguard Worker             /* initialize u1_tran_form8x8 to zero to aviod uninitialized accesses */
1050*495ae853SAndroid Build Coastguard Worker             /*********************************************************************/
1051*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->u1_tran_form8x8 = 0;
1052*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
1053*495ae853SAndroid Build Coastguard Worker 
1054*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
1055*495ae853SAndroid Build Coastguard Worker             /* Set the deblocking parameters for this MB                   */
1056*495ae853SAndroid Build Coastguard Worker             /***************************************************************/
1057*495ae853SAndroid Build Coastguard Worker             ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
1058*495ae853SAndroid Build Coastguard Worker             if(ps_dec->u4_app_disable_deblk_frm == 0)
1059*495ae853SAndroid Build Coastguard Worker                 ih264d_set_deblocking_parameters(
1060*495ae853SAndroid Build Coastguard Worker                                 ps_cur_deblk_mb, ps_slice,
1061*495ae853SAndroid Build Coastguard Worker                                 ps_dec->u1_mb_ngbr_availablity,
1062*495ae853SAndroid Build Coastguard Worker                                 ps_dec->u1_cur_mb_fld_dec_flag);
1063*495ae853SAndroid Build Coastguard Worker 
1064*495ae853SAndroid Build Coastguard Worker             ps_cur_deblk_mb->u1_mb_type = ps_cur_deblk_mb->u1_mb_type
1065*495ae853SAndroid Build Coastguard Worker                             | D_INTRA_MB;
1066*495ae853SAndroid Build Coastguard Worker 
1067*495ae853SAndroid Build Coastguard Worker             /* Macroblock Layer Begins */
1068*495ae853SAndroid Build Coastguard Worker             /* Decode the u1_mb_type */
1069*495ae853SAndroid Build Coastguard Worker             u1_mb_type = ih264d_parse_mb_type_intra_cabac(0, ps_dec);
1070*495ae853SAndroid Build Coastguard Worker             if(u1_mb_type > 25)
1071*495ae853SAndroid Build Coastguard Worker                 return ERROR_MB_TYPE;
1072*495ae853SAndroid Build Coastguard Worker             ps_cur_mb_info->u1_mb_type = u1_mb_type;
1073*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("u1_mb_type", u1_mb_type);
1074*495ae853SAndroid Build Coastguard Worker 
1075*495ae853SAndroid Build Coastguard Worker             /* Parse Macroblock Data */
1076*495ae853SAndroid Build Coastguard Worker             if(25 == u1_mb_type)
1077*495ae853SAndroid Build Coastguard Worker             {
1078*495ae853SAndroid Build Coastguard Worker                 /* I_PCM_MB */
1079*495ae853SAndroid Build Coastguard Worker                 ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
1080*495ae853SAndroid Build Coastguard Worker                 ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
1081*495ae853SAndroid Build Coastguard Worker                 if(ret != OK)
1082*495ae853SAndroid Build Coastguard Worker                     return ret;
1083*495ae853SAndroid Build Coastguard Worker                 ps_cur_deblk_mb->u1_mb_qp = 0;
1084*495ae853SAndroid Build Coastguard Worker             }
1085*495ae853SAndroid Build Coastguard Worker             else
1086*495ae853SAndroid Build Coastguard Worker             {
1087*495ae853SAndroid Build Coastguard Worker                 ret = ih264d_parse_imb_cabac(ps_dec, ps_cur_mb_info, u1_mb_type);
1088*495ae853SAndroid Build Coastguard Worker                 if(ret != OK)
1089*495ae853SAndroid Build Coastguard Worker                     return ret;
1090*495ae853SAndroid Build Coastguard Worker                 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
1091*495ae853SAndroid Build Coastguard Worker             }
1092*495ae853SAndroid Build Coastguard Worker 
1093*495ae853SAndroid Build Coastguard Worker             if(ps_dec->u1_enable_mb_info)
1094*495ae853SAndroid Build Coastguard Worker             {
1095*495ae853SAndroid Build Coastguard Worker                 ih264d_populate_mb_info_map(ps_dec, ps_cur_mb_info, ps_cur_mb_info->u2_mbx << 1,
1096*495ae853SAndroid Build Coastguard Worker                                             ps_cur_mb_info->u2_mby << 1, ps_cur_deblk_mb->u1_mb_qp);
1097*495ae853SAndroid Build Coastguard Worker             }
1098*495ae853SAndroid Build Coastguard Worker 
1099*495ae853SAndroid Build Coastguard Worker             if(u1_mbaff)
1100*495ae853SAndroid Build Coastguard Worker             {
1101*495ae853SAndroid Build Coastguard Worker                 ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1102*495ae853SAndroid Build Coastguard Worker             }
1103*495ae853SAndroid Build Coastguard Worker 
1104*495ae853SAndroid Build Coastguard Worker 
1105*495ae853SAndroid Build Coastguard Worker             if(ps_cur_mb_info->u1_topmb && u1_mbaff)
1106*495ae853SAndroid Build Coastguard Worker                 uc_more_data_flag = 1;
1107*495ae853SAndroid Build Coastguard Worker             else
1108*495ae853SAndroid Build Coastguard Worker             {
1109*495ae853SAndroid Build Coastguard Worker                 uc_more_data_flag = ih264d_decode_terminate(&ps_dec->s_cab_dec_env,
1110*495ae853SAndroid Build Coastguard Worker                                                           ps_bitstrm);
1111*495ae853SAndroid Build Coastguard Worker                 uc_more_data_flag = !uc_more_data_flag;
1112*495ae853SAndroid Build Coastguard Worker                 COPYTHECONTEXT("Decode Sliceterm",!uc_more_data_flag);
1113*495ae853SAndroid Build Coastguard Worker             }
1114*495ae853SAndroid Build Coastguard Worker 
1115*495ae853SAndroid Build Coastguard Worker             if(u1_mbaff)
1116*495ae853SAndroid Build Coastguard Worker             {
1117*495ae853SAndroid Build Coastguard Worker                 if(!uc_more_data_flag && (0 == (i2_cur_mb_addr & 1)))
1118*495ae853SAndroid Build Coastguard Worker                 {
1119*495ae853SAndroid Build Coastguard Worker                     return ERROR_EOB_FLUSHBITS_T;
1120*495ae853SAndroid Build Coastguard Worker                 }
1121*495ae853SAndroid Build Coastguard Worker             }
1122*495ae853SAndroid Build Coastguard Worker             /* Next macroblock information */
1123*495ae853SAndroid Build Coastguard Worker             i2_cur_mb_addr++;
1124*495ae853SAndroid Build Coastguard Worker             /* Store the colocated information */
1125*495ae853SAndroid Build Coastguard Worker             {
1126*495ae853SAndroid Build Coastguard Worker 
1127*495ae853SAndroid Build Coastguard Worker                 mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_num_mbs << 4);
1128*495ae853SAndroid Build Coastguard Worker                 mv_pred_t s_mvPred =
1129*495ae853SAndroid Build Coastguard Worker                     {
1130*495ae853SAndroid Build Coastguard Worker                         { 0, 0, 0, 0 },
1131*495ae853SAndroid Build Coastguard Worker                           { -1, -1 }, 0, 0};
1132*495ae853SAndroid Build Coastguard Worker                 ih264d_rep_mv_colz(
1133*495ae853SAndroid Build Coastguard Worker                                 ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
1134*495ae853SAndroid Build Coastguard Worker                                 (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1),
1135*495ae853SAndroid Build Coastguard Worker                                 4, 4);
1136*495ae853SAndroid Build Coastguard Worker             }
1137*495ae853SAndroid Build Coastguard Worker             /*if num _cores is set to 3,compute bs will be done in another thread*/
1138*495ae853SAndroid Build Coastguard Worker             if(ps_dec->u4_num_cores < 3)
1139*495ae853SAndroid Build Coastguard Worker             {
1140*495ae853SAndroid Build Coastguard Worker                 if(ps_dec->u4_app_disable_deblk_frm == 0)
1141*495ae853SAndroid Build Coastguard Worker                     ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
1142*495ae853SAndroid Build Coastguard Worker                                          (UWORD16)(u1_num_mbs >> u1_mbaff));
1143*495ae853SAndroid Build Coastguard Worker             }
1144*495ae853SAndroid Build Coastguard Worker             u1_num_mbs++;
1145*495ae853SAndroid Build Coastguard Worker 
1146*495ae853SAndroid Build Coastguard Worker         }
1147*495ae853SAndroid Build Coastguard Worker 
1148*495ae853SAndroid Build Coastguard Worker         /****************************************************************/
1149*495ae853SAndroid Build Coastguard Worker         /* Check for End Of Row                                         */
1150*495ae853SAndroid Build Coastguard Worker         /****************************************************************/
1151*495ae853SAndroid Build Coastguard Worker         u1_num_mbs_next = i2_pic_wdin_mbs - u2_mbx - 1;
1152*495ae853SAndroid Build Coastguard Worker         u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1153*495ae853SAndroid Build Coastguard Worker         u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1154*495ae853SAndroid Build Coastguard Worker                         || (!uc_more_data_flag);
1155*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->u1_end_of_slice = (!uc_more_data_flag);
1156*495ae853SAndroid Build Coastguard Worker 
1157*495ae853SAndroid Build Coastguard Worker         if(u1_tfr_n_mb || (!uc_more_data_flag))
1158*495ae853SAndroid Build Coastguard Worker         {
1159*495ae853SAndroid Build Coastguard Worker 
1160*495ae853SAndroid Build Coastguard Worker 
1161*495ae853SAndroid Build Coastguard Worker             if(ps_dec->u1_separate_parse)
1162*495ae853SAndroid Build Coastguard Worker             {
1163*495ae853SAndroid Build Coastguard Worker                 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1164*495ae853SAndroid Build Coastguard Worker                                      u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1165*495ae853SAndroid Build Coastguard Worker                 ps_dec->ps_nmb_info +=  u1_num_mbs;
1166*495ae853SAndroid Build Coastguard Worker             }
1167*495ae853SAndroid Build Coastguard Worker             else
1168*495ae853SAndroid Build Coastguard Worker             {
1169*495ae853SAndroid Build Coastguard Worker                 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1170*495ae853SAndroid Build Coastguard Worker                                             u1_num_mbs_next, u1_tfr_n_mb,
1171*495ae853SAndroid Build Coastguard Worker                                             u1_end_of_row);
1172*495ae853SAndroid Build Coastguard Worker             }
1173*495ae853SAndroid Build Coastguard Worker             ps_dec->u2_total_mbs_coded += u1_num_mbs;
1174*495ae853SAndroid Build Coastguard Worker             if(u1_tfr_n_mb)
1175*495ae853SAndroid Build Coastguard Worker                 u1_num_mbs = 0;
1176*495ae853SAndroid Build Coastguard Worker             u1_mb_idx = u1_num_mbs;
1177*495ae853SAndroid Build Coastguard Worker             ps_dec->u1_mb_idx = u1_num_mbs;
1178*495ae853SAndroid Build Coastguard Worker 
1179*495ae853SAndroid Build Coastguard Worker         }
1180*495ae853SAndroid Build Coastguard Worker     }
1181*495ae853SAndroid Build Coastguard Worker     while(uc_more_data_flag);
1182*495ae853SAndroid Build Coastguard Worker 
1183*495ae853SAndroid Build Coastguard Worker     ps_dec->u4_num_mbs_cur_nmb = 0;
1184*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
1185*495ae853SAndroid Build Coastguard Worker 
1186*495ae853SAndroid Build Coastguard Worker                         - (u2_first_mb_in_slice << u1_mbaff);
1187*495ae853SAndroid Build Coastguard Worker 
1188*495ae853SAndroid Build Coastguard Worker     return ret;
1189*495ae853SAndroid Build Coastguard Worker }
1190*495ae853SAndroid Build Coastguard Worker 
1191*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
1192*495ae853SAndroid Build Coastguard Worker /*                                                                           */
1193*495ae853SAndroid Build Coastguard Worker /*  Function Name : ih264d_parse_ipcm_mb                                       */
1194*495ae853SAndroid Build Coastguard Worker /*                                                                           */
1195*495ae853SAndroid Build Coastguard Worker /*  Description   : This function decodes the pixel values of I_PCM Mb.      */
1196*495ae853SAndroid Build Coastguard Worker /*                                                                           */
1197*495ae853SAndroid Build Coastguard Worker /*  Inputs        : ps_dec,  ps_cur_mb_info and mb number                          */
1198*495ae853SAndroid Build Coastguard Worker /*                                                                           */
1199*495ae853SAndroid Build Coastguard Worker /*  Description   : This function reads the luma and chroma pixels directly  */
1200*495ae853SAndroid Build Coastguard Worker /*                  from the bitstream when the mbtype is I_PCM and stores   */
1201*495ae853SAndroid Build Coastguard Worker /*                  them in recon buffer. If the entropy coding mode is      */
1202*495ae853SAndroid Build Coastguard Worker /*                  cabac, decoding engine is re-initialized. The nnzs and   */
1203*495ae853SAndroid Build Coastguard Worker /*                  cabac contexts are appropriately modified.               */
1204*495ae853SAndroid Build Coastguard Worker /*  Returns       : void                                                     */
1205*495ae853SAndroid Build Coastguard Worker /*                                                                           */
1206*495ae853SAndroid Build Coastguard Worker /*  Revision History:                                                        */
1207*495ae853SAndroid Build Coastguard Worker /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1208*495ae853SAndroid Build Coastguard Worker /*         13 07 2002   Jay                                                  */
1209*495ae853SAndroid Build Coastguard Worker /*                                                                           */
1210*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
1211*495ae853SAndroid Build Coastguard Worker 
ih264d_parse_ipcm_mb(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mbNum)1212*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_ipcm_mb(dec_struct_t * ps_dec,
1213*495ae853SAndroid Build Coastguard Worker                           dec_mb_info_t *ps_cur_mb_info,
1214*495ae853SAndroid Build Coastguard Worker                           UWORD8 u1_mbNum)
1215*495ae853SAndroid Build Coastguard Worker {
1216*495ae853SAndroid Build Coastguard Worker     dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1217*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1218*495ae853SAndroid Build Coastguard Worker     UWORD8 *pu1_y, *pu1_u, *pu1_v;
1219*495ae853SAndroid Build Coastguard Worker     WORD32 ret;
1220*495ae853SAndroid Build Coastguard Worker 
1221*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_rec_width_y, u4_rec_width_uv;
1222*495ae853SAndroid Build Coastguard Worker     UWORD32 u1_num_mb_pair;
1223*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_x, u1_y;
1224*495ae853SAndroid Build Coastguard Worker     /* CHANGED CODE */
1225*495ae853SAndroid Build Coastguard Worker     tfr_ctxt_t *ps_frame_buf;
1226*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_mb_field_decoding_flag;
1227*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_buf;
1228*495ae853SAndroid Build Coastguard Worker     UWORD8 *pu1_buf;
1229*495ae853SAndroid Build Coastguard Worker     /* CHANGED CODE */
1230*495ae853SAndroid Build Coastguard Worker 
1231*495ae853SAndroid Build Coastguard Worker     if(ps_dec->u1_separate_parse)
1232*495ae853SAndroid Build Coastguard Worker     {
1233*495ae853SAndroid Build Coastguard Worker         ps_frame_buf = &ps_dec->s_tran_addrecon_parse;
1234*495ae853SAndroid Build Coastguard Worker     }
1235*495ae853SAndroid Build Coastguard Worker     else
1236*495ae853SAndroid Build Coastguard Worker     {
1237*495ae853SAndroid Build Coastguard Worker         ps_frame_buf = &ps_dec->s_tran_addrecon;
1238*495ae853SAndroid Build Coastguard Worker     }
1239*495ae853SAndroid Build Coastguard Worker     /* align bistream to byte boundary. */
1240*495ae853SAndroid Build Coastguard Worker     /* pcm_alignment_zero_bit discarded */
1241*495ae853SAndroid Build Coastguard Worker     /* For XX GotoByteBoundary */
1242*495ae853SAndroid Build Coastguard Worker     if(ps_bitstrm->u4_ofst & 0x07)
1243*495ae853SAndroid Build Coastguard Worker     {
1244*495ae853SAndroid Build Coastguard Worker         ps_bitstrm->u4_ofst += 8;
1245*495ae853SAndroid Build Coastguard Worker         ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
1246*495ae853SAndroid Build Coastguard Worker     }
1247*495ae853SAndroid Build Coastguard Worker 
1248*495ae853SAndroid Build Coastguard Worker     /*  Store left Nnz as 16 for each 4x4 blk */
1249*495ae853SAndroid Build Coastguard Worker 
1250*495ae853SAndroid Build Coastguard Worker     pu1_buf = ps_dec->pu1_left_nnz_y;
1251*495ae853SAndroid Build Coastguard Worker     pu4_buf = (UWORD32 *)pu1_buf;
1252*495ae853SAndroid Build Coastguard Worker     *pu4_buf = 0x10101010;
1253*495ae853SAndroid Build Coastguard Worker     pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1254*495ae853SAndroid Build Coastguard Worker     pu4_buf = (UWORD32 *)pu1_buf;
1255*495ae853SAndroid Build Coastguard Worker     *pu4_buf = 0x10101010;
1256*495ae853SAndroid Build Coastguard Worker     pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1257*495ae853SAndroid Build Coastguard Worker     pu4_buf = (UWORD32 *)pu1_buf;
1258*495ae853SAndroid Build Coastguard Worker     *pu4_buf = 0x10101010;
1259*495ae853SAndroid Build Coastguard Worker     pu1_buf = ps_dec->pu1_left_nnz_uv;
1260*495ae853SAndroid Build Coastguard Worker     pu4_buf = (UWORD32 *)pu1_buf;
1261*495ae853SAndroid Build Coastguard Worker     *pu4_buf = 0x10101010;
1262*495ae853SAndroid Build Coastguard Worker     ps_cur_mb_info->u1_cbp = 0xff;
1263*495ae853SAndroid Build Coastguard Worker 
1264*495ae853SAndroid Build Coastguard Worker     ps_dec->i1_prev_mb_qp_delta = 0;
1265*495ae853SAndroid Build Coastguard Worker     /* Get neighbour MB's */
1266*495ae853SAndroid Build Coastguard Worker     u1_num_mb_pair = (u1_mbNum >> u1_mbaff);
1267*495ae853SAndroid Build Coastguard Worker 
1268*495ae853SAndroid Build Coastguard Worker     /*****************************************************************************/
1269*495ae853SAndroid Build Coastguard Worker     /* calculate the RECON buffer YUV pointers for the PCM data                  */
1270*495ae853SAndroid Build Coastguard Worker     /*****************************************************************************/
1271*495ae853SAndroid Build Coastguard Worker     /* CHANGED CODE  */
1272*495ae853SAndroid Build Coastguard Worker     u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
1273*495ae853SAndroid Build Coastguard Worker     pu1_y = ps_frame_buf->pu1_dest_y + (u1_num_mb_pair << 4);
1274*495ae853SAndroid Build Coastguard Worker     pu1_u = ps_frame_buf->pu1_dest_u + (u1_num_mb_pair << 4);
1275*495ae853SAndroid Build Coastguard Worker     pu1_v = pu1_u + 1;
1276*495ae853SAndroid Build Coastguard Worker 
1277*495ae853SAndroid Build Coastguard Worker     u4_rec_width_y = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
1278*495ae853SAndroid Build Coastguard Worker     u4_rec_width_uv = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
1279*495ae853SAndroid Build Coastguard Worker     /* CHANGED CODE  */
1280*495ae853SAndroid Build Coastguard Worker 
1281*495ae853SAndroid Build Coastguard Worker     if(u1_mbaff)
1282*495ae853SAndroid Build Coastguard Worker     {
1283*495ae853SAndroid Build Coastguard Worker         UWORD8 u1_top_mb;
1284*495ae853SAndroid Build Coastguard Worker 
1285*495ae853SAndroid Build Coastguard Worker         u1_top_mb = ps_cur_mb_info->u1_topmb;
1286*495ae853SAndroid Build Coastguard Worker 
1287*495ae853SAndroid Build Coastguard Worker         if(u1_top_mb == 0)
1288*495ae853SAndroid Build Coastguard Worker         {
1289*495ae853SAndroid Build Coastguard Worker             pu1_y += (u1_mb_field_decoding_flag ?
1290*495ae853SAndroid Build Coastguard Worker                             (u4_rec_width_y >> 1) : (u4_rec_width_y << 4));
1291*495ae853SAndroid Build Coastguard Worker             pu1_u += (u1_mb_field_decoding_flag ?
1292*495ae853SAndroid Build Coastguard Worker                             (u4_rec_width_uv) : (u4_rec_width_uv << 4));
1293*495ae853SAndroid Build Coastguard Worker             pu1_v = pu1_u + 1;
1294*495ae853SAndroid Build Coastguard Worker         }
1295*495ae853SAndroid Build Coastguard Worker     }
1296*495ae853SAndroid Build Coastguard Worker 
1297*495ae853SAndroid Build Coastguard Worker     /* Read Luma samples */
1298*495ae853SAndroid Build Coastguard Worker     for(u1_y = 0; u1_y < 16; u1_y++)
1299*495ae853SAndroid Build Coastguard Worker     {
1300*495ae853SAndroid Build Coastguard Worker         for(u1_x = 0; u1_x < 16; u1_x++)
1301*495ae853SAndroid Build Coastguard Worker             pu1_y[u1_x] = ih264d_get_bits_h264(ps_bitstrm, 8);
1302*495ae853SAndroid Build Coastguard Worker 
1303*495ae853SAndroid Build Coastguard Worker         pu1_y += u4_rec_width_y;
1304*495ae853SAndroid Build Coastguard Worker     }
1305*495ae853SAndroid Build Coastguard Worker 
1306*495ae853SAndroid Build Coastguard Worker     /* Read Chroma samples */
1307*495ae853SAndroid Build Coastguard Worker     for(u1_y = 0; u1_y < 8; u1_y++)
1308*495ae853SAndroid Build Coastguard Worker     {
1309*495ae853SAndroid Build Coastguard Worker         for(u1_x = 0; u1_x < 8; u1_x++)
1310*495ae853SAndroid Build Coastguard Worker             pu1_u[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8);
1311*495ae853SAndroid Build Coastguard Worker 
1312*495ae853SAndroid Build Coastguard Worker         pu1_u += u4_rec_width_uv;
1313*495ae853SAndroid Build Coastguard Worker     }
1314*495ae853SAndroid Build Coastguard Worker 
1315*495ae853SAndroid Build Coastguard Worker     for(u1_y = 0; u1_y < 8; u1_y++)
1316*495ae853SAndroid Build Coastguard Worker     {
1317*495ae853SAndroid Build Coastguard Worker         for(u1_x = 0; u1_x < 8; u1_x++)
1318*495ae853SAndroid Build Coastguard Worker             pu1_v[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8);
1319*495ae853SAndroid Build Coastguard Worker 
1320*495ae853SAndroid Build Coastguard Worker         pu1_v += u4_rec_width_uv;
1321*495ae853SAndroid Build Coastguard Worker     }
1322*495ae853SAndroid Build Coastguard Worker 
1323*495ae853SAndroid Build Coastguard Worker     if(CABAC == ps_dec->ps_cur_pps->u1_entropy_coding_mode)
1324*495ae853SAndroid Build Coastguard Worker     {
1325*495ae853SAndroid Build Coastguard Worker         UWORD32 *pu4_buf;
1326*495ae853SAndroid Build Coastguard Worker         UWORD8 *pu1_buf;
1327*495ae853SAndroid Build Coastguard Worker         ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
1328*495ae853SAndroid Build Coastguard Worker         /* Re-initialize the cabac decoding engine. */
1329*495ae853SAndroid Build Coastguard Worker         ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
1330*495ae853SAndroid Build Coastguard Worker         if(ret != OK)
1331*495ae853SAndroid Build Coastguard Worker             return ret;
1332*495ae853SAndroid Build Coastguard Worker         /* update the cabac contetxs */
1333*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_mb_type = CAB_I_PCM;
1334*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_cbp = 47;
1335*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_intra_chroma_pred_mode = 0;
1336*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_transform8x8_ctxt = 0;
1337*495ae853SAndroid Build Coastguard Worker         ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
1338*495ae853SAndroid Build Coastguard Worker 
1339*495ae853SAndroid Build Coastguard Worker         pu1_buf = ps_dec->pu1_left_nnz_y;
1340*495ae853SAndroid Build Coastguard Worker         pu4_buf = (UWORD32 *)pu1_buf;
1341*495ae853SAndroid Build Coastguard Worker         *pu4_buf = 0x01010101;
1342*495ae853SAndroid Build Coastguard Worker 
1343*495ae853SAndroid Build Coastguard Worker         pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1344*495ae853SAndroid Build Coastguard Worker         pu4_buf = (UWORD32 *)pu1_buf;
1345*495ae853SAndroid Build Coastguard Worker         *pu4_buf = 0x01010101;
1346*495ae853SAndroid Build Coastguard Worker 
1347*495ae853SAndroid Build Coastguard Worker         pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1348*495ae853SAndroid Build Coastguard Worker         pu4_buf = (UWORD32 *)pu1_buf;
1349*495ae853SAndroid Build Coastguard Worker         *pu4_buf = 0x01010101;
1350*495ae853SAndroid Build Coastguard Worker 
1351*495ae853SAndroid Build Coastguard Worker         pu1_buf = ps_dec->pu1_left_nnz_uv;
1352*495ae853SAndroid Build Coastguard Worker         pu4_buf = (UWORD32 *)pu1_buf;
1353*495ae853SAndroid Build Coastguard Worker         *pu4_buf = 0x01010101;
1354*495ae853SAndroid Build Coastguard Worker 
1355*495ae853SAndroid Build Coastguard Worker         p_curr_ctxt->u1_yuv_dc_csbp = 0x7;
1356*495ae853SAndroid Build Coastguard Worker         ps_dec->pu1_left_yuv_dc_csbp[0] = 0x7;
1357*495ae853SAndroid Build Coastguard Worker         if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE)
1358*495ae853SAndroid Build Coastguard Worker         {
1359*495ae853SAndroid Build Coastguard Worker 
1360*495ae853SAndroid Build Coastguard Worker             MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
1361*495ae853SAndroid Build Coastguard Worker             memset(ps_dec->pi1_left_ref_idx_ctxt_inc, 0, 4);
1362*495ae853SAndroid Build Coastguard Worker             MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
1363*495ae853SAndroid Build Coastguard Worker             memset(p_curr_ctxt->i1_ref_idx, 0, 4);
1364*495ae853SAndroid Build Coastguard Worker 
1365*495ae853SAndroid Build Coastguard Worker         }
1366*495ae853SAndroid Build Coastguard Worker     }
1367*495ae853SAndroid Build Coastguard Worker     return OK;
1368*495ae853SAndroid Build Coastguard Worker }
1369*495ae853SAndroid Build Coastguard Worker 
1370*495ae853SAndroid Build Coastguard Worker /*!
1371*495ae853SAndroid Build Coastguard Worker  **************************************************************************
1372*495ae853SAndroid Build Coastguard Worker  * \if Function name : ih264d_decode_islice \endif
1373*495ae853SAndroid Build Coastguard Worker  *
1374*495ae853SAndroid Build Coastguard Worker  * \brief
1375*495ae853SAndroid Build Coastguard Worker  *    Decodes an I Slice
1376*495ae853SAndroid Build Coastguard Worker  *
1377*495ae853SAndroid Build Coastguard Worker  *
1378*495ae853SAndroid Build Coastguard Worker  * \return
1379*495ae853SAndroid Build Coastguard Worker  *    0 on Success and Error code otherwise
1380*495ae853SAndroid Build Coastguard Worker  **************************************************************************
1381*495ae853SAndroid Build Coastguard Worker  */
ih264d_parse_islice(dec_struct_t * ps_dec,UWORD16 u2_first_mb_in_slice)1382*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_islice(dec_struct_t *ps_dec,
1383*495ae853SAndroid Build Coastguard Worker                             UWORD16 u2_first_mb_in_slice)
1384*495ae853SAndroid Build Coastguard Worker {
1385*495ae853SAndroid Build Coastguard Worker     dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps;
1386*495ae853SAndroid Build Coastguard Worker     dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
1387*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
1388*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
1389*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_temp;
1390*495ae853SAndroid Build Coastguard Worker     WORD32 i_temp;
1391*495ae853SAndroid Build Coastguard Worker     WORD64 i8_temp;
1392*495ae853SAndroid Build Coastguard Worker     WORD32 ret;
1393*495ae853SAndroid Build Coastguard Worker 
1394*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
1395*495ae853SAndroid Build Coastguard Worker     /* Read remaining contents of the slice header                        */
1396*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
1397*495ae853SAndroid Build Coastguard Worker     /* dec_ref_pic_marking function */
1398*495ae853SAndroid Build Coastguard Worker     /* G050 */
1399*495ae853SAndroid Build Coastguard Worker     if(ps_slice->u1_nal_ref_idc != 0)
1400*495ae853SAndroid Build Coastguard Worker     {
1401*495ae853SAndroid Build Coastguard Worker         if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
1402*495ae853SAndroid Build Coastguard Worker         {
1403*495ae853SAndroid Build Coastguard Worker             i_temp = ih264d_read_mmco_commands(ps_dec);
1404*495ae853SAndroid Build Coastguard Worker             if (i_temp < 0)
1405*495ae853SAndroid Build Coastguard Worker             {
1406*495ae853SAndroid Build Coastguard Worker                 return ERROR_DBP_MANAGER_T;
1407*495ae853SAndroid Build Coastguard Worker             }
1408*495ae853SAndroid Build Coastguard Worker             ps_dec->u4_bitoffset = i_temp;
1409*495ae853SAndroid Build Coastguard Worker         }
1410*495ae853SAndroid Build Coastguard Worker         else
1411*495ae853SAndroid Build Coastguard Worker             ps_dec->ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset;
1412*495ae853SAndroid Build Coastguard Worker     }
1413*495ae853SAndroid Build Coastguard Worker     /* G050 */
1414*495ae853SAndroid Build Coastguard Worker 
1415*495ae853SAndroid Build Coastguard Worker     /* Read slice_qp_delta */
1416*495ae853SAndroid Build Coastguard Worker     i8_temp = (WORD64)ps_pps->u1_pic_init_qp
1417*495ae853SAndroid Build Coastguard Worker                         + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1418*495ae853SAndroid Build Coastguard Worker     if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
1419*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_RANGE_QP_T;
1420*495ae853SAndroid Build Coastguard Worker     ps_slice->u1_slice_qp = i8_temp;
1421*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SH: slice_qp_delta",
1422*495ae853SAndroid Build Coastguard Worker                     ps_slice->u1_slice_qp - ps_pps->u1_pic_init_qp);
1423*495ae853SAndroid Build Coastguard Worker 
1424*495ae853SAndroid Build Coastguard Worker     if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1)
1425*495ae853SAndroid Build Coastguard Worker     {
1426*495ae853SAndroid Build Coastguard Worker         u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1427*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp);
1428*495ae853SAndroid Build Coastguard Worker 
1429*495ae853SAndroid Build Coastguard Worker         if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED)
1430*495ae853SAndroid Build Coastguard Worker         {
1431*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_SLICE_HDR_T;
1432*495ae853SAndroid Build Coastguard Worker         }
1433*495ae853SAndroid Build Coastguard Worker         ps_slice->u1_disable_dblk_filter_idc = u4_temp;
1434*495ae853SAndroid Build Coastguard Worker         if(u4_temp != 1)
1435*495ae853SAndroid Build Coastguard Worker         {
1436*495ae853SAndroid Build Coastguard Worker             i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1437*495ae853SAndroid Build Coastguard Worker                             << 1;
1438*495ae853SAndroid Build Coastguard Worker             if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1439*495ae853SAndroid Build Coastguard Worker             {
1440*495ae853SAndroid Build Coastguard Worker                 return ERROR_INV_SLICE_HDR_T;
1441*495ae853SAndroid Build Coastguard Worker             }
1442*495ae853SAndroid Build Coastguard Worker             ps_slice->i1_slice_alpha_c0_offset = i_temp;
1443*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2",
1444*495ae853SAndroid Build Coastguard Worker                             ps_slice->i1_slice_alpha_c0_offset >> 1);
1445*495ae853SAndroid Build Coastguard Worker 
1446*495ae853SAndroid Build Coastguard Worker             i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1447*495ae853SAndroid Build Coastguard Worker                             << 1;
1448*495ae853SAndroid Build Coastguard Worker             if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1449*495ae853SAndroid Build Coastguard Worker             {
1450*495ae853SAndroid Build Coastguard Worker                 return ERROR_INV_SLICE_HDR_T;
1451*495ae853SAndroid Build Coastguard Worker             }
1452*495ae853SAndroid Build Coastguard Worker             ps_slice->i1_slice_beta_offset = i_temp;
1453*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("SH: slice_beta_offset_div2",
1454*495ae853SAndroid Build Coastguard Worker                             ps_slice->i1_slice_beta_offset >> 1);
1455*495ae853SAndroid Build Coastguard Worker 
1456*495ae853SAndroid Build Coastguard Worker         }
1457*495ae853SAndroid Build Coastguard Worker         else
1458*495ae853SAndroid Build Coastguard Worker         {
1459*495ae853SAndroid Build Coastguard Worker             ps_slice->i1_slice_alpha_c0_offset = 0;
1460*495ae853SAndroid Build Coastguard Worker             ps_slice->i1_slice_beta_offset = 0;
1461*495ae853SAndroid Build Coastguard Worker         }
1462*495ae853SAndroid Build Coastguard Worker     }
1463*495ae853SAndroid Build Coastguard Worker     else
1464*495ae853SAndroid Build Coastguard Worker     {
1465*495ae853SAndroid Build Coastguard Worker         ps_slice->u1_disable_dblk_filter_idc = 0;
1466*495ae853SAndroid Build Coastguard Worker         ps_slice->i1_slice_alpha_c0_offset = 0;
1467*495ae853SAndroid Build Coastguard Worker         ps_slice->i1_slice_beta_offset = 0;
1468*495ae853SAndroid Build Coastguard Worker     }
1469*495ae853SAndroid Build Coastguard Worker 
1470*495ae853SAndroid Build Coastguard Worker     /* Initialization to check if number of motion vector per 2 Mbs */
1471*495ae853SAndroid Build Coastguard Worker     /* are exceeding the range or not */
1472*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_mv_2mb[0] = 0;
1473*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_mv_2mb[1] = 0;
1474*495ae853SAndroid Build Coastguard Worker 
1475*495ae853SAndroid Build Coastguard Worker 
1476*495ae853SAndroid Build Coastguard Worker     /*set slice header cone to 2 ,to indicate  correct header*/
1477*495ae853SAndroid Build Coastguard Worker     ps_dec->u1_slice_header_done = 2;
1478*495ae853SAndroid Build Coastguard Worker 
1479*495ae853SAndroid Build Coastguard Worker     if(ps_pps->u1_entropy_coding_mode)
1480*495ae853SAndroid Build Coastguard Worker     {
1481*495ae853SAndroid Build Coastguard Worker         SWITCHOFFTRACE; SWITCHONTRACECABAC;
1482*495ae853SAndroid Build Coastguard Worker         if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1483*495ae853SAndroid Build Coastguard Worker         {
1484*495ae853SAndroid Build Coastguard Worker             ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff;
1485*495ae853SAndroid Build Coastguard Worker         }
1486*495ae853SAndroid Build Coastguard Worker         else
1487*495ae853SAndroid Build Coastguard Worker             ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff;
1488*495ae853SAndroid Build Coastguard Worker 
1489*495ae853SAndroid Build Coastguard Worker         ret = ih264d_parse_islice_data_cabac(ps_dec, ps_slice,
1490*495ae853SAndroid Build Coastguard Worker                                              u2_first_mb_in_slice);
1491*495ae853SAndroid Build Coastguard Worker         if(ret != OK)
1492*495ae853SAndroid Build Coastguard Worker             return ret;
1493*495ae853SAndroid Build Coastguard Worker         SWITCHONTRACE; SWITCHOFFTRACECABAC;
1494*495ae853SAndroid Build Coastguard Worker     }
1495*495ae853SAndroid Build Coastguard Worker     else
1496*495ae853SAndroid Build Coastguard Worker     {
1497*495ae853SAndroid Build Coastguard Worker         if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1498*495ae853SAndroid Build Coastguard Worker         {
1499*495ae853SAndroid Build Coastguard Worker             ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff;
1500*495ae853SAndroid Build Coastguard Worker         }
1501*495ae853SAndroid Build Coastguard Worker         else
1502*495ae853SAndroid Build Coastguard Worker             ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff;
1503*495ae853SAndroid Build Coastguard Worker         ret = ih264d_parse_islice_data_cavlc(ps_dec, ps_slice,
1504*495ae853SAndroid Build Coastguard Worker                                        u2_first_mb_in_slice);
1505*495ae853SAndroid Build Coastguard Worker         if(ret != OK)
1506*495ae853SAndroid Build Coastguard Worker             return ret;
1507*495ae853SAndroid Build Coastguard Worker     }
1508*495ae853SAndroid Build Coastguard Worker 
1509*495ae853SAndroid Build Coastguard Worker     return OK;
1510*495ae853SAndroid Build Coastguard Worker }
1511