Initializing reference list for every P/B slice.

Reference list needs to be initialized for every P/B
slice, to ensure colocated picture always points to a
valid picture buffer, even in the case of error.

Bug: 36279112

Change-Id: I051d7e725b0af209cc7bb333db8da3518adf78a0
(cherry picked from commit f9d3f9af8fc113acda28e1a4e48d85736ee29c75)
diff --git a/decoder/ih264d_api.c b/decoder/ih264d_api.c
index 640fdea..2cde456 100644
--- a/decoder/ih264d_api.c
+++ b/decoder/ih264d_api.c
@@ -1002,7 +1002,6 @@
     ps_dec->ps_cur_sps = NULL;
     ps_dec->u1_init_dec_flag = 0;
     ps_dec->u1_first_slice_in_stream = 1;
-    ps_dec->u1_first_pb_nal_in_pic = 1;
     ps_dec->u1_last_pic_not_decoded = 0;
     ps_dec->u4_app_disp_width = 0;
     ps_dec->i4_header_decoded = 0;
@@ -1919,7 +1918,6 @@
     ps_dec->cur_dec_mb_num = 0;
     ps_dec->cur_recon_mb_num = 0;
     ps_dec->u4_first_slice_in_pic = 1;
-    ps_dec->u1_first_pb_nal_in_pic = 1;
     ps_dec->u1_slice_header_done = 0;
     ps_dec->u1_dangling_field = 0;
 
diff --git a/decoder/ih264d_parse_bslice.c b/decoder/ih264d_parse_bslice.c
index 85b0d0f..772964a 100644
--- a/decoder/ih264d_parse_bslice.c
+++ b/decoder/ih264d_parse_bslice.c
@@ -1405,22 +1405,9 @@
         ps_slice->u1_num_ref_idx_lx_active[0] = u4_temp;
         ps_slice->u1_num_ref_idx_lx_active[1] = ui_temp1;
     }
-    /* Initialize the Reference list once in Picture if the slice type    */
-    /* of first slice is between 5 to 9 defined in table 7.3 of standard  */
-    /* If picture contains both P & B slices then Initialize the Reference*/
-    /* List only when it switches from P to B and B to P                     */
 
-    {
-        UWORD8 init_idx_flg = (ps_dec->u1_pr_sl_type
-                        != ps_dec->ps_cur_slice->u1_slice_type);
-        if(ps_dec->u1_first_pb_nal_in_pic
-                        || (init_idx_flg & !ps_dec->u1_sl_typ_5_9)
-                        || ps_dec->u1_num_ref_idx_lx_active_prev
-                                        != ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0])
-            ih264d_init_ref_idx_lx_b(ps_dec);
-        if(ps_dec->u1_first_pb_nal_in_pic & ps_dec->u1_sl_typ_5_9)
-            ps_dec->u1_first_pb_nal_in_pic = 0;
-    }
+
+    ih264d_init_ref_idx_lx_b(ps_dec);
     /* Store the value for future slices in the same picture */
     ps_dec->u1_num_ref_idx_lx_active_prev =
                     ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
diff --git a/decoder/ih264d_parse_pslice.c b/decoder/ih264d_parse_pslice.c
index 97ea27c..bcfbe05 100644
--- a/decoder/ih264d_parse_pslice.c
+++ b/decoder/ih264d_parse_pslice.c
@@ -1977,23 +1977,7 @@
         UWORD8 uc_refIdxReFlagL0 = ih264d_get_bit_h264(ps_bitstrm);
         COPYTHECONTEXT("SH: ref_pic_list_reordering_flag_l0",uc_refIdxReFlagL0);
 
-        /* Initialize the Reference list once in Picture if the slice type    */
-        /* of first slice is between 5 to 9 defined in table 7.3 of standard  */
-        /* If picture contains both P & B slices then Initialize the Reference*/
-        /* List only when it switches from P to B and B to P                     */
-        {
-            UWORD8 init_idx_flg = (ps_dec->u1_pr_sl_type
-                            != ps_dec->ps_cur_slice->u1_slice_type);
-            if(ps_dec->u1_first_pb_nal_in_pic
-                            || (init_idx_flg & !ps_dec->u1_sl_typ_5_9)
-                            || ps_dec->u1_num_ref_idx_lx_active_prev
-                                            != ps_cur_slice->u1_num_ref_idx_lx_active[0])
-            {
-                ih264d_init_ref_idx_lx_p(ps_dec);
-            }
-            if(ps_dec->u1_first_pb_nal_in_pic & ps_dec->u1_sl_typ_5_9)
-                ps_dec->u1_first_pb_nal_in_pic = 0;
-        }
+        ih264d_init_ref_idx_lx_p(ps_dec);
         /* Store the value for future slices in the same picture */
         ps_dec->u1_num_ref_idx_lx_active_prev =
                         ps_cur_slice->u1_num_ref_idx_lx_active[0];
diff --git a/decoder/ih264d_parse_slice.c b/decoder/ih264d_parse_slice.c
index 7e0815f..fad2dff 100644
--- a/decoder/ih264d_parse_slice.c
+++ b/decoder/ih264d_parse_slice.c
@@ -284,10 +284,8 @@
 
     {
         dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
-        if(ps_dec->u1_sl_typ_5_9
-                        && ((ps_cur_slice->u1_slice_type == I_SLICE)
-                                        || (ps_cur_slice->u1_slice_type
-                                                        == SI_SLICE)))
+        if((ps_cur_slice->u1_slice_type == I_SLICE)
+                        || (ps_cur_slice->u1_slice_type == SI_SLICE))
             ps_err->u1_cur_pic_type = PIC_TYPE_I;
         else
             ps_err->u1_cur_pic_type = PIC_TYPE_UNKNOWN;
@@ -1034,14 +1032,12 @@
 
     u1_slice_type = u4_temp;
     COPYTHECONTEXT("SH: slice_type",(u1_slice_type));
-    ps_dec->u1_sl_typ_5_9 = 0;
     /* Find Out the Slice Type is 5 to 9 or not then Set the Flag   */
     /* u1_sl_typ_5_9 = 1 .Which tells that all the slices in the Pic*/
     /* will be of same type of current                            */
     if(u1_slice_type > 4)
     {
         u1_slice_type -= 5;
-        ps_dec->u1_sl_typ_5_9 = 1;
     }
 
     {
diff --git a/decoder/ih264d_structs.h b/decoder/ih264d_structs.h
index cde3dd7..c83c34e 100644
--- a/decoder/ih264d_structs.h
+++ b/decoder/ih264d_structs.h
@@ -897,11 +897,9 @@
 
     /* slice Header Simplification */
     UWORD8 u1_pr_sl_type;
-    UWORD8 u1_sl_typ_5_9;
     WORD32 i4_frametype;
     UWORD32 u4_app_disp_width;
     WORD32 i4_error_code;
-    UWORD8 u1_first_pb_nal_in_pic;
     UWORD32 u4_bitoffset;
 
     /* Variables added to handle field pics */