From 87eddd54d5479baaca552e1667a4b2028b4f8760 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Sat, 4 Dec 2010 10:15:34 -0300 Subject: [PATCH] basecamerasrc: Add mode property Move mode property from v4l2camerasrc to basecamerasrc, as all camera sources should handle it. --- gst/camerabin2/gstbasecamerasrc.c | 19 ++++++++++++++++++- gst/camerabin2/gstbasecamerasrc.h | 6 +++++- gst/camerabin2/gstv4l2camerasrc.c | 25 ++++++------------------- gst/camerabin2/gstv4l2camerasrc.h | 2 -- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/gst/camerabin2/gstbasecamerasrc.c b/gst/camerabin2/gstbasecamerasrc.c index 57b5ab7c14..fd4dc4b6f7 100644 --- a/gst/camerabin2/gstbasecamerasrc.c +++ b/gst/camerabin2/gstbasecamerasrc.c @@ -125,7 +125,11 @@ gst_base_camera_src_set_mode (GstBaseCameraSrc * self, GstCameraBinMode mode) g_return_val_if_fail (bclass->set_mode, FALSE); - return bclass->set_mode (self, mode); + if (bclass->set_mode (self, mode)) { + self->mode = mode; + return TRUE; + } + return FALSE; } /** @@ -274,6 +278,10 @@ gst_base_camera_src_set_property (GObject * object, GstBaseCameraSrc *self = GST_BASE_CAMERA_SRC (object); switch (prop_id) { + case ARG_MODE: + gst_base_camera_src_set_mode (GST_BASE_CAMERA_SRC (self), + g_value_get_enum (value)); + break; case ARG_ZOOM:{ g_atomic_int_set (&self->zoom, g_value_get_int (value)); /* does not set it if in NULL, the src is not created yet */ @@ -294,6 +302,9 @@ gst_base_camera_src_get_property (GObject * object, GstBaseCameraSrc *self = GST_BASE_CAMERA_SRC (object); switch (prop_id) { + case ARG_MODE: + g_value_set_enum (value, self->mode); + break; case ARG_ZOOM: g_value_set_int (value, g_atomic_int_get (&self->zoom)); break; @@ -414,6 +425,11 @@ gst_base_camera_src_class_init (GstBaseCameraSrcClass * klass) gobject_class->get_property = gst_base_camera_src_get_property; // g_object_class_install_property .... + g_object_class_install_property (gobject_class, ARG_MODE, + g_param_spec_enum ("mode", "Mode", + "The capture mode (still image capture or video recording)", + GST_TYPE_CAMERABIN_MODE, MODE_IMAGE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); gstelement_class->change_state = gst_base_camera_src_change_state; @@ -437,6 +453,7 @@ gst_base_camera_src_init (GstBaseCameraSrc * self, self->zoom = DEFAULT_ZOOM; self->image_capture_width = 0; self->image_capture_height = 0; + self->mode = MODE_IMAGE; self->night_mode = FALSE; diff --git a/gst/camerabin2/gstbasecamerasrc.h b/gst/camerabin2/gstbasecamerasrc.h index 75ef0222ac..2f22d813da 100644 --- a/gst/camerabin2/gstbasecamerasrc.h +++ b/gst/camerabin2/gstbasecamerasrc.h @@ -41,7 +41,9 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_CAMERA_SRC)) #define GST_IS_BASE_CAMERA_SRC_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_CAMERA_SRC)) - GType gst_base_camera_src_get_type (void); +#define GST_BASE_CAMERA_SRC_CAST(obj) \ + ((GstBaseCameraSrc *) (obj)) +GType gst_base_camera_src_get_type (void); typedef struct _GstBaseCameraSrc GstBaseCameraSrc; typedef struct _GstBaseCameraSrcClass GstBaseCameraSrcClass; @@ -58,6 +60,8 @@ struct _GstBaseCameraSrc GstPad *imgsrc; GstPad *vidsrc; + gint mode; + /* XXX preview pads? */ /* Resolution of the buffers configured to camerabin */ diff --git a/gst/camerabin2/gstv4l2camerasrc.c b/gst/camerabin2/gstv4l2camerasrc.c index 878fa5a3fa..00b6a50ab3 100644 --- a/gst/camerabin2/gstv4l2camerasrc.c +++ b/gst/camerabin2/gstv4l2camerasrc.c @@ -83,10 +83,6 @@ gst_v4l2_camera_src_set_property (GObject * object, GstV4l2CameraSrc *self = GST_V4L2_CAMERA_SRC (object); switch (prop_id) { - case ARG_MODE: - gst_base_camera_src_set_mode (GST_BASE_CAMERA_SRC (self), - g_value_get_enum (value)); - break; case ARG_FILTER_CAPS: GST_OBJECT_LOCK (self); gst_caps_replace (&self->view_finder_caps, @@ -130,9 +126,6 @@ gst_v4l2_camera_src_get_property (GObject * object, GstV4l2CameraSrc *self = GST_V4L2_CAMERA_SRC (object); switch (prop_id) { - case ARG_MODE: - g_value_set_enum (value, self->mode); - break; case ARG_READY_FOR_CAPTURE: g_value_set_boolean (value, !self->capturing); break; @@ -724,7 +717,6 @@ start_image_capture (GstV4l2CameraSrc * self) static gboolean gst_v4l2_camera_src_set_mode (GstBaseCameraSrc * bcamsrc, GstCameraBinMode mode) { - GstV4l2CameraSrc *self = GST_V4L2_CAMERA_SRC (bcamsrc); GstPhotography *photography = gst_base_camera_src_get_photography (bcamsrc); if (photography) { @@ -733,8 +725,6 @@ gst_v4l2_camera_src_set_mode (GstBaseCameraSrc * bcamsrc, GstCameraBinMode mode) g_object_set (G_OBJECT (photography), "capture-mode", mode, NULL); } } - - self->mode = mode; return TRUE; } @@ -1047,6 +1037,7 @@ gst_v4l2_camera_src_finish_image_capture (GstBaseCameraSrc * bcamsrc) static void gst_v4l2_camera_src_start_capture (GstV4l2CameraSrc * src) { + GstBaseCameraSrc *camerasrc = GST_BASE_CAMERA_SRC_CAST (src); g_mutex_lock (src->capturing_mutex); if (src->capturing) { GST_WARNING_OBJECT (src, "Capturing already ongoing"); @@ -1055,10 +1046,11 @@ gst_v4l2_camera_src_start_capture (GstV4l2CameraSrc * src) } src->capturing = TRUE; - if (src->mode == MODE_IMAGE) { + /* TODO should we use a macro? */ + if (camerasrc->mode == MODE_IMAGE) { src->image_capture_count = 1; start_image_capture (src); - } else if (src->mode == MODE_VIDEO) { + } else if (camerasrc->mode == MODE_VIDEO) { if (src->video_rec_status == GST_VIDEO_RECORDING_STATUS_DONE) { src->video_rec_status = GST_VIDEO_RECORDING_STATUS_STARTING; } @@ -1074,13 +1066,14 @@ gst_v4l2_camera_src_start_capture (GstV4l2CameraSrc * src) static void gst_v4l2_camera_src_stop_capture (GstV4l2CameraSrc * src) { + GstBaseCameraSrc *camerasrc = GST_BASE_CAMERA_SRC_CAST (src); g_mutex_lock (src->capturing_mutex); if (!src->capturing) { GST_DEBUG_OBJECT (src, "No ongoing capture"); g_mutex_unlock (src->capturing_mutex); return; } - if (src->mode == MODE_VIDEO) { + if (camerasrc->mode == MODE_VIDEO) { if (src->video_rec_status == GST_VIDEO_RECORDING_STATUS_STARTING) { GST_DEBUG_OBJECT (src, "Aborting, had not started recording"); src->video_rec_status = GST_VIDEO_RECORDING_STATUS_DONE; @@ -1125,11 +1118,6 @@ gst_v4l2_camera_src_class_init (GstV4l2CameraSrcClass * klass) gobject_class->get_property = gst_v4l2_camera_src_get_property; /* g_object_class_install_property .... */ - g_object_class_install_property (gobject_class, ARG_MODE, - g_param_spec_enum ("mode", "Mode", - "The capture mode (still image capture or video recording)", - GST_TYPE_CAMERABIN_MODE, MODE_IMAGE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); /** * GstV4l2CameraSrc:ready-for-capture: @@ -1181,7 +1169,6 @@ gst_v4l2_camera_src_init (GstV4l2CameraSrc * self, GstV4l2CameraSrcClass * klass) { /* TODO where are variables reset? */ - self->mode = MODE_IMAGE; self->image_capture_count = 0; self->video_rec_status = GST_VIDEO_RECORDING_STATUS_DONE; self->capturing_mutex = g_mutex_new (); diff --git a/gst/camerabin2/gstv4l2camerasrc.h b/gst/camerabin2/gstv4l2camerasrc.h index cd1a8fe257..e996920fff 100644 --- a/gst/camerabin2/gstv4l2camerasrc.h +++ b/gst/camerabin2/gstv4l2camerasrc.h @@ -57,8 +57,6 @@ struct _GstV4l2CameraSrc { GstBaseCameraSrc parent; - GstCameraBinMode mode; - gboolean capturing; GMutex *capturing_mutex;