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 *  impeg2_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 *   - impeg2_disp_mgr_init()
33 *   - impeg2_disp_mgr_add()
34 *   - impeg2_disp_mgr_get()
35 *
36 * @remarks
37 *  None
38 *
39 *******************************************************************************
40 */
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include "iv_datatypedef.h"
44 #include "impeg2_defs.h"
45 #include "impeg2_disp_mgr.h"
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 */
impeg2_disp_mgr_init(disp_mgr_t * ps_disp_mgr)66 void impeg2_disp_mgr_init(
67                 disp_mgr_t *ps_disp_mgr)
68 {
69     WORD32 id;
70 
71 
72     for(id = 0; id < DISP_MGR_MAX_CNT; id++)
73     {
74         ps_disp_mgr->apv_ptr[id] = NULL;
75     }
76 
77     ps_disp_mgr->i4_wr_idx = 0;
78     ps_disp_mgr->i4_rd_idx = 0;
79 }
80 
81 
82 /**
83 *******************************************************************************
84 *
85 * @brief
86 *     Adds a buffer to the display manager
87 *
88 * @par Description:
89 *      Adds a buffer to the display buffer manager
90 *
91 * @param[in] ps_disp_mgr
92 *  Pointer to the diaplay buffer management structure
93 *
94 * @param[in] buf_id
95 *  ID of the display buffer
96 *
97 * @param[in] abs_poc
98 *  Absolute POC of the display buffer
99 *
100 * @param[in] pv_ptr
101 *  Pointer to the display buffer
102 *
103 * @returns  0 if success, -1 otherwise
104 *
105 * @remarks
106 *  None
107 *
108 *******************************************************************************
109 */
impeg2_disp_mgr_add(disp_mgr_t * ps_disp_mgr,void * pv_ptr,WORD32 i4_buf_id)110 WORD32 impeg2_disp_mgr_add(disp_mgr_t *ps_disp_mgr,
111                           void *pv_ptr,
112                           WORD32 i4_buf_id)
113 {
114 
115 
116     WORD32 id;
117     id = ps_disp_mgr->i4_wr_idx % DISP_MGR_MAX_CNT;
118 
119     ps_disp_mgr->apv_ptr[id] = pv_ptr;
120     ps_disp_mgr->ai4_buf_id[id] = i4_buf_id;
121     ps_disp_mgr->i4_wr_idx++;
122 
123     return 0;
124 }
125 
126 
127 /**
128 *******************************************************************************
129 *
130 * @brief
131 *  Gets the next buffer
132 *
133 * @par Description:
134 *  Gets the next display buffer
135 *
136 * @param[in] ps_disp_mgr
137 *  Pointer to the display buffer structure
138 *
139 * @param[out]  pi4_buf_id
140 *  Pointer to hold buffer id of the display buffer being returned
141 *
142 * @returns  Pointer to the next display buffer
143 *
144 * @remarks
145 *  None
146 *
147 *******************************************************************************
148 */
impeg2_disp_mgr_get(disp_mgr_t * ps_disp_mgr,WORD32 * pi4_buf_id)149 void* impeg2_disp_mgr_get(disp_mgr_t *ps_disp_mgr, WORD32 *pi4_buf_id)
150 {
151     WORD32 id;
152 
153     *pi4_buf_id = -1;
154 
155     if(ps_disp_mgr->i4_rd_idx < ps_disp_mgr->i4_wr_idx)
156     {
157         id = ps_disp_mgr->i4_rd_idx % DISP_MGR_MAX_CNT;
158         if(NULL == ps_disp_mgr->apv_ptr[id])
159         {
160             return NULL;
161         }
162 
163         *pi4_buf_id = ps_disp_mgr->ai4_buf_id[id];
164 
165         ps_disp_mgr->i4_rd_idx++;
166 
167         return ps_disp_mgr->apv_ptr[id];
168     }
169     else
170         return NULL;
171 
172 }
173