int af_enabled, ae_enabled, awb_enabled;
int af_result; // 0 means fail, it will be filled when captured finished.
int still_af_count, start_still_af;
+ struct timeval af_start_time;
int initflag;
int mmap;
int first_frame;
float frame_rate;
int sensor_type;
struct timeval timestamp;
+ int focus_done;
};
struct buffer
size_t length;
};
+/* TODO: Check if this is needed anymore after focus works like it should.
+ * Hysteriss added to focus_done
+ * in some case when old focus is still in progress and appication
+ * ask new focus to be started might be a case that 3A returns false "focus ready"
+ * and status info is sent to app. -> for some reason it will crash to that.
+* */
+#define FOCUS_REALLY_DONE 2
+
+/* Maximum auto focus time */
+static const int STILL_AF_MAX_TIME_IN_MS = 2200;
+
/* FIXME: Add lock to protec this global variable
* */
static struct mfld_cam_settings_t mfld_cam_settings;
static struct mfld_driver_t mfld_driver;
static GstV4l2MFLDAdvCI *mfldadvci;
+static inline long
+calculate_timediff(struct timeval *t0, struct timeval *t1)
+{
+ return ((t1->tv_sec - t0->tv_sec) * 1000000 +
+ t1->tv_usec - t0->tv_usec) / 1000;
+}
+
static void
clear_bit (int nr, unsigned int *addr)
{
/* V4l2camerasrc uses this to query autofocusing status.
*/
-cam_err_t
-cam_checkfocus_status (cam_focus_status_t * status)
+int
+cam_checkfocus_status (cam_focus_status_t * status, int force_update)
{
- ia_3a_af_status adv_status;
-
+ ia_3a_af_status af_status;
+ bool do_read = FALSE;
- mfldadvci->AfGetStillAfStatus (&adv_status);
-
- cam_driver_dbg ("%s\n", __func__);
-
- *status = cam_find_item_new (focus_status_map, adv_status, 1);
- return CAM_ERR_NONE;
+ if (mfld_driver.focus_done >= FOCUS_REALLY_DONE) {
+ mfld_driver.focus_done = 0;
+ do_read = TRUE;
+ }
+ if ((do_read == TRUE) || (force_update == 1)) {
+ mfldadvci->AfGetStillAfStatus (&af_status);
+ *status = cam_find_item_new (focus_status_map, af_status, 1);
+ cam_driver_dbg ("%s *status : %d\n ", __func__, *status);
+ *status = CAM_FOCUS_STATUS_RUNNING;
+ return 1;
+ }
+ return 0;
}
/* V4l2camerasrc uses this to query the risk for image shaking.
mfld_driver.dvs_vector.x = 0;
mfld_driver.dvs_vector.y = 0;
+ mfld_driver.focus_done = 0;
mfldadvci = advci;
if (mfld_driver.start_still_af) {
if (mfld_driver.af_enabled && mfld_driver.still_af_count > 0)
mfldadvci->af_stop ();
+ mfld_driver.focus_done = 0;
mfld_driver.start_still_af = 0;
mfld_driver.still_af_count = 1;
+ mfld_driver.af_start_time = mfld_driver.timestamp;
if (mfld_driver.af_enabled)
mfldadvci->af_start ();
if (mfld_driver.af_enabled)
complete = mfldadvci->af_is_complete ();
- if (complete || mfld_driver.still_af_count > 100) {
- mfld_driver.still_af_count = 0;
- if (complete == 0) {
- mfldadvci->af_stop();
- cam_driver_dbg ("AF: Focus Failed %s\n", __func__);
+ if (complete ||
+ (calculate_timediff(&mfld_driver.af_start_time, &mfld_driver.timestamp)
+ > STILL_AF_MAX_TIME_IN_MS) ) {
+ mfld_driver.focus_done ++;
+ if(mfld_driver.focus_done >= FOCUS_REALLY_DONE) {
+ mfld_driver.still_af_count = 0;
+ if (complete == 0) {
+ mfldadvci->af_stop();
+ cam_driver_dbg ("AF: Focus Failed %s\n", __func__);
+ }
}
+ else
+ mfld_driver.still_af_count++;
} else
mfld_driver.still_af_count++;
}
gst_camerasrc_camera_control_channel,
GstCameraControlChannel, GST_TYPE_CAMERA_CONTROL_CHANNEL);
-gboolean
-gst_camerasrc_camera_control_parse_preview_caps (GstCameraSrc *camerasrc,
- GstCaps *op_mode_caps);
-
-gboolean
-gst_camerasrc_camera_control_parse_capture_caps (GstCameraSrc * camerasrc,
- GstCaps * op_mode_caps);
static void
gst_camerasrc_camera_control_channel_base_init (gpointer g_class)
case MM_CAMCORDER_FOCUS_MODE_NONE:
focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_INFINITY;
break;
- case MM_CAMCORDER_FOCUS_MODE_PAN:
case MM_CAMCORDER_FOCUS_MODE_AUTO:
case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_AUTO;
break;
+ case MM_CAMCORDER_FOCUS_MODE_PAN:
+ focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_HYPERFOCAL;
+ break;
case MM_CAMCORDER_FOCUS_MODE_MANUAL:
focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_INFINITY;
break;
case GST_PHOTOGRAPHY_FOCUS_MODE_AUTO:
*mode = MM_CAMCORDER_FOCUS_MODE_AUTO;
break;
+ case GST_PHOTOGRAPHY_FOCUS_MODE_HYPERFOCAL:
+ *mode = MM_CAMCORDER_FOCUS_MODE_PAN;
+ break;
case GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL:
*mode = MM_CAMCORDER_FOCUS_MODE_CONTINUOUS;
break;
"framerate", GST_TYPE_FRACTION, camerasrc->capture_fps_n,
camerasrc->capture_fps_d, NULL);
- gst_camerasrc_camera_control_parse_capture_caps(camerasrc,CaptureCaps);
camerasrc->photo_capture_phase = GST_CAMERA_CAPTURE_START;
g_mutex_unlock (camerasrc->state_lock);
}
g_mutex_unlock (camerasrc->state_lock);
}
}
-
-
-gboolean
-gst_camerasrc_camera_control_parse_capture_caps (GstCameraSrc * camerasrc,
- GstCaps * op_mode_caps)
-{
- GstCameraSrcClass *bclass;
-
- gboolean ret = TRUE;
- GstStructure *cstr;
- guint32 fcc_format;
- gint tmp_fps_n = 0;
- gint tmp_fps_d = 0;
- gint tmp_w = 0;
- gint tmp_h = 0;
-
- bclass = GST_CAMERA_SRC_GET_CLASS (camerasrc);
-
- GST_DEBUG_OBJECT (camerasrc, "Parsing image capture caps");
-
- if (op_mode_caps == NULL) {
- camerasrc->capture_resolution_set = FALSE;
- GST_DEBUG_OBJECT (camerasrc, "NULL caps received for image capture");
- goto done;
- }
-
- cstr = gst_caps_get_structure (op_mode_caps, 0);
-
- /* FIXME: Use VF format if fourcc is not given */
- /* FIXME: Don't require FPS here */
- if (gst_structure_get_fourcc (cstr, "format", &fcc_format) &&
- gst_structure_get_int (cstr, "width", &tmp_w) &&
- gst_structure_get_int (cstr, "height", &tmp_h) &&
- gst_structure_get_fraction (cstr, "framerate", &tmp_fps_n, &tmp_fps_d)) {
- /* check if the requested fourcc format is supported */
- GstCaps *s_caps = NULL;
-
- /* get camsrc sourcepad caps, because the pad has
- * caps-template including supported formats */
- s_caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD
- (camerasrc)));
-
- /* if intersection is empty -> provided caps not supported */
- GST_LOG_OBJECT (camerasrc, "op_mode_caps caps: %" GST_PTR_FORMAT, op_mode_caps);
- GST_LOG_OBJECT (camerasrc, "s_caps caps: %" GST_PTR_FORMAT, s_caps);
-
- if (!gst_caps_can_intersect (op_mode_caps, s_caps)) {
- GST_WARNING_OBJECT (camerasrc,
- "Unsupported fourcc format provided by caller");
- ret = FALSE;
- }
-
- /* Check that the requested resolution is not the same as what is
- * currently configured to be in use. If so, no need to set it again.
- */
- if ((camerasrc->capture_w != tmp_w ||
- camerasrc->capture_h != tmp_h ||
- camerasrc->capture_fourcc != fcc_format) && ret == TRUE) {
- GST_DEBUG_OBJECT (camerasrc,
- "set width: %d , height: %d , fps_n: %d , fps_d :%d , format: %"
- GST_FOURCC_FORMAT, tmp_w, tmp_h, tmp_fps_n, tmp_fps_d,
- GST_FOURCC_ARGS (fcc_format));
-
- ret = bclass->set_capture (camerasrc,
- GST_PHOTOGRAPHY_OPERATION_MODE_IMAGE_CAPTURE, FALSE, &fcc_format,
- (guint *) & tmp_w, (guint *) & tmp_h, NULL, NULL);
-/*
- ret = bclass->set_capture (camerasrc,
- GST_PHOTOGRAPHY_OPERATION_MODE_PREVIEW, FALSE, &fcc_format,
- (guint *) & tmp_w, (guint *) & tmp_h, NULL, NULL);
-*/
- if (ret) {
- camerasrc->capture_w = tmp_w;
- camerasrc->capture_h = tmp_h;
- camerasrc->capture_fps_n = tmp_fps_n;
- camerasrc->capture_fps_d = tmp_fps_d;
- camerasrc->capture_fourcc = fcc_format;
- camerasrc->capture_resolution_set = TRUE;
-
- /* Write the assigned values back to the caps structure if possible */
- if (GST_CAPS_REFCOUNT_VALUE (op_mode_caps) == 1) {
- gst_caps_set_simple (op_mode_caps,
- "width", G_TYPE_INT, camerasrc->capture_w,
- "height", G_TYPE_INT, camerasrc->capture_h,
- "format", GST_TYPE_FOURCC, camerasrc->capture_fourcc, NULL);
- }
-
- /* It may not be possible to create the preview with previously
- * given resolution. Therefore we cancel the preview creation */
- gst_camerasrc_camera_control_parse_preview_caps (camerasrc, NULL);
-
- /* Notify that supported preview caps may have changed */
- g_object_notify (G_OBJECT (camerasrc),
- GST_PHOTOGRAPHY_PROP_IMAGE_PREVIEW_SUPPORTED_CAPS);
- }
- } else {
- GST_DEBUG_OBJECT (camerasrc, "format not set");
- ret = FALSE;
- }
- if (s_caps)
- gst_caps_unref (s_caps);
-
- } else {
- GST_DEBUG_OBJECT (camerasrc, "Unable to parse given caps");
- ret = FALSE;
- }
-
-done:
-
- return ret;
-}
-
-
-gboolean
-gst_camerasrc_camera_control_parse_preview_caps (GstCameraSrc *camerasrc,
- GstCaps *op_mode_caps)
-{
- GstCameraSrcClass *bclass;
- gboolean ret = FALSE;
- guint32 fourcc = 0;
- gint tmp_w = 0;
- gint tmp_h = 0;
-
- bclass = GST_CAMERA_SRC_GET_CLASS (camerasrc);
-
- if (op_mode_caps == NULL) {
- /* Setting NULL caps means canceling the preview image creation process.
- * In this case resolution 0x0 will be given to subclass */
- GST_DEBUG_OBJECT (camerasrc, "NULL caps received for preview image");
- ret = TRUE;
- }
- else {
- GstStructure *cstr;
-
- GST_DEBUG_OBJECT (camerasrc, "parsing preview caps");
-
- cstr = gst_caps_get_structure (op_mode_caps, 0);
-
- /* FIXME: Use VF format if fourcc is not given */
- if (gst_structure_get_fourcc (cstr, "format", &fourcc) &&
- gst_structure_get_int (cstr, "width", &tmp_w) &&
- gst_structure_get_int (cstr, "height", &tmp_h))
- {
-#if 0
- /* check if the requested fourcc format is supported */
- GstCaps * s_caps = NULL;
- GstCaps * r_caps = NULL;
-
- /* get camsrc sourcepad caps, because the pad has
- * caps-template including supported formats */
- s_caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD
- (camerasrc)));
- /* take an intersection between sourcepad caps and provided caps */
- r_caps = gst_caps_intersect (op_mode_caps, s_caps);
-
- /* if EMPTY or NULL => provided caps not supported as not set in sourcepad */
- if (r_caps == NULL || gst_caps_is_empty (r_caps)) {
- GST_WARNING_OBJECT (camerasrc,
- "Unsupported fourcc format provided by caller");
- ret = FALSE;
- }
- if (s_caps)
- gst_caps_unref (s_caps);
- if (r_caps)
- gst_caps_unref (r_caps);
-#endif
- ret = TRUE;
- }
- else {
- GST_DEBUG_OBJECT (camerasrc, "Unable to parse given caps");
- ret = FALSE;
- }
- }
-
- /* Check that the requested resolution is not the same as what is
- * currently configured to be in use. If so, no need to set it again.
- */
- if (ret && (camerasrc->preview_w != tmp_w || camerasrc->preview_h != tmp_h ||
- camerasrc->preview_fourcc != fourcc))
- {
- GST_DEBUG_OBJECT (camerasrc,
- "set preview width: %d, height: %d, format: %"
- GST_FOURCC_FORMAT, tmp_w, tmp_h, GST_FOURCC_ARGS (fourcc));
-
- ret = bclass->set_capture (camerasrc,
- GST_PHOTOGRAPHY_OPERATION_MODE_PREVIEW, FALSE,
- &fourcc, (guint *) &tmp_w, (guint *) &tmp_h, NULL, NULL);
-
- if (fourcc == 0) {
- /* Special case: preview image creation is canceled (NULL caps)*/
- camerasrc->preview_resolution_set = FALSE;
- ret = TRUE;
- }
- else {
- if (ret && op_mode_caps && GST_CAPS_REFCOUNT_VALUE (op_mode_caps) == 1) {
- /* Write the assigned values back to the caps structure */
- gst_caps_set_simple (op_mode_caps,
- "width", G_TYPE_INT, tmp_w,
- "height", G_TYPE_INT, tmp_h,
- "format", GST_TYPE_FOURCC, fourcc,
- NULL);
- }
-
- GST_DEBUG_OBJECT (camerasrc,
- "selected preview width: %d, height: %d, format: %"
- GST_FOURCC_FORMAT, tmp_w, tmp_h, GST_FOURCC_ARGS (fourcc));
-
- camerasrc->preview_resolution_set = ret;
- }
- } else {
- GST_DEBUG_OBJECT (camerasrc, "format not set");
- ret = FALSE;
- }
-
- if (ret) {
- camerasrc->preview_w = tmp_w;
- camerasrc->preview_h = tmp_h;
- camerasrc->preview_fourcc = fourcc;
- }
-
- return ret;
-}