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 */
ih264_disp_mgr_init(disp_mgr_t * ps_disp_mgr)76 void ih264_disp_mgr_init(disp_mgr_t *ps_disp_mgr)
77 {
78 WORD32 id;
79
80 ps_disp_mgr->u4_last_abs_poc = DEFAULT_POC;
81
82 for(id = 0; id < DISP_MGR_MAX_CNT; id++)
83 {
84 ps_disp_mgr->ai4_abs_poc[id] = DEFAULT_POC;
85 ps_disp_mgr->apv_ptr[id] = NULL;
86 }
87 }
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 */
ih264_disp_mgr_add(disp_mgr_t * ps_disp_mgr,WORD32 buf_id,WORD32 abs_poc,void * pv_ptr)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 {
121 if(buf_id >= DISP_MGR_MAX_CNT)
122 {
123 return (-1);
124 }
125
126 if(ps_disp_mgr->apv_ptr[buf_id] != NULL)
127 {
128 return (-1);
129 }
130
131 ps_disp_mgr->apv_ptr[buf_id] = pv_ptr;
132 ps_disp_mgr->ai4_abs_poc[buf_id] = abs_poc;
133
134 return 0;
135 }
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 */
ih264_disp_mgr_get(disp_mgr_t * ps_disp_mgr,WORD32 * pi4_buf_id)158 void* ih264_disp_mgr_get(disp_mgr_t *ps_disp_mgr, WORD32 *pi4_buf_id)
159 {
160 WORD32 id;
161 void *pv_ret_ptr = NULL;
162 WORD32 i4_min_poc = 0x7FFFFFFF;
163 WORD32 min_poc_id = -1;
164
165 /* Find minimum POC */
166 for(id = 0; id < DISP_MGR_MAX_CNT; id++)
167 {
168 if((DEFAULT_POC != ps_disp_mgr->ai4_abs_poc[id]) &&
169 (ps_disp_mgr->ai4_abs_poc[id] <= i4_min_poc))
170 {
171 i4_min_poc = ps_disp_mgr->ai4_abs_poc[id];
172 min_poc_id = id;
173 }
174 }
175 *pi4_buf_id = min_poc_id;
176 /* If all pocs are still default_poc then return NULL */
177 if(-1 == min_poc_id)
178 {
179 return NULL;
180 }
181
182 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 ps_disp_mgr->apv_ptr[min_poc_id] = NULL;
186 ps_disp_mgr->ai4_abs_poc[min_poc_id] = DEFAULT_POC;
187
188 return pv_ret_ptr;
189 }
190