merge with master
[adaptation/intel_mfld/gst-plugins-atomisp.git] / gst-libs / atomisphal / mfld_cam.h
1 /* Gstreamer MFLD camera source abstract Layer API
2  * Copyright (c) 2010 Intel Corporation
3
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #ifndef _MFLD_CAM_H_
20 #define _MFLD_CAM_H_
21
22 #include "mfld_cam_defs.h"
23 #include "mfld_driver.h"
24 #include "gstv4l2mfldadvci.h"
25 #include <linux/videodev2.h>
26
27 #define V4L2_COLORFX_BW 1
28 #define V4L2_COLORFX_SKY_BLUE 6
29
30 /* init: Initialize the driver. V4l2camerasrc calls this immediately after
31  * the camera device has been opened and registers the device file
32  * descriptor to the driver.
33  */
34
35 /* Support the photography configure
36  * Capture Correction has removed from the photography interface
37  * We also implement it here ane export it as the camsrc property
38  * */
39
40 typedef enum
41 {
42   CAM_AWB_MODE, /* wb_mode */
43   CAM_GENERAL_EFFECT_TYPE, /* Tone Mode */
44   CAM_GENERAL_SCENE_MODE, /* Tone Mode */
45   CAM_LIGHT_FLASH_MODE, /* Flash Mode */
46   CAM_EXPOSURE_MANUAL_TIME, /* Exposure value */
47   CAM_EXPOSURE_MANUAL_APERTURE, /* Aperture Value */
48   CAM_EXPOSURE_COMPENSATION, /* ev_compensation */
49   CAM_EXPOSURE_ISO_VALUE, /* ISO Speed */
50   CAM_FOCUS_MODE, /* Focus Mode */
51   CAM_GENERAL_FLICKER_REDUCTION_MODE, /* flicker mode */
52   CAM_NOISE_REDUCTION_MODE, /* Noise reduction */
53   CAM_CAPTURE_CORRECTION, /* Capture Correction */
54 } cam_photo_feature_t;
55
56 typedef enum
57 {
58   CAM_GAMMA_VALUE,      /* Gamma Setting */
59   CAM_CONTRAST_VALUE,   /* Contrast Setting */
60   CAM_BRIGHTNESS_VALUE  /* Brightness Setting */
61 } cam_tone_control_t;
62
63 /* Supported white balance mode by our 3A library */
64 typedef enum
65 {
66   CAM_AWB_MODE_AUTO,
67   CAM_AWB_MODE_DAYLIGHT,
68   CAM_AWB_MODE_SUNSET,
69   CAM_AWB_MODE_CLOUDY,
70   CAM_AWB_MODE_TUNGSTEN,
71   CAM_AWB_MODE_FLUORESCENT
72 } cam_awb_mode_t;
73
74 /* Color effect in the V4L2 */
75 typedef enum
76 {
77   CAM_GENERAL_EFFECT_TYPE_NORMAL = V4L2_COLORFX_NONE,
78   CAM_GENERAL_EFFECT_TYPE_GRAYSCALE = V4L2_COLORFX_BW,
79   CAM_GENERAL_EFFECT_TYPE_SEPIA ,
80   CAM_GENERAL_EFFECT_TYPE_NEGATIVE ,
81   CAM_GENERAL_EFFECT_TYPE_SKY_BLUE = V4L2_COLORFX_SKY_BLUE,
82   CAM_GENERAL_EFFECT_TYPE_GRASS_GREEN ,
83   CAM_GENERAL_EFFECT_TYPE_SKIN_WHITEN ,
84   CAM_GENERAL_EFFECT_TYPE_VIVID,
85 } cam_general_effect_t;
86
87 /* Scence Mode are not supported by MFLD camera currently */
88 typedef enum
89 {
90   CAM_GENERAL_SCENE_MODE_CLOSEUP = 1000,
91   CAM_GENERAL_SCENE_MODE_PORTRAIT,
92   CAM_GENERAL_SCENE_MODE_LANDSCAPE,
93   CAM_GENERAL_SCENE_MODE_SPORT,
94   CAM_GENERAL_SCENE_MODE_NIGHT,
95   CAM_GENERAL_SCENE_MODE_AUTO,
96   CAM_GENERAL_SCENE_MODE_FIREWORKS,
97 } cam_scene_mode_t;
98
99 /* Focus Status */
100 typedef enum
101 {
102   CAM_FOCUS_STATUS_IDLE,
103   CAM_FOCUS_STATUS_SUCCESS,
104   CAM_FOCUS_STATUS_RUNNING,
105   CAM_FOCUS_STATUS_FAIL
106 } cam_focus_status_t;
107
108 /* capture mode */
109 typedef enum
110 {
111   CAM_CAPTURE_MODE_VIEWFINDER,
112   CAM_CAPTURE_MODE_STILL_CAPTURE,
113   CAM_CAPTURE_MODE_VIDEO_RECORD
114 } cam_capture_mode_t;
115
116 typedef enum
117 {
118   CAM_LIGHT_FLASH_MODE_AUTO,
119   CAM_LIGHT_FLASH_MODE_OFF,
120   CAM_LIGHT_FLASH_MODE_ON,
121   CAM_LIGHT_FLASH_MODE_FILL_IN,
122   CAM_LIGHT_FLASH_MODE_RED_EYE
123 } cam_flash_mode_t;
124
125 typedef enum
126 {
127   CAM_EXPOSURE_ISO_VALUE_1600,
128   CAM_EXPOSURE_ISO_VALUE_800,
129   CAM_EXPOSURE_ISO_VALUE_400,
130   CAM_EXPOSURE_ISO_VALUE_200,
131   CAM_EXPOSURE_ISO_VALUE_100,
132   CAM_EXPOSURE_ISO_VALUE_AUTO
133 } cam_exposure_iso_value_t;
134
135
136 typedef enum
137 {
138   CAM_FOCUS_MODE_AUTO,       /* GST_PHOTOGRAPHY_FOCUS_MODE_AUTO = 0 */
139   CAM_FOCUS_MODE_MACRO,
140   CAM_FOCUS_MODE_FULL,
141   CAM_FOCUS_MODE_NORM,
142   CAM_FOCUS_MODE_CONTINUOUS,
143   CAM_FOCUS_MODE_TOUCH_AUTO,
144 } cam_focus_mode_t;
145
146 typedef enum
147 {
148   CAM_VIEWFINDER_MODE_VIEWFINDER,
149   CAM_VIEWFINDER_MODE_STILL_CAPTURE,
150   CAM_VIEWFINDER_MODE_VIDEO_RECORD
151 } cam_viewfinder_mode_t;
152
153 /* Supported noise reduction mode
154  * These mode can be combiled together */
155 typedef enum
156 {
157   CAM_NOISE_REDUCTION_BAYER,
158   CAM_NOISE_REDUCTION_YCC,
159   CAM_NOISE_REDUCTION_TEMPORAL,
160   CAM_NOISE_REDUCTION_FIXED_PATTERN,
161   CAM_NOISE_REDUCTION_EXTRA,
162 } cam_noise_reduction_t;
163
164 /* Know as advanced mode before.
165  * RER, Image Stable and GDC are post processing.
166  * Others are on the fly processing
167  */
168 typedef enum
169 {
170   CAM_CAPTURE_CORRECTION_GDC, /* Geometry Distortion Correction */
171   CAM_CAPTURE_CORRECTION_CAC, /* Chromatic Aberration Correction */
172   CAM_CAPTURE_CORRECTION_EE, /* Edge Enhancement, increates the sharpness of the image */
173   CAM_CAPTURE_CORRECTION_SC, /* Shading Correction */
174   CAM_CAPTURE_CORRECTION_BLC, /* Black Level Compensation */
175   CAM_CAPTURE_CORRECTION_BPD, /* Bad Pixel Detection */
176   CAM_CAPTURE_CORRECTION_RER, /* Red Eye reduction */
177   CAM_CAPTURE_CORRECTION_DIS, /* Still Image Stabilization */
178   CAM_CAPTURE_CORRECTION_DVS /* Video Stabilization */
179 } cam_capture_correction_t;
180
181 /* Flicker mode supported on SH 3A library */
182 typedef enum
183 {
184   CAM_GENERAL_FLICKER_REDUCTION_MODE_OFF,  /* GST_PHOTOGRAPHY_FLICKER_REDUCTION_OFF = 0 */
185   CAM_GENERAL_FLICKER_REDUCTION_MODE_50HZ, /* GST_PHOTOGRAPHY_FLICKER_REDUCTION_50HZ */
186   CAM_GENERAL_FLICKER_REDUCTION_MODE_60HZ, /* GST_PHOTOGRAPHY_FLICKER_REDUCTION_60HZ */
187   CAM_GENERAL_FLICKER_REDUCTION_MODE_AUTO, /* GST_PHOTOGRAPHY_FLICKER_REDUCTION_AUTO */
188 } cam_flicker_reduction_mode_t;
189
190 /* noise filter setting names */
191 #define EENF_LNF_STRENGTH              "luma-noise-filter-strength"
192 #define EENF_CNF_STRENGTH              "chroma-noise-filter-strength"
193
194 struct tone_control
195 {
196   float gamma;
197   int contrast, brightness;
198 };
199
200 /* Camera Interal Status saved for upper layer */
201 struct mfld_cam_settings_t
202 {
203   int wb_mode;
204   int tone_mode;
205   int scene_mode;
206   int flash_mode;
207   int exposure, aperture;
208   int ev_compensation;
209   int iso_speed;
210   struct tone_control tone;
211   int flicker_mode, focus_mode;
212   int noise_reduction, capture_correction;
213   float zoom;
214 };
215
216 struct cam_capture_settings
217 {
218   int mmap;
219   int ae_awb_af;
220   int dump_raw;
221   unsigned int raw_output_size;
222   int dump_image;
223 };
224
225 cam_err_t cam_driver_init (int fd, const char *sensor_id);
226
227 cam_err_t cam_driver_deinit (int fd);
228
229 /* Known as read_settings before: mfldcamsrc tells the driver to retrieve settings from
230  * device and store them into #GstPhotoSettings structure.
231  */
232 cam_err_t cam_feature_get (int fd, cam_photo_feature_t feature, int *value);
233
234 /* Known as write_settings before: Called when some settings in mfldcamsrc's #GstPhotoSettings
235  * structure has changed. Driver needs to forward the settings to device.
236  */
237 cam_err_t cam_feature_set (int fd, cam_photo_feature_t feature, int value);
238
239 cam_err_t cam_set_capture_correction(int fd, cam_capture_correction_t mode, int on);
240
241 cam_err_t cam_set_tone_control(int fd, cam_tone_control_t tone, struct tone_control *value);
242
243 cam_err_t cam_set_autoexposure (int fd, int on);
244
245 cam_err_t cam_set_autofocus (int on);
246
247 cam_err_t cam_set_frame_rate( float frame_rate);
248
249 int cam_checkfocus_status (cam_focus_status_t * status, int force_update);
250
251 cam_err_t cam_get_shake_risk (int fd, int risk);
252
253 cam_err_t cam_set_flash (int fd, int on);
254
255 cam_err_t cam_get_flash_intensity (int fd, int on);
256
257 cam_err_t cam_set_flash_intensity (int fd, int on);
258
259 cam_err_t cam_set_capture_mode (int fd, cam_capture_mode_t mode);
260
261 cam_err_t cam_set_capture_fmt(int fd, unsigned int width,unsigned int height,
262                               unsigned int  fourcc);
263
264 cam_err_t cam_post_process(int fd);
265
266 cam_err_t cam_get_makernote (int fd, unsigned char *buf, unsigned size);
267
268 cam_err_t cam_start_capture(int fd);
269
270 cam_err_t cam_stop_capture(int fd);
271
272 cam_err_t cam_capture_frames(int fd, struct v4l2_buffer *buffer,
273                 struct cam_capture_settings *capture_settings);
274
275 cam_err_t cam_set_zoom(int fd, float zoom);
276
277 void mfldcam_3a_start (void);
278 void mfldcam_3a_stop (void);
279
280 void libmfld_cam_init (GstV4l2MFLDAdvCI *advci);
281 void libmfld_cam_dispose (void);
282
283
284 cam_err_t get_ae_windows_num(int fd, int * num);
285 void get_awb_version(int fd, int * major, int * minor);
286 void get_ae_version(int fd, int * major, int * minor);
287 void get_rer_status(int fd, int * status);
288 void get_rer_version(int fd, int * major, int * minor);
289 void get_af_version(int fd, int * major, int * minor);
290 cam_err_t cam_get_focus_posi(int fd, unsigned * posi);
291 void get_af_result(int fd, unsigned * result);
292 cam_err_t get_af_status(int fd, unsigned * status);
293 void cam_set_af_ae_window(advci_window *window);
294
295 cam_err_t get_exp_mode(int fd, cam_scene_mode_t *expmode);
296 void get_ae_bias(int fd, int * bias);
297 cam_err_t get_ae_manual_shutter(int fd, float *time);
298 cam_err_t get_ae_manual_aperture(int fd, int *aperture);
299 cam_err_t get_ae_flash_mode(int fd, cam_flash_mode_t *mode);
300 cam_err_t set_ae_flash_mode(int fd, cam_flash_mode_t mode);
301
302 int cam_find_item_new (const int table[][2], const int item, int reverse);
303
304 cam_err_t get_awb_manual_color_temperature(int fd, int *ctemp);
305 cam_err_t get_wb_mode (int *wb_mode);
306 gboolean cam_is_flash_used(void);
307
308 #endif