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