xref: /aosp_15_r20/external/libavc/common/ih264_dpb_mgr.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
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 *******************************************************************************
23 * @file
24 *  ih264_dpb_mgr.h
25 *
26 * @brief
27 *  Function declarations used for decoded picture buffer management
28 *
29 * @author
30 *  none
31 *
32 * @remarks
33 *  none
34 *
35 *******************************************************************************
36 */
37 #ifndef _IH264_DPB_MGR_H_
38 #define _IH264_DPB_MGR_H_
39 
40 /*****************************************************************************/
41 /* Constant Macros                                                           */
42 /*****************************************************************************/
43 #define MAX_DPB_BUFS                (MAX_DPB_SIZE * 4)
44 
45 #define MARK_ST_PICNUM_AS_NONREF    1
46 #define MARK_LT_INDEX_AS_NONREF     2
47 #define MARK_ST_PICNUM_AS_LT_INDEX  3
48 #define RESET_REF_PICTURES          5
49 
50 /*****************************************************************************/
51 /* Enums                                                                     */
52 /*****************************************************************************/
53 enum
54 {
55     INVALID = -1,
56     UNUSED_FOR_REF = 0,
57     LONG_TERM_REF,
58     SHORT_TERM_REF,
59 };
60 
61 /*****************************************************************************/
62 /* Structure Definitions                                                     */
63 /*****************************************************************************/
64 typedef struct dpb_info_t
65 {
66     /**
67      * Pointer to picture buffer structure
68      */
69     pic_buf_t *ps_pic_buf;
70 
71     /**
72      * Link to the DPB buffer with previous link
73      */
74     struct dpb_info_t *ps_prev_dpb;
75 
76 } dpb_info_t;
77 
78 typedef struct
79 {
80     /**
81      * Pointer to the most recent pic Num
82      */
83     dpb_info_t *ps_dpb_short_term_head;
84 
85     /**
86      * Pointer to the most recent pic Num
87      */
88     dpb_info_t *ps_dpb_long_term_head;
89 
90     /**
91      * Physical storage for dpbInfo for ref bufs
92      */
93     dpb_info_t as_dpb_info[MAX_DPB_BUFS];
94 
95     /**
96      * Array of structures for bottom field.
97      */
98     pic_buf_t as_top_field_pics[MAX_DPB_BUFS];
99 
100     /**
101      * Array of structures for bottom field.
102      */
103     pic_buf_t as_bottom_field_pics[MAX_DPB_BUFS];
104 
105     /**
106      * Number of short-term reference buffers
107      */
108     UWORD8 u1_num_short_term_ref_bufs;
109 
110     /**
111      * Number of long-term reference buffers
112      */
113     UWORD8 u1_num_long_term_ref_bufs;
114 
115     /**
116      * buffer ID current frame
117      */
118     WORD32 i4_cur_frame_buf_id;
119 
120 } dpb_mgr_t;
121 
122 /*****************************************************************************/
123 /* Function Declarations                                                     */
124 /*****************************************************************************/
125 void ih264_dpb_mgr_init(dpb_mgr_t *ps_dpb_mgr);
126 
127 WORD32 ih264_dpb_mgr_insert_ref_frame(dpb_mgr_t *ps_dpb_mgr,
128                                       pic_buf_t *ps_pic_buf,
129                                       WORD32 reference_type,
130                                       UWORD32 frame_num,
131                                       WORD32 long_term_frame_idx);
132 
133 WORD32 ih264_dpb_mgr_delete_ref_frame(dpb_mgr_t *ps_dpb_mgr,
134                                       WORD32 reference_type);
135 
136 WORD32 ih264_dpb_mgr_delete_all_ref_frames(dpb_mgr_t *ps_dpb_mgr);
137 
138 WORD32 ih264_dpb_mgr_count_ref_frames(dpb_mgr_t *ps_dpb_mgr,
139                                       WORD32 curr_frame_num,
140                                       WORD32 max_frame_num);
141 
142 WORD32 ih264_dpb_mgr_delete_short_ref_frame(dpb_mgr_t *ps_dpb_mgr,
143                                             WORD32 curr_frame_num,
144                                             WORD32 max_frame_num);
145 
146 WORD32 ih264_dpb_mgr_insert_ref_field(dpb_mgr_t *ps_dpb_mgr,
147                                       pic_buf_t *ps_pic_buf,
148                                       WORD32 reference_type,
149                                       UWORD32 frame_num,
150                                       WORD32 long_term_frame_idx);
151 
152 WORD32 ih264_dpb_mgr_delete_ref_field(dpb_mgr_t *ps_dpb_mgr,
153                                       WORD32 reference_type);
154 
155 WORD32 ih264_dpb_mgr_alternate_ref_fields(dpb_mgr_t *ps_dpb_mgr,
156                                           WORD32 reference_type,
157                                           WORD32 first_field_type);
158 
159 WORD32 ih264_dpb_mgr_sort_short_term_fields_by_frame_num(dpb_mgr_t *ps_dpb_mgr,
160                                                          WORD32 curr_frame_num,
161                                                          WORD32 first_field_type,
162                                                          WORD32 max_frame_num);
163 
164 WORD32 ih264_dpb_mgr_sort_short_term_fields_by_poc_l0(dpb_mgr_t *ps_dpb_mgr,
165                                                       WORD32 curr_poc,
166                                                       WORD32 first_field_type);
167 
168 WORD32 ih264_dpb_mgr_sort_short_term_fields_by_poc_l1(dpb_mgr_t *ps_dpb_mgr,
169                                                       WORD32 curr_poc,
170                                                       WORD32 first_field_type);
171 
172 WORD32 ih264_dpb_mgr_sort_long_term_fields_by_frame_idx(dpb_mgr_t *ps_dpb_mgr,
173                                                         WORD32 first_field_type);
174 
175 WORD32 ih264_dpb_mgr_delete_long_ref_fields_max_frame_idx(dpb_mgr_t *ps_dpb_mgr,
176                                                           WORD32 max_frame_idx);
177 
178 void ih264_dpb_mgr_del_ref(dpb_mgr_t *ps_dpb_mgr,
179                            buf_mgr_t *ps_buf_mgr,
180                            WORD32 u4_abs_poc);
181 
182 pic_buf_t *ih264_dpb_mgr_get_ref_by_nearest_poc(dpb_mgr_t *ps_dpb_mgr,
183                                                 WORD32 cur_abs_poc);
184 
185 pic_buf_t *ih264_dpb_mgr_get_ref_by_poc(dpb_mgr_t *ps_dpb_mgr, WORD32 abs_poc);
186 
187 pic_buf_t *ih264_dpb_mgr_get_ref_by_poc_lsb(dpb_mgr_t *ps_dpb_mgr,
188                                             WORD32 poc_lsb);
189 
190 void ih264_dpb_mgr_reset(dpb_mgr_t *ps_dpb_mgr, buf_mgr_t *ps_buf_mgr);
191 
192 void ih264_dpb_mgr_release_pics(buf_mgr_t *ps_buf_mgr, UWORD8 u1_disp_bufs);
193 
194 #endif /*  _IH264_DPB_MGR_H_ */
195