[aravis] gst_plugin: add auto gain, auto exposure, x and y offset properties.



commit 92f1391db835df026e9d3bc13b385246818b73c6
Author: Philipp Hausmann <philipp hausmann 314 ch>
Date:   Fri Jun 22 11:33:39 2012 +0200

    gst_plugin: add auto gain, auto exposure, x and y offset properties.

 gst/gstaravis.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 gst/gstaravis.h |    5 +++
 2 files changed, 95 insertions(+), 10 deletions(-)
---
diff --git a/gst/gstaravis.c b/gst/gstaravis.c
index 5cc92f4..97d616b 100644
--- a/gst/gstaravis.c
+++ b/gst/gstaravis.c
@@ -48,9 +48,13 @@ enum
   PROP_0,
   PROP_CAMERA_NAME,
   PROP_GAIN,
+  PROP_GAIN_AUTO,
   PROP_EXPOSURE,
+  PROP_EXPOSURE_AUTO,
   PROP_H_BINNING,
-  PROP_V_BINNING
+  PROP_V_BINNING,
+  PROP_OFFSET_X,
+  PROP_OFFSET_Y
 };
 
 GST_BOILERPLATE (GstAravis, gst_aravis, GstPushSrc, GST_TYPE_PUSH_SRC);
@@ -152,7 +156,7 @@ gst_aravis_set_caps (GstBaseSrc *src, GstCaps *caps)
 
 	pixel_format = arv_pixel_format_from_gst_caps (gst_structure_get_name (structure), bpp, depth, fourcc);
 
-	arv_camera_set_region (gst_aravis->camera, 0, 0, width, height);
+	arv_camera_set_region (gst_aravis->camera, gst_aravis->offset_x, gst_aravis->offset_y, width, height);
 	arv_camera_set_binning (gst_aravis->camera, gst_aravis->h_binning, gst_aravis->v_binning);
 	arv_camera_set_pixel_format (gst_aravis->camera, pixel_format);
 
@@ -177,13 +181,29 @@ gst_aravis_set_caps (GstBaseSrc *src, GstCaps *caps)
 
 	GST_DEBUG_OBJECT (gst_aravis, "Actual frame rate = %g Hz", arv_camera_get_frame_rate (gst_aravis->camera));
 
-	GST_DEBUG_OBJECT (gst_aravis, "Gain       = %d", gst_aravis->gain);
-	arv_camera_set_gain (gst_aravis->camera, gst_aravis->gain);
-	GST_DEBUG_OBJECT (gst_aravis, "Actual gain       = %d", arv_camera_get_gain (gst_aravis->camera));
+	if(gst_aravis->gain_auto) {
+		arv_camera_set_gain_auto (gst_aravis->camera, ARV_AUTO_CONTINUOUS);
+		GST_DEBUG_OBJECT (gst_aravis, "Auto Gain = continuous", gst_aravis->gain_auto);
+	} else {
+		if (gst_aravis->gain >= 0) {
+			GST_DEBUG_OBJECT (gst_aravis, "Gain = %d", gst_aravis->gain);
+			arv_camera_set_gain_auto (gst_aravis->camera, ARV_AUTO_OFF);
+			arv_camera_set_gain (gst_aravis->camera, gst_aravis->gain);
+		}
+		GST_DEBUG_OBJECT (gst_aravis, "Actual gain = %d", arv_camera_get_gain (gst_aravis->camera));
+	}
 
-	GST_DEBUG_OBJECT (gst_aravis, "Exposure   = %g Âs", gst_aravis->exposure_time_us);
-	arv_camera_set_exposure_time (gst_aravis->camera, gst_aravis->exposure_time_us);
-	GST_DEBUG_OBJECT (gst_aravis, "Actual exposure   = %g Âs", arv_camera_get_exposure_time (gst_aravis->camera));
+	if(gst_aravis->exposure_auto) {
+		arv_camera_set_exposure_time_auto (gst_aravis->camera, ARV_AUTO_CONTINUOUS);
+		GST_DEBUG_OBJECT (gst_aravis, "Auto Exposure = contiuous", gst_aravis->exposure_auto);
+	} else {
+		if (gst_aravis->exposure_time_us > 0.0) {
+			GST_DEBUG_OBJECT (gst_aravis, "Exposure = %g Âs", gst_aravis->exposure_time_us);
+			arv_camera_set_exposure_time_auto (gst_aravis->camera, ARV_AUTO_OFF);
+			arv_camera_set_exposure_time (gst_aravis->camera, gst_aravis->exposure_time_us);
+		}
+		GST_DEBUG_OBJECT (gst_aravis, "Actual exposure = %g Âs", arv_camera_get_exposure_time (gst_aravis->camera));
+	}
 
 	if (gst_aravis->fixed_caps != NULL)
 		gst_caps_unref (gst_aravis->fixed_caps);
