camerabin2: Use a single location for both modes

Implement the location property just like it works in camerabin, the
same location is used for both images and videos
This commit is contained in:
Thiago Santos 2011-06-22 18:58:29 -03:00
parent f31554bc4f
commit f1fa6c6531
3 changed files with 19 additions and 39 deletions

View file

@ -127,8 +127,7 @@ enum
static guint camerabin_signals[LAST_SIGNAL]; static guint camerabin_signals[LAST_SIGNAL];
#define DEFAULT_MODE MODE_IMAGE #define DEFAULT_MODE MODE_IMAGE
#define DEFAULT_VID_LOCATION "vid_%d" #define DEFAULT_LOCATION "cap_%d"
#define DEFAULT_IMG_LOCATION "img_%d"
#define DEFAULT_POST_PREVIEWS TRUE #define DEFAULT_POST_PREVIEWS TRUE
#define DEFAULT_MUTE_AUDIO FALSE #define DEFAULT_MUTE_AUDIO FALSE
#define DEFAULT_IDLE TRUE #define DEFAULT_IDLE TRUE
@ -222,8 +221,7 @@ gst_camera_bin_start_capture (GstCameraBin * camerabin)
GST_DEBUG_OBJECT (camerabin, "Received start-capture"); GST_DEBUG_OBJECT (camerabin, "Received start-capture");
/* check that we have a valid location */ /* check that we have a valid location */
if ((camerabin->mode == MODE_VIDEO && camerabin->video_location == NULL) if (camerabin->location == NULL) {
|| (camerabin->mode == MODE_IMAGE && camerabin->image_location == NULL)) {
GST_ELEMENT_ERROR (camerabin, RESOURCE, OPEN_WRITE, GST_ELEMENT_ERROR (camerabin, RESOURCE, OPEN_WRITE,
(_("File location is set to NULL, please set it to a valid filename")), (_("File location is set to NULL, please set it to a valid filename")),
(NULL)); (NULL));
@ -251,7 +249,7 @@ gst_camera_bin_start_capture (GstCameraBin * camerabin)
/* store the next capture buffer filename */ /* store the next capture buffer filename */
location = location =
g_strdup_printf (camerabin->image_location, camerabin->image_index++); g_strdup_printf (camerabin->location, camerabin->capture_index++);
camerabin->image_location_list = camerabin->image_location_list =
g_slist_append (camerabin->image_location_list, location); g_slist_append (camerabin->image_location_list, location);
} }
@ -332,8 +330,7 @@ gst_camera_bin_src_notify_readyforcapture (GObject * obj, GParamSpec * pspec,
gst_element_set_state (camera->video_encodebin, GST_STATE_NULL); gst_element_set_state (camera->video_encodebin, GST_STATE_NULL);
gst_element_set_state (camera->videobin_capsfilter, GST_STATE_NULL); gst_element_set_state (camera->videobin_capsfilter, GST_STATE_NULL);
gst_element_set_state (camera->videobin_queue, GST_STATE_NULL); gst_element_set_state (camera->videobin_queue, GST_STATE_NULL);
location = location = g_strdup_printf (camera->location, camera->capture_index++);
g_strdup_printf (camera->video_location, camera->video_index++);
GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location); GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
g_object_set (camera->videosink, "location", location, NULL); g_object_set (camera->videosink, "location", location, NULL);
g_free (location); g_free (location);
@ -351,8 +348,7 @@ gst_camera_bin_dispose (GObject * object)
{ {
GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object); GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object);
g_free (camerabin->image_location); g_free (camerabin->location);
g_free (camerabin->video_location);
if (camerabin->src_capture_notify_id) if (camerabin->src_capture_notify_id)
g_signal_handler_disconnect (camerabin->src, g_signal_handler_disconnect (camerabin->src,
@ -493,8 +489,8 @@ gst_camera_bin_class_init (GstCameraBinClass * klass)
g_param_spec_string ("location", "Location", g_param_spec_string ("location", "Location",
"Location to save the captured files. A %d might be used on the" "Location to save the captured files. A %d might be used on the"
"filename as a placeholder for a numeric index of the capture." "filename as a placeholder for a numeric index of the capture."
"Default for images is img_%d and vid_%d for videos", "Default is cap_%d",
DEFAULT_IMG_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_CAMERA_SRC, g_object_class_install_property (object_class, PROP_CAMERA_SRC,
g_param_spec_object ("camera-source", "Camera source", g_param_spec_object ("camera-source", "Camera source",
@ -691,8 +687,7 @@ gst_camera_bin_init (GstCameraBin * camera)
{ {
camera->post_previews = DEFAULT_POST_PREVIEWS; camera->post_previews = DEFAULT_POST_PREVIEWS;
camera->mode = DEFAULT_MODE; camera->mode = DEFAULT_MODE;
camera->video_location = g_strdup (DEFAULT_VID_LOCATION); camera->location = g_strdup (DEFAULT_LOCATION);
camera->image_location = g_strdup (DEFAULT_IMG_LOCATION);
camera->viewfinderbin = gst_element_factory_make ("viewfinderbin", "vf-bin"); camera->viewfinderbin = gst_element_factory_make ("viewfinderbin", "vf-bin");
camera->zoom = DEFAULT_ZOOM; camera->zoom = DEFAULT_ZOOM;
camera->max_zoom = MAX_ZOOM; camera->max_zoom = MAX_ZOOM;
@ -1196,8 +1191,8 @@ gst_camera_bin_create_elements (GstCameraBin * camera)
gst_element_set_locked_state (camera->videosink, TRUE); gst_element_set_locked_state (camera->videosink, TRUE);
gst_element_set_locked_state (camera->imagesink, TRUE); gst_element_set_locked_state (camera->imagesink, TRUE);
g_object_set (camera->videosink, "location", camera->video_location, NULL); g_object_set (camera->videosink, "location", camera->location, NULL);
g_object_set (camera->imagesink, "location", camera->image_location, NULL); g_object_set (camera->imagesink, "location", camera->location, NULL);
} }
if (camera->video_profile_switch) { if (camera->video_profile_switch) {
@ -1463,13 +1458,8 @@ gst_camera_bin_set_location (GstCameraBin * camera, const gchar * location)
{ {
GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode, GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode,
location); location);
if (camera->mode == MODE_IMAGE) { g_free (camera->location);
g_free (camera->image_location); camera->location = g_strdup (location);
camera->image_location = g_strdup (location);
} else {
g_free (camera->video_location);
camera->video_location = g_strdup (location);
}
} }
static void static void
@ -1692,11 +1682,7 @@ gst_camera_bin_get_property (GObject * object, guint prop_id,
g_value_set_enum (value, camera->mode); g_value_set_enum (value, camera->mode);
break; break;
case PROP_LOCATION: case PROP_LOCATION:
if (camera->mode == MODE_VIDEO) { g_value_set_string (value, camera->location);
g_value_set_string (value, camera->video_location);
} else {
g_value_set_string (value, camera->image_location);
}
break; break;
case PROP_CAMERA_SRC: case PROP_CAMERA_SRC:
g_value_set_object (value, camera->user_src); g_value_set_object (value, camera->user_src);

View file

@ -75,8 +75,7 @@ struct _GstCameraBin
gint processing_counter; /* atomic int */ gint processing_counter; /* atomic int */
/* Index of the auto incrementing file index for captures */ /* Index of the auto incrementing file index for captures */
gint video_index; gint capture_index;
gint image_index;
/* stores list of image locations to be pushed to the image sink /* stores list of image locations to be pushed to the image sink
* as file location change notifications, they are pushed before * as file location change notifications, they are pushed before
@ -88,8 +87,7 @@ struct _GstCameraBin
/* properties */ /* properties */
gint mode; gint mode;
gchar *video_location; gchar *location;
gchar *image_location;
gboolean post_previews; gboolean post_previews;
GstCaps *preview_caps; GstCaps *preview_caps;
GstElement *preview_filter; GstElement *preview_filter;

View file

@ -746,14 +746,6 @@ GST_START_TEST (test_image_video_cycle)
if (!camera) if (!camera)
return; return;
/* set filepaths for image and videos */
g_object_set (camera, "mode", 1, NULL);
g_object_set (camera, "location", make_test_file_name (IMAGE_FILENAME, -1),
NULL);
g_object_set (camera, "mode", 2, NULL);
g_object_set (camera, "location", make_test_file_name (VIDEO_FILENAME, -1),
NULL);
if (gst_element_set_state (GST_ELEMENT (camera), GST_STATE_PLAYING) == if (gst_element_set_state (GST_ELEMENT (camera), GST_STATE_PLAYING) ==
GST_STATE_CHANGE_FAILURE) { GST_STATE_CHANGE_FAILURE) {
GST_WARNING ("setting camerabin to PLAYING failed"); GST_WARNING ("setting camerabin to PLAYING failed");
@ -769,6 +761,8 @@ GST_START_TEST (test_image_video_cycle)
/* take a picture */ /* take a picture */
g_object_set (camera, "mode", 1, NULL); g_object_set (camera, "mode", 1, NULL);
g_object_set (camera, "location", make_test_file_name (IMAGE_FILENAME, i),
NULL);
g_signal_emit_by_name (camera, "start-capture", NULL); g_signal_emit_by_name (camera, "start-capture", NULL);
g_timeout_add_seconds (3, (GSourceFunc) g_main_loop_quit, main_loop); g_timeout_add_seconds (3, (GSourceFunc) g_main_loop_quit, main_loop);
g_main_loop_run (main_loop); g_main_loop_run (main_loop);
@ -777,6 +771,8 @@ GST_START_TEST (test_image_video_cycle)
/* now go to video */ /* now go to video */
g_object_set (camera, "mode", 2, NULL); g_object_set (camera, "mode", 2, NULL);
g_object_set (camera, "location", make_test_file_name (VIDEO_FILENAME, i),
NULL);
g_signal_emit_by_name (camera, "start-capture", NULL); g_signal_emit_by_name (camera, "start-capture", NULL);
g_timeout_add_seconds (VIDEO_DURATION, (GSourceFunc) g_main_loop_quit, g_timeout_add_seconds (VIDEO_DURATION, (GSourceFunc) g_main_loop_quit,
main_loop); main_loop);