• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2022 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19  */
20 /**
21  *******************************************************************************
22  * @file
23  *  isvcd_process_epslice.c
24  *
25  * @brief
26  *  Contains routines that decode a I slice type
27  *
28  * @author
29  *  Kishore
30  *
31  * @remarks
32  *  None
33  *
34  *******************************************************************************
35  */
36 
37 #include <assert.h>
38 #include <string.h>
39 
40 #include "ih264_typedefs.h"
41 #include "ih264_macros.h"
42 #include "ih264_platform_macros.h"
43 #include "ih264d_bitstrm.h"
44 #include "ih264d_defs.h"
45 #include "ih264d_debug.h"
46 #include "isvcd_structs.h"
47 #include "ih264d_defs.h"
48 #include "ih264d_parse_cavlc.h"
49 #include "ih264d_mb_utils.h"
50 #include "ih264d_deblocking.h"
51 #include "ih264d_dpb_manager.h"
52 #include "ih264d_mvpred.h"
53 #include "ih264d_inter_pred.h"
54 #include "ih264d_process_pslice.h"
55 #include "isvcd_process_epslice.h"
56 #include "ih264d_error_handler.h"
57 #include "ih264d_cabac.h"
58 #include "ih264d_debug.h"
59 #include "ih264d_tables.h"
60 #include "ih264d_parse_slice.h"
61 #include "ih264d_utils.h"
62 #include "ih264d_parse_islice.h"
63 #include "ih264d_process_bslice.h"
64 #include "ih264d_process_intra_mb.h"
65 #include "isvcd_mode_mv_resamp.h"
66 #include "ih264_debug.h"
67 
68 /*!
69  **************************************************************************
70  * \if Function name : isvcd_retrive_infer_mode_mv \endif
71  *
72  * \brief
73  *
74  * \return
75  *    0 on Success and Error code otherwise
76  **************************************************************************
77  */
isvcd_retrive_infer_mode_mv(svc_dec_lyr_struct_t * ps_svc_lyr_dec,mv_pred_t * ps_mvpred,UWORD8 u1_lx,UWORD8 u1_sub_mb_num)78 void isvcd_retrive_infer_mode_mv(svc_dec_lyr_struct_t *ps_svc_lyr_dec, mv_pred_t *ps_mvpred,
79                                  UWORD8 u1_lx, UWORD8 u1_sub_mb_num)
80 {
81     mode_motion_ctxt_t *ps_ctxt;
82     mv_pred_t *ps_motion_pred;
83     UWORD8 u1_tmp_lx = (u1_lx << 1);
84 
85     ps_ctxt = (mode_motion_ctxt_t *) ps_svc_lyr_dec->pv_mode_mv_sample_ctxt;
86     ps_motion_pred = ps_ctxt->ps_motion_pred_struct;
87     ps_motion_pred += u1_sub_mb_num;
88     ps_mvpred->i2_mv[u1_tmp_lx] = ps_motion_pred->i2_mv[u1_tmp_lx];
89     ps_mvpred->i2_mv[u1_tmp_lx + 1] = ps_motion_pred->i2_mv[u1_tmp_lx + 1];
90 
91     return;
92 }
93 /*!
94  **************************************************************************
95  * \if Function name : isvcd_interlyr_motion_mode_pred \endif
96  *
97  * \brief
98  *
99  *
100  * \return
101  *    0 on Success and Error code otherwise
102  **************************************************************************
103  */
isvcd_interlyr_motion_mode_pred(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info,dec_svc_mb_info_t * ps_svc_cur_mb_info,parse_pmbarams_t * ps_mb_part_info,parse_part_params_t * ps_part)104 WORD32 isvcd_interlyr_motion_mode_pred(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
105                                        dec_mb_info_t *ps_cur_mb_info,
106                                        dec_svc_mb_info_t *ps_svc_cur_mb_info,
107                                        parse_pmbarams_t *ps_mb_part_info,
108                                        parse_part_params_t *ps_part)
109 {
110     dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
111     WORD32 i4_inter_layer_pred_req_flag;
112     WORD32 i4_listx;
113     WORD32 i4_mb_mode = -1;
114     i4_inter_layer_pred_req_flag = SVCD_FALSE;
115     i4_listx = (ps_dec->ps_cur_slice->u1_slice_type == B_SLICE) ? 2 : 1;
116     /* check Base mode flag and motion predcition flags */
117     if(1 == ps_svc_cur_mb_info->u1_base_mode_flag)
118     {
119         i4_inter_layer_pred_req_flag = SVCD_TRUE;
120     }
121     else
122     {
123         UWORD8 u1_mot_pred_flag;
124 
125         /* get the packed the motion pred flag of list 0 */
126         u1_mot_pred_flag = ps_svc_cur_mb_info->au1_motion_pred_flag[0];
127 
128         /* extract the last 4 bits */
129         u1_mot_pred_flag &= 0x0F;
130 
131         if(0 != u1_mot_pred_flag)
132         {
133             i4_inter_layer_pred_req_flag = SVCD_TRUE;
134         }
135 
136         /* check for list 1 flags if required */
137         if((2 == i4_listx) && (SVCD_FALSE == i4_inter_layer_pred_req_flag))
138         {
139             /* get the packed the motion pred flag of list 1 */
140             u1_mot_pred_flag = ps_svc_cur_mb_info->au1_motion_pred_flag[1];
141 
142             /* extract the last 4 bits */
143             u1_mot_pred_flag &= 0x0F;
144 
145             if(0 != u1_mot_pred_flag)
146             {
147                 i4_inter_layer_pred_req_flag = SVCD_TRUE;
148             }
149         }
150     }
151 
152     if(SVCD_TRUE == i4_inter_layer_pred_req_flag)
153     {
154         mode_motion_ctxt_t *ps_ctxt;
155         mode_motion_lyr_ctxt *ps_lyr_mem;
156 
157         ps_ctxt = (mode_motion_ctxt_t *) ps_svc_lyr_dec->pv_mode_mv_sample_ctxt;
158         /* get the current layer ctxt */
159         ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
160 
161         ps_ctxt->i4_listx = i4_listx;
162 
163         i4_mb_mode =
164             ps_lyr_mem->pf_inter_lyr_pred(ps_svc_lyr_dec->pv_mode_mv_sample_ctxt, ps_cur_mb_info,
165                                           ps_svc_cur_mb_info, ps_dec, ps_mb_part_info, ps_part);
166     }
167     return i4_mb_mode;
168 }
169 /*!
170  **************************************************************************
171  * \if Function name : isvcd_mv_pred_ref_tfr_nby2_epmb \endif
172  *
173  * \brief
174  *
175  * \return
176  *    0 on Success and Error code otherwise
177  **************************************************************************
178  */
isvcd_mv_pred_ref_tfr_nby2_epmb(dec_struct_t * ps_dec,UWORD8 u1_mb_idx,UWORD8 u1_num_mbs)179 WORD32 isvcd_mv_pred_ref_tfr_nby2_epmb(dec_struct_t *ps_dec, UWORD8 u1_mb_idx, UWORD8 u1_num_mbs)
180 {
181     svc_dec_lyr_struct_t *ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) ps_dec;
182     parse_pmbarams_t *ps_mb_part_info;
183     parse_part_params_t *ps_part;
184     mv_pred_t *ps_mv_nmb, *ps_mv_nmb_start, *ps_mv_ntop, *ps_mv_ntop_start;
185     UWORD32 i, j;
186     const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
187     dec_mb_info_t *ps_cur_mb_info;
188     dec_svc_mb_info_t *ps_svc_cur_mb_info;
189     WORD32 i2_mv_x, i2_mv_y;
190 
191     ps_dec->i4_submb_ofst -= (u1_num_mbs - u1_mb_idx) << 4;
192     ps_mb_part_info = ps_dec->ps_parse_mb_data;
193     ps_part = ps_dec->ps_parse_part_params;
194 
195     /* N/2 Mb MvPred and Transfer Setup Loop */
196     for(i = u1_mb_idx; i < u1_num_mbs; i++, ps_mb_part_info++)
197     {
198         UWORD32 u1_colz;
199         UWORD32 u1_field;
200         mv_pred_t s_mvPred = {0};
201         mv_pred_t *ps_mv_pred = &s_mvPred;
202 
203         *ps_mv_pred = ps_dec->s_default_mv_pred;
204 
205         ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
206 
207         /* Restore the slice scratch MbX and MbY context */
208         ps_cur_mb_info = ps_dec->ps_nmb_info + i;
209         ps_svc_cur_mb_info = ps_svc_lyr_dec->ps_svc_nmb_info + i;
210         u1_field = ps_cur_mb_info->u1_mb_field_decodingflag;
211 
212         ps_mv_nmb_start = ps_dec->ps_mv_cur + (i << 4);
213         ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
214         ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
215         ps_dec->u2_mv_2mb[i & 0x1] = 0;
216 
217         /* Look for MV Prediction and Reference Transfer in Non-I Mbs */
218         if(!ps_mb_part_info->u1_isI_mb)
219         {
220             UWORD32 u1_blk_no;
221             WORD32 i1_ref_idx, i1_ref_idx1;
222             UWORD32 u1_sub_mb_x, u1_sub_mb_y, u1_sub_mb_num;
223             UWORD32 u1_num_part, u1_num_ref, u1_wd, u1_ht;
224             UWORD32 *pu4_wt_offst, **ppu4_wt_ofst;
225             UWORD32 u1_scale_ref, u4_bot_mb;
226             WORD8 *pi1_ref_idx = ps_mb_part_info->i1_ref_idx[0];
227             pic_buffer_t *ps_ref_frame, **pps_ref_frame;
228             deblk_mb_t *ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + i;
229             WORD32 i4_mb_mode_svc;
230             UWORD8 u1_motion_pred_flag_l0 = ps_svc_cur_mb_info->au1_motion_pred_flag[0];
231 
232             /* MB Level initialisations */
233             ps_dec->u4_num_pmbair = i >> u1_mbaff;
234             ps_dec->u1_mb_idx_mv = i;
235             ppu4_wt_ofst = ps_mb_part_info->pu4_wt_offst;
236             pps_ref_frame = ps_dec->ps_ref_pic_buf_lx[0];
237 
238             i4_mb_mode_svc = isvcd_interlyr_motion_mode_pred(
239                 ps_svc_lyr_dec, ps_cur_mb_info, ps_svc_cur_mb_info, ps_mb_part_info, ps_part);
240 
241             if((-1 == i4_mb_mode_svc) || (SVC_INTER_MB == i4_mb_mode_svc))
242             {
243                 ps_mv_ntop_start =
244                     ps_mv_nmb_start - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12;
245 
246                 u1_num_part = ps_mb_part_info->u1_num_part;
247                 ps_cur_deblk_mb->u1_mb_type |= (u1_num_part > 1) << 1;
248                 ps_cur_mb_info->u4_pred_info_pkd_idx = ps_dec->u4_pred_info_pkd_idx;
249                 ps_cur_mb_info->u1_num_pred_parts = 0;
250 
251                 /****************************************************/
252                 /* weighted u4_ofst pointer calculations, this loop  */
253                 /* runs maximum 4 times, even in direct cases       */
254                 /****************************************************/
255                 u1_scale_ref = u1_mbaff & u1_field;
256 
257                 u4_bot_mb = 1 - ps_cur_mb_info->u1_topmb;
258                 if(ps_dec->ps_cur_pps->u1_wted_pred_flag)
259                 {
260                     u1_num_ref = MIN(u1_num_part, 4);
261                     for(u1_blk_no = 0; u1_blk_no < u1_num_ref; u1_blk_no++)
262                     {
263                         i1_ref_idx = pi1_ref_idx[u1_blk_no];
264                         if(u1_scale_ref) i1_ref_idx >>= 1;
265                         pu4_wt_offst = (UWORD32 *) &ps_dec->pu4_wt_ofsts[2 * X3(i1_ref_idx)];
266                         ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
267                     }
268                 }
269                 else
270                 {
271                     ppu4_wt_ofst[0] = NULL;
272                     ppu4_wt_ofst[1] = NULL;
273                     ppu4_wt_ofst[2] = NULL;
274                     ppu4_wt_ofst[3] = NULL;
275                 }
276 
277                 /**************************************************/
278                 /* Loop on Partitions                             */
279                 /**************************************************/
280                 for(j = 0; j < u1_num_part; j++, ps_part++)
281                 {
282                     u1_sub_mb_num = ps_part->u1_sub_mb_num;
283                     ps_dec->u1_sub_mb_num = u1_sub_mb_num;
284 
285                     if(PART_NOT_DIRECT != ps_part->u1_is_direct)
286                     {
287                         /* Mb Skip Mode */
288                         /* Setting the default and other members of MvPred Structure */
289                         s_mvPred.i2_mv[2] = -1;
290                         s_mvPred.i2_mv[3] = -1;
291                         s_mvPred.i1_ref_frame[0] = 0;
292                         i1_ref_idx = (u1_scale_ref && u4_bot_mb) ? MAX_REF_BUFS : 0;
293                         ps_ref_frame = pps_ref_frame[i1_ref_idx];
294                         s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
295                         s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
296                         pu4_wt_offst = (UWORD32 *) &ps_dec->pu4_wt_ofsts[0];
297 
298                         ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb_start, ps_mv_ntop_start,
299                                           &s_mvPred, 0, 4, 0, 1, MB_SKIP);
300 
301                         {
302                             pred_info_pkd_t *ps_pred_pkd;
303                             ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
304                             ih264d_fill_pred_info(s_mvPred.i2_mv, 4, 4, 0, PRED_L0, ps_pred_pkd,
305                                                   ps_ref_frame->u1_pic_buf_id,
306                                                   (i1_ref_idx >> u1_scale_ref), pu4_wt_offst,
307                                                   ps_ref_frame->u1_pic_type);
308 
309                             ps_dec->u4_pred_info_pkd_idx++;
310                             ps_cur_mb_info->u1_num_pred_parts++;
311                         }
312 
313                         /* Storing colocated zero information */
314                         u1_colz = ((ABS(s_mvPred.i2_mv[0]) <= 1) && (ABS(s_mvPred.i2_mv[1]) <= 1)) +
315                                   (u1_field << 1);
316 
317                         if(ps_mv_nmb_start)
318                         {
319                             ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0, u1_colz, 4,
320                                                4);
321                         }
322                         else
323                         {
324                             return NOT_OK;
325                         }
326                     }
327                     else
328                     {
329                         u1_sub_mb_x = u1_sub_mb_num & 0x03;
330                         u1_sub_mb_y = u1_sub_mb_num >> 2;
331                         u1_blk_no = (u1_num_part < 4)
332                                         ? j
333                                         : (((u1_sub_mb_y >> 1) << 1) + (u1_sub_mb_x >> 1));
334 
335                         ps_mv_ntop = ps_mv_ntop_start + u1_sub_mb_x;
336                         ps_mv_nmb = ps_mv_nmb_start + u1_sub_mb_num;
337 
338                         u1_wd = ps_part->u1_partwidth;
339                         u1_ht = ps_part->u1_partheight;
340 
341                         /* Populate the colpic info and reference frames */
342                         i1_ref_idx = pi1_ref_idx[u1_blk_no];
343                         s_mvPred.i1_ref_frame[0] = i1_ref_idx;
344 
345                         if((1 != ps_svc_cur_mb_info->u1_base_mode_flag) &&
346                            (0 == (u1_motion_pred_flag_l0 & (1 << u1_blk_no))))
347                         {
348                             /********************************************************/
349                             /* Predict Mv                                           */
350                             /* Add Mv Residuals and store back                      */
351                             /********************************************************/
352                             ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb, ps_mv_ntop,
353                                               &s_mvPred, u1_sub_mb_num, u1_wd, 0, 1,
354                                               ps_cur_mb_info->u1_mb_mc_mode);
355 
356                             i2_mv_x = ps_mv_nmb->i2_mv[0];
357                             i2_mv_y = ps_mv_nmb->i2_mv[1];
358                             i2_mv_x += s_mvPred.i2_mv[0];
359                             i2_mv_y += s_mvPred.i2_mv[1];
360                             s_mvPred.i2_mv[0] = i2_mv_x;
361                             s_mvPred.i2_mv[1] = i2_mv_y;
362                         }
363                         else
364                         {
365                             isvcd_retrive_infer_mode_mv(ps_svc_lyr_dec, &s_mvPred, 0,
366                                                         u1_sub_mb_num);
367 
368                             if(0 != (u1_motion_pred_flag_l0 & (1 << u1_blk_no)))
369                             {
370                                 i2_mv_x = ps_mv_nmb->i2_mv[0];
371                                 i2_mv_y = ps_mv_nmb->i2_mv[1];
372                                 i2_mv_x += s_mvPred.i2_mv[0];
373                                 i2_mv_y += s_mvPred.i2_mv[1];
374                                 s_mvPred.i2_mv[0] = i2_mv_x;
375                                 s_mvPred.i2_mv[1] = i2_mv_y;
376                             }
377                             i2_mv_x = s_mvPred.i2_mv[0];
378                             i2_mv_y = s_mvPred.i2_mv[1];
379                         }
380                         /********************************************************/
381                         /* Transfer setup call                                  */
382                         /* convert RefIdx if it is MbAff                        */
383                         /* Pass Weight Offset and refFrame                      */
384                         /********************************************************/
385                         i1_ref_idx1 = i1_ref_idx >> u1_scale_ref;
386                         if(u1_scale_ref && ((i1_ref_idx & 0x01) != u4_bot_mb))
387                             i1_ref_idx1 += MAX_REF_BUFS;
388                         if(-1 == i1_ref_idx1) return NOT_OK;
389                         ps_ref_frame = pps_ref_frame[i1_ref_idx1];
390                         pu4_wt_offst = ppu4_wt_ofst[u1_blk_no];
391 
392                         {
393                             pred_info_pkd_t *ps_pred_pkd;
394                             ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
395                             ih264d_fill_pred_info(s_mvPred.i2_mv, u1_wd, u1_ht, u1_sub_mb_num,
396                                                   PRED_L0, ps_pred_pkd, ps_ref_frame->u1_pic_buf_id,
397                                                   (i1_ref_idx >> u1_scale_ref), pu4_wt_offst,
398                                                   ps_ref_frame->u1_pic_type);
399 
400                             ps_dec->u4_pred_info_pkd_idx++;
401                             ps_cur_mb_info->u1_num_pred_parts++;
402                         }
403 
404                         /* Fill colocated info in MvPred structure */
405                         s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
406                         s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
407 
408                         /* Calculating colocated zero information */
409                         u1_colz = (u1_field << 1) |
410                                   ((i1_ref_idx == 0) && (ABS(i2_mv_x) <= 1) && (ABS(i2_mv_y) <= 1));
411                         u1_colz |= ps_mb_part_info->u1_col_info[u1_blk_no];
412 
413                         /* Replicate the motion vectors and colzero u4_flag  */
414                         /* for all sub-partitions                         */
415 
416                         if(ps_mv_nmb)
417                         {
418                             ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb, u1_sub_mb_num, u1_colz,
419                                                u1_ht, u1_wd);
420                         }
421                         else
422                         {
423                             return NOT_OK;
424                         }
425                     }
426                 }
427 
428                 /* to take care of 16 parttitions increment for base mode flag case*/
429                 if(1 == ps_svc_cur_mb_info->u1_base_mode_flag)
430                 {
431                     ps_part += (MAX_NUM_MB_PART - u1_num_part);
432                 }
433             }
434             else
435             {
436                 ps_cur_deblk_mb->u1_mb_type |= D_INTRA_IBL;
437                 if((ps_svc_lyr_dec->u1_layer_identifier != TARGET_LAYER) &&
438                    (DBLK_ENABLED == ps_dec->ps_cur_slice->u1_disable_dblk_filter_idc))
439                 {
440                     ps_cur_deblk_mb->u1_deblocking_mode = MB_ENABLE_FILTERING;
441                 }
442                 /* to take care of 16 parttitions increment for base mode flag case*/
443                 if(1 != ps_svc_cur_mb_info->u1_base_mode_flag)
444                 {
445                     return NOT_OK;
446                 }
447                 {
448                     ps_part += (MAX_NUM_MB_PART);
449                 }
450                 /* Storing colocated zero information */
451                 if(ps_mv_nmb_start)
452                 {
453                     ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
454                                        (UWORD8) (u1_field << 1), 4, 4);
455                 }
456                 else
457                 {
458                     return NOT_OK;
459                 }
460             }
461         }
462         else
463         {
464             /* Storing colocated zero information */
465             if(ps_mv_nmb_start)
466             {
467                 ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0, (UWORD8) (u1_field << 1),
468                                    4, 4);
469             }
470             else
471             {
472                 return NOT_OK;
473             }
474         }
475     }
476     return OK;
477 }
478 /*!
479  **************************************************************************
480  * \if Function name : isvcd_update_intra_mb_inter_layer_info \endif
481  *
482  * \brief : IT
483  *    This function decodes an Inter MB fornfor ot target base layers
484  *    Only for Progressive : saves residual for upper enhancement layers
485  *
486  * \return
487  *    0 on Success and Error code otherwise
488  **************************************************************************
489  */
isvcd_update_intra_mb_inter_layer_info(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info)490 void isvcd_update_intra_mb_inter_layer_info(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
491                                             dec_mb_info_t *ps_cur_mb_info)
492 {
493     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb =
494         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start + ps_cur_mb_info->u2_mbx +
495         (ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride * (ps_cur_mb_info->u2_mby));
496 
497     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode = SVC_INTRA_MB;
498     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size = ps_cur_mb_info->u1_tran_form8x8;
499     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = 0;
500     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz = 0;
501 }
502 
503 /*!
504 **************************************************************************
505 * \if Function name : isvcd_update_ipcm_mb_inter_layer_info \endif
506 *
507 * \brief : IT
508 *    This function decodes an IPM MB fornfor ot target base layers
509 *    Only for Progressive : saves residual for upper enhancement layers
510 *
511 * \return
512 *    0 on Success and Error code otherwise
513 **************************************************************************
514 */
isvcd_update_ipcm_mb_inter_layer_info(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info)515 void isvcd_update_ipcm_mb_inter_layer_info(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
516                                            dec_mb_info_t *ps_cur_mb_info)
517 {
518     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode = SVC_IPCM_MB;
519     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size = ps_cur_mb_info->u1_tran_form8x8;
520     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = 0;
521     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz = 0;
522 }
523 
524 /*!
525 **************************************************************************
526 * \if Function name : isvcd_update_ibl_mb_inter_layer_info \endif
527 *
528 * \brief : IT
529 *    This function decodes an IBL MB fornfor ot target base layers
530 *    Only for Progressive : saves residual for upper enhancement layers
531 *
532 * \return
533 *    0 on Success and Error code otherwise
534 **************************************************************************
535 */
isvcd_update_ibl_mb_inter_layer_info(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info)536 void isvcd_update_ibl_mb_inter_layer_info(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
537                                           dec_mb_info_t *ps_cur_mb_info)
538 {
539     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode = SVC_IBL_MB;
540     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size = ps_cur_mb_info->u1_tran_form8x8;
541     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = 0;
542     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz = 0;
543 }
544 /*!
545 **************************************************************************
546 * \if Function name : isvcd_update_inter_mb_inter_layer_info \endif
547 *
548 * \brief : IT
549 *    This function decodes an IBL MB fornfor ot target base layers
550 *    Only for Progressive : saves residual for upper enhancement layers
551 *
552 * \return
553 *    0 on Success and Error code otherwise
554 **************************************************************************
555 */
isvcd_update_inter_mb_inter_layer_info(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_inference_mode)556 void isvcd_update_inter_mb_inter_layer_info(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
557                                             dec_mb_info_t *ps_cur_mb_info, UWORD8 u1_inference_mode)
558 {
559     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb =
560         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start + ps_cur_mb_info->u2_mbx +
561         (ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride * (ps_cur_mb_info->u2_mby));
562     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode =
563         u1_inference_mode ? SVC_IBL_MB : SVC_INTER_MB;
564     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size = ps_cur_mb_info->u1_tran_form8x8;
565     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = ps_cur_mb_info->u2_luma_csbp;
566     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz =
567         (UWORD8) ps_cur_mb_info->u2_chroma_csbp;
568     if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag, 1))
569     {
570         /* Four bits for Cb in DC only cbp */
571         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz |= 0x0F;
572     }
573     if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag, 2))
574     {
575         /* Four bits for Cr in DC only cbp */
576         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz |= 0xF0;
577     }
578 }
579 /*!
580  **************************************************************************
581  * \if Function name : isvcd_process_inter_mb_no_rsd_pred_non_target \endif
582  *
583  * \brief : IT
584  *    This function decodes an Inter MB fornfor ot target base layers
585  *    Only for Progressive : saves residual for upper enhancement layers
586  *
587  * \return
588  *    0 on Success and Error code otherwise
589  **************************************************************************
590  */
isvcd_process_inter_mb_no_rsd_pred_non_target(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_inference_mode)591 WORD32 isvcd_process_inter_mb_no_rsd_pred_non_target(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
592                                                      dec_mb_info_t *ps_cur_mb_info,
593                                                      UWORD8 u1_inference_mode)
594 {
595     dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
596     UWORD16 u2_luma_stride, u2_chroma_stride;
597     WORD16 *pi2_y_coeff, *pi2_luma_res_ptr, *pi2_chroma_res_ptr;
598     UWORD32 u4_luma_dc_only_csbp = 0;
599     UWORD32 u4_luma_dc_only_cbp = 0;
600 
601     if(0 != ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
602     {
603         return NOT_OK;
604     }
605     u2_luma_stride = ps_svc_lyr_dec->u2_residual_resample_luma_stride;
606     pi2_luma_res_ptr = ps_svc_lyr_dec->pi2_il_residual_resample_mb_luma_frm_start +
607                        (ps_cur_mb_info->u2_mbx << 4) +
608                        ((ps_cur_mb_info->u2_mby << 4) * u2_luma_stride);
609 
610     u2_chroma_stride = ps_svc_lyr_dec->u2_residual_resample_chroma_stride;
611     pi2_chroma_res_ptr = ps_svc_lyr_dec->pi2_il_residual_resample_mb_chroma_frm_start +
612                          (ps_cur_mb_info->u2_mbx << 4) +
613                          ((ps_cur_mb_info->u2_mby << 3) * u2_chroma_stride);
614 
615     if(!ps_cur_mb_info->u1_tran_form8x8)
616     {
617         u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec, ps_cur_mb_info, 0);
618     }
619     else
620     {
621         if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
622         {
623             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec, ps_cur_mb_info, 0);
624         }
625         else
626         {
627             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec, ps_cur_mb_info);
628         }
629     }
630 
631     pi2_y_coeff = ps_dec->pi2_coeff_data;
632     /* Inverse Transform and Reconstruction */
633     if(ps_cur_mb_info->u1_cbp & 0x0f)
634     {
635         if(!ps_cur_mb_info->u1_tran_form8x8)
636         {
637             UWORD32 i;
638             WORD16 ai2_tmp[16] = {0};
639             for(i = 0; i < 16; i++)
640             {
641                 if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
642                 {
643                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
644                     WORD16 *pi2_out = pi2_luma_res_ptr + ((i & 0x3) * BLK_SIZE) +
645                                       (i >> 2) * (u2_luma_stride << 2);
646                     PROFILE_DISABLE_IQ_IT_RECON()
647                     {
648                         if(CHECKBIT(u4_luma_dc_only_csbp, i))
649                         {
650                             ps_svc_lyr_dec->pf_iquant_itrans_luma_4x4_dc(
651                                 pi2_level, pi2_out, u2_luma_stride,
652                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
653                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[3],
654                                 ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0, NULL);
655                         }
656                         else
657                         {
658                             ps_svc_lyr_dec->pf_iquant_itrans_luma_4x4(
659                                 pi2_level, pi2_out, u2_luma_stride,
660                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
661                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[3],
662                                 ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0, NULL);
663                         }
664                     }
665                 }
666             }
667         }
668         else
669         {
670             WORD16 *pi2_scale_matrix_ptr;
671             WORD32 i;
672 
673             pi2_scale_matrix_ptr = ps_dec->s_high_profile.i2_scalinglist8x8[1];
674 
675             for(i = 0; i < 4; i++)
676             {
677                 WORD16 ai2_tmp[64] = {0};
678                 WORD16 *pi16_levelBlock =
679                     pi2_y_coeff + (i << 6); /* move to the next 8x8 adding 64 */
680 
681                 WORD16 *pi2_out =
682                     pi2_luma_res_ptr + ((i & 0x1) * BLK8x8SIZE) + (i >> 1) * (u2_luma_stride << 3);
683                 if(CHECKBIT(ps_cur_mb_info->u1_cbp, i))
684                 {
685                     PROFILE_DISABLE_IQ_IT_RECON()
686                     {
687                         if(CHECKBIT(u4_luma_dc_only_cbp, i))
688                         {
689                             ps_svc_lyr_dec->pf_iquant_itrans_luma_8x8_dc(
690                                 pi16_levelBlock, pi2_out, u2_luma_stride,
691                                 gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
692                                 (UWORD16 *) pi2_scale_matrix_ptr, ps_cur_mb_info->u1_qp_div6,
693                                 ai2_tmp, 0, NULL);
694                         }
695                         else
696                         {
697                             ps_svc_lyr_dec->pf_iquant_itrans_luma_8x8(
698                                 pi16_levelBlock, pi2_out, u2_luma_stride,
699                                 gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
700                                 (UWORD16 *) pi2_scale_matrix_ptr, ps_cur_mb_info->u1_qp_div6,
701                                 ai2_tmp, 0, NULL);
702                         }
703                     }
704                 }
705             }
706         }
707     }
708 
709     /* Decode Chroma Block */
710     ih264d_unpack_chroma_coeff4x4_mb(ps_dec, ps_cur_mb_info);
711     /*--------------------------------------------------------------------*/
712     /* Chroma Blocks decoding                                             */
713     /*--------------------------------------------------------------------*/
714     {
715         UWORD8 u1_chroma_cbp = (UWORD8) (ps_cur_mb_info->u1_cbp >> 4);
716 
717         if(u1_chroma_cbp != CBPC_ALLZERO)
718         {
719             UWORD32 u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
720             UWORD32 u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
721             UWORD16 u2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
722 
723             pi2_y_coeff = ps_dec->pi2_coeff_data;
724 
725             {
726                 UWORD32 i;
727                 WORD16 ai2_tmp[16] = {0};
728                 for(i = 0; i < 4; i++)
729                 {
730                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
731                     WORD16 *pi2_out = pi2_chroma_res_ptr +
732                                       ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR) +
733                                       (i >> 1) * (u2_chroma_stride << 2);
734                     PROFILE_DISABLE_IQ_IT_RECON()
735                     {
736                         if(CHECKBIT(u2_chroma_csbp, i))
737                         {
738                             ps_svc_lyr_dec->pf_iquant_itrans_chroma_4x4(
739                                 pi2_level, pi2_out, u2_chroma_stride,
740                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
741                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[4], u4_scale_u,
742                                 ai2_tmp, pi2_level);
743                         }
744                         else if(pi2_level[0] != 0)
745                         {
746                             ps_svc_lyr_dec->pf_iquant_itrans_chroma_4x4_dc(
747                                 pi2_level, pi2_out, u2_chroma_stride,
748                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
749                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[4], u4_scale_u,
750                                 ai2_tmp, pi2_level);
751                         }
752                     }
753                 }
754             }
755 
756             pi2_y_coeff += MB_CHROM_SIZE;
757             u2_chroma_csbp >>= 4;
758 
759             {
760                 UWORD32 i;
761                 WORD16 ai2_tmp[16] = {0};
762                 for(i = 0; i < 4; i++)
763                 {
764                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
765                     WORD16 *pi2_out = pi2_chroma_res_ptr + 1 +
766                                       ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR) +
767                                       (i >> 1) * (u2_chroma_stride << 2);
768                     PROFILE_DISABLE_IQ_IT_RECON()
769                     {
770                         if(CHECKBIT(u2_chroma_csbp, i))
771                         {
772                             ps_svc_lyr_dec->pf_iquant_itrans_chroma_4x4(
773                                 pi2_level, pi2_out, u2_chroma_stride,
774                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
775                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[5], u4_scale_v,
776                                 ai2_tmp, pi2_level);
777                         }
778                         else if(pi2_level[0] != 0)
779                         {
780                             ps_svc_lyr_dec->pf_iquant_itrans_chroma_4x4_dc(
781                                 pi2_level, pi2_out, u2_chroma_stride,
782                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
783                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[5], u4_scale_v,
784                                 ai2_tmp, pi2_level);
785                         }
786                     }
787                 }
788             }
789         }
790     }
791 
792     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb =
793         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start + ps_cur_mb_info->u2_mbx +
794         (ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride * (ps_cur_mb_info->u2_mby));
795     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode =
796         u1_inference_mode ? SVC_IBL_MB : SVC_INTER_MB;
797     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size = ps_cur_mb_info->u1_tran_form8x8;
798     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = ps_cur_mb_info->u2_luma_csbp;
799     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz =
800         (UWORD8) ps_cur_mb_info->u2_chroma_csbp;
801     if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag, 1))
802     {
803         /* Four bits for Cb in DC only cbp */
804         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz |= 0x0F;
805     }
806     if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag, 2))
807     {
808         /* Four bits for Cr in DC only cbp */
809         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz |= 0xF0;
810     }
811     return OK;
812 }
813 
814 /*!
815  **************************************************************************
816  * \if Function name : isvcd_process_inter_mb_rsd_pred_non_target \endif
817  *
818  * \brief : IT + Residual :
819  *    This function decodes an Inter MB for non target layers
820  *    Only for Progressive : saves residual + IT for upper enhancement layers
821  *
822  * \return
823  *    0 on Success and Error code otherwise
824  **************************************************************************
825  */
isvcd_process_inter_mb_rsd_pred_non_target(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_inference_mode,UWORD16 * pu2_res_luma_csbp)826 WORD32 isvcd_process_inter_mb_rsd_pred_non_target(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
827                                                   dec_mb_info_t *ps_cur_mb_info,
828                                                   UWORD8 u1_inference_mode,
829                                                   UWORD16 *pu2_res_luma_csbp)
830 {
831     dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
832     UWORD16 u2_luma_stride, u2_chroma_stride;
833     WORD16 *pi2_y_coeff, *pi2_luma_res_ptr, *pi2_chroma_res_ptr;
834     UWORD32 u4_luma_dc_only_csbp = 0;
835     UWORD32 u4_luma_dc_only_cbp = 0;
836     UWORD16 u2_res_luma_csbp = 0;
837     UWORD16 u2_res_chroma_csbp = 0, u2_res_chroma_nnz = 0;
838     WORD32 ret;
839 
840     if(0 != ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
841     {
842         return NOT_OK;
843     }
844     u2_luma_stride = ps_svc_lyr_dec->u2_residual_resample_luma_stride;
845     pi2_luma_res_ptr = ps_svc_lyr_dec->pi2_il_residual_resample_mb_luma_frm_start +
846                        (ps_cur_mb_info->u2_mbx << 4) +
847                        ((ps_cur_mb_info->u2_mby << 4) * u2_luma_stride);
848 
849     u2_chroma_stride = ps_svc_lyr_dec->u2_residual_resample_chroma_stride;
850     pi2_chroma_res_ptr = ps_svc_lyr_dec->pi2_il_residual_resample_mb_chroma_frm_start +
851                          (ps_cur_mb_info->u2_mbx << 4) +
852                          ((ps_cur_mb_info->u2_mby << 3) * u2_chroma_stride);
853 
854     // residual prediction SVC
855     ret = isvcd_process_residual_resample_mb(ps_svc_lyr_dec, ps_cur_mb_info);
856     if(ret != OK)
857     {
858         return ret;
859     }
860 
861     if(!ps_cur_mb_info->u1_tran_form8x8)
862     {
863         u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec, ps_cur_mb_info, 0);
864     }
865     else
866     {
867         if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
868         {
869             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec, ps_cur_mb_info, 0);
870         }
871         else
872         {
873             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec, ps_cur_mb_info);
874         }
875     }
876 
877     *pu2_res_luma_csbp = 0;
878     pi2_y_coeff = ps_dec->pi2_coeff_data;
879     /* Inverse Transform and Reconstruction */
880     if(ps_cur_mb_info->u1_cbp & 0x0f)
881     {
882         if(!ps_cur_mb_info->u1_tran_form8x8)
883         {
884             UWORD32 i;
885             WORD16 ai2_tmp[16] = {0};
886             for(i = 0; i < 16; i++)
887             {
888                 if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
889                 {
890                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
891                     WORD16 *pi2_out = pi2_luma_res_ptr + ((i & 0x3) * BLK_SIZE) +
892                                       (i >> 2) * (u2_luma_stride << 2);
893                     PROFILE_DISABLE_IQ_IT_RECON()
894                     {
895                         if(CHECKBIT(u4_luma_dc_only_csbp, i))
896                         {
897                             u2_res_luma_csbp =
898                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_luma_4x4_dc(
899                                     pi2_level, pi2_out, pi2_out, u2_luma_stride, u2_luma_stride,
900                                     gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
901                                     (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[3],
902                                     ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0, NULL);
903                         }
904                         else
905                         {
906                             u2_res_luma_csbp = ps_svc_lyr_dec->pf_iquant_itrans_residual_luma_4x4(
907                                 pi2_level, pi2_out, pi2_out, u2_luma_stride, u2_luma_stride,
908                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
909                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[3],
910                                 ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0, NULL);
911                         }
912                     }
913                 }
914                 else
915                 {
916                     WORD16 *pi2_out = pi2_luma_res_ptr + ((i & 0x3) * BLK_SIZE) +
917                                       (i >> 2) * (u2_luma_stride << 2);
918 
919                     u2_res_luma_csbp =
920                         ps_svc_lyr_dec->pf_residual_luma_4x4(pi2_out, u2_luma_stride);
921                 }
922                 *pu2_res_luma_csbp |= (u2_res_luma_csbp << i);
923             }
924         }
925         else
926         {
927             WORD16 *pi2_scale_matrix_ptr;
928             WORD32 i;
929 
930             pi2_scale_matrix_ptr = ps_dec->s_high_profile.i2_scalinglist8x8[1];
931 
932             for(i = 0; i < 4; i++)
933             {
934                 WORD16 ai2_tmp[64] = {0};
935                 WORD16 *pi16_levelBlock =
936                     pi2_y_coeff + (i << 6); /* move to the next 8x8 adding 64 */
937 
938                 WORD16 *pi2_out =
939                     pi2_luma_res_ptr + ((i & 0x1) * BLK8x8SIZE) + (i >> 1) * (u2_luma_stride << 3);
940                 if(CHECKBIT(ps_cur_mb_info->u1_cbp, i))
941                 {
942                     PROFILE_DISABLE_IQ_IT_RECON()
943                     {
944                         if(CHECKBIT(u4_luma_dc_only_cbp, i))
945                         {
946                             u2_res_luma_csbp =
947                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_luma_8x8_dc(
948                                     pi16_levelBlock, pi2_out, pi2_out, u2_luma_stride,
949                                     u2_luma_stride,
950                                     gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
951                                     (UWORD16 *) pi2_scale_matrix_ptr, ps_cur_mb_info->u1_qp_div6,
952                                     ai2_tmp, 0, NULL);
953                         }
954                         else
955                         {
956                             u2_res_luma_csbp = ps_svc_lyr_dec->pf_iquant_itrans_residual_luma_8x8(
957                                 pi16_levelBlock, pi2_out, pi2_out, u2_luma_stride, u2_luma_stride,
958                                 gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
959                                 (UWORD16 *) pi2_scale_matrix_ptr, ps_cur_mb_info->u1_qp_div6,
960                                 ai2_tmp, 0, NULL);
961                         }
962                     }
963                 }
964                 else
965                 {
966                     WORD16 *pi2_out = pi2_luma_res_ptr + ((i & 0x1) * BLK8x8SIZE) +
967                                       (i >> 1) * (u2_luma_stride << 3);
968 
969                     u2_res_luma_csbp =
970                         ps_svc_lyr_dec->pf_residual_luma_8x8(pi2_out, u2_luma_stride);
971                 }
972                 *pu2_res_luma_csbp |= (u2_res_luma_csbp << (((i >> 1) << 3) + ((i & 0x01) << 1)));
973             }
974         }
975     }
976     else
977     {
978         WORD16 *pi2_out = pi2_luma_res_ptr;
979 
980         *pu2_res_luma_csbp = ps_svc_lyr_dec->pf_residual_luma_16x16(pi2_out, u2_luma_stride);
981     }
982 
983     /* Decode Chroma Block */
984     ih264d_unpack_chroma_coeff4x4_mb(ps_dec, ps_cur_mb_info);
985     /*--------------------------------------------------------------------*/
986     /* Chroma Blocks decoding                                             */
987     /*--------------------------------------------------------------------*/
988     {
989         UWORD8 u1_chroma_cbp = (UWORD8) (ps_cur_mb_info->u1_cbp >> 4);
990 
991         u2_res_chroma_nnz =
992             ps_svc_lyr_dec->pf_residual_chroma_cb_cr_8x8(pi2_chroma_res_ptr, u2_chroma_stride);
993 
994         if(u1_chroma_cbp != CBPC_ALLZERO)
995         {
996             UWORD32 u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
997             UWORD32 u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
998             UWORD16 u2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
999 
1000             pi2_y_coeff = ps_dec->pi2_coeff_data;
1001 
1002             {
1003                 UWORD32 i;
1004                 WORD16 ai2_tmp[16] = {0};
1005                 for(i = 0; i < 4; i++)
1006                 {
1007                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
1008                     WORD16 *pi2_out = pi2_chroma_res_ptr +
1009                                       ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR) +
1010                                       (i >> 1) * (u2_chroma_stride << 2);
1011                     PROFILE_DISABLE_IQ_IT_RECON()
1012                     {
1013                         if(CHECKBIT(u2_chroma_csbp, i))
1014                         {
1015                             u2_res_chroma_csbp =
1016                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_chroma_4x4(
1017                                     pi2_level, pi2_out, pi2_out, u2_chroma_stride, u2_chroma_stride,
1018                                     gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
1019                                     (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[4],
1020                                     u4_scale_u, ai2_tmp, pi2_level);
1021                             u2_res_chroma_nnz &= (0XFF ^ (1 << i));
1022                             u2_res_chroma_nnz |= (u2_res_chroma_csbp << i);
1023                         }
1024                         else if(pi2_level[0] != 0)
1025                         {
1026                             u2_res_chroma_csbp =
1027                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_chroma_4x4_dc(
1028                                     pi2_level, pi2_out, pi2_out, u2_chroma_stride, u2_chroma_stride,
1029                                     gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
1030                                     (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[4],
1031                                     u4_scale_u, ai2_tmp, pi2_level);
1032                             u2_res_chroma_nnz &= (0XFF ^ (1 << i));
1033                             u2_res_chroma_nnz |= (u2_res_chroma_csbp << i);
1034                         }
1035                     }
1036                 }
1037             }
1038 
1039             pi2_y_coeff += MB_CHROM_SIZE;
1040             u2_chroma_csbp >>= 4;
1041 
1042             {
1043                 UWORD32 i;
1044                 WORD16 ai2_tmp[16] = {0};
1045                 for(i = 0; i < 4; i++)
1046                 {
1047                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
1048                     WORD16 *pi2_out = pi2_chroma_res_ptr + 1 +
1049                                       ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR) +
1050                                       (i >> 1) * (u2_chroma_stride << 2);
1051                     PROFILE_DISABLE_IQ_IT_RECON()
1052                     {
1053                         if(CHECKBIT(u2_chroma_csbp, i))
1054                         {
1055                             u2_res_chroma_csbp =
1056                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_chroma_4x4(
1057                                     pi2_level, pi2_out, pi2_out, u2_chroma_stride, u2_chroma_stride,
1058                                     gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
1059                                     (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[5],
1060                                     u4_scale_v, ai2_tmp, pi2_level);
1061                             u2_res_chroma_nnz &= (0XFF ^ (1 << (i + 4)));
1062                             u2_res_chroma_nnz |= (u2_res_chroma_csbp << (i + 4));
1063                         }
1064                         else if(pi2_level[0] != 0)
1065                         {
1066                             u2_res_chroma_csbp =
1067                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_chroma_4x4_dc(
1068                                     pi2_level, pi2_out, pi2_out, u2_chroma_stride, u2_chroma_stride,
1069                                     gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
1070                                     (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[5],
1071                                     u4_scale_v, ai2_tmp, pi2_level);
1072                             u2_res_chroma_nnz &= (0XFF ^ (1 << (i + 4)));
1073                             u2_res_chroma_nnz |= (u2_res_chroma_csbp << (i + 4));
1074                         }
1075                     }
1076                 }
1077             }
1078         }
1079     }
1080 
1081     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb =
1082         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start + ps_cur_mb_info->u2_mbx +
1083         (ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride * (ps_cur_mb_info->u2_mby));
1084     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode =
1085         u1_inference_mode ? SVC_IBL_MB : SVC_INTER_MB;
1086     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size = ps_cur_mb_info->u1_tran_form8x8;
1087 
1088     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = *pu2_res_luma_csbp;
1089     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz = (UWORD8) u2_res_chroma_nnz;
1090     return OK;
1091 }
1092 /*!
1093 **************************************************************************
1094 * \if Function name : isvcd_process_ii_mb \endif
1095 *
1096 * \brief
1097 *    This function decodes an intra inter mb
1098 *
1099 * \return
1100 *    0 on Success and Error code otherwise
1101 **************************************************************************
1102 */
isvcd_process_ii_mb(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info,dec_svc_mb_info_t * ps_svc_cur_mb_info,UWORD8 u1_mb_num)1103 WORD32 isvcd_process_ii_mb(svc_dec_lyr_struct_t *ps_svc_lyr_dec, dec_mb_info_t *ps_cur_mb_info,
1104                            dec_svc_mb_info_t *ps_svc_cur_mb_info, UWORD8 u1_mb_num)
1105 {
1106     res_prms_t *ps_res_prms;
1107     WORD32 i4_status;
1108     UWORD8 u1_ii_mb_mode = 0;
1109     mb_coord_t s_mb_coord = {0};
1110     mem_element_t s_ref_mb_mode = {0};
1111     svc_dec_lyr_struct_t *ps_svc_dec_ref_layer;
1112 
1113     ps_svc_dec_ref_layer = ps_svc_lyr_dec->ps_dec_svc_ref_layer;
1114     ps_res_prms = &ps_svc_lyr_dec->s_res_prms;
1115     s_mb_coord.u2_mb_x = ps_cur_mb_info->u2_mbx;
1116     s_mb_coord.u2_mb_y = ps_cur_mb_info->u2_mby;
1117 
1118     /* Restricted resolution change has significance only */
1119     /* at resolution change layer                         */
1120     if(SVCD_FALSE == ps_res_prms->u1_rstrct_res_change_flag)
1121     {
1122         s_ref_mb_mode.pv_buffer = ps_svc_dec_ref_layer->ps_inter_lyr_mb_prms_frm_start;
1123         s_ref_mb_mode.i4_element_size = sizeof(inter_lyr_mb_prms_t);
1124         s_ref_mb_mode.i4_num_element_stride = ps_svc_dec_ref_layer->u2_inter_lyr_mb_prms_stride;
1125 
1126         i4_status = isvcd_ii_pred_compute_flags_mb(ps_svc_lyr_dec->pv_ii_pred_ctxt, &s_ref_mb_mode,
1127                                                    &s_mb_coord, ps_cur_mb_info, ps_svc_cur_mb_info,
1128                                                    &u1_ii_mb_mode);
1129 
1130         if(OK != i4_status)
1131         {
1132             return i4_status;
1133         }
1134     }
1135 
1136     if(SVC_INTRA_INTER_MB == u1_ii_mb_mode)
1137     {
1138         i4_status = isvcd_process_ibl_mb(ps_svc_lyr_dec, ps_cur_mb_info, u1_mb_num, 1);
1139         if(OK != i4_status)
1140         {
1141             return i4_status;
1142         }
1143         isvcd_ii_pred_mb(ps_svc_lyr_dec, ps_cur_mb_info);
1144     }
1145     return OK;
1146 }
1147 /*!
1148  **************************************************************************
1149  * \if Function name : isvcd_decode_recon_tfr_nmb_non_base_lyr \endif
1150  *
1151  * \brief
1152  *
1153  *
1154  * \return
1155  *    0 on Success and Error code otherwise
1156  **************************************************************************
1157  */
isvcd_decode_recon_tfr_nmb_non_base_lyr(svc_dec_lyr_struct_t * ps_svc_lyr_dec,UWORD8 u1_mb_idx,UWORD8 u1_num_mbs,UWORD8 u1_num_mbs_next,UWORD8 u1_tfr_n_mb,UWORD8 u1_end_of_row)1158 WORD32 isvcd_decode_recon_tfr_nmb_non_base_lyr(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
1159                                                UWORD8 u1_mb_idx, UWORD8 u1_num_mbs,
1160                                                UWORD8 u1_num_mbs_next, UWORD8 u1_tfr_n_mb,
1161                                                UWORD8 u1_end_of_row)
1162 {
1163     WORD32 i, j;
1164     dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1165     UWORD32 u1_end_of_row_next;
1166     dec_mb_info_t *ps_cur_mb_info;
1167     dec_svc_mb_info_t *ps_svc_cur_mb_info;
1168     UWORD16 *pu2_res_luma_csbp;
1169     const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1170     const UWORD32 u1_slice_type = ps_dec->ps_cur_slice->u1_slice_type;
1171     const WORD32 u1_skip_th =
1172         ((u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? B_8x8 : PRED_8x8R0) : -1);
1173     const UWORD32 u1_ipcm_th = ((u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? 23 : 5) : 0);
1174     WORD32 ret = OK;
1175 
1176     if(!((0 == ps_svc_lyr_dec->u1_base_res_flag) ||
1177          ((1 == ps_svc_lyr_dec->u1_base_res_flag) &&
1178           (1 == ps_svc_lyr_dec->ps_nal_svc_ext->u1_no_inter_layer_pred_flag))))
1179     {
1180         return NOT_OK;
1181     }
1182     /* N Mb MC Loop */
1183     for(i = u1_mb_idx; i < u1_num_mbs; i++)
1184     {
1185         ps_cur_mb_info = ps_dec->ps_nmb_info + i;
1186         ps_dec->u4_dma_buf_idx = 0;
1187         ps_dec->u4_pred_info_idx = 0;
1188 
1189         /*Pointer assignment for Residual NNZ */
1190         pu2_res_luma_csbp = ps_svc_lyr_dec->pu2_frm_res_luma_csbp + ps_cur_mb_info->u2_mbx;
1191         pu2_res_luma_csbp += ps_cur_mb_info->u2_mby * ps_svc_lyr_dec->i4_frm_res_luma_csbp_stride;
1192 
1193         if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
1194         {
1195             {
1196                 WORD32 pred_cnt = 0;
1197                 pred_info_pkd_t *ps_pred_pkd;
1198                 UWORD32 u4_pred_info_pkd_idx;
1199 
1200                 u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
1201 
1202                 while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
1203                 {
1204                     ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
1205 
1206                     ps_dec->p_form_mb_part_info(ps_pred_pkd, ps_dec, ps_cur_mb_info->u2_mbx,
1207                                                 ps_cur_mb_info->u2_mby, (i >> u1_mbaff),
1208                                                 ps_cur_mb_info);
1209                     u4_pred_info_pkd_idx++;
1210                     pred_cnt++;
1211                 }
1212             }
1213             if(ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER)
1214             {
1215                 ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
1216             }
1217         }
1218         else if(ps_cur_mb_info->u1_mb_type == MB_SKIP)
1219         {
1220             {
1221                 WORD32 pred_cnt = 0;
1222                 pred_info_pkd_t *ps_pred_pkd;
1223                 UWORD32 u4_pred_info_pkd_idx;
1224 
1225                 u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
1226 
1227                 while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
1228                 {
1229                     ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
1230 
1231                     ps_dec->p_form_mb_part_info(ps_pred_pkd, ps_dec, ps_cur_mb_info->u2_mbx,
1232                                                 ps_cur_mb_info->u2_mby, (i >> u1_mbaff),
1233                                                 ps_cur_mb_info);
1234 
1235                     u4_pred_info_pkd_idx++;
1236                     pred_cnt++;
1237                 }
1238             }
1239             if(ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER)
1240             {
1241                 /* Decode MB skip */
1242                 ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
1243             }
1244 
1245             *pu2_res_luma_csbp = 0;
1246             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb =
1247                 ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start + ps_cur_mb_info->u2_mbx +
1248                 (ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride * (ps_cur_mb_info->u2_mby));
1249             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode = SVC_INTER_MB;
1250             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size =
1251                 ps_cur_mb_info->u1_tran_form8x8;
1252             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = 0;
1253             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz = 0;
1254         }
1255     }
1256 
1257     /* N Mb IQ IT RECON  Loop */
1258     for(j = u1_mb_idx; j < i; j++)
1259     {
1260         ps_cur_mb_info = ps_dec->ps_nmb_info + j;
1261         ps_svc_cur_mb_info = ps_svc_lyr_dec->ps_svc_nmb_info + j;
1262 
1263         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb =
1264             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start + ps_cur_mb_info->u2_mbx +
1265             (ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride * (ps_cur_mb_info->u2_mby));
1266 
1267         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_slice_id = (WORD8) ps_dec->u2_cur_slice_num;
1268 
1269         /*Pointer assignment for Residual NNZ */
1270         pu2_res_luma_csbp = ps_svc_lyr_dec->pu2_frm_res_luma_csbp + ps_cur_mb_info->u2_mbx;
1271         pu2_res_luma_csbp += ps_cur_mb_info->u2_mby * ps_svc_lyr_dec->i4_frm_res_luma_csbp_stride;
1272 
1273         if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
1274         {
1275             if(ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER)
1276             {
1277                 /* inter intra pred generation */
1278                 if(SVCD_FALSE == ps_svc_lyr_dec->u1_dyadic_flag)
1279                 {
1280                     ret =
1281                         isvcd_process_ii_mb(ps_svc_lyr_dec, ps_cur_mb_info, ps_svc_cur_mb_info, j);
1282                     if(ret != OK) return ret;
1283                 }
1284                 if(0 == ps_svc_cur_mb_info->u1_residual_prediction_flag)
1285                 {
1286                     // IT + Recon
1287                     ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
1288                     isvcd_update_inter_mb_inter_layer_info(ps_svc_lyr_dec, ps_cur_mb_info, 0);
1289                     *pu2_res_luma_csbp = ps_cur_mb_info->u2_luma_csbp;
1290                 }
1291                 else
1292                 {
1293                     // IT + Residual + Recon
1294                     ret = isvcd_process_inter_mb_rsd_pred_target_lyr(ps_svc_lyr_dec, ps_cur_mb_info,
1295                                                                      j, 0, pu2_res_luma_csbp);
1296                     if(ret != OK) return ret;
1297                 }
1298             }
1299             else if(ps_svc_lyr_dec->u1_layer_identifier == MEDIAL_ENHANCEMENT_LAYER)
1300             {
1301                 if(0 == ps_svc_cur_mb_info->u1_residual_prediction_flag)
1302                 {
1303                     // IT : to be consumed by Target
1304                     ret = isvcd_process_inter_mb_no_rsd_pred_non_target(ps_svc_lyr_dec,
1305                                                                         ps_cur_mb_info, 0);
1306                     *pu2_res_luma_csbp = ps_cur_mb_info->u2_luma_csbp;
1307                     if(ret != OK) return ret;
1308                 }
1309                 else
1310                 {
1311                     // IT + Residual : to be consumed by target
1312                     ret = isvcd_process_inter_mb_rsd_pred_non_target(ps_svc_lyr_dec, ps_cur_mb_info,
1313                                                                      0, pu2_res_luma_csbp);
1314                     if(ret != OK) return ret;
1315                 }
1316             }
1317             else
1318             {
1319                 return NOT_OK;
1320             }
1321         }
1322         else if((ps_cur_mb_info->u1_mb_type != MB_SKIP) && (ps_cur_mb_info->u1_mb_type != MB_INFER))
1323         {
1324             if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
1325             {
1326                 ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
1327                 ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
1328                 isvcd_update_intra_mb_inter_layer_info(ps_svc_lyr_dec, ps_cur_mb_info);
1329             }
1330             else
1331             {
1332                 isvcd_update_ipcm_mb_inter_layer_info(ps_svc_lyr_dec, ps_cur_mb_info);
1333             }
1334             *pu2_res_luma_csbp = 0;
1335         }
1336         else if(ps_cur_mb_info->u1_mb_type == MB_INFER)
1337         {
1338             /* inter layer intra prediction : intra upsample, IQ, IT ,deblock */
1339             /* Intra resample for IBL mode */
1340             ret = isvcd_process_ibl_mb(ps_svc_lyr_dec, ps_cur_mb_info, j, 0);
1341             if(ret != OK) return ret;
1342             ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
1343             isvcd_update_inter_mb_inter_layer_info(ps_svc_lyr_dec, ps_cur_mb_info, 1);
1344             *pu2_res_luma_csbp = ps_cur_mb_info->u2_luma_csbp;
1345 
1346             ps_dec->pi1_left_pred_mode[0] = DC;
1347             ps_dec->pi1_left_pred_mode[1] = DC;
1348             ps_dec->pi1_left_pred_mode[2] = DC;
1349             ps_dec->pi1_left_pred_mode[3] = DC;
1350 
1351             ps_cur_mb_info->ps_curmb->pi1_intrapredmodes[0] = DC;
1352             ps_cur_mb_info->ps_curmb->pi1_intrapredmodes[1] = DC;
1353             ps_cur_mb_info->ps_curmb->pi1_intrapredmodes[2] = DC;
1354             ps_cur_mb_info->ps_curmb->pi1_intrapredmodes[3] = DC;
1355 
1356             isvcd_update_ibl_mb_inter_layer_info(ps_svc_lyr_dec, ps_cur_mb_info);
1357         }
1358 
1359         if(ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER)
1360         {
1361             if(ps_dec->u4_num_cores < 3)
1362             {
1363                 if(ps_dec->u4_app_disable_deblk_frm == 0)
1364                     ps_svc_lyr_dec->pf_svc_compute_bs(ps_svc_lyr_dec, ps_cur_mb_info,
1365                                                       (UWORD16) (j >> u1_mbaff));
1366             }
1367         }
1368         else if(ps_svc_lyr_dec->u1_layer_identifier == MEDIAL_ENHANCEMENT_LAYER)
1369         {
1370             if(ps_dec->u4_num_cores < 3)
1371             {
1372                 if(ps_dec->u4_app_disable_deblk_frm == 0)
1373                     ps_svc_lyr_dec->pf_svc_compute_bs(ps_svc_lyr_dec, ps_cur_mb_info,
1374                                                       (UWORD16) (j >> u1_mbaff));
1375             }
1376         }
1377 
1378         if(ps_dec->u4_use_intrapred_line_copy)
1379         {
1380             ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
1381         }
1382     }
1383 
1384     /*MB deblocking*/
1385     if(ps_dec->u4_nmb_deblk == 1)
1386     {
1387         UWORD32 u4_wd_y, u4_wd_uv;
1388         tfr_ctxt_t *ps_tfr_cxt = &(ps_dec->s_tran_addrecon);
1389         UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
1390         const WORD32 i4_cb_qp_idx_ofst = ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
1391         const WORD32 i4_cr_qp_idx_ofst = ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
1392 
1393         u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
1394         u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
1395 
1396         ps_cur_mb_info = ps_dec->ps_nmb_info + u1_mb_idx;
1397 
1398         ps_dec->u4_deblk_mb_x = ps_cur_mb_info->u2_mbx;
1399         ps_dec->u4_deblk_mb_y = ps_cur_mb_info->u2_mby;
1400 
1401         for(j = u1_mb_idx; j < i; j++)
1402         {
1403             if(ps_dec->u4_cur_deblk_mb_num > ps_dec->ps_cur_sps->u2_max_mb_addr)
1404             {
1405                 return NOT_OK;
1406             }
1407             ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt, i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
1408                                        u4_wd_y, u4_wd_uv);
1409         }
1410     }
1411 
1412     if(u1_tfr_n_mb)
1413     {
1414         /****************************************************************/
1415         /* Check for End Of Row in Next iteration                       */
1416         /****************************************************************/
1417         u1_end_of_row_next =
1418             u1_num_mbs_next && (u1_num_mbs_next <= (ps_dec->u1_recon_mb_grp >> u1_mbaff));
1419 
1420         /****************************************************************/
1421         /* Transfer the Following things                                */
1422         /* N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )       */
1423         /* N-Mb Recon Data          ( To Ext Frame Buffer )             */
1424         /* N-Mb Intrapredline Data  ( Updated Internally)               */
1425         /* N-Mb MV Data             ( To Ext MV Buffer )                */
1426         /* N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)    */
1427         /****************************************************************/
1428         ih264d_transfer_mb_group_data(ps_dec, u1_num_mbs, u1_end_of_row, u1_end_of_row_next);
1429         ps_dec->u4_num_mbs_prev_nmb = u1_num_mbs;
1430         ps_dec->u4_pred_info_idx = 0;
1431         ps_dec->u4_dma_buf_idx = 0;
1432     }
1433     return OK;
1434 }
1435 /*!
1436  **************************************************************************
1437  * \if Function name : isvcd_decode_recon_tfr_nmb_base_lyr \endif
1438  *
1439  * \brief
1440  *
1441  *
1442  * \return
1443  *    0 on Success and Error code otherwise
1444  **************************************************************************
1445  */
isvcd_decode_recon_tfr_nmb_base_lyr(svc_dec_lyr_struct_t * ps_svc_lyr_dec,UWORD8 u1_mb_idx,UWORD8 u1_num_mbs,UWORD8 u1_num_mbs_next,UWORD8 u1_tfr_n_mb,UWORD8 u1_end_of_row)1446 WORD32 isvcd_decode_recon_tfr_nmb_base_lyr(svc_dec_lyr_struct_t *ps_svc_lyr_dec, UWORD8 u1_mb_idx,
1447                                            UWORD8 u1_num_mbs, UWORD8 u1_num_mbs_next,
1448                                            UWORD8 u1_tfr_n_mb, UWORD8 u1_end_of_row)
1449 {
1450     WORD32 j;
1451     dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1452     UWORD32 u1_end_of_row_next;
1453     dec_mb_info_t *ps_cur_mb_info;
1454     const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1455     const UWORD32 u1_slice_type = ps_dec->ps_cur_slice->u1_slice_type;
1456     const WORD32 u1_skip_th =
1457         ((u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? B_8x8 : PRED_8x8R0) : -1);
1458     const UWORD32 u1_ipcm_th = ((u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? 23 : 5) : 0);
1459     WORD32 ret = OK;
1460 
1461     if(1 != ps_svc_lyr_dec->u1_base_res_flag)
1462     {
1463         return NOT_OK;
1464     }
1465     if(ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER)
1466     {
1467         return NOT_OK;
1468     }
1469 
1470     /* N Mb IQ IT + Residual Store for Inter / + Recon for Intra Loop */
1471     for(j = u1_mb_idx; j < u1_num_mbs; j++)
1472     {
1473         ps_dec->u4_dma_buf_idx = 0;
1474         ps_dec->u4_pred_info_idx = 0;
1475         ps_cur_mb_info = ps_dec->ps_nmb_info + j;
1476 
1477         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb =
1478             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start + ps_cur_mb_info->u2_mbx +
1479             (ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride * (ps_cur_mb_info->u2_mby));
1480 
1481         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_slice_id = (WORD8) ps_dec->u2_cur_slice_num;
1482 
1483         if(ps_cur_mb_info->u1_mb_type == MB_SKIP)
1484         {
1485             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode = SVC_INTER_MB;
1486             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size =
1487                 ps_cur_mb_info->u1_tran_form8x8;
1488             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = 0;
1489             ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz = 0;
1490         }
1491         else if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
1492         {
1493             /* Only IT : Store Residual (WORD16) for Higher Layers : Base layer*/
1494             ret = isvcd_process_inter_mb_no_rsd_pred_non_target(ps_svc_lyr_dec, ps_cur_mb_info, 0);
1495             if(ret != OK) return ret;
1496         }
1497         else if(ps_cur_mb_info->u1_mb_type != MB_SKIP)
1498         {
1499             if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
1500             {
1501                 ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
1502                 ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
1503                 isvcd_update_intra_mb_inter_layer_info(ps_svc_lyr_dec, ps_cur_mb_info);
1504             }
1505             else
1506             {
1507                 isvcd_update_ipcm_mb_inter_layer_info(ps_svc_lyr_dec, ps_cur_mb_info);
1508             }
1509         }
1510 
1511         if(ps_dec->u4_use_intrapred_line_copy)
1512         {
1513             ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
1514         }
1515     }
1516 
1517     /*MB deblocking*/
1518     if(ps_dec->u4_nmb_deblk == 1)
1519     {
1520         UWORD32 u4_wd_y, u4_wd_uv;
1521         tfr_ctxt_t *ps_tfr_cxt = &(ps_dec->s_tran_addrecon);
1522         UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
1523         const WORD32 i4_cb_qp_idx_ofst = ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
1524         const WORD32 i4_cr_qp_idx_ofst = ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
1525 
1526         u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
1527         u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
1528 
1529         ps_cur_mb_info = ps_dec->ps_nmb_info + u1_mb_idx;
1530 
1531         ps_dec->u4_deblk_mb_x = ps_cur_mb_info->u2_mbx;
1532         ps_dec->u4_deblk_mb_y = ps_cur_mb_info->u2_mby;
1533 
1534         for(j = u1_mb_idx; j < u1_num_mbs; j++)
1535         {
1536             /* IN SVC base layers only intra MB's Need to be deblocked*/
1537             deblk_mb_t *ps_top_mb, *ps_left_mb, *ps_cur_mb;
1538             ps_cur_mb = ps_dec->ps_cur_deblk_mb;
1539             if(!(ps_cur_mb->u1_deblocking_mode & MB_DISABLE_FILTERING))
1540             {
1541                 if(ps_dec->u4_deblk_mb_x)
1542                 {
1543                     ps_left_mb = ps_cur_mb - 1;
1544                 }
1545                 else
1546                 {
1547                     ps_left_mb = NULL;
1548                 }
1549                 if(ps_dec->u4_deblk_mb_y != 0)
1550                 {
1551                     ps_top_mb = ps_cur_mb - (ps_dec->u2_frm_wd_in_mbs);
1552                 }
1553                 else
1554                 {
1555                     ps_top_mb = NULL;
1556                 }
1557 
1558                 if(ps_cur_mb->u1_deblocking_mode & MB_DISABLE_LEFT_EDGE) ps_left_mb = NULL;
1559                 if(ps_cur_mb->u1_deblocking_mode & MB_DISABLE_TOP_EDGE) ps_top_mb = NULL;
1560 
1561                 /* Top Horizontal Edge*/
1562                 if(NULL != ps_top_mb)
1563                 {
1564                     if(!(ps_top_mb->u1_mb_type & D_INTRA_MB))
1565                     {
1566                         ps_cur_mb->u4_bs_table[0] = 0;
1567                     }
1568                 }
1569                 else
1570                 {
1571                     ps_cur_mb->u4_bs_table[0] = 0;
1572                 }
1573 
1574                 /* Left Vertical Edge*/
1575                 if(NULL != ps_left_mb)
1576                 {
1577                     if(!(ps_left_mb->u1_mb_type & D_INTRA_MB))
1578                     {
1579                         ps_cur_mb->u4_bs_table[4] = 0;
1580                     }
1581                 }
1582                 else
1583                 {
1584                     ps_cur_mb->u4_bs_table[4] = 0;
1585                 }
1586             }
1587 
1588             if(ps_dec->u4_cur_deblk_mb_num > ps_dec->ps_cur_sps->u2_max_mb_addr)
1589             {
1590                 return NOT_OK;
1591             }
1592 
1593             ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt, i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
1594                                        u4_wd_y, u4_wd_uv);
1595         }
1596     }
1597 
1598     if(u1_tfr_n_mb)
1599     {
1600         /****************************************************************/
1601         /* Check for End Of Row in Next iteration                       */
1602         /****************************************************************/
1603         u1_end_of_row_next =
1604             u1_num_mbs_next && (u1_num_mbs_next <= (ps_dec->u1_recon_mb_grp >> u1_mbaff));
1605 
1606         /****************************************************************/
1607         /* Transfer the Following things                                */
1608         /* N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )       */
1609         /* N-Mb Recon Data          ( To Ext Frame Buffer )             */
1610         /* N-Mb Intrapredline Data  ( Updated Internally)               */
1611         /* N-Mb MV Data             ( To Ext MV Buffer )                */
1612         /* N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)    */
1613         /****************************************************************/
1614         ih264d_transfer_mb_group_data(ps_dec, u1_num_mbs, u1_end_of_row, u1_end_of_row_next);
1615         ps_dec->u4_num_mbs_prev_nmb = u1_num_mbs;
1616         ps_dec->u4_pred_info_idx = 0;
1617         ps_dec->u4_dma_buf_idx = 0;
1618     }
1619     return OK;
1620 }
1621 /*!
1622 **************************************************************************
1623 * \if Function name : isvcd_process_ibl_mb \endif
1624 *
1625 * \brief
1626 *    This function decodes an ibl mb
1627 *
1628 *
1629 * \return
1630 *
1631 **************************************************************************
1632 */
isvcd_process_ibl_mb(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mb_num,UWORD8 u1_inter_intra_mode)1633 WORD32 isvcd_process_ibl_mb(svc_dec_lyr_struct_t *ps_svc_lyr_dec, dec_mb_info_t *ps_cur_mb_info,
1634                             UWORD8 u1_mb_num, UWORD8 u1_inter_intra_mode)
1635 {
1636     dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1637     intra_sampling_ctxt_t *ps_ctxt;
1638     svc_dec_lyr_struct_t *ps_svc_dec_ref_layer;
1639     pic_buffer_t *ps_frame_buf = ps_dec->ps_cur_pic;
1640     pic_buffer_t *ps_frame_buf_ref_layer;
1641     intra_samp_lyr_ctxt *ps_lyr_ctxt;
1642     mem_element_t s_ref_mb_mode = {0};
1643     mem_element_t s_inp_luma = {0};
1644     mem_element_t s_inp_chroma = {0};
1645     mem_element_t s_out_luma = {0};
1646     mem_element_t s_out_chroma = {0};
1647     WORD32 i4_ref_x_luma, i4_ref_y_luma, i4_luma_incr = 0;
1648     WORD32 i4_ref_x_chroma, i4_ref_y_chroma, i4_chroma_incr = 0;
1649     UWORD32 u4_cur_y_stride, u4_cur_uv_stride;
1650     UWORD32 u4_ref_y_stride, u4_ref_uv_stride;
1651     WORD32 i4_ref_luma_instra_sample_correction_offset = 0;
1652     WORD32 i4_ref_chroma_instra_sample_correction_offset = 0;
1653     ref_mb_map_t *ps_x_off_len_luma;
1654     ref_mb_map_t *ps_y_off_len_luma;
1655     ref_mb_map_t *ps_x_off_len_chroma;
1656     ref_mb_map_t *ps_y_off_len_chroma;
1657     mb_coord_t s_mb_coord = {0};
1658     WORD32 ret = OK;
1659     UNUSED(u1_mb_num);
1660 
1661     ps_ctxt = (intra_sampling_ctxt_t *) ps_svc_lyr_dec->pv_intra_sample_ctxt;
1662     ps_svc_dec_ref_layer = ps_svc_lyr_dec->ps_dec_svc_ref_layer;
1663 
1664     ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
1665     u4_cur_y_stride = ps_dec->u2_frm_wd_y;
1666     u4_cur_uv_stride = ps_dec->u2_frm_wd_uv;
1667     u4_ref_y_stride = ps_svc_dec_ref_layer->s_dec.u2_frm_wd_y;
1668     u4_ref_uv_stride = ps_svc_dec_ref_layer->s_dec.u2_frm_wd_uv;
1669 
1670     ps_frame_buf_ref_layer = ps_svc_dec_ref_layer->s_dec.ps_cur_pic;
1671     if(0 == u1_inter_intra_mode)
1672     {
1673         s_out_luma.pv_buffer = ps_frame_buf->pu1_buf1 + (ps_cur_mb_info->u2_mbx << 4) +
1674                                (u4_cur_y_stride * (ps_cur_mb_info->u2_mby << 4));
1675         s_out_luma.i4_element_size = 1;
1676         s_out_luma.i4_num_element_stride = u4_cur_y_stride;
1677 
1678         s_out_chroma.pv_buffer = ps_frame_buf->pu1_buf2 +
1679                                  (ps_cur_mb_info->u2_mbx << 3) * YUV420SP_FACTOR +
1680                                  (u4_cur_uv_stride * (ps_cur_mb_info->u2_mby << 3));
1681         s_out_chroma.i4_element_size = 1;
1682         s_out_chroma.i4_num_element_stride = u4_cur_uv_stride;
1683     }
1684     else
1685     {
1686         if(SVCD_TRUE == ps_svc_lyr_dec->s_res_prms.u1_dyadic_flag)
1687         {
1688             return NOT_OK;
1689         }
1690 
1691         s_out_luma.pv_buffer = ps_svc_lyr_dec->pu1_ii_resamp_buffer_luma;
1692         s_out_luma.i4_element_size = 1;
1693         s_out_luma.i4_num_element_stride = MB_SIZE;
1694 
1695         s_out_chroma.pv_buffer = ps_svc_lyr_dec->pu1_ii_resamp_buffer_chroma;
1696         s_out_chroma.i4_element_size = 1;
1697         s_out_chroma.i4_num_element_stride = MB_SIZE;
1698     }
1699 
1700     /* get the projected locations buffer pointers */
1701     {
1702         intra_samp_map_ctxt_t *ps_luma_map, *ps_chroma_map;
1703 
1704         ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
1705         ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
1706 
1707         ps_x_off_len_luma = ps_luma_map->ps_x_offset_length;
1708         ps_y_off_len_luma = ps_luma_map->ps_y_offset_length;
1709         ps_x_off_len_chroma = ps_chroma_map->ps_x_offset_length;
1710         ps_y_off_len_chroma = ps_chroma_map->ps_y_offset_length;
1711     }
1712     i4_ref_x_luma = ps_svc_lyr_dec->ps_intsam_luma_map_horz[ps_cur_mb_info->u2_mbx].i2_offset;
1713     i4_ref_y_luma = ps_svc_lyr_dec->ps_intsam_luma_map_vert[ps_cur_mb_info->u2_mby].i2_offset;
1714 
1715     i4_luma_incr = ps_x_off_len_luma[ps_cur_mb_info->u2_mbx].i2_offset - i4_ref_x_luma;
1716     i4_luma_incr +=
1717         (ps_y_off_len_luma[ps_cur_mb_info->u2_mby].i2_offset - i4_ref_y_luma) * u4_ref_y_stride;
1718 
1719     i4_ref_x_chroma = ps_svc_lyr_dec->ps_intsam_chroma_map_horz[ps_cur_mb_info->u2_mbx].i2_offset;
1720     i4_ref_y_chroma = ps_svc_lyr_dec->ps_intsam_chroma_map_vert[ps_cur_mb_info->u2_mby].i2_offset;
1721 
1722     i4_chroma_incr = ps_x_off_len_chroma[ps_cur_mb_info->u2_mbx].i2_offset - i4_ref_x_chroma;
1723     i4_chroma_incr <<= 1;
1724     i4_chroma_incr += (ps_y_off_len_chroma[ps_cur_mb_info->u2_mby].i2_offset - i4_ref_y_chroma) *
1725                       u4_ref_uv_stride;
1726     if(SVCD_FALSE == ps_svc_lyr_dec->s_res_prms.u1_dyadic_flag)
1727     {
1728         i4_ref_x_luma = CLIP3(0, (ps_svc_dec_ref_layer->s_dec.u2_frm_wd_y - 1), i4_ref_x_luma);
1729         i4_ref_y_luma = CLIP3(0, (ps_svc_dec_ref_layer->s_dec.u2_frm_ht_y - 1), i4_ref_y_luma);
1730     }
1731 
1732     i4_ref_luma_instra_sample_correction_offset =
1733         i4_ref_x_luma + (i4_ref_y_luma) * (WORD32) u4_ref_y_stride;
1734 
1735     s_inp_luma.pv_buffer = ps_frame_buf_ref_layer->pu1_buf1 + i4_luma_incr +
1736                            i4_ref_luma_instra_sample_correction_offset;
1737     s_inp_luma.i4_element_size = 1;
1738     s_inp_luma.i4_num_element_stride = u4_ref_y_stride;
1739 
1740     if(SVCD_FALSE == ps_svc_lyr_dec->s_res_prms.u1_dyadic_flag)
1741     {
1742         i4_ref_x_chroma = CLIP3(0, (ps_svc_dec_ref_layer->s_dec.u2_frm_wd_uv - 1), i4_ref_x_chroma);
1743         i4_ref_y_chroma = CLIP3(0, (ps_svc_dec_ref_layer->s_dec.u2_frm_ht_uv - 1), i4_ref_y_chroma);
1744     }
1745     i4_ref_chroma_instra_sample_correction_offset =
1746         (i4_ref_x_chroma << 1) + (i4_ref_y_chroma) * (WORD32) u4_ref_uv_stride;
1747 
1748     s_inp_chroma.pv_buffer = ps_frame_buf_ref_layer->pu1_buf2 + i4_chroma_incr +
1749                              i4_ref_chroma_instra_sample_correction_offset;
1750     s_inp_chroma.i4_element_size = 1;
1751     s_inp_chroma.i4_num_element_stride = u4_ref_uv_stride;
1752 
1753     s_ref_mb_mode.pv_buffer = ps_svc_dec_ref_layer->ps_inter_lyr_mb_prms_frm_start;
1754     s_ref_mb_mode.i4_element_size = sizeof(inter_lyr_mb_prms_t);
1755     s_ref_mb_mode.i4_num_element_stride = ps_svc_dec_ref_layer->u2_inter_lyr_mb_prms_stride;
1756 
1757     s_mb_coord.u2_mb_x = ps_cur_mb_info->u2_mbx;
1758     s_mb_coord.u2_mb_y = ps_cur_mb_info->u2_mby;
1759 
1760     if(SVCD_TRUE == ps_svc_lyr_dec->s_res_prms.u1_dyadic_flag)
1761     {
1762         ret = isvcd_intra_resamp_mb_dyadic(ps_ctxt, &s_inp_luma, &s_inp_chroma, &s_ref_mb_mode,
1763                                            &s_out_luma, &s_out_chroma, &s_mb_coord, ps_svc_lyr_dec);
1764     }
1765     else
1766     {
1767         ret = isvcd_intra_resamp_mb(ps_ctxt, &s_inp_luma, &s_inp_chroma, &s_ref_mb_mode,
1768                                     &s_out_luma, &s_out_chroma, &s_mb_coord);
1769     }
1770     if(OK != ret) return ret;
1771     return OK;
1772 }
1773 /*!
1774 **************************************************************************
1775 * \if Function name : isvcd_process_residual_resample_mb \endif
1776 *
1777 * \brief
1778 *    This function decodes a residual resample mb
1779 *
1780 *
1781 * \return
1782 *
1783 **************************************************************************
1784 */
isvcd_process_residual_resample_mb(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info)1785 WORD32 isvcd_process_residual_resample_mb(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
1786                                           dec_mb_info_t *ps_cur_mb_info)
1787 {
1788     residual_sampling_ctxt_t *ps_ctxt;
1789     svc_dec_lyr_struct_t *ps_svc_dec_ref_layer;
1790     res_lyr_ctxt *ps_lyr_ctxt;
1791     mem_element_t s_ref_mb_mode = {0};
1792     mem_element_t s_inp_luma = {0};
1793     mem_element_t s_inp_chroma = {0};
1794     mem_element_t s_out_luma = {0};
1795     mem_element_t s_out_chroma = {0};
1796 
1797     /* projected locations pointer */
1798     ref_mb_map_t *ps_x_off_len_luma;
1799     ref_mb_map_t *ps_y_off_len_luma;
1800     ref_mb_map_t *ps_x_off_len_chroma;
1801     ref_mb_map_t *ps_y_off_len_chroma;
1802     WORD32 i4_ref_x_luma, i4_ref_y_luma;
1803     WORD32 i4_ref_x_chroma, i4_ref_y_chroma;
1804     WORD32 i4_ref_luma_ressam_correction_offset = 0;
1805     WORD32 i4_ref_chroma_ressam_correction_offset = 0;
1806     WORD32 i4_inp_luma_stride, i4_inp_chroma_stride;
1807     WORD32 i4_out_luma_stride, i4_out_chroma_stride;
1808     WORD32 i4_inp_luma_offset = 0, i4_inp_chroma_offset = 0;
1809     WORD32 ret;
1810 
1811     ps_svc_dec_ref_layer = ps_svc_lyr_dec->ps_dec_svc_ref_layer;
1812     ps_ctxt = (residual_sampling_ctxt_t *) ps_svc_lyr_dec->pv_residual_sample_ctxt;
1813     ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
1814 
1815     i4_inp_luma_stride = ps_svc_dec_ref_layer->u2_residual_resample_luma_stride;
1816     i4_inp_chroma_stride = ps_svc_dec_ref_layer->u2_residual_resample_chroma_stride;
1817     i4_out_luma_stride = ps_svc_lyr_dec->u2_residual_resample_luma_stride;
1818     i4_out_chroma_stride = ps_svc_lyr_dec->u2_residual_resample_chroma_stride;
1819 
1820     {
1821         residual_samp_map_ctxt_t *ps_luma_map, *ps_chroma_map;
1822 
1823         ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
1824         ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
1825         ps_x_off_len_luma = ps_luma_map->ps_x_offset_length;
1826         ps_y_off_len_luma = ps_luma_map->ps_y_offset_length;
1827         ps_x_off_len_chroma = ps_chroma_map->ps_x_offset_length;
1828         ps_y_off_len_chroma = ps_chroma_map->ps_y_offset_length;
1829     }
1830     i4_ref_x_luma = ps_svc_lyr_dec->ps_ressam_luma_map_horz[ps_cur_mb_info->u2_mbx].i2_offset;
1831     i4_ref_y_luma = ps_svc_lyr_dec->ps_ressam_luma_map_vert[ps_cur_mb_info->u2_mby].i2_offset;
1832 
1833     i4_ref_x_chroma = ps_svc_lyr_dec->ps_ressam_chroma_map_horz[ps_cur_mb_info->u2_mbx].i2_offset;
1834     i4_ref_y_chroma = ps_svc_lyr_dec->ps_ressam_chroma_map_vert[ps_cur_mb_info->u2_mby].i2_offset;
1835 
1836     i4_ref_x_luma = CLIP3(0, (ps_lyr_ctxt->i4_ref_width - 1), i4_ref_x_luma);
1837     i4_ref_y_luma = CLIP3(0, (ps_lyr_ctxt->i4_ref_height - 1), i4_ref_y_luma);
1838     i4_ref_x_chroma = CLIP3(0, ((ps_lyr_ctxt->i4_ref_width >> 1) - 1), i4_ref_x_chroma);
1839     i4_ref_y_chroma = CLIP3(0, ((ps_lyr_ctxt->i4_ref_height >> 1) - 1), i4_ref_y_chroma);
1840 
1841     {
1842         WORD32 i4_offset_x, i4_offset_y;
1843 
1844         i4_offset_x = ps_x_off_len_luma[ps_cur_mb_info->u2_mbx].i2_offset;
1845         i4_offset_y = ps_y_off_len_luma[ps_cur_mb_info->u2_mby].i2_offset;
1846 
1847         /* check for offsets inside frame dimensions */
1848         if(0 <= i4_offset_x)
1849         {
1850             /* validity of pointer passed */
1851             if(!(i4_offset_x >= i4_ref_x_luma))
1852             {
1853                 return NOT_OK;
1854             }
1855             i4_inp_luma_offset += (i4_offset_x - i4_ref_x_luma);
1856         }
1857 
1858         if(0 <= i4_offset_y)
1859         {
1860             /* validity of pointer passed */
1861             if(!(i4_offset_y >= i4_ref_y_luma))
1862             {
1863                 return NOT_OK;
1864             }
1865             i4_inp_luma_offset += (i4_offset_y - i4_ref_y_luma) * i4_inp_luma_stride;
1866         }
1867 
1868         i4_offset_x = ps_x_off_len_chroma[ps_cur_mb_info->u2_mbx].i2_offset;
1869         i4_offset_y = ps_y_off_len_chroma[ps_cur_mb_info->u2_mby].i2_offset;
1870 
1871         /* check for offsets inside frame dimensions */
1872         if(0 <= i4_offset_x)
1873         {
1874             /* validity of pointer passed */
1875             if(!(i4_offset_x >= i4_ref_x_chroma))
1876             {
1877                 return NOT_OK;
1878             }
1879             i4_inp_chroma_offset += (i4_offset_x - i4_ref_x_chroma) << 1;
1880         }
1881 
1882         if(0 <= i4_offset_y)
1883         {
1884             /* validity of pointer passed */
1885             if(!(i4_offset_y >= i4_ref_y_chroma))
1886             {
1887                 return NOT_OK;
1888             }
1889             i4_inp_chroma_offset += (i4_offset_y - i4_ref_y_chroma) * (i4_inp_chroma_stride << 1);
1890         }
1891     }
1892 
1893     i4_ref_luma_ressam_correction_offset = i4_ref_x_luma + (i4_ref_y_luma) *i4_inp_luma_stride;
1894 
1895     s_inp_luma.pv_buffer = ps_svc_dec_ref_layer->pi2_il_residual_resample_mb_luma_frm_start +
1896                            i4_inp_luma_offset + i4_ref_luma_ressam_correction_offset;
1897     s_inp_luma.i4_element_size = 1;
1898     s_inp_luma.i4_num_element_stride = i4_inp_luma_stride;
1899 
1900     i4_ref_chroma_ressam_correction_offset =
1901         (i4_ref_x_chroma << 1) + (i4_ref_y_chroma) *i4_inp_chroma_stride;
1902 
1903     s_inp_chroma.pv_buffer = ps_svc_dec_ref_layer->pi2_il_residual_resample_mb_chroma_frm_start +
1904                              i4_inp_chroma_offset + i4_ref_chroma_ressam_correction_offset;
1905     s_inp_chroma.i4_element_size = 1;
1906     s_inp_chroma.i4_num_element_stride = i4_inp_luma_stride;
1907 
1908     s_ref_mb_mode.pv_buffer = ps_svc_dec_ref_layer->ps_inter_lyr_mb_prms_frm_start;
1909     s_ref_mb_mode.i4_element_size = sizeof(inter_lyr_mb_prms_t);
1910     s_ref_mb_mode.i4_num_element_stride = ps_svc_dec_ref_layer->u2_inter_lyr_mb_prms_stride;
1911 
1912     s_out_luma.i4_element_size = 1;
1913     s_out_luma.pv_buffer =
1914         ps_svc_lyr_dec->pi2_il_residual_resample_mb_luma_frm_start +
1915         ((ps_cur_mb_info->u2_mbx << 4) +
1916          (i4_out_luma_stride * (ps_cur_mb_info->u2_mby << 4)) * s_out_luma.i4_element_size);
1917 
1918     s_out_luma.i4_num_element_stride = i4_out_luma_stride;
1919 
1920     s_out_chroma.i4_element_size = 1;
1921     s_out_chroma.pv_buffer =
1922         ps_svc_lyr_dec->pi2_il_residual_resample_mb_chroma_frm_start +
1923         ((ps_cur_mb_info->u2_mbx << 4) +
1924          (i4_out_chroma_stride * (ps_cur_mb_info->u2_mby << 3)) * s_out_chroma.i4_element_size);
1925     s_out_chroma.i4_num_element_stride = i4_out_chroma_stride;
1926 
1927     ret = ps_lyr_ctxt->pf_residual_samp_mb(ps_ctxt, &s_inp_luma, &s_inp_chroma, &s_ref_mb_mode,
1928                                            &s_out_luma, &s_out_chroma, ps_cur_mb_info->u2_mbx,
1929                                            ps_cur_mb_info->u2_mby);
1930     if(ret != OK)
1931     {
1932         return ret;
1933     }
1934     return OK;
1935 }
1936 
1937 /*!
1938  **************************************************************************
1939  * \if Function name : isvcd_process_inter_mb_rsd_pred_target_lyr \endif
1940  *
1941  * \brief IT+ Residual + Recon
1942  *    This function decodes an Inter MB.
1943  *
1944  *
1945  * \return
1946  *    0 on Success and Error code otherwise
1947  **************************************************************************
1948  */
isvcd_process_inter_mb_rsd_pred_target_lyr(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mb_num,UWORD8 u1_inference_mode,UWORD16 * pu2_res_luma_csbp)1949 WORD32 isvcd_process_inter_mb_rsd_pred_target_lyr(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
1950                                                   dec_mb_info_t *ps_cur_mb_info, UWORD8 u1_mb_num,
1951                                                   UWORD8 u1_inference_mode,
1952                                                   UWORD16 *pu2_res_luma_csbp)
1953 {
1954     UWORD8 *pu1_rec_y, *pu1_rec_u;
1955     dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1956     UWORD32 ui_rec_width, u4_recwidth_cr;
1957     UWORD16 u2_luma_stride, u2_chroma_stride;
1958     WORD16 *pi2_y_coeff, *pi2_luma_res_ptr, *pi2_chroma_res_ptr;
1959     UWORD32 u1_mb_field_decoding_flag;
1960     const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1961     UWORD32 uc_botMb;
1962     UWORD32 u4_num_pmbair;
1963     tfr_ctxt_t *ps_frame_buf = ps_dec->ps_frame_buf_ip_recon;
1964     UWORD32 u4_luma_dc_only_csbp = 0;
1965     UWORD32 u4_luma_dc_only_cbp = 0;
1966     UWORD16 u2_res_luma_csbp = 0;
1967     WORD32 ret;
1968 
1969     if(0 != ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1970     {
1971         return NOT_OK;
1972     }
1973     uc_botMb = 1 - ps_cur_mb_info->u1_topmb;
1974     u4_num_pmbair = (u1_mb_num >> u1_mbaff);
1975     u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
1976 
1977     pu1_rec_y = ps_frame_buf->pu1_dest_y + (u4_num_pmbair << 4);
1978     pu1_rec_u = ps_frame_buf->pu1_dest_u + (u4_num_pmbair << 3) * YUV420SP_FACTOR;
1979     ui_rec_width = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
1980     u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
1981 
1982     u2_luma_stride = ps_svc_lyr_dec->u2_residual_resample_luma_stride;
1983     pi2_luma_res_ptr = ps_svc_lyr_dec->pi2_il_residual_resample_mb_luma_frm_start +
1984                        (ps_cur_mb_info->u2_mbx << 4) +
1985                        ((ps_cur_mb_info->u2_mby << 4) * u2_luma_stride);
1986 
1987     u2_chroma_stride = ps_svc_lyr_dec->u2_residual_resample_chroma_stride;
1988     pi2_chroma_res_ptr = ps_svc_lyr_dec->pi2_il_residual_resample_mb_chroma_frm_start +
1989                          (ps_cur_mb_info->u2_mbx << 4) +
1990                          ((ps_cur_mb_info->u2_mby << 3) * u2_chroma_stride);
1991 
1992     ret = isvcd_process_residual_resample_mb(ps_svc_lyr_dec, ps_cur_mb_info);
1993     if(ret != OK)
1994     {
1995         return ret;
1996     }
1997     if(u1_mbaff)
1998     {
1999         if(uc_botMb)
2000         {
2001             pu1_rec_y += (u1_mb_field_decoding_flag ? (ui_rec_width >> 1) : (ui_rec_width << 4));
2002             pu1_rec_u +=
2003                 (u1_mb_field_decoding_flag ? (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
2004         }
2005     }
2006 
2007     if(!ps_cur_mb_info->u1_tran_form8x8)
2008     {
2009         u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec, ps_cur_mb_info, 0);
2010     }
2011     else
2012     {
2013         if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
2014         {
2015             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec, ps_cur_mb_info, 0);
2016         }
2017         else
2018         {
2019             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec, ps_cur_mb_info);
2020         }
2021     }
2022 
2023     *pu2_res_luma_csbp = 0;
2024     pi2_y_coeff = ps_dec->pi2_coeff_data;
2025 
2026     /* Inverse Transform and Reconstruction */
2027     if(ps_cur_mb_info->u1_cbp & 0x0f)
2028     {
2029         if(!ps_cur_mb_info->u1_tran_form8x8)
2030         {
2031             UWORD32 i;
2032             WORD16 ai2_tmp[16] = {0};
2033             for(i = 0; i < 16; i++)
2034             {
2035                 if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
2036                 {
2037                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
2038                     UWORD8 *pu1_pred_sblk =
2039                         pu1_rec_y + ((i & 0x3) * BLK_SIZE) + (i >> 2) * (ui_rec_width << 2);
2040                     WORD16 *pi2_out = pi2_luma_res_ptr + ((i & 0x3) * BLK_SIZE) +
2041                                       (i >> 2) * (u2_luma_stride << 2);
2042                     PROFILE_DISABLE_IQ_IT_RECON()
2043                     {
2044                         if(CHECKBIT(u4_luma_dc_only_csbp, i))
2045                         {
2046                             u2_res_luma_csbp =
2047                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_recon_luma_4x4_dc(
2048                                     pi2_level, pu1_pred_sblk, pi2_out, pu1_pred_sblk, ui_rec_width,
2049                                     u2_luma_stride, ui_rec_width,
2050                                     gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
2051                                     (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[3],
2052                                     ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0, NULL);
2053                         }
2054                         else
2055                         {
2056                             u2_res_luma_csbp =
2057                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_recon_luma_4x4(
2058                                     pi2_level, pu1_pred_sblk, pi2_out, pu1_pred_sblk, ui_rec_width,
2059                                     u2_luma_stride, ui_rec_width,
2060                                     gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
2061                                     (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[3],
2062                                     ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0, NULL);
2063                         }
2064                     }
2065                 }
2066                 else
2067                 {
2068                     UWORD8 *pu1_pred_sblk =
2069                         pu1_rec_y + ((i & 0x3) * BLK_SIZE) + (i >> 2) * (ui_rec_width << 2);
2070                     WORD16 *pi2_out = pi2_luma_res_ptr + ((i & 0x3) * BLK_SIZE) +
2071                                       (i >> 2) * (u2_luma_stride << 2);
2072 
2073                     u2_res_luma_csbp = ps_svc_lyr_dec->pf_pred_residual_recon_luma_4x4(
2074                         pu1_pred_sblk, pi2_out, pu1_pred_sblk, ui_rec_width, u2_luma_stride,
2075                         ui_rec_width);
2076                 }
2077                 *pu2_res_luma_csbp |= (u2_res_luma_csbp << i);
2078             }
2079         }
2080         else
2081         {
2082             WORD16 *pi2_scale_matrix_ptr;
2083             WORD32 i;
2084 
2085             pi2_scale_matrix_ptr = ps_dec->s_high_profile.i2_scalinglist8x8[1];
2086 
2087             for(i = 0; i < 4; i++)
2088             {
2089                 WORD16 ai2_tmp[64] = {0};
2090                 WORD16 *pi16_levelBlock =
2091                     pi2_y_coeff + (i << 6); /* move to the next 8x8 adding 64 */
2092 
2093                 UWORD8 *pu1_pred_sblk =
2094                     pu1_rec_y + ((i & 0x1) * BLK8x8SIZE) + (i >> 1) * (ui_rec_width << 3);
2095                 WORD16 *pi2_out =
2096                     pi2_luma_res_ptr + ((i & 0x1) * BLK8x8SIZE) + (i >> 1) * (u2_luma_stride << 3);
2097                 if(CHECKBIT(ps_cur_mb_info->u1_cbp, i))
2098                 {
2099                     PROFILE_DISABLE_IQ_IT_RECON()
2100                     {
2101                         if(CHECKBIT(u4_luma_dc_only_cbp, i))
2102                         {
2103                             u2_res_luma_csbp =
2104                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_recon_luma_8x8_dc(
2105                                     pi16_levelBlock, pu1_pred_sblk, pi2_out, pu1_pred_sblk,
2106                                     ui_rec_width, u2_luma_stride, ui_rec_width,
2107                                     gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
2108                                     (UWORD16 *) pi2_scale_matrix_ptr, ps_cur_mb_info->u1_qp_div6,
2109                                     ai2_tmp, 0, NULL);
2110                         }
2111                         else
2112                         {
2113                             u2_res_luma_csbp =
2114                                 ps_svc_lyr_dec->pf_iquant_itrans_residual_recon_luma_8x8(
2115                                     pi16_levelBlock, pu1_pred_sblk, pi2_out, pu1_pred_sblk,
2116                                     ui_rec_width, u2_luma_stride, ui_rec_width,
2117                                     gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
2118                                     (UWORD16 *) pi2_scale_matrix_ptr, ps_cur_mb_info->u1_qp_div6,
2119                                     ai2_tmp, 0, NULL);
2120                         }
2121                     }
2122                 }
2123                 else
2124                 {
2125                     UWORD8 *pu1_pred_sblk =
2126                         pu1_rec_y + ((i & 0x1) * BLK8x8SIZE) + (i >> 1) * (ui_rec_width << 3);
2127                     WORD16 *pi2_out = pi2_luma_res_ptr + ((i & 0x1) * BLK8x8SIZE) +
2128                                       (i >> 1) * (u2_luma_stride << 3);
2129 
2130                     u2_res_luma_csbp = ps_svc_lyr_dec->pf_pred_residual_recon_luma_8x8(
2131                         pu1_pred_sblk, pi2_out, pu1_pred_sblk, ui_rec_width, u2_luma_stride,
2132                         ui_rec_width);
2133                 }
2134                 *pu2_res_luma_csbp |= (u2_res_luma_csbp << (((i >> 1) << 3) + ((i & 0x01) << 1)));
2135             }
2136         }
2137     }
2138     else
2139     {
2140         UWORD8 *pu1_pred_sblk = pu1_rec_y;
2141         WORD16 *pi2_out = pi2_luma_res_ptr;
2142 
2143         *pu2_res_luma_csbp = ps_svc_lyr_dec->pf_pred_residual_recon_luma_16x16(
2144             pu1_pred_sblk, pi2_out, pu1_pred_sblk, ui_rec_width, u2_luma_stride, ui_rec_width);
2145     }
2146 
2147     /* Decode Chroma Block */
2148     ih264d_unpack_chroma_coeff4x4_mb(ps_dec, ps_cur_mb_info);
2149     /*--------------------------------------------------------------------*/
2150     /* Chroma Blocks decoding                                             */
2151     /*--------------------------------------------------------------------*/
2152     {
2153         UWORD8 u1_chroma_cbp = (UWORD8) (ps_cur_mb_info->u1_cbp >> 4);
2154 
2155         if(u1_chroma_cbp != CBPC_ALLZERO)
2156         {
2157             UWORD32 u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
2158             UWORD32 u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
2159             UWORD16 u2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
2160 
2161             pi2_y_coeff = ps_dec->pi2_coeff_data;
2162 
2163             {
2164                 UWORD32 i;
2165                 WORD16 ai2_tmp[16] = {0};
2166                 for(i = 0; i < 4; i++)
2167                 {
2168                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
2169                     UWORD8 *pu1_pred_sblk = pu1_rec_u + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR) +
2170                                             (i >> 1) * (u4_recwidth_cr << 2);
2171                     WORD16 *pi2_out = pi2_chroma_res_ptr +
2172                                       ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR) +
2173                                       (i >> 1) * (u2_chroma_stride << 2);
2174                     PROFILE_DISABLE_IQ_IT_RECON()
2175                     {
2176                         if(CHECKBIT(u2_chroma_csbp, i))
2177                         {
2178                             ps_svc_lyr_dec->pf_iquant_itrans_residual_recon_chroma_4x4(
2179                                 pi2_level, pu1_pred_sblk, pi2_out, pu1_pred_sblk, u4_recwidth_cr,
2180                                 u2_chroma_stride, u4_recwidth_cr,
2181                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
2182                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[4], u4_scale_u,
2183                                 ai2_tmp, pi2_level);
2184                         }
2185                         else if(pi2_level[0] != 0)
2186                         {
2187                             ps_svc_lyr_dec->pf_iquant_itrans_residual_recon_chroma_4x4_dc(
2188                                 pi2_level, pu1_pred_sblk, pi2_out, pu1_pred_sblk, u4_recwidth_cr,
2189                                 u2_chroma_stride, u4_recwidth_cr,
2190                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
2191                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[4], u4_scale_u,
2192                                 ai2_tmp, pi2_level);
2193                         }
2194                         else
2195                         {
2196                             ps_svc_lyr_dec->pf_pred_residual_recon_chroma_4x4(
2197                                 pu1_pred_sblk, pi2_out, pu1_pred_sblk, u4_recwidth_cr,
2198                                 u2_chroma_stride, u4_recwidth_cr);
2199                         }
2200                     }
2201                 }
2202             }
2203 
2204             pi2_y_coeff += MB_CHROM_SIZE;
2205             u2_chroma_csbp >>= 4;
2206 
2207             {
2208                 UWORD32 i;
2209                 WORD16 ai2_tmp[16] = {0};
2210                 for(i = 0; i < 4; i++)
2211                 {
2212                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
2213                     UWORD8 *pu1_pred_sblk = pu1_rec_u + 1 +
2214                                             ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR) +
2215                                             (i >> 1) * (u4_recwidth_cr << 2);
2216                     WORD16 *pi2_out = pi2_chroma_res_ptr + 1 +
2217                                       ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR) +
2218                                       (i >> 1) * (u2_chroma_stride << 2);
2219                     PROFILE_DISABLE_IQ_IT_RECON()
2220                     {
2221                         if(CHECKBIT(u2_chroma_csbp, i))
2222                         {
2223                             ps_svc_lyr_dec->pf_iquant_itrans_residual_recon_chroma_4x4(
2224                                 pi2_level, pu1_pred_sblk, pi2_out, pu1_pred_sblk, u4_recwidth_cr,
2225                                 u2_chroma_stride, u4_recwidth_cr,
2226                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
2227                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[5], u4_scale_v,
2228                                 ai2_tmp, pi2_level);
2229                         }
2230                         else if(pi2_level[0] != 0)
2231                         {
2232                             ps_svc_lyr_dec->pf_iquant_itrans_residual_recon_chroma_4x4_dc(
2233                                 pi2_level, pu1_pred_sblk, pi2_out, pu1_pred_sblk, u4_recwidth_cr,
2234                                 u2_chroma_stride, u4_recwidth_cr,
2235                                 gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
2236                                 (UWORD16 *) ps_dec->s_high_profile.i2_scalinglist4x4[5], u4_scale_v,
2237                                 ai2_tmp, pi2_level);
2238                         }
2239                         else
2240                         {
2241                             ps_svc_lyr_dec->pf_pred_residual_recon_chroma_4x4(
2242                                 pu1_pred_sblk, pi2_out, pu1_pred_sblk, u4_recwidth_cr,
2243                                 u2_chroma_stride, u4_recwidth_cr);
2244                         }
2245                     }
2246                 }
2247             }
2248         }
2249         else
2250         {
2251             /* Cr*/
2252             {
2253                 UWORD8 *pu1_pred_sblk = pu1_rec_u;
2254                 WORD16 *pi2_out = pi2_chroma_res_ptr;
2255 
2256                 ps_svc_lyr_dec->pf_pred_residual_recon_chroma_8x8(pu1_pred_sblk, pi2_out,
2257                                                                   pu1_pred_sblk, u4_recwidth_cr,
2258                                                                   u2_chroma_stride, u4_recwidth_cr);
2259             }
2260 
2261             /* Cb*/
2262             {
2263                 UWORD8 *pu1_pred_sblk = pu1_rec_u + 1;
2264                 WORD16 *pi2_out = pi2_chroma_res_ptr + 1;
2265                 ps_svc_lyr_dec->pf_pred_residual_recon_chroma_8x8(pu1_pred_sblk, pi2_out,
2266                                                                   pu1_pred_sblk, u4_recwidth_cr,
2267                                                                   u2_chroma_stride, u4_recwidth_cr);
2268             }
2269         }
2270     }
2271     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb =
2272         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start + ps_cur_mb_info->u2_mbx +
2273         (ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride * (ps_cur_mb_info->u2_mby));
2274     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_mb_mode =
2275         u1_inference_mode ? SVC_IBL_MB : SVC_INTER_MB;
2276     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->i1_tx_size = ps_cur_mb_info->u1_tran_form8x8;
2277     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u2_luma_nnz = ps_cur_mb_info->u2_luma_csbp;
2278     ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz =
2279         (UWORD8) ps_cur_mb_info->u2_chroma_csbp;
2280     if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag, 1))
2281     {
2282         /* Four bits for Cb in DC only cbp */
2283         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz |= 0x0F;
2284     }
2285     if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag, 2))
2286     {
2287         /* Four bits for Cr in DC only cbp */
2288         ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb->u1_chroma_nnz |= 0xF0;
2289     }
2290     return (0);
2291 }
2292