Home | History | Annotate | Download | only in decoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2015 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at:
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  *
     17  *****************************************************************************
     18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
     19 */
     20 /*!
     21  **************************************************************************
     22  * \file ih264d_process_pslice.c
     23  *
     24  * \brief
     25  *    Contains routines that decode a I slice type
     26  *
     27  * Detailed_description
     28  *
     29  * \date
     30  *    21/12/2002
     31  *
     32  * \author  NS
     33  **************************************************************************
     34  */
     35 #include "ih264_typedefs.h"
     36 #include "ih264_macros.h"
     37 #include "ih264_platform_macros.h"
     38 
     39 #include <string.h>
     40 #include "ih264d_bitstrm.h"
     41 #include "ih264d_defs.h"
     42 #include "ih264d_debug.h"
     43 #include "ih264d_structs.h"
     44 #include "ih264d_defs.h"
     45 #include "ih264d_parse_cavlc.h"
     46 #include "ih264d_mb_utils.h"
     47 #include "ih264d_deblocking.h"
     48 #include "ih264d_dpb_manager.h"
     49 #include "ih264d_mvpred.h"
     50 #include "ih264d_inter_pred.h"
     51 #include "ih264d_process_pslice.h"
     52 #include "ih264d_error_handler.h"
     53 #include "ih264d_cabac.h"
     54 #include "ih264d_debug.h"
     55 #include "ih264d_tables.h"
     56 #include "ih264d_parse_slice.h"
     57 #include "ih264d_utils.h"
     58 #include "ih264d_parse_islice.h"
     59 #include "ih264d_process_bslice.h"
     60 #include "ih264d_process_intra_mb.h"
     61 
     62 void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
     63 
     64 void ih264d_insert_pic_in_ref_pic_listx(struct pic_buffer_t *ps_ref_pic_buf_lx,
     65                                         struct pic_buffer_t *ps_pic)
     66 {
     67     *ps_ref_pic_buf_lx = *ps_pic;
     68 }
     69 
     70 WORD32 ih264d_mv_pred_ref_tfr_nby2_pmb(dec_struct_t * ps_dec,
     71                                      UWORD8 u1_mb_idx,
     72                                      UWORD8 u1_num_mbs)
     73 {
     74     parse_pmbarams_t * ps_mb_part_info;
     75     parse_part_params_t * ps_part;
     76     mv_pred_t *ps_mv_nmb, *ps_mv_nmb_start, *ps_mv_ntop, *ps_mv_ntop_start;
     77     UWORD32 i, j;
     78     const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
     79     dec_mb_info_t * ps_cur_mb_info;
     80     WORD32 i2_mv_x, i2_mv_y;
     81     WORD32 ret;
     82 
     83     ps_dec->i4_submb_ofst -= (u1_num_mbs - u1_mb_idx) << 4;
     84     ps_mb_part_info = ps_dec->ps_parse_mb_data; // + u1_mb_idx;
     85     ps_part = ps_dec->ps_parse_part_params; // + u1_mb_idx;
     86 
     87     /* N/2 Mb MvPred and Transfer Setup Loop */
     88     for(i = u1_mb_idx; i < u1_num_mbs; i++, ps_mb_part_info++)
     89     {
     90         UWORD32 u1_colz;
     91         UWORD32 u1_field;
     92         mv_pred_t s_mvPred;
     93         mv_pred_t *ps_mv_pred = &s_mvPred;
     94 
     95 
     96 
     97         *ps_mv_pred = ps_dec->s_default_mv_pred;
     98 
     99         ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
    100 
    101         /* Restore the slice scratch MbX and MbY context */
    102         ps_cur_mb_info = ps_dec->ps_nmb_info + i;
    103         u1_field = ps_cur_mb_info->u1_mb_field_decodingflag;
    104 
    105 
    106 
    107         ps_mv_nmb_start = ps_dec->ps_mv_cur + (i << 4);
    108         ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
    109         ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
    110         ps_dec->u2_mv_2mb[i & 0x1] = 0;
    111 
    112         /* Look for MV Prediction and Reference Transfer in Non-I Mbs */
    113         if(!ps_mb_part_info->u1_isI_mb)
    114         {
    115             UWORD32 u1_blk_no;
    116             WORD32 i1_ref_idx, i1_ref_idx1;
    117             UWORD32 u1_sub_mb_x, u1_sub_mb_y, u1_sub_mb_num;
    118             UWORD32 u1_num_part, u1_num_ref, u1_wd, u1_ht;
    119             UWORD32 *pu4_wt_offst, **ppu4_wt_ofst;
    120             UWORD32 u1_scale_ref, u4_bot_mb;
    121             WORD8 *pi1_ref_idx = ps_mb_part_info->i1_ref_idx[0];
    122             pic_buffer_t *ps_ref_frame, **pps_ref_frame;
    123             deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + i;
    124 
    125             /* MB Level initialisations */
    126             ps_dec->u4_num_pmbair = i >> u1_mbaff;
    127             ps_dec->u1_mb_idx_mv = i;
    128             ppu4_wt_ofst = ps_mb_part_info->pu4_wt_offst;
    129             pps_ref_frame = ps_dec->ps_ref_pic_buf_lx[0];
    130             /* CHANGED CODE */
    131             ps_mv_ntop_start = ps_mv_nmb_start
    132                             - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12;
    133 
    134             u1_num_part = ps_mb_part_info->u1_num_part;
    135             ps_cur_deblk_mb->u1_mb_type |= (u1_num_part > 1) << 1;
    136             ps_cur_mb_info->u4_pred_info_pkd_idx = ps_dec->u4_pred_info_pkd_idx;
    137             ps_cur_mb_info->u1_num_pred_parts = 0;
    138 
    139 
    140             /****************************************************/
    141             /* weighted u4_ofst pointer calculations, this loop  */
    142             /* runs maximum 4 times, even in direct cases       */
    143             /****************************************************/
    144             u1_scale_ref = u1_mbaff & u1_field;
    145 
    146             u4_bot_mb = 1 - ps_cur_mb_info->u1_topmb;
    147             if(ps_dec->ps_cur_pps->u1_wted_pred_flag)
    148             {
    149                 u1_num_ref = MIN(u1_num_part, 4);
    150                 for(u1_blk_no = 0; u1_blk_no < u1_num_ref; u1_blk_no++)
    151                 {
    152                     i1_ref_idx = pi1_ref_idx[u1_blk_no];
    153                     if(u1_scale_ref)
    154                         i1_ref_idx >>= 1;
    155                     pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[2
    156                                     * X3(i1_ref_idx)];
    157                     ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
    158                 }
    159             }
    160             else
    161             {
    162                 ppu4_wt_ofst[0] = NULL;
    163                 ppu4_wt_ofst[1] = NULL;
    164                 ppu4_wt_ofst[2] = NULL;
    165                 ppu4_wt_ofst[3] = NULL;
    166             }
    167 
    168             /**************************************************/
    169             /* Loop on Partitions                             */
    170             /**************************************************/
    171             for(j = 0; j < u1_num_part; j++, ps_part++)
    172             {
    173 
    174                 u1_sub_mb_num = ps_part->u1_sub_mb_num;
    175                 ps_dec->u1_sub_mb_num = u1_sub_mb_num;
    176 
    177                 if(PART_NOT_DIRECT != ps_part->u1_is_direct)
    178                 {
    179                     /* Mb Skip Mode */
    180                     /* Setting the default and other members of MvPred Structure */
    181                     s_mvPred.i2_mv[2] = -1;
    182                     s_mvPred.i2_mv[3] = -1;
    183                     s_mvPred.i1_ref_frame[0] = 0;
    184                     i1_ref_idx = (u1_scale_ref && u4_bot_mb) ? MAX_REF_BUFS : 0;
    185                     ps_ref_frame = pps_ref_frame[i1_ref_idx];
    186                     s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
    187                     s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
    188                     pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[0];
    189 
    190                     ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb_start,
    191                                       ps_mv_ntop_start, &s_mvPred, 0, 4, 0, 1,
    192                                       MB_SKIP);
    193 
    194 
    195 
    196 
    197 
    198 
    199                     {
    200                         pred_info_pkd_t *ps_pred_pkd;
    201                         ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
    202                     ih264d_fill_pred_info (s_mvPred.i2_mv,4,4,0,PRED_L0,ps_pred_pkd,ps_ref_frame->u1_pic_buf_id,
    203                                            (i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
    204                                            ps_ref_frame->u1_pic_type);
    205 
    206 
    207                     ps_dec->u4_pred_info_pkd_idx++;
    208                     ps_cur_mb_info->u1_num_pred_parts++;
    209                     }
    210 
    211 
    212 
    213                     /* Storing colocated zero information */
    214                     u1_colz = ((ABS(s_mvPred.i2_mv[0]) <= 1)
    215                                     && (ABS(s_mvPred.i2_mv[1]) <= 1))
    216                                     + (u1_field << 1);
    217 
    218                     ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
    219                                        u1_colz, 4, 4);
    220                 }
    221                 else
    222                 {
    223                     u1_sub_mb_x = u1_sub_mb_num & 0x03;
    224                     u1_sub_mb_y = u1_sub_mb_num >> 2;
    225                     u1_blk_no =
    226                                     (u1_num_part < 4) ?
    227                                                     j :
    228                                                     (((u1_sub_mb_y >> 1) << 1)
    229                                                                     + (u1_sub_mb_x
    230                                                                                     >> 1));
    231 
    232                     ps_mv_ntop = ps_mv_ntop_start + u1_sub_mb_x;
    233                     ps_mv_nmb = ps_mv_nmb_start + u1_sub_mb_num;
    234 
    235                     u1_wd = ps_part->u1_partwidth;
    236                     u1_ht = ps_part->u1_partheight;
    237 
    238                     /* Populate the colpic info and reference frames */
    239                     i1_ref_idx = pi1_ref_idx[u1_blk_no];
    240                     s_mvPred.i1_ref_frame[0] = i1_ref_idx;
    241 
    242                     /********************************************************/
    243                     /* Predict Mv                                           */
    244                     /* Add Mv Residuals and store back                      */
    245                     /********************************************************/
    246                     ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb, ps_mv_ntop,
    247                                       &s_mvPred, u1_sub_mb_num, u1_wd, 0, 1,
    248                                       ps_cur_mb_info->u1_mb_mc_mode);
    249                     i2_mv_x = ps_mv_nmb->i2_mv[0];
    250                     i2_mv_y = ps_mv_nmb->i2_mv[1];
    251                     i2_mv_x += s_mvPred.i2_mv[0];
    252                     i2_mv_y += s_mvPred.i2_mv[1];
    253                     s_mvPred.i2_mv[0] = i2_mv_x;
    254                     s_mvPred.i2_mv[1] = i2_mv_y;
    255 
    256                     /********************************************************/
    257                     /* Transfer setup call                                  */
    258                     /* convert RefIdx if it is MbAff                        */
    259                     /* Pass Weight Offset and refFrame                      */
    260                     /********************************************************/
    261                     i1_ref_idx1 = i1_ref_idx >> u1_scale_ref;
    262                     if(u1_scale_ref && ((i1_ref_idx & 0x01) != u4_bot_mb))
    263                         i1_ref_idx1 += MAX_REF_BUFS;
    264                     ps_ref_frame = pps_ref_frame[i1_ref_idx1];
    265                     pu4_wt_offst = ppu4_wt_ofst[u1_blk_no];
    266 
    267 
    268 
    269 
    270 
    271 
    272                     {
    273                     pred_info_pkd_t *ps_pred_pkd;
    274                     ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
    275                     ih264d_fill_pred_info (s_mvPred.i2_mv,u1_wd,u1_ht,u1_sub_mb_num,PRED_L0,ps_pred_pkd,
    276                                            ps_ref_frame->u1_pic_buf_id,(i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
    277                                            ps_ref_frame->u1_pic_type);
    278 
    279                     ps_dec->u4_pred_info_pkd_idx++;
    280                     ps_cur_mb_info->u1_num_pred_parts++;
    281                     }
    282 
    283 
    284 
    285                     /* Fill colocated info in MvPred structure */
    286                     s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
    287                     s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
    288 
    289                     /* Calculating colocated zero information */
    290                     u1_colz =
    291                                     (u1_field << 1)
    292                                                     | ((i1_ref_idx == 0)
    293                                                                     && (ABS(i2_mv_x)
    294                                                                                     <= 1)
    295                                                                     && (ABS(i2_mv_y)
    296                                                                                     <= 1));
    297                     u1_colz |= ps_mb_part_info->u1_col_info[u1_blk_no];
    298 
    299                     /* Replicate the motion vectors and colzero u4_flag  */
    300                     /* for all sub-partitions                         */
    301 
    302                     ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb,
    303                                        u1_sub_mb_num, u1_colz, u1_ht,
    304                                        u1_wd);
    305                 }
    306             }
    307 
    308         }
    309         else
    310         {
    311             /* Storing colocated zero information */
    312             ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
    313                                (UWORD8)(u1_field << 1), 4, 4);
    314 
    315         }
    316         /*if num _cores is set to 3,compute bs will be done in another thread*/
    317         if(ps_dec->u4_num_cores < 3)
    318         {
    319 
    320             if(ps_dec->u4_app_disable_deblk_frm == 0)
    321                 ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
    322                                      (UWORD16)(i >> u1_mbaff));
    323         }
    324     }
    325 
    326 
    327 
    328     return OK;
    329 }
    330 
    331 
    332 WORD32 ih264d_decode_recon_tfr_nmb(dec_struct_t * ps_dec,
    333                                    UWORD8 u1_mb_idx,
    334                                    UWORD8 u1_num_mbs,
    335                                    UWORD8 u1_num_mbs_next,
    336                                    UWORD8 u1_tfr_n_mb,
    337                                    UWORD8 u1_end_of_row)
    338 {
    339     WORD32 i,j;
    340     UWORD32 u1_end_of_row_next;
    341     dec_mb_info_t * ps_cur_mb_info;
    342     UWORD32 u4_update_mbaff = 0;
    343     WORD32 ret;
    344     const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
    345     const UWORD32 u1_slice_type = ps_dec->ps_cur_slice->u1_slice_type;
    346     const WORD32 u1_skip_th = (
    347                     (u1_slice_type != I_SLICE) ?
    348                                     (ps_dec->u1_B ? B_8x8 : PRED_8x8R0) : -1);
    349     const UWORD32 u1_ipcm_th = (
    350                     (u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? 23 : 5) : 0);
    351 
    352 
    353 
    354 
    355 
    356     /* N Mb MC Loop */
    357     for(i = u1_mb_idx; i < u1_num_mbs; i++)
    358     {
    359         ps_cur_mb_info = ps_dec->ps_nmb_info + i;
    360         ps_dec->u4_dma_buf_idx = 0;
    361         ps_dec->u4_pred_info_idx = 0;
    362 
    363         if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
    364         {
    365             {
    366                 WORD32 pred_cnt = 0;
    367                 pred_info_pkd_t *ps_pred_pkd;
    368                 UWORD32 u4_pred_info_pkd_idx;
    369                 WORD8 i1_pred;
    370 
    371                 u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
    372 
    373                 while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
    374                 {
    375 
    376                     ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
    377 
    378                      ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
    379                                                ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
    380                                          ps_cur_mb_info);
    381                     u4_pred_info_pkd_idx++;
    382                     pred_cnt++;
    383                 }
    384             }
    385 
    386             ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
    387 
    388         }
    389         else if(ps_cur_mb_info->u1_mb_type == MB_SKIP)
    390         {
    391             {
    392                 WORD32 pred_cnt = 0;
    393                 pred_info_pkd_t *ps_pred_pkd;
    394                 UWORD32 u4_pred_info_pkd_idx;
    395                 WORD8 i1_pred;
    396 
    397                 u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
    398 
    399                 while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
    400                 {
    401 
    402                     ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
    403 
    404                     ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
    405                                                ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
    406                                          ps_cur_mb_info);
    407 
    408                     u4_pred_info_pkd_idx++;
    409                     pred_cnt++;
    410                 }
    411             }
    412             /* Decode MB skip */
    413             ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
    414 
    415         }
    416 
    417      }
    418 
    419 
    420     /* N Mb IQ IT RECON  Loop */
    421     for(j = u1_mb_idx; j < i; j++)
    422     {
    423         ps_cur_mb_info = ps_dec->ps_nmb_info + j;
    424 
    425         if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
    426         {
    427             ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
    428 
    429         }
    430         else if(ps_cur_mb_info->u1_mb_type != MB_SKIP)
    431         {
    432             if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
    433             {
    434                 ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
    435                 ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
    436             }
    437         }
    438 
    439 
    440         if(ps_dec->u4_use_intrapred_line_copy)
    441         {
    442             ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
    443         }
    444 
    445     }
    446 
    447     /*N MB deblocking*/
    448     if(ps_dec->u4_nmb_deblk == 1)
    449     {
    450 
    451         UWORD32 u4_cur_mb, u4_right_mb;
    452         UWORD32 u4_mb_x, u4_mb_y;
    453         UWORD32 u4_wd_y, u4_wd_uv;
    454         tfr_ctxt_t *ps_tfr_cxt = &(ps_dec->s_tran_addrecon);
    455         UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
    456         const WORD32 i4_cb_qp_idx_ofst =
    457                        ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
    458         const WORD32 i4_cr_qp_idx_ofst =
    459                        ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
    460 
    461         u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
    462         u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
    463 
    464 
    465         ps_cur_mb_info = ps_dec->ps_nmb_info + u1_mb_idx;
    466 
    467         ps_dec->u4_deblk_mb_x = ps_cur_mb_info->u2_mbx;
    468         ps_dec->u4_deblk_mb_y = ps_cur_mb_info->u2_mby;
    469 
    470         for(j = u1_mb_idx; j < i; j++)
    471         {
    472 
    473             ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
    474                                        i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
    475                                         u4_wd_y, u4_wd_uv);
    476 
    477 
    478         }
    479 
    480 
    481 
    482     }
    483 
    484 
    485 
    486     if(u1_tfr_n_mb)
    487     {
    488         /****************************************************************/
    489         /* Check for End Of Row in Next iteration                       */
    490         /****************************************************************/
    491         u1_end_of_row_next =
    492                         u1_num_mbs_next
    493                                         && (u1_num_mbs_next
    494                                                         <= (ps_dec->u1_recon_mb_grp
    495                                                                         >> u1_mbaff));
    496 
    497         /****************************************************************/
    498         /* Transfer the Following things                                */
    499         /* N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )       */
    500         /* N-Mb Recon Data          ( To Ext Frame Buffer )             */
    501         /* N-Mb Intrapredline Data  ( Updated Internally)               */
    502         /* N-Mb MV Data             ( To Ext MV Buffer )                */
    503         /* N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)    */
    504         /****************************************************************/
    505         ih264d_transfer_mb_group_data(ps_dec, u1_num_mbs, u1_end_of_row,
    506                                       u1_end_of_row_next);
    507         ps_dec->u4_num_mbs_prev_nmb = u1_num_mbs;
    508 
    509         ps_dec->u4_pred_info_idx = 0;
    510         ps_dec->u4_dma_buf_idx = 0;
    511 
    512 
    513     }
    514     return OK;
    515 }
    516 
    517 /*!
    518  **************************************************************************
    519  * \if Function name : ih264d_process_inter_mb \endif
    520  *
    521  * \brief
    522  *    This function decodes an Inter MB.
    523  *
    524  *
    525  * \return
    526  *    0 on Success and Error code otherwise
    527  **************************************************************************
    528  */
    529 WORD32 ih264d_process_inter_mb(dec_struct_t * ps_dec,
    530                                dec_mb_info_t * ps_cur_mb_info,
    531                                UWORD8 u1_mb_num)
    532 {
    533     /* CHANGED CODE */
    534     UWORD8 *pu1_rec_y, *pu1_rec_u, *pu1_rec_v;
    535 
    536     /*CHANGED CODE */
    537     UWORD32 ui_rec_width, u4_recwidth_cr;
    538     WORD16 *pi2_y_coeff;
    539     UWORD32 u1_mb_field_decoding_flag;
    540     const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
    541     UWORD32 uc_botMb;
    542     UWORD32 u4_num_pmbair;
    543     /* CHANGED CODE */
    544     tfr_ctxt_t *ps_frame_buf = ps_dec->ps_frame_buf_ip_recon;
    545     UWORD32 u4_luma_dc_only_csbp = 0;
    546     UWORD32 u4_luma_dc_only_cbp = 0;
    547     /* CHANGED CODE */
    548 
    549     uc_botMb = 1 - ps_cur_mb_info->u1_topmb;
    550     u4_num_pmbair = (u1_mb_num >> u1_mbaff);
    551     u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
    552 
    553 
    554     /* CHANGED CODE */
    555     pu1_rec_y = ps_frame_buf->pu1_dest_y + (u4_num_pmbair << 4);
    556     pu1_rec_u =
    557                     ps_frame_buf->pu1_dest_u
    558                                     + (u4_num_pmbair << 3) * YUV420SP_FACTOR;
    559     pu1_rec_v = ps_frame_buf->pu1_dest_v + (u4_num_pmbair << 3);
    560     ui_rec_width = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
    561     u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
    562 
    563     /* CHANGED CODE */
    564 
    565     if(u1_mbaff)
    566     {
    567         if(uc_botMb)
    568         {
    569             pu1_rec_y += (u1_mb_field_decoding_flag ?
    570                             (ui_rec_width >> 1) : (ui_rec_width << 4));
    571             pu1_rec_u += (u1_mb_field_decoding_flag ?
    572                             (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
    573             pu1_rec_v += (u1_mb_field_decoding_flag ?
    574                             (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
    575         }
    576     }
    577 
    578     if(!ps_cur_mb_info->u1_tran_form8x8)
    579     {
    580         u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
    581                                        ps_cur_mb_info,
    582                                        0);
    583     }
    584     else
    585     {
    586         if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
    587         {
    588             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
    589                                            ps_cur_mb_info,
    590                                            0);
    591         }
    592         else
    593         {
    594             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec,
    595                                            ps_cur_mb_info);
    596         }
    597     }
    598 
    599     pi2_y_coeff = ps_dec->pi2_coeff_data;
    600     /* Inverse Transform and Reconstruction */
    601     if(ps_cur_mb_info->u1_cbp & 0x0f)
    602     {
    603         /* CHANGED CODE */
    604         if(!ps_cur_mb_info->u1_tran_form8x8)
    605         {
    606             UWORD32 i;
    607             WORD16 ai2_tmp[16];
    608             for(i = 0; i < 16; i++)
    609             {
    610                 if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
    611                 {
    612                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
    613                     UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x3) * BLK_SIZE)
    614                                     + (i >> 2) * (ui_rec_width << 2);
    615                     PROFILE_DISABLE_IQ_IT_RECON()
    616                     {
    617                         if(CHECKBIT(u4_luma_dc_only_csbp, i))
    618                         {
    619                             ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
    620                                             pi2_level,
    621                                             pu1_pred_sblk,
    622                                             pu1_pred_sblk,
    623                                             ui_rec_width,
    624                                             ui_rec_width,
    625                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
    626                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
    627                                             ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
    628                                             NULL);
    629                         }
    630                         else
    631                         {
    632                             ps_dec->pf_iquant_itrans_recon_luma_4x4(
    633                                             pi2_level,
    634                                             pu1_pred_sblk,
    635                                             pu1_pred_sblk,
    636                                             ui_rec_width,
    637                                             ui_rec_width,
    638                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
    639                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
    640                                             ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
    641                                             NULL);
    642                         }
    643                     }
    644                 }
    645             }
    646         }
    647         else
    648         {
    649             WORD16 *pi2_scale_matrix_ptr;
    650             WORD32 i;
    651 
    652             pi2_scale_matrix_ptr =
    653                             ps_dec->s_high_profile.i2_scalinglist8x8[1];
    654 
    655             for(i = 0; i < 4; i++)
    656             {
    657                 WORD16 ai2_tmp[64];
    658                 WORD16 *pi16_levelBlock = pi2_y_coeff + (i << 6); /* move to the next 8x8 adding 64 */
    659 
    660                 UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x1) * BLK8x8SIZE)
    661                                 + (i >> 1) * (ui_rec_width << 3);
    662                 if(CHECKBIT(ps_cur_mb_info->u1_cbp, i))
    663                 {
    664                     PROFILE_DISABLE_IQ_IT_RECON()
    665                     {
    666                         if(CHECKBIT(u4_luma_dc_only_cbp, i))
    667                         {
    668                             ps_dec->pf_iquant_itrans_recon_luma_8x8_dc(
    669                                             pi16_levelBlock,
    670                                             pu1_pred_sblk,
    671                                             pu1_pred_sblk,
    672                                             ui_rec_width,
    673                                             ui_rec_width,
    674                                             gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
    675                                             (UWORD16 *)pi2_scale_matrix_ptr,
    676                                             ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
    677                                             NULL);
    678                         }
    679                         else
    680                         {
    681                             ps_dec->pf_iquant_itrans_recon_luma_8x8(
    682                                             pi16_levelBlock,
    683                                             pu1_pred_sblk,
    684                                             pu1_pred_sblk,
    685                                             ui_rec_width,
    686                                             ui_rec_width,
    687                                             gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
    688                                             (UWORD16 *)pi2_scale_matrix_ptr,
    689                                             ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
    690                                             NULL);
    691                         }
    692                     }
    693                 }
    694             }
    695 
    696         }
    697     }
    698 
    699     /* Decode Chroma Block */
    700     ih264d_unpack_chroma_coeff4x4_mb(ps_dec,
    701                                      ps_cur_mb_info);
    702     /*--------------------------------------------------------------------*/
    703     /* Chroma Blocks decoding                                             */
    704     /*--------------------------------------------------------------------*/
    705     {
    706         UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
    707 
    708         if(u1_chroma_cbp != CBPC_ALLZERO)
    709         {
    710             UWORD32 u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
    711             UWORD32 u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
    712             UWORD16 u2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
    713 
    714             pi2_y_coeff = ps_dec->pi2_coeff_data;
    715 
    716             {
    717                 UWORD32 i;
    718                 WORD16 ai2_tmp[16];
    719                 for(i = 0; i < 4; i++)
    720                 {
    721                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
    722                     UWORD8 *pu1_pred_sblk = pu1_rec_u
    723                                     + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
    724                                     + (i >> 1) * (u4_recwidth_cr << 2);
    725                     PROFILE_DISABLE_IQ_IT_RECON()
    726                     {
    727                         if(CHECKBIT(u2_chroma_csbp, i))
    728                         {
    729                             ps_dec->pf_iquant_itrans_recon_chroma_4x4(
    730                                             pi2_level,
    731                                             pu1_pred_sblk,
    732                                             pu1_pred_sblk,
    733                                             u4_recwidth_cr,
    734                                             u4_recwidth_cr,
    735                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
    736                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
    737                                             u4_scale_u, ai2_tmp, pi2_level);
    738                         }
    739                         else if(pi2_level[0] != 0)
    740                         {
    741                             ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
    742                                             pi2_level,
    743                                             pu1_pred_sblk,
    744                                             pu1_pred_sblk,
    745                                             u4_recwidth_cr,
    746                                             u4_recwidth_cr,
    747                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
    748                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
    749                                             u4_scale_u, ai2_tmp, pi2_level);
    750                         }
    751                     }
    752                 }
    753             }
    754 
    755             pi2_y_coeff += MB_CHROM_SIZE;
    756             u2_chroma_csbp >>= 4;
    757 
    758             {
    759                 UWORD32 i;
    760                 WORD16 ai2_tmp[16];
    761                 for(i = 0; i < 4; i++)
    762                 {
    763                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
    764                     UWORD8 *pu1_pred_sblk = pu1_rec_u + 1
    765                                     + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
    766                                     + (i >> 1) * (u4_recwidth_cr << 2);
    767                     PROFILE_DISABLE_IQ_IT_RECON()
    768                     {
    769                         if(CHECKBIT(u2_chroma_csbp, i))
    770                         {
    771                             ps_dec->pf_iquant_itrans_recon_chroma_4x4(
    772                                             pi2_level,
    773                                             pu1_pred_sblk,
    774                                             pu1_pred_sblk,
    775                                             u4_recwidth_cr,
    776                                             u4_recwidth_cr,
    777                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
    778                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
    779                                             u4_scale_v, ai2_tmp, pi2_level);
    780                         }
    781                         else if(pi2_level[0] != 0)
    782                         {
    783                             ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
    784                                             pi2_level,
    785                                             pu1_pred_sblk,
    786                                             pu1_pred_sblk,
    787                                             u4_recwidth_cr,
    788                                             u4_recwidth_cr,
    789                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
    790                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
    791                                             u4_scale_v, ai2_tmp, pi2_level);
    792                         }
    793                     }
    794                 }
    795             }
    796         }
    797     }
    798     return (0);
    799 }
    800 
    801 /*!
    802  **************************************************************************
    803  * \if Function name : ih264d_parse_pred_weight_table \endif
    804  *
    805  * \brief
    806  *    Implements pred_weight_table() of 7.3.3.2.
    807  *
    808  * \return
    809  *    None
    810  *
    811  **************************************************************************
    812  */
    813 WORD32 ih264d_parse_pred_weight_table(dec_slice_params_t * ps_cur_slice,
    814                                       dec_bit_stream_t * ps_bitstrm)
    815 {
    816     UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
    817     UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
    818     WORD8 i, cont, lx;
    819     UWORD8 uc_weight_flag;
    820     UWORD32 *pui32_weight_offset_lx;
    821     WORD16 c_weight, c_offset;
    822     UWORD32 ui32_y_def_weight_ofst, ui32_cr_def_weight_ofst;
    823     UWORD32 ui32_temp;
    824     UWORD8 uc_luma_log2_weight_denom;
    825     UWORD8 uc_chroma_log2_weight_denom;
    826 
    827     /* Variables for error resilience checks */
    828     UWORD32 u4_temp;
    829     WORD32 i_temp;
    830 
    831     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
    832     if(u4_temp & MASK_LOG2_WEIGHT_DENOM)
    833     {
    834         return ERROR_PRED_WEIGHT_TABLE_T;
    835     }
    836     uc_luma_log2_weight_denom = u4_temp;
    837     COPYTHECONTEXT("SH: luma_log2_weight_denom",uc_luma_log2_weight_denom);
    838     ui32_y_def_weight_ofst = (1 << uc_luma_log2_weight_denom);
    839 
    840     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
    841     if(u4_temp & MASK_LOG2_WEIGHT_DENOM)
    842     {
    843         return ERROR_PRED_WEIGHT_TABLE_T;
    844     }
    845     uc_chroma_log2_weight_denom = u4_temp;
    846     COPYTHECONTEXT("SH: chroma_log2_weight_denom",uc_chroma_log2_weight_denom);
    847     ui32_cr_def_weight_ofst = (1 << uc_chroma_log2_weight_denom);
    848 
    849     ps_cur_slice->u2_log2Y_crwd = uc_luma_log2_weight_denom
    850                     | (uc_chroma_log2_weight_denom << 8);
    851 
    852     cont = (ps_cur_slice->u1_slice_type == B_SLICE);
    853     lx = 0;
    854     do
    855     {
    856         for(i = 0; i < ps_cur_slice->u1_num_ref_idx_lx_active[lx]; i++)
    857         {
    858             pui32_weight_offset_lx = ps_cur_slice->u4_wt_ofst_lx[lx][i];
    859 
    860             uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
    861             pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
    862             COPYTHECONTEXT("SH: luma_weight_l0_flag",uc_weight_flag);
    863             if(uc_weight_flag)
    864             {
    865                 i_temp = ih264d_sev(pu4_bitstrm_ofst,
    866                                     pu4_bitstrm_buf);
    867                 if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
    868                     return ERROR_PRED_WEIGHT_TABLE_T;
    869                 c_weight = i_temp;
    870                 COPYTHECONTEXT("SH: luma_weight_l0",c_weight);
    871 
    872                 i_temp = ih264d_sev(pu4_bitstrm_ofst,
    873                                     pu4_bitstrm_buf);
    874                 if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
    875                     return ERROR_PRED_WEIGHT_TABLE_T;
    876                 c_offset = i_temp;
    877                 COPYTHECONTEXT("SH: luma_offset_l0",c_offset);
    878 
    879                 ui32_temp = (c_offset << 16) | (c_weight & 0xFFFF);
    880                 pui32_weight_offset_lx[0] = ui32_temp;
    881             }
    882             else
    883             {
    884 
    885                 pui32_weight_offset_lx[0] = ui32_y_def_weight_ofst;
    886             }
    887 
    888             {
    889                 WORD8 c_weightCb, c_weightCr, c_offsetCb, c_offsetCr;
    890                 uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
    891                 pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
    892                 COPYTHECONTEXT("SH: chroma_weight_l0_flag",uc_weight_flag);
    893                 if(uc_weight_flag)
    894                 {
    895                     i_temp = ih264d_sev(pu4_bitstrm_ofst,
    896                                         pu4_bitstrm_buf);
    897                     if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
    898                         return ERROR_PRED_WEIGHT_TABLE_T;
    899                     c_weightCb = i_temp;
    900                     COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCb);
    901 
    902                     i_temp = ih264d_sev(pu4_bitstrm_ofst,
    903                                         pu4_bitstrm_buf);
    904                     if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
    905                         return ERROR_PRED_WEIGHT_TABLE_T;
    906                     c_offsetCb = i_temp;
    907                     COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCb);
    908 
    909                     ui32_temp = (c_offsetCb << 16) | (c_weightCb & 0xFFFF);
    910                     pui32_weight_offset_lx[1] = ui32_temp;
    911 
    912                     i_temp = ih264d_sev(pu4_bitstrm_ofst,
    913                                         pu4_bitstrm_buf);
    914                     if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
    915                         return ERROR_PRED_WEIGHT_TABLE_T;
    916                     c_weightCr = i_temp;
    917                     COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCr);
    918 
    919                     i_temp = ih264d_sev(pu4_bitstrm_ofst,
    920                                         pu4_bitstrm_buf);
    921                     if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
    922                         return ERROR_PRED_WEIGHT_TABLE_T;
    923                     c_offsetCr = i_temp;
    924                     COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCr);
    925 
    926                     ui32_temp = (c_offsetCr << 16) | (c_weightCr & 0xFFFF);
    927                     pui32_weight_offset_lx[2] = ui32_temp;
    928                 }
    929                 else
    930                 {
    931                     pui32_weight_offset_lx[1] = ui32_cr_def_weight_ofst;
    932                     pui32_weight_offset_lx[2] = ui32_cr_def_weight_ofst;
    933                 }
    934             }
    935         }
    936         lx++;
    937     }
    938     while(cont--);
    939 
    940     return OK;
    941 }
    942 
    943 
    944 /*****************************************************************************/
    945 /*                                                                           */
    946 /*  Function Name : ih264d_init_ref_idx_lx_p                                        */
    947 /*                                                                           */
    948 /*  Description   : This function initializes the reference picture L0 list  */
    949 /*                  for P slices as per section 8.2.4.2.1 and 8.2.4.2.2.     */
    950 /*                                                                           */
    951 /*  Inputs        : pointer to ps_dec struture                               */
    952 /*  Globals       : NO                                                       */
    953 /*  Processing    : arranges all the short term pictures according to        */
    954 /*                  pic_num in descending order starting from curr pic_num.  */
    955 /*                  and inserts it in L0 list followed by all Long term      */
    956 /*                  pictures in ascending order.                             */
    957 /*                                                                           */
    958 /*  Returns       : void                                                     */
    959 /*                                                                           */
    960 /*  Issues        : <List any issues or problems with this function>         */
    961 /*                                                                           */
    962 /*  Revision History:                                                        */
    963 /*                                                                           */
    964 /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
    965 /*         13 07 2002   Jay             Draft                                */
    966 /*                                                                           */
    967 /*****************************************************************************/
    968 void ih264d_init_ref_idx_lx_p(dec_struct_t *ps_dec)
    969 {
    970     struct pic_buffer_t *ps_ref_pic_buf_lx;
    971     dpb_manager_t *ps_dpb_mgr;
    972     struct dpb_info_t *ps_next_dpb;
    973     WORD8 i;
    974     UWORD8 u1_max_lt_index, u1_min_lt_index;
    975     UWORD32 u4_lt_index;
    976     UWORD8 u1_field_pic_flag;
    977     dec_slice_params_t *ps_cur_slice;
    978     UWORD8 u1_L0;
    979     WORD32 i4_cur_pic_num, i4_min_st_pic_num;
    980     WORD32 i4_temp_pic_num, i4_ref_pic_num;
    981     UWORD8 u1_num_short_term_bufs;
    982     UWORD8 u1_max_ref_idx_l0;
    983 
    984     ps_cur_slice = ps_dec->ps_cur_slice;
    985     u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
    986     u1_max_ref_idx_l0 = ps_cur_slice->u1_num_ref_idx_lx_active[0]
    987                     << u1_field_pic_flag;
    988 
    989     ps_dpb_mgr = ps_dec->ps_dpb_mgr;
    990     /* Get the current frame number */
    991     i4_cur_pic_num = ps_dec->ps_cur_pic->i4_pic_num;
    992 
    993     /* Get Min pic_num,MinLt */
    994     i4_min_st_pic_num = i4_cur_pic_num;
    995     u1_max_lt_index = MAX_REF_BUFS + 1;
    996     u1_min_lt_index = MAX_REF_BUFS + 1;
    997 
    998     /* Start from ST head */
    999     ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
   1000     for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
   1001     {
   1002         i4_ref_pic_num = ps_next_dpb->ps_pic_buf->i4_pic_num;
   1003         if(i4_ref_pic_num < i4_cur_pic_num)
   1004         {
   1005             /* RefPic Buf pic_num is before Current pic_num in decode order */
   1006             i4_min_st_pic_num = MIN(i4_min_st_pic_num, i4_ref_pic_num);
   1007         }
   1008 
   1009         /* Chase the next link */
   1010         ps_next_dpb = ps_next_dpb->ps_prev_short;
   1011     }
   1012 
   1013     /* Start from LT head */
   1014     ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
   1015     if(ps_next_dpb)
   1016     {
   1017         u1_max_lt_index = ps_next_dpb->u1_lt_idx;
   1018         u1_min_lt_index = ps_next_dpb->u1_lt_idx;
   1019 
   1020         for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
   1021         {
   1022             u4_lt_index = ps_next_dpb->u1_lt_idx;
   1023             u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u4_lt_index));
   1024             u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u4_lt_index));
   1025 
   1026             /* Chase the next link */
   1027             ps_next_dpb = ps_next_dpb->ps_prev_long;
   1028         }
   1029     }
   1030     /* 1. Initialize refIdxL0 */
   1031     u1_L0 = 0;
   1032     if(u1_field_pic_flag)
   1033     {
   1034         ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
   1035         ps_ref_pic_buf_lx += MAX_REF_BUFS;
   1036         i4_temp_pic_num = i4_cur_pic_num;
   1037     }
   1038     else
   1039     {
   1040         ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
   1041         i4_temp_pic_num = i4_cur_pic_num;
   1042     }
   1043 
   1044     /* Arrange all short term buffers in output order as given by pic_num */
   1045     /* Arrange pic_num's less than Curr pic_num in the descending pic_num */
   1046     /* order starting from (Curr pic_num - 1)                             */
   1047     for(; i4_temp_pic_num >= i4_min_st_pic_num; i4_temp_pic_num--)
   1048     {
   1049         /* Start from ST head */
   1050         ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
   1051         for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
   1052         {
   1053             if((WORD32)ps_next_dpb->ps_pic_buf->i4_pic_num == i4_temp_pic_num)
   1054             {
   1055                 /* Copy info in pic buffer */
   1056                 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
   1057                                                    ps_next_dpb->ps_pic_buf);
   1058                 ps_ref_pic_buf_lx++;
   1059                 u1_L0++;
   1060                 break;
   1061             }
   1062             ps_next_dpb = ps_next_dpb->ps_prev_short;
   1063         }
   1064     }
   1065 
   1066     /* Arrange all Long term buffers in ascending order, in LongtermIndex */
   1067     /* Start from LT head */
   1068     u1_num_short_term_bufs = u1_L0;
   1069     for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index;
   1070                     u4_lt_index++)
   1071     {
   1072         ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
   1073         for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
   1074         {
   1075             if(ps_next_dpb->u1_lt_idx == u4_lt_index)
   1076             {
   1077                 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
   1078                                                    ps_next_dpb->ps_pic_buf);
   1079 
   1080                 ps_ref_pic_buf_lx->u1_long_term_pic_num =
   1081                                 ps_ref_pic_buf_lx->u1_long_term_frm_idx;
   1082                 ps_ref_pic_buf_lx++;
   1083                 u1_L0++;
   1084                 break;
   1085             }
   1086             ps_next_dpb = ps_next_dpb->ps_prev_long;
   1087         }
   1088     }
   1089 
   1090     if(u1_field_pic_flag)
   1091     {
   1092         /* Initialize the rest of the entries in the */
   1093         /* reference list to handle of errors        */
   1094         {
   1095             UWORD8 u1_i;
   1096             pic_buffer_t *ps_ref_pic;
   1097 
   1098             ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS;
   1099 
   1100             if(NULL == ps_ref_pic->pu1_buf1)
   1101             {
   1102                 ps_ref_pic = ps_dec->ps_cur_pic;
   1103             }
   1104             for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
   1105             {
   1106                 *ps_ref_pic_buf_lx = *ps_ref_pic;
   1107                 ps_ref_pic_buf_lx++;
   1108             }
   1109         }
   1110 
   1111         ih264d_convert_frm_to_fld_list(
   1112                         ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS, &u1_L0,
   1113                         ps_dec, u1_num_short_term_bufs);
   1114 
   1115         ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0] + u1_L0;
   1116     }
   1117 
   1118     /* Initialize the rest of the entries in the */
   1119     /* reference list to handle of errors        */
   1120     {
   1121         UWORD8 u1_i;
   1122         pic_buffer_t *ps_ref_pic;
   1123 
   1124         ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0];
   1125 
   1126         if(NULL == ps_ref_pic->pu1_buf1)
   1127         {
   1128             ps_ref_pic = ps_dec->ps_cur_pic;
   1129         }
   1130         for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
   1131         {
   1132             *ps_ref_pic_buf_lx = *ps_ref_pic;
   1133             ps_ref_pic_buf_lx++;
   1134         }
   1135     }
   1136     ps_dec->ps_cur_slice->u1_initial_list_size[0] = u1_L0;
   1137 }
   1138 
   1139