Commit 34d2250c authored by Justin Kim's avatar Justin Kim

ahc2src: implement AF

Signed-off-by: Justin Kim's avatarJustin Kim <justin.kim@collabora.com>
parent 495d6b39
......@@ -215,6 +215,119 @@ gst_ahc2_src_get_capabilities (GstPhotography * photo)
return caps;
}
static void
gst_ahc2_src_set_autofocus (GstPhotography * photo, gboolean on)
{
GstAHC2Src *self = GST_AHC2_SRC (photo);
GstAHC2SrcPrivate *priv = GST_AHC2_SRC_GET_PRIVATE (self);
guint8 mode = on ? ACAMERA_CONTROL_AF_MODE_AUTO :
ACAMERA_CONTROL_AF_MODE_OFF;
g_return_if_fail (priv->capture_request != NULL);
ACameraCaptureSession_stopRepeating (priv->camera_capture_session);
ACaptureRequest_setEntry_u8 (priv->capture_request,
ACAMERA_CONTROL_AF_MODE, 1, &mode);
ACameraCaptureSession_setRepeatingRequest (priv->camera_capture_session,
NULL, 1, &priv->capture_request, NULL);
}
static gboolean
gst_ahc2_src_get_focus_mode (GstPhotography * photo,
GstPhotographyFocusMode * focus_mode)
{
GstAHC2Src *self = GST_AHC2_SRC (photo);
GstAHC2SrcPrivate *priv = GST_AHC2_SRC_GET_PRIVATE (self);
ACameraMetadata_const_entry entry;
g_return_val_if_fail (priv->capture_request != NULL, FALSE);
if (ACaptureRequest_getConstEntry (priv->capture_request,
ACAMERA_CONTROL_AF_MODE, &entry) != ACAMERA_OK) {
GST_WARNING_OBJECT (self, "Failed to get AF MODE");
return FALSE;
}
/* GstPhotographyFocusMode doesn't matches
* acamera_metadata_enum_acamera_control_af_mode. */
switch (entry.data.u8[0]) {
case ACAMERA_CONTROL_AF_MODE_OFF:
*focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_MANUAL;
break;
case ACAMERA_CONTROL_AF_MODE_AUTO:
*focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_AUTO;
break;
case ACAMERA_CONTROL_AF_MODE_MACRO:
*focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_MACRO;
break;
case ACAMERA_CONTROL_AF_MODE_CONTINUOUS_VIDEO:
*focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_HYPERFOCAL;
break;
case ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE:
*focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL;
break;
case ACAMERA_CONTROL_AF_MODE_EDOF:
*focus_mode = GST_PHOTOGRAPHY_FOCUS_MODE_EXTENDED;
break;
default:
g_assert_not_reached ();
break;
}
return TRUE;
}
static gboolean
gst_ahc2_src_set_focus_mode (GstPhotography * photo,
GstPhotographyFocusMode focus_mode)
{
GstAHC2Src *self = GST_AHC2_SRC (photo);
GstAHC2SrcPrivate *priv = GST_AHC2_SRC_GET_PRIVATE (self);
guint8 mode;
g_return_val_if_fail (priv->capture_request != NULL, FALSE);
switch (focus_mode) {
case GST_PHOTOGRAPHY_FOCUS_MODE_AUTO:
mode = ACAMERA_CONTROL_AF_MODE_AUTO;
break;
case GST_PHOTOGRAPHY_FOCUS_MODE_MACRO:
mode = ACAMERA_CONTROL_AF_MODE_MACRO;
break;
case GST_PHOTOGRAPHY_FOCUS_MODE_PORTRAIT:
mode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
break;
case GST_PHOTOGRAPHY_FOCUS_MODE_INFINITY:
case GST_PHOTOGRAPHY_FOCUS_MODE_HYPERFOCAL:
case GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL:
case GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_EXTENDED:
mode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_VIDEO;
break;
case GST_PHOTOGRAPHY_FOCUS_MODE_MANUAL:
mode = ACAMERA_CONTROL_AF_MODE_OFF;
break;
case GST_PHOTOGRAPHY_FOCUS_MODE_EXTENDED:
mode = ACAMERA_CONTROL_AF_MODE_EDOF;
break;
default:
g_assert_not_reached ();
break;
}
ACameraCaptureSession_stopRepeating (priv->camera_capture_session);
ACaptureRequest_setEntry_u8 (priv->capture_request,
ACAMERA_CONTROL_AF_MODE, 1, &mode);
ACameraCaptureSession_setRepeatingRequest (priv->camera_capture_session,
NULL, 1, &priv->capture_request, NULL);
return TRUE;
}
static gboolean
gst_ahc2_src_get_ev_compensation (GstPhotography * photo, gfloat * ev_comp)
{
......@@ -945,6 +1058,11 @@ gst_ahc2_src_set_property (GObject * object,
gst_ahc2_src_set_white_balance_mode (GST_PHOTOGRAPHY (self), wb);
break;
}
case PROP_FOCUS_MODE: {
GstPhotographyFocusMode focus = g_value_get_enum (value);
gst_ahc2_src_set_focus_mode (GST_PHOTOGRAPHY (self), focus);
break;
}
case PROP_ZOOM: {
gfloat zoom = g_value_get_float (value);
gst_ahc2_src_set_zoom (GST_PHOTOGRAPHY (self), zoom);
......@@ -995,6 +1113,12 @@ gst_ahc2_src_get_property (GObject * object,
g_value_set_enum (value, wb);
break;
}
case PROP_FOCUS_MODE: {
GstPhotographyFocusMode focus;
if (gst_ahc2_src_get_focus_mode (GST_PHOTOGRAPHY (self), &focus))
g_value_set_enum (value, focus);
break;
}
case PROP_ZOOM: {
gfloat zoom;
if (gst_ahc2_src_get_zoom (GST_PHOTOGRAPHY (self), &zoom))
......@@ -1454,6 +1578,10 @@ gst_ahc2_src_photography_init (gpointer g_iface, gpointer iface_data)
iface->get_capabilities = gst_ahc2_src_get_capabilities;
iface->set_autofocus = gst_ahc2_src_set_autofocus;
iface->get_focus_mode = gst_ahc2_src_get_focus_mode;
iface->set_focus_mode = gst_ahc2_src_set_focus_mode;
iface->get_white_balance_mode = gst_ahc2_src_get_white_balance_mode;
iface->set_white_balance_mode = gst_ahc2_src_set_white_balance_mode;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment