merge with master
[adaptation/intel_mfld/gst-plugins-atomisp.git] / gst-libs / gst / camera / gstmfldcamerasrc.h
1 /* GStreamer
2  *
3  * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4  *               2006 Edgard Lima <edgard.lima@indt.org.br>
5  *               2008-2010 Nokia Corporation <multimedia@maemo.org>
6  *
7  * gstcamerasrc.h: Abstract camera source base class
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #ifndef __GST_CAMSRC_H__
26 #define __GST_CAMSRC_H__
27
28 #ifndef GST_USE_UNSTABLE_API
29 #define GST_USE_UNSTABLE_API
30 #endif
31
32 #include <gst/gst.h>
33 #include <gst/base/gstpushsrc.h>
34 #include <gst/interfaces/photography.h>
35 #include <gst/interfaces/colorbalance.h>
36 #include <gst/interfaces/cameracontrol.h>
37
38 /**
39  * GST_CAMERA_SRC_MAX_SIZE:
40  *
41  * Maximum frame width or height size.
42  */
43 #define GST_CAMERA_SRC_MAX_SIZE (1<<15) /* 2^15 == 32768 */
44
45 G_BEGIN_DECLS
46
47 #define GST_TYPE_CAMERA_SRC            (gst_camerasrc_get_type())
48 #define GST_CAMERA_SRC(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CAMERA_SRC,GstCameraSrc))
49 #define GST_CAMERA_SRC_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CAMERA_SRC,GstCameraSrcClass))
50 #define GST_CAMERA_SRC_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_CAMERA_SRC,GstCameraSrcClass))
51 #define GST_IS_CAMERA_SRC(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CAMERA_SRC))
52 #define GST_IS_CAMERA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CAMERA_SRC))
53
54 #define GST_CAMERA_SRC_CAST(obj) ((GstCameraSrc *)(obj))
55 #define GST_CAMERA_SRC_CLASS_CAST(klass) ((GstCameraSrcClass *)(klass))
56
57 #define GST_TYPE_CAMERA_SRC_CAPTURE_MODE (gst_camerasrc_capture_mode_get_type())
58 #define GST_TYPE_CAMERA_SRC_VIEWFINDER_MODE (gst_camerasrc_viewfinder_mode_get_type())
59
60 /**
61  * GST_CAMERA_SRC_CAPTURE_START:
62  *
63  * Message that is sent when capturing process is about to start.
64  */
65 #define GST_CAMERA_SRC_CAPTURE_START "photo-capture-start"
66
67 /**
68  * GST_CAMERA_SRC_CAPTURE_END:
69  *
70  * Message that is sent when capturing process has finished.
71  */
72 #define GST_CAMERA_SRC_CAPTURE_END "photo-capture-end"
73
74 /**
75  * GST_CAMERA_SRC_PREVIEW_IMAGE:
76  *
77  * This message is used to send the preview image to application. Message will
78  * contain one field called "buffer" which will hold a GstBuffer containing
79  * the preview image data.
80  */
81 #define GST_CAMERA_SRC_PREVIEW_IMAGE "photo-capture-preview"
82
83 /**
84 * GST_CAMERA_SRC_CAF_STATUS:
85 *
86 * Continuous autofocus algorithm status update message.
87 */
88 #define GST_CAMERA_SRC_CAF_STATUS "caf-update"
89
90 typedef enum {
91     CAMERASRC_AUTO_FOCUS_RESULT_FOCUSED = 2,    /**< Focused.*/
92     CAMERASRC_AUTO_FOCUS_RESULT_FAILED,         /**< AF failed.*/
93     CAMERASRC_AUTO_FOCUS_RESULT_NUM,            /**< Number of AF result*/
94 }camerasrc_auto_focus_result_t;
95
96
97 /**
98  * GstCameraSrcCaptureMode:
99  * @GST_CAMERA_SRC_CAPTURE_MODE_VIEWFINDER: Viewfinder is running.
100  * @GST_CAMERA_SRC_CAPTURE_MODE_STILL: Still image capture mode.
101  * @GST_CAMERA_SRC_CAPTURE_MODE_VIDEO: Video capture mode.
102  *
103  * Camera element capturing modes.
104  */
105 typedef enum {
106   GST_CAMERA_SRC_CAPTURE_MODE_VIEWFINDER,
107   GST_CAMERA_SRC_CAPTURE_MODE_STILL,
108   GST_CAMERA_SRC_CAPTURE_MODE_VIDEO
109 } GstCameraSrcCaptureMode;
110
111
112 /**
113  * GstCameraSrcViewfinderMode:
114  * @GST_CAMERA_SRC_VIEWFINDER_MODE_STILL: Still image capture VF mode.
115  * @GST_CAMERA_SRC_VIEWFINDER_MODE_VIDEO: Video capture VF mode.
116  *
117  * Defines in which mode viewfinder should be run.
118  */
119 typedef enum {
120   GST_CAMERA_SRC_VIEWFINDER_MODE_STILL,
121   GST_CAMERA_SRC_VIEWFINDER_MODE_VIDEO
122 } GstCameraSrcViewfinderMode;
123
124
125 /**
126  * GstCameraSrcAFReqMode:
127  * @AF_NONE_REQUESTED: No change to AF mode requested.
128  * @AF_OFF_REQUESTED: AF should be turned off.
129  * @AF_ON_REQUESTED: AF should be turned on.
130  *
131  * Requested autofocus status.
132  */
133 typedef enum {
134   AF_NONE_REQUESTED = 0,
135   AF_OFF_REQUESTED,
136   AF_ON_REQUESTED
137 } GstCameraSrcAFReqMode;
138
139
140 /**
141  * GstCameraCapturePhase:
142  * @GST_CAMERA_OFF: photo capturing functionality disabled.
143  * @GST_CAMERA_VIEWFINDER: element is running in viewfinder mode.
144  * @GST_CAMERA_AUTOFOCUS: element is running autofocus phase.
145  * @GST_CAMERA_AUTOFOCUS_DONE: autofocus phase has ended.
146  * @GST_CAMERA_CAPTURE_START: element is preparing to capture HQ image.
147  * @GST_CAMERA_CAPTURE: element is capturing HQ image.
148  * @GST_CAMERA_CAPTURE_DONE: finishing HQ capture operation.
149  *
150  * Photo capturing phases.
151  */
152 typedef enum {
153   GST_CAMERA_OFF = 0,
154   GST_CAMERA_VIEWFINDER,
155   GST_CAMERA_AUTOFOCUS,
156   GST_CAMERA_AUTOFOCUS_DONE,
157   GST_CAMERA_CAPTURE_START,
158   GST_CAMERA_CAPTURE,
159   GST_CAMERA_CAPTURE_DONE
160 } GstCameraCapturePhase;
161
162 /* Signal Enumerations */
163 enum {
164   /*signal*/
165   CAMERA_IN_SIGNAL_STILL_CAPTURE,
166   CAMERA_IN_SIGNAL_NEGO_COMPLETE,
167   CAMERA_IN_SIGNAL_STILL_USRPTR_BUFFER,
168   CAMERA_IN_LAST_SIGNAL
169 };
170
171 typedef struct _GstCameraSrc GstCameraSrc;
172 typedef struct _GstCameraSrcClass GstCameraSrcClass;
173 typedef struct _GstCameraFocusStatus GstCameraFocusStatus;
174
175
176 typedef struct {
177         int x_left;
178         int x_right;
179         int y_top;
180         int y_bottom;
181         int weight;
182 } GstCameraSrc3a_window;
183
184 typedef struct
185 {
186   GstCameraControlExifInfo exif_info;
187   GstCameraSrc3a_window aaa_window;
188 } GstCameraControlInt;
189
190
191 /**
192  * GstCameraSrc:
193  * @element: the parent element.
194  *
195  * Opaque #GstCameraSrc object.
196  */
197 struct _GstCameraSrc {
198   GstPushSrc element;
199
200   /*< private >*/
201   GstCaps *vf_caps;
202   GList *colors;
203   GList *camera_controls;
204
205   /* TRUE if outgoing buffer should be always duplicated */
206   gboolean always_copy;
207
208   /* Current video device format */
209   guint   current_w, current_h;   /* current capture frame size */
210   guint   fps_d, fps_n;           /* framerate if device is open */
211   guint32 current_fourcc;         /* current color format */
212   GstClockTime duration;          /* duration of one frame */
213
214   /* Photo interface -related */
215   GstPhotoSettings        photoconf;    /* Caches the settings */
216   GMutex                  *state_lock;
217   GMutex                  *af_lock;
218   GstPhotoCapturePrepared prep_func;
219   gpointer                prep_udata;
220
221   /* camera control interface related */
222   GstCameraControlInt cam_ctrl;
223
224   /* Image capture format */
225   guint   capture_w, capture_h;
226   guint   capture_fps_n, capture_fps_d;
227   guint32 capture_fourcc;
228   guint32 capture_count;
229   guint32 capture_counter;
230   gboolean req_negotiation;
231   gboolean signal_still_capture;
232   gboolean capture_resolution_set; /* Is capture resolution set already? */
233
234   /* Preview image format */
235   guint   preview_w, preview_h;
236   guint32 preview_fourcc;
237   gboolean preview_resolution_set; /* Is preview resolution set already? */
238
239   GstCameraSrcCaptureMode capture_mode;
240   GstCameraSrcViewfinderMode viewfinder_mode;
241
242   /* Protected with state_lock */
243   GstCameraCapturePhase photo_capture_phase;
244
245   //guint       frame_byte_size;
246
247   guint8 requested_af_mode;
248   gboolean      maker_note;
249   gboolean enable_torch;
250 };
251
252
253 /**
254  * GstCameraSrcClass:
255  * @parent_class: the parent class structure.
256  * @open: Called when subclass should open the video device.
257  * @is_open: Called to get information if video device is currently open.
258  * @close: Called when subclass should close video device and free resources.
259  * @get_attribute: Called to get V4L2 attribute from device.
260  * @set_attribute: Called to set V4L2 attribute to device.
261  * @set_capture: Called to set VF/capture/preview resolution & format.
262  * @start: Capturing should start.
263  * @is_active: Ask subclass whether capturing is ongoing.
264  * @grab_frame: Ask the subclass to capture a frame.
265  * @stop: Subclass should stop capturing frames from device.
266  * @get_caps: Ask the subclass for supported output (viewfinder) caps.
267  * @get_num_buffers: Ask the subclass how many video buffers it is using.
268  * @unlock: Tell the subclass to stop any pending operation to video device.
269  * @unlock_stop: Clear previous unlock request.
270  * @fill_image_tags: Called after image capturing to retrieve image metadata.
271  * @get_preview_image: Called after image capture to retrieve preview image.
272  * @event: Used for passing custom events to subclass.
273  * @get_capabilities: Ask what capabilities subclass has.
274  * @set_vfinder_mode: Set viewfinder mode.
275  * @set_capture_mode: Set capturing mode.
276  * @set_autofocus: Turn on / off autofocus algorithm.
277  * @write_settings: Write all GstPhotoSettings to subclass at once.
278  * @read_settings: Read all device settings to given GstPhotoSettings structure.
279  * @set_zoom: Set the zoom factor.
280  * @get_max_zoom: Ask for maximum zoom factor that can be used.
281  * @get_supported_caps: Ask subclass about supported caps for given mode.
282  * @get_makernote: Get driver's makernote part
283  * @makernote_init: Init makernote
284  * @makernote_deal: The main part for deal with makernote
285  * @makernote_uninit: Uninit makernote
286  * #GstCameraSrc class object.
287  */
288 struct _GstCameraSrcClass
289 {
290   GstPushSrcClass parent_class;
291
292   /*< public >*/
293  /* virtual methods for subclasses */
294   gboolean (*open)              (GstCameraSrc *camsrc);
295
296   gboolean (*is_open)           (GstCameraSrc *camsrc);
297
298   gboolean (*close)             (GstCameraSrc *camsrc);
299
300   /* attribute control */
301   gboolean (*get_attribute)     (GstCameraSrc *camsrc, int attribute,
302                                  int *value);
303
304   gboolean (*set_attribute)     (GstCameraSrc *camsrc, int attribute,
305                                  const int value);
306
307   gboolean   (*set_capture)     (GstCameraSrc *camsrc,
308                                  GstOperationMode mode,
309                                  gboolean try_only,
310                                  guint32 *pixelformat,
311                                  guint *width, guint32 *height,
312                                  guint *fps_n, guint *fps_d);
313
314   gboolean   (*start)           (GstCameraSrc *camsrc, GstCaps *caps);
315
316   gboolean   (*is_active)       (GstCameraSrc *camsrc);
317
318   GstFlowReturn (*grab_frame)   (GstCameraSrc *camsrc, GstBuffer **buf,
319                                  GstCameraCapturePhase phase);
320
321   gboolean   (*stop)            (GstCameraSrc *camsrc);
322
323   GstCaps*   (*get_caps)        (GstCameraSrc *camsrc);
324
325   guint      (*get_num_buffers) (GstCameraSrc *camsrc);
326
327   gboolean   (*unlock)          (GstCameraSrc *camsrc);
328
329   gboolean   (*unlock_stop)     (GstCameraSrc *camsrc);
330
331   gboolean   (*fill_image_tags) (GstCameraSrc *camsrc, GstTagList *tlist);
332
333   gboolean   (*get_preview_image) (GstCameraSrc *camsrc, GstBuffer **buf);
334
335   gboolean   (*event)           (GstCameraSrc *camsrc, GstEvent *event);
336
337   /* FORMER DRIVER-API */
338
339   GstPhotoCaps
340   (*get_capabilities)  (GstCameraSrc *camsrc);
341
342   gboolean
343   (*set_vfinder_mode)  (GstCameraSrc *camsrc,
344                         GstCameraSrcViewfinderMode mode);
345
346   gboolean
347   (*set_capture_mode)  (GstCameraSrc *camsrc,
348                         GstCameraSrcCaptureMode mode);
349
350   gboolean
351   (*set_strobe_state)  (GstCameraSrc *camsrc, gboolean  state);
352
353
354   gboolean
355   (*set_autofocus)     (GstCameraSrc *camsrc, gboolean on_off);
356   gboolean
357   (*write_settings)    (GstCameraSrc *camsrc,
358                         GstPhotoSettings *photoconf,
359                         gboolean scene_mode_override);
360
361   gboolean
362   (*read_settings)     (GstCameraSrc *camsrc, GstPhotoSettings *photoconf);
363
364   gboolean
365   (*set_zoom)          (GstCameraSrc *camsrc, gfloat zoomfactor);
366
367   gboolean
368   (*set_AeAafwindow)  (GstCameraSrc *camsrc, GstCameraSrc3a_window window);
369
370   gboolean
371   (*set_ae_mode)      (GstCameraSrc *camsrc, int  mode);
372
373   gboolean
374   (*get_ae_mode)      (GstCameraSrc *camsrc, int *mode);
375
376   gboolean
377   (*get_max_zoom)     (GstCameraSrc *camsrc, gfloat *maxzoom);
378
379   GstCaps *
380   (*get_supported_caps)  (GstCameraSrc *camsrc, GstOperationMode mode);
381
382   gboolean
383   (*get_makernote) (GstCameraSrc *camsrc, unsigned char *buf, unsigned size);
384
385   gboolean
386   (*makernote_init)(GstCameraSrc * camsrc,
387                       unsigned * buf_size,
388                       unsigned num_afwindows,
389                       unsigned num_faces,
390                       unsigned num_eyes,
391                       unsigned num_grid,
392                       int *handle);
393   gboolean
394   (*makernote_deal)(GstCameraSrc * camsrc,
395                       GstBuffer *pmakerbuf,
396                       unsigned num_afwindows,
397                       unsigned num_grid,
398                       int handle);
399   gboolean
400   (*makernote_uninit)(GstCameraSrc * camsrc, int handle);
401   gboolean
402   (*read_exif)     (GstCameraSrc *camsrc,
403                     GstCameraControlExifInfo *exif_info);
404
405   gboolean
406   (*set_flash_mode)(GstCameraSrc *camsrc, int value);
407
408   /* signals */
409   void (*nego_complete) (GstElement *element);
410   void (*still_capture) (GstElement *element, GstBuffer *main, GstBuffer *sub, GstBuffer *scrnl);
411   void (*still_capture_usrptr_buffer) (GstElement *element, GstBuffer *usrptr);
412
413
414   /*< private >*/
415   gpointer       _gst_reserved[GST_PADDING_LARGE];
416 };
417
418
419 /**
420  * GstCameraFocusStatus:
421  * @status: GstFocusStatus indicating the status of focus operation.
422  * @windows: Table of integers defining the focused windows.
423  * @num_windows: Number of items in the @windows table.
424  * @focus_rows: Number of rows in window matrix.
425  * @focus_columns: Number of columns in window matrix.
426  * @coverage: Percentage of viewfinder area being used for focusing.
427  */
428 struct _GstCameraFocusStatus
429 {
430   GstFocusStatus status;
431   guint          *windows;
432   guint          num_windows;
433   guint8         focus_rows;
434   guint8         focus_columns;
435   guint          coverage;
436 };
437
438
439 GType gst_camerasrc_get_type (void);
440
441 void gst_camerasrc_add_color_channel (GstCameraSrc *camsrc,
442                                       GstColorBalanceChannel *channel);
443
444 void gst_camerasrc_clear_color_channels (GstCameraSrc *camsrc);
445
446
447 void gst_camerasrc_add_cameracontrol_channel (GstCameraSrc *camsrc,
448                                       GstCameraControlChannel *channel);
449
450 void gst_camerasrc_clear_cameracontrol_channels (GstCameraSrc *camsrc);
451
452 void gst_camerasrc_send_capture_start_message (GstCameraSrc *camsrc);
453
454 void gst_camerasrc_send_capture_stop_message (GstCameraSrc *camsrc);
455
456 void gst_camerasrc_af_update (GstCameraSrc *camsrc, GstCameraFocusStatus *fs);
457
458 void gst_camerasrc_caf_update (GstCameraSrc *camsrc, GstCameraFocusStatus *fs);
459
460 void gst_camerasrc_shake_update (GstCameraSrc *camsrc, GstPhotoShakeRisk risk);
461
462 GstCaps *
463 gst_camerasrc_get_caps_from_info (GstCameraSrc *camsrc, guint32 fourcc,
464     guint width, guint height, guint fps_n, guint fps_d);
465
466 const gchar * gst_camerasrc_exposure_mode_from_exif_value (gint value);
467
468 const gchar * gst_camerasrc_scene_capture_type_from_exif_value (gint value);
469
470 const gchar * gst_camerasrc_gain_adjustment_from_exif_value (gint value);
471
472 const gchar * gst_camerasrc_contrast_from_exif_value (gint value);
473
474 const gchar * gst_camerasrc_saturation_from_exif_value (gint value);
475
476 const gchar * gst_camerasrc_flash_mode_from_exif_value (gint value);
477
478 const gchar * gst_camerasrc_sharpness_from_exif_value (gint value);
479
480 const gchar * gst_camerasrc_metering_mode_from_exif_value (gint value);
481
482 const gchar * gst_camerasrc_file_source_from_exif_value (gint value);
483
484 int gst_camerasrc_send_af_status(GstCameraSrc *camsrc , int state);
485
486 G_END_DECLS
487
488 #endif /* __GST_CAMSRC_H__ */