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