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 #ifndef _IH264D_DPB_MANAGER_H_
21 #define _IH264D_DPB_MANAGER_H_
22 /*!
23 ***************************************************************************
24 * \file ih264d_dpb_manager.h
25 *
26 * \brief
27 *    Decoded Picture Buffer Manager Include File
28 *
29 * Detailed_description
30 *
31 * \date
32 *    19-12-2002
33 *
34 * \author  Sriram Sethuraman
35 ***************************************************************************
36 */
37 #include "ih264_typedefs.h"
38 #include "ih264_macros.h"
39 #include "ih264_platform_macros.h"
40 #include "ih264d_bitstrm.h"
41 #include "ih264d_defs.h"
42 
43 #define END_OF_MMCO                 0
44 #define MARK_ST_PICNUM_AS_NONREF    1
45 #define MARK_LT_INDEX_AS_NONREF     2
46 #define MARK_ST_PICNUM_AS_LT_INDEX  3
47 #define SET_MAX_LT_INDEX            4
48 #define RESET_REF_PICTURES          5
49 #define SET_LT_INDEX                6
50 #define RESET_NONREF_PICTURES       7
51 #define RESET_ALL_PICTURES          8
52 
53 struct field_t
54 {
55     /* picNum of tbe reference field              */
56     WORD32 i4_pic_num;
57 
58     /*  assigned when used for long term reference */
59     /* else MAX_REF_BUFS+1 */
60     UWORD8 u1_long_term_frame_idx;
61 
62     /* 0 : unused for reference                   */
63     /* 1 : used for short term reference          */
64     /* 2 : used for long term reference           */
65     UWORD8 u1_reference_info;
66 };
67 
68 
69 struct dpb_info_t
70 {
71   struct pic_buffer_t *ps_pic_buf;       /** Pointer to picture buffer structure */
72   WORD32 i4_frame_num;      /** frame number of picture - unique for each ref*/
73   struct dpb_info_t *ps_prev_short;/** Link to the DPB with previous picNum */
74   struct dpb_info_t *ps_prev_long;     /** Link to the DPB with previous long term frame*/
75   struct field_t s_top_field;       /** Contains information of the top_field
76                                      reference info, pic num and longt term frame idx */
77   struct field_t s_bot_field;       /** Contains information of the bot_field
78                                      reference info, pic num and longt term frame idx */
79   UWORD8 u1_buf_id;     /** bufID from bufAPI */
80   UWORD8 u1_used_as_ref;        /** whether buffer is used as ref for frame or
81                                      complementary reference field pair */
82   UWORD8 u1_lt_idx;     /** If buf is assigned long-term index; else MAX_REF_BUFS+1 */
83 
84 };
85 
86 typedef struct
87 {
88   struct pic_buffer_t *ps_def_dpb[MAX_REF_BUFS];/** DPB in default index order */
89   struct pic_buffer_t *ps_mod_dpb[2][2 * MAX_REF_BUFS];/** DPB in reordered index order, 0-fwd,1-bwd */
90   struct pic_buffer_t *ps_init_dpb[2][2 * MAX_REF_BUFS];/** DPB in reordered index order, 0-fwd,1-bwd */
91   struct dpb_info_t *ps_dpb_st_head;     /** Pointer to the most recent picNum */
92   struct dpb_info_t *ps_dpb_ht_head;     /** Pointer to the smallest LT index */
93   struct dpb_info_t as_dpb_info[MAX_REF_BUFS];       /** Physical storage for dpbInfo for ref bufs */
94   UWORD8 u1_num_st_ref_bufs;        /** Number of short term ref. buffers */
95   UWORD8 u1_num_lt_ref_bufs;        /** Number of long term ref. buffer */
96   UWORD8 u1_max_lt_pic_idx_plus1;       /** Maximum long term pictures - 0 to max_long_term_pic_idx */
97   UWORD8 u1_num_gaps;       /** Total number of outstanding gaps */
98   void * pv_codec_handle;             /* For Error Handling */
99   WORD32 i4_max_frm_num;        /** Max frame number */
100   WORD32 ai4_gaps_start_frm_num[MAX_FRAMES];/** start frame number for a gap seqn */
101   WORD32 ai4_gaps_end_frm_num[MAX_FRAMES];       /** start frame number for a gap seqn */
102   WORD8  ai1_gaps_per_seq[MAX_FRAMES];      /** number of gaps with each gap seqn */
103   WORD32 ai4_poc_buf_id_map[MAX_FRAMES][3];
104   WORD8 i1_poc_buf_id_entries;
105   WORD8 i1_gaps_deleted;
106   UWORD16 u2_pic_wd;
107   UWORD16 u2_pic_ht;
108 }dpb_manager_t;
109 
110 /** Structure store the MMC Commands */
111 struct MMCParams
112 {
113   UWORD32 u4_mmco;      /** memory managemet control operation */
114   UWORD32 u4_diff_pic_num;      /** diff Of Pic Nums Minus1 */
115   UWORD32 u4_lt_idx;        /** Long Term Pic Idx */
116   UWORD32 u4_max_lt_idx_plus1;      /** MaxLongTermPicIdxPlus1 */
117 };
118 
119 typedef struct
120 {
121   UWORD8  u1_dpb_commands_read;     /** Flag to indicate that DBP commands are read */
122   UWORD8  u1_buf_mode;      /** decoder Pic bugffering mode*/
123   UWORD8  u1_num_of_commands;       /** Number of MMC commands */
124   /* These variables are ised in case of IDR pictures only */
125   UWORD8  u1_idr_pic;       /** = 1 ,IDR pic */
126   UWORD8  u1_no_output_of_prior_pics_flag;
127   UWORD8  u1_long_term_reference_flag;
128   struct MMCParams  as_mmc_params[MAX_REF_BUFS];      /* < Buffer to store MMC commands */
129   UWORD8 u1_dpb_commands_read_slc;
130 }dpb_commands_t;
131 
132 void ih264d_init_ref_bufs(dpb_manager_t *ps_dpb_mgr);
133 
134 WORD32 ih264d_insert_st_node(dpb_manager_t *ps_dpb_mgr,
135                           struct pic_buffer_t *ps_pic_buf,
136                           UWORD8 u1_buf_id,
137                           UWORD32 u2_cur_pic_num);
138 WORD32 ih264d_update_default_index_list(dpb_manager_t *ps_dpb_mgr);
139 WORD32 ih264d_do_mmco_buffer(dpb_commands_t *ps_dpb_cmds,
140                           dpb_manager_t *ps_dpb_mgr,
141                           UWORD8 u1_numRef_frames_for_seq,
142                           UWORD32 u4_cur_pic_num,
143                           UWORD32 u2_u4_max_pic_num_minus1,
144                           UWORD8 u1_nal_unit_type,
145                           struct pic_buffer_t *ps_pic_buf,
146                           UWORD8 u1_buf_id,
147                           UWORD8 u1_fld_pic_flag,
148                           UWORD8 u1_curr_pic_in_err);
149 void ih264d_release_pics_in_dpb(void *pv_dec,
150                                 UWORD8 u1_disp_bufs);
151 void ih264d_reset_ref_bufs(dpb_manager_t *ps_dpb_mgr);
152 WORD32 ih264d_delete_st_node_or_make_lt(dpb_manager_t *ps_dpb_mgr,
153                                       WORD32 u4_pic_num,
154                                       UWORD32 u4_lt_idx,
155                                       UWORD8 u1_fld_pic_flag);
156 
157 WORD32 ih264d_delete_gap_frm_mmco(dpb_manager_t *ps_dpb_mgr,
158                                   WORD32 i4_frame_num,
159                                   UWORD8 *pu1_del_node);
160 
161 WORD32 ih264d_delete_gap_frm_sliding(dpb_manager_t *ps_dpb_mgr,
162                                      WORD32 i4_frame_num,
163                                      UWORD8 *pu1_del_node);
164 
165 WORD32 ih264d_do_mmco_for_gaps(dpb_manager_t *ps_dpb_mgr,
166                              UWORD8 u1_num_ref_frames);
167 
168 WORD32 ih264d_insert_pic_in_display_list(dpb_manager_t *ps_dpb_mgr,
169                                          UWORD8 u1_buf_id,
170                                          WORD32 i4_display_poc,
171                                          UWORD32 u4_frame_num);
172 void ih264d_delete_nonref_nondisplay_pics(dpb_manager_t *ps_dpb_mgr);
173 #endif /*  _IH264D_DPB_MANAGER_H_ */
174