1 /* Copyright (C) 2010 Texas Instruments, Inc. All rights reserved. */
3 #ifndef _OMX_VISIONCAM_H_
4 #define _OMX_VISIONCAM_H_
6 #if defined(WIN32) || defined(UNDER_CE)
7 #include <windows.h>
8 #else
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <math.h>
12 #include <string.h>
13 #endif
15 #include <list>
17 #include <VisionCam.h>
19 #include <semaphore.h>
21 #include <OMX_Types.h>
22 #include <OMX_Core.h>
23 #include <OMX_IVCommon.h>
24 #include <OMX_Component.h>
25 #include <OMX_Index.h>
26 #include <OMX_TI_Index.h>
27 #include <OMX_TI_IVCommon.h>
28 #include <OMX_TI_Common.h>
29 #include <OMX_CoreExt.h>
30 #include <OMX_IndexExt.h>
32 /** Enables some manual camera contols, like manual white balance color gains and gamma table coeficients. */
33 #define OMX_CAMERA_SUPPORTS_MANUAL_CONTROLS
34 #define OMX_CAMERA_SUPPORTS_GESTURES
36 /** Maximum camera output port count, not used. @see VisionCamPort_e */
37 const uint32_t USED_PORTS_NUMBER = VCAM_PORT_MAX;
39 /** Initial frame width. */
40 const uint32_t QVGA_WIDTH = 320;
42 /** Initial frame height. */
43 const uint32_t QVGA_HEIGHT = 240;
45 /** Initial frame rate. */
46 const uint32_t INITIAL_FRAMERATE = 30;
48 /** Minimum value for manual WB color gain. @see VCAM_PARAM_WB_COLOR_GAINS */
49 const uint32_t COLOR_GAIN_MIN = 512;
51 /** Maximum value for manual WB color gain. @see VCAM_PARAM_WB_COLOR_GAINS */
52 const uint32_t COLOR_GAIN_MAX = 2048;
54 /** Maximum white balance delay time. @see VCAM_PARAM_AWB_MIN_DELAY_TIME */
55 const uint32_t AWB_Delay_Time_Max = 10000;
57 /** Minimum white balance delay time. @see VCAM_PARAM_AWB_MIN_DELAY_TIME */
58 const uint32_t AWB_Delay_Time_Min = 0;
60 /** Maimum exposure gain delay time. @see VCAM_PARAM_AGC_MIN_DELAY_TIME */
61 const uint32_t AE_Delay_Time_Max = 10000;
63 /** Minimum exposure gain delay time. @see VCAM_PARAM_AGC_MIN_DELAY_TIME */
64 const uint32_t AE_Delay_Time_Min = 0;
66 /** Maximum count of face data that could be output bu face detction algotithm.
67 * In othe words maximum count of face that could be detected.
68 */
69 const uint32_t VCAM_Max_Gesture_Per_Frame = 35;
71 #define ARR_SIZE(arr) ( sizeof(arr)/sizeof(arr[0]) )
73 #if TIME_PROFILE
74 /** In case ot time profiling this is the start time
75 * of a certain time measurement target.
76 */
77 #define TIME_START( time_prof ) {\
78 gettimeofday( &time_prof->mStart , NULL);\
79 }
81 /** In case of time profiling this is the ending time
82 * of a certain time measurement target.
83 */
84 #define TIME_END( time_prof ) {\
85 gettimeofday( &time_prof->mEnd , NULL);\
86 }
88 /** @enum TimeProfileTargets
89 * Defines time profiling targets - the commands for which execution time is measured.
90 * This is just an indexing of of measured time windows.
91 */
92 typedef enum _time_profile_targets{
93 first,
94 second,
95 last,
97 VCAM_TIME_TARGET_MAX
98 }TimeProfileTargets;
100 /** @class VisionCamTimeProfile
101 * Implementation of time profiling.
102 * Each measured time is an object of this type.
103 * Measured time is dumped when this object is destroyed.
104 */
105 class VisionCamTimePtofile{
106 public:
107 /** @fn Constructor
108 * @param name a string that will be used when measured time of dumped.
109 */
110 VisionCamTimePtofile( const char * name = NULL);
111 /** @fn Destructor
112 * Destroys a profiling object and dumps measured time in milliseconds.
113 */
114 ~VisionCamTimePtofile();
116 /** @fn dump()
117 * Prints the time measured for execution of command corresponding to this object.
118 * This function, also sets the start and end moment to 0, so it can be used again.
119 */
120 void dump();
122 struct timeval mStart; /** System time at start. */
123 struct timeval mEnd; /** System time at end. */
124 const char * mName; /** User defined name of the command. Used when results are shown. */
125 };
126 #endif
128 /** @struct OMXVCAM_Msg_t
129 * Message structure used for event handling for OMX Camera events.
130 */
131 typedef struct _omxvcam_msg_t {
132 OMX_EVENTTYPE eEvent; /** Event, defined by OMX IL specification. */
133 OMX_U32 nData1; /** A data passed by OMX Camera. */
134 OMX_U32 nData2; /** A data passed by OMX Camera. */
135 sem_t *semaphore; /** Semaphore on which this event will be expected. */
136 OMX_HANDLETYPE hComponent; /** OMX Camera component. */
137 OMX_U32 timeout; /** Semaphore time out. */
138 } OMXVCAM_Msg_t;
140 /** ExtraDataTypeLUT[][]
141 * A look-up table used to translate VisoinCam extra data type to OMX extra data type.
142 * For details about OMX defined extra data types, refer to OMX IL specification.
143 * @see VisionCamExtraDataType_e
144 */
145 const int ExtraDataTypeLUT[][ 2 ] =
146 {
147 { VCAM_EXTRA_DATA_NONE, OMX_ExtraDataNone },
148 // { VCAM_EXIF_ATTRIBUTES , VCAM_ExifAttributes },
149 { VCAM_ANCILLARY_DATA , OMX_AncillaryData },
150 { VCAM_WHITE_BALANCE , OMX_WhiteBalance },
151 #ifndef __QNX__
152 { VCAM_MANUAL_WHITE_BALANCE , OMX_TI_WhiteBalanceOverWrite },
153 #endif
154 { VCAM_UNSATURATED_REGIONS , OMX_UnsaturatedRegions },
155 { VCAM_FACE_DETECTION , OMX_FaceDetection },
156 // { VCAM_BARCODE_DETECTION , OMX_BarcodeDetection },
157 // { VCAM_FRONT_OBJECT_DETECTION , OMX_FrontObjectDetection },
158 // { VCAM_MOTION_ESTIMATION , OMX_MotionEstimation },
159 // { VCAM_DISTANCE_ESTIMATION , OMX_DistanceEstimation },
160 { VCAM_HISTOGRAM , OMX_Histogram },
161 { VCAM_FOCUS_REGION , OMX_FocusRegion },
162 // { VCAM_EXTRA_DATA_PAN_AND_SCAN , OMX_ExtraDataPanAndScan },
163 // { VCAM_RAW_FORMAT , OMX_RawFormat },
164 // { VCAM_SENSOR_TYPE , OMX_SensorType },
165 // { VCAM_SENSOR_CUSTOM_DATA_LENGTH , OMX_SensorCustomDataLength },
166 // { VCAM_SENSOR_CUSTOM_DATA , OMX_SensorCustomData }
167 };
169 /** CaptureModeLUT[][]
170 * A look-up table, used to translate VisionCam operating mode to OMX Camera operating mode.
171 * @see VisionCamCaptureMode for supported operating modes.
172 */
173 const int CaptureModeLUT[][ 2 ] =
174 {
175 #if defined(GT_I9100G)
176 { VCAM_VIDEO_NORMAL , OMX_CaptureVideo },
177 #else // all other platforms
178 { VCAM_VIDEO_NORMAL , OMX_CaptureImageProfileBase },
179 #endif
180 #if defined(GT_I9100G)
181 { VCAM_VIDEO_HIGH_SPEED , OMX_CaptureImageHighSpeedTemporalBracketing },
182 #else // all other platforms
183 { VCAM_VIDEO_HIGH_SPEED , OMX_CaptureHighSpeedVideo },
184 #endif
185 { VCAM_GESTURE_MODE , OMX_TI_CaptureGestureRecognition },
186 { VCAM_STEREO_MODE , OMX_CaptureStereoImageCapture },
187 #ifdef OMX_CAMERA_SUPPORTS_STEREO_GESTURES
188 { VCAM_STEREO_GEST_MODE , OMX_TI_StereoGestureRecognition },
189 #endif
190 #if defined(__QNX__)
191 { VCAM_VIEWFINDER_MODE , OMX_CaptureVideo },
192 #endif
193 { VCAM_CAP_MODE_MAX , OMX_CamOperatingModeMax }
194 };
196 /** FocusModeLUT[][]
197 * A look-up table, use to translate focus modes, supported by VisionCam, to OMX defined focus modes.
198 * @see VisionCamFocusMode for supported focus modes.
199 */
200 const int FocusModeLUT[][ 2 ] =
201 {
202 { VCAM_FOCUS_CONTROL_ON , OMX_IMAGE_FocusControlOn },
203 { VCAM_FOCUS_CONTROL_OFF , OMX_IMAGE_FocusControlOff },
204 { VCAM_FOCUS_CONTROL_AUTO , OMX_IMAGE_FocusControlAuto },
205 { VCAM_FOCUS_CONTROL_AUTO_LOCK , OMX_IMAGE_FocusControlAutoLock },
206 #if !defined(__QNX__)
207 { VCAM_FOCUS_CONTRO_AUTO_MACRO , OMX_IMAGE_FocusControlAutoMacro },
208 #endif
209 { VCAM_FOCUS_CONTROL_AUTO_INFINITY , OMX_IMAGE_FocusControlAutoInfinity },
210 // { VCAM_FOCUS_FACE_PRIORITY_MODE , OMX_IMAGE_FocusFacePriorityMode },
211 // { VCAM_FOCUS_REGION_PRIORITY_MODE , OMX_IMAGE_FocusRegionPriorityMode },
212 { VCAM_FOCUS_CONTROL_HYPERFOCAL , OMX_IMAGE_FocusControlHyperfocal },
213 { VCAM_FOCUS_CONTROL_PORTRAIT , OMX_IMAGE_FocusControlPortrait },
214 { VCAM_FOCUS_CONTROL_EXTENDED , OMX_IMAGE_FocusControlExtended },
215 { VCAM_FOCUS_CONTROL_CONTINOUS_NORMAL , OMX_IMAGE_FocusControlContinousNormal },
216 #if !defined(__QNX__)
217 { VCAM_FOCUS_CONTROL_CONTINOUS_EXTENDED , OMX_IMAGE_FocusControlContinousExtended },
218 #else
219 { VCAM_FOCUS_CONTROL_CONTINOUS_EXTENDED , OMX_TI_IMAGE_FocusControlContinuousExtended },
220 #endif
221 // { VCAM_FOCUS_FACE_PRIORITY_CONTINOUS_MODE , OMX_IMAGE_FocusFacePriorityContinousMode },
222 // { VCAM_FOCUS_REGION_PRIORITY_CONTINOUS_MODE , OMX_IMAGE_FocusRegionPriorityContinousMode },
223 { VCAM_FOCUS_CONTROL_MAX , OMX_IMAGE_FocusControlMax }
224 };
226 /** MirrorTypeLUT[][]
227 * A look-up table, used to translate VisionCam supported mirroring modes, to OMX mirror modes.
228 * @see VisionCamMirrorType
229 */
230 const int MirrorTypeLUT[][ 2 ] =
231 {
232 { VCAM_MIRROR_NONE , OMX_MirrorNone },
233 { VCAM_MIRROR_VERTICAL , OMX_MirrorVertical },
234 { VCAM_MIRROR_HORIZONTAL , OMX_MirrorHorizontal },
235 { VCAM_MIRROR_BOTH , OMX_MirrorBoth },
236 { VCAM_MIRROR_MAX , OMX_MirrorMax }
237 };
239 #if ( defined(DUCATI_1_5) || defined(DUCATI_2_0) ) && defined(OMX_CAMERA_SUPPORTS_GESTURES)
240 /** GestureTypeLUT[][]
241 * A look-up table, used to translate VisionCam defined gesture events, to OMX defined gesture events.
242 * @see VisionCamGestureEvent_e
243 */
244 const int GestureTypeLUT[][2] =
245 {
246 { VCAM_GESTURE_EVENT_INVALID , OMX_TI_GESTURE_NO_GESTURE },
247 { VCAM_GESTURE_EVENT_SWIPE_LEFT , OMX_TI_GESTURE_SWIPE_LEFT },
248 { VCAM_GESTURE_EVENT_SWIPE_RIGHT , OMX_TI_GESTURE_SWIPE_RIGHT },
249 { VCAM_GESTURE_EVENT_FIST_LEFT , OMX_TI_GESTURE_FIST_LEFT },
250 { VCAM_GESTURE_EVENT_FIST_RIGHT , OMX_TI_GESTURE_FIST_RIGHT },
251 { VCAM_GESTURE_EVENT_MAX , OMX_TI_GESTURE_MAX }
252 };
254 /** ObjectTypeLUT[][]
255 * A look-up table, used to translate VisionCam gesture object type to coresponding OMX gesture object.
256 * @see VisionCamObjectType
257 */
258 const int ObjectTypeLUT[][2] =
259 {
260 { VCAM_OBJECT_PALM , OMX_TI_OBJECT_PALM },
261 { VCAM_OBJECT_FIST , OMX_TI_OBJECT_FIST },
262 { VCAM_OBJECT_FACE , OMX_TI_OBJECT_FACE },
263 { VCAM_OBJECT_MAX , OMX_TI_OBJECT_MAX }
264 };
265 #endif
267 /** StereoLayoutLUT[][]
268 * A look-up table, used to translate VisionCam defined stereo layouts to OMX stereo layouts.
269 * @see VisionCamStereoLayout
270 */
271 const int StereoLayoutLUT[][2] =
272 {
273 { VCAM_STEREO_LAYOUT_TOPBOTTOM, OMX_TI_StereoFrameLayoutTopBottom },
274 { VCAM_STEREO_LAYOUT_LEFTRIGHT, OMX_TI_StereoFrameLayoutLeftRight },
275 { VCAM_STEREO_LAYOUT_MAX, OMX_TI_StereoFrameLayoutMax }
276 };
278 /** OMX index of preview frame output port. */
279 const int VCAM_CAMERA_PORT_VIDEO_OUT_PREVIEW = 2;
281 /** OMX index of video frame output port. */
282 const int VCAM_CAMERA_PORT_VIDEO_OUT_VIDEO = 3;
284 /** Needed for priority memagement. Camera Group ID is set DOMX layers. */
285 const unsigned int CAMERA_GROUP_ID = 8;
287 /** @fn void* PreemptionThreadLauncher( void *arg )
288 * A thread function that implements preemption mechanism for OMXVisionCam.
289 * Preemption model used here is defined by OMX standard.
290 * @param arg The instance of OMXVisionCam that is preempted.
291 */
292 void* PreemptionThreadLauncher( void *arg );
294 /** void* FrameThreadFunc(void *arg)
295 * Thread function that implements frame transmit/receive mechanism between user and OMX camera.
296 * @param arg Thee instance of OMXVisinCam that this thead serves.
297 */
298 void* FrameThreadFunc(void *arg);
300 /** @class OMXVisionCam
301 * @implements VisionCam
302 *
303 * Implements OMX Camera interface. Publicly inherits VisionCam.
304 * This is the final point before camera specific software inplementaion.
305 */
306 class OMXVisionCam : public VisionCam
307 {
308 protected:
309 OMX_HANDLETYPE* mHandle;
311 private: // internal data types
313 /** @class VCAM_PortParameters
314 * Keeps all the data needed to control certain camera output port.
315 */
316 class VCAM_PortParameters
317 {
318 public:
319 // OMX_U32 mHostBufaddr[VCAM_NUM_BUFFERS]; /** The address of each buffer assigned to this port. This is only used for tailor buffers. @todo check if last is true (gingerbread, froyo) */
320 OMX_BUFFERHEADERTYPE *mBufferHeader[VCAM_NUM_BUFFERS];/** Buffer specific data, generated by OMX camera handle at the time a buffer is registered. */
321 OMX_U32 mWidth; /** Image width in pixels of a buffer. @see fourcc_t definitions to check pixel in bytes size for different formats. */
322 OMX_U32 mHeight; /** Image height in pixels of a buffer. */
323 OMX_U32 mStride; /** Byte distance from one pixel to the next pixel in the y direction. */
324 OMX_U8 mNumBufs; /** Number of buffers assigned to this port. */
325 OMX_U32 mBufSize; /** The size of a buffer in bytes. */
326 OMX_COLOR_FORMATTYPE mColorFormat; /** The fourcc_t color fomat used to calculate buffer allocation sizes. This must be also the color format applied to OMX camera. */
327 // OMX_PARAM_VIDEONOISEFILTERTYPE mVNFMode; /** Video noise filtering mode: on, off or auto. @todo check if used */
328 // OMX_PARAM_VIDEOYUVRANGETYPE mYUVRange; /** Frame YUV Range. @todo check if used */
329 // OMX_CONFIG_BOOLEANTYPE mVidStabParam; /** Video stabilisation mode: enabled or disabled. @todo check if used and needed at all. */
330 // OMX_CONFIG_FRAMESTABTYPE mVidStabConfig; /** Video stabilisation mode: enabled or disabled. @todo check if used and needed at all. */
331 // OMX_U32 mCapFrame; /** @todo is it used. */
332 OMX_U32 mFrameRate; /** Frame rate. @note Frame rate is applied to all ports. */
333 OMX_U32 mRotation; /** Applied rotation. @see VisionCamRotation_e */
334 bool mIsActive; /** Indicates if this port is currently outputting any data. */
335 };
337 /** @class VCAM_ComponentContext
338 * Holds the current status of OMX camera handle.
339 */
340 class VCAM_ComponentContext
341 {
342 public:
343 OMX_HANDLETYPE mHandleComp; /** The camera handle. */
344 OMX_U32 mNumPorts; /** Number of ports that camera could use. */
345 /*VisionCamPort_e*/ OMX_U32 mPortsInUse[VCAM_PORT_MAX]; /** Output port indexes, as they are defined in OMX camera. */
346 OMX_U32 mExtraDataPortIndex; /** @todo remove me! */
347 VCAM_PortParameters mCameraPortParams[VCAM_PORT_MAX]; /** The parameters for each port. */
348 };
350 /** @struct BuffersInUse_t
351 * A structure that packs a buffer array and buffer count.
352 @todo move to port parameters
353 */
354 typedef struct BuffersInUse_t {
355 BufferMeta* mBuffers; /** Array of buffers. */
356 uint32_t mNumberBuffers; /** Number of buffers. */
357 } BuffersInUse_t;
359 /** @enum ValueTypeOrigin
360 * Used to parse look-up tables.
361 * Marks where exactly the value, for which a match is searched, is defined.
362 */
363 typedef enum
364 {
365 VCAM_VALUE_TYPE = 0, /** Value is defined in VisionCam and matching OMX value is searched. */
366 OMX_VALUE_TYPE = 1 /** Value is defined in OMX and matching VisionCam value is searched. */
367 } ValueTypeOrigin ;
369 /** @enum VisionCamPreemptionActivity_e
370 * Used to define component preemption stage.
371 */
372 enum VisionCamPreemptionActivity_e {
373 VCAM_PREEMPT_INACTIVE, /** No preemption is started. */
374 VCAM_PREEMPT_SUSPEND, /** OMX camera was preempted by a process with a higher priority than VisionCam, so VisionCam has to be suspended. */
375 VCAM_PREEMPT_RESUME, /** VisionCam is ready to continue its work, after it has been suspended. */
376 VCAM_PREEMPT_WAIT_TO_START /** VisionCam is waiting to get the control over camera. */
377 };
379 /** @typedef int(*serviceFunc)(OMXVisionCam *, void *)
380 * Pointer to a serving function.
381 * Serving functions are used in the cases where additional setup must be done
382 * in order for a certain job to be finished by camera.
383 */
384 typedef int(*serviceFunc)(OMXVisionCam *, void *);
385 // Inherited Methods from VisionCam
386 public:
387 /** Constructor. */
388 OMXVisionCam();
389 /** Destructor. */
390 ~OMXVisionCam();
392 /** @fn int init(void * cookie)
393 * Initialises OMXVisionCam, gets a camera handle and gives some default values.
394 */
395 int init(void * cookie);
397 /** @fn int deinit()
398 * Deinits OMXVisionCam, releases the camera and frees all available resources.
399 */
400 int deinit();
402 /** @fn int useBuffers(BufferMeta* meta, uint32_t num_images, VisionCamPort_e port)
403 * Registers and allocates (internal for OMXVisionCam) frame descriptor for each buffer passed.
404 * This way, buffers are ready to be passed to OMX camera. Implements VisionCam::useBuffers().
405 * @param *prvBufArr array of buffers as thay are allocated.
406 * @param numPrvBuf number of the buffers in this array.
407 * @param port the port on which these buffers must be assigned to.
408 */
409 int useBuffers(BufferMeta* meta, uint32_t num_images, VisionCamPort_e port);
411 /** @fn int releaseBuffers( VisionCamPort_e port )
412 * Unregisters (internal for OMXVisionCam) all buffers registered with useBuffers() to OMXVisoinCam
413 * and frees corresponding frame descriptors. Implements VisionCam::releaseBuffers().
414 * @param port the port on which these buffers are assigned.
415 */
416 int releaseBuffers( VisionCamPort_e port );
418 /** @fn int flushBuffers( VisionCamPort_e port )
419 *
420 */
421 int flushBuffers( VisionCamPort_e port );
423 /** @fn int sendCommand( VisionCamCmd_e cmdId, void *param, uint32_t size, VisionCamPort_e port )
424 * Requests camera to execute some additional functionality. Implements VisionCam::sendCommand().
425 * @param cmdId the command id that bust be executed.
426 * @param param pointer to additional data that refers to this command.
427 * @param size size of data pointed by param.
428 * @param port the port on which this must be executed.
429 * @return STATUS_SUCCESS on success and any other error code otherwise.
430 * @see VisionCamCmd_e for possible commands.
431 * @see VisionCamPort_e for available ports.
432 */
433 int sendCommand( VisionCamCmd_e cmdId, void *param, uint32_t size, VisionCamPort_e port );
435 /** @fn int setParameter( VisionCamParam_e paramId, void* param, uint32_t size, VisionCamPort_e port)
436 * Configure the camera with supplied parameter. Implements VisionCam::setParameter().
437 * @param paramId ID of the parameter that has to be applied.
438 * @param param Pointer to parameter data.
439 * @param size Size of parameter data.
440 * @param port Output port for which this parameters will be applied.
441 * @return STATUS_SUCCESS on success and any other error code otherwise.
442 * @see VisionCamParam_e for possible parameters.
443 * @see VisionCamPort_e for available ports.
444 */
445 int setParameter( VisionCamParam_e paramId, void* param, uint32_t size, VisionCamPort_e port);
447 /** @fn int getParameter( VisionCamParam_e paramId, void* param, uint32_t size, VisionCamPort_e port)
448 * Reads camera configuration parameter. Implements VisionCam::getParameter().
449 * @param paramId ID of the parameter that has to be read.
450 * @param param Pointer to user allocated space, where parameter value will be written.
451 * @param size Size of parameter data.
452 * @param port Output port for which this parameters are applied.
453 * @return STATUS_SUCCESS on success and any other error code otherwise.
454 * @see VisionCamParam_e for possible parameters.
455 * @see VisionCamPort_e for available ports.
456 */
457 int getParameter( VisionCamParam_e paramId, void* param, uint32_t size, VisionCamPort_e port);
459 /** @fn int returnFrame( VisionCamFrame *cameraFrame )
460 * This must be called after VisionCam client has finished his job with a frame buffer.
461 * With this, user notifies VisionCam that this frame buffer is ready to be returned back to camera.
462 * @param cameraFrame The pointer to the frame given to the user which is now completed.
463 */
464 int returnFrame( VisionCamFrame *cameraFrame );
466 private:
467 // OMXVisionCam
468 /** @fn int startPreview( VisionCamPort_e port )
469 * Signals the camera to start a streaming a frames on a certain output port.
470 * @param port the port on which this streaming shold be started.
471 * @return STATUS_SUCCESS on success and any other error code otherwise.
472 */
473 int startPreview( VisionCamPort_e port );
475 /** @fn int stopPreview( VisionCamPort_e port )
476 * Signals the camera to stop a streaming a frames on a certain output port.
477 * @param port the port on which this streaming shold be stopped.
478 * @return STATUS_SUCCESS on success and any other error code otherwise.
479 */
480 int stopPreview( VisionCamPort_e port );
482 /** @fn inline OMX_STATETYPE getComponentState()
483 * Gets current state of OMX camera.
484 */
485 inline OMX_STATETYPE getComponentState();
487 /** @fn inline OMX_ERRORTYPE initPortCheck( OMX_PARAM_PORTDEFINITIONTYPE * portCheck , OMX_U32 portIndex )
488 * Read and initialises current configuration applied to a certain output port.
489 * The configuratin structure is passed by a pointer so it can be used later for port reconfiguration.
490 * @param portCheck configuratin structure pointer that will be filled with appropriate data.
491 * @param portIndex one of VisionCamPort_e port indexes; this is the port which configuration is requested
492 * @return OMX_ErrorNone on successful read.
493 */
494 inline OMX_ERRORTYPE initPortCheck( OMX_PARAM_PORTDEFINITIONTYPE * portCheck , OMX_U32 portIndex );
496 /** @fn inline int ConvertError(OMX_ERRORTYPE error)
497 * Converts OMX error codes to VisionCam error codes (int)
498 * @param error one of OMX error codes.
499 * @return int value.
500 * @see int
501 */
502 inline int ConvertError(OMX_ERRORTYPE error);
504 /** @fn inline int getLutValue( int searchVal, ValueTypeOrigin origin, const int lut[][2], int lutSize)
505 * Parses VisionCam <-> OMX look-up tables.
506 * @param searchVal The value for which a match is required.
507 * @param origin Indicates if searchVal is defined by VisionCam or by OMX.
508 * Depending on that, returned value is respectively OMX or VisionCam defined.
509 * @param lut[][2] The look-up table to be parsed.
510 * @param lutSize Number of couples in this table.
511 * @return The value corresponding to searchVal.
512 */
513 inline int getLutValue( int searchVal, ValueTypeOrigin origin, const int lut[][2], int lutSize);
516 /** @fn void GetDucatiVersion()
517 * Gets currnet domx version.
518 */
519 void GetDucatiVersion();
521 /** @fn OMX_ERRORTYPE RegisterForEvent(OMX_IN OMX_HANDLETYPE hComponent,
522 OMX_IN OMX_EVENTTYPE eEvent,
523 OMX_IN OMX_U32 nData1,
524 OMX_IN OMX_U32 nData2,
525 OMX_IN sem_t *semaphore,
526 OMX_IN OMX_U32 timeout)
527 * Creates an event message and adds it to the list of events that are expected to occur at OMX side.
528 */
529 OMX_ERRORTYPE RegisterForEvent(OMX_IN OMX_HANDLETYPE hComponent,
530 OMX_IN OMX_EVENTTYPE eEvent,
531 OMX_IN OMX_U32 nData1,
532 OMX_IN OMX_U32 nData2,
533 OMX_IN sem_t *semaphore,
534 OMX_IN OMX_U32 timeout);
536 /** @fn static OMX_ERRORTYPE EventHandler(OMX_IN OMX_HANDLETYPE hComponent,
537 OMX_IN OMX_PTR pAppData,
538 OMX_IN OMX_EVENTTYPE eEvent,
539 OMX_IN OMX_U32 nData1,
540 OMX_IN OMX_U32 nData2,
541 OMX_IN OMX_PTR pEventData);
542 *
543 * OMX event handler. This is a callback function, registerd in OMX component, by the time of its initialization.
544 * It is invoked every time an event is generated by camera.
545 * The events handled are not only internal camera events,
546 * but also a results ot some external processes that deal with camera.
547 */
548 static OMX_ERRORTYPE EventHandler(OMX_IN OMX_HANDLETYPE hComponent,
549 OMX_IN OMX_PTR pAppData,
550 OMX_IN OMX_EVENTTYPE eEvent,
551 OMX_IN OMX_U32 nData1,
552 OMX_IN OMX_U32 nData2,
553 OMX_IN OMX_PTR pEventData);
555 /** @fn static OMX_ERRORTYPE EmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
556 OMX_IN OMX_PTR pAppData,
557 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
558 * A callback notifing that OMX camera has unregistered a buffer and has freed its buffer header.
559 */
560 static OMX_ERRORTYPE EmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
561 OMX_IN OMX_PTR pAppData,
562 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
564 /** @fn static OMX_ERRORTYPE FillBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
565 OMX_IN OMX_PTR pAppData,
566 OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader);
567 *
568 * A callback notifing that OMX camera has wrote a frame buffer and it is ready to be passed to user.
569 */
570 static OMX_ERRORTYPE FillBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
571 OMX_IN OMX_PTR pAppData,
572 OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader);
574 // /** int frameReceiveService(OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader)
575 // *
576 // */
577 // int frameReceiveService(OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader);
579 /** @fn OMX_ERRORTYPE setPortDef( int portIndex )
580 * Configures a port. Sets the data that port needs to get ready for image processing.
581 * @param portIndex VisionCam defined index of the port.
582 * @see VisionCamPort_e
583 * @return OMX_ErrorNone on success.
584 */
585 OMX_ERRORTYPE setPortDef( int portIndex/*, VCAM_PortParameters * portData*/);
587 /** @fn int startAutoFocus( VisionCamFocusMode focusMode )
588 * Starts auto focus in a certain mode. Starts a thread that will wait for focus event.
589 * @param focusMode mode in which auto focus must start.
590 * @see VisionCamFocusMode
591 * @return STATUS_SUCCESS on success and any other error code otherwise.
592 */
593 int startAutoFocus( VisionCamFocusMode focusMode );
595 /** @fn int enableFaceDetect(VisionCamPort_e port)
596 * This will configure the component to start/stop face detection.
597 * Will also start/stop face detection extra data
598 * faces coordinates will be written into camera frame received in preview callback.
599 * @see VisionCamFaceType
600 * @see VisionCamFrame::mFaces
601 * @return STATUS_SUCCESS on success and any other error code otherwise.
602 */
603 int enableFaceDetect(VisionCamPort_e port);
605 /** @fn void getFacesCoordinates( VisionCamFrame *frame)
606 * Fill the face coordinates field in camera frame,
607 * which will be received by OMXVisionCam client at each frame.
608 * @param frame a frame descripror.
609 */
610 void getFacesCoordinates( VisionCamFrame *frame);
612 /** @fn void getMetadataPtrs( VisionCamFrame *frame)
613 * Parse through the extra data type structure to find the pointer to the relevent
614 * data type. This is to abstract the port number, version, and packet structure from the client.
615 * @param frame pointer to a frame descripror.
616 */
617 void getMetadataPtrs( VisionCamFrame *frame);
619 /** @fn OMX_ERRORTYPE getFocusStatus(OMX_FOCUSSTATUSTYPE *status)
620 * Gest current status of focus command execution.
621 * @param *status points to the variable, where focus status will be written.
622 * @return OMX_ErrorNone on success.
623 */
624 OMX_ERRORTYPE getFocusStatus(OMX_FOCUSSTATUSTYPE *status);
626 /** @fn int transitToState(OMX_STATETYPE targetState, serviceFunc transitionService = NULL, void * data = NULL)
627 * Sets OMX camera in a certain state. Camera state represent camera behaviour and configuration status.
628 * @param targetState the state that must be reached. Refer to OMX_STATETYPE in OMX IL specification.
629 * @param transitionService in some cases, OMXVisionCam must do additional steps in order for camera to reach requested state.
630 * transitionService must point to the function that does this steps.
631 * @param data any data (like buffers for example), that may be needed for this transition to finish.
632 * @return STATUS_SUCCESS on success and any other error code otherwise.
633 * @see serviceFunc
634 */
635 int transitToState(OMX_STATETYPE targetState, serviceFunc transitionService = NULL, void * data = NULL);
637 /** @fn int portEnableDisable( OMX_COMMANDTYPE enCmd, serviceFunc enablementService, VisionCamPort_e port )
638 * Enables and disables a port. Enabled port transfers frames only if camera is in OMX_StateExecuting.
639 * @param enCmd shows whether to enable the port or to disable it.
640 * @param enablementService pointer to a function that will do the additinal steps that may be needed for this port to execute this enablement command.
641 * @param port Index of the port that has to be enabled/disabled.
642 * @return STATUS_SUCCESS on success and any other error code otherwise.
643 */
644 int portEnableDisable( OMX_COMMANDTYPE enCmd, serviceFunc enablementService, VisionCamPort_e port );
646 /** @fn int PreemptionService()
647 * Handle preemption events. Takes care of all the steps needed in order preempt camera without bothering its normal work.
648 * @return STATUS_SUCCESS on success and any other error code otherwise.
649 */
650 int PreemptionService();
652 /** @fn friend void* PreemptionThreadLauncher( void *arg )
653 * Started by OMXVisionCam::EventHandler(), this thread function, call preemption service.
654 */
655 friend void* PreemptionThreadLauncher( void *arg );
657 /** @fn int populatePort( VisionCamPort_e port )
658 * Registers all buffers, that user has passed to OMXVisionCam, to OMX camera.
659 * @param port specifies tha port on which these buffers must be supplied.
660 * @return STATUS_SUCCESS on success and any other error code otherwise.
661 */
662 int populatePort( VisionCamPort_e port );
664 /** @fn static inline int populatePortSrvc( OMXVisionCam *inst, void *in )
665 * Function that may be called during camera state transitions or port eneblement.
666 * @return STATUS_SUCCESS on success and any other error code otherwise.
667 */
668 static inline int populatePortSrvc( OMXVisionCam *inst, void *in )
669 {
670 VisionCamPort_e whichPort = *(VisionCamPort_e*)in;
671 return inst->populatePort( whichPort );
672 }
674 /** @fn int fillPortBuffers( VisionCamPort_e port )
675 * Requests the camera to start wrtiting into buffers suppiled on a port.
676 * This is needed in some state transitions and sometimes during port enable command, depending on camera state.
677 * Basically this is needed when preview is started.
678 * @param port the port on which buffers are supplied.
679 * @return STATUS_SUCCESS on success and any other error code otherwise.
680 */
681 int fillPortBuffers( VisionCamPort_e port );
683 /** @fn static inline int populatePortSrvc( OMXVisionCam *inst, void *in )
684 * Function that may be called during camera state transitions or port eneblement.
685 * @return STATUS_SUCCESS on success and any other error code otherwise.
686 */
687 static inline int fillPortBuffersSrvc( OMXVisionCam *inst, void *in )
688 {
689 VisionCamPort_e whichPort = *(VisionCamPort_e*)in;
690 return inst->fillPortBuffers( whichPort );
691 }
693 /** @fn int freePortBuffers( VisionCamPort_e port )
694 * Request the camera to unregister all buffers supplied to a port.
695 * Internally, the camera will free its buffer headers.
696 * Basically this is done by the time preview is stopped.
697 * @param port the port for which buffers must be released.
698 * @return STATUS_SUCCESS on success and any other error code otherwise.
699 */
700 int freePortBuffers( VisionCamPort_e port );
702 /** @fn static inline int freePortBuffersSrvc( OMXVisionCam *inst, void *in )
703 * Function that may be called during camera state transitions or port eneblement.
704 * @return STATUS_SUCCESS on success and any other error code otherwise.
705 */
706 static inline int freePortBuffersSrvc( OMXVisionCam *inst, void *in )
707 {
708 VisionCamPort_e whichPort = *((VisionCamPort_e*)in);
709 return inst->freePortBuffers( whichPort );
710 }
712 public:
713 /** @fn int waitForFocus()
714 * Waits for focus reached event.
715 * @return STATUS_SUCCESS on success and any other error code otherwise.
716 */
717 int waitForFocus();
719 /** @fn void frameReceivedSrvc(void *data)
720 * Called inside frame thread, when a frame arrives,
721 * this function pareses the frame data and sends it to user via preview callback.
722 * @note In cases when a frame packing option is enabled and more then one output ports are running,
723 * then the frames from different ports are put into a packet and are sent to user only when all the ports have sent a frame.
724 * @see thread_t mFrameThread
725 * @see queue_t *mFrameMessageQ
726 */
727 void frameReceivedSrvc(void *data);
729 /** @var thread_t mFrameThread
730 * The thread that waits for frame event.
731 * This thead is responsible for packing a frames, if needed, and sending them to VisionCam client.
732 *
733 * @see void frameReceivedSrvc(void *data)
734 * @see queue_t *mFrameMessageQ
735 */
736 pthread_t mFrameThread;
738 /** @var queue_t *mFrameMessageQ
739 *
740 */
741 struct CallbackData {
742 pthread_mutex_t mutex;
743 std::list<OMX_BUFFERHEADERTYPE*> frames;
744 CallbackData() {
745 pthread_mutex_init(&mutex, NULL);
746 }
747 ~CallbackData() {
748 pthread_mutex_destroy(&mutex);
749 }
750 };
751 CallbackData mFrameCbData;
753 private:
754 bool mFlushInProcess;
755 VisionCamPreemptionActivity_e mPreemptionState;
757 OMX_PRIORITYMGMTTYPE mVisionCamPriority;
758 VisionCamFrame ** mFrameDescriptors[VCAM_PORT_MAX];
759 VCAM_ComponentContext mCurGreContext;
760 OMX_VERSIONTYPE *mLocalVersion;
761 OMX_CALLBACKTYPE mGreCallbacks;
763 BuffersInUse_t mBuffersInUse[VCAM_PORT_MAX];
765 pthread_mutex_t mFrameBufferLock;
766 pthread_mutex_t mUserRequestLock;
768 sem_t mGreLocalSem;
769 sem_t mGreFocusSem;
770 sem_t mFrameReceivedSem;
772 std::list<OMXVCAM_Msg_t*> mEventSignalQ;
774 uint32_t mManualFocusDistance;
776 bool mFaceDetectionEnabled;
777 bool mReturnToExecuting;
779 VisionCamClientNotifier mClientNotifier;
781 VisionCamFramePack mFramePackage;
782 bool mUseFramePackaging;
784 #ifdef _USE_GAMMA_RESET_HC_
785 bool mGammaResetPolulated;
786 #endif /// _USE_GAMMA_RESET_HC_
787 #if TIME_PROFILE
788 VisionCamTimePtofile * mTimeProfiler[ VCAM_TIME_TARGET_MAX ];
789 void PopulateTimeProfiler();
790 #endif
791 };
793 #endif