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