/src/libavc/common/ih264_disp_mgr.c
Line | Count | Source |
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_disp_mgr.c |
25 | | * |
26 | | * @brief |
27 | | * Contains function definitions for display management |
28 | | * |
29 | | * @author |
30 | | * ittiam |
31 | | * |
32 | | * @par List of Functions: |
33 | | * - ih264_disp_mgr_init |
34 | | * - ih264_disp_mgr_add |
35 | | * - ih264_disp_mgr_get |
36 | | * |
37 | | * @remarks |
38 | | * none |
39 | | * |
40 | | ******************************************************************************* |
41 | | */ |
42 | | |
43 | | /*****************************************************************************/ |
44 | | /* File Includes */ |
45 | | /*****************************************************************************/ |
46 | | |
47 | | /* System Include Files */ |
48 | | #include <stdlib.h> |
49 | | |
50 | | /* User Include Files */ |
51 | | #include "ih264_typedefs.h" |
52 | | #include "ih264_macros.h" |
53 | | #include "ih264_disp_mgr.h" |
54 | | |
55 | | /*****************************************************************************/ |
56 | | /* Function Definitions */ |
57 | | /*****************************************************************************/ |
58 | | |
59 | | /** |
60 | | ******************************************************************************* |
61 | | * |
62 | | * @brief Initialization function for display buffer manager |
63 | | * |
64 | | * @par Description |
65 | | * Initializes the display buffer management structure |
66 | | * |
67 | | * @param[in] ps_disp_mgr |
68 | | * Pointer to the display buffer management structure |
69 | | * |
70 | | * @returns none |
71 | | * |
72 | | * @remarks none |
73 | | * |
74 | | ******************************************************************************* |
75 | | */ |
76 | | void ih264_disp_mgr_init(disp_mgr_t *ps_disp_mgr) |
77 | 46.7k | { |
78 | 46.7k | WORD32 id; |
79 | | |
80 | 46.7k | ps_disp_mgr->u4_last_abs_poc = DEFAULT_POC; |
81 | | |
82 | 3.03M | for(id = 0; id < DISP_MGR_MAX_CNT; id++) |
83 | 2.99M | { |
84 | 2.99M | ps_disp_mgr->ai4_abs_poc[id] = DEFAULT_POC; |
85 | 2.99M | ps_disp_mgr->apv_ptr[id] = NULL; |
86 | 2.99M | } |
87 | 46.7k | } |
88 | | |
89 | | /** |
90 | | ******************************************************************************* |
91 | | * |
92 | | * @brief Adds a buffer to the display manager |
93 | | * |
94 | | * @par Description: |
95 | | * Adds a buffer to the display buffer manager |
96 | | * |
97 | | * @param[in] ps_disp_mgr |
98 | | * Pointer to the display buffer management structure |
99 | | * |
100 | | * @param[in] buf_id |
101 | | * ID of the display buffer |
102 | | * |
103 | | * @param[in] abs_poc |
104 | | * Absolute POC of the display buffer |
105 | | * |
106 | | * @param[in] pv_ptr |
107 | | * Pointer to the display buffer |
108 | | * |
109 | | * @returns 0 if success, -1 otherwise |
110 | | * |
111 | | * @remarks |
112 | | * None |
113 | | * |
114 | | ******************************************************************************* |
115 | | */ |
116 | | WORD32 ih264_disp_mgr_add(disp_mgr_t *ps_disp_mgr, |
117 | | WORD32 buf_id, |
118 | | WORD32 abs_poc, |
119 | | void *pv_ptr) |
120 | 178k | { |
121 | 178k | if(buf_id >= DISP_MGR_MAX_CNT) |
122 | 0 | { |
123 | 0 | return (-1); |
124 | 0 | } |
125 | | |
126 | 178k | if(ps_disp_mgr->apv_ptr[buf_id] != NULL) |
127 | 538 | { |
128 | 538 | return (-1); |
129 | 538 | } |
130 | | |
131 | 178k | ps_disp_mgr->apv_ptr[buf_id] = pv_ptr; |
132 | 178k | ps_disp_mgr->ai4_abs_poc[buf_id] = abs_poc; |
133 | | |
134 | 178k | return 0; |
135 | 178k | } |
136 | | |
137 | | /** |
138 | | ******************************************************************************* |
139 | | * |
140 | | * @brief Gets the next buffer |
141 | | * |
142 | | * @par Description: |
143 | | * Gets the next display buffer |
144 | | * |
145 | | * @param[in] ps_disp_mgr |
146 | | * Pointer to the display buffer structure |
147 | | * |
148 | | * @param[out] pi4_buf_id |
149 | | * Pointer to hold buffer id of the display buffer being returned |
150 | | * |
151 | | * @returns Pointer to the next display buffer |
152 | | * |
153 | | * @remarks |
154 | | * None |
155 | | * |
156 | | ******************************************************************************* |
157 | | */ |
158 | | void* ih264_disp_mgr_get(disp_mgr_t *ps_disp_mgr, WORD32 *pi4_buf_id) |
159 | 308k | { |
160 | 308k | WORD32 id; |
161 | 308k | void *pv_ret_ptr = NULL; |
162 | 308k | WORD32 i4_min_poc = 0x7FFFFFFF; |
163 | 308k | WORD32 min_poc_id = -1; |
164 | | |
165 | | /* Find minimum POC */ |
166 | 20.0M | for(id = 0; id < DISP_MGR_MAX_CNT; id++) |
167 | 19.7M | { |
168 | 19.7M | if((DEFAULT_POC != ps_disp_mgr->ai4_abs_poc[id]) && |
169 | 308k | (ps_disp_mgr->ai4_abs_poc[id] <= i4_min_poc)) |
170 | 200k | { |
171 | 200k | i4_min_poc = ps_disp_mgr->ai4_abs_poc[id]; |
172 | 200k | min_poc_id = id; |
173 | 200k | } |
174 | 19.7M | } |
175 | 308k | *pi4_buf_id = min_poc_id; |
176 | | /* If all pocs are still default_poc then return NULL */ |
177 | 308k | if(-1 == min_poc_id) |
178 | 143k | { |
179 | 143k | return NULL; |
180 | 143k | } |
181 | | |
182 | 165k | pv_ret_ptr = ps_disp_mgr->apv_ptr[min_poc_id]; |
183 | | |
184 | | /* Set abs poc to default and apv_ptr to null so that the buffer is not returned again */ |
185 | 165k | ps_disp_mgr->apv_ptr[min_poc_id] = NULL; |
186 | 165k | ps_disp_mgr->ai4_abs_poc[min_poc_id] = DEFAULT_POC; |
187 | | |
188 | 165k | return pv_ret_ptr; |
189 | 308k | } |