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>
7 * gstcamerasrc.h: Abstract camera source base class
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.
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.
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.
25 #ifndef __GST_CAMSRC_H__
26 #define __GST_CAMSRC_H__
28 #ifndef GST_USE_UNSTABLE_API
29 #define GST_USE_UNSTABLE_API
33 #include <gst/base/gstpushsrc.h>
34 #include <gst/interfaces/photography.h>
35 #include <gst/interfaces/colorbalance.h>
36 #include <gst/interfaces/cameracontrol.h>
39 * GST_CAMERA_SRC_MAX_SIZE:
41 * Maximum frame width or height size.
43 #define GST_CAMERA_SRC_MAX_SIZE (1<<15) /* 2^15 == 32768 */
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))
54 #define GST_CAMERA_SRC_CAST(obj) ((GstCameraSrc *)(obj))
55 #define GST_CAMERA_SRC_CLASS_CAST(klass) ((GstCameraSrcClass *)(klass))
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())
61 * GST_CAMERA_SRC_CAPTURE_START:
63 * Message that is sent when capturing process is about to start.
65 #define GST_CAMERA_SRC_CAPTURE_START "photo-capture-start"
68 * GST_CAMERA_SRC_CAPTURE_END:
70 * Message that is sent when capturing process has finished.
72 #define GST_CAMERA_SRC_CAPTURE_END "photo-capture-end"
75 * GST_CAMERA_SRC_PREVIEW_IMAGE:
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.
81 #define GST_CAMERA_SRC_PREVIEW_IMAGE "photo-capture-preview"
84 * GST_CAMERA_SRC_CAF_STATUS:
86 * Continuous autofocus algorithm status update message.
88 #define GST_CAMERA_SRC_CAF_STATUS "caf-update"
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;
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.
103 * Camera element capturing modes.
106 GST_CAMERA_SRC_CAPTURE_MODE_VIEWFINDER,
107 GST_CAMERA_SRC_CAPTURE_MODE_STILL,
108 GST_CAMERA_SRC_CAPTURE_MODE_VIDEO
109 } GstCameraSrcCaptureMode;
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.
117 * Defines in which mode viewfinder should be run.
120 GST_CAMERA_SRC_VIEWFINDER_MODE_STILL,
121 GST_CAMERA_SRC_VIEWFINDER_MODE_VIDEO
122 } GstCameraSrcViewfinderMode;
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.
131 * Requested autofocus status.
134 AF_NONE_REQUESTED = 0,
137 } GstCameraSrcAFReqMode;
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.
150 * Photo capturing phases.
154 GST_CAMERA_VIEWFINDER,
155 GST_CAMERA_AUTOFOCUS,
156 GST_CAMERA_AUTOFOCUS_DONE,
157 GST_CAMERA_CAPTURE_START,
159 GST_CAMERA_CAPTURE_DONE
160 } GstCameraCapturePhase;
162 /* Signal Enumerations */
165 CAMERA_IN_SIGNAL_STILL_CAPTURE,
166 CAMERA_IN_SIGNAL_NEGO_COMPLETE,
167 CAMERA_IN_SIGNAL_STILL_USRPTR_BUFFER,
168 CAMERA_IN_LAST_SIGNAL
171 typedef struct _GstCameraSrc GstCameraSrc;
172 typedef struct _GstCameraSrcClass GstCameraSrcClass;
173 typedef struct _GstCameraFocusStatus GstCameraFocusStatus;
182 } GstCameraSrc3a_window;
186 GstCameraControlExifInfo exif_info;
187 GstCameraSrc3a_window aaa_window;
188 } GstCameraControlInt;
193 * @element: the parent element.
195 * Opaque #GstCameraSrc object.
197 struct _GstCameraSrc {
203 GList *camera_controls;
205 /* TRUE if outgoing buffer should be always duplicated */
206 gboolean always_copy;
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 */
214 /* Photo interface -related */
215 GstPhotoSettings photoconf; /* Caches the settings */
218 GstPhotoCapturePrepared prep_func;
221 /* camera control interface related */
222 GstCameraControlInt cam_ctrl;
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? */
234 /* Preview image format */
235 guint preview_w, preview_h;
236 guint32 preview_fourcc;
237 gboolean preview_resolution_set; /* Is preview resolution set already? */
239 GstCameraSrcCaptureMode capture_mode;
240 GstCameraSrcViewfinderMode viewfinder_mode;
242 /* Protected with state_lock */
243 GstCameraCapturePhase photo_capture_phase;
245 //guint frame_byte_size;
247 guint8 requested_af_mode;
249 gboolean enable_torch;
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.
288 struct _GstCameraSrcClass
290 GstPushSrcClass parent_class;
293 /* virtual methods for subclasses */
294 gboolean (*open) (GstCameraSrc *camsrc);
296 gboolean (*is_open) (GstCameraSrc *camsrc);
298 gboolean (*close) (GstCameraSrc *camsrc);
300 /* attribute control */
301 gboolean (*get_attribute) (GstCameraSrc *camsrc, int attribute,
304 gboolean (*set_attribute) (GstCameraSrc *camsrc, int attribute,
307 gboolean (*set_capture) (GstCameraSrc *camsrc,
308 GstOperationMode mode,
310 guint32 *pixelformat,
311 guint *width, guint32 *height,
312 guint *fps_n, guint *fps_d);
314 gboolean (*start) (GstCameraSrc *camsrc, GstCaps *caps);
316 gboolean (*is_active) (GstCameraSrc *camsrc);
318 GstFlowReturn (*grab_frame) (GstCameraSrc *camsrc, GstBuffer **buf,
319 GstCameraCapturePhase phase);
321 gboolean (*stop) (GstCameraSrc *camsrc);
323 GstCaps* (*get_caps) (GstCameraSrc *camsrc);
325 guint (*get_num_buffers) (GstCameraSrc *camsrc);
327 gboolean (*unlock) (GstCameraSrc *camsrc);
329 gboolean (*unlock_stop) (GstCameraSrc *camsrc);
331 gboolean (*fill_image_tags) (GstCameraSrc *camsrc, GstTagList *tlist);
333 gboolean (*get_preview_image) (GstCameraSrc *camsrc, GstBuffer **buf);
335 gboolean (*event) (GstCameraSrc *camsrc, GstEvent *event);
337 /* FORMER DRIVER-API */
340 (*get_capabilities) (GstCameraSrc *camsrc);
343 (*set_vfinder_mode) (GstCameraSrc *camsrc,
344 GstCameraSrcViewfinderMode mode);
347 (*set_capture_mode) (GstCameraSrc *camsrc,
348 GstCameraSrcCaptureMode mode);
351 (*set_strobe_state) (GstCameraSrc *camsrc, gboolean state);
355 (*set_autofocus) (GstCameraSrc *camsrc, gboolean on_off);
357 (*write_settings) (GstCameraSrc *camsrc,
358 GstPhotoSettings *photoconf,
359 gboolean scene_mode_override);
362 (*read_settings) (GstCameraSrc *camsrc, GstPhotoSettings *photoconf);
365 (*set_zoom) (GstCameraSrc *camsrc, gfloat zoomfactor);
368 (*set_AeAafwindow) (GstCameraSrc *camsrc, GstCameraSrc3a_window window);
371 (*set_ae_mode) (GstCameraSrc *camsrc, int mode);
374 (*get_ae_mode) (GstCameraSrc *camsrc, int *mode);
377 (*get_max_zoom) (GstCameraSrc *camsrc, gfloat *maxzoom);
380 (*get_supported_caps) (GstCameraSrc *camsrc, GstOperationMode mode);
383 (*get_makernote) (GstCameraSrc *camsrc, unsigned char *buf, unsigned size);
386 (*makernote_init)(GstCameraSrc * camsrc,
388 unsigned num_afwindows,
394 (*makernote_deal)(GstCameraSrc * camsrc,
395 GstBuffer *pmakerbuf,
396 unsigned num_afwindows,
400 (*makernote_uninit)(GstCameraSrc * camsrc, int handle);
402 (*read_exif) (GstCameraSrc *camsrc,
403 GstCameraControlExifInfo *exif_info);
406 (*set_flash_mode)(GstCameraSrc *camsrc, int value);
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);
415 gpointer _gst_reserved[GST_PADDING_LARGE];
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.
428 struct _GstCameraFocusStatus
430 GstFocusStatus status;
434 guint8 focus_columns;
439 GType gst_camerasrc_get_type (void);
441 void gst_camerasrc_add_color_channel (GstCameraSrc *camsrc,
442 GstColorBalanceChannel *channel);
444 void gst_camerasrc_clear_color_channels (GstCameraSrc *camsrc);
447 void gst_camerasrc_add_cameracontrol_channel (GstCameraSrc *camsrc,
448 GstCameraControlChannel *channel);
450 void gst_camerasrc_clear_cameracontrol_channels (GstCameraSrc *camsrc);
452 void gst_camerasrc_send_capture_start_message (GstCameraSrc *camsrc);
454 void gst_camerasrc_send_capture_stop_message (GstCameraSrc *camsrc);
456 void gst_camerasrc_af_update (GstCameraSrc *camsrc, GstCameraFocusStatus *fs);
458 void gst_camerasrc_caf_update (GstCameraSrc *camsrc, GstCameraFocusStatus *fs);
460 void gst_camerasrc_shake_update (GstCameraSrc *camsrc, GstPhotoShakeRisk risk);
463 gst_camerasrc_get_caps_from_info (GstCameraSrc *camsrc, guint32 fourcc,
464 guint width, guint height, guint fps_n, guint fps_d);
466 const gchar * gst_camerasrc_exposure_mode_from_exif_value (gint value);
468 const gchar * gst_camerasrc_scene_capture_type_from_exif_value (gint value);
470 const gchar * gst_camerasrc_gain_adjustment_from_exif_value (gint value);
472 const gchar * gst_camerasrc_contrast_from_exif_value (gint value);
474 const gchar * gst_camerasrc_saturation_from_exif_value (gint value);
476 const gchar * gst_camerasrc_flash_mode_from_exif_value (gint value);
478 const gchar * gst_camerasrc_sharpness_from_exif_value (gint value);
480 const gchar * gst_camerasrc_metering_mode_from_exif_value (gint value);
482 const gchar * gst_camerasrc_file_source_from_exif_value (gint value);
484 int gst_camerasrc_send_af_status(GstCameraSrc *camsrc , int state);
488 #endif /* __GST_CAMSRC_H__ */