Commit 1eeec779 authored by Justin Kim's avatar Justin Kim

ahc2src: implement ev_compensation

Signed-off-by: Justin Kim's avatarJustin Kim <justin.kim@collabora.com>
parent b87b5a49
......@@ -24,6 +24,7 @@
#include "gstahc2src.h"
#include <math.h>
#include <stdbool.h>
#include <gst/base/base.h>
#include <gst/video/video.h>
......@@ -214,6 +215,123 @@ gst_ahc2_src_get_capabilities (GstPhotography * photo)
return caps;
}
static gboolean
gst_ahc2_src_get_ev_compensation (GstPhotography * photo, gfloat * ev_comp)
{
GstAHC2Src *self = GST_AHC2_SRC (photo);
GstAHC2SrcPrivate *priv = GST_AHC2_SRC_GET_PRIVATE (self);
ACameraMetadata* metadata = NULL;
ACameraMetadata_const_entry entry;
gint ev;
ACameraMetadata_rational ev_step;
gboolean ret = FALSE;
g_return_val_if_fail (priv->camera_manager != NULL, FALSE);
g_return_val_if_fail (priv->camera_id_list != NULL, FALSE);
g_return_val_if_fail (priv->camera_index < priv->camera_id_list->numCameras,
FALSE);
g_return_val_if_fail (priv->capture_request != NULL, FALSE);
if (ACameraManager_getCameraCharacteristics (priv->camera_manager,
priv->camera_id_list->cameraIds[priv->camera_index],
&metadata) != ACAMERA_OK) {
GST_ERROR_OBJECT (self, "Failed to get metadata object");
goto out;
}
if (ACameraMetadata_getConstEntry (metadata,
ACAMERA_CONTROL_AE_COMPENSATION_STEP, &entry) != ACAMERA_OK) {
GST_WARNING_OBJECT (self, "Failed to get EV STEP");
goto out;
}
ev_step = entry.data.r[0];
if (ACaptureRequest_getConstEntry (priv->capture_request,
ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION, &entry) != ACAMERA_OK) {
GST_WARNING_OBJECT (self, "Failed to get EV COMPENSATION");
goto out;
}
ev = entry.data.i32[0];
*ev_comp = (gfloat) (ev * ev_step.numerator / ev_step.denominator);
ret = TRUE;
out:
g_clear_pointer (&metadata, (GDestroyNotify) ACameraMetadata_free);
return ret;
}
static gboolean
gst_ahc2_src_set_ev_compensation (GstPhotography * photo, gfloat ev_comp)
{
GstAHC2Src *self = GST_AHC2_SRC (photo);
GstAHC2SrcPrivate *priv = GST_AHC2_SRC_GET_PRIVATE (self);
ACameraMetadata* metadata = NULL;
ACameraMetadata_const_entry entry;
gint ev, ev_min, ev_max;
ACameraMetadata_rational ev_step;
gboolean ret = FALSE;
g_return_val_if_fail (priv->camera_manager != NULL, FALSE);
g_return_val_if_fail (priv->camera_id_list != NULL, FALSE);
g_return_val_if_fail (priv->camera_index < priv->camera_id_list->numCameras,
FALSE);
g_return_val_if_fail (priv->capture_request != NULL, FALSE);
if (ACameraManager_getCameraCharacteristics (priv->camera_manager,
priv->camera_id_list->cameraIds[priv->camera_index],
&metadata) != ACAMERA_OK) {
GST_ERROR_OBJECT (self, "Failed to get metadata object");
goto out;
}
if (ACameraMetadata_getConstEntry (metadata,
ACAMERA_CONTROL_AE_COMPENSATION_STEP, &entry) != ACAMERA_OK) {
GST_WARNING_OBJECT (self, "Failed to get EV STEP");
goto out;
}
ev_step = entry.data.r[0];
if (ACameraMetadata_getConstEntry (metadata,
ACAMERA_CONTROL_AE_COMPENSATION_RANGE, &entry) != ACAMERA_OK) {
GST_WARNING_OBJECT (self, "Failed to get EV RANGE");
goto out;
}
ev_min = entry.data.i32[0];
ev_max = entry.data.i32[1];
ev = (gint) round (ev_comp / ev_step.numerator * ev_step.denominator);
if (ev < ev_min) {
GST_WARNING_OBJECT (self, "converted EV(%d) is less than min(%d)", ev, ev_min);
ev = ev_min;
}
if (ev > ev_max) {
GST_WARNING_OBJECT (self, "converted EV(%d) is greater than max(%d)", ev, ev_max);
ev = ev_max;
}
ACameraCaptureSession_stopRepeating (priv->camera_capture_session);
ACaptureRequest_setEntry_i32 (priv->capture_request,
ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION, 1, &ev);
ACameraCaptureSession_setRepeatingRequest (priv->camera_capture_session,
NULL, 1, &priv->capture_request, NULL);
ret = TRUE;
out:
g_clear_pointer (&metadata, (GDestroyNotify) ACameraMetadata_free);
return ret;
}
static gboolean
gst_ahc2_src_get_white_balance_mode (GstPhotography * photo,
GstPhotographyWhiteBalanceMode * mode)
......@@ -747,6 +865,11 @@ gst_ahc2_src_set_property (GObject * object,
case PROP_MAX_IMAGES:
priv->max_images = g_value_get_int (value);
break;
case PROP_EV_COMPENSATION: {
gfloat ev = g_value_get_float (value);
gst_ahc2_src_set_ev_compensation (GST_PHOTOGRAPHY (self), ev);
break;
}
case PROP_WHITE_BALANCE_MODE: {
GstPhotographyWhiteBalanceMode wb = g_value_get_enum (value);
gst_ahc2_src_set_white_balance_mode (GST_PHOTOGRAPHY (self), wb);
......@@ -783,6 +906,14 @@ gst_ahc2_src_get_property (GObject * object,
break;
}
case PROP_EV_COMPENSATION: {
gfloat ev;
if (gst_ahc2_src_get_ev_compensation (GST_PHOTOGRAPHY (self), &ev))
g_value_set_float (value, ev);
break;
}
case PROP_WHITE_BALANCE_MODE: {
GstPhotographyWhiteBalanceMode wb;
if (gst_ahc2_src_get_white_balance_mode (GST_PHOTOGRAPHY (self), &wb))
......@@ -1244,6 +1375,9 @@ gst_ahc2_src_photography_init (gpointer g_iface, gpointer iface_data)
iface->get_white_balance_mode = gst_ahc2_src_get_white_balance_mode;
iface->set_white_balance_mode = gst_ahc2_src_set_white_balance_mode;
iface->get_ev_compensation = gst_ahc2_src_get_ev_compensation;
iface->set_ev_compensation = gst_ahc2_src_set_ev_compensation;
}
static gboolean
......
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