diff options
author | Lasse Laukkanen <ext-lasse.2.laukkanen@nokia.com> | 2009-05-27 11:33:01 +0300 |
---|---|---|
committer | Stefan Kost <ensonic@users.sf.net> | 2009-06-05 15:51:31 +0300 |
commit | 6a47f6f594740e28dcf9176fb88260114a94f8b3 (patch) | |
tree | 1d1244808502bb12d23225084e176074013e8848 /tests | |
parent | bbf48697fbdf1c7b037c07d7876c3907336fd049 (diff) | |
download | gst-plugins-bad-6a47f6f594740e28dcf9176fb88260114a94f8b3.tar.gz gst-plugins-bad-6a47f6f594740e28dcf9176fb88260114a94f8b3.tar.bz2 gst-plugins-bad-6a47f6f594740e28dcf9176fb88260114a94f8b3.zip |
camerabin: preview image sending optimization
* decouple image capturing from image post-processing and encoding
* post image-captured message after image is captured
* post preview-image message with snapshot of captured image
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check/elements/camerabin.c | 185 |
1 files changed, 104 insertions, 81 deletions
diff --git a/tests/check/elements/camerabin.c b/tests/check/elements/camerabin.c index 7c6187d2..2b72c6ff 100644 --- a/tests/check/elements/camerabin.c +++ b/tests/check/elements/camerabin.c @@ -40,13 +40,11 @@ #define MAX_BURST_IMAGES 10 #define PHOTO_SETTING_DELAY_US 0 -static gboolean continuous = FALSE; -static guint captured_images = 0; - static GstElement *camera; static GCond *cam_cond; static GMutex *cam_mutex; - +static GMainLoop *main_loop; +static guint cycle_count = 0; /* helper function for filenames */ static const gchar * @@ -61,6 +59,8 @@ make_test_file_name (const gchar * base_name) return file_name; } +/* burst capture is not supported in camerabin for the moment */ +#ifdef ENABLE_BURST_CAPTURE static const gchar * make_test_seq_file_name (const gchar * base_name) { @@ -72,30 +72,49 @@ make_test_seq_file_name (const gchar * base_name) GST_INFO ("capturing to: %s", file_name); return file_name; } - +#endif /* signal handlers */ static gboolean -capture_done (GstElement * elem, const gchar * filename, gpointer user_data) +handle_image_captured_cb (gpointer data) { - captured_images++; - - if (captured_images >= MAX_BURST_IMAGES) { - /* release the shutter button */ - GST_DEBUG ("signal for img-done"); - g_mutex_lock (cam_mutex); - g_cond_signal (cam_cond); - g_mutex_unlock (cam_mutex); - continuous = FALSE; - } + GMainLoop *loop = (GMainLoop *) data; + + GST_DEBUG ("handle_image_captured_cb, cycle: %d", cycle_count); + if (cycle_count == 0) { + g_main_loop_quit (loop); + } else { + /* Set video recording mode */ + g_object_set (camera, "mode", 1, + "filename", make_test_file_name (CYCLE_VIDEO_FILENAME), NULL); + /* Record video */ + g_signal_emit_by_name (camera, "user-start", 0); + g_usleep (G_USEC_PER_SEC); + g_signal_emit_by_name (camera, "user-stop", 0); + GST_DEBUG ("video captured"); + + /* Set still image mode */ + g_object_set (camera, "mode", 0, + "filename", make_test_file_name (CYCLE_IMAGE_FILENAME), NULL); + /* Take a picture */ + g_signal_emit_by_name (camera, "user-start", 0); - if (continuous) { - /* Must set filename for new picture */ - g_object_set (G_OBJECT (elem), "filename", - make_test_seq_file_name (BURST_IMAGE_FILENAME), NULL); + cycle_count--; } + GST_DEBUG ("handle_image_captured_cb done"); + return FALSE; +} + +static gboolean +capture_done (GstElement * elem, const gchar * filename, gpointer user_data) +{ + GMainLoop *loop = (GMainLoop *) user_data; - return continuous; + g_idle_add ((GSourceFunc) handle_image_captured_cb, loop); + + GST_DEBUG ("image saved"); + + return FALSE; } /* configuration */ @@ -103,7 +122,8 @@ capture_done (GstElement * elem, const gchar * filename, gpointer user_data) static void setup_camerabin_elements (GstElement * camera) { - GstElement *vfsink, *audiosrc, *videosrc; + GstElement *vfsink, *audiosrc, *videosrc, *audioenc, *videoenc, *imageenc, + *videomux; /* Use fakesink for view finder */ vfsink = gst_element_factory_make ("fakesink", NULL); @@ -111,9 +131,42 @@ setup_camerabin_elements (GstElement * camera) g_object_set (audiosrc, "is-live", TRUE, NULL); videosrc = gst_element_factory_make ("videotestsrc", NULL); g_object_set (videosrc, "is-live", TRUE, NULL); + audioenc = gst_element_factory_make ("vorbisenc", NULL); + videoenc = gst_element_factory_make ("theoraenc", NULL); + videomux = gst_element_factory_make ("oggmux", NULL); + imageenc = gst_element_factory_make ("jpegenc", NULL); + + if (vfsink && audiosrc && videosrc && audioenc && videoenc && videomux + && imageenc) { + g_object_set (camera, "vfsink", vfsink, "audiosrc", audiosrc, "videosrc", + videosrc, "audioenc", audioenc, "videoenc", videoenc, "imageenc", + imageenc, "videomux", videomux, NULL); + } +} + +static gboolean +capture_bus_cb (GstBus * bus, GstMessage * message, gpointer data) +{ + GMainLoop *loop = (GMainLoop *) data; + const GstStructure *st; - g_object_set (camera, "vfsink", vfsink, "audiosrc", audiosrc, - "videosrc", videosrc, NULL); + switch (GST_MESSAGE_TYPE (message)) { + case GST_MESSAGE_ERROR: + fail_if (TRUE, "error while capturing"); + g_main_loop_quit (loop); + break; + case GST_MESSAGE_EOS: + GST_DEBUG ("eos"); + g_main_loop_quit (loop); + break; + default: + st = gst_message_get_structure (message); + if (st && gst_structure_has_name (st, "image-captured")) { + GST_DEBUG ("image-captured"); + } + break; + } + return TRUE; } static void @@ -121,6 +174,10 @@ setup (void) { GstTagSetter *setter; gchar *desc_str; + GstCaps *filter_caps; + GstBus *bus; + + main_loop = g_main_loop_new (NULL, TRUE); cam_cond = g_cond_new (); cam_mutex = g_mutex_new (); @@ -129,9 +186,15 @@ setup (void) setup_camerabin_elements (camera); - g_signal_connect (camera, "img-done", G_CALLBACK (capture_done), NULL); + g_signal_connect (camera, "img-done", G_CALLBACK (capture_done), main_loop); + + bus = gst_pipeline_get_bus (GST_PIPELINE (camera)); + gst_bus_add_watch (bus, (GstBusFunc) capture_bus_cb, main_loop); + gst_object_unref (bus); - captured_images = 0; + filter_caps = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420"); + g_object_set (G_OBJECT (camera), "filter-caps", filter_caps, NULL); + gst_caps_unref (filter_caps); /* Set some default tags */ setter = GST_TAG_SETTER (camera); @@ -141,8 +204,8 @@ setup (void) GST_TAG_DESCRIPTION, desc_str, NULL); g_free (desc_str); - if (gst_element_set_state (GST_ELEMENT (camera), GST_STATE_PLAYING) != - GST_STATE_CHANGE_SUCCESS) { + if (gst_element_set_state (GST_ELEMENT (camera), GST_STATE_PLAYING) == + GST_STATE_CHANGE_FAILURE) { gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL); gst_object_unref (camera); camera = NULL; @@ -314,39 +377,13 @@ GST_START_TEST (test_single_image_capture) g_object_set (camera, "mode", 0, "filename", make_test_file_name (SINGLE_IMAGE_FILENAME), NULL); - continuous = FALSE; - /* Test photography iface settings */ gst_element_get_state (GST_ELEMENT (camera), NULL, NULL, (2 * GST_SECOND)); test_photography_settings (camera); g_signal_emit_by_name (camera, "user-start", 0); - g_signal_emit_by_name (camera, "user-stop", 0); -} - -GST_END_TEST; - -GST_START_TEST (test_burst_image_capture) -{ - if (!camera) - return; - - /* set still image mode */ - g_object_set (camera, "mode", 0, - "filename", make_test_seq_file_name (BURST_IMAGE_FILENAME), NULL); - - /* set burst mode */ - continuous = TRUE; - - g_signal_emit_by_name (camera, "user-start", 0); - GST_DEBUG ("waiting for img-done"); - g_mutex_lock (cam_mutex); - g_cond_wait (cam_cond, cam_mutex); - g_mutex_unlock (cam_mutex); - GST_DEBUG ("received img-done"); - - g_signal_emit_by_name (camera, "user-stop", 0); + g_main_loop_run (main_loop); } GST_END_TEST; @@ -370,48 +407,35 @@ GST_END_TEST; GST_START_TEST (test_image_video_cycle) { - guint i; - if (!camera) return; - continuous = FALSE; - - for (i = 0; i < 2; i++) { - /* Set still image mode */ - g_object_set (camera, "mode", 0, - "filename", make_test_file_name (CYCLE_IMAGE_FILENAME), NULL); + cycle_count = 2; - /* Take a picture */ - g_signal_emit_by_name (camera, "user-start", 0); - g_signal_emit_by_name (camera, "user-stop", 0); - GST_DEBUG ("image captured"); + /* set still image mode */ + g_object_set (camera, "mode", 0, + "filename", make_test_file_name (CYCLE_IMAGE_FILENAME), NULL); - /* Set video recording mode */ - g_object_set (camera, "mode", 1, - "filename", make_test_file_name (CYCLE_VIDEO_FILENAME), NULL); + g_signal_emit_by_name (camera, "user-start", 0); - /* Record video */ - g_signal_emit_by_name (camera, "user-start", 0); - g_usleep (G_USEC_PER_SEC); - g_signal_emit_by_name (camera, "user-stop", 0); - GST_DEBUG ("video captured"); - } + g_main_loop_run (main_loop); } GST_END_TEST; GST_START_TEST (validate_captured_image_files) { - GString *filename; - gint i; - if (!camera) return; /* validate single image */ check_file_validity (SINGLE_IMAGE_FILENAME); +/* burst capture is not supported in camerabin for the moment */ +#ifdef ENABLE_BURST_CAPTURE + GString *filename; + gint i; + /* validate burst mode images */ filename = g_string_new (""); for (i = 0; i < MAX_BURST_IMAGES; i++) { @@ -419,7 +443,7 @@ GST_START_TEST (validate_captured_image_files) check_file_validity (filename->str); } g_string_free (filename, TRUE); - +#endif /* validate cycled image */ check_file_validity (CYCLE_IMAGE_FILENAME); } @@ -453,7 +477,6 @@ camerabin_suite (void) tcase_set_timeout (tc_basic, 20); tcase_add_checked_fixture (tc_basic, setup, teardown); tcase_add_test (tc_basic, test_single_image_capture); - tcase_add_test (tc_basic, test_burst_image_capture); tcase_add_test (tc_basic, test_video_recording); tcase_add_test (tc_basic, test_image_video_cycle); |