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