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 
ih264d_insert_pic_in_ref_pic_listx(struct pic_buffer_t * ps_ref_pic_buf_lx,struct pic_buffer_t * ps_pic)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 
ih264d_mv_pred_ref_tfr_nby2_pmb(dec_struct_t * ps_dec,UWORD8 u1_mb_idx,UWORD8 u1_num_mbs)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         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             for(j = 0; j < u1_num_part; j++, ps_part++)
173             {
174 
175                 u1_sub_mb_num = ps_part->u1_sub_mb_num;
176                 ps_dec->u1_sub_mb_num = u1_sub_mb_num;
177 
178                 if(PART_NOT_DIRECT != ps_part->u1_is_direct)
179                 {
180                     /* Mb Skip Mode */
181                     /* Setting the default and other members of MvPred Structure */
182                     s_mvPred.i2_mv[2] = -1;
183                     s_mvPred.i2_mv[3] = -1;
184                     s_mvPred.i1_ref_frame[0] = 0;
185                     i1_ref_idx = (u1_scale_ref && u4_bot_mb) ? MAX_REF_BUFS : 0;
186                     ps_ref_frame = pps_ref_frame[i1_ref_idx];
187                     s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
188                     s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
189                     pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[0];
190 
191                     ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb_start,
192                                       ps_mv_ntop_start, &s_mvPred, 0, 4, 0, 1,
193                                       MB_SKIP);
194 
195 
196 
197 
198 
199 
200                     {
201                         pred_info_pkd_t *ps_pred_pkd;
202                         ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
203                     ih264d_fill_pred_info (s_mvPred.i2_mv,4,4,0,PRED_L0,ps_pred_pkd,ps_ref_frame->u1_pic_buf_id,
204                                            (i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
205                                            ps_ref_frame->u1_pic_type);
206 
207 
208                     ps_dec->u4_pred_info_pkd_idx++;
209                     ps_cur_mb_info->u1_num_pred_parts++;
210                     }
211 
212 
213 
214                     /* Storing colocated zero information */
215                     u1_colz = ((ABS(s_mvPred.i2_mv[0]) <= 1)
216                                     && (ABS(s_mvPred.i2_mv[1]) <= 1))
217                                     + (u1_field << 1);
218 
219                     ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
220                                        u1_colz, 4, 4);
221                 }
222                 else
223                 {
224                     u1_sub_mb_x = u1_sub_mb_num & 0x03;
225                     u1_sub_mb_y = u1_sub_mb_num >> 2;
226                     u1_blk_no =
227                                     (u1_num_part < 4) ?
228                                                     j :
229                                                     (((u1_sub_mb_y >> 1) << 1)
230                                                                     + (u1_sub_mb_x
231                                                                                     >> 1));
232 
233                     ps_mv_ntop = ps_mv_ntop_start + u1_sub_mb_x;
234                     ps_mv_nmb = ps_mv_nmb_start + u1_sub_mb_num;
235 
236                     u1_wd = ps_part->u1_partwidth;
237                     u1_ht = ps_part->u1_partheight;
238 
239                     /* Populate the colpic info and reference frames */
240                     i1_ref_idx = pi1_ref_idx[u1_blk_no];
241                     s_mvPred.i1_ref_frame[0] = i1_ref_idx;
242 
243                     /********************************************************/
244                     /* Predict Mv                                           */
245                     /* Add Mv Residuals and store back                      */
246                     /********************************************************/
247                     ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb, ps_mv_ntop,
248                                       &s_mvPred, u1_sub_mb_num, u1_wd, 0, 1,
249                                       ps_cur_mb_info->u1_mb_mc_mode);
250                     i2_mv_x = ps_mv_nmb->i2_mv[0];
251                     i2_mv_y = ps_mv_nmb->i2_mv[1];
252                     i2_mv_x += s_mvPred.i2_mv[0];
253                     i2_mv_y += s_mvPred.i2_mv[1];
254                     s_mvPred.i2_mv[0] = i2_mv_x;
255                     s_mvPred.i2_mv[1] = i2_mv_y;
256 
257                     /********************************************************/
258                     /* Transfer setup call                                  */
259                     /* convert RefIdx if it is MbAff                        */
260                     /* Pass Weight Offset and refFrame                      */
261                     /********************************************************/
262                     i1_ref_idx1 = i1_ref_idx >> u1_scale_ref;
263                     if(u1_scale_ref && ((i1_ref_idx & 0x01) != u4_bot_mb))
264                         i1_ref_idx1 += MAX_REF_BUFS;
265                     ps_ref_frame = pps_ref_frame[i1_ref_idx1];
266                     pu4_wt_offst = ppu4_wt_ofst[u1_blk_no];
267 
268 
269 
270 
271 
272 
273                     {
274                     pred_info_pkd_t *ps_pred_pkd;
275                     ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
276                     ih264d_fill_pred_info (s_mvPred.i2_mv,u1_wd,u1_ht,u1_sub_mb_num,PRED_L0,ps_pred_pkd,
277                                            ps_ref_frame->u1_pic_buf_id,(i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
278                                            ps_ref_frame->u1_pic_type);
279 
280                     ps_dec->u4_pred_info_pkd_idx++;
281                     ps_cur_mb_info->u1_num_pred_parts++;
282                     }
283 
284 
285 
286                     /* Fill colocated info in MvPred structure */
287                     s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
288                     s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
289 
290                     /* Calculating colocated zero information */
291                     u1_colz =
292                                     (u1_field << 1)
293                                                     | ((i1_ref_idx == 0)
294                                                                     && (ABS(i2_mv_x)
295                                                                                     <= 1)
296                                                                     && (ABS(i2_mv_y)
297                                                                                     <= 1));
298                     u1_colz |= ps_mb_part_info->u1_col_info[u1_blk_no];
299 
300                     /* Replicate the motion vectors and colzero u4_flag  */
301                     /* for all sub-partitions                         */
302 
303                     ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb,
304                                        u1_sub_mb_num, u1_colz, u1_ht,
305                                        u1_wd);
306                 }
307             }
308 
309         }
310         else
311         {
312             /* Storing colocated zero information */
313             ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
314                                (UWORD8)(u1_field << 1), 4, 4);
315 
316         }
317         /*if num _cores is set to 3,compute bs will be done in another thread*/
318         if(ps_dec->u4_num_cores < 3)
319         {
320 
321             if(ps_dec->u4_app_disable_deblk_frm == 0)
322                 ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
323                                      (UWORD16)(i >> u1_mbaff));
324         }
325     }
326 
327 
328 
329     return OK;
330 }
331 
332 
ih264d_decode_recon_tfr_nmb(dec_struct_t * ps_dec,UWORD8 u1_mb_idx,UWORD8 u1_num_mbs,UWORD8 u1_num_mbs_next,UWORD8 u1_tfr_n_mb,UWORD8 u1_end_of_row)333 WORD32 ih264d_decode_recon_tfr_nmb(dec_struct_t * ps_dec,
334                                    UWORD8 u1_mb_idx,
335                                    UWORD8 u1_num_mbs,
336                                    UWORD8 u1_num_mbs_next,
337                                    UWORD8 u1_tfr_n_mb,
338                                    UWORD8 u1_end_of_row)
339 {
340     WORD32 i,j;
341     UWORD32 u1_end_of_row_next;
342     dec_mb_info_t * ps_cur_mb_info;
343     UWORD32 u4_update_mbaff = 0;
344     WORD32 ret;
345     const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
346     const UWORD32 u1_slice_type = ps_dec->ps_cur_slice->u1_slice_type;
347     const WORD32 u1_skip_th = (
348                     (u1_slice_type != I_SLICE) ?
349                                     (ps_dec->u1_B ? B_8x8 : PRED_8x8R0) : -1);
350     const UWORD32 u1_ipcm_th = (
351                     (u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? 23 : 5) : 0);
352 
353 
354 
355 
356 
357     /* N Mb MC Loop */
358     for(i = u1_mb_idx; i < u1_num_mbs; i++)
359     {
360         ps_cur_mb_info = ps_dec->ps_nmb_info + i;
361         ps_dec->u4_dma_buf_idx = 0;
362         ps_dec->u4_pred_info_idx = 0;
363 
364         if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
365         {
366             {
367                 WORD32 pred_cnt = 0;
368                 pred_info_pkd_t *ps_pred_pkd;
369                 UWORD32 u4_pred_info_pkd_idx;
370                 WORD8 i1_pred;
371 
372                 u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
373 
374                 while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
375                 {
376 
377                     ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
378 
379                      ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
380                                                ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
381                                          ps_cur_mb_info);
382                     u4_pred_info_pkd_idx++;
383                     pred_cnt++;
384                 }
385             }
386 
387             ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
388 
389         }
390         else if(ps_cur_mb_info->u1_mb_type == MB_SKIP)
391         {
392             {
393                 WORD32 pred_cnt = 0;
394                 pred_info_pkd_t *ps_pred_pkd;
395                 UWORD32 u4_pred_info_pkd_idx;
396                 WORD8 i1_pred;
397 
398                 u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
399 
400                 while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
401                 {
402 
403                     ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
404 
405                     ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
406                                                ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
407                                          ps_cur_mb_info);
408 
409                     u4_pred_info_pkd_idx++;
410                     pred_cnt++;
411                 }
412             }
413             /* Decode MB skip */
414             ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
415 
416         }
417 
418      }
419 
420 
421     /* N Mb IQ IT RECON  Loop */
422     for(j = u1_mb_idx; j < i; j++)
423     {
424         ps_cur_mb_info = ps_dec->ps_nmb_info + j;
425 
426         if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
427         {
428             ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
429 
430         }
431         else if(ps_cur_mb_info->u1_mb_type != MB_SKIP)
432         {
433             if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
434             {
435                 ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
436                 ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
437             }
438         }
439 
440 
441         if(ps_dec->u4_use_intrapred_line_copy)
442         {
443             ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
444         }
445 
446     }
447 
448     /*N MB deblocking*/
449     if(ps_dec->u4_nmb_deblk == 1)
450     {
451 
452         UWORD32 u4_cur_mb, u4_right_mb;
453         UWORD32 u4_mb_x, u4_mb_y;
454         UWORD32 u4_wd_y, u4_wd_uv;
455         tfr_ctxt_t *ps_tfr_cxt = &(ps_dec->s_tran_addrecon);
456         UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
457         const WORD32 i4_cb_qp_idx_ofst =
458                        ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
459         const WORD32 i4_cr_qp_idx_ofst =
460                        ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
461 
462         u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
463         u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
464 
465 
466         ps_cur_mb_info = ps_dec->ps_nmb_info + u1_mb_idx;
467 
468         ps_dec->u4_deblk_mb_x = ps_cur_mb_info->u2_mbx;
469         ps_dec->u4_deblk_mb_y = ps_cur_mb_info->u2_mby;
470 
471         for(j = u1_mb_idx; j < i; j++)
472         {
473 
474             ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
475                                        i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
476                                         u4_wd_y, u4_wd_uv);
477 
478 
479         }
480 
481 
482 
483     }
484 
485 
486 
487     if(u1_tfr_n_mb)
488     {
489         /****************************************************************/
490         /* Check for End Of Row in Next iteration                       */
491         /****************************************************************/
492         u1_end_of_row_next =
493                         u1_num_mbs_next
494                                         && (u1_num_mbs_next
495                                                         <= (ps_dec->u1_recon_mb_grp
496                                                                         >> u1_mbaff));
497 
498         /****************************************************************/
499         /* Transfer the Following things                                */
500         /* N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )       */
501         /* N-Mb Recon Data          ( To Ext Frame Buffer )             */
502         /* N-Mb Intrapredline Data  ( Updated Internally)               */
503         /* N-Mb MV Data             ( To Ext MV Buffer )                */
504         /* N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)    */
505         /****************************************************************/
506         ih264d_transfer_mb_group_data(ps_dec, u1_num_mbs, u1_end_of_row,
507                                       u1_end_of_row_next);
508         ps_dec->u4_num_mbs_prev_nmb = u1_num_mbs;
509 
510         ps_dec->u4_pred_info_idx = 0;
511         ps_dec->u4_dma_buf_idx = 0;
512 
513 
514     }
515     return OK;
516 }
517 
518 /*!
519  **************************************************************************
520  * \if Function name : ih264d_process_inter_mb \endif
521  *
522  * \brief
523  *    This function decodes an Inter MB.
524  *
525  *
526  * \return
527  *    0 on Success and Error code otherwise
528  **************************************************************************
529  */
ih264d_process_inter_mb(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mb_num)530 WORD32 ih264d_process_inter_mb(dec_struct_t * ps_dec,
531                                dec_mb_info_t * ps_cur_mb_info,
532                                UWORD8 u1_mb_num)
533 {
534     /* CHANGED CODE */
535     UWORD8 *pu1_rec_y, *pu1_rec_u, *pu1_rec_v;
536 
537     /*CHANGED CODE */
538     UWORD32 ui_rec_width, u4_recwidth_cr;
539     WORD16 *pi2_y_coeff;
540     UWORD32 u1_mb_field_decoding_flag;
541     const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
542     UWORD32 uc_botMb;
543     UWORD32 u4_num_pmbair;
544     /* CHANGED CODE */
545     tfr_ctxt_t *ps_frame_buf = ps_dec->ps_frame_buf_ip_recon;
546     UWORD32 u4_luma_dc_only_csbp = 0;
547     UWORD32 u4_luma_dc_only_cbp = 0;
548     /* CHANGED CODE */
549 
550     uc_botMb = 1 - ps_cur_mb_info->u1_topmb;
551     u4_num_pmbair = (u1_mb_num >> u1_mbaff);
552     u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
553 
554 
555     /* CHANGED CODE */
556     pu1_rec_y = ps_frame_buf->pu1_dest_y + (u4_num_pmbair << 4);
557     pu1_rec_u =
558                     ps_frame_buf->pu1_dest_u
559                                     + (u4_num_pmbair << 3) * YUV420SP_FACTOR;
560     pu1_rec_v = ps_frame_buf->pu1_dest_v + (u4_num_pmbair << 3);
561     ui_rec_width = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
562     u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
563 
564     /* CHANGED CODE */
565 
566     if(u1_mbaff)
567     {
568         if(uc_botMb)
569         {
570             pu1_rec_y += (u1_mb_field_decoding_flag ?
571                             (ui_rec_width >> 1) : (ui_rec_width << 4));
572             pu1_rec_u += (u1_mb_field_decoding_flag ?
573                             (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
574             pu1_rec_v += (u1_mb_field_decoding_flag ?
575                             (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
576         }
577     }
578 
579     if(!ps_cur_mb_info->u1_tran_form8x8)
580     {
581         u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
582                                        ps_cur_mb_info,
583                                        0);
584     }
585     else
586     {
587         if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
588         {
589             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
590                                            ps_cur_mb_info,
591                                            0);
592         }
593         else
594         {
595             u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec,
596                                            ps_cur_mb_info);
597         }
598     }
599 
600     pi2_y_coeff = ps_dec->pi2_coeff_data;
601     /* Inverse Transform and Reconstruction */
602     if(ps_cur_mb_info->u1_cbp & 0x0f)
603     {
604         /* CHANGED CODE */
605         if(!ps_cur_mb_info->u1_tran_form8x8)
606         {
607             UWORD32 i;
608             WORD16 ai2_tmp[16];
609             for(i = 0; i < 16; i++)
610             {
611                 if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
612                 {
613                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
614                     UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x3) * BLK_SIZE)
615                                     + (i >> 2) * (ui_rec_width << 2);
616                     PROFILE_DISABLE_IQ_IT_RECON()
617                     {
618                         if(CHECKBIT(u4_luma_dc_only_csbp, i))
619                         {
620                             ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
621                                             pi2_level,
622                                             pu1_pred_sblk,
623                                             pu1_pred_sblk,
624                                             ui_rec_width,
625                                             ui_rec_width,
626                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
627                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
628                                             ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
629                                             NULL);
630                         }
631                         else
632                         {
633                             ps_dec->pf_iquant_itrans_recon_luma_4x4(
634                                             pi2_level,
635                                             pu1_pred_sblk,
636                                             pu1_pred_sblk,
637                                             ui_rec_width,
638                                             ui_rec_width,
639                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
640                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
641                                             ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
642                                             NULL);
643                         }
644                     }
645                 }
646             }
647         }
648         else
649         {
650             WORD16 *pi2_scale_matrix_ptr;
651             WORD32 i;
652 
653             pi2_scale_matrix_ptr =
654                             ps_dec->s_high_profile.i2_scalinglist8x8[1];
655 
656             for(i = 0; i < 4; i++)
657             {
658                 WORD16 ai2_tmp[64];
659                 WORD16 *pi16_levelBlock = pi2_y_coeff + (i << 6); /* move to the next 8x8 adding 64 */
660 
661                 UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x1) * BLK8x8SIZE)
662                                 + (i >> 1) * (ui_rec_width << 3);
663                 if(CHECKBIT(ps_cur_mb_info->u1_cbp, i))
664                 {
665                     PROFILE_DISABLE_IQ_IT_RECON()
666                     {
667                         if(CHECKBIT(u4_luma_dc_only_cbp, i))
668                         {
669                             ps_dec->pf_iquant_itrans_recon_luma_8x8_dc(
670                                             pi16_levelBlock,
671                                             pu1_pred_sblk,
672                                             pu1_pred_sblk,
673                                             ui_rec_width,
674                                             ui_rec_width,
675                                             gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
676                                             (UWORD16 *)pi2_scale_matrix_ptr,
677                                             ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
678                                             NULL);
679                         }
680                         else
681                         {
682                             ps_dec->pf_iquant_itrans_recon_luma_8x8(
683                                             pi16_levelBlock,
684                                             pu1_pred_sblk,
685                                             pu1_pred_sblk,
686                                             ui_rec_width,
687                                             ui_rec_width,
688                                             gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
689                                             (UWORD16 *)pi2_scale_matrix_ptr,
690                                             ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
691                                             NULL);
692                         }
693                     }
694                 }
695             }
696 
697         }
698     }
699 
700     /* Decode Chroma Block */
701     ih264d_unpack_chroma_coeff4x4_mb(ps_dec,
702                                      ps_cur_mb_info);
703     /*--------------------------------------------------------------------*/
704     /* Chroma Blocks decoding                                             */
705     /*--------------------------------------------------------------------*/
706     {
707         UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
708 
709         if(u1_chroma_cbp != CBPC_ALLZERO)
710         {
711             UWORD32 u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
712             UWORD32 u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
713             UWORD16 u2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
714 
715             pi2_y_coeff = ps_dec->pi2_coeff_data;
716 
717             {
718                 UWORD32 i;
719                 WORD16 ai2_tmp[16];
720                 for(i = 0; i < 4; i++)
721                 {
722                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
723                     UWORD8 *pu1_pred_sblk = pu1_rec_u
724                                     + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
725                                     + (i >> 1) * (u4_recwidth_cr << 2);
726                     PROFILE_DISABLE_IQ_IT_RECON()
727                     {
728                         if(CHECKBIT(u2_chroma_csbp, i))
729                         {
730                             ps_dec->pf_iquant_itrans_recon_chroma_4x4(
731                                             pi2_level,
732                                             pu1_pred_sblk,
733                                             pu1_pred_sblk,
734                                             u4_recwidth_cr,
735                                             u4_recwidth_cr,
736                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
737                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
738                                             u4_scale_u, ai2_tmp, pi2_level);
739                         }
740                         else if(pi2_level[0] != 0)
741                         {
742                             ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
743                                             pi2_level,
744                                             pu1_pred_sblk,
745                                             pu1_pred_sblk,
746                                             u4_recwidth_cr,
747                                             u4_recwidth_cr,
748                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
749                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
750                                             u4_scale_u, ai2_tmp, pi2_level);
751                         }
752                     }
753                 }
754             }
755 
756             pi2_y_coeff += MB_CHROM_SIZE;
757             u2_chroma_csbp >>= 4;
758 
759             {
760                 UWORD32 i;
761                 WORD16 ai2_tmp[16];
762                 for(i = 0; i < 4; i++)
763                 {
764                     WORD16 *pi2_level = pi2_y_coeff + (i << 4);
765                     UWORD8 *pu1_pred_sblk = pu1_rec_u + 1
766                                     + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
767                                     + (i >> 1) * (u4_recwidth_cr << 2);
768                     PROFILE_DISABLE_IQ_IT_RECON()
769                     {
770                         if(CHECKBIT(u2_chroma_csbp, i))
771                         {
772                             ps_dec->pf_iquant_itrans_recon_chroma_4x4(
773                                             pi2_level,
774                                             pu1_pred_sblk,
775                                             pu1_pred_sblk,
776                                             u4_recwidth_cr,
777                                             u4_recwidth_cr,
778                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
779                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
780                                             u4_scale_v, ai2_tmp, pi2_level);
781                         }
782                         else if(pi2_level[0] != 0)
783                         {
784                             ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
785                                             pi2_level,
786                                             pu1_pred_sblk,
787                                             pu1_pred_sblk,
788                                             u4_recwidth_cr,
789                                             u4_recwidth_cr,
790                                             gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
791                                             (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
792                                             u4_scale_v, ai2_tmp, pi2_level);
793                         }
794                     }
795                 }
796             }
797         }
798     }
799     return (0);
800 }
801 
802 /*!
803  **************************************************************************
804  * \if Function name : ih264d_parse_pred_weight_table \endif
805  *
806  * \brief
807  *    Implements pred_weight_table() of 7.3.3.2.
808  *
809  * \return
810  *    None
811  *
812  **************************************************************************
813  */
ih264d_parse_pred_weight_table(dec_slice_params_t * ps_cur_slice,dec_bit_stream_t * ps_bitstrm)814 WORD32 ih264d_parse_pred_weight_table(dec_slice_params_t * ps_cur_slice,
815                                       dec_bit_stream_t * ps_bitstrm)
816 {
817     UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
818     UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
819     WORD8 i, cont, lx;
820     UWORD8 uc_weight_flag;
821     UWORD32 *pui32_weight_offset_lx;
822     WORD16 c_weight, c_offset;
823     UWORD32 ui32_y_def_weight_ofst, ui32_cr_def_weight_ofst;
824     UWORD32 ui32_temp;
825     UWORD8 uc_luma_log2_weight_denom;
826     UWORD8 uc_chroma_log2_weight_denom;
827 
828     /* Variables for error resilience checks */
829     UWORD32 u4_temp;
830     WORD32 i_temp;
831 
832     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
833     if(u4_temp & MASK_LOG2_WEIGHT_DENOM)
834     {
835         return ERROR_PRED_WEIGHT_TABLE_T;
836     }
837     uc_luma_log2_weight_denom = u4_temp;
838     COPYTHECONTEXT("SH: luma_log2_weight_denom",uc_luma_log2_weight_denom);
839     ui32_y_def_weight_ofst = (1 << uc_luma_log2_weight_denom);
840 
841     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
842     if(u4_temp & MASK_LOG2_WEIGHT_DENOM)
843     {
844         return ERROR_PRED_WEIGHT_TABLE_T;
845     }
846     uc_chroma_log2_weight_denom = u4_temp;
847     COPYTHECONTEXT("SH: chroma_log2_weight_denom",uc_chroma_log2_weight_denom);
848     ui32_cr_def_weight_ofst = (1 << uc_chroma_log2_weight_denom);
849 
850     ps_cur_slice->u2_log2Y_crwd = uc_luma_log2_weight_denom
851                     | (uc_chroma_log2_weight_denom << 8);
852 
853     cont = (ps_cur_slice->u1_slice_type == B_SLICE);
854     lx = 0;
855     do
856     {
857         for(i = 0; i < ps_cur_slice->u1_num_ref_idx_lx_active[lx]; i++)
858         {
859             pui32_weight_offset_lx = ps_cur_slice->u4_wt_ofst_lx[lx][i];
860 
861             uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
862             pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
863             COPYTHECONTEXT("SH: luma_weight_l0_flag",uc_weight_flag);
864             if(uc_weight_flag)
865             {
866                 i_temp = ih264d_sev(pu4_bitstrm_ofst,
867                                     pu4_bitstrm_buf);
868                 if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
869                     return ERROR_PRED_WEIGHT_TABLE_T;
870                 c_weight = i_temp;
871                 COPYTHECONTEXT("SH: luma_weight_l0",c_weight);
872 
873                 i_temp = ih264d_sev(pu4_bitstrm_ofst,
874                                     pu4_bitstrm_buf);
875                 if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
876                     return ERROR_PRED_WEIGHT_TABLE_T;
877                 c_offset = i_temp;
878                 COPYTHECONTEXT("SH: luma_offset_l0",c_offset);
879 
880                 ui32_temp = (c_offset << 16) | (c_weight & 0xFFFF);
881                 pui32_weight_offset_lx[0] = ui32_temp;
882             }
883             else
884             {
885 
886                 pui32_weight_offset_lx[0] = ui32_y_def_weight_ofst;
887             }
888 
889             {
890                 WORD8 c_weightCb, c_weightCr, c_offsetCb, c_offsetCr;
891                 uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
892                 pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
893                 COPYTHECONTEXT("SH: chroma_weight_l0_flag",uc_weight_flag);
894                 if(uc_weight_flag)
895                 {
896                     i_temp = ih264d_sev(pu4_bitstrm_ofst,
897                                         pu4_bitstrm_buf);
898                     if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
899                         return ERROR_PRED_WEIGHT_TABLE_T;
900                     c_weightCb = i_temp;
901                     COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCb);
902 
903                     i_temp = ih264d_sev(pu4_bitstrm_ofst,
904                                         pu4_bitstrm_buf);
905                     if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
906                         return ERROR_PRED_WEIGHT_TABLE_T;
907                     c_offsetCb = i_temp;
908                     COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCb);
909 
910                     ui32_temp = (c_offsetCb << 16) | (c_weightCb & 0xFFFF);
911                     pui32_weight_offset_lx[1] = ui32_temp;
912 
913                     i_temp = ih264d_sev(pu4_bitstrm_ofst,
914                                         pu4_bitstrm_buf);
915                     if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
916                         return ERROR_PRED_WEIGHT_TABLE_T;
917                     c_weightCr = i_temp;
918                     COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCr);
919 
920                     i_temp = ih264d_sev(pu4_bitstrm_ofst,
921                                         pu4_bitstrm_buf);
922                     if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
923                         return ERROR_PRED_WEIGHT_TABLE_T;
924                     c_offsetCr = i_temp;
925                     COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCr);
926 
927                     ui32_temp = (c_offsetCr << 16) | (c_weightCr & 0xFFFF);
928                     pui32_weight_offset_lx[2] = ui32_temp;
929                 }
930                 else
931                 {
932                     pui32_weight_offset_lx[1] = ui32_cr_def_weight_ofst;
933                     pui32_weight_offset_lx[2] = ui32_cr_def_weight_ofst;
934                 }
935             }
936         }
937         lx++;
938     }
939     while(cont--);
940 
941     return OK;
942 }
943 
944 
945 /*****************************************************************************/
946 /*                                                                           */
947 /*  Function Name : ih264d_init_ref_idx_lx_p                                        */
948 /*                                                                           */
949 /*  Description   : This function initializes the reference picture L0 list  */
950 /*                  for P slices as per section 8.2.4.2.1 and 8.2.4.2.2.     */
951 /*                                                                           */
952 /*  Inputs        : pointer to ps_dec struture                               */
953 /*  Globals       : NO                                                       */
954 /*  Processing    : arranges all the short term pictures according to        */
955 /*                  pic_num in descending order starting from curr pic_num.  */
956 /*                  and inserts it in L0 list followed by all Long term      */
957 /*                  pictures in ascending order.                             */
958 /*                                                                           */
959 /*  Returns       : void                                                     */
960 /*                                                                           */
961 /*  Issues        : <List any issues or problems with this function>         */
962 /*                                                                           */
963 /*  Revision History:                                                        */
964 /*                                                                           */
965 /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
966 /*         13 07 2002   Jay             Draft                                */
967 /*                                                                           */
968 /*****************************************************************************/
ih264d_init_ref_idx_lx_p(dec_struct_t * ps_dec)969 void ih264d_init_ref_idx_lx_p(dec_struct_t *ps_dec)
970 {
971     struct pic_buffer_t *ps_ref_pic_buf_lx;
972     dpb_manager_t *ps_dpb_mgr;
973     struct dpb_info_t *ps_next_dpb;
974     WORD8 i;
975     UWORD8 u1_max_lt_index, u1_min_lt_index, u1_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             u1_lt_index = ps_next_dpb->u1_lt_idx;
1023             u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u1_lt_index));
1024             u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u1_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(u1_lt_index = u1_min_lt_index; u1_lt_index <= u1_max_lt_index;
1070                     u1_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 == u1_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