1 /*******************************************************************************
2 * File Name : src/pp/PostProcess.cpp
5 * Created Time : Fri 30 Oct 2009 01:03:05 PM CST
7 ******************************************************************************/
10 /*******************************************************************************
11 * Desc : Includes Files
12 ******************************************************************************/
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
51 ******************************************************************************/
52 PostProcessor::PostProcessor ()
56 } // ----- end of method PostProcessor::PostProcessor (constructor) -----
59 /******************************************************************************
60 * Func : PostProcessor::~PostProcessor
61 * Desc : Deconstructor of PostProcessor
64 ******************************************************************************/
65 PostProcessor::~PostProcessor ()
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
);
95 // Unlock this instance
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
);
104 HLH_DEBUG ( HLH_DEBUG_PP
|HLH_DEBUG_MAIN
, ("can't open %s", pcDevPath
) );
108 // Notify that this instance is created
111 // Unlock this instance
112 m_zhmMutex
.Unlock ();
117 // Unlock this instance
118 m_zhmMutex
.Unlock ();
120 return POST_PROCESSOR_ERR_FAILED
;
125 /******************************************************************************
126 * Func : PostProcessor::Destroy
127 * Desc : Destroy this instance
130 ******************************************************************************/
131 void PostProcessor::Destroy ()
134 // Lock this instance
138 // Unlock this instance
139 m_zhmMutex
.Unlock ();
141 HLH_DEBUG ( HLH_DEBUG_PP
, ("not created") );
145 // Close post process device
149 // Notify this instance not created or set parameter
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
)
195 // Lock this instance
198 // Check if instance created
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
);
225 HLH_DEBUG ( HLH_DEBUG_PP
|HLH_DEBUG_MAIN
, ("can't set parameter") );
229 // Notify that the parameter of this instance has been set.
232 // Unlock this instance
233 m_zhmMutex
.Unlock ();
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)
253 ******************************************************************************/
254 int PostProcessor::Process (void * pvSrcBuf
, void *pvDstBuf
)
258 struct pollfd zpfPoll
;
260 // Lock this instance
263 // Check if instance created
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
274 HLH_DEBUG ( HLH_DEBUG_PP
|HLH_DEBUG_MAIN
, ("process before set parameter") );
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
);
282 HLH_DEBUG ( HLH_DEBUG_PP
|HLH_DEBUG_MAIN
, ("ioctl set source address failed") );
286 m_zspParam
.dst_buf_addr_phy
= (UINT32
)pvDstBuf
;
287 nRetVal
= ioctl (m_fdPP
, S3C_PP_SET_DST_BUF_ADDR_PHY
, &m_zspParam
);
289 HLH_DEBUG ( HLH_DEBUG_PP
|HLH_DEBUG_MAIN
, ("ioctl set dst address failed") );
295 zpfPoll
.events
= POLLOUT
| POLLERR
;
297 nRetVal
= poll (&zpfPoll
, 1, 30);
299 HLH_DEBUG ( HLH_DEBUG_PP
|HLH_DEBUG_MAIN
, ("poll failed") );
303 // Start post process
304 nRetVal
= ioctl (m_fdPP
, S3C_PP_START
);
306 HLH_DEBUG ( HLH_DEBUG_PP
|HLH_DEBUG_MAIN
, ("pp start failed") );
310 // Unlock this instance
311 m_zhmMutex
.Unlock ();
316 // Unlock this instance
317 m_zhmMutex
.Unlock ();
319 return POST_PROCESSOR_ERR_FAILED
;