Create Project for repo.or.cz
[vp.git] / src / pp / PostProcess.cpp
blobf5fa4c5505efe405b4a6025df816c9935e2dbcbb
1 /*******************************************************************************
2 * File Name : src/pp/PostProcess.cpp
3 *
4 * Author : Henry He
5 * Created Time : Fri 30 Oct 2009 01:03:05 PM CST
6 * Description :
7 ******************************************************************************/
10 /*******************************************************************************
11 * Desc : Includes Files
12 ******************************************************************************/
13 #include <poll.h>
15 #include "pp/PostProcess.h"
19 /*******************************************************************************
20 * Desc : Macro Definations
21 ******************************************************************************/
24 /*******************************************************************************
25 * Desc : Type Definations
26 ******************************************************************************/
29 /*******************************************************************************
30 * Desc : Global Variables
31 ******************************************************************************/
34 /*******************************************************************************
35 * Desc : File Variables
36 ******************************************************************************/
41 // ==================== LIFECYCLE =========================================
46 /******************************************************************************
47 * Func : PostProcessor::PostProcessor
48 * Desc : Constructor of PostProcessor
49 * Args :
50 * Outs :
51 ******************************************************************************/
52 PostProcessor::PostProcessor ()
54 m_zhmMutex.Init ();
55 m_bCreated = false;
56 } // ----- end of method PostProcessor::PostProcessor (constructor) -----
59 /******************************************************************************
60 * Func : PostProcessor::~PostProcessor
61 * Desc : Deconstructor of PostProcessor
62 * Args :
63 * Outs :
64 ******************************************************************************/
65 PostProcessor::~PostProcessor ()
67 Destroy ();
68 m_zhmMutex.Unlock ();
69 } // ----- end of method PostProcessor::~PostProcessor (deconstructor) -----
75 // ==================== OPERATIONS =========================================
80 /******************************************************************************
81 * Func : PostProcessor::Create
82 * Desc : Create instance of PostProcessor
83 * Args : pcDevPath Path of pp device
84 * Outs : If success return 0, otherwise return error code
85 ******************************************************************************/
86 int PostProcessor::Create (const char *pcDevPath)
89 ASSERT (pcDevPath != NULL);
91 // Lock this instance
92 m_zhmMutex.Init ();
94 if (m_bCreated) {
95 // Unlock this instance
96 m_zhmMutex.Unlock ();
97 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("already created") );
98 return POST_PROCESSOR_ERR_ALREADY_CREATED;
101 // Open post process device
102 m_fdPP = open ( pcDevPath, O_RDWR|O_NONBLOCK );
103 if (m_fdPP < 0) {
104 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("can't open %s", pcDevPath) );
105 goto failed;
108 // Notify that this instance is created
109 m_bCreated = true;
111 // Unlock this instance
112 m_zhmMutex.Unlock ();
114 return 0;
116 failed:
117 // Unlock this instance
118 m_zhmMutex.Unlock ();
120 return POST_PROCESSOR_ERR_FAILED;
125 /******************************************************************************
126 * Func : PostProcessor::Destroy
127 * Desc : Destroy this instance
128 * Args : NONE
129 * Outs : NONE
130 ******************************************************************************/
131 void PostProcessor::Destroy ()
134 // Lock this instance
135 m_zhmMutex.Lock ();
137 if(!m_bCreated) {
138 // Unlock this instance
139 m_zhmMutex.Unlock ();
141 HLH_DEBUG ( HLH_DEBUG_PP, ("not created") );
142 return;
145 // Close post process device
146 close (m_fdPP);
147 m_fdPP = -1;
149 // Notify this instance not created or set parameter
150 m_bSetParam = false;
151 m_bCreated = false;
153 // Unlock this instance
154 m_zhmMutex.Unlock ();
162 /******************************************************************************
163 * Func : PostProcessor::SetParam
164 * Desc : Set most parameter of /dev/misc/s3c-pp
165 * Args : unSrcWidthBuf Width of source buffer
166 * unSrcHeightBuf Heigth of source buffer
167 * unSrcX X of source buffer to convert
168 * unSrcY Y of source buffer to convert
169 * unSrcWidth Width of source buffer to convert
170 * unSrcHeight Height of source buffer to convert
171 * unSrcColorSpace Color space of source buffer to convert
173 * unDstWidthBuf Width of dst buffer
174 * unDstHeightBuf Heigth of dst buffer
175 * unDstX X of dst buffer to convert
176 * unDstY Y of dst buffer to convert
177 * unDstWidth Width of dst buffer to convert
178 * unDstHeight Height of dst buffer to convert
179 * unDstColorSpace Color space of dst buffer to convert
180 * Outs : If success return 0, otherwise return error code
181 ******************************************************************************/
182 int PostProcessor::SetParam (
183 UINT32 unSrcWidthBuf, UINT32 unSrcHeightBuf,
184 UINT32 unSrcX, UINT32 unSrcY,
185 UINT32 unSrcWidth, UINT32 unSrcHeight,
186 UINT32 unSrcColorSpace,
188 UINT32 unDstWidthBuf, UINT32 unDstHeightBuf,
189 UINT32 unDstX, UINT32 unDstY,
190 UINT32 unDstWidth, UINT32 unDstHeight,
191 UINT32 unDstColorSpace )
193 int nRetVal;
195 // Lock this instance
196 m_zhmMutex.Lock ();
198 // Check if instance created
199 if (!m_bCreated) {
200 // Unlock this instance
201 m_zhmMutex.Unlock ();
202 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("not created") );
203 return POST_PROCESSOR_ERR_NOT_CREATED;
206 // Set post processor configuration
207 m_zspParam.src_full_width = unSrcWidthBuf;
208 m_zspParam.src_full_height = unSrcHeightBuf;
209 m_zspParam.src_start_x = unSrcX;
210 m_zspParam.src_start_y = unSrcY;
211 m_zspParam.src_width = unSrcWidth;
212 m_zspParam.src_height = unSrcHeight;
213 m_zspParam.src_color_space = (s3c_color_space_t) unSrcColorSpace;
214 m_zspParam.dst_full_width = unDstWidthBuf;
215 m_zspParam.dst_full_height = unDstHeightBuf;
216 m_zspParam.dst_start_x = unDstX;
217 m_zspParam.dst_start_y = unDstY;
218 m_zspParam.dst_width = unDstWidth;
219 m_zspParam.dst_height = unDstHeight;
220 m_zspParam.dst_color_space = (s3c_color_space_t) unDstColorSpace;
221 m_zspParam.out_path = DMA_ONESHOT;
223 nRetVal = ioctl (m_fdPP, S3C_PP_SET_PARAMS, &m_zspParam);
224 if (nRetVal < 0) {
225 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("can't set parameter") );
226 goto failed;
229 // Notify that the parameter of this instance has been set.
230 m_bSetParam = true;
232 // Unlock this instance
233 m_zhmMutex.Unlock ();
235 return 0;
237 failed:
239 // Unlock this instance
240 m_zhmMutex.Unlock ();
242 return POST_PROCESSOR_ERR_FAILED;
248 /******************************************************************************
249 * Func : PostProcessor::Process
250 * Desc : Convert from pvSrcBuf to pvDstBuf (must be DMA memory space)
251 * Args :
252 * Outs :
253 ******************************************************************************/
254 int PostProcessor::Process (void * pvSrcBuf, void *pvDstBuf)
257 int nRetVal;
258 struct pollfd zpfPoll;
260 // Lock this instance
261 m_zhmMutex.Lock ();
263 // Check if instance created
264 if (!m_bCreated) {
265 // Unlock this instance
266 m_zhmMutex.Unlock ();
268 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("not created") );
269 return POST_PROCESSOR_ERR_NOT_CREATED;
272 // Check if parameter set
273 if (!m_bSetParam) {
274 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("process before set parameter") );
275 goto failed;
278 // Set source address
279 m_zspParam.src_buf_addr_phy = (UINT32)pvSrcBuf;
280 nRetVal = ioctl (m_fdPP, S3C_PP_SET_SRC_BUF_ADDR_PHY, &m_zspParam);
281 if (nRetVal < 0) {
282 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("ioctl set source address failed") );
283 goto failed;
286 m_zspParam.dst_buf_addr_phy = (UINT32)pvDstBuf;
287 nRetVal = ioctl (m_fdPP, S3C_PP_SET_DST_BUF_ADDR_PHY, &m_zspParam);
288 if (nRetVal < 0) {
289 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("ioctl set dst address failed") );
290 goto failed;
293 // Wait for ready ?
294 zpfPoll.fd = m_fdPP;
295 zpfPoll.events = POLLOUT | POLLERR;
297 nRetVal = poll (&zpfPoll, 1, 30);
298 if (nRetVal < 0) {
299 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("poll failed") );
300 goto failed;
303 // Start post process
304 nRetVal = ioctl (m_fdPP, S3C_PP_START);
305 if (nRetVal < 0) {
306 HLH_DEBUG ( HLH_DEBUG_PP|HLH_DEBUG_MAIN, ("pp start failed") );
307 goto failed;
310 // Unlock this instance
311 m_zhmMutex.Unlock ();
313 return 0;
315 failed:
316 // Unlock this instance
317 m_zhmMutex.Unlock ();
319 return POST_PROCESSOR_ERR_FAILED;