• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2 *
3 * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
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 /**
19 *******************************************************************************
20 * @file
21 *  ihevc_disp_mgr.c
22 *
23 * @brief
24 *  Contains function definitions for display management
25 *
26 * @author
27 *  Srinivas T
28 *
29 * @par List of Functions:
30 *   - ihevc_disp_mgr_init()
31 *   - ihevc_disp_mgr_add()
32 *   - ihevc_disp_mgr_get()
33 *
34 * @remarks
35 *  None
36 *
37 *******************************************************************************
38 */
39 #include <stdlib.h>
40 #include "ihevc_typedefs.h"
41 #include "ihevc_macros.h"
42 #include "ihevc_func_selector.h"
43 #include "ihevc_disp_mgr.h"
44 
45 
46 /**
47 *******************************************************************************
48 *
49 * @brief
50 *    Initialization function for display buffer manager
51 *
52 * @par Description:
53 *    Initializes the display buffer management structure
54 *
55 * @param[in] ps_disp_mgr
56 *  Pointer to the display buffer management structure
57 *
58 * @returns none
59 *
60 * @remarks
61 *  None
62 *
63 *******************************************************************************
64 */
ihevc_disp_mgr_init(disp_mgr_t * ps_disp_mgr)65 void ihevc_disp_mgr_init(
66                 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 diaplay 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 */
ihevc_disp_mgr_add(disp_mgr_t * ps_disp_mgr,WORD32 buf_id,WORD32 abs_poc,void * pv_ptr)108 WORD32 ihevc_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 */
ihevc_disp_mgr_get(disp_mgr_t * ps_disp_mgr,WORD32 * pi4_buf_id)151 void* ihevc_disp_mgr_get(
152                 disp_mgr_t *ps_disp_mgr,
153                 WORD32 *pi4_buf_id)
154 {
155     WORD32 id;
156     void *pv_ret_ptr;
157     WORD32 i4_min_poc;
158     WORD32 min_poc_id;
159 
160 
161     pv_ret_ptr = NULL;
162     i4_min_poc = 0x7FFFFFFF;
163     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     return pv_ret_ptr;
188 }
189