@@ -365,7 +385,11 @@ gst_aravis_init (GstAravis *gst_aravis, GstAravisClass *g_class)
 	gst_aravis->camera_name = NULL;
 
 	gst_aravis->gain = -1;
+	gst_aravis->gain_auto = FALSE;
 	gst_aravis->exposure_time_us = -1;
+	gst_aravis->exposure_auto = FALSE;
+	gst_aravis->offset_x = 0;
+	gst_aravis->offset_y = 0;
 	gst_aravis->h_binning = -1;
 	gst_aravis->v_binning = -1;
 	gst_aravis->payload = 0;
@@ -424,9 +448,21 @@ gst_aravis_set_property (GObject * object, guint prop_id,
 		case PROP_GAIN:
 			gst_aravis->gain = g_value_get_int (value);
 			break;
+		case PROP_GAIN_AUTO:
+			gst_aravis->gain_auto = g_value_get_boolean (value);
+			break;
 		case PROP_EXPOSURE:
 			gst_aravis->exposure_time_us = g_value_get_double (value);
 			break;
+		case PROP_EXPOSURE_AUTO:
+			gst_aravis->exposure_auto = g_value_get_boolean (value);
+			break;
+		case PROP_OFFSET_X:
+			gst_aravis->offset_x = g_value_get_int (value);
+			break;
+		case PROP_OFFSET_Y:
+			gst_aravis->offset_y = g_value_get_int (value);
+			break;
 		case PROP_H_BINNING:
 			gst_aravis->h_binning = g_value_get_int (value);
 			break;
@@ -452,9 +488,21 @@ gst_aravis_get_property (GObject * object, guint prop_id, GValue * value,
 		case PROP_GAIN:
 			g_value_set_int (value, gst_aravis->gain);
 			break;
+		case PROP_GAIN_AUTO:
+			g_value_set_boolean (value, gst_aravis->gain_auto);
+			break;
 		case PROP_EXPOSURE:
 			g_value_set_double (value, gst_aravis->exposure_time_us);
 			break;
+		case PROP_EXPOSURE_AUTO:
+			g_value_set_boolean (value, gst_aravis->exposure_auto);
+			break;
+		case PROP_OFFSET_X:
+			g_value_set_int (value, gst_aravis->offset_x);
+			break;
+		case PROP_OFFSET_Y:
+			g_value_set_int (value, gst_aravis->offset_y);
+			break;
 		case PROP_H_BINNING:
 			g_value_set_int (value, gst_aravis->h_binning);
 			break;
@@ -506,18 +554,50 @@ gst_aravis_class_init (GstAravisClass * klass)
 		 g_param_spec_int ("gain",
 				   "Gain",
 				   "Gain (dB)",
-				   0, 500, 0,
+				   -1, 500, 0,
 				   G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 	g_object_class_install_property
 		(gobject_class,
+		 PROP_GAIN_AUTO,
+		 g_param_spec_boolean ("gain-auto",
+				       "Auto Gain",
+				       "Auto Gain Mode",
+				       TRUE,
+				       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property
+		(gobject_class,
 		 PROP_EXPOSURE,
 		 g_param_spec_double ("exposure",
 				      "Exposure",
 				      "Exposure time (Âs)",
-				      0.0, 100000000.0, 500.0,
+				      -1, 100000000.0, 500.0,
 				      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 	g_object_class_install_property
 		(gobject_class,
+		 PROP_EXPOSURE_AUTO,
+		 g_param_spec_boolean ("exposure-auto",
+				       "Auto Exposure",
+				       "Auto Exposure Mode",
+				       TRUE,
+				       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_OFFSET_X,
+		 g_param_spec_int ("offset-x",
+				   "x Offset",
+				   "Offset in x direction",
+				   0, G_MAXINT, 0,
+				   G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_OFFSET_Y,
+		 g_param_spec_int ("offset-y",
+				   "y Offset",
+				   "Offset in y direction",
+				   0, G_MAXINT, 0,
+				   G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property
+		(gobject_class,
 		 PROP_H_BINNING,
 		 g_param_spec_int ("h-binning",
 				   "Horizontal binning",
diff --git a/gst/gstaravis.h b/gst/gstaravis.h
index eae7a36..3cf0ac2 100644
--- a/gst/gstaravis.h
+++ b/gst/gstaravis.h
@@ -44,7 +44,12 @@ struct _GstAravis {
 	char *camera_name;
 
 	gint64 gain;
+	gboolean gain_auto;
 	double exposure_time_us;
+	gboolean exposure_auto;
+
+	gint offset_x;
+	gint offset_y;
 
 	gint h_binning;
 	gint v_binning;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]