From 5dadb325ae3d21d69d4c9bf8c2c759fe8f0ef8f1 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Fri, 13 May 2011 17:18:52 -0300 Subject: [PATCH] camerabin2: Remove obsolete imagecapturebin imagecapturebin has been replaced by encodebin, no need for it anymore --- gst/camerabin2/Makefile.am | 2 - gst/camerabin2/gstcamerabin2.c | 3 +- gst/camerabin2/gstimagecapturebin.c | 380 ----------------------- gst/camerabin2/gstimagecapturebin.h | 63 ---- gst/camerabin2/gstplugin.c | 3 - tests/check/Makefile.am | 8 - tests/check/elements/imagecapturebin.c | 410 ------------------------- 7 files changed, 2 insertions(+), 867 deletions(-) delete mode 100644 gst/camerabin2/gstimagecapturebin.c delete mode 100644 gst/camerabin2/gstimagecapturebin.h delete mode 100644 tests/check/elements/imagecapturebin.c diff --git a/gst/camerabin2/Makefile.am b/gst/camerabin2/Makefile.am index 400641c784..3433263ad5 100644 --- a/gst/camerabin2/Makefile.am +++ b/gst/camerabin2/Makefile.am @@ -1,7 +1,6 @@ plugin_LTLIBRARIES = libgstcamerabin2.la libgstcamerabin2_la_SOURCES = gstviewfinderbin.c \ - gstimagecapturebin.c \ camerabingeneral.c \ gstwrappercamerabinsrc.c \ gstcamerabin2.c \ @@ -23,7 +22,6 @@ libgstcamerabin2_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstcamerabin2_la_LIBTOOLFLAGS = --tag=disable-static noinst_HEADERS = gstviewfinderbin.h \ - gstimagecapturebin.h \ camerabingeneral.h \ gstwrappercamerabinsrc.h \ gstcamerabin2.h diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c index 37b8015eef..deaa8807a0 100644 --- a/gst/camerabin2/gstcamerabin2.c +++ b/gst/camerabin2/gstcamerabin2.c @@ -1061,7 +1061,8 @@ gst_camera_bin_create_elements (GstCameraBin * camera) prof = gst_encoding_container_profile_new ("jpeg", "jpeg container", caps, NULL); - gst_encoding_container_profile_add_profile (prof, vprof); + gst_encoding_container_profile_add_profile (prof, + (GstEncodingProfile *) vprof); gst_caps_unref (caps); camera->image_profile = (GstEncodingProfile *) prof; diff --git a/gst/camerabin2/gstimagecapturebin.c b/gst/camerabin2/gstimagecapturebin.c deleted file mode 100644 index d7c8d0101d..0000000000 --- a/gst/camerabin2/gstimagecapturebin.c +++ /dev/null @@ -1,380 +0,0 @@ -/* GStreamer - * Copyright (C) 2010 Thiago Santos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -/** - * SECTION:element-gstimagecapturebin - * - * The gstimagecapturebin element does FIXME stuff. - * - * - * Example launch line - * |[ - * gst-launch -v videotestsrc num-buffers=3 ! imagecapturebin - * ]| - * FIXME Describe what the pipeline does. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstimagecapturebin.h" -#include "camerabingeneral.h" -#include -#include - -/* prototypes */ - - -enum -{ - PROP_0, - PROP_LOCATION, - PROP_ENCODER, - PROP_MUXER -}; - -#define DEFAULT_LOCATION "img_%d" -#define DEFAULT_COLORSPACE "ffmpegcolorspace" -#define DEFAULT_ENCODER "jpegenc" -#define DEFAULT_MUXER "jifmux" -#define DEFAULT_SINK "multifilesink" - -/* pad templates */ - -static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-raw-yuv; video/x-raw-rgb") - ); - -/* class initialization */ - -GST_BOILERPLATE (GstImageCaptureBin, gst_image_capture_bin, GstBin, - GST_TYPE_BIN); - -/* GObject callbacks */ -static void gst_image_capture_bin_dispose (GObject * object); -static void gst_image_capture_bin_finalize (GObject * object); - -/* Element class functions */ -static GstStateChangeReturn -gst_image_capture_bin_change_state (GstElement * element, GstStateChange trans); - -static void -gst_image_capture_bin_set_encoder (GstImageCaptureBin * imagebin, - GstElement * encoder) -{ - GST_DEBUG_OBJECT (GST_OBJECT (imagebin), - "Setting image encoder %" GST_PTR_FORMAT, encoder); - - if (imagebin->user_encoder) - g_object_unref (imagebin->user_encoder); - - if (encoder) - g_object_ref (encoder); - - imagebin->user_encoder = encoder; -} - -static void -gst_image_capture_bin_set_muxer (GstImageCaptureBin * imagebin, - GstElement * muxer) -{ - GST_DEBUG_OBJECT (GST_OBJECT (imagebin), - "Setting image muxer %" GST_PTR_FORMAT, muxer); - - if (imagebin->user_muxer) - g_object_unref (imagebin->user_muxer); - - if (muxer) - g_object_ref (muxer); - - imagebin->user_muxer = muxer; -} - -static void -gst_image_capture_bin_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstImageCaptureBin *imagebin = GST_IMAGE_CAPTURE_BIN_CAST (object); - - switch (prop_id) { - case PROP_LOCATION: - g_free (imagebin->location); - imagebin->location = g_value_dup_string (value); - GST_DEBUG_OBJECT (imagebin, "setting location to %s", imagebin->location); - if (imagebin->sink) { - g_object_set (imagebin->sink, "location", imagebin->location, NULL); - } - break; - case PROP_ENCODER: - gst_image_capture_bin_set_encoder (imagebin, g_value_get_object (value)); - break; - case PROP_MUXER: - gst_image_capture_bin_set_muxer (imagebin, g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gst_image_capture_bin_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec) -{ - GstImageCaptureBin *imagebin = GST_IMAGE_CAPTURE_BIN_CAST (object); - - switch (prop_id) { - case PROP_LOCATION: - g_value_set_string (value, imagebin->location); - break; - case PROP_ENCODER: - g_value_set_object (value, imagebin->encoder); - break; - case PROP_MUXER: - g_value_set_object (value, imagebin->muxer); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gst_image_capture_bin_finalize (GObject * object) -{ - GstImageCaptureBin *imgbin = GST_IMAGE_CAPTURE_BIN_CAST (object); - - g_free (imgbin->location); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -gst_image_capture_bin_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); - - gst_element_class_set_details_simple (element_class, "Image Capture Bin", - "Sink/Video", "Image Capture Bin used in camerabin2", - "Thiago Santos "); -} - -static void -gst_image_capture_bin_class_init (GstImageCaptureBinClass * klass) -{ - GObjectClass *gobject_class; - GstElementClass *element_class; - - gobject_class = G_OBJECT_CLASS (klass); - element_class = GST_ELEMENT_CLASS (klass); - - gobject_class->dispose = gst_image_capture_bin_dispose; - gobject_class->finalize = gst_image_capture_bin_finalize; - gobject_class->set_property = gst_image_capture_bin_set_property; - gobject_class->get_property = gst_image_capture_bin_get_property; - - element_class->change_state = - GST_DEBUG_FUNCPTR (gst_image_capture_bin_change_state); - - g_object_class_install_property (gobject_class, PROP_LOCATION, - g_param_spec_string ("location", "Location", - "Location to save the captured files. A %%d can be used as a " - "placeholder for a capture count", - DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (gobject_class, PROP_ENCODER, - g_param_spec_object ("image-encoder", "Image encoder", - "Image encoder GStreamer element (default is jpegenc)", - GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property (gobject_class, PROP_MUXER, - g_param_spec_object ("image-muxer", "Image muxer", - "Image muxer GStreamer element (default is jifmux)", - GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); -} - -static void -gst_image_capture_bin_init (GstImageCaptureBin * imagebin, - GstImageCaptureBinClass * imagebin_class) -{ - GstPadTemplate *tmpl; - - tmpl = gst_static_pad_template_get (&sink_template); - imagebin->ghostpad = gst_ghost_pad_new_no_target_from_template ("sink", tmpl); - gst_object_unref (tmpl); - gst_element_add_pad (GST_ELEMENT_CAST (imagebin), imagebin->ghostpad); - - imagebin->sink = NULL; - - imagebin->location = g_strdup (DEFAULT_LOCATION); - imagebin->encoder = NULL; - imagebin->user_encoder = NULL; - imagebin->muxer = NULL; - imagebin->user_muxer = NULL; -} - -static void -gst_image_capture_bin_dispose (GObject * object) -{ - GstImageCaptureBin *imagebin = GST_IMAGE_CAPTURE_BIN_CAST (object); - - if (imagebin->user_encoder) { - gst_object_unref (imagebin->user_encoder); - imagebin->user_encoder = NULL; - } - - if (imagebin->user_muxer) { - gst_object_unref (imagebin->user_muxer); - imagebin->user_muxer = NULL; - } - G_OBJECT_CLASS (parent_class)->dispose ((GObject *) imagebin); -} - -static gboolean -gst_image_capture_bin_create_elements (GstImageCaptureBin * imagebin) -{ - GstElement *colorspace; - GstPad *pad = NULL; - const gchar *missing_element_name; - - if (imagebin->elements_created) - return TRUE; - - /* create elements */ - colorspace = - gst_camerabin_create_and_add_element (GST_BIN (imagebin), - DEFAULT_COLORSPACE, "imagebin-colorspace"); - if (!colorspace) { - missing_element_name = DEFAULT_COLORSPACE; - goto missing_element; - } - - if (imagebin->user_encoder) { - imagebin->encoder = imagebin->user_encoder; - if (!gst_camerabin_add_element (GST_BIN (imagebin), imagebin->encoder)) { - goto error; - } - } else { - imagebin->encoder = - gst_camerabin_create_and_add_element (GST_BIN (imagebin), - DEFAULT_ENCODER, "imagebin-encoder"); - if (!imagebin->encoder) { - missing_element_name = DEFAULT_ENCODER; - goto missing_element; - } - } - - if (imagebin->user_muxer) { - imagebin->muxer = imagebin->user_muxer; - if (!gst_camerabin_add_element (GST_BIN (imagebin), imagebin->muxer)) { - goto error; - } - } else { - imagebin->muxer = - gst_camerabin_create_and_add_element (GST_BIN (imagebin), - DEFAULT_MUXER, "imagebin-muxer"); - if (!imagebin->muxer) { - missing_element_name = DEFAULT_MUXER; - goto missing_element; - } - } - - imagebin->sink = - gst_camerabin_create_and_add_element (GST_BIN (imagebin), DEFAULT_SINK, - "imagebin-sink"); - if (!imagebin->sink) { - missing_element_name = DEFAULT_SINK; - goto missing_element; - } - - g_object_set (imagebin->sink, "location", imagebin->location, "async", FALSE, - "post-messages", TRUE, NULL); - - /* add ghostpad */ - pad = gst_element_get_static_pad (colorspace, "sink"); - if (!gst_ghost_pad_set_target (GST_GHOST_PAD (imagebin->ghostpad), pad)) - goto error; - gst_object_unref (pad); - - imagebin->elements_created = TRUE; - return TRUE; - -missing_element: - gst_element_post_message (GST_ELEMENT_CAST (imagebin), - gst_missing_element_message_new (GST_ELEMENT_CAST (imagebin), - missing_element_name)); - GST_ELEMENT_ERROR (imagebin, CORE, MISSING_PLUGIN, - (_("Missing element '%s' - check your GStreamer installation."), - missing_element_name), (NULL)); - goto error; - -error: - if (pad) - gst_object_unref (pad); - return FALSE; -} - -static GstStateChangeReturn -gst_image_capture_bin_change_state (GstElement * element, GstStateChange trans) -{ - GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; - GstImageCaptureBin *imagebin = GST_IMAGE_CAPTURE_BIN_CAST (element); - - switch (trans) { - case GST_STATE_CHANGE_NULL_TO_READY: - if (!gst_image_capture_bin_create_elements (imagebin)) { - return GST_STATE_CHANGE_FAILURE; - } - - /* set our image muxer to MERGE_REPLACE mode if it is a tagsetter */ - if (imagebin->muxer && gst_element_implements_interface (imagebin->muxer, - GST_TYPE_TAG_SETTER)) { - gst_tag_setter_set_tag_merge_mode (GST_TAG_SETTER (imagebin->muxer), - GST_TAG_MERGE_REPLACE); - } - - break; - default: - break; - } - - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, trans); - - switch (trans) { - case GST_STATE_CHANGE_READY_TO_NULL: - break; - default: - break; - } - - return ret; -} - -gboolean -gst_image_capture_bin_plugin_init (GstPlugin * plugin) -{ - return gst_element_register (plugin, "imagecapturebin", GST_RANK_NONE, - gst_image_capture_bin_get_type ()); -} diff --git a/gst/camerabin2/gstimagecapturebin.h b/gst/camerabin2/gstimagecapturebin.h deleted file mode 100644 index 98a28e9831..0000000000 --- a/gst/camerabin2/gstimagecapturebin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* GStreamer - * Copyright (C) 2010 Thiago Santos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef _GST_IMAGE_CAPTURE_BIN_H_ -#define _GST_IMAGE_CAPTURE_BIN_H_ - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_IMAGE_CAPTURE_BIN (gst_image_capture_bin_get_type()) -#define GST_IMAGE_CAPTURE_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IMAGE_CAPTURE_BIN,GstImageCaptureBin)) -#define GST_IMAGE_CAPTURE_BIN_CAST(obj) ((GstImageCaptureBin *) obj) -#define GST_IMAGE_CAPTURE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IMAGE_CAPTURE_BIN,GstImageCaptureBinClass)) -#define GST_IS_IMAGE_CAPTURE_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IMAGE_CAPTURE_BIN)) -#define GST_IS_IMAGE_CAPTURE_BIN_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IMAGE_CAPTURE_BIN)) - -typedef struct _GstImageCaptureBin GstImageCaptureBin; -typedef struct _GstImageCaptureBinClass GstImageCaptureBinClass; - -struct _GstImageCaptureBin -{ - GstBin bin; - - GstPad *ghostpad; - GstElement *sink; - - /* props */ - gchar *location; - GstElement *encoder; - GstElement *user_encoder; - GstElement *muxer; - GstElement *user_muxer; - - gboolean elements_created; -}; - -struct _GstImageCaptureBinClass -{ - GstBinClass bin_class; -}; - -GType gst_image_capture_bin_get_type (void); -gboolean gst_image_capture_bin_plugin_init (GstPlugin * plugin); - -G_END_DECLS - -#endif diff --git a/gst/camerabin2/gstplugin.c b/gst/camerabin2/gstplugin.c index 56fa78f800..6053521468 100644 --- a/gst/camerabin2/gstplugin.c +++ b/gst/camerabin2/gstplugin.c @@ -24,7 +24,6 @@ #endif #include "gstviewfinderbin.h" -#include "gstimagecapturebin.h" #include "gstwrappercamerabinsrc.h" #include "gstcamerabin2.h" @@ -33,8 +32,6 @@ plugin_init (GstPlugin * plugin) { if (!gst_viewfinder_bin_plugin_init (plugin)) return FALSE; - if (!gst_image_capture_bin_plugin_init (plugin)) - return FALSE; if (!gst_wrapper_camera_bin_src_plugin_init (plugin)) return FALSE; if (!gst_camera_bin_plugin_init (plugin)) diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 929ca51fc0..26a52c4922 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -141,7 +141,6 @@ VALGRIND_TESTS_DISABLE = \ if BUILD_EXPERIMENTAL EXPERIMENTAL_CHECKS=elements/camerabin2 \ - elements/imagecapturebin \ elements/viewfinderbin endif @@ -219,13 +218,6 @@ elements_camerabin2_LDADD = \ $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) elements_camerabin2_SOURCES = elements/camerabin2.c -elements_imagecapturebin_CFLAGS = \ - $(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(AM_CFLAGS) -DGST_USE_UNSTABLE_API -elements_imagecapturebin_LDADD = \ - $(GST_PLUGINS_BASE_LIBS) -lgstapp-@GST_MAJORMINOR@ \ - $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) -elements_imagecapturebin_SOURCES = elements/imagecapturebin.c endif elements_jifmux_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(EXIF_CFLAGS) $(AM_CFLAGS) diff --git a/tests/check/elements/imagecapturebin.c b/tests/check/elements/imagecapturebin.c deleted file mode 100644 index 5c5f73613b..0000000000 --- a/tests/check/elements/imagecapturebin.c +++ /dev/null @@ -1,410 +0,0 @@ -/* GStreamer unit test for the imagecapturebin element - * Copyright (C) 2010 Thiago Santos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include - -#define N_BUFFERS 3 - -typedef struct -{ - GstElement *pipe; - GstElement *src; - GstElement *icbin; -} GstImageCaptureBinTestContext; - -static void -gstimagecapturebin_init_test_context (GstImageCaptureBinTestContext * ctx, - const gchar * src, gint num_buffers) -{ - fail_unless (ctx != NULL); - - ctx->pipe = gst_pipeline_new ("pipeline"); - fail_unless (ctx->pipe != NULL); - ctx->src = gst_element_factory_make (src, "src"); - fail_unless (ctx->src != NULL, "Failed to create src element"); - ctx->icbin = gst_element_factory_make ("imagecapturebin", "icbin"); - fail_unless (ctx->icbin != NULL, "Failed to create imagecapturebin element"); - - if (num_buffers > 0) - g_object_set (ctx->src, "num-buffers", num_buffers, NULL); - - fail_unless (gst_bin_add (GST_BIN (ctx->pipe), ctx->src)); - fail_unless (gst_bin_add (GST_BIN (ctx->pipe), ctx->icbin)); - fail_unless (gst_element_link_many (ctx->src, ctx->icbin, NULL)); -} - -static void -gstimagecapturebin_unset_test_context (GstImageCaptureBinTestContext * ctx) -{ - gst_element_set_state (ctx->pipe, GST_STATE_NULL); - gst_object_unref (ctx->pipe); - memset (ctx, 0, sizeof (GstImageCaptureBinTestContext)); -} - -static gchar * -make_test_file_name (void) -{ - return g_strdup_printf ("%s" G_DIR_SEPARATOR_S - "imagecapturebintest_%%d.cap", g_get_tmp_dir ()); -} - -static gboolean -get_file_info (const gchar * filename, gint * width, gint * height) -{ - GstElement *playbin = gst_element_factory_make ("playbin2", NULL); - GstElement *fakesink = gst_element_factory_make ("fakesink", NULL); - GstState state = GST_STATE_NULL; - GstPad *pad; - GstCaps *caps; - gchar *uri = g_strdup_printf ("file://%s", filename); - - g_object_set (playbin, "video-sink", fakesink, NULL); - g_object_set (playbin, "uri", uri, NULL); - g_free (uri); - - gst_element_set_state (playbin, GST_STATE_PAUSED); - - gst_element_get_state (playbin, &state, NULL, GST_SECOND * 5); - - fail_unless (state == GST_STATE_PAUSED); - - g_signal_emit_by_name (playbin, "get-video-pad", 0, &pad, NULL); - caps = gst_pad_get_negotiated_caps (pad); - fail_unless (gst_structure_get_int (gst_caps_get_structure (caps, 0), "width", - width)); - fail_unless (gst_structure_get_int (gst_caps_get_structure (caps, 0), - "height", height)); - - gst_object_unref (pad); - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); - return TRUE; -} - -static GstBuffer * -create_video_buffer (GstCaps * caps) -{ - GstElement *pipeline; - GstElement *cf; - GstElement *sink; - GstBuffer *buffer; - - pipeline = - gst_parse_launch - ("videotestsrc num-buffers=1 ! capsfilter name=cf ! appsink name=sink", - NULL); - g_assert (pipeline != NULL); - - cf = gst_bin_get_by_name (GST_BIN (pipeline), "cf"); - sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink"); - - g_object_set (G_OBJECT (cf), "caps", caps, NULL); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - buffer = gst_app_sink_pull_buffer (GST_APP_SINK (sink)); - - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - gst_object_unref (sink); - gst_object_unref (cf); - return buffer; -} - - -GST_START_TEST (test_simple_capture) -{ - GstImageCaptureBinTestContext ctx; - GstBus *bus; - GstMessage *msg; - gchar *test_file_name; - gint i; - - gstimagecapturebin_init_test_context (&ctx, "videotestsrc", N_BUFFERS); - bus = gst_element_get_bus (ctx.pipe); - - test_file_name = make_test_file_name (); - g_object_set (ctx.icbin, "location", test_file_name, NULL); - - fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) == - GST_STATE_CHANGE_FAILURE); - - msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 10, - GST_MESSAGE_EOS | GST_MESSAGE_ERROR); - fail_unless (msg != NULL); - fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS); - gst_message_unref (msg); - - /* check there are N_BUFFERS files */ - for (i = 0; i < N_BUFFERS; i++) { - gchar *filename; - FILE *f; - - filename = g_strdup_printf (test_file_name, i); - - fail_unless (g_file_test (filename, G_FILE_TEST_EXISTS)); - fail_unless (g_file_test (filename, G_FILE_TEST_IS_REGULAR)); - fail_if (g_file_test (filename, G_FILE_TEST_IS_SYMLINK)); - - /* check the file isn't empty */ - f = fopen (filename, "r"); - fseek (f, 0, SEEK_END); - fail_unless (ftell (f) > 0); - fclose (f); - - g_free (filename); - } - - gstimagecapturebin_unset_test_context (&ctx); - gst_object_unref (bus); - g_free (test_file_name); -} - -GST_END_TEST; - - -GST_START_TEST (test_multiple_captures_different_caps) -{ - GstImageCaptureBinTestContext ctx; - GstBus *bus; - GstMessage *msg; - gchar *test_file_name; - gint i; - gint widths[] = { 100, 300, 200 }; - gint heights[] = { 300, 200, 100 }; - GstPad *pad; - - gstimagecapturebin_init_test_context (&ctx, "appsrc", N_BUFFERS); - bus = gst_element_get_bus (ctx.pipe); - - test_file_name = make_test_file_name (); - g_object_set (ctx.icbin, "location", test_file_name, NULL); - fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) == - GST_STATE_CHANGE_FAILURE); - - /* push data directly because set_caps and buffer pushes on appsrc - * are not serialized into the flow, so we can't guarantee the buffers - * have the caps we want on them when pushed */ - pad = gst_element_get_static_pad (ctx.src, "src"); - - /* push the buffers */ - for (i = 0; i < N_BUFFERS; i++) { - GstCaps *caps; - GstBuffer *buf; - - caps = gst_caps_new_simple ("video/x-raw-yuv", "width", G_TYPE_INT, - widths[i], "height", G_TYPE_INT, heights[i], "framerate", - GST_TYPE_FRACTION, 1, 1, "format", GST_TYPE_FOURCC, - GST_MAKE_FOURCC ('I', '4', '2', '0'), NULL); - - buf = create_video_buffer (caps); - fail_if (buf == NULL); - - fail_unless (gst_pad_push (pad, buf) == GST_FLOW_OK); - gst_caps_unref (caps); - } - gst_app_src_end_of_stream (GST_APP_SRC (ctx.src)); - gst_object_unref (pad); - - msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 10, - GST_MESSAGE_EOS | GST_MESSAGE_ERROR); - fail_unless (msg != NULL); - fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS); - gst_message_unref (msg); - - /* check there are N_BUFFERS files */ - for (i = 0; i < N_BUFFERS; i++) { - gchar *filename; - FILE *f; - gint width = 0, height = 0; - - filename = g_strdup_printf (test_file_name, i); - - fail_unless (g_file_test (filename, G_FILE_TEST_EXISTS)); - fail_unless (g_file_test (filename, G_FILE_TEST_IS_REGULAR)); - fail_if (g_file_test (filename, G_FILE_TEST_IS_SYMLINK)); - - /* check the file isn't empty */ - f = fopen (filename, "r"); - fseek (f, 0, SEEK_END); - fail_unless (ftell (f) > 0); - fclose (f); - - /* get the file info */ - fail_unless (get_file_info (filename, &width, &height)); - fail_unless (width == widths[i]); - fail_unless (height == heights[i]); - - g_free (filename); - } - - gstimagecapturebin_unset_test_context (&ctx); - gst_object_unref (bus); - g_free (test_file_name); -} - -GST_END_TEST; - -GST_START_TEST (test_setting_encoder) -{ - GstImageCaptureBinTestContext ctx; - GstBus *bus; - GstMessage *msg; - GstElement *encoder; - gchar *test_file_name; - gint i; - - gstimagecapturebin_init_test_context (&ctx, "videotestsrc", N_BUFFERS); - bus = gst_element_get_bus (ctx.pipe); - - test_file_name = make_test_file_name (); - g_object_set (ctx.icbin, "location", test_file_name, NULL); - - encoder = gst_element_factory_make ("jpegenc", NULL); - g_object_set (ctx.icbin, "image-encoder", encoder, NULL); - - fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) == - GST_STATE_CHANGE_FAILURE); - - msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 10, - GST_MESSAGE_EOS | GST_MESSAGE_ERROR); - fail_unless (msg != NULL); - fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS); - - /* check there are N_BUFFERS files */ - for (i = 0; i < N_BUFFERS; i++) { - gchar *filename; - FILE *f; - - filename = g_strdup_printf (test_file_name, i); - - fail_unless (g_file_test (filename, G_FILE_TEST_EXISTS)); - fail_unless (g_file_test (filename, G_FILE_TEST_IS_REGULAR)); - fail_if (g_file_test (filename, G_FILE_TEST_IS_SYMLINK)); - - /* check the file isn't empty */ - f = fopen (filename, "r"); - fseek (f, 0, SEEK_END); - fail_unless (ftell (f) > 0); - fclose (f); - - g_free (filename); - } - - gstimagecapturebin_unset_test_context (&ctx); - gst_object_unref (bus); - g_free (test_file_name); -} - -GST_END_TEST; - -GST_START_TEST (test_setting_muxer) -{ - GstImageCaptureBinTestContext ctx; - GstBus *bus; - GstMessage *msg; - GstElement *encoder; - gchar *test_file_name; - gint i; - - gstimagecapturebin_init_test_context (&ctx, "videotestsrc", N_BUFFERS); - bus = gst_element_get_bus (ctx.pipe); - - test_file_name = make_test_file_name (); - g_object_set (ctx.icbin, "location", test_file_name, NULL); - - encoder = gst_element_factory_make ("pngenc", NULL); - g_object_set (ctx.icbin, "image-encoder", encoder, NULL); - - encoder = gst_element_factory_make ("identity", NULL); - g_object_set (ctx.icbin, "image-muxer", encoder, NULL); - - fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) == - GST_STATE_CHANGE_FAILURE); - - msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 10, - GST_MESSAGE_EOS | GST_MESSAGE_ERROR); - fail_unless (msg != NULL); - fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS); - - /* check there are N_BUFFERS files */ - for (i = 0; i < N_BUFFERS; i++) { - gchar *filename; - FILE *f; - - filename = g_strdup_printf (test_file_name, i); - - fail_unless (g_file_test (filename, G_FILE_TEST_EXISTS)); - fail_unless (g_file_test (filename, G_FILE_TEST_IS_REGULAR)); - fail_if (g_file_test (filename, G_FILE_TEST_IS_SYMLINK)); - - /* check the file isn't empty */ - f = fopen (filename, "r"); - fseek (f, 0, SEEK_END); - fail_unless (ftell (f) > 0); - fclose (f); - - g_free (filename); - } - - gstimagecapturebin_unset_test_context (&ctx); - gst_object_unref (bus); - g_free (test_file_name); -} - -GST_END_TEST; - -static Suite * -imagecapturebin_suite (void) -{ - GstElementFactory *jpegenc_factory; - - Suite *s = suite_create ("imagecapturebin"); - TCase *tc_chain = tcase_create ("general"); - - jpegenc_factory = gst_element_factory_find ("jpegenc"); - - suite_add_tcase (s, tc_chain); - if (jpegenc_factory) { - tcase_add_test (tc_chain, test_simple_capture); - - /* only adds this test if jpegenc contains the fix for its getcaps - * The fix on good: dcbba0932dc579abd6aab4460fa1a416374eda1b */ - if (gst_plugin_feature_check_version ((GstPluginFeature *) jpegenc_factory, - 0, 10, 27)) - tcase_add_test (tc_chain, test_multiple_captures_different_caps); - else - GST_WARNING ("Skipped test that needs gst-plugins-good 0.10.27"); - - tcase_add_test (tc_chain, test_setting_encoder); - tcase_add_test (tc_chain, test_setting_muxer); - } else - GST_WARNING ("Skipped imagecapturebin tests because jpegenc is missing"); - - return s; -} - -GST_CHECK_MAIN (imagecapturebin